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.
22 // Robert Boehne 30 May 2000 : Dec Osf
28 #include <OpenGl_GlCore20.hxx>
29 #include <AIS_Shape.hxx>
30 #include <AIS_Drawer.hxx>
31 #include <AIS_InteractiveObject.hxx>
32 #include <AIS_ListOfInteractive.hxx>
33 #include <AIS_ListIteratorOfListOfInteractive.hxx>
35 #include <Graphic3d_AspectMarker3d.hxx>
36 #include <Graphic3d_ExportFormat.hxx>
37 #include <Graphic3d_NameOfTextureEnv.hxx>
38 #include <Graphic3d_TextureEnv.hxx>
39 #include <Graphic3d_TextureParams.hxx>
40 #include <Graphic3d_TypeOfTextureFilter.hxx>
41 #include <Graphic3d_AspectFillArea3d.hxx>
42 #include <ViewerTest.hxx>
43 #include <ViewerTest_EventManager.hxx>
44 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
46 #include <Visual3d_View.hxx>
47 #include <Visual3d_ViewManager.hxx>
48 #include <V3d_LayerMgr.hxx>
49 #include <NCollection_DoubleMap.hxx>
50 #include <NCollection_List.hxx>
51 #include <NCollection_Vector.hxx>
52 #include <NIS_View.hxx>
53 #include <NIS_Triangulated.hxx>
54 #include <NIS_InteractiveContext.hxx>
55 #include <AIS_InteractiveContext.hxx>
56 #include <Draw_Interpretor.hxx>
58 #include <Draw_Appli.hxx>
59 #include <Aspect_PrintAlgo.hxx>
60 #include <Image_AlienPixMap.hxx>
61 #include <OpenGl_GraphicDriver.hxx>
62 #include <OSD_Timer.hxx>
63 #include <TColStd_SequenceOfInteger.hxx>
64 #include <TColStd_HSequenceOfReal.hxx>
65 #include <TColgp_Array1OfPnt2d.hxx>
66 #include <Visual3d_LayerItem.hxx>
67 #include <V3d_LayerMgr.hxx>
68 #include <V3d_LayerMgrPointer.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>
101 #include <Xw_Window.hxx>
102 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
103 #include <X11/Xutil.h>
107 //==============================================================================
109 //==============================================================================
110 // VIEWER GLOBAL VARIABLES
111 //==============================================================================
113 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
115 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
116 extern const Handle(NIS_InteractiveContext)& TheNISContext();
117 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
120 static Handle(WNT_Window)& VT_GetWindow() {
121 static Handle(WNT_Window) WNTWin;
124 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
125 static Handle(Cocoa_Window)& VT_GetWindow()
127 static Handle(Cocoa_Window) aWindow;
130 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
131 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
132 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
135 static Handle(Xw_Window)& VT_GetWindow(){
136 static Handle(Xw_Window) XWWin;
140 static void VProcessEvents(ClientData,int);
143 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
145 static Handle(Aspect_DisplayConnection) aDisplayConnection;
146 return aDisplayConnection;
149 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
151 GetDisplayConnection() = theDisplayConnection;
154 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
155 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
157 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
159 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
160 if (!aWindow.IsNull())
161 return aWindow->HWindow();
162 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
163 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
164 if (!aWindow.IsNull())
165 return aWindow->XWindow();
167 return aWindowHandle;
171 static Standard_Boolean MyHLRIsOn = Standard_False;
173 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
174 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
175 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
176 static OpenGl_Caps ViewerTest_myDefaultCaps;
178 #define ZCLIPWIDTH 1.
180 static void OSWindowSetup();
182 //==============================================================================
183 // EVENT GLOBAL VARIABLES
184 //==============================================================================
186 static int Start_Rot = 0;
187 static int ZClipIsOn = 0;
188 int X_Motion = 0; // Current cursor position
190 int X_ButtonPress = 0; // Last ButtonPress position
191 int Y_ButtonPress = 0;
192 Standard_Boolean IsDragged = Standard_False;
193 Standard_Boolean DragFirst;
195 //==============================================================================
198 static LRESULT WINAPI ViewerWindowProc(
203 static LRESULT WINAPI AdvViewerWindowProc(
211 //==============================================================================
214 //==============================================================================
216 const Handle(MMgt_TShared)& ViewerTest::WClass()
218 static Handle(MMgt_TShared) theWClass;
220 if (theWClass.IsNull())
222 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
223 CS_VREDRAW | CS_HREDRAW, 0, 0,
224 ::LoadCursor (NULL, IDC_ARROW));
230 //==============================================================================
231 //function : CreateName
232 //purpose : Create numerical name for new object in theMap
233 //==============================================================================
234 template <typename ObjectType>
235 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
236 const TCollection_AsciiString& theDefaultString)
238 if (theObjectMap.IsEmpty())
239 return theDefaultString + TCollection_AsciiString(1);
241 Standard_Integer aNextKey = 1;
242 Standard_Boolean isFound = Standard_False;
245 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
246 // Look for objects with default names
247 if (theObjectMap.IsBound1(aStringKey))
252 isFound = Standard_True;
255 return theDefaultString + TCollection_AsciiString(aNextKey);
258 //==============================================================================
259 //structure : ViewerTest_Names
260 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
261 //==============================================================================
262 struct ViewerTest_Names
265 TCollection_AsciiString myDriverName;
266 TCollection_AsciiString myViewerName;
267 TCollection_AsciiString myViewName;
271 const TCollection_AsciiString& GetDriverName () const
275 void SetDriverName (const TCollection_AsciiString& theDriverName)
277 myDriverName = theDriverName;
279 const TCollection_AsciiString& GetViewerName () const
283 void SetViewerName (const TCollection_AsciiString& theViewerName)
285 myViewerName = theViewerName;
287 const TCollection_AsciiString& GetViewName () const
291 void SetViewName (const TCollection_AsciiString& theViewName)
293 myViewName = theViewName;
296 //===========================================================================
297 //function : Constructor for ViewerTest_Names
298 //purpose : Get view, viewer, driver names from custom string
299 //===========================================================================
301 ViewerTest_Names (const TCollection_AsciiString& theInputString)
303 TCollection_AsciiString aName(theInputString);
304 if (theInputString.IsEmpty())
306 // Get current configuration
307 if (ViewerTest_myDrivers.IsEmpty())
308 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
309 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
311 myDriverName = ViewerTest_myDrivers.Find2
312 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
314 if(ViewerTest_myContexts.IsEmpty())
316 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
317 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
320 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
322 myViewName = CreateName <Handle(V3d_View)>
323 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
327 // There is at least view name
328 Standard_Integer aParserNumber = 0;
329 for (Standard_Integer i = 0; i < 3; ++i)
331 Standard_Integer aParserPos = aName.SearchFromEnd("/");
335 aName.Split(aParserPos-1);
340 if (aParserNumber == 0)
343 if (!ViewerTest::GetAISContext().IsNull())
345 myDriverName = ViewerTest_myDrivers.Find2
346 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
347 myViewerName = ViewerTest_myContexts.Find2
348 (ViewerTest::GetAISContext());
352 // There is no opened contexts here, need to create names for viewer and driver
353 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
354 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
356 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
357 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
359 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
361 else if (aParserNumber == 1)
363 // Here is viewerName/viewName
364 if (!ViewerTest::GetAISContext().IsNull())
365 myDriverName = ViewerTest_myDrivers.Find2
366 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
369 // There is no opened contexts here, need to create name for driver
370 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
371 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
373 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
375 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
379 //Here is driverName/viewerName/viewName
380 myDriverName = TCollection_AsciiString(aName);
382 TCollection_AsciiString aViewerName(theInputString);
383 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
384 myViewerName = TCollection_AsciiString(aViewerName);
386 myViewName = TCollection_AsciiString(theInputString);
392 //==============================================================================
393 //function : FindContextByView
394 //purpose : Find AIS_InteractiveContext by View
395 //==============================================================================
397 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
399 Handle(AIS_InteractiveContext) anAISContext;
401 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
402 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
404 if (anIter.Value()->CurrentViewer() == theView->Viewer())
405 return anIter.Key2();
411 //==============================================================================
412 //function : SetWindowTitle
413 //purpose : Set window title
414 //==============================================================================
416 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
417 Standard_CString theTitle)
420 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
422 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
423 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
425 if(GetDisplayConnection()->GetDisplay())
428 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
429 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
434 //==============================================================================
435 //function : IsWindowOverlapped
436 //purpose : Check if theWindow overlapp another view
437 //==============================================================================
439 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
440 const Standard_Integer thePxTop,
441 const Standard_Integer thePxRight,
442 const Standard_Integer thePxBottom,
443 TCollection_AsciiString& theViewId)
445 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
446 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
448 Standard_Integer aTop = 0,
452 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
453 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
454 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
455 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
456 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
458 theViewId = anIter.Key1();
459 return Standard_True;
462 return Standard_False;
465 // Workaround: to create and delete non-orthographic views outside ViewerTest
466 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
468 ViewerTest_myViews.UnBind1 (theName);
471 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
472 const Handle(V3d_View)& theView)
474 ViewerTest_myViews.Bind (theName, theView);
477 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
479 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
481 //==============================================================================
482 //function : ViewerInit
483 //purpose : Create the window viewer and initialize all the global variable
484 //==============================================================================
486 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
487 const Standard_Integer thePxTop,
488 const Standard_Integer thePxWidth,
489 const Standard_Integer thePxHeight,
490 Standard_CString theViewName,
491 Standard_CString theDisplayName)
493 // Default position and dimension of the viewer window.
494 // Note that left top corner is set to be sufficiently small to have
495 // window fit in the small screens (actual for remote desktops, see #23003).
496 // The position corresponds to the window's client area, thus some
497 // gap is added for window frame to be visible.
498 Standard_Integer aPxLeft = 20;
499 Standard_Integer aPxTop = 40;
500 Standard_Integer aPxWidth = 409;
501 Standard_Integer aPxHeight = 409;
502 Standard_Boolean toCreateViewer = Standard_False;
504 Handle(OpenGl_GraphicDriver) aGraphicDriver;
505 ViewerTest_Names aViewNames(theViewName);
506 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
507 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
514 aPxWidth = thePxWidth;
515 if (thePxHeight != 0)
516 aPxHeight = thePxHeight;
518 // Get graphic driver (create it or get from another view)
519 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
521 // Get connection string
522 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
523 TCollection_AsciiString aDisplayName(theDisplayName);
524 if (!aDisplayName.IsEmpty())
525 SetDisplayConnection (new Aspect_DisplayConnection ());
527 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
529 (void)theDisplayName; // avoid warning on unused argument
530 SetDisplayConnection (new Aspect_DisplayConnection ());
532 aGraphicDriver = new OpenGl_GraphicDriver();
533 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
534 aGraphicDriver->Begin (GetDisplayConnection());
535 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
536 toCreateViewer = Standard_True;
540 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
543 //Dispose the window if input parameters are default
544 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
546 Standard_Integer aTop = 0,
553 // Get screen resolution
554 #if defined(_WIN32) || defined(__WIN32__)
556 GetClientRect(GetDesktopWindow(), &aWindowSize);
557 aScreenHeight = aWindowSize.bottom;
558 aScreenWidth = aWindowSize.right;
559 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
560 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
562 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
563 aScreenWidth = WidthOfScreen(aScreen);
564 aScreenHeight = HeightOfScreen(aScreen);
567 TCollection_AsciiString anOverlappedViewId("");
569 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
571 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
573 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
574 && aRight + 2*aPxWidth + 40 > aScreenWidth)
576 if (aBottom + aPxHeight + 40 > aScreenHeight)
583 aPxTop = aBottom + 40;
586 aPxLeft = aRight + 20;
591 TCollection_AsciiString aTitle("3D View - ");
592 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
594 // Change name of current active window
595 if (!ViewerTest::CurrentView().IsNull())
597 TCollection_AsciiString aTitle("3D View - ");
599 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
600 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
604 Handle(V3d_Viewer) a3DViewer, a3DCollector;
605 // If it's the single view, we first look for empty context
606 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
608 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
609 anIter(ViewerTest_myContexts);
611 ViewerTest::SetAISContext (anIter.Value());
612 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
613 a3DCollector= ViewerTest::GetAISContext()->Collector();
615 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
617 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
618 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
619 a3DCollector= ViewerTest::GetAISContext()->Collector();
621 else if (a3DViewer.IsNull() || a3DCollector.IsNull())
623 toCreateViewer = Standard_True;
624 TCollection_ExtendedString NameOfWindow("Viewer3D");
625 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
627 NameOfWindow = TCollection_ExtendedString("Collector");
628 a3DCollector = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
630 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
631 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
635 if (ViewerTest::GetAISContext().IsNull() ||
636 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
638 Handle(AIS_InteractiveContext) aContext =
639 new AIS_InteractiveContext(a3DViewer, a3DCollector);
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();
710 a3DCollector.Nullify();
712 return aViewNames.GetViewName();
715 //==============================================================================
716 //function : RedrawAllViews
717 //purpose : Redraw all created views
718 //==============================================================================
719 void ViewerTest::RedrawAllViews()
721 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
722 for (; aViewIt.More(); aViewIt.Next())
724 const Handle(V3d_View)& aView = aViewIt.Key2();
729 //==============================================================================
730 //function : SplitParameter
731 //purpose : Split parameter string to parameter name an patameter value
732 //==============================================================================
733 Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
734 TCollection_AsciiString& theName,
735 TCollection_AsciiString& theValue)
737 Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
738 if (aParamNameEnd == 0)
739 return Standard_False;
740 TCollection_AsciiString aString(theString);
741 if (aParamNameEnd != 0)
743 theValue = aString.Split(aParamNameEnd);
744 aString.Split(aString.Length()-1);
747 return Standard_True;
750 //==============================================================================
752 //purpose : Create the window viewer and initialize all the global variable
753 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
754 //==============================================================================
756 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
760 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
761 << "Type help for more information.\n";
764 TCollection_AsciiString aViewName (""),
766 Standard_Integer aPxLeft = 0,
771 for (Standard_Integer i = 1; i < theArgsNb; ++i)
773 TCollection_AsciiString aName = "", aValue = "";
774 if(!SplitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
776 // In case of syntax: vinit ViewName
777 aViewName = theArgVec[1];
785 else if (aName == "l" || aName == "left")
786 aPxLeft = aValue.IntegerValue();
787 else if (aName == "t" || aName == "top")
788 aPxTop = aValue.IntegerValue();
789 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
790 else if (aName == "display")
791 aDisplayName = aValue;
793 else if (aName == "w" || aName == "width")
794 aPxWidth = aValue.IntegerValue();
795 else if (aName == "h" || aName == "height")
796 aPxHeight = aValue.IntegerValue();
799 theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n";
804 ViewerTest_Names aViewNames (aViewName);
805 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
807 TCollection_AsciiString aCommand("vactivate ");
808 aCommand = aCommand + aViewNames.GetViewName();
809 theDi.Eval(aCommand.ToCString());
813 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
814 aViewName.ToCString(),
815 aDisplayName.ToCString());
816 cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n";
820 //==============================================================================
822 //purpose : hidden lines removal algorithm
823 //==============================================================================
825 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
827 if (ViewerTest::CurrentView().IsNull())
829 di << argv[0] << ": Call vinit before this command, please.\n";
835 di << argv[0] << ": Wrong number of command arguments.\n"
836 << "Type help " << argv[0] << " for more information.\n";
840 Standard_Boolean isHLROn =
841 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
843 if (isHLROn == MyHLRIsOn)
849 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
854 //==============================================================================
855 //function : VHLRType
856 //purpose : change type of using HLR algorithm
857 //==============================================================================
859 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
861 if (ViewerTest::CurrentView().IsNull())
863 di << argv[0] << ": Call vinit before this command, please.\n";
869 di << argv[0] << ": Wrong number of command arguments.\n"
870 << "Type help " << argv[0] << " for more information.\n";
874 Prs3d_TypeOfHLR aTypeOfHLR =
875 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
879 AIS_ListOfInteractive aListOfShapes;
880 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
881 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
882 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
883 anIter.More(); anIter.Next())
885 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
888 if (aShape->TypeOfHLR() != aTypeOfHLR)
889 aShape->SetTypeOfHLR (aTypeOfHLR);
893 ViewerTest::CurrentView()->Update();
898 for (Standard_Integer i = 2; i < argc; ++i)
900 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
901 TCollection_AsciiString aName (argv[i]);
903 if (!aMap.IsBound2 (aName))
905 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
908 Handle(AIS_Shape) anAISObject =
909 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
910 if (anAISObject.IsNull())
912 anAISObject->SetTypeOfHLR (aTypeOfHLR);
914 anAISObject->Redisplay();
916 ViewerTest::CurrentView()->Update();
922 //==============================================================================
923 //function : FindViewIdByWindowHandle
924 //purpose : Find theView Id in the map of views by window handle
925 //==============================================================================
926 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
927 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
929 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
930 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
932 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
933 if (aWindowHandle == theWindowHandle)
934 return anIter.Key1();
936 return TCollection_AsciiString("");
940 //==============================================================================
941 //function : ActivateView
942 //purpose : Make the view active
943 //==============================================================================
945 void ActivateView (const TCollection_AsciiString& theViewName)
947 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
950 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
951 if (!anAISContext.IsNull())
953 if (!ViewerTest::CurrentView().IsNull())
955 TCollection_AsciiString aTitle("3D View - ");
956 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
957 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
960 ViewerTest::CurrentView (aView);
961 // Update degenerate mode
962 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
963 ViewerTest::SetAISContext (anAISContext);
964 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
965 aTitle = aTitle + theViewName + "(*)";
966 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
967 #if defined(_WIN32) || defined(__WIN32__)
968 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
969 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
970 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
972 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
974 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
975 ViewerTest::CurrentView()->Redraw();
980 //==============================================================================
981 //function : RemoveView
982 //purpose : Close and remove view from display, clear maps if neccessary
983 //==============================================================================
984 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
986 if (!ViewerTest_myViews.IsBound1(theViewName))
988 cout << "Wrong view name\n";
992 // Activate another view if it's active now
993 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
995 if (ViewerTest_myViews.Extent() > 1)
997 TCollection_AsciiString aNewViewName;
998 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
999 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1000 if (anIter.Key1() != theViewName)
1002 aNewViewName = anIter.Key1();
1005 ActivateView (aNewViewName);
1009 Handle(V3d_View) anEmptyView;
1010 #if defined(_WIN32) || defined(__WIN32__)
1011 Handle(WNT_Window) anEmptyWindow;
1012 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1013 Handle(Cocoa_Window) anEmptyWindow;
1015 Handle(Xw_Window) anEmptyWindow;
1017 VT_GetWindow() = anEmptyWindow;
1018 ViewerTest::CurrentView (anEmptyView);
1019 if (isContextRemoved)
1021 Handle(AIS_InteractiveContext) anEmptyContext;
1022 ViewerTest::SetAISContext(anEmptyContext);
1028 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1029 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1031 // Remove view resources
1032 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1033 ViewerTest_myViews.UnBind1(theViewName);
1036 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1037 XFlush (GetDisplayConnection()->GetDisplay());
1040 // Keep context opened only if the closed view is last to avoid
1041 // unused empty contexts
1042 if (!aCurrentContext.IsNull())
1044 // Check if there are more difined views in the viewer
1045 aCurrentContext->CurrentViewer()->InitDefinedViews();
1046 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1048 // Remove driver if there is no viewers that use it
1049 Standard_Boolean isRemoveDriver = Standard_True;
1050 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1051 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1053 if (aCurrentContext != anIter.Key2() &&
1054 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1056 isRemoveDriver = Standard_False;
1062 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1063 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1064 #if TCL_MAJOR_VERSION < 8
1065 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1067 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1072 ViewerTest_myContexts.UnBind2(aCurrentContext);
1075 cout << "3D View - " << theViewName << " was deleted.\n";
1079 //==============================================================================
1081 //purpose : Remove the view defined by its name
1082 //==============================================================================
1084 static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1088 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
1089 << "Type help " << theArgVec[0] << " for more information.\n";
1093 if (ViewerTest_myViews.IsEmpty())
1095 theDi << theArgVec[0] <<": there is no views to close.\n";
1099 TCollection_AsciiString anInputString(theArgVec[1]);
1101 // Create list to iterate and remove views from the map of views
1102 NCollection_List<TCollection_AsciiString> aViewList;
1103 if ( strcasecmp( anInputString.ToCString(), "ALL" ) == 0 )
1105 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
1106 anIter.More(); anIter.Next())
1108 aViewList.Append(anIter.Key1());
1113 ViewerTest_Names aViewNames(anInputString);
1114 aViewList.Append(aViewNames.GetViewName());
1117 Standard_Boolean isContextRemoved = (theArgsNb == 3 && atoi(theArgVec[2])==1) ? Standard_False : Standard_True;
1118 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1119 anIter.More(); anIter.Next())
1121 ViewerTest::RemoveView(anIter.Value(), isContextRemoved);
1127 //==============================================================================
1128 //function : VActivate
1129 //purpose : Activate the view defined by its ID
1130 //==============================================================================
1132 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1136 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1137 << "Usage: " << theArgVec[0] << " ViewID\n";
1142 theDi.Eval("vviewlist");
1146 TCollection_AsciiString aNameString(theArgVec[1]);
1147 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1149 TCollection_AsciiString aTitle("3D View - ");
1150 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1151 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1152 Handle(V3d_View) anEmptyView;
1153 #if defined(_WIN32) || defined(__WIN32__)
1154 Handle(WNT_Window) anEmptyWindow;
1155 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1156 Handle(Cocoa_Window) anEmptyWindow;
1158 Handle(Xw_Window) anEmptyWindow;
1160 VT_GetWindow() = anEmptyWindow;
1161 ViewerTest::CurrentView (anEmptyView);
1162 ViewerTest::ResetEventManager();
1163 theDi << theArgVec[0] << ": all views are inactive\n";
1167 ViewerTest_Names aViewNames(aNameString);
1169 // Check if this view exists in the viewer with the driver
1170 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1172 theDi << "Wrong view name\n";
1176 // Check if it is active already
1177 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1179 theDi << theArgVec[0] << ": the view is active already\n";
1183 ActivateView (aViewNames.GetViewName());
1187 //==============================================================================
1188 //function : VViewList
1189 //purpose : Print current list of views per viewer and graphic driver ID
1190 // shared between viewers
1191 //==============================================================================
1193 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1197 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1198 << "Usage: " << theArgVec[0] << " name";
1201 if (ViewerTest_myContexts.Size() < 1)
1204 Standard_Boolean isTreeView =
1205 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1208 theDi << theArgVec[0] <<":\n";
1210 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1211 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1214 theDi << aDriverIter.Key1() << ":\n";
1216 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1217 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1219 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1223 TCollection_AsciiString aContextName(aContextIter.Key1());
1224 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1227 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1228 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1230 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1232 TCollection_AsciiString aViewName(aViewIter.Key1());
1235 if (aViewIter.Value() == ViewerTest::CurrentView())
1236 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1238 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1242 theDi << aViewName << " ";
1252 //==============================================================================
1253 //function : VT_ProcessKeyPress
1254 //purpose : Handle KeyPress event from a CString
1255 //==============================================================================
1256 void VT_ProcessKeyPress (const char* buf_ret)
1258 //cout << "KeyPress" << endl;
1259 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1260 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1261 // Letter in alphabetic order
1263 if ( !strcasecmp(buf_ret, "A") ) {
1265 aView->SetProj(V3d_XposYnegZpos);
1267 else if ( !strcasecmp(buf_ret, "D") ) {
1271 else if ( !strcasecmp(buf_ret, "F") ) {
1273 if (aNisView.IsNull())
1276 aNisView->FitAll3d();
1278 else if ( !strcasecmp(buf_ret, "H") ) {
1280 cout << "HLR" << endl;
1281 aView->SetComputedMode (!aView->ComputedMode());
1282 MyHLRIsOn = aView->ComputedMode();
1284 else if ( !strcasecmp(buf_ret, "P") ) {
1286 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1287 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1288 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1290 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1291 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1293 AIS_ListOfInteractive aListOfShapes;
1294 aContext->DisplayedObjects(aListOfShapes);
1295 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1296 anIter.More(); anIter.Next())
1298 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1299 if (aShape.IsNull())
1301 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1302 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1304 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1305 aShape->Redisplay();
1310 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1312 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1313 if (aShape.IsNull())
1315 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1316 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1318 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1319 aShape->Redisplay();
1323 aContext->UpdateCurrentViewer();
1326 else if ( !strcasecmp(buf_ret, "S") ) {
1328 cout << "passage en mode 1 (shading pour les shapes)" << endl;
1330 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1331 if(Ctx->NbCurrents()==0 ||
1332 Ctx->NbSelected()==0)
1333 Ctx->SetDisplayMode(AIS_Shaded);
1335 if(Ctx->HasOpenedContext()){
1336 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1337 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1340 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1341 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1343 Ctx->UpdateCurrentViewer();
1346 else if ( !strcasecmp(buf_ret, "U") ) {
1347 // Unset display mode
1348 cout<<"passage au mode par defaut"<<endl;
1350 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1351 if(Ctx->NbCurrents()==0 ||
1352 Ctx->NbSelected()==0)
1353 Ctx->SetDisplayMode(AIS_WireFrame);
1355 if(Ctx->HasOpenedContext()){
1356 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1357 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1360 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1361 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1363 Ctx->UpdateCurrentViewer();
1367 else if ( !strcasecmp(buf_ret, "T") ) {
1369 aView->SetProj(V3d_Zpos);
1371 else if ( !strcasecmp(buf_ret, "B") ) {
1373 aView->SetProj(V3d_Zneg);
1375 else if ( !strcasecmp(buf_ret, "L") ) {
1377 aView->SetProj(V3d_Xneg);
1379 else if ( !strcasecmp(buf_ret, "R") ) {
1381 aView->SetProj(V3d_Xpos);
1384 else if ( !strcasecmp(buf_ret, "W") ) {
1386 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
1387 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1388 if(Ctx->NbCurrents()==0 ||
1389 Ctx->NbSelected()==0)
1390 Ctx->SetDisplayMode(AIS_WireFrame);
1392 if(Ctx->HasOpenedContext()){
1393 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1394 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1397 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1398 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1400 Ctx->UpdateCurrentViewer();
1403 else if ( !strcasecmp(buf_ret, "Z") ) {
1407 cout << "ZClipping OFF" << endl;
1410 aView->SetZClippingType(V3d_OFF);
1414 cout << "ZClipping ON" << endl;
1417 aView->SetZClippingType(V3d_FRONT);
1421 else if ( !strcasecmp(buf_ret, ",") ) {
1422 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1426 else if ( !strcasecmp(buf_ret, ".") ) {
1427 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1431 Standard_Integer Num = Draw::Atoi(buf_ret);
1432 if(Num>=0 && Num<=7)
1433 ViewerTest::StandardModeActivation(Num);
1437 //==============================================================================
1438 //function : VT_ProcessExpose
1439 //purpose : Redraw the View on an Expose Event
1440 //==============================================================================
1441 void VT_ProcessExpose()
1443 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1444 if (!aView3d.IsNull())
1450 //==============================================================================
1451 //function : VT_ProcessConfigure
1452 //purpose : Resize the View on an Configure Event
1453 //==============================================================================
1454 void VT_ProcessConfigure()
1456 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1457 if (aView3d.IsNull())
1462 aView3d->MustBeResized();
1467 //==============================================================================
1468 //function : VT_ProcessButton1Press
1470 //==============================================================================
1471 Standard_Boolean VT_ProcessButton1Press(
1474 Standard_Boolean pick,
1475 Standard_Boolean shift)
1477 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1479 Standard_Real X, Y, Z;
1481 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1483 Draw::Set(argv[1], X);
1484 Draw::Set(argv[2], Y);
1485 Draw::Set(argv[3], Z);}
1496 //==============================================================================
1497 //function : VT_ProcessButton1Release
1498 //purpose : End selecting
1499 //==============================================================================
1500 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1504 IsDragged = Standard_False;
1505 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1508 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1509 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1513 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1514 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1519 //==============================================================================
1520 //function : VT_ProcessButton3Press
1521 //purpose : Start Rotation
1522 //==============================================================================
1523 void VT_ProcessButton3Press()
1528 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1530 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1533 //==============================================================================
1534 //function : VT_ProcessButton3Release
1535 //purpose : End rotation
1536 //==============================================================================
1537 void VT_ProcessButton3Release()
1544 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1549 //==============================================================================
1550 //function : ProcessZClipMotion
1552 //==============================================================================
1554 void ProcessZClipMotion()
1556 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1557 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1558 static Standard_Real CurZPos = 0.;
1560 //Quantity_Length VDX, VDY;
1561 //a3DView->Size(VDX,VDY);
1562 //Standard_Real VDZ = a3DView->ZSize();
1563 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1565 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1567 // Front = Depth + width/2.
1568 Standard_Real D = 0.5;
1569 Standard_Real W = 0.1;
1575 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1577 a3DView->SetZClippingType(V3d_OFF);
1578 a3DView->SetZClippingDepth(D);
1579 a3DView->SetZClippingWidth(W);
1580 a3DView->SetZClippingType(V3d_FRONT);
1584 X_ButtonPress = X_Motion;
1585 Y_ButtonPress = Y_Motion;
1589 //==============================================================================
1590 //function : ProcessControlButton1Motion
1592 //==============================================================================
1594 static void ProcessControlButton1Motion()
1596 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1598 X_ButtonPress = X_Motion;
1599 Y_ButtonPress = Y_Motion;
1602 //==============================================================================
1603 //function : VT_ProcessControlButton2Motion
1605 //==============================================================================
1606 void VT_ProcessControlButton2Motion()
1608 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1609 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1611 dy = -dy; // Xwindow Y axis is from top to Bottom
1613 ViewerTest::CurrentView()->Panning( dx, dy );
1615 X_ButtonPress = X_Motion;
1616 Y_ButtonPress = Y_Motion;
1619 //==============================================================================
1620 //function : VT_ProcessControlButton3Motion
1621 //purpose : Rotation
1622 //==============================================================================
1623 void VT_ProcessControlButton3Motion()
1627 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1631 //==============================================================================
1632 //function : VT_ProcessMotion
1634 //==============================================================================
1635 void VT_ProcessMotion()
1637 //pre-hilights detected objects at mouse position
1639 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1640 EM->MoveTo(X_Motion, Y_Motion);
1644 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1646 Xpix = X_Motion;Ypix=Y_Motion;
1649 //==============================================================================
1650 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1651 //purpose : Switches to an axonometric, top, left and other views
1652 //==============================================================================
1654 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1656 if ( ViewerTest::CurrentView().IsNull() )
1658 di<<"Call vinit before this command, please"<<"\n";
1662 ViewerTest::CurrentView()->SetProj(ori);
1666 //==============================================================================
1668 //purpose : Switch to an Axonometric view
1669 //Draw arg : No args
1670 //==============================================================================
1672 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1674 return ViewProject(di, V3d_XposYnegZpos);
1677 //==============================================================================
1679 //purpose : Switch to a Top View
1680 //Draw arg : No args
1681 //==============================================================================
1683 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1685 return ViewProject(di, V3d_Zpos);
1688 //==============================================================================
1689 //function : VBottom
1690 //purpose : Switch to a Bottom View
1691 //Draw arg : No args
1692 //==============================================================================
1694 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1696 return ViewProject(di, V3d_Zneg);
1699 //==============================================================================
1701 //purpose : Switch to a Left View
1702 //Draw arg : No args
1703 //==============================================================================
1705 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1707 return ViewProject(di, V3d_Ypos);
1710 //==============================================================================
1712 //purpose : Switch to a Right View
1713 //Draw arg : No args
1714 //==============================================================================
1716 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1718 return ViewProject(di, V3d_Yneg);
1721 //==============================================================================
1723 //purpose : Switch to a Front View
1724 //Draw arg : No args
1725 //==============================================================================
1727 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1729 return ViewProject(di, V3d_Xpos);
1732 //==============================================================================
1734 //purpose : Switch to a Back View
1735 //Draw arg : No args
1736 //==============================================================================
1738 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1740 return ViewProject(di, V3d_Xneg);
1743 //==============================================================================
1745 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1746 //Draw arg : No args
1747 //==============================================================================
1749 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1752 di << "Q : Quit the application" << "\n";
1754 di << "========================="<<"\n";
1755 di << "F : FitAll" << "\n";
1756 di << "T : TopView" << "\n";
1757 di << "B : BottomView" << "\n";
1758 di << "R : RightView" << "\n";
1759 di << "L : LeftView" << "\n";
1760 di << "A : AxonometricView" << "\n";
1761 di << "D : ResetView" << "\n";
1763 di << "========================="<<"\n";
1764 di << "S : Shading" << "\n";
1765 di << "W : Wireframe" << "\n";
1766 di << "H : HidelLineRemoval" << "\n";
1767 di << "U : Unset display mode" << "\n";
1769 di << "========================="<<"\n";
1770 di << "Selection mode "<<"\n";
1771 di << "0 : Shape" <<"\n";
1772 di << "1 : Vertex" <<"\n";
1773 di << "2 : Edge" <<"\n";
1774 di << "3 : Wire" <<"\n";
1775 di << "4 : Face" <<"\n";
1776 di << "5 : Shell" <<"\n";
1777 di << "6 : Solid" <<"\n";
1778 di << "7 : Compound" <<"\n";
1780 di << "========================="<<"\n";
1781 di << "Z : Switch Z clipping On/Off" << "\n";
1782 di << ", : Hilight next detected" << "\n";
1783 di << ". : Hilight previous detected" << "\n";
1790 static Standard_Boolean Ppick = 0;
1791 static Standard_Integer Pargc = 0;
1792 static const char** Pargv = NULL;
1795 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1800 if (!ViewerTest_myViews.IsEmpty()) {
1802 WPARAM fwKeys = wParam;
1807 // Delete view from map of views
1808 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1813 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1814 || ViewerTest::CurrentView().IsNull())
1816 // Activate inactive window
1817 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1819 ActivateView (FindViewIdByWindowHandle(hwnd));
1824 IsDragged = Standard_False;
1827 HDC hdc = GetDC( hwnd );
1828 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1829 SetROP2( hdc, R2_NOT );
1830 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1831 ReleaseDC( hwnd, hdc );
1833 const Handle(ViewerTest_EventManager) EM =
1834 ViewerTest::CurrentEventManager();
1835 if ( fwKeys & MK_SHIFT )
1836 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1837 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1839 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1840 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1842 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1844 case WM_LBUTTONDOWN:
1845 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1847 IsDragged = Standard_True;
1848 DragFirst = Standard_True;
1849 X_ButtonPress = LOWORD(lParam);
1850 Y_ButtonPress = HIWORD(lParam);
1852 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1859 HDC hdc = GetDC( hwnd );
1861 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1862 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1863 SetROP2( hdc, R2_NOT );
1866 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1868 DragFirst = Standard_False;
1869 X_Motion = LOWORD(lParam);
1870 Y_Motion = HIWORD(lParam);
1872 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1874 SelectObject( hdc, anObj );
1876 ReleaseDC( hwnd, hdc );
1879 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1883 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1887 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1891 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1898 if ( !ViewerTest::CurrentView().IsNull() ) {
1903 BeginPaint(hwnd, &ps);
1904 EndPaint(hwnd, &ps);
1909 VT_ProcessConfigure();
1913 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1916 c[0] = (char) wParam;
1918 VT_ProcessKeyPress (c);
1926 VT_ProcessButton3Release();
1929 case WM_LBUTTONDOWN:
1930 case WM_MBUTTONDOWN:
1931 case WM_RBUTTONDOWN:
1933 WPARAM fwKeys = wParam;
1937 X_ButtonPress = LOWORD(lParam);
1938 Y_ButtonPress = HIWORD(lParam);
1940 if (Msg == WM_LBUTTONDOWN)
1942 if (fwKeys & MK_CONTROL)
1944 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1948 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1951 else if (Msg == WM_RBUTTONDOWN)
1954 VT_ProcessButton3Press();
1961 //cout << "\t WM_MOUSEMOVE" << endl;
1962 WPARAM fwKeys = wParam;
1963 X_Motion = LOWORD(lParam);
1964 Y_Motion = HIWORD(lParam);
1967 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1969 X_ButtonPress = LOWORD(lParam);
1970 Y_ButtonPress = HIWORD(lParam);
1972 if ( fwKeys & MK_RBUTTON ) {
1974 VT_ProcessButton3Press();
1978 if ( fwKeys & MK_CONTROL ) {
1979 if ( fwKeys & MK_LBUTTON ) {
1980 ProcessControlButton1Motion();
1982 else if ( fwKeys & MK_MBUTTON ||
1983 ((fwKeys&MK_LBUTTON) &&
1984 (fwKeys&MK_RBUTTON) ) ){
1985 VT_ProcessControlButton2Motion();
1987 else if ( fwKeys & MK_RBUTTON ) {
1988 VT_ProcessControlButton3Motion();
1992 else if ( fwKeys & MK_SHIFT ) {
1993 if ( fwKeys & MK_MBUTTON ||
1994 ((fwKeys&MK_LBUTTON) &&
1995 (fwKeys&MK_RBUTTON) ) ) {
1996 cout << "ProcessZClipMotion()" << endl;
1997 ProcessZClipMotion();
2001 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2003 if ((fwKeys & MK_MBUTTON
2004 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2006 ProcessZClipMotion();
2017 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2022 return DefWindowProc( hwnd, Msg, wParam, lParam );
2028 //==============================================================================
2029 //function : ViewerMainLoop
2030 //purpose : Get a Event on the view and dispatch it
2031 //==============================================================================
2034 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2036 Ppick = (argc > 0)? 1 : 0;
2044 cout << "Start picking" << endl;
2046 while ( Ppick == 1 ) {
2047 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2048 if (GetMessage(&msg, NULL, 0, 0) ) {
2049 TranslateMessage(&msg);
2050 DispatchMessage(&msg);
2054 cout << "Picking done" << endl;
2060 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2062 int min( int a, int b )
2070 int max( int a, int b )
2078 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2081 static XEvent aReport;
2082 Standard_Boolean pick = argc > 0;
2083 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2084 XNextEvent (aDisplay, &aReport);
2086 // Handle event for the chosen display connection
2087 switch (aReport.type) {
2090 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2093 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2099 // Activate inactive view
2100 Window aWindow = GetWindowHandle(VT_GetWindow());
2101 if(aWindow != aReport.xfocus.window)
2103 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2112 case ConfigureNotify:
2114 VT_ProcessConfigure();
2123 XComposeStatus status_in_out;
2125 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2126 (char *) buf_ret , 10 ,
2127 &ks_ret , &status_in_out ) ;
2130 buf_ret[ret_len] = '\0' ;
2134 VT_ProcessKeyPress (buf_ret);
2140 X_ButtonPress = aReport.xbutton.x;
2141 Y_ButtonPress = aReport.xbutton.y;
2143 if (aReport.xbutton.button == Button1)
2145 if (aReport.xbutton.state & ControlMask)
2147 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2151 IsDragged = Standard_True;
2152 DragFirst = Standard_True;
2155 else if (aReport.xbutton.button == Button3)
2158 VT_ProcessButton3Press();
2168 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2169 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2170 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2173 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2174 if( aContext.IsNull() )
2176 cout << "The context is null. Please use vinit before createmesh" << endl;
2180 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2181 if( aReport.xbutton.button==1 )
2185 aContext->ShiftSelect();
2194 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2195 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2196 ViewerTest::CurrentView());
2200 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2201 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2202 ViewerTest::CurrentView() );
2205 VT_ProcessButton3Release();
2207 IsDragged = Standard_False;
2210 VT_ProcessButton3Release();
2215 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2221 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2222 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2223 XSetFunction( aDisplay, gc, GXinvert );
2226 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2228 X_Motion = aReport.xmotion.x;
2229 Y_Motion = aReport.xmotion.y;
2230 DragFirst = Standard_False;
2232 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2236 X_Motion = aReport.xmotion.x;
2237 Y_Motion = aReport.xmotion.y;
2239 // remove all the ButtonMotionMaskr
2240 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2242 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2243 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2245 Quantity_Length VDX, VDY;
2247 ViewerTest::CurrentView()->Size(VDX,VDY);
2248 Standard_Real VDZ =0 ;
2249 VDZ = ViewerTest::CurrentView()->ZSize();
2251 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2253 Quantity_Length dx = 0 ;
2254 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2258 dx = dx / VDX * VDZ;
2262 ViewerTest::CurrentView()->Redraw();
2266 if ( aReport.xmotion.state & ControlMask ) {
2267 if ( aReport.xmotion.state & Button1Mask ) {
2268 ProcessControlButton1Motion();
2270 else if ( aReport.xmotion.state & Button2Mask ) {
2271 VT_ProcessControlButton2Motion();
2273 else if ( aReport.xmotion.state & Button3Mask ) {
2274 VT_ProcessControlButton3Motion();
2288 //==============================================================================
2289 //function : VProcessEvents
2290 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2291 // event in the Viewer window
2292 //==============================================================================
2294 static void VProcessEvents(ClientData,int)
2296 NCollection_Vector<int> anEventNumbers;
2297 // Get number of messages from every display
2298 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2299 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2301 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2303 // Handle events for every display
2304 int anEventIter = 0;
2305 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2306 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2308 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2309 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2311 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2312 int anEventResult = ViewerMainLoop( 0, NULL);
2313 // If window is closed or context was not found finish current event processing loop
2319 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2324 //==============================================================================
2325 //function : OSWindowSetup
2326 //purpose : Setup for the X11 window to be able to cath the event
2327 //==============================================================================
2330 static void OSWindowSetup()
2332 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2335 Window window = VT_GetWindow()->XWindow();
2336 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2337 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2338 XSynchronize(aDisplay, 1);
2340 // X11 : For keyboard on SUN
2342 wmhints.flags = InputHint;
2345 XSetWMHints( aDisplay, window, &wmhints);
2347 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2348 ButtonPressMask | ButtonReleaseMask |
2349 StructureNotifyMask |
2351 Button1MotionMask | Button2MotionMask |
2352 Button3MotionMask | FocusChangeMask
2354 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2355 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2357 XSynchronize(aDisplay, 0);
2366 //==============================================================================
2369 //purpose : Fitall, no DRAW arguments
2370 //Draw arg : No args
2371 //==============================================================================
2373 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2375 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2376 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2377 if (V.IsNull() == Standard_False) {
2379 } else if (aView.IsNull() == Standard_False) {
2385 //==============================================================================
2387 //purpose : ZFitall, no DRAW arguments
2388 //Draw arg : No args
2389 //==============================================================================
2391 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2393 Handle(V3d_View) V = ViewerTest::CurrentView();
2394 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2397 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2399 Handle(V3d_View) V = ViewerTest::CurrentView();
2400 if ( !V.IsNull() ) V->Redraw(); return 0;
2404 //==============================================================================
2406 //purpose : Remove all the object from the viewer
2407 //Draw arg : No args
2408 //==============================================================================
2410 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2412 Handle(V3d_View) V = ViewerTest::CurrentView();
2414 ViewerTest::Clear();
2418 //==============================================================================
2421 //==============================================================================
2423 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2424 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2427 di << argv[0] << "Invalid number of arguments" << "\n";
2431 while (ViewerMainLoop( argc, argv)) {
2437 //==============================================================================
2438 //function : InitViewerTest
2439 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2440 //==============================================================================
2442 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2444 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2445 ViewerTest::SetAISContext(theContext);
2446 aViewer->InitActiveViews();
2447 Handle(V3d_View) aView = aViewer->ActiveView();
2448 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2449 ViewerTest::ResetEventManager();
2450 Handle(Aspect_Window) aWindow = aView->Window();
2451 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2453 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2455 static int aFirst = 1;
2457 #if TCL_MAJOR_VERSION < 8
2458 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2459 TK_READABLE, VProcessEvents, (ClientData) 0);
2461 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2462 TK_READABLE, VProcessEvents, (ClientData) 0);
2469 //==============================================================================
2471 //purpose : Load image as background
2472 //==============================================================================
2474 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2476 if (argc < 2 || argc > 3)
2478 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2479 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2483 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2484 if(AISContext.IsNull())
2486 di << "use 'vinit' command before " << argv[0] << "\n";
2490 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2493 const char* szType = argv[2];
2494 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2495 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2496 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2497 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2500 di << "Wrong fill type : " << szType << "\n";
2501 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2506 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2507 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2512 //==============================================================================
2513 //function : VSetBgMode
2514 //purpose : Change background image fill type
2515 //==============================================================================
2517 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2521 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2522 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2526 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2527 if(AISContext.IsNull())
2529 di << "use 'vinit' command before " << argv[0] << "\n";
2532 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2533 const char* szType = argv[1];
2534 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2535 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2536 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2537 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2540 di << "Wrong fill type : " << szType << "\n";
2541 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2544 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2545 V3dView->SetBgImageStyle(aFillType, Standard_True);
2549 //==============================================================================
2550 //function : VSetGradientBg
2551 //purpose : Mount gradient background
2552 //==============================================================================
2553 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2557 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2558 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2559 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2560 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2564 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2565 if(AISContext.IsNull())
2567 di << "use 'vinit' command before " << argv[0] << "\n";
2573 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2574 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2575 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2576 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2578 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2579 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2580 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2582 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2583 int aType = Draw::Atoi(argv[7]);
2584 if( aType < 0 || aType > 8 )
2586 di << "Wrong fill type " << "\n";
2587 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2588 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2592 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2594 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2595 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2601 //==============================================================================
2602 //function : VSetGradientBgMode
2603 //purpose : Change gradient background fill style
2604 //==============================================================================
2605 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2609 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2610 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2611 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2615 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2616 if(AISContext.IsNull())
2618 di << "use 'vinit' command before " << argv[0] << "\n";
2623 int aType = Draw::Atoi(argv[1]);
2624 if( aType < 0 || aType > 8 )
2626 di << "Wrong fill type " << "\n";
2627 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2628 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2632 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2634 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2635 V3dView->SetBgGradientStyle( aMethod, 1 );
2641 //==============================================================================
2642 //function : VSetColorBg
2643 //purpose : Set color background
2644 //==============================================================================
2645 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2649 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2650 di << "R,G,B = [0..255]" << "\n";
2654 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2655 if(AISContext.IsNull())
2657 di << "use 'vinit' command before " << argv[0] << "\n";
2663 Standard_Real R = Draw::Atof(argv[1])/255.;
2664 Standard_Real G = Draw::Atof(argv[2])/255.;
2665 Standard_Real B = Draw::Atof(argv[3])/255.;
2666 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2668 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2669 V3dView->SetBackgroundColor( aColor );
2676 //==============================================================================
2678 //purpose : View Scaling
2679 //==============================================================================
2681 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2683 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2684 if ( V3dView.IsNull() ) return 1;
2687 di << argv[0] << "Invalid number of arguments" << "\n";
2690 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2693 //==============================================================================
2694 //function : VTestZBuffTrihedron
2695 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2696 //==============================================================================
2698 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2700 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2701 if ( V3dView.IsNull() ) return 1;
2703 V3dView->ZBufferTriedronSetup();
2706 // Set up default trihedron parameters
2707 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2711 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2712 const char* aPosType = argv[1];
2714 if ( strcmp(aPosType, "center") == 0 )
2716 aPosition = Aspect_TOTP_CENTER;
2718 if (strcmp(aPosType, "left_lower") == 0)
2720 aPosition = Aspect_TOTP_LEFT_LOWER;
2722 if (strcmp(aPosType, "left_upper") == 0)
2724 aPosition = Aspect_TOTP_LEFT_UPPER;
2726 if (strcmp(aPosType, "right_lower") == 0)
2728 aPosition = Aspect_TOTP_RIGHT_LOWER;
2730 if (strcmp(aPosType, "right_upper") == 0)
2732 aPosition = Aspect_TOTP_RIGHT_UPPER;
2735 di << argv[1] << " Invalid type of alignment" << "\n";
2736 di << "Must be one of [ center, left_lower," << "\n";
2737 di << "left_upper, right_lower, right_upper ]" << "\n";
2741 Standard_Real R = Draw::Atof(argv[2])/255.;
2742 Standard_Real G = Draw::Atof(argv[3])/255.;
2743 Standard_Real B = Draw::Atof(argv[4])/255.;
2744 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2746 Standard_Real aScale = Draw::Atof(argv[5]);
2750 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2754 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2755 const char* aPresType = argv[6];
2757 if ( strcmp(aPresType, "wireframe") == 0 )
2759 aPresentation = V3d_WIREFRAME;
2761 if (strcmp(aPresType, "zbuffer") == 0)
2763 aPresentation = V3d_ZBUFFER;
2766 di << argv[6] << " Invalid type of visualization" << "\n";
2767 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2771 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2775 di << argv[0] << " Invalid number of arguments" << "\n";
2784 //==============================================================================
2785 //function : VRotate
2786 //purpose : Camera Rotating
2787 //==============================================================================
2789 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2790 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2791 if ( V3dView.IsNull() ) {
2796 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2798 } else if ( argc == 7 ) {
2799 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]) );
2802 di << argv[0] << " Invalid number of arguments" << "\n";
2807 //==============================================================================
2809 //purpose : View zoom in / out (relative to current zoom)
2810 //==============================================================================
2812 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2813 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2814 if ( V3dView.IsNull() ) {
2819 Standard_Real coef = Draw::Atof(argv[1]);
2820 if ( coef <= 0.0 ) {
2821 di << argv[1] << "Invalid value" << "\n";
2824 V3dView->SetZoom( Draw::Atof(argv[1]) );
2827 di << argv[0] << " Invalid number of arguments" << "\n";
2832 //==============================================================================
2834 //purpose : View panning (in pixels)
2835 //==============================================================================
2837 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2838 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2839 if ( V3dView.IsNull() ) return 1;
2842 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2845 di << argv[0] << " Invalid number of arguments" << "\n";
2851 //==============================================================================
2852 //function : VExport
2853 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2854 //==============================================================================
2856 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2858 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2859 if (V3dView.IsNull())
2864 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2868 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2869 TCollection_AsciiString aFormatStr;
2871 TCollection_AsciiString aFileName (argv[1]);
2872 Standard_Integer aLen = aFileName.Length();
2876 aFormatStr = TCollection_AsciiString (argv[2]);
2880 if (aFileName.Value (aLen - 2) == '.')
2882 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2884 else if (aFileName.Value (aLen - 3) == '.')
2886 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2890 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2896 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2900 aFormatStr.UpperCase();
2901 if (aFormatStr == "PS")
2902 anExpFormat = Graphic3d_EF_PostScript;
2903 else if (aFormatStr == "EPS")
2904 anExpFormat = Graphic3d_EF_EnhPostScript;
2905 else if (aFormatStr == "TEX")
2906 anExpFormat = Graphic3d_EF_TEX;
2907 else if (aFormatStr == "PDF")
2908 anExpFormat = Graphic3d_EF_PDF;
2909 else if (aFormatStr == "SVG")
2910 anExpFormat = Graphic3d_EF_SVG;
2911 else if (aFormatStr == "PGF")
2912 anExpFormat = Graphic3d_EF_PGF;
2913 else if (aFormatStr == "EMF")
2914 anExpFormat = Graphic3d_EF_EMF;
2917 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2922 if (!V3dView->View()->Export (argv[1], anExpFormat))
2924 di << "Error: export of image to " << aFormatStr << " failed!\n";
2927 catch (Standard_Failure)
2929 di << "Error: export of image to " << aFormatStr << " failed";
2930 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2935 //==============================================================================
2936 //function : VColorScale
2937 //purpose : representation color scale
2938 //==============================================================================
2939 #include <V3d_ColorScale.hxx>
2941 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2943 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2945 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2949 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2950 if(aContext.IsNull()) {
2951 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2955 Standard_Real minRange = 0. , maxRange = 100. ;
2957 Standard_Integer numIntervals = 10 ;
2958 Standard_Integer textHeight = 16;
2959 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2960 Standard_Real X = 0., Y = 0. ;
2966 minRange = Draw::Atof( argv[1] );
2967 maxRange = Draw::Atof( argv[2] );
2968 numIntervals = Draw::Atoi( argv[3] );
2971 textHeight = Draw::Atoi( argv[4] );
2973 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2976 X = Draw::Atof( argv[6] );
2977 Y = Draw::Atof( argv[7] );
2980 Handle(V3d_View) curView = ViewerTest::CurrentView( );
2981 if ( curView.IsNull( ) )
2983 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2984 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2985 if( ! aCS.IsNull( ) )
2987 aCS->SetPosition( X , Y );
2988 aCS->SetHeight( 0.95) ;
2989 aCS->SetTextHeight( textHeight );
2990 aCS->SetRange( minRange , maxRange );
2991 aCS->SetNumberOfIntervals( numIntervals );
2992 aCS->SetLabelPosition( position );
2993 if( !curView->ColorScaleIsDisplayed() )
2994 curView->ColorScaleDisplay( );
2999 //==============================================================================
3000 //function : VGraduatedTrihedron
3001 //purpose : Displays a graduated trihedron
3002 //==============================================================================
3004 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3006 const char *str = arg;
3009 unsigned short c1 = *str++;
3010 unsigned short c2 = *str++;
3011 if (!c1 || !c2) break;
3012 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3016 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3019 if (argc != 2 && argc < 5)
3021 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3022 di<<"Usage: type help "<<argv[0]<<"\n";
3023 return 1; //TCL_ERROR
3026 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3028 // Create 3D view if it doesn't exist
3029 if ( aV3dView.IsNull() )
3031 ViewerTest::ViewerInit();
3032 aV3dView = ViewerTest::CurrentView();
3033 if( aV3dView.IsNull() )
3035 di << "Error: Cannot create a 3D view\n";
3036 return 1; //TCL_ERROR
3040 // Erase (==0) or display (!=0)
3041 const int display = Draw::Atoi(argv[1]);
3046 TCollection_AsciiString font;
3048 font.AssignCat("Courier");
3050 font.AssignCat(argv[5]);
3052 // Text is multibyte
3053 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3056 TCollection_ExtendedString xname, yname, zname;
3061 AddMultibyteString(xname, argv[2]);
3062 AddMultibyteString(yname, argv[3]);
3063 AddMultibyteString(zname, argv[4]);
3079 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3080 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3081 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3082 Standard_True/*drawgrid*/,
3083 Standard_True/*drawaxes*/,
3084 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3085 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3086 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3087 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3088 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3089 Quantity_NOC_WHITE/*gridcolor*/,
3090 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3091 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3094 aV3dView->GraduatedTrihedronErase();
3096 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3102 //==============================================================================
3103 //function : VPrintView
3104 //purpose : Test printing algorithm, print the view to image file with given
3105 // width and height. Printing implemented only for WNT.
3106 //==============================================================================
3107 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3111 di << "Printing implemented only for wnt!\n";
3115 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3116 Handle(V3d_View) aView = NULL;
3117 aContextAIS = ViewerTest::GetAISContext();
3118 if (!aContextAIS.IsNull())
3120 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3121 Vwr->InitActiveViews();
3122 if(Vwr->MoreActiveViews())
3123 aView = Vwr->ActiveView();
3129 di << "Call vinit before!\n";
3134 di << "Use: " << argv[0];
3135 di << " width height filename [print algo=0]\n";
3136 di << "width, height of the intermediate buffer for operation\n";
3137 di << "algo : {0|1}\n";
3138 di << " 0 - stretch algorithm\n";
3139 di << " 1 - tile algorithm\n";
3140 di << "test printing algorithms into an intermediate buffer\n";
3141 di << "with saving output to an image file\n";
3145 // get the input params
3146 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3147 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3148 Standard_Integer aMode = 0;
3149 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3151 aMode = Draw::Atoi (argv[4]);
3153 // check the input parameters
3154 if (aWidth <= 0 || aHeight <= 0)
3156 di << "Width and height must be positive values!\n";
3159 if (aMode != 0 && aMode != 1)
3162 // define compatible bitmap
3163 HDC anDC = CreateCompatibleDC(0);
3164 BITMAPINFO aBitmapData;
3165 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3166 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3167 aBitmapData.bmiHeader.biWidth = aWidth ;
3168 aBitmapData.bmiHeader.biHeight = aHeight;
3169 aBitmapData.bmiHeader.biPlanes = 1;
3170 aBitmapData.bmiHeader.biBitCount = 24;
3171 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3172 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3173 aBitmapData.bmiHeader.biClrUsed = 0;
3174 aBitmapData.bmiHeader.biClrImportant = 0;
3175 aBitmapData.bmiHeader.biCompression = BI_RGB;
3176 aBitmapData.bmiHeader.biSizeImage = 0;
3178 // Create Device Independent Bitmap
3179 void* aBitsOut = NULL;
3180 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3181 &aBitsOut, NULL, 0);
3182 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3184 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3185 if (aBitsOut != NULL)
3188 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3190 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3192 // succesfully printed into an intermediate buffer
3195 Image_PixMap aWrapper;
3196 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3197 aWrapper.SetTopDown (false);
3199 Image_AlienPixMap anImageBitmap;
3200 anImageBitmap.InitCopy (aWrapper);
3201 isSaved = anImageBitmap.Save (aFileName);
3205 di << "Print operation failed due to printing errors or\n";
3206 di << "insufficient memory available\n";
3207 di << "Please, try to use smaller dimensions for this test\n";
3208 di << "command, as it allocates intermediate buffer for storing\n";
3209 di << "the result\n";
3214 di << "Can't allocate memory for intermediate buffer\n";
3215 di << "Please use smaller dimensions\n";
3220 SelectObject (anDC, anOldBitmap);
3221 DeleteObject (aMemoryBitmap);
3227 di << "Save to file operation failed. This operation may fail\n";
3228 di << "if you don't have enough available memory, then you can\n";
3229 di << "use smaller dimensions for the output file\n";
3238 //==============================================================================
3239 //function : VZLayer
3240 //purpose : Test z layer operations for v3d viewer
3241 //==============================================================================
3242 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3244 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3245 if (aContextAIS.IsNull())
3247 di << "Call vinit before!\n";
3252 di << "Use: vzlayer " << argv[0];
3253 di << " add/del/get [id]\n";
3254 di << " add - add new z layer to viewer and print its id\n";
3255 di << " del - del z layer by its id\n";
3256 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3257 di << "id - the layer identificator value defined when removing z layer\n";
3261 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3262 if (aViewer.IsNull())
3264 di << "No active viewer!\n";
3268 // perform operation
3269 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3272 Standard_Integer aNewId;
3273 if (!aViewer->AddZLayer (aNewId))
3275 di << "Impossible to add new z layer!\n";
3279 di << "New z layer added with index: " << aNewId << "\n";
3281 else if (anOp == "del")
3285 di << "Please also provide as argument id of z layer to remove\n";
3289 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3290 if (!aViewer->RemoveZLayer (aDelId))
3292 di << "Impossible to remove the z layer or invalid id!\n";
3296 di << "Z layer " << aDelId << " has been removed\n";
3298 else if (anOp == "get")
3300 TColStd_SequenceOfInteger anIds;
3301 aViewer->GetAllZLayers (anIds);
3302 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3304 di << anIds.Value (aSeqIdx) << " ";
3311 di << "Invalid operation, please use { add / del / get }\n";
3318 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3320 // this class provides a presentation of text item in v3d view under-/overlayer
3321 class V3d_TextItem : public Visual3d_LayerItem
3326 DEFINE_STANDARD_RTTI(V3d_TextItem)
3329 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3330 const Standard_Real theX1,
3331 const Standard_Real theY1,
3332 const Standard_Real theHeight,
3333 const TCollection_AsciiString& theFontName,
3334 const Quantity_Color& theColor,
3335 const Quantity_Color& theSubtitleColor,
3336 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3337 const Handle(Visual3d_Layer)& theLayer);
3340 Standard_EXPORT void RedrawLayerPrs();
3346 TCollection_AsciiString myText;
3347 Standard_Real myHeight;
3348 Handle(Visual3d_Layer) myLayer;
3349 Quantity_Color myColor;
3350 Quantity_Color mySubtitleColor;
3351 Aspect_TypeOfDisplayText myType;
3352 TCollection_AsciiString myFontName;
3355 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3356 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3358 // create and add to display the text item
3359 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3360 const Standard_Real theX1,
3361 const Standard_Real theY1,
3362 const Standard_Real theHeight,
3363 const TCollection_AsciiString& theFontName,
3364 const Quantity_Color& theColor,
3365 const Quantity_Color& theSubtitleColor,
3366 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3367 const Handle(Visual3d_Layer)& theLayer)
3368 : myX1 (theX1), myY1 (theY1),
3370 myHeight (theHeight),
3373 mySubtitleColor (theSubtitleColor),
3374 myType (theTypeOfDisplay),
3375 myFontName (theFontName)
3377 if (!myLayer.IsNull ())
3378 myLayer->AddLayerItem (this);
3382 void V3d_TextItem::RedrawLayerPrs ()
3384 if (myLayer.IsNull ())
3387 myLayer->SetColor (myColor);
3388 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3389 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3392 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3394 // The Visual3d_LayerItem line item for "vlayerline" command
3395 // it provides a presentation of line with user-defined
3396 // linewidth, linetype and transparency.
3397 class V3d_LineItem : public Visual3d_LayerItem
3401 DEFINE_STANDARD_RTTI(V3d_LineItem)
3404 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3405 Standard_Real X2, Standard_Real Y2,
3406 V3d_LayerMgrPointer theLayerMgr,
3407 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3408 Standard_Real theWidth = 0.5,
3409 Standard_Real theTransp = 1.0);
3412 Standard_EXPORT void RedrawLayerPrs();
3416 Standard_Real myX1, myY1, myX2, myY2;
3417 V3d_LayerMgrPointer myLayerMgr;
3418 Aspect_TypeOfLine myType;
3419 Standard_Real myWidth;
3420 Standard_Real myTransparency;
3423 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3424 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3426 // default constructor for line item
3427 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3428 Standard_Real X2, Standard_Real Y2,
3429 V3d_LayerMgrPointer theLayerMgr,
3430 Aspect_TypeOfLine theType,
3431 Standard_Real theWidth,
3432 Standard_Real theTransp) :
3433 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3434 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3436 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3437 myLayerMgr->Overlay()->AddLayerItem (this);
3441 void V3d_LineItem::RedrawLayerPrs ()
3443 Handle (Visual3d_Layer) aOverlay;
3446 aOverlay = myLayerMgr->Overlay();
3448 if (!aOverlay.IsNull())
3450 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3451 aOverlay->SetColor(aColor);
3452 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3453 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3454 aOverlay->BeginPolyline();
3455 aOverlay->AddVertex(myX1, myY1);
3456 aOverlay->AddVertex(myX2, myY2);
3457 aOverlay->ClosePrimitive();
3461 //=============================================================================
3462 //function : VLayerLine
3463 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3464 // : linewidth, transparency coefficient
3465 //============================================================================
3466 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3468 // get the active view
3469 Handle(V3d_View) aView = ViewerTest::CurrentView();
3472 di << "Call vinit before!\n";
3477 di << "Use: " << argv[0];
3478 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3479 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3480 di << " 0 - solid \n";
3481 di << " 1 - dashed \n";
3482 di << " 2 - dot \n";
3483 di << " 3 - dashdot\n";
3484 di << " transparency : { 0.0 - 1.0 } \n";
3485 di << " 0.0 - transparent\n";
3486 di << " 1.0 - visible \n";
3490 // get the input params
3491 Standard_Real X1 = Draw::Atof(argv[1]);
3492 Standard_Real Y1 = Draw::Atof(argv[2]);
3493 Standard_Real X2 = Draw::Atof(argv[3]);
3494 Standard_Real Y2 = Draw::Atof(argv[4]);
3496 Standard_Real aWidth = 0.5;
3497 Standard_Integer aType = 0;
3498 Standard_Real aTransparency = 1.0;
3502 aWidth = Draw::Atof(argv[5]);
3506 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3511 aTransparency = Draw::Atof(argv[7]);
3512 if (aTransparency < 0 || aTransparency > 1.0)
3513 aTransparency = 1.0;
3516 // select appropriate line type
3517 Aspect_TypeOfLine aLineType;
3521 aLineType = Aspect_TOL_DASH;
3525 aLineType = Aspect_TOL_DOT;
3529 aLineType = Aspect_TOL_DOTDASH;
3533 aLineType = Aspect_TOL_SOLID;
3536 // replace layer manager
3537 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3538 aView->SetLayerMgr(aMgr);
3541 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3547 aView->MustBeResized();
3553 //=======================================================================
3554 //function : VOverlayText
3555 //purpose : Test text displaying in view overlay
3556 //=======================================================================
3557 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3559 // get the active view
3560 Handle(V3d_View) aView = ViewerTest::CurrentView();
3563 di << "No active view. Please call vinit.\n";
3566 else if (argc < 4 || argc > 13)
3568 di << "Use: " << argv[0];
3569 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3570 di << "[background_color: R G B]\n";
3571 di << " height - pixel height of the text (default=10.0)\n";
3572 di << " font_name - name of font (default=courier)\n";
3573 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3574 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
3575 di << " background_color- R G B values used for subtitle and decal text\n";
3576 di << "(default=255.0 255.0 255.0)\n";
3580 TCollection_AsciiString aText (argv[1]);
3581 Standard_Real aPosX = Draw::Atof(argv[2]);
3582 Standard_Real aPosY = Draw::Atof(argv[3]);
3583 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3586 TCollection_AsciiString aFontName = "Courier";
3588 aFontName = TCollection_AsciiString (argv[5]);
3591 Quantity_Parameter aColorRed = 1.0;
3592 Quantity_Parameter aColorGreen = 1.0;
3593 Quantity_Parameter aColorBlue = 1.0;
3596 aColorRed = Draw::Atof (argv[6])/255.;
3597 aColorGreen = Draw::Atof (argv[7])/255.;
3598 aColorBlue = Draw::Atof (argv[8])/255.;
3602 TCollection_AsciiString aDispStr;
3604 aDispStr = TCollection_AsciiString (argv[9]);
3606 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3607 if (aDispStr.IsEqual ("subtitle"))
3608 aTextType = Aspect_TODT_SUBTITLE;
3609 else if (aDispStr.IsEqual ("decal"))
3610 aTextType = Aspect_TODT_DEKALE;
3611 else if (aDispStr.IsEqual ("blend"))
3612 aTextType = Aspect_TODT_BLEND;
3615 Quantity_Parameter aSubRed = 1.0;
3616 Quantity_Parameter aSubGreen = 1.0;
3617 Quantity_Parameter aSubBlue = 1.0;
3620 aSubRed = Draw::Atof (argv[10])/255.;
3621 aSubGreen = Draw::Atof (argv[11])/255.;
3622 aSubBlue = Draw::Atof (argv[12])/255.;
3625 // check fo current overlay
3626 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3627 if (anOverlay.IsNull ())
3629 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3630 anOverlay = aMgr->Overlay ();
3631 aView->SetLayerMgr (aMgr);
3634 Quantity_Color aTextColor (aColorRed, aColorGreen,
3635 aColorBlue, Quantity_TOC_RGB);
3636 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3637 aSubBlue, Quantity_TOC_RGB);
3640 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3641 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3644 aView->MustBeResized();
3650 //==============================================================================
3653 //==============================================================================
3655 static int VGrid (Draw_Interpretor& /*theDI*/,
3656 Standard_Integer theArgNb,
3657 const char** theArgVec)
3659 // get the active view
3660 Handle(V3d_View) aView = ViewerTest::CurrentView();
3661 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3662 if (aView.IsNull() || aViewer.IsNull())
3664 std::cerr << "No active view. Please call vinit.\n";
3668 Aspect_GridType aType = aViewer->GridType();
3669 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3671 Standard_Integer anIter = 1;
3672 for (; anIter < theArgNb; ++anIter)
3674 const char* aValue = theArgVec[anIter];
3677 aType = Aspect_GT_Rectangular;
3679 else if (*aValue == 'c')
3681 aType = Aspect_GT_Circular;
3683 else if (*aValue == 'l')
3685 aMode = Aspect_GDM_Lines;
3687 else if (*aValue == 'p')
3689 aMode = Aspect_GDM_Points;
3691 else if (strcmp (aValue, "off" ) == 0)
3693 aViewer->DeactivateGrid();
3702 Standard_Integer aTail = (theArgNb - anIter);
3705 aViewer->ActivateGrid (aType, aMode);
3708 else if (aTail != 2 && aTail != 5)
3710 std::cerr << "Incorrect arguments number! Usage:\n"
3711 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3715 Quantity_Length anOriginX, anOriginY;
3716 Quantity_PlaneAngle aRotAngle;
3717 if (aType == Aspect_GT_Rectangular)
3719 Quantity_Length aRStepX, aRStepY;
3720 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3722 anOriginX = Draw::Atof (theArgVec[anIter++]);
3723 anOriginY = Draw::Atof (theArgVec[anIter++]);
3726 aRStepX = Draw::Atof (theArgVec[anIter++]);
3727 aRStepY = Draw::Atof (theArgVec[anIter++]);
3728 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3730 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3731 aViewer->ActivateGrid (aType, aMode);
3733 else if (aType == Aspect_GT_Circular)
3735 Quantity_Length aRadiusStep;
3736 Standard_Integer aDivisionNumber;
3737 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3739 anOriginX = Draw::Atof (theArgVec[anIter++]);
3740 anOriginY = Draw::Atof (theArgVec[anIter++]);
3743 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3744 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3745 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3748 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3749 aViewer->ActivateGrid (aType, aMode);
3755 //==============================================================================
3758 //==============================================================================
3760 static int VFps (Draw_Interpretor& theDI,
3761 Standard_Integer theArgNb,
3762 const char** theArgVec)
3764 // get the active view
3765 Handle(V3d_View) aView = ViewerTest::CurrentView();
3768 std::cerr << "No active view. Please call vinit.\n";
3772 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3775 std::cerr << "Incorrect arguments!\n";
3779 // the time is meaningless for first call
3780 // due to async OpenGl rendering
3783 // redraw view in loop to estimate average values
3786 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3792 const Standard_Real aTime = aTimer.ElapsedTime();
3793 aTimer.OSD_Chronometer::Show (aCpu);
3795 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3796 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3798 // return statistics
3799 theDI << "FPS: " << aFpsAver << "\n"
3800 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3805 //==============================================================================
3806 //function : VGlDebug
3808 //==============================================================================
3810 static int VGlDebug (Draw_Interpretor& theDI,
3811 Standard_Integer theArgNb,
3812 const char** theArgVec)
3816 Handle(V3d_View) aView = ViewerTest::CurrentView();
3819 std::cerr << "No active view. Please call vinit.\n";
3823 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3824 "GL_ARB_debug_output");
3825 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3826 theDI << (isActive ? "1" : "0");
3830 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3834 //==============================================================================
3837 //==============================================================================
3839 static int VVbo (Draw_Interpretor& theDI,
3840 Standard_Integer theArgNb,
3841 const char** theArgVec)
3843 const Standard_Boolean toSet = (theArgNb > 1);
3844 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3847 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
3851 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3852 if (aContextAIS.IsNull())
3856 std::cerr << "No active view!\n";
3860 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3861 if (!aDriver.IsNull())
3865 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3869 aDriver->ChangeOptions().vboDisable = toUseVbo;
3876 //==============================================================================
3879 //==============================================================================
3881 static int VCaps (Draw_Interpretor& theDI,
3882 Standard_Integer theArgNb,
3883 const char** theArgVec)
3885 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
3886 Handle(OpenGl_GraphicDriver) aDriver;
3887 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3888 if (!aContextAIS.IsNull())
3890 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3891 aCaps = &aDriver->ChangeOptions();
3896 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
3897 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
3898 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
3902 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3904 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
3905 if (anArg.Search ("vbo=") > -1)
3907 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3909 else if (anArg.Search ("sprites=") > -1)
3911 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3913 else if (anArg.Search ("soft=") > -1)
3915 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
3919 std::cerr << "Unknown argument: " << anArg << "\n";
3922 if (aCaps != &ViewerTest_myDefaultCaps)
3924 ViewerTest_myDefaultCaps = *aCaps;
3929 //==============================================================================
3930 //function : VMemGpu
3932 //==============================================================================
3934 static int VMemGpu (Draw_Interpretor& theDI,
3935 Standard_Integer theArgNb,
3936 const char** theArgVec)
3939 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3940 if (aContextAIS.IsNull())
3942 std::cerr << "No active view. Please call vinit.\n";
3946 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3947 if (aDriver.IsNull())
3949 std::cerr << "Graphic driver not available.\n";
3953 Standard_Size aFreeBytes = 0;
3954 TCollection_AsciiString anInfo;
3955 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3957 std::cerr << "Information not available.\n";
3961 if (theArgNb > 1 && *theArgVec[1] == 'f')
3963 theDI << Standard_Real (aFreeBytes);
3973 // ==============================================================================
3974 // function : VReadPixel
3976 // ==============================================================================
3977 static int VReadPixel (Draw_Interpretor& theDI,
3978 Standard_Integer theArgNb,
3979 const char** theArgVec)
3981 // get the active view
3982 Handle(V3d_View) aView = ViewerTest::CurrentView();
3985 std::cerr << "No active view. Please call vinit.\n";
3988 else if (theArgNb < 3)
3990 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
3994 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3995 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
3997 Standard_Integer aWidth, aHeight;
3998 aView->Window()->Size (aWidth, aHeight);
3999 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4000 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4001 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4003 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4007 Standard_Boolean toShowName = Standard_False;
4008 Standard_Boolean toShowHls = Standard_False;
4009 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4011 const char* aParam = theArgVec[anIter];
4012 if ( strcasecmp( aParam, "rgb" ) == 0 )
4014 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4015 aBufferType = Graphic3d_BT_RGB;
4017 else if ( strcasecmp( aParam, "hls" ) == 0 )
4019 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4020 aBufferType = Graphic3d_BT_RGB;
4021 toShowHls = Standard_True;
4023 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4025 aFormat = Image_PixMap::ImgRGBF;
4026 aBufferType = Graphic3d_BT_RGB;
4028 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4030 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4031 aBufferType = Graphic3d_BT_RGBA;
4033 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4035 aFormat = Image_PixMap::ImgRGBAF;
4036 aBufferType = Graphic3d_BT_RGBA;
4038 else if ( strcasecmp( aParam, "depth" ) == 0 )
4040 aFormat = Image_PixMap::ImgGrayF;
4041 aBufferType = Graphic3d_BT_Depth;
4043 else if ( strcasecmp( aParam, "name" ) == 0 )
4045 toShowName = Standard_True;
4049 Image_PixMap anImage;
4050 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4052 std::cerr << "Image allocation failed\n";
4055 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4057 std::cerr << "Image dump failed\n";
4061 Quantity_Parameter anAlpha;
4062 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4065 if (aBufferType == Graphic3d_BT_RGBA)
4067 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
4071 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
4076 switch (aBufferType)
4079 case Graphic3d_BT_RGB:
4083 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
4087 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
4091 case Graphic3d_BT_RGBA:
4093 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
4096 case Graphic3d_BT_Depth:
4098 theDI << aColor.Red() << "\n";
4107 //==============================================================================
4108 //function : VDiffImage
4109 //purpose : The draw-command compares two images.
4110 //==============================================================================
4112 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4116 theDI << "Not enough arguments.\n";
4121 const char* anImgPathRef = theArgVec[1];
4122 const char* anImgPathNew = theArgVec[2];
4124 // get string tolerance and check its validity
4125 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4126 if (aTolColor < 0.0)
4128 if (aTolColor > 1.0)
4131 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4132 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4134 // image file of difference
4135 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4137 // compare the images
4138 Image_Diff aComparer;
4139 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4144 aComparer.SetColorTolerance (aTolColor);
4145 aComparer.SetBorderFilterOn (isBorderFilterOn);
4146 Standard_Integer aDiffColorsNb = aComparer.Compare();
4147 theDI << aDiffColorsNb << "\n";
4149 // save image of difference
4150 if (aDiffImagePath != NULL)
4152 aComparer.SaveDiffImage (aDiffImagePath);
4158 //=======================================================================
4159 //function : VSelect
4160 //purpose : Emulates different types of selection by mouse:
4161 // 1) single click selection
4162 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4163 // 3) selection with polygon having corners at
4164 // pixel positions (x1,y1),...,(xn,yn)
4165 // 4) any of these selections with shift button pressed
4166 //=======================================================================
4167 static Standard_Integer VSelect (Draw_Interpretor& di,
4168 Standard_Integer argc,
4173 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4177 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4178 if(myAIScontext.IsNull())
4180 di << "use 'vinit' command before " << argv[0] << "\n";
4183 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4184 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4185 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4188 if(isShiftSelection)
4189 aCurrentEventManager->ShiftSelect();
4191 aCurrentEventManager->Select();
4195 if(isShiftSelection)
4196 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4198 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4202 Standard_Integer anUpper = 0;
4204 if(isShiftSelection)
4205 anUpper = (argc-1)/2;
4208 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4210 for(Standard_Integer i=1;i<=anUpper;++i)
4211 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4213 if(isShiftSelection)
4214 aCurrentEventManager->ShiftSelect(aPolyline);
4216 aCurrentEventManager->Select(aPolyline);
4221 //=======================================================================
4222 //function : VMoveTo
4223 //purpose : Emulates cursor movement to defined pixel position
4224 //=======================================================================
4225 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4226 Standard_Integer argc,
4231 di << "Usage : " << argv[0] << " x y" << "\n";
4235 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4236 if(aContext.IsNull())
4238 di << "use 'vinit' command before " << argv[0] << "\n";
4241 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4245 //=======================================================================
4246 //function : VViewParams
4247 //purpose : Gets or sets AIS View characteristics
4248 //=======================================================================
4249 static Standard_Integer VViewParams (Draw_Interpretor& di,
4250 Standard_Integer argc,
4253 if ( argc != 1 && argc != 13)
4255 di << "Usage : " << argv[0] << "\n";
4258 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
4259 if ( anAISView.IsNull () )
4261 di << "use 'vinit' command before " << argv[0] << "\n";
4265 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
4266 Standard_Real anAISViewCenterCoordinateX = 0.0;
4267 Standard_Real anAISViewCenterCoordinateY = 0.0;
4268 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4269 Standard_Real anAISViewProjX = 0.0;
4270 Standard_Real anAISViewProjY = 0.0;
4271 Standard_Real anAISViewProjZ = 0.0;
4272 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4273 Standard_Real anAISViewUpX = 0.0;
4274 Standard_Real anAISViewUpY = 0.0;
4275 Standard_Real anAISViewUpZ = 0.0;
4276 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4277 Standard_Real anAISViewAtX = 0.0;
4278 Standard_Real anAISViewAtY = 0.0;
4279 Standard_Real anAISViewAtZ = 0.0;
4280 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4281 di << "Scale of current view: " << anAISViewScale << "\n";
4282 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
4283 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4284 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4285 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4289 Quantity_Factor anAISViewScale = atof (argv [1]);
4290 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
4291 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
4292 Standard_Real anAISViewProjX = atof (argv [4]);
4293 Standard_Real anAISViewProjY = atof (argv [5]);
4294 Standard_Real anAISViewProjZ = atof (argv [6]);
4295 Standard_Real anAISViewUpX = atof (argv [7]);
4296 Standard_Real anAISViewUpY = atof (argv [8]);
4297 Standard_Real anAISViewUpZ = atof (argv [9]);
4298 Standard_Real anAISViewAtX = atof (argv [10]);
4299 Standard_Real anAISViewAtY = atof (argv [11]);
4300 Standard_Real anAISViewAtZ = atof (argv [12]);
4301 anAISView -> V3d_View::SetScale (anAISViewScale);
4302 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4303 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4304 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4305 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4310 //=======================================================================
4311 //function : VChangeSelected
4312 //purpose : Adds the shape to selection or remove one from it
4313 //=======================================================================
4314 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4315 Standard_Integer argc,
4320 di<<"Usage : " << argv[0] << " shape \n";
4324 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4325 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4326 TCollection_AsciiString aName(argv[1]);
4327 Handle(AIS_InteractiveObject) anAISObject;
4329 if(!aMap.IsBound2(aName))
4331 di<<"Use 'vdisplay' before";
4336 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4337 if(anAISObject.IsNull()){
4338 di<<"No interactive object \n";
4342 if(aContext->HasOpenedContext())
4344 aContext->AddOrRemoveSelected(anAISObject);
4348 aContext->AddOrRemoveCurrentObject(anAISObject);
4354 //=======================================================================
4355 //function : VZClipping
4356 //purpose : Gets or sets ZClipping mode, width and depth
4357 //=======================================================================
4358 static Standard_Integer VZClipping (Draw_Interpretor& di,
4359 Standard_Integer argc,
4364 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4365 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4368 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4369 if(aContext.IsNull())
4371 di << "use 'vinit' command before " << argv[0] << "\n";
4374 Handle(V3d_View) aView = ViewerTest::CurrentView();
4375 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4378 TCollection_AsciiString aZClippingModeString;
4379 Quantity_Length aDepth, aWidth;
4380 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4381 switch (aZClippingMode)
4384 aZClippingModeString.Copy("OFF");
4387 aZClippingModeString.Copy("BACK");
4390 aZClippingModeString.Copy("FRONT");
4393 aZClippingModeString.Copy("SLICE");
4396 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4399 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4400 << "ZClipping depth = " << aDepth << "\n"
4401 << "ZClipping width = " << aWidth << "\n";
4407 Standard_Integer aStatus = 0;
4408 if ( strcmp (argv [1], "OFF") == 0 ) {
4410 aZClippingMode = V3d_OFF;
4412 if ( strcmp (argv [1], "BACK") == 0 ) {
4414 aZClippingMode = V3d_BACK;
4416 if ( strcmp (argv [1], "FRONT") == 0 ) {
4418 aZClippingMode = V3d_FRONT;
4420 if ( strcmp (argv [1], "SLICE") == 0 ) {
4422 aZClippingMode = V3d_SLICE;
4426 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4427 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4430 aView->SetZClippingType(aZClippingMode);
4434 Quantity_Length aDepth = 0., aWidth = 1.;
4437 aDepth = atof(argv[1]);
4438 aWidth = atof(argv[2]);
4442 aDepth = atof(argv[2]);
4443 aWidth = atof(argv[3]);
4446 if(aDepth<0. || aDepth>1.)
4448 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4449 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4452 if(aWidth<0. || aWidth>1.)
4454 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4455 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4459 aView->SetZClippingDepth(aDepth);
4460 aView->SetZClippingWidth(aWidth);
4467 //=======================================================================
4468 //function : VNbSelected
4469 //purpose : Returns number of selected objects
4470 //=======================================================================
4471 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4472 Standard_Integer argc,
4477 di << "Usage : " << argv[0] << "\n";
4480 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4481 if(aContext.IsNull())
4483 di << "use 'vinit' command before " << argv[0] << "\n";
4486 di << aContext->NbSelected() << "\n";
4490 //=======================================================================
4491 //function : VAntialiasing
4492 //purpose : Switches altialiasing on or off
4493 //=======================================================================
4494 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4495 Standard_Integer argc,
4500 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4504 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4505 if(aContext.IsNull())
4507 di << "use 'vinit' command before " << argv[0] << "\n";
4511 Handle(V3d_View) aView = ViewerTest::CurrentView();
4513 if((argc == 2) && (atof(argv[1]) == 0))
4514 aView->SetAntialiasingOff();
4516 aView->SetAntialiasingOn();
4521 //=======================================================================
4522 //function : VPurgeDisplay
4523 //purpose : Switches altialiasing on or off
4524 //=======================================================================
4525 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4526 Standard_Integer argc,
4531 di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
4534 Standard_Boolean isCollectorToo = Standard_False;
4537 isCollectorToo = (atoi(argv [1]) != 0);
4539 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4540 if (aContext.IsNull())
4542 di << "use 'vinit' command before " << argv[0] << "\n";
4545 aContext->CloseAllContexts(Standard_False);
4546 di << aContext->PurgeDisplay(isCollectorToo) << "\n";
4550 //=======================================================================
4551 //function : VSetViewSize
4553 //=======================================================================
4554 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4555 Standard_Integer argc,
4558 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4559 if(aContext.IsNull())
4561 di << "use 'vinit' command before " << argv[0] << "\n";
4566 di<<"Usage : " << argv[0] << " Size\n";
4569 Standard_Real aSize = atof(argv[1]);
4572 di<<"Bad Size value : " << aSize << "\n";
4576 Handle(V3d_View) aView = ViewerTest::CurrentView();
4577 aView->SetSize(aSize);
4581 //=======================================================================
4582 //function : VMoveView
4584 //=======================================================================
4585 static Standard_Integer VMoveView (Draw_Interpretor& di,
4586 Standard_Integer argc,
4589 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4590 if(aContext.IsNull())
4592 di << "use 'vinit' command before " << argv[0] << "\n";
4595 if(argc < 4 || argc > 5)
4597 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4600 Standard_Real Dx = atof(argv[1]);
4601 Standard_Real Dy = atof(argv[2]);
4602 Standard_Real Dz = atof(argv[3]);
4603 Standard_Boolean aStart = Standard_True;
4606 aStart = (atoi(argv[4]) > 0);
4609 Handle(V3d_View) aView = ViewerTest::CurrentView();
4610 aView->Move(Dx,Dy,Dz,aStart);
4614 //=======================================================================
4615 //function : VTranslateView
4617 //=======================================================================
4618 static Standard_Integer VTranslateView (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->Translate(Dx,Dy,Dz,aStart);
4647 //=======================================================================
4648 //function : VTurnView
4650 //=======================================================================
4651 static Standard_Integer VTurnView (Draw_Interpretor& di,
4652 Standard_Integer argc,
4655 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4656 if(aContext.IsNull()) {
4657 di << "use 'vinit' command before " << argv[0] << "\n";
4660 if(argc < 4 || argc > 5){
4661 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4664 Standard_Real Ax = atof(argv[1]);
4665 Standard_Real Ay = atof(argv[2]);
4666 Standard_Real Az = atof(argv[3]);
4667 Standard_Boolean aStart = Standard_True;
4670 aStart = (atoi(argv[4]) > 0);
4673 Handle(V3d_View) aView = ViewerTest::CurrentView();
4674 aView->Turn(Ax,Ay,Az,aStart);
4678 //==============================================================================
4679 //function : VTextureEnv
4680 //purpose : ENables or disables environment mapping
4681 //==============================================================================
4682 class OCC_TextureEnv : public Graphic3d_TextureEnv
4685 OCC_TextureEnv(const Standard_CString FileName);
4686 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4687 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4688 const Standard_Boolean theModulateFlag,
4689 const Graphic3d_TypeOfTextureFilter theFilter,
4690 const Standard_ShortReal theXScale,
4691 const Standard_ShortReal theYScale,
4692 const Standard_ShortReal theXShift,
4693 const Standard_ShortReal theYShift,
4694 const Standard_ShortReal theAngle);
4695 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4697 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4698 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4699 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4701 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4702 : Graphic3d_TextureEnv(theFileName)
4706 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4707 : Graphic3d_TextureEnv(theTexId)
4711 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4712 const Standard_Boolean theModulateFlag,
4713 const Graphic3d_TypeOfTextureFilter theFilter,
4714 const Standard_ShortReal theXScale,
4715 const Standard_ShortReal theYScale,
4716 const Standard_ShortReal theXShift,
4717 const Standard_ShortReal theYShift,
4718 const Standard_ShortReal theAngle)
4720 myParams->SetRepeat (theRepeatFlag);
4721 myParams->SetModulate (theModulateFlag);
4722 myParams->SetFilter (theFilter);
4723 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
4724 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4725 myParams->SetRotation (theAngle);
4728 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4730 // get the active view
4731 Handle(V3d_View) aView = ViewerTest::CurrentView();
4734 std::cerr << "No active view. Please call vinit.\n";
4738 // Checking the input arguments
4739 Standard_Boolean anEnableFlag = Standard_False;
4740 Standard_Boolean isOk = theArgNb >= 2;
4743 TCollection_AsciiString anEnableOpt(theArgVec[1]);
4744 anEnableFlag = anEnableOpt.IsEqual("on");
4745 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
4749 isOk = (theArgNb == 3 || theArgNb == 11);
4752 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4753 isOk = (!aTextureOpt.IsIntegerValue() ||
4754 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
4756 if (isOk && theArgNb == 11)
4758 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
4759 aModulateOpt(theArgVec[4]),
4760 aFilterOpt (theArgVec[5]),
4761 aSScaleOpt (theArgVec[6]),
4762 aTScaleOpt (theArgVec[7]),
4763 aSTransOpt (theArgVec[8]),
4764 aTTransOpt (theArgVec[9]),
4765 anAngleOpt (theArgVec[10]);
4766 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
4767 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
4768 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
4769 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
4770 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
4771 anAngleOpt.IsRealValue());
4778 std::cerr << "Usage :" << std::endl;
4779 std::cerr << theArgVec[0] << " off" << std::endl;
4780 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;
4786 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4787 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
4788 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
4789 new OCC_TextureEnv(theArgVec[2]);
4793 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
4794 aTexEnv->SetTextureParameters(
4795 aRepeatOpt. IsEqual("repeat"),
4796 aModulateOpt.IsEqual("modulate"),
4797 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
4798 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
4799 Graphic3d_TOTF_TRILINEAR,
4800 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
4801 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
4802 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
4803 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
4804 (Standard_ShortReal)Draw::Atof(theArgVec[10])
4807 aView->SetTextureEnv(aTexEnv);
4808 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
4810 else // Disabling environment mapping
4812 aView->SetSurfaceDetail(V3d_TEX_NONE);
4813 Handle(Graphic3d_TextureEnv) aTexture;
4814 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
4821 //===============================================================================================
4822 //function : VClipPlane
4824 //===============================================================================================
4825 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4827 // use short-cut for created clip planes map of created (or "registered by name") clip planes
4828 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
4829 static MapOfPlanes aRegPlanes;
4833 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
4837 TCollection_AsciiString aCommand (theArgVec[1]);
4839 // print maximum number of planes for current viewer
4840 if (aCommand == "maxplanes")
4844 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
4848 TCollection_AsciiString aViewName (theArgVec[2]);
4850 if (!ViewerTest_myViews.IsBound1 (aViewName))
4852 theDi << theArgVec[0] << ": view is not found.\n";
4856 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
4858 theDi << theArgVec[0] << ": "
4859 << aView->Viewer()->Driver()->InquirePlaneLimit()
4860 << " plane slots provided by driver."
4861 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
4866 // create / delete plane instance
4867 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
4871 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
4875 Standard_Boolean toCreate = (aCommand == "create");
4876 Standard_Boolean toClone = (aCommand == "clone");
4877 TCollection_AsciiString aPlane (theArgVec[2]);
4881 if (aRegPlanes.IsBound (aPlane))
4883 theDi << theArgVec[0] << ": plane name is in use.\n";
4887 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
4889 else if (toClone) // toClone
4891 if (!aRegPlanes.IsBound (aPlane))
4893 theDi << theArgVec[0] << ": no such plane.\n";
4899 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
4903 TCollection_AsciiString aClone (theArgVec[3]);
4904 if (aRegPlanes.IsBound (aClone))
4906 theDi << theArgVec[0] << ": plane name is in use.\n";
4910 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4912 aRegPlanes.Bind (aClone, aClipPlane->Clone());
4916 if (!aRegPlanes.IsBound (aPlane))
4918 theDi << theArgVec[0] << ": no such plane.\n";
4922 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
4923 aRegPlanes.UnBind (aPlane);
4925 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
4926 for (; anIObjIt.More(); anIObjIt.Next())
4928 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
4929 aPrs->RemoveClipPlane(aClipPlane);
4932 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
4933 for (; aViewIt.More(); aViewIt.Next())
4935 const Handle(V3d_View)& aView = aViewIt.Key2();
4936 aView->RemoveClipPlane(aClipPlane);
4939 ViewerTest::RedrawAllViews();
4945 // set / unset plane command
4946 if (aCommand == "set" || aCommand == "unset")
4950 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
4954 Standard_Boolean toSet = (aCommand == "set");
4955 TCollection_AsciiString aPlane (theArgVec [2]);
4956 if (!aRegPlanes.IsBound (aPlane))
4958 theDi << theArgVec[0] << ": no such plane.\n";
4962 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4964 TCollection_AsciiString aTarget (theArgVec [3]);
4965 if (aTarget != "object" && aTarget != "view")
4967 theDi << theArgVec[0] << ": invalid target.\n";
4971 if (aTarget == "object" || aTarget == "view")
4975 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
4979 Standard_Boolean isObject = (aTarget == "object");
4981 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
4983 TCollection_AsciiString anEntityName (theArgVec[anIt]);
4984 if (isObject) // to object
4986 if (!GetMapOfAIS().IsBound2 (anEntityName))
4988 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
4992 Handle(AIS_InteractiveObject) aIObj =
4993 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
4996 aIObj->AddClipPlane (aClipPlane);
4998 aIObj->RemoveClipPlane (aClipPlane);
5002 if (!ViewerTest_myViews.IsBound1 (anEntityName))
5004 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
5008 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
5010 aView->AddClipPlane (aClipPlane);
5012 aView->RemoveClipPlane (aClipPlane);
5016 ViewerTest::RedrawAllViews();
5022 // change plane command
5023 if (aCommand == "change")
5027 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5031 TCollection_AsciiString aPlane (theArgVec [2]);
5032 if (!aRegPlanes.IsBound (aPlane))
5034 theDi << theArgVec[0] << ": no such plane.\n";
5038 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5040 TCollection_AsciiString aChangeArg (theArgVec [3]);
5041 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5043 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5047 if (aChangeArg == "on" || aChangeArg == "off") // on / off
5049 aClipPlane->SetOn (aChangeArg == "on");
5051 else if (aChangeArg == "equation") // change equation
5055 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5059 Standard_Real aCoeffA = atof (theArgVec [4]);
5060 Standard_Real aCoeffB = atof (theArgVec [5]);
5061 Standard_Real aCoeffC = atof (theArgVec [6]);
5062 Standard_Real aCoeffD = atof (theArgVec [7]);
5063 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5065 else if (aChangeArg == "capping") // change capping aspects
5069 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5073 TCollection_AsciiString aCappingArg (theArgVec [4]);
5074 if (aCappingArg != "on" && aCappingArg != "off" &&
5075 aCappingArg != "color" && aCappingArg != "texname" &&
5076 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5077 aCappingArg != "texrotate" && aCappingArg != "hatch")
5079 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5083 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5085 aClipPlane->SetCapping (aCappingArg == "on");
5087 else if (aCappingArg == "color") // color aspect for capping
5091 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5095 Standard_Real aRed = atof (theArgVec [5]);
5096 Standard_Real aGrn = atof (theArgVec [6]);
5097 Standard_Real aBlu = atof (theArgVec [7]);
5099 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5100 aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
5101 aClipPlane->SetCappingMaterial (aMat);
5103 else if (aCappingArg == "texname") // texture name
5107 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5111 TCollection_AsciiString aTextureName (theArgVec [5]);
5113 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5114 if (!aTexture->IsDone ())
5116 aClipPlane->SetCappingTexture (NULL);
5120 aTexture->EnableModulate();
5121 aTexture->EnableRepeat();
5122 aClipPlane->SetCappingTexture (aTexture);
5125 else if (aCappingArg == "texscale") // texture scale
5127 if (aClipPlane->CappingTexture().IsNull())
5129 theDi << theArgVec[0] << ": no texture is set.\n";
5135 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5139 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5140 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5142 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5144 else if (aCappingArg == "texorigin") // texture origin
5146 if (aClipPlane->CappingTexture().IsNull())
5148 theDi << theArgVec[0] << ": no texture is set.\n";
5154 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5158 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5159 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5161 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5163 else if (aCappingArg == "texrotate") // texture rotation
5165 if (aClipPlane->CappingTexture().IsNull())
5167 theDi << theArgVec[0] << ": no texture is set.\n";
5173 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5177 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5179 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5181 else if (aCappingArg == "hatch") // hatch style
5185 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5189 TCollection_AsciiString aHatchStr (theArgVec [5]);
5190 if (aHatchStr == "on")
5192 aClipPlane->SetCappingHatchOn();
5194 else if (aHatchStr == "off")
5196 aClipPlane->SetCappingHatchOff();
5200 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5205 ViewerTest::RedrawAllViews();
5210 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5214 //===============================================================================================
5215 //function : VSetTextureMode
5217 //===============================================================================================
5218 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5222 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5226 TCollection_AsciiString aViewName (theArgVec[1]);
5227 if (!ViewerTest_myViews.IsBound1 (aViewName))
5229 theDi << theArgVec[0] << ": view is not found.\n";
5233 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5234 switch (atoi (theArgVec[2]))
5236 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5237 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5238 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5240 theDi << theArgVec[0] << ": invalid mode.\n";
5248 //=======================================================================
5249 //function : ViewerCommands
5251 //=======================================================================
5253 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
5256 const char *group = "ZeViewer";
5257 theCommands.Add("vinit",
5258 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5259 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5261 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5263 " - Creates new View window with specified name view_name.\n"
5264 "By default the new view is created in the viewer and in"
5265 " graphic driver shared with active view.\n"
5266 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
5267 "If driverName isn't specified the driver will be shared with active view.\n"
5268 "If viewerName isn't specified the viewer will be shared with active view.\n"
5269 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5270 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
5271 "is used in creation of graphic driver\n"
5273 " - l, t: pixel position of left top corner of the window\n"
5274 " - w,h: width and heigth of window respectively.\n"
5275 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
5276 __FILE__,VInit,group);
5277 theCommands.Add("vclose" ,
5278 "view_id [keep_context=0|1]\n"
5279 "or vclose ALL - to remove all created views\n"
5280 " - removes view(viewer window) defined by its view_id.\n"
5281 " - keep_context: by default 0; if 1 and the last view is deleted"
5282 " the current context is not removed.",
5283 __FILE__,VClose,group);
5284 theCommands.Add("vactivate" ,
5286 " - activates view(viewer window) defined by its view_id",
5287 __FILE__,VActivate,group);
5288 theCommands.Add("vviewlist",
5289 "vviewlist [format={tree, long}]"
5290 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
5291 " - format: format of result output, if tree the output is a tree view;"
5292 "otherwise it's a list of full view names. By default format = tree",
5293 __FILE__,VViewList,group);
5294 theCommands.Add("vhelp" ,
5295 "vhelp : display help on the viewer commands",
5296 __FILE__,VHelp,group);
5297 theCommands.Add("vtop" ,
5298 "vtop or <T> : Top view" ,
5299 __FILE__,VTop,group);
5300 theCommands.Add("vbottom" ,
5301 "vbottom : Bottom view" ,
5302 __FILE__,VBottom,group);
5303 theCommands.Add("vleft" ,
5304 "vleft : Left view" ,
5305 __FILE__,VLeft,group);
5306 theCommands.Add("vright" ,
5307 "vright : Right view" ,
5308 __FILE__,VRight,group);
5309 theCommands.Add("vaxo" ,
5310 " vaxo or <A> : Axonometric view ",
5311 __FILE__,VAxo,group);
5312 theCommands.Add("vfront" ,
5313 "vfront : Front view" ,
5314 __FILE__,VFront,group);
5315 theCommands.Add("vback" ,
5316 "vback : Back view" ,
5317 __FILE__,VBack,group);
5318 theCommands.Add("vpick" ,
5319 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
5321 theCommands.Add("vfit" ,
5322 "vfit or <F> : vfit",
5323 __FILE__,VFit,group);
5324 theCommands.Add("vzfit" ,
5326 __FILE__,VZFit,group);
5327 theCommands.Add("vrepaint",
5328 "vrepaint : vrepaint, force redraw",
5329 __FILE__,VRepaint,group);
5330 theCommands.Add("vclear",
5332 __FILE__,VClear,group);
5333 theCommands.Add("vsetbg",
5334 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
5335 __FILE__,VSetBg,group);
5336 theCommands.Add("vsetbgmode",
5337 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
5338 __FILE__,VSetBgMode,group);
5339 theCommands.Add("vsetgradientbg",
5340 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
5341 __FILE__,VSetGradientBg,group);
5342 theCommands.Add("vsetgrbgmode",
5343 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
5344 __FILE__,VSetGradientBgMode,group);
5345 theCommands.Add("vsetcolorbg",
5346 "vsetcolorbg : vsetcolorbg r g b : Set background color",
5347 __FILE__,VSetColorBg,group);
5348 theCommands.Add("vscale",
5349 "vscale : vscale X Y Z",
5350 __FILE__,VScale,group);
5351 theCommands.Add("vzbufftrihedron",
5352 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
5353 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
5354 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
5355 __FILE__,VTestZBuffTrihedron,group);
5356 theCommands.Add("vrotate",
5357 "vrotate : vrotate AX AY AZ [X Y Z]",
5358 __FILE__,VRotate,group);
5359 theCommands.Add("vzoom",
5360 "vzoom : vzoom coef",
5361 __FILE__,VZoom,group);
5362 theCommands.Add("vpan",
5363 "vpan : vpan dx dy",
5364 __FILE__,VPan,group);
5365 theCommands.Add("vexport",
5366 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
5367 " : exports the view to a vector file of a given format"
5368 " : notice that EMF format requires patched gl2ps",
5369 __FILE__,VExport,group);
5370 theCommands.Add("vcolorscale",
5371 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
5372 __FILE__,VColorScale,group);
5373 theCommands.Add("vgraduatedtrihedron",
5374 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
5375 __FILE__,VGraduatedTrihedron,group);
5376 theCommands.Add("vprintview" ,
5377 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
5378 __FILE__,VPrintView,group);
5379 theCommands.Add("vzlayer",
5380 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
5381 __FILE__,VZLayer,group);
5382 theCommands.Add("voverlaytext",
5383 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
5384 " : height - pixel height of the text (default=10.0)"
5385 " : font_name - name of font (default=courier)"
5386 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
5387 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
5388 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
5389 __FILE__,VOverlayText,group);
5390 theCommands.Add("vlayerline",
5391 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
5392 __FILE__,VLayerLine,group);
5393 theCommands.Add ("vgrid",
5394 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
5395 " : Mode - rectangular or circular"
5396 " : Type - lines or points",
5397 __FILE__, VGrid, group);
5398 theCommands.Add ("vfps",
5399 "vfps [framesNb=100] : estimate average frame rate for active view",
5400 __FILE__, VFps, group);
5401 theCommands.Add ("vgldebug",
5402 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
5403 " : this function is implemented only for Windows\n"
5404 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
5405 __FILE__, VGlDebug, group);
5406 theCommands.Add ("vvbo",
5407 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
5408 __FILE__, VVbo, group);
5409 theCommands.Add ("vcaps",
5410 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
5411 __FILE__, VCaps, group);
5412 theCommands.Add ("vmemgpu",
5413 "vmemgpu [f]: print system-dependent GPU memory information if available;"
5414 " with f option returns free memory in bytes",
5415 __FILE__, VMemGpu, group);
5416 theCommands.Add ("vreadpixel",
5417 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
5418 " : Read pixel value for active view",
5419 __FILE__, VReadPixel, group);
5420 theCommands.Add("diffimage",
5421 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
5422 __FILE__, VDiffImage, group);
5423 theCommands.Add ("vselect",
5424 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
5425 "- emulates different types of selection:\n"
5426 "- 1) single click selection\n"
5427 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
5428 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
5429 "- 4) any of these selections with shift button pressed",
5430 __FILE__, VSelect, group);
5431 theCommands.Add ("vmoveto",
5433 "- emulates cursor movement to pixel postion (x,y)",
5434 __FILE__, VMoveTo, group);
5435 theCommands.Add("vviewparams",
5436 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
5437 "- gets or sets current view characteristics",
5438 __FILE__,VViewParams, group);
5439 theCommands.Add("vchangeselected",
5440 "vchangeselected shape"
5441 "- adds to shape to selection or remove one from it",
5442 __FILE__, VChangeSelected, group);
5443 theCommands.Add("vzclipping",
5444 "vzclipping [mode] [depth width]\n"
5445 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
5446 "- gets or sets ZClipping mode, width and depth",
5447 __FILE__,VZClipping,group);
5448 theCommands.Add ("vnbselected",
5449 "vnbselected", __FILE__, VNbSelected, group);
5450 theCommands.Add("vantialiasing",
5451 "vantialiasing 1|0",
5452 __FILE__,VAntialiasing,group);
5453 theCommands.Add ("vpurgedisplay",
5454 "vpurgedisplay [CollectorToo = 0|1]"
5455 "- removes structures which don't belong to objects displayed in neutral point",
5456 __FILE__, VPurgeDisplay, group);
5457 theCommands.Add("vsetviewsize",
5458 "vsetviewsize size",
5459 __FILE__,VSetViewSize,group);
5460 theCommands.Add("vmoveview",
5461 "vmoveview Dx Dy Dz [Start = 1|0]",
5462 __FILE__,VMoveView,group);
5463 theCommands.Add("vtranslateview",
5464 "vtranslateview Dx Dy Dz [Start = 1|0)]",
5465 __FILE__,VTranslateView,group);
5466 theCommands.Add("vturnview",
5467 "vturnview Ax Ay Az [Start = 1|0]",
5468 __FILE__,VTurnView,group);
5469 theCommands.Add("vtextureenv",
5470 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
5471 "or user-defined file and optionally applying texture mapping parameters\n"
5473 " vtextureenv off - disables environment mapping\n"
5474 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
5475 " std_texture = (0..7)\n"
5476 " rep = {clamp|repeat}\n"
5477 " mod = {decal|modulate}\n"
5478 " flt = {nearest|bilinear|trilinear}\n"
5479 " ss, st - scale factors for s and t texture coordinates\n"
5480 " ts, tt - translation for s and t texture coordinates\n"
5481 " rot - texture rotation angle in degrees",
5482 __FILE__, VTextureEnv, group);
5483 theCommands.Add("vhlr" ,
5484 "is_enabled={on|off}"
5485 " - Hidden line removal algorithm:"
5486 " - is_enabled: if is on HLR algorithm is applied\n",
5487 __FILE__,VHLR,group);
5488 theCommands.Add("vhlrtype" ,
5489 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
5490 " - Changes the type of HLR algorithm using for shapes."
5491 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
5492 " if equals to polyalgo, polygonal HLR algorithm is applied."
5493 "If shapes are not given HLR algoithm of given type is applied"
5494 " to all shapes in the view\n",
5495 __FILE__,VHLRType,group);
5496 theCommands.Add("vclipplane", "vclipplane usage: \n"
5497 " maxplanes <view_name> - get plane limit for view.\n"
5498 " create <plane_name> - create new plane.\n"
5499 " delete <plane_name> - delete plane.\n"
5500 " clone <source_plane> <plane_name> - clone the plane definition.\n"
5501 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
5502 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
5503 " change <plane_name> on/off - turn clipping on/off.\n"
5504 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
5505 " change <plane_name> capping on/off - turn capping on/off.\n"
5506 " change <plane_name> capping color <r> <g> <b> - set color.\n"
5507 " change <plane name> capping texname <texture> - set texture.\n"
5508 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
5509 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
5510 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
5511 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
5512 " please use VSetTextureMode command to enable texture rendering in view.\n"
5513 , __FILE__, VClipPlane, group);
5514 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
5516 " 0 - no textures enabled in view.\n"
5517 " 1 - only environment textures enabled.\n"
5518 " 2 - all textures enabled.\n"
5519 " this command sets texture details mode for the specified view.\n"
5520 , __FILE__, VSetTextureMode, group);