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 =
639 new AIS_InteractiveContext(a3DViewer);
640 ViewerTest::SetAISContext (aContext);
641 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
644 ViewerTest::ResetEventManager();
647 #if defined(_WIN32) || defined(__WIN32__)
648 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
649 Handle(WNT_WClass)::DownCast (WClass()),
650 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
654 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
655 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
657 aPxWidth, aPxHeight);
658 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
660 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
663 aPxWidth, aPxHeight);
665 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
668 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
670 ViewerTest::CurrentView(aView);
671 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
672 TheNISContext()->AttachView (aView);
674 // Setup for X11 or NT
677 // Set parameters for V3d_View and V3d_Viewer
678 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
679 aV3dView->SetComputedMode(Standard_False);
680 MyHLRIsOn = aV3dView->ComputedMode();
681 aV3dView->SetZClippingDepth(0.5);
682 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
684 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
687 a3DViewer->SetDefaultLights();
688 a3DViewer->SetLightOn();
691 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
692 #if TCL_MAJOR_VERSION < 8
693 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
694 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
696 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
697 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
701 VT_GetWindow()->Map();
703 // Set the handle of created view in the event manager
704 ViewerTest::ResetEventManager();
706 ViewerTest::CurrentView()->Redraw();
711 return aViewNames.GetViewName();
714 //==============================================================================
715 //function : RedrawAllViews
716 //purpose : Redraw all created views
717 //==============================================================================
718 void ViewerTest::RedrawAllViews()
720 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
721 for (; aViewIt.More(); aViewIt.Next())
723 const Handle(V3d_View)& aView = aViewIt.Key2();
728 //==============================================================================
729 //function : splitParameter
730 //purpose : Split parameter string to parameter name an parameter value
731 //==============================================================================
732 Standard_Boolean splitParameter (const TCollection_AsciiString& theString,
733 TCollection_AsciiString& theName,
734 TCollection_AsciiString& theValue)
736 Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
737 if (aParamNameEnd == 0)
738 return Standard_False;
739 TCollection_AsciiString aString(theString);
740 if (aParamNameEnd != 0)
742 theValue = aString.Split(aParamNameEnd);
743 aString.Split(aString.Length()-1);
746 return Standard_True;
749 //==============================================================================
751 //purpose : Create the window viewer and initialize all the global variable
752 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
753 //==============================================================================
755 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
759 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
760 << "Type help for more information.\n";
763 TCollection_AsciiString aViewName (""),
765 Standard_Integer aPxLeft = 0,
770 for (Standard_Integer i = 1; i < theArgsNb; ++i)
772 TCollection_AsciiString aName = "", aValue = "";
773 if(!splitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
775 // In case of syntax: vinit ViewName
776 aViewName = theArgVec[1];
784 else if (aName == "l" || aName == "left")
785 aPxLeft = aValue.IntegerValue();
786 else if (aName == "t" || aName == "top")
787 aPxTop = aValue.IntegerValue();
788 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
789 else if (aName == "display")
790 aDisplayName = aValue;
792 else if (aName == "w" || aName == "width")
793 aPxWidth = aValue.IntegerValue();
794 else if (aName == "h" || aName == "height")
795 aPxHeight = aValue.IntegerValue();
798 theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n";
803 ViewerTest_Names aViewNames (aViewName);
804 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
806 TCollection_AsciiString aCommand("vactivate ");
807 aCommand = aCommand + aViewNames.GetViewName();
808 theDi.Eval(aCommand.ToCString());
812 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
813 aViewName.ToCString(),
814 aDisplayName.ToCString());
815 cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n";
819 //==============================================================================
821 //purpose : hidden lines removal algorithm
822 //==============================================================================
824 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
826 if (ViewerTest::CurrentView().IsNull())
828 di << argv[0] << ": Call vinit before this command, please.\n";
834 di << argv[0] << ": Wrong number of command arguments.\n"
835 << "Type help " << argv[0] << " for more information.\n";
839 Standard_Boolean isHLROn =
840 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
842 if (isHLROn == MyHLRIsOn)
848 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
853 //==============================================================================
854 //function : VHLRType
855 //purpose : change type of using HLR algorithm
856 //==============================================================================
858 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
860 if (ViewerTest::CurrentView().IsNull())
862 di << argv[0] << ": Call vinit before this command, please.\n";
868 di << argv[0] << ": Wrong number of command arguments.\n"
869 << "Type help " << argv[0] << " for more information.\n";
873 Prs3d_TypeOfHLR aTypeOfHLR =
874 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
878 AIS_ListOfInteractive aListOfShapes;
879 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
880 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
881 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
882 anIter.More(); anIter.Next())
884 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
887 if (aShape->TypeOfHLR() != aTypeOfHLR)
888 aShape->SetTypeOfHLR (aTypeOfHLR);
892 ViewerTest::CurrentView()->Update();
897 for (Standard_Integer i = 2; i < argc; ++i)
899 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
900 TCollection_AsciiString aName (argv[i]);
902 if (!aMap.IsBound2 (aName))
904 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
907 Handle(AIS_Shape) anAISObject =
908 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
909 if (anAISObject.IsNull())
911 anAISObject->SetTypeOfHLR (aTypeOfHLR);
913 anAISObject->Redisplay();
915 ViewerTest::CurrentView()->Update();
921 //==============================================================================
922 //function : FindViewIdByWindowHandle
923 //purpose : Find theView Id in the map of views by window handle
924 //==============================================================================
925 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
926 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
928 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
929 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
931 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
932 if (aWindowHandle == theWindowHandle)
933 return anIter.Key1();
935 return TCollection_AsciiString("");
939 //==============================================================================
940 //function : ActivateView
941 //purpose : Make the view active
942 //==============================================================================
944 void ActivateView (const TCollection_AsciiString& theViewName)
946 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
949 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
950 if (!anAISContext.IsNull())
952 if (!ViewerTest::CurrentView().IsNull())
954 TCollection_AsciiString aTitle("3D View - ");
955 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
956 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
959 ViewerTest::CurrentView (aView);
960 // Update degenerate mode
961 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
962 ViewerTest::SetAISContext (anAISContext);
963 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
964 aTitle = aTitle + theViewName + "(*)";
965 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
966 #if defined(_WIN32) || defined(__WIN32__)
967 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
968 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
969 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
971 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
973 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
974 ViewerTest::CurrentView()->Redraw();
979 //==============================================================================
980 //function : RemoveView
981 //purpose : Close and remove view from display, clear maps if neccessary
982 //==============================================================================
983 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
985 if (!ViewerTest_myViews.IsBound1(theViewName))
987 cout << "Wrong view name\n";
991 // Activate another view if it's active now
992 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
994 if (ViewerTest_myViews.Extent() > 1)
996 TCollection_AsciiString aNewViewName;
997 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
998 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
999 if (anIter.Key1() != theViewName)
1001 aNewViewName = anIter.Key1();
1004 ActivateView (aNewViewName);
1008 Handle(V3d_View) anEmptyView;
1009 #if defined(_WIN32) || defined(__WIN32__)
1010 Handle(WNT_Window) anEmptyWindow;
1011 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1012 Handle(Cocoa_Window) anEmptyWindow;
1014 Handle(Xw_Window) anEmptyWindow;
1016 VT_GetWindow() = anEmptyWindow;
1017 ViewerTest::CurrentView (anEmptyView);
1018 if (isContextRemoved)
1020 Handle(AIS_InteractiveContext) anEmptyContext;
1021 ViewerTest::SetAISContext(anEmptyContext);
1027 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1028 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1030 // Remove view resources
1031 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1032 ViewerTest_myViews.UnBind1(theViewName);
1035 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1036 XFlush (GetDisplayConnection()->GetDisplay());
1039 // Keep context opened only if the closed view is last to avoid
1040 // unused empty contexts
1041 if (!aCurrentContext.IsNull())
1043 // Check if there are more difined views in the viewer
1044 aCurrentContext->CurrentViewer()->InitDefinedViews();
1045 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1047 // Remove driver if there is no viewers that use it
1048 Standard_Boolean isRemoveDriver = Standard_True;
1049 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1050 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1052 if (aCurrentContext != anIter.Key2() &&
1053 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1055 isRemoveDriver = Standard_False;
1061 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1062 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1063 #if TCL_MAJOR_VERSION < 8
1064 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1066 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1071 ViewerTest_myContexts.UnBind2(aCurrentContext);
1074 cout << "3D View - " << theViewName << " was deleted.\n";
1078 //==============================================================================
1080 //purpose : Remove the view defined by its name
1081 //==============================================================================
1083 static int VClose (Draw_Interpretor& /*theDi*/,
1084 Standard_Integer theArgsNb,
1085 const char** theArgVec)
1087 NCollection_List<TCollection_AsciiString> aViewList;
1090 TCollection_AsciiString anArg (theArgVec[1]);
1092 if (anArg.IsEqual ("ALL")
1093 || anArg.IsEqual ("*"))
1095 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1096 anIter.More(); anIter.Next())
1098 aViewList.Append (anIter.Key1());
1100 if (aViewList.IsEmpty())
1102 std::cout << "No view to close\n";
1108 ViewerTest_Names aViewName (theArgVec[1]);
1109 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1111 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1114 aViewList.Append (aViewName.GetViewName());
1119 // close active view
1120 if (ViewerTest::CurrentView().IsNull())
1122 std::cerr << "No active view!\n";
1125 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1128 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1129 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1130 anIter.More(); anIter.Next())
1132 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1138 //==============================================================================
1139 //function : VActivate
1140 //purpose : Activate the view defined by its ID
1141 //==============================================================================
1143 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1147 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1148 << "Usage: " << theArgVec[0] << " ViewID\n";
1153 theDi.Eval("vviewlist");
1157 TCollection_AsciiString aNameString(theArgVec[1]);
1158 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1160 TCollection_AsciiString aTitle("3D View - ");
1161 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1162 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1163 Handle(V3d_View) anEmptyView;
1164 #if defined(_WIN32) || defined(__WIN32__)
1165 Handle(WNT_Window) anEmptyWindow;
1166 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1167 Handle(Cocoa_Window) anEmptyWindow;
1169 Handle(Xw_Window) anEmptyWindow;
1171 VT_GetWindow() = anEmptyWindow;
1172 ViewerTest::CurrentView (anEmptyView);
1173 ViewerTest::ResetEventManager();
1174 theDi << theArgVec[0] << ": all views are inactive\n";
1178 ViewerTest_Names aViewNames(aNameString);
1180 // Check if this view exists in the viewer with the driver
1181 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1183 theDi << "Wrong view name\n";
1187 // Check if it is active already
1188 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1190 theDi << theArgVec[0] << ": the view is active already\n";
1194 ActivateView (aViewNames.GetViewName());
1198 //==============================================================================
1199 //function : VViewList
1200 //purpose : Print current list of views per viewer and graphic driver ID
1201 // shared between viewers
1202 //==============================================================================
1204 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1208 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1209 << "Usage: " << theArgVec[0] << " name";
1212 if (ViewerTest_myContexts.Size() < 1)
1215 Standard_Boolean isTreeView =
1216 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1219 theDi << theArgVec[0] <<":\n";
1221 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1222 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1225 theDi << aDriverIter.Key1() << ":\n";
1227 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1228 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1230 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1234 TCollection_AsciiString aContextName(aContextIter.Key1());
1235 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1238 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1239 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1241 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1243 TCollection_AsciiString aViewName(aViewIter.Key1());
1246 if (aViewIter.Value() == ViewerTest::CurrentView())
1247 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1249 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1253 theDi << aViewName << " ";
1263 //==============================================================================
1264 //function : VT_ProcessKeyPress
1265 //purpose : Handle KeyPress event from a CString
1266 //==============================================================================
1267 void VT_ProcessKeyPress (const char* buf_ret)
1269 //cout << "KeyPress" << endl;
1270 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1271 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1272 // Letter in alphabetic order
1274 if (!strcasecmp (buf_ret, "A"))
1277 aView->SetProj(V3d_XposYnegZpos);
1279 else if (!strcasecmp (buf_ret, "D"))
1284 else if (!strcasecmp (buf_ret, "F"))
1287 if (aNisView.IsNull())
1290 aNisView->FitAll3d();
1292 else if (!strcasecmp (buf_ret, "H"))
1295 cout << "HLR" << endl;
1296 aView->SetComputedMode (!aView->ComputedMode());
1297 MyHLRIsOn = aView->ComputedMode();
1299 else if (!strcasecmp (buf_ret, "P"))
1302 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1303 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1304 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1306 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1307 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1309 AIS_ListOfInteractive aListOfShapes;
1310 aContext->DisplayedObjects(aListOfShapes);
1311 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1312 anIter.More(); anIter.Next())
1314 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1315 if (aShape.IsNull())
1317 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1318 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1320 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1321 aShape->Redisplay();
1326 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1328 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1329 if (aShape.IsNull())
1331 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1332 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1334 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1335 aShape->Redisplay();
1339 aContext->UpdateCurrentViewer();
1342 else if (!strcasecmp (buf_ret, "S"))
1344 std::cout << "setup Shaded display mode" << std::endl;
1346 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1347 if(Ctx->NbCurrents()==0 ||
1348 Ctx->NbSelected()==0)
1349 Ctx->SetDisplayMode(AIS_Shaded);
1351 if(Ctx->HasOpenedContext()){
1352 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1353 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1356 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1357 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1359 Ctx->UpdateCurrentViewer();
1362 else if (!strcasecmp (buf_ret, "U"))
1364 // Unset display mode
1365 std::cout << "reset display mode to defaults" << std::endl;
1367 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1368 if(Ctx->NbCurrents()==0 ||
1369 Ctx->NbSelected()==0)
1370 Ctx->SetDisplayMode(AIS_WireFrame);
1372 if(Ctx->HasOpenedContext()){
1373 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1374 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1377 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1378 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1380 Ctx->UpdateCurrentViewer();
1384 else if (!strcasecmp (buf_ret, "T"))
1387 aView->SetProj(V3d_Zpos);
1389 else if (!strcasecmp (buf_ret, "B"))
1392 aView->SetProj(V3d_Zneg);
1394 else if (!strcasecmp (buf_ret, "L"))
1397 aView->SetProj(V3d_Xneg);
1399 else if (!strcasecmp (buf_ret, "R"))
1402 aView->SetProj(V3d_Xpos);
1404 else if (!strcasecmp (buf_ret, "W"))
1406 std::cout << "setup WireFrame display mode" << std::endl;
1407 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1408 if(Ctx->NbCurrents()==0 ||
1409 Ctx->NbSelected()==0)
1410 Ctx->SetDisplayMode(AIS_WireFrame);
1412 if(Ctx->HasOpenedContext()){
1413 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1414 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1417 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1418 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1420 Ctx->UpdateCurrentViewer();
1423 else if (!strcasecmp (buf_ret, "Z"))
1427 cout << "ZClipping OFF" << endl;
1430 aView->SetZClippingType(V3d_OFF);
1434 cout << "ZClipping ON" << endl;
1437 aView->SetZClippingType(V3d_FRONT);
1441 else if (!strcasecmp (buf_ret, ","))
1443 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1445 else if (!strcasecmp (buf_ret, "."))
1447 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1449 else if (*buf_ret == THE_KEY_DELETE)
1451 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1453 && aCtx->NbCurrents() > 0
1454 && aCtx->NbSelected() > 0)
1456 Draw_Interprete ("verase");
1462 Standard_Integer Num = Draw::Atoi(buf_ret);
1463 if(Num>=0 && Num<=7)
1464 ViewerTest::StandardModeActivation(Num);
1468 //==============================================================================
1469 //function : VT_ProcessExpose
1470 //purpose : Redraw the View on an Expose Event
1471 //==============================================================================
1472 void VT_ProcessExpose()
1474 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1475 if (!aView3d.IsNull())
1481 //==============================================================================
1482 //function : VT_ProcessConfigure
1483 //purpose : Resize the View on an Configure Event
1484 //==============================================================================
1485 void VT_ProcessConfigure()
1487 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1488 if (aView3d.IsNull())
1493 aView3d->MustBeResized();
1498 //==============================================================================
1499 //function : VT_ProcessButton1Press
1501 //==============================================================================
1502 Standard_Boolean VT_ProcessButton1Press(
1505 Standard_Boolean pick,
1506 Standard_Boolean shift)
1508 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1510 Standard_Real X, Y, Z;
1512 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1514 Draw::Set(argv[1], X);
1515 Draw::Set(argv[2], Y);
1516 Draw::Set(argv[3], Z);}
1527 //==============================================================================
1528 //function : VT_ProcessButton1Release
1529 //purpose : End selecting
1530 //==============================================================================
1531 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1535 IsDragged = Standard_False;
1536 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1539 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1540 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1544 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1545 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1550 //==============================================================================
1551 //function : VT_ProcessButton3Press
1552 //purpose : Start Rotation
1553 //==============================================================================
1554 void VT_ProcessButton3Press()
1559 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1561 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1564 //==============================================================================
1565 //function : VT_ProcessButton3Release
1566 //purpose : End rotation
1567 //==============================================================================
1568 void VT_ProcessButton3Release()
1575 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1580 //==============================================================================
1581 //function : ProcessZClipMotion
1583 //==============================================================================
1585 void ProcessZClipMotion()
1587 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1588 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1589 static Standard_Real CurZPos = 0.;
1591 //Quantity_Length VDX, VDY;
1592 //a3DView->Size(VDX,VDY);
1593 //Standard_Real VDZ = a3DView->ZSize();
1594 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1596 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1598 // Front = Depth + width/2.
1599 Standard_Real D = 0.5;
1600 Standard_Real W = 0.1;
1606 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1608 a3DView->SetZClippingType(V3d_OFF);
1609 a3DView->SetZClippingDepth(D);
1610 a3DView->SetZClippingWidth(W);
1611 a3DView->SetZClippingType(V3d_FRONT);
1615 X_ButtonPress = X_Motion;
1616 Y_ButtonPress = Y_Motion;
1620 //==============================================================================
1621 //function : ProcessControlButton1Motion
1623 //==============================================================================
1625 static void ProcessControlButton1Motion()
1627 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1629 X_ButtonPress = X_Motion;
1630 Y_ButtonPress = Y_Motion;
1633 //==============================================================================
1634 //function : VT_ProcessControlButton2Motion
1636 //==============================================================================
1637 void VT_ProcessControlButton2Motion()
1639 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1640 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1642 dy = -dy; // Xwindow Y axis is from top to Bottom
1644 ViewerTest::CurrentView()->Panning( dx, dy );
1646 X_ButtonPress = X_Motion;
1647 Y_ButtonPress = Y_Motion;
1650 //==============================================================================
1651 //function : VT_ProcessControlButton3Motion
1652 //purpose : Rotation
1653 //==============================================================================
1654 void VT_ProcessControlButton3Motion()
1658 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1662 //==============================================================================
1663 //function : VT_ProcessMotion
1665 //==============================================================================
1666 void VT_ProcessMotion()
1668 //pre-hilights detected objects at mouse position
1670 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1671 EM->MoveTo(X_Motion, Y_Motion);
1675 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1677 Xpix = X_Motion;Ypix=Y_Motion;
1680 //==============================================================================
1681 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1682 //purpose : Switches to an axonometric, top, left and other views
1683 //==============================================================================
1685 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1687 if ( ViewerTest::CurrentView().IsNull() )
1689 di<<"Call vinit before this command, please"<<"\n";
1693 ViewerTest::CurrentView()->SetProj(ori);
1697 //==============================================================================
1699 //purpose : Switch to an Axonometric view
1700 //Draw arg : No args
1701 //==============================================================================
1703 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1705 return ViewProject(di, V3d_XposYnegZpos);
1708 //==============================================================================
1710 //purpose : Switch to a Top View
1711 //Draw arg : No args
1712 //==============================================================================
1714 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1716 return ViewProject(di, V3d_Zpos);
1719 //==============================================================================
1720 //function : VBottom
1721 //purpose : Switch to a Bottom View
1722 //Draw arg : No args
1723 //==============================================================================
1725 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1727 return ViewProject(di, V3d_Zneg);
1730 //==============================================================================
1732 //purpose : Switch to a Left View
1733 //Draw arg : No args
1734 //==============================================================================
1736 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1738 return ViewProject(di, V3d_Ypos);
1741 //==============================================================================
1743 //purpose : Switch to a Right View
1744 //Draw arg : No args
1745 //==============================================================================
1747 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1749 return ViewProject(di, V3d_Yneg);
1752 //==============================================================================
1754 //purpose : Switch to a Front View
1755 //Draw arg : No args
1756 //==============================================================================
1758 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1760 return ViewProject(di, V3d_Xpos);
1763 //==============================================================================
1765 //purpose : Switch to a Back View
1766 //Draw arg : No args
1767 //==============================================================================
1769 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1771 return ViewProject(di, V3d_Xneg);
1774 //==============================================================================
1776 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1777 //Draw arg : No args
1778 //==============================================================================
1780 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1783 di << "Q : Quit the application" << "\n";
1785 di << "========================="<<"\n";
1786 di << "F : FitAll" << "\n";
1787 di << "T : TopView" << "\n";
1788 di << "B : BottomView" << "\n";
1789 di << "R : RightView" << "\n";
1790 di << "L : LeftView" << "\n";
1791 di << "A : AxonometricView" << "\n";
1792 di << "D : ResetView" << "\n";
1794 di << "========================="<<"\n";
1795 di << "S : Shading" << "\n";
1796 di << "W : Wireframe" << "\n";
1797 di << "H : HidelLineRemoval" << "\n";
1798 di << "U : Unset display mode" << "\n";
1799 di << "Delete : Remove selection from viewer" << "\n";
1801 di << "========================="<<"\n";
1802 di << "Selection mode "<<"\n";
1803 di << "0 : Shape" <<"\n";
1804 di << "1 : Vertex" <<"\n";
1805 di << "2 : Edge" <<"\n";
1806 di << "3 : Wire" <<"\n";
1807 di << "4 : Face" <<"\n";
1808 di << "5 : Shell" <<"\n";
1809 di << "6 : Solid" <<"\n";
1810 di << "7 : Compound" <<"\n";
1812 di << "========================="<<"\n";
1813 di << "Z : Switch Z clipping On/Off" << "\n";
1814 di << ", : Hilight next detected" << "\n";
1815 di << ". : Hilight previous detected" << "\n";
1822 static Standard_Boolean Ppick = 0;
1823 static Standard_Integer Pargc = 0;
1824 static const char** Pargv = NULL;
1827 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1832 if (!ViewerTest_myViews.IsEmpty()) {
1834 WPARAM fwKeys = wParam;
1839 // Delete view from map of views
1840 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1845 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1846 || ViewerTest::CurrentView().IsNull())
1848 // Activate inactive window
1849 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1851 ActivateView (FindViewIdByWindowHandle(hwnd));
1856 IsDragged = Standard_False;
1859 HDC hdc = GetDC( hwnd );
1860 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1861 SetROP2( hdc, R2_NOT );
1862 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1863 ReleaseDC( hwnd, hdc );
1865 const Handle(ViewerTest_EventManager) EM =
1866 ViewerTest::CurrentEventManager();
1867 if ( fwKeys & MK_SHIFT )
1868 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1869 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1871 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1872 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1874 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1876 case WM_LBUTTONDOWN:
1877 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1879 IsDragged = Standard_True;
1880 DragFirst = Standard_True;
1881 X_ButtonPress = LOWORD(lParam);
1882 Y_ButtonPress = HIWORD(lParam);
1884 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1891 HDC hdc = GetDC( hwnd );
1893 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1894 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1895 SetROP2( hdc, R2_NOT );
1898 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1900 DragFirst = Standard_False;
1901 X_Motion = LOWORD(lParam);
1902 Y_Motion = HIWORD(lParam);
1904 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1906 SelectObject( hdc, anObj );
1908 ReleaseDC( hwnd, hdc );
1911 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1915 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1919 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1923 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1930 if ( !ViewerTest::CurrentView().IsNull() ) {
1935 BeginPaint(hwnd, &ps);
1936 EndPaint(hwnd, &ps);
1941 VT_ProcessConfigure();
1945 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1948 c[0] = (char) wParam;
1950 if (wParam == VK_DELETE)
1952 c[0] = THE_KEY_DELETE;
1954 VT_ProcessKeyPress (c);
1962 VT_ProcessButton3Release();
1965 case WM_LBUTTONDOWN:
1966 case WM_MBUTTONDOWN:
1967 case WM_RBUTTONDOWN:
1969 WPARAM fwKeys = wParam;
1973 X_ButtonPress = LOWORD(lParam);
1974 Y_ButtonPress = HIWORD(lParam);
1976 if (Msg == WM_LBUTTONDOWN)
1978 if (fwKeys & MK_CONTROL)
1980 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1984 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1987 else if (Msg == WM_RBUTTONDOWN)
1990 VT_ProcessButton3Press();
1997 //cout << "\t WM_MOUSEMOVE" << endl;
1998 WPARAM fwKeys = wParam;
1999 X_Motion = LOWORD(lParam);
2000 Y_Motion = HIWORD(lParam);
2003 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2005 X_ButtonPress = LOWORD(lParam);
2006 Y_ButtonPress = HIWORD(lParam);
2008 if ( fwKeys & MK_RBUTTON ) {
2010 VT_ProcessButton3Press();
2014 if ( fwKeys & MK_CONTROL ) {
2015 if ( fwKeys & MK_LBUTTON ) {
2016 ProcessControlButton1Motion();
2018 else if ( fwKeys & MK_MBUTTON ||
2019 ((fwKeys&MK_LBUTTON) &&
2020 (fwKeys&MK_RBUTTON) ) ){
2021 VT_ProcessControlButton2Motion();
2023 else if ( fwKeys & MK_RBUTTON ) {
2024 VT_ProcessControlButton3Motion();
2028 else if ( fwKeys & MK_SHIFT ) {
2029 if ( fwKeys & MK_MBUTTON ||
2030 ((fwKeys&MK_LBUTTON) &&
2031 (fwKeys&MK_RBUTTON) ) ) {
2032 cout << "ProcessZClipMotion()" << endl;
2033 ProcessZClipMotion();
2037 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2039 if ((fwKeys & MK_MBUTTON
2040 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2042 ProcessZClipMotion();
2053 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2058 return DefWindowProc( hwnd, Msg, wParam, lParam );
2064 //==============================================================================
2065 //function : ViewerMainLoop
2066 //purpose : Get a Event on the view and dispatch it
2067 //==============================================================================
2070 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2072 Ppick = (argc > 0)? 1 : 0;
2080 cout << "Start picking" << endl;
2082 while ( Ppick == 1 ) {
2083 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2084 if (GetMessage(&msg, NULL, 0, 0) ) {
2085 TranslateMessage(&msg);
2086 DispatchMessage(&msg);
2090 cout << "Picking done" << endl;
2096 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2098 int min( int a, int b )
2106 int max( int a, int b )
2114 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2117 static XEvent aReport;
2118 Standard_Boolean pick = argc > 0;
2119 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2120 XNextEvent (aDisplay, &aReport);
2122 // Handle event for the chosen display connection
2123 switch (aReport.type) {
2126 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2129 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2135 // Activate inactive view
2136 Window aWindow = GetWindowHandle(VT_GetWindow());
2137 if(aWindow != aReport.xfocus.window)
2139 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2148 case ConfigureNotify:
2150 VT_ProcessConfigure();
2159 XComposeStatus status_in_out;
2161 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2162 (char *) buf_ret , 10 ,
2163 &ks_ret , &status_in_out ) ;
2166 buf_ret[ret_len] = '\0' ;
2170 VT_ProcessKeyPress (buf_ret);
2176 X_ButtonPress = aReport.xbutton.x;
2177 Y_ButtonPress = aReport.xbutton.y;
2179 if (aReport.xbutton.button == Button1)
2181 if (aReport.xbutton.state & ControlMask)
2183 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2187 IsDragged = Standard_True;
2188 DragFirst = Standard_True;
2191 else if (aReport.xbutton.button == Button3)
2194 VT_ProcessButton3Press();
2204 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2205 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2206 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2209 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2210 if( aContext.IsNull() )
2212 cout << "The context is null. Please use vinit before createmesh" << endl;
2216 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2217 if( aReport.xbutton.button==1 )
2221 aContext->ShiftSelect();
2230 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2231 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2232 ViewerTest::CurrentView());
2236 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2237 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2238 ViewerTest::CurrentView() );
2241 VT_ProcessButton3Release();
2243 IsDragged = Standard_False;
2246 VT_ProcessButton3Release();
2251 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2257 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2258 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2259 XSetFunction( aDisplay, gc, GXinvert );
2262 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2264 X_Motion = aReport.xmotion.x;
2265 Y_Motion = aReport.xmotion.y;
2266 DragFirst = Standard_False;
2268 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2272 X_Motion = aReport.xmotion.x;
2273 Y_Motion = aReport.xmotion.y;
2275 // remove all the ButtonMotionMaskr
2276 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2278 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2279 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2281 Quantity_Length VDX, VDY;
2283 ViewerTest::CurrentView()->Size(VDX,VDY);
2284 Standard_Real VDZ =0 ;
2285 VDZ = ViewerTest::CurrentView()->ZSize();
2287 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2289 Quantity_Length dx = 0 ;
2290 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2294 dx = dx / VDX * VDZ;
2298 ViewerTest::CurrentView()->Redraw();
2302 if ( aReport.xmotion.state & ControlMask ) {
2303 if ( aReport.xmotion.state & Button1Mask ) {
2304 ProcessControlButton1Motion();
2306 else if ( aReport.xmotion.state & Button2Mask ) {
2307 VT_ProcessControlButton2Motion();
2309 else if ( aReport.xmotion.state & Button3Mask ) {
2310 VT_ProcessControlButton3Motion();
2324 //==============================================================================
2325 //function : VProcessEvents
2326 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2327 // event in the Viewer window
2328 //==============================================================================
2330 static void VProcessEvents(ClientData,int)
2332 NCollection_Vector<int> anEventNumbers;
2333 // Get number of messages from every display
2334 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2335 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2337 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2339 // Handle events for every display
2340 int anEventIter = 0;
2341 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2342 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2344 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2345 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2347 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2348 int anEventResult = ViewerMainLoop( 0, NULL);
2349 // If window is closed or context was not found finish current event processing loop
2355 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2360 //==============================================================================
2361 //function : OSWindowSetup
2362 //purpose : Setup for the X11 window to be able to cath the event
2363 //==============================================================================
2366 static void OSWindowSetup()
2368 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2371 Window window = VT_GetWindow()->XWindow();
2372 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2373 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2374 XSynchronize(aDisplay, 1);
2376 // X11 : For keyboard on SUN
2378 wmhints.flags = InputHint;
2381 XSetWMHints( aDisplay, window, &wmhints);
2383 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2384 ButtonPressMask | ButtonReleaseMask |
2385 StructureNotifyMask |
2387 Button1MotionMask | Button2MotionMask |
2388 Button3MotionMask | FocusChangeMask
2390 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2391 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2393 XSynchronize(aDisplay, 0);
2402 //==============================================================================
2405 //purpose : Fitall, no DRAW arguments
2406 //Draw arg : No args
2407 //==============================================================================
2409 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2411 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2412 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2413 if (V.IsNull() == Standard_False) {
2415 } else if (aView.IsNull() == Standard_False) {
2421 //==============================================================================
2423 //purpose : ZFitall, no DRAW arguments
2424 //Draw arg : No args
2425 //==============================================================================
2427 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2429 Handle(V3d_View) V = ViewerTest::CurrentView();
2430 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2433 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2435 Handle(V3d_View) V = ViewerTest::CurrentView();
2436 if ( !V.IsNull() ) V->Redraw(); return 0;
2440 //==============================================================================
2442 //purpose : Remove all the object from the viewer
2443 //Draw arg : No args
2444 //==============================================================================
2446 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2448 Handle(V3d_View) V = ViewerTest::CurrentView();
2450 ViewerTest::Clear();
2454 //==============================================================================
2457 //==============================================================================
2459 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2460 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2463 di << argv[0] << "Invalid number of arguments" << "\n";
2467 while (ViewerMainLoop( argc, argv)) {
2473 //==============================================================================
2474 //function : InitViewerTest
2475 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2476 //==============================================================================
2478 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2480 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2481 ViewerTest::SetAISContext(theContext);
2482 aViewer->InitActiveViews();
2483 Handle(V3d_View) aView = aViewer->ActiveView();
2484 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2485 ViewerTest::ResetEventManager();
2486 Handle(Aspect_Window) aWindow = aView->Window();
2487 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2489 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2491 static int aFirst = 1;
2493 #if TCL_MAJOR_VERSION < 8
2494 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2495 TK_READABLE, VProcessEvents, (ClientData) 0);
2497 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2498 TK_READABLE, VProcessEvents, (ClientData) 0);
2505 //==============================================================================
2507 //purpose : Load image as background
2508 //==============================================================================
2510 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2512 if (argc < 2 || argc > 3)
2514 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2515 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2519 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2520 if(AISContext.IsNull())
2522 di << "use 'vinit' command before " << argv[0] << "\n";
2526 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2529 const char* szType = argv[2];
2530 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2531 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2532 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2533 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2536 di << "Wrong fill type : " << szType << "\n";
2537 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2542 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2543 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2548 //==============================================================================
2549 //function : VSetBgMode
2550 //purpose : Change background image fill type
2551 //==============================================================================
2553 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2557 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2558 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2562 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2563 if(AISContext.IsNull())
2565 di << "use 'vinit' command before " << argv[0] << "\n";
2568 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2569 const char* szType = argv[1];
2570 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2571 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2572 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2573 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2576 di << "Wrong fill type : " << szType << "\n";
2577 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2580 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2581 V3dView->SetBgImageStyle(aFillType, Standard_True);
2585 //==============================================================================
2586 //function : VSetGradientBg
2587 //purpose : Mount gradient background
2588 //==============================================================================
2589 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2593 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2594 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2595 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2596 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2600 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2601 if(AISContext.IsNull())
2603 di << "use 'vinit' command before " << argv[0] << "\n";
2609 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2610 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2611 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2612 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2614 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2615 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2616 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2618 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2619 int aType = Draw::Atoi(argv[7]);
2620 if( aType < 0 || aType > 8 )
2622 di << "Wrong fill type " << "\n";
2623 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2624 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2628 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2630 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2631 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2637 //==============================================================================
2638 //function : VSetGradientBgMode
2639 //purpose : Change gradient background fill style
2640 //==============================================================================
2641 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2645 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2646 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2647 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2651 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2652 if(AISContext.IsNull())
2654 di << "use 'vinit' command before " << argv[0] << "\n";
2659 int aType = Draw::Atoi(argv[1]);
2660 if( aType < 0 || aType > 8 )
2662 di << "Wrong fill type " << "\n";
2663 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2664 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2668 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2670 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2671 V3dView->SetBgGradientStyle( aMethod, 1 );
2677 //==============================================================================
2678 //function : VSetColorBg
2679 //purpose : Set color background
2680 //==============================================================================
2681 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2685 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2686 di << "R,G,B = [0..255]" << "\n";
2690 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2691 if(AISContext.IsNull())
2693 di << "use 'vinit' command before " << argv[0] << "\n";
2699 Standard_Real R = Draw::Atof(argv[1])/255.;
2700 Standard_Real G = Draw::Atof(argv[2])/255.;
2701 Standard_Real B = Draw::Atof(argv[3])/255.;
2702 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2704 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2705 V3dView->SetBackgroundColor( aColor );
2712 //==============================================================================
2714 //purpose : View Scaling
2715 //==============================================================================
2717 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2719 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2720 if ( V3dView.IsNull() ) return 1;
2723 di << argv[0] << "Invalid number of arguments" << "\n";
2726 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2729 //==============================================================================
2730 //function : VTestZBuffTrihedron
2731 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2732 //==============================================================================
2734 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2736 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2737 if ( V3dView.IsNull() ) return 1;
2739 V3dView->ZBufferTriedronSetup();
2742 // Set up default trihedron parameters
2743 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2747 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2748 const char* aPosType = argv[1];
2750 if ( strcmp(aPosType, "center") == 0 )
2752 aPosition = Aspect_TOTP_CENTER;
2754 if (strcmp(aPosType, "left_lower") == 0)
2756 aPosition = Aspect_TOTP_LEFT_LOWER;
2758 if (strcmp(aPosType, "left_upper") == 0)
2760 aPosition = Aspect_TOTP_LEFT_UPPER;
2762 if (strcmp(aPosType, "right_lower") == 0)
2764 aPosition = Aspect_TOTP_RIGHT_LOWER;
2766 if (strcmp(aPosType, "right_upper") == 0)
2768 aPosition = Aspect_TOTP_RIGHT_UPPER;
2771 di << argv[1] << " Invalid type of alignment" << "\n";
2772 di << "Must be one of [ center, left_lower," << "\n";
2773 di << "left_upper, right_lower, right_upper ]" << "\n";
2777 Standard_Real R = Draw::Atof(argv[2])/255.;
2778 Standard_Real G = Draw::Atof(argv[3])/255.;
2779 Standard_Real B = Draw::Atof(argv[4])/255.;
2780 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2782 Standard_Real aScale = Draw::Atof(argv[5]);
2786 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2790 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2791 const char* aPresType = argv[6];
2793 if ( strcmp(aPresType, "wireframe") == 0 )
2795 aPresentation = V3d_WIREFRAME;
2797 if (strcmp(aPresType, "zbuffer") == 0)
2799 aPresentation = V3d_ZBUFFER;
2802 di << argv[6] << " Invalid type of visualization" << "\n";
2803 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2807 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2811 di << argv[0] << " Invalid number of arguments" << "\n";
2820 //==============================================================================
2821 //function : VRotate
2822 //purpose : Camera Rotating
2823 //==============================================================================
2825 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2826 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2827 if ( V3dView.IsNull() ) {
2832 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2834 } else if ( argc == 7 ) {
2835 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]) );
2838 di << argv[0] << " Invalid number of arguments" << "\n";
2843 //==============================================================================
2845 //purpose : View zoom in / out (relative to current zoom)
2846 //==============================================================================
2848 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2849 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2850 if ( V3dView.IsNull() ) {
2855 Standard_Real coef = Draw::Atof(argv[1]);
2856 if ( coef <= 0.0 ) {
2857 di << argv[1] << "Invalid value" << "\n";
2860 V3dView->SetZoom( Draw::Atof(argv[1]) );
2863 di << argv[0] << " Invalid number of arguments" << "\n";
2868 //==============================================================================
2870 //purpose : View panning (in pixels)
2871 //==============================================================================
2873 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2874 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2875 if ( V3dView.IsNull() ) return 1;
2878 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2881 di << argv[0] << " Invalid number of arguments" << "\n";
2887 //==============================================================================
2888 //function : VExport
2889 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2890 //==============================================================================
2892 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2894 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2895 if (V3dView.IsNull())
2900 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2904 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2905 TCollection_AsciiString aFormatStr;
2907 TCollection_AsciiString aFileName (argv[1]);
2908 Standard_Integer aLen = aFileName.Length();
2912 aFormatStr = TCollection_AsciiString (argv[2]);
2916 if (aFileName.Value (aLen - 2) == '.')
2918 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2920 else if (aFileName.Value (aLen - 3) == '.')
2922 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2926 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2932 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2936 aFormatStr.UpperCase();
2937 if (aFormatStr == "PS")
2938 anExpFormat = Graphic3d_EF_PostScript;
2939 else if (aFormatStr == "EPS")
2940 anExpFormat = Graphic3d_EF_EnhPostScript;
2941 else if (aFormatStr == "TEX")
2942 anExpFormat = Graphic3d_EF_TEX;
2943 else if (aFormatStr == "PDF")
2944 anExpFormat = Graphic3d_EF_PDF;
2945 else if (aFormatStr == "SVG")
2946 anExpFormat = Graphic3d_EF_SVG;
2947 else if (aFormatStr == "PGF")
2948 anExpFormat = Graphic3d_EF_PGF;
2949 else if (aFormatStr == "EMF")
2950 anExpFormat = Graphic3d_EF_EMF;
2953 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2958 if (!V3dView->View()->Export (argv[1], anExpFormat))
2960 di << "Error: export of image to " << aFormatStr << " failed!\n";
2963 catch (Standard_Failure)
2965 di << "Error: export of image to " << aFormatStr << " failed";
2966 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2971 //==============================================================================
2972 //function : VColorScale
2973 //purpose : representation color scale
2974 //==============================================================================
2975 #include <V3d_ColorScale.hxx>
2977 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2979 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2981 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2985 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2986 if(aContext.IsNull()) {
2987 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2991 Standard_Real minRange = 0. , maxRange = 100. ;
2993 Standard_Integer numIntervals = 10 ;
2994 Standard_Integer textHeight = 16;
2995 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2996 Standard_Real X = 0., Y = 0. ;
3002 minRange = Draw::Atof( argv[1] );
3003 maxRange = Draw::Atof( argv[2] );
3004 numIntervals = Draw::Atoi( argv[3] );
3007 textHeight = Draw::Atoi( argv[4] );
3009 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
3012 X = Draw::Atof( argv[6] );
3013 Y = Draw::Atof( argv[7] );
3016 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3017 if ( curView.IsNull( ) )
3019 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3020 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3021 if( ! aCS.IsNull( ) )
3023 aCS->SetPosition( X , Y );
3024 aCS->SetHeight( 0.95) ;
3025 aCS->SetTextHeight( textHeight );
3026 aCS->SetRange( minRange , maxRange );
3027 aCS->SetNumberOfIntervals( numIntervals );
3028 aCS->SetLabelPosition( position );
3029 if( !curView->ColorScaleIsDisplayed() )
3030 curView->ColorScaleDisplay( );
3035 //==============================================================================
3036 //function : VGraduatedTrihedron
3037 //purpose : Displays a graduated trihedron
3038 //==============================================================================
3040 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3042 const char *str = arg;
3045 unsigned short c1 = *str++;
3046 unsigned short c2 = *str++;
3047 if (!c1 || !c2) break;
3048 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3052 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3055 if (argc != 2 && argc < 5)
3057 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3058 di<<"Usage: type help "<<argv[0]<<"\n";
3059 return 1; //TCL_ERROR
3062 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3064 // Create 3D view if it doesn't exist
3065 if ( aV3dView.IsNull() )
3067 ViewerTest::ViewerInit();
3068 aV3dView = ViewerTest::CurrentView();
3069 if( aV3dView.IsNull() )
3071 di << "Error: Cannot create a 3D view\n";
3072 return 1; //TCL_ERROR
3076 // Erase (==0) or display (!=0)
3077 const int display = Draw::Atoi(argv[1]);
3082 TCollection_AsciiString font;
3084 font.AssignCat("Courier");
3086 font.AssignCat(argv[5]);
3088 // Text is multibyte
3089 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3092 TCollection_ExtendedString xname, yname, zname;
3097 AddMultibyteString(xname, argv[2]);
3098 AddMultibyteString(yname, argv[3]);
3099 AddMultibyteString(zname, argv[4]);
3115 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3116 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3117 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3118 Standard_True/*drawgrid*/,
3119 Standard_True/*drawaxes*/,
3120 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3121 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3122 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3123 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3124 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3125 Quantity_NOC_WHITE/*gridcolor*/,
3126 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3127 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3130 aV3dView->GraduatedTrihedronErase();
3132 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3138 //==============================================================================
3139 //function : VPrintView
3140 //purpose : Test printing algorithm, print the view to image file with given
3141 // width and height. Printing implemented only for WNT.
3142 //==============================================================================
3143 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3147 di << "Printing implemented only for wnt!\n";
3151 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3152 Handle(V3d_View) aView = NULL;
3153 aContextAIS = ViewerTest::GetAISContext();
3154 if (!aContextAIS.IsNull())
3156 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3157 Vwr->InitActiveViews();
3158 if(Vwr->MoreActiveViews())
3159 aView = Vwr->ActiveView();
3165 di << "Call vinit before!\n";
3170 di << "Use: " << argv[0];
3171 di << " width height filename [print algo=0]\n";
3172 di << "width, height of the intermediate buffer for operation\n";
3173 di << "algo : {0|1}\n";
3174 di << " 0 - stretch algorithm\n";
3175 di << " 1 - tile algorithm\n";
3176 di << "test printing algorithms into an intermediate buffer\n";
3177 di << "with saving output to an image file\n";
3181 // get the input params
3182 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3183 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3184 Standard_Integer aMode = 0;
3185 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3187 aMode = Draw::Atoi (argv[4]);
3189 // check the input parameters
3190 if (aWidth <= 0 || aHeight <= 0)
3192 di << "Width and height must be positive values!\n";
3195 if (aMode != 0 && aMode != 1)
3198 // define compatible bitmap
3199 HDC anDC = CreateCompatibleDC(0);
3200 BITMAPINFO aBitmapData;
3201 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3202 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3203 aBitmapData.bmiHeader.biWidth = aWidth ;
3204 aBitmapData.bmiHeader.biHeight = aHeight;
3205 aBitmapData.bmiHeader.biPlanes = 1;
3206 aBitmapData.bmiHeader.biBitCount = 24;
3207 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3208 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3209 aBitmapData.bmiHeader.biClrUsed = 0;
3210 aBitmapData.bmiHeader.biClrImportant = 0;
3211 aBitmapData.bmiHeader.biCompression = BI_RGB;
3212 aBitmapData.bmiHeader.biSizeImage = 0;
3214 // Create Device Independent Bitmap
3215 void* aBitsOut = NULL;
3216 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3217 &aBitsOut, NULL, 0);
3218 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3220 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3221 if (aBitsOut != NULL)
3224 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3226 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3228 // succesfully printed into an intermediate buffer
3231 Image_PixMap aWrapper;
3232 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3233 aWrapper.SetTopDown (false);
3235 Image_AlienPixMap anImageBitmap;
3236 anImageBitmap.InitCopy (aWrapper);
3237 isSaved = anImageBitmap.Save (aFileName);
3241 di << "Print operation failed due to printing errors or\n";
3242 di << "insufficient memory available\n";
3243 di << "Please, try to use smaller dimensions for this test\n";
3244 di << "command, as it allocates intermediate buffer for storing\n";
3245 di << "the result\n";
3250 di << "Can't allocate memory for intermediate buffer\n";
3251 di << "Please use smaller dimensions\n";
3256 SelectObject (anDC, anOldBitmap);
3257 DeleteObject (aMemoryBitmap);
3263 di << "Save to file operation failed. This operation may fail\n";
3264 di << "if you don't have enough available memory, then you can\n";
3265 di << "use smaller dimensions for the output file\n";
3274 //==============================================================================
3275 //function : VZLayer
3276 //purpose : Test z layer operations for v3d viewer
3277 //==============================================================================
3278 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3280 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3281 if (aContextAIS.IsNull())
3283 di << "Call vinit before!\n";
3288 di << "Use: vzlayer " << argv[0];
3289 di << " add/del/get [id]\n";
3290 di << " add - add new z layer to viewer and print its id\n";
3291 di << " del - del z layer by its id\n";
3292 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3293 di << "id - the layer identificator value defined when removing z layer\n";
3297 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3298 if (aViewer.IsNull())
3300 di << "No active viewer!\n";
3304 // perform operation
3305 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3308 Standard_Integer aNewId;
3309 if (!aViewer->AddZLayer (aNewId))
3311 di << "Impossible to add new z layer!\n";
3315 di << "New z layer added with index: " << aNewId << "\n";
3317 else if (anOp == "del")
3321 di << "Please also provide as argument id of z layer to remove\n";
3325 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3326 if (!aViewer->RemoveZLayer (aDelId))
3328 di << "Impossible to remove the z layer or invalid id!\n";
3332 di << "Z layer " << aDelId << " has been removed\n";
3334 else if (anOp == "get")
3336 TColStd_SequenceOfInteger anIds;
3337 aViewer->GetAllZLayers (anIds);
3338 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3340 di << anIds.Value (aSeqIdx) << " ";
3347 di << "Invalid operation, please use { add / del / get }\n";
3354 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3356 // this class provides a presentation of text item in v3d view under-/overlayer
3357 class V3d_TextItem : public Visual3d_LayerItem
3362 DEFINE_STANDARD_RTTI(V3d_TextItem)
3365 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3366 const Standard_Real theX1,
3367 const Standard_Real theY1,
3368 const Standard_Real theHeight,
3369 const TCollection_AsciiString& theFontName,
3370 const Quantity_Color& theColor,
3371 const Quantity_Color& theSubtitleColor,
3372 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3373 const Handle(Visual3d_Layer)& theLayer);
3376 Standard_EXPORT void RedrawLayerPrs();
3382 TCollection_AsciiString myText;
3383 Standard_Real myHeight;
3384 Handle(Visual3d_Layer) myLayer;
3385 Quantity_Color myColor;
3386 Quantity_Color mySubtitleColor;
3387 Aspect_TypeOfDisplayText myType;
3388 TCollection_AsciiString myFontName;
3391 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3392 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3394 // create and add to display the text item
3395 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3396 const Standard_Real theX1,
3397 const Standard_Real theY1,
3398 const Standard_Real theHeight,
3399 const TCollection_AsciiString& theFontName,
3400 const Quantity_Color& theColor,
3401 const Quantity_Color& theSubtitleColor,
3402 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3403 const Handle(Visual3d_Layer)& theLayer)
3404 : myX1 (theX1), myY1 (theY1),
3406 myHeight (theHeight),
3409 mySubtitleColor (theSubtitleColor),
3410 myType (theTypeOfDisplay),
3411 myFontName (theFontName)
3413 if (!myLayer.IsNull ())
3414 myLayer->AddLayerItem (this);
3418 void V3d_TextItem::RedrawLayerPrs ()
3420 if (myLayer.IsNull ())
3423 myLayer->SetColor (myColor);
3424 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3425 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3428 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3430 // The Visual3d_LayerItem line item for "vlayerline" command
3431 // it provides a presentation of line with user-defined
3432 // linewidth, linetype and transparency.
3433 class V3d_LineItem : public Visual3d_LayerItem
3437 DEFINE_STANDARD_RTTI(V3d_LineItem)
3440 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3441 Standard_Real X2, Standard_Real Y2,
3442 V3d_LayerMgrPointer theLayerMgr,
3443 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3444 Standard_Real theWidth = 0.5,
3445 Standard_Real theTransp = 1.0);
3448 Standard_EXPORT void RedrawLayerPrs();
3452 Standard_Real myX1, myY1, myX2, myY2;
3453 V3d_LayerMgrPointer myLayerMgr;
3454 Aspect_TypeOfLine myType;
3455 Standard_Real myWidth;
3456 Standard_Real myTransparency;
3459 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3460 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3462 // default constructor for line item
3463 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3464 Standard_Real X2, Standard_Real Y2,
3465 V3d_LayerMgrPointer theLayerMgr,
3466 Aspect_TypeOfLine theType,
3467 Standard_Real theWidth,
3468 Standard_Real theTransp) :
3469 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3470 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3472 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3473 myLayerMgr->Overlay()->AddLayerItem (this);
3477 void V3d_LineItem::RedrawLayerPrs ()
3479 Handle (Visual3d_Layer) aOverlay;
3482 aOverlay = myLayerMgr->Overlay();
3484 if (!aOverlay.IsNull())
3486 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3487 aOverlay->SetColor(aColor);
3488 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3489 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3490 aOverlay->BeginPolyline();
3491 aOverlay->AddVertex(myX1, myY1);
3492 aOverlay->AddVertex(myX2, myY2);
3493 aOverlay->ClosePrimitive();
3497 //=============================================================================
3498 //function : VLayerLine
3499 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3500 // : linewidth, transparency coefficient
3501 //============================================================================
3502 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3504 // get the active view
3505 Handle(V3d_View) aView = ViewerTest::CurrentView();
3508 di << "Call vinit before!\n";
3513 di << "Use: " << argv[0];
3514 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3515 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3516 di << " 0 - solid \n";
3517 di << " 1 - dashed \n";
3518 di << " 2 - dot \n";
3519 di << " 3 - dashdot\n";
3520 di << " transparency : { 0.0 - 1.0 } \n";
3521 di << " 0.0 - transparent\n";
3522 di << " 1.0 - visible \n";
3526 // get the input params
3527 Standard_Real X1 = Draw::Atof(argv[1]);
3528 Standard_Real Y1 = Draw::Atof(argv[2]);
3529 Standard_Real X2 = Draw::Atof(argv[3]);
3530 Standard_Real Y2 = Draw::Atof(argv[4]);
3532 Standard_Real aWidth = 0.5;
3533 Standard_Integer aType = 0;
3534 Standard_Real aTransparency = 1.0;
3538 aWidth = Draw::Atof(argv[5]);
3542 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3547 aTransparency = Draw::Atof(argv[7]);
3548 if (aTransparency < 0 || aTransparency > 1.0)
3549 aTransparency = 1.0;
3552 // select appropriate line type
3553 Aspect_TypeOfLine aLineType;
3557 aLineType = Aspect_TOL_DASH;
3561 aLineType = Aspect_TOL_DOT;
3565 aLineType = Aspect_TOL_DOTDASH;
3569 aLineType = Aspect_TOL_SOLID;
3572 // replace layer manager
3573 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3574 aView->SetLayerMgr(aMgr);
3577 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3583 aView->MustBeResized();
3589 //=======================================================================
3590 //function : VOverlayText
3591 //purpose : Test text displaying in view overlay
3592 //=======================================================================
3593 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3595 // get the active view
3596 Handle(V3d_View) aView = ViewerTest::CurrentView();
3599 di << "No active view. Please call vinit.\n";
3602 else if (argc < 4 || argc > 13)
3604 di << "Use: " << argv[0];
3605 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3606 di << "[background_color: R G B]\n";
3607 di << " height - pixel height of the text (default=10.0)\n";
3608 di << " font_name - name of font (default=courier)\n";
3609 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3610 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
3611 di << " background_color- R G B values used for subtitle and decal text\n";
3612 di << "(default=255.0 255.0 255.0)\n";
3616 TCollection_AsciiString aText (argv[1]);
3617 Standard_Real aPosX = Draw::Atof(argv[2]);
3618 Standard_Real aPosY = Draw::Atof(argv[3]);
3619 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3622 TCollection_AsciiString aFontName = "Courier";
3624 aFontName = TCollection_AsciiString (argv[5]);
3627 Quantity_Parameter aColorRed = 1.0;
3628 Quantity_Parameter aColorGreen = 1.0;
3629 Quantity_Parameter aColorBlue = 1.0;
3632 aColorRed = Draw::Atof (argv[6])/255.;
3633 aColorGreen = Draw::Atof (argv[7])/255.;
3634 aColorBlue = Draw::Atof (argv[8])/255.;
3638 TCollection_AsciiString aDispStr;
3640 aDispStr = TCollection_AsciiString (argv[9]);
3642 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3643 if (aDispStr.IsEqual ("subtitle"))
3644 aTextType = Aspect_TODT_SUBTITLE;
3645 else if (aDispStr.IsEqual ("decal"))
3646 aTextType = Aspect_TODT_DEKALE;
3647 else if (aDispStr.IsEqual ("blend"))
3648 aTextType = Aspect_TODT_BLEND;
3649 else if (aDispStr.IsEqual ("dimension"))
3650 aTextType = Aspect_TODT_DIMENSION;
3653 Quantity_Parameter aSubRed = 1.0;
3654 Quantity_Parameter aSubGreen = 1.0;
3655 Quantity_Parameter aSubBlue = 1.0;
3658 aSubRed = Draw::Atof (argv[10])/255.;
3659 aSubGreen = Draw::Atof (argv[11])/255.;
3660 aSubBlue = Draw::Atof (argv[12])/255.;
3663 // check fo current overlay
3664 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3665 if (anOverlay.IsNull ())
3667 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3668 anOverlay = aMgr->Overlay ();
3669 aView->SetLayerMgr (aMgr);
3672 Quantity_Color aTextColor (aColorRed, aColorGreen,
3673 aColorBlue, Quantity_TOC_RGB);
3674 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3675 aSubBlue, Quantity_TOC_RGB);
3678 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3679 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3682 aView->MustBeResized();
3688 //==============================================================================
3691 //==============================================================================
3693 static int VGrid (Draw_Interpretor& /*theDI*/,
3694 Standard_Integer theArgNb,
3695 const char** theArgVec)
3697 // get the active view
3698 Handle(V3d_View) aView = ViewerTest::CurrentView();
3699 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3700 if (aView.IsNull() || aViewer.IsNull())
3702 std::cerr << "No active view. Please call vinit.\n";
3706 Aspect_GridType aType = aViewer->GridType();
3707 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3709 Standard_Integer anIter = 1;
3710 for (; anIter < theArgNb; ++anIter)
3712 const char* aValue = theArgVec[anIter];
3715 aType = Aspect_GT_Rectangular;
3717 else if (*aValue == 'c')
3719 aType = Aspect_GT_Circular;
3721 else if (*aValue == 'l')
3723 aMode = Aspect_GDM_Lines;
3725 else if (*aValue == 'p')
3727 aMode = Aspect_GDM_Points;
3729 else if (strcmp (aValue, "off" ) == 0)
3731 aViewer->DeactivateGrid();
3740 Standard_Integer aTail = (theArgNb - anIter);
3743 aViewer->ActivateGrid (aType, aMode);
3746 else if (aTail != 2 && aTail != 5)
3748 std::cerr << "Incorrect arguments number! Usage:\n"
3749 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3753 Quantity_Length anOriginX, anOriginY;
3754 Quantity_PlaneAngle aRotAngle;
3755 if (aType == Aspect_GT_Rectangular)
3757 Quantity_Length aRStepX, aRStepY;
3758 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3760 anOriginX = Draw::Atof (theArgVec[anIter++]);
3761 anOriginY = Draw::Atof (theArgVec[anIter++]);
3764 aRStepX = Draw::Atof (theArgVec[anIter++]);
3765 aRStepY = Draw::Atof (theArgVec[anIter++]);
3766 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3768 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3769 aViewer->ActivateGrid (aType, aMode);
3771 else if (aType == Aspect_GT_Circular)
3773 Quantity_Length aRadiusStep;
3774 Standard_Integer aDivisionNumber;
3775 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3777 anOriginX = Draw::Atof (theArgVec[anIter++]);
3778 anOriginY = Draw::Atof (theArgVec[anIter++]);
3781 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3782 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3783 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3786 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3787 aViewer->ActivateGrid (aType, aMode);
3793 //==============================================================================
3796 //==============================================================================
3798 static int VFps (Draw_Interpretor& theDI,
3799 Standard_Integer theArgNb,
3800 const char** theArgVec)
3802 // get the active view
3803 Handle(V3d_View) aView = ViewerTest::CurrentView();
3806 std::cerr << "No active view. Please call vinit.\n";
3810 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3813 std::cerr << "Incorrect arguments!\n";
3817 // the time is meaningless for first call
3818 // due to async OpenGl rendering
3821 // redraw view in loop to estimate average values
3824 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3830 const Standard_Real aTime = aTimer.ElapsedTime();
3831 aTimer.OSD_Chronometer::Show (aCpu);
3833 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3834 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3836 // return statistics
3837 theDI << "FPS: " << aFpsAver << "\n"
3838 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3843 //==============================================================================
3844 //function : VGlDebug
3846 //==============================================================================
3848 static int VGlDebug (Draw_Interpretor& theDI,
3849 Standard_Integer theArgNb,
3850 const char** theArgVec)
3854 Handle(V3d_View) aView = ViewerTest::CurrentView();
3857 std::cerr << "No active view. Please call vinit.\n";
3861 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3862 "GL_ARB_debug_output");
3863 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3864 theDI << (isActive ? "1" : "0");
3868 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3872 //==============================================================================
3875 //==============================================================================
3877 static int VVbo (Draw_Interpretor& theDI,
3878 Standard_Integer theArgNb,
3879 const char** theArgVec)
3881 const Standard_Boolean toSet = (theArgNb > 1);
3882 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3885 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
3889 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3890 if (aContextAIS.IsNull())
3894 std::cerr << "No active view!\n";
3898 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3899 if (!aDriver.IsNull())
3903 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3907 aDriver->ChangeOptions().vboDisable = toUseVbo;
3914 //==============================================================================
3917 //==============================================================================
3919 static int VCaps (Draw_Interpretor& theDI,
3920 Standard_Integer theArgNb,
3921 const char** theArgVec)
3923 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
3924 Handle(OpenGl_GraphicDriver) aDriver;
3925 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3926 if (!aContextAIS.IsNull())
3928 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3929 aCaps = &aDriver->ChangeOptions();
3934 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
3935 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
3936 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
3940 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3942 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
3943 if (anArg.Search ("vbo=") > -1)
3945 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3947 else if (anArg.Search ("sprites=") > -1)
3949 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3951 else if (anArg.Search ("soft=") > -1)
3953 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
3957 std::cerr << "Unknown argument: " << anArg << "\n";
3960 if (aCaps != &ViewerTest_myDefaultCaps)
3962 ViewerTest_myDefaultCaps = *aCaps;
3967 //==============================================================================
3968 //function : VMemGpu
3970 //==============================================================================
3972 static int VMemGpu (Draw_Interpretor& theDI,
3973 Standard_Integer theArgNb,
3974 const char** theArgVec)
3977 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3978 if (aContextAIS.IsNull())
3980 std::cerr << "No active view. Please call vinit.\n";
3984 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3985 if (aDriver.IsNull())
3987 std::cerr << "Graphic driver not available.\n";
3991 Standard_Size aFreeBytes = 0;
3992 TCollection_AsciiString anInfo;
3993 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3995 std::cerr << "Information not available.\n";
3999 if (theArgNb > 1 && *theArgVec[1] == 'f')
4001 theDI << Standard_Real (aFreeBytes);
4011 // ==============================================================================
4012 // function : VReadPixel
4014 // ==============================================================================
4015 static int VReadPixel (Draw_Interpretor& theDI,
4016 Standard_Integer theArgNb,
4017 const char** theArgVec)
4019 // get the active view
4020 Handle(V3d_View) aView = ViewerTest::CurrentView();
4023 std::cerr << "No active view. Please call vinit.\n";
4026 else if (theArgNb < 3)
4028 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4032 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4033 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4035 Standard_Integer aWidth, aHeight;
4036 aView->Window()->Size (aWidth, aHeight);
4037 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4038 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4039 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4041 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4045 Standard_Boolean toShowName = Standard_False;
4046 Standard_Boolean toShowHls = Standard_False;
4047 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4049 const char* aParam = theArgVec[anIter];
4050 if ( strcasecmp( aParam, "rgb" ) == 0 )
4052 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4053 aBufferType = Graphic3d_BT_RGB;
4055 else if ( strcasecmp( aParam, "hls" ) == 0 )
4057 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4058 aBufferType = Graphic3d_BT_RGB;
4059 toShowHls = Standard_True;
4061 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4063 aFormat = Image_PixMap::ImgRGBF;
4064 aBufferType = Graphic3d_BT_RGB;
4066 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4068 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4069 aBufferType = Graphic3d_BT_RGBA;
4071 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4073 aFormat = Image_PixMap::ImgRGBAF;
4074 aBufferType = Graphic3d_BT_RGBA;
4076 else if ( strcasecmp( aParam, "depth" ) == 0 )
4078 aFormat = Image_PixMap::ImgGrayF;
4079 aBufferType = Graphic3d_BT_Depth;
4081 else if ( strcasecmp( aParam, "name" ) == 0 )
4083 toShowName = Standard_True;
4087 Image_PixMap anImage;
4088 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4090 std::cerr << "Image allocation failed\n";
4093 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4095 std::cerr << "Image dump failed\n";
4099 Quantity_Parameter anAlpha;
4100 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4103 if (aBufferType == Graphic3d_BT_RGBA)
4105 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
4109 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
4114 switch (aBufferType)
4117 case Graphic3d_BT_RGB:
4121 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
4125 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
4129 case Graphic3d_BT_RGBA:
4131 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
4134 case Graphic3d_BT_Depth:
4136 theDI << aColor.Red() << "\n";
4145 //==============================================================================
4146 //function : VDiffImage
4147 //purpose : The draw-command compares two images.
4148 //==============================================================================
4150 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4154 theDI << "Not enough arguments.\n";
4159 const char* anImgPathRef = theArgVec[1];
4160 const char* anImgPathNew = theArgVec[2];
4162 // get string tolerance and check its validity
4163 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4164 if (aTolColor < 0.0)
4166 if (aTolColor > 1.0)
4169 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4170 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4172 // image file of difference
4173 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4175 // compare the images
4176 Image_Diff aComparer;
4177 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4182 aComparer.SetColorTolerance (aTolColor);
4183 aComparer.SetBorderFilterOn (isBorderFilterOn);
4184 Standard_Integer aDiffColorsNb = aComparer.Compare();
4185 theDI << aDiffColorsNb << "\n";
4187 // save image of difference
4188 if (aDiffImagePath != NULL)
4190 aComparer.SaveDiffImage (aDiffImagePath);
4196 //=======================================================================
4197 //function : VSelect
4198 //purpose : Emulates different types of selection by mouse:
4199 // 1) single click selection
4200 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4201 // 3) selection with polygon having corners at
4202 // pixel positions (x1,y1),...,(xn,yn)
4203 // 4) any of these selections with shift button pressed
4204 //=======================================================================
4205 static Standard_Integer VSelect (Draw_Interpretor& di,
4206 Standard_Integer argc,
4211 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4215 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4216 if(myAIScontext.IsNull())
4218 di << "use 'vinit' command before " << argv[0] << "\n";
4221 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4222 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4223 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4226 if(isShiftSelection)
4227 aCurrentEventManager->ShiftSelect();
4229 aCurrentEventManager->Select();
4233 if(isShiftSelection)
4234 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4236 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4240 Standard_Integer anUpper = 0;
4242 if(isShiftSelection)
4243 anUpper = (argc-1)/2;
4246 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4248 for(Standard_Integer i=1;i<=anUpper;++i)
4249 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4251 if(isShiftSelection)
4252 aCurrentEventManager->ShiftSelect(aPolyline);
4254 aCurrentEventManager->Select(aPolyline);
4259 //=======================================================================
4260 //function : VMoveTo
4261 //purpose : Emulates cursor movement to defined pixel position
4262 //=======================================================================
4263 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4264 Standard_Integer argc,
4269 di << "Usage : " << argv[0] << " x y" << "\n";
4273 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4274 if(aContext.IsNull())
4276 di << "use 'vinit' command before " << argv[0] << "\n";
4279 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4283 //=======================================================================
4284 //function : VViewParams
4285 //purpose : Gets or sets AIS View characteristics
4286 //=======================================================================
4287 static Standard_Integer VViewParams (Draw_Interpretor& di,
4288 Standard_Integer argc,
4291 if ( argc != 1 && argc != 13)
4293 di << "Usage : " << argv[0] << "\n";
4296 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
4297 if ( anAISView.IsNull () )
4299 di << "use 'vinit' command before " << argv[0] << "\n";
4303 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
4304 Standard_Real anAISViewCenterCoordinateX = 0.0;
4305 Standard_Real anAISViewCenterCoordinateY = 0.0;
4306 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4307 Standard_Real anAISViewProjX = 0.0;
4308 Standard_Real anAISViewProjY = 0.0;
4309 Standard_Real anAISViewProjZ = 0.0;
4310 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4311 Standard_Real anAISViewUpX = 0.0;
4312 Standard_Real anAISViewUpY = 0.0;
4313 Standard_Real anAISViewUpZ = 0.0;
4314 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4315 Standard_Real anAISViewAtX = 0.0;
4316 Standard_Real anAISViewAtY = 0.0;
4317 Standard_Real anAISViewAtZ = 0.0;
4318 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4319 di << "Scale of current view: " << anAISViewScale << "\n";
4320 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
4321 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4322 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4323 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4327 Quantity_Factor anAISViewScale = atof (argv [1]);
4328 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
4329 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
4330 Standard_Real anAISViewProjX = atof (argv [4]);
4331 Standard_Real anAISViewProjY = atof (argv [5]);
4332 Standard_Real anAISViewProjZ = atof (argv [6]);
4333 Standard_Real anAISViewUpX = atof (argv [7]);
4334 Standard_Real anAISViewUpY = atof (argv [8]);
4335 Standard_Real anAISViewUpZ = atof (argv [9]);
4336 Standard_Real anAISViewAtX = atof (argv [10]);
4337 Standard_Real anAISViewAtY = atof (argv [11]);
4338 Standard_Real anAISViewAtZ = atof (argv [12]);
4339 anAISView -> V3d_View::SetScale (anAISViewScale);
4340 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4341 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4342 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4343 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4348 //=======================================================================
4349 //function : VChangeSelected
4350 //purpose : Adds the shape to selection or remove one from it
4351 //=======================================================================
4352 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4353 Standard_Integer argc,
4358 di<<"Usage : " << argv[0] << " shape \n";
4362 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4363 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4364 TCollection_AsciiString aName(argv[1]);
4365 Handle(AIS_InteractiveObject) anAISObject;
4367 if(!aMap.IsBound2(aName))
4369 di<<"Use 'vdisplay' before";
4374 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4375 if(anAISObject.IsNull()){
4376 di<<"No interactive object \n";
4380 if(aContext->HasOpenedContext())
4382 aContext->AddOrRemoveSelected(anAISObject);
4386 aContext->AddOrRemoveCurrentObject(anAISObject);
4392 //=======================================================================
4393 //function : VZClipping
4394 //purpose : Gets or sets ZClipping mode, width and depth
4395 //=======================================================================
4396 static Standard_Integer VZClipping (Draw_Interpretor& di,
4397 Standard_Integer argc,
4402 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4403 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4406 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4407 if(aContext.IsNull())
4409 di << "use 'vinit' command before " << argv[0] << "\n";
4412 Handle(V3d_View) aView = ViewerTest::CurrentView();
4413 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4416 TCollection_AsciiString aZClippingModeString;
4417 Quantity_Length aDepth, aWidth;
4418 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4419 switch (aZClippingMode)
4422 aZClippingModeString.Copy("OFF");
4425 aZClippingModeString.Copy("BACK");
4428 aZClippingModeString.Copy("FRONT");
4431 aZClippingModeString.Copy("SLICE");
4434 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4437 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4438 << "ZClipping depth = " << aDepth << "\n"
4439 << "ZClipping width = " << aWidth << "\n";
4445 Standard_Integer aStatus = 0;
4446 if ( strcmp (argv [1], "OFF") == 0 ) {
4448 aZClippingMode = V3d_OFF;
4450 if ( strcmp (argv [1], "BACK") == 0 ) {
4452 aZClippingMode = V3d_BACK;
4454 if ( strcmp (argv [1], "FRONT") == 0 ) {
4456 aZClippingMode = V3d_FRONT;
4458 if ( strcmp (argv [1], "SLICE") == 0 ) {
4460 aZClippingMode = V3d_SLICE;
4464 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4465 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4468 aView->SetZClippingType(aZClippingMode);
4472 Quantity_Length aDepth = 0., aWidth = 1.;
4475 aDepth = atof(argv[1]);
4476 aWidth = atof(argv[2]);
4480 aDepth = atof(argv[2]);
4481 aWidth = atof(argv[3]);
4484 if(aDepth<0. || aDepth>1.)
4486 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4487 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4490 if(aWidth<0. || aWidth>1.)
4492 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4493 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4497 aView->SetZClippingDepth(aDepth);
4498 aView->SetZClippingWidth(aWidth);
4505 //=======================================================================
4506 //function : VNbSelected
4507 //purpose : Returns number of selected objects
4508 //=======================================================================
4509 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4510 Standard_Integer argc,
4515 di << "Usage : " << argv[0] << "\n";
4518 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4519 if(aContext.IsNull())
4521 di << "use 'vinit' command before " << argv[0] << "\n";
4524 di << aContext->NbSelected() << "\n";
4528 //=======================================================================
4529 //function : VAntialiasing
4530 //purpose : Switches altialiasing on or off
4531 //=======================================================================
4532 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4533 Standard_Integer argc,
4538 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4542 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4543 if(aContext.IsNull())
4545 di << "use 'vinit' command before " << argv[0] << "\n";
4549 Handle(V3d_View) aView = ViewerTest::CurrentView();
4551 if((argc == 2) && (atof(argv[1]) == 0))
4552 aView->SetAntialiasingOff();
4554 aView->SetAntialiasingOn();
4559 //=======================================================================
4560 //function : VPurgeDisplay
4561 //purpose : Switches altialiasing on or off
4562 //=======================================================================
4563 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4564 Standard_Integer argc,
4569 di << "Usage : " << argv[0] << "\n";
4572 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4573 if (aContext.IsNull())
4575 di << "use 'vinit' command before " << argv[0] << "\n";
4578 aContext->CloseAllContexts(Standard_False);
4579 di << aContext->PurgeDisplay() << "\n";
4583 //=======================================================================
4584 //function : VSetViewSize
4586 //=======================================================================
4587 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4588 Standard_Integer argc,
4591 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4592 if(aContext.IsNull())
4594 di << "use 'vinit' command before " << argv[0] << "\n";
4599 di<<"Usage : " << argv[0] << " Size\n";
4602 Standard_Real aSize = atof(argv[1]);
4605 di<<"Bad Size value : " << aSize << "\n";
4609 Handle(V3d_View) aView = ViewerTest::CurrentView();
4610 aView->SetSize(aSize);
4614 //=======================================================================
4615 //function : VMoveView
4617 //=======================================================================
4618 static Standard_Integer VMoveView (Draw_Interpretor& di,
4619 Standard_Integer argc,
4622 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4623 if(aContext.IsNull())
4625 di << "use 'vinit' command before " << argv[0] << "\n";
4628 if(argc < 4 || argc > 5)
4630 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4633 Standard_Real Dx = atof(argv[1]);
4634 Standard_Real Dy = atof(argv[2]);
4635 Standard_Real Dz = atof(argv[3]);
4636 Standard_Boolean aStart = Standard_True;
4639 aStart = (atoi(argv[4]) > 0);
4642 Handle(V3d_View) aView = ViewerTest::CurrentView();
4643 aView->Move(Dx,Dy,Dz,aStart);
4647 //=======================================================================
4648 //function : VTranslateView
4650 //=======================================================================
4651 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4652 Standard_Integer argc,
4655 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4656 if(aContext.IsNull())
4658 di << "use 'vinit' command before " << argv[0] << "\n";
4661 if(argc < 4 || argc > 5)
4663 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4666 Standard_Real Dx = atof(argv[1]);
4667 Standard_Real Dy = atof(argv[2]);
4668 Standard_Real Dz = atof(argv[3]);
4669 Standard_Boolean aStart = Standard_True;
4672 aStart = (atoi(argv[4]) > 0);
4675 Handle(V3d_View) aView = ViewerTest::CurrentView();
4676 aView->Translate(Dx,Dy,Dz,aStart);
4680 //=======================================================================
4681 //function : VTurnView
4683 //=======================================================================
4684 static Standard_Integer VTurnView (Draw_Interpretor& di,
4685 Standard_Integer argc,
4688 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4689 if(aContext.IsNull()) {
4690 di << "use 'vinit' command before " << argv[0] << "\n";
4693 if(argc < 4 || argc > 5){
4694 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4697 Standard_Real Ax = atof(argv[1]);
4698 Standard_Real Ay = atof(argv[2]);
4699 Standard_Real Az = atof(argv[3]);
4700 Standard_Boolean aStart = Standard_True;
4703 aStart = (atoi(argv[4]) > 0);
4706 Handle(V3d_View) aView = ViewerTest::CurrentView();
4707 aView->Turn(Ax,Ay,Az,aStart);
4711 //==============================================================================
4712 //function : VTextureEnv
4713 //purpose : ENables or disables environment mapping
4714 //==============================================================================
4715 class OCC_TextureEnv : public Graphic3d_TextureEnv
4718 OCC_TextureEnv(const Standard_CString FileName);
4719 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4720 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4721 const Standard_Boolean theModulateFlag,
4722 const Graphic3d_TypeOfTextureFilter theFilter,
4723 const Standard_ShortReal theXScale,
4724 const Standard_ShortReal theYScale,
4725 const Standard_ShortReal theXShift,
4726 const Standard_ShortReal theYShift,
4727 const Standard_ShortReal theAngle);
4728 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4730 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4731 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4732 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4734 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4735 : Graphic3d_TextureEnv(theFileName)
4739 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4740 : Graphic3d_TextureEnv(theTexId)
4744 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4745 const Standard_Boolean theModulateFlag,
4746 const Graphic3d_TypeOfTextureFilter theFilter,
4747 const Standard_ShortReal theXScale,
4748 const Standard_ShortReal theYScale,
4749 const Standard_ShortReal theXShift,
4750 const Standard_ShortReal theYShift,
4751 const Standard_ShortReal theAngle)
4753 myParams->SetRepeat (theRepeatFlag);
4754 myParams->SetModulate (theModulateFlag);
4755 myParams->SetFilter (theFilter);
4756 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
4757 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4758 myParams->SetRotation (theAngle);
4761 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4763 // get the active view
4764 Handle(V3d_View) aView = ViewerTest::CurrentView();
4767 std::cerr << "No active view. Please call vinit.\n";
4771 // Checking the input arguments
4772 Standard_Boolean anEnableFlag = Standard_False;
4773 Standard_Boolean isOk = theArgNb >= 2;
4776 TCollection_AsciiString anEnableOpt(theArgVec[1]);
4777 anEnableFlag = anEnableOpt.IsEqual("on");
4778 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
4782 isOk = (theArgNb == 3 || theArgNb == 11);
4785 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4786 isOk = (!aTextureOpt.IsIntegerValue() ||
4787 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
4789 if (isOk && theArgNb == 11)
4791 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
4792 aModulateOpt(theArgVec[4]),
4793 aFilterOpt (theArgVec[5]),
4794 aSScaleOpt (theArgVec[6]),
4795 aTScaleOpt (theArgVec[7]),
4796 aSTransOpt (theArgVec[8]),
4797 aTTransOpt (theArgVec[9]),
4798 anAngleOpt (theArgVec[10]);
4799 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
4800 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
4801 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
4802 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
4803 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
4804 anAngleOpt.IsRealValue());
4811 std::cerr << "Usage :" << std::endl;
4812 std::cerr << theArgVec[0] << " off" << std::endl;
4813 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;
4819 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4820 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
4821 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
4822 new OCC_TextureEnv(theArgVec[2]);
4826 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
4827 aTexEnv->SetTextureParameters(
4828 aRepeatOpt. IsEqual("repeat"),
4829 aModulateOpt.IsEqual("modulate"),
4830 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
4831 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
4832 Graphic3d_TOTF_TRILINEAR,
4833 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
4834 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
4835 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
4836 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
4837 (Standard_ShortReal)Draw::Atof(theArgVec[10])
4840 aView->SetTextureEnv(aTexEnv);
4841 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
4843 else // Disabling environment mapping
4845 aView->SetSurfaceDetail(V3d_TEX_NONE);
4846 Handle(Graphic3d_TextureEnv) aTexture;
4847 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
4854 //===============================================================================================
4855 //function : VClipPlane
4857 //===============================================================================================
4858 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4860 // use short-cut for created clip planes map of created (or "registered by name") clip planes
4861 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
4862 static MapOfPlanes aRegPlanes;
4866 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
4870 TCollection_AsciiString aCommand (theArgVec[1]);
4872 // print maximum number of planes for current viewer
4873 if (aCommand == "maxplanes")
4877 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
4881 TCollection_AsciiString aViewName (theArgVec[2]);
4883 if (!ViewerTest_myViews.IsBound1 (aViewName))
4885 theDi << theArgVec[0] << ": view is not found.\n";
4889 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
4891 theDi << theArgVec[0] << ": "
4892 << aView->Viewer()->Driver()->InquirePlaneLimit()
4893 << " plane slots provided by driver."
4894 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
4899 // create / delete plane instance
4900 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
4904 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
4908 Standard_Boolean toCreate = (aCommand == "create");
4909 Standard_Boolean toClone = (aCommand == "clone");
4910 TCollection_AsciiString aPlane (theArgVec[2]);
4914 if (aRegPlanes.IsBound (aPlane))
4916 theDi << theArgVec[0] << ": plane name is in use.\n";
4920 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
4922 else if (toClone) // toClone
4924 if (!aRegPlanes.IsBound (aPlane))
4926 theDi << theArgVec[0] << ": no such plane.\n";
4932 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
4936 TCollection_AsciiString aClone (theArgVec[3]);
4937 if (aRegPlanes.IsBound (aClone))
4939 theDi << theArgVec[0] << ": plane name is in use.\n";
4943 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4945 aRegPlanes.Bind (aClone, aClipPlane->Clone());
4949 if (!aRegPlanes.IsBound (aPlane))
4951 theDi << theArgVec[0] << ": no such plane.\n";
4955 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
4956 aRegPlanes.UnBind (aPlane);
4958 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
4959 for (; anIObjIt.More(); anIObjIt.Next())
4961 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
4962 aPrs->RemoveClipPlane(aClipPlane);
4965 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
4966 for (; aViewIt.More(); aViewIt.Next())
4968 const Handle(V3d_View)& aView = aViewIt.Key2();
4969 aView->RemoveClipPlane(aClipPlane);
4972 ViewerTest::RedrawAllViews();
4978 // set / unset plane command
4979 if (aCommand == "set" || aCommand == "unset")
4983 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
4987 Standard_Boolean toSet = (aCommand == "set");
4988 TCollection_AsciiString aPlane (theArgVec [2]);
4989 if (!aRegPlanes.IsBound (aPlane))
4991 theDi << theArgVec[0] << ": no such plane.\n";
4995 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4997 TCollection_AsciiString aTarget (theArgVec [3]);
4998 if (aTarget != "object" && aTarget != "view")
5000 theDi << theArgVec[0] << ": invalid target.\n";
5004 if (aTarget == "object" || aTarget == "view")
5008 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5012 Standard_Boolean isObject = (aTarget == "object");
5014 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
5016 TCollection_AsciiString anEntityName (theArgVec[anIt]);
5017 if (isObject) // to object
5019 if (!GetMapOfAIS().IsBound2 (anEntityName))
5021 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
5025 Handle(AIS_InteractiveObject) aIObj =
5026 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
5029 aIObj->AddClipPlane (aClipPlane);
5031 aIObj->RemoveClipPlane (aClipPlane);
5035 if (!ViewerTest_myViews.IsBound1 (anEntityName))
5037 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
5041 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
5043 aView->AddClipPlane (aClipPlane);
5045 aView->RemoveClipPlane (aClipPlane);
5049 ViewerTest::RedrawAllViews();
5055 // change plane command
5056 if (aCommand == "change")
5060 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5064 TCollection_AsciiString aPlane (theArgVec [2]);
5065 if (!aRegPlanes.IsBound (aPlane))
5067 theDi << theArgVec[0] << ": no such plane.\n";
5071 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5073 TCollection_AsciiString aChangeArg (theArgVec [3]);
5074 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5076 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5080 if (aChangeArg == "on" || aChangeArg == "off") // on / off
5082 aClipPlane->SetOn (aChangeArg == "on");
5084 else if (aChangeArg == "equation") // change equation
5088 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5092 Standard_Real aCoeffA = atof (theArgVec [4]);
5093 Standard_Real aCoeffB = atof (theArgVec [5]);
5094 Standard_Real aCoeffC = atof (theArgVec [6]);
5095 Standard_Real aCoeffD = atof (theArgVec [7]);
5096 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5098 else if (aChangeArg == "capping") // change capping aspects
5102 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5106 TCollection_AsciiString aCappingArg (theArgVec [4]);
5107 if (aCappingArg != "on" && aCappingArg != "off" &&
5108 aCappingArg != "color" && aCappingArg != "texname" &&
5109 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5110 aCappingArg != "texrotate" && aCappingArg != "hatch")
5112 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5116 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5118 aClipPlane->SetCapping (aCappingArg == "on");
5120 else if (aCappingArg == "color") // color aspect for capping
5124 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5128 Standard_Real aRed = atof (theArgVec [5]);
5129 Standard_Real aGrn = atof (theArgVec [6]);
5130 Standard_Real aBlu = atof (theArgVec [7]);
5132 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5133 aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
5134 aClipPlane->SetCappingMaterial (aMat);
5136 else if (aCappingArg == "texname") // texture name
5140 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5144 TCollection_AsciiString aTextureName (theArgVec [5]);
5146 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5147 if (!aTexture->IsDone ())
5149 aClipPlane->SetCappingTexture (NULL);
5153 aTexture->EnableModulate();
5154 aTexture->EnableRepeat();
5155 aClipPlane->SetCappingTexture (aTexture);
5158 else if (aCappingArg == "texscale") // texture scale
5160 if (aClipPlane->CappingTexture().IsNull())
5162 theDi << theArgVec[0] << ": no texture is set.\n";
5168 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5172 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5173 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5175 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5177 else if (aCappingArg == "texorigin") // texture origin
5179 if (aClipPlane->CappingTexture().IsNull())
5181 theDi << theArgVec[0] << ": no texture is set.\n";
5187 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5191 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5192 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5194 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5196 else if (aCappingArg == "texrotate") // texture rotation
5198 if (aClipPlane->CappingTexture().IsNull())
5200 theDi << theArgVec[0] << ": no texture is set.\n";
5206 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5210 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5212 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5214 else if (aCappingArg == "hatch") // hatch style
5218 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5222 TCollection_AsciiString aHatchStr (theArgVec [5]);
5223 if (aHatchStr == "on")
5225 aClipPlane->SetCappingHatchOn();
5227 else if (aHatchStr == "off")
5229 aClipPlane->SetCappingHatchOff();
5233 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5238 ViewerTest::RedrawAllViews();
5243 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5247 //===============================================================================================
5248 //function : VSetTextureMode
5250 //===============================================================================================
5251 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5255 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5259 TCollection_AsciiString aViewName (theArgVec[1]);
5260 if (!ViewerTest_myViews.IsBound1 (aViewName))
5262 theDi << theArgVec[0] << ": view is not found.\n";
5266 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5267 switch (atoi (theArgVec[2]))
5269 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5270 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5271 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5273 theDi << theArgVec[0] << ": invalid mode.\n";
5281 //===============================================================================================
5282 //function : VDefaults
5284 //===============================================================================================
5285 static int VDefaults (Draw_Interpretor& theDi,
5286 Standard_Integer theArgsNb,
5287 const char** theArgVec)
5289 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5292 std::cerr << "No active viewer!\n";
5296 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
5299 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
5301 theDi << "DeflType: relative\n"
5302 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
5306 theDi << "DeflType: absolute\n"
5307 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
5309 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
5313 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5315 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5316 TCollection_AsciiString aKey, aValue;
5317 if (!splitParameter (anArg, aKey, aValue)
5318 || aValue.IsEmpty())
5320 std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
5325 if (aKey == "ABSDEFL"
5326 || aKey == "ABSOLUTEDEFLECTION"
5328 || aKey == "DEFLECTION")
5330 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
5331 aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
5333 else if (aKey == "RELDEFL"
5334 || aKey == "RELATIVEDEFLECTION"
5335 || aKey == "DEVCOEFF"
5336 || aKey == "DEVIATIONCOEFF"
5337 || aKey == "DEVIATIONCOEFFICIENT")
5339 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
5340 aDefParams->SetDeviationCoefficient (aValue.RealValue());
5342 else if (aKey == "ANGDEFL"
5343 || aKey == "ANGULARDEFL"
5344 || aKey == "ANGULARDEFLECTION")
5346 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
5347 aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
5351 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
5358 //! Auxiliary method
5359 inline void addLight (const Handle(V3d_Light)& theLightNew,
5360 const Standard_Boolean theIsGlobal)
5362 if (theLightNew.IsNull())
5369 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
5373 ViewerTest::CurrentView()->SetLightOn (theLightNew);
5377 //! Auxiliary method
5378 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
5380 TCollection_AsciiString anArgNextCase (theArgNext);
5381 anArgNextCase.UpperCase();
5382 if (anArgNextCase.Length() > 5
5383 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
5385 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
5389 return theArgNext.IntegerValue();
5393 //===============================================================================================
5396 //===============================================================================================
5397 static int VLight (Draw_Interpretor& theDi,
5398 Standard_Integer theArgsNb,
5399 const char** theArgVec)
5401 Handle(V3d_View) aView = ViewerTest::CurrentView();
5402 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5404 || aViewer.IsNull())
5406 std::cerr << "No active viewer!\n";
5410 Standard_Real anXYZ[3];
5411 Quantity_Coefficient anAtten[2];
5414 // print lights info
5415 Standard_Integer aLightId = 0;
5416 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
5418 Handle(V3d_Light) aLight = aView->ActiveLight();
5419 const Quantity_Color aColor = aLight->Color();
5420 theDi << "Light" << aLightId << "\n";
5421 switch (aLight->Type())
5425 theDi << " Type: Ambient\n";
5428 case V3d_DIRECTIONAL:
5430 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
5431 theDi << " Type: Directional\n";
5432 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5433 if (!aLightDir.IsNull())
5435 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5436 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5437 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
5438 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5442 case V3d_POSITIONAL:
5444 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
5445 theDi << " Type: Positional\n";
5446 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5447 if (!aLightPos.IsNull())
5449 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5450 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5451 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5452 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
5458 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
5459 theDi << " Type: Spot\n";
5460 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5461 if (!aLightSpot.IsNull())
5463 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5464 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5465 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
5466 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5467 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5468 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
5469 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
5470 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
5476 theDi << " Type: UNKNOWN\n";
5480 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
5484 Handle(V3d_Light) aLightNew;
5485 Handle(V3d_Light) aLightOld;
5486 Standard_Boolean isGlobal = Standard_True;
5487 Standard_Boolean toCreate = Standard_False;
5488 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5490 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
5491 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
5492 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
5493 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
5494 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
5496 TCollection_AsciiString aName, aValue;
5497 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
5498 TCollection_AsciiString anArgCase (anArg);
5499 anArgCase.UpperCase();
5500 if (anArgCase.IsEqual ("NEW")
5501 || anArgCase.IsEqual ("ADD")
5502 || anArgCase.IsEqual ("CREATE"))
5504 toCreate = Standard_True;
5506 else if (anArgCase.IsEqual ("GLOB")
5507 || anArgCase.IsEqual ("GLOBAL"))
5509 isGlobal = Standard_True;
5511 else if (anArgCase.IsEqual ("LOC")
5512 || anArgCase.IsEqual ("LOCAL"))
5514 isGlobal = Standard_False;
5516 else if (anArgCase.IsEqual ("AMB")
5517 || anArgCase.IsEqual ("AMBIENT")
5518 || anArgCase.IsEqual ("AMBLIGHT"))
5520 addLight (aLightNew, isGlobal);
5523 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5526 toCreate = Standard_False;
5527 aLightNew = new V3d_AmbientLight (aViewer);
5529 else if (anArgCase.IsEqual ("DIRECTIONAL")
5530 || anArgCase.IsEqual ("DIRLIGHT"))
5532 addLight (aLightNew, isGlobal);
5535 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5538 toCreate = Standard_False;
5539 aLightNew = new V3d_DirectionalLight (aViewer);
5541 else if (anArgCase.IsEqual ("SPOT")
5542 || anArgCase.IsEqual ("SPOTLIGHT"))
5544 addLight (aLightNew, isGlobal);
5547 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5550 toCreate = Standard_False;
5551 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
5553 else if (anArgCase.IsEqual ("POSLIGHT")
5554 || anArgCase.IsEqual ("POSITIONAL"))
5556 addLight (aLightNew, isGlobal);
5559 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5562 toCreate = Standard_False;
5563 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
5565 else if (anArgCase.IsEqual ("CHANGE"))
5567 addLight (aLightNew, isGlobal);
5568 aLightNew.Nullify();
5569 if (++anArgIt >= theArgsNb)
5571 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5575 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
5576 Standard_Integer aLightIt = 0;
5577 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
5579 if (aLightIt == aLightId)
5581 aLightOld = aView->ActiveLight();
5586 if (aLightOld.IsNull())
5588 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
5592 else if (anArgCase.IsEqual ("DEL")
5593 || anArgCase.IsEqual ("DELETE"))
5595 Handle(V3d_Light) aLightDel;
5596 if (++anArgIt >= theArgsNb)
5598 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5602 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
5603 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
5604 Standard_Integer aLightIt = 0;
5605 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
5607 aLightDel = aView->ActiveLight();
5608 if (aLightIt == aLightDelId)
5613 if (!aLightDel.IsNull())
5615 aViewer->DelLight (aLightDel);
5618 else if (anArgCase.IsEqual ("COLOR")
5619 || anArgCase.IsEqual ("COLOUR"))
5621 if (++anArgIt >= theArgsNb)
5623 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5627 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
5628 anArgNext.UpperCase();
5629 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
5630 if (!aLightCurr.IsNull())
5632 aLightCurr->SetColor (aColor);
5635 else if (anArgCase.IsEqual ("POS")
5636 || anArgCase.IsEqual ("POSITION"))
5638 if ((anArgIt + 3) >= theArgsNb)
5640 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5644 anXYZ[0] = Atof (theArgVec[++anArgIt]);
5645 anXYZ[1] = Atof (theArgVec[++anArgIt]);
5646 anXYZ[2] = Atof (theArgVec[++anArgIt]);
5647 if (!aLightDir.IsNull())
5649 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
5651 else if (!aLightPos.IsNull())
5653 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
5655 else if (!aLightSpot.IsNull())
5657 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
5661 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5665 else if (anArgCase.IsEqual ("DIR")
5666 || anArgCase.IsEqual ("DIRECTION"))
5668 if ((anArgIt + 3) >= theArgsNb)
5670 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5674 anXYZ[0] = Atof (theArgVec[++anArgIt]);
5675 anXYZ[1] = Atof (theArgVec[++anArgIt]);
5676 anXYZ[2] = Atof (theArgVec[++anArgIt]);
5677 if (!aLightDir.IsNull())
5679 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
5681 else if (!aLightSpot.IsNull())
5683 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
5687 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5691 else if (anArgCase.IsEqual ("CONSTATTEN")
5692 || anArgCase.IsEqual ("CONSTATTENUATION"))
5694 if (++anArgIt >= theArgsNb)
5696 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5700 if (!aLightPos.IsNull())
5702 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5703 anAtten[0] = Atof (theArgVec[anArgIt]);
5704 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
5706 else if (!aLightSpot.IsNull())
5708 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5709 anAtten[0] = Atof (theArgVec[anArgIt]);
5710 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
5714 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5718 else if (anArgCase.IsEqual ("LINATTEN")
5719 || anArgCase.IsEqual ("LINEARATTEN")
5720 || anArgCase.IsEqual ("LINEARATTENUATION"))
5722 if (++anArgIt >= theArgsNb)
5724 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5728 if (!aLightPos.IsNull())
5730 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5731 anAtten[1] = Atof (theArgVec[anArgIt]);
5732 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
5734 else if (!aLightSpot.IsNull())
5736 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5737 anAtten[1] = Atof (theArgVec[anArgIt]);
5738 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
5742 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5746 else if (anArgCase.IsEqual ("EXP")
5747 || anArgCase.IsEqual ("EXPONENT")
5748 || anArgCase.IsEqual ("SPOTEXP")
5749 || anArgCase.IsEqual ("SPOTEXPONENT"))
5751 if (++anArgIt >= theArgsNb)
5753 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5757 if (!aLightSpot.IsNull())
5759 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
5763 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5767 else if (anArgCase.IsEqual ("HEAD")
5768 || anArgCase.IsEqual ("HEADLIGHT"))
5770 if (++anArgIt >= theArgsNb)
5772 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5776 if (aLightAmb.IsNull()
5777 && !aLightCurr.IsNull())
5779 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
5783 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5789 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
5793 addLight (aLightNew, isGlobal);
5794 aViewer->UpdateLights();
5801 //==============================================================================
5802 //function : VClInfo
5803 //purpose : Prints info about active OpenCL device
5804 //==============================================================================
5806 static Standard_Integer VClInfo (Draw_Interpretor& theDi,
5810 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5811 if (aContextAIS.IsNull())
5813 std::cerr << "Call vinit before!\n";
5817 Handle(OpenGl_GraphicDriver) aDrv = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5818 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
5819 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> anInfo;
5822 || !aDrv->GetOpenClDeviceInfo (*aCView, anInfo))
5824 theDi << "OpenCL device info is unavailable!\n";
5828 theDi << "OpenCL device info:\n";
5829 for (NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator anIter (anInfo);
5830 anIter.More(); anIter.Next())
5832 theDi << anIter.Key() << ": \t" << anIter.Value() << "\n";
5837 //=======================================================================
5838 //function : VRaytrace
5839 //purpose : Enables/disables OpenCL-based ray-tracing
5840 //=======================================================================
5842 static Standard_Integer VRaytrace (Draw_Interpretor& ,
5843 Standard_Integer theArgNb,
5844 const char** theArgVec)
5846 Handle(V3d_View) aView = ViewerTest::CurrentView();
5849 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
5854 || Draw::Atoi (theArgVec[1]))
5856 aView->SetRaytracingMode();
5860 aView->SetRasterizationMode();
5866 //=======================================================================
5867 //function : VSetRaytraceMode
5868 //purpose : Enables/disables features of OpenCL-based ray-tracing
5869 //=======================================================================
5871 static Standard_Integer VSetRaytraceMode (Draw_Interpretor&,
5872 Standard_Integer theArgNb,
5873 const char ** theArgVec)
5875 Handle(V3d_View) aView = ViewerTest::CurrentView();
5878 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
5881 else if (theArgNb < 2)
5883 std::cerr << "Usage : " << theArgVec[0] << " [shad=0|1] [refl=0|1] [aa=0|1]\n";
5887 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5889 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5891 if (anArg.Search ("shad=") > -1)
5893 if (anArg.Token ("=", 2).IntegerValue() != 0)
5894 aView->EnableRaytracedShadows();
5896 aView->DisableRaytracedShadows();
5898 else if (anArg.Search ("refl=") > -1)
5900 if (anArg.Token ("=", 2).IntegerValue() != 0)
5901 aView->EnableRaytracedReflections();
5903 aView->DisableRaytracedReflections();
5905 else if (anArg.Search ("aa=") > -1)
5907 if (anArg.Token ("=", 2).IntegerValue() != 0)
5908 aView->EnableRaytracedAntialiasing();
5910 aView->DisableRaytracedAntialiasing();
5914 std::cerr << "Unknown argument: " << anArg << "\n";
5922 //=======================================================================
5923 //function : ViewerCommands
5925 //=======================================================================
5927 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
5930 const char *group = "ZeViewer";
5931 theCommands.Add("vinit",
5932 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5933 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5935 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5937 " - Creates new View window with specified name view_name.\n"
5938 "By default the new view is created in the viewer and in"
5939 " graphic driver shared with active view.\n"
5940 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
5941 "If driverName isn't specified the driver will be shared with active view.\n"
5942 "If viewerName isn't specified the viewer will be shared with active view.\n"
5943 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5944 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
5945 "is used in creation of graphic driver\n"
5947 " - l, t: pixel position of left top corner of the window\n"
5948 " - w,h: width and heigth of window respectively.\n"
5949 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
5950 __FILE__,VInit,group);
5951 theCommands.Add("vclose" ,
5952 "[view_id [keep_context=0|1]]\n"
5953 "or vclose ALL - to remove all created views\n"
5954 " - removes view(viewer window) defined by its view_id.\n"
5955 " - keep_context: by default 0; if 1 and the last view is deleted"
5956 " the current context is not removed.",
5957 __FILE__,VClose,group);
5958 theCommands.Add("vactivate" ,
5960 " - activates view(viewer window) defined by its view_id",
5961 __FILE__,VActivate,group);
5962 theCommands.Add("vviewlist",
5963 "vviewlist [format={tree, long}]"
5964 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
5965 " - format: format of result output, if tree the output is a tree view;"
5966 "otherwise it's a list of full view names. By default format = tree",
5967 __FILE__,VViewList,group);
5968 theCommands.Add("vhelp" ,
5969 "vhelp : display help on the viewer commands",
5970 __FILE__,VHelp,group);
5971 theCommands.Add("vtop" ,
5972 "vtop or <T> : Top view" ,
5973 __FILE__,VTop,group);
5974 theCommands.Add("vbottom" ,
5975 "vbottom : Bottom view" ,
5976 __FILE__,VBottom,group);
5977 theCommands.Add("vleft" ,
5978 "vleft : Left view" ,
5979 __FILE__,VLeft,group);
5980 theCommands.Add("vright" ,
5981 "vright : Right view" ,
5982 __FILE__,VRight,group);
5983 theCommands.Add("vaxo" ,
5984 " vaxo or <A> : Axonometric view ",
5985 __FILE__,VAxo,group);
5986 theCommands.Add("vfront" ,
5987 "vfront : Front view" ,
5988 __FILE__,VFront,group);
5989 theCommands.Add("vback" ,
5990 "vback : Back view" ,
5991 __FILE__,VBack,group);
5992 theCommands.Add("vpick" ,
5993 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
5995 theCommands.Add("vfit" ,
5996 "vfit or <F> : vfit",
5997 __FILE__,VFit,group);
5998 theCommands.Add("vzfit" ,
6000 __FILE__,VZFit,group);
6001 theCommands.Add("vrepaint",
6002 "vrepaint : vrepaint, force redraw",
6003 __FILE__,VRepaint,group);
6004 theCommands.Add("vclear",
6006 __FILE__,VClear,group);
6007 theCommands.Add("vsetbg",
6008 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
6009 __FILE__,VSetBg,group);
6010 theCommands.Add("vsetbgmode",
6011 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
6012 __FILE__,VSetBgMode,group);
6013 theCommands.Add("vsetgradientbg",
6014 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
6015 __FILE__,VSetGradientBg,group);
6016 theCommands.Add("vsetgrbgmode",
6017 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
6018 __FILE__,VSetGradientBgMode,group);
6019 theCommands.Add("vsetcolorbg",
6020 "vsetcolorbg : vsetcolorbg r g b : Set background color",
6021 __FILE__,VSetColorBg,group);
6022 theCommands.Add("vscale",
6023 "vscale : vscale X Y Z",
6024 __FILE__,VScale,group);
6025 theCommands.Add("vzbufftrihedron",
6026 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
6027 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
6028 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
6029 __FILE__,VTestZBuffTrihedron,group);
6030 theCommands.Add("vrotate",
6031 "vrotate : vrotate AX AY AZ [X Y Z]",
6032 __FILE__,VRotate,group);
6033 theCommands.Add("vzoom",
6034 "vzoom : vzoom coef",
6035 __FILE__,VZoom,group);
6036 theCommands.Add("vpan",
6037 "vpan : vpan dx dy",
6038 __FILE__,VPan,group);
6039 theCommands.Add("vexport",
6040 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
6041 " : exports the view to a vector file of a given format"
6042 " : notice that EMF format requires patched gl2ps",
6043 __FILE__,VExport,group);
6044 theCommands.Add("vcolorscale",
6045 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
6046 __FILE__,VColorScale,group);
6047 theCommands.Add("vgraduatedtrihedron",
6048 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
6049 __FILE__,VGraduatedTrihedron,group);
6050 theCommands.Add("vprintview" ,
6051 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
6052 __FILE__,VPrintView,group);
6053 theCommands.Add("vzlayer",
6054 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
6055 __FILE__,VZLayer,group);
6056 theCommands.Add("voverlaytext",
6057 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
6058 " : height - pixel height of the text (default=10.0)"
6059 " : font_name - name of font (default=courier)"
6060 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
6061 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
6062 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
6063 __FILE__,VOverlayText,group);
6064 theCommands.Add("vlayerline",
6065 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
6066 __FILE__,VLayerLine,group);
6067 theCommands.Add ("vgrid",
6068 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
6069 " : Mode - rectangular or circular"
6070 " : Type - lines or points",
6071 __FILE__, VGrid, group);
6072 theCommands.Add ("vfps",
6073 "vfps [framesNb=100] : estimate average frame rate for active view",
6074 __FILE__, VFps, group);
6075 theCommands.Add ("vgldebug",
6076 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
6077 " : this function is implemented only for Windows\n"
6078 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
6079 __FILE__, VGlDebug, group);
6080 theCommands.Add ("vvbo",
6081 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
6082 __FILE__, VVbo, group);
6083 theCommands.Add ("vcaps",
6084 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
6085 __FILE__, VCaps, group);
6086 theCommands.Add ("vmemgpu",
6087 "vmemgpu [f]: print system-dependent GPU memory information if available;"
6088 " with f option returns free memory in bytes",
6089 __FILE__, VMemGpu, group);
6090 theCommands.Add ("vreadpixel",
6091 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
6092 " : Read pixel value for active view",
6093 __FILE__, VReadPixel, group);
6094 theCommands.Add("diffimage",
6095 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
6096 __FILE__, VDiffImage, group);
6097 theCommands.Add ("vselect",
6098 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
6099 "- emulates different types of selection:\n"
6100 "- 1) single click selection\n"
6101 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
6102 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
6103 "- 4) any of these selections with shift button pressed",
6104 __FILE__, VSelect, group);
6105 theCommands.Add ("vmoveto",
6107 "- emulates cursor movement to pixel postion (x,y)",
6108 __FILE__, VMoveTo, group);
6109 theCommands.Add("vviewparams",
6110 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
6111 "- gets or sets current view characteristics",
6112 __FILE__,VViewParams, group);
6113 theCommands.Add("vchangeselected",
6114 "vchangeselected shape"
6115 "- adds to shape to selection or remove one from it",
6116 __FILE__, VChangeSelected, group);
6117 theCommands.Add("vzclipping",
6118 "vzclipping [mode] [depth width]\n"
6119 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
6120 "- gets or sets ZClipping mode, width and depth",
6121 __FILE__,VZClipping,group);
6122 theCommands.Add ("vnbselected",
6123 "vnbselected", __FILE__, VNbSelected, group);
6124 theCommands.Add("vantialiasing",
6125 "vantialiasing 1|0",
6126 __FILE__,VAntialiasing,group);
6127 theCommands.Add ("vpurgedisplay",
6129 "- removes structures which don't belong to objects displayed in neutral point",
6130 __FILE__, VPurgeDisplay, group);
6131 theCommands.Add("vsetviewsize",
6132 "vsetviewsize size",
6133 __FILE__,VSetViewSize,group);
6134 theCommands.Add("vmoveview",
6135 "vmoveview Dx Dy Dz [Start = 1|0]",
6136 __FILE__,VMoveView,group);
6137 theCommands.Add("vtranslateview",
6138 "vtranslateview Dx Dy Dz [Start = 1|0)]",
6139 __FILE__,VTranslateView,group);
6140 theCommands.Add("vturnview",
6141 "vturnview Ax Ay Az [Start = 1|0]",
6142 __FILE__,VTurnView,group);
6143 theCommands.Add("vtextureenv",
6144 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
6145 "or user-defined file and optionally applying texture mapping parameters\n"
6147 " vtextureenv off - disables environment mapping\n"
6148 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
6149 " std_texture = (0..7)\n"
6150 " rep = {clamp|repeat}\n"
6151 " mod = {decal|modulate}\n"
6152 " flt = {nearest|bilinear|trilinear}\n"
6153 " ss, st - scale factors for s and t texture coordinates\n"
6154 " ts, tt - translation for s and t texture coordinates\n"
6155 " rot - texture rotation angle in degrees",
6156 __FILE__, VTextureEnv, group);
6157 theCommands.Add("vhlr" ,
6158 "is_enabled={on|off}"
6159 " - Hidden line removal algorithm:"
6160 " - is_enabled: if is on HLR algorithm is applied\n",
6161 __FILE__,VHLR,group);
6162 theCommands.Add("vhlrtype" ,
6163 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
6164 " - Changes the type of HLR algorithm using for shapes."
6165 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
6166 " if equals to polyalgo, polygonal HLR algorithm is applied."
6167 "If shapes are not given HLR algoithm of given type is applied"
6168 " to all shapes in the view\n",
6169 __FILE__,VHLRType,group);
6170 theCommands.Add("vclipplane", "vclipplane usage: \n"
6171 " maxplanes <view_name> - get plane limit for view.\n"
6172 " create <plane_name> - create new plane.\n"
6173 " delete <plane_name> - delete plane.\n"
6174 " clone <source_plane> <plane_name> - clone the plane definition.\n"
6175 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
6176 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
6177 " change <plane_name> on/off - turn clipping on/off.\n"
6178 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
6179 " change <plane_name> capping on/off - turn capping on/off.\n"
6180 " change <plane_name> capping color <r> <g> <b> - set color.\n"
6181 " change <plane name> capping texname <texture> - set texture.\n"
6182 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
6183 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
6184 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
6185 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
6186 " please use VSetTextureMode command to enable texture rendering in view.\n"
6187 , __FILE__, VClipPlane, group);
6188 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
6190 " 0 - no textures enabled in view.\n"
6191 " 1 - only environment textures enabled.\n"
6192 " 2 - all textures enabled.\n"
6193 " this command sets texture details mode for the specified view.\n"
6194 , __FILE__, VSetTextureMode, group);
6195 theCommands.Add("vdefaults",
6196 "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
6197 __FILE__, VDefaults, group);
6198 theCommands.Add("vlight",
6199 "vlight [add|new {amb}ient|directional|{spot}light|positional]"
6200 "\n\t\t: [{del}ete|change lightId] [local|global]"
6201 "\n\t\t: [{pos}ition X Y Z] [color colorName] [{head}light 0|1]"
6202 "\n\t\t: [{constAtten}uation value] [{linearAtten}uation value]"
6203 "\n\t\t: [angle angleDeg] [{spotexp}onent value]",
6204 __FILE__, VLight, group);
6205 theCommands.Add("vraytrace",
6207 __FILE__,VRaytrace,group);
6208 theCommands.Add("vclinfo",
6210 __FILE__,VClInfo,group);
6211 theCommands.Add("vsetraytracemode",
6212 "vsetraytracemode [shad=0|1] [refl=0|1] [aa=0|1]",
6213 __FILE__,VSetRaytraceMode,group);