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_Drawer.hxx>
20 #include <AIS_InteractiveObject.hxx>
21 #include <AIS_ListOfInteractive.hxx>
22 #include <AIS_ListIteratorOfListOfInteractive.hxx>
24 #include <Graphic3d_AspectMarker3d.hxx>
25 #include <Graphic3d_ExportFormat.hxx>
26 #include <Graphic3d_NameOfTextureEnv.hxx>
27 #include <Graphic3d_TextureEnv.hxx>
28 #include <Graphic3d_TextureParams.hxx>
29 #include <Graphic3d_TypeOfTextureFilter.hxx>
30 #include <Graphic3d_AspectFillArea3d.hxx>
31 #include <ViewerTest.hxx>
32 #include <ViewerTest_AutoUpdater.hxx>
33 #include <ViewerTest_EventManager.hxx>
34 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
35 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
36 #include <Visual3d_View.hxx>
37 #include <Visual3d_ViewManager.hxx>
38 #include <V3d_AmbientLight.hxx>
39 #include <V3d_ColorScale.hxx>
40 #include <V3d_DirectionalLight.hxx>
41 #include <V3d_LayerMgr.hxx>
42 #include <V3d_LayerMgrPointer.hxx>
43 #include <V3d_PositionalLight.hxx>
44 #include <V3d_SpotLight.hxx>
45 #include <NCollection_DoubleMap.hxx>
46 #include <NCollection_List.hxx>
47 #include <NCollection_Vector.hxx>
48 #include <NIS_View.hxx>
49 #include <NIS_Triangulated.hxx>
50 #include <NIS_InteractiveContext.hxx>
51 #include <AIS_InteractiveContext.hxx>
52 #include <Draw_Interpretor.hxx>
54 #include <Draw_Appli.hxx>
55 #include <Aspect_PrintAlgo.hxx>
56 #include <Image_AlienPixMap.hxx>
57 #include <OpenGl_GraphicDriver.hxx>
58 #include <OSD_Timer.hxx>
59 #include <TColStd_HSequenceOfAsciiString.hxx>
60 #include <TColStd_SequenceOfInteger.hxx>
61 #include <TColStd_HSequenceOfReal.hxx>
62 #include <TColgp_Array1OfPnt2d.hxx>
63 #include <TColStd_MapOfAsciiString.hxx>
64 #include <Visual3d_LayerItem.hxx>
65 #include <Aspect_TypeOfLine.hxx>
66 #include <Image_Diff.hxx>
67 #include <Aspect_DisplayConnection.hxx>
71 #include <PrsMgr_PresentableObject.hxx>
72 #include <Graphic3d_ClipPlane.hxx>
73 #include <NCollection_DataMap.hxx>
74 #include <Graphic3d_Texture2Dmanual.hxx>
75 #include <Prs3d_ShadingAspect.hxx>
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";
4729 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4730 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4732 Standard_CString anArg = theArgVec[anArgIter];
4733 TCollection_AsciiString anArgCase (anArg);
4734 anArgCase.LowerCase();
4735 if (anUpdateTool.parseRedrawMode (anArg))
4739 else if (anArgCase == "-ffp")
4741 Standard_Boolean toEnable = Standard_True;
4742 if (++anArgIter < theArgNb
4743 && !parseOnOff (theArgVec[anArgIter], toEnable))
4747 aCaps->ffpEnable = toEnable;
4749 else if (anArgCase == "-vbo")
4751 Standard_Boolean toEnable = Standard_True;
4752 if (++anArgIter < theArgNb
4753 && !parseOnOff (theArgVec[anArgIter], toEnable))
4757 aCaps->vboDisable = !toEnable;
4759 else if (anArgCase == "-sprite"
4760 || anArgCase == "-sprites")
4762 Standard_Boolean toEnable = Standard_True;
4763 if (++anArgIter < theArgNb
4764 && !parseOnOff (theArgVec[anArgIter], toEnable))
4768 aCaps->pntSpritesDisable = !toEnable;
4770 else if (anArgCase == "-softmode")
4772 Standard_Boolean toEnable = Standard_True;
4773 if (++anArgIter < theArgNb
4774 && !parseOnOff (theArgVec[anArgIter], toEnable))
4778 aCaps->contextNoAccel = toEnable;
4780 else if (anArgCase == "-accel"
4781 || anArgCase == "-acceleration")
4783 Standard_Boolean toEnable = Standard_True;
4784 if (++anArgIter < theArgNb
4785 && !parseOnOff (theArgVec[anArgIter], toEnable))
4789 aCaps->contextNoAccel = !toEnable;
4793 std::cout << "Error: unknown argument '" << anArg << "'\n";
4797 if (aCaps != &ViewerTest_myDefaultCaps)
4799 ViewerTest_myDefaultCaps = *aCaps;
4804 //==============================================================================
4805 //function : VMemGpu
4807 //==============================================================================
4809 static int VMemGpu (Draw_Interpretor& theDI,
4810 Standard_Integer theArgNb,
4811 const char** theArgVec)
4814 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4815 if (aContextAIS.IsNull())
4817 std::cerr << "No active view. Please call vinit.\n";
4821 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
4822 if (aDriver.IsNull())
4824 std::cerr << "Graphic driver not available.\n";
4828 Standard_Size aFreeBytes = 0;
4829 TCollection_AsciiString anInfo;
4830 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
4832 std::cerr << "Information not available.\n";
4836 if (theArgNb > 1 && *theArgVec[1] == 'f')
4838 theDI << Standard_Real (aFreeBytes);
4848 // ==============================================================================
4849 // function : VReadPixel
4851 // ==============================================================================
4852 static int VReadPixel (Draw_Interpretor& theDI,
4853 Standard_Integer theArgNb,
4854 const char** theArgVec)
4856 // get the active view
4857 Handle(V3d_View) aView = ViewerTest::CurrentView();
4860 std::cerr << "No active view. Please call vinit.\n";
4863 else if (theArgNb < 3)
4865 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4869 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4870 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4872 Standard_Integer aWidth, aHeight;
4873 aView->Window()->Size (aWidth, aHeight);
4874 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4875 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4876 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4878 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4882 Standard_Boolean toShowName = Standard_False;
4883 Standard_Boolean toShowHls = Standard_False;
4884 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4886 const char* aParam = theArgVec[anIter];
4887 if ( strcasecmp( aParam, "rgb" ) == 0 )
4889 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4890 aBufferType = Graphic3d_BT_RGB;
4892 else if ( strcasecmp( aParam, "hls" ) == 0 )
4894 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4895 aBufferType = Graphic3d_BT_RGB;
4896 toShowHls = Standard_True;
4898 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4900 aFormat = Image_PixMap::ImgRGBF;
4901 aBufferType = Graphic3d_BT_RGB;
4903 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4905 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4906 aBufferType = Graphic3d_BT_RGBA;
4908 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4910 aFormat = Image_PixMap::ImgRGBAF;
4911 aBufferType = Graphic3d_BT_RGBA;
4913 else if ( strcasecmp( aParam, "depth" ) == 0 )
4915 aFormat = Image_PixMap::ImgGrayF;
4916 aBufferType = Graphic3d_BT_Depth;
4918 else if ( strcasecmp( aParam, "name" ) == 0 )
4920 toShowName = Standard_True;
4924 Image_PixMap anImage;
4925 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4927 std::cerr << "Image allocation failed\n";
4930 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4932 std::cerr << "Image dump failed\n";
4936 Quantity_Parameter anAlpha;
4937 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4940 if (aBufferType == Graphic3d_BT_RGBA)
4942 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
4946 theDI << Quantity_Color::StringName (aColor.Name());
4951 switch (aBufferType)
4954 case Graphic3d_BT_RGB:
4958 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
4962 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
4966 case Graphic3d_BT_RGBA:
4968 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
4971 case Graphic3d_BT_Depth:
4973 theDI << aColor.Red();
4982 //==============================================================================
4983 //function : VDiffImage
4984 //purpose : The draw-command compares two images.
4985 //==============================================================================
4987 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4991 theDI << "Not enough arguments.\n";
4996 const char* anImgPathRef = theArgVec[1];
4997 const char* anImgPathNew = theArgVec[2];
4999 // get string tolerance and check its validity
5000 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5001 if (aTolColor < 0.0)
5003 if (aTolColor > 1.0)
5006 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5007 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5009 // image file of difference
5010 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5012 // compare the images
5013 Image_Diff aComparer;
5014 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5019 aComparer.SetColorTolerance (aTolColor);
5020 aComparer.SetBorderFilterOn (isBorderFilterOn);
5021 Standard_Integer aDiffColorsNb = aComparer.Compare();
5022 theDI << aDiffColorsNb << "\n";
5024 // save image of difference
5025 if (aDiffImagePath != NULL)
5027 aComparer.SaveDiffImage (aDiffImagePath);
5033 //=======================================================================
5034 //function : VSelect
5035 //purpose : Emulates different types of selection by mouse:
5036 // 1) single click selection
5037 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5038 // 3) selection with polygon having corners at
5039 // pixel positions (x1,y1),...,(xn,yn)
5040 // 4) any of these selections with shift button pressed
5041 //=======================================================================
5042 static Standard_Integer VSelect (Draw_Interpretor& di,
5043 Standard_Integer argc,
5048 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
5052 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5053 if(myAIScontext.IsNull())
5055 di << "use 'vinit' command before " << argv[0] << "\n";
5058 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
5059 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5060 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5063 if(isShiftSelection)
5064 aCurrentEventManager->ShiftSelect();
5066 aCurrentEventManager->Select();
5070 if(isShiftSelection)
5071 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
5073 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
5077 Standard_Integer anUpper = 0;
5079 if(isShiftSelection)
5080 anUpper = (argc-1)/2;
5083 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
5085 for(Standard_Integer i=1;i<=anUpper;++i)
5086 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5088 if(isShiftSelection)
5089 aCurrentEventManager->ShiftSelect(aPolyline);
5091 aCurrentEventManager->Select(aPolyline);
5096 //=======================================================================
5097 //function : VMoveTo
5098 //purpose : Emulates cursor movement to defined pixel position
5099 //=======================================================================
5100 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5101 Standard_Integer argc,
5106 di << "Usage : " << argv[0] << " x y" << "\n";
5110 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5111 if(aContext.IsNull())
5113 di << "use 'vinit' command before " << argv[0] << "\n";
5116 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5120 //=================================================================================================
5121 //function : VViewParams
5122 //purpose : Gets or sets AIS View characteristics
5123 //=================================================================================================
5124 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5126 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5127 if (anAISView.IsNull())
5129 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
5135 // print all of the available view parameters
5136 Quantity_Factor anAISViewScale = anAISView->Scale();
5138 Standard_Real anAISViewProjX = 0.0;
5139 Standard_Real anAISViewProjY = 0.0;
5140 Standard_Real anAISViewProjZ = 0.0;
5141 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
5143 Standard_Real anAISViewUpX = 0.0;
5144 Standard_Real anAISViewUpY = 0.0;
5145 Standard_Real anAISViewUpZ = 0.0;
5146 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
5148 Standard_Real anAISViewAtX = 0.0;
5149 Standard_Real anAISViewAtY = 0.0;
5150 Standard_Real anAISViewAtZ = 0.0;
5151 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
5153 Standard_Real anAISViewEyeX = 0.0;
5154 Standard_Real anAISViewEyeY = 0.0;
5155 Standard_Real anAISViewEyeZ = 0.0;
5156 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
5158 theDi << "Scale of current view: " << anAISViewScale << "\n";
5159 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
5160 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
5161 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
5162 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
5166 // -------------------------
5167 // Parse options and values
5168 // -------------------------
5170 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
5171 TCollection_AsciiString aParseKey;
5172 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5174 TCollection_AsciiString anArg (theArgVec [anArgIt]);
5176 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5179 aParseKey.Remove (1);
5180 aParseKey.UpperCase();
5181 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5185 if (aParseKey.IsEmpty())
5187 std::cout << theArgVec[0] << ": values should be passed with key.\n";
5188 std::cout << "Type help for more information.\n";
5192 aMapOfKeysByValues(aParseKey)->Append (anArg);
5195 // ---------------------------------------------
5196 // Change or print parameters, order plays role
5197 // ---------------------------------------------
5199 // Check arguments for validity
5200 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
5201 for (; aMapIt.More(); aMapIt.Next())
5203 const TCollection_AsciiString& aKey = aMapIt.Key();
5204 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
5206 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5207 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5208 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
5209 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
5210 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
5211 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
5212 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
5214 TCollection_AsciiString aLowerKey;
5217 aLowerKey.LowerCase();
5218 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
5219 std::cout << "Type help for more information.\n";
5224 Handle(TColStd_HSequenceOfAsciiString) aValues;
5226 // Change view parameters in proper order
5227 if (aMapOfKeysByValues.Find ("SCALE", aValues))
5229 if (aValues->IsEmpty())
5231 theDi << "Scale: " << anAISView->Scale() << "\n";
5235 anAISView->SetScale (aValues->Value(1).RealValue());
5238 if (aMapOfKeysByValues.Find ("SIZE", aValues))
5240 if (aValues->IsEmpty())
5242 Standard_Real aSizeX = 0.0;
5243 Standard_Real aSizeY = 0.0;
5244 anAISView->Size (aSizeX, aSizeY);
5245 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
5249 anAISView->SetSize (aValues->Value(1).RealValue());
5252 if (aMapOfKeysByValues.Find ("EYE", aValues))
5254 if (aValues->IsEmpty())
5256 Standard_Real anEyeX = 0.0;
5257 Standard_Real anEyeY = 0.0;
5258 Standard_Real anEyeZ = 0.0;
5259 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
5260 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
5264 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5267 if (aMapOfKeysByValues.Find ("AT", aValues))
5269 if (aValues->IsEmpty())
5271 Standard_Real anAtX = 0.0;
5272 Standard_Real anAtY = 0.0;
5273 Standard_Real anAtZ = 0.0;
5274 anAISView->At (anAtX, anAtY, anAtZ);
5275 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
5279 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5282 if (aMapOfKeysByValues.Find ("PROJ", aValues))
5284 if (aValues->IsEmpty())
5286 Standard_Real aProjX = 0.0;
5287 Standard_Real aProjY = 0.0;
5288 Standard_Real aProjZ = 0.0;
5289 anAISView->Proj (aProjX, aProjY, aProjZ);
5290 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
5294 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5297 if (aMapOfKeysByValues.Find ("UP", aValues))
5299 if (aValues->IsEmpty())
5301 Standard_Real anUpX = 0.0;
5302 Standard_Real anUpY = 0.0;
5303 Standard_Real anUpZ = 0.0;
5304 anAISView->Up (anUpX, anUpY, anUpZ);
5305 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
5309 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5312 if (aMapOfKeysByValues.Find ("CENTER", aValues))
5314 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
5320 //=======================================================================
5321 //function : VChangeSelected
5322 //purpose : Adds the shape to selection or remove one from it
5323 //=======================================================================
5324 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
5325 Standard_Integer argc,
5330 di<<"Usage : " << argv[0] << " shape \n";
5334 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5335 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5336 TCollection_AsciiString aName(argv[1]);
5337 Handle(AIS_InteractiveObject) anAISObject;
5339 if(!aMap.IsBound2(aName))
5341 di<<"Use 'vdisplay' before";
5346 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
5347 if(anAISObject.IsNull()){
5348 di<<"No interactive object \n";
5352 if(aContext->HasOpenedContext())
5354 aContext->AddOrRemoveSelected(anAISObject);
5358 aContext->AddOrRemoveCurrentObject(anAISObject);
5364 //=======================================================================
5365 //function : VZClipping
5366 //purpose : Gets or sets ZClipping mode, width and depth
5367 //=======================================================================
5368 static Standard_Integer VZClipping (Draw_Interpretor& di,
5369 Standard_Integer argc,
5374 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5375 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5378 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5379 if(aContext.IsNull())
5381 di << "use 'vinit' command before " << argv[0] << "\n";
5384 Handle(V3d_View) aView = ViewerTest::CurrentView();
5385 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
5388 TCollection_AsciiString aZClippingModeString;
5389 Quantity_Length aDepth, aWidth;
5390 aZClippingMode = aView->ZClipping(aDepth, aWidth);
5391 switch (aZClippingMode)
5394 aZClippingModeString.Copy("OFF");
5397 aZClippingModeString.Copy("BACK");
5400 aZClippingModeString.Copy("FRONT");
5403 aZClippingModeString.Copy("SLICE");
5406 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
5409 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
5410 << "ZClipping depth = " << aDepth << "\n"
5411 << "ZClipping width = " << aWidth << "\n";
5417 Standard_Integer aStatus = 0;
5418 if ( strcmp (argv [1], "OFF") == 0 ) {
5420 aZClippingMode = V3d_OFF;
5422 if ( strcmp (argv [1], "BACK") == 0 ) {
5424 aZClippingMode = V3d_BACK;
5426 if ( strcmp (argv [1], "FRONT") == 0 ) {
5428 aZClippingMode = V3d_FRONT;
5430 if ( strcmp (argv [1], "SLICE") == 0 ) {
5432 aZClippingMode = V3d_SLICE;
5436 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5437 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5440 aView->SetZClippingType(aZClippingMode);
5444 Quantity_Length aDepth = 0., aWidth = 1.;
5447 aDepth = Draw::Atof (argv[1]);
5448 aWidth = Draw::Atof (argv[2]);
5452 aDepth = Draw::Atof (argv[2]);
5453 aWidth = Draw::Atof (argv[3]);
5456 if(aDepth<0. || aDepth>1.)
5458 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5459 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5462 if(aWidth<0. || aWidth>1.)
5464 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5465 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5469 aView->SetZClippingDepth(aDepth);
5470 aView->SetZClippingWidth(aWidth);
5477 //=======================================================================
5478 //function : VNbSelected
5479 //purpose : Returns number of selected objects
5480 //=======================================================================
5481 static Standard_Integer VNbSelected (Draw_Interpretor& di,
5482 Standard_Integer argc,
5487 di << "Usage : " << argv[0] << "\n";
5490 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5491 if(aContext.IsNull())
5493 di << "use 'vinit' command before " << argv[0] << "\n";
5496 di << aContext->NbSelected() << "\n";
5500 //=======================================================================
5501 //function : VAntialiasing
5502 //purpose : Switches altialiasing on or off
5503 //=======================================================================
5504 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
5505 Standard_Integer argc,
5510 di << "Usage : " << argv[0] << " [1|0]" << "\n";
5514 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5515 if(aContext.IsNull())
5517 di << "use 'vinit' command before " << argv[0] << "\n";
5521 Handle(V3d_View) aView = ViewerTest::CurrentView();
5523 if((argc == 2) && (atof(argv[1]) == 0))
5524 aView->SetAntialiasingOff();
5526 aView->SetAntialiasingOn();
5531 //=======================================================================
5532 //function : VPurgeDisplay
5533 //purpose : Switches altialiasing on or off
5534 //=======================================================================
5535 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
5536 Standard_Integer argc,
5541 di << "Usage : " << argv[0] << "\n";
5544 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5545 if (aContext.IsNull())
5547 di << "use 'vinit' command before " << argv[0] << "\n";
5550 aContext->CloseAllContexts(Standard_False);
5551 di << aContext->PurgeDisplay() << "\n";
5555 //=======================================================================
5556 //function : VSetViewSize
5558 //=======================================================================
5559 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
5560 Standard_Integer argc,
5563 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5564 if(aContext.IsNull())
5566 di << "use 'vinit' command before " << argv[0] << "\n";
5571 di<<"Usage : " << argv[0] << " Size\n";
5574 Standard_Real aSize = Draw::Atof (argv[1]);
5577 di<<"Bad Size value : " << aSize << "\n";
5581 Handle(V3d_View) aView = ViewerTest::CurrentView();
5582 aView->SetSize(aSize);
5586 //=======================================================================
5587 //function : VMoveView
5589 //=======================================================================
5590 static Standard_Integer VMoveView (Draw_Interpretor& di,
5591 Standard_Integer argc,
5594 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5595 if(aContext.IsNull())
5597 di << "use 'vinit' command before " << argv[0] << "\n";
5600 if(argc < 4 || argc > 5)
5602 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
5605 Standard_Real Dx = Draw::Atof (argv[1]);
5606 Standard_Real Dy = Draw::Atof (argv[2]);
5607 Standard_Real Dz = Draw::Atof (argv[3]);
5608 Standard_Boolean aStart = Standard_True;
5611 aStart = (Draw::Atoi (argv[4]) > 0);
5614 Handle(V3d_View) aView = ViewerTest::CurrentView();
5615 aView->Move(Dx,Dy,Dz,aStart);
5619 //=======================================================================
5620 //function : VTranslateView
5622 //=======================================================================
5623 static Standard_Integer VTranslateView (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->Translate(Dx,Dy,Dz,aStart);
5652 //=======================================================================
5653 //function : VTurnView
5655 //=======================================================================
5656 static Standard_Integer VTurnView (Draw_Interpretor& di,
5657 Standard_Integer argc,
5660 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5661 if(aContext.IsNull()) {
5662 di << "use 'vinit' command before " << argv[0] << "\n";
5665 if(argc < 4 || argc > 5){
5666 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
5669 Standard_Real Ax = Draw::Atof (argv[1]);
5670 Standard_Real Ay = Draw::Atof (argv[2]);
5671 Standard_Real Az = Draw::Atof (argv[3]);
5672 Standard_Boolean aStart = Standard_True;
5675 aStart = (Draw::Atoi (argv[4]) > 0);
5678 Handle(V3d_View) aView = ViewerTest::CurrentView();
5679 aView->Turn(Ax,Ay,Az,aStart);
5683 //==============================================================================
5684 //function : VTextureEnv
5685 //purpose : ENables or disables environment mapping
5686 //==============================================================================
5687 class OCC_TextureEnv : public Graphic3d_TextureEnv
5690 OCC_TextureEnv(const Standard_CString FileName);
5691 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
5692 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
5693 const Standard_Boolean theModulateFlag,
5694 const Graphic3d_TypeOfTextureFilter theFilter,
5695 const Standard_ShortReal theXScale,
5696 const Standard_ShortReal theYScale,
5697 const Standard_ShortReal theXShift,
5698 const Standard_ShortReal theYShift,
5699 const Standard_ShortReal theAngle);
5700 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
5702 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
5703 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
5704 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
5706 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
5707 : Graphic3d_TextureEnv(theFileName)
5711 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
5712 : Graphic3d_TextureEnv(theTexId)
5716 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
5717 const Standard_Boolean theModulateFlag,
5718 const Graphic3d_TypeOfTextureFilter theFilter,
5719 const Standard_ShortReal theXScale,
5720 const Standard_ShortReal theYScale,
5721 const Standard_ShortReal theXShift,
5722 const Standard_ShortReal theYShift,
5723 const Standard_ShortReal theAngle)
5725 myParams->SetRepeat (theRepeatFlag);
5726 myParams->SetModulate (theModulateFlag);
5727 myParams->SetFilter (theFilter);
5728 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
5729 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
5730 myParams->SetRotation (theAngle);
5733 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
5735 // get the active view
5736 Handle(V3d_View) aView = ViewerTest::CurrentView();
5739 std::cerr << "No active view. Please call vinit.\n";
5743 // Checking the input arguments
5744 Standard_Boolean anEnableFlag = Standard_False;
5745 Standard_Boolean isOk = theArgNb >= 2;
5748 TCollection_AsciiString anEnableOpt(theArgVec[1]);
5749 anEnableFlag = anEnableOpt.IsEqual("on");
5750 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
5754 isOk = (theArgNb == 3 || theArgNb == 11);
5757 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5758 isOk = (!aTextureOpt.IsIntegerValue() ||
5759 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
5761 if (isOk && theArgNb == 11)
5763 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
5764 aModulateOpt(theArgVec[4]),
5765 aFilterOpt (theArgVec[5]),
5766 aSScaleOpt (theArgVec[6]),
5767 aTScaleOpt (theArgVec[7]),
5768 aSTransOpt (theArgVec[8]),
5769 aTTransOpt (theArgVec[9]),
5770 anAngleOpt (theArgVec[10]);
5771 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
5772 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
5773 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
5774 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
5775 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
5776 anAngleOpt.IsRealValue());
5783 std::cerr << "Usage :" << std::endl;
5784 std::cerr << theArgVec[0] << " off" << std::endl;
5785 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;
5791 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5792 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
5793 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
5794 new OCC_TextureEnv(theArgVec[2]);
5798 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
5799 aTexEnv->SetTextureParameters(
5800 aRepeatOpt. IsEqual("repeat"),
5801 aModulateOpt.IsEqual("modulate"),
5802 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
5803 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
5804 Graphic3d_TOTF_TRILINEAR,
5805 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
5806 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
5807 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
5808 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
5809 (Standard_ShortReal)Draw::Atof(theArgVec[10])
5812 aView->SetTextureEnv(aTexEnv);
5813 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
5815 else // Disabling environment mapping
5817 aView->SetSurfaceDetail(V3d_TEX_NONE);
5818 Handle(Graphic3d_TextureEnv) aTexture;
5819 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
5826 //===============================================================================================
5827 //function : VClipPlane
5829 //===============================================================================================
5830 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5832 // use short-cut for created clip planes map of created (or "registered by name") clip planes
5833 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
5834 static MapOfPlanes aRegPlanes;
5838 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
5842 TCollection_AsciiString aCommand (theArgVec[1]);
5844 // print maximum number of planes for current viewer
5845 if (aCommand == "maxplanes")
5849 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
5853 TCollection_AsciiString aViewName (theArgVec[2]);
5855 if (!ViewerTest_myViews.IsBound1 (aViewName))
5857 theDi << theArgVec[0] << ": view is not found.\n";
5861 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5863 theDi << theArgVec[0] << ": "
5864 << aView->Viewer()->Driver()->InquirePlaneLimit()
5865 << " plane slots provided by driver."
5866 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
5871 // create / delete plane instance
5872 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
5876 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
5880 Standard_Boolean toCreate = (aCommand == "create");
5881 Standard_Boolean toClone = (aCommand == "clone");
5882 TCollection_AsciiString aPlane (theArgVec[2]);
5886 if (aRegPlanes.IsBound (aPlane))
5888 theDi << theArgVec[0] << ": plane name is in use.\n";
5892 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
5894 else if (toClone) // toClone
5896 if (!aRegPlanes.IsBound (aPlane))
5898 theDi << theArgVec[0] << ": no such plane.\n";
5904 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
5908 TCollection_AsciiString aClone (theArgVec[3]);
5909 if (aRegPlanes.IsBound (aClone))
5911 theDi << theArgVec[0] << ": plane name is in use.\n";
5915 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5917 aRegPlanes.Bind (aClone, aClipPlane->Clone());
5921 if (!aRegPlanes.IsBound (aPlane))
5923 theDi << theArgVec[0] << ": no such plane.\n";
5927 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
5928 aRegPlanes.UnBind (aPlane);
5930 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
5931 for (; anIObjIt.More(); anIObjIt.Next())
5933 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
5934 aPrs->RemoveClipPlane(aClipPlane);
5937 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
5938 for (; aViewIt.More(); aViewIt.Next())
5940 const Handle(V3d_View)& aView = aViewIt.Key2();
5941 aView->RemoveClipPlane(aClipPlane);
5944 ViewerTest::RedrawAllViews();
5950 // set / unset plane command
5951 if (aCommand == "set" || aCommand == "unset")
5955 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5959 Standard_Boolean toSet = (aCommand == "set");
5960 TCollection_AsciiString aPlane (theArgVec [2]);
5961 if (!aRegPlanes.IsBound (aPlane))
5963 theDi << theArgVec[0] << ": no such plane.\n";
5967 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5969 TCollection_AsciiString aTarget (theArgVec [3]);
5970 if (aTarget != "object" && aTarget != "view")
5972 theDi << theArgVec[0] << ": invalid target.\n";
5976 if (aTarget == "object" || aTarget == "view")
5980 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5984 Standard_Boolean isObject = (aTarget == "object");
5986 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
5988 TCollection_AsciiString anEntityName (theArgVec[anIt]);
5989 if (isObject) // to object
5991 if (!GetMapOfAIS().IsBound2 (anEntityName))
5993 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
5997 Handle(AIS_InteractiveObject) aIObj =
5998 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
6001 aIObj->AddClipPlane (aClipPlane);
6003 aIObj->RemoveClipPlane (aClipPlane);
6007 if (!ViewerTest_myViews.IsBound1 (anEntityName))
6009 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
6013 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
6015 aView->AddClipPlane (aClipPlane);
6017 aView->RemoveClipPlane (aClipPlane);
6021 ViewerTest::RedrawAllViews();
6027 // change plane command
6028 if (aCommand == "change")
6032 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6036 TCollection_AsciiString aPlane (theArgVec [2]);
6037 if (!aRegPlanes.IsBound (aPlane))
6039 theDi << theArgVec[0] << ": no such plane.\n";
6043 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6045 TCollection_AsciiString aChangeArg (theArgVec [3]);
6046 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
6048 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6052 if (aChangeArg == "on" || aChangeArg == "off") // on / off
6054 aClipPlane->SetOn (aChangeArg == "on");
6056 else if (aChangeArg == "equation") // change equation
6060 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6064 Standard_Real aCoeffA = Draw::Atof (theArgVec [4]);
6065 Standard_Real aCoeffB = Draw::Atof (theArgVec [5]);
6066 Standard_Real aCoeffC = Draw::Atof (theArgVec [6]);
6067 Standard_Real aCoeffD = Draw::Atof (theArgVec [7]);
6068 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6070 else if (aChangeArg == "capping") // change capping aspects
6074 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6078 TCollection_AsciiString aCappingArg (theArgVec [4]);
6079 if (aCappingArg != "on" && aCappingArg != "off" &&
6080 aCappingArg != "color" && aCappingArg != "texname" &&
6081 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
6082 aCappingArg != "texrotate" && aCappingArg != "hatch")
6084 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6088 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
6090 aClipPlane->SetCapping (aCappingArg == "on");
6092 else if (aCappingArg == "color") // color aspect for capping
6096 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6100 Standard_Real aRed = Draw::Atof (theArgVec [5]);
6101 Standard_Real aGrn = Draw::Atof (theArgVec [6]);
6102 Standard_Real aBlu = Draw::Atof (theArgVec [7]);
6104 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
6105 Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB);
6106 aMat.SetAmbientColor (aColor);
6107 aMat.SetDiffuseColor (aColor);
6108 aClipPlane->SetCappingMaterial (aMat);
6110 else if (aCappingArg == "texname") // texture name
6114 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6118 TCollection_AsciiString aTextureName (theArgVec [5]);
6120 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6121 if (!aTexture->IsDone ())
6123 aClipPlane->SetCappingTexture (NULL);
6127 aTexture->EnableModulate();
6128 aTexture->EnableRepeat();
6129 aClipPlane->SetCappingTexture (aTexture);
6132 else if (aCappingArg == "texscale") // texture scale
6134 if (aClipPlane->CappingTexture().IsNull())
6136 theDi << theArgVec[0] << ": no texture is set.\n";
6142 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6146 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
6147 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
6149 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6151 else if (aCappingArg == "texorigin") // texture origin
6153 if (aClipPlane->CappingTexture().IsNull())
6155 theDi << theArgVec[0] << ": no texture is set.\n";
6161 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6165 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
6166 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
6168 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6170 else if (aCappingArg == "texrotate") // texture rotation
6172 if (aClipPlane->CappingTexture().IsNull())
6174 theDi << theArgVec[0] << ": no texture is set.\n";
6180 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6184 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
6186 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6188 else if (aCappingArg == "hatch") // hatch style
6192 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6196 TCollection_AsciiString aHatchStr (theArgVec [5]);
6197 if (aHatchStr == "on")
6199 aClipPlane->SetCappingHatchOn();
6201 else if (aHatchStr == "off")
6203 aClipPlane->SetCappingHatchOff();
6207 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
6212 ViewerTest::RedrawAllViews();
6217 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
6221 //===============================================================================================
6222 //function : VSetTextureMode
6224 //===============================================================================================
6225 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6229 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
6233 TCollection_AsciiString aViewName (theArgVec[1]);
6234 if (!ViewerTest_myViews.IsBound1 (aViewName))
6236 theDi << theArgVec[0] << ": view is not found.\n";
6240 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6241 switch (atoi (theArgVec[2]))
6243 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
6244 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
6245 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
6247 theDi << theArgVec[0] << ": invalid mode.\n";
6255 //===============================================================================================
6256 //function : VZRange
6258 //===============================================================================================
6259 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6261 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6263 if (aCurrentView.IsNull())
6265 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
6269 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
6273 theDi << "ZNear: " << aCamera->ZNear() << "\n";
6274 theDi << "ZFar: " << aCamera->ZFar() << "\n";
6280 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
6281 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
6283 if (aNewZNear >= aNewZFar)
6285 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
6289 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
6291 std::cout << theArgVec[0] << ": invalid arguments: ";
6292 std::cout << "znear, zfar should be positive for perspective camera.\n";
6296 aCamera->SetZRange (aNewZNear, aNewZFar);
6300 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
6304 aCurrentView->Redraw();
6309 //===============================================================================================
6310 //function : VAutoZFit
6312 //===============================================================================================
6313 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6315 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6317 if (aCurrentView.IsNull())
6319 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
6323 Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor();
6327 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
6333 theDi << "Auto z-fit mode: " << "\n"
6334 << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n"
6335 << "Scale: " << aScale << "\n";
6339 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
6343 aScale = Draw::Atoi (theArgVec[2]);
6346 aCurrentView->View()->SetAutoZFitMode (isOn, aScale);
6347 aCurrentView->View()->AutoZFit();
6348 aCurrentView->Redraw();
6353 //! Auxiliary function to print projection type
6354 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
6356 switch (theProjType)
6358 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
6359 case Graphic3d_Camera::Projection_Perspective: return "perspective";
6360 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
6361 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
6362 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
6367 //===============================================================================================
6368 //function : VCamera
6370 //===============================================================================================
6371 static int VCamera (Draw_Interpretor& theDI,
6372 Standard_Integer theArgsNb,
6373 const char** theArgVec)
6375 Handle(V3d_View) aView = ViewerTest::CurrentView();
6378 std::cout << "Error: no active view.\n";
6382 Handle(Graphic3d_Camera) aCamera = aView->Camera();
6385 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
6386 theDI << "FOVy: " << aCamera->FOVy() << "\n";
6387 theDI << "Distance: " << aCamera->Distance() << "\n";
6388 theDI << "IOD: " << aCamera->IOD() << "\n";
6389 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
6390 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
6391 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
6395 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6397 Standard_CString anArg = theArgVec[anArgIter];
6398 TCollection_AsciiString anArgCase (anArg);
6399 anArgCase.LowerCase();
6400 if (anArgCase == "-proj"
6401 || anArgCase == "-projection"
6402 || anArgCase == "-projtype"
6403 || anArgCase == "-projectiontype")
6405 theDI << projTypeName (aCamera->ProjectionType()) << " ";
6407 else if (anArgCase == "-ortho"
6408 || anArgCase == "-orthographic")
6410 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
6412 else if (anArgCase == "-persp"
6413 || anArgCase == "-perspective"
6414 || anArgCase == "-perspmono"
6415 || anArgCase == "-perspectivemono"
6416 || anArgCase == "-mono")
6418 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
6420 else if (anArgCase == "-stereo"
6421 || anArgCase == "-stereoscopic"
6422 || anArgCase == "-perspstereo"
6423 || anArgCase == "-perspectivestereo")
6425 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
6427 else if (anArgCase == "-left"
6428 || anArgCase == "-lefteye"
6429 || anArgCase == "-monoleft"
6430 || anArgCase == "-monolefteye"
6431 || anArgCase == "-perpsleft"
6432 || anArgCase == "-perpslefteye")
6434 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
6436 else if (anArgCase == "-right"
6437 || anArgCase == "-righteye"
6438 || anArgCase == "-monoright"
6439 || anArgCase == "-monorighteye"
6440 || anArgCase == "-perpsright")
6442 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
6444 else if (anArgCase == "-dist"
6445 || anArgCase == "-distance")
6447 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6448 if (anArgValue != NULL
6449 && *anArgValue != '-')
6452 aCamera->SetDistance (Draw::Atof (anArgValue));
6455 theDI << aCamera->Distance() << " ";
6457 else if (anArgCase == "-iod")
6459 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6460 if (anArgValue != NULL
6461 && *anArgValue != '-')
6464 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
6467 theDI << aCamera->IOD() << " ";
6469 else if (anArgCase == "-iodtype")
6471 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
6472 TCollection_AsciiString anValueCase (anArgValue);
6473 anValueCase.LowerCase();
6474 if (anValueCase == "abs"
6475 || anValueCase == "absolute")
6478 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
6481 else if (anValueCase == "rel"
6482 || anValueCase == "relative")
6485 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
6488 else if (*anArgValue != '-')
6490 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
6493 switch (aCamera->GetIODType())
6495 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
6496 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
6499 else if (anArgCase == "-zfocus")
6501 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6502 if (anArgValue != NULL
6503 && *anArgValue != '-')
6506 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
6509 theDI << aCamera->ZFocus() << " ";
6511 else if (anArgCase == "-zfocustype")
6513 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
6514 TCollection_AsciiString anValueCase (anArgValue);
6515 anValueCase.LowerCase();
6516 if (anValueCase == "abs"
6517 || anValueCase == "absolute")
6520 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
6523 else if (anValueCase == "rel"
6524 || anValueCase == "relative")
6527 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
6530 else if (*anArgValue != '-')
6532 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
6535 switch (aCamera->ZFocusType())
6537 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
6538 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
6541 else if (anArgCase == "-fov"
6542 || anArgCase == "-fovy")
6544 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6545 if (anArgValue != NULL
6546 && *anArgValue != '-')
6549 aCamera->SetFOVy (Draw::Atof (anArgValue));
6552 theDI << aCamera->FOVy() << " ";
6556 std::cout << "Error: unknown argument '" << anArg << "'\n";
6561 aView->View()->AutoZFit();
6567 //==============================================================================
6568 //function : VStereo
6570 //==============================================================================
6572 static int VStereo (Draw_Interpretor& theDI,
6573 Standard_Integer theArgNb,
6574 const char** theArgVec)
6578 Handle(V3d_View) aView = ViewerTest::CurrentView();
6581 std::cerr << "No active view. Please call vinit.\n";
6585 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
6586 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
6590 ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0;
6594 //===============================================================================================
6595 //function : VDefaults
6597 //===============================================================================================
6598 static int VDefaults (Draw_Interpretor& theDi,
6599 Standard_Integer theArgsNb,
6600 const char** theArgVec)
6602 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
6605 std::cerr << "No active viewer!\n";
6609 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
6612 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
6614 theDi << "DeflType: relative\n"
6615 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
6619 theDi << "DeflType: absolute\n"
6620 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
6622 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
6626 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6628 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6629 TCollection_AsciiString aKey, aValue;
6630 if (!ViewerTest::SplitParameter (anArg, aKey, aValue)
6631 || aValue.IsEmpty())
6633 std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
6638 if (aKey == "ABSDEFL"
6639 || aKey == "ABSOLUTEDEFLECTION"
6641 || aKey == "DEFLECTION")
6643 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
6644 aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
6646 else if (aKey == "RELDEFL"
6647 || aKey == "RELATIVEDEFLECTION"
6648 || aKey == "DEVCOEFF"
6649 || aKey == "DEVIATIONCOEFF"
6650 || aKey == "DEVIATIONCOEFFICIENT")
6652 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
6653 aDefParams->SetDeviationCoefficient (aValue.RealValue());
6655 else if (aKey == "ANGDEFL"
6656 || aKey == "ANGULARDEFL"
6657 || aKey == "ANGULARDEFLECTION")
6659 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
6660 aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
6664 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
6671 //! Auxiliary method
6672 inline void addLight (const Handle(V3d_Light)& theLightNew,
6673 const Standard_Boolean theIsGlobal)
6675 if (theLightNew.IsNull())
6682 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
6686 ViewerTest::CurrentView()->SetLightOn (theLightNew);
6690 //! Auxiliary method
6691 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
6693 TCollection_AsciiString anArgNextCase (theArgNext);
6694 anArgNextCase.UpperCase();
6695 if (anArgNextCase.Length() > 5
6696 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
6698 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
6702 return theArgNext.IntegerValue();
6706 //===============================================================================================
6709 //===============================================================================================
6710 static int VLight (Draw_Interpretor& theDi,
6711 Standard_Integer theArgsNb,
6712 const char** theArgVec)
6714 Handle(V3d_View) aView = ViewerTest::CurrentView();
6715 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6717 || aViewer.IsNull())
6719 std::cerr << "No active viewer!\n";
6723 Standard_Real anXYZ[3];
6724 Quantity_Coefficient anAtten[2];
6727 // print lights info
6728 Standard_Integer aLightId = 0;
6729 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
6731 Handle(V3d_Light) aLight = aView->ActiveLight();
6732 const Quantity_Color aColor = aLight->Color();
6733 theDi << "Light" << aLightId << "\n";
6734 switch (aLight->Type())
6738 theDi << " Type: Ambient\n";
6741 case V3d_DIRECTIONAL:
6743 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
6744 theDi << " Type: Directional\n";
6745 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
6746 if (!aLightDir.IsNull())
6748 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6749 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6750 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
6751 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6755 case V3d_POSITIONAL:
6757 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
6758 theDi << " Type: Positional\n";
6759 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
6760 if (!aLightPos.IsNull())
6762 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6763 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6764 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6765 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
6771 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
6772 theDi << " Type: Spot\n";
6773 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
6774 if (!aLightSpot.IsNull())
6776 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6777 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6778 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
6779 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6780 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6781 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
6782 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
6783 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
6789 theDi << " Type: UNKNOWN\n";
6793 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
6797 Handle(V3d_Light) aLightNew;
6798 Handle(V3d_Light) aLightOld;
6799 Standard_Boolean isGlobal = Standard_True;
6800 Standard_Boolean toCreate = Standard_False;
6801 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
6803 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
6804 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
6805 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
6806 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
6807 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
6809 TCollection_AsciiString aName, aValue;
6810 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
6811 TCollection_AsciiString anArgCase (anArg);
6812 anArgCase.UpperCase();
6813 if (anArgCase.IsEqual ("NEW")
6814 || anArgCase.IsEqual ("ADD")
6815 || anArgCase.IsEqual ("CREATE"))
6817 toCreate = Standard_True;
6819 else if (anArgCase.IsEqual ("GLOB")
6820 || anArgCase.IsEqual ("GLOBAL"))
6822 isGlobal = Standard_True;
6824 else if (anArgCase.IsEqual ("LOC")
6825 || anArgCase.IsEqual ("LOCAL"))
6827 isGlobal = Standard_False;
6829 else if (anArgCase.IsEqual ("DEF")
6830 || anArgCase.IsEqual ("DEFAULTS"))
6832 toCreate = Standard_False;
6833 aViewer->SetDefaultLights();
6835 else if (anArgCase.IsEqual ("CLR")
6836 || anArgCase.IsEqual ("CLEAR"))
6838 toCreate = Standard_False;
6839 aView->InitActiveLights();
6840 while (aView->MoreActiveLights())
6842 aViewer->DelLight (aView->ActiveLight());
6843 aView->InitActiveLights();
6846 else if (anArgCase.IsEqual ("AMB")
6847 || anArgCase.IsEqual ("AMBIENT")
6848 || anArgCase.IsEqual ("AMBLIGHT"))
6850 addLight (aLightNew, isGlobal);
6853 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6856 toCreate = Standard_False;
6857 aLightNew = new V3d_AmbientLight (aViewer);
6859 else if (anArgCase.IsEqual ("DIRECTIONAL")
6860 || anArgCase.IsEqual ("DIRLIGHT"))
6862 addLight (aLightNew, isGlobal);
6865 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6868 toCreate = Standard_False;
6869 aLightNew = new V3d_DirectionalLight (aViewer);
6871 else if (anArgCase.IsEqual ("SPOT")
6872 || anArgCase.IsEqual ("SPOTLIGHT"))
6874 addLight (aLightNew, isGlobal);
6877 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6880 toCreate = Standard_False;
6881 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
6883 else if (anArgCase.IsEqual ("POSLIGHT")
6884 || anArgCase.IsEqual ("POSITIONAL"))
6886 addLight (aLightNew, isGlobal);
6889 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6892 toCreate = Standard_False;
6893 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
6895 else if (anArgCase.IsEqual ("CHANGE"))
6897 addLight (aLightNew, isGlobal);
6898 aLightNew.Nullify();
6899 if (++anArgIt >= theArgsNb)
6901 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6905 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
6906 Standard_Integer aLightIt = 0;
6907 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6909 if (aLightIt == aLightId)
6911 aLightOld = aView->ActiveLight();
6916 if (aLightOld.IsNull())
6918 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
6922 else if (anArgCase.IsEqual ("DEL")
6923 || anArgCase.IsEqual ("DELETE"))
6925 Handle(V3d_Light) aLightDel;
6926 if (++anArgIt >= theArgsNb)
6928 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6932 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6933 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
6934 Standard_Integer aLightIt = 0;
6935 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6937 aLightDel = aView->ActiveLight();
6938 if (aLightIt == aLightDelId)
6943 if (!aLightDel.IsNull())
6945 aViewer->DelLight (aLightDel);
6948 else if (anArgCase.IsEqual ("COLOR")
6949 || anArgCase.IsEqual ("COLOUR"))
6951 if (++anArgIt >= theArgsNb)
6953 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6957 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6958 anArgNext.UpperCase();
6959 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
6960 if (!aLightCurr.IsNull())
6962 aLightCurr->SetColor (aColor);
6965 else if (anArgCase.IsEqual ("POS")
6966 || anArgCase.IsEqual ("POSITION"))
6968 if ((anArgIt + 3) >= theArgsNb)
6970 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6974 anXYZ[0] = Atof (theArgVec[++anArgIt]);
6975 anXYZ[1] = Atof (theArgVec[++anArgIt]);
6976 anXYZ[2] = Atof (theArgVec[++anArgIt]);
6977 if (!aLightDir.IsNull())
6979 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6981 else if (!aLightPos.IsNull())
6983 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6985 else if (!aLightSpot.IsNull())
6987 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6991 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6995 else if (anArgCase.IsEqual ("DIR")
6996 || anArgCase.IsEqual ("DIRECTION"))
6998 if ((anArgIt + 3) >= theArgsNb)
7000 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7004 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7005 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7006 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7007 if (!aLightDir.IsNull())
7009 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7011 else if (!aLightSpot.IsNull())
7013 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7017 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7021 else if (anArgCase.IsEqual ("ANG")
7022 || anArgCase.IsEqual ("ANGLE"))
7024 if (++anArgIt >= theArgsNb)
7026 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7030 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
7032 if (!aLightSpot.IsNull())
7034 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
7037 else if (anArgCase.IsEqual ("CONSTATTEN")
7038 || anArgCase.IsEqual ("CONSTATTENUATION"))
7040 if (++anArgIt >= theArgsNb)
7042 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7046 if (!aLightPos.IsNull())
7048 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7049 anAtten[0] = Atof (theArgVec[anArgIt]);
7050 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
7052 else if (!aLightSpot.IsNull())
7054 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7055 anAtten[0] = Atof (theArgVec[anArgIt]);
7056 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
7060 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7064 else if (anArgCase.IsEqual ("LINATTEN")
7065 || anArgCase.IsEqual ("LINEARATTEN")
7066 || anArgCase.IsEqual ("LINEARATTENUATION"))
7068 if (++anArgIt >= theArgsNb)
7070 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7074 if (!aLightPos.IsNull())
7076 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7077 anAtten[1] = Atof (theArgVec[anArgIt]);
7078 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
7080 else if (!aLightSpot.IsNull())
7082 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7083 anAtten[1] = Atof (theArgVec[anArgIt]);
7084 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
7088 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7092 else if (anArgCase.IsEqual ("EXP")
7093 || anArgCase.IsEqual ("EXPONENT")
7094 || anArgCase.IsEqual ("SPOTEXP")
7095 || anArgCase.IsEqual ("SPOTEXPONENT"))
7097 if (++anArgIt >= theArgsNb)
7099 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7103 if (!aLightSpot.IsNull())
7105 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
7109 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7113 else if (anArgCase.IsEqual ("HEAD")
7114 || anArgCase.IsEqual ("HEADLIGHT"))
7116 if (++anArgIt >= theArgsNb)
7118 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7122 if (aLightAmb.IsNull()
7123 && !aLightCurr.IsNull())
7125 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
7129 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7135 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
7139 addLight (aLightNew, isGlobal);
7140 aViewer->UpdateLights();
7145 //=======================================================================
7146 //function : VRenderParams
7147 //purpose : Enables/disables rendering features
7148 //=======================================================================
7150 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
7151 Standard_Integer theArgNb,
7152 const char** theArgVec)
7154 Handle(V3d_View) aView = ViewerTest::CurrentView();
7157 std::cerr << "Error: no active viewer!\n";
7161 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
7162 TCollection_AsciiString aCmdName (theArgVec[0]);
7163 aCmdName.LowerCase();
7164 if (aCmdName == "vraytrace")
7168 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
7171 else if (theArgNb == 2)
7173 TCollection_AsciiString aValue (theArgVec[1]);
7178 aParams.Method = Graphic3d_RM_RAYTRACING;
7182 else if (aValue == "off"
7185 aParams.Method = Graphic3d_RM_RASTERIZATION;
7191 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
7197 std::cout << "Error: wrong number of arguments\n";
7204 theDI << "renderMode: ";
7205 switch (aParams.Method)
7207 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
7208 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
7211 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
7212 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
7213 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
7214 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
7215 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
7216 theDI << "shadingModel: ";
7217 switch (aView->ShadingModel())
7219 case V3d_COLOR: theDI << "color"; break;
7220 case V3d_FLAT: theDI << "flat"; break;
7221 case V3d_GOURAUD: theDI << "gouraud"; break;
7222 case V3d_PHONG: theDI << "phong"; break;
7228 Standard_Boolean toPrint = Standard_False;
7229 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7230 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7232 Standard_CString anArg (theArgVec[anArgIter]);
7233 TCollection_AsciiString aFlag (anArg);
7235 if (anUpdateTool.parseRedrawMode (aFlag))
7239 else if (aFlag == "-echo"
7240 || aFlag == "-print")
7242 toPrint = Standard_True;
7243 anUpdateTool.Invalidate();
7245 else if (aFlag == "-mode"
7246 || aFlag == "-rendermode"
7247 || aFlag == "-render_mode")
7251 switch (aParams.Method)
7253 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
7254 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
7260 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7264 else if (aFlag == "-ray"
7265 || aFlag == "-raytrace")
7269 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
7273 aParams.Method = Graphic3d_RM_RAYTRACING;
7275 else if (aFlag == "-rast"
7276 || aFlag == "-raster"
7277 || aFlag == "-rasterization")
7281 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
7285 aParams.Method = Graphic3d_RM_RASTERIZATION;
7287 else if (aFlag == "-raydepth"
7288 || aFlag == "-ray_depth")
7292 theDI << aParams.RaytracingDepth << " ";
7295 else if (++anArgIter >= theArgNb)
7297 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7301 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
7302 if (aDepth < 1 || aDepth > 10)
7304 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
7309 aParams.RaytracingDepth = aDepth;
7312 else if (aFlag == "-shad"
7313 || aFlag == "-shadows")
7317 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
7321 Standard_Boolean toEnable = Standard_True;
7322 if (++anArgIter < theArgNb
7323 && !parseOnOff (theArgVec[anArgIter], toEnable))
7327 aParams.IsShadowEnabled = toEnable;
7329 else if (aFlag == "-refl"
7330 || aFlag == "-reflections")
7334 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
7338 Standard_Boolean toEnable = Standard_True;
7339 if (++anArgIter < theArgNb
7340 && !parseOnOff (theArgVec[anArgIter], toEnable))
7344 aParams.IsReflectionEnabled = toEnable;
7346 else if (aFlag == "-fsaa")
7350 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
7354 Standard_Boolean toEnable = Standard_True;
7355 if (++anArgIter < theArgNb
7356 && !parseOnOff (theArgVec[anArgIter], toEnable))
7360 aParams.IsAntialiasingEnabled = toEnable;
7362 else if (aFlag == "-gleam")
7366 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
7370 Standard_Boolean toEnable = Standard_True;
7371 if (++anArgIter < theArgNb
7372 && !parseOnOff (theArgVec[anArgIter], toEnable))
7376 aParams.IsTransparentShadowEnabled = toEnable;
7378 else if (aFlag == "-shademodel"
7379 || aFlag == "-shadingmodel"
7380 || aFlag == "-shading")
7384 switch (aView->ShadingModel())
7386 case V3d_COLOR: theDI << "color "; break;
7387 case V3d_FLAT: theDI << "flat "; break;
7388 case V3d_GOURAUD: theDI << "gouraud "; break;
7389 case V3d_PHONG: theDI << "phong "; break;
7394 if (++anArgIter >= theArgNb)
7396 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7399 TCollection_AsciiString aMode (theArgVec[anArgIter]);
7401 if (aMode == "color"
7404 aView->SetShadingModel (V3d_COLOR);
7406 else if (aMode == "flat"
7407 || aMode == "facet")
7409 aView->SetShadingModel (V3d_FLAT);
7411 else if (aMode == "gouraud"
7412 || aMode == "vertex"
7415 aView->SetShadingModel (V3d_GOURAUD);
7417 else if (aMode == "phong"
7418 || aMode == "fragment"
7420 || aMode == "pixel")
7422 aView->SetShadingModel (V3d_PHONG);
7426 std::cout << "Error: unknown shading model '" << aMode << "'\n";
7432 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
7439 //=======================================================================
7440 //function : VFrustumCulling
7441 //purpose : enables/disables view volume's culling.
7442 //=======================================================================
7443 static int VFrustumCulling (Draw_Interpretor& theDI,
7444 Standard_Integer theArgNb,
7445 const char** theArgVec)
7447 Handle(V3d_View) aView = ViewerTest::CurrentView();
7450 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
7456 theDI << (aView->IsCullingEnabled() ? "on" : "off");
7459 else if (theArgNb != 2)
7461 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
7465 TCollection_AsciiString aModeStr (theArgVec[1]);
7466 aModeStr.LowerCase();
7467 Standard_Boolean toEnable = 0;
7468 if (aModeStr == "on")
7472 else if (aModeStr == "off")
7478 toEnable = Draw::Atoi (theArgVec[1]) != 0;
7481 aView->SetFrustumCulling (toEnable);
7486 //=======================================================================
7487 //function : VHighlightSelected
7489 //=======================================================================
7490 static int VHighlightSelected (Draw_Interpretor& theDI,
7491 Standard_Integer theArgNb,
7492 const char** theArgVec)
7494 if (ViewerTest::GetAISContext().IsNull())
7496 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
7500 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7504 theDI << (aContext->ToHilightSelected() ? "on" : "off");
7510 std::cout << theArgVec[0] << " error : wrong number of parameters."
7511 << "Type 'help" << theArgVec[0] << "' for more information.";
7516 TCollection_AsciiString aMode (theArgVec[1]);
7518 Standard_Boolean toEnable = Standard_False;
7519 if (aMode.IsEqual ("on"))
7521 toEnable = Standard_True;
7523 else if (aMode.IsEqual ("off"))
7525 toEnable = Standard_False;
7529 toEnable = Draw::Atoi (theArgVec[1]) != 0;
7532 if (toEnable != aContext->ToHilightSelected())
7534 aContext->SetToHilightSelected (toEnable);
7536 // Move cursor to null position and back to process updating of detection
7537 // and highlighting of selected object immediatly.
7538 Standard_Integer aPixX = 0;
7539 Standard_Integer aPixY = 0;
7540 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
7542 anEventManager->GetCurrentPosition (aPixX, aPixY);
7543 anEventManager->MoveTo (0, 0);
7544 anEventManager->MoveTo (aPixX, aPixY);
7550 //=======================================================================
7551 //function : VXRotate
7553 //=======================================================================
7554 static Standard_Integer VXRotate (Draw_Interpretor& di,
7555 Standard_Integer argc,
7558 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7559 if (aContext.IsNull())
7561 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
7567 di << "ERROR : Usage : " << argv[0] << " name angle" << "\n";
7571 TCollection_AsciiString aName (argv[1]);
7572 Standard_Real anAngle = Draw::Atof (argv[2]);
7575 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
7576 Handle(AIS_InteractiveObject) anIObj;
7577 if (!aMap.IsBound2 (aName) )
7579 di << "Use 'vdisplay' before" << "\n";
7584 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
7587 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
7588 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
7590 aContext->SetLocation (anIObj, aTransform);
7591 aContext->UpdateCurrentViewer();
7597 //=======================================================================
7598 //function : ViewerCommands
7600 //=======================================================================
7602 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
7605 const char *group = "ZeViewer";
7606 theCommands.Add("vinit",
7607 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7608 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
7610 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
7612 " - Creates new View window with specified name view_name.\n"
7613 "By default the new view is created in the viewer and in"
7614 " graphic driver shared with active view.\n"
7615 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
7616 "If driverName isn't specified the driver will be shared with active view.\n"
7617 "If viewerName isn't specified the viewer will be shared with active view.\n"
7618 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7619 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
7620 "is used in creation of graphic driver\n"
7622 " - l, t: pixel position of left top corner of the window\n"
7623 " - w,h: width and heigth of window respectively.\n"
7624 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
7625 __FILE__,VInit,group);
7626 theCommands.Add("vclose" ,
7627 "[view_id [keep_context=0|1]]\n"
7628 "or vclose ALL - to remove all created views\n"
7629 " - removes view(viewer window) defined by its view_id.\n"
7630 " - keep_context: by default 0; if 1 and the last view is deleted"
7631 " the current context is not removed.",
7632 __FILE__,VClose,group);
7633 theCommands.Add("vactivate" ,
7635 " - activates view(viewer window) defined by its view_id",
7636 __FILE__,VActivate,group);
7637 theCommands.Add("vviewlist",
7638 "vviewlist [format={tree, long}]"
7639 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
7640 " - format: format of result output, if tree the output is a tree view;"
7641 "otherwise it's a list of full view names. By default format = tree",
7642 __FILE__,VViewList,group);
7643 theCommands.Add("vhelp" ,
7644 "vhelp : display help on the viewer commands",
7645 __FILE__,VHelp,group);
7646 theCommands.Add("vtop" ,
7647 "vtop or <T> : Top view" ,
7648 __FILE__,VTop,group);
7649 theCommands.Add("vbottom" ,
7650 "vbottom : Bottom view" ,
7651 __FILE__,VBottom,group);
7652 theCommands.Add("vleft" ,
7653 "vleft : Left view" ,
7654 __FILE__,VLeft,group);
7655 theCommands.Add("vright" ,
7656 "vright : Right view" ,
7657 __FILE__,VRight,group);
7658 theCommands.Add("vaxo" ,
7659 " vaxo or <A> : Axonometric view ",
7660 __FILE__,VAxo,group);
7661 theCommands.Add("vfront" ,
7662 "vfront : Front view" ,
7663 __FILE__,VFront,group);
7664 theCommands.Add("vback" ,
7665 "vback : Back view" ,
7666 __FILE__,VBack,group);
7667 theCommands.Add("vpick" ,
7668 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
7670 theCommands.Add("vfit" ,
7671 "vfit or <F> : vfit",
7672 __FILE__,VFit,group);
7673 theCommands.Add ("vfitarea",
7674 "vfitarea x1 y1 x2 y2"
7675 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
7676 "\n\t\t: Fit view to show area located between two points"
7677 "\n\t\t: given in world 2D or 3D corrdinates.",
7678 __FILE__, VFitArea, group);
7679 theCommands.Add ("vzfit", "vzfit [scale]\n"
7680 " Matches Z near, Z far view volume planes to the displayed objects.\n"
7681 " \"scale\" - specifies factor to scale computed z range.\n",
7682 __FILE__, VZFit, group);
7683 theCommands.Add("vrepaint",
7684 "vrepaint : vrepaint, force redraw",
7685 __FILE__,VRepaint,group);
7686 theCommands.Add("vclear",
7688 __FILE__,VClear,group);
7689 theCommands.Add("vsetbg",
7690 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
7691 __FILE__,VSetBg,group);
7692 theCommands.Add("vsetbgmode",
7693 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
7694 __FILE__,VSetBgMode,group);
7695 theCommands.Add("vsetgradientbg",
7696 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
7697 __FILE__,VSetGradientBg,group);
7698 theCommands.Add("vsetgrbgmode",
7699 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
7700 __FILE__,VSetGradientBgMode,group);
7701 theCommands.Add("vsetcolorbg",
7702 "vsetcolorbg : vsetcolorbg r g b : Set background color",
7703 __FILE__,VSetColorBg,group);
7704 theCommands.Add("vscale",
7705 "vscale : vscale X Y Z",
7706 __FILE__,VScale,group);
7707 theCommands.Add("vzbufftrihedron",
7708 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
7709 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
7710 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
7711 __FILE__,VTestZBuffTrihedron,group);
7712 theCommands.Add("vrotate",
7713 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
7714 "\n : Option -mouseStart starts rotation according to the mouse position"
7715 "\n : Option -mouseMove continues rotation with angle computed"
7716 "\n : from last and new mouse position."
7717 "\n : vrotate AX AY AZ [X Y Z]",
7718 __FILE__,VRotate,group);
7719 theCommands.Add("vzoom",
7720 "vzoom : vzoom coef",
7721 __FILE__,VZoom,group);
7722 theCommands.Add("vpan",
7723 "vpan : vpan dx dy",
7724 __FILE__,VPan,group);
7725 theCommands.Add("vexport",
7726 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
7727 " : exports the view to a vector file of a given format"
7728 " : notice that EMF format requires patched gl2ps",
7729 __FILE__,VExport,group);
7730 theCommands.Add("vcolorscale",
7731 "vcolorscale : vcolorscale [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
7732 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
7733 "-demo/-demoversion draw a demoversion of color scale.\n"
7734 "-show/display display color scale.\n"
7735 "-hide/erase erase color scale.\n"
7736 "Please note that -show/-hide option must be the first argument!\n"
7737 "-color Index R G B: set color for indexed interval\n"
7738 "-color Index ColorName: set color for indexed interval\n"
7739 "-colors R G B R G B ...: set colors for all intervals\n"
7740 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
7741 "-colors supports both color names and rgb values in one call\n"
7742 "-label Index Text: set label for indexed interval\n"
7743 "-labels Text Text Text ...: set labels for all intervals\n"
7744 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
7745 "Available text positions: left, right, center, none;\n",
7746 __FILE__,VColorScale,group);
7747 theCommands.Add("vgraduatedtrihedron",
7748 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
7749 __FILE__,VGraduatedTrihedron,group);
7750 theCommands.Add("vprintview" ,
7751 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
7752 __FILE__,VPrintView,group);
7753 theCommands.Add("vzlayer",
7754 "vzlayer add/del/get/settings/enable/disable [id]\n"
7755 " add - add new z layer to viewer and print its id\n"
7756 " del - del z layer by its id\n"
7757 " get - print sequence of z layers in increasing order of their overlay level\n"
7758 " settings - print status of z layer settings\n"
7759 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
7760 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
7761 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
7762 "\nWhere id is the layer identificator\n"
7765 " vzlayer enable poffset 1\n"
7766 " vzlayer disable depthtest 1\n"
7768 __FILE__,VZLayer,group);
7769 theCommands.Add("voverlaytext",
7770 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
7771 " : height - pixel height of the text (default=10.0)"
7772 " : font_name - name of font (default=courier)"
7773 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
7774 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
7775 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
7776 __FILE__,VOverlayText,group);
7777 theCommands.Add("vlayerline",
7778 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
7779 __FILE__,VLayerLine,group);
7780 theCommands.Add ("vgrid",
7781 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
7782 " : Mode - rectangular or circular"
7783 " : Type - lines or points",
7784 __FILE__, VGrid, group);
7785 theCommands.Add ("vfps",
7786 "vfps [framesNb=100] : estimate average frame rate for active view",
7787 __FILE__, VFps, group);
7788 theCommands.Add ("vgldebug",
7789 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
7790 " : this function is implemented only for Windows\n"
7791 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
7792 __FILE__, VGlDebug, group);
7793 theCommands.Add ("vvbo",
7794 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
7795 __FILE__, VVbo, group);
7796 theCommands.Add ("vstereo",
7797 "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects",
7798 __FILE__, VStereo, group);
7799 theCommands.Add ("vcaps",
7800 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
7801 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
7802 "\n\t\t: Modify particular graphic driver options:"
7803 "\n\t\t: FFP - use fixed-function pipeline instead of"
7804 "\n\t\t: built-in GLSL programs"
7805 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
7806 "\n\t\t: arrays to GPU memory)"
7807 "\n\t\t: sprite - use textured sprites instead of bitmaps"
7808 "\n\t\t: softMode - use software OpenGL implementation,"
7809 "\n\t\t: should be set BEFORE viewer creation"
7810 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
7811 "\n\t\t: rendering paths producing the same visual result when"
7813 "\n\t\t: Command is intended for testing old hardware compatibility.",
7814 __FILE__, VCaps, group);
7815 theCommands.Add ("vmemgpu",
7816 "vmemgpu [f]: print system-dependent GPU memory information if available;"
7817 " with f option returns free memory in bytes",
7818 __FILE__, VMemGpu, group);
7819 theCommands.Add ("vreadpixel",
7820 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
7821 " : Read pixel value for active view",
7822 __FILE__, VReadPixel, group);
7823 theCommands.Add("diffimage",
7824 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
7825 __FILE__, VDiffImage, group);
7826 theCommands.Add ("vselect",
7827 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
7828 "- emulates different types of selection:\n"
7829 "- 1) single click selection\n"
7830 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
7831 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
7832 "- 4) any of these selections with shift button pressed",
7833 __FILE__, VSelect, group);
7834 theCommands.Add ("vmoveto",
7836 "- emulates cursor movement to pixel postion (x,y)",
7837 __FILE__, VMoveTo, group);
7838 theCommands.Add ("vviewparams", "vviewparams usage:\n"
7840 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
7841 " [-proj [x y z]] [-center x y] [-size sx]\n"
7842 "- Gets or sets current view parameters.\n"
7843 "- If called without arguments, all view parameters are printed.\n"
7844 "- The options are:\n"
7845 " -scale [s] : prints or sets viewport relative scale.\n"
7846 " -eye [x y z] : prints or sets eye location.\n"
7847 " -at [x y z] : prints or sets center of look.\n"
7848 " -up [x y z] : prints or sets direction of up vector.\n"
7849 " -proj [x y z] : prints or sets direction of look.\n"
7850 " -center x y : sets location of center of the screen in pixels.\n"
7851 " -size [sx] : prints viewport projection width and height sizes\n"
7852 " : or changes the size of its maximum dimension.\n",
7853 __FILE__, VViewParams, group);
7854 theCommands.Add("vchangeselected",
7855 "vchangeselected shape"
7856 "- adds to shape to selection or remove one from it",
7857 __FILE__, VChangeSelected, group);
7858 theCommands.Add("vzclipping",
7859 "vzclipping [mode] [depth width]\n"
7860 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
7861 "- gets or sets ZClipping mode, width and depth",
7862 __FILE__,VZClipping,group);
7863 theCommands.Add ("vnbselected",
7864 "vnbselected", __FILE__, VNbSelected, group);
7865 theCommands.Add ("vcamera",
7866 "vcamera [-ortho] [-projtype]"
7868 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
7869 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
7870 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
7871 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
7872 "\n\t\t: Manage camera parameters."
7873 "\n\t\t: Prints current value when option called without argument."
7874 "\n\t\t: Orthographic camera:"
7875 "\n\t\t: -ortho activate orthographic projection"
7876 "\n\t\t: Perspective camera:"
7877 "\n\t\t: -persp activate perspective projection (mono)"
7878 "\n\t\t: -fovy field of view in y axis, in degrees"
7879 "\n\t\t: -distance distance of eye from camera center"
7880 "\n\t\t: Stereoscopic camera:"
7881 "\n\t\t: -stereo perspective projection (stereo)"
7882 "\n\t\t: -leftEye perspective projection (left eye)"
7883 "\n\t\t: -rightEye perspective projection (right eye)"
7884 "\n\t\t: -iod intraocular distance value"
7885 "\n\t\t: -iodType distance type, absolute or relative"
7886 "\n\t\t: -zfocus stereographic focus value"
7887 "\n\t\t: -zfocusType focus type, absolute or relative",
7888 __FILE__, VCamera, group);
7889 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
7890 "- vautozfit [on={1|0}] [scale]\n"
7891 " Prints or changes parameters of automatic z-fit mode:\n"
7892 " \"on\" - turns automatic z-fit on or off\n"
7893 " \"scale\" - specifies factor to scale computed z range.\n",
7894 __FILE__, VAutoZFit, group);
7895 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
7896 " vzrange - without parameters shows current values\n"
7897 " vzrange [znear] [zfar] - applies provided values to view",
7898 __FILE__,VZRange, group);
7899 theCommands.Add("vantialiasing",
7900 "vantialiasing 1|0",
7901 __FILE__,VAntialiasing,group);
7902 theCommands.Add ("vpurgedisplay",
7904 "- removes structures which don't belong to objects displayed in neutral point",
7905 __FILE__, VPurgeDisplay, group);
7906 theCommands.Add("vsetviewsize",
7907 "vsetviewsize size",
7908 __FILE__,VSetViewSize,group);
7909 theCommands.Add("vmoveview",
7910 "vmoveview Dx Dy Dz [Start = 1|0]",
7911 __FILE__,VMoveView,group);
7912 theCommands.Add("vtranslateview",
7913 "vtranslateview Dx Dy Dz [Start = 1|0)]",
7914 __FILE__,VTranslateView,group);
7915 theCommands.Add("vturnview",
7916 "vturnview Ax Ay Az [Start = 1|0]",
7917 __FILE__,VTurnView,group);
7918 theCommands.Add("vtextureenv",
7919 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
7920 "or user-defined file and optionally applying texture mapping parameters\n"
7922 " vtextureenv off - disables environment mapping\n"
7923 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
7924 " std_texture = (0..7)\n"
7925 " rep = {clamp|repeat}\n"
7926 " mod = {decal|modulate}\n"
7927 " flt = {nearest|bilinear|trilinear}\n"
7928 " ss, st - scale factors for s and t texture coordinates\n"
7929 " ts, tt - translation for s and t texture coordinates\n"
7930 " rot - texture rotation angle in degrees",
7931 __FILE__, VTextureEnv, group);
7932 theCommands.Add("vhlr" ,
7933 "is_enabled={on|off} [show_hidden={1|0}]"
7934 " - Hidden line removal algorithm:"
7935 " - is_enabled: if is on HLR algorithm is applied\n"
7936 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
7937 __FILE__,VHLR,group);
7938 theCommands.Add("vhlrtype" ,
7939 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
7940 " - Changes the type of HLR algorithm using for shapes."
7941 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
7942 " if equals to polyalgo, polygonal HLR algorithm is applied."
7943 "If shapes are not given HLR algoithm of given type is applied"
7944 " to all shapes in the view\n",
7945 __FILE__,VHLRType,group);
7946 theCommands.Add("vclipplane", "vclipplane usage: \n"
7947 " maxplanes <view_name> - get plane limit for view.\n"
7948 " create <plane_name> - create new plane.\n"
7949 " delete <plane_name> - delete plane.\n"
7950 " clone <source_plane> <plane_name> - clone the plane definition.\n"
7951 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
7952 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
7953 " change <plane_name> on/off - turn clipping on/off.\n"
7954 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
7955 " change <plane_name> capping on/off - turn capping on/off.\n"
7956 " change <plane_name> capping color <r> <g> <b> - set color.\n"
7957 " change <plane name> capping texname <texture> - set texture.\n"
7958 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
7959 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
7960 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
7961 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
7962 " please use VSetTextureMode command to enable texture rendering in view.\n"
7963 , __FILE__, VClipPlane, group);
7964 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
7966 " 0 - no textures enabled in view.\n"
7967 " 1 - only environment textures enabled.\n"
7968 " 2 - all textures enabled.\n"
7969 " this command sets texture details mode for the specified view.\n"
7970 , __FILE__, VSetTextureMode, group);
7971 theCommands.Add("vdefaults",
7972 "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
7973 __FILE__, VDefaults, group);
7974 theCommands.Add("vlight",
7975 "tool to manage light sources, without arguments shows list of lights."
7976 "\n Main commands: "
7977 "\n 'clear' to clear lights"
7978 "\n '{def}aults' to load deafault lights"
7979 "\n 'add' (or 'new') <type> to add any light source"
7980 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
7981 "\n 'change' <lightId> to edit light source with specified lightId"
7982 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
7983 "\n {pos}ition X Y Z"
7984 "\n {dir}ection X Y Z (for directional light or for spotlight)"
7985 "\n color colorName"
7986 "\n {head}light 0|1"
7987 "\n {constAtten}uation value"
7988 "\n {linearAtten}uation value"
7990 "\n {spotexp}onent value"
7992 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
7993 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
7994 __FILE__, VLight, group);
7995 theCommands.Add("vraytrace",
7997 "\n\t\t: Turn on/off raytracing renderer."
7998 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
7999 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
8000 __FILE__, VRenderParams, group);
8001 theCommands.Add("vrenderparams",
8002 "\n Manages rendering parameters: "
8003 "\n '-rayTrace' Enables GPU ray-tracing"
8004 "\n '-raster' Disables GPU ray-tracing"
8005 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
8006 "\n '-shadows on|off' Enables/disables shadows rendering"
8007 "\n '-reflections on|off' Enables/disables specular reflections"
8008 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
8009 "\n '-gleam on|off' Enables/disables transparency shadow effects"
8010 "\n '-shadingModel model' Controls shading model from enumeration"
8011 "\n color, flat, gouraud, phong"
8012 "\n Unlike vcaps, these parameters dramatically change visual properties."
8013 "\n Command is intended to control presentation quality depending on"
8014 "\n hardware capabilities and performance.",
8015 __FILE__, VRenderParams, group);
8016 theCommands.Add("vfrustumculling",
8017 "vfrustumculling [toEnable]: enables/disables objects clipping",
8018 __FILE__,VFrustumCulling,group);
8019 theCommands.Add("vhighlightselected",
8020 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
8021 "Without arguments it shows if highlighting of selected objects is enabled now.",
8022 __FILE__,VHighlightSelected,group);
8023 theCommands.Add ("vplace",
8025 "\n\t\t: Places the point (in pixels) at the center of the window",
8026 __FILE__, VPlace, group);
8027 theCommands.Add("vxrotate",
8029 __FILE__,VXRotate,group);