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.
21 #include <OpenGl_GlCore20.hxx>
22 #include <AIS_Shape.hxx>
23 #include <AIS_Drawer.hxx>
24 #include <AIS_InteractiveObject.hxx>
25 #include <AIS_ListOfInteractive.hxx>
26 #include <AIS_ListIteratorOfListOfInteractive.hxx>
28 #include <Graphic3d_AspectMarker3d.hxx>
29 #include <Graphic3d_ExportFormat.hxx>
30 #include <Graphic3d_NameOfTextureEnv.hxx>
31 #include <Graphic3d_TextureEnv.hxx>
32 #include <Graphic3d_TextureParams.hxx>
33 #include <Graphic3d_TypeOfTextureFilter.hxx>
34 #include <Graphic3d_AspectFillArea3d.hxx>
35 #include <ViewerTest.hxx>
36 #include <ViewerTest_EventManager.hxx>
37 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
38 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
39 #include <Visual3d_View.hxx>
40 #include <Visual3d_ViewManager.hxx>
41 #include <V3d_AmbientLight.hxx>
42 #include <V3d_DirectionalLight.hxx>
43 #include <V3d_LayerMgr.hxx>
44 #include <V3d_LayerMgrPointer.hxx>
45 #include <V3d_PositionalLight.hxx>
46 #include <V3d_SpotLight.hxx>
47 #include <NCollection_DoubleMap.hxx>
48 #include <NCollection_List.hxx>
49 #include <NCollection_Vector.hxx>
50 #include <NIS_View.hxx>
51 #include <NIS_Triangulated.hxx>
52 #include <NIS_InteractiveContext.hxx>
53 #include <AIS_InteractiveContext.hxx>
54 #include <Draw_Interpretor.hxx>
56 #include <Draw_Appli.hxx>
57 #include <Aspect_PrintAlgo.hxx>
58 #include <Image_AlienPixMap.hxx>
59 #include <OpenGl_GraphicDriver.hxx>
60 #include <OSD_Timer.hxx>
61 #include <TColStd_HSequenceOfAsciiString.hxx>
62 #include <TColStd_SequenceOfInteger.hxx>
63 #include <TColStd_HSequenceOfReal.hxx>
64 #include <TColgp_Array1OfPnt2d.hxx>
65 #include <TColStd_MapOfAsciiString.hxx>
66 #include <Visual3d_LayerItem.hxx>
67 #include <Aspect_TypeOfLine.hxx>
68 #include <Image_Diff.hxx>
69 #include <Aspect_DisplayConnection.hxx>
70 #include <Graphic3d.hxx>
74 #include <PrsMgr_PresentableObject.hxx>
75 #include <Graphic3d_ClipPlane.hxx>
76 #include <NCollection_DataMap.hxx>
77 #include <Graphic3d_Texture2Dmanual.hxx>
78 #include <Prs3d_ShadingAspect.hxx>
84 #include <Visual3d_Layer.hxx>
88 #include <WNT_WClass.hxx>
89 #include <WNT_Window.hxx>
92 #define _CRT_SECURE_NO_DEPRECATE
93 #pragma warning (disable:4996)
95 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
96 #include <Cocoa_Window.hxx>
98 #include <Xw_Window.hxx>
99 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
100 #include <X11/Xutil.h>
104 // Auxiliary definitions
105 static const char THE_KEY_DELETE = 127;
107 //==============================================================================
108 // VIEWER GLOBAL VARIABLES
109 //==============================================================================
111 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
112 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
114 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
115 extern const Handle(NIS_InteractiveContext)& TheNISContext();
116 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
118 extern int VErase (Draw_Interpretor& theDI,
119 Standard_Integer theArgNb,
120 const char** theArgVec);
123 static Handle(WNT_Window)& VT_GetWindow() {
124 static Handle(WNT_Window) WNTWin;
127 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
128 static Handle(Cocoa_Window)& VT_GetWindow()
130 static Handle(Cocoa_Window) aWindow;
133 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
134 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
135 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
138 static Handle(Xw_Window)& VT_GetWindow(){
139 static Handle(Xw_Window) XWWin;
143 static void VProcessEvents(ClientData,int);
146 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
148 static Handle(Aspect_DisplayConnection) aDisplayConnection;
149 return aDisplayConnection;
152 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
154 GetDisplayConnection() = theDisplayConnection;
157 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
158 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
160 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
162 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
163 if (!aWindow.IsNull())
164 return aWindow->HWindow();
165 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
166 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
167 if (!aWindow.IsNull())
168 return aWindow->XWindow();
170 return aWindowHandle;
174 static Standard_Boolean MyHLRIsOn = Standard_False;
176 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
177 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
178 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
179 static OpenGl_Caps ViewerTest_myDefaultCaps;
181 #define ZCLIPWIDTH 1.
183 static void OSWindowSetup();
185 //==============================================================================
186 // EVENT GLOBAL VARIABLES
187 //==============================================================================
189 static int Start_Rot = 0;
190 static int ZClipIsOn = 0;
191 int X_Motion = 0; // Current cursor position
193 int X_ButtonPress = 0; // Last ButtonPress position
194 int Y_ButtonPress = 0;
195 Standard_Boolean IsDragged = Standard_False;
196 Standard_Boolean DragFirst = Standard_False;
198 //==============================================================================
201 static LRESULT WINAPI ViewerWindowProc(
206 static LRESULT WINAPI AdvViewerWindowProc(
214 //==============================================================================
217 //==============================================================================
219 const Handle(MMgt_TShared)& ViewerTest::WClass()
221 static Handle(MMgt_TShared) theWClass;
223 if (theWClass.IsNull())
225 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
226 CS_VREDRAW | CS_HREDRAW, 0, 0,
227 ::LoadCursor (NULL, IDC_ARROW));
233 //==============================================================================
234 //function : CreateName
235 //purpose : Create numerical name for new object in theMap
236 //==============================================================================
237 template <typename ObjectType>
238 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
239 const TCollection_AsciiString& theDefaultString)
241 if (theObjectMap.IsEmpty())
242 return theDefaultString + TCollection_AsciiString(1);
244 Standard_Integer aNextKey = 1;
245 Standard_Boolean isFound = Standard_False;
248 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
249 // Look for objects with default names
250 if (theObjectMap.IsBound1(aStringKey))
255 isFound = Standard_True;
258 return theDefaultString + TCollection_AsciiString(aNextKey);
261 //==============================================================================
262 //structure : ViewerTest_Names
263 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
264 //==============================================================================
265 struct ViewerTest_Names
268 TCollection_AsciiString myDriverName;
269 TCollection_AsciiString myViewerName;
270 TCollection_AsciiString myViewName;
274 const TCollection_AsciiString& GetDriverName () const
278 void SetDriverName (const TCollection_AsciiString& theDriverName)
280 myDriverName = theDriverName;
282 const TCollection_AsciiString& GetViewerName () const
286 void SetViewerName (const TCollection_AsciiString& theViewerName)
288 myViewerName = theViewerName;
290 const TCollection_AsciiString& GetViewName () const
294 void SetViewName (const TCollection_AsciiString& theViewName)
296 myViewName = theViewName;
299 //===========================================================================
300 //function : Constructor for ViewerTest_Names
301 //purpose : Get view, viewer, driver names from custom string
302 //===========================================================================
304 ViewerTest_Names (const TCollection_AsciiString& theInputString)
306 TCollection_AsciiString aName(theInputString);
307 if (theInputString.IsEmpty())
309 // Get current configuration
310 if (ViewerTest_myDrivers.IsEmpty())
311 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
312 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
314 myDriverName = ViewerTest_myDrivers.Find2
315 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
317 if(ViewerTest_myContexts.IsEmpty())
319 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
320 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
323 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
325 myViewName = CreateName <Handle(V3d_View)>
326 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
330 // There is at least view name
331 Standard_Integer aParserNumber = 0;
332 for (Standard_Integer i = 0; i < 3; ++i)
334 Standard_Integer aParserPos = aName.SearchFromEnd("/");
338 aName.Split(aParserPos-1);
343 if (aParserNumber == 0)
346 if (!ViewerTest::GetAISContext().IsNull())
348 myDriverName = ViewerTest_myDrivers.Find2
349 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
350 myViewerName = ViewerTest_myContexts.Find2
351 (ViewerTest::GetAISContext());
355 // There is no opened contexts here, need to create names for viewer and driver
356 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
357 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
359 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
360 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
362 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
364 else if (aParserNumber == 1)
366 // Here is viewerName/viewName
367 if (!ViewerTest::GetAISContext().IsNull())
368 myDriverName = ViewerTest_myDrivers.Find2
369 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
372 // There is no opened contexts here, need to create name for driver
373 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
374 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
376 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
378 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
382 //Here is driverName/viewerName/viewName
383 myDriverName = TCollection_AsciiString(aName);
385 TCollection_AsciiString aViewerName(theInputString);
386 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
387 myViewerName = TCollection_AsciiString(aViewerName);
389 myViewName = TCollection_AsciiString(theInputString);
395 //==============================================================================
396 //function : FindContextByView
397 //purpose : Find AIS_InteractiveContext by View
398 //==============================================================================
400 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
402 Handle(AIS_InteractiveContext) anAISContext;
404 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
405 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
407 if (anIter.Value()->CurrentViewer() == theView->Viewer())
408 return anIter.Key2();
414 //==============================================================================
415 //function : SetWindowTitle
416 //purpose : Set window title
417 //==============================================================================
419 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
420 Standard_CString theTitle)
423 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
425 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
426 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
428 if(GetDisplayConnection()->GetDisplay())
431 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
432 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
437 //==============================================================================
438 //function : IsWindowOverlapped
439 //purpose : Check if theWindow overlapp another view
440 //==============================================================================
442 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
443 const Standard_Integer thePxTop,
444 const Standard_Integer thePxRight,
445 const Standard_Integer thePxBottom,
446 TCollection_AsciiString& theViewId)
448 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
449 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
451 Standard_Integer aTop = 0,
455 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
456 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
457 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
458 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
459 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
461 theViewId = anIter.Key1();
462 return Standard_True;
465 return Standard_False;
468 // Workaround: to create and delete non-orthographic views outside ViewerTest
469 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
471 ViewerTest_myViews.UnBind1 (theName);
474 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
475 const Handle(V3d_View)& theView)
477 ViewerTest_myViews.Bind (theName, theView);
480 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
482 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
484 //==============================================================================
485 //function : ViewerInit
486 //purpose : Create the window viewer and initialize all the global variable
487 //==============================================================================
489 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
490 const Standard_Integer thePxTop,
491 const Standard_Integer thePxWidth,
492 const Standard_Integer thePxHeight,
493 Standard_CString theViewName,
494 Standard_CString theDisplayName)
496 // Default position and dimension of the viewer window.
497 // Note that left top corner is set to be sufficiently small to have
498 // window fit in the small screens (actual for remote desktops, see #23003).
499 // The position corresponds to the window's client area, thus some
500 // gap is added for window frame to be visible.
501 Standard_Integer aPxLeft = 20;
502 Standard_Integer aPxTop = 40;
503 Standard_Integer aPxWidth = 409;
504 Standard_Integer aPxHeight = 409;
505 Standard_Boolean toCreateViewer = Standard_False;
507 Handle(OpenGl_GraphicDriver) aGraphicDriver;
508 ViewerTest_Names aViewNames(theViewName);
509 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
510 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
517 aPxWidth = thePxWidth;
518 if (thePxHeight != 0)
519 aPxHeight = thePxHeight;
521 // Get graphic driver (create it or get from another view)
522 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
524 // Get connection string
525 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
526 TCollection_AsciiString aDisplayName(theDisplayName);
527 if (!aDisplayName.IsEmpty())
528 SetDisplayConnection (new Aspect_DisplayConnection ());
530 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
532 (void)theDisplayName; // avoid warning on unused argument
533 SetDisplayConnection (new Aspect_DisplayConnection ());
535 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
536 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
537 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
538 toCreateViewer = Standard_True;
542 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
545 //Dispose the window if input parameters are default
546 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
548 Standard_Integer aTop = 0,
555 // Get screen resolution
556 #if defined(_WIN32) || defined(__WIN32__)
558 GetClientRect(GetDesktopWindow(), &aWindowSize);
559 aScreenHeight = aWindowSize.bottom;
560 aScreenWidth = aWindowSize.right;
561 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
562 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
564 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
565 aScreenWidth = WidthOfScreen(aScreen);
566 aScreenHeight = HeightOfScreen(aScreen);
569 TCollection_AsciiString anOverlappedViewId("");
571 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
573 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
575 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
576 && aRight + 2*aPxWidth + 40 > aScreenWidth)
578 if (aBottom + aPxHeight + 40 > aScreenHeight)
585 aPxTop = aBottom + 40;
588 aPxLeft = aRight + 20;
593 TCollection_AsciiString aTitle("3D View - ");
594 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
596 // Change name of current active window
597 if (!ViewerTest::CurrentView().IsNull())
599 TCollection_AsciiString aTitle("3D View - ");
601 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
602 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
606 Handle(V3d_Viewer) a3DViewer;
607 // If it's the single view, we first look for empty context
608 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
610 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
611 anIter(ViewerTest_myContexts);
613 ViewerTest::SetAISContext (anIter.Value());
614 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
616 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
618 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
619 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
621 else if (a3DViewer.IsNull())
623 toCreateViewer = Standard_True;
624 TCollection_ExtendedString NameOfWindow("Viewer3D");
625 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
627 NameOfWindow = TCollection_ExtendedString("Collector");
629 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
633 if (ViewerTest::GetAISContext().IsNull() ||
634 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
636 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
637 ViewerTest::SetAISContext (aContext);
638 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
642 ViewerTest::ResetEventManager();
647 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
648 Handle(WNT_WClass)::DownCast (WClass()),
649 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
653 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
654 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
656 aPxWidth, aPxHeight);
657 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
659 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
662 aPxWidth, aPxHeight);
664 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
667 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
669 ViewerTest::CurrentView(aView);
670 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
671 TheNISContext()->AttachView (aView);
673 // Setup for X11 or NT
676 // Set parameters for V3d_View and V3d_Viewer
677 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
678 aV3dView->SetComputedMode(Standard_False);
679 MyHLRIsOn = aV3dView->ComputedMode();
680 aV3dView->SetZClippingDepth(0.5);
681 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
683 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
686 a3DViewer->SetDefaultLights();
687 a3DViewer->SetLightOn();
690 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
691 #if TCL_MAJOR_VERSION < 8
692 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
693 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
695 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
696 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
700 VT_GetWindow()->Map();
702 // Set the handle of created view in the event manager
703 ViewerTest::ResetEventManager();
705 ViewerTest::CurrentView()->Redraw();
710 return aViewNames.GetViewName();
713 //==============================================================================
714 //function : RedrawAllViews
715 //purpose : Redraw all created views
716 //==============================================================================
717 void ViewerTest::RedrawAllViews()
719 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
720 for (; aViewIt.More(); aViewIt.Next())
722 const Handle(V3d_View)& aView = aViewIt.Key2();
727 //==============================================================================
729 //purpose : Create the window viewer and initialize all the global variable
730 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
731 //==============================================================================
733 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
737 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
738 << "Type help for more information.\n";
742 TCollection_AsciiString aViewName, aDisplayName;
743 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
744 TCollection_AsciiString aName, aValue;
745 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
747 const TCollection_AsciiString anArg = theArgVec[anArgIt];
748 TCollection_AsciiString anArgCase = anArg;
749 anArgCase.UpperCase();
750 if (ViewerTest::SplitParameter (anArg, aName, aValue))
753 if (aName.IsEqual ("NAME"))
757 else if (aName.IsEqual ("L")
758 || aName.IsEqual ("LEFT"))
760 aPxLeft = aValue.IntegerValue();
762 else if (aName.IsEqual ("T")
763 || aName.IsEqual ("TOP"))
765 aPxTop = aValue.IntegerValue();
767 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
768 else if (aName.IsEqual ("DISP")
769 || aName.IsEqual ("DISPLAY"))
771 aDisplayName = aValue;
774 else if (aName.IsEqual ("W")
775 || aName.IsEqual ("WIDTH"))
777 aPxWidth = aValue.IntegerValue();
779 else if (aName.IsEqual ("H")
780 || aName.IsEqual ("HEIGHT"))
782 aPxHeight = aValue.IntegerValue();
786 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
789 else if (aViewName.IsEmpty())
795 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
799 ViewerTest_Names aViewNames (aViewName);
800 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
802 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
803 theDi.Eval (aCommand.ToCString());
807 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
808 aViewName.ToCString(),
809 aDisplayName.ToCString());
814 //==============================================================================
816 //purpose : hidden lines removal algorithm
817 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
818 //==============================================================================
820 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
822 if (ViewerTest::CurrentView().IsNull())
824 di << argv[0] << ": Call vinit before this command, please.\n";
830 di << argv[0] << ": Wrong number of command arguments.\n"
831 << "Type help " << argv[0] << " for more information.\n";
835 // Enable or disable HLR mode.
836 Standard_Boolean isHLROn =
837 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
839 if (isHLROn != MyHLRIsOn)
842 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
845 // Show or hide hidden lines in HLR mode.
846 Standard_Boolean isCurrentShowHidden
847 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
849 Standard_Boolean isShowHidden =
850 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
851 : isCurrentShowHidden;
854 if (isShowHidden != isCurrentShowHidden)
858 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
862 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
868 AIS_ListOfInteractive aListOfShapes;
869 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
871 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
873 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
883 ViewerTest::CurrentView()->Update();
887 //==============================================================================
888 //function : VHLRType
889 //purpose : change type of using HLR algorithm
890 //==============================================================================
892 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
894 if (ViewerTest::CurrentView().IsNull())
896 di << argv[0] << ": Call vinit before this command, please.\n";
902 di << argv[0] << ": Wrong number of command arguments.\n"
903 << "Type help " << argv[0] << " for more information.\n";
907 Prs3d_TypeOfHLR aTypeOfHLR =
908 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
912 AIS_ListOfInteractive aListOfShapes;
913 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
914 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
915 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
916 anIter.More(); anIter.Next())
918 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
921 if (aShape->TypeOfHLR() != aTypeOfHLR)
922 aShape->SetTypeOfHLR (aTypeOfHLR);
926 ViewerTest::CurrentView()->Update();
931 for (Standard_Integer i = 2; i < argc; ++i)
933 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
934 TCollection_AsciiString aName (argv[i]);
936 if (!aMap.IsBound2 (aName))
938 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
941 Handle(AIS_Shape) anAISObject =
942 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
943 if (anAISObject.IsNull())
945 anAISObject->SetTypeOfHLR (aTypeOfHLR);
947 anAISObject->Redisplay();
949 ViewerTest::CurrentView()->Update();
955 //==============================================================================
956 //function : FindViewIdByWindowHandle
957 //purpose : Find theView Id in the map of views by window handle
958 //==============================================================================
959 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
960 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
962 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
963 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
965 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
966 if (aWindowHandle == theWindowHandle)
967 return anIter.Key1();
969 return TCollection_AsciiString("");
973 //==============================================================================
974 //function : ActivateView
975 //purpose : Make the view active
976 //==============================================================================
978 void ActivateView (const TCollection_AsciiString& theViewName)
980 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
983 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
984 if (!anAISContext.IsNull())
986 if (!ViewerTest::CurrentView().IsNull())
988 TCollection_AsciiString aTitle("3D View - ");
989 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
990 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
993 ViewerTest::CurrentView (aView);
994 // Update degenerate mode
995 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
996 ViewerTest::SetAISContext (anAISContext);
997 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
998 aTitle = aTitle + theViewName + "(*)";
999 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1000 #if defined(_WIN32) || defined(__WIN32__)
1001 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1002 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1003 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1005 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1007 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1008 ViewerTest::CurrentView()->Redraw();
1013 //==============================================================================
1014 //function : RemoveView
1015 //purpose : Close and remove view from display, clear maps if neccessary
1016 //==============================================================================
1017 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1019 if (!ViewerTest_myViews.IsBound1(theViewName))
1021 cout << "Wrong view name\n";
1025 // Activate another view if it's active now
1026 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1028 if (ViewerTest_myViews.Extent() > 1)
1030 TCollection_AsciiString aNewViewName;
1031 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1032 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1033 if (anIter.Key1() != theViewName)
1035 aNewViewName = anIter.Key1();
1038 ActivateView (aNewViewName);
1042 Handle(V3d_View) anEmptyView;
1043 #if defined(_WIN32) || defined(__WIN32__)
1044 Handle(WNT_Window) anEmptyWindow;
1045 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1046 Handle(Cocoa_Window) anEmptyWindow;
1048 Handle(Xw_Window) anEmptyWindow;
1050 VT_GetWindow() = anEmptyWindow;
1051 ViewerTest::CurrentView (anEmptyView);
1052 if (isContextRemoved)
1054 Handle(AIS_InteractiveContext) anEmptyContext;
1055 ViewerTest::SetAISContext(anEmptyContext);
1061 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1062 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1064 // Remove view resources
1065 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1066 ViewerTest_myViews.UnBind1(theViewName);
1069 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1070 XFlush (GetDisplayConnection()->GetDisplay());
1073 // Keep context opened only if the closed view is last to avoid
1074 // unused empty contexts
1075 if (!aCurrentContext.IsNull())
1077 // Check if there are more difined views in the viewer
1078 aCurrentContext->CurrentViewer()->InitDefinedViews();
1079 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1081 // Remove driver if there is no viewers that use it
1082 Standard_Boolean isRemoveDriver = Standard_True;
1083 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1084 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1086 if (aCurrentContext != anIter.Key2() &&
1087 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1089 isRemoveDriver = Standard_False;
1095 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1096 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1097 #if TCL_MAJOR_VERSION < 8
1098 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1100 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1105 ViewerTest_myContexts.UnBind2(aCurrentContext);
1108 cout << "3D View - " << theViewName << " was deleted.\n";
1112 //==============================================================================
1114 //purpose : Remove the view defined by its name
1115 //==============================================================================
1117 static int VClose (Draw_Interpretor& /*theDi*/,
1118 Standard_Integer theArgsNb,
1119 const char** theArgVec)
1121 NCollection_List<TCollection_AsciiString> aViewList;
1124 TCollection_AsciiString anArg (theArgVec[1]);
1126 if (anArg.IsEqual ("ALL")
1127 || anArg.IsEqual ("*"))
1129 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1130 anIter.More(); anIter.Next())
1132 aViewList.Append (anIter.Key1());
1134 if (aViewList.IsEmpty())
1136 std::cout << "No view to close\n";
1142 ViewerTest_Names aViewName (theArgVec[1]);
1143 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1145 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1148 aViewList.Append (aViewName.GetViewName());
1153 // close active view
1154 if (ViewerTest::CurrentView().IsNull())
1156 std::cerr << "No active view!\n";
1159 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1162 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1163 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1164 anIter.More(); anIter.Next())
1166 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1172 //==============================================================================
1173 //function : VActivate
1174 //purpose : Activate the view defined by its ID
1175 //==============================================================================
1177 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1181 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1182 << "Usage: " << theArgVec[0] << " ViewID\n";
1187 theDi.Eval("vviewlist");
1191 TCollection_AsciiString aNameString(theArgVec[1]);
1192 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1194 TCollection_AsciiString aTitle("3D View - ");
1195 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1196 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1197 Handle(V3d_View) anEmptyView;
1198 #if defined(_WIN32) || defined(__WIN32__)
1199 Handle(WNT_Window) anEmptyWindow;
1200 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1201 Handle(Cocoa_Window) anEmptyWindow;
1203 Handle(Xw_Window) anEmptyWindow;
1205 VT_GetWindow() = anEmptyWindow;
1206 ViewerTest::CurrentView (anEmptyView);
1207 ViewerTest::ResetEventManager();
1208 theDi << theArgVec[0] << ": all views are inactive\n";
1212 ViewerTest_Names aViewNames(aNameString);
1214 // Check if this view exists in the viewer with the driver
1215 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1217 theDi << "Wrong view name\n";
1221 // Check if it is active already
1222 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1224 theDi << theArgVec[0] << ": the view is active already\n";
1228 ActivateView (aViewNames.GetViewName());
1232 //==============================================================================
1233 //function : VViewList
1234 //purpose : Print current list of views per viewer and graphic driver ID
1235 // shared between viewers
1236 //==============================================================================
1238 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1242 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1243 << "Usage: " << theArgVec[0] << " name";
1246 if (ViewerTest_myContexts.Size() < 1)
1249 Standard_Boolean isTreeView =
1250 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1253 theDi << theArgVec[0] <<":\n";
1255 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1256 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1259 theDi << aDriverIter.Key1() << ":\n";
1261 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1262 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1264 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1268 TCollection_AsciiString aContextName(aContextIter.Key1());
1269 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1272 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1273 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1275 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1277 TCollection_AsciiString aViewName(aViewIter.Key1());
1280 if (aViewIter.Value() == ViewerTest::CurrentView())
1281 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1283 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1287 theDi << aViewName << " ";
1297 //==============================================================================
1298 //function : VT_ProcessKeyPress
1299 //purpose : Handle KeyPress event from a CString
1300 //==============================================================================
1301 void VT_ProcessKeyPress (const char* buf_ret)
1303 //cout << "KeyPress" << endl;
1304 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1305 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1306 // Letter in alphabetic order
1308 if (!strcasecmp (buf_ret, "A"))
1311 aView->SetProj(V3d_XposYnegZpos);
1313 else if (!strcasecmp (buf_ret, "D"))
1318 else if (!strcasecmp (buf_ret, "F"))
1321 if (aNisView.IsNull())
1324 aNisView->FitAll3d();
1326 else if (!strcasecmp (buf_ret, "H"))
1329 cout << "HLR" << endl;
1330 aView->SetComputedMode (!aView->ComputedMode());
1331 MyHLRIsOn = aView->ComputedMode();
1333 else if (!strcasecmp (buf_ret, "P"))
1336 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1337 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1338 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1340 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1341 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1343 AIS_ListOfInteractive aListOfShapes;
1344 aContext->DisplayedObjects(aListOfShapes);
1345 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1346 anIter.More(); anIter.Next())
1348 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1349 if (aShape.IsNull())
1351 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1352 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1354 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1355 aShape->Redisplay();
1360 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1362 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1363 if (aShape.IsNull())
1365 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1366 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1368 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1369 aShape->Redisplay();
1373 aContext->UpdateCurrentViewer();
1376 else if (!strcasecmp (buf_ret, "S"))
1378 std::cout << "setup Shaded display mode" << std::endl;
1380 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1381 if(Ctx->NbCurrents()==0 ||
1382 Ctx->NbSelected()==0)
1383 Ctx->SetDisplayMode(AIS_Shaded);
1385 if(Ctx->HasOpenedContext()){
1386 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1387 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1390 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1391 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1393 Ctx->UpdateCurrentViewer();
1396 else if (!strcasecmp (buf_ret, "U"))
1398 // Unset display mode
1399 std::cout << "reset display mode to defaults" << std::endl;
1401 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1402 if(Ctx->NbCurrents()==0 ||
1403 Ctx->NbSelected()==0)
1404 Ctx->SetDisplayMode(AIS_WireFrame);
1406 if(Ctx->HasOpenedContext()){
1407 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1408 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1411 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1412 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1414 Ctx->UpdateCurrentViewer();
1418 else if (!strcasecmp (buf_ret, "T"))
1421 aView->SetProj(V3d_Zpos);
1423 else if (!strcasecmp (buf_ret, "B"))
1426 aView->SetProj(V3d_Zneg);
1428 else if (!strcasecmp (buf_ret, "L"))
1431 aView->SetProj(V3d_Xneg);
1433 else if (!strcasecmp (buf_ret, "R"))
1436 aView->SetProj(V3d_Xpos);
1438 else if (!strcasecmp (buf_ret, "W"))
1440 std::cout << "setup WireFrame display mode" << std::endl;
1441 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1442 if(Ctx->NbCurrents()==0 ||
1443 Ctx->NbSelected()==0)
1444 Ctx->SetDisplayMode(AIS_WireFrame);
1446 if(Ctx->HasOpenedContext()){
1447 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1448 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1451 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1452 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1454 Ctx->UpdateCurrentViewer();
1457 else if (!strcasecmp (buf_ret, "Z"))
1461 cout << "ZClipping OFF" << endl;
1464 aView->SetZClippingType(V3d_OFF);
1468 cout << "ZClipping ON" << endl;
1471 aView->SetZClippingType(V3d_FRONT);
1475 else if (!strcasecmp (buf_ret, ","))
1477 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1479 else if (!strcasecmp (buf_ret, "."))
1481 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1483 else if (*buf_ret == THE_KEY_DELETE)
1485 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1487 && aCtx->NbCurrents() > 0
1488 && aCtx->NbSelected() > 0)
1490 Draw_Interprete ("verase");
1496 Standard_Integer Num = Draw::Atoi(buf_ret);
1497 if(Num>=0 && Num<=7)
1498 ViewerTest::StandardModeActivation(Num);
1502 //==============================================================================
1503 //function : VT_ProcessExpose
1504 //purpose : Redraw the View on an Expose Event
1505 //==============================================================================
1506 void VT_ProcessExpose()
1508 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1509 if (!aView3d.IsNull())
1515 //==============================================================================
1516 //function : VT_ProcessConfigure
1517 //purpose : Resize the View on an Configure Event
1518 //==============================================================================
1519 void VT_ProcessConfigure()
1521 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1522 if (aView3d.IsNull())
1527 aView3d->MustBeResized();
1532 //==============================================================================
1533 //function : VT_ProcessButton1Press
1535 //==============================================================================
1536 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1537 const char** theArgVec,
1538 Standard_Boolean theToPick,
1539 Standard_Boolean theIsShift)
1543 Standard_Real X, Y, Z;
1544 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1546 Draw::Set (theArgVec[1], X);
1547 Draw::Set (theArgVec[2], Y);
1548 Draw::Set (theArgVec[3], Z);
1553 ViewerTest::CurrentEventManager()->ShiftSelect();
1557 ViewerTest::CurrentEventManager()->Select();
1560 return Standard_False;
1563 //==============================================================================
1564 //function : VT_ProcessButton1Release
1565 //purpose : End selecting
1566 //==============================================================================
1567 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1571 IsDragged = Standard_False;
1572 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1575 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1576 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1580 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1581 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1586 //==============================================================================
1587 //function : VT_ProcessButton3Press
1588 //purpose : Start Rotation
1589 //==============================================================================
1590 void VT_ProcessButton3Press()
1595 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1597 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1600 //==============================================================================
1601 //function : VT_ProcessButton3Release
1602 //purpose : End rotation
1603 //==============================================================================
1604 void VT_ProcessButton3Release()
1611 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1616 //==============================================================================
1617 //function : ProcessZClipMotion
1619 //==============================================================================
1621 void ProcessZClipMotion()
1623 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1624 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1625 static Standard_Real CurZPos = 0.;
1627 //Quantity_Length VDX, VDY;
1628 //a3DView->Size(VDX,VDY);
1629 //Standard_Real VDZ = a3DView->ZSize();
1630 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1632 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1634 // Front = Depth + width/2.
1635 Standard_Real D = 0.5;
1636 Standard_Real W = 0.1;
1642 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1644 a3DView->SetZClippingType(V3d_OFF);
1645 a3DView->SetZClippingDepth(D);
1646 a3DView->SetZClippingWidth(W);
1647 a3DView->SetZClippingType(V3d_FRONT);
1651 X_ButtonPress = X_Motion;
1652 Y_ButtonPress = Y_Motion;
1656 //==============================================================================
1657 //function : ProcessControlButton1Motion
1659 //==============================================================================
1661 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1662 static void ProcessControlButton1Motion()
1664 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1666 X_ButtonPress = X_Motion;
1667 Y_ButtonPress = Y_Motion;
1671 //==============================================================================
1672 //function : VT_ProcessControlButton2Motion
1674 //==============================================================================
1675 void VT_ProcessControlButton2Motion()
1677 Standard_Integer aDx = X_Motion - X_ButtonPress;
1678 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1680 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1682 ViewerTest::CurrentView()->Pan (aDx, aDy);
1684 X_ButtonPress = X_Motion;
1685 Y_ButtonPress = Y_Motion;
1688 //==============================================================================
1689 //function : VT_ProcessControlButton3Motion
1690 //purpose : Rotation
1691 //==============================================================================
1692 void VT_ProcessControlButton3Motion()
1696 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1700 //==============================================================================
1701 //function : VT_ProcessMotion
1703 //==============================================================================
1704 void VT_ProcessMotion()
1706 //pre-hilights detected objects at mouse position
1708 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1709 EM->MoveTo(X_Motion, Y_Motion);
1713 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1715 Xpix = X_Motion;Ypix=Y_Motion;
1718 //==============================================================================
1719 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1720 //purpose : Switches to an axonometric, top, left and other views
1721 //==============================================================================
1723 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1725 if ( ViewerTest::CurrentView().IsNull() )
1727 di<<"Call vinit before this command, please"<<"\n";
1731 ViewerTest::CurrentView()->SetProj(ori);
1735 //==============================================================================
1737 //purpose : Switch to an Axonometric view
1738 //Draw arg : No args
1739 //==============================================================================
1741 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1743 return ViewProject(di, V3d_XposYnegZpos);
1746 //==============================================================================
1748 //purpose : Switch to a Top View
1749 //Draw arg : No args
1750 //==============================================================================
1752 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1754 return ViewProject(di, V3d_Zpos);
1757 //==============================================================================
1758 //function : VBottom
1759 //purpose : Switch to a Bottom View
1760 //Draw arg : No args
1761 //==============================================================================
1763 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1765 return ViewProject(di, V3d_Zneg);
1768 //==============================================================================
1770 //purpose : Switch to a Left View
1771 //Draw arg : No args
1772 //==============================================================================
1774 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1776 return ViewProject(di, V3d_Ypos);
1779 //==============================================================================
1781 //purpose : Switch to a Right View
1782 //Draw arg : No args
1783 //==============================================================================
1785 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1787 return ViewProject(di, V3d_Yneg);
1790 //==============================================================================
1792 //purpose : Switch to a Front View
1793 //Draw arg : No args
1794 //==============================================================================
1796 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1798 return ViewProject(di, V3d_Xpos);
1801 //==============================================================================
1803 //purpose : Switch to a Back View
1804 //Draw arg : No args
1805 //==============================================================================
1807 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1809 return ViewProject(di, V3d_Xneg);
1812 //==============================================================================
1814 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1815 //Draw arg : No args
1816 //==============================================================================
1818 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1821 di << "Q : Quit the application" << "\n";
1823 di << "========================="<<"\n";
1824 di << "F : FitAll" << "\n";
1825 di << "T : TopView" << "\n";
1826 di << "B : BottomView" << "\n";
1827 di << "R : RightView" << "\n";
1828 di << "L : LeftView" << "\n";
1829 di << "A : AxonometricView" << "\n";
1830 di << "D : ResetView" << "\n";
1832 di << "========================="<<"\n";
1833 di << "S : Shading" << "\n";
1834 di << "W : Wireframe" << "\n";
1835 di << "H : HidelLineRemoval" << "\n";
1836 di << "U : Unset display mode" << "\n";
1837 di << "Delete : Remove selection from viewer" << "\n";
1839 di << "========================="<<"\n";
1840 di << "Selection mode "<<"\n";
1841 di << "0 : Shape" <<"\n";
1842 di << "1 : Vertex" <<"\n";
1843 di << "2 : Edge" <<"\n";
1844 di << "3 : Wire" <<"\n";
1845 di << "4 : Face" <<"\n";
1846 di << "5 : Shell" <<"\n";
1847 di << "6 : Solid" <<"\n";
1848 di << "7 : Compound" <<"\n";
1850 di << "========================="<<"\n";
1851 di << "Z : Switch Z clipping On/Off" << "\n";
1852 di << ", : Hilight next detected" << "\n";
1853 di << ". : Hilight previous detected" << "\n";
1860 static Standard_Boolean Ppick = 0;
1861 static Standard_Integer Pargc = 0;
1862 static const char** Pargv = NULL;
1865 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1870 if (!ViewerTest_myViews.IsEmpty()) {
1872 WPARAM fwKeys = wParam;
1877 // Delete view from map of views
1878 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1883 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1884 || ViewerTest::CurrentView().IsNull())
1886 // Activate inactive window
1887 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1889 ActivateView (FindViewIdByWindowHandle(hwnd));
1896 HDC hdc = GetDC( hwnd );
1897 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1898 SetROP2( hdc, R2_NOT );
1899 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1900 ReleaseDC( hwnd, hdc );
1901 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1903 IsDragged = Standard_False;
1904 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1906 case WM_LBUTTONDOWN:
1907 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1909 IsDragged = Standard_True;
1910 DragFirst = Standard_True;
1911 X_ButtonPress = LOWORD(lParam);
1912 Y_ButtonPress = HIWORD(lParam);
1914 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1921 HDC hdc = GetDC( hwnd );
1923 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1924 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1925 SetROP2( hdc, R2_NOT );
1928 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1930 DragFirst = Standard_False;
1931 X_Motion = LOWORD(lParam);
1932 Y_Motion = HIWORD(lParam);
1934 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1936 SelectObject( hdc, anObj );
1938 ReleaseDC( hwnd, hdc );
1941 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1945 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1949 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1953 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1960 if ( !ViewerTest::CurrentView().IsNull() ) {
1965 BeginPaint(hwnd, &ps);
1966 EndPaint(hwnd, &ps);
1971 VT_ProcessConfigure();
1975 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1978 c[0] = (char) wParam;
1980 if (wParam == VK_DELETE)
1982 c[0] = THE_KEY_DELETE;
1984 VT_ProcessKeyPress (c);
1992 VT_ProcessButton3Release();
1995 case WM_LBUTTONDOWN:
1996 case WM_MBUTTONDOWN:
1997 case WM_RBUTTONDOWN:
1999 WPARAM fwKeys = wParam;
2003 X_ButtonPress = LOWORD(lParam);
2004 Y_ButtonPress = HIWORD(lParam);
2006 if (Msg == WM_LBUTTONDOWN)
2008 if (fwKeys & MK_CONTROL)
2010 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2014 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2017 else if (Msg == WM_RBUTTONDOWN)
2020 VT_ProcessButton3Press();
2027 //cout << "\t WM_MOUSEMOVE" << endl;
2028 WPARAM fwKeys = wParam;
2029 X_Motion = LOWORD(lParam);
2030 Y_Motion = HIWORD(lParam);
2033 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2035 X_ButtonPress = LOWORD(lParam);
2036 Y_ButtonPress = HIWORD(lParam);
2038 if ( fwKeys & MK_RBUTTON ) {
2040 VT_ProcessButton3Press();
2044 if ( fwKeys & MK_CONTROL ) {
2045 if ( fwKeys & MK_LBUTTON ) {
2046 ProcessControlButton1Motion();
2048 else if ( fwKeys & MK_MBUTTON ||
2049 ((fwKeys&MK_LBUTTON) &&
2050 (fwKeys&MK_RBUTTON) ) ){
2051 VT_ProcessControlButton2Motion();
2053 else if ( fwKeys & MK_RBUTTON ) {
2054 VT_ProcessControlButton3Motion();
2058 else if ( fwKeys & MK_SHIFT ) {
2059 if ( fwKeys & MK_MBUTTON ||
2060 ((fwKeys&MK_LBUTTON) &&
2061 (fwKeys&MK_RBUTTON) ) ) {
2062 cout << "ProcessZClipMotion()" << endl;
2063 ProcessZClipMotion();
2067 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2069 if ((fwKeys & MK_MBUTTON
2070 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2072 ProcessZClipMotion();
2083 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2088 return DefWindowProc( hwnd, Msg, wParam, lParam );
2094 //==============================================================================
2095 //function : ViewerMainLoop
2096 //purpose : Get a Event on the view and dispatch it
2097 //==============================================================================
2100 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2102 Ppick = (argc > 0)? 1 : 0;
2110 cout << "Start picking" << endl;
2112 while ( Ppick == 1 ) {
2113 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2114 if (GetMessage(&msg, NULL, 0, 0) ) {
2115 TranslateMessage(&msg);
2116 DispatchMessage(&msg);
2120 cout << "Picking done" << endl;
2126 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2128 int min( int a, int b )
2136 int max( int a, int b )
2144 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2147 static XEvent aReport;
2148 Standard_Boolean pick = argc > 0;
2149 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2150 XNextEvent (aDisplay, &aReport);
2152 // Handle event for the chosen display connection
2153 switch (aReport.type) {
2156 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2159 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2165 // Activate inactive view
2166 Window aWindow = GetWindowHandle(VT_GetWindow());
2167 if(aWindow != aReport.xfocus.window)
2169 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2178 case ConfigureNotify:
2180 VT_ProcessConfigure();
2189 XComposeStatus status_in_out;
2191 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2192 (char *) buf_ret , 10 ,
2193 &ks_ret , &status_in_out ) ;
2196 buf_ret[ret_len] = '\0' ;
2200 VT_ProcessKeyPress (buf_ret);
2206 X_ButtonPress = aReport.xbutton.x;
2207 Y_ButtonPress = aReport.xbutton.y;
2209 if (aReport.xbutton.button == Button1)
2211 if (aReport.xbutton.state & ControlMask)
2213 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2217 IsDragged = Standard_True;
2218 DragFirst = Standard_True;
2221 else if (aReport.xbutton.button == Button3)
2224 VT_ProcessButton3Press();
2234 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2235 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2236 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2239 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2240 if( aContext.IsNull() )
2242 cout << "The context is null. Please use vinit before createmesh" << endl;
2246 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2247 if( aReport.xbutton.button==1 )
2251 aContext->ShiftSelect();
2260 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2261 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2262 ViewerTest::CurrentView());
2266 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2267 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2268 ViewerTest::CurrentView() );
2271 VT_ProcessButton3Release();
2273 IsDragged = Standard_False;
2276 VT_ProcessButton3Release();
2281 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2287 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2288 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2289 XSetFunction( aDisplay, gc, GXinvert );
2292 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2294 X_Motion = aReport.xmotion.x;
2295 Y_Motion = aReport.xmotion.y;
2296 DragFirst = Standard_False;
2298 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2302 X_Motion = aReport.xmotion.x;
2303 Y_Motion = aReport.xmotion.y;
2305 // remove all the ButtonMotionMaskr
2306 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2308 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2309 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2311 Quantity_Length VDX, VDY;
2313 ViewerTest::CurrentView()->Size(VDX,VDY);
2314 Standard_Real VDZ =0 ;
2315 VDZ = ViewerTest::CurrentView()->ZSize();
2317 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2319 Quantity_Length dx = 0 ;
2320 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2324 dx = dx / VDX * VDZ;
2328 ViewerTest::CurrentView()->Redraw();
2332 if ( aReport.xmotion.state & ControlMask ) {
2333 if ( aReport.xmotion.state & Button1Mask ) {
2334 ProcessControlButton1Motion();
2336 else if ( aReport.xmotion.state & Button2Mask ) {
2337 VT_ProcessControlButton2Motion();
2339 else if ( aReport.xmotion.state & Button3Mask ) {
2340 VT_ProcessControlButton3Motion();
2354 //==============================================================================
2355 //function : VProcessEvents
2356 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2357 // event in the Viewer window
2358 //==============================================================================
2360 static void VProcessEvents(ClientData,int)
2362 NCollection_Vector<int> anEventNumbers;
2363 // Get number of messages from every display
2364 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2365 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2367 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2369 // Handle events for every display
2370 int anEventIter = 0;
2371 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2372 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2374 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2375 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2377 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2378 int anEventResult = ViewerMainLoop( 0, NULL);
2379 // If window is closed or context was not found finish current event processing loop
2385 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2390 //==============================================================================
2391 //function : OSWindowSetup
2392 //purpose : Setup for the X11 window to be able to cath the event
2393 //==============================================================================
2396 static void OSWindowSetup()
2398 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2401 Window window = VT_GetWindow()->XWindow();
2402 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2403 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2404 XSynchronize(aDisplay, 1);
2406 // X11 : For keyboard on SUN
2408 wmhints.flags = InputHint;
2411 XSetWMHints( aDisplay, window, &wmhints);
2413 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2414 ButtonPressMask | ButtonReleaseMask |
2415 StructureNotifyMask |
2417 Button1MotionMask | Button2MotionMask |
2418 Button3MotionMask | FocusChangeMask
2420 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2421 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2423 XSynchronize(aDisplay, 0);
2432 //==============================================================================
2435 //purpose : Fitall, no DRAW arguments
2436 //Draw arg : No args
2437 //==============================================================================
2439 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2441 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2442 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2443 if (V.IsNull() == Standard_False) {
2445 } else if (aView.IsNull() == Standard_False) {
2451 //==============================================================================
2453 //purpose : ZFitall, no DRAW arguments
2454 //Draw arg : No args
2455 //==============================================================================
2456 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2458 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2460 if (aCurrentView.IsNull())
2462 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2468 aCurrentView->ZFitAll();
2469 aCurrentView->Redraw();
2473 Standard_Real aScale = 1.0;
2477 aScale = Draw::Atoi (theArgVec[1]);
2480 aCurrentView->ZFitAll (aScale);
2481 aCurrentView->Redraw();
2486 //==============================================================================
2487 //function : VRepaint
2489 //==============================================================================
2490 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2492 Handle(V3d_View) V = ViewerTest::CurrentView();
2493 if ( !V.IsNull() ) V->Redraw(); return 0;
2496 //==============================================================================
2498 //purpose : Remove all the object from the viewer
2499 //Draw arg : No args
2500 //==============================================================================
2502 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2504 Handle(V3d_View) V = ViewerTest::CurrentView();
2506 ViewerTest::Clear();
2510 //==============================================================================
2513 //==============================================================================
2515 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2516 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2519 di << argv[0] << "Invalid number of arguments" << "\n";
2523 while (ViewerMainLoop( argc, argv)) {
2529 //==============================================================================
2530 //function : InitViewerTest
2531 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2532 //==============================================================================
2534 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2536 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2537 ViewerTest::SetAISContext(theContext);
2538 aViewer->InitActiveViews();
2539 Handle(V3d_View) aView = aViewer->ActiveView();
2540 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2541 ViewerTest::ResetEventManager();
2542 Handle(Aspect_Window) aWindow = aView->Window();
2543 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2545 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2547 static int aFirst = 1;
2549 #if TCL_MAJOR_VERSION < 8
2550 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2551 TK_READABLE, VProcessEvents, (ClientData) 0);
2553 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2554 TK_READABLE, VProcessEvents, (ClientData) 0);
2561 //==============================================================================
2563 //purpose : Load image as background
2564 //==============================================================================
2566 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2568 if (argc < 2 || argc > 3)
2570 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2571 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2575 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2576 if(AISContext.IsNull())
2578 di << "use 'vinit' command before " << argv[0] << "\n";
2582 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2585 const char* szType = argv[2];
2586 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2587 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2588 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2589 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2592 di << "Wrong fill type : " << szType << "\n";
2593 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2598 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2599 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2604 //==============================================================================
2605 //function : VSetBgMode
2606 //purpose : Change background image fill type
2607 //==============================================================================
2609 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2613 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2614 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2618 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2619 if(AISContext.IsNull())
2621 di << "use 'vinit' command before " << argv[0] << "\n";
2624 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2625 const char* szType = argv[1];
2626 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2627 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2628 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2629 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2632 di << "Wrong fill type : " << szType << "\n";
2633 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2636 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2637 V3dView->SetBgImageStyle(aFillType, Standard_True);
2641 //==============================================================================
2642 //function : VSetGradientBg
2643 //purpose : Mount gradient background
2644 //==============================================================================
2645 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2649 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2650 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2651 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2652 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2656 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2657 if(AISContext.IsNull())
2659 di << "use 'vinit' command before " << argv[0] << "\n";
2665 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2666 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2667 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2668 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2670 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2671 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2672 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2674 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2675 int aType = Draw::Atoi(argv[7]);
2676 if( aType < 0 || aType > 8 )
2678 di << "Wrong fill type " << "\n";
2679 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2680 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2684 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2686 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2687 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2693 //==============================================================================
2694 //function : VSetGradientBgMode
2695 //purpose : Change gradient background fill style
2696 //==============================================================================
2697 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2701 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2702 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2703 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2707 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2708 if(AISContext.IsNull())
2710 di << "use 'vinit' command before " << argv[0] << "\n";
2715 int aType = Draw::Atoi(argv[1]);
2716 if( aType < 0 || aType > 8 )
2718 di << "Wrong fill type " << "\n";
2719 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2720 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2724 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2726 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2727 V3dView->SetBgGradientStyle( aMethod, 1 );
2733 //==============================================================================
2734 //function : VSetColorBg
2735 //purpose : Set color background
2736 //==============================================================================
2737 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2741 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2742 di << "R,G,B = [0..255]" << "\n";
2746 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2747 if(AISContext.IsNull())
2749 di << "use 'vinit' command before " << argv[0] << "\n";
2755 Standard_Real R = Draw::Atof(argv[1])/255.;
2756 Standard_Real G = Draw::Atof(argv[2])/255.;
2757 Standard_Real B = Draw::Atof(argv[3])/255.;
2758 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2760 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2761 V3dView->SetBackgroundColor( aColor );
2768 //==============================================================================
2770 //purpose : View Scaling
2771 //==============================================================================
2773 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2775 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2776 if ( V3dView.IsNull() ) return 1;
2779 di << argv[0] << "Invalid number of arguments" << "\n";
2782 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2785 //==============================================================================
2786 //function : VTestZBuffTrihedron
2787 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2788 //==============================================================================
2790 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2792 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2793 if ( V3dView.IsNull() ) return 1;
2795 V3dView->ZBufferTriedronSetup();
2798 // Set up default trihedron parameters
2799 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2803 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2804 const char* aPosType = argv[1];
2806 if ( strcmp(aPosType, "center") == 0 )
2808 aPosition = Aspect_TOTP_CENTER;
2810 if (strcmp(aPosType, "left_lower") == 0)
2812 aPosition = Aspect_TOTP_LEFT_LOWER;
2814 if (strcmp(aPosType, "left_upper") == 0)
2816 aPosition = Aspect_TOTP_LEFT_UPPER;
2818 if (strcmp(aPosType, "right_lower") == 0)
2820 aPosition = Aspect_TOTP_RIGHT_LOWER;
2822 if (strcmp(aPosType, "right_upper") == 0)
2824 aPosition = Aspect_TOTP_RIGHT_UPPER;
2827 di << argv[1] << " Invalid type of alignment" << "\n";
2828 di << "Must be one of [ center, left_lower," << "\n";
2829 di << "left_upper, right_lower, right_upper ]" << "\n";
2833 Standard_Real R = Draw::Atof(argv[2])/255.;
2834 Standard_Real G = Draw::Atof(argv[3])/255.;
2835 Standard_Real B = Draw::Atof(argv[4])/255.;
2836 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2838 Standard_Real aScale = Draw::Atof(argv[5]);
2842 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2846 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2847 const char* aPresType = argv[6];
2849 if ( strcmp(aPresType, "wireframe") == 0 )
2851 aPresentation = V3d_WIREFRAME;
2853 if (strcmp(aPresType, "zbuffer") == 0)
2855 aPresentation = V3d_ZBUFFER;
2858 di << argv[6] << " Invalid type of visualization" << "\n";
2859 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2863 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2867 di << argv[0] << " Invalid number of arguments" << "\n";
2876 //==============================================================================
2877 //function : VRotate
2878 //purpose : Camera Rotating
2879 //==============================================================================
2881 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2882 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2883 if ( V3dView.IsNull() ) {
2888 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2890 } else if ( argc == 7 ) {
2891 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]) );
2894 di << argv[0] << " Invalid number of arguments" << "\n";
2899 //==============================================================================
2901 //purpose : View zoom in / out (relative to current zoom)
2902 //==============================================================================
2904 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2905 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2906 if ( V3dView.IsNull() ) {
2911 Standard_Real coef = Draw::Atof(argv[1]);
2912 if ( coef <= 0.0 ) {
2913 di << argv[1] << "Invalid value" << "\n";
2916 V3dView->SetZoom( Draw::Atof(argv[1]) );
2919 di << argv[0] << " Invalid number of arguments" << "\n";
2924 //==============================================================================
2926 //purpose : View panning (in pixels)
2927 //==============================================================================
2929 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2930 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2931 if ( V3dView.IsNull() ) return 1;
2934 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2937 di << argv[0] << " Invalid number of arguments" << "\n";
2943 //==============================================================================
2944 //function : VExport
2945 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2946 //==============================================================================
2948 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2950 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2951 if (V3dView.IsNull())
2956 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2960 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2961 TCollection_AsciiString aFormatStr;
2963 TCollection_AsciiString aFileName (argv[1]);
2964 Standard_Integer aLen = aFileName.Length();
2968 aFormatStr = TCollection_AsciiString (argv[2]);
2972 if (aFileName.Value (aLen - 2) == '.')
2974 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2976 else if (aFileName.Value (aLen - 3) == '.')
2978 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2982 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2988 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2992 aFormatStr.UpperCase();
2993 if (aFormatStr == "PS")
2994 anExpFormat = Graphic3d_EF_PostScript;
2995 else if (aFormatStr == "EPS")
2996 anExpFormat = Graphic3d_EF_EnhPostScript;
2997 else if (aFormatStr == "TEX")
2998 anExpFormat = Graphic3d_EF_TEX;
2999 else if (aFormatStr == "PDF")
3000 anExpFormat = Graphic3d_EF_PDF;
3001 else if (aFormatStr == "SVG")
3002 anExpFormat = Graphic3d_EF_SVG;
3003 else if (aFormatStr == "PGF")
3004 anExpFormat = Graphic3d_EF_PGF;
3005 else if (aFormatStr == "EMF")
3006 anExpFormat = Graphic3d_EF_EMF;
3009 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3014 if (!V3dView->View()->Export (argv[1], anExpFormat))
3016 di << "Error: export of image to " << aFormatStr << " failed!\n";
3019 catch (Standard_Failure)
3021 di << "Error: export of image to " << aFormatStr << " failed";
3022 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3027 //==============================================================================
3028 //function : VColorScale
3029 //purpose : representation color scale
3030 //==============================================================================
3031 #include <V3d_ColorScale.hxx>
3033 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3035 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
3037 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
3041 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3042 if(aContext.IsNull()) {
3043 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
3047 Standard_Real minRange = 0. , maxRange = 100. ;
3049 Standard_Integer numIntervals = 10 ;
3050 Standard_Integer textHeight = 16;
3051 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
3052 Standard_Real X = 0., Y = 0. ;
3058 minRange = Draw::Atof( argv[1] );
3059 maxRange = Draw::Atof( argv[2] );
3060 numIntervals = Draw::Atoi( argv[3] );
3063 textHeight = Draw::Atoi( argv[4] );
3065 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
3068 X = Draw::Atof( argv[6] );
3069 Y = Draw::Atof( argv[7] );
3072 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3073 if ( curView.IsNull( ) )
3075 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3076 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3077 if( ! aCS.IsNull( ) )
3079 aCS->SetPosition( X , Y );
3080 aCS->SetHeight( 0.95) ;
3081 aCS->SetTextHeight( textHeight );
3082 aCS->SetRange( minRange , maxRange );
3083 aCS->SetNumberOfIntervals( numIntervals );
3084 aCS->SetLabelPosition( position );
3085 if( !curView->ColorScaleIsDisplayed() )
3086 curView->ColorScaleDisplay( );
3091 //==============================================================================
3092 //function : VGraduatedTrihedron
3093 //purpose : Displays a graduated trihedron
3094 //==============================================================================
3096 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3098 const char *str = arg;
3101 unsigned short c1 = *str++;
3102 unsigned short c2 = *str++;
3103 if (!c1 || !c2) break;
3104 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3108 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3111 if (argc != 2 && argc < 5)
3113 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3114 di<<"Usage: type help "<<argv[0]<<"\n";
3115 return 1; //TCL_ERROR
3118 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3120 // Create 3D view if it doesn't exist
3121 if ( aV3dView.IsNull() )
3123 ViewerTest::ViewerInit();
3124 aV3dView = ViewerTest::CurrentView();
3125 if( aV3dView.IsNull() )
3127 di << "Error: Cannot create a 3D view\n";
3128 return 1; //TCL_ERROR
3132 // Erase (==0) or display (!=0)
3133 const int display = Draw::Atoi(argv[1]);
3138 TCollection_AsciiString font;
3140 font.AssignCat("Courier");
3142 font.AssignCat(argv[5]);
3144 // Text is multibyte
3145 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3148 TCollection_ExtendedString xname, yname, zname;
3153 AddMultibyteString(xname, argv[2]);
3154 AddMultibyteString(yname, argv[3]);
3155 AddMultibyteString(zname, argv[4]);
3171 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3172 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3173 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3174 Standard_True/*drawgrid*/,
3175 Standard_True/*drawaxes*/,
3176 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3177 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3178 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3179 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3180 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3181 Quantity_NOC_WHITE/*gridcolor*/,
3182 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3183 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3186 aV3dView->GraduatedTrihedronErase();
3188 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3194 //==============================================================================
3195 //function : VPrintView
3196 //purpose : Test printing algorithm, print the view to image file with given
3197 // width and height. Printing implemented only for WNT.
3198 //==============================================================================
3199 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3203 di << "Printing implemented only for wnt!\n";
3207 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3208 Handle(V3d_View) aView = NULL;
3209 aContextAIS = ViewerTest::GetAISContext();
3210 if (!aContextAIS.IsNull())
3212 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3213 Vwr->InitActiveViews();
3214 if(Vwr->MoreActiveViews())
3215 aView = Vwr->ActiveView();
3221 di << "Call vinit before!\n";
3226 di << "Use: " << argv[0];
3227 di << " width height filename [print algo=0] [tile_width tile_height]\n";
3228 di << "width, height of the intermediate buffer for operation\n";
3229 di << "algo : {0|1}\n";
3230 di << " 0 - stretch algorithm\n";
3231 di << " 1 - tile algorithm\n";
3232 di << "test printing algorithms into an intermediate buffer\n";
3233 di << "using specific tile size if provided\n";
3234 di << "with saving output to an image file\n";
3238 // get the input params
3239 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3240 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3241 Standard_Integer aMode = 0;
3242 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3244 aMode = Draw::Atoi (argv[4]);
3246 Standard_Integer aTileWidth = 0;
3247 Standard_Integer aTileHeight = 0;
3248 Standard_Boolean isTileSizeProvided = Standard_False;
3251 isTileSizeProvided = Standard_True;
3252 aTileWidth = Draw::Atoi (argv[5]);
3253 aTileHeight = Draw::Atoi (argv[6]);
3256 // check the input parameters
3257 if (aWidth <= 0 || aHeight <= 0)
3259 di << "Width and height must be positive values!\n";
3262 if (aMode != 0 && aMode != 1)
3265 // define compatible bitmap
3266 HDC anDC = CreateCompatibleDC(0);
3267 BITMAPINFO aBitmapData;
3268 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3269 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3270 aBitmapData.bmiHeader.biWidth = aWidth ;
3271 aBitmapData.bmiHeader.biHeight = aHeight;
3272 aBitmapData.bmiHeader.biPlanes = 1;
3273 aBitmapData.bmiHeader.biBitCount = 24;
3274 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3275 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3276 aBitmapData.bmiHeader.biClrUsed = 0;
3277 aBitmapData.bmiHeader.biClrImportant = 0;
3278 aBitmapData.bmiHeader.biCompression = BI_RGB;
3279 aBitmapData.bmiHeader.biSizeImage = 0;
3281 // Create Device Independent Bitmap
3282 void* aBitsOut = NULL;
3283 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3284 &aBitsOut, NULL, 0);
3285 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3287 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3288 if (aBitsOut != NULL)
3291 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3294 if (isTileSizeProvided)
3296 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
3297 Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
3298 aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight);
3300 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
3302 Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
3303 aView->View()->FBORelease (aNewBuffer);
3304 aCView->ptrFBO = anOldBuffer;
3308 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
3312 // succesfully printed into an intermediate buffer
3315 Image_PixMap aWrapper;
3316 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3317 aWrapper.SetTopDown (false);
3319 Image_AlienPixMap anImageBitmap;
3320 anImageBitmap.InitCopy (aWrapper);
3321 isSaved = anImageBitmap.Save (aFileName);
3325 di << "Print operation failed due to printing errors or\n";
3326 di << "insufficient memory available\n";
3327 di << "Please, try to use smaller dimensions for this test\n";
3328 di << "command, as it allocates intermediate buffer for storing\n";
3329 di << "the result\n";
3334 di << "Can't allocate memory for intermediate buffer\n";
3335 di << "Please use smaller dimensions\n";
3340 SelectObject (anDC, anOldBitmap);
3341 DeleteObject (aMemoryBitmap);
3347 di << "Save to file operation failed. This operation may fail\n";
3348 di << "if you don't have enough available memory, then you can\n";
3349 di << "use smaller dimensions for the output file\n";
3358 //==============================================================================
3359 //function : VZLayer
3360 //purpose : Test z layer operations for v3d viewer
3361 //==============================================================================
3362 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3364 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3365 if (aContextAIS.IsNull())
3367 di << "Call vinit before!\n";
3372 di << "Use: vzlayer " << argv[0];
3373 di << " add/del/get [id]\n";
3374 di << " add - add new z layer to viewer and print its id\n";
3375 di << " del - del z layer by its id\n";
3376 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3377 di << "id - the layer identificator value defined when removing z layer\n";
3381 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3382 if (aViewer.IsNull())
3384 di << "No active viewer!\n";
3388 // perform operation
3389 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3392 Standard_Integer aNewId;
3393 if (!aViewer->AddZLayer (aNewId))
3395 di << "Impossible to add new z layer!\n";
3399 di << "New z layer added with index: " << aNewId << "\n";
3401 else if (anOp == "del")
3405 di << "Please also provide as argument id of z layer to remove\n";
3409 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3410 if (!aViewer->RemoveZLayer (aDelId))
3412 di << "Impossible to remove the z layer or invalid id!\n";
3416 di << "Z layer " << aDelId << " has been removed\n";
3418 else if (anOp == "get")
3420 TColStd_SequenceOfInteger anIds;
3421 aViewer->GetAllZLayers (anIds);
3422 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3424 di << anIds.Value (aSeqIdx) << " ";
3431 di << "Invalid operation, please use { add / del / get }\n";
3438 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3440 // this class provides a presentation of text item in v3d view under-/overlayer
3441 class V3d_TextItem : public Visual3d_LayerItem
3446 DEFINE_STANDARD_RTTI(V3d_TextItem)
3449 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3450 const Standard_Real theX1,
3451 const Standard_Real theY1,
3452 const Standard_Real theHeight,
3453 const TCollection_AsciiString& theFontName,
3454 const Quantity_Color& theColor,
3455 const Quantity_Color& theSubtitleColor,
3456 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3457 const Handle(Visual3d_Layer)& theLayer);
3460 Standard_EXPORT void RedrawLayerPrs();
3466 TCollection_AsciiString myText;
3467 Standard_Real myHeight;
3468 Handle(Visual3d_Layer) myLayer;
3469 Quantity_Color myColor;
3470 Quantity_Color mySubtitleColor;
3471 Aspect_TypeOfDisplayText myType;
3472 TCollection_AsciiString myFontName;
3475 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3476 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3478 // create and add to display the text item
3479 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3480 const Standard_Real theX1,
3481 const Standard_Real theY1,
3482 const Standard_Real theHeight,
3483 const TCollection_AsciiString& theFontName,
3484 const Quantity_Color& theColor,
3485 const Quantity_Color& theSubtitleColor,
3486 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3487 const Handle(Visual3d_Layer)& theLayer)
3488 : myX1 (theX1), myY1 (theY1),
3490 myHeight (theHeight),
3493 mySubtitleColor (theSubtitleColor),
3494 myType (theTypeOfDisplay),
3495 myFontName (theFontName)
3497 if (!myLayer.IsNull ())
3498 myLayer->AddLayerItem (this);
3502 void V3d_TextItem::RedrawLayerPrs ()
3504 if (myLayer.IsNull ())
3507 myLayer->SetColor (myColor);
3508 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3509 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3512 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3514 // The Visual3d_LayerItem line item for "vlayerline" command
3515 // it provides a presentation of line with user-defined
3516 // linewidth, linetype and transparency.
3517 class V3d_LineItem : public Visual3d_LayerItem
3521 DEFINE_STANDARD_RTTI(V3d_LineItem)
3524 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3525 Standard_Real X2, Standard_Real Y2,
3526 V3d_LayerMgrPointer theLayerMgr,
3527 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3528 Standard_Real theWidth = 0.5,
3529 Standard_Real theTransp = 1.0);
3532 Standard_EXPORT void RedrawLayerPrs();
3536 Standard_Real myX1, myY1, myX2, myY2;
3537 V3d_LayerMgrPointer myLayerMgr;
3538 Aspect_TypeOfLine myType;
3539 Standard_Real myWidth;
3540 Standard_Real myTransparency;
3543 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3544 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3546 // default constructor for line item
3547 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3548 Standard_Real X2, Standard_Real Y2,
3549 V3d_LayerMgrPointer theLayerMgr,
3550 Aspect_TypeOfLine theType,
3551 Standard_Real theWidth,
3552 Standard_Real theTransp) :
3553 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3554 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3556 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3557 myLayerMgr->Overlay()->AddLayerItem (this);
3561 void V3d_LineItem::RedrawLayerPrs ()
3563 Handle (Visual3d_Layer) aOverlay;
3566 aOverlay = myLayerMgr->Overlay();
3568 if (!aOverlay.IsNull())
3570 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3571 aOverlay->SetColor(aColor);
3572 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3573 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3574 aOverlay->BeginPolyline();
3575 aOverlay->AddVertex(myX1, myY1);
3576 aOverlay->AddVertex(myX2, myY2);
3577 aOverlay->ClosePrimitive();
3581 //=============================================================================
3582 //function : VLayerLine
3583 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3584 // : linewidth, transparency coefficient
3585 //============================================================================
3586 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3588 // get the active view
3589 Handle(V3d_View) aView = ViewerTest::CurrentView();
3592 di << "Call vinit before!\n";
3597 di << "Use: " << argv[0];
3598 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3599 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3600 di << " 0 - solid \n";
3601 di << " 1 - dashed \n";
3602 di << " 2 - dot \n";
3603 di << " 3 - dashdot\n";
3604 di << " transparency : { 0.0 - 1.0 } \n";
3605 di << " 0.0 - transparent\n";
3606 di << " 1.0 - visible \n";
3610 // get the input params
3611 Standard_Real X1 = Draw::Atof(argv[1]);
3612 Standard_Real Y1 = Draw::Atof(argv[2]);
3613 Standard_Real X2 = Draw::Atof(argv[3]);
3614 Standard_Real Y2 = Draw::Atof(argv[4]);
3616 Standard_Real aWidth = 0.5;
3617 Standard_Integer aType = 0;
3618 Standard_Real aTransparency = 1.0;
3622 aWidth = Draw::Atof(argv[5]);
3626 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3631 aTransparency = Draw::Atof(argv[7]);
3632 if (aTransparency < 0 || aTransparency > 1.0)
3633 aTransparency = 1.0;
3636 // select appropriate line type
3637 Aspect_TypeOfLine aLineType;
3641 aLineType = Aspect_TOL_DASH;
3645 aLineType = Aspect_TOL_DOT;
3649 aLineType = Aspect_TOL_DOTDASH;
3653 aLineType = Aspect_TOL_SOLID;
3656 // replace layer manager
3657 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3658 aView->SetLayerMgr(aMgr);
3661 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3667 aView->MustBeResized();
3673 //=======================================================================
3674 //function : VOverlayText
3675 //purpose : Test text displaying in view overlay
3676 //=======================================================================
3677 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3679 // get the active view
3680 Handle(V3d_View) aView = ViewerTest::CurrentView();
3683 di << "No active view. Please call vinit.\n";
3686 else if (argc < 4 || argc > 13)
3688 di << "Use: " << argv[0];
3689 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3690 di << "[background_color: R G B]\n";
3691 di << " height - pixel height of the text (default=10.0)\n";
3692 di << " font_name - name of font (default=courier)\n";
3693 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3694 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
3695 di << " background_color- R G B values used for subtitle and decal text\n";
3696 di << "(default=255.0 255.0 255.0)\n";
3700 TCollection_AsciiString aText (argv[1]);
3701 Standard_Real aPosX = Draw::Atof(argv[2]);
3702 Standard_Real aPosY = Draw::Atof(argv[3]);
3703 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3706 TCollection_AsciiString aFontName = "Courier";
3708 aFontName = TCollection_AsciiString (argv[5]);
3711 Quantity_Parameter aColorRed = 1.0;
3712 Quantity_Parameter aColorGreen = 1.0;
3713 Quantity_Parameter aColorBlue = 1.0;
3716 aColorRed = Draw::Atof (argv[6])/255.;
3717 aColorGreen = Draw::Atof (argv[7])/255.;
3718 aColorBlue = Draw::Atof (argv[8])/255.;
3722 TCollection_AsciiString aDispStr;
3724 aDispStr = TCollection_AsciiString (argv[9]);
3726 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3727 if (aDispStr.IsEqual ("subtitle"))
3728 aTextType = Aspect_TODT_SUBTITLE;
3729 else if (aDispStr.IsEqual ("decal"))
3730 aTextType = Aspect_TODT_DEKALE;
3731 else if (aDispStr.IsEqual ("blend"))
3732 aTextType = Aspect_TODT_BLEND;
3733 else if (aDispStr.IsEqual ("dimension"))
3734 aTextType = Aspect_TODT_DIMENSION;
3737 Quantity_Parameter aSubRed = 1.0;
3738 Quantity_Parameter aSubGreen = 1.0;
3739 Quantity_Parameter aSubBlue = 1.0;
3742 aSubRed = Draw::Atof (argv[10])/255.;
3743 aSubGreen = Draw::Atof (argv[11])/255.;
3744 aSubBlue = Draw::Atof (argv[12])/255.;
3747 // check fo current overlay
3748 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3749 if (anOverlay.IsNull ())
3751 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3752 anOverlay = aMgr->Overlay ();
3753 aView->SetLayerMgr (aMgr);
3756 Quantity_Color aTextColor (aColorRed, aColorGreen,
3757 aColorBlue, Quantity_TOC_RGB);
3758 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3759 aSubBlue, Quantity_TOC_RGB);
3762 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3763 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3766 aView->MustBeResized();
3772 //==============================================================================
3775 //==============================================================================
3777 static int VGrid (Draw_Interpretor& /*theDI*/,
3778 Standard_Integer theArgNb,
3779 const char** theArgVec)
3781 // get the active view
3782 Handle(V3d_View) aView = ViewerTest::CurrentView();
3783 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3784 if (aView.IsNull() || aViewer.IsNull())
3786 std::cerr << "No active view. Please call vinit.\n";
3790 Aspect_GridType aType = aViewer->GridType();
3791 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3793 Standard_Integer anIter = 1;
3794 for (; anIter < theArgNb; ++anIter)
3796 const char* aValue = theArgVec[anIter];
3799 aType = Aspect_GT_Rectangular;
3801 else if (*aValue == 'c')
3803 aType = Aspect_GT_Circular;
3805 else if (*aValue == 'l')
3807 aMode = Aspect_GDM_Lines;
3809 else if (*aValue == 'p')
3811 aMode = Aspect_GDM_Points;
3813 else if (strcmp (aValue, "off" ) == 0)
3815 aViewer->DeactivateGrid();
3824 Standard_Integer aTail = (theArgNb - anIter);
3827 aViewer->ActivateGrid (aType, aMode);
3830 else if (aTail != 2 && aTail != 5)
3832 std::cerr << "Incorrect arguments number! Usage:\n"
3833 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3837 Quantity_Length anOriginX, anOriginY;
3838 Quantity_PlaneAngle aRotAngle;
3839 if (aType == Aspect_GT_Rectangular)
3841 Quantity_Length aRStepX, aRStepY;
3842 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3844 anOriginX = Draw::Atof (theArgVec[anIter++]);
3845 anOriginY = Draw::Atof (theArgVec[anIter++]);
3848 aRStepX = Draw::Atof (theArgVec[anIter++]);
3849 aRStepY = Draw::Atof (theArgVec[anIter++]);
3850 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3852 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3853 aViewer->ActivateGrid (aType, aMode);
3855 else if (aType == Aspect_GT_Circular)
3857 Quantity_Length aRadiusStep;
3858 Standard_Integer aDivisionNumber;
3859 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3861 anOriginX = Draw::Atof (theArgVec[anIter++]);
3862 anOriginY = Draw::Atof (theArgVec[anIter++]);
3865 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3866 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3867 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3870 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3871 aViewer->ActivateGrid (aType, aMode);
3877 //==============================================================================
3880 //==============================================================================
3882 static int VFps (Draw_Interpretor& theDI,
3883 Standard_Integer theArgNb,
3884 const char** theArgVec)
3886 // get the active view
3887 Handle(V3d_View) aView = ViewerTest::CurrentView();
3890 std::cerr << "No active view. Please call vinit.\n";
3894 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3897 std::cerr << "Incorrect arguments!\n";
3901 // the time is meaningless for first call
3902 // due to async OpenGl rendering
3905 // redraw view in loop to estimate average values
3908 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3914 const Standard_Real aTime = aTimer.ElapsedTime();
3915 aTimer.OSD_Chronometer::Show (aCpu);
3917 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3918 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3920 // return statistics
3921 theDI << "FPS: " << aFpsAver << "\n"
3922 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3927 //==============================================================================
3928 //function : VGlDebug
3930 //==============================================================================
3932 static int VGlDebug (Draw_Interpretor& theDI,
3933 Standard_Integer theArgNb,
3934 const char** theArgVec)
3938 Handle(V3d_View) aView = ViewerTest::CurrentView();
3941 std::cerr << "No active view. Please call vinit.\n";
3945 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3946 "GL_ARB_debug_output");
3947 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3948 theDI << (isActive ? "1" : "0");
3952 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3956 //==============================================================================
3959 //==============================================================================
3961 static int VVbo (Draw_Interpretor& theDI,
3962 Standard_Integer theArgNb,
3963 const char** theArgVec)
3965 const Standard_Boolean toSet = (theArgNb > 1);
3966 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3969 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
3973 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3974 if (aContextAIS.IsNull())
3978 std::cerr << "No active view!\n";
3982 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3983 if (!aDriver.IsNull())
3987 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3991 aDriver->ChangeOptions().vboDisable = toUseVbo;
3998 //==============================================================================
4001 //==============================================================================
4003 static int VCaps (Draw_Interpretor& theDI,
4004 Standard_Integer theArgNb,
4005 const char** theArgVec)
4007 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
4008 Handle(OpenGl_GraphicDriver) aDriver;
4009 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4010 if (!aContextAIS.IsNull())
4012 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
4013 aCaps = &aDriver->ChangeOptions();
4018 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
4019 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
4020 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
4024 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4026 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
4027 if (anArg.Search ("vbo=") > -1)
4029 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
4031 else if (anArg.Search ("sprites=") > -1)
4033 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
4035 else if (anArg.Search ("soft=") > -1)
4037 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
4041 std::cerr << "Unknown argument: " << anArg << "\n";
4044 if (aCaps != &ViewerTest_myDefaultCaps)
4046 ViewerTest_myDefaultCaps = *aCaps;
4051 //==============================================================================
4052 //function : VMemGpu
4054 //==============================================================================
4056 static int VMemGpu (Draw_Interpretor& theDI,
4057 Standard_Integer theArgNb,
4058 const char** theArgVec)
4061 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4062 if (aContextAIS.IsNull())
4064 std::cerr << "No active view. Please call vinit.\n";
4068 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
4069 if (aDriver.IsNull())
4071 std::cerr << "Graphic driver not available.\n";
4075 Standard_Size aFreeBytes = 0;
4076 TCollection_AsciiString anInfo;
4077 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
4079 std::cerr << "Information not available.\n";
4083 if (theArgNb > 1 && *theArgVec[1] == 'f')
4085 theDI << Standard_Real (aFreeBytes);
4095 // ==============================================================================
4096 // function : VReadPixel
4098 // ==============================================================================
4099 static int VReadPixel (Draw_Interpretor& theDI,
4100 Standard_Integer theArgNb,
4101 const char** theArgVec)
4103 // get the active view
4104 Handle(V3d_View) aView = ViewerTest::CurrentView();
4107 std::cerr << "No active view. Please call vinit.\n";
4110 else if (theArgNb < 3)
4112 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4116 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4117 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4119 Standard_Integer aWidth, aHeight;
4120 aView->Window()->Size (aWidth, aHeight);
4121 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4122 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4123 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4125 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4129 Standard_Boolean toShowName = Standard_False;
4130 Standard_Boolean toShowHls = Standard_False;
4131 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4133 const char* aParam = theArgVec[anIter];
4134 if ( strcasecmp( aParam, "rgb" ) == 0 )
4136 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4137 aBufferType = Graphic3d_BT_RGB;
4139 else if ( strcasecmp( aParam, "hls" ) == 0 )
4141 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4142 aBufferType = Graphic3d_BT_RGB;
4143 toShowHls = Standard_True;
4145 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4147 aFormat = Image_PixMap::ImgRGBF;
4148 aBufferType = Graphic3d_BT_RGB;
4150 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4152 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4153 aBufferType = Graphic3d_BT_RGBA;
4155 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4157 aFormat = Image_PixMap::ImgRGBAF;
4158 aBufferType = Graphic3d_BT_RGBA;
4160 else if ( strcasecmp( aParam, "depth" ) == 0 )
4162 aFormat = Image_PixMap::ImgGrayF;
4163 aBufferType = Graphic3d_BT_Depth;
4165 else if ( strcasecmp( aParam, "name" ) == 0 )
4167 toShowName = Standard_True;
4171 Image_PixMap anImage;
4172 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4174 std::cerr << "Image allocation failed\n";
4177 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4179 std::cerr << "Image dump failed\n";
4183 Quantity_Parameter anAlpha;
4184 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4187 if (aBufferType == Graphic3d_BT_RGBA)
4189 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
4193 theDI << Quantity_Color::StringName (aColor.Name());
4198 switch (aBufferType)
4201 case Graphic3d_BT_RGB:
4205 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
4209 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
4213 case Graphic3d_BT_RGBA:
4215 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
4218 case Graphic3d_BT_Depth:
4220 theDI << aColor.Red();
4229 //==============================================================================
4230 //function : VDiffImage
4231 //purpose : The draw-command compares two images.
4232 //==============================================================================
4234 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4238 theDI << "Not enough arguments.\n";
4243 const char* anImgPathRef = theArgVec[1];
4244 const char* anImgPathNew = theArgVec[2];
4246 // get string tolerance and check its validity
4247 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4248 if (aTolColor < 0.0)
4250 if (aTolColor > 1.0)
4253 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4254 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4256 // image file of difference
4257 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4259 // compare the images
4260 Image_Diff aComparer;
4261 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4266 aComparer.SetColorTolerance (aTolColor);
4267 aComparer.SetBorderFilterOn (isBorderFilterOn);
4268 Standard_Integer aDiffColorsNb = aComparer.Compare();
4269 theDI << aDiffColorsNb << "\n";
4271 // save image of difference
4272 if (aDiffImagePath != NULL)
4274 aComparer.SaveDiffImage (aDiffImagePath);
4280 //=======================================================================
4281 //function : VSelect
4282 //purpose : Emulates different types of selection by mouse:
4283 // 1) single click selection
4284 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4285 // 3) selection with polygon having corners at
4286 // pixel positions (x1,y1),...,(xn,yn)
4287 // 4) any of these selections with shift button pressed
4288 //=======================================================================
4289 static Standard_Integer VSelect (Draw_Interpretor& di,
4290 Standard_Integer argc,
4295 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4299 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4300 if(myAIScontext.IsNull())
4302 di << "use 'vinit' command before " << argv[0] << "\n";
4305 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4306 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4307 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4310 if(isShiftSelection)
4311 aCurrentEventManager->ShiftSelect();
4313 aCurrentEventManager->Select();
4317 if(isShiftSelection)
4318 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4320 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4324 Standard_Integer anUpper = 0;
4326 if(isShiftSelection)
4327 anUpper = (argc-1)/2;
4330 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4332 for(Standard_Integer i=1;i<=anUpper;++i)
4333 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4335 if(isShiftSelection)
4336 aCurrentEventManager->ShiftSelect(aPolyline);
4338 aCurrentEventManager->Select(aPolyline);
4343 //=======================================================================
4344 //function : VMoveTo
4345 //purpose : Emulates cursor movement to defined pixel position
4346 //=======================================================================
4347 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4348 Standard_Integer argc,
4353 di << "Usage : " << argv[0] << " x y" << "\n";
4357 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4358 if(aContext.IsNull())
4360 di << "use 'vinit' command before " << argv[0] << "\n";
4363 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4367 //=================================================================================================
4368 //function : VViewParams
4369 //purpose : Gets or sets AIS View characteristics
4370 //=================================================================================================
4371 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4373 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
4374 if (anAISView.IsNull())
4376 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
4382 // print all of the available view parameters
4383 Quantity_Factor anAISViewScale = anAISView->Scale();
4385 Standard_Real anAISViewProjX = 0.0;
4386 Standard_Real anAISViewProjY = 0.0;
4387 Standard_Real anAISViewProjZ = 0.0;
4388 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4390 Standard_Real anAISViewUpX = 0.0;
4391 Standard_Real anAISViewUpY = 0.0;
4392 Standard_Real anAISViewUpZ = 0.0;
4393 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4395 Standard_Real anAISViewAtX = 0.0;
4396 Standard_Real anAISViewAtY = 0.0;
4397 Standard_Real anAISViewAtZ = 0.0;
4398 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4400 Standard_Real anAISViewEyeX = 0.0;
4401 Standard_Real anAISViewEyeY = 0.0;
4402 Standard_Real anAISViewEyeZ = 0.0;
4403 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
4405 theDi << "Scale of current view: " << anAISViewScale << "\n";
4406 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4407 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4408 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4409 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
4413 // -------------------------
4414 // Parse options and values
4415 // -------------------------
4417 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
4418 TCollection_AsciiString aParseKey;
4419 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4421 TCollection_AsciiString anArg (theArgVec [anArgIt]);
4423 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4426 aParseKey.Remove (1);
4427 aParseKey.UpperCase();
4428 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4432 if (aParseKey.IsEmpty())
4434 std::cout << theArgVec[0] << ": values should be passed with key.\n";
4435 std::cout << "Type help for more information.\n";
4439 aMapOfKeysByValues(aParseKey)->Append (anArg);
4442 // ---------------------------------------------
4443 // Change or print parameters, order plays role
4444 // ---------------------------------------------
4446 // Check arguments for validity
4447 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
4448 for (; aMapIt.More(); aMapIt.Next())
4450 const TCollection_AsciiString& aKey = aMapIt.Key();
4451 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
4453 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
4454 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
4455 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
4456 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
4457 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
4458 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
4459 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
4461 TCollection_AsciiString aLowerKey;
4464 aLowerKey.LowerCase();
4465 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
4466 std::cout << "Type help for more information.\n";
4471 Handle(TColStd_HSequenceOfAsciiString) aValues;
4473 // Change view parameters in proper order
4474 if (aMapOfKeysByValues.Find ("SCALE", aValues))
4476 if (aValues->IsEmpty())
4478 theDi << "Scale: " << anAISView->Scale() << "\n";
4482 anAISView->SetScale (aValues->Value(1).RealValue());
4485 if (aMapOfKeysByValues.Find ("SIZE", aValues))
4487 if (aValues->IsEmpty())
4489 Standard_Real aSizeX = 0.0;
4490 Standard_Real aSizeY = 0.0;
4491 anAISView->Size (aSizeX, aSizeY);
4492 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
4496 anAISView->SetSize (aValues->Value(1).RealValue());
4499 if (aMapOfKeysByValues.Find ("EYE", aValues))
4501 if (aValues->IsEmpty())
4503 Standard_Real anEyeX = 0.0;
4504 Standard_Real anEyeY = 0.0;
4505 Standard_Real anEyeZ = 0.0;
4506 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
4507 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
4511 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4514 if (aMapOfKeysByValues.Find ("AT", aValues))
4516 if (aValues->IsEmpty())
4518 Standard_Real anAtX = 0.0;
4519 Standard_Real anAtY = 0.0;
4520 Standard_Real anAtZ = 0.0;
4521 anAISView->At (anAtX, anAtY, anAtZ);
4522 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
4526 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4529 if (aMapOfKeysByValues.Find ("PROJ", aValues))
4531 if (aValues->IsEmpty())
4533 Standard_Real aProjX = 0.0;
4534 Standard_Real aProjY = 0.0;
4535 Standard_Real aProjZ = 0.0;
4536 anAISView->Proj (aProjX, aProjY, aProjZ);
4537 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
4541 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4544 if (aMapOfKeysByValues.Find ("UP", aValues))
4546 if (aValues->IsEmpty())
4548 Standard_Real anUpX = 0.0;
4549 Standard_Real anUpY = 0.0;
4550 Standard_Real anUpZ = 0.0;
4551 anAISView->Up (anUpX, anUpY, anUpZ);
4552 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
4556 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4559 if (aMapOfKeysByValues.Find ("CENTER", aValues))
4561 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
4567 //=======================================================================
4568 //function : VChangeSelected
4569 //purpose : Adds the shape to selection or remove one from it
4570 //=======================================================================
4571 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4572 Standard_Integer argc,
4577 di<<"Usage : " << argv[0] << " shape \n";
4581 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4582 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4583 TCollection_AsciiString aName(argv[1]);
4584 Handle(AIS_InteractiveObject) anAISObject;
4586 if(!aMap.IsBound2(aName))
4588 di<<"Use 'vdisplay' before";
4593 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4594 if(anAISObject.IsNull()){
4595 di<<"No interactive object \n";
4599 if(aContext->HasOpenedContext())
4601 aContext->AddOrRemoveSelected(anAISObject);
4605 aContext->AddOrRemoveCurrentObject(anAISObject);
4611 //=======================================================================
4612 //function : VZClipping
4613 //purpose : Gets or sets ZClipping mode, width and depth
4614 //=======================================================================
4615 static Standard_Integer VZClipping (Draw_Interpretor& di,
4616 Standard_Integer argc,
4621 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4622 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4625 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4626 if(aContext.IsNull())
4628 di << "use 'vinit' command before " << argv[0] << "\n";
4631 Handle(V3d_View) aView = ViewerTest::CurrentView();
4632 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4635 TCollection_AsciiString aZClippingModeString;
4636 Quantity_Length aDepth, aWidth;
4637 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4638 switch (aZClippingMode)
4641 aZClippingModeString.Copy("OFF");
4644 aZClippingModeString.Copy("BACK");
4647 aZClippingModeString.Copy("FRONT");
4650 aZClippingModeString.Copy("SLICE");
4653 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4656 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4657 << "ZClipping depth = " << aDepth << "\n"
4658 << "ZClipping width = " << aWidth << "\n";
4664 Standard_Integer aStatus = 0;
4665 if ( strcmp (argv [1], "OFF") == 0 ) {
4667 aZClippingMode = V3d_OFF;
4669 if ( strcmp (argv [1], "BACK") == 0 ) {
4671 aZClippingMode = V3d_BACK;
4673 if ( strcmp (argv [1], "FRONT") == 0 ) {
4675 aZClippingMode = V3d_FRONT;
4677 if ( strcmp (argv [1], "SLICE") == 0 ) {
4679 aZClippingMode = V3d_SLICE;
4683 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4684 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4687 aView->SetZClippingType(aZClippingMode);
4691 Quantity_Length aDepth = 0., aWidth = 1.;
4694 aDepth = atof(argv[1]);
4695 aWidth = atof(argv[2]);
4699 aDepth = atof(argv[2]);
4700 aWidth = atof(argv[3]);
4703 if(aDepth<0. || aDepth>1.)
4705 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4706 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4709 if(aWidth<0. || aWidth>1.)
4711 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4712 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4716 aView->SetZClippingDepth(aDepth);
4717 aView->SetZClippingWidth(aWidth);
4724 //=======================================================================
4725 //function : VNbSelected
4726 //purpose : Returns number of selected objects
4727 //=======================================================================
4728 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4729 Standard_Integer argc,
4734 di << "Usage : " << argv[0] << "\n";
4737 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4738 if(aContext.IsNull())
4740 di << "use 'vinit' command before " << argv[0] << "\n";
4743 di << aContext->NbSelected() << "\n";
4747 //=======================================================================
4748 //function : VAntialiasing
4749 //purpose : Switches altialiasing on or off
4750 //=======================================================================
4751 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4752 Standard_Integer argc,
4757 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4761 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4762 if(aContext.IsNull())
4764 di << "use 'vinit' command before " << argv[0] << "\n";
4768 Handle(V3d_View) aView = ViewerTest::CurrentView();
4770 if((argc == 2) && (atof(argv[1]) == 0))
4771 aView->SetAntialiasingOff();
4773 aView->SetAntialiasingOn();
4778 //=======================================================================
4779 //function : VPurgeDisplay
4780 //purpose : Switches altialiasing on or off
4781 //=======================================================================
4782 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4783 Standard_Integer argc,
4788 di << "Usage : " << argv[0] << "\n";
4791 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4792 if (aContext.IsNull())
4794 di << "use 'vinit' command before " << argv[0] << "\n";
4797 aContext->CloseAllContexts(Standard_False);
4798 di << aContext->PurgeDisplay() << "\n";
4802 //=======================================================================
4803 //function : VSetViewSize
4805 //=======================================================================
4806 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4807 Standard_Integer argc,
4810 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4811 if(aContext.IsNull())
4813 di << "use 'vinit' command before " << argv[0] << "\n";
4818 di<<"Usage : " << argv[0] << " Size\n";
4821 Standard_Real aSize = atof(argv[1]);
4824 di<<"Bad Size value : " << aSize << "\n";
4828 Handle(V3d_View) aView = ViewerTest::CurrentView();
4829 aView->SetSize(aSize);
4833 //=======================================================================
4834 //function : VMoveView
4836 //=======================================================================
4837 static Standard_Integer VMoveView (Draw_Interpretor& di,
4838 Standard_Integer argc,
4841 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4842 if(aContext.IsNull())
4844 di << "use 'vinit' command before " << argv[0] << "\n";
4847 if(argc < 4 || argc > 5)
4849 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4852 Standard_Real Dx = atof(argv[1]);
4853 Standard_Real Dy = atof(argv[2]);
4854 Standard_Real Dz = atof(argv[3]);
4855 Standard_Boolean aStart = Standard_True;
4858 aStart = (atoi(argv[4]) > 0);
4861 Handle(V3d_View) aView = ViewerTest::CurrentView();
4862 aView->Move(Dx,Dy,Dz,aStart);
4866 //=======================================================================
4867 //function : VTranslateView
4869 //=======================================================================
4870 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4871 Standard_Integer argc,
4874 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4875 if(aContext.IsNull())
4877 di << "use 'vinit' command before " << argv[0] << "\n";
4880 if(argc < 4 || argc > 5)
4882 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4885 Standard_Real Dx = atof(argv[1]);
4886 Standard_Real Dy = atof(argv[2]);
4887 Standard_Real Dz = atof(argv[3]);
4888 Standard_Boolean aStart = Standard_True;
4891 aStart = (atoi(argv[4]) > 0);
4894 Handle(V3d_View) aView = ViewerTest::CurrentView();
4895 aView->Translate(Dx,Dy,Dz,aStart);
4899 //=======================================================================
4900 //function : VTurnView
4902 //=======================================================================
4903 static Standard_Integer VTurnView (Draw_Interpretor& di,
4904 Standard_Integer argc,
4907 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4908 if(aContext.IsNull()) {
4909 di << "use 'vinit' command before " << argv[0] << "\n";
4912 if(argc < 4 || argc > 5){
4913 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4916 Standard_Real Ax = atof(argv[1]);
4917 Standard_Real Ay = atof(argv[2]);
4918 Standard_Real Az = atof(argv[3]);
4919 Standard_Boolean aStart = Standard_True;
4922 aStart = (atoi(argv[4]) > 0);
4925 Handle(V3d_View) aView = ViewerTest::CurrentView();
4926 aView->Turn(Ax,Ay,Az,aStart);
4930 //==============================================================================
4931 //function : VTextureEnv
4932 //purpose : ENables or disables environment mapping
4933 //==============================================================================
4934 class OCC_TextureEnv : public Graphic3d_TextureEnv
4937 OCC_TextureEnv(const Standard_CString FileName);
4938 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4939 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4940 const Standard_Boolean theModulateFlag,
4941 const Graphic3d_TypeOfTextureFilter theFilter,
4942 const Standard_ShortReal theXScale,
4943 const Standard_ShortReal theYScale,
4944 const Standard_ShortReal theXShift,
4945 const Standard_ShortReal theYShift,
4946 const Standard_ShortReal theAngle);
4947 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4949 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4950 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4951 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4953 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4954 : Graphic3d_TextureEnv(theFileName)
4958 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4959 : Graphic3d_TextureEnv(theTexId)
4963 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4964 const Standard_Boolean theModulateFlag,
4965 const Graphic3d_TypeOfTextureFilter theFilter,
4966 const Standard_ShortReal theXScale,
4967 const Standard_ShortReal theYScale,
4968 const Standard_ShortReal theXShift,
4969 const Standard_ShortReal theYShift,
4970 const Standard_ShortReal theAngle)
4972 myParams->SetRepeat (theRepeatFlag);
4973 myParams->SetModulate (theModulateFlag);
4974 myParams->SetFilter (theFilter);
4975 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
4976 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4977 myParams->SetRotation (theAngle);
4980 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4982 // get the active view
4983 Handle(V3d_View) aView = ViewerTest::CurrentView();
4986 std::cerr << "No active view. Please call vinit.\n";
4990 // Checking the input arguments
4991 Standard_Boolean anEnableFlag = Standard_False;
4992 Standard_Boolean isOk = theArgNb >= 2;
4995 TCollection_AsciiString anEnableOpt(theArgVec[1]);
4996 anEnableFlag = anEnableOpt.IsEqual("on");
4997 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
5001 isOk = (theArgNb == 3 || theArgNb == 11);
5004 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5005 isOk = (!aTextureOpt.IsIntegerValue() ||
5006 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
5008 if (isOk && theArgNb == 11)
5010 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
5011 aModulateOpt(theArgVec[4]),
5012 aFilterOpt (theArgVec[5]),
5013 aSScaleOpt (theArgVec[6]),
5014 aTScaleOpt (theArgVec[7]),
5015 aSTransOpt (theArgVec[8]),
5016 aTTransOpt (theArgVec[9]),
5017 anAngleOpt (theArgVec[10]);
5018 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
5019 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
5020 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
5021 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
5022 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
5023 anAngleOpt.IsRealValue());
5030 std::cerr << "Usage :" << std::endl;
5031 std::cerr << theArgVec[0] << " off" << std::endl;
5032 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;
5038 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5039 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
5040 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
5041 new OCC_TextureEnv(theArgVec[2]);
5045 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
5046 aTexEnv->SetTextureParameters(
5047 aRepeatOpt. IsEqual("repeat"),
5048 aModulateOpt.IsEqual("modulate"),
5049 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
5050 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
5051 Graphic3d_TOTF_TRILINEAR,
5052 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
5053 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
5054 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
5055 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
5056 (Standard_ShortReal)Draw::Atof(theArgVec[10])
5059 aView->SetTextureEnv(aTexEnv);
5060 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
5062 else // Disabling environment mapping
5064 aView->SetSurfaceDetail(V3d_TEX_NONE);
5065 Handle(Graphic3d_TextureEnv) aTexture;
5066 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
5073 //===============================================================================================
5074 //function : VClipPlane
5076 //===============================================================================================
5077 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5079 // use short-cut for created clip planes map of created (or "registered by name") clip planes
5080 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
5081 static MapOfPlanes aRegPlanes;
5085 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
5089 TCollection_AsciiString aCommand (theArgVec[1]);
5091 // print maximum number of planes for current viewer
5092 if (aCommand == "maxplanes")
5096 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
5100 TCollection_AsciiString aViewName (theArgVec[2]);
5102 if (!ViewerTest_myViews.IsBound1 (aViewName))
5104 theDi << theArgVec[0] << ": view is not found.\n";
5108 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5110 theDi << theArgVec[0] << ": "
5111 << aView->Viewer()->Driver()->InquirePlaneLimit()
5112 << " plane slots provided by driver."
5113 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
5118 // create / delete plane instance
5119 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
5123 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
5127 Standard_Boolean toCreate = (aCommand == "create");
5128 Standard_Boolean toClone = (aCommand == "clone");
5129 TCollection_AsciiString aPlane (theArgVec[2]);
5133 if (aRegPlanes.IsBound (aPlane))
5135 theDi << theArgVec[0] << ": plane name is in use.\n";
5139 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
5141 else if (toClone) // toClone
5143 if (!aRegPlanes.IsBound (aPlane))
5145 theDi << theArgVec[0] << ": no such plane.\n";
5151 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
5155 TCollection_AsciiString aClone (theArgVec[3]);
5156 if (aRegPlanes.IsBound (aClone))
5158 theDi << theArgVec[0] << ": plane name is in use.\n";
5162 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5164 aRegPlanes.Bind (aClone, aClipPlane->Clone());
5168 if (!aRegPlanes.IsBound (aPlane))
5170 theDi << theArgVec[0] << ": no such plane.\n";
5174 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
5175 aRegPlanes.UnBind (aPlane);
5177 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
5178 for (; anIObjIt.More(); anIObjIt.Next())
5180 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
5181 aPrs->RemoveClipPlane(aClipPlane);
5184 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
5185 for (; aViewIt.More(); aViewIt.Next())
5187 const Handle(V3d_View)& aView = aViewIt.Key2();
5188 aView->RemoveClipPlane(aClipPlane);
5191 ViewerTest::RedrawAllViews();
5197 // set / unset plane command
5198 if (aCommand == "set" || aCommand == "unset")
5202 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5206 Standard_Boolean toSet = (aCommand == "set");
5207 TCollection_AsciiString aPlane (theArgVec [2]);
5208 if (!aRegPlanes.IsBound (aPlane))
5210 theDi << theArgVec[0] << ": no such plane.\n";
5214 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5216 TCollection_AsciiString aTarget (theArgVec [3]);
5217 if (aTarget != "object" && aTarget != "view")
5219 theDi << theArgVec[0] << ": invalid target.\n";
5223 if (aTarget == "object" || aTarget == "view")
5227 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5231 Standard_Boolean isObject = (aTarget == "object");
5233 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
5235 TCollection_AsciiString anEntityName (theArgVec[anIt]);
5236 if (isObject) // to object
5238 if (!GetMapOfAIS().IsBound2 (anEntityName))
5240 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
5244 Handle(AIS_InteractiveObject) aIObj =
5245 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
5248 aIObj->AddClipPlane (aClipPlane);
5250 aIObj->RemoveClipPlane (aClipPlane);
5254 if (!ViewerTest_myViews.IsBound1 (anEntityName))
5256 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
5260 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
5262 aView->AddClipPlane (aClipPlane);
5264 aView->RemoveClipPlane (aClipPlane);
5268 ViewerTest::RedrawAllViews();
5274 // change plane command
5275 if (aCommand == "change")
5279 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5283 TCollection_AsciiString aPlane (theArgVec [2]);
5284 if (!aRegPlanes.IsBound (aPlane))
5286 theDi << theArgVec[0] << ": no such plane.\n";
5290 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5292 TCollection_AsciiString aChangeArg (theArgVec [3]);
5293 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5295 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5299 if (aChangeArg == "on" || aChangeArg == "off") // on / off
5301 aClipPlane->SetOn (aChangeArg == "on");
5303 else if (aChangeArg == "equation") // change equation
5307 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5311 Standard_Real aCoeffA = atof (theArgVec [4]);
5312 Standard_Real aCoeffB = atof (theArgVec [5]);
5313 Standard_Real aCoeffC = atof (theArgVec [6]);
5314 Standard_Real aCoeffD = atof (theArgVec [7]);
5315 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5317 else if (aChangeArg == "capping") // change capping aspects
5321 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5325 TCollection_AsciiString aCappingArg (theArgVec [4]);
5326 if (aCappingArg != "on" && aCappingArg != "off" &&
5327 aCappingArg != "color" && aCappingArg != "texname" &&
5328 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5329 aCappingArg != "texrotate" && aCappingArg != "hatch")
5331 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5335 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5337 aClipPlane->SetCapping (aCappingArg == "on");
5339 else if (aCappingArg == "color") // color aspect for capping
5343 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5347 Standard_Real aRed = atof (theArgVec [5]);
5348 Standard_Real aGrn = atof (theArgVec [6]);
5349 Standard_Real aBlu = atof (theArgVec [7]);
5351 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5352 aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
5353 aClipPlane->SetCappingMaterial (aMat);
5355 else if (aCappingArg == "texname") // texture name
5359 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5363 TCollection_AsciiString aTextureName (theArgVec [5]);
5365 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5366 if (!aTexture->IsDone ())
5368 aClipPlane->SetCappingTexture (NULL);
5372 aTexture->EnableModulate();
5373 aTexture->EnableRepeat();
5374 aClipPlane->SetCappingTexture (aTexture);
5377 else if (aCappingArg == "texscale") // texture scale
5379 if (aClipPlane->CappingTexture().IsNull())
5381 theDi << theArgVec[0] << ": no texture is set.\n";
5387 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5391 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5392 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5394 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5396 else if (aCappingArg == "texorigin") // texture origin
5398 if (aClipPlane->CappingTexture().IsNull())
5400 theDi << theArgVec[0] << ": no texture is set.\n";
5406 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5410 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5411 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5413 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5415 else if (aCappingArg == "texrotate") // texture rotation
5417 if (aClipPlane->CappingTexture().IsNull())
5419 theDi << theArgVec[0] << ": no texture is set.\n";
5425 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5429 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5431 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5433 else if (aCappingArg == "hatch") // hatch style
5437 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5441 TCollection_AsciiString aHatchStr (theArgVec [5]);
5442 if (aHatchStr == "on")
5444 aClipPlane->SetCappingHatchOn();
5446 else if (aHatchStr == "off")
5448 aClipPlane->SetCappingHatchOff();
5452 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5457 ViewerTest::RedrawAllViews();
5462 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5466 //===============================================================================================
5467 //function : VSetTextureMode
5469 //===============================================================================================
5470 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5474 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5478 TCollection_AsciiString aViewName (theArgVec[1]);
5479 if (!ViewerTest_myViews.IsBound1 (aViewName))
5481 theDi << theArgVec[0] << ": view is not found.\n";
5485 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5486 switch (atoi (theArgVec[2]))
5488 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5489 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5490 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5492 theDi << theArgVec[0] << ": invalid mode.\n";
5500 //===============================================================================================
5501 //function : VZRange
5503 //===============================================================================================
5504 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5506 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
5508 if (aCurrentView.IsNull())
5510 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
5514 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
5518 theDi << "ZNear: " << aCamera->ZNear() << "\n";
5519 theDi << "ZFar: " << aCamera->ZFar() << "\n";
5525 Standard_Real aNewZNear = atof (theArgVec[1]);
5526 Standard_Real aNewZFar = atof (theArgVec[2]);
5528 if (aNewZNear >= aNewZFar)
5530 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
5534 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
5536 std::cout << theArgVec[0] << ": invalid arguments: ";
5537 std::cout << "znear, zfar should be positive for perspective camera.\n";
5541 aCamera->SetZRange (aNewZNear, aNewZFar);
5545 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
5549 aCurrentView->Redraw();
5554 //===============================================================================================
5555 //function : VAutoZFit
5557 //===============================================================================================
5558 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5560 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
5562 if (aCurrentView.IsNull())
5564 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
5568 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
5572 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
5578 theDi << "Auto z-fit mode: " << "\n"
5579 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
5580 << "Scale: " << aScale << "\n";
5584 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
5588 aScale = Draw::Atoi (theArgVec[2]);
5591 aCurrentView->SetAutoZFitMode (isOn, aScale);
5592 aCurrentView->AutoZFit();
5593 aCurrentView->Redraw();
5598 //===============================================================================================
5599 //function : VChangeCamera
5601 //===============================================================================================
5602 static int VChangeCamera (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5604 if (ViewerTest::CurrentView().IsNull())
5606 theDi << theArgVec[0] << ": Call vinit before this command, please.\n";
5610 const char anErrorMessage[] = ": wrong command arguments. Type help for more information.\n";
5613 theDi << theArgVec[0] << anErrorMessage;
5617 Handle(Graphic3d_Camera) aCamera = ViewerTest::CurrentView()->Camera();
5619 TCollection_AsciiString aCommand (theArgVec[1]);
5620 TCollection_AsciiString aValue (theArgVec[2]);
5622 aCommand.LowerCase();
5625 if (aCommand == "proj")
5627 if (aValue == "ortho")
5629 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
5631 else if (aValue == "persp")
5633 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
5635 else if (aValue == "left")
5637 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
5639 else if (aValue == "right")
5641 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
5643 else if (aValue == "stereo")
5645 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
5649 theDi << theArgVec[0] << anErrorMessage;
5653 else if (aCommand == "dist")
5655 aCamera->SetDistance (aValue.RealValue());
5657 else if (aCommand == "iod")
5659 aCamera->SetIOD (aCamera->GetIODType(), aValue.RealValue());
5661 else if (aCommand == "zfocus")
5663 aCamera->SetZFocus (aCamera->ZFocusType(), aValue.RealValue());
5665 else if (aCommand == "fov")
5667 aCamera->SetFOVy (aValue.RealValue());
5669 else if (aCommand == "zfocustype")
5671 if (aValue == "absolute")
5673 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
5675 else if (aValue == "relative")
5677 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
5681 theDi << theArgVec[0] << anErrorMessage;
5685 else if (aCommand == "iodtype")
5687 if (aValue == "absolute")
5689 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
5691 else if (aValue == "relative")
5693 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
5697 theDi << theArgVec[0] << anErrorMessage;
5703 theDi << theArgVec[0] << anErrorMessage;
5707 ViewerTest::CurrentView()->AutoZFit();
5708 ViewerTest::CurrentView()->Redraw();
5713 //==============================================================================
5714 //function : VStereo
5716 //==============================================================================
5718 static int VStereo (Draw_Interpretor& theDI,
5719 Standard_Integer theArgNb,
5720 const char** theArgVec)
5724 Handle(V3d_View) aView = ViewerTest::CurrentView();
5727 std::cerr << "No active view. Please call vinit.\n";
5731 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
5732 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
5736 ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0;
5740 //===============================================================================================
5741 //function : VDefaults
5743 //===============================================================================================
5744 static int VDefaults (Draw_Interpretor& theDi,
5745 Standard_Integer theArgsNb,
5746 const char** theArgVec)
5748 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5751 std::cerr << "No active viewer!\n";
5755 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
5758 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
5760 theDi << "DeflType: relative\n"
5761 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
5765 theDi << "DeflType: absolute\n"
5766 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
5768 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
5772 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5774 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5775 TCollection_AsciiString aKey, aValue;
5776 if (!ViewerTest::SplitParameter (anArg, aKey, aValue)
5777 || aValue.IsEmpty())
5779 std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
5784 if (aKey == "ABSDEFL"
5785 || aKey == "ABSOLUTEDEFLECTION"
5787 || aKey == "DEFLECTION")
5789 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
5790 aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
5792 else if (aKey == "RELDEFL"
5793 || aKey == "RELATIVEDEFLECTION"
5794 || aKey == "DEVCOEFF"
5795 || aKey == "DEVIATIONCOEFF"
5796 || aKey == "DEVIATIONCOEFFICIENT")
5798 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
5799 aDefParams->SetDeviationCoefficient (aValue.RealValue());
5801 else if (aKey == "ANGDEFL"
5802 || aKey == "ANGULARDEFL"
5803 || aKey == "ANGULARDEFLECTION")
5805 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
5806 aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
5810 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
5817 //! Auxiliary method
5818 inline void addLight (const Handle(V3d_Light)& theLightNew,
5819 const Standard_Boolean theIsGlobal)
5821 if (theLightNew.IsNull())
5828 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
5832 ViewerTest::CurrentView()->SetLightOn (theLightNew);
5836 //! Auxiliary method
5837 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
5839 TCollection_AsciiString anArgNextCase (theArgNext);
5840 anArgNextCase.UpperCase();
5841 if (anArgNextCase.Length() > 5
5842 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
5844 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
5848 return theArgNext.IntegerValue();
5852 //===============================================================================================
5855 //===============================================================================================
5856 static int VLight (Draw_Interpretor& theDi,
5857 Standard_Integer theArgsNb,
5858 const char** theArgVec)
5860 Handle(V3d_View) aView = ViewerTest::CurrentView();
5861 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5863 || aViewer.IsNull())
5865 std::cerr << "No active viewer!\n";
5869 Standard_Real anXYZ[3];
5870 Quantity_Coefficient anAtten[2];
5873 // print lights info
5874 Standard_Integer aLightId = 0;
5875 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
5877 Handle(V3d_Light) aLight = aView->ActiveLight();
5878 const Quantity_Color aColor = aLight->Color();
5879 theDi << "Light" << aLightId << "\n";
5880 switch (aLight->Type())
5884 theDi << " Type: Ambient\n";
5887 case V3d_DIRECTIONAL:
5889 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
5890 theDi << " Type: Directional\n";
5891 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5892 if (!aLightDir.IsNull())
5894 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5895 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5896 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
5897 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5901 case V3d_POSITIONAL:
5903 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
5904 theDi << " Type: Positional\n";
5905 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5906 if (!aLightPos.IsNull())
5908 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5909 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5910 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5911 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
5917 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
5918 theDi << " Type: Spot\n";
5919 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5920 if (!aLightSpot.IsNull())
5922 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5923 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5924 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
5925 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5926 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5927 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
5928 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
5929 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
5935 theDi << " Type: UNKNOWN\n";
5939 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
5943 Handle(V3d_Light) aLightNew;
5944 Handle(V3d_Light) aLightOld;
5945 Standard_Boolean isGlobal = Standard_True;
5946 Standard_Boolean toCreate = Standard_False;
5947 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5949 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
5950 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
5951 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
5952 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
5953 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
5955 TCollection_AsciiString aName, aValue;
5956 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
5957 TCollection_AsciiString anArgCase (anArg);
5958 anArgCase.UpperCase();
5959 if (anArgCase.IsEqual ("NEW")
5960 || anArgCase.IsEqual ("ADD")
5961 || anArgCase.IsEqual ("CREATE"))
5963 toCreate = Standard_True;
5965 else if (anArgCase.IsEqual ("GLOB")
5966 || anArgCase.IsEqual ("GLOBAL"))
5968 isGlobal = Standard_True;
5970 else if (anArgCase.IsEqual ("LOC")
5971 || anArgCase.IsEqual ("LOCAL"))
5973 isGlobal = Standard_False;
5975 else if (anArgCase.IsEqual ("DEF")
5976 || anArgCase.IsEqual ("DEFAULTS"))
5978 toCreate = Standard_False;
5979 aViewer->SetDefaultLights();
5981 else if (anArgCase.IsEqual ("CLR")
5982 || anArgCase.IsEqual ("CLEAR"))
5984 toCreate = Standard_False;
5985 aView->InitActiveLights();
5986 while (aView->MoreActiveLights())
5988 aViewer->DelLight (aView->ActiveLight());
5989 aView->InitActiveLights();
5992 else if (anArgCase.IsEqual ("AMB")
5993 || anArgCase.IsEqual ("AMBIENT")
5994 || anArgCase.IsEqual ("AMBLIGHT"))
5996 addLight (aLightNew, isGlobal);
5999 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6002 toCreate = Standard_False;
6003 aLightNew = new V3d_AmbientLight (aViewer);
6005 else if (anArgCase.IsEqual ("DIRECTIONAL")
6006 || anArgCase.IsEqual ("DIRLIGHT"))
6008 addLight (aLightNew, isGlobal);
6011 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6014 toCreate = Standard_False;
6015 aLightNew = new V3d_DirectionalLight (aViewer);
6017 else if (anArgCase.IsEqual ("SPOT")
6018 || anArgCase.IsEqual ("SPOTLIGHT"))
6020 addLight (aLightNew, isGlobal);
6023 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6026 toCreate = Standard_False;
6027 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
6029 else if (anArgCase.IsEqual ("POSLIGHT")
6030 || anArgCase.IsEqual ("POSITIONAL"))
6032 addLight (aLightNew, isGlobal);
6035 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6038 toCreate = Standard_False;
6039 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
6041 else if (anArgCase.IsEqual ("CHANGE"))
6043 addLight (aLightNew, isGlobal);
6044 aLightNew.Nullify();
6045 if (++anArgIt >= theArgsNb)
6047 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6051 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
6052 Standard_Integer aLightIt = 0;
6053 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6055 if (aLightIt == aLightId)
6057 aLightOld = aView->ActiveLight();
6062 if (aLightOld.IsNull())
6064 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
6068 else if (anArgCase.IsEqual ("DEL")
6069 || anArgCase.IsEqual ("DELETE"))
6071 Handle(V3d_Light) aLightDel;
6072 if (++anArgIt >= theArgsNb)
6074 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6078 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6079 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
6080 Standard_Integer aLightIt = 0;
6081 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6083 aLightDel = aView->ActiveLight();
6084 if (aLightIt == aLightDelId)
6089 if (!aLightDel.IsNull())
6091 aViewer->DelLight (aLightDel);
6094 else if (anArgCase.IsEqual ("COLOR")
6095 || anArgCase.IsEqual ("COLOUR"))
6097 if (++anArgIt >= theArgsNb)
6099 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6103 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6104 anArgNext.UpperCase();
6105 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
6106 if (!aLightCurr.IsNull())
6108 aLightCurr->SetColor (aColor);
6111 else if (anArgCase.IsEqual ("POS")
6112 || anArgCase.IsEqual ("POSITION"))
6114 if ((anArgIt + 3) >= theArgsNb)
6116 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6120 anXYZ[0] = Atof (theArgVec[++anArgIt]);
6121 anXYZ[1] = Atof (theArgVec[++anArgIt]);
6122 anXYZ[2] = Atof (theArgVec[++anArgIt]);
6123 if (!aLightDir.IsNull())
6125 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6127 else if (!aLightPos.IsNull())
6129 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6131 else if (!aLightSpot.IsNull())
6133 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6137 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6141 else if (anArgCase.IsEqual ("DIR")
6142 || anArgCase.IsEqual ("DIRECTION"))
6144 if ((anArgIt + 3) >= theArgsNb)
6146 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6150 anXYZ[0] = Atof (theArgVec[++anArgIt]);
6151 anXYZ[1] = Atof (theArgVec[++anArgIt]);
6152 anXYZ[2] = Atof (theArgVec[++anArgIt]);
6153 if (!aLightDir.IsNull())
6155 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
6157 else if (!aLightSpot.IsNull())
6159 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
6163 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6167 else if (anArgCase.IsEqual ("ANG")
6168 || anArgCase.IsEqual ("ANGLE"))
6170 if (++anArgIt >= theArgsNb)
6172 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6176 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
6178 if (!aLightSpot.IsNull())
6180 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
6183 else if (anArgCase.IsEqual ("CONSTATTEN")
6184 || anArgCase.IsEqual ("CONSTATTENUATION"))
6186 if (++anArgIt >= theArgsNb)
6188 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6192 if (!aLightPos.IsNull())
6194 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6195 anAtten[0] = Atof (theArgVec[anArgIt]);
6196 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
6198 else if (!aLightSpot.IsNull())
6200 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6201 anAtten[0] = Atof (theArgVec[anArgIt]);
6202 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
6206 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6210 else if (anArgCase.IsEqual ("LINATTEN")
6211 || anArgCase.IsEqual ("LINEARATTEN")
6212 || anArgCase.IsEqual ("LINEARATTENUATION"))
6214 if (++anArgIt >= theArgsNb)
6216 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6220 if (!aLightPos.IsNull())
6222 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6223 anAtten[1] = Atof (theArgVec[anArgIt]);
6224 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
6226 else if (!aLightSpot.IsNull())
6228 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6229 anAtten[1] = Atof (theArgVec[anArgIt]);
6230 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
6234 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6238 else if (anArgCase.IsEqual ("EXP")
6239 || anArgCase.IsEqual ("EXPONENT")
6240 || anArgCase.IsEqual ("SPOTEXP")
6241 || anArgCase.IsEqual ("SPOTEXPONENT"))
6243 if (++anArgIt >= theArgsNb)
6245 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6249 if (!aLightSpot.IsNull())
6251 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
6255 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6259 else if (anArgCase.IsEqual ("HEAD")
6260 || anArgCase.IsEqual ("HEADLIGHT"))
6262 if (++anArgIt >= theArgsNb)
6264 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6268 if (aLightAmb.IsNull()
6269 && !aLightCurr.IsNull())
6271 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
6275 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6281 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
6285 addLight (aLightNew, isGlobal);
6286 aViewer->UpdateLights();
6293 //==============================================================================
6294 //function : VClInfo
6295 //purpose : Prints info about active OpenCL device
6296 //==============================================================================
6298 static Standard_Integer VClInfo (Draw_Interpretor& theDi,
6302 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6303 if (aContextAIS.IsNull())
6305 std::cerr << "Call vinit before!\n";
6309 Handle(OpenGl_GraphicDriver) aDrv = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
6310 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
6311 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> anInfo;
6314 || !aDrv->GetOpenClDeviceInfo (*aCView, anInfo))
6316 theDi << "OpenCL device info is unavailable!\n";
6320 theDi << "OpenCL device info:\n";
6321 for (NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator anIter (anInfo);
6322 anIter.More(); anIter.Next())
6324 theDi << anIter.Key() << ": \t" << anIter.Value() << "\n";
6329 //=======================================================================
6330 //function : VRaytrace
6331 //purpose : Enables/disables OpenCL-based ray-tracing
6332 //=======================================================================
6334 static Standard_Integer VRaytrace (Draw_Interpretor& ,
6335 Standard_Integer theArgNb,
6336 const char** theArgVec)
6338 Handle(V3d_View) aView = ViewerTest::CurrentView();
6341 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
6346 || Draw::Atoi (theArgVec[1]))
6348 aView->SetRaytracingMode();
6352 aView->SetRasterizationMode();
6358 //=======================================================================
6359 //function : VSetRaytraceMode
6360 //purpose : Enables/disables features of OpenCL-based ray-tracing
6361 //=======================================================================
6363 static Standard_Integer VSetRaytraceMode (Draw_Interpretor&,
6364 Standard_Integer theArgNb,
6365 const char ** theArgVec)
6367 Handle(V3d_View) aView = ViewerTest::CurrentView();
6370 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
6373 else if (theArgNb < 2)
6375 std::cerr << "Usage : " << theArgVec[0] << " [shad=0|1] [refl=0|1] [aa=0|1]\n";
6379 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6381 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
6383 if (anArg.Search ("shad=") > -1)
6385 if (anArg.Token ("=", 2).IntegerValue() != 0)
6386 aView->EnableRaytracedShadows();
6388 aView->DisableRaytracedShadows();
6390 else if (anArg.Search ("refl=") > -1)
6392 if (anArg.Token ("=", 2).IntegerValue() != 0)
6393 aView->EnableRaytracedReflections();
6395 aView->DisableRaytracedReflections();
6397 else if (anArg.Search ("aa=") > -1)
6399 if (anArg.Token ("=", 2).IntegerValue() != 0)
6400 aView->EnableRaytracedAntialiasing();
6402 aView->DisableRaytracedAntialiasing();
6406 std::cerr << "Unknown argument: " << anArg << "\n";
6414 //=======================================================================
6415 //function : ViewerCommands
6417 //=======================================================================
6419 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
6422 const char *group = "ZeViewer";
6423 theCommands.Add("vinit",
6424 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
6425 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
6427 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
6429 " - Creates new View window with specified name view_name.\n"
6430 "By default the new view is created in the viewer and in"
6431 " graphic driver shared with active view.\n"
6432 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
6433 "If driverName isn't specified the driver will be shared with active view.\n"
6434 "If viewerName isn't specified the viewer will be shared with active view.\n"
6435 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
6436 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
6437 "is used in creation of graphic driver\n"
6439 " - l, t: pixel position of left top corner of the window\n"
6440 " - w,h: width and heigth of window respectively.\n"
6441 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
6442 __FILE__,VInit,group);
6443 theCommands.Add("vclose" ,
6444 "[view_id [keep_context=0|1]]\n"
6445 "or vclose ALL - to remove all created views\n"
6446 " - removes view(viewer window) defined by its view_id.\n"
6447 " - keep_context: by default 0; if 1 and the last view is deleted"
6448 " the current context is not removed.",
6449 __FILE__,VClose,group);
6450 theCommands.Add("vactivate" ,
6452 " - activates view(viewer window) defined by its view_id",
6453 __FILE__,VActivate,group);
6454 theCommands.Add("vviewlist",
6455 "vviewlist [format={tree, long}]"
6456 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
6457 " - format: format of result output, if tree the output is a tree view;"
6458 "otherwise it's a list of full view names. By default format = tree",
6459 __FILE__,VViewList,group);
6460 theCommands.Add("vhelp" ,
6461 "vhelp : display help on the viewer commands",
6462 __FILE__,VHelp,group);
6463 theCommands.Add("vtop" ,
6464 "vtop or <T> : Top view" ,
6465 __FILE__,VTop,group);
6466 theCommands.Add("vbottom" ,
6467 "vbottom : Bottom view" ,
6468 __FILE__,VBottom,group);
6469 theCommands.Add("vleft" ,
6470 "vleft : Left view" ,
6471 __FILE__,VLeft,group);
6472 theCommands.Add("vright" ,
6473 "vright : Right view" ,
6474 __FILE__,VRight,group);
6475 theCommands.Add("vaxo" ,
6476 " vaxo or <A> : Axonometric view ",
6477 __FILE__,VAxo,group);
6478 theCommands.Add("vfront" ,
6479 "vfront : Front view" ,
6480 __FILE__,VFront,group);
6481 theCommands.Add("vback" ,
6482 "vback : Back view" ,
6483 __FILE__,VBack,group);
6484 theCommands.Add("vpick" ,
6485 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
6487 theCommands.Add("vfit" ,
6488 "vfit or <F> : vfit",
6489 __FILE__,VFit,group);
6490 theCommands.Add ("vzfit", "vzfit [scale]\n"
6491 " Matches Z near, Z far view volume planes to the displayed objects.\n"
6492 " \"scale\" - specifies factor to scale computed z range.\n",
6493 __FILE__, VZFit, group);
6494 theCommands.Add("vrepaint",
6495 "vrepaint : vrepaint, force redraw",
6496 __FILE__,VRepaint,group);
6497 theCommands.Add("vclear",
6499 __FILE__,VClear,group);
6500 theCommands.Add("vsetbg",
6501 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
6502 __FILE__,VSetBg,group);
6503 theCommands.Add("vsetbgmode",
6504 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
6505 __FILE__,VSetBgMode,group);
6506 theCommands.Add("vsetgradientbg",
6507 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
6508 __FILE__,VSetGradientBg,group);
6509 theCommands.Add("vsetgrbgmode",
6510 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
6511 __FILE__,VSetGradientBgMode,group);
6512 theCommands.Add("vsetcolorbg",
6513 "vsetcolorbg : vsetcolorbg r g b : Set background color",
6514 __FILE__,VSetColorBg,group);
6515 theCommands.Add("vscale",
6516 "vscale : vscale X Y Z",
6517 __FILE__,VScale,group);
6518 theCommands.Add("vzbufftrihedron",
6519 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
6520 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
6521 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
6522 __FILE__,VTestZBuffTrihedron,group);
6523 theCommands.Add("vrotate",
6524 "vrotate : vrotate AX AY AZ [X Y Z]",
6525 __FILE__,VRotate,group);
6526 theCommands.Add("vzoom",
6527 "vzoom : vzoom coef",
6528 __FILE__,VZoom,group);
6529 theCommands.Add("vpan",
6530 "vpan : vpan dx dy",
6531 __FILE__,VPan,group);
6532 theCommands.Add("vexport",
6533 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
6534 " : exports the view to a vector file of a given format"
6535 " : notice that EMF format requires patched gl2ps",
6536 __FILE__,VExport,group);
6537 theCommands.Add("vcolorscale",
6538 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
6539 __FILE__,VColorScale,group);
6540 theCommands.Add("vgraduatedtrihedron",
6541 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
6542 __FILE__,VGraduatedTrihedron,group);
6543 theCommands.Add("vprintview" ,
6544 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
6545 __FILE__,VPrintView,group);
6546 theCommands.Add("vzlayer",
6547 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
6548 __FILE__,VZLayer,group);
6549 theCommands.Add("voverlaytext",
6550 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
6551 " : height - pixel height of the text (default=10.0)"
6552 " : font_name - name of font (default=courier)"
6553 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
6554 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
6555 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
6556 __FILE__,VOverlayText,group);
6557 theCommands.Add("vlayerline",
6558 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
6559 __FILE__,VLayerLine,group);
6560 theCommands.Add ("vgrid",
6561 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
6562 " : Mode - rectangular or circular"
6563 " : Type - lines or points",
6564 __FILE__, VGrid, group);
6565 theCommands.Add ("vfps",
6566 "vfps [framesNb=100] : estimate average frame rate for active view",
6567 __FILE__, VFps, group);
6568 theCommands.Add ("vgldebug",
6569 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
6570 " : this function is implemented only for Windows\n"
6571 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
6572 __FILE__, VGlDebug, group);
6573 theCommands.Add ("vvbo",
6574 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
6575 __FILE__, VVbo, group);
6576 theCommands.Add ("vstereo",
6577 "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects",
6578 __FILE__, VStereo, group);
6579 theCommands.Add ("vcaps",
6580 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
6581 __FILE__, VCaps, group);
6582 theCommands.Add ("vmemgpu",
6583 "vmemgpu [f]: print system-dependent GPU memory information if available;"
6584 " with f option returns free memory in bytes",
6585 __FILE__, VMemGpu, group);
6586 theCommands.Add ("vreadpixel",
6587 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
6588 " : Read pixel value for active view",
6589 __FILE__, VReadPixel, group);
6590 theCommands.Add("diffimage",
6591 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
6592 __FILE__, VDiffImage, group);
6593 theCommands.Add ("vselect",
6594 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
6595 "- emulates different types of selection:\n"
6596 "- 1) single click selection\n"
6597 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
6598 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
6599 "- 4) any of these selections with shift button pressed",
6600 __FILE__, VSelect, group);
6601 theCommands.Add ("vmoveto",
6603 "- emulates cursor movement to pixel postion (x,y)",
6604 __FILE__, VMoveTo, group);
6605 theCommands.Add ("vviewparams", "vviewparams usage:\n"
6607 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
6608 " [-proj [x y z]] [-center x y] [-size sx]\n"
6609 "- Gets or sets current view parameters.\n"
6610 "- If called without arguments, all view parameters are printed.\n"
6611 "- The options are:\n"
6612 " -scale [s] : prints or sets viewport relative scale.\n"
6613 " -eye [x y z] : prints or sets eye location.\n"
6614 " -at [x y z] : prints or sets center of look.\n"
6615 " -up [x y z] : prints or sets direction of up vector.\n"
6616 " -proj [x y z] : prints or sets direction of look.\n"
6617 " -center x y : sets location of center of the screen in pixels.\n"
6618 " -size [sx] : prints viewport projection width and height sizes\n"
6619 " : or changes the size of its maximum dimension.\n",
6620 __FILE__, VViewParams, group);
6621 theCommands.Add("vchangeselected",
6622 "vchangeselected shape"
6623 "- adds to shape to selection or remove one from it",
6624 __FILE__, VChangeSelected, group);
6625 theCommands.Add("vzclipping",
6626 "vzclipping [mode] [depth width]\n"
6627 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
6628 "- gets or sets ZClipping mode, width and depth",
6629 __FILE__,VZClipping,group);
6630 theCommands.Add ("vnbselected",
6631 "vnbselected", __FILE__, VNbSelected, group);
6632 theCommands.Add ("vchangecamera",
6633 " changes camera parameters \n"
6634 "- vchangecamera [param_type] [value]\n"
6635 "- vchangecamera proj {ortho/persp/left/right/stereo}\n"
6636 " Projection type including left and right stereo parts.\n"
6637 "- vchangecamera dist [real]\n"
6638 " Sets distance from target point to camera eye (moving eye).\n"
6639 "- vchangecamera iod [real]\n"
6640 " Intraocular distance value.\n"
6641 "- vchangecamera zfocus [real]\n"
6642 " Stereographic focus value.\n"
6643 "- vchangecamera fov [real]\n"
6644 " Field Of View value (in degrees).\n"
6645 "- vchangecamera zfocustype {absolute/relative}\n"
6646 " Stereographic focus definition type (absolute value or coefficient).\n"
6647 "- vchangecamera iodtype {absolute/relative}\n"
6648 " Intraocular distance definition type (absolute value or coefficient).\n",
6649 __FILE__, VChangeCamera, group);
6650 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
6651 "- vautozfit [on={1|0}] [scale]\n"
6652 " Prints or changes parameters of automatic z-fit mode:\n"
6653 " \"on\" - turns automatic z-fit on or off\n"
6654 " \"scale\" - specifies factor to scale computed z range.\n",
6655 __FILE__, VAutoZFit, group);
6656 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
6657 " vzrange - without parameters shows current values\n"
6658 " vzrange [znear] [zfar] - applies provided values to view",
6659 __FILE__,VZRange, group);
6660 theCommands.Add("vantialiasing",
6661 "vantialiasing 1|0",
6662 __FILE__,VAntialiasing,group);
6663 theCommands.Add ("vpurgedisplay",
6665 "- removes structures which don't belong to objects displayed in neutral point",
6666 __FILE__, VPurgeDisplay, group);
6667 theCommands.Add("vsetviewsize",
6668 "vsetviewsize size",
6669 __FILE__,VSetViewSize,group);
6670 theCommands.Add("vmoveview",
6671 "vmoveview Dx Dy Dz [Start = 1|0]",
6672 __FILE__,VMoveView,group);
6673 theCommands.Add("vtranslateview",
6674 "vtranslateview Dx Dy Dz [Start = 1|0)]",
6675 __FILE__,VTranslateView,group);
6676 theCommands.Add("vturnview",
6677 "vturnview Ax Ay Az [Start = 1|0]",
6678 __FILE__,VTurnView,group);
6679 theCommands.Add("vtextureenv",
6680 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
6681 "or user-defined file and optionally applying texture mapping parameters\n"
6683 " vtextureenv off - disables environment mapping\n"
6684 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
6685 " std_texture = (0..7)\n"
6686 " rep = {clamp|repeat}\n"
6687 " mod = {decal|modulate}\n"
6688 " flt = {nearest|bilinear|trilinear}\n"
6689 " ss, st - scale factors for s and t texture coordinates\n"
6690 " ts, tt - translation for s and t texture coordinates\n"
6691 " rot - texture rotation angle in degrees",
6692 __FILE__, VTextureEnv, group);
6693 theCommands.Add("vhlr" ,
6694 "is_enabled={on|off} [show_hidden={1|0}]"
6695 " - Hidden line removal algorithm:"
6696 " - is_enabled: if is on HLR algorithm is applied\n"
6697 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
6698 __FILE__,VHLR,group);
6699 theCommands.Add("vhlrtype" ,
6700 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
6701 " - Changes the type of HLR algorithm using for shapes."
6702 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
6703 " if equals to polyalgo, polygonal HLR algorithm is applied."
6704 "If shapes are not given HLR algoithm of given type is applied"
6705 " to all shapes in the view\n",
6706 __FILE__,VHLRType,group);
6707 theCommands.Add("vclipplane", "vclipplane usage: \n"
6708 " maxplanes <view_name> - get plane limit for view.\n"
6709 " create <plane_name> - create new plane.\n"
6710 " delete <plane_name> - delete plane.\n"
6711 " clone <source_plane> <plane_name> - clone the plane definition.\n"
6712 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
6713 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
6714 " change <plane_name> on/off - turn clipping on/off.\n"
6715 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
6716 " change <plane_name> capping on/off - turn capping on/off.\n"
6717 " change <plane_name> capping color <r> <g> <b> - set color.\n"
6718 " change <plane name> capping texname <texture> - set texture.\n"
6719 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
6720 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
6721 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
6722 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
6723 " please use VSetTextureMode command to enable texture rendering in view.\n"
6724 , __FILE__, VClipPlane, group);
6725 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
6727 " 0 - no textures enabled in view.\n"
6728 " 1 - only environment textures enabled.\n"
6729 " 2 - all textures enabled.\n"
6730 " this command sets texture details mode for the specified view.\n"
6731 , __FILE__, VSetTextureMode, group);
6732 theCommands.Add("vdefaults",
6733 "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
6734 __FILE__, VDefaults, group);
6735 theCommands.Add("vlight",
6736 "tool to manage light sources, without arguments shows list of lights."
6737 "\n Main commands: "
6738 "\n 'clear' to clear lights"
6739 "\n '{def}aults' to load deafault lights"
6740 "\n 'add' (or 'new') <type> to add any light source"
6741 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
6742 "\n 'change' <lightId> to edit light source with specified lightId"
6743 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
6744 "\n {pos}ition X Y Z"
6745 "\n {dir}ection X Y Z (for directional light or for spotlight)"
6746 "\n color colorName"
6747 "\n {head}light 0|1"
6748 "\n {constAtten}uation value"
6749 "\n {linearAtten}uation value"
6751 "\n {spotexp}onent value"
6753 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
6754 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
6755 __FILE__, VLight, group);
6756 theCommands.Add("vraytrace",
6758 __FILE__,VRaytrace,group);
6759 theCommands.Add("vclinfo",
6761 __FILE__,VClInfo,group);
6762 theCommands.Add("vsetraytracemode",
6763 "vsetraytracemode [shad=0|1] [refl=0|1] [aa=0|1]",
6764 __FILE__,VSetRaytraceMode,group);