1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
25 #include <OpenGl_GlCore20.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_Drawer.hxx>
28 #include <AIS_InteractiveObject.hxx>
29 #include <AIS_ListOfInteractive.hxx>
30 #include <AIS_ListIteratorOfListOfInteractive.hxx>
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_ExportFormat.hxx>
34 #include <Graphic3d_NameOfTextureEnv.hxx>
35 #include <Graphic3d_TextureEnv.hxx>
36 #include <Graphic3d_TextureParams.hxx>
37 #include <Graphic3d_TypeOfTextureFilter.hxx>
38 #include <Graphic3d_AspectFillArea3d.hxx>
39 #include <ViewerTest.hxx>
40 #include <ViewerTest_EventManager.hxx>
41 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
42 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
43 #include <Visual3d_View.hxx>
44 #include <Visual3d_ViewManager.hxx>
45 #include <V3d_LayerMgr.hxx>
46 #include <NCollection_DoubleMap.hxx>
47 #include <NCollection_List.hxx>
48 #include <NCollection_Vector.hxx>
49 #include <NIS_View.hxx>
50 #include <NIS_Triangulated.hxx>
51 #include <NIS_InteractiveContext.hxx>
52 #include <AIS_InteractiveContext.hxx>
53 #include <Draw_Interpretor.hxx>
55 #include <Draw_Appli.hxx>
56 #include <Aspect_PrintAlgo.hxx>
57 #include <Image_AlienPixMap.hxx>
58 #include <OpenGl_GraphicDriver.hxx>
59 #include <OSD_Timer.hxx>
60 #include <TColStd_SequenceOfInteger.hxx>
61 #include <TColStd_HSequenceOfReal.hxx>
62 #include <TColgp_Array1OfPnt2d.hxx>
63 #include <Visual3d_LayerItem.hxx>
64 #include <V3d_LayerMgr.hxx>
65 #include <V3d_LayerMgrPointer.hxx>
66 #include <Aspect_TypeOfLine.hxx>
67 #include <Image_Diff.hxx>
68 #include <Aspect_DisplayConnection.hxx>
69 #include <Graphic3d.hxx>
73 #include <PrsMgr_PresentableObject.hxx>
74 #include <Graphic3d_ClipPlane.hxx>
75 #include <NCollection_DataMap.hxx>
76 #include <Graphic3d_Texture2Dmanual.hxx>
77 #include <Prs3d_ShadingAspect.hxx>
83 #include <Visual3d_Layer.hxx>
87 #include <WNT_WClass.hxx>
88 #include <WNT_Window.hxx>
91 #define _CRT_SECURE_NO_DEPRECATE
92 #pragma warning (disable:4996)
94 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
95 #include <Cocoa_Window.hxx>
98 #include <Xw_Window.hxx>
99 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
100 #include <X11/Xutil.h>
104 // Auxiliary definitions
105 static const char THE_KEY_DELETE = 127;
107 //==============================================================================
108 // VIEWER GLOBAL VARIABLES
109 //==============================================================================
111 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
112 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
114 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
115 extern const Handle(NIS_InteractiveContext)& TheNISContext();
116 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
118 extern int VErase (Draw_Interpretor& theDI,
119 Standard_Integer theArgNb,
120 const char** theArgVec);
123 static Handle(WNT_Window)& VT_GetWindow() {
124 static Handle(WNT_Window) WNTWin;
127 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
128 static Handle(Cocoa_Window)& VT_GetWindow()
130 static Handle(Cocoa_Window) aWindow;
133 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
134 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
135 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
138 static Handle(Xw_Window)& VT_GetWindow(){
139 static Handle(Xw_Window) XWWin;
143 static void VProcessEvents(ClientData,int);
146 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
148 static Handle(Aspect_DisplayConnection) aDisplayConnection;
149 return aDisplayConnection;
152 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
154 GetDisplayConnection() = theDisplayConnection;
157 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
158 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
160 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
162 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
163 if (!aWindow.IsNull())
164 return aWindow->HWindow();
165 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
166 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
167 if (!aWindow.IsNull())
168 return aWindow->XWindow();
170 return aWindowHandle;
174 static Standard_Boolean MyHLRIsOn = Standard_False;
176 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
177 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
178 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
179 static OpenGl_Caps ViewerTest_myDefaultCaps;
181 #define ZCLIPWIDTH 1.
183 static void OSWindowSetup();
185 //==============================================================================
186 // EVENT GLOBAL VARIABLES
187 //==============================================================================
189 static int Start_Rot = 0;
190 static int ZClipIsOn = 0;
191 int X_Motion = 0; // Current cursor position
193 int X_ButtonPress = 0; // Last ButtonPress position
194 int Y_ButtonPress = 0;
195 Standard_Boolean IsDragged = Standard_False;
196 Standard_Boolean DragFirst;
198 //==============================================================================
201 static LRESULT WINAPI ViewerWindowProc(
206 static LRESULT WINAPI AdvViewerWindowProc(
214 //==============================================================================
217 //==============================================================================
219 const Handle(MMgt_TShared)& ViewerTest::WClass()
221 static Handle(MMgt_TShared) theWClass;
223 if (theWClass.IsNull())
225 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
226 CS_VREDRAW | CS_HREDRAW, 0, 0,
227 ::LoadCursor (NULL, IDC_ARROW));
233 //==============================================================================
234 //function : CreateName
235 //purpose : Create numerical name for new object in theMap
236 //==============================================================================
237 template <typename ObjectType>
238 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
239 const TCollection_AsciiString& theDefaultString)
241 if (theObjectMap.IsEmpty())
242 return theDefaultString + TCollection_AsciiString(1);
244 Standard_Integer aNextKey = 1;
245 Standard_Boolean isFound = Standard_False;
248 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
249 // Look for objects with default names
250 if (theObjectMap.IsBound1(aStringKey))
255 isFound = Standard_True;
258 return theDefaultString + TCollection_AsciiString(aNextKey);
261 //==============================================================================
262 //structure : ViewerTest_Names
263 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
264 //==============================================================================
265 struct ViewerTest_Names
268 TCollection_AsciiString myDriverName;
269 TCollection_AsciiString myViewerName;
270 TCollection_AsciiString myViewName;
274 const TCollection_AsciiString& GetDriverName () const
278 void SetDriverName (const TCollection_AsciiString& theDriverName)
280 myDriverName = theDriverName;
282 const TCollection_AsciiString& GetViewerName () const
286 void SetViewerName (const TCollection_AsciiString& theViewerName)
288 myViewerName = theViewerName;
290 const TCollection_AsciiString& GetViewName () const
294 void SetViewName (const TCollection_AsciiString& theViewName)
296 myViewName = theViewName;
299 //===========================================================================
300 //function : Constructor for ViewerTest_Names
301 //purpose : Get view, viewer, driver names from custom string
302 //===========================================================================
304 ViewerTest_Names (const TCollection_AsciiString& theInputString)
306 TCollection_AsciiString aName(theInputString);
307 if (theInputString.IsEmpty())
309 // Get current configuration
310 if (ViewerTest_myDrivers.IsEmpty())
311 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
312 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
314 myDriverName = ViewerTest_myDrivers.Find2
315 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
317 if(ViewerTest_myContexts.IsEmpty())
319 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
320 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
323 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
325 myViewName = CreateName <Handle(V3d_View)>
326 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
330 // There is at least view name
331 Standard_Integer aParserNumber = 0;
332 for (Standard_Integer i = 0; i < 3; ++i)
334 Standard_Integer aParserPos = aName.SearchFromEnd("/");
338 aName.Split(aParserPos-1);
343 if (aParserNumber == 0)
346 if (!ViewerTest::GetAISContext().IsNull())
348 myDriverName = ViewerTest_myDrivers.Find2
349 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
350 myViewerName = ViewerTest_myContexts.Find2
351 (ViewerTest::GetAISContext());
355 // There is no opened contexts here, need to create names for viewer and driver
356 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
357 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
359 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
360 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
362 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
364 else if (aParserNumber == 1)
366 // Here is viewerName/viewName
367 if (!ViewerTest::GetAISContext().IsNull())
368 myDriverName = ViewerTest_myDrivers.Find2
369 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
372 // There is no opened contexts here, need to create name for driver
373 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
374 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
376 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
378 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
382 //Here is driverName/viewerName/viewName
383 myDriverName = TCollection_AsciiString(aName);
385 TCollection_AsciiString aViewerName(theInputString);
386 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
387 myViewerName = TCollection_AsciiString(aViewerName);
389 myViewName = TCollection_AsciiString(theInputString);
395 //==============================================================================
396 //function : FindContextByView
397 //purpose : Find AIS_InteractiveContext by View
398 //==============================================================================
400 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
402 Handle(AIS_InteractiveContext) anAISContext;
404 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
405 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
407 if (anIter.Value()->CurrentViewer() == theView->Viewer())
408 return anIter.Key2();
414 //==============================================================================
415 //function : SetWindowTitle
416 //purpose : Set window title
417 //==============================================================================
419 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
420 Standard_CString theTitle)
423 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
425 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
426 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
428 if(GetDisplayConnection()->GetDisplay())
431 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
432 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
437 //==============================================================================
438 //function : IsWindowOverlapped
439 //purpose : Check if theWindow overlapp another view
440 //==============================================================================
442 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
443 const Standard_Integer thePxTop,
444 const Standard_Integer thePxRight,
445 const Standard_Integer thePxBottom,
446 TCollection_AsciiString& theViewId)
448 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
449 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
451 Standard_Integer aTop = 0,
455 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
456 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
457 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
458 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
459 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
461 theViewId = anIter.Key1();
462 return Standard_True;
465 return Standard_False;
468 // Workaround: to create and delete non-orthographic views outside ViewerTest
469 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
471 ViewerTest_myViews.UnBind1 (theName);
474 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
475 const Handle(V3d_View)& theView)
477 ViewerTest_myViews.Bind (theName, theView);
480 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
482 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
484 //==============================================================================
485 //function : ViewerInit
486 //purpose : Create the window viewer and initialize all the global variable
487 //==============================================================================
489 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
490 const Standard_Integer thePxTop,
491 const Standard_Integer thePxWidth,
492 const Standard_Integer thePxHeight,
493 Standard_CString theViewName,
494 Standard_CString theDisplayName)
496 // Default position and dimension of the viewer window.
497 // Note that left top corner is set to be sufficiently small to have
498 // window fit in the small screens (actual for remote desktops, see #23003).
499 // The position corresponds to the window's client area, thus some
500 // gap is added for window frame to be visible.
501 Standard_Integer aPxLeft = 20;
502 Standard_Integer aPxTop = 40;
503 Standard_Integer aPxWidth = 409;
504 Standard_Integer aPxHeight = 409;
505 Standard_Boolean toCreateViewer = Standard_False;
507 Handle(OpenGl_GraphicDriver) aGraphicDriver;
508 ViewerTest_Names aViewNames(theViewName);
509 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
510 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
517 aPxWidth = thePxWidth;
518 if (thePxHeight != 0)
519 aPxHeight = thePxHeight;
521 // Get graphic driver (create it or get from another view)
522 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
524 // Get connection string
525 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
526 TCollection_AsciiString aDisplayName(theDisplayName);
527 if (!aDisplayName.IsEmpty())
528 SetDisplayConnection (new Aspect_DisplayConnection ());
530 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
532 (void)theDisplayName; // avoid warning on unused argument
533 SetDisplayConnection (new Aspect_DisplayConnection ());
535 aGraphicDriver = new OpenGl_GraphicDriver();
536 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
537 aGraphicDriver->Begin (GetDisplayConnection());
538 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
539 toCreateViewer = Standard_True;
543 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
546 //Dispose the window if input parameters are default
547 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
549 Standard_Integer aTop = 0,
556 // Get screen resolution
557 #if defined(_WIN32) || defined(__WIN32__)
559 GetClientRect(GetDesktopWindow(), &aWindowSize);
560 aScreenHeight = aWindowSize.bottom;
561 aScreenWidth = aWindowSize.right;
562 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
563 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
565 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
566 aScreenWidth = WidthOfScreen(aScreen);
567 aScreenHeight = HeightOfScreen(aScreen);
570 TCollection_AsciiString anOverlappedViewId("");
572 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
574 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
576 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
577 && aRight + 2*aPxWidth + 40 > aScreenWidth)
579 if (aBottom + aPxHeight + 40 > aScreenHeight)
586 aPxTop = aBottom + 40;
589 aPxLeft = aRight + 20;
594 TCollection_AsciiString aTitle("3D View - ");
595 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
597 // Change name of current active window
598 if (!ViewerTest::CurrentView().IsNull())
600 TCollection_AsciiString aTitle("3D View - ");
602 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
603 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
607 Handle(V3d_Viewer) a3DViewer;
608 // If it's the single view, we first look for empty context
609 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
611 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
612 anIter(ViewerTest_myContexts);
614 ViewerTest::SetAISContext (anIter.Value());
615 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
617 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
619 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
620 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
622 else if (a3DViewer.IsNull())
624 toCreateViewer = Standard_True;
625 TCollection_ExtendedString NameOfWindow("Viewer3D");
626 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
628 NameOfWindow = TCollection_ExtendedString("Collector");
630 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
634 if (ViewerTest::GetAISContext().IsNull() ||
635 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
637 Handle(AIS_InteractiveContext) aContext =
638 new AIS_InteractiveContext(a3DViewer);
639 ViewerTest::SetAISContext (aContext);
640 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
643 ViewerTest::ResetEventManager();
646 #if defined(_WIN32) || defined(__WIN32__)
647 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
648 Handle(WNT_WClass)::DownCast (WClass()),
649 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
653 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
654 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
656 aPxWidth, aPxHeight);
657 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
659 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
662 aPxWidth, aPxHeight);
664 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
667 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
669 ViewerTest::CurrentView(aView);
670 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
671 TheNISContext()->AttachView (aView);
673 // Setup for X11 or NT
676 // Set parameters for V3d_View and V3d_Viewer
677 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
678 aV3dView->SetComputedMode(Standard_False);
679 MyHLRIsOn = aV3dView->ComputedMode();
680 aV3dView->SetZClippingDepth(0.5);
681 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
683 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
686 a3DViewer->SetDefaultLights();
687 a3DViewer->SetLightOn();
690 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
691 #if TCL_MAJOR_VERSION < 8
692 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
693 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
695 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
696 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
700 VT_GetWindow()->Map();
702 // Set the handle of created view in the event manager
703 ViewerTest::ResetEventManager();
705 ViewerTest::CurrentView()->Redraw();
710 return aViewNames.GetViewName();
713 //==============================================================================
714 //function : RedrawAllViews
715 //purpose : Redraw all created views
716 //==============================================================================
717 void ViewerTest::RedrawAllViews()
719 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
720 for (; aViewIt.More(); aViewIt.Next())
722 const Handle(V3d_View)& aView = aViewIt.Key2();
727 //==============================================================================
728 //function : SplitParameter
729 //purpose : Split parameter string to parameter name an patameter value
730 //==============================================================================
731 Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
732 TCollection_AsciiString& theName,
733 TCollection_AsciiString& theValue)
735 Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
736 if (aParamNameEnd == 0)
737 return Standard_False;
738 TCollection_AsciiString aString(theString);
739 if (aParamNameEnd != 0)
741 theValue = aString.Split(aParamNameEnd);
742 aString.Split(aString.Length()-1);
745 return Standard_True;
748 //==============================================================================
750 //purpose : Create the window viewer and initialize all the global variable
751 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
752 //==============================================================================
754 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
758 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
759 << "Type help for more information.\n";
762 TCollection_AsciiString aViewName (""),
764 Standard_Integer aPxLeft = 0,
769 for (Standard_Integer i = 1; i < theArgsNb; ++i)
771 TCollection_AsciiString aName = "", aValue = "";
772 if(!SplitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
774 // In case of syntax: vinit ViewName
775 aViewName = theArgVec[1];
783 else if (aName == "l" || aName == "left")
784 aPxLeft = aValue.IntegerValue();
785 else if (aName == "t" || aName == "top")
786 aPxTop = aValue.IntegerValue();
787 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
788 else if (aName == "display")
789 aDisplayName = aValue;
791 else if (aName == "w" || aName == "width")
792 aPxWidth = aValue.IntegerValue();
793 else if (aName == "h" || aName == "height")
794 aPxHeight = aValue.IntegerValue();
797 theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n";
802 ViewerTest_Names aViewNames (aViewName);
803 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
805 TCollection_AsciiString aCommand("vactivate ");
806 aCommand = aCommand + aViewNames.GetViewName();
807 theDi.Eval(aCommand.ToCString());
811 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
812 aViewName.ToCString(),
813 aDisplayName.ToCString());
814 cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n";
818 //==============================================================================
820 //purpose : hidden lines removal algorithm
821 //==============================================================================
823 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
825 if (ViewerTest::CurrentView().IsNull())
827 di << argv[0] << ": Call vinit before this command, please.\n";
833 di << argv[0] << ": Wrong number of command arguments.\n"
834 << "Type help " << argv[0] << " for more information.\n";
838 Standard_Boolean isHLROn =
839 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
841 if (isHLROn == MyHLRIsOn)
847 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
852 //==============================================================================
853 //function : VHLRType
854 //purpose : change type of using HLR algorithm
855 //==============================================================================
857 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
859 if (ViewerTest::CurrentView().IsNull())
861 di << argv[0] << ": Call vinit before this command, please.\n";
867 di << argv[0] << ": Wrong number of command arguments.\n"
868 << "Type help " << argv[0] << " for more information.\n";
872 Prs3d_TypeOfHLR aTypeOfHLR =
873 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
877 AIS_ListOfInteractive aListOfShapes;
878 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
879 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
880 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
881 anIter.More(); anIter.Next())
883 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
886 if (aShape->TypeOfHLR() != aTypeOfHLR)
887 aShape->SetTypeOfHLR (aTypeOfHLR);
891 ViewerTest::CurrentView()->Update();
896 for (Standard_Integer i = 2; i < argc; ++i)
898 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
899 TCollection_AsciiString aName (argv[i]);
901 if (!aMap.IsBound2 (aName))
903 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
906 Handle(AIS_Shape) anAISObject =
907 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
908 if (anAISObject.IsNull())
910 anAISObject->SetTypeOfHLR (aTypeOfHLR);
912 anAISObject->Redisplay();
914 ViewerTest::CurrentView()->Update();
920 //==============================================================================
921 //function : FindViewIdByWindowHandle
922 //purpose : Find theView Id in the map of views by window handle
923 //==============================================================================
924 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
925 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
927 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
928 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
930 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
931 if (aWindowHandle == theWindowHandle)
932 return anIter.Key1();
934 return TCollection_AsciiString("");
938 //==============================================================================
939 //function : ActivateView
940 //purpose : Make the view active
941 //==============================================================================
943 void ActivateView (const TCollection_AsciiString& theViewName)
945 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
948 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
949 if (!anAISContext.IsNull())
951 if (!ViewerTest::CurrentView().IsNull())
953 TCollection_AsciiString aTitle("3D View - ");
954 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
955 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
958 ViewerTest::CurrentView (aView);
959 // Update degenerate mode
960 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
961 ViewerTest::SetAISContext (anAISContext);
962 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
963 aTitle = aTitle + theViewName + "(*)";
964 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
965 #if defined(_WIN32) || defined(__WIN32__)
966 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
967 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
968 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
970 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
972 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
973 ViewerTest::CurrentView()->Redraw();
978 //==============================================================================
979 //function : RemoveView
980 //purpose : Close and remove view from display, clear maps if neccessary
981 //==============================================================================
982 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
984 if (!ViewerTest_myViews.IsBound1(theViewName))
986 cout << "Wrong view name\n";
990 // Activate another view if it's active now
991 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
993 if (ViewerTest_myViews.Extent() > 1)
995 TCollection_AsciiString aNewViewName;
996 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
997 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
998 if (anIter.Key1() != theViewName)
1000 aNewViewName = anIter.Key1();
1003 ActivateView (aNewViewName);
1007 Handle(V3d_View) anEmptyView;
1008 #if defined(_WIN32) || defined(__WIN32__)
1009 Handle(WNT_Window) anEmptyWindow;
1010 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1011 Handle(Cocoa_Window) anEmptyWindow;
1013 Handle(Xw_Window) anEmptyWindow;
1015 VT_GetWindow() = anEmptyWindow;
1016 ViewerTest::CurrentView (anEmptyView);
1017 if (isContextRemoved)
1019 Handle(AIS_InteractiveContext) anEmptyContext;
1020 ViewerTest::SetAISContext(anEmptyContext);
1026 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1027 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1029 // Remove view resources
1030 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1031 ViewerTest_myViews.UnBind1(theViewName);
1034 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1035 XFlush (GetDisplayConnection()->GetDisplay());
1038 // Keep context opened only if the closed view is last to avoid
1039 // unused empty contexts
1040 if (!aCurrentContext.IsNull())
1042 // Check if there are more difined views in the viewer
1043 aCurrentContext->CurrentViewer()->InitDefinedViews();
1044 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1046 // Remove driver if there is no viewers that use it
1047 Standard_Boolean isRemoveDriver = Standard_True;
1048 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1049 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1051 if (aCurrentContext != anIter.Key2() &&
1052 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1054 isRemoveDriver = Standard_False;
1060 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1061 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1062 #if TCL_MAJOR_VERSION < 8
1063 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1065 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1070 ViewerTest_myContexts.UnBind2(aCurrentContext);
1073 cout << "3D View - " << theViewName << " was deleted.\n";
1077 //==============================================================================
1079 //purpose : Remove the view defined by its name
1080 //==============================================================================
1082 static int VClose (Draw_Interpretor& /*theDi*/,
1083 Standard_Integer theArgsNb,
1084 const char** theArgVec)
1086 NCollection_List<TCollection_AsciiString> aViewList;
1089 TCollection_AsciiString anArg (theArgVec[1]);
1091 if (anArg.IsEqual ("ALL")
1092 || anArg.IsEqual ("*"))
1094 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1095 anIter.More(); anIter.Next())
1097 aViewList.Append (anIter.Key1());
1099 if (aViewList.IsEmpty())
1101 std::cout << "No view to close\n";
1107 ViewerTest_Names aViewName (theArgVec[1]);
1108 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1110 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1113 aViewList.Append (aViewName.GetViewName());
1118 // close active view
1119 if (ViewerTest::CurrentView().IsNull())
1121 std::cerr << "No active view!\n";
1124 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1127 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1128 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1129 anIter.More(); anIter.Next())
1131 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1137 //==============================================================================
1138 //function : VActivate
1139 //purpose : Activate the view defined by its ID
1140 //==============================================================================
1142 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1146 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1147 << "Usage: " << theArgVec[0] << " ViewID\n";
1152 theDi.Eval("vviewlist");
1156 TCollection_AsciiString aNameString(theArgVec[1]);
1157 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1159 TCollection_AsciiString aTitle("3D View - ");
1160 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1161 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1162 Handle(V3d_View) anEmptyView;
1163 #if defined(_WIN32) || defined(__WIN32__)
1164 Handle(WNT_Window) anEmptyWindow;
1165 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1166 Handle(Cocoa_Window) anEmptyWindow;
1168 Handle(Xw_Window) anEmptyWindow;
1170 VT_GetWindow() = anEmptyWindow;
1171 ViewerTest::CurrentView (anEmptyView);
1172 ViewerTest::ResetEventManager();
1173 theDi << theArgVec[0] << ": all views are inactive\n";
1177 ViewerTest_Names aViewNames(aNameString);
1179 // Check if this view exists in the viewer with the driver
1180 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1182 theDi << "Wrong view name\n";
1186 // Check if it is active already
1187 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1189 theDi << theArgVec[0] << ": the view is active already\n";
1193 ActivateView (aViewNames.GetViewName());
1197 //==============================================================================
1198 //function : VViewList
1199 //purpose : Print current list of views per viewer and graphic driver ID
1200 // shared between viewers
1201 //==============================================================================
1203 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1207 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1208 << "Usage: " << theArgVec[0] << " name";
1211 if (ViewerTest_myContexts.Size() < 1)
1214 Standard_Boolean isTreeView =
1215 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1218 theDi << theArgVec[0] <<":\n";
1220 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1221 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1224 theDi << aDriverIter.Key1() << ":\n";
1226 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1227 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1229 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1233 TCollection_AsciiString aContextName(aContextIter.Key1());
1234 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1237 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1238 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1240 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1242 TCollection_AsciiString aViewName(aViewIter.Key1());
1245 if (aViewIter.Value() == ViewerTest::CurrentView())
1246 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1248 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1252 theDi << aViewName << " ";
1262 //==============================================================================
1263 //function : VT_ProcessKeyPress
1264 //purpose : Handle KeyPress event from a CString
1265 //==============================================================================
1266 void VT_ProcessKeyPress (const char* buf_ret)
1268 //cout << "KeyPress" << endl;
1269 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1270 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1271 // Letter in alphabetic order
1273 if (!strcasecmp (buf_ret, "A"))
1276 aView->SetProj(V3d_XposYnegZpos);
1278 else if (!strcasecmp (buf_ret, "D"))
1283 else if (!strcasecmp (buf_ret, "F"))
1286 if (aNisView.IsNull())
1289 aNisView->FitAll3d();
1291 else if (!strcasecmp (buf_ret, "H"))
1294 cout << "HLR" << endl;
1295 aView->SetComputedMode (!aView->ComputedMode());
1296 MyHLRIsOn = aView->ComputedMode();
1298 else if (!strcasecmp (buf_ret, "P"))
1301 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1302 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1303 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1305 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1306 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1308 AIS_ListOfInteractive aListOfShapes;
1309 aContext->DisplayedObjects(aListOfShapes);
1310 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1311 anIter.More(); anIter.Next())
1313 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1314 if (aShape.IsNull())
1316 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1317 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1319 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1320 aShape->Redisplay();
1325 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1327 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1328 if (aShape.IsNull())
1330 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1331 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1333 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1334 aShape->Redisplay();
1338 aContext->UpdateCurrentViewer();
1341 else if (!strcasecmp (buf_ret, "S"))
1343 std::cout << "setup Shaded display mode" << std::endl;
1345 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1346 if(Ctx->NbCurrents()==0 ||
1347 Ctx->NbSelected()==0)
1348 Ctx->SetDisplayMode(AIS_Shaded);
1350 if(Ctx->HasOpenedContext()){
1351 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1352 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1355 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1356 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1358 Ctx->UpdateCurrentViewer();
1361 else if (!strcasecmp (buf_ret, "U"))
1363 // Unset display mode
1364 std::cout << "reset display mode to defaults" << std::endl;
1366 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1367 if(Ctx->NbCurrents()==0 ||
1368 Ctx->NbSelected()==0)
1369 Ctx->SetDisplayMode(AIS_WireFrame);
1371 if(Ctx->HasOpenedContext()){
1372 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1373 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1376 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1377 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1379 Ctx->UpdateCurrentViewer();
1383 else if (!strcasecmp (buf_ret, "T"))
1386 aView->SetProj(V3d_Zpos);
1388 else if (!strcasecmp (buf_ret, "B"))
1391 aView->SetProj(V3d_Zneg);
1393 else if (!strcasecmp (buf_ret, "L"))
1396 aView->SetProj(V3d_Xneg);
1398 else if (!strcasecmp (buf_ret, "R"))
1401 aView->SetProj(V3d_Xpos);
1403 else if (!strcasecmp (buf_ret, "W"))
1405 std::cout << "setup WireFrame display mode" << std::endl;
1406 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1407 if(Ctx->NbCurrents()==0 ||
1408 Ctx->NbSelected()==0)
1409 Ctx->SetDisplayMode(AIS_WireFrame);
1411 if(Ctx->HasOpenedContext()){
1412 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1413 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1416 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1417 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1419 Ctx->UpdateCurrentViewer();
1422 else if (!strcasecmp (buf_ret, "Z"))
1426 cout << "ZClipping OFF" << endl;
1429 aView->SetZClippingType(V3d_OFF);
1433 cout << "ZClipping ON" << endl;
1436 aView->SetZClippingType(V3d_FRONT);
1440 else if (!strcasecmp (buf_ret, ","))
1442 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1444 else if (!strcasecmp (buf_ret, "."))
1446 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1448 else if (*buf_ret == THE_KEY_DELETE)
1450 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1452 && aCtx->NbCurrents() > 0
1453 && aCtx->NbSelected() > 0)
1455 Draw_Interprete ("verase");
1461 Standard_Integer Num = Draw::Atoi(buf_ret);
1462 if(Num>=0 && Num<=7)
1463 ViewerTest::StandardModeActivation(Num);
1467 //==============================================================================
1468 //function : VT_ProcessExpose
1469 //purpose : Redraw the View on an Expose Event
1470 //==============================================================================
1471 void VT_ProcessExpose()
1473 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1474 if (!aView3d.IsNull())
1480 //==============================================================================
1481 //function : VT_ProcessConfigure
1482 //purpose : Resize the View on an Configure Event
1483 //==============================================================================
1484 void VT_ProcessConfigure()
1486 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1487 if (aView3d.IsNull())
1492 aView3d->MustBeResized();
1497 //==============================================================================
1498 //function : VT_ProcessButton1Press
1500 //==============================================================================
1501 Standard_Boolean VT_ProcessButton1Press(
1504 Standard_Boolean pick,
1505 Standard_Boolean shift)
1507 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1509 Standard_Real X, Y, Z;
1511 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1513 Draw::Set(argv[1], X);
1514 Draw::Set(argv[2], Y);
1515 Draw::Set(argv[3], Z);}
1526 //==============================================================================
1527 //function : VT_ProcessButton1Release
1528 //purpose : End selecting
1529 //==============================================================================
1530 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1534 IsDragged = Standard_False;
1535 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1538 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1539 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1543 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1544 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1549 //==============================================================================
1550 //function : VT_ProcessButton3Press
1551 //purpose : Start Rotation
1552 //==============================================================================
1553 void VT_ProcessButton3Press()
1558 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1560 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1563 //==============================================================================
1564 //function : VT_ProcessButton3Release
1565 //purpose : End rotation
1566 //==============================================================================
1567 void VT_ProcessButton3Release()
1574 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1579 //==============================================================================
1580 //function : ProcessZClipMotion
1582 //==============================================================================
1584 void ProcessZClipMotion()
1586 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1587 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1588 static Standard_Real CurZPos = 0.;
1590 //Quantity_Length VDX, VDY;
1591 //a3DView->Size(VDX,VDY);
1592 //Standard_Real VDZ = a3DView->ZSize();
1593 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1595 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1597 // Front = Depth + width/2.
1598 Standard_Real D = 0.5;
1599 Standard_Real W = 0.1;
1605 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1607 a3DView->SetZClippingType(V3d_OFF);
1608 a3DView->SetZClippingDepth(D);
1609 a3DView->SetZClippingWidth(W);
1610 a3DView->SetZClippingType(V3d_FRONT);
1614 X_ButtonPress = X_Motion;
1615 Y_ButtonPress = Y_Motion;
1619 //==============================================================================
1620 //function : ProcessControlButton1Motion
1622 //==============================================================================
1624 static void ProcessControlButton1Motion()
1626 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1628 X_ButtonPress = X_Motion;
1629 Y_ButtonPress = Y_Motion;
1632 //==============================================================================
1633 //function : VT_ProcessControlButton2Motion
1635 //==============================================================================
1636 void VT_ProcessControlButton2Motion()
1638 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1639 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1641 dy = -dy; // Xwindow Y axis is from top to Bottom
1643 ViewerTest::CurrentView()->Panning( dx, dy );
1645 X_ButtonPress = X_Motion;
1646 Y_ButtonPress = Y_Motion;
1649 //==============================================================================
1650 //function : VT_ProcessControlButton3Motion
1651 //purpose : Rotation
1652 //==============================================================================
1653 void VT_ProcessControlButton3Motion()
1657 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1661 //==============================================================================
1662 //function : VT_ProcessMotion
1664 //==============================================================================
1665 void VT_ProcessMotion()
1667 //pre-hilights detected objects at mouse position
1669 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1670 EM->MoveTo(X_Motion, Y_Motion);
1674 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1676 Xpix = X_Motion;Ypix=Y_Motion;
1679 //==============================================================================
1680 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1681 //purpose : Switches to an axonometric, top, left and other views
1682 //==============================================================================
1684 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1686 if ( ViewerTest::CurrentView().IsNull() )
1688 di<<"Call vinit before this command, please"<<"\n";
1692 ViewerTest::CurrentView()->SetProj(ori);
1696 //==============================================================================
1698 //purpose : Switch to an Axonometric view
1699 //Draw arg : No args
1700 //==============================================================================
1702 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1704 return ViewProject(di, V3d_XposYnegZpos);
1707 //==============================================================================
1709 //purpose : Switch to a Top View
1710 //Draw arg : No args
1711 //==============================================================================
1713 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1715 return ViewProject(di, V3d_Zpos);
1718 //==============================================================================
1719 //function : VBottom
1720 //purpose : Switch to a Bottom View
1721 //Draw arg : No args
1722 //==============================================================================
1724 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1726 return ViewProject(di, V3d_Zneg);
1729 //==============================================================================
1731 //purpose : Switch to a Left View
1732 //Draw arg : No args
1733 //==============================================================================
1735 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1737 return ViewProject(di, V3d_Ypos);
1740 //==============================================================================
1742 //purpose : Switch to a Right View
1743 //Draw arg : No args
1744 //==============================================================================
1746 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1748 return ViewProject(di, V3d_Yneg);
1751 //==============================================================================
1753 //purpose : Switch to a Front View
1754 //Draw arg : No args
1755 //==============================================================================
1757 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1759 return ViewProject(di, V3d_Xpos);
1762 //==============================================================================
1764 //purpose : Switch to a Back View
1765 //Draw arg : No args
1766 //==============================================================================
1768 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1770 return ViewProject(di, V3d_Xneg);
1773 //==============================================================================
1775 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1776 //Draw arg : No args
1777 //==============================================================================
1779 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1782 di << "Q : Quit the application" << "\n";
1784 di << "========================="<<"\n";
1785 di << "F : FitAll" << "\n";
1786 di << "T : TopView" << "\n";
1787 di << "B : BottomView" << "\n";
1788 di << "R : RightView" << "\n";
1789 di << "L : LeftView" << "\n";
1790 di << "A : AxonometricView" << "\n";
1791 di << "D : ResetView" << "\n";
1793 di << "========================="<<"\n";
1794 di << "S : Shading" << "\n";
1795 di << "W : Wireframe" << "\n";
1796 di << "H : HidelLineRemoval" << "\n";
1797 di << "U : Unset display mode" << "\n";
1798 di << "Delete : Remove selection from viewer" << "\n";
1800 di << "========================="<<"\n";
1801 di << "Selection mode "<<"\n";
1802 di << "0 : Shape" <<"\n";
1803 di << "1 : Vertex" <<"\n";
1804 di << "2 : Edge" <<"\n";
1805 di << "3 : Wire" <<"\n";
1806 di << "4 : Face" <<"\n";
1807 di << "5 : Shell" <<"\n";
1808 di << "6 : Solid" <<"\n";
1809 di << "7 : Compound" <<"\n";
1811 di << "========================="<<"\n";
1812 di << "Z : Switch Z clipping On/Off" << "\n";
1813 di << ", : Hilight next detected" << "\n";
1814 di << ". : Hilight previous detected" << "\n";
1821 static Standard_Boolean Ppick = 0;
1822 static Standard_Integer Pargc = 0;
1823 static const char** Pargv = NULL;
1826 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1831 if (!ViewerTest_myViews.IsEmpty()) {
1833 WPARAM fwKeys = wParam;
1838 // Delete view from map of views
1839 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1844 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1845 || ViewerTest::CurrentView().IsNull())
1847 // Activate inactive window
1848 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1850 ActivateView (FindViewIdByWindowHandle(hwnd));
1855 IsDragged = Standard_False;
1858 HDC hdc = GetDC( hwnd );
1859 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1860 SetROP2( hdc, R2_NOT );
1861 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1862 ReleaseDC( hwnd, hdc );
1864 const Handle(ViewerTest_EventManager) EM =
1865 ViewerTest::CurrentEventManager();
1866 if ( fwKeys & MK_SHIFT )
1867 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1868 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1870 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1871 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1873 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1875 case WM_LBUTTONDOWN:
1876 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1878 IsDragged = Standard_True;
1879 DragFirst = Standard_True;
1880 X_ButtonPress = LOWORD(lParam);
1881 Y_ButtonPress = HIWORD(lParam);
1883 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1890 HDC hdc = GetDC( hwnd );
1892 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1893 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1894 SetROP2( hdc, R2_NOT );
1897 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1899 DragFirst = Standard_False;
1900 X_Motion = LOWORD(lParam);
1901 Y_Motion = HIWORD(lParam);
1903 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1905 SelectObject( hdc, anObj );
1907 ReleaseDC( hwnd, hdc );
1910 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1914 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1918 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1922 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1929 if ( !ViewerTest::CurrentView().IsNull() ) {
1934 BeginPaint(hwnd, &ps);
1935 EndPaint(hwnd, &ps);
1940 VT_ProcessConfigure();
1944 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1947 c[0] = (char) wParam;
1949 if (wParam == VK_DELETE)
1951 c[0] = THE_KEY_DELETE;
1953 VT_ProcessKeyPress (c);
1961 VT_ProcessButton3Release();
1964 case WM_LBUTTONDOWN:
1965 case WM_MBUTTONDOWN:
1966 case WM_RBUTTONDOWN:
1968 WPARAM fwKeys = wParam;
1972 X_ButtonPress = LOWORD(lParam);
1973 Y_ButtonPress = HIWORD(lParam);
1975 if (Msg == WM_LBUTTONDOWN)
1977 if (fwKeys & MK_CONTROL)
1979 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1983 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1986 else if (Msg == WM_RBUTTONDOWN)
1989 VT_ProcessButton3Press();
1996 //cout << "\t WM_MOUSEMOVE" << endl;
1997 WPARAM fwKeys = wParam;
1998 X_Motion = LOWORD(lParam);
1999 Y_Motion = HIWORD(lParam);
2002 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2004 X_ButtonPress = LOWORD(lParam);
2005 Y_ButtonPress = HIWORD(lParam);
2007 if ( fwKeys & MK_RBUTTON ) {
2009 VT_ProcessButton3Press();
2013 if ( fwKeys & MK_CONTROL ) {
2014 if ( fwKeys & MK_LBUTTON ) {
2015 ProcessControlButton1Motion();
2017 else if ( fwKeys & MK_MBUTTON ||
2018 ((fwKeys&MK_LBUTTON) &&
2019 (fwKeys&MK_RBUTTON) ) ){
2020 VT_ProcessControlButton2Motion();
2022 else if ( fwKeys & MK_RBUTTON ) {
2023 VT_ProcessControlButton3Motion();
2027 else if ( fwKeys & MK_SHIFT ) {
2028 if ( fwKeys & MK_MBUTTON ||
2029 ((fwKeys&MK_LBUTTON) &&
2030 (fwKeys&MK_RBUTTON) ) ) {
2031 cout << "ProcessZClipMotion()" << endl;
2032 ProcessZClipMotion();
2036 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2038 if ((fwKeys & MK_MBUTTON
2039 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2041 ProcessZClipMotion();
2052 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2057 return DefWindowProc( hwnd, Msg, wParam, lParam );
2063 //==============================================================================
2064 //function : ViewerMainLoop
2065 //purpose : Get a Event on the view and dispatch it
2066 //==============================================================================
2069 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2071 Ppick = (argc > 0)? 1 : 0;
2079 cout << "Start picking" << endl;
2081 while ( Ppick == 1 ) {
2082 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2083 if (GetMessage(&msg, NULL, 0, 0) ) {
2084 TranslateMessage(&msg);
2085 DispatchMessage(&msg);
2089 cout << "Picking done" << endl;
2095 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2097 int min( int a, int b )
2105 int max( int a, int b )
2113 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2116 static XEvent aReport;
2117 Standard_Boolean pick = argc > 0;
2118 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2119 XNextEvent (aDisplay, &aReport);
2121 // Handle event for the chosen display connection
2122 switch (aReport.type) {
2125 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2128 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2134 // Activate inactive view
2135 Window aWindow = GetWindowHandle(VT_GetWindow());
2136 if(aWindow != aReport.xfocus.window)
2138 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2147 case ConfigureNotify:
2149 VT_ProcessConfigure();
2158 XComposeStatus status_in_out;
2160 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2161 (char *) buf_ret , 10 ,
2162 &ks_ret , &status_in_out ) ;
2165 buf_ret[ret_len] = '\0' ;
2169 VT_ProcessKeyPress (buf_ret);
2175 X_ButtonPress = aReport.xbutton.x;
2176 Y_ButtonPress = aReport.xbutton.y;
2178 if (aReport.xbutton.button == Button1)
2180 if (aReport.xbutton.state & ControlMask)
2182 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2186 IsDragged = Standard_True;
2187 DragFirst = Standard_True;
2190 else if (aReport.xbutton.button == Button3)
2193 VT_ProcessButton3Press();
2203 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2204 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2205 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2208 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2209 if( aContext.IsNull() )
2211 cout << "The context is null. Please use vinit before createmesh" << endl;
2215 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2216 if( aReport.xbutton.button==1 )
2220 aContext->ShiftSelect();
2229 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2230 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2231 ViewerTest::CurrentView());
2235 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2236 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2237 ViewerTest::CurrentView() );
2240 VT_ProcessButton3Release();
2242 IsDragged = Standard_False;
2245 VT_ProcessButton3Release();
2250 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2256 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2257 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2258 XSetFunction( aDisplay, gc, GXinvert );
2261 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2263 X_Motion = aReport.xmotion.x;
2264 Y_Motion = aReport.xmotion.y;
2265 DragFirst = Standard_False;
2267 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2271 X_Motion = aReport.xmotion.x;
2272 Y_Motion = aReport.xmotion.y;
2274 // remove all the ButtonMotionMaskr
2275 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2277 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2278 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2280 Quantity_Length VDX, VDY;
2282 ViewerTest::CurrentView()->Size(VDX,VDY);
2283 Standard_Real VDZ =0 ;
2284 VDZ = ViewerTest::CurrentView()->ZSize();
2286 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2288 Quantity_Length dx = 0 ;
2289 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2293 dx = dx / VDX * VDZ;
2297 ViewerTest::CurrentView()->Redraw();
2301 if ( aReport.xmotion.state & ControlMask ) {
2302 if ( aReport.xmotion.state & Button1Mask ) {
2303 ProcessControlButton1Motion();
2305 else if ( aReport.xmotion.state & Button2Mask ) {
2306 VT_ProcessControlButton2Motion();
2308 else if ( aReport.xmotion.state & Button3Mask ) {
2309 VT_ProcessControlButton3Motion();
2323 //==============================================================================
2324 //function : VProcessEvents
2325 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2326 // event in the Viewer window
2327 //==============================================================================
2329 static void VProcessEvents(ClientData,int)
2331 NCollection_Vector<int> anEventNumbers;
2332 // Get number of messages from every display
2333 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2334 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2336 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2338 // Handle events for every display
2339 int anEventIter = 0;
2340 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2341 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2343 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2344 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2346 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2347 int anEventResult = ViewerMainLoop( 0, NULL);
2348 // If window is closed or context was not found finish current event processing loop
2354 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2359 //==============================================================================
2360 //function : OSWindowSetup
2361 //purpose : Setup for the X11 window to be able to cath the event
2362 //==============================================================================
2365 static void OSWindowSetup()
2367 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2370 Window window = VT_GetWindow()->XWindow();
2371 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2372 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2373 XSynchronize(aDisplay, 1);
2375 // X11 : For keyboard on SUN
2377 wmhints.flags = InputHint;
2380 XSetWMHints( aDisplay, window, &wmhints);
2382 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2383 ButtonPressMask | ButtonReleaseMask |
2384 StructureNotifyMask |
2386 Button1MotionMask | Button2MotionMask |
2387 Button3MotionMask | FocusChangeMask
2389 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2390 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2392 XSynchronize(aDisplay, 0);
2401 //==============================================================================
2404 //purpose : Fitall, no DRAW arguments
2405 //Draw arg : No args
2406 //==============================================================================
2408 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2410 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2411 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2412 if (V.IsNull() == Standard_False) {
2414 } else if (aView.IsNull() == Standard_False) {
2420 //==============================================================================
2422 //purpose : ZFitall, no DRAW arguments
2423 //Draw arg : No args
2424 //==============================================================================
2426 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2428 Handle(V3d_View) V = ViewerTest::CurrentView();
2429 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2432 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2434 Handle(V3d_View) V = ViewerTest::CurrentView();
2435 if ( !V.IsNull() ) V->Redraw(); return 0;
2439 //==============================================================================
2441 //purpose : Remove all the object from the viewer
2442 //Draw arg : No args
2443 //==============================================================================
2445 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2447 Handle(V3d_View) V = ViewerTest::CurrentView();
2449 ViewerTest::Clear();
2453 //==============================================================================
2456 //==============================================================================
2458 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2459 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2462 di << argv[0] << "Invalid number of arguments" << "\n";
2466 while (ViewerMainLoop( argc, argv)) {
2472 //==============================================================================
2473 //function : InitViewerTest
2474 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2475 //==============================================================================
2477 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2479 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2480 ViewerTest::SetAISContext(theContext);
2481 aViewer->InitActiveViews();
2482 Handle(V3d_View) aView = aViewer->ActiveView();
2483 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2484 ViewerTest::ResetEventManager();
2485 Handle(Aspect_Window) aWindow = aView->Window();
2486 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2488 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2490 static int aFirst = 1;
2492 #if TCL_MAJOR_VERSION < 8
2493 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2494 TK_READABLE, VProcessEvents, (ClientData) 0);
2496 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2497 TK_READABLE, VProcessEvents, (ClientData) 0);
2504 //==============================================================================
2506 //purpose : Load image as background
2507 //==============================================================================
2509 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2511 if (argc < 2 || argc > 3)
2513 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2514 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2518 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2519 if(AISContext.IsNull())
2521 di << "use 'vinit' command before " << argv[0] << "\n";
2525 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2528 const char* szType = argv[2];
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";
2541 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2542 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2547 //==============================================================================
2548 //function : VSetBgMode
2549 //purpose : Change background image fill type
2550 //==============================================================================
2552 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2556 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2557 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2561 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2562 if(AISContext.IsNull())
2564 di << "use 'vinit' command before " << argv[0] << "\n";
2567 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2568 const char* szType = argv[1];
2569 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2570 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2571 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2572 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2575 di << "Wrong fill type : " << szType << "\n";
2576 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2579 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2580 V3dView->SetBgImageStyle(aFillType, Standard_True);
2584 //==============================================================================
2585 //function : VSetGradientBg
2586 //purpose : Mount gradient background
2587 //==============================================================================
2588 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2592 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2593 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2594 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2595 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2599 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2600 if(AISContext.IsNull())
2602 di << "use 'vinit' command before " << argv[0] << "\n";
2608 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2609 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2610 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2611 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2613 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2614 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2615 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2617 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2618 int aType = Draw::Atoi(argv[7]);
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->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2636 //==============================================================================
2637 //function : VSetGradientBgMode
2638 //purpose : Change gradient background fill style
2639 //==============================================================================
2640 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2644 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2645 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2646 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2650 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2651 if(AISContext.IsNull())
2653 di << "use 'vinit' command before " << argv[0] << "\n";
2658 int aType = Draw::Atoi(argv[1]);
2659 if( aType < 0 || aType > 8 )
2661 di << "Wrong fill type " << "\n";
2662 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2663 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2667 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2669 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2670 V3dView->SetBgGradientStyle( aMethod, 1 );
2676 //==============================================================================
2677 //function : VSetColorBg
2678 //purpose : Set color background
2679 //==============================================================================
2680 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2684 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2685 di << "R,G,B = [0..255]" << "\n";
2689 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2690 if(AISContext.IsNull())
2692 di << "use 'vinit' command before " << argv[0] << "\n";
2698 Standard_Real R = Draw::Atof(argv[1])/255.;
2699 Standard_Real G = Draw::Atof(argv[2])/255.;
2700 Standard_Real B = Draw::Atof(argv[3])/255.;
2701 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2703 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2704 V3dView->SetBackgroundColor( aColor );
2711 //==============================================================================
2713 //purpose : View Scaling
2714 //==============================================================================
2716 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2718 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2719 if ( V3dView.IsNull() ) return 1;
2722 di << argv[0] << "Invalid number of arguments" << "\n";
2725 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2728 //==============================================================================
2729 //function : VTestZBuffTrihedron
2730 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2731 //==============================================================================
2733 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2735 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2736 if ( V3dView.IsNull() ) return 1;
2738 V3dView->ZBufferTriedronSetup();
2741 // Set up default trihedron parameters
2742 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2746 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2747 const char* aPosType = argv[1];
2749 if ( strcmp(aPosType, "center") == 0 )
2751 aPosition = Aspect_TOTP_CENTER;
2753 if (strcmp(aPosType, "left_lower") == 0)
2755 aPosition = Aspect_TOTP_LEFT_LOWER;
2757 if (strcmp(aPosType, "left_upper") == 0)
2759 aPosition = Aspect_TOTP_LEFT_UPPER;
2761 if (strcmp(aPosType, "right_lower") == 0)
2763 aPosition = Aspect_TOTP_RIGHT_LOWER;
2765 if (strcmp(aPosType, "right_upper") == 0)
2767 aPosition = Aspect_TOTP_RIGHT_UPPER;
2770 di << argv[1] << " Invalid type of alignment" << "\n";
2771 di << "Must be one of [ center, left_lower," << "\n";
2772 di << "left_upper, right_lower, right_upper ]" << "\n";
2776 Standard_Real R = Draw::Atof(argv[2])/255.;
2777 Standard_Real G = Draw::Atof(argv[3])/255.;
2778 Standard_Real B = Draw::Atof(argv[4])/255.;
2779 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2781 Standard_Real aScale = Draw::Atof(argv[5]);
2785 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2789 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2790 const char* aPresType = argv[6];
2792 if ( strcmp(aPresType, "wireframe") == 0 )
2794 aPresentation = V3d_WIREFRAME;
2796 if (strcmp(aPresType, "zbuffer") == 0)
2798 aPresentation = V3d_ZBUFFER;
2801 di << argv[6] << " Invalid type of visualization" << "\n";
2802 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2806 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2810 di << argv[0] << " Invalid number of arguments" << "\n";
2819 //==============================================================================
2820 //function : VRotate
2821 //purpose : Camera Rotating
2822 //==============================================================================
2824 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2825 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2826 if ( V3dView.IsNull() ) {
2831 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2833 } else if ( argc == 7 ) {
2834 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]) );
2837 di << argv[0] << " Invalid number of arguments" << "\n";
2842 //==============================================================================
2844 //purpose : View zoom in / out (relative to current zoom)
2845 //==============================================================================
2847 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2848 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2849 if ( V3dView.IsNull() ) {
2854 Standard_Real coef = Draw::Atof(argv[1]);
2855 if ( coef <= 0.0 ) {
2856 di << argv[1] << "Invalid value" << "\n";
2859 V3dView->SetZoom( Draw::Atof(argv[1]) );
2862 di << argv[0] << " Invalid number of arguments" << "\n";
2867 //==============================================================================
2869 //purpose : View panning (in pixels)
2870 //==============================================================================
2872 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2873 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2874 if ( V3dView.IsNull() ) return 1;
2877 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2880 di << argv[0] << " Invalid number of arguments" << "\n";
2886 //==============================================================================
2887 //function : VExport
2888 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2889 //==============================================================================
2891 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2893 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2894 if (V3dView.IsNull())
2899 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2903 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2904 TCollection_AsciiString aFormatStr;
2906 TCollection_AsciiString aFileName (argv[1]);
2907 Standard_Integer aLen = aFileName.Length();
2911 aFormatStr = TCollection_AsciiString (argv[2]);
2915 if (aFileName.Value (aLen - 2) == '.')
2917 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2919 else if (aFileName.Value (aLen - 3) == '.')
2921 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2925 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2931 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2935 aFormatStr.UpperCase();
2936 if (aFormatStr == "PS")
2937 anExpFormat = Graphic3d_EF_PostScript;
2938 else if (aFormatStr == "EPS")
2939 anExpFormat = Graphic3d_EF_EnhPostScript;
2940 else if (aFormatStr == "TEX")
2941 anExpFormat = Graphic3d_EF_TEX;
2942 else if (aFormatStr == "PDF")
2943 anExpFormat = Graphic3d_EF_PDF;
2944 else if (aFormatStr == "SVG")
2945 anExpFormat = Graphic3d_EF_SVG;
2946 else if (aFormatStr == "PGF")
2947 anExpFormat = Graphic3d_EF_PGF;
2948 else if (aFormatStr == "EMF")
2949 anExpFormat = Graphic3d_EF_EMF;
2952 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2957 if (!V3dView->View()->Export (argv[1], anExpFormat))
2959 di << "Error: export of image to " << aFormatStr << " failed!\n";
2962 catch (Standard_Failure)
2964 di << "Error: export of image to " << aFormatStr << " failed";
2965 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2970 //==============================================================================
2971 //function : VColorScale
2972 //purpose : representation color scale
2973 //==============================================================================
2974 #include <V3d_ColorScale.hxx>
2976 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2978 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2980 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2984 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2985 if(aContext.IsNull()) {
2986 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2990 Standard_Real minRange = 0. , maxRange = 100. ;
2992 Standard_Integer numIntervals = 10 ;
2993 Standard_Integer textHeight = 16;
2994 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2995 Standard_Real X = 0., Y = 0. ;
3001 minRange = Draw::Atof( argv[1] );
3002 maxRange = Draw::Atof( argv[2] );
3003 numIntervals = Draw::Atoi( argv[3] );
3006 textHeight = Draw::Atoi( argv[4] );
3008 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
3011 X = Draw::Atof( argv[6] );
3012 Y = Draw::Atof( argv[7] );
3015 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3016 if ( curView.IsNull( ) )
3018 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3019 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3020 if( ! aCS.IsNull( ) )
3022 aCS->SetPosition( X , Y );
3023 aCS->SetHeight( 0.95) ;
3024 aCS->SetTextHeight( textHeight );
3025 aCS->SetRange( minRange , maxRange );
3026 aCS->SetNumberOfIntervals( numIntervals );
3027 aCS->SetLabelPosition( position );
3028 if( !curView->ColorScaleIsDisplayed() )
3029 curView->ColorScaleDisplay( );
3034 //==============================================================================
3035 //function : VGraduatedTrihedron
3036 //purpose : Displays a graduated trihedron
3037 //==============================================================================
3039 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3041 const char *str = arg;
3044 unsigned short c1 = *str++;
3045 unsigned short c2 = *str++;
3046 if (!c1 || !c2) break;
3047 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3051 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3054 if (argc != 2 && argc < 5)
3056 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3057 di<<"Usage: type help "<<argv[0]<<"\n";
3058 return 1; //TCL_ERROR
3061 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3063 // Create 3D view if it doesn't exist
3064 if ( aV3dView.IsNull() )
3066 ViewerTest::ViewerInit();
3067 aV3dView = ViewerTest::CurrentView();
3068 if( aV3dView.IsNull() )
3070 di << "Error: Cannot create a 3D view\n";
3071 return 1; //TCL_ERROR
3075 // Erase (==0) or display (!=0)
3076 const int display = Draw::Atoi(argv[1]);
3081 TCollection_AsciiString font;
3083 font.AssignCat("Courier");
3085 font.AssignCat(argv[5]);
3087 // Text is multibyte
3088 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3091 TCollection_ExtendedString xname, yname, zname;
3096 AddMultibyteString(xname, argv[2]);
3097 AddMultibyteString(yname, argv[3]);
3098 AddMultibyteString(zname, argv[4]);
3114 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3115 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3116 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3117 Standard_True/*drawgrid*/,
3118 Standard_True/*drawaxes*/,
3119 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3120 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3121 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3122 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3123 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3124 Quantity_NOC_WHITE/*gridcolor*/,
3125 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3126 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3129 aV3dView->GraduatedTrihedronErase();
3131 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3137 //==============================================================================
3138 //function : VPrintView
3139 //purpose : Test printing algorithm, print the view to image file with given
3140 // width and height. Printing implemented only for WNT.
3141 //==============================================================================
3142 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3146 di << "Printing implemented only for wnt!\n";
3150 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3151 Handle(V3d_View) aView = NULL;
3152 aContextAIS = ViewerTest::GetAISContext();
3153 if (!aContextAIS.IsNull())
3155 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3156 Vwr->InitActiveViews();
3157 if(Vwr->MoreActiveViews())
3158 aView = Vwr->ActiveView();
3164 di << "Call vinit before!\n";
3169 di << "Use: " << argv[0];
3170 di << " width height filename [print algo=0]\n";
3171 di << "width, height of the intermediate buffer for operation\n";
3172 di << "algo : {0|1}\n";
3173 di << " 0 - stretch algorithm\n";
3174 di << " 1 - tile algorithm\n";
3175 di << "test printing algorithms into an intermediate buffer\n";
3176 di << "with saving output to an image file\n";
3180 // get the input params
3181 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3182 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3183 Standard_Integer aMode = 0;
3184 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3186 aMode = Draw::Atoi (argv[4]);
3188 // check the input parameters
3189 if (aWidth <= 0 || aHeight <= 0)
3191 di << "Width and height must be positive values!\n";
3194 if (aMode != 0 && aMode != 1)
3197 // define compatible bitmap
3198 HDC anDC = CreateCompatibleDC(0);
3199 BITMAPINFO aBitmapData;
3200 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3201 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3202 aBitmapData.bmiHeader.biWidth = aWidth ;
3203 aBitmapData.bmiHeader.biHeight = aHeight;
3204 aBitmapData.bmiHeader.biPlanes = 1;
3205 aBitmapData.bmiHeader.biBitCount = 24;
3206 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3207 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3208 aBitmapData.bmiHeader.biClrUsed = 0;
3209 aBitmapData.bmiHeader.biClrImportant = 0;
3210 aBitmapData.bmiHeader.biCompression = BI_RGB;
3211 aBitmapData.bmiHeader.biSizeImage = 0;
3213 // Create Device Independent Bitmap
3214 void* aBitsOut = NULL;
3215 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3216 &aBitsOut, NULL, 0);
3217 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3219 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3220 if (aBitsOut != NULL)
3223 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3225 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3227 // succesfully printed into an intermediate buffer
3230 Image_PixMap aWrapper;
3231 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3232 aWrapper.SetTopDown (false);
3234 Image_AlienPixMap anImageBitmap;
3235 anImageBitmap.InitCopy (aWrapper);
3236 isSaved = anImageBitmap.Save (aFileName);
3240 di << "Print operation failed due to printing errors or\n";
3241 di << "insufficient memory available\n";
3242 di << "Please, try to use smaller dimensions for this test\n";
3243 di << "command, as it allocates intermediate buffer for storing\n";
3244 di << "the result\n";
3249 di << "Can't allocate memory for intermediate buffer\n";
3250 di << "Please use smaller dimensions\n";
3255 SelectObject (anDC, anOldBitmap);
3256 DeleteObject (aMemoryBitmap);
3262 di << "Save to file operation failed. This operation may fail\n";
3263 di << "if you don't have enough available memory, then you can\n";
3264 di << "use smaller dimensions for the output file\n";
3273 //==============================================================================
3274 //function : VZLayer
3275 //purpose : Test z layer operations for v3d viewer
3276 //==============================================================================
3277 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3279 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3280 if (aContextAIS.IsNull())
3282 di << "Call vinit before!\n";
3287 di << "Use: vzlayer " << argv[0];
3288 di << " add/del/get [id]\n";
3289 di << " add - add new z layer to viewer and print its id\n";
3290 di << " del - del z layer by its id\n";
3291 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3292 di << "id - the layer identificator value defined when removing z layer\n";
3296 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3297 if (aViewer.IsNull())
3299 di << "No active viewer!\n";
3303 // perform operation
3304 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3307 Standard_Integer aNewId;
3308 if (!aViewer->AddZLayer (aNewId))
3310 di << "Impossible to add new z layer!\n";
3314 di << "New z layer added with index: " << aNewId << "\n";
3316 else if (anOp == "del")
3320 di << "Please also provide as argument id of z layer to remove\n";
3324 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3325 if (!aViewer->RemoveZLayer (aDelId))
3327 di << "Impossible to remove the z layer or invalid id!\n";
3331 di << "Z layer " << aDelId << " has been removed\n";
3333 else if (anOp == "get")
3335 TColStd_SequenceOfInteger anIds;
3336 aViewer->GetAllZLayers (anIds);
3337 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3339 di << anIds.Value (aSeqIdx) << " ";
3346 di << "Invalid operation, please use { add / del / get }\n";
3353 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3355 // this class provides a presentation of text item in v3d view under-/overlayer
3356 class V3d_TextItem : public Visual3d_LayerItem
3361 DEFINE_STANDARD_RTTI(V3d_TextItem)
3364 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3365 const Standard_Real theX1,
3366 const Standard_Real theY1,
3367 const Standard_Real theHeight,
3368 const TCollection_AsciiString& theFontName,
3369 const Quantity_Color& theColor,
3370 const Quantity_Color& theSubtitleColor,
3371 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3372 const Handle(Visual3d_Layer)& theLayer);
3375 Standard_EXPORT void RedrawLayerPrs();
3381 TCollection_AsciiString myText;
3382 Standard_Real myHeight;
3383 Handle(Visual3d_Layer) myLayer;
3384 Quantity_Color myColor;
3385 Quantity_Color mySubtitleColor;
3386 Aspect_TypeOfDisplayText myType;
3387 TCollection_AsciiString myFontName;
3390 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3391 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3393 // create and add to display the text item
3394 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3395 const Standard_Real theX1,
3396 const Standard_Real theY1,
3397 const Standard_Real theHeight,
3398 const TCollection_AsciiString& theFontName,
3399 const Quantity_Color& theColor,
3400 const Quantity_Color& theSubtitleColor,
3401 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3402 const Handle(Visual3d_Layer)& theLayer)
3403 : myX1 (theX1), myY1 (theY1),
3405 myHeight (theHeight),
3408 mySubtitleColor (theSubtitleColor),
3409 myType (theTypeOfDisplay),
3410 myFontName (theFontName)
3412 if (!myLayer.IsNull ())
3413 myLayer->AddLayerItem (this);
3417 void V3d_TextItem::RedrawLayerPrs ()
3419 if (myLayer.IsNull ())
3422 myLayer->SetColor (myColor);
3423 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3424 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3427 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3429 // The Visual3d_LayerItem line item for "vlayerline" command
3430 // it provides a presentation of line with user-defined
3431 // linewidth, linetype and transparency.
3432 class V3d_LineItem : public Visual3d_LayerItem
3436 DEFINE_STANDARD_RTTI(V3d_LineItem)
3439 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3440 Standard_Real X2, Standard_Real Y2,
3441 V3d_LayerMgrPointer theLayerMgr,
3442 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3443 Standard_Real theWidth = 0.5,
3444 Standard_Real theTransp = 1.0);
3447 Standard_EXPORT void RedrawLayerPrs();
3451 Standard_Real myX1, myY1, myX2, myY2;
3452 V3d_LayerMgrPointer myLayerMgr;
3453 Aspect_TypeOfLine myType;
3454 Standard_Real myWidth;
3455 Standard_Real myTransparency;
3458 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3459 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3461 // default constructor for line item
3462 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3463 Standard_Real X2, Standard_Real Y2,
3464 V3d_LayerMgrPointer theLayerMgr,
3465 Aspect_TypeOfLine theType,
3466 Standard_Real theWidth,
3467 Standard_Real theTransp) :
3468 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3469 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3471 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3472 myLayerMgr->Overlay()->AddLayerItem (this);
3476 void V3d_LineItem::RedrawLayerPrs ()
3478 Handle (Visual3d_Layer) aOverlay;
3481 aOverlay = myLayerMgr->Overlay();
3483 if (!aOverlay.IsNull())
3485 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3486 aOverlay->SetColor(aColor);
3487 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3488 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3489 aOverlay->BeginPolyline();
3490 aOverlay->AddVertex(myX1, myY1);
3491 aOverlay->AddVertex(myX2, myY2);
3492 aOverlay->ClosePrimitive();
3496 //=============================================================================
3497 //function : VLayerLine
3498 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3499 // : linewidth, transparency coefficient
3500 //============================================================================
3501 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3503 // get the active view
3504 Handle(V3d_View) aView = ViewerTest::CurrentView();
3507 di << "Call vinit before!\n";
3512 di << "Use: " << argv[0];
3513 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3514 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3515 di << " 0 - solid \n";
3516 di << " 1 - dashed \n";
3517 di << " 2 - dot \n";
3518 di << " 3 - dashdot\n";
3519 di << " transparency : { 0.0 - 1.0 } \n";
3520 di << " 0.0 - transparent\n";
3521 di << " 1.0 - visible \n";
3525 // get the input params
3526 Standard_Real X1 = Draw::Atof(argv[1]);
3527 Standard_Real Y1 = Draw::Atof(argv[2]);
3528 Standard_Real X2 = Draw::Atof(argv[3]);
3529 Standard_Real Y2 = Draw::Atof(argv[4]);
3531 Standard_Real aWidth = 0.5;
3532 Standard_Integer aType = 0;
3533 Standard_Real aTransparency = 1.0;
3537 aWidth = Draw::Atof(argv[5]);
3541 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3546 aTransparency = Draw::Atof(argv[7]);
3547 if (aTransparency < 0 || aTransparency > 1.0)
3548 aTransparency = 1.0;
3551 // select appropriate line type
3552 Aspect_TypeOfLine aLineType;
3556 aLineType = Aspect_TOL_DASH;
3560 aLineType = Aspect_TOL_DOT;
3564 aLineType = Aspect_TOL_DOTDASH;
3568 aLineType = Aspect_TOL_SOLID;
3571 // replace layer manager
3572 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3573 aView->SetLayerMgr(aMgr);
3576 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3582 aView->MustBeResized();
3588 //=======================================================================
3589 //function : VOverlayText
3590 //purpose : Test text displaying in view overlay
3591 //=======================================================================
3592 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3594 // get the active view
3595 Handle(V3d_View) aView = ViewerTest::CurrentView();
3598 di << "No active view. Please call vinit.\n";
3601 else if (argc < 4 || argc > 13)
3603 di << "Use: " << argv[0];
3604 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3605 di << "[background_color: R G B]\n";
3606 di << " height - pixel height of the text (default=10.0)\n";
3607 di << " font_name - name of font (default=courier)\n";
3608 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3609 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
3610 di << " background_color- R G B values used for subtitle and decal text\n";
3611 di << "(default=255.0 255.0 255.0)\n";
3615 TCollection_AsciiString aText (argv[1]);
3616 Standard_Real aPosX = Draw::Atof(argv[2]);
3617 Standard_Real aPosY = Draw::Atof(argv[3]);
3618 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3621 TCollection_AsciiString aFontName = "Courier";
3623 aFontName = TCollection_AsciiString (argv[5]);
3626 Quantity_Parameter aColorRed = 1.0;
3627 Quantity_Parameter aColorGreen = 1.0;
3628 Quantity_Parameter aColorBlue = 1.0;
3631 aColorRed = Draw::Atof (argv[6])/255.;
3632 aColorGreen = Draw::Atof (argv[7])/255.;
3633 aColorBlue = Draw::Atof (argv[8])/255.;
3637 TCollection_AsciiString aDispStr;
3639 aDispStr = TCollection_AsciiString (argv[9]);
3641 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3642 if (aDispStr.IsEqual ("subtitle"))
3643 aTextType = Aspect_TODT_SUBTITLE;
3644 else if (aDispStr.IsEqual ("decal"))
3645 aTextType = Aspect_TODT_DEKALE;
3646 else if (aDispStr.IsEqual ("blend"))
3647 aTextType = Aspect_TODT_BLEND;
3650 Quantity_Parameter aSubRed = 1.0;
3651 Quantity_Parameter aSubGreen = 1.0;
3652 Quantity_Parameter aSubBlue = 1.0;
3655 aSubRed = Draw::Atof (argv[10])/255.;
3656 aSubGreen = Draw::Atof (argv[11])/255.;
3657 aSubBlue = Draw::Atof (argv[12])/255.;
3660 // check fo current overlay
3661 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3662 if (anOverlay.IsNull ())
3664 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3665 anOverlay = aMgr->Overlay ();
3666 aView->SetLayerMgr (aMgr);
3669 Quantity_Color aTextColor (aColorRed, aColorGreen,
3670 aColorBlue, Quantity_TOC_RGB);
3671 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3672 aSubBlue, Quantity_TOC_RGB);
3675 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3676 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3679 aView->MustBeResized();
3685 //==============================================================================
3688 //==============================================================================
3690 static int VGrid (Draw_Interpretor& /*theDI*/,
3691 Standard_Integer theArgNb,
3692 const char** theArgVec)
3694 // get the active view
3695 Handle(V3d_View) aView = ViewerTest::CurrentView();
3696 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3697 if (aView.IsNull() || aViewer.IsNull())
3699 std::cerr << "No active view. Please call vinit.\n";
3703 Aspect_GridType aType = aViewer->GridType();
3704 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3706 Standard_Integer anIter = 1;
3707 for (; anIter < theArgNb; ++anIter)
3709 const char* aValue = theArgVec[anIter];
3712 aType = Aspect_GT_Rectangular;
3714 else if (*aValue == 'c')
3716 aType = Aspect_GT_Circular;
3718 else if (*aValue == 'l')
3720 aMode = Aspect_GDM_Lines;
3722 else if (*aValue == 'p')
3724 aMode = Aspect_GDM_Points;
3726 else if (strcmp (aValue, "off" ) == 0)
3728 aViewer->DeactivateGrid();
3737 Standard_Integer aTail = (theArgNb - anIter);
3740 aViewer->ActivateGrid (aType, aMode);
3743 else if (aTail != 2 && aTail != 5)
3745 std::cerr << "Incorrect arguments number! Usage:\n"
3746 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3750 Quantity_Length anOriginX, anOriginY;
3751 Quantity_PlaneAngle aRotAngle;
3752 if (aType == Aspect_GT_Rectangular)
3754 Quantity_Length aRStepX, aRStepY;
3755 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3757 anOriginX = Draw::Atof (theArgVec[anIter++]);
3758 anOriginY = Draw::Atof (theArgVec[anIter++]);
3761 aRStepX = Draw::Atof (theArgVec[anIter++]);
3762 aRStepY = Draw::Atof (theArgVec[anIter++]);
3763 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3765 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3766 aViewer->ActivateGrid (aType, aMode);
3768 else if (aType == Aspect_GT_Circular)
3770 Quantity_Length aRadiusStep;
3771 Standard_Integer aDivisionNumber;
3772 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3774 anOriginX = Draw::Atof (theArgVec[anIter++]);
3775 anOriginY = Draw::Atof (theArgVec[anIter++]);
3778 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3779 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3780 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3783 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3784 aViewer->ActivateGrid (aType, aMode);
3790 //==============================================================================
3793 //==============================================================================
3795 static int VFps (Draw_Interpretor& theDI,
3796 Standard_Integer theArgNb,
3797 const char** theArgVec)
3799 // get the active view
3800 Handle(V3d_View) aView = ViewerTest::CurrentView();
3803 std::cerr << "No active view. Please call vinit.\n";
3807 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3810 std::cerr << "Incorrect arguments!\n";
3814 // the time is meaningless for first call
3815 // due to async OpenGl rendering
3818 // redraw view in loop to estimate average values
3821 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3827 const Standard_Real aTime = aTimer.ElapsedTime();
3828 aTimer.OSD_Chronometer::Show (aCpu);
3830 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3831 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3833 // return statistics
3834 theDI << "FPS: " << aFpsAver << "\n"
3835 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3840 //==============================================================================
3841 //function : VGlDebug
3843 //==============================================================================
3845 static int VGlDebug (Draw_Interpretor& theDI,
3846 Standard_Integer theArgNb,
3847 const char** theArgVec)
3851 Handle(V3d_View) aView = ViewerTest::CurrentView();
3854 std::cerr << "No active view. Please call vinit.\n";
3858 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3859 "GL_ARB_debug_output");
3860 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3861 theDI << (isActive ? "1" : "0");
3865 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3869 //==============================================================================
3872 //==============================================================================
3874 static int VVbo (Draw_Interpretor& theDI,
3875 Standard_Integer theArgNb,
3876 const char** theArgVec)
3878 const Standard_Boolean toSet = (theArgNb > 1);
3879 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3882 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
3886 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3887 if (aContextAIS.IsNull())
3891 std::cerr << "No active view!\n";
3895 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3896 if (!aDriver.IsNull())
3900 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3904 aDriver->ChangeOptions().vboDisable = toUseVbo;
3911 //==============================================================================
3914 //==============================================================================
3916 static int VCaps (Draw_Interpretor& theDI,
3917 Standard_Integer theArgNb,
3918 const char** theArgVec)
3920 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
3921 Handle(OpenGl_GraphicDriver) aDriver;
3922 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3923 if (!aContextAIS.IsNull())
3925 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3926 aCaps = &aDriver->ChangeOptions();
3931 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
3932 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
3933 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
3937 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3939 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
3940 if (anArg.Search ("vbo=") > -1)
3942 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3944 else if (anArg.Search ("sprites=") > -1)
3946 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3948 else if (anArg.Search ("soft=") > -1)
3950 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
3954 std::cerr << "Unknown argument: " << anArg << "\n";
3957 if (aCaps != &ViewerTest_myDefaultCaps)
3959 ViewerTest_myDefaultCaps = *aCaps;
3964 //==============================================================================
3965 //function : VMemGpu
3967 //==============================================================================
3969 static int VMemGpu (Draw_Interpretor& theDI,
3970 Standard_Integer theArgNb,
3971 const char** theArgVec)
3974 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3975 if (aContextAIS.IsNull())
3977 std::cerr << "No active view. Please call vinit.\n";
3981 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3982 if (aDriver.IsNull())
3984 std::cerr << "Graphic driver not available.\n";
3988 Standard_Size aFreeBytes = 0;
3989 TCollection_AsciiString anInfo;
3990 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3992 std::cerr << "Information not available.\n";
3996 if (theArgNb > 1 && *theArgVec[1] == 'f')
3998 theDI << Standard_Real (aFreeBytes);
4008 // ==============================================================================
4009 // function : VReadPixel
4011 // ==============================================================================
4012 static int VReadPixel (Draw_Interpretor& theDI,
4013 Standard_Integer theArgNb,
4014 const char** theArgVec)
4016 // get the active view
4017 Handle(V3d_View) aView = ViewerTest::CurrentView();
4020 std::cerr << "No active view. Please call vinit.\n";
4023 else if (theArgNb < 3)
4025 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4029 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4030 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4032 Standard_Integer aWidth, aHeight;
4033 aView->Window()->Size (aWidth, aHeight);
4034 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4035 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4036 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4038 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4042 Standard_Boolean toShowName = Standard_False;
4043 Standard_Boolean toShowHls = Standard_False;
4044 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4046 const char* aParam = theArgVec[anIter];
4047 if ( strcasecmp( aParam, "rgb" ) == 0 )
4049 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4050 aBufferType = Graphic3d_BT_RGB;
4052 else if ( strcasecmp( aParam, "hls" ) == 0 )
4054 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4055 aBufferType = Graphic3d_BT_RGB;
4056 toShowHls = Standard_True;
4058 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4060 aFormat = Image_PixMap::ImgRGBF;
4061 aBufferType = Graphic3d_BT_RGB;
4063 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4065 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4066 aBufferType = Graphic3d_BT_RGBA;
4068 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4070 aFormat = Image_PixMap::ImgRGBAF;
4071 aBufferType = Graphic3d_BT_RGBA;
4073 else if ( strcasecmp( aParam, "depth" ) == 0 )
4075 aFormat = Image_PixMap::ImgGrayF;
4076 aBufferType = Graphic3d_BT_Depth;
4078 else if ( strcasecmp( aParam, "name" ) == 0 )
4080 toShowName = Standard_True;
4084 Image_PixMap anImage;
4085 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4087 std::cerr << "Image allocation failed\n";
4090 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4092 std::cerr << "Image dump failed\n";
4096 Quantity_Parameter anAlpha;
4097 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4100 if (aBufferType == Graphic3d_BT_RGBA)
4102 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
4106 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
4111 switch (aBufferType)
4114 case Graphic3d_BT_RGB:
4118 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
4122 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
4126 case Graphic3d_BT_RGBA:
4128 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
4131 case Graphic3d_BT_Depth:
4133 theDI << aColor.Red() << "\n";
4142 //==============================================================================
4143 //function : VDiffImage
4144 //purpose : The draw-command compares two images.
4145 //==============================================================================
4147 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4151 theDI << "Not enough arguments.\n";
4156 const char* anImgPathRef = theArgVec[1];
4157 const char* anImgPathNew = theArgVec[2];
4159 // get string tolerance and check its validity
4160 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4161 if (aTolColor < 0.0)
4163 if (aTolColor > 1.0)
4166 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4167 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4169 // image file of difference
4170 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4172 // compare the images
4173 Image_Diff aComparer;
4174 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4179 aComparer.SetColorTolerance (aTolColor);
4180 aComparer.SetBorderFilterOn (isBorderFilterOn);
4181 Standard_Integer aDiffColorsNb = aComparer.Compare();
4182 theDI << aDiffColorsNb << "\n";
4184 // save image of difference
4185 if (aDiffImagePath != NULL)
4187 aComparer.SaveDiffImage (aDiffImagePath);
4193 //=======================================================================
4194 //function : VSelect
4195 //purpose : Emulates different types of selection by mouse:
4196 // 1) single click selection
4197 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4198 // 3) selection with polygon having corners at
4199 // pixel positions (x1,y1),...,(xn,yn)
4200 // 4) any of these selections with shift button pressed
4201 //=======================================================================
4202 static Standard_Integer VSelect (Draw_Interpretor& di,
4203 Standard_Integer argc,
4208 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4212 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4213 if(myAIScontext.IsNull())
4215 di << "use 'vinit' command before " << argv[0] << "\n";
4218 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4219 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4220 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4223 if(isShiftSelection)
4224 aCurrentEventManager->ShiftSelect();
4226 aCurrentEventManager->Select();
4230 if(isShiftSelection)
4231 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4233 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4237 Standard_Integer anUpper = 0;
4239 if(isShiftSelection)
4240 anUpper = (argc-1)/2;
4243 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4245 for(Standard_Integer i=1;i<=anUpper;++i)
4246 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4248 if(isShiftSelection)
4249 aCurrentEventManager->ShiftSelect(aPolyline);
4251 aCurrentEventManager->Select(aPolyline);
4256 //=======================================================================
4257 //function : VMoveTo
4258 //purpose : Emulates cursor movement to defined pixel position
4259 //=======================================================================
4260 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4261 Standard_Integer argc,
4266 di << "Usage : " << argv[0] << " x y" << "\n";
4270 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4271 if(aContext.IsNull())
4273 di << "use 'vinit' command before " << argv[0] << "\n";
4276 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4280 //=======================================================================
4281 //function : VViewParams
4282 //purpose : Gets or sets AIS View characteristics
4283 //=======================================================================
4284 static Standard_Integer VViewParams (Draw_Interpretor& di,
4285 Standard_Integer argc,
4288 if ( argc != 1 && argc != 13)
4290 di << "Usage : " << argv[0] << "\n";
4293 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
4294 if ( anAISView.IsNull () )
4296 di << "use 'vinit' command before " << argv[0] << "\n";
4300 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
4301 Standard_Real anAISViewCenterCoordinateX = 0.0;
4302 Standard_Real anAISViewCenterCoordinateY = 0.0;
4303 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4304 Standard_Real anAISViewProjX = 0.0;
4305 Standard_Real anAISViewProjY = 0.0;
4306 Standard_Real anAISViewProjZ = 0.0;
4307 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4308 Standard_Real anAISViewUpX = 0.0;
4309 Standard_Real anAISViewUpY = 0.0;
4310 Standard_Real anAISViewUpZ = 0.0;
4311 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4312 Standard_Real anAISViewAtX = 0.0;
4313 Standard_Real anAISViewAtY = 0.0;
4314 Standard_Real anAISViewAtZ = 0.0;
4315 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4316 di << "Scale of current view: " << anAISViewScale << "\n";
4317 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
4318 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4319 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4320 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4324 Quantity_Factor anAISViewScale = atof (argv [1]);
4325 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
4326 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
4327 Standard_Real anAISViewProjX = atof (argv [4]);
4328 Standard_Real anAISViewProjY = atof (argv [5]);
4329 Standard_Real anAISViewProjZ = atof (argv [6]);
4330 Standard_Real anAISViewUpX = atof (argv [7]);
4331 Standard_Real anAISViewUpY = atof (argv [8]);
4332 Standard_Real anAISViewUpZ = atof (argv [9]);
4333 Standard_Real anAISViewAtX = atof (argv [10]);
4334 Standard_Real anAISViewAtY = atof (argv [11]);
4335 Standard_Real anAISViewAtZ = atof (argv [12]);
4336 anAISView -> V3d_View::SetScale (anAISViewScale);
4337 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4338 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4339 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4340 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4345 //=======================================================================
4346 //function : VChangeSelected
4347 //purpose : Adds the shape to selection or remove one from it
4348 //=======================================================================
4349 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4350 Standard_Integer argc,
4355 di<<"Usage : " << argv[0] << " shape \n";
4359 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4360 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4361 TCollection_AsciiString aName(argv[1]);
4362 Handle(AIS_InteractiveObject) anAISObject;
4364 if(!aMap.IsBound2(aName))
4366 di<<"Use 'vdisplay' before";
4371 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4372 if(anAISObject.IsNull()){
4373 di<<"No interactive object \n";
4377 if(aContext->HasOpenedContext())
4379 aContext->AddOrRemoveSelected(anAISObject);
4383 aContext->AddOrRemoveCurrentObject(anAISObject);
4389 //=======================================================================
4390 //function : VZClipping
4391 //purpose : Gets or sets ZClipping mode, width and depth
4392 //=======================================================================
4393 static Standard_Integer VZClipping (Draw_Interpretor& di,
4394 Standard_Integer argc,
4399 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4400 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4403 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4404 if(aContext.IsNull())
4406 di << "use 'vinit' command before " << argv[0] << "\n";
4409 Handle(V3d_View) aView = ViewerTest::CurrentView();
4410 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4413 TCollection_AsciiString aZClippingModeString;
4414 Quantity_Length aDepth, aWidth;
4415 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4416 switch (aZClippingMode)
4419 aZClippingModeString.Copy("OFF");
4422 aZClippingModeString.Copy("BACK");
4425 aZClippingModeString.Copy("FRONT");
4428 aZClippingModeString.Copy("SLICE");
4431 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4434 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4435 << "ZClipping depth = " << aDepth << "\n"
4436 << "ZClipping width = " << aWidth << "\n";
4442 Standard_Integer aStatus = 0;
4443 if ( strcmp (argv [1], "OFF") == 0 ) {
4445 aZClippingMode = V3d_OFF;
4447 if ( strcmp (argv [1], "BACK") == 0 ) {
4449 aZClippingMode = V3d_BACK;
4451 if ( strcmp (argv [1], "FRONT") == 0 ) {
4453 aZClippingMode = V3d_FRONT;
4455 if ( strcmp (argv [1], "SLICE") == 0 ) {
4457 aZClippingMode = V3d_SLICE;
4461 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4462 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4465 aView->SetZClippingType(aZClippingMode);
4469 Quantity_Length aDepth = 0., aWidth = 1.;
4472 aDepth = atof(argv[1]);
4473 aWidth = atof(argv[2]);
4477 aDepth = atof(argv[2]);
4478 aWidth = atof(argv[3]);
4481 if(aDepth<0. || aDepth>1.)
4483 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4484 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4487 if(aWidth<0. || aWidth>1.)
4489 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4490 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4494 aView->SetZClippingDepth(aDepth);
4495 aView->SetZClippingWidth(aWidth);
4502 //=======================================================================
4503 //function : VNbSelected
4504 //purpose : Returns number of selected objects
4505 //=======================================================================
4506 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4507 Standard_Integer argc,
4512 di << "Usage : " << argv[0] << "\n";
4515 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4516 if(aContext.IsNull())
4518 di << "use 'vinit' command before " << argv[0] << "\n";
4521 di << aContext->NbSelected() << "\n";
4525 //=======================================================================
4526 //function : VAntialiasing
4527 //purpose : Switches altialiasing on or off
4528 //=======================================================================
4529 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4530 Standard_Integer argc,
4535 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4539 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4540 if(aContext.IsNull())
4542 di << "use 'vinit' command before " << argv[0] << "\n";
4546 Handle(V3d_View) aView = ViewerTest::CurrentView();
4548 if((argc == 2) && (atof(argv[1]) == 0))
4549 aView->SetAntialiasingOff();
4551 aView->SetAntialiasingOn();
4556 //=======================================================================
4557 //function : VPurgeDisplay
4558 //purpose : Switches altialiasing on or off
4559 //=======================================================================
4560 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4561 Standard_Integer argc,
4566 di << "Usage : " << argv[0] << "\n";
4569 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4570 if (aContext.IsNull())
4572 di << "use 'vinit' command before " << argv[0] << "\n";
4575 aContext->CloseAllContexts(Standard_False);
4576 di << aContext->PurgeDisplay() << "\n";
4580 //=======================================================================
4581 //function : VSetViewSize
4583 //=======================================================================
4584 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4585 Standard_Integer argc,
4588 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4589 if(aContext.IsNull())
4591 di << "use 'vinit' command before " << argv[0] << "\n";
4596 di<<"Usage : " << argv[0] << " Size\n";
4599 Standard_Real aSize = atof(argv[1]);
4602 di<<"Bad Size value : " << aSize << "\n";
4606 Handle(V3d_View) aView = ViewerTest::CurrentView();
4607 aView->SetSize(aSize);
4611 //=======================================================================
4612 //function : VMoveView
4614 //=======================================================================
4615 static Standard_Integer VMoveView (Draw_Interpretor& di,
4616 Standard_Integer argc,
4619 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4620 if(aContext.IsNull())
4622 di << "use 'vinit' command before " << argv[0] << "\n";
4625 if(argc < 4 || argc > 5)
4627 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4630 Standard_Real Dx = atof(argv[1]);
4631 Standard_Real Dy = atof(argv[2]);
4632 Standard_Real Dz = atof(argv[3]);
4633 Standard_Boolean aStart = Standard_True;
4636 aStart = (atoi(argv[4]) > 0);
4639 Handle(V3d_View) aView = ViewerTest::CurrentView();
4640 aView->Move(Dx,Dy,Dz,aStart);
4644 //=======================================================================
4645 //function : VTranslateView
4647 //=======================================================================
4648 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4649 Standard_Integer argc,
4652 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4653 if(aContext.IsNull())
4655 di << "use 'vinit' command before " << argv[0] << "\n";
4658 if(argc < 4 || argc > 5)
4660 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4663 Standard_Real Dx = atof(argv[1]);
4664 Standard_Real Dy = atof(argv[2]);
4665 Standard_Real Dz = atof(argv[3]);
4666 Standard_Boolean aStart = Standard_True;
4669 aStart = (atoi(argv[4]) > 0);
4672 Handle(V3d_View) aView = ViewerTest::CurrentView();
4673 aView->Translate(Dx,Dy,Dz,aStart);
4677 //=======================================================================
4678 //function : VTurnView
4680 //=======================================================================
4681 static Standard_Integer VTurnView (Draw_Interpretor& di,
4682 Standard_Integer argc,
4685 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4686 if(aContext.IsNull()) {
4687 di << "use 'vinit' command before " << argv[0] << "\n";
4690 if(argc < 4 || argc > 5){
4691 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4694 Standard_Real Ax = atof(argv[1]);
4695 Standard_Real Ay = atof(argv[2]);
4696 Standard_Real Az = atof(argv[3]);
4697 Standard_Boolean aStart = Standard_True;
4700 aStart = (atoi(argv[4]) > 0);
4703 Handle(V3d_View) aView = ViewerTest::CurrentView();
4704 aView->Turn(Ax,Ay,Az,aStart);
4708 //==============================================================================
4709 //function : VTextureEnv
4710 //purpose : ENables or disables environment mapping
4711 //==============================================================================
4712 class OCC_TextureEnv : public Graphic3d_TextureEnv
4715 OCC_TextureEnv(const Standard_CString FileName);
4716 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4717 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4718 const Standard_Boolean theModulateFlag,
4719 const Graphic3d_TypeOfTextureFilter theFilter,
4720 const Standard_ShortReal theXScale,
4721 const Standard_ShortReal theYScale,
4722 const Standard_ShortReal theXShift,
4723 const Standard_ShortReal theYShift,
4724 const Standard_ShortReal theAngle);
4725 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4727 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4728 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4729 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4731 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4732 : Graphic3d_TextureEnv(theFileName)
4736 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4737 : Graphic3d_TextureEnv(theTexId)
4741 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4742 const Standard_Boolean theModulateFlag,
4743 const Graphic3d_TypeOfTextureFilter theFilter,
4744 const Standard_ShortReal theXScale,
4745 const Standard_ShortReal theYScale,
4746 const Standard_ShortReal theXShift,
4747 const Standard_ShortReal theYShift,
4748 const Standard_ShortReal theAngle)
4750 myParams->SetRepeat (theRepeatFlag);
4751 myParams->SetModulate (theModulateFlag);
4752 myParams->SetFilter (theFilter);
4753 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
4754 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4755 myParams->SetRotation (theAngle);
4758 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4760 // get the active view
4761 Handle(V3d_View) aView = ViewerTest::CurrentView();
4764 std::cerr << "No active view. Please call vinit.\n";
4768 // Checking the input arguments
4769 Standard_Boolean anEnableFlag = Standard_False;
4770 Standard_Boolean isOk = theArgNb >= 2;
4773 TCollection_AsciiString anEnableOpt(theArgVec[1]);
4774 anEnableFlag = anEnableOpt.IsEqual("on");
4775 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
4779 isOk = (theArgNb == 3 || theArgNb == 11);
4782 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4783 isOk = (!aTextureOpt.IsIntegerValue() ||
4784 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
4786 if (isOk && theArgNb == 11)
4788 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
4789 aModulateOpt(theArgVec[4]),
4790 aFilterOpt (theArgVec[5]),
4791 aSScaleOpt (theArgVec[6]),
4792 aTScaleOpt (theArgVec[7]),
4793 aSTransOpt (theArgVec[8]),
4794 aTTransOpt (theArgVec[9]),
4795 anAngleOpt (theArgVec[10]);
4796 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
4797 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
4798 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
4799 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
4800 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
4801 anAngleOpt.IsRealValue());
4808 std::cerr << "Usage :" << std::endl;
4809 std::cerr << theArgVec[0] << " off" << std::endl;
4810 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;
4816 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4817 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
4818 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
4819 new OCC_TextureEnv(theArgVec[2]);
4823 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
4824 aTexEnv->SetTextureParameters(
4825 aRepeatOpt. IsEqual("repeat"),
4826 aModulateOpt.IsEqual("modulate"),
4827 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
4828 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
4829 Graphic3d_TOTF_TRILINEAR,
4830 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
4831 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
4832 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
4833 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
4834 (Standard_ShortReal)Draw::Atof(theArgVec[10])
4837 aView->SetTextureEnv(aTexEnv);
4838 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
4840 else // Disabling environment mapping
4842 aView->SetSurfaceDetail(V3d_TEX_NONE);
4843 Handle(Graphic3d_TextureEnv) aTexture;
4844 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
4851 //===============================================================================================
4852 //function : VClipPlane
4854 //===============================================================================================
4855 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4857 // use short-cut for created clip planes map of created (or "registered by name") clip planes
4858 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
4859 static MapOfPlanes aRegPlanes;
4863 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
4867 TCollection_AsciiString aCommand (theArgVec[1]);
4869 // print maximum number of planes for current viewer
4870 if (aCommand == "maxplanes")
4874 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
4878 TCollection_AsciiString aViewName (theArgVec[2]);
4880 if (!ViewerTest_myViews.IsBound1 (aViewName))
4882 theDi << theArgVec[0] << ": view is not found.\n";
4886 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
4888 theDi << theArgVec[0] << ": "
4889 << aView->Viewer()->Driver()->InquirePlaneLimit()
4890 << " plane slots provided by driver."
4891 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
4896 // create / delete plane instance
4897 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
4901 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
4905 Standard_Boolean toCreate = (aCommand == "create");
4906 Standard_Boolean toClone = (aCommand == "clone");
4907 TCollection_AsciiString aPlane (theArgVec[2]);
4911 if (aRegPlanes.IsBound (aPlane))
4913 theDi << theArgVec[0] << ": plane name is in use.\n";
4917 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
4919 else if (toClone) // toClone
4921 if (!aRegPlanes.IsBound (aPlane))
4923 theDi << theArgVec[0] << ": no such plane.\n";
4929 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
4933 TCollection_AsciiString aClone (theArgVec[3]);
4934 if (aRegPlanes.IsBound (aClone))
4936 theDi << theArgVec[0] << ": plane name is in use.\n";
4940 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4942 aRegPlanes.Bind (aClone, aClipPlane->Clone());
4946 if (!aRegPlanes.IsBound (aPlane))
4948 theDi << theArgVec[0] << ": no such plane.\n";
4952 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
4953 aRegPlanes.UnBind (aPlane);
4955 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
4956 for (; anIObjIt.More(); anIObjIt.Next())
4958 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
4959 aPrs->RemoveClipPlane(aClipPlane);
4962 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
4963 for (; aViewIt.More(); aViewIt.Next())
4965 const Handle(V3d_View)& aView = aViewIt.Key2();
4966 aView->RemoveClipPlane(aClipPlane);
4969 ViewerTest::RedrawAllViews();
4975 // set / unset plane command
4976 if (aCommand == "set" || aCommand == "unset")
4980 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
4984 Standard_Boolean toSet = (aCommand == "set");
4985 TCollection_AsciiString aPlane (theArgVec [2]);
4986 if (!aRegPlanes.IsBound (aPlane))
4988 theDi << theArgVec[0] << ": no such plane.\n";
4992 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4994 TCollection_AsciiString aTarget (theArgVec [3]);
4995 if (aTarget != "object" && aTarget != "view")
4997 theDi << theArgVec[0] << ": invalid target.\n";
5001 if (aTarget == "object" || aTarget == "view")
5005 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5009 Standard_Boolean isObject = (aTarget == "object");
5011 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
5013 TCollection_AsciiString anEntityName (theArgVec[anIt]);
5014 if (isObject) // to object
5016 if (!GetMapOfAIS().IsBound2 (anEntityName))
5018 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
5022 Handle(AIS_InteractiveObject) aIObj =
5023 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
5026 aIObj->AddClipPlane (aClipPlane);
5028 aIObj->RemoveClipPlane (aClipPlane);
5032 if (!ViewerTest_myViews.IsBound1 (anEntityName))
5034 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
5038 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
5040 aView->AddClipPlane (aClipPlane);
5042 aView->RemoveClipPlane (aClipPlane);
5046 ViewerTest::RedrawAllViews();
5052 // change plane command
5053 if (aCommand == "change")
5057 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5061 TCollection_AsciiString aPlane (theArgVec [2]);
5062 if (!aRegPlanes.IsBound (aPlane))
5064 theDi << theArgVec[0] << ": no such plane.\n";
5068 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5070 TCollection_AsciiString aChangeArg (theArgVec [3]);
5071 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5073 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5077 if (aChangeArg == "on" || aChangeArg == "off") // on / off
5079 aClipPlane->SetOn (aChangeArg == "on");
5081 else if (aChangeArg == "equation") // change equation
5085 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5089 Standard_Real aCoeffA = atof (theArgVec [4]);
5090 Standard_Real aCoeffB = atof (theArgVec [5]);
5091 Standard_Real aCoeffC = atof (theArgVec [6]);
5092 Standard_Real aCoeffD = atof (theArgVec [7]);
5093 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5095 else if (aChangeArg == "capping") // change capping aspects
5099 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5103 TCollection_AsciiString aCappingArg (theArgVec [4]);
5104 if (aCappingArg != "on" && aCappingArg != "off" &&
5105 aCappingArg != "color" && aCappingArg != "texname" &&
5106 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5107 aCappingArg != "texrotate" && aCappingArg != "hatch")
5109 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5113 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5115 aClipPlane->SetCapping (aCappingArg == "on");
5117 else if (aCappingArg == "color") // color aspect for capping
5121 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5125 Standard_Real aRed = atof (theArgVec [5]);
5126 Standard_Real aGrn = atof (theArgVec [6]);
5127 Standard_Real aBlu = atof (theArgVec [7]);
5129 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5130 aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
5131 aClipPlane->SetCappingMaterial (aMat);
5133 else if (aCappingArg == "texname") // texture name
5137 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5141 TCollection_AsciiString aTextureName (theArgVec [5]);
5143 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5144 if (!aTexture->IsDone ())
5146 aClipPlane->SetCappingTexture (NULL);
5150 aTexture->EnableModulate();
5151 aTexture->EnableRepeat();
5152 aClipPlane->SetCappingTexture (aTexture);
5155 else if (aCappingArg == "texscale") // texture scale
5157 if (aClipPlane->CappingTexture().IsNull())
5159 theDi << theArgVec[0] << ": no texture is set.\n";
5165 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5169 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5170 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5172 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5174 else if (aCappingArg == "texorigin") // texture origin
5176 if (aClipPlane->CappingTexture().IsNull())
5178 theDi << theArgVec[0] << ": no texture is set.\n";
5184 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5188 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5189 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5191 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5193 else if (aCappingArg == "texrotate") // texture rotation
5195 if (aClipPlane->CappingTexture().IsNull())
5197 theDi << theArgVec[0] << ": no texture is set.\n";
5203 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5207 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5209 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5211 else if (aCappingArg == "hatch") // hatch style
5215 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5219 TCollection_AsciiString aHatchStr (theArgVec [5]);
5220 if (aHatchStr == "on")
5222 aClipPlane->SetCappingHatchOn();
5224 else if (aHatchStr == "off")
5226 aClipPlane->SetCappingHatchOff();
5230 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5235 ViewerTest::RedrawAllViews();
5240 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5244 //===============================================================================================
5245 //function : VSetTextureMode
5247 //===============================================================================================
5248 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5252 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5256 TCollection_AsciiString aViewName (theArgVec[1]);
5257 if (!ViewerTest_myViews.IsBound1 (aViewName))
5259 theDi << theArgVec[0] << ": view is not found.\n";
5263 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5264 switch (atoi (theArgVec[2]))
5266 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5267 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5268 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5270 theDi << theArgVec[0] << ": invalid mode.\n";
5278 //=======================================================================
5279 //function : ViewerCommands
5281 //=======================================================================
5283 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
5286 const char *group = "ZeViewer";
5287 theCommands.Add("vinit",
5288 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5289 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5291 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5293 " - Creates new View window with specified name view_name.\n"
5294 "By default the new view is created in the viewer and in"
5295 " graphic driver shared with active view.\n"
5296 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
5297 "If driverName isn't specified the driver will be shared with active view.\n"
5298 "If viewerName isn't specified the viewer will be shared with active view.\n"
5299 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5300 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
5301 "is used in creation of graphic driver\n"
5303 " - l, t: pixel position of left top corner of the window\n"
5304 " - w,h: width and heigth of window respectively.\n"
5305 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
5306 __FILE__,VInit,group);
5307 theCommands.Add("vclose" ,
5308 "[view_id [keep_context=0|1]]\n"
5309 "or vclose ALL - to remove all created views\n"
5310 " - removes view(viewer window) defined by its view_id.\n"
5311 " - keep_context: by default 0; if 1 and the last view is deleted"
5312 " the current context is not removed.",
5313 __FILE__,VClose,group);
5314 theCommands.Add("vactivate" ,
5316 " - activates view(viewer window) defined by its view_id",
5317 __FILE__,VActivate,group);
5318 theCommands.Add("vviewlist",
5319 "vviewlist [format={tree, long}]"
5320 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
5321 " - format: format of result output, if tree the output is a tree view;"
5322 "otherwise it's a list of full view names. By default format = tree",
5323 __FILE__,VViewList,group);
5324 theCommands.Add("vhelp" ,
5325 "vhelp : display help on the viewer commands",
5326 __FILE__,VHelp,group);
5327 theCommands.Add("vtop" ,
5328 "vtop or <T> : Top view" ,
5329 __FILE__,VTop,group);
5330 theCommands.Add("vbottom" ,
5331 "vbottom : Bottom view" ,
5332 __FILE__,VBottom,group);
5333 theCommands.Add("vleft" ,
5334 "vleft : Left view" ,
5335 __FILE__,VLeft,group);
5336 theCommands.Add("vright" ,
5337 "vright : Right view" ,
5338 __FILE__,VRight,group);
5339 theCommands.Add("vaxo" ,
5340 " vaxo or <A> : Axonometric view ",
5341 __FILE__,VAxo,group);
5342 theCommands.Add("vfront" ,
5343 "vfront : Front view" ,
5344 __FILE__,VFront,group);
5345 theCommands.Add("vback" ,
5346 "vback : Back view" ,
5347 __FILE__,VBack,group);
5348 theCommands.Add("vpick" ,
5349 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
5351 theCommands.Add("vfit" ,
5352 "vfit or <F> : vfit",
5353 __FILE__,VFit,group);
5354 theCommands.Add("vzfit" ,
5356 __FILE__,VZFit,group);
5357 theCommands.Add("vrepaint",
5358 "vrepaint : vrepaint, force redraw",
5359 __FILE__,VRepaint,group);
5360 theCommands.Add("vclear",
5362 __FILE__,VClear,group);
5363 theCommands.Add("vsetbg",
5364 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
5365 __FILE__,VSetBg,group);
5366 theCommands.Add("vsetbgmode",
5367 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
5368 __FILE__,VSetBgMode,group);
5369 theCommands.Add("vsetgradientbg",
5370 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
5371 __FILE__,VSetGradientBg,group);
5372 theCommands.Add("vsetgrbgmode",
5373 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
5374 __FILE__,VSetGradientBgMode,group);
5375 theCommands.Add("vsetcolorbg",
5376 "vsetcolorbg : vsetcolorbg r g b : Set background color",
5377 __FILE__,VSetColorBg,group);
5378 theCommands.Add("vscale",
5379 "vscale : vscale X Y Z",
5380 __FILE__,VScale,group);
5381 theCommands.Add("vzbufftrihedron",
5382 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
5383 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
5384 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
5385 __FILE__,VTestZBuffTrihedron,group);
5386 theCommands.Add("vrotate",
5387 "vrotate : vrotate AX AY AZ [X Y Z]",
5388 __FILE__,VRotate,group);
5389 theCommands.Add("vzoom",
5390 "vzoom : vzoom coef",
5391 __FILE__,VZoom,group);
5392 theCommands.Add("vpan",
5393 "vpan : vpan dx dy",
5394 __FILE__,VPan,group);
5395 theCommands.Add("vexport",
5396 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
5397 " : exports the view to a vector file of a given format"
5398 " : notice that EMF format requires patched gl2ps",
5399 __FILE__,VExport,group);
5400 theCommands.Add("vcolorscale",
5401 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
5402 __FILE__,VColorScale,group);
5403 theCommands.Add("vgraduatedtrihedron",
5404 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
5405 __FILE__,VGraduatedTrihedron,group);
5406 theCommands.Add("vprintview" ,
5407 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
5408 __FILE__,VPrintView,group);
5409 theCommands.Add("vzlayer",
5410 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
5411 __FILE__,VZLayer,group);
5412 theCommands.Add("voverlaytext",
5413 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
5414 " : height - pixel height of the text (default=10.0)"
5415 " : font_name - name of font (default=courier)"
5416 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
5417 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
5418 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
5419 __FILE__,VOverlayText,group);
5420 theCommands.Add("vlayerline",
5421 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
5422 __FILE__,VLayerLine,group);
5423 theCommands.Add ("vgrid",
5424 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
5425 " : Mode - rectangular or circular"
5426 " : Type - lines or points",
5427 __FILE__, VGrid, group);
5428 theCommands.Add ("vfps",
5429 "vfps [framesNb=100] : estimate average frame rate for active view",
5430 __FILE__, VFps, group);
5431 theCommands.Add ("vgldebug",
5432 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
5433 " : this function is implemented only for Windows\n"
5434 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
5435 __FILE__, VGlDebug, group);
5436 theCommands.Add ("vvbo",
5437 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
5438 __FILE__, VVbo, group);
5439 theCommands.Add ("vcaps",
5440 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
5441 __FILE__, VCaps, group);
5442 theCommands.Add ("vmemgpu",
5443 "vmemgpu [f]: print system-dependent GPU memory information if available;"
5444 " with f option returns free memory in bytes",
5445 __FILE__, VMemGpu, group);
5446 theCommands.Add ("vreadpixel",
5447 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
5448 " : Read pixel value for active view",
5449 __FILE__, VReadPixel, group);
5450 theCommands.Add("diffimage",
5451 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
5452 __FILE__, VDiffImage, group);
5453 theCommands.Add ("vselect",
5454 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
5455 "- emulates different types of selection:\n"
5456 "- 1) single click selection\n"
5457 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
5458 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
5459 "- 4) any of these selections with shift button pressed",
5460 __FILE__, VSelect, group);
5461 theCommands.Add ("vmoveto",
5463 "- emulates cursor movement to pixel postion (x,y)",
5464 __FILE__, VMoveTo, group);
5465 theCommands.Add("vviewparams",
5466 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
5467 "- gets or sets current view characteristics",
5468 __FILE__,VViewParams, group);
5469 theCommands.Add("vchangeselected",
5470 "vchangeselected shape"
5471 "- adds to shape to selection or remove one from it",
5472 __FILE__, VChangeSelected, group);
5473 theCommands.Add("vzclipping",
5474 "vzclipping [mode] [depth width]\n"
5475 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
5476 "- gets or sets ZClipping mode, width and depth",
5477 __FILE__,VZClipping,group);
5478 theCommands.Add ("vnbselected",
5479 "vnbselected", __FILE__, VNbSelected, group);
5480 theCommands.Add("vantialiasing",
5481 "vantialiasing 1|0",
5482 __FILE__,VAntialiasing,group);
5483 theCommands.Add ("vpurgedisplay",
5485 "- removes structures which don't belong to objects displayed in neutral point",
5486 __FILE__, VPurgeDisplay, group);
5487 theCommands.Add("vsetviewsize",
5488 "vsetviewsize size",
5489 __FILE__,VSetViewSize,group);
5490 theCommands.Add("vmoveview",
5491 "vmoveview Dx Dy Dz [Start = 1|0]",
5492 __FILE__,VMoveView,group);
5493 theCommands.Add("vtranslateview",
5494 "vtranslateview Dx Dy Dz [Start = 1|0)]",
5495 __FILE__,VTranslateView,group);
5496 theCommands.Add("vturnview",
5497 "vturnview Ax Ay Az [Start = 1|0]",
5498 __FILE__,VTurnView,group);
5499 theCommands.Add("vtextureenv",
5500 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
5501 "or user-defined file and optionally applying texture mapping parameters\n"
5503 " vtextureenv off - disables environment mapping\n"
5504 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
5505 " std_texture = (0..7)\n"
5506 " rep = {clamp|repeat}\n"
5507 " mod = {decal|modulate}\n"
5508 " flt = {nearest|bilinear|trilinear}\n"
5509 " ss, st - scale factors for s and t texture coordinates\n"
5510 " ts, tt - translation for s and t texture coordinates\n"
5511 " rot - texture rotation angle in degrees",
5512 __FILE__, VTextureEnv, group);
5513 theCommands.Add("vhlr" ,
5514 "is_enabled={on|off}"
5515 " - Hidden line removal algorithm:"
5516 " - is_enabled: if is on HLR algorithm is applied\n",
5517 __FILE__,VHLR,group);
5518 theCommands.Add("vhlrtype" ,
5519 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
5520 " - Changes the type of HLR algorithm using for shapes."
5521 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
5522 " if equals to polyalgo, polygonal HLR algorithm is applied."
5523 "If shapes are not given HLR algoithm of given type is applied"
5524 " to all shapes in the view\n",
5525 __FILE__,VHLRType,group);
5526 theCommands.Add("vclipplane", "vclipplane usage: \n"
5527 " maxplanes <view_name> - get plane limit for view.\n"
5528 " create <plane_name> - create new plane.\n"
5529 " delete <plane_name> - delete plane.\n"
5530 " clone <source_plane> <plane_name> - clone the plane definition.\n"
5531 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
5532 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
5533 " change <plane_name> on/off - turn clipping on/off.\n"
5534 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
5535 " change <plane_name> capping on/off - turn capping on/off.\n"
5536 " change <plane_name> capping color <r> <g> <b> - set color.\n"
5537 " change <plane name> capping texname <texture> - set texture.\n"
5538 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
5539 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
5540 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
5541 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
5542 " please use VSetTextureMode command to enable texture rendering in view.\n"
5543 , __FILE__, VClipPlane, group);
5544 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
5546 " 0 - no textures enabled in view.\n"
5547 " 1 - only environment textures enabled.\n"
5548 " 2 - all textures enabled.\n"
5549 " this command sets texture details mode for the specified view.\n"
5550 , __FILE__, VSetTextureMode, group);