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;
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();
614 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
616 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
617 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
619 else if (a3DViewer.IsNull())
621 toCreateViewer = Standard_True;
622 TCollection_ExtendedString NameOfWindow("Viewer3D");
623 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
625 NameOfWindow = TCollection_ExtendedString("Collector");
627 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
631 if (ViewerTest::GetAISContext().IsNull() ||
632 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
634 Handle(AIS_InteractiveContext) aContext =
635 new AIS_InteractiveContext(a3DViewer);
636 ViewerTest::SetAISContext (aContext);
637 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
640 ViewerTest::ResetEventManager();
643 #if defined(_WIN32) || defined(__WIN32__)
644 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
645 Handle(WNT_WClass)::DownCast (WClass()),
646 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
650 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
651 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
653 aPxWidth, aPxHeight);
654 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
656 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
659 aPxWidth, aPxHeight);
661 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
664 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
666 ViewerTest::CurrentView(aView);
667 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
668 TheNISContext()->AttachView (aView);
670 // Setup for X11 or NT
673 // Set parameters for V3d_View and V3d_Viewer
674 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
675 aV3dView->SetComputedMode(Standard_False);
676 MyHLRIsOn = aV3dView->ComputedMode();
677 aV3dView->SetZClippingDepth(0.5);
678 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
680 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
683 a3DViewer->SetDefaultLights();
684 a3DViewer->SetLightOn();
687 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
688 #if TCL_MAJOR_VERSION < 8
689 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
690 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
692 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
693 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
697 VT_GetWindow()->Map();
699 // Set the handle of created view in the event manager
700 ViewerTest::ResetEventManager();
702 ViewerTest::CurrentView()->Redraw();
707 return aViewNames.GetViewName();
710 //==============================================================================
711 //function : RedrawAllViews
712 //purpose : Redraw all created views
713 //==============================================================================
714 void ViewerTest::RedrawAllViews()
716 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
717 for (; aViewIt.More(); aViewIt.Next())
719 const Handle(V3d_View)& aView = aViewIt.Key2();
724 //==============================================================================
725 //function : SplitParameter
726 //purpose : Split parameter string to parameter name an patameter value
727 //==============================================================================
728 Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
729 TCollection_AsciiString& theName,
730 TCollection_AsciiString& theValue)
732 Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
733 if (aParamNameEnd == 0)
734 return Standard_False;
735 TCollection_AsciiString aString(theString);
736 if (aParamNameEnd != 0)
738 theValue = aString.Split(aParamNameEnd);
739 aString.Split(aString.Length()-1);
742 return Standard_True;
745 //==============================================================================
747 //purpose : Create the window viewer and initialize all the global variable
748 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
749 //==============================================================================
751 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
755 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
756 << "Type help for more information.\n";
759 TCollection_AsciiString aViewName (""),
761 Standard_Integer aPxLeft = 0,
766 for (Standard_Integer i = 1; i < theArgsNb; ++i)
768 TCollection_AsciiString aName = "", aValue = "";
769 if(!SplitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
771 // In case of syntax: vinit ViewName
772 aViewName = theArgVec[1];
780 else if (aName == "l" || aName == "left")
781 aPxLeft = aValue.IntegerValue();
782 else if (aName == "t" || aName == "top")
783 aPxTop = aValue.IntegerValue();
784 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
785 else if (aName == "display")
786 aDisplayName = aValue;
788 else if (aName == "w" || aName == "width")
789 aPxWidth = aValue.IntegerValue();
790 else if (aName == "h" || aName == "height")
791 aPxHeight = aValue.IntegerValue();
794 theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n";
799 ViewerTest_Names aViewNames (aViewName);
800 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
802 TCollection_AsciiString aCommand("vactivate ");
803 aCommand = aCommand + aViewNames.GetViewName();
804 theDi.Eval(aCommand.ToCString());
808 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
809 aViewName.ToCString(),
810 aDisplayName.ToCString());
811 cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n";
815 //==============================================================================
817 //purpose : hidden lines removal algorithm
818 //==============================================================================
820 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
822 if (ViewerTest::CurrentView().IsNull())
824 di << argv[0] << ": Call vinit before this command, please.\n";
830 di << argv[0] << ": Wrong number of command arguments.\n"
831 << "Type help " << argv[0] << " for more information.\n";
835 Standard_Boolean isHLROn =
836 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
838 if (isHLROn == MyHLRIsOn)
844 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
849 //==============================================================================
850 //function : VHLRType
851 //purpose : change type of using HLR algorithm
852 //==============================================================================
854 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
856 if (ViewerTest::CurrentView().IsNull())
858 di << argv[0] << ": Call vinit before this command, please.\n";
864 di << argv[0] << ": Wrong number of command arguments.\n"
865 << "Type help " << argv[0] << " for more information.\n";
869 Prs3d_TypeOfHLR aTypeOfHLR =
870 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
874 AIS_ListOfInteractive aListOfShapes;
875 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
876 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
877 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
878 anIter.More(); anIter.Next())
880 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
883 if (aShape->TypeOfHLR() != aTypeOfHLR)
884 aShape->SetTypeOfHLR (aTypeOfHLR);
888 ViewerTest::CurrentView()->Update();
893 for (Standard_Integer i = 2; i < argc; ++i)
895 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
896 TCollection_AsciiString aName (argv[i]);
898 if (!aMap.IsBound2 (aName))
900 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
903 Handle(AIS_Shape) anAISObject =
904 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
905 if (anAISObject.IsNull())
907 anAISObject->SetTypeOfHLR (aTypeOfHLR);
909 anAISObject->Redisplay();
911 ViewerTest::CurrentView()->Update();
917 //==============================================================================
918 //function : FindViewIdByWindowHandle
919 //purpose : Find theView Id in the map of views by window handle
920 //==============================================================================
921 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
922 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
924 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
925 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
927 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
928 if (aWindowHandle == theWindowHandle)
929 return anIter.Key1();
931 return TCollection_AsciiString("");
935 //==============================================================================
936 //function : ActivateView
937 //purpose : Make the view active
938 //==============================================================================
940 void ActivateView (const TCollection_AsciiString& theViewName)
942 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
945 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
946 if (!anAISContext.IsNull())
948 if (!ViewerTest::CurrentView().IsNull())
950 TCollection_AsciiString aTitle("3D View - ");
951 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
952 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
955 ViewerTest::CurrentView (aView);
956 // Update degenerate mode
957 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
958 ViewerTest::SetAISContext (anAISContext);
959 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
960 aTitle = aTitle + theViewName + "(*)";
961 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
962 #if defined(_WIN32) || defined(__WIN32__)
963 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
964 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
965 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
967 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
969 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
970 ViewerTest::CurrentView()->Redraw();
975 //==============================================================================
976 //function : RemoveView
977 //purpose : Close and remove view from display, clear maps if neccessary
978 //==============================================================================
979 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
981 if (!ViewerTest_myViews.IsBound1(theViewName))
983 cout << "Wrong view name\n";
987 // Activate another view if it's active now
988 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
990 if (ViewerTest_myViews.Extent() > 1)
992 TCollection_AsciiString aNewViewName;
993 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
994 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
995 if (anIter.Key1() != theViewName)
997 aNewViewName = anIter.Key1();
1000 ActivateView (aNewViewName);
1004 Handle(V3d_View) anEmptyView;
1005 #if defined(_WIN32) || defined(__WIN32__)
1006 Handle(WNT_Window) anEmptyWindow;
1007 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1008 Handle(Cocoa_Window) anEmptyWindow;
1010 Handle(Xw_Window) anEmptyWindow;
1012 VT_GetWindow() = anEmptyWindow;
1013 ViewerTest::CurrentView (anEmptyView);
1014 if (isContextRemoved)
1016 Handle(AIS_InteractiveContext) anEmptyContext;
1017 ViewerTest::SetAISContext(anEmptyContext);
1023 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1024 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1026 // Remove view resources
1027 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1028 ViewerTest_myViews.UnBind1(theViewName);
1031 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1032 XFlush (GetDisplayConnection()->GetDisplay());
1035 // Keep context opened only if the closed view is last to avoid
1036 // unused empty contexts
1037 if (!aCurrentContext.IsNull())
1039 // Check if there are more difined views in the viewer
1040 aCurrentContext->CurrentViewer()->InitDefinedViews();
1041 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1043 // Remove driver if there is no viewers that use it
1044 Standard_Boolean isRemoveDriver = Standard_True;
1045 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1046 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1048 if (aCurrentContext != anIter.Key2() &&
1049 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1051 isRemoveDriver = Standard_False;
1057 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1058 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1059 #if TCL_MAJOR_VERSION < 8
1060 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1062 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1067 ViewerTest_myContexts.UnBind2(aCurrentContext);
1070 cout << "3D View - " << theViewName << " was deleted.\n";
1074 //==============================================================================
1076 //purpose : Remove the view defined by its name
1077 //==============================================================================
1079 static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1083 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
1084 << "Type help " << theArgVec[0] << " for more information.\n";
1088 if (ViewerTest_myViews.IsEmpty())
1090 theDi << theArgVec[0] <<": there is no views to close.\n";
1094 TCollection_AsciiString anInputString(theArgVec[1]);
1096 // Create list to iterate and remove views from the map of views
1097 NCollection_List<TCollection_AsciiString> aViewList;
1098 if ( strcasecmp( anInputString.ToCString(), "ALL" ) == 0 )
1100 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
1101 anIter.More(); anIter.Next())
1103 aViewList.Append(anIter.Key1());
1108 ViewerTest_Names aViewNames(anInputString);
1109 aViewList.Append(aViewNames.GetViewName());
1112 Standard_Boolean isContextRemoved = (theArgsNb == 3 && atoi(theArgVec[2])==1) ? Standard_False : Standard_True;
1113 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1114 anIter.More(); anIter.Next())
1116 ViewerTest::RemoveView(anIter.Value(), isContextRemoved);
1122 //==============================================================================
1123 //function : VActivate
1124 //purpose : Activate the view defined by its ID
1125 //==============================================================================
1127 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1131 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1132 << "Usage: " << theArgVec[0] << " ViewID\n";
1137 theDi.Eval("vviewlist");
1141 TCollection_AsciiString aNameString(theArgVec[1]);
1142 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1144 TCollection_AsciiString aTitle("3D View - ");
1145 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1146 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1147 Handle(V3d_View) anEmptyView;
1148 #if defined(_WIN32) || defined(__WIN32__)
1149 Handle(WNT_Window) anEmptyWindow;
1150 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1151 Handle(Cocoa_Window) anEmptyWindow;
1153 Handle(Xw_Window) anEmptyWindow;
1155 VT_GetWindow() = anEmptyWindow;
1156 ViewerTest::CurrentView (anEmptyView);
1157 ViewerTest::ResetEventManager();
1158 theDi << theArgVec[0] << ": all views are inactive\n";
1162 ViewerTest_Names aViewNames(aNameString);
1164 // Check if this view exists in the viewer with the driver
1165 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1167 theDi << "Wrong view name\n";
1171 // Check if it is active already
1172 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1174 theDi << theArgVec[0] << ": the view is active already\n";
1178 ActivateView (aViewNames.GetViewName());
1182 //==============================================================================
1183 //function : VViewList
1184 //purpose : Print current list of views per viewer and graphic driver ID
1185 // shared between viewers
1186 //==============================================================================
1188 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1192 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1193 << "Usage: " << theArgVec[0] << " name";
1196 if (ViewerTest_myContexts.Size() < 1)
1199 Standard_Boolean isTreeView =
1200 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1203 theDi << theArgVec[0] <<":\n";
1205 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1206 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1209 theDi << aDriverIter.Key1() << ":\n";
1211 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1212 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1214 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1218 TCollection_AsciiString aContextName(aContextIter.Key1());
1219 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1222 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1223 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1225 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1227 TCollection_AsciiString aViewName(aViewIter.Key1());
1230 if (aViewIter.Value() == ViewerTest::CurrentView())
1231 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1233 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1237 theDi << aViewName << " ";
1247 //==============================================================================
1248 //function : VT_ProcessKeyPress
1249 //purpose : Handle KeyPress event from a CString
1250 //==============================================================================
1251 void VT_ProcessKeyPress (const char* buf_ret)
1253 //cout << "KeyPress" << endl;
1254 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1255 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1256 // Letter in alphabetic order
1258 if ( !strcasecmp(buf_ret, "A") ) {
1260 aView->SetProj(V3d_XposYnegZpos);
1262 else if ( !strcasecmp(buf_ret, "D") ) {
1266 else if ( !strcasecmp(buf_ret, "F") ) {
1268 if (aNisView.IsNull())
1271 aNisView->FitAll3d();
1273 else if ( !strcasecmp(buf_ret, "H") ) {
1275 cout << "HLR" << endl;
1276 aView->SetComputedMode (!aView->ComputedMode());
1277 MyHLRIsOn = aView->ComputedMode();
1279 else if ( !strcasecmp(buf_ret, "P") ) {
1281 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1282 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1283 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1285 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1286 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1288 AIS_ListOfInteractive aListOfShapes;
1289 aContext->DisplayedObjects(aListOfShapes);
1290 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1291 anIter.More(); anIter.Next())
1293 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1294 if (aShape.IsNull())
1296 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1297 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1299 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1300 aShape->Redisplay();
1305 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1307 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1308 if (aShape.IsNull())
1310 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1311 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1313 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1314 aShape->Redisplay();
1318 aContext->UpdateCurrentViewer();
1321 else if ( !strcasecmp(buf_ret, "S") ) {
1323 cout << "passage en mode 1 (shading pour les shapes)" << endl;
1325 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1326 if(Ctx->NbCurrents()==0 ||
1327 Ctx->NbSelected()==0)
1328 Ctx->SetDisplayMode(AIS_Shaded);
1330 if(Ctx->HasOpenedContext()){
1331 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1332 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1335 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1336 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1338 Ctx->UpdateCurrentViewer();
1341 else if ( !strcasecmp(buf_ret, "U") ) {
1342 // Unset display mode
1343 cout<<"passage au mode par defaut"<<endl;
1345 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1346 if(Ctx->NbCurrents()==0 ||
1347 Ctx->NbSelected()==0)
1348 Ctx->SetDisplayMode(AIS_WireFrame);
1350 if(Ctx->HasOpenedContext()){
1351 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1352 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1355 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1356 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1358 Ctx->UpdateCurrentViewer();
1362 else if ( !strcasecmp(buf_ret, "T") ) {
1364 aView->SetProj(V3d_Zpos);
1366 else if ( !strcasecmp(buf_ret, "B") ) {
1368 aView->SetProj(V3d_Zneg);
1370 else if ( !strcasecmp(buf_ret, "L") ) {
1372 aView->SetProj(V3d_Xneg);
1374 else if ( !strcasecmp(buf_ret, "R") ) {
1376 aView->SetProj(V3d_Xpos);
1379 else if ( !strcasecmp(buf_ret, "W") ) {
1381 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
1382 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1383 if(Ctx->NbCurrents()==0 ||
1384 Ctx->NbSelected()==0)
1385 Ctx->SetDisplayMode(AIS_WireFrame);
1387 if(Ctx->HasOpenedContext()){
1388 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1389 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1392 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1393 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1395 Ctx->UpdateCurrentViewer();
1398 else if ( !strcasecmp(buf_ret, "Z") ) {
1402 cout << "ZClipping OFF" << endl;
1405 aView->SetZClippingType(V3d_OFF);
1409 cout << "ZClipping ON" << endl;
1412 aView->SetZClippingType(V3d_FRONT);
1416 else if ( !strcasecmp(buf_ret, ",") ) {
1417 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1421 else if ( !strcasecmp(buf_ret, ".") ) {
1422 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1426 Standard_Integer Num = Draw::Atoi(buf_ret);
1427 if(Num>=0 && Num<=7)
1428 ViewerTest::StandardModeActivation(Num);
1432 //==============================================================================
1433 //function : VT_ProcessExpose
1434 //purpose : Redraw the View on an Expose Event
1435 //==============================================================================
1436 void VT_ProcessExpose()
1438 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1439 if (!aView3d.IsNull())
1445 //==============================================================================
1446 //function : VT_ProcessConfigure
1447 //purpose : Resize the View on an Configure Event
1448 //==============================================================================
1449 void VT_ProcessConfigure()
1451 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1452 if (aView3d.IsNull())
1457 aView3d->MustBeResized();
1462 //==============================================================================
1463 //function : VT_ProcessButton1Press
1465 //==============================================================================
1466 Standard_Boolean VT_ProcessButton1Press(
1469 Standard_Boolean pick,
1470 Standard_Boolean shift)
1472 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1474 Standard_Real X, Y, Z;
1476 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1478 Draw::Set(argv[1], X);
1479 Draw::Set(argv[2], Y);
1480 Draw::Set(argv[3], Z);}
1491 //==============================================================================
1492 //function : VT_ProcessButton1Release
1493 //purpose : End selecting
1494 //==============================================================================
1495 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1499 IsDragged = Standard_False;
1500 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1503 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1504 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1508 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1509 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1514 //==============================================================================
1515 //function : VT_ProcessButton3Press
1516 //purpose : Start Rotation
1517 //==============================================================================
1518 void VT_ProcessButton3Press()
1523 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1525 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1528 //==============================================================================
1529 //function : VT_ProcessButton3Release
1530 //purpose : End rotation
1531 //==============================================================================
1532 void VT_ProcessButton3Release()
1539 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1544 //==============================================================================
1545 //function : ProcessZClipMotion
1547 //==============================================================================
1549 void ProcessZClipMotion()
1551 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1552 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1553 static Standard_Real CurZPos = 0.;
1555 //Quantity_Length VDX, VDY;
1556 //a3DView->Size(VDX,VDY);
1557 //Standard_Real VDZ = a3DView->ZSize();
1558 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1560 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1562 // Front = Depth + width/2.
1563 Standard_Real D = 0.5;
1564 Standard_Real W = 0.1;
1570 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1572 a3DView->SetZClippingType(V3d_OFF);
1573 a3DView->SetZClippingDepth(D);
1574 a3DView->SetZClippingWidth(W);
1575 a3DView->SetZClippingType(V3d_FRONT);
1579 X_ButtonPress = X_Motion;
1580 Y_ButtonPress = Y_Motion;
1584 //==============================================================================
1585 //function : ProcessControlButton1Motion
1587 //==============================================================================
1589 static void ProcessControlButton1Motion()
1591 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1593 X_ButtonPress = X_Motion;
1594 Y_ButtonPress = Y_Motion;
1597 //==============================================================================
1598 //function : VT_ProcessControlButton2Motion
1600 //==============================================================================
1601 void VT_ProcessControlButton2Motion()
1603 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1604 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1606 dy = -dy; // Xwindow Y axis is from top to Bottom
1608 ViewerTest::CurrentView()->Panning( dx, dy );
1610 X_ButtonPress = X_Motion;
1611 Y_ButtonPress = Y_Motion;
1614 //==============================================================================
1615 //function : VT_ProcessControlButton3Motion
1616 //purpose : Rotation
1617 //==============================================================================
1618 void VT_ProcessControlButton3Motion()
1622 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1626 //==============================================================================
1627 //function : VT_ProcessMotion
1629 //==============================================================================
1630 void VT_ProcessMotion()
1632 //pre-hilights detected objects at mouse position
1634 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1635 EM->MoveTo(X_Motion, Y_Motion);
1639 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1641 Xpix = X_Motion;Ypix=Y_Motion;
1644 //==============================================================================
1645 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1646 //purpose : Switches to an axonometric, top, left and other views
1647 //==============================================================================
1649 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1651 if ( ViewerTest::CurrentView().IsNull() )
1653 di<<"Call vinit before this command, please"<<"\n";
1657 ViewerTest::CurrentView()->SetProj(ori);
1661 //==============================================================================
1663 //purpose : Switch to an Axonometric view
1664 //Draw arg : No args
1665 //==============================================================================
1667 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1669 return ViewProject(di, V3d_XposYnegZpos);
1672 //==============================================================================
1674 //purpose : Switch to a Top View
1675 //Draw arg : No args
1676 //==============================================================================
1678 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1680 return ViewProject(di, V3d_Zpos);
1683 //==============================================================================
1684 //function : VBottom
1685 //purpose : Switch to a Bottom View
1686 //Draw arg : No args
1687 //==============================================================================
1689 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1691 return ViewProject(di, V3d_Zneg);
1694 //==============================================================================
1696 //purpose : Switch to a Left View
1697 //Draw arg : No args
1698 //==============================================================================
1700 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1702 return ViewProject(di, V3d_Ypos);
1705 //==============================================================================
1707 //purpose : Switch to a Right View
1708 //Draw arg : No args
1709 //==============================================================================
1711 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1713 return ViewProject(di, V3d_Yneg);
1716 //==============================================================================
1718 //purpose : Switch to a Front View
1719 //Draw arg : No args
1720 //==============================================================================
1722 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1724 return ViewProject(di, V3d_Xpos);
1727 //==============================================================================
1729 //purpose : Switch to a Back View
1730 //Draw arg : No args
1731 //==============================================================================
1733 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1735 return ViewProject(di, V3d_Xneg);
1738 //==============================================================================
1740 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1741 //Draw arg : No args
1742 //==============================================================================
1744 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1747 di << "Q : Quit the application" << "\n";
1749 di << "========================="<<"\n";
1750 di << "F : FitAll" << "\n";
1751 di << "T : TopView" << "\n";
1752 di << "B : BottomView" << "\n";
1753 di << "R : RightView" << "\n";
1754 di << "L : LeftView" << "\n";
1755 di << "A : AxonometricView" << "\n";
1756 di << "D : ResetView" << "\n";
1758 di << "========================="<<"\n";
1759 di << "S : Shading" << "\n";
1760 di << "W : Wireframe" << "\n";
1761 di << "H : HidelLineRemoval" << "\n";
1762 di << "U : Unset display mode" << "\n";
1764 di << "========================="<<"\n";
1765 di << "Selection mode "<<"\n";
1766 di << "0 : Shape" <<"\n";
1767 di << "1 : Vertex" <<"\n";
1768 di << "2 : Edge" <<"\n";
1769 di << "3 : Wire" <<"\n";
1770 di << "4 : Face" <<"\n";
1771 di << "5 : Shell" <<"\n";
1772 di << "6 : Solid" <<"\n";
1773 di << "7 : Compound" <<"\n";
1775 di << "========================="<<"\n";
1776 di << "Z : Switch Z clipping On/Off" << "\n";
1777 di << ", : Hilight next detected" << "\n";
1778 di << ". : Hilight previous detected" << "\n";
1785 static Standard_Boolean Ppick = 0;
1786 static Standard_Integer Pargc = 0;
1787 static const char** Pargv = NULL;
1790 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1795 if (!ViewerTest_myViews.IsEmpty()) {
1797 WPARAM fwKeys = wParam;
1802 // Delete view from map of views
1803 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1808 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1809 || ViewerTest::CurrentView().IsNull())
1811 // Activate inactive window
1812 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1814 ActivateView (FindViewIdByWindowHandle(hwnd));
1819 IsDragged = Standard_False;
1822 HDC hdc = GetDC( hwnd );
1823 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1824 SetROP2( hdc, R2_NOT );
1825 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1826 ReleaseDC( hwnd, hdc );
1828 const Handle(ViewerTest_EventManager) EM =
1829 ViewerTest::CurrentEventManager();
1830 if ( fwKeys & MK_SHIFT )
1831 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1832 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1834 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1835 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1837 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1839 case WM_LBUTTONDOWN:
1840 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1842 IsDragged = Standard_True;
1843 DragFirst = Standard_True;
1844 X_ButtonPress = LOWORD(lParam);
1845 Y_ButtonPress = HIWORD(lParam);
1847 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1854 HDC hdc = GetDC( hwnd );
1856 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1857 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1858 SetROP2( hdc, R2_NOT );
1861 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1863 DragFirst = Standard_False;
1864 X_Motion = LOWORD(lParam);
1865 Y_Motion = HIWORD(lParam);
1867 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1869 SelectObject( hdc, anObj );
1871 ReleaseDC( hwnd, hdc );
1874 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1878 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1882 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1886 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1893 if ( !ViewerTest::CurrentView().IsNull() ) {
1898 BeginPaint(hwnd, &ps);
1899 EndPaint(hwnd, &ps);
1904 VT_ProcessConfigure();
1908 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1911 c[0] = (char) wParam;
1913 VT_ProcessKeyPress (c);
1921 VT_ProcessButton3Release();
1924 case WM_LBUTTONDOWN:
1925 case WM_MBUTTONDOWN:
1926 case WM_RBUTTONDOWN:
1928 WPARAM fwKeys = wParam;
1932 X_ButtonPress = LOWORD(lParam);
1933 Y_ButtonPress = HIWORD(lParam);
1935 if (Msg == WM_LBUTTONDOWN)
1937 if (fwKeys & MK_CONTROL)
1939 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1943 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1946 else if (Msg == WM_RBUTTONDOWN)
1949 VT_ProcessButton3Press();
1956 //cout << "\t WM_MOUSEMOVE" << endl;
1957 WPARAM fwKeys = wParam;
1958 X_Motion = LOWORD(lParam);
1959 Y_Motion = HIWORD(lParam);
1962 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1964 X_ButtonPress = LOWORD(lParam);
1965 Y_ButtonPress = HIWORD(lParam);
1967 if ( fwKeys & MK_RBUTTON ) {
1969 VT_ProcessButton3Press();
1973 if ( fwKeys & MK_CONTROL ) {
1974 if ( fwKeys & MK_LBUTTON ) {
1975 ProcessControlButton1Motion();
1977 else if ( fwKeys & MK_MBUTTON ||
1978 ((fwKeys&MK_LBUTTON) &&
1979 (fwKeys&MK_RBUTTON) ) ){
1980 VT_ProcessControlButton2Motion();
1982 else if ( fwKeys & MK_RBUTTON ) {
1983 VT_ProcessControlButton3Motion();
1987 else if ( fwKeys & MK_SHIFT ) {
1988 if ( fwKeys & MK_MBUTTON ||
1989 ((fwKeys&MK_LBUTTON) &&
1990 (fwKeys&MK_RBUTTON) ) ) {
1991 cout << "ProcessZClipMotion()" << endl;
1992 ProcessZClipMotion();
1996 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
1998 if ((fwKeys & MK_MBUTTON
1999 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2001 ProcessZClipMotion();
2012 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2017 return DefWindowProc( hwnd, Msg, wParam, lParam );
2023 //==============================================================================
2024 //function : ViewerMainLoop
2025 //purpose : Get a Event on the view and dispatch it
2026 //==============================================================================
2029 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2031 Ppick = (argc > 0)? 1 : 0;
2039 cout << "Start picking" << endl;
2041 while ( Ppick == 1 ) {
2042 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2043 if (GetMessage(&msg, NULL, 0, 0) ) {
2044 TranslateMessage(&msg);
2045 DispatchMessage(&msg);
2049 cout << "Picking done" << endl;
2055 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2057 int min( int a, int b )
2065 int max( int a, int b )
2073 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2076 static XEvent aReport;
2077 Standard_Boolean pick = argc > 0;
2078 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2079 XNextEvent (aDisplay, &aReport);
2081 // Handle event for the chosen display connection
2082 switch (aReport.type) {
2085 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2088 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2094 // Activate inactive view
2095 Window aWindow = GetWindowHandle(VT_GetWindow());
2096 if(aWindow != aReport.xfocus.window)
2098 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2107 case ConfigureNotify:
2109 VT_ProcessConfigure();
2118 XComposeStatus status_in_out;
2120 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2121 (char *) buf_ret , 10 ,
2122 &ks_ret , &status_in_out ) ;
2125 buf_ret[ret_len] = '\0' ;
2129 VT_ProcessKeyPress (buf_ret);
2135 X_ButtonPress = aReport.xbutton.x;
2136 Y_ButtonPress = aReport.xbutton.y;
2138 if (aReport.xbutton.button == Button1)
2140 if (aReport.xbutton.state & ControlMask)
2142 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2146 IsDragged = Standard_True;
2147 DragFirst = Standard_True;
2150 else if (aReport.xbutton.button == Button3)
2153 VT_ProcessButton3Press();
2163 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2164 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2165 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2168 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2169 if( aContext.IsNull() )
2171 cout << "The context is null. Please use vinit before createmesh" << endl;
2175 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2176 if( aReport.xbutton.button==1 )
2180 aContext->ShiftSelect();
2189 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2190 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2191 ViewerTest::CurrentView());
2195 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2196 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2197 ViewerTest::CurrentView() );
2200 VT_ProcessButton3Release();
2202 IsDragged = Standard_False;
2205 VT_ProcessButton3Release();
2210 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2216 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2217 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2218 XSetFunction( aDisplay, gc, GXinvert );
2221 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2223 X_Motion = aReport.xmotion.x;
2224 Y_Motion = aReport.xmotion.y;
2225 DragFirst = Standard_False;
2227 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2231 X_Motion = aReport.xmotion.x;
2232 Y_Motion = aReport.xmotion.y;
2234 // remove all the ButtonMotionMaskr
2235 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2237 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2238 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2240 Quantity_Length VDX, VDY;
2242 ViewerTest::CurrentView()->Size(VDX,VDY);
2243 Standard_Real VDZ =0 ;
2244 VDZ = ViewerTest::CurrentView()->ZSize();
2246 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2248 Quantity_Length dx = 0 ;
2249 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2253 dx = dx / VDX * VDZ;
2257 ViewerTest::CurrentView()->Redraw();
2261 if ( aReport.xmotion.state & ControlMask ) {
2262 if ( aReport.xmotion.state & Button1Mask ) {
2263 ProcessControlButton1Motion();
2265 else if ( aReport.xmotion.state & Button2Mask ) {
2266 VT_ProcessControlButton2Motion();
2268 else if ( aReport.xmotion.state & Button3Mask ) {
2269 VT_ProcessControlButton3Motion();
2283 //==============================================================================
2284 //function : VProcessEvents
2285 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2286 // event in the Viewer window
2287 //==============================================================================
2289 static void VProcessEvents(ClientData,int)
2291 NCollection_Vector<int> anEventNumbers;
2292 // Get number of messages from every display
2293 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2294 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2296 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2298 // Handle events for every display
2299 int anEventIter = 0;
2300 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2301 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2303 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2304 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2306 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2307 int anEventResult = ViewerMainLoop( 0, NULL);
2308 // If window is closed or context was not found finish current event processing loop
2314 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2319 //==============================================================================
2320 //function : OSWindowSetup
2321 //purpose : Setup for the X11 window to be able to cath the event
2322 //==============================================================================
2325 static void OSWindowSetup()
2327 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2330 Window window = VT_GetWindow()->XWindow();
2331 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2332 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2333 XSynchronize(aDisplay, 1);
2335 // X11 : For keyboard on SUN
2337 wmhints.flags = InputHint;
2340 XSetWMHints( aDisplay, window, &wmhints);
2342 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2343 ButtonPressMask | ButtonReleaseMask |
2344 StructureNotifyMask |
2346 Button1MotionMask | Button2MotionMask |
2347 Button3MotionMask | FocusChangeMask
2349 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2350 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2352 XSynchronize(aDisplay, 0);
2361 //==============================================================================
2364 //purpose : Fitall, no DRAW arguments
2365 //Draw arg : No args
2366 //==============================================================================
2368 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2370 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2371 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2372 if (V.IsNull() == Standard_False) {
2374 } else if (aView.IsNull() == Standard_False) {
2380 //==============================================================================
2382 //purpose : ZFitall, no DRAW arguments
2383 //Draw arg : No args
2384 //==============================================================================
2386 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2388 Handle(V3d_View) V = ViewerTest::CurrentView();
2389 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2392 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2394 Handle(V3d_View) V = ViewerTest::CurrentView();
2395 if ( !V.IsNull() ) V->Redraw(); return 0;
2399 //==============================================================================
2401 //purpose : Remove all the object from the viewer
2402 //Draw arg : No args
2403 //==============================================================================
2405 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2407 Handle(V3d_View) V = ViewerTest::CurrentView();
2409 ViewerTest::Clear();
2413 //==============================================================================
2416 //==============================================================================
2418 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2419 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2422 di << argv[0] << "Invalid number of arguments" << "\n";
2426 while (ViewerMainLoop( argc, argv)) {
2432 //==============================================================================
2433 //function : InitViewerTest
2434 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2435 //==============================================================================
2437 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2439 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2440 ViewerTest::SetAISContext(theContext);
2441 aViewer->InitActiveViews();
2442 Handle(V3d_View) aView = aViewer->ActiveView();
2443 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2444 ViewerTest::ResetEventManager();
2445 Handle(Aspect_Window) aWindow = aView->Window();
2446 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2448 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2450 static int aFirst = 1;
2452 #if TCL_MAJOR_VERSION < 8
2453 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2454 TK_READABLE, VProcessEvents, (ClientData) 0);
2456 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2457 TK_READABLE, VProcessEvents, (ClientData) 0);
2464 //==============================================================================
2466 //purpose : Load image as background
2467 //==============================================================================
2469 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2471 if (argc < 2 || argc > 3)
2473 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2474 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2478 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2479 if(AISContext.IsNull())
2481 di << "use 'vinit' command before " << argv[0] << "\n";
2485 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2488 const char* szType = argv[2];
2489 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2490 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2491 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2492 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2495 di << "Wrong fill type : " << szType << "\n";
2496 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2501 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2502 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2507 //==============================================================================
2508 //function : VSetBgMode
2509 //purpose : Change background image fill type
2510 //==============================================================================
2512 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2516 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2517 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2521 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2522 if(AISContext.IsNull())
2524 di << "use 'vinit' command before " << argv[0] << "\n";
2527 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2528 const char* szType = argv[1];
2529 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2530 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2531 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2532 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2535 di << "Wrong fill type : " << szType << "\n";
2536 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2539 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2540 V3dView->SetBgImageStyle(aFillType, Standard_True);
2544 //==============================================================================
2545 //function : VSetGradientBg
2546 //purpose : Mount gradient background
2547 //==============================================================================
2548 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2552 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2553 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2554 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2555 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2559 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2560 if(AISContext.IsNull())
2562 di << "use 'vinit' command before " << argv[0] << "\n";
2568 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2569 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2570 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2571 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2573 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2574 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2575 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2577 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2578 int aType = Draw::Atoi(argv[7]);
2579 if( aType < 0 || aType > 8 )
2581 di << "Wrong fill type " << "\n";
2582 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2583 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2587 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2589 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2590 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2596 //==============================================================================
2597 //function : VSetGradientBgMode
2598 //purpose : Change gradient background fill style
2599 //==============================================================================
2600 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2604 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2605 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2606 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2610 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2611 if(AISContext.IsNull())
2613 di << "use 'vinit' command before " << argv[0] << "\n";
2618 int aType = Draw::Atoi(argv[1]);
2619 if( aType < 0 || aType > 8 )
2621 di << "Wrong fill type " << "\n";
2622 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2623 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2627 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2629 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2630 V3dView->SetBgGradientStyle( aMethod, 1 );
2636 //==============================================================================
2637 //function : VSetColorBg
2638 //purpose : Set color background
2639 //==============================================================================
2640 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2644 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2645 di << "R,G,B = [0..255]" << "\n";
2649 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2650 if(AISContext.IsNull())
2652 di << "use 'vinit' command before " << argv[0] << "\n";
2658 Standard_Real R = Draw::Atof(argv[1])/255.;
2659 Standard_Real G = Draw::Atof(argv[2])/255.;
2660 Standard_Real B = Draw::Atof(argv[3])/255.;
2661 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2663 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2664 V3dView->SetBackgroundColor( aColor );
2671 //==============================================================================
2673 //purpose : View Scaling
2674 //==============================================================================
2676 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2678 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2679 if ( V3dView.IsNull() ) return 1;
2682 di << argv[0] << "Invalid number of arguments" << "\n";
2685 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2688 //==============================================================================
2689 //function : VTestZBuffTrihedron
2690 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2691 //==============================================================================
2693 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2695 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2696 if ( V3dView.IsNull() ) return 1;
2698 V3dView->ZBufferTriedronSetup();
2701 // Set up default trihedron parameters
2702 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2706 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2707 const char* aPosType = argv[1];
2709 if ( strcmp(aPosType, "center") == 0 )
2711 aPosition = Aspect_TOTP_CENTER;
2713 if (strcmp(aPosType, "left_lower") == 0)
2715 aPosition = Aspect_TOTP_LEFT_LOWER;
2717 if (strcmp(aPosType, "left_upper") == 0)
2719 aPosition = Aspect_TOTP_LEFT_UPPER;
2721 if (strcmp(aPosType, "right_lower") == 0)
2723 aPosition = Aspect_TOTP_RIGHT_LOWER;
2725 if (strcmp(aPosType, "right_upper") == 0)
2727 aPosition = Aspect_TOTP_RIGHT_UPPER;
2730 di << argv[1] << " Invalid type of alignment" << "\n";
2731 di << "Must be one of [ center, left_lower," << "\n";
2732 di << "left_upper, right_lower, right_upper ]" << "\n";
2736 Standard_Real R = Draw::Atof(argv[2])/255.;
2737 Standard_Real G = Draw::Atof(argv[3])/255.;
2738 Standard_Real B = Draw::Atof(argv[4])/255.;
2739 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2741 Standard_Real aScale = Draw::Atof(argv[5]);
2745 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2749 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2750 const char* aPresType = argv[6];
2752 if ( strcmp(aPresType, "wireframe") == 0 )
2754 aPresentation = V3d_WIREFRAME;
2756 if (strcmp(aPresType, "zbuffer") == 0)
2758 aPresentation = V3d_ZBUFFER;
2761 di << argv[6] << " Invalid type of visualization" << "\n";
2762 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2766 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2770 di << argv[0] << " Invalid number of arguments" << "\n";
2779 //==============================================================================
2780 //function : VRotate
2781 //purpose : Camera Rotating
2782 //==============================================================================
2784 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2785 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2786 if ( V3dView.IsNull() ) {
2791 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2793 } else if ( argc == 7 ) {
2794 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]) );
2797 di << argv[0] << " Invalid number of arguments" << "\n";
2802 //==============================================================================
2804 //purpose : View zoom in / out (relative to current zoom)
2805 //==============================================================================
2807 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2808 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2809 if ( V3dView.IsNull() ) {
2814 Standard_Real coef = Draw::Atof(argv[1]);
2815 if ( coef <= 0.0 ) {
2816 di << argv[1] << "Invalid value" << "\n";
2819 V3dView->SetZoom( Draw::Atof(argv[1]) );
2822 di << argv[0] << " Invalid number of arguments" << "\n";
2827 //==============================================================================
2829 //purpose : View panning (in pixels)
2830 //==============================================================================
2832 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2833 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2834 if ( V3dView.IsNull() ) return 1;
2837 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2840 di << argv[0] << " Invalid number of arguments" << "\n";
2846 //==============================================================================
2847 //function : VExport
2848 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2849 //==============================================================================
2851 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2853 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2854 if (V3dView.IsNull())
2859 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2863 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2864 TCollection_AsciiString aFormatStr;
2866 TCollection_AsciiString aFileName (argv[1]);
2867 Standard_Integer aLen = aFileName.Length();
2871 aFormatStr = TCollection_AsciiString (argv[2]);
2875 if (aFileName.Value (aLen - 2) == '.')
2877 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2879 else if (aFileName.Value (aLen - 3) == '.')
2881 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2885 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2891 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2895 aFormatStr.UpperCase();
2896 if (aFormatStr == "PS")
2897 anExpFormat = Graphic3d_EF_PostScript;
2898 else if (aFormatStr == "EPS")
2899 anExpFormat = Graphic3d_EF_EnhPostScript;
2900 else if (aFormatStr == "TEX")
2901 anExpFormat = Graphic3d_EF_TEX;
2902 else if (aFormatStr == "PDF")
2903 anExpFormat = Graphic3d_EF_PDF;
2904 else if (aFormatStr == "SVG")
2905 anExpFormat = Graphic3d_EF_SVG;
2906 else if (aFormatStr == "PGF")
2907 anExpFormat = Graphic3d_EF_PGF;
2908 else if (aFormatStr == "EMF")
2909 anExpFormat = Graphic3d_EF_EMF;
2912 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2917 if (!V3dView->View()->Export (argv[1], anExpFormat))
2919 di << "Error: export of image to " << aFormatStr << " failed!\n";
2922 catch (Standard_Failure)
2924 di << "Error: export of image to " << aFormatStr << " failed";
2925 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2930 //==============================================================================
2931 //function : VColorScale
2932 //purpose : representation color scale
2933 //==============================================================================
2934 #include <V3d_ColorScale.hxx>
2936 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2938 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2940 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2944 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2945 if(aContext.IsNull()) {
2946 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2950 Standard_Real minRange = 0. , maxRange = 100. ;
2952 Standard_Integer numIntervals = 10 ;
2953 Standard_Integer textHeight = 16;
2954 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2955 Standard_Real X = 0., Y = 0. ;
2961 minRange = Draw::Atof( argv[1] );
2962 maxRange = Draw::Atof( argv[2] );
2963 numIntervals = Draw::Atoi( argv[3] );
2966 textHeight = Draw::Atoi( argv[4] );
2968 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2971 X = Draw::Atof( argv[6] );
2972 Y = Draw::Atof( argv[7] );
2975 Handle(V3d_View) curView = ViewerTest::CurrentView( );
2976 if ( curView.IsNull( ) )
2978 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2979 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2980 if( ! aCS.IsNull( ) )
2982 aCS->SetPosition( X , Y );
2983 aCS->SetHeight( 0.95) ;
2984 aCS->SetTextHeight( textHeight );
2985 aCS->SetRange( minRange , maxRange );
2986 aCS->SetNumberOfIntervals( numIntervals );
2987 aCS->SetLabelPosition( position );
2988 if( !curView->ColorScaleIsDisplayed() )
2989 curView->ColorScaleDisplay( );
2994 //==============================================================================
2995 //function : VGraduatedTrihedron
2996 //purpose : Displays a graduated trihedron
2997 //==============================================================================
2999 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3001 const char *str = arg;
3004 unsigned short c1 = *str++;
3005 unsigned short c2 = *str++;
3006 if (!c1 || !c2) break;
3007 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3011 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3014 if (argc != 2 && argc < 5)
3016 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3017 di<<"Usage: type help "<<argv[0]<<"\n";
3018 return 1; //TCL_ERROR
3021 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3023 // Create 3D view if it doesn't exist
3024 if ( aV3dView.IsNull() )
3026 ViewerTest::ViewerInit();
3027 aV3dView = ViewerTest::CurrentView();
3028 if( aV3dView.IsNull() )
3030 di << "Error: Cannot create a 3D view\n";
3031 return 1; //TCL_ERROR
3035 // Erase (==0) or display (!=0)
3036 const int display = Draw::Atoi(argv[1]);
3041 TCollection_AsciiString font;
3043 font.AssignCat("Courier");
3045 font.AssignCat(argv[5]);
3047 // Text is multibyte
3048 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3051 TCollection_ExtendedString xname, yname, zname;
3056 AddMultibyteString(xname, argv[2]);
3057 AddMultibyteString(yname, argv[3]);
3058 AddMultibyteString(zname, argv[4]);
3074 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3075 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3076 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3077 Standard_True/*drawgrid*/,
3078 Standard_True/*drawaxes*/,
3079 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3080 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3081 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3082 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3083 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3084 Quantity_NOC_WHITE/*gridcolor*/,
3085 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3086 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3089 aV3dView->GraduatedTrihedronErase();
3091 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3097 //==============================================================================
3098 //function : VPrintView
3099 //purpose : Test printing algorithm, print the view to image file with given
3100 // width and height. Printing implemented only for WNT.
3101 //==============================================================================
3102 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3106 di << "Printing implemented only for wnt!\n";
3110 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3111 Handle(V3d_View) aView = NULL;
3112 aContextAIS = ViewerTest::GetAISContext();
3113 if (!aContextAIS.IsNull())
3115 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3116 Vwr->InitActiveViews();
3117 if(Vwr->MoreActiveViews())
3118 aView = Vwr->ActiveView();
3124 di << "Call vinit before!\n";
3129 di << "Use: " << argv[0];
3130 di << " width height filename [print algo=0]\n";
3131 di << "width, height of the intermediate buffer for operation\n";
3132 di << "algo : {0|1}\n";
3133 di << " 0 - stretch algorithm\n";
3134 di << " 1 - tile algorithm\n";
3135 di << "test printing algorithms into an intermediate buffer\n";
3136 di << "with saving output to an image file\n";
3140 // get the input params
3141 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3142 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3143 Standard_Integer aMode = 0;
3144 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3146 aMode = Draw::Atoi (argv[4]);
3148 // check the input parameters
3149 if (aWidth <= 0 || aHeight <= 0)
3151 di << "Width and height must be positive values!\n";
3154 if (aMode != 0 && aMode != 1)
3157 // define compatible bitmap
3158 HDC anDC = CreateCompatibleDC(0);
3159 BITMAPINFO aBitmapData;
3160 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3161 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3162 aBitmapData.bmiHeader.biWidth = aWidth ;
3163 aBitmapData.bmiHeader.biHeight = aHeight;
3164 aBitmapData.bmiHeader.biPlanes = 1;
3165 aBitmapData.bmiHeader.biBitCount = 24;
3166 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3167 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3168 aBitmapData.bmiHeader.biClrUsed = 0;
3169 aBitmapData.bmiHeader.biClrImportant = 0;
3170 aBitmapData.bmiHeader.biCompression = BI_RGB;
3171 aBitmapData.bmiHeader.biSizeImage = 0;
3173 // Create Device Independent Bitmap
3174 void* aBitsOut = NULL;
3175 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3176 &aBitsOut, NULL, 0);
3177 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3179 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3180 if (aBitsOut != NULL)
3183 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3185 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3187 // succesfully printed into an intermediate buffer
3190 Image_PixMap aWrapper;
3191 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3192 aWrapper.SetTopDown (false);
3194 Image_AlienPixMap anImageBitmap;
3195 anImageBitmap.InitCopy (aWrapper);
3196 isSaved = anImageBitmap.Save (aFileName);
3200 di << "Print operation failed due to printing errors or\n";
3201 di << "insufficient memory available\n";
3202 di << "Please, try to use smaller dimensions for this test\n";
3203 di << "command, as it allocates intermediate buffer for storing\n";
3204 di << "the result\n";
3209 di << "Can't allocate memory for intermediate buffer\n";
3210 di << "Please use smaller dimensions\n";
3215 SelectObject (anDC, anOldBitmap);
3216 DeleteObject (aMemoryBitmap);
3222 di << "Save to file operation failed. This operation may fail\n";
3223 di << "if you don't have enough available memory, then you can\n";
3224 di << "use smaller dimensions for the output file\n";
3233 //==============================================================================
3234 //function : VZLayer
3235 //purpose : Test z layer operations for v3d viewer
3236 //==============================================================================
3237 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3239 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3240 if (aContextAIS.IsNull())
3242 di << "Call vinit before!\n";
3247 di << "Use: vzlayer " << argv[0];
3248 di << " add/del/get [id]\n";
3249 di << " add - add new z layer to viewer and print its id\n";
3250 di << " del - del z layer by its id\n";
3251 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3252 di << "id - the layer identificator value defined when removing z layer\n";
3256 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3257 if (aViewer.IsNull())
3259 di << "No active viewer!\n";
3263 // perform operation
3264 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3267 Standard_Integer aNewId;
3268 if (!aViewer->AddZLayer (aNewId))
3270 di << "Impossible to add new z layer!\n";
3274 di << "New z layer added with index: " << aNewId << "\n";
3276 else if (anOp == "del")
3280 di << "Please also provide as argument id of z layer to remove\n";
3284 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3285 if (!aViewer->RemoveZLayer (aDelId))
3287 di << "Impossible to remove the z layer or invalid id!\n";
3291 di << "Z layer " << aDelId << " has been removed\n";
3293 else if (anOp == "get")
3295 TColStd_SequenceOfInteger anIds;
3296 aViewer->GetAllZLayers (anIds);
3297 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3299 di << anIds.Value (aSeqIdx) << " ";
3306 di << "Invalid operation, please use { add / del / get }\n";
3313 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3315 // this class provides a presentation of text item in v3d view under-/overlayer
3316 class V3d_TextItem : public Visual3d_LayerItem
3321 DEFINE_STANDARD_RTTI(V3d_TextItem)
3324 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3325 const Standard_Real theX1,
3326 const Standard_Real theY1,
3327 const Standard_Real theHeight,
3328 const TCollection_AsciiString& theFontName,
3329 const Quantity_Color& theColor,
3330 const Quantity_Color& theSubtitleColor,
3331 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3332 const Handle(Visual3d_Layer)& theLayer);
3335 Standard_EXPORT void RedrawLayerPrs();
3341 TCollection_AsciiString myText;
3342 Standard_Real myHeight;
3343 Handle(Visual3d_Layer) myLayer;
3344 Quantity_Color myColor;
3345 Quantity_Color mySubtitleColor;
3346 Aspect_TypeOfDisplayText myType;
3347 TCollection_AsciiString myFontName;
3350 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3351 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3353 // create and add to display the text item
3354 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3355 const Standard_Real theX1,
3356 const Standard_Real theY1,
3357 const Standard_Real theHeight,
3358 const TCollection_AsciiString& theFontName,
3359 const Quantity_Color& theColor,
3360 const Quantity_Color& theSubtitleColor,
3361 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3362 const Handle(Visual3d_Layer)& theLayer)
3363 : myX1 (theX1), myY1 (theY1),
3365 myHeight (theHeight),
3368 mySubtitleColor (theSubtitleColor),
3369 myType (theTypeOfDisplay),
3370 myFontName (theFontName)
3372 if (!myLayer.IsNull ())
3373 myLayer->AddLayerItem (this);
3377 void V3d_TextItem::RedrawLayerPrs ()
3379 if (myLayer.IsNull ())
3382 myLayer->SetColor (myColor);
3383 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3384 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3387 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3389 // The Visual3d_LayerItem line item for "vlayerline" command
3390 // it provides a presentation of line with user-defined
3391 // linewidth, linetype and transparency.
3392 class V3d_LineItem : public Visual3d_LayerItem
3396 DEFINE_STANDARD_RTTI(V3d_LineItem)
3399 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3400 Standard_Real X2, Standard_Real Y2,
3401 V3d_LayerMgrPointer theLayerMgr,
3402 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3403 Standard_Real theWidth = 0.5,
3404 Standard_Real theTransp = 1.0);
3407 Standard_EXPORT void RedrawLayerPrs();
3411 Standard_Real myX1, myY1, myX2, myY2;
3412 V3d_LayerMgrPointer myLayerMgr;
3413 Aspect_TypeOfLine myType;
3414 Standard_Real myWidth;
3415 Standard_Real myTransparency;
3418 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3419 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3421 // default constructor for line item
3422 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3423 Standard_Real X2, Standard_Real Y2,
3424 V3d_LayerMgrPointer theLayerMgr,
3425 Aspect_TypeOfLine theType,
3426 Standard_Real theWidth,
3427 Standard_Real theTransp) :
3428 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3429 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3431 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3432 myLayerMgr->Overlay()->AddLayerItem (this);
3436 void V3d_LineItem::RedrawLayerPrs ()
3438 Handle (Visual3d_Layer) aOverlay;
3441 aOverlay = myLayerMgr->Overlay();
3443 if (!aOverlay.IsNull())
3445 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3446 aOverlay->SetColor(aColor);
3447 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3448 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3449 aOverlay->BeginPolyline();
3450 aOverlay->AddVertex(myX1, myY1);
3451 aOverlay->AddVertex(myX2, myY2);
3452 aOverlay->ClosePrimitive();
3456 //=============================================================================
3457 //function : VLayerLine
3458 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3459 // : linewidth, transparency coefficient
3460 //============================================================================
3461 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3463 // get the active view
3464 Handle(V3d_View) aView = ViewerTest::CurrentView();
3467 di << "Call vinit before!\n";
3472 di << "Use: " << argv[0];
3473 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3474 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3475 di << " 0 - solid \n";
3476 di << " 1 - dashed \n";
3477 di << " 2 - dot \n";
3478 di << " 3 - dashdot\n";
3479 di << " transparency : { 0.0 - 1.0 } \n";
3480 di << " 0.0 - transparent\n";
3481 di << " 1.0 - visible \n";
3485 // get the input params
3486 Standard_Real X1 = Draw::Atof(argv[1]);
3487 Standard_Real Y1 = Draw::Atof(argv[2]);
3488 Standard_Real X2 = Draw::Atof(argv[3]);
3489 Standard_Real Y2 = Draw::Atof(argv[4]);
3491 Standard_Real aWidth = 0.5;
3492 Standard_Integer aType = 0;
3493 Standard_Real aTransparency = 1.0;
3497 aWidth = Draw::Atof(argv[5]);
3501 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3506 aTransparency = Draw::Atof(argv[7]);
3507 if (aTransparency < 0 || aTransparency > 1.0)
3508 aTransparency = 1.0;
3511 // select appropriate line type
3512 Aspect_TypeOfLine aLineType;
3516 aLineType = Aspect_TOL_DASH;
3520 aLineType = Aspect_TOL_DOT;
3524 aLineType = Aspect_TOL_DOTDASH;
3528 aLineType = Aspect_TOL_SOLID;
3531 // replace layer manager
3532 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3533 aView->SetLayerMgr(aMgr);
3536 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3542 aView->MustBeResized();
3548 //=======================================================================
3549 //function : VOverlayText
3550 //purpose : Test text displaying in view overlay
3551 //=======================================================================
3552 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3554 // get the active view
3555 Handle(V3d_View) aView = ViewerTest::CurrentView();
3558 di << "No active view. Please call vinit.\n";
3561 else if (argc < 4 || argc > 13)
3563 di << "Use: " << argv[0];
3564 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3565 di << "[background_color: R G B]\n";
3566 di << " height - pixel height of the text (default=10.0)\n";
3567 di << " font_name - name of font (default=courier)\n";
3568 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3569 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
3570 di << " background_color- R G B values used for subtitle and decal text\n";
3571 di << "(default=255.0 255.0 255.0)\n";
3575 TCollection_AsciiString aText (argv[1]);
3576 Standard_Real aPosX = Draw::Atof(argv[2]);
3577 Standard_Real aPosY = Draw::Atof(argv[3]);
3578 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3581 TCollection_AsciiString aFontName = "Courier";
3583 aFontName = TCollection_AsciiString (argv[5]);
3586 Quantity_Parameter aColorRed = 1.0;
3587 Quantity_Parameter aColorGreen = 1.0;
3588 Quantity_Parameter aColorBlue = 1.0;
3591 aColorRed = Draw::Atof (argv[6])/255.;
3592 aColorGreen = Draw::Atof (argv[7])/255.;
3593 aColorBlue = Draw::Atof (argv[8])/255.;
3597 TCollection_AsciiString aDispStr;
3599 aDispStr = TCollection_AsciiString (argv[9]);
3601 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3602 if (aDispStr.IsEqual ("subtitle"))
3603 aTextType = Aspect_TODT_SUBTITLE;
3604 else if (aDispStr.IsEqual ("decal"))
3605 aTextType = Aspect_TODT_DEKALE;
3606 else if (aDispStr.IsEqual ("blend"))
3607 aTextType = Aspect_TODT_BLEND;
3610 Quantity_Parameter aSubRed = 1.0;
3611 Quantity_Parameter aSubGreen = 1.0;
3612 Quantity_Parameter aSubBlue = 1.0;
3615 aSubRed = Draw::Atof (argv[10])/255.;
3616 aSubGreen = Draw::Atof (argv[11])/255.;
3617 aSubBlue = Draw::Atof (argv[12])/255.;
3620 // check fo current overlay
3621 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3622 if (anOverlay.IsNull ())
3624 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3625 anOverlay = aMgr->Overlay ();
3626 aView->SetLayerMgr (aMgr);
3629 Quantity_Color aTextColor (aColorRed, aColorGreen,
3630 aColorBlue, Quantity_TOC_RGB);
3631 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3632 aSubBlue, Quantity_TOC_RGB);
3635 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3636 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3639 aView->MustBeResized();
3645 //==============================================================================
3648 //==============================================================================
3650 static int VGrid (Draw_Interpretor& /*theDI*/,
3651 Standard_Integer theArgNb,
3652 const char** theArgVec)
3654 // get the active view
3655 Handle(V3d_View) aView = ViewerTest::CurrentView();
3656 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3657 if (aView.IsNull() || aViewer.IsNull())
3659 std::cerr << "No active view. Please call vinit.\n";
3663 Aspect_GridType aType = aViewer->GridType();
3664 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3666 Standard_Integer anIter = 1;
3667 for (; anIter < theArgNb; ++anIter)
3669 const char* aValue = theArgVec[anIter];
3672 aType = Aspect_GT_Rectangular;
3674 else if (*aValue == 'c')
3676 aType = Aspect_GT_Circular;
3678 else if (*aValue == 'l')
3680 aMode = Aspect_GDM_Lines;
3682 else if (*aValue == 'p')
3684 aMode = Aspect_GDM_Points;
3686 else if (strcmp (aValue, "off" ) == 0)
3688 aViewer->DeactivateGrid();
3697 Standard_Integer aTail = (theArgNb - anIter);
3700 aViewer->ActivateGrid (aType, aMode);
3703 else if (aTail != 2 && aTail != 5)
3705 std::cerr << "Incorrect arguments number! Usage:\n"
3706 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3710 Quantity_Length anOriginX, anOriginY;
3711 Quantity_PlaneAngle aRotAngle;
3712 if (aType == Aspect_GT_Rectangular)
3714 Quantity_Length aRStepX, aRStepY;
3715 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3717 anOriginX = Draw::Atof (theArgVec[anIter++]);
3718 anOriginY = Draw::Atof (theArgVec[anIter++]);
3721 aRStepX = Draw::Atof (theArgVec[anIter++]);
3722 aRStepY = Draw::Atof (theArgVec[anIter++]);
3723 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3725 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3726 aViewer->ActivateGrid (aType, aMode);
3728 else if (aType == Aspect_GT_Circular)
3730 Quantity_Length aRadiusStep;
3731 Standard_Integer aDivisionNumber;
3732 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3734 anOriginX = Draw::Atof (theArgVec[anIter++]);
3735 anOriginY = Draw::Atof (theArgVec[anIter++]);
3738 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3739 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3740 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3743 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3744 aViewer->ActivateGrid (aType, aMode);
3750 //==============================================================================
3753 //==============================================================================
3755 static int VFps (Draw_Interpretor& theDI,
3756 Standard_Integer theArgNb,
3757 const char** theArgVec)
3759 // get the active view
3760 Handle(V3d_View) aView = ViewerTest::CurrentView();
3763 std::cerr << "No active view. Please call vinit.\n";
3767 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3770 std::cerr << "Incorrect arguments!\n";
3774 // the time is meaningless for first call
3775 // due to async OpenGl rendering
3778 // redraw view in loop to estimate average values
3781 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3787 const Standard_Real aTime = aTimer.ElapsedTime();
3788 aTimer.OSD_Chronometer::Show (aCpu);
3790 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3791 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3793 // return statistics
3794 theDI << "FPS: " << aFpsAver << "\n"
3795 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3800 //==============================================================================
3801 //function : VGlDebug
3803 //==============================================================================
3805 static int VGlDebug (Draw_Interpretor& theDI,
3806 Standard_Integer theArgNb,
3807 const char** theArgVec)
3811 Handle(V3d_View) aView = ViewerTest::CurrentView();
3814 std::cerr << "No active view. Please call vinit.\n";
3818 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3819 "GL_ARB_debug_output");
3820 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3821 theDI << (isActive ? "1" : "0");
3825 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3829 //==============================================================================
3832 //==============================================================================
3834 static int VVbo (Draw_Interpretor& theDI,
3835 Standard_Integer theArgNb,
3836 const char** theArgVec)
3838 const Standard_Boolean toSet = (theArgNb > 1);
3839 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3842 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
3846 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3847 if (aContextAIS.IsNull())
3851 std::cerr << "No active view!\n";
3855 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3856 if (!aDriver.IsNull())
3860 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3864 aDriver->ChangeOptions().vboDisable = toUseVbo;
3871 //==============================================================================
3874 //==============================================================================
3876 static int VCaps (Draw_Interpretor& theDI,
3877 Standard_Integer theArgNb,
3878 const char** theArgVec)
3880 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
3881 Handle(OpenGl_GraphicDriver) aDriver;
3882 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3883 if (!aContextAIS.IsNull())
3885 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3886 aCaps = &aDriver->ChangeOptions();
3891 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
3892 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
3893 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
3897 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3899 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
3900 if (anArg.Search ("vbo=") > -1)
3902 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3904 else if (anArg.Search ("sprites=") > -1)
3906 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3908 else if (anArg.Search ("soft=") > -1)
3910 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
3914 std::cerr << "Unknown argument: " << anArg << "\n";
3917 if (aCaps != &ViewerTest_myDefaultCaps)
3919 ViewerTest_myDefaultCaps = *aCaps;
3924 //==============================================================================
3925 //function : VMemGpu
3927 //==============================================================================
3929 static int VMemGpu (Draw_Interpretor& theDI,
3930 Standard_Integer theArgNb,
3931 const char** theArgVec)
3934 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3935 if (aContextAIS.IsNull())
3937 std::cerr << "No active view. Please call vinit.\n";
3941 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3942 if (aDriver.IsNull())
3944 std::cerr << "Graphic driver not available.\n";
3948 Standard_Size aFreeBytes = 0;
3949 TCollection_AsciiString anInfo;
3950 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3952 std::cerr << "Information not available.\n";
3956 if (theArgNb > 1 && *theArgVec[1] == 'f')
3958 theDI << Standard_Real (aFreeBytes);
3968 // ==============================================================================
3969 // function : VReadPixel
3971 // ==============================================================================
3972 static int VReadPixel (Draw_Interpretor& theDI,
3973 Standard_Integer theArgNb,
3974 const char** theArgVec)
3976 // get the active view
3977 Handle(V3d_View) aView = ViewerTest::CurrentView();
3980 std::cerr << "No active view. Please call vinit.\n";
3983 else if (theArgNb < 3)
3985 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
3989 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3990 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
3992 Standard_Integer aWidth, aHeight;
3993 aView->Window()->Size (aWidth, aHeight);
3994 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
3995 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
3996 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
3998 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4002 Standard_Boolean toShowName = Standard_False;
4003 Standard_Boolean toShowHls = Standard_False;
4004 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4006 const char* aParam = theArgVec[anIter];
4007 if ( strcasecmp( aParam, "rgb" ) == 0 )
4009 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4010 aBufferType = Graphic3d_BT_RGB;
4012 else if ( strcasecmp( aParam, "hls" ) == 0 )
4014 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4015 aBufferType = Graphic3d_BT_RGB;
4016 toShowHls = Standard_True;
4018 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4020 aFormat = Image_PixMap::ImgRGBF;
4021 aBufferType = Graphic3d_BT_RGB;
4023 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4025 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4026 aBufferType = Graphic3d_BT_RGBA;
4028 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4030 aFormat = Image_PixMap::ImgRGBAF;
4031 aBufferType = Graphic3d_BT_RGBA;
4033 else if ( strcasecmp( aParam, "depth" ) == 0 )
4035 aFormat = Image_PixMap::ImgGrayF;
4036 aBufferType = Graphic3d_BT_Depth;
4038 else if ( strcasecmp( aParam, "name" ) == 0 )
4040 toShowName = Standard_True;
4044 Image_PixMap anImage;
4045 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4047 std::cerr << "Image allocation failed\n";
4050 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4052 std::cerr << "Image dump failed\n";
4056 Quantity_Parameter anAlpha;
4057 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4060 if (aBufferType == Graphic3d_BT_RGBA)
4062 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
4066 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
4071 switch (aBufferType)
4074 case Graphic3d_BT_RGB:
4078 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
4082 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
4086 case Graphic3d_BT_RGBA:
4088 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
4091 case Graphic3d_BT_Depth:
4093 theDI << aColor.Red() << "\n";
4102 //==============================================================================
4103 //function : VDiffImage
4104 //purpose : The draw-command compares two images.
4105 //==============================================================================
4107 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4111 theDI << "Not enough arguments.\n";
4116 const char* anImgPathRef = theArgVec[1];
4117 const char* anImgPathNew = theArgVec[2];
4119 // get string tolerance and check its validity
4120 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4121 if (aTolColor < 0.0)
4123 if (aTolColor > 1.0)
4126 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4127 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4129 // image file of difference
4130 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4132 // compare the images
4133 Image_Diff aComparer;
4134 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4139 aComparer.SetColorTolerance (aTolColor);
4140 aComparer.SetBorderFilterOn (isBorderFilterOn);
4141 Standard_Integer aDiffColorsNb = aComparer.Compare();
4142 theDI << aDiffColorsNb << "\n";
4144 // save image of difference
4145 if (aDiffImagePath != NULL)
4147 aComparer.SaveDiffImage (aDiffImagePath);
4153 //=======================================================================
4154 //function : VSelect
4155 //purpose : Emulates different types of selection by mouse:
4156 // 1) single click selection
4157 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4158 // 3) selection with polygon having corners at
4159 // pixel positions (x1,y1),...,(xn,yn)
4160 // 4) any of these selections with shift button pressed
4161 //=======================================================================
4162 static Standard_Integer VSelect (Draw_Interpretor& di,
4163 Standard_Integer argc,
4168 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4172 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4173 if(myAIScontext.IsNull())
4175 di << "use 'vinit' command before " << argv[0] << "\n";
4178 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4179 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4180 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4183 if(isShiftSelection)
4184 aCurrentEventManager->ShiftSelect();
4186 aCurrentEventManager->Select();
4190 if(isShiftSelection)
4191 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4193 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4197 Standard_Integer anUpper = 0;
4199 if(isShiftSelection)
4200 anUpper = (argc-1)/2;
4203 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4205 for(Standard_Integer i=1;i<=anUpper;++i)
4206 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4208 if(isShiftSelection)
4209 aCurrentEventManager->ShiftSelect(aPolyline);
4211 aCurrentEventManager->Select(aPolyline);
4216 //=======================================================================
4217 //function : VMoveTo
4218 //purpose : Emulates cursor movement to defined pixel position
4219 //=======================================================================
4220 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4221 Standard_Integer argc,
4226 di << "Usage : " << argv[0] << " x y" << "\n";
4230 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4231 if(aContext.IsNull())
4233 di << "use 'vinit' command before " << argv[0] << "\n";
4236 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4240 //=======================================================================
4241 //function : VViewParams
4242 //purpose : Gets or sets AIS View characteristics
4243 //=======================================================================
4244 static Standard_Integer VViewParams (Draw_Interpretor& di,
4245 Standard_Integer argc,
4248 if ( argc != 1 && argc != 13)
4250 di << "Usage : " << argv[0] << "\n";
4253 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
4254 if ( anAISView.IsNull () )
4256 di << "use 'vinit' command before " << argv[0] << "\n";
4260 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
4261 Standard_Real anAISViewCenterCoordinateX = 0.0;
4262 Standard_Real anAISViewCenterCoordinateY = 0.0;
4263 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4264 Standard_Real anAISViewProjX = 0.0;
4265 Standard_Real anAISViewProjY = 0.0;
4266 Standard_Real anAISViewProjZ = 0.0;
4267 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4268 Standard_Real anAISViewUpX = 0.0;
4269 Standard_Real anAISViewUpY = 0.0;
4270 Standard_Real anAISViewUpZ = 0.0;
4271 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4272 Standard_Real anAISViewAtX = 0.0;
4273 Standard_Real anAISViewAtY = 0.0;
4274 Standard_Real anAISViewAtZ = 0.0;
4275 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4276 di << "Scale of current view: " << anAISViewScale << "\n";
4277 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
4278 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4279 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4280 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4284 Quantity_Factor anAISViewScale = atof (argv [1]);
4285 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
4286 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
4287 Standard_Real anAISViewProjX = atof (argv [4]);
4288 Standard_Real anAISViewProjY = atof (argv [5]);
4289 Standard_Real anAISViewProjZ = atof (argv [6]);
4290 Standard_Real anAISViewUpX = atof (argv [7]);
4291 Standard_Real anAISViewUpY = atof (argv [8]);
4292 Standard_Real anAISViewUpZ = atof (argv [9]);
4293 Standard_Real anAISViewAtX = atof (argv [10]);
4294 Standard_Real anAISViewAtY = atof (argv [11]);
4295 Standard_Real anAISViewAtZ = atof (argv [12]);
4296 anAISView -> V3d_View::SetScale (anAISViewScale);
4297 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4298 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4299 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4300 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4305 //=======================================================================
4306 //function : VChangeSelected
4307 //purpose : Adds the shape to selection or remove one from it
4308 //=======================================================================
4309 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4310 Standard_Integer argc,
4315 di<<"Usage : " << argv[0] << " shape \n";
4319 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4320 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4321 TCollection_AsciiString aName(argv[1]);
4322 Handle(AIS_InteractiveObject) anAISObject;
4324 if(!aMap.IsBound2(aName))
4326 di<<"Use 'vdisplay' before";
4331 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4332 if(anAISObject.IsNull()){
4333 di<<"No interactive object \n";
4337 if(aContext->HasOpenedContext())
4339 aContext->AddOrRemoveSelected(anAISObject);
4343 aContext->AddOrRemoveCurrentObject(anAISObject);
4349 //=======================================================================
4350 //function : VZClipping
4351 //purpose : Gets or sets ZClipping mode, width and depth
4352 //=======================================================================
4353 static Standard_Integer VZClipping (Draw_Interpretor& di,
4354 Standard_Integer argc,
4359 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4360 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4363 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4364 if(aContext.IsNull())
4366 di << "use 'vinit' command before " << argv[0] << "\n";
4369 Handle(V3d_View) aView = ViewerTest::CurrentView();
4370 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4373 TCollection_AsciiString aZClippingModeString;
4374 Quantity_Length aDepth, aWidth;
4375 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4376 switch (aZClippingMode)
4379 aZClippingModeString.Copy("OFF");
4382 aZClippingModeString.Copy("BACK");
4385 aZClippingModeString.Copy("FRONT");
4388 aZClippingModeString.Copy("SLICE");
4391 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4394 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4395 << "ZClipping depth = " << aDepth << "\n"
4396 << "ZClipping width = " << aWidth << "\n";
4402 Standard_Integer aStatus = 0;
4403 if ( strcmp (argv [1], "OFF") == 0 ) {
4405 aZClippingMode = V3d_OFF;
4407 if ( strcmp (argv [1], "BACK") == 0 ) {
4409 aZClippingMode = V3d_BACK;
4411 if ( strcmp (argv [1], "FRONT") == 0 ) {
4413 aZClippingMode = V3d_FRONT;
4415 if ( strcmp (argv [1], "SLICE") == 0 ) {
4417 aZClippingMode = V3d_SLICE;
4421 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4422 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4425 aView->SetZClippingType(aZClippingMode);
4429 Quantity_Length aDepth = 0., aWidth = 1.;
4432 aDepth = atof(argv[1]);
4433 aWidth = atof(argv[2]);
4437 aDepth = atof(argv[2]);
4438 aWidth = atof(argv[3]);
4441 if(aDepth<0. || aDepth>1.)
4443 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4444 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4447 if(aWidth<0. || aWidth>1.)
4449 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4450 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4454 aView->SetZClippingDepth(aDepth);
4455 aView->SetZClippingWidth(aWidth);
4462 //=======================================================================
4463 //function : VNbSelected
4464 //purpose : Returns number of selected objects
4465 //=======================================================================
4466 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4467 Standard_Integer argc,
4472 di << "Usage : " << argv[0] << "\n";
4475 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4476 if(aContext.IsNull())
4478 di << "use 'vinit' command before " << argv[0] << "\n";
4481 di << aContext->NbSelected() << "\n";
4485 //=======================================================================
4486 //function : VAntialiasing
4487 //purpose : Switches altialiasing on or off
4488 //=======================================================================
4489 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4490 Standard_Integer argc,
4495 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4499 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4500 if(aContext.IsNull())
4502 di << "use 'vinit' command before " << argv[0] << "\n";
4506 Handle(V3d_View) aView = ViewerTest::CurrentView();
4508 if((argc == 2) && (atof(argv[1]) == 0))
4509 aView->SetAntialiasingOff();
4511 aView->SetAntialiasingOn();
4516 //=======================================================================
4517 //function : VPurgeDisplay
4518 //purpose : Switches altialiasing on or off
4519 //=======================================================================
4520 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4521 Standard_Integer argc,
4526 di << "Usage : " << argv[0] << "\n";
4529 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4530 if (aContext.IsNull())
4532 di << "use 'vinit' command before " << argv[0] << "\n";
4535 aContext->CloseAllContexts(Standard_False);
4536 di << aContext->PurgeDisplay() << "\n";
4540 //=======================================================================
4541 //function : VSetViewSize
4543 //=======================================================================
4544 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4545 Standard_Integer argc,
4548 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4549 if(aContext.IsNull())
4551 di << "use 'vinit' command before " << argv[0] << "\n";
4556 di<<"Usage : " << argv[0] << " Size\n";
4559 Standard_Real aSize = atof(argv[1]);
4562 di<<"Bad Size value : " << aSize << "\n";
4566 Handle(V3d_View) aView = ViewerTest::CurrentView();
4567 aView->SetSize(aSize);
4571 //=======================================================================
4572 //function : VMoveView
4574 //=======================================================================
4575 static Standard_Integer VMoveView (Draw_Interpretor& di,
4576 Standard_Integer argc,
4579 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4580 if(aContext.IsNull())
4582 di << "use 'vinit' command before " << argv[0] << "\n";
4585 if(argc < 4 || argc > 5)
4587 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4590 Standard_Real Dx = atof(argv[1]);
4591 Standard_Real Dy = atof(argv[2]);
4592 Standard_Real Dz = atof(argv[3]);
4593 Standard_Boolean aStart = Standard_True;
4596 aStart = (atoi(argv[4]) > 0);
4599 Handle(V3d_View) aView = ViewerTest::CurrentView();
4600 aView->Move(Dx,Dy,Dz,aStart);
4604 //=======================================================================
4605 //function : VTranslateView
4607 //=======================================================================
4608 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4609 Standard_Integer argc,
4612 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4613 if(aContext.IsNull())
4615 di << "use 'vinit' command before " << argv[0] << "\n";
4618 if(argc < 4 || argc > 5)
4620 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4623 Standard_Real Dx = atof(argv[1]);
4624 Standard_Real Dy = atof(argv[2]);
4625 Standard_Real Dz = atof(argv[3]);
4626 Standard_Boolean aStart = Standard_True;
4629 aStart = (atoi(argv[4]) > 0);
4632 Handle(V3d_View) aView = ViewerTest::CurrentView();
4633 aView->Translate(Dx,Dy,Dz,aStart);
4637 //=======================================================================
4638 //function : VTurnView
4640 //=======================================================================
4641 static Standard_Integer VTurnView (Draw_Interpretor& di,
4642 Standard_Integer argc,
4645 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4646 if(aContext.IsNull()) {
4647 di << "use 'vinit' command before " << argv[0] << "\n";
4650 if(argc < 4 || argc > 5){
4651 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4654 Standard_Real Ax = atof(argv[1]);
4655 Standard_Real Ay = atof(argv[2]);
4656 Standard_Real Az = atof(argv[3]);
4657 Standard_Boolean aStart = Standard_True;
4660 aStart = (atoi(argv[4]) > 0);
4663 Handle(V3d_View) aView = ViewerTest::CurrentView();
4664 aView->Turn(Ax,Ay,Az,aStart);
4668 //==============================================================================
4669 //function : VTextureEnv
4670 //purpose : ENables or disables environment mapping
4671 //==============================================================================
4672 class OCC_TextureEnv : public Graphic3d_TextureEnv
4675 OCC_TextureEnv(const Standard_CString FileName);
4676 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4677 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4678 const Standard_Boolean theModulateFlag,
4679 const Graphic3d_TypeOfTextureFilter theFilter,
4680 const Standard_ShortReal theXScale,
4681 const Standard_ShortReal theYScale,
4682 const Standard_ShortReal theXShift,
4683 const Standard_ShortReal theYShift,
4684 const Standard_ShortReal theAngle);
4685 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4687 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4688 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4689 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4691 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4692 : Graphic3d_TextureEnv(theFileName)
4696 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4697 : Graphic3d_TextureEnv(theTexId)
4701 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4702 const Standard_Boolean theModulateFlag,
4703 const Graphic3d_TypeOfTextureFilter theFilter,
4704 const Standard_ShortReal theXScale,
4705 const Standard_ShortReal theYScale,
4706 const Standard_ShortReal theXShift,
4707 const Standard_ShortReal theYShift,
4708 const Standard_ShortReal theAngle)
4710 myParams->SetRepeat (theRepeatFlag);
4711 myParams->SetModulate (theModulateFlag);
4712 myParams->SetFilter (theFilter);
4713 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
4714 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4715 myParams->SetRotation (theAngle);
4718 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4720 // get the active view
4721 Handle(V3d_View) aView = ViewerTest::CurrentView();
4724 std::cerr << "No active view. Please call vinit.\n";
4728 // Checking the input arguments
4729 Standard_Boolean anEnableFlag = Standard_False;
4730 Standard_Boolean isOk = theArgNb >= 2;
4733 TCollection_AsciiString anEnableOpt(theArgVec[1]);
4734 anEnableFlag = anEnableOpt.IsEqual("on");
4735 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
4739 isOk = (theArgNb == 3 || theArgNb == 11);
4742 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4743 isOk = (!aTextureOpt.IsIntegerValue() ||
4744 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
4746 if (isOk && theArgNb == 11)
4748 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
4749 aModulateOpt(theArgVec[4]),
4750 aFilterOpt (theArgVec[5]),
4751 aSScaleOpt (theArgVec[6]),
4752 aTScaleOpt (theArgVec[7]),
4753 aSTransOpt (theArgVec[8]),
4754 aTTransOpt (theArgVec[9]),
4755 anAngleOpt (theArgVec[10]);
4756 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
4757 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
4758 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
4759 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
4760 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
4761 anAngleOpt.IsRealValue());
4768 std::cerr << "Usage :" << std::endl;
4769 std::cerr << theArgVec[0] << " off" << std::endl;
4770 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;
4776 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4777 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
4778 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
4779 new OCC_TextureEnv(theArgVec[2]);
4783 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
4784 aTexEnv->SetTextureParameters(
4785 aRepeatOpt. IsEqual("repeat"),
4786 aModulateOpt.IsEqual("modulate"),
4787 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
4788 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
4789 Graphic3d_TOTF_TRILINEAR,
4790 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
4791 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
4792 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
4793 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
4794 (Standard_ShortReal)Draw::Atof(theArgVec[10])
4797 aView->SetTextureEnv(aTexEnv);
4798 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
4800 else // Disabling environment mapping
4802 aView->SetSurfaceDetail(V3d_TEX_NONE);
4803 Handle(Graphic3d_TextureEnv) aTexture;
4804 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
4811 //===============================================================================================
4812 //function : VClipPlane
4814 //===============================================================================================
4815 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4817 // use short-cut for created clip planes map of created (or "registered by name") clip planes
4818 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
4819 static MapOfPlanes aRegPlanes;
4823 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
4827 TCollection_AsciiString aCommand (theArgVec[1]);
4829 // print maximum number of planes for current viewer
4830 if (aCommand == "maxplanes")
4834 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
4838 TCollection_AsciiString aViewName (theArgVec[2]);
4840 if (!ViewerTest_myViews.IsBound1 (aViewName))
4842 theDi << theArgVec[0] << ": view is not found.\n";
4846 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
4848 theDi << theArgVec[0] << ": "
4849 << aView->Viewer()->Driver()->InquirePlaneLimit()
4850 << " plane slots provided by driver."
4851 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
4856 // create / delete plane instance
4857 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
4861 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
4865 Standard_Boolean toCreate = (aCommand == "create");
4866 Standard_Boolean toClone = (aCommand == "clone");
4867 TCollection_AsciiString aPlane (theArgVec[2]);
4871 if (aRegPlanes.IsBound (aPlane))
4873 theDi << theArgVec[0] << ": plane name is in use.\n";
4877 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
4879 else if (toClone) // toClone
4881 if (!aRegPlanes.IsBound (aPlane))
4883 theDi << theArgVec[0] << ": no such plane.\n";
4889 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
4893 TCollection_AsciiString aClone (theArgVec[3]);
4894 if (aRegPlanes.IsBound (aClone))
4896 theDi << theArgVec[0] << ": plane name is in use.\n";
4900 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4902 aRegPlanes.Bind (aClone, aClipPlane->Clone());
4906 if (!aRegPlanes.IsBound (aPlane))
4908 theDi << theArgVec[0] << ": no such plane.\n";
4912 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
4913 aRegPlanes.UnBind (aPlane);
4915 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
4916 for (; anIObjIt.More(); anIObjIt.Next())
4918 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
4919 aPrs->RemoveClipPlane(aClipPlane);
4922 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
4923 for (; aViewIt.More(); aViewIt.Next())
4925 const Handle(V3d_View)& aView = aViewIt.Key2();
4926 aView->RemoveClipPlane(aClipPlane);
4929 ViewerTest::RedrawAllViews();
4935 // set / unset plane command
4936 if (aCommand == "set" || aCommand == "unset")
4940 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
4944 Standard_Boolean toSet = (aCommand == "set");
4945 TCollection_AsciiString aPlane (theArgVec [2]);
4946 if (!aRegPlanes.IsBound (aPlane))
4948 theDi << theArgVec[0] << ": no such plane.\n";
4952 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4954 TCollection_AsciiString aTarget (theArgVec [3]);
4955 if (aTarget != "object" && aTarget != "view")
4957 theDi << theArgVec[0] << ": invalid target.\n";
4961 if (aTarget == "object" || aTarget == "view")
4965 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
4969 Standard_Boolean isObject = (aTarget == "object");
4971 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
4973 TCollection_AsciiString anEntityName (theArgVec[anIt]);
4974 if (isObject) // to object
4976 if (!GetMapOfAIS().IsBound2 (anEntityName))
4978 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
4982 Handle(AIS_InteractiveObject) aIObj =
4983 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
4986 aIObj->AddClipPlane (aClipPlane);
4988 aIObj->RemoveClipPlane (aClipPlane);
4992 if (!ViewerTest_myViews.IsBound1 (anEntityName))
4994 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
4998 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
5000 aView->AddClipPlane (aClipPlane);
5002 aView->RemoveClipPlane (aClipPlane);
5006 ViewerTest::RedrawAllViews();
5012 // change plane command
5013 if (aCommand == "change")
5017 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5021 TCollection_AsciiString aPlane (theArgVec [2]);
5022 if (!aRegPlanes.IsBound (aPlane))
5024 theDi << theArgVec[0] << ": no such plane.\n";
5028 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5030 TCollection_AsciiString aChangeArg (theArgVec [3]);
5031 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5033 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5037 if (aChangeArg == "on" || aChangeArg == "off") // on / off
5039 aClipPlane->SetOn (aChangeArg == "on");
5041 else if (aChangeArg == "equation") // change equation
5045 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5049 Standard_Real aCoeffA = atof (theArgVec [4]);
5050 Standard_Real aCoeffB = atof (theArgVec [5]);
5051 Standard_Real aCoeffC = atof (theArgVec [6]);
5052 Standard_Real aCoeffD = atof (theArgVec [7]);
5053 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5055 else if (aChangeArg == "capping") // change capping aspects
5059 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5063 TCollection_AsciiString aCappingArg (theArgVec [4]);
5064 if (aCappingArg != "on" && aCappingArg != "off" &&
5065 aCappingArg != "color" && aCappingArg != "texname" &&
5066 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5067 aCappingArg != "texrotate" && aCappingArg != "hatch")
5069 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5073 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5075 aClipPlane->SetCapping (aCappingArg == "on");
5077 else if (aCappingArg == "color") // color aspect for capping
5081 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5085 Standard_Real aRed = atof (theArgVec [5]);
5086 Standard_Real aGrn = atof (theArgVec [6]);
5087 Standard_Real aBlu = atof (theArgVec [7]);
5089 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5090 aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
5091 aClipPlane->SetCappingMaterial (aMat);
5093 else if (aCappingArg == "texname") // texture name
5097 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5101 TCollection_AsciiString aTextureName (theArgVec [5]);
5103 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5104 if (!aTexture->IsDone ())
5106 aClipPlane->SetCappingTexture (NULL);
5110 aTexture->EnableModulate();
5111 aTexture->EnableRepeat();
5112 aClipPlane->SetCappingTexture (aTexture);
5115 else if (aCappingArg == "texscale") // texture scale
5117 if (aClipPlane->CappingTexture().IsNull())
5119 theDi << theArgVec[0] << ": no texture is set.\n";
5125 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5129 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5130 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5132 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5134 else if (aCappingArg == "texorigin") // texture origin
5136 if (aClipPlane->CappingTexture().IsNull())
5138 theDi << theArgVec[0] << ": no texture is set.\n";
5144 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5148 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5149 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5151 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5153 else if (aCappingArg == "texrotate") // texture rotation
5155 if (aClipPlane->CappingTexture().IsNull())
5157 theDi << theArgVec[0] << ": no texture is set.\n";
5163 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5167 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5169 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5171 else if (aCappingArg == "hatch") // hatch style
5175 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5179 TCollection_AsciiString aHatchStr (theArgVec [5]);
5180 if (aHatchStr == "on")
5182 aClipPlane->SetCappingHatchOn();
5184 else if (aHatchStr == "off")
5186 aClipPlane->SetCappingHatchOff();
5190 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5195 ViewerTest::RedrawAllViews();
5200 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5204 //===============================================================================================
5205 //function : VSetTextureMode
5207 //===============================================================================================
5208 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5212 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5216 TCollection_AsciiString aViewName (theArgVec[1]);
5217 if (!ViewerTest_myViews.IsBound1 (aViewName))
5219 theDi << theArgVec[0] << ": view is not found.\n";
5223 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5224 switch (atoi (theArgVec[2]))
5226 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5227 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5228 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5230 theDi << theArgVec[0] << ": invalid mode.\n";
5238 //=======================================================================
5239 //function : ViewerCommands
5241 //=======================================================================
5243 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
5246 const char *group = "ZeViewer";
5247 theCommands.Add("vinit",
5248 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5249 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5251 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5253 " - Creates new View window with specified name view_name.\n"
5254 "By default the new view is created in the viewer and in"
5255 " graphic driver shared with active view.\n"
5256 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
5257 "If driverName isn't specified the driver will be shared with active view.\n"
5258 "If viewerName isn't specified the viewer will be shared with active view.\n"
5259 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5260 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
5261 "is used in creation of graphic driver\n"
5263 " - l, t: pixel position of left top corner of the window\n"
5264 " - w,h: width and heigth of window respectively.\n"
5265 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
5266 __FILE__,VInit,group);
5267 theCommands.Add("vclose" ,
5268 "view_id [keep_context=0|1]\n"
5269 "or vclose ALL - to remove all created views\n"
5270 " - removes view(viewer window) defined by its view_id.\n"
5271 " - keep_context: by default 0; if 1 and the last view is deleted"
5272 " the current context is not removed.",
5273 __FILE__,VClose,group);
5274 theCommands.Add("vactivate" ,
5276 " - activates view(viewer window) defined by its view_id",
5277 __FILE__,VActivate,group);
5278 theCommands.Add("vviewlist",
5279 "vviewlist [format={tree, long}]"
5280 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
5281 " - format: format of result output, if tree the output is a tree view;"
5282 "otherwise it's a list of full view names. By default format = tree",
5283 __FILE__,VViewList,group);
5284 theCommands.Add("vhelp" ,
5285 "vhelp : display help on the viewer commands",
5286 __FILE__,VHelp,group);
5287 theCommands.Add("vtop" ,
5288 "vtop or <T> : Top view" ,
5289 __FILE__,VTop,group);
5290 theCommands.Add("vbottom" ,
5291 "vbottom : Bottom view" ,
5292 __FILE__,VBottom,group);
5293 theCommands.Add("vleft" ,
5294 "vleft : Left view" ,
5295 __FILE__,VLeft,group);
5296 theCommands.Add("vright" ,
5297 "vright : Right view" ,
5298 __FILE__,VRight,group);
5299 theCommands.Add("vaxo" ,
5300 " vaxo or <A> : Axonometric view ",
5301 __FILE__,VAxo,group);
5302 theCommands.Add("vfront" ,
5303 "vfront : Front view" ,
5304 __FILE__,VFront,group);
5305 theCommands.Add("vback" ,
5306 "vback : Back view" ,
5307 __FILE__,VBack,group);
5308 theCommands.Add("vpick" ,
5309 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
5311 theCommands.Add("vfit" ,
5312 "vfit or <F> : vfit",
5313 __FILE__,VFit,group);
5314 theCommands.Add("vzfit" ,
5316 __FILE__,VZFit,group);
5317 theCommands.Add("vrepaint",
5318 "vrepaint : vrepaint, force redraw",
5319 __FILE__,VRepaint,group);
5320 theCommands.Add("vclear",
5322 __FILE__,VClear,group);
5323 theCommands.Add("vsetbg",
5324 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
5325 __FILE__,VSetBg,group);
5326 theCommands.Add("vsetbgmode",
5327 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
5328 __FILE__,VSetBgMode,group);
5329 theCommands.Add("vsetgradientbg",
5330 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
5331 __FILE__,VSetGradientBg,group);
5332 theCommands.Add("vsetgrbgmode",
5333 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
5334 __FILE__,VSetGradientBgMode,group);
5335 theCommands.Add("vsetcolorbg",
5336 "vsetcolorbg : vsetcolorbg r g b : Set background color",
5337 __FILE__,VSetColorBg,group);
5338 theCommands.Add("vscale",
5339 "vscale : vscale X Y Z",
5340 __FILE__,VScale,group);
5341 theCommands.Add("vzbufftrihedron",
5342 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
5343 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
5344 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
5345 __FILE__,VTestZBuffTrihedron,group);
5346 theCommands.Add("vrotate",
5347 "vrotate : vrotate AX AY AZ [X Y Z]",
5348 __FILE__,VRotate,group);
5349 theCommands.Add("vzoom",
5350 "vzoom : vzoom coef",
5351 __FILE__,VZoom,group);
5352 theCommands.Add("vpan",
5353 "vpan : vpan dx dy",
5354 __FILE__,VPan,group);
5355 theCommands.Add("vexport",
5356 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
5357 " : exports the view to a vector file of a given format"
5358 " : notice that EMF format requires patched gl2ps",
5359 __FILE__,VExport,group);
5360 theCommands.Add("vcolorscale",
5361 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
5362 __FILE__,VColorScale,group);
5363 theCommands.Add("vgraduatedtrihedron",
5364 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
5365 __FILE__,VGraduatedTrihedron,group);
5366 theCommands.Add("vprintview" ,
5367 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
5368 __FILE__,VPrintView,group);
5369 theCommands.Add("vzlayer",
5370 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
5371 __FILE__,VZLayer,group);
5372 theCommands.Add("voverlaytext",
5373 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
5374 " : height - pixel height of the text (default=10.0)"
5375 " : font_name - name of font (default=courier)"
5376 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
5377 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
5378 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
5379 __FILE__,VOverlayText,group);
5380 theCommands.Add("vlayerline",
5381 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
5382 __FILE__,VLayerLine,group);
5383 theCommands.Add ("vgrid",
5384 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
5385 " : Mode - rectangular or circular"
5386 " : Type - lines or points",
5387 __FILE__, VGrid, group);
5388 theCommands.Add ("vfps",
5389 "vfps [framesNb=100] : estimate average frame rate for active view",
5390 __FILE__, VFps, group);
5391 theCommands.Add ("vgldebug",
5392 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
5393 " : this function is implemented only for Windows\n"
5394 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
5395 __FILE__, VGlDebug, group);
5396 theCommands.Add ("vvbo",
5397 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
5398 __FILE__, VVbo, group);
5399 theCommands.Add ("vcaps",
5400 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
5401 __FILE__, VCaps, group);
5402 theCommands.Add ("vmemgpu",
5403 "vmemgpu [f]: print system-dependent GPU memory information if available;"
5404 " with f option returns free memory in bytes",
5405 __FILE__, VMemGpu, group);
5406 theCommands.Add ("vreadpixel",
5407 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
5408 " : Read pixel value for active view",
5409 __FILE__, VReadPixel, group);
5410 theCommands.Add("diffimage",
5411 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
5412 __FILE__, VDiffImage, group);
5413 theCommands.Add ("vselect",
5414 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
5415 "- emulates different types of selection:\n"
5416 "- 1) single click selection\n"
5417 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
5418 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
5419 "- 4) any of these selections with shift button pressed",
5420 __FILE__, VSelect, group);
5421 theCommands.Add ("vmoveto",
5423 "- emulates cursor movement to pixel postion (x,y)",
5424 __FILE__, VMoveTo, group);
5425 theCommands.Add("vviewparams",
5426 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
5427 "- gets or sets current view characteristics",
5428 __FILE__,VViewParams, group);
5429 theCommands.Add("vchangeselected",
5430 "vchangeselected shape"
5431 "- adds to shape to selection or remove one from it",
5432 __FILE__, VChangeSelected, group);
5433 theCommands.Add("vzclipping",
5434 "vzclipping [mode] [depth width]\n"
5435 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
5436 "- gets or sets ZClipping mode, width and depth",
5437 __FILE__,VZClipping,group);
5438 theCommands.Add ("vnbselected",
5439 "vnbselected", __FILE__, VNbSelected, group);
5440 theCommands.Add("vantialiasing",
5441 "vantialiasing 1|0",
5442 __FILE__,VAntialiasing,group);
5443 theCommands.Add ("vpurgedisplay",
5445 "- removes structures which don't belong to objects displayed in neutral point",
5446 __FILE__, VPurgeDisplay, group);
5447 theCommands.Add("vsetviewsize",
5448 "vsetviewsize size",
5449 __FILE__,VSetViewSize,group);
5450 theCommands.Add("vmoveview",
5451 "vmoveview Dx Dy Dz [Start = 1|0]",
5452 __FILE__,VMoveView,group);
5453 theCommands.Add("vtranslateview",
5454 "vtranslateview Dx Dy Dz [Start = 1|0)]",
5455 __FILE__,VTranslateView,group);
5456 theCommands.Add("vturnview",
5457 "vturnview Ax Ay Az [Start = 1|0]",
5458 __FILE__,VTurnView,group);
5459 theCommands.Add("vtextureenv",
5460 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
5461 "or user-defined file and optionally applying texture mapping parameters\n"
5463 " vtextureenv off - disables environment mapping\n"
5464 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
5465 " std_texture = (0..7)\n"
5466 " rep = {clamp|repeat}\n"
5467 " mod = {decal|modulate}\n"
5468 " flt = {nearest|bilinear|trilinear}\n"
5469 " ss, st - scale factors for s and t texture coordinates\n"
5470 " ts, tt - translation for s and t texture coordinates\n"
5471 " rot - texture rotation angle in degrees",
5472 __FILE__, VTextureEnv, group);
5473 theCommands.Add("vhlr" ,
5474 "is_enabled={on|off}"
5475 " - Hidden line removal algorithm:"
5476 " - is_enabled: if is on HLR algorithm is applied\n",
5477 __FILE__,VHLR,group);
5478 theCommands.Add("vhlrtype" ,
5479 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
5480 " - Changes the type of HLR algorithm using for shapes."
5481 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
5482 " if equals to polyalgo, polygonal HLR algorithm is applied."
5483 "If shapes are not given HLR algoithm of given type is applied"
5484 " to all shapes in the view\n",
5485 __FILE__,VHLRType,group);
5486 theCommands.Add("vclipplane", "vclipplane usage: \n"
5487 " maxplanes <view_name> - get plane limit for view.\n"
5488 " create <plane_name> - create new plane.\n"
5489 " delete <plane_name> - delete plane.\n"
5490 " clone <source_plane> <plane_name> - clone the plane definition.\n"
5491 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
5492 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
5493 " change <plane_name> on/off - turn clipping on/off.\n"
5494 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
5495 " change <plane_name> capping on/off - turn capping on/off.\n"
5496 " change <plane_name> capping color <r> <g> <b> - set color.\n"
5497 " change <plane name> capping texname <texture> - set texture.\n"
5498 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
5499 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
5500 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
5501 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
5502 " please use VSetTextureMode command to enable texture rendering in view.\n"
5503 , __FILE__, VClipPlane, group);
5504 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
5506 " 0 - no textures enabled in view.\n"
5507 " 1 - only environment textures enabled.\n"
5508 " 2 - all textures enabled.\n"
5509 " this command sets texture details mode for the specified view.\n"
5510 , __FILE__, VSetTextureMode, group);