1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
25 #include <OpenGl_GlCore20.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_Drawer.hxx>
28 #include <AIS_InteractiveObject.hxx>
29 #include <AIS_ListOfInteractive.hxx>
30 #include <AIS_ListIteratorOfListOfInteractive.hxx>
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_ExportFormat.hxx>
34 #include <Graphic3d_NameOfTextureEnv.hxx>
35 #include <Graphic3d_TextureEnv.hxx>
36 #include <Graphic3d_TextureParams.hxx>
37 #include <Graphic3d_TypeOfTextureFilter.hxx>
38 #include <Graphic3d_AspectFillArea3d.hxx>
39 #include <ViewerTest.hxx>
40 #include <ViewerTest_EventManager.hxx>
41 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
42 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
43 #include <Visual3d_View.hxx>
44 #include <Visual3d_ViewManager.hxx>
45 #include <V3d_AmbientLight.hxx>
46 #include <V3d_DirectionalLight.hxx>
47 #include <V3d_LayerMgr.hxx>
48 #include <V3d_LayerMgrPointer.hxx>
49 #include <V3d_PositionalLight.hxx>
50 #include <V3d_SpotLight.hxx>
51 #include <NCollection_DoubleMap.hxx>
52 #include <NCollection_List.hxx>
53 #include <NCollection_Vector.hxx>
54 #include <NIS_View.hxx>
55 #include <NIS_Triangulated.hxx>
56 #include <NIS_InteractiveContext.hxx>
57 #include <AIS_InteractiveContext.hxx>
58 #include <Draw_Interpretor.hxx>
60 #include <Draw_Appli.hxx>
61 #include <Aspect_PrintAlgo.hxx>
62 #include <Image_AlienPixMap.hxx>
63 #include <OpenGl_GraphicDriver.hxx>
64 #include <OSD_Timer.hxx>
65 #include <TColStd_SequenceOfInteger.hxx>
66 #include <TColStd_HSequenceOfReal.hxx>
67 #include <TColgp_Array1OfPnt2d.hxx>
68 #include <Visual3d_LayerItem.hxx>
69 #include <Aspect_TypeOfLine.hxx>
70 #include <Image_Diff.hxx>
71 #include <Aspect_DisplayConnection.hxx>
72 #include <Graphic3d.hxx>
76 #include <PrsMgr_PresentableObject.hxx>
77 #include <Graphic3d_ClipPlane.hxx>
78 #include <NCollection_DataMap.hxx>
79 #include <Graphic3d_Texture2Dmanual.hxx>
80 #include <Prs3d_ShadingAspect.hxx>
86 #include <Visual3d_Layer.hxx>
90 #include <WNT_WClass.hxx>
91 #include <WNT_Window.hxx>
94 #define _CRT_SECURE_NO_DEPRECATE
95 #pragma warning (disable:4996)
97 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
98 #include <Cocoa_Window.hxx>
100 #include <Xw_Window.hxx>
101 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
102 #include <X11/Xutil.h>
106 // Auxiliary definitions
107 static const char THE_KEY_DELETE = 127;
109 //==============================================================================
110 // VIEWER GLOBAL VARIABLES
111 //==============================================================================
113 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
114 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
116 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
117 extern const Handle(NIS_InteractiveContext)& TheNISContext();
118 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
120 extern int VErase (Draw_Interpretor& theDI,
121 Standard_Integer theArgNb,
122 const char** theArgVec);
125 static Handle(WNT_Window)& VT_GetWindow() {
126 static Handle(WNT_Window) WNTWin;
129 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
130 static Handle(Cocoa_Window)& VT_GetWindow()
132 static Handle(Cocoa_Window) aWindow;
135 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
136 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
137 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
140 static Handle(Xw_Window)& VT_GetWindow(){
141 static Handle(Xw_Window) XWWin;
145 static void VProcessEvents(ClientData,int);
148 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
150 static Handle(Aspect_DisplayConnection) aDisplayConnection;
151 return aDisplayConnection;
154 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
156 GetDisplayConnection() = theDisplayConnection;
159 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
160 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
162 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
164 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
165 if (!aWindow.IsNull())
166 return aWindow->HWindow();
167 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
168 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
169 if (!aWindow.IsNull())
170 return aWindow->XWindow();
172 return aWindowHandle;
176 static Standard_Boolean MyHLRIsOn = Standard_False;
178 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
179 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
180 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
181 static OpenGl_Caps ViewerTest_myDefaultCaps;
183 #define ZCLIPWIDTH 1.
185 static void OSWindowSetup();
187 //==============================================================================
188 // EVENT GLOBAL VARIABLES
189 //==============================================================================
191 static int Start_Rot = 0;
192 static int ZClipIsOn = 0;
193 int X_Motion = 0; // Current cursor position
195 int X_ButtonPress = 0; // Last ButtonPress position
196 int Y_ButtonPress = 0;
197 Standard_Boolean IsDragged = Standard_False;
198 Standard_Boolean DragFirst;
200 //==============================================================================
203 static LRESULT WINAPI ViewerWindowProc(
208 static LRESULT WINAPI AdvViewerWindowProc(
216 //==============================================================================
219 //==============================================================================
221 const Handle(MMgt_TShared)& ViewerTest::WClass()
223 static Handle(MMgt_TShared) theWClass;
225 if (theWClass.IsNull())
227 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
228 CS_VREDRAW | CS_HREDRAW, 0, 0,
229 ::LoadCursor (NULL, IDC_ARROW));
235 //==============================================================================
236 //function : CreateName
237 //purpose : Create numerical name for new object in theMap
238 //==============================================================================
239 template <typename ObjectType>
240 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
241 const TCollection_AsciiString& theDefaultString)
243 if (theObjectMap.IsEmpty())
244 return theDefaultString + TCollection_AsciiString(1);
246 Standard_Integer aNextKey = 1;
247 Standard_Boolean isFound = Standard_False;
250 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
251 // Look for objects with default names
252 if (theObjectMap.IsBound1(aStringKey))
257 isFound = Standard_True;
260 return theDefaultString + TCollection_AsciiString(aNextKey);
263 //==============================================================================
264 //structure : ViewerTest_Names
265 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
266 //==============================================================================
267 struct ViewerTest_Names
270 TCollection_AsciiString myDriverName;
271 TCollection_AsciiString myViewerName;
272 TCollection_AsciiString myViewName;
276 const TCollection_AsciiString& GetDriverName () const
280 void SetDriverName (const TCollection_AsciiString& theDriverName)
282 myDriverName = theDriverName;
284 const TCollection_AsciiString& GetViewerName () const
288 void SetViewerName (const TCollection_AsciiString& theViewerName)
290 myViewerName = theViewerName;
292 const TCollection_AsciiString& GetViewName () const
296 void SetViewName (const TCollection_AsciiString& theViewName)
298 myViewName = theViewName;
301 //===========================================================================
302 //function : Constructor for ViewerTest_Names
303 //purpose : Get view, viewer, driver names from custom string
304 //===========================================================================
306 ViewerTest_Names (const TCollection_AsciiString& theInputString)
308 TCollection_AsciiString aName(theInputString);
309 if (theInputString.IsEmpty())
311 // Get current configuration
312 if (ViewerTest_myDrivers.IsEmpty())
313 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
314 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
316 myDriverName = ViewerTest_myDrivers.Find2
317 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
319 if(ViewerTest_myContexts.IsEmpty())
321 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
322 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
325 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
327 myViewName = CreateName <Handle(V3d_View)>
328 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
332 // There is at least view name
333 Standard_Integer aParserNumber = 0;
334 for (Standard_Integer i = 0; i < 3; ++i)
336 Standard_Integer aParserPos = aName.SearchFromEnd("/");
340 aName.Split(aParserPos-1);
345 if (aParserNumber == 0)
348 if (!ViewerTest::GetAISContext().IsNull())
350 myDriverName = ViewerTest_myDrivers.Find2
351 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
352 myViewerName = ViewerTest_myContexts.Find2
353 (ViewerTest::GetAISContext());
357 // There is no opened contexts here, need to create names for viewer and driver
358 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
359 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
361 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
362 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
364 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
366 else if (aParserNumber == 1)
368 // Here is viewerName/viewName
369 if (!ViewerTest::GetAISContext().IsNull())
370 myDriverName = ViewerTest_myDrivers.Find2
371 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
374 // There is no opened contexts here, need to create name for driver
375 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
376 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
378 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
380 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
384 //Here is driverName/viewerName/viewName
385 myDriverName = TCollection_AsciiString(aName);
387 TCollection_AsciiString aViewerName(theInputString);
388 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
389 myViewerName = TCollection_AsciiString(aViewerName);
391 myViewName = TCollection_AsciiString(theInputString);
397 //==============================================================================
398 //function : FindContextByView
399 //purpose : Find AIS_InteractiveContext by View
400 //==============================================================================
402 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
404 Handle(AIS_InteractiveContext) anAISContext;
406 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
407 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
409 if (anIter.Value()->CurrentViewer() == theView->Viewer())
410 return anIter.Key2();
416 //==============================================================================
417 //function : SetWindowTitle
418 //purpose : Set window title
419 //==============================================================================
421 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
422 Standard_CString theTitle)
425 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
427 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
428 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
430 if(GetDisplayConnection()->GetDisplay())
433 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
434 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
439 //==============================================================================
440 //function : IsWindowOverlapped
441 //purpose : Check if theWindow overlapp another view
442 //==============================================================================
444 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
445 const Standard_Integer thePxTop,
446 const Standard_Integer thePxRight,
447 const Standard_Integer thePxBottom,
448 TCollection_AsciiString& theViewId)
450 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
451 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
453 Standard_Integer aTop = 0,
457 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
458 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
459 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
460 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
461 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
463 theViewId = anIter.Key1();
464 return Standard_True;
467 return Standard_False;
470 // Workaround: to create and delete non-orthographic views outside ViewerTest
471 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
473 ViewerTest_myViews.UnBind1 (theName);
476 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
477 const Handle(V3d_View)& theView)
479 ViewerTest_myViews.Bind (theName, theView);
482 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
484 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
486 //==============================================================================
487 //function : ViewerInit
488 //purpose : Create the window viewer and initialize all the global variable
489 //==============================================================================
491 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
492 const Standard_Integer thePxTop,
493 const Standard_Integer thePxWidth,
494 const Standard_Integer thePxHeight,
495 Standard_CString theViewName,
496 Standard_CString theDisplayName)
498 // Default position and dimension of the viewer window.
499 // Note that left top corner is set to be sufficiently small to have
500 // window fit in the small screens (actual for remote desktops, see #23003).
501 // The position corresponds to the window's client area, thus some
502 // gap is added for window frame to be visible.
503 Standard_Integer aPxLeft = 20;
504 Standard_Integer aPxTop = 40;
505 Standard_Integer aPxWidth = 409;
506 Standard_Integer aPxHeight = 409;
507 Standard_Boolean toCreateViewer = Standard_False;
509 Handle(OpenGl_GraphicDriver) aGraphicDriver;
510 ViewerTest_Names aViewNames(theViewName);
511 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
512 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
519 aPxWidth = thePxWidth;
520 if (thePxHeight != 0)
521 aPxHeight = thePxHeight;
523 // Get graphic driver (create it or get from another view)
524 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
526 // Get connection string
527 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
528 TCollection_AsciiString aDisplayName(theDisplayName);
529 if (!aDisplayName.IsEmpty())
530 SetDisplayConnection (new Aspect_DisplayConnection ());
532 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
534 (void)theDisplayName; // avoid warning on unused argument
535 SetDisplayConnection (new Aspect_DisplayConnection ());
537 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
538 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
539 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
540 toCreateViewer = Standard_True;
544 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
547 //Dispose the window if input parameters are default
548 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
550 Standard_Integer aTop = 0,
557 // Get screen resolution
558 #if defined(_WIN32) || defined(__WIN32__)
560 GetClientRect(GetDesktopWindow(), &aWindowSize);
561 aScreenHeight = aWindowSize.bottom;
562 aScreenWidth = aWindowSize.right;
563 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
564 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
566 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
567 aScreenWidth = WidthOfScreen(aScreen);
568 aScreenHeight = HeightOfScreen(aScreen);
571 TCollection_AsciiString anOverlappedViewId("");
573 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
575 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
577 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
578 && aRight + 2*aPxWidth + 40 > aScreenWidth)
580 if (aBottom + aPxHeight + 40 > aScreenHeight)
587 aPxTop = aBottom + 40;
590 aPxLeft = aRight + 20;
595 TCollection_AsciiString aTitle("3D View - ");
596 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
598 // Change name of current active window
599 if (!ViewerTest::CurrentView().IsNull())
601 TCollection_AsciiString aTitle("3D View - ");
603 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
604 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
608 Handle(V3d_Viewer) a3DViewer;
609 // If it's the single view, we first look for empty context
610 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
612 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
613 anIter(ViewerTest_myContexts);
615 ViewerTest::SetAISContext (anIter.Value());
616 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
618 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
620 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
621 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
623 else if (a3DViewer.IsNull())
625 toCreateViewer = Standard_True;
626 TCollection_ExtendedString NameOfWindow("Viewer3D");
627 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
629 NameOfWindow = TCollection_ExtendedString("Collector");
631 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
635 if (ViewerTest::GetAISContext().IsNull() ||
636 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
638 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
639 ViewerTest::SetAISContext (aContext);
640 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
644 ViewerTest::ResetEventManager();
649 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
650 Handle(WNT_WClass)::DownCast (WClass()),
651 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
655 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
656 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
658 aPxWidth, aPxHeight);
659 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
661 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
664 aPxWidth, aPxHeight);
666 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
669 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
671 ViewerTest::CurrentView(aView);
672 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
673 TheNISContext()->AttachView (aView);
675 // Setup for X11 or NT
678 // Set parameters for V3d_View and V3d_Viewer
679 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
680 aV3dView->SetComputedMode(Standard_False);
681 MyHLRIsOn = aV3dView->ComputedMode();
682 aV3dView->SetZClippingDepth(0.5);
683 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
685 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
688 a3DViewer->SetDefaultLights();
689 a3DViewer->SetLightOn();
692 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
693 #if TCL_MAJOR_VERSION < 8
694 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
695 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
697 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
698 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
702 VT_GetWindow()->Map();
704 // Set the handle of created view in the event manager
705 ViewerTest::ResetEventManager();
707 ViewerTest::CurrentView()->Redraw();
712 return aViewNames.GetViewName();
715 //==============================================================================
716 //function : RedrawAllViews
717 //purpose : Redraw all created views
718 //==============================================================================
719 void ViewerTest::RedrawAllViews()
721 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
722 for (; aViewIt.More(); aViewIt.Next())
724 const Handle(V3d_View)& aView = aViewIt.Key2();
729 //==============================================================================
730 //function : splitParameter
731 //purpose : Split parameter string to parameter name an parameter value
732 //==============================================================================
733 Standard_Boolean splitParameter (const TCollection_AsciiString& theString,
734 TCollection_AsciiString& theName,
735 TCollection_AsciiString& theValue)
737 Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
738 if (aParamNameEnd == 0)
739 return Standard_False;
740 TCollection_AsciiString aString(theString);
741 if (aParamNameEnd != 0)
743 theValue = aString.Split(aParamNameEnd);
744 aString.Split(aString.Length()-1);
747 return Standard_True;
750 //==============================================================================
752 //purpose : Create the window viewer and initialize all the global variable
753 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
754 //==============================================================================
756 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
760 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
761 << "Type help for more information.\n";
765 TCollection_AsciiString aViewName, aDisplayName;
766 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
767 TCollection_AsciiString aName, aValue;
768 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
770 const TCollection_AsciiString anArg = theArgVec[anArgIt];
771 TCollection_AsciiString anArgCase = anArg;
772 anArgCase.UpperCase();
773 if (splitParameter (anArg, aName, aValue))
776 if (aName.IsEqual ("NAME"))
780 else if (aName.IsEqual ("L")
781 || aName.IsEqual ("LEFT"))
783 aPxLeft = aValue.IntegerValue();
785 else if (aName.IsEqual ("T")
786 || aName.IsEqual ("TOP"))
788 aPxTop = aValue.IntegerValue();
790 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
791 else if (aName.IsEqual ("DISP")
792 || aName.IsEqual ("DISPLAY"))
794 aDisplayName = aValue;
797 else if (aName.IsEqual ("W")
798 || aName.IsEqual ("WIDTH"))
800 aPxWidth = aValue.IntegerValue();
802 else if (aName.IsEqual ("H")
803 || aName.IsEqual ("HEIGHT"))
805 aPxHeight = aValue.IntegerValue();
809 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
812 else if (aViewName.IsEmpty())
818 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
822 ViewerTest_Names aViewNames (aViewName);
823 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
825 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
826 theDi.Eval (aCommand.ToCString());
830 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
831 aViewName.ToCString(),
832 aDisplayName.ToCString());
837 //==============================================================================
839 //purpose : hidden lines removal algorithm
840 //==============================================================================
842 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
844 if (ViewerTest::CurrentView().IsNull())
846 di << argv[0] << ": Call vinit before this command, please.\n";
852 di << argv[0] << ": Wrong number of command arguments.\n"
853 << "Type help " << argv[0] << " for more information.\n";
857 Standard_Boolean isHLROn =
858 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
860 if (isHLROn == MyHLRIsOn)
866 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
871 //==============================================================================
872 //function : VHLRType
873 //purpose : change type of using HLR algorithm
874 //==============================================================================
876 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
878 if (ViewerTest::CurrentView().IsNull())
880 di << argv[0] << ": Call vinit before this command, please.\n";
886 di << argv[0] << ": Wrong number of command arguments.\n"
887 << "Type help " << argv[0] << " for more information.\n";
891 Prs3d_TypeOfHLR aTypeOfHLR =
892 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
896 AIS_ListOfInteractive aListOfShapes;
897 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
898 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
899 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
900 anIter.More(); anIter.Next())
902 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
905 if (aShape->TypeOfHLR() != aTypeOfHLR)
906 aShape->SetTypeOfHLR (aTypeOfHLR);
910 ViewerTest::CurrentView()->Update();
915 for (Standard_Integer i = 2; i < argc; ++i)
917 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
918 TCollection_AsciiString aName (argv[i]);
920 if (!aMap.IsBound2 (aName))
922 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
925 Handle(AIS_Shape) anAISObject =
926 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
927 if (anAISObject.IsNull())
929 anAISObject->SetTypeOfHLR (aTypeOfHLR);
931 anAISObject->Redisplay();
933 ViewerTest::CurrentView()->Update();
939 //==============================================================================
940 //function : FindViewIdByWindowHandle
941 //purpose : Find theView Id in the map of views by window handle
942 //==============================================================================
943 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
944 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
946 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
947 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
949 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
950 if (aWindowHandle == theWindowHandle)
951 return anIter.Key1();
953 return TCollection_AsciiString("");
957 //==============================================================================
958 //function : ActivateView
959 //purpose : Make the view active
960 //==============================================================================
962 void ActivateView (const TCollection_AsciiString& theViewName)
964 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
967 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
968 if (!anAISContext.IsNull())
970 if (!ViewerTest::CurrentView().IsNull())
972 TCollection_AsciiString aTitle("3D View - ");
973 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
974 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
977 ViewerTest::CurrentView (aView);
978 // Update degenerate mode
979 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
980 ViewerTest::SetAISContext (anAISContext);
981 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
982 aTitle = aTitle + theViewName + "(*)";
983 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
984 #if defined(_WIN32) || defined(__WIN32__)
985 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
986 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
987 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
989 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
991 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
992 ViewerTest::CurrentView()->Redraw();
997 //==============================================================================
998 //function : RemoveView
999 //purpose : Close and remove view from display, clear maps if neccessary
1000 //==============================================================================
1001 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1003 if (!ViewerTest_myViews.IsBound1(theViewName))
1005 cout << "Wrong view name\n";
1009 // Activate another view if it's active now
1010 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1012 if (ViewerTest_myViews.Extent() > 1)
1014 TCollection_AsciiString aNewViewName;
1015 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1016 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1017 if (anIter.Key1() != theViewName)
1019 aNewViewName = anIter.Key1();
1022 ActivateView (aNewViewName);
1026 Handle(V3d_View) anEmptyView;
1027 #if defined(_WIN32) || defined(__WIN32__)
1028 Handle(WNT_Window) anEmptyWindow;
1029 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1030 Handle(Cocoa_Window) anEmptyWindow;
1032 Handle(Xw_Window) anEmptyWindow;
1034 VT_GetWindow() = anEmptyWindow;
1035 ViewerTest::CurrentView (anEmptyView);
1036 if (isContextRemoved)
1038 Handle(AIS_InteractiveContext) anEmptyContext;
1039 ViewerTest::SetAISContext(anEmptyContext);
1045 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1046 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1048 // Remove view resources
1049 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1050 ViewerTest_myViews.UnBind1(theViewName);
1053 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1054 XFlush (GetDisplayConnection()->GetDisplay());
1057 // Keep context opened only if the closed view is last to avoid
1058 // unused empty contexts
1059 if (!aCurrentContext.IsNull())
1061 // Check if there are more difined views in the viewer
1062 aCurrentContext->CurrentViewer()->InitDefinedViews();
1063 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1065 // Remove driver if there is no viewers that use it
1066 Standard_Boolean isRemoveDriver = Standard_True;
1067 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1068 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1070 if (aCurrentContext != anIter.Key2() &&
1071 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1073 isRemoveDriver = Standard_False;
1079 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1080 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1081 #if TCL_MAJOR_VERSION < 8
1082 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1084 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1089 ViewerTest_myContexts.UnBind2(aCurrentContext);
1092 cout << "3D View - " << theViewName << " was deleted.\n";
1096 //==============================================================================
1098 //purpose : Remove the view defined by its name
1099 //==============================================================================
1101 static int VClose (Draw_Interpretor& /*theDi*/,
1102 Standard_Integer theArgsNb,
1103 const char** theArgVec)
1105 NCollection_List<TCollection_AsciiString> aViewList;
1108 TCollection_AsciiString anArg (theArgVec[1]);
1110 if (anArg.IsEqual ("ALL")
1111 || anArg.IsEqual ("*"))
1113 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1114 anIter.More(); anIter.Next())
1116 aViewList.Append (anIter.Key1());
1118 if (aViewList.IsEmpty())
1120 std::cout << "No view to close\n";
1126 ViewerTest_Names aViewName (theArgVec[1]);
1127 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1129 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1132 aViewList.Append (aViewName.GetViewName());
1137 // close active view
1138 if (ViewerTest::CurrentView().IsNull())
1140 std::cerr << "No active view!\n";
1143 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1146 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1147 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1148 anIter.More(); anIter.Next())
1150 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1156 //==============================================================================
1157 //function : VActivate
1158 //purpose : Activate the view defined by its ID
1159 //==============================================================================
1161 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1165 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1166 << "Usage: " << theArgVec[0] << " ViewID\n";
1171 theDi.Eval("vviewlist");
1175 TCollection_AsciiString aNameString(theArgVec[1]);
1176 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1178 TCollection_AsciiString aTitle("3D View - ");
1179 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1180 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1181 Handle(V3d_View) anEmptyView;
1182 #if defined(_WIN32) || defined(__WIN32__)
1183 Handle(WNT_Window) anEmptyWindow;
1184 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1185 Handle(Cocoa_Window) anEmptyWindow;
1187 Handle(Xw_Window) anEmptyWindow;
1189 VT_GetWindow() = anEmptyWindow;
1190 ViewerTest::CurrentView (anEmptyView);
1191 ViewerTest::ResetEventManager();
1192 theDi << theArgVec[0] << ": all views are inactive\n";
1196 ViewerTest_Names aViewNames(aNameString);
1198 // Check if this view exists in the viewer with the driver
1199 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1201 theDi << "Wrong view name\n";
1205 // Check if it is active already
1206 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1208 theDi << theArgVec[0] << ": the view is active already\n";
1212 ActivateView (aViewNames.GetViewName());
1216 //==============================================================================
1217 //function : VViewList
1218 //purpose : Print current list of views per viewer and graphic driver ID
1219 // shared between viewers
1220 //==============================================================================
1222 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1226 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1227 << "Usage: " << theArgVec[0] << " name";
1230 if (ViewerTest_myContexts.Size() < 1)
1233 Standard_Boolean isTreeView =
1234 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1237 theDi << theArgVec[0] <<":\n";
1239 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1240 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1243 theDi << aDriverIter.Key1() << ":\n";
1245 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1246 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1248 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1252 TCollection_AsciiString aContextName(aContextIter.Key1());
1253 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1256 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1257 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1259 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1261 TCollection_AsciiString aViewName(aViewIter.Key1());
1264 if (aViewIter.Value() == ViewerTest::CurrentView())
1265 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1267 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1271 theDi << aViewName << " ";
1281 //==============================================================================
1282 //function : VT_ProcessKeyPress
1283 //purpose : Handle KeyPress event from a CString
1284 //==============================================================================
1285 void VT_ProcessKeyPress (const char* buf_ret)
1287 //cout << "KeyPress" << endl;
1288 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1289 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1290 // Letter in alphabetic order
1292 if (!strcasecmp (buf_ret, "A"))
1295 aView->SetProj(V3d_XposYnegZpos);
1297 else if (!strcasecmp (buf_ret, "D"))
1302 else if (!strcasecmp (buf_ret, "F"))
1305 if (aNisView.IsNull())
1308 aNisView->FitAll3d();
1310 else if (!strcasecmp (buf_ret, "H"))
1313 cout << "HLR" << endl;
1314 aView->SetComputedMode (!aView->ComputedMode());
1315 MyHLRIsOn = aView->ComputedMode();
1317 else if (!strcasecmp (buf_ret, "P"))
1320 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1321 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1322 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1324 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1325 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1327 AIS_ListOfInteractive aListOfShapes;
1328 aContext->DisplayedObjects(aListOfShapes);
1329 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1330 anIter.More(); anIter.Next())
1332 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1333 if (aShape.IsNull())
1335 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1336 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1338 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1339 aShape->Redisplay();
1344 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1346 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1347 if (aShape.IsNull())
1349 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1350 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1352 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1353 aShape->Redisplay();
1357 aContext->UpdateCurrentViewer();
1360 else if (!strcasecmp (buf_ret, "S"))
1362 std::cout << "setup Shaded display mode" << std::endl;
1364 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1365 if(Ctx->NbCurrents()==0 ||
1366 Ctx->NbSelected()==0)
1367 Ctx->SetDisplayMode(AIS_Shaded);
1369 if(Ctx->HasOpenedContext()){
1370 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1371 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1374 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1375 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1377 Ctx->UpdateCurrentViewer();
1380 else if (!strcasecmp (buf_ret, "U"))
1382 // Unset display mode
1383 std::cout << "reset display mode to defaults" << std::endl;
1385 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1386 if(Ctx->NbCurrents()==0 ||
1387 Ctx->NbSelected()==0)
1388 Ctx->SetDisplayMode(AIS_WireFrame);
1390 if(Ctx->HasOpenedContext()){
1391 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1392 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1395 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1396 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1398 Ctx->UpdateCurrentViewer();
1402 else if (!strcasecmp (buf_ret, "T"))
1405 aView->SetProj(V3d_Zpos);
1407 else if (!strcasecmp (buf_ret, "B"))
1410 aView->SetProj(V3d_Zneg);
1412 else if (!strcasecmp (buf_ret, "L"))
1415 aView->SetProj(V3d_Xneg);
1417 else if (!strcasecmp (buf_ret, "R"))
1420 aView->SetProj(V3d_Xpos);
1422 else if (!strcasecmp (buf_ret, "W"))
1424 std::cout << "setup WireFrame display mode" << std::endl;
1425 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1426 if(Ctx->NbCurrents()==0 ||
1427 Ctx->NbSelected()==0)
1428 Ctx->SetDisplayMode(AIS_WireFrame);
1430 if(Ctx->HasOpenedContext()){
1431 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1432 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1435 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1436 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1438 Ctx->UpdateCurrentViewer();
1441 else if (!strcasecmp (buf_ret, "Z"))
1445 cout << "ZClipping OFF" << endl;
1448 aView->SetZClippingType(V3d_OFF);
1452 cout << "ZClipping ON" << endl;
1455 aView->SetZClippingType(V3d_FRONT);
1459 else if (!strcasecmp (buf_ret, ","))
1461 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1463 else if (!strcasecmp (buf_ret, "."))
1465 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1467 else if (*buf_ret == THE_KEY_DELETE)
1469 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1471 && aCtx->NbCurrents() > 0
1472 && aCtx->NbSelected() > 0)
1474 Draw_Interprete ("verase");
1480 Standard_Integer Num = Draw::Atoi(buf_ret);
1481 if(Num>=0 && Num<=7)
1482 ViewerTest::StandardModeActivation(Num);
1486 //==============================================================================
1487 //function : VT_ProcessExpose
1488 //purpose : Redraw the View on an Expose Event
1489 //==============================================================================
1490 void VT_ProcessExpose()
1492 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1493 if (!aView3d.IsNull())
1499 //==============================================================================
1500 //function : VT_ProcessConfigure
1501 //purpose : Resize the View on an Configure Event
1502 //==============================================================================
1503 void VT_ProcessConfigure()
1505 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1506 if (aView3d.IsNull())
1511 aView3d->MustBeResized();
1516 //==============================================================================
1517 //function : VT_ProcessButton1Press
1519 //==============================================================================
1520 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1521 const char** theArgVec,
1522 Standard_Boolean theToPick,
1523 Standard_Boolean theIsShift)
1527 Standard_Real X, Y, Z;
1528 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1530 Draw::Set (theArgVec[1], X);
1531 Draw::Set (theArgVec[2], Y);
1532 Draw::Set (theArgVec[3], Z);
1537 ViewerTest::CurrentEventManager()->ShiftSelect();
1541 ViewerTest::CurrentEventManager()->Select();
1544 return Standard_False;
1547 //==============================================================================
1548 //function : VT_ProcessButton1Release
1549 //purpose : End selecting
1550 //==============================================================================
1551 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1555 IsDragged = Standard_False;
1556 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1559 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1560 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1564 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1565 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1570 //==============================================================================
1571 //function : VT_ProcessButton3Press
1572 //purpose : Start Rotation
1573 //==============================================================================
1574 void VT_ProcessButton3Press()
1579 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1581 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1584 //==============================================================================
1585 //function : VT_ProcessButton3Release
1586 //purpose : End rotation
1587 //==============================================================================
1588 void VT_ProcessButton3Release()
1595 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1600 //==============================================================================
1601 //function : ProcessZClipMotion
1603 //==============================================================================
1605 void ProcessZClipMotion()
1607 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1608 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1609 static Standard_Real CurZPos = 0.;
1611 //Quantity_Length VDX, VDY;
1612 //a3DView->Size(VDX,VDY);
1613 //Standard_Real VDZ = a3DView->ZSize();
1614 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1616 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1618 // Front = Depth + width/2.
1619 Standard_Real D = 0.5;
1620 Standard_Real W = 0.1;
1626 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1628 a3DView->SetZClippingType(V3d_OFF);
1629 a3DView->SetZClippingDepth(D);
1630 a3DView->SetZClippingWidth(W);
1631 a3DView->SetZClippingType(V3d_FRONT);
1635 X_ButtonPress = X_Motion;
1636 Y_ButtonPress = Y_Motion;
1640 //==============================================================================
1641 //function : ProcessControlButton1Motion
1643 //==============================================================================
1645 static void ProcessControlButton1Motion()
1647 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1649 X_ButtonPress = X_Motion;
1650 Y_ButtonPress = Y_Motion;
1653 //==============================================================================
1654 //function : VT_ProcessControlButton2Motion
1656 //==============================================================================
1657 void VT_ProcessControlButton2Motion()
1659 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1660 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1662 dy = -dy; // Xwindow Y axis is from top to Bottom
1664 ViewerTest::CurrentView()->Panning( dx, dy );
1666 X_ButtonPress = X_Motion;
1667 Y_ButtonPress = Y_Motion;
1670 //==============================================================================
1671 //function : VT_ProcessControlButton3Motion
1672 //purpose : Rotation
1673 //==============================================================================
1674 void VT_ProcessControlButton3Motion()
1678 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1682 //==============================================================================
1683 //function : VT_ProcessMotion
1685 //==============================================================================
1686 void VT_ProcessMotion()
1688 //pre-hilights detected objects at mouse position
1690 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1691 EM->MoveTo(X_Motion, Y_Motion);
1695 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1697 Xpix = X_Motion;Ypix=Y_Motion;
1700 //==============================================================================
1701 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1702 //purpose : Switches to an axonometric, top, left and other views
1703 //==============================================================================
1705 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1707 if ( ViewerTest::CurrentView().IsNull() )
1709 di<<"Call vinit before this command, please"<<"\n";
1713 ViewerTest::CurrentView()->SetProj(ori);
1717 //==============================================================================
1719 //purpose : Switch to an Axonometric view
1720 //Draw arg : No args
1721 //==============================================================================
1723 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1725 return ViewProject(di, V3d_XposYnegZpos);
1728 //==============================================================================
1730 //purpose : Switch to a Top View
1731 //Draw arg : No args
1732 //==============================================================================
1734 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1736 return ViewProject(di, V3d_Zpos);
1739 //==============================================================================
1740 //function : VBottom
1741 //purpose : Switch to a Bottom View
1742 //Draw arg : No args
1743 //==============================================================================
1745 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1747 return ViewProject(di, V3d_Zneg);
1750 //==============================================================================
1752 //purpose : Switch to a Left View
1753 //Draw arg : No args
1754 //==============================================================================
1756 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1758 return ViewProject(di, V3d_Ypos);
1761 //==============================================================================
1763 //purpose : Switch to a Right View
1764 //Draw arg : No args
1765 //==============================================================================
1767 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1769 return ViewProject(di, V3d_Yneg);
1772 //==============================================================================
1774 //purpose : Switch to a Front View
1775 //Draw arg : No args
1776 //==============================================================================
1778 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1780 return ViewProject(di, V3d_Xpos);
1783 //==============================================================================
1785 //purpose : Switch to a Back View
1786 //Draw arg : No args
1787 //==============================================================================
1789 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1791 return ViewProject(di, V3d_Xneg);
1794 //==============================================================================
1796 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1797 //Draw arg : No args
1798 //==============================================================================
1800 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1803 di << "Q : Quit the application" << "\n";
1805 di << "========================="<<"\n";
1806 di << "F : FitAll" << "\n";
1807 di << "T : TopView" << "\n";
1808 di << "B : BottomView" << "\n";
1809 di << "R : RightView" << "\n";
1810 di << "L : LeftView" << "\n";
1811 di << "A : AxonometricView" << "\n";
1812 di << "D : ResetView" << "\n";
1814 di << "========================="<<"\n";
1815 di << "S : Shading" << "\n";
1816 di << "W : Wireframe" << "\n";
1817 di << "H : HidelLineRemoval" << "\n";
1818 di << "U : Unset display mode" << "\n";
1819 di << "Delete : Remove selection from viewer" << "\n";
1821 di << "========================="<<"\n";
1822 di << "Selection mode "<<"\n";
1823 di << "0 : Shape" <<"\n";
1824 di << "1 : Vertex" <<"\n";
1825 di << "2 : Edge" <<"\n";
1826 di << "3 : Wire" <<"\n";
1827 di << "4 : Face" <<"\n";
1828 di << "5 : Shell" <<"\n";
1829 di << "6 : Solid" <<"\n";
1830 di << "7 : Compound" <<"\n";
1832 di << "========================="<<"\n";
1833 di << "Z : Switch Z clipping On/Off" << "\n";
1834 di << ", : Hilight next detected" << "\n";
1835 di << ". : Hilight previous detected" << "\n";
1842 static Standard_Boolean Ppick = 0;
1843 static Standard_Integer Pargc = 0;
1844 static const char** Pargv = NULL;
1847 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1852 if (!ViewerTest_myViews.IsEmpty()) {
1854 WPARAM fwKeys = wParam;
1859 // Delete view from map of views
1860 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1865 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1866 || ViewerTest::CurrentView().IsNull())
1868 // Activate inactive window
1869 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1871 ActivateView (FindViewIdByWindowHandle(hwnd));
1876 IsDragged = Standard_False;
1879 HDC hdc = GetDC( hwnd );
1880 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1881 SetROP2( hdc, R2_NOT );
1882 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1883 ReleaseDC( hwnd, hdc );
1885 const Handle(ViewerTest_EventManager) EM =
1886 ViewerTest::CurrentEventManager();
1887 if ( fwKeys & MK_SHIFT )
1888 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1889 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1891 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1892 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1894 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1896 case WM_LBUTTONDOWN:
1897 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1899 IsDragged = Standard_True;
1900 DragFirst = Standard_True;
1901 X_ButtonPress = LOWORD(lParam);
1902 Y_ButtonPress = HIWORD(lParam);
1904 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1911 HDC hdc = GetDC( hwnd );
1913 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1914 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1915 SetROP2( hdc, R2_NOT );
1918 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1920 DragFirst = Standard_False;
1921 X_Motion = LOWORD(lParam);
1922 Y_Motion = HIWORD(lParam);
1924 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1926 SelectObject( hdc, anObj );
1928 ReleaseDC( hwnd, hdc );
1931 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1935 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1939 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1943 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1950 if ( !ViewerTest::CurrentView().IsNull() ) {
1955 BeginPaint(hwnd, &ps);
1956 EndPaint(hwnd, &ps);
1961 VT_ProcessConfigure();
1965 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1968 c[0] = (char) wParam;
1970 if (wParam == VK_DELETE)
1972 c[0] = THE_KEY_DELETE;
1974 VT_ProcessKeyPress (c);
1982 VT_ProcessButton3Release();
1985 case WM_LBUTTONDOWN:
1986 case WM_MBUTTONDOWN:
1987 case WM_RBUTTONDOWN:
1989 WPARAM fwKeys = wParam;
1993 X_ButtonPress = LOWORD(lParam);
1994 Y_ButtonPress = HIWORD(lParam);
1996 if (Msg == WM_LBUTTONDOWN)
1998 if (fwKeys & MK_CONTROL)
2000 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2004 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2007 else if (Msg == WM_RBUTTONDOWN)
2010 VT_ProcessButton3Press();
2017 //cout << "\t WM_MOUSEMOVE" << endl;
2018 WPARAM fwKeys = wParam;
2019 X_Motion = LOWORD(lParam);
2020 Y_Motion = HIWORD(lParam);
2023 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2025 X_ButtonPress = LOWORD(lParam);
2026 Y_ButtonPress = HIWORD(lParam);
2028 if ( fwKeys & MK_RBUTTON ) {
2030 VT_ProcessButton3Press();
2034 if ( fwKeys & MK_CONTROL ) {
2035 if ( fwKeys & MK_LBUTTON ) {
2036 ProcessControlButton1Motion();
2038 else if ( fwKeys & MK_MBUTTON ||
2039 ((fwKeys&MK_LBUTTON) &&
2040 (fwKeys&MK_RBUTTON) ) ){
2041 VT_ProcessControlButton2Motion();
2043 else if ( fwKeys & MK_RBUTTON ) {
2044 VT_ProcessControlButton3Motion();
2048 else if ( fwKeys & MK_SHIFT ) {
2049 if ( fwKeys & MK_MBUTTON ||
2050 ((fwKeys&MK_LBUTTON) &&
2051 (fwKeys&MK_RBUTTON) ) ) {
2052 cout << "ProcessZClipMotion()" << endl;
2053 ProcessZClipMotion();
2057 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2059 if ((fwKeys & MK_MBUTTON
2060 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2062 ProcessZClipMotion();
2073 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2078 return DefWindowProc( hwnd, Msg, wParam, lParam );
2084 //==============================================================================
2085 //function : ViewerMainLoop
2086 //purpose : Get a Event on the view and dispatch it
2087 //==============================================================================
2090 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2092 Ppick = (argc > 0)? 1 : 0;
2100 cout << "Start picking" << endl;
2102 while ( Ppick == 1 ) {
2103 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2104 if (GetMessage(&msg, NULL, 0, 0) ) {
2105 TranslateMessage(&msg);
2106 DispatchMessage(&msg);
2110 cout << "Picking done" << endl;
2116 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2118 int min( int a, int b )
2126 int max( int a, int b )
2134 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2137 static XEvent aReport;
2138 Standard_Boolean pick = argc > 0;
2139 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2140 XNextEvent (aDisplay, &aReport);
2142 // Handle event for the chosen display connection
2143 switch (aReport.type) {
2146 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2149 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2155 // Activate inactive view
2156 Window aWindow = GetWindowHandle(VT_GetWindow());
2157 if(aWindow != aReport.xfocus.window)
2159 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2168 case ConfigureNotify:
2170 VT_ProcessConfigure();
2179 XComposeStatus status_in_out;
2181 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2182 (char *) buf_ret , 10 ,
2183 &ks_ret , &status_in_out ) ;
2186 buf_ret[ret_len] = '\0' ;
2190 VT_ProcessKeyPress (buf_ret);
2196 X_ButtonPress = aReport.xbutton.x;
2197 Y_ButtonPress = aReport.xbutton.y;
2199 if (aReport.xbutton.button == Button1)
2201 if (aReport.xbutton.state & ControlMask)
2203 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2207 IsDragged = Standard_True;
2208 DragFirst = Standard_True;
2211 else if (aReport.xbutton.button == Button3)
2214 VT_ProcessButton3Press();
2224 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2225 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2226 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2229 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2230 if( aContext.IsNull() )
2232 cout << "The context is null. Please use vinit before createmesh" << endl;
2236 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2237 if( aReport.xbutton.button==1 )
2241 aContext->ShiftSelect();
2250 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2251 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2252 ViewerTest::CurrentView());
2256 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2257 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2258 ViewerTest::CurrentView() );
2261 VT_ProcessButton3Release();
2263 IsDragged = Standard_False;
2266 VT_ProcessButton3Release();
2271 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2277 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2278 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2279 XSetFunction( aDisplay, gc, GXinvert );
2282 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2284 X_Motion = aReport.xmotion.x;
2285 Y_Motion = aReport.xmotion.y;
2286 DragFirst = Standard_False;
2288 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2292 X_Motion = aReport.xmotion.x;
2293 Y_Motion = aReport.xmotion.y;
2295 // remove all the ButtonMotionMaskr
2296 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2298 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2299 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2301 Quantity_Length VDX, VDY;
2303 ViewerTest::CurrentView()->Size(VDX,VDY);
2304 Standard_Real VDZ =0 ;
2305 VDZ = ViewerTest::CurrentView()->ZSize();
2307 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2309 Quantity_Length dx = 0 ;
2310 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2314 dx = dx / VDX * VDZ;
2318 ViewerTest::CurrentView()->Redraw();
2322 if ( aReport.xmotion.state & ControlMask ) {
2323 if ( aReport.xmotion.state & Button1Mask ) {
2324 ProcessControlButton1Motion();
2326 else if ( aReport.xmotion.state & Button2Mask ) {
2327 VT_ProcessControlButton2Motion();
2329 else if ( aReport.xmotion.state & Button3Mask ) {
2330 VT_ProcessControlButton3Motion();
2344 //==============================================================================
2345 //function : VProcessEvents
2346 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2347 // event in the Viewer window
2348 //==============================================================================
2350 static void VProcessEvents(ClientData,int)
2352 NCollection_Vector<int> anEventNumbers;
2353 // Get number of messages from every display
2354 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2355 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2357 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2359 // Handle events for every display
2360 int anEventIter = 0;
2361 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2362 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2364 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2365 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2367 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2368 int anEventResult = ViewerMainLoop( 0, NULL);
2369 // If window is closed or context was not found finish current event processing loop
2375 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2380 //==============================================================================
2381 //function : OSWindowSetup
2382 //purpose : Setup for the X11 window to be able to cath the event
2383 //==============================================================================
2386 static void OSWindowSetup()
2388 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2391 Window window = VT_GetWindow()->XWindow();
2392 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2393 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2394 XSynchronize(aDisplay, 1);
2396 // X11 : For keyboard on SUN
2398 wmhints.flags = InputHint;
2401 XSetWMHints( aDisplay, window, &wmhints);
2403 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2404 ButtonPressMask | ButtonReleaseMask |
2405 StructureNotifyMask |
2407 Button1MotionMask | Button2MotionMask |
2408 Button3MotionMask | FocusChangeMask
2410 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2411 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2413 XSynchronize(aDisplay, 0);
2422 //==============================================================================
2425 //purpose : Fitall, no DRAW arguments
2426 //Draw arg : No args
2427 //==============================================================================
2429 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2431 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2432 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2433 if (V.IsNull() == Standard_False) {
2435 } else if (aView.IsNull() == Standard_False) {
2441 //==============================================================================
2443 //purpose : ZFitall, no DRAW arguments
2444 //Draw arg : No args
2445 //==============================================================================
2447 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2449 Handle(V3d_View) V = ViewerTest::CurrentView();
2450 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2453 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2455 Handle(V3d_View) V = ViewerTest::CurrentView();
2456 if ( !V.IsNull() ) V->Redraw(); return 0;
2460 //==============================================================================
2462 //purpose : Remove all the object from the viewer
2463 //Draw arg : No args
2464 //==============================================================================
2466 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2468 Handle(V3d_View) V = ViewerTest::CurrentView();
2470 ViewerTest::Clear();
2474 //==============================================================================
2477 //==============================================================================
2479 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2480 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2483 di << argv[0] << "Invalid number of arguments" << "\n";
2487 while (ViewerMainLoop( argc, argv)) {
2493 //==============================================================================
2494 //function : InitViewerTest
2495 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2496 //==============================================================================
2498 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2500 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2501 ViewerTest::SetAISContext(theContext);
2502 aViewer->InitActiveViews();
2503 Handle(V3d_View) aView = aViewer->ActiveView();
2504 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2505 ViewerTest::ResetEventManager();
2506 Handle(Aspect_Window) aWindow = aView->Window();
2507 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2509 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2511 static int aFirst = 1;
2513 #if TCL_MAJOR_VERSION < 8
2514 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2515 TK_READABLE, VProcessEvents, (ClientData) 0);
2517 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2518 TK_READABLE, VProcessEvents, (ClientData) 0);
2525 //==============================================================================
2527 //purpose : Load image as background
2528 //==============================================================================
2530 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2532 if (argc < 2 || argc > 3)
2534 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2535 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2539 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2540 if(AISContext.IsNull())
2542 di << "use 'vinit' command before " << argv[0] << "\n";
2546 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2549 const char* szType = argv[2];
2550 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2551 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2552 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2553 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2556 di << "Wrong fill type : " << szType << "\n";
2557 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2562 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2563 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2568 //==============================================================================
2569 //function : VSetBgMode
2570 //purpose : Change background image fill type
2571 //==============================================================================
2573 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2577 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2578 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2582 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2583 if(AISContext.IsNull())
2585 di << "use 'vinit' command before " << argv[0] << "\n";
2588 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2589 const char* szType = argv[1];
2590 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2591 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2592 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2593 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2596 di << "Wrong fill type : " << szType << "\n";
2597 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2600 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2601 V3dView->SetBgImageStyle(aFillType, Standard_True);
2605 //==============================================================================
2606 //function : VSetGradientBg
2607 //purpose : Mount gradient background
2608 //==============================================================================
2609 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2613 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2614 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2615 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2616 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2620 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2621 if(AISContext.IsNull())
2623 di << "use 'vinit' command before " << argv[0] << "\n";
2629 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2630 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2631 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2632 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2634 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2635 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2636 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2638 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2639 int aType = Draw::Atoi(argv[7]);
2640 if( aType < 0 || aType > 8 )
2642 di << "Wrong fill type " << "\n";
2643 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2644 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2648 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2650 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2651 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2657 //==============================================================================
2658 //function : VSetGradientBgMode
2659 //purpose : Change gradient background fill style
2660 //==============================================================================
2661 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2665 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2666 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2667 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2671 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2672 if(AISContext.IsNull())
2674 di << "use 'vinit' command before " << argv[0] << "\n";
2679 int aType = Draw::Atoi(argv[1]);
2680 if( aType < 0 || aType > 8 )
2682 di << "Wrong fill type " << "\n";
2683 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2684 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2688 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2690 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2691 V3dView->SetBgGradientStyle( aMethod, 1 );
2697 //==============================================================================
2698 //function : VSetColorBg
2699 //purpose : Set color background
2700 //==============================================================================
2701 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2705 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2706 di << "R,G,B = [0..255]" << "\n";
2710 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2711 if(AISContext.IsNull())
2713 di << "use 'vinit' command before " << argv[0] << "\n";
2719 Standard_Real R = Draw::Atof(argv[1])/255.;
2720 Standard_Real G = Draw::Atof(argv[2])/255.;
2721 Standard_Real B = Draw::Atof(argv[3])/255.;
2722 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2724 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2725 V3dView->SetBackgroundColor( aColor );
2732 //==============================================================================
2734 //purpose : View Scaling
2735 //==============================================================================
2737 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2739 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2740 if ( V3dView.IsNull() ) return 1;
2743 di << argv[0] << "Invalid number of arguments" << "\n";
2746 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2749 //==============================================================================
2750 //function : VTestZBuffTrihedron
2751 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2752 //==============================================================================
2754 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2756 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2757 if ( V3dView.IsNull() ) return 1;
2759 V3dView->ZBufferTriedronSetup();
2762 // Set up default trihedron parameters
2763 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2767 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2768 const char* aPosType = argv[1];
2770 if ( strcmp(aPosType, "center") == 0 )
2772 aPosition = Aspect_TOTP_CENTER;
2774 if (strcmp(aPosType, "left_lower") == 0)
2776 aPosition = Aspect_TOTP_LEFT_LOWER;
2778 if (strcmp(aPosType, "left_upper") == 0)
2780 aPosition = Aspect_TOTP_LEFT_UPPER;
2782 if (strcmp(aPosType, "right_lower") == 0)
2784 aPosition = Aspect_TOTP_RIGHT_LOWER;
2786 if (strcmp(aPosType, "right_upper") == 0)
2788 aPosition = Aspect_TOTP_RIGHT_UPPER;
2791 di << argv[1] << " Invalid type of alignment" << "\n";
2792 di << "Must be one of [ center, left_lower," << "\n";
2793 di << "left_upper, right_lower, right_upper ]" << "\n";
2797 Standard_Real R = Draw::Atof(argv[2])/255.;
2798 Standard_Real G = Draw::Atof(argv[3])/255.;
2799 Standard_Real B = Draw::Atof(argv[4])/255.;
2800 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2802 Standard_Real aScale = Draw::Atof(argv[5]);
2806 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2810 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2811 const char* aPresType = argv[6];
2813 if ( strcmp(aPresType, "wireframe") == 0 )
2815 aPresentation = V3d_WIREFRAME;
2817 if (strcmp(aPresType, "zbuffer") == 0)
2819 aPresentation = V3d_ZBUFFER;
2822 di << argv[6] << " Invalid type of visualization" << "\n";
2823 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2827 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2831 di << argv[0] << " Invalid number of arguments" << "\n";
2840 //==============================================================================
2841 //function : VRotate
2842 //purpose : Camera Rotating
2843 //==============================================================================
2845 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2846 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2847 if ( V3dView.IsNull() ) {
2852 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2854 } else if ( argc == 7 ) {
2855 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]) );
2858 di << argv[0] << " Invalid number of arguments" << "\n";
2863 //==============================================================================
2865 //purpose : View zoom in / out (relative to current zoom)
2866 //==============================================================================
2868 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2869 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2870 if ( V3dView.IsNull() ) {
2875 Standard_Real coef = Draw::Atof(argv[1]);
2876 if ( coef <= 0.0 ) {
2877 di << argv[1] << "Invalid value" << "\n";
2880 V3dView->SetZoom( Draw::Atof(argv[1]) );
2883 di << argv[0] << " Invalid number of arguments" << "\n";
2888 //==============================================================================
2890 //purpose : View panning (in pixels)
2891 //==============================================================================
2893 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2894 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2895 if ( V3dView.IsNull() ) return 1;
2898 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2901 di << argv[0] << " Invalid number of arguments" << "\n";
2907 //==============================================================================
2908 //function : VExport
2909 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2910 //==============================================================================
2912 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2914 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2915 if (V3dView.IsNull())
2920 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2924 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2925 TCollection_AsciiString aFormatStr;
2927 TCollection_AsciiString aFileName (argv[1]);
2928 Standard_Integer aLen = aFileName.Length();
2932 aFormatStr = TCollection_AsciiString (argv[2]);
2936 if (aFileName.Value (aLen - 2) == '.')
2938 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2940 else if (aFileName.Value (aLen - 3) == '.')
2942 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2946 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2952 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2956 aFormatStr.UpperCase();
2957 if (aFormatStr == "PS")
2958 anExpFormat = Graphic3d_EF_PostScript;
2959 else if (aFormatStr == "EPS")
2960 anExpFormat = Graphic3d_EF_EnhPostScript;
2961 else if (aFormatStr == "TEX")
2962 anExpFormat = Graphic3d_EF_TEX;
2963 else if (aFormatStr == "PDF")
2964 anExpFormat = Graphic3d_EF_PDF;
2965 else if (aFormatStr == "SVG")
2966 anExpFormat = Graphic3d_EF_SVG;
2967 else if (aFormatStr == "PGF")
2968 anExpFormat = Graphic3d_EF_PGF;
2969 else if (aFormatStr == "EMF")
2970 anExpFormat = Graphic3d_EF_EMF;
2973 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2978 if (!V3dView->View()->Export (argv[1], anExpFormat))
2980 di << "Error: export of image to " << aFormatStr << " failed!\n";
2983 catch (Standard_Failure)
2985 di << "Error: export of image to " << aFormatStr << " failed";
2986 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2991 //==============================================================================
2992 //function : VColorScale
2993 //purpose : representation color scale
2994 //==============================================================================
2995 #include <V3d_ColorScale.hxx>
2997 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2999 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
3001 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
3005 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3006 if(aContext.IsNull()) {
3007 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
3011 Standard_Real minRange = 0. , maxRange = 100. ;
3013 Standard_Integer numIntervals = 10 ;
3014 Standard_Integer textHeight = 16;
3015 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
3016 Standard_Real X = 0., Y = 0. ;
3022 minRange = Draw::Atof( argv[1] );
3023 maxRange = Draw::Atof( argv[2] );
3024 numIntervals = Draw::Atoi( argv[3] );
3027 textHeight = Draw::Atoi( argv[4] );
3029 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
3032 X = Draw::Atof( argv[6] );
3033 Y = Draw::Atof( argv[7] );
3036 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3037 if ( curView.IsNull( ) )
3039 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3040 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3041 if( ! aCS.IsNull( ) )
3043 aCS->SetPosition( X , Y );
3044 aCS->SetHeight( 0.95) ;
3045 aCS->SetTextHeight( textHeight );
3046 aCS->SetRange( minRange , maxRange );
3047 aCS->SetNumberOfIntervals( numIntervals );
3048 aCS->SetLabelPosition( position );
3049 if( !curView->ColorScaleIsDisplayed() )
3050 curView->ColorScaleDisplay( );
3055 //==============================================================================
3056 //function : VGraduatedTrihedron
3057 //purpose : Displays a graduated trihedron
3058 //==============================================================================
3060 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3062 const char *str = arg;
3065 unsigned short c1 = *str++;
3066 unsigned short c2 = *str++;
3067 if (!c1 || !c2) break;
3068 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3072 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3075 if (argc != 2 && argc < 5)
3077 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3078 di<<"Usage: type help "<<argv[0]<<"\n";
3079 return 1; //TCL_ERROR
3082 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3084 // Create 3D view if it doesn't exist
3085 if ( aV3dView.IsNull() )
3087 ViewerTest::ViewerInit();
3088 aV3dView = ViewerTest::CurrentView();
3089 if( aV3dView.IsNull() )
3091 di << "Error: Cannot create a 3D view\n";
3092 return 1; //TCL_ERROR
3096 // Erase (==0) or display (!=0)
3097 const int display = Draw::Atoi(argv[1]);
3102 TCollection_AsciiString font;
3104 font.AssignCat("Courier");
3106 font.AssignCat(argv[5]);
3108 // Text is multibyte
3109 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3112 TCollection_ExtendedString xname, yname, zname;
3117 AddMultibyteString(xname, argv[2]);
3118 AddMultibyteString(yname, argv[3]);
3119 AddMultibyteString(zname, argv[4]);
3135 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3136 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3137 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3138 Standard_True/*drawgrid*/,
3139 Standard_True/*drawaxes*/,
3140 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3141 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3142 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3143 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3144 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3145 Quantity_NOC_WHITE/*gridcolor*/,
3146 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3147 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3150 aV3dView->GraduatedTrihedronErase();
3152 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3158 //==============================================================================
3159 //function : VPrintView
3160 //purpose : Test printing algorithm, print the view to image file with given
3161 // width and height. Printing implemented only for WNT.
3162 //==============================================================================
3163 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3167 di << "Printing implemented only for wnt!\n";
3171 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3172 Handle(V3d_View) aView = NULL;
3173 aContextAIS = ViewerTest::GetAISContext();
3174 if (!aContextAIS.IsNull())
3176 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3177 Vwr->InitActiveViews();
3178 if(Vwr->MoreActiveViews())
3179 aView = Vwr->ActiveView();
3185 di << "Call vinit before!\n";
3190 di << "Use: " << argv[0];
3191 di << " width height filename [print algo=0]\n";
3192 di << "width, height of the intermediate buffer for operation\n";
3193 di << "algo : {0|1}\n";
3194 di << " 0 - stretch algorithm\n";
3195 di << " 1 - tile algorithm\n";
3196 di << "test printing algorithms into an intermediate buffer\n";
3197 di << "with saving output to an image file\n";
3201 // get the input params
3202 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3203 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3204 Standard_Integer aMode = 0;
3205 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3207 aMode = Draw::Atoi (argv[4]);
3209 // check the input parameters
3210 if (aWidth <= 0 || aHeight <= 0)
3212 di << "Width and height must be positive values!\n";
3215 if (aMode != 0 && aMode != 1)
3218 // define compatible bitmap
3219 HDC anDC = CreateCompatibleDC(0);
3220 BITMAPINFO aBitmapData;
3221 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3222 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3223 aBitmapData.bmiHeader.biWidth = aWidth ;
3224 aBitmapData.bmiHeader.biHeight = aHeight;
3225 aBitmapData.bmiHeader.biPlanes = 1;
3226 aBitmapData.bmiHeader.biBitCount = 24;
3227 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3228 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3229 aBitmapData.bmiHeader.biClrUsed = 0;
3230 aBitmapData.bmiHeader.biClrImportant = 0;
3231 aBitmapData.bmiHeader.biCompression = BI_RGB;
3232 aBitmapData.bmiHeader.biSizeImage = 0;
3234 // Create Device Independent Bitmap
3235 void* aBitsOut = NULL;
3236 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3237 &aBitsOut, NULL, 0);
3238 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3240 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3241 if (aBitsOut != NULL)
3244 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3246 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3248 // succesfully printed into an intermediate buffer
3251 Image_PixMap aWrapper;
3252 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3253 aWrapper.SetTopDown (false);
3255 Image_AlienPixMap anImageBitmap;
3256 anImageBitmap.InitCopy (aWrapper);
3257 isSaved = anImageBitmap.Save (aFileName);
3261 di << "Print operation failed due to printing errors or\n";
3262 di << "insufficient memory available\n";
3263 di << "Please, try to use smaller dimensions for this test\n";
3264 di << "command, as it allocates intermediate buffer for storing\n";
3265 di << "the result\n";
3270 di << "Can't allocate memory for intermediate buffer\n";
3271 di << "Please use smaller dimensions\n";
3276 SelectObject (anDC, anOldBitmap);
3277 DeleteObject (aMemoryBitmap);
3283 di << "Save to file operation failed. This operation may fail\n";
3284 di << "if you don't have enough available memory, then you can\n";
3285 di << "use smaller dimensions for the output file\n";
3294 //==============================================================================
3295 //function : VZLayer
3296 //purpose : Test z layer operations for v3d viewer
3297 //==============================================================================
3298 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3300 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3301 if (aContextAIS.IsNull())
3303 di << "Call vinit before!\n";
3308 di << "Use: vzlayer " << argv[0];
3309 di << " add/del/get [id]\n";
3310 di << " add - add new z layer to viewer and print its id\n";
3311 di << " del - del z layer by its id\n";
3312 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3313 di << "id - the layer identificator value defined when removing z layer\n";
3317 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3318 if (aViewer.IsNull())
3320 di << "No active viewer!\n";
3324 // perform operation
3325 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3328 Standard_Integer aNewId;
3329 if (!aViewer->AddZLayer (aNewId))
3331 di << "Impossible to add new z layer!\n";
3335 di << "New z layer added with index: " << aNewId << "\n";
3337 else if (anOp == "del")
3341 di << "Please also provide as argument id of z layer to remove\n";
3345 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3346 if (!aViewer->RemoveZLayer (aDelId))
3348 di << "Impossible to remove the z layer or invalid id!\n";
3352 di << "Z layer " << aDelId << " has been removed\n";
3354 else if (anOp == "get")
3356 TColStd_SequenceOfInteger anIds;
3357 aViewer->GetAllZLayers (anIds);
3358 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3360 di << anIds.Value (aSeqIdx) << " ";
3367 di << "Invalid operation, please use { add / del / get }\n";
3374 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3376 // this class provides a presentation of text item in v3d view under-/overlayer
3377 class V3d_TextItem : public Visual3d_LayerItem
3382 DEFINE_STANDARD_RTTI(V3d_TextItem)
3385 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3386 const Standard_Real theX1,
3387 const Standard_Real theY1,
3388 const Standard_Real theHeight,
3389 const TCollection_AsciiString& theFontName,
3390 const Quantity_Color& theColor,
3391 const Quantity_Color& theSubtitleColor,
3392 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3393 const Handle(Visual3d_Layer)& theLayer);
3396 Standard_EXPORT void RedrawLayerPrs();
3402 TCollection_AsciiString myText;
3403 Standard_Real myHeight;
3404 Handle(Visual3d_Layer) myLayer;
3405 Quantity_Color myColor;
3406 Quantity_Color mySubtitleColor;
3407 Aspect_TypeOfDisplayText myType;
3408 TCollection_AsciiString myFontName;
3411 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3412 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3414 // create and add to display the text item
3415 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3416 const Standard_Real theX1,
3417 const Standard_Real theY1,
3418 const Standard_Real theHeight,
3419 const TCollection_AsciiString& theFontName,
3420 const Quantity_Color& theColor,
3421 const Quantity_Color& theSubtitleColor,
3422 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3423 const Handle(Visual3d_Layer)& theLayer)
3424 : myX1 (theX1), myY1 (theY1),
3426 myHeight (theHeight),
3429 mySubtitleColor (theSubtitleColor),
3430 myType (theTypeOfDisplay),
3431 myFontName (theFontName)
3433 if (!myLayer.IsNull ())
3434 myLayer->AddLayerItem (this);
3438 void V3d_TextItem::RedrawLayerPrs ()
3440 if (myLayer.IsNull ())
3443 myLayer->SetColor (myColor);
3444 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3445 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3448 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3450 // The Visual3d_LayerItem line item for "vlayerline" command
3451 // it provides a presentation of line with user-defined
3452 // linewidth, linetype and transparency.
3453 class V3d_LineItem : public Visual3d_LayerItem
3457 DEFINE_STANDARD_RTTI(V3d_LineItem)
3460 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3461 Standard_Real X2, Standard_Real Y2,
3462 V3d_LayerMgrPointer theLayerMgr,
3463 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3464 Standard_Real theWidth = 0.5,
3465 Standard_Real theTransp = 1.0);
3468 Standard_EXPORT void RedrawLayerPrs();
3472 Standard_Real myX1, myY1, myX2, myY2;
3473 V3d_LayerMgrPointer myLayerMgr;
3474 Aspect_TypeOfLine myType;
3475 Standard_Real myWidth;
3476 Standard_Real myTransparency;
3479 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3480 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3482 // default constructor for line item
3483 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3484 Standard_Real X2, Standard_Real Y2,
3485 V3d_LayerMgrPointer theLayerMgr,
3486 Aspect_TypeOfLine theType,
3487 Standard_Real theWidth,
3488 Standard_Real theTransp) :
3489 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3490 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3492 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3493 myLayerMgr->Overlay()->AddLayerItem (this);
3497 void V3d_LineItem::RedrawLayerPrs ()
3499 Handle (Visual3d_Layer) aOverlay;
3502 aOverlay = myLayerMgr->Overlay();
3504 if (!aOverlay.IsNull())
3506 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3507 aOverlay->SetColor(aColor);
3508 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3509 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3510 aOverlay->BeginPolyline();
3511 aOverlay->AddVertex(myX1, myY1);
3512 aOverlay->AddVertex(myX2, myY2);
3513 aOverlay->ClosePrimitive();
3517 //=============================================================================
3518 //function : VLayerLine
3519 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3520 // : linewidth, transparency coefficient
3521 //============================================================================
3522 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3524 // get the active view
3525 Handle(V3d_View) aView = ViewerTest::CurrentView();
3528 di << "Call vinit before!\n";
3533 di << "Use: " << argv[0];
3534 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3535 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3536 di << " 0 - solid \n";
3537 di << " 1 - dashed \n";
3538 di << " 2 - dot \n";
3539 di << " 3 - dashdot\n";
3540 di << " transparency : { 0.0 - 1.0 } \n";
3541 di << " 0.0 - transparent\n";
3542 di << " 1.0 - visible \n";
3546 // get the input params
3547 Standard_Real X1 = Draw::Atof(argv[1]);
3548 Standard_Real Y1 = Draw::Atof(argv[2]);
3549 Standard_Real X2 = Draw::Atof(argv[3]);
3550 Standard_Real Y2 = Draw::Atof(argv[4]);
3552 Standard_Real aWidth = 0.5;
3553 Standard_Integer aType = 0;
3554 Standard_Real aTransparency = 1.0;
3558 aWidth = Draw::Atof(argv[5]);
3562 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3567 aTransparency = Draw::Atof(argv[7]);
3568 if (aTransparency < 0 || aTransparency > 1.0)
3569 aTransparency = 1.0;
3572 // select appropriate line type
3573 Aspect_TypeOfLine aLineType;
3577 aLineType = Aspect_TOL_DASH;
3581 aLineType = Aspect_TOL_DOT;
3585 aLineType = Aspect_TOL_DOTDASH;
3589 aLineType = Aspect_TOL_SOLID;
3592 // replace layer manager
3593 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3594 aView->SetLayerMgr(aMgr);
3597 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3603 aView->MustBeResized();
3609 //=======================================================================
3610 //function : VOverlayText
3611 //purpose : Test text displaying in view overlay
3612 //=======================================================================
3613 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3615 // get the active view
3616 Handle(V3d_View) aView = ViewerTest::CurrentView();
3619 di << "No active view. Please call vinit.\n";
3622 else if (argc < 4 || argc > 13)
3624 di << "Use: " << argv[0];
3625 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3626 di << "[background_color: R G B]\n";
3627 di << " height - pixel height of the text (default=10.0)\n";
3628 di << " font_name - name of font (default=courier)\n";
3629 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3630 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
3631 di << " background_color- R G B values used for subtitle and decal text\n";
3632 di << "(default=255.0 255.0 255.0)\n";
3636 TCollection_AsciiString aText (argv[1]);
3637 Standard_Real aPosX = Draw::Atof(argv[2]);
3638 Standard_Real aPosY = Draw::Atof(argv[3]);
3639 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3642 TCollection_AsciiString aFontName = "Courier";
3644 aFontName = TCollection_AsciiString (argv[5]);
3647 Quantity_Parameter aColorRed = 1.0;
3648 Quantity_Parameter aColorGreen = 1.0;
3649 Quantity_Parameter aColorBlue = 1.0;
3652 aColorRed = Draw::Atof (argv[6])/255.;
3653 aColorGreen = Draw::Atof (argv[7])/255.;
3654 aColorBlue = Draw::Atof (argv[8])/255.;
3658 TCollection_AsciiString aDispStr;
3660 aDispStr = TCollection_AsciiString (argv[9]);
3662 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3663 if (aDispStr.IsEqual ("subtitle"))
3664 aTextType = Aspect_TODT_SUBTITLE;
3665 else if (aDispStr.IsEqual ("decal"))
3666 aTextType = Aspect_TODT_DEKALE;
3667 else if (aDispStr.IsEqual ("blend"))
3668 aTextType = Aspect_TODT_BLEND;
3669 else if (aDispStr.IsEqual ("dimension"))
3670 aTextType = Aspect_TODT_DIMENSION;
3673 Quantity_Parameter aSubRed = 1.0;
3674 Quantity_Parameter aSubGreen = 1.0;
3675 Quantity_Parameter aSubBlue = 1.0;
3678 aSubRed = Draw::Atof (argv[10])/255.;
3679 aSubGreen = Draw::Atof (argv[11])/255.;
3680 aSubBlue = Draw::Atof (argv[12])/255.;
3683 // check fo current overlay
3684 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3685 if (anOverlay.IsNull ())
3687 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3688 anOverlay = aMgr->Overlay ();
3689 aView->SetLayerMgr (aMgr);
3692 Quantity_Color aTextColor (aColorRed, aColorGreen,
3693 aColorBlue, Quantity_TOC_RGB);
3694 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3695 aSubBlue, Quantity_TOC_RGB);
3698 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3699 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3702 aView->MustBeResized();
3708 //==============================================================================
3711 //==============================================================================
3713 static int VGrid (Draw_Interpretor& /*theDI*/,
3714 Standard_Integer theArgNb,
3715 const char** theArgVec)
3717 // get the active view
3718 Handle(V3d_View) aView = ViewerTest::CurrentView();
3719 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3720 if (aView.IsNull() || aViewer.IsNull())
3722 std::cerr << "No active view. Please call vinit.\n";
3726 Aspect_GridType aType = aViewer->GridType();
3727 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3729 Standard_Integer anIter = 1;
3730 for (; anIter < theArgNb; ++anIter)
3732 const char* aValue = theArgVec[anIter];
3735 aType = Aspect_GT_Rectangular;
3737 else if (*aValue == 'c')
3739 aType = Aspect_GT_Circular;
3741 else if (*aValue == 'l')
3743 aMode = Aspect_GDM_Lines;
3745 else if (*aValue == 'p')
3747 aMode = Aspect_GDM_Points;
3749 else if (strcmp (aValue, "off" ) == 0)
3751 aViewer->DeactivateGrid();
3760 Standard_Integer aTail = (theArgNb - anIter);
3763 aViewer->ActivateGrid (aType, aMode);
3766 else if (aTail != 2 && aTail != 5)
3768 std::cerr << "Incorrect arguments number! Usage:\n"
3769 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3773 Quantity_Length anOriginX, anOriginY;
3774 Quantity_PlaneAngle aRotAngle;
3775 if (aType == Aspect_GT_Rectangular)
3777 Quantity_Length aRStepX, aRStepY;
3778 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3780 anOriginX = Draw::Atof (theArgVec[anIter++]);
3781 anOriginY = Draw::Atof (theArgVec[anIter++]);
3784 aRStepX = Draw::Atof (theArgVec[anIter++]);
3785 aRStepY = Draw::Atof (theArgVec[anIter++]);
3786 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3788 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3789 aViewer->ActivateGrid (aType, aMode);
3791 else if (aType == Aspect_GT_Circular)
3793 Quantity_Length aRadiusStep;
3794 Standard_Integer aDivisionNumber;
3795 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3797 anOriginX = Draw::Atof (theArgVec[anIter++]);
3798 anOriginY = Draw::Atof (theArgVec[anIter++]);
3801 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3802 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3803 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3806 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3807 aViewer->ActivateGrid (aType, aMode);
3813 //==============================================================================
3816 //==============================================================================
3818 static int VFps (Draw_Interpretor& theDI,
3819 Standard_Integer theArgNb,
3820 const char** theArgVec)
3822 // get the active view
3823 Handle(V3d_View) aView = ViewerTest::CurrentView();
3826 std::cerr << "No active view. Please call vinit.\n";
3830 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3833 std::cerr << "Incorrect arguments!\n";
3837 // the time is meaningless for first call
3838 // due to async OpenGl rendering
3841 // redraw view in loop to estimate average values
3844 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3850 const Standard_Real aTime = aTimer.ElapsedTime();
3851 aTimer.OSD_Chronometer::Show (aCpu);
3853 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3854 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3856 // return statistics
3857 theDI << "FPS: " << aFpsAver << "\n"
3858 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3863 //==============================================================================
3864 //function : VGlDebug
3866 //==============================================================================
3868 static int VGlDebug (Draw_Interpretor& theDI,
3869 Standard_Integer theArgNb,
3870 const char** theArgVec)
3874 Handle(V3d_View) aView = ViewerTest::CurrentView();
3877 std::cerr << "No active view. Please call vinit.\n";
3881 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3882 "GL_ARB_debug_output");
3883 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3884 theDI << (isActive ? "1" : "0");
3888 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3892 //==============================================================================
3895 //==============================================================================
3897 static int VVbo (Draw_Interpretor& theDI,
3898 Standard_Integer theArgNb,
3899 const char** theArgVec)
3901 const Standard_Boolean toSet = (theArgNb > 1);
3902 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3905 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
3909 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3910 if (aContextAIS.IsNull())
3914 std::cerr << "No active view!\n";
3918 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3919 if (!aDriver.IsNull())
3923 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3927 aDriver->ChangeOptions().vboDisable = toUseVbo;
3934 //==============================================================================
3937 //==============================================================================
3939 static int VCaps (Draw_Interpretor& theDI,
3940 Standard_Integer theArgNb,
3941 const char** theArgVec)
3943 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
3944 Handle(OpenGl_GraphicDriver) aDriver;
3945 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3946 if (!aContextAIS.IsNull())
3948 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3949 aCaps = &aDriver->ChangeOptions();
3954 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
3955 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
3956 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
3960 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3962 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
3963 if (anArg.Search ("vbo=") > -1)
3965 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3967 else if (anArg.Search ("sprites=") > -1)
3969 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3971 else if (anArg.Search ("soft=") > -1)
3973 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
3977 std::cerr << "Unknown argument: " << anArg << "\n";
3980 if (aCaps != &ViewerTest_myDefaultCaps)
3982 ViewerTest_myDefaultCaps = *aCaps;
3987 //==============================================================================
3988 //function : VMemGpu
3990 //==============================================================================
3992 static int VMemGpu (Draw_Interpretor& theDI,
3993 Standard_Integer theArgNb,
3994 const char** theArgVec)
3997 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3998 if (aContextAIS.IsNull())
4000 std::cerr << "No active view. Please call vinit.\n";
4004 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
4005 if (aDriver.IsNull())
4007 std::cerr << "Graphic driver not available.\n";
4011 Standard_Size aFreeBytes = 0;
4012 TCollection_AsciiString anInfo;
4013 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
4015 std::cerr << "Information not available.\n";
4019 if (theArgNb > 1 && *theArgVec[1] == 'f')
4021 theDI << Standard_Real (aFreeBytes);
4031 // ==============================================================================
4032 // function : VReadPixel
4034 // ==============================================================================
4035 static int VReadPixel (Draw_Interpretor& theDI,
4036 Standard_Integer theArgNb,
4037 const char** theArgVec)
4039 // get the active view
4040 Handle(V3d_View) aView = ViewerTest::CurrentView();
4043 std::cerr << "No active view. Please call vinit.\n";
4046 else if (theArgNb < 3)
4048 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4052 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4053 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4055 Standard_Integer aWidth, aHeight;
4056 aView->Window()->Size (aWidth, aHeight);
4057 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4058 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4059 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4061 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4065 Standard_Boolean toShowName = Standard_False;
4066 Standard_Boolean toShowHls = Standard_False;
4067 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4069 const char* aParam = theArgVec[anIter];
4070 if ( strcasecmp( aParam, "rgb" ) == 0 )
4072 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4073 aBufferType = Graphic3d_BT_RGB;
4075 else if ( strcasecmp( aParam, "hls" ) == 0 )
4077 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4078 aBufferType = Graphic3d_BT_RGB;
4079 toShowHls = Standard_True;
4081 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4083 aFormat = Image_PixMap::ImgRGBF;
4084 aBufferType = Graphic3d_BT_RGB;
4086 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4088 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4089 aBufferType = Graphic3d_BT_RGBA;
4091 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4093 aFormat = Image_PixMap::ImgRGBAF;
4094 aBufferType = Graphic3d_BT_RGBA;
4096 else if ( strcasecmp( aParam, "depth" ) == 0 )
4098 aFormat = Image_PixMap::ImgGrayF;
4099 aBufferType = Graphic3d_BT_Depth;
4101 else if ( strcasecmp( aParam, "name" ) == 0 )
4103 toShowName = Standard_True;
4107 Image_PixMap anImage;
4108 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4110 std::cerr << "Image allocation failed\n";
4113 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4115 std::cerr << "Image dump failed\n";
4119 Quantity_Parameter anAlpha;
4120 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4123 if (aBufferType == Graphic3d_BT_RGBA)
4125 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
4129 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
4134 switch (aBufferType)
4137 case Graphic3d_BT_RGB:
4141 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
4145 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
4149 case Graphic3d_BT_RGBA:
4151 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
4154 case Graphic3d_BT_Depth:
4156 theDI << aColor.Red() << "\n";
4165 //==============================================================================
4166 //function : VDiffImage
4167 //purpose : The draw-command compares two images.
4168 //==============================================================================
4170 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4174 theDI << "Not enough arguments.\n";
4179 const char* anImgPathRef = theArgVec[1];
4180 const char* anImgPathNew = theArgVec[2];
4182 // get string tolerance and check its validity
4183 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4184 if (aTolColor < 0.0)
4186 if (aTolColor > 1.0)
4189 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4190 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4192 // image file of difference
4193 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4195 // compare the images
4196 Image_Diff aComparer;
4197 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4202 aComparer.SetColorTolerance (aTolColor);
4203 aComparer.SetBorderFilterOn (isBorderFilterOn);
4204 Standard_Integer aDiffColorsNb = aComparer.Compare();
4205 theDI << aDiffColorsNb << "\n";
4207 // save image of difference
4208 if (aDiffImagePath != NULL)
4210 aComparer.SaveDiffImage (aDiffImagePath);
4216 //=======================================================================
4217 //function : VSelect
4218 //purpose : Emulates different types of selection by mouse:
4219 // 1) single click selection
4220 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4221 // 3) selection with polygon having corners at
4222 // pixel positions (x1,y1),...,(xn,yn)
4223 // 4) any of these selections with shift button pressed
4224 //=======================================================================
4225 static Standard_Integer VSelect (Draw_Interpretor& di,
4226 Standard_Integer argc,
4231 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4235 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4236 if(myAIScontext.IsNull())
4238 di << "use 'vinit' command before " << argv[0] << "\n";
4241 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4242 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4243 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4246 if(isShiftSelection)
4247 aCurrentEventManager->ShiftSelect();
4249 aCurrentEventManager->Select();
4253 if(isShiftSelection)
4254 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4256 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4260 Standard_Integer anUpper = 0;
4262 if(isShiftSelection)
4263 anUpper = (argc-1)/2;
4266 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4268 for(Standard_Integer i=1;i<=anUpper;++i)
4269 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4271 if(isShiftSelection)
4272 aCurrentEventManager->ShiftSelect(aPolyline);
4274 aCurrentEventManager->Select(aPolyline);
4279 //=======================================================================
4280 //function : VMoveTo
4281 //purpose : Emulates cursor movement to defined pixel position
4282 //=======================================================================
4283 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4284 Standard_Integer argc,
4289 di << "Usage : " << argv[0] << " x y" << "\n";
4293 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4294 if(aContext.IsNull())
4296 di << "use 'vinit' command before " << argv[0] << "\n";
4299 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4303 //=======================================================================
4304 //function : VViewParams
4305 //purpose : Gets or sets AIS View characteristics
4306 //=======================================================================
4307 static Standard_Integer VViewParams (Draw_Interpretor& di,
4308 Standard_Integer argc,
4311 if ( argc != 1 && argc != 13)
4313 di << "Usage : " << argv[0] << "\n";
4316 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
4317 if ( anAISView.IsNull () )
4319 di << "use 'vinit' command before " << argv[0] << "\n";
4323 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
4324 Standard_Real anAISViewCenterCoordinateX = 0.0;
4325 Standard_Real anAISViewCenterCoordinateY = 0.0;
4326 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4327 Standard_Real anAISViewProjX = 0.0;
4328 Standard_Real anAISViewProjY = 0.0;
4329 Standard_Real anAISViewProjZ = 0.0;
4330 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4331 Standard_Real anAISViewUpX = 0.0;
4332 Standard_Real anAISViewUpY = 0.0;
4333 Standard_Real anAISViewUpZ = 0.0;
4334 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4335 Standard_Real anAISViewAtX = 0.0;
4336 Standard_Real anAISViewAtY = 0.0;
4337 Standard_Real anAISViewAtZ = 0.0;
4338 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4339 di << "Scale of current view: " << anAISViewScale << "\n";
4340 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
4341 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4342 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4343 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4347 Quantity_Factor anAISViewScale = atof (argv [1]);
4348 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
4349 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
4350 Standard_Real anAISViewProjX = atof (argv [4]);
4351 Standard_Real anAISViewProjY = atof (argv [5]);
4352 Standard_Real anAISViewProjZ = atof (argv [6]);
4353 Standard_Real anAISViewUpX = atof (argv [7]);
4354 Standard_Real anAISViewUpY = atof (argv [8]);
4355 Standard_Real anAISViewUpZ = atof (argv [9]);
4356 Standard_Real anAISViewAtX = atof (argv [10]);
4357 Standard_Real anAISViewAtY = atof (argv [11]);
4358 Standard_Real anAISViewAtZ = atof (argv [12]);
4359 anAISView -> V3d_View::SetScale (anAISViewScale);
4360 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4361 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4362 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4363 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4368 //=======================================================================
4369 //function : VChangeSelected
4370 //purpose : Adds the shape to selection or remove one from it
4371 //=======================================================================
4372 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4373 Standard_Integer argc,
4378 di<<"Usage : " << argv[0] << " shape \n";
4382 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4383 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4384 TCollection_AsciiString aName(argv[1]);
4385 Handle(AIS_InteractiveObject) anAISObject;
4387 if(!aMap.IsBound2(aName))
4389 di<<"Use 'vdisplay' before";
4394 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4395 if(anAISObject.IsNull()){
4396 di<<"No interactive object \n";
4400 if(aContext->HasOpenedContext())
4402 aContext->AddOrRemoveSelected(anAISObject);
4406 aContext->AddOrRemoveCurrentObject(anAISObject);
4412 //=======================================================================
4413 //function : VZClipping
4414 //purpose : Gets or sets ZClipping mode, width and depth
4415 //=======================================================================
4416 static Standard_Integer VZClipping (Draw_Interpretor& di,
4417 Standard_Integer argc,
4422 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4423 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4426 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4427 if(aContext.IsNull())
4429 di << "use 'vinit' command before " << argv[0] << "\n";
4432 Handle(V3d_View) aView = ViewerTest::CurrentView();
4433 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4436 TCollection_AsciiString aZClippingModeString;
4437 Quantity_Length aDepth, aWidth;
4438 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4439 switch (aZClippingMode)
4442 aZClippingModeString.Copy("OFF");
4445 aZClippingModeString.Copy("BACK");
4448 aZClippingModeString.Copy("FRONT");
4451 aZClippingModeString.Copy("SLICE");
4454 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4457 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4458 << "ZClipping depth = " << aDepth << "\n"
4459 << "ZClipping width = " << aWidth << "\n";
4465 Standard_Integer aStatus = 0;
4466 if ( strcmp (argv [1], "OFF") == 0 ) {
4468 aZClippingMode = V3d_OFF;
4470 if ( strcmp (argv [1], "BACK") == 0 ) {
4472 aZClippingMode = V3d_BACK;
4474 if ( strcmp (argv [1], "FRONT") == 0 ) {
4476 aZClippingMode = V3d_FRONT;
4478 if ( strcmp (argv [1], "SLICE") == 0 ) {
4480 aZClippingMode = V3d_SLICE;
4484 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4485 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4488 aView->SetZClippingType(aZClippingMode);
4492 Quantity_Length aDepth = 0., aWidth = 1.;
4495 aDepth = atof(argv[1]);
4496 aWidth = atof(argv[2]);
4500 aDepth = atof(argv[2]);
4501 aWidth = atof(argv[3]);
4504 if(aDepth<0. || aDepth>1.)
4506 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4507 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4510 if(aWidth<0. || aWidth>1.)
4512 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4513 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4517 aView->SetZClippingDepth(aDepth);
4518 aView->SetZClippingWidth(aWidth);
4525 //=======================================================================
4526 //function : VNbSelected
4527 //purpose : Returns number of selected objects
4528 //=======================================================================
4529 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4530 Standard_Integer argc,
4535 di << "Usage : " << argv[0] << "\n";
4538 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4539 if(aContext.IsNull())
4541 di << "use 'vinit' command before " << argv[0] << "\n";
4544 di << aContext->NbSelected() << "\n";
4548 //=======================================================================
4549 //function : VAntialiasing
4550 //purpose : Switches altialiasing on or off
4551 //=======================================================================
4552 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4553 Standard_Integer argc,
4558 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4562 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4563 if(aContext.IsNull())
4565 di << "use 'vinit' command before " << argv[0] << "\n";
4569 Handle(V3d_View) aView = ViewerTest::CurrentView();
4571 if((argc == 2) && (atof(argv[1]) == 0))
4572 aView->SetAntialiasingOff();
4574 aView->SetAntialiasingOn();
4579 //=======================================================================
4580 //function : VPurgeDisplay
4581 //purpose : Switches altialiasing on or off
4582 //=======================================================================
4583 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4584 Standard_Integer argc,
4589 di << "Usage : " << argv[0] << "\n";
4592 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4593 if (aContext.IsNull())
4595 di << "use 'vinit' command before " << argv[0] << "\n";
4598 aContext->CloseAllContexts(Standard_False);
4599 di << aContext->PurgeDisplay() << "\n";
4603 //=======================================================================
4604 //function : VSetViewSize
4606 //=======================================================================
4607 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4608 Standard_Integer argc,
4611 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4612 if(aContext.IsNull())
4614 di << "use 'vinit' command before " << argv[0] << "\n";
4619 di<<"Usage : " << argv[0] << " Size\n";
4622 Standard_Real aSize = atof(argv[1]);
4625 di<<"Bad Size value : " << aSize << "\n";
4629 Handle(V3d_View) aView = ViewerTest::CurrentView();
4630 aView->SetSize(aSize);
4634 //=======================================================================
4635 //function : VMoveView
4637 //=======================================================================
4638 static Standard_Integer VMoveView (Draw_Interpretor& di,
4639 Standard_Integer argc,
4642 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4643 if(aContext.IsNull())
4645 di << "use 'vinit' command before " << argv[0] << "\n";
4648 if(argc < 4 || argc > 5)
4650 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4653 Standard_Real Dx = atof(argv[1]);
4654 Standard_Real Dy = atof(argv[2]);
4655 Standard_Real Dz = atof(argv[3]);
4656 Standard_Boolean aStart = Standard_True;
4659 aStart = (atoi(argv[4]) > 0);
4662 Handle(V3d_View) aView = ViewerTest::CurrentView();
4663 aView->Move(Dx,Dy,Dz,aStart);
4667 //=======================================================================
4668 //function : VTranslateView
4670 //=======================================================================
4671 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4672 Standard_Integer argc,
4675 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4676 if(aContext.IsNull())
4678 di << "use 'vinit' command before " << argv[0] << "\n";
4681 if(argc < 4 || argc > 5)
4683 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4686 Standard_Real Dx = atof(argv[1]);
4687 Standard_Real Dy = atof(argv[2]);
4688 Standard_Real Dz = atof(argv[3]);
4689 Standard_Boolean aStart = Standard_True;
4692 aStart = (atoi(argv[4]) > 0);
4695 Handle(V3d_View) aView = ViewerTest::CurrentView();
4696 aView->Translate(Dx,Dy,Dz,aStart);
4700 //=======================================================================
4701 //function : VTurnView
4703 //=======================================================================
4704 static Standard_Integer VTurnView (Draw_Interpretor& di,
4705 Standard_Integer argc,
4708 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4709 if(aContext.IsNull()) {
4710 di << "use 'vinit' command before " << argv[0] << "\n";
4713 if(argc < 4 || argc > 5){
4714 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4717 Standard_Real Ax = atof(argv[1]);
4718 Standard_Real Ay = atof(argv[2]);
4719 Standard_Real Az = atof(argv[3]);
4720 Standard_Boolean aStart = Standard_True;
4723 aStart = (atoi(argv[4]) > 0);
4726 Handle(V3d_View) aView = ViewerTest::CurrentView();
4727 aView->Turn(Ax,Ay,Az,aStart);
4731 //==============================================================================
4732 //function : VTextureEnv
4733 //purpose : ENables or disables environment mapping
4734 //==============================================================================
4735 class OCC_TextureEnv : public Graphic3d_TextureEnv
4738 OCC_TextureEnv(const Standard_CString FileName);
4739 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4740 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4741 const Standard_Boolean theModulateFlag,
4742 const Graphic3d_TypeOfTextureFilter theFilter,
4743 const Standard_ShortReal theXScale,
4744 const Standard_ShortReal theYScale,
4745 const Standard_ShortReal theXShift,
4746 const Standard_ShortReal theYShift,
4747 const Standard_ShortReal theAngle);
4748 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4750 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4751 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4752 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4754 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4755 : Graphic3d_TextureEnv(theFileName)
4759 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4760 : Graphic3d_TextureEnv(theTexId)
4764 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4765 const Standard_Boolean theModulateFlag,
4766 const Graphic3d_TypeOfTextureFilter theFilter,
4767 const Standard_ShortReal theXScale,
4768 const Standard_ShortReal theYScale,
4769 const Standard_ShortReal theXShift,
4770 const Standard_ShortReal theYShift,
4771 const Standard_ShortReal theAngle)
4773 myParams->SetRepeat (theRepeatFlag);
4774 myParams->SetModulate (theModulateFlag);
4775 myParams->SetFilter (theFilter);
4776 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
4777 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4778 myParams->SetRotation (theAngle);
4781 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4783 // get the active view
4784 Handle(V3d_View) aView = ViewerTest::CurrentView();
4787 std::cerr << "No active view. Please call vinit.\n";
4791 // Checking the input arguments
4792 Standard_Boolean anEnableFlag = Standard_False;
4793 Standard_Boolean isOk = theArgNb >= 2;
4796 TCollection_AsciiString anEnableOpt(theArgVec[1]);
4797 anEnableFlag = anEnableOpt.IsEqual("on");
4798 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
4802 isOk = (theArgNb == 3 || theArgNb == 11);
4805 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4806 isOk = (!aTextureOpt.IsIntegerValue() ||
4807 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
4809 if (isOk && theArgNb == 11)
4811 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
4812 aModulateOpt(theArgVec[4]),
4813 aFilterOpt (theArgVec[5]),
4814 aSScaleOpt (theArgVec[6]),
4815 aTScaleOpt (theArgVec[7]),
4816 aSTransOpt (theArgVec[8]),
4817 aTTransOpt (theArgVec[9]),
4818 anAngleOpt (theArgVec[10]);
4819 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
4820 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
4821 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
4822 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
4823 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
4824 anAngleOpt.IsRealValue());
4831 std::cerr << "Usage :" << std::endl;
4832 std::cerr << theArgVec[0] << " off" << std::endl;
4833 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;
4839 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4840 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
4841 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
4842 new OCC_TextureEnv(theArgVec[2]);
4846 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
4847 aTexEnv->SetTextureParameters(
4848 aRepeatOpt. IsEqual("repeat"),
4849 aModulateOpt.IsEqual("modulate"),
4850 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
4851 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
4852 Graphic3d_TOTF_TRILINEAR,
4853 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
4854 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
4855 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
4856 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
4857 (Standard_ShortReal)Draw::Atof(theArgVec[10])
4860 aView->SetTextureEnv(aTexEnv);
4861 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
4863 else // Disabling environment mapping
4865 aView->SetSurfaceDetail(V3d_TEX_NONE);
4866 Handle(Graphic3d_TextureEnv) aTexture;
4867 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
4874 //===============================================================================================
4875 //function : VClipPlane
4877 //===============================================================================================
4878 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4880 // use short-cut for created clip planes map of created (or "registered by name") clip planes
4881 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
4882 static MapOfPlanes aRegPlanes;
4886 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
4890 TCollection_AsciiString aCommand (theArgVec[1]);
4892 // print maximum number of planes for current viewer
4893 if (aCommand == "maxplanes")
4897 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
4901 TCollection_AsciiString aViewName (theArgVec[2]);
4903 if (!ViewerTest_myViews.IsBound1 (aViewName))
4905 theDi << theArgVec[0] << ": view is not found.\n";
4909 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
4911 theDi << theArgVec[0] << ": "
4912 << aView->Viewer()->Driver()->InquirePlaneLimit()
4913 << " plane slots provided by driver."
4914 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
4919 // create / delete plane instance
4920 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
4924 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
4928 Standard_Boolean toCreate = (aCommand == "create");
4929 Standard_Boolean toClone = (aCommand == "clone");
4930 TCollection_AsciiString aPlane (theArgVec[2]);
4934 if (aRegPlanes.IsBound (aPlane))
4936 theDi << theArgVec[0] << ": plane name is in use.\n";
4940 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
4942 else if (toClone) // toClone
4944 if (!aRegPlanes.IsBound (aPlane))
4946 theDi << theArgVec[0] << ": no such plane.\n";
4952 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
4956 TCollection_AsciiString aClone (theArgVec[3]);
4957 if (aRegPlanes.IsBound (aClone))
4959 theDi << theArgVec[0] << ": plane name is in use.\n";
4963 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4965 aRegPlanes.Bind (aClone, aClipPlane->Clone());
4969 if (!aRegPlanes.IsBound (aPlane))
4971 theDi << theArgVec[0] << ": no such plane.\n";
4975 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
4976 aRegPlanes.UnBind (aPlane);
4978 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
4979 for (; anIObjIt.More(); anIObjIt.Next())
4981 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
4982 aPrs->RemoveClipPlane(aClipPlane);
4985 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
4986 for (; aViewIt.More(); aViewIt.Next())
4988 const Handle(V3d_View)& aView = aViewIt.Key2();
4989 aView->RemoveClipPlane(aClipPlane);
4992 ViewerTest::RedrawAllViews();
4998 // set / unset plane command
4999 if (aCommand == "set" || aCommand == "unset")
5003 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5007 Standard_Boolean toSet = (aCommand == "set");
5008 TCollection_AsciiString aPlane (theArgVec [2]);
5009 if (!aRegPlanes.IsBound (aPlane))
5011 theDi << theArgVec[0] << ": no such plane.\n";
5015 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5017 TCollection_AsciiString aTarget (theArgVec [3]);
5018 if (aTarget != "object" && aTarget != "view")
5020 theDi << theArgVec[0] << ": invalid target.\n";
5024 if (aTarget == "object" || aTarget == "view")
5028 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5032 Standard_Boolean isObject = (aTarget == "object");
5034 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
5036 TCollection_AsciiString anEntityName (theArgVec[anIt]);
5037 if (isObject) // to object
5039 if (!GetMapOfAIS().IsBound2 (anEntityName))
5041 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
5045 Handle(AIS_InteractiveObject) aIObj =
5046 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
5049 aIObj->AddClipPlane (aClipPlane);
5051 aIObj->RemoveClipPlane (aClipPlane);
5055 if (!ViewerTest_myViews.IsBound1 (anEntityName))
5057 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
5061 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
5063 aView->AddClipPlane (aClipPlane);
5065 aView->RemoveClipPlane (aClipPlane);
5069 ViewerTest::RedrawAllViews();
5075 // change plane command
5076 if (aCommand == "change")
5080 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5084 TCollection_AsciiString aPlane (theArgVec [2]);
5085 if (!aRegPlanes.IsBound (aPlane))
5087 theDi << theArgVec[0] << ": no such plane.\n";
5091 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5093 TCollection_AsciiString aChangeArg (theArgVec [3]);
5094 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5096 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5100 if (aChangeArg == "on" || aChangeArg == "off") // on / off
5102 aClipPlane->SetOn (aChangeArg == "on");
5104 else if (aChangeArg == "equation") // change equation
5108 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5112 Standard_Real aCoeffA = atof (theArgVec [4]);
5113 Standard_Real aCoeffB = atof (theArgVec [5]);
5114 Standard_Real aCoeffC = atof (theArgVec [6]);
5115 Standard_Real aCoeffD = atof (theArgVec [7]);
5116 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5118 else if (aChangeArg == "capping") // change capping aspects
5122 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5126 TCollection_AsciiString aCappingArg (theArgVec [4]);
5127 if (aCappingArg != "on" && aCappingArg != "off" &&
5128 aCappingArg != "color" && aCappingArg != "texname" &&
5129 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5130 aCappingArg != "texrotate" && aCappingArg != "hatch")
5132 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5136 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5138 aClipPlane->SetCapping (aCappingArg == "on");
5140 else if (aCappingArg == "color") // color aspect for capping
5144 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5148 Standard_Real aRed = atof (theArgVec [5]);
5149 Standard_Real aGrn = atof (theArgVec [6]);
5150 Standard_Real aBlu = atof (theArgVec [7]);
5152 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5153 aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
5154 aClipPlane->SetCappingMaterial (aMat);
5156 else if (aCappingArg == "texname") // texture name
5160 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5164 TCollection_AsciiString aTextureName (theArgVec [5]);
5166 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5167 if (!aTexture->IsDone ())
5169 aClipPlane->SetCappingTexture (NULL);
5173 aTexture->EnableModulate();
5174 aTexture->EnableRepeat();
5175 aClipPlane->SetCappingTexture (aTexture);
5178 else if (aCappingArg == "texscale") // texture scale
5180 if (aClipPlane->CappingTexture().IsNull())
5182 theDi << theArgVec[0] << ": no texture is set.\n";
5188 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5192 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5193 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5195 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5197 else if (aCappingArg == "texorigin") // texture origin
5199 if (aClipPlane->CappingTexture().IsNull())
5201 theDi << theArgVec[0] << ": no texture is set.\n";
5207 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5211 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5212 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5214 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5216 else if (aCappingArg == "texrotate") // texture rotation
5218 if (aClipPlane->CappingTexture().IsNull())
5220 theDi << theArgVec[0] << ": no texture is set.\n";
5226 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5230 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5232 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5234 else if (aCappingArg == "hatch") // hatch style
5238 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5242 TCollection_AsciiString aHatchStr (theArgVec [5]);
5243 if (aHatchStr == "on")
5245 aClipPlane->SetCappingHatchOn();
5247 else if (aHatchStr == "off")
5249 aClipPlane->SetCappingHatchOff();
5253 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5258 ViewerTest::RedrawAllViews();
5263 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5267 //===============================================================================================
5268 //function : VSetTextureMode
5270 //===============================================================================================
5271 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5275 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5279 TCollection_AsciiString aViewName (theArgVec[1]);
5280 if (!ViewerTest_myViews.IsBound1 (aViewName))
5282 theDi << theArgVec[0] << ": view is not found.\n";
5286 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5287 switch (atoi (theArgVec[2]))
5289 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5290 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5291 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5293 theDi << theArgVec[0] << ": invalid mode.\n";
5301 //===============================================================================================
5302 //function : VDefaults
5304 //===============================================================================================
5305 static int VDefaults (Draw_Interpretor& theDi,
5306 Standard_Integer theArgsNb,
5307 const char** theArgVec)
5309 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5312 std::cerr << "No active viewer!\n";
5316 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
5319 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
5321 theDi << "DeflType: relative\n"
5322 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
5326 theDi << "DeflType: absolute\n"
5327 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
5329 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
5333 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5335 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5336 TCollection_AsciiString aKey, aValue;
5337 if (!splitParameter (anArg, aKey, aValue)
5338 || aValue.IsEmpty())
5340 std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
5345 if (aKey == "ABSDEFL"
5346 || aKey == "ABSOLUTEDEFLECTION"
5348 || aKey == "DEFLECTION")
5350 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
5351 aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
5353 else if (aKey == "RELDEFL"
5354 || aKey == "RELATIVEDEFLECTION"
5355 || aKey == "DEVCOEFF"
5356 || aKey == "DEVIATIONCOEFF"
5357 || aKey == "DEVIATIONCOEFFICIENT")
5359 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
5360 aDefParams->SetDeviationCoefficient (aValue.RealValue());
5362 else if (aKey == "ANGDEFL"
5363 || aKey == "ANGULARDEFL"
5364 || aKey == "ANGULARDEFLECTION")
5366 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
5367 aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
5371 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
5378 //! Auxiliary method
5379 inline void addLight (const Handle(V3d_Light)& theLightNew,
5380 const Standard_Boolean theIsGlobal)
5382 if (theLightNew.IsNull())
5389 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
5393 ViewerTest::CurrentView()->SetLightOn (theLightNew);
5397 //! Auxiliary method
5398 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
5400 TCollection_AsciiString anArgNextCase (theArgNext);
5401 anArgNextCase.UpperCase();
5402 if (anArgNextCase.Length() > 5
5403 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
5405 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
5409 return theArgNext.IntegerValue();
5413 //===============================================================================================
5416 //===============================================================================================
5417 static int VLight (Draw_Interpretor& theDi,
5418 Standard_Integer theArgsNb,
5419 const char** theArgVec)
5421 Handle(V3d_View) aView = ViewerTest::CurrentView();
5422 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5424 || aViewer.IsNull())
5426 std::cerr << "No active viewer!\n";
5430 Standard_Real anXYZ[3];
5431 Quantity_Coefficient anAtten[2];
5434 // print lights info
5435 Standard_Integer aLightId = 0;
5436 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
5438 Handle(V3d_Light) aLight = aView->ActiveLight();
5439 const Quantity_Color aColor = aLight->Color();
5440 theDi << "Light" << aLightId << "\n";
5441 switch (aLight->Type())
5445 theDi << " Type: Ambient\n";
5448 case V3d_DIRECTIONAL:
5450 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
5451 theDi << " Type: Directional\n";
5452 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5453 if (!aLightDir.IsNull())
5455 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5456 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5457 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
5458 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5462 case V3d_POSITIONAL:
5464 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
5465 theDi << " Type: Positional\n";
5466 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5467 if (!aLightPos.IsNull())
5469 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5470 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5471 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5472 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
5478 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
5479 theDi << " Type: Spot\n";
5480 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5481 if (!aLightSpot.IsNull())
5483 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5484 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5485 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
5486 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5487 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5488 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
5489 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
5490 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
5496 theDi << " Type: UNKNOWN\n";
5500 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
5504 Handle(V3d_Light) aLightNew;
5505 Handle(V3d_Light) aLightOld;
5506 Standard_Boolean isGlobal = Standard_True;
5507 Standard_Boolean toCreate = Standard_False;
5508 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5510 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
5511 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
5512 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
5513 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
5514 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
5516 TCollection_AsciiString aName, aValue;
5517 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
5518 TCollection_AsciiString anArgCase (anArg);
5519 anArgCase.UpperCase();
5520 if (anArgCase.IsEqual ("NEW")
5521 || anArgCase.IsEqual ("ADD")
5522 || anArgCase.IsEqual ("CREATE"))
5524 toCreate = Standard_True;
5526 else if (anArgCase.IsEqual ("GLOB")
5527 || anArgCase.IsEqual ("GLOBAL"))
5529 isGlobal = Standard_True;
5531 else if (anArgCase.IsEqual ("LOC")
5532 || anArgCase.IsEqual ("LOCAL"))
5534 isGlobal = Standard_False;
5536 else if (anArgCase.IsEqual ("AMB")
5537 || anArgCase.IsEqual ("AMBIENT")
5538 || anArgCase.IsEqual ("AMBLIGHT"))
5540 addLight (aLightNew, isGlobal);
5543 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5546 toCreate = Standard_False;
5547 aLightNew = new V3d_AmbientLight (aViewer);
5549 else if (anArgCase.IsEqual ("DIRECTIONAL")
5550 || anArgCase.IsEqual ("DIRLIGHT"))
5552 addLight (aLightNew, isGlobal);
5555 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5558 toCreate = Standard_False;
5559 aLightNew = new V3d_DirectionalLight (aViewer);
5561 else if (anArgCase.IsEqual ("SPOT")
5562 || anArgCase.IsEqual ("SPOTLIGHT"))
5564 addLight (aLightNew, isGlobal);
5567 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5570 toCreate = Standard_False;
5571 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
5573 else if (anArgCase.IsEqual ("POSLIGHT")
5574 || anArgCase.IsEqual ("POSITIONAL"))
5576 addLight (aLightNew, isGlobal);
5579 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5582 toCreate = Standard_False;
5583 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
5585 else if (anArgCase.IsEqual ("CHANGE"))
5587 addLight (aLightNew, isGlobal);
5588 aLightNew.Nullify();
5589 if (++anArgIt >= theArgsNb)
5591 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5595 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
5596 Standard_Integer aLightIt = 0;
5597 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
5599 if (aLightIt == aLightId)
5601 aLightOld = aView->ActiveLight();
5606 if (aLightOld.IsNull())
5608 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
5612 else if (anArgCase.IsEqual ("DEL")
5613 || anArgCase.IsEqual ("DELETE"))
5615 Handle(V3d_Light) aLightDel;
5616 if (++anArgIt >= theArgsNb)
5618 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5622 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
5623 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
5624 Standard_Integer aLightIt = 0;
5625 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
5627 aLightDel = aView->ActiveLight();
5628 if (aLightIt == aLightDelId)
5633 if (!aLightDel.IsNull())
5635 aViewer->DelLight (aLightDel);
5638 else if (anArgCase.IsEqual ("COLOR")
5639 || anArgCase.IsEqual ("COLOUR"))
5641 if (++anArgIt >= theArgsNb)
5643 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5647 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
5648 anArgNext.UpperCase();
5649 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
5650 if (!aLightCurr.IsNull())
5652 aLightCurr->SetColor (aColor);
5655 else if (anArgCase.IsEqual ("POS")
5656 || anArgCase.IsEqual ("POSITION"))
5658 if ((anArgIt + 3) >= theArgsNb)
5660 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5664 anXYZ[0] = Atof (theArgVec[++anArgIt]);
5665 anXYZ[1] = Atof (theArgVec[++anArgIt]);
5666 anXYZ[2] = Atof (theArgVec[++anArgIt]);
5667 if (!aLightDir.IsNull())
5669 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
5671 else if (!aLightPos.IsNull())
5673 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
5675 else if (!aLightSpot.IsNull())
5677 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
5681 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5685 else if (anArgCase.IsEqual ("DIR")
5686 || anArgCase.IsEqual ("DIRECTION"))
5688 if ((anArgIt + 3) >= theArgsNb)
5690 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5694 anXYZ[0] = Atof (theArgVec[++anArgIt]);
5695 anXYZ[1] = Atof (theArgVec[++anArgIt]);
5696 anXYZ[2] = Atof (theArgVec[++anArgIt]);
5697 if (!aLightDir.IsNull())
5699 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
5701 else if (!aLightSpot.IsNull())
5703 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
5707 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5711 else if (anArgCase.IsEqual ("CONSTATTEN")
5712 || anArgCase.IsEqual ("CONSTATTENUATION"))
5714 if (++anArgIt >= theArgsNb)
5716 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5720 if (!aLightPos.IsNull())
5722 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5723 anAtten[0] = Atof (theArgVec[anArgIt]);
5724 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
5726 else if (!aLightSpot.IsNull())
5728 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5729 anAtten[0] = Atof (theArgVec[anArgIt]);
5730 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
5734 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5738 else if (anArgCase.IsEqual ("LINATTEN")
5739 || anArgCase.IsEqual ("LINEARATTEN")
5740 || anArgCase.IsEqual ("LINEARATTENUATION"))
5742 if (++anArgIt >= theArgsNb)
5744 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5748 if (!aLightPos.IsNull())
5750 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5751 anAtten[1] = Atof (theArgVec[anArgIt]);
5752 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
5754 else if (!aLightSpot.IsNull())
5756 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5757 anAtten[1] = Atof (theArgVec[anArgIt]);
5758 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
5762 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5766 else if (anArgCase.IsEqual ("EXP")
5767 || anArgCase.IsEqual ("EXPONENT")
5768 || anArgCase.IsEqual ("SPOTEXP")
5769 || anArgCase.IsEqual ("SPOTEXPONENT"))
5771 if (++anArgIt >= theArgsNb)
5773 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5777 if (!aLightSpot.IsNull())
5779 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
5783 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5787 else if (anArgCase.IsEqual ("HEAD")
5788 || anArgCase.IsEqual ("HEADLIGHT"))
5790 if (++anArgIt >= theArgsNb)
5792 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5796 if (aLightAmb.IsNull()
5797 && !aLightCurr.IsNull())
5799 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
5803 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5809 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
5813 addLight (aLightNew, isGlobal);
5814 aViewer->UpdateLights();
5821 //==============================================================================
5822 //function : VClInfo
5823 //purpose : Prints info about active OpenCL device
5824 //==============================================================================
5826 static Standard_Integer VClInfo (Draw_Interpretor& theDi,
5830 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5831 if (aContextAIS.IsNull())
5833 std::cerr << "Call vinit before!\n";
5837 Handle(OpenGl_GraphicDriver) aDrv = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5838 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
5839 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> anInfo;
5842 || !aDrv->GetOpenClDeviceInfo (*aCView, anInfo))
5844 theDi << "OpenCL device info is unavailable!\n";
5848 theDi << "OpenCL device info:\n";
5849 for (NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator anIter (anInfo);
5850 anIter.More(); anIter.Next())
5852 theDi << anIter.Key() << ": \t" << anIter.Value() << "\n";
5857 //=======================================================================
5858 //function : VRaytrace
5859 //purpose : Enables/disables OpenCL-based ray-tracing
5860 //=======================================================================
5862 static Standard_Integer VRaytrace (Draw_Interpretor& ,
5863 Standard_Integer theArgNb,
5864 const char** theArgVec)
5866 Handle(V3d_View) aView = ViewerTest::CurrentView();
5869 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
5874 || Draw::Atoi (theArgVec[1]))
5876 aView->SetRaytracingMode();
5880 aView->SetRasterizationMode();
5886 //=======================================================================
5887 //function : VSetRaytraceMode
5888 //purpose : Enables/disables features of OpenCL-based ray-tracing
5889 //=======================================================================
5891 static Standard_Integer VSetRaytraceMode (Draw_Interpretor&,
5892 Standard_Integer theArgNb,
5893 const char ** theArgVec)
5895 Handle(V3d_View) aView = ViewerTest::CurrentView();
5898 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
5901 else if (theArgNb < 2)
5903 std::cerr << "Usage : " << theArgVec[0] << " [shad=0|1] [refl=0|1] [aa=0|1]\n";
5907 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5909 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5911 if (anArg.Search ("shad=") > -1)
5913 if (anArg.Token ("=", 2).IntegerValue() != 0)
5914 aView->EnableRaytracedShadows();
5916 aView->DisableRaytracedShadows();
5918 else if (anArg.Search ("refl=") > -1)
5920 if (anArg.Token ("=", 2).IntegerValue() != 0)
5921 aView->EnableRaytracedReflections();
5923 aView->DisableRaytracedReflections();
5925 else if (anArg.Search ("aa=") > -1)
5927 if (anArg.Token ("=", 2).IntegerValue() != 0)
5928 aView->EnableRaytracedAntialiasing();
5930 aView->DisableRaytracedAntialiasing();
5934 std::cerr << "Unknown argument: " << anArg << "\n";
5942 //=======================================================================
5943 //function : ViewerCommands
5945 //=======================================================================
5947 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
5950 const char *group = "ZeViewer";
5951 theCommands.Add("vinit",
5952 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5953 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5955 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5957 " - Creates new View window with specified name view_name.\n"
5958 "By default the new view is created in the viewer and in"
5959 " graphic driver shared with active view.\n"
5960 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
5961 "If driverName isn't specified the driver will be shared with active view.\n"
5962 "If viewerName isn't specified the viewer will be shared with active view.\n"
5963 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5964 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
5965 "is used in creation of graphic driver\n"
5967 " - l, t: pixel position of left top corner of the window\n"
5968 " - w,h: width and heigth of window respectively.\n"
5969 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
5970 __FILE__,VInit,group);
5971 theCommands.Add("vclose" ,
5972 "[view_id [keep_context=0|1]]\n"
5973 "or vclose ALL - to remove all created views\n"
5974 " - removes view(viewer window) defined by its view_id.\n"
5975 " - keep_context: by default 0; if 1 and the last view is deleted"
5976 " the current context is not removed.",
5977 __FILE__,VClose,group);
5978 theCommands.Add("vactivate" ,
5980 " - activates view(viewer window) defined by its view_id",
5981 __FILE__,VActivate,group);
5982 theCommands.Add("vviewlist",
5983 "vviewlist [format={tree, long}]"
5984 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
5985 " - format: format of result output, if tree the output is a tree view;"
5986 "otherwise it's a list of full view names. By default format = tree",
5987 __FILE__,VViewList,group);
5988 theCommands.Add("vhelp" ,
5989 "vhelp : display help on the viewer commands",
5990 __FILE__,VHelp,group);
5991 theCommands.Add("vtop" ,
5992 "vtop or <T> : Top view" ,
5993 __FILE__,VTop,group);
5994 theCommands.Add("vbottom" ,
5995 "vbottom : Bottom view" ,
5996 __FILE__,VBottom,group);
5997 theCommands.Add("vleft" ,
5998 "vleft : Left view" ,
5999 __FILE__,VLeft,group);
6000 theCommands.Add("vright" ,
6001 "vright : Right view" ,
6002 __FILE__,VRight,group);
6003 theCommands.Add("vaxo" ,
6004 " vaxo or <A> : Axonometric view ",
6005 __FILE__,VAxo,group);
6006 theCommands.Add("vfront" ,
6007 "vfront : Front view" ,
6008 __FILE__,VFront,group);
6009 theCommands.Add("vback" ,
6010 "vback : Back view" ,
6011 __FILE__,VBack,group);
6012 theCommands.Add("vpick" ,
6013 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
6015 theCommands.Add("vfit" ,
6016 "vfit or <F> : vfit",
6017 __FILE__,VFit,group);
6018 theCommands.Add("vzfit" ,
6020 __FILE__,VZFit,group);
6021 theCommands.Add("vrepaint",
6022 "vrepaint : vrepaint, force redraw",
6023 __FILE__,VRepaint,group);
6024 theCommands.Add("vclear",
6026 __FILE__,VClear,group);
6027 theCommands.Add("vsetbg",
6028 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
6029 __FILE__,VSetBg,group);
6030 theCommands.Add("vsetbgmode",
6031 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
6032 __FILE__,VSetBgMode,group);
6033 theCommands.Add("vsetgradientbg",
6034 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
6035 __FILE__,VSetGradientBg,group);
6036 theCommands.Add("vsetgrbgmode",
6037 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
6038 __FILE__,VSetGradientBgMode,group);
6039 theCommands.Add("vsetcolorbg",
6040 "vsetcolorbg : vsetcolorbg r g b : Set background color",
6041 __FILE__,VSetColorBg,group);
6042 theCommands.Add("vscale",
6043 "vscale : vscale X Y Z",
6044 __FILE__,VScale,group);
6045 theCommands.Add("vzbufftrihedron",
6046 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
6047 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
6048 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
6049 __FILE__,VTestZBuffTrihedron,group);
6050 theCommands.Add("vrotate",
6051 "vrotate : vrotate AX AY AZ [X Y Z]",
6052 __FILE__,VRotate,group);
6053 theCommands.Add("vzoom",
6054 "vzoom : vzoom coef",
6055 __FILE__,VZoom,group);
6056 theCommands.Add("vpan",
6057 "vpan : vpan dx dy",
6058 __FILE__,VPan,group);
6059 theCommands.Add("vexport",
6060 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
6061 " : exports the view to a vector file of a given format"
6062 " : notice that EMF format requires patched gl2ps",
6063 __FILE__,VExport,group);
6064 theCommands.Add("vcolorscale",
6065 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
6066 __FILE__,VColorScale,group);
6067 theCommands.Add("vgraduatedtrihedron",
6068 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
6069 __FILE__,VGraduatedTrihedron,group);
6070 theCommands.Add("vprintview" ,
6071 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
6072 __FILE__,VPrintView,group);
6073 theCommands.Add("vzlayer",
6074 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
6075 __FILE__,VZLayer,group);
6076 theCommands.Add("voverlaytext",
6077 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
6078 " : height - pixel height of the text (default=10.0)"
6079 " : font_name - name of font (default=courier)"
6080 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
6081 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
6082 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
6083 __FILE__,VOverlayText,group);
6084 theCommands.Add("vlayerline",
6085 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
6086 __FILE__,VLayerLine,group);
6087 theCommands.Add ("vgrid",
6088 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
6089 " : Mode - rectangular or circular"
6090 " : Type - lines or points",
6091 __FILE__, VGrid, group);
6092 theCommands.Add ("vfps",
6093 "vfps [framesNb=100] : estimate average frame rate for active view",
6094 __FILE__, VFps, group);
6095 theCommands.Add ("vgldebug",
6096 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
6097 " : this function is implemented only for Windows\n"
6098 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
6099 __FILE__, VGlDebug, group);
6100 theCommands.Add ("vvbo",
6101 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
6102 __FILE__, VVbo, group);
6103 theCommands.Add ("vcaps",
6104 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
6105 __FILE__, VCaps, group);
6106 theCommands.Add ("vmemgpu",
6107 "vmemgpu [f]: print system-dependent GPU memory information if available;"
6108 " with f option returns free memory in bytes",
6109 __FILE__, VMemGpu, group);
6110 theCommands.Add ("vreadpixel",
6111 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
6112 " : Read pixel value for active view",
6113 __FILE__, VReadPixel, group);
6114 theCommands.Add("diffimage",
6115 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
6116 __FILE__, VDiffImage, group);
6117 theCommands.Add ("vselect",
6118 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
6119 "- emulates different types of selection:\n"
6120 "- 1) single click selection\n"
6121 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
6122 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
6123 "- 4) any of these selections with shift button pressed",
6124 __FILE__, VSelect, group);
6125 theCommands.Add ("vmoveto",
6127 "- emulates cursor movement to pixel postion (x,y)",
6128 __FILE__, VMoveTo, group);
6129 theCommands.Add("vviewparams",
6130 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
6131 "- gets or sets current view characteristics",
6132 __FILE__,VViewParams, group);
6133 theCommands.Add("vchangeselected",
6134 "vchangeselected shape"
6135 "- adds to shape to selection or remove one from it",
6136 __FILE__, VChangeSelected, group);
6137 theCommands.Add("vzclipping",
6138 "vzclipping [mode] [depth width]\n"
6139 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
6140 "- gets or sets ZClipping mode, width and depth",
6141 __FILE__,VZClipping,group);
6142 theCommands.Add ("vnbselected",
6143 "vnbselected", __FILE__, VNbSelected, group);
6144 theCommands.Add("vantialiasing",
6145 "vantialiasing 1|0",
6146 __FILE__,VAntialiasing,group);
6147 theCommands.Add ("vpurgedisplay",
6149 "- removes structures which don't belong to objects displayed in neutral point",
6150 __FILE__, VPurgeDisplay, group);
6151 theCommands.Add("vsetviewsize",
6152 "vsetviewsize size",
6153 __FILE__,VSetViewSize,group);
6154 theCommands.Add("vmoveview",
6155 "vmoveview Dx Dy Dz [Start = 1|0]",
6156 __FILE__,VMoveView,group);
6157 theCommands.Add("vtranslateview",
6158 "vtranslateview Dx Dy Dz [Start = 1|0)]",
6159 __FILE__,VTranslateView,group);
6160 theCommands.Add("vturnview",
6161 "vturnview Ax Ay Az [Start = 1|0]",
6162 __FILE__,VTurnView,group);
6163 theCommands.Add("vtextureenv",
6164 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
6165 "or user-defined file and optionally applying texture mapping parameters\n"
6167 " vtextureenv off - disables environment mapping\n"
6168 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
6169 " std_texture = (0..7)\n"
6170 " rep = {clamp|repeat}\n"
6171 " mod = {decal|modulate}\n"
6172 " flt = {nearest|bilinear|trilinear}\n"
6173 " ss, st - scale factors for s and t texture coordinates\n"
6174 " ts, tt - translation for s and t texture coordinates\n"
6175 " rot - texture rotation angle in degrees",
6176 __FILE__, VTextureEnv, group);
6177 theCommands.Add("vhlr" ,
6178 "is_enabled={on|off}"
6179 " - Hidden line removal algorithm:"
6180 " - is_enabled: if is on HLR algorithm is applied\n",
6181 __FILE__,VHLR,group);
6182 theCommands.Add("vhlrtype" ,
6183 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
6184 " - Changes the type of HLR algorithm using for shapes."
6185 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
6186 " if equals to polyalgo, polygonal HLR algorithm is applied."
6187 "If shapes are not given HLR algoithm of given type is applied"
6188 " to all shapes in the view\n",
6189 __FILE__,VHLRType,group);
6190 theCommands.Add("vclipplane", "vclipplane usage: \n"
6191 " maxplanes <view_name> - get plane limit for view.\n"
6192 " create <plane_name> - create new plane.\n"
6193 " delete <plane_name> - delete plane.\n"
6194 " clone <source_plane> <plane_name> - clone the plane definition.\n"
6195 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
6196 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
6197 " change <plane_name> on/off - turn clipping on/off.\n"
6198 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
6199 " change <plane_name> capping on/off - turn capping on/off.\n"
6200 " change <plane_name> capping color <r> <g> <b> - set color.\n"
6201 " change <plane name> capping texname <texture> - set texture.\n"
6202 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
6203 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
6204 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
6205 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
6206 " please use VSetTextureMode command to enable texture rendering in view.\n"
6207 , __FILE__, VClipPlane, group);
6208 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
6210 " 0 - no textures enabled in view.\n"
6211 " 1 - only environment textures enabled.\n"
6212 " 2 - all textures enabled.\n"
6213 " this command sets texture details mode for the specified view.\n"
6214 , __FILE__, VSetTextureMode, group);
6215 theCommands.Add("vdefaults",
6216 "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
6217 __FILE__, VDefaults, group);
6218 theCommands.Add("vlight",
6219 "vlight [add|new {amb}ient|directional|{spot}light|positional]"
6220 "\n\t\t: [{del}ete|change lightId] [local|global]"
6221 "\n\t\t: [{pos}ition X Y Z] [color colorName] [{head}light 0|1]"
6222 "\n\t\t: [{constAtten}uation value] [{linearAtten}uation value]"
6223 "\n\t\t: [angle angleDeg] [{spotexp}onent value]",
6224 __FILE__, VLight, group);
6225 theCommands.Add("vraytrace",
6227 __FILE__,VRaytrace,group);
6228 theCommands.Add("vclinfo",
6230 __FILE__,VClInfo,group);
6231 theCommands.Add("vsetraytracemode",
6232 "vsetraytracemode [shad=0|1] [refl=0|1] [aa=0|1]",
6233 __FILE__,VSetRaytraceMode,group);