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>
97 #include <Xw_Window.hxx>
98 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
99 #include <X11/Xutil.h>
103 // Auxiliary definitions
104 static const char THE_KEY_DELETE = 127;
106 //==============================================================================
107 // VIEWER GLOBAL VARIABLES
108 //==============================================================================
110 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
111 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
113 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
114 extern const Handle(NIS_InteractiveContext)& TheNISContext();
115 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
117 extern int VErase (Draw_Interpretor& theDI,
118 Standard_Integer theArgNb,
119 const char** theArgVec);
122 static Handle(WNT_Window)& VT_GetWindow() {
123 static Handle(WNT_Window) WNTWin;
126 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
127 static Handle(Cocoa_Window)& VT_GetWindow()
129 static Handle(Cocoa_Window) aWindow;
132 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
133 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
134 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
137 static Handle(Xw_Window)& VT_GetWindow(){
138 static Handle(Xw_Window) XWWin;
142 static void VProcessEvents(ClientData,int);
145 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
147 static Handle(Aspect_DisplayConnection) aDisplayConnection;
148 return aDisplayConnection;
151 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
153 GetDisplayConnection() = theDisplayConnection;
156 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
157 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
159 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
161 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
162 if (!aWindow.IsNull())
163 return aWindow->HWindow();
164 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
165 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
166 if (!aWindow.IsNull())
167 return aWindow->XWindow();
169 return aWindowHandle;
173 static Standard_Boolean MyHLRIsOn = Standard_False;
175 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
176 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
177 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
178 static OpenGl_Caps ViewerTest_myDefaultCaps;
180 #define ZCLIPWIDTH 1.
182 static void OSWindowSetup();
184 //==============================================================================
185 // EVENT GLOBAL VARIABLES
186 //==============================================================================
188 static int Start_Rot = 0;
189 static int ZClipIsOn = 0;
190 int X_Motion = 0; // Current cursor position
192 int X_ButtonPress = 0; // Last ButtonPress position
193 int Y_ButtonPress = 0;
194 Standard_Boolean IsDragged = Standard_False;
195 Standard_Boolean DragFirst;
197 //==============================================================================
200 static LRESULT WINAPI ViewerWindowProc(
205 static LRESULT WINAPI AdvViewerWindowProc(
213 //==============================================================================
216 //==============================================================================
218 const Handle(MMgt_TShared)& ViewerTest::WClass()
220 static Handle(MMgt_TShared) theWClass;
222 if (theWClass.IsNull())
224 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
225 CS_VREDRAW | CS_HREDRAW, 0, 0,
226 ::LoadCursor (NULL, IDC_ARROW));
232 //==============================================================================
233 //function : CreateName
234 //purpose : Create numerical name for new object in theMap
235 //==============================================================================
236 template <typename ObjectType>
237 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
238 const TCollection_AsciiString& theDefaultString)
240 if (theObjectMap.IsEmpty())
241 return theDefaultString + TCollection_AsciiString(1);
243 Standard_Integer aNextKey = 1;
244 Standard_Boolean isFound = Standard_False;
247 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
248 // Look for objects with default names
249 if (theObjectMap.IsBound1(aStringKey))
254 isFound = Standard_True;
257 return theDefaultString + TCollection_AsciiString(aNextKey);
260 //==============================================================================
261 //structure : ViewerTest_Names
262 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
263 //==============================================================================
264 struct ViewerTest_Names
267 TCollection_AsciiString myDriverName;
268 TCollection_AsciiString myViewerName;
269 TCollection_AsciiString myViewName;
273 const TCollection_AsciiString& GetDriverName () const
277 void SetDriverName (const TCollection_AsciiString& theDriverName)
279 myDriverName = theDriverName;
281 const TCollection_AsciiString& GetViewerName () const
285 void SetViewerName (const TCollection_AsciiString& theViewerName)
287 myViewerName = theViewerName;
289 const TCollection_AsciiString& GetViewName () const
293 void SetViewName (const TCollection_AsciiString& theViewName)
295 myViewName = theViewName;
298 //===========================================================================
299 //function : Constructor for ViewerTest_Names
300 //purpose : Get view, viewer, driver names from custom string
301 //===========================================================================
303 ViewerTest_Names (const TCollection_AsciiString& theInputString)
305 TCollection_AsciiString aName(theInputString);
306 if (theInputString.IsEmpty())
308 // Get current configuration
309 if (ViewerTest_myDrivers.IsEmpty())
310 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
311 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
313 myDriverName = ViewerTest_myDrivers.Find2
314 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
316 if(ViewerTest_myContexts.IsEmpty())
318 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
319 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
322 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
324 myViewName = CreateName <Handle(V3d_View)>
325 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
329 // There is at least view name
330 Standard_Integer aParserNumber = 0;
331 for (Standard_Integer i = 0; i < 3; ++i)
333 Standard_Integer aParserPos = aName.SearchFromEnd("/");
337 aName.Split(aParserPos-1);
342 if (aParserNumber == 0)
345 if (!ViewerTest::GetAISContext().IsNull())
347 myDriverName = ViewerTest_myDrivers.Find2
348 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
349 myViewerName = ViewerTest_myContexts.Find2
350 (ViewerTest::GetAISContext());
354 // There is no opened contexts here, need to create names for viewer and driver
355 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
356 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
358 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
359 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
361 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
363 else if (aParserNumber == 1)
365 // Here is viewerName/viewName
366 if (!ViewerTest::GetAISContext().IsNull())
367 myDriverName = ViewerTest_myDrivers.Find2
368 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
371 // There is no opened contexts here, need to create name for driver
372 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
373 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
375 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
377 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
381 //Here is driverName/viewerName/viewName
382 myDriverName = TCollection_AsciiString(aName);
384 TCollection_AsciiString aViewerName(theInputString);
385 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
386 myViewerName = TCollection_AsciiString(aViewerName);
388 myViewName = TCollection_AsciiString(theInputString);
394 //==============================================================================
395 //function : FindContextByView
396 //purpose : Find AIS_InteractiveContext by View
397 //==============================================================================
399 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
401 Handle(AIS_InteractiveContext) anAISContext;
403 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
404 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
406 if (anIter.Value()->CurrentViewer() == theView->Viewer())
407 return anIter.Key2();
413 //==============================================================================
414 //function : SetWindowTitle
415 //purpose : Set window title
416 //==============================================================================
418 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
419 Standard_CString theTitle)
422 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
424 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
425 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
427 if(GetDisplayConnection()->GetDisplay())
430 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
431 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
436 //==============================================================================
437 //function : IsWindowOverlapped
438 //purpose : Check if theWindow overlapp another view
439 //==============================================================================
441 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
442 const Standard_Integer thePxTop,
443 const Standard_Integer thePxRight,
444 const Standard_Integer thePxBottom,
445 TCollection_AsciiString& theViewId)
447 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
448 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
450 Standard_Integer aTop = 0,
454 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
455 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
456 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
457 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
458 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
460 theViewId = anIter.Key1();
461 return Standard_True;
464 return Standard_False;
467 // Workaround: to create and delete non-orthographic views outside ViewerTest
468 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
470 ViewerTest_myViews.UnBind1 (theName);
473 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
474 const Handle(V3d_View)& theView)
476 ViewerTest_myViews.Bind (theName, theView);
479 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
481 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
483 //==============================================================================
484 //function : ViewerInit
485 //purpose : Create the window viewer and initialize all the global variable
486 //==============================================================================
488 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
489 const Standard_Integer thePxTop,
490 const Standard_Integer thePxWidth,
491 const Standard_Integer thePxHeight,
492 Standard_CString theViewName,
493 Standard_CString theDisplayName)
495 // Default position and dimension of the viewer window.
496 // Note that left top corner is set to be sufficiently small to have
497 // window fit in the small screens (actual for remote desktops, see #23003).
498 // The position corresponds to the window's client area, thus some
499 // gap is added for window frame to be visible.
500 Standard_Integer aPxLeft = 20;
501 Standard_Integer aPxTop = 40;
502 Standard_Integer aPxWidth = 409;
503 Standard_Integer aPxHeight = 409;
504 Standard_Boolean toCreateViewer = Standard_False;
506 Handle(OpenGl_GraphicDriver) aGraphicDriver;
507 ViewerTest_Names aViewNames(theViewName);
508 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
509 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
516 aPxWidth = thePxWidth;
517 if (thePxHeight != 0)
518 aPxHeight = thePxHeight;
520 // Get graphic driver (create it or get from another view)
521 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
523 // Get connection string
524 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
525 TCollection_AsciiString aDisplayName(theDisplayName);
526 if (!aDisplayName.IsEmpty())
527 SetDisplayConnection (new Aspect_DisplayConnection ());
529 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
531 (void)theDisplayName; // avoid warning on unused argument
532 SetDisplayConnection (new Aspect_DisplayConnection ());
534 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
535 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
536 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
537 toCreateViewer = Standard_True;
541 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
544 //Dispose the window if input parameters are default
545 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
547 Standard_Integer aTop = 0,
554 // Get screen resolution
555 #if defined(_WIN32) || defined(__WIN32__)
557 GetClientRect(GetDesktopWindow(), &aWindowSize);
558 aScreenHeight = aWindowSize.bottom;
559 aScreenWidth = aWindowSize.right;
560 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
561 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
563 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
564 aScreenWidth = WidthOfScreen(aScreen);
565 aScreenHeight = HeightOfScreen(aScreen);
568 TCollection_AsciiString anOverlappedViewId("");
570 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
572 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
574 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
575 && aRight + 2*aPxWidth + 40 > aScreenWidth)
577 if (aBottom + aPxHeight + 40 > aScreenHeight)
584 aPxTop = aBottom + 40;
587 aPxLeft = aRight + 20;
592 TCollection_AsciiString aTitle("3D View - ");
593 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
595 // Change name of current active window
596 if (!ViewerTest::CurrentView().IsNull())
598 TCollection_AsciiString aTitle("3D View - ");
600 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
601 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
605 Handle(V3d_Viewer) a3DViewer;
606 // If it's the single view, we first look for empty context
607 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
609 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
610 anIter(ViewerTest_myContexts);
612 ViewerTest::SetAISContext (anIter.Value());
613 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
615 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
617 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
618 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
620 else if (a3DViewer.IsNull())
622 toCreateViewer = Standard_True;
623 TCollection_ExtendedString NameOfWindow("Viewer3D");
624 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
626 NameOfWindow = TCollection_ExtendedString("Collector");
628 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
632 if (ViewerTest::GetAISContext().IsNull() ||
633 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
635 Handle(AIS_InteractiveContext) aContext =
636 new AIS_InteractiveContext(a3DViewer);
637 ViewerTest::SetAISContext (aContext);
638 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
641 ViewerTest::ResetEventManager();
644 #if defined(_WIN32) || defined(__WIN32__)
645 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
646 Handle(WNT_WClass)::DownCast (WClass()),
647 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
651 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
652 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
654 aPxWidth, aPxHeight);
655 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
657 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
660 aPxWidth, aPxHeight);
662 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
665 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
667 ViewerTest::CurrentView(aView);
668 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
669 TheNISContext()->AttachView (aView);
671 // Setup for X11 or NT
674 // Set parameters for V3d_View and V3d_Viewer
675 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
676 aV3dView->SetComputedMode(Standard_False);
677 MyHLRIsOn = aV3dView->ComputedMode();
678 aV3dView->SetZClippingDepth(0.5);
679 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
681 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
684 a3DViewer->SetDefaultLights();
685 a3DViewer->SetLightOn();
688 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
689 #if TCL_MAJOR_VERSION < 8
690 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
691 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
693 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
694 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
698 VT_GetWindow()->Map();
700 // Set the handle of created view in the event manager
701 ViewerTest::ResetEventManager();
703 ViewerTest::CurrentView()->Redraw();
708 return aViewNames.GetViewName();
711 //==============================================================================
712 //function : RedrawAllViews
713 //purpose : Redraw all created views
714 //==============================================================================
715 void ViewerTest::RedrawAllViews()
717 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
718 for (; aViewIt.More(); aViewIt.Next())
720 const Handle(V3d_View)& aView = aViewIt.Key2();
725 //==============================================================================
726 //function : splitParameter
727 //purpose : Split parameter string to parameter name an parameter value
728 //==============================================================================
729 Standard_Boolean splitParameter (const TCollection_AsciiString& theString,
730 TCollection_AsciiString& theName,
731 TCollection_AsciiString& theValue)
733 Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
734 if (aParamNameEnd == 0)
735 return Standard_False;
736 TCollection_AsciiString aString(theString);
737 if (aParamNameEnd != 0)
739 theValue = aString.Split(aParamNameEnd);
740 aString.Split(aString.Length()-1);
743 return Standard_True;
746 //==============================================================================
748 //purpose : Create the window viewer and initialize all the global variable
749 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
750 //==============================================================================
752 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
756 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
757 << "Type help for more information.\n";
760 TCollection_AsciiString aViewName (""),
762 Standard_Integer aPxLeft = 0,
767 for (Standard_Integer i = 1; i < theArgsNb; ++i)
769 TCollection_AsciiString aName = "", aValue = "";
770 if(!splitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
772 // In case of syntax: vinit ViewName
773 aViewName = theArgVec[1];
781 else if (aName == "l" || aName == "left")
782 aPxLeft = aValue.IntegerValue();
783 else if (aName == "t" || aName == "top")
784 aPxTop = aValue.IntegerValue();
785 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
786 else if (aName == "display")
787 aDisplayName = aValue;
789 else if (aName == "w" || aName == "width")
790 aPxWidth = aValue.IntegerValue();
791 else if (aName == "h" || aName == "height")
792 aPxHeight = aValue.IntegerValue();
795 theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n";
800 ViewerTest_Names aViewNames (aViewName);
801 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
803 TCollection_AsciiString aCommand("vactivate ");
804 aCommand = aCommand + aViewNames.GetViewName();
805 theDi.Eval(aCommand.ToCString());
809 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
810 aViewName.ToCString(),
811 aDisplayName.ToCString());
812 cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n";
816 //==============================================================================
818 //purpose : hidden lines removal algorithm
819 //==============================================================================
821 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
823 if (ViewerTest::CurrentView().IsNull())
825 di << argv[0] << ": Call vinit before this command, please.\n";
831 di << argv[0] << ": Wrong number of command arguments.\n"
832 << "Type help " << argv[0] << " for more information.\n";
836 Standard_Boolean isHLROn =
837 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
839 if (isHLROn == MyHLRIsOn)
845 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
850 //==============================================================================
851 //function : VHLRType
852 //purpose : change type of using HLR algorithm
853 //==============================================================================
855 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
857 if (ViewerTest::CurrentView().IsNull())
859 di << argv[0] << ": Call vinit before this command, please.\n";
865 di << argv[0] << ": Wrong number of command arguments.\n"
866 << "Type help " << argv[0] << " for more information.\n";
870 Prs3d_TypeOfHLR aTypeOfHLR =
871 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
875 AIS_ListOfInteractive aListOfShapes;
876 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
877 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
878 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
879 anIter.More(); anIter.Next())
881 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
884 if (aShape->TypeOfHLR() != aTypeOfHLR)
885 aShape->SetTypeOfHLR (aTypeOfHLR);
889 ViewerTest::CurrentView()->Update();
894 for (Standard_Integer i = 2; i < argc; ++i)
896 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
897 TCollection_AsciiString aName (argv[i]);
899 if (!aMap.IsBound2 (aName))
901 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
904 Handle(AIS_Shape) anAISObject =
905 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
906 if (anAISObject.IsNull())
908 anAISObject->SetTypeOfHLR (aTypeOfHLR);
910 anAISObject->Redisplay();
912 ViewerTest::CurrentView()->Update();
918 //==============================================================================
919 //function : FindViewIdByWindowHandle
920 //purpose : Find theView Id in the map of views by window handle
921 //==============================================================================
922 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
923 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
925 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
926 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
928 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
929 if (aWindowHandle == theWindowHandle)
930 return anIter.Key1();
932 return TCollection_AsciiString("");
936 //==============================================================================
937 //function : ActivateView
938 //purpose : Make the view active
939 //==============================================================================
941 void ActivateView (const TCollection_AsciiString& theViewName)
943 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
946 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
947 if (!anAISContext.IsNull())
949 if (!ViewerTest::CurrentView().IsNull())
951 TCollection_AsciiString aTitle("3D View - ");
952 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
953 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
956 ViewerTest::CurrentView (aView);
957 // Update degenerate mode
958 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
959 ViewerTest::SetAISContext (anAISContext);
960 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
961 aTitle = aTitle + theViewName + "(*)";
962 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
963 #if defined(_WIN32) || defined(__WIN32__)
964 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
965 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
966 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
968 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
970 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
971 ViewerTest::CurrentView()->Redraw();
976 //==============================================================================
977 //function : RemoveView
978 //purpose : Close and remove view from display, clear maps if neccessary
979 //==============================================================================
980 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
982 if (!ViewerTest_myViews.IsBound1(theViewName))
984 cout << "Wrong view name\n";
988 // Activate another view if it's active now
989 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
991 if (ViewerTest_myViews.Extent() > 1)
993 TCollection_AsciiString aNewViewName;
994 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
995 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
996 if (anIter.Key1() != theViewName)
998 aNewViewName = anIter.Key1();
1001 ActivateView (aNewViewName);
1005 Handle(V3d_View) anEmptyView;
1006 #if defined(_WIN32) || defined(__WIN32__)
1007 Handle(WNT_Window) anEmptyWindow;
1008 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1009 Handle(Cocoa_Window) anEmptyWindow;
1011 Handle(Xw_Window) anEmptyWindow;
1013 VT_GetWindow() = anEmptyWindow;
1014 ViewerTest::CurrentView (anEmptyView);
1015 if (isContextRemoved)
1017 Handle(AIS_InteractiveContext) anEmptyContext;
1018 ViewerTest::SetAISContext(anEmptyContext);
1024 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1025 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1027 // Remove view resources
1028 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1029 ViewerTest_myViews.UnBind1(theViewName);
1032 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1033 XFlush (GetDisplayConnection()->GetDisplay());
1036 // Keep context opened only if the closed view is last to avoid
1037 // unused empty contexts
1038 if (!aCurrentContext.IsNull())
1040 // Check if there are more difined views in the viewer
1041 aCurrentContext->CurrentViewer()->InitDefinedViews();
1042 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1044 // Remove driver if there is no viewers that use it
1045 Standard_Boolean isRemoveDriver = Standard_True;
1046 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1047 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1049 if (aCurrentContext != anIter.Key2() &&
1050 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1052 isRemoveDriver = Standard_False;
1058 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1059 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1060 #if TCL_MAJOR_VERSION < 8
1061 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1063 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1068 ViewerTest_myContexts.UnBind2(aCurrentContext);
1071 cout << "3D View - " << theViewName << " was deleted.\n";
1075 //==============================================================================
1077 //purpose : Remove the view defined by its name
1078 //==============================================================================
1080 static int VClose (Draw_Interpretor& /*theDi*/,
1081 Standard_Integer theArgsNb,
1082 const char** theArgVec)
1084 NCollection_List<TCollection_AsciiString> aViewList;
1087 TCollection_AsciiString anArg (theArgVec[1]);
1089 if (anArg.IsEqual ("ALL")
1090 || anArg.IsEqual ("*"))
1092 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1093 anIter.More(); anIter.Next())
1095 aViewList.Append (anIter.Key1());
1097 if (aViewList.IsEmpty())
1099 std::cout << "No view to close\n";
1105 ViewerTest_Names aViewName (theArgVec[1]);
1106 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1108 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1111 aViewList.Append (aViewName.GetViewName());
1116 // close active view
1117 if (ViewerTest::CurrentView().IsNull())
1119 std::cerr << "No active view!\n";
1122 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1125 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1126 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1127 anIter.More(); anIter.Next())
1129 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1135 //==============================================================================
1136 //function : VActivate
1137 //purpose : Activate the view defined by its ID
1138 //==============================================================================
1140 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1144 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1145 << "Usage: " << theArgVec[0] << " ViewID\n";
1150 theDi.Eval("vviewlist");
1154 TCollection_AsciiString aNameString(theArgVec[1]);
1155 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1157 TCollection_AsciiString aTitle("3D View - ");
1158 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1159 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1160 Handle(V3d_View) anEmptyView;
1161 #if defined(_WIN32) || defined(__WIN32__)
1162 Handle(WNT_Window) anEmptyWindow;
1163 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1164 Handle(Cocoa_Window) anEmptyWindow;
1166 Handle(Xw_Window) anEmptyWindow;
1168 VT_GetWindow() = anEmptyWindow;
1169 ViewerTest::CurrentView (anEmptyView);
1170 ViewerTest::ResetEventManager();
1171 theDi << theArgVec[0] << ": all views are inactive\n";
1175 ViewerTest_Names aViewNames(aNameString);
1177 // Check if this view exists in the viewer with the driver
1178 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1180 theDi << "Wrong view name\n";
1184 // Check if it is active already
1185 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1187 theDi << theArgVec[0] << ": the view is active already\n";
1191 ActivateView (aViewNames.GetViewName());
1195 //==============================================================================
1196 //function : VViewList
1197 //purpose : Print current list of views per viewer and graphic driver ID
1198 // shared between viewers
1199 //==============================================================================
1201 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1205 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1206 << "Usage: " << theArgVec[0] << " name";
1209 if (ViewerTest_myContexts.Size() < 1)
1212 Standard_Boolean isTreeView =
1213 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1216 theDi << theArgVec[0] <<":\n";
1218 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1219 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1222 theDi << aDriverIter.Key1() << ":\n";
1224 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1225 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1227 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1231 TCollection_AsciiString aContextName(aContextIter.Key1());
1232 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1235 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1236 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1238 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1240 TCollection_AsciiString aViewName(aViewIter.Key1());
1243 if (aViewIter.Value() == ViewerTest::CurrentView())
1244 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1246 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1250 theDi << aViewName << " ";
1260 //==============================================================================
1261 //function : VT_ProcessKeyPress
1262 //purpose : Handle KeyPress event from a CString
1263 //==============================================================================
1264 void VT_ProcessKeyPress (const char* buf_ret)
1266 //cout << "KeyPress" << endl;
1267 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1268 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1269 // Letter in alphabetic order
1271 if (!strcasecmp (buf_ret, "A"))
1274 aView->SetProj(V3d_XposYnegZpos);
1276 else if (!strcasecmp (buf_ret, "D"))
1281 else if (!strcasecmp (buf_ret, "F"))
1284 if (aNisView.IsNull())
1287 aNisView->FitAll3d();
1289 else if (!strcasecmp (buf_ret, "H"))
1292 cout << "HLR" << endl;
1293 aView->SetComputedMode (!aView->ComputedMode());
1294 MyHLRIsOn = aView->ComputedMode();
1296 else if (!strcasecmp (buf_ret, "P"))
1299 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1300 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1301 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1303 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1304 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1306 AIS_ListOfInteractive aListOfShapes;
1307 aContext->DisplayedObjects(aListOfShapes);
1308 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1309 anIter.More(); anIter.Next())
1311 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1312 if (aShape.IsNull())
1314 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1315 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1317 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1318 aShape->Redisplay();
1323 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1325 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1326 if (aShape.IsNull())
1328 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1329 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1331 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1332 aShape->Redisplay();
1336 aContext->UpdateCurrentViewer();
1339 else if (!strcasecmp (buf_ret, "S"))
1341 std::cout << "setup Shaded display mode" << std::endl;
1343 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1344 if(Ctx->NbCurrents()==0 ||
1345 Ctx->NbSelected()==0)
1346 Ctx->SetDisplayMode(AIS_Shaded);
1348 if(Ctx->HasOpenedContext()){
1349 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1350 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1353 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1354 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1356 Ctx->UpdateCurrentViewer();
1359 else if (!strcasecmp (buf_ret, "U"))
1361 // Unset display mode
1362 std::cout << "reset display mode to defaults" << std::endl;
1364 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1365 if(Ctx->NbCurrents()==0 ||
1366 Ctx->NbSelected()==0)
1367 Ctx->SetDisplayMode(AIS_WireFrame);
1369 if(Ctx->HasOpenedContext()){
1370 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1371 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1374 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1375 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1377 Ctx->UpdateCurrentViewer();
1381 else if (!strcasecmp (buf_ret, "T"))
1384 aView->SetProj(V3d_Zpos);
1386 else if (!strcasecmp (buf_ret, "B"))
1389 aView->SetProj(V3d_Zneg);
1391 else if (!strcasecmp (buf_ret, "L"))
1394 aView->SetProj(V3d_Xneg);
1396 else if (!strcasecmp (buf_ret, "R"))
1399 aView->SetProj(V3d_Xpos);
1401 else if (!strcasecmp (buf_ret, "W"))
1403 std::cout << "setup WireFrame display mode" << std::endl;
1404 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1405 if(Ctx->NbCurrents()==0 ||
1406 Ctx->NbSelected()==0)
1407 Ctx->SetDisplayMode(AIS_WireFrame);
1409 if(Ctx->HasOpenedContext()){
1410 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1411 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1414 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1415 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1417 Ctx->UpdateCurrentViewer();
1420 else if (!strcasecmp (buf_ret, "Z"))
1424 cout << "ZClipping OFF" << endl;
1427 aView->SetZClippingType(V3d_OFF);
1431 cout << "ZClipping ON" << endl;
1434 aView->SetZClippingType(V3d_FRONT);
1438 else if (!strcasecmp (buf_ret, ","))
1440 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1442 else if (!strcasecmp (buf_ret, "."))
1444 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1446 else if (*buf_ret == THE_KEY_DELETE)
1448 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1450 && aCtx->NbCurrents() > 0
1451 && aCtx->NbSelected() > 0)
1453 Draw_Interprete ("verase");
1459 Standard_Integer Num = Draw::Atoi(buf_ret);
1460 if(Num>=0 && Num<=7)
1461 ViewerTest::StandardModeActivation(Num);
1465 //==============================================================================
1466 //function : VT_ProcessExpose
1467 //purpose : Redraw the View on an Expose Event
1468 //==============================================================================
1469 void VT_ProcessExpose()
1471 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1472 if (!aView3d.IsNull())
1478 //==============================================================================
1479 //function : VT_ProcessConfigure
1480 //purpose : Resize the View on an Configure Event
1481 //==============================================================================
1482 void VT_ProcessConfigure()
1484 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1485 if (aView3d.IsNull())
1490 aView3d->MustBeResized();
1495 //==============================================================================
1496 //function : VT_ProcessButton1Press
1498 //==============================================================================
1499 Standard_Boolean VT_ProcessButton1Press(
1502 Standard_Boolean pick,
1503 Standard_Boolean shift)
1505 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1507 Standard_Real X, Y, Z;
1509 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1511 Draw::Set(argv[1], X);
1512 Draw::Set(argv[2], Y);
1513 Draw::Set(argv[3], Z);}
1524 //==============================================================================
1525 //function : VT_ProcessButton1Release
1526 //purpose : End selecting
1527 //==============================================================================
1528 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1532 IsDragged = Standard_False;
1533 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1536 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1537 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1541 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1542 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1547 //==============================================================================
1548 //function : VT_ProcessButton3Press
1549 //purpose : Start Rotation
1550 //==============================================================================
1551 void VT_ProcessButton3Press()
1556 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1558 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1561 //==============================================================================
1562 //function : VT_ProcessButton3Release
1563 //purpose : End rotation
1564 //==============================================================================
1565 void VT_ProcessButton3Release()
1572 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1577 //==============================================================================
1578 //function : ProcessZClipMotion
1580 //==============================================================================
1582 void ProcessZClipMotion()
1584 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1585 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1586 static Standard_Real CurZPos = 0.;
1588 //Quantity_Length VDX, VDY;
1589 //a3DView->Size(VDX,VDY);
1590 //Standard_Real VDZ = a3DView->ZSize();
1591 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1593 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1595 // Front = Depth + width/2.
1596 Standard_Real D = 0.5;
1597 Standard_Real W = 0.1;
1603 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1605 a3DView->SetZClippingType(V3d_OFF);
1606 a3DView->SetZClippingDepth(D);
1607 a3DView->SetZClippingWidth(W);
1608 a3DView->SetZClippingType(V3d_FRONT);
1612 X_ButtonPress = X_Motion;
1613 Y_ButtonPress = Y_Motion;
1617 //==============================================================================
1618 //function : ProcessControlButton1Motion
1620 //==============================================================================
1622 static void ProcessControlButton1Motion()
1624 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1626 X_ButtonPress = X_Motion;
1627 Y_ButtonPress = Y_Motion;
1630 //==============================================================================
1631 //function : VT_ProcessControlButton2Motion
1633 //==============================================================================
1634 void VT_ProcessControlButton2Motion()
1636 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1637 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1639 dy = -dy; // Xwindow Y axis is from top to Bottom
1641 ViewerTest::CurrentView()->Panning( dx, dy );
1643 X_ButtonPress = X_Motion;
1644 Y_ButtonPress = Y_Motion;
1647 //==============================================================================
1648 //function : VT_ProcessControlButton3Motion
1649 //purpose : Rotation
1650 //==============================================================================
1651 void VT_ProcessControlButton3Motion()
1655 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1659 //==============================================================================
1660 //function : VT_ProcessMotion
1662 //==============================================================================
1663 void VT_ProcessMotion()
1665 //pre-hilights detected objects at mouse position
1667 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1668 EM->MoveTo(X_Motion, Y_Motion);
1672 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1674 Xpix = X_Motion;Ypix=Y_Motion;
1677 //==============================================================================
1678 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1679 //purpose : Switches to an axonometric, top, left and other views
1680 //==============================================================================
1682 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1684 if ( ViewerTest::CurrentView().IsNull() )
1686 di<<"Call vinit before this command, please"<<"\n";
1690 ViewerTest::CurrentView()->SetProj(ori);
1694 //==============================================================================
1696 //purpose : Switch to an Axonometric view
1697 //Draw arg : No args
1698 //==============================================================================
1700 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1702 return ViewProject(di, V3d_XposYnegZpos);
1705 //==============================================================================
1707 //purpose : Switch to a Top View
1708 //Draw arg : No args
1709 //==============================================================================
1711 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1713 return ViewProject(di, V3d_Zpos);
1716 //==============================================================================
1717 //function : VBottom
1718 //purpose : Switch to a Bottom View
1719 //Draw arg : No args
1720 //==============================================================================
1722 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1724 return ViewProject(di, V3d_Zneg);
1727 //==============================================================================
1729 //purpose : Switch to a Left View
1730 //Draw arg : No args
1731 //==============================================================================
1733 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1735 return ViewProject(di, V3d_Ypos);
1738 //==============================================================================
1740 //purpose : Switch to a Right View
1741 //Draw arg : No args
1742 //==============================================================================
1744 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1746 return ViewProject(di, V3d_Yneg);
1749 //==============================================================================
1751 //purpose : Switch to a Front View
1752 //Draw arg : No args
1753 //==============================================================================
1755 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1757 return ViewProject(di, V3d_Xpos);
1760 //==============================================================================
1762 //purpose : Switch to a Back View
1763 //Draw arg : No args
1764 //==============================================================================
1766 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1768 return ViewProject(di, V3d_Xneg);
1771 //==============================================================================
1773 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1774 //Draw arg : No args
1775 //==============================================================================
1777 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1780 di << "Q : Quit the application" << "\n";
1782 di << "========================="<<"\n";
1783 di << "F : FitAll" << "\n";
1784 di << "T : TopView" << "\n";
1785 di << "B : BottomView" << "\n";
1786 di << "R : RightView" << "\n";
1787 di << "L : LeftView" << "\n";
1788 di << "A : AxonometricView" << "\n";
1789 di << "D : ResetView" << "\n";
1791 di << "========================="<<"\n";
1792 di << "S : Shading" << "\n";
1793 di << "W : Wireframe" << "\n";
1794 di << "H : HidelLineRemoval" << "\n";
1795 di << "U : Unset display mode" << "\n";
1796 di << "Delete : Remove selection from viewer" << "\n";
1798 di << "========================="<<"\n";
1799 di << "Selection mode "<<"\n";
1800 di << "0 : Shape" <<"\n";
1801 di << "1 : Vertex" <<"\n";
1802 di << "2 : Edge" <<"\n";
1803 di << "3 : Wire" <<"\n";
1804 di << "4 : Face" <<"\n";
1805 di << "5 : Shell" <<"\n";
1806 di << "6 : Solid" <<"\n";
1807 di << "7 : Compound" <<"\n";
1809 di << "========================="<<"\n";
1810 di << "Z : Switch Z clipping On/Off" << "\n";
1811 di << ", : Hilight next detected" << "\n";
1812 di << ". : Hilight previous detected" << "\n";
1819 static Standard_Boolean Ppick = 0;
1820 static Standard_Integer Pargc = 0;
1821 static const char** Pargv = NULL;
1824 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1829 if (!ViewerTest_myViews.IsEmpty()) {
1831 WPARAM fwKeys = wParam;
1836 // Delete view from map of views
1837 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1842 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1843 || ViewerTest::CurrentView().IsNull())
1845 // Activate inactive window
1846 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1848 ActivateView (FindViewIdByWindowHandle(hwnd));
1853 IsDragged = Standard_False;
1856 HDC hdc = GetDC( hwnd );
1857 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1858 SetROP2( hdc, R2_NOT );
1859 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1860 ReleaseDC( hwnd, hdc );
1862 const Handle(ViewerTest_EventManager) EM =
1863 ViewerTest::CurrentEventManager();
1864 if ( fwKeys & MK_SHIFT )
1865 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1866 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1868 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1869 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1871 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1873 case WM_LBUTTONDOWN:
1874 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1876 IsDragged = Standard_True;
1877 DragFirst = Standard_True;
1878 X_ButtonPress = LOWORD(lParam);
1879 Y_ButtonPress = HIWORD(lParam);
1881 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1888 HDC hdc = GetDC( hwnd );
1890 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1891 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1892 SetROP2( hdc, R2_NOT );
1895 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1897 DragFirst = Standard_False;
1898 X_Motion = LOWORD(lParam);
1899 Y_Motion = HIWORD(lParam);
1901 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1903 SelectObject( hdc, anObj );
1905 ReleaseDC( hwnd, hdc );
1908 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1912 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1916 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1920 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1927 if ( !ViewerTest::CurrentView().IsNull() ) {
1932 BeginPaint(hwnd, &ps);
1933 EndPaint(hwnd, &ps);
1938 VT_ProcessConfigure();
1942 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1945 c[0] = (char) wParam;
1947 if (wParam == VK_DELETE)
1949 c[0] = THE_KEY_DELETE;
1951 VT_ProcessKeyPress (c);
1959 VT_ProcessButton3Release();
1962 case WM_LBUTTONDOWN:
1963 case WM_MBUTTONDOWN:
1964 case WM_RBUTTONDOWN:
1966 WPARAM fwKeys = wParam;
1970 X_ButtonPress = LOWORD(lParam);
1971 Y_ButtonPress = HIWORD(lParam);
1973 if (Msg == WM_LBUTTONDOWN)
1975 if (fwKeys & MK_CONTROL)
1977 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1981 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1984 else if (Msg == WM_RBUTTONDOWN)
1987 VT_ProcessButton3Press();
1994 //cout << "\t WM_MOUSEMOVE" << endl;
1995 WPARAM fwKeys = wParam;
1996 X_Motion = LOWORD(lParam);
1997 Y_Motion = HIWORD(lParam);
2000 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2002 X_ButtonPress = LOWORD(lParam);
2003 Y_ButtonPress = HIWORD(lParam);
2005 if ( fwKeys & MK_RBUTTON ) {
2007 VT_ProcessButton3Press();
2011 if ( fwKeys & MK_CONTROL ) {
2012 if ( fwKeys & MK_LBUTTON ) {
2013 ProcessControlButton1Motion();
2015 else if ( fwKeys & MK_MBUTTON ||
2016 ((fwKeys&MK_LBUTTON) &&
2017 (fwKeys&MK_RBUTTON) ) ){
2018 VT_ProcessControlButton2Motion();
2020 else if ( fwKeys & MK_RBUTTON ) {
2021 VT_ProcessControlButton3Motion();
2025 else if ( fwKeys & MK_SHIFT ) {
2026 if ( fwKeys & MK_MBUTTON ||
2027 ((fwKeys&MK_LBUTTON) &&
2028 (fwKeys&MK_RBUTTON) ) ) {
2029 cout << "ProcessZClipMotion()" << endl;
2030 ProcessZClipMotion();
2034 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2036 if ((fwKeys & MK_MBUTTON
2037 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2039 ProcessZClipMotion();
2050 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2055 return DefWindowProc( hwnd, Msg, wParam, lParam );
2061 //==============================================================================
2062 //function : ViewerMainLoop
2063 //purpose : Get a Event on the view and dispatch it
2064 //==============================================================================
2067 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2069 Ppick = (argc > 0)? 1 : 0;
2077 cout << "Start picking" << endl;
2079 while ( Ppick == 1 ) {
2080 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2081 if (GetMessage(&msg, NULL, 0, 0) ) {
2082 TranslateMessage(&msg);
2083 DispatchMessage(&msg);
2087 cout << "Picking done" << endl;
2093 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2095 int min( int a, int b )
2103 int max( int a, int b )
2111 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2114 static XEvent aReport;
2115 Standard_Boolean pick = argc > 0;
2116 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2117 XNextEvent (aDisplay, &aReport);
2119 // Handle event for the chosen display connection
2120 switch (aReport.type) {
2123 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2126 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2132 // Activate inactive view
2133 Window aWindow = GetWindowHandle(VT_GetWindow());
2134 if(aWindow != aReport.xfocus.window)
2136 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2145 case ConfigureNotify:
2147 VT_ProcessConfigure();
2156 XComposeStatus status_in_out;
2158 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2159 (char *) buf_ret , 10 ,
2160 &ks_ret , &status_in_out ) ;
2163 buf_ret[ret_len] = '\0' ;
2167 VT_ProcessKeyPress (buf_ret);
2173 X_ButtonPress = aReport.xbutton.x;
2174 Y_ButtonPress = aReport.xbutton.y;
2176 if (aReport.xbutton.button == Button1)
2178 if (aReport.xbutton.state & ControlMask)
2180 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2184 IsDragged = Standard_True;
2185 DragFirst = Standard_True;
2188 else if (aReport.xbutton.button == Button3)
2191 VT_ProcessButton3Press();
2201 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2202 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2203 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2206 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2207 if( aContext.IsNull() )
2209 cout << "The context is null. Please use vinit before createmesh" << endl;
2213 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2214 if( aReport.xbutton.button==1 )
2218 aContext->ShiftSelect();
2227 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2228 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2229 ViewerTest::CurrentView());
2233 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2234 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2235 ViewerTest::CurrentView() );
2238 VT_ProcessButton3Release();
2240 IsDragged = Standard_False;
2243 VT_ProcessButton3Release();
2248 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2254 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2255 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2256 XSetFunction( aDisplay, gc, GXinvert );
2259 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2261 X_Motion = aReport.xmotion.x;
2262 Y_Motion = aReport.xmotion.y;
2263 DragFirst = Standard_False;
2265 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2269 X_Motion = aReport.xmotion.x;
2270 Y_Motion = aReport.xmotion.y;
2272 // remove all the ButtonMotionMaskr
2273 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2275 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2276 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2278 Quantity_Length VDX, VDY;
2280 ViewerTest::CurrentView()->Size(VDX,VDY);
2281 Standard_Real VDZ =0 ;
2282 VDZ = ViewerTest::CurrentView()->ZSize();
2284 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2286 Quantity_Length dx = 0 ;
2287 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2291 dx = dx / VDX * VDZ;
2295 ViewerTest::CurrentView()->Redraw();
2299 if ( aReport.xmotion.state & ControlMask ) {
2300 if ( aReport.xmotion.state & Button1Mask ) {
2301 ProcessControlButton1Motion();
2303 else if ( aReport.xmotion.state & Button2Mask ) {
2304 VT_ProcessControlButton2Motion();
2306 else if ( aReport.xmotion.state & Button3Mask ) {
2307 VT_ProcessControlButton3Motion();
2321 //==============================================================================
2322 //function : VProcessEvents
2323 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2324 // event in the Viewer window
2325 //==============================================================================
2327 static void VProcessEvents(ClientData,int)
2329 NCollection_Vector<int> anEventNumbers;
2330 // Get number of messages from every display
2331 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2332 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2334 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2336 // Handle events for every display
2337 int anEventIter = 0;
2338 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2339 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2341 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2342 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2344 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2345 int anEventResult = ViewerMainLoop( 0, NULL);
2346 // If window is closed or context was not found finish current event processing loop
2352 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2357 //==============================================================================
2358 //function : OSWindowSetup
2359 //purpose : Setup for the X11 window to be able to cath the event
2360 //==============================================================================
2363 static void OSWindowSetup()
2365 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2368 Window window = VT_GetWindow()->XWindow();
2369 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2370 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2371 XSynchronize(aDisplay, 1);
2373 // X11 : For keyboard on SUN
2375 wmhints.flags = InputHint;
2378 XSetWMHints( aDisplay, window, &wmhints);
2380 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2381 ButtonPressMask | ButtonReleaseMask |
2382 StructureNotifyMask |
2384 Button1MotionMask | Button2MotionMask |
2385 Button3MotionMask | FocusChangeMask
2387 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2388 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2390 XSynchronize(aDisplay, 0);
2399 //==============================================================================
2402 //purpose : Fitall, no DRAW arguments
2403 //Draw arg : No args
2404 //==============================================================================
2406 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2408 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2409 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2410 if (V.IsNull() == Standard_False) {
2412 } else if (aView.IsNull() == Standard_False) {
2418 //==============================================================================
2420 //purpose : ZFitall, no DRAW arguments
2421 //Draw arg : No args
2422 //==============================================================================
2424 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2426 Handle(V3d_View) V = ViewerTest::CurrentView();
2427 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2430 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2432 Handle(V3d_View) V = ViewerTest::CurrentView();
2433 if ( !V.IsNull() ) V->Redraw(); return 0;
2437 //==============================================================================
2439 //purpose : Remove all the object from the viewer
2440 //Draw arg : No args
2441 //==============================================================================
2443 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2445 Handle(V3d_View) V = ViewerTest::CurrentView();
2447 ViewerTest::Clear();
2451 //==============================================================================
2454 //==============================================================================
2456 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2457 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2460 di << argv[0] << "Invalid number of arguments" << "\n";
2464 while (ViewerMainLoop( argc, argv)) {
2470 //==============================================================================
2471 //function : InitViewerTest
2472 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2473 //==============================================================================
2475 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2477 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2478 ViewerTest::SetAISContext(theContext);
2479 aViewer->InitActiveViews();
2480 Handle(V3d_View) aView = aViewer->ActiveView();
2481 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2482 ViewerTest::ResetEventManager();
2483 Handle(Aspect_Window) aWindow = aView->Window();
2484 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2486 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2488 static int aFirst = 1;
2490 #if TCL_MAJOR_VERSION < 8
2491 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2492 TK_READABLE, VProcessEvents, (ClientData) 0);
2494 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2495 TK_READABLE, VProcessEvents, (ClientData) 0);
2502 //==============================================================================
2504 //purpose : Load image as background
2505 //==============================================================================
2507 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2509 if (argc < 2 || argc > 3)
2511 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2512 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2516 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2517 if(AISContext.IsNull())
2519 di << "use 'vinit' command before " << argv[0] << "\n";
2523 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2526 const char* szType = argv[2];
2527 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2528 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2529 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2530 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2533 di << "Wrong fill type : " << szType << "\n";
2534 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2539 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2540 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2545 //==============================================================================
2546 //function : VSetBgMode
2547 //purpose : Change background image fill type
2548 //==============================================================================
2550 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2554 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2555 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2559 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2560 if(AISContext.IsNull())
2562 di << "use 'vinit' command before " << argv[0] << "\n";
2565 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2566 const char* szType = argv[1];
2567 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2568 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2569 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2570 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2573 di << "Wrong fill type : " << szType << "\n";
2574 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2577 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2578 V3dView->SetBgImageStyle(aFillType, Standard_True);
2582 //==============================================================================
2583 //function : VSetGradientBg
2584 //purpose : Mount gradient background
2585 //==============================================================================
2586 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2590 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2591 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2592 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2593 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2597 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2598 if(AISContext.IsNull())
2600 di << "use 'vinit' command before " << argv[0] << "\n";
2606 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2607 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2608 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2609 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2611 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2612 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2613 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2615 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2616 int aType = Draw::Atoi(argv[7]);
2617 if( aType < 0 || aType > 8 )
2619 di << "Wrong fill type " << "\n";
2620 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2621 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2625 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2627 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2628 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2634 //==============================================================================
2635 //function : VSetGradientBgMode
2636 //purpose : Change gradient background fill style
2637 //==============================================================================
2638 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2642 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2643 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2644 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2648 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2649 if(AISContext.IsNull())
2651 di << "use 'vinit' command before " << argv[0] << "\n";
2656 int aType = Draw::Atoi(argv[1]);
2657 if( aType < 0 || aType > 8 )
2659 di << "Wrong fill type " << "\n";
2660 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2661 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2665 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2667 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2668 V3dView->SetBgGradientStyle( aMethod, 1 );
2674 //==============================================================================
2675 //function : VSetColorBg
2676 //purpose : Set color background
2677 //==============================================================================
2678 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2682 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2683 di << "R,G,B = [0..255]" << "\n";
2687 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2688 if(AISContext.IsNull())
2690 di << "use 'vinit' command before " << argv[0] << "\n";
2696 Standard_Real R = Draw::Atof(argv[1])/255.;
2697 Standard_Real G = Draw::Atof(argv[2])/255.;
2698 Standard_Real B = Draw::Atof(argv[3])/255.;
2699 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2701 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2702 V3dView->SetBackgroundColor( aColor );
2709 //==============================================================================
2711 //purpose : View Scaling
2712 //==============================================================================
2714 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2716 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2717 if ( V3dView.IsNull() ) return 1;
2720 di << argv[0] << "Invalid number of arguments" << "\n";
2723 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2726 //==============================================================================
2727 //function : VTestZBuffTrihedron
2728 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2729 //==============================================================================
2731 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2733 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2734 if ( V3dView.IsNull() ) return 1;
2736 V3dView->ZBufferTriedronSetup();
2739 // Set up default trihedron parameters
2740 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2744 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2745 const char* aPosType = argv[1];
2747 if ( strcmp(aPosType, "center") == 0 )
2749 aPosition = Aspect_TOTP_CENTER;
2751 if (strcmp(aPosType, "left_lower") == 0)
2753 aPosition = Aspect_TOTP_LEFT_LOWER;
2755 if (strcmp(aPosType, "left_upper") == 0)
2757 aPosition = Aspect_TOTP_LEFT_UPPER;
2759 if (strcmp(aPosType, "right_lower") == 0)
2761 aPosition = Aspect_TOTP_RIGHT_LOWER;
2763 if (strcmp(aPosType, "right_upper") == 0)
2765 aPosition = Aspect_TOTP_RIGHT_UPPER;
2768 di << argv[1] << " Invalid type of alignment" << "\n";
2769 di << "Must be one of [ center, left_lower," << "\n";
2770 di << "left_upper, right_lower, right_upper ]" << "\n";
2774 Standard_Real R = Draw::Atof(argv[2])/255.;
2775 Standard_Real G = Draw::Atof(argv[3])/255.;
2776 Standard_Real B = Draw::Atof(argv[4])/255.;
2777 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2779 Standard_Real aScale = Draw::Atof(argv[5]);
2783 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2787 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2788 const char* aPresType = argv[6];
2790 if ( strcmp(aPresType, "wireframe") == 0 )
2792 aPresentation = V3d_WIREFRAME;
2794 if (strcmp(aPresType, "zbuffer") == 0)
2796 aPresentation = V3d_ZBUFFER;
2799 di << argv[6] << " Invalid type of visualization" << "\n";
2800 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2804 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2808 di << argv[0] << " Invalid number of arguments" << "\n";
2817 //==============================================================================
2818 //function : VRotate
2819 //purpose : Camera Rotating
2820 //==============================================================================
2822 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2823 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2824 if ( V3dView.IsNull() ) {
2829 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2831 } else if ( argc == 7 ) {
2832 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]) );
2835 di << argv[0] << " Invalid number of arguments" << "\n";
2840 //==============================================================================
2842 //purpose : View zoom in / out (relative to current zoom)
2843 //==============================================================================
2845 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2846 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2847 if ( V3dView.IsNull() ) {
2852 Standard_Real coef = Draw::Atof(argv[1]);
2853 if ( coef <= 0.0 ) {
2854 di << argv[1] << "Invalid value" << "\n";
2857 V3dView->SetZoom( Draw::Atof(argv[1]) );
2860 di << argv[0] << " Invalid number of arguments" << "\n";
2865 //==============================================================================
2867 //purpose : View panning (in pixels)
2868 //==============================================================================
2870 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2871 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2872 if ( V3dView.IsNull() ) return 1;
2875 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2878 di << argv[0] << " Invalid number of arguments" << "\n";
2884 //==============================================================================
2885 //function : VExport
2886 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2887 //==============================================================================
2889 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2891 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2892 if (V3dView.IsNull())
2897 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2901 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2902 TCollection_AsciiString aFormatStr;
2904 TCollection_AsciiString aFileName (argv[1]);
2905 Standard_Integer aLen = aFileName.Length();
2909 aFormatStr = TCollection_AsciiString (argv[2]);
2913 if (aFileName.Value (aLen - 2) == '.')
2915 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2917 else if (aFileName.Value (aLen - 3) == '.')
2919 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2923 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2929 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2933 aFormatStr.UpperCase();
2934 if (aFormatStr == "PS")
2935 anExpFormat = Graphic3d_EF_PostScript;
2936 else if (aFormatStr == "EPS")
2937 anExpFormat = Graphic3d_EF_EnhPostScript;
2938 else if (aFormatStr == "TEX")
2939 anExpFormat = Graphic3d_EF_TEX;
2940 else if (aFormatStr == "PDF")
2941 anExpFormat = Graphic3d_EF_PDF;
2942 else if (aFormatStr == "SVG")
2943 anExpFormat = Graphic3d_EF_SVG;
2944 else if (aFormatStr == "PGF")
2945 anExpFormat = Graphic3d_EF_PGF;
2946 else if (aFormatStr == "EMF")
2947 anExpFormat = Graphic3d_EF_EMF;
2950 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2955 if (!V3dView->View()->Export (argv[1], anExpFormat))
2957 di << "Error: export of image to " << aFormatStr << " failed!\n";
2960 catch (Standard_Failure)
2962 di << "Error: export of image to " << aFormatStr << " failed";
2963 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2968 //==============================================================================
2969 //function : VColorScale
2970 //purpose : representation color scale
2971 //==============================================================================
2972 #include <V3d_ColorScale.hxx>
2974 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2976 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2978 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2982 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2983 if(aContext.IsNull()) {
2984 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2988 Standard_Real minRange = 0. , maxRange = 100. ;
2990 Standard_Integer numIntervals = 10 ;
2991 Standard_Integer textHeight = 16;
2992 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2993 Standard_Real X = 0., Y = 0. ;
2999 minRange = Draw::Atof( argv[1] );
3000 maxRange = Draw::Atof( argv[2] );
3001 numIntervals = Draw::Atoi( argv[3] );
3004 textHeight = Draw::Atoi( argv[4] );
3006 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
3009 X = Draw::Atof( argv[6] );
3010 Y = Draw::Atof( argv[7] );
3013 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3014 if ( curView.IsNull( ) )
3016 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3017 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3018 if( ! aCS.IsNull( ) )
3020 aCS->SetPosition( X , Y );
3021 aCS->SetHeight( 0.95) ;
3022 aCS->SetTextHeight( textHeight );
3023 aCS->SetRange( minRange , maxRange );
3024 aCS->SetNumberOfIntervals( numIntervals );
3025 aCS->SetLabelPosition( position );
3026 if( !curView->ColorScaleIsDisplayed() )
3027 curView->ColorScaleDisplay( );
3032 //==============================================================================
3033 //function : VGraduatedTrihedron
3034 //purpose : Displays a graduated trihedron
3035 //==============================================================================
3037 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3039 const char *str = arg;
3042 unsigned short c1 = *str++;
3043 unsigned short c2 = *str++;
3044 if (!c1 || !c2) break;
3045 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3049 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3052 if (argc != 2 && argc < 5)
3054 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3055 di<<"Usage: type help "<<argv[0]<<"\n";
3056 return 1; //TCL_ERROR
3059 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3061 // Create 3D view if it doesn't exist
3062 if ( aV3dView.IsNull() )
3064 ViewerTest::ViewerInit();
3065 aV3dView = ViewerTest::CurrentView();
3066 if( aV3dView.IsNull() )
3068 di << "Error: Cannot create a 3D view\n";
3069 return 1; //TCL_ERROR
3073 // Erase (==0) or display (!=0)
3074 const int display = Draw::Atoi(argv[1]);
3079 TCollection_AsciiString font;
3081 font.AssignCat("Courier");
3083 font.AssignCat(argv[5]);
3085 // Text is multibyte
3086 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3089 TCollection_ExtendedString xname, yname, zname;
3094 AddMultibyteString(xname, argv[2]);
3095 AddMultibyteString(yname, argv[3]);
3096 AddMultibyteString(zname, argv[4]);
3112 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3113 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3114 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3115 Standard_True/*drawgrid*/,
3116 Standard_True/*drawaxes*/,
3117 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3118 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3119 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3120 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3121 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3122 Quantity_NOC_WHITE/*gridcolor*/,
3123 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3124 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3127 aV3dView->GraduatedTrihedronErase();
3129 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3135 //==============================================================================
3136 //function : VPrintView
3137 //purpose : Test printing algorithm, print the view to image file with given
3138 // width and height. Printing implemented only for WNT.
3139 //==============================================================================
3140 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3144 di << "Printing implemented only for wnt!\n";
3148 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3149 Handle(V3d_View) aView = NULL;
3150 aContextAIS = ViewerTest::GetAISContext();
3151 if (!aContextAIS.IsNull())
3153 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3154 Vwr->InitActiveViews();
3155 if(Vwr->MoreActiveViews())
3156 aView = Vwr->ActiveView();
3162 di << "Call vinit before!\n";
3167 di << "Use: " << argv[0];
3168 di << " width height filename [print algo=0]\n";
3169 di << "width, height of the intermediate buffer for operation\n";
3170 di << "algo : {0|1}\n";
3171 di << " 0 - stretch algorithm\n";
3172 di << " 1 - tile algorithm\n";
3173 di << "test printing algorithms into an intermediate buffer\n";
3174 di << "with saving output to an image file\n";
3178 // get the input params
3179 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3180 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3181 Standard_Integer aMode = 0;
3182 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3184 aMode = Draw::Atoi (argv[4]);
3186 // check the input parameters
3187 if (aWidth <= 0 || aHeight <= 0)
3189 di << "Width and height must be positive values!\n";
3192 if (aMode != 0 && aMode != 1)
3195 // define compatible bitmap
3196 HDC anDC = CreateCompatibleDC(0);
3197 BITMAPINFO aBitmapData;
3198 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3199 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3200 aBitmapData.bmiHeader.biWidth = aWidth ;
3201 aBitmapData.bmiHeader.biHeight = aHeight;
3202 aBitmapData.bmiHeader.biPlanes = 1;
3203 aBitmapData.bmiHeader.biBitCount = 24;
3204 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3205 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3206 aBitmapData.bmiHeader.biClrUsed = 0;
3207 aBitmapData.bmiHeader.biClrImportant = 0;
3208 aBitmapData.bmiHeader.biCompression = BI_RGB;
3209 aBitmapData.bmiHeader.biSizeImage = 0;
3211 // Create Device Independent Bitmap
3212 void* aBitsOut = NULL;
3213 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3214 &aBitsOut, NULL, 0);
3215 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3217 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3218 if (aBitsOut != NULL)
3221 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3223 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3225 // succesfully printed into an intermediate buffer
3228 Image_PixMap aWrapper;
3229 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3230 aWrapper.SetTopDown (false);
3232 Image_AlienPixMap anImageBitmap;
3233 anImageBitmap.InitCopy (aWrapper);
3234 isSaved = anImageBitmap.Save (aFileName);
3238 di << "Print operation failed due to printing errors or\n";
3239 di << "insufficient memory available\n";
3240 di << "Please, try to use smaller dimensions for this test\n";
3241 di << "command, as it allocates intermediate buffer for storing\n";
3242 di << "the result\n";
3247 di << "Can't allocate memory for intermediate buffer\n";
3248 di << "Please use smaller dimensions\n";
3253 SelectObject (anDC, anOldBitmap);
3254 DeleteObject (aMemoryBitmap);
3260 di << "Save to file operation failed. This operation may fail\n";
3261 di << "if you don't have enough available memory, then you can\n";
3262 di << "use smaller dimensions for the output file\n";
3271 //==============================================================================
3272 //function : VZLayer
3273 //purpose : Test z layer operations for v3d viewer
3274 //==============================================================================
3275 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3277 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3278 if (aContextAIS.IsNull())
3280 di << "Call vinit before!\n";
3285 di << "Use: vzlayer " << argv[0];
3286 di << " add/del/get [id]\n";
3287 di << " add - add new z layer to viewer and print its id\n";
3288 di << " del - del z layer by its id\n";
3289 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3290 di << "id - the layer identificator value defined when removing z layer\n";
3294 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3295 if (aViewer.IsNull())
3297 di << "No active viewer!\n";
3301 // perform operation
3302 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3305 Standard_Integer aNewId;
3306 if (!aViewer->AddZLayer (aNewId))
3308 di << "Impossible to add new z layer!\n";
3312 di << "New z layer added with index: " << aNewId << "\n";
3314 else if (anOp == "del")
3318 di << "Please also provide as argument id of z layer to remove\n";
3322 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3323 if (!aViewer->RemoveZLayer (aDelId))
3325 di << "Impossible to remove the z layer or invalid id!\n";
3329 di << "Z layer " << aDelId << " has been removed\n";
3331 else if (anOp == "get")
3333 TColStd_SequenceOfInteger anIds;
3334 aViewer->GetAllZLayers (anIds);
3335 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3337 di << anIds.Value (aSeqIdx) << " ";
3344 di << "Invalid operation, please use { add / del / get }\n";
3351 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3353 // this class provides a presentation of text item in v3d view under-/overlayer
3354 class V3d_TextItem : public Visual3d_LayerItem
3359 DEFINE_STANDARD_RTTI(V3d_TextItem)
3362 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3363 const Standard_Real theX1,
3364 const Standard_Real theY1,
3365 const Standard_Real theHeight,
3366 const TCollection_AsciiString& theFontName,
3367 const Quantity_Color& theColor,
3368 const Quantity_Color& theSubtitleColor,
3369 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3370 const Handle(Visual3d_Layer)& theLayer);
3373 Standard_EXPORT void RedrawLayerPrs();
3379 TCollection_AsciiString myText;
3380 Standard_Real myHeight;
3381 Handle(Visual3d_Layer) myLayer;
3382 Quantity_Color myColor;
3383 Quantity_Color mySubtitleColor;
3384 Aspect_TypeOfDisplayText myType;
3385 TCollection_AsciiString myFontName;
3388 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3389 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3391 // create and add to display the text item
3392 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3393 const Standard_Real theX1,
3394 const Standard_Real theY1,
3395 const Standard_Real theHeight,
3396 const TCollection_AsciiString& theFontName,
3397 const Quantity_Color& theColor,
3398 const Quantity_Color& theSubtitleColor,
3399 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3400 const Handle(Visual3d_Layer)& theLayer)
3401 : myX1 (theX1), myY1 (theY1),
3403 myHeight (theHeight),
3406 mySubtitleColor (theSubtitleColor),
3407 myType (theTypeOfDisplay),
3408 myFontName (theFontName)
3410 if (!myLayer.IsNull ())
3411 myLayer->AddLayerItem (this);
3415 void V3d_TextItem::RedrawLayerPrs ()
3417 if (myLayer.IsNull ())
3420 myLayer->SetColor (myColor);
3421 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3422 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3425 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3427 // The Visual3d_LayerItem line item for "vlayerline" command
3428 // it provides a presentation of line with user-defined
3429 // linewidth, linetype and transparency.
3430 class V3d_LineItem : public Visual3d_LayerItem
3434 DEFINE_STANDARD_RTTI(V3d_LineItem)
3437 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3438 Standard_Real X2, Standard_Real Y2,
3439 V3d_LayerMgrPointer theLayerMgr,
3440 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3441 Standard_Real theWidth = 0.5,
3442 Standard_Real theTransp = 1.0);
3445 Standard_EXPORT void RedrawLayerPrs();
3449 Standard_Real myX1, myY1, myX2, myY2;
3450 V3d_LayerMgrPointer myLayerMgr;
3451 Aspect_TypeOfLine myType;
3452 Standard_Real myWidth;
3453 Standard_Real myTransparency;
3456 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3457 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3459 // default constructor for line item
3460 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3461 Standard_Real X2, Standard_Real Y2,
3462 V3d_LayerMgrPointer theLayerMgr,
3463 Aspect_TypeOfLine theType,
3464 Standard_Real theWidth,
3465 Standard_Real theTransp) :
3466 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3467 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3469 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3470 myLayerMgr->Overlay()->AddLayerItem (this);
3474 void V3d_LineItem::RedrawLayerPrs ()
3476 Handle (Visual3d_Layer) aOverlay;
3479 aOverlay = myLayerMgr->Overlay();
3481 if (!aOverlay.IsNull())
3483 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3484 aOverlay->SetColor(aColor);
3485 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3486 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3487 aOverlay->BeginPolyline();
3488 aOverlay->AddVertex(myX1, myY1);
3489 aOverlay->AddVertex(myX2, myY2);
3490 aOverlay->ClosePrimitive();
3494 //=============================================================================
3495 //function : VLayerLine
3496 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3497 // : linewidth, transparency coefficient
3498 //============================================================================
3499 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3501 // get the active view
3502 Handle(V3d_View) aView = ViewerTest::CurrentView();
3505 di << "Call vinit before!\n";
3510 di << "Use: " << argv[0];
3511 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3512 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3513 di << " 0 - solid \n";
3514 di << " 1 - dashed \n";
3515 di << " 2 - dot \n";
3516 di << " 3 - dashdot\n";
3517 di << " transparency : { 0.0 - 1.0 } \n";
3518 di << " 0.0 - transparent\n";
3519 di << " 1.0 - visible \n";
3523 // get the input params
3524 Standard_Real X1 = Draw::Atof(argv[1]);
3525 Standard_Real Y1 = Draw::Atof(argv[2]);
3526 Standard_Real X2 = Draw::Atof(argv[3]);
3527 Standard_Real Y2 = Draw::Atof(argv[4]);
3529 Standard_Real aWidth = 0.5;
3530 Standard_Integer aType = 0;
3531 Standard_Real aTransparency = 1.0;
3535 aWidth = Draw::Atof(argv[5]);
3539 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3544 aTransparency = Draw::Atof(argv[7]);
3545 if (aTransparency < 0 || aTransparency > 1.0)
3546 aTransparency = 1.0;
3549 // select appropriate line type
3550 Aspect_TypeOfLine aLineType;
3554 aLineType = Aspect_TOL_DASH;
3558 aLineType = Aspect_TOL_DOT;
3562 aLineType = Aspect_TOL_DOTDASH;
3566 aLineType = Aspect_TOL_SOLID;
3569 // replace layer manager
3570 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3571 aView->SetLayerMgr(aMgr);
3574 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3580 aView->MustBeResized();
3586 //=======================================================================
3587 //function : VOverlayText
3588 //purpose : Test text displaying in view overlay
3589 //=======================================================================
3590 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3592 // get the active view
3593 Handle(V3d_View) aView = ViewerTest::CurrentView();
3596 di << "No active view. Please call vinit.\n";
3599 else if (argc < 4 || argc > 13)
3601 di << "Use: " << argv[0];
3602 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3603 di << "[background_color: R G B]\n";
3604 di << " height - pixel height of the text (default=10.0)\n";
3605 di << " font_name - name of font (default=courier)\n";
3606 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3607 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
3608 di << " background_color- R G B values used for subtitle and decal text\n";
3609 di << "(default=255.0 255.0 255.0)\n";
3613 TCollection_AsciiString aText (argv[1]);
3614 Standard_Real aPosX = Draw::Atof(argv[2]);
3615 Standard_Real aPosY = Draw::Atof(argv[3]);
3616 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3619 TCollection_AsciiString aFontName = "Courier";
3621 aFontName = TCollection_AsciiString (argv[5]);
3624 Quantity_Parameter aColorRed = 1.0;
3625 Quantity_Parameter aColorGreen = 1.0;
3626 Quantity_Parameter aColorBlue = 1.0;
3629 aColorRed = Draw::Atof (argv[6])/255.;
3630 aColorGreen = Draw::Atof (argv[7])/255.;
3631 aColorBlue = Draw::Atof (argv[8])/255.;
3635 TCollection_AsciiString aDispStr;
3637 aDispStr = TCollection_AsciiString (argv[9]);
3639 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3640 if (aDispStr.IsEqual ("subtitle"))
3641 aTextType = Aspect_TODT_SUBTITLE;
3642 else if (aDispStr.IsEqual ("decal"))
3643 aTextType = Aspect_TODT_DEKALE;
3644 else if (aDispStr.IsEqual ("blend"))
3645 aTextType = Aspect_TODT_BLEND;
3646 else if (aDispStr.IsEqual ("dimension"))
3647 aTextType = Aspect_TODT_DIMENSION;
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 : VDefaults
5281 //===============================================================================================
5282 static int VDefaults (Draw_Interpretor& theDi,
5283 Standard_Integer theArgsNb,
5284 const char** theArgVec)
5286 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5289 std::cerr << "No active viewer!\n";
5293 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
5296 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
5298 theDi << "DeflType: relative\n"
5299 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
5303 theDi << "DeflType: absolute\n"
5304 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
5306 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
5310 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5312 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5313 TCollection_AsciiString aKey, aValue;
5314 if (!splitParameter (anArg, aKey, aValue)
5315 || aValue.IsEmpty())
5317 std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
5322 if (aKey == "ABSDEFL"
5323 || aKey == "ABSOLUTEDEFLECTION"
5325 || aKey == "DEFLECTION")
5327 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
5328 aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
5330 else if (aKey == "RELDEFL"
5331 || aKey == "RELATIVEDEFLECTION"
5332 || aKey == "DEVCOEFF"
5333 || aKey == "DEVIATIONCOEFF"
5334 || aKey == "DEVIATIONCOEFFICIENT")
5336 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
5337 aDefParams->SetDeviationCoefficient (aValue.RealValue());
5339 else if (aKey == "ANGDEFL"
5340 || aKey == "ANGULARDEFL"
5341 || aKey == "ANGULARDEFLECTION")
5343 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
5344 aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
5348 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
5355 //==============================================================================
5356 //function : VClInfo
5357 //purpose : Prints info about active OpenCL device
5358 //==============================================================================
5360 static Standard_Integer VClInfo (Draw_Interpretor& theDi,
5364 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5365 if (aContextAIS.IsNull())
5367 std::cerr << "Call vinit before!\n";
5371 Handle(OpenGl_GraphicDriver) aDrv = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5372 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
5373 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> anInfo;
5376 || !aDrv->GetOpenClDeviceInfo (*aCView, anInfo))
5378 theDi << "OpenCL device info is unavailable!\n";
5382 theDi << "OpenCL device info:\n";
5383 for (NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator anIter (anInfo);
5384 anIter.More(); anIter.Next())
5386 theDi << anIter.Key() << ": \t" << anIter.Value() << "\n";
5391 //=======================================================================
5392 //function : VRaytrace
5393 //purpose : Enables/disables OpenCL-based ray-tracing
5394 //=======================================================================
5396 static Standard_Integer VRaytrace (Draw_Interpretor& ,
5397 Standard_Integer theArgNb,
5398 const char** theArgVec)
5400 Handle(V3d_View) aView = ViewerTest::CurrentView();
5403 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
5408 || Draw::Atoi (theArgVec[1]))
5410 aView->SetRaytracingMode();
5414 aView->SetRasterizationMode();
5420 //=======================================================================
5421 //function : VSetRaytraceMode
5422 //purpose : Enables/disables features of OpenCL-based ray-tracing
5423 //=======================================================================
5425 static Standard_Integer VSetRaytraceMode (Draw_Interpretor&,
5426 Standard_Integer theArgNb,
5427 const char ** theArgVec)
5429 Handle(V3d_View) aView = ViewerTest::CurrentView();
5432 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
5435 else if (theArgNb < 2)
5437 std::cerr << "Usage : " << theArgVec[0] << " [shad=0|1] [refl=0|1] [aa=0|1]\n";
5441 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5443 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5445 if (anArg.Search ("shad=") > -1)
5447 if (anArg.Token ("=", 2).IntegerValue() != 0)
5448 aView->EnableRaytracedShadows();
5450 aView->DisableRaytracedShadows();
5452 else if (anArg.Search ("refl=") > -1)
5454 if (anArg.Token ("=", 2).IntegerValue() != 0)
5455 aView->EnableRaytracedReflections();
5457 aView->DisableRaytracedReflections();
5459 else if (anArg.Search ("aa=") > -1)
5461 if (anArg.Token ("=", 2).IntegerValue() != 0)
5462 aView->EnableRaytracedAntialiasing();
5464 aView->DisableRaytracedAntialiasing();
5468 std::cerr << "Unknown argument: " << anArg << "\n";
5476 //=======================================================================
5477 //function : ViewerCommands
5479 //=======================================================================
5481 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
5484 const char *group = "ZeViewer";
5485 theCommands.Add("vinit",
5486 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5487 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5489 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5491 " - Creates new View window with specified name view_name.\n"
5492 "By default the new view is created in the viewer and in"
5493 " graphic driver shared with active view.\n"
5494 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
5495 "If driverName isn't specified the driver will be shared with active view.\n"
5496 "If viewerName isn't specified the viewer will be shared with active view.\n"
5497 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5498 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
5499 "is used in creation of graphic driver\n"
5501 " - l, t: pixel position of left top corner of the window\n"
5502 " - w,h: width and heigth of window respectively.\n"
5503 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
5504 __FILE__,VInit,group);
5505 theCommands.Add("vclose" ,
5506 "[view_id [keep_context=0|1]]\n"
5507 "or vclose ALL - to remove all created views\n"
5508 " - removes view(viewer window) defined by its view_id.\n"
5509 " - keep_context: by default 0; if 1 and the last view is deleted"
5510 " the current context is not removed.",
5511 __FILE__,VClose,group);
5512 theCommands.Add("vactivate" ,
5514 " - activates view(viewer window) defined by its view_id",
5515 __FILE__,VActivate,group);
5516 theCommands.Add("vviewlist",
5517 "vviewlist [format={tree, long}]"
5518 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
5519 " - format: format of result output, if tree the output is a tree view;"
5520 "otherwise it's a list of full view names. By default format = tree",
5521 __FILE__,VViewList,group);
5522 theCommands.Add("vhelp" ,
5523 "vhelp : display help on the viewer commands",
5524 __FILE__,VHelp,group);
5525 theCommands.Add("vtop" ,
5526 "vtop or <T> : Top view" ,
5527 __FILE__,VTop,group);
5528 theCommands.Add("vbottom" ,
5529 "vbottom : Bottom view" ,
5530 __FILE__,VBottom,group);
5531 theCommands.Add("vleft" ,
5532 "vleft : Left view" ,
5533 __FILE__,VLeft,group);
5534 theCommands.Add("vright" ,
5535 "vright : Right view" ,
5536 __FILE__,VRight,group);
5537 theCommands.Add("vaxo" ,
5538 " vaxo or <A> : Axonometric view ",
5539 __FILE__,VAxo,group);
5540 theCommands.Add("vfront" ,
5541 "vfront : Front view" ,
5542 __FILE__,VFront,group);
5543 theCommands.Add("vback" ,
5544 "vback : Back view" ,
5545 __FILE__,VBack,group);
5546 theCommands.Add("vpick" ,
5547 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
5549 theCommands.Add("vfit" ,
5550 "vfit or <F> : vfit",
5551 __FILE__,VFit,group);
5552 theCommands.Add("vzfit" ,
5554 __FILE__,VZFit,group);
5555 theCommands.Add("vrepaint",
5556 "vrepaint : vrepaint, force redraw",
5557 __FILE__,VRepaint,group);
5558 theCommands.Add("vclear",
5560 __FILE__,VClear,group);
5561 theCommands.Add("vsetbg",
5562 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
5563 __FILE__,VSetBg,group);
5564 theCommands.Add("vsetbgmode",
5565 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
5566 __FILE__,VSetBgMode,group);
5567 theCommands.Add("vsetgradientbg",
5568 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
5569 __FILE__,VSetGradientBg,group);
5570 theCommands.Add("vsetgrbgmode",
5571 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
5572 __FILE__,VSetGradientBgMode,group);
5573 theCommands.Add("vsetcolorbg",
5574 "vsetcolorbg : vsetcolorbg r g b : Set background color",
5575 __FILE__,VSetColorBg,group);
5576 theCommands.Add("vscale",
5577 "vscale : vscale X Y Z",
5578 __FILE__,VScale,group);
5579 theCommands.Add("vzbufftrihedron",
5580 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
5581 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
5582 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
5583 __FILE__,VTestZBuffTrihedron,group);
5584 theCommands.Add("vrotate",
5585 "vrotate : vrotate AX AY AZ [X Y Z]",
5586 __FILE__,VRotate,group);
5587 theCommands.Add("vzoom",
5588 "vzoom : vzoom coef",
5589 __FILE__,VZoom,group);
5590 theCommands.Add("vpan",
5591 "vpan : vpan dx dy",
5592 __FILE__,VPan,group);
5593 theCommands.Add("vexport",
5594 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
5595 " : exports the view to a vector file of a given format"
5596 " : notice that EMF format requires patched gl2ps",
5597 __FILE__,VExport,group);
5598 theCommands.Add("vcolorscale",
5599 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
5600 __FILE__,VColorScale,group);
5601 theCommands.Add("vgraduatedtrihedron",
5602 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
5603 __FILE__,VGraduatedTrihedron,group);
5604 theCommands.Add("vprintview" ,
5605 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
5606 __FILE__,VPrintView,group);
5607 theCommands.Add("vzlayer",
5608 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
5609 __FILE__,VZLayer,group);
5610 theCommands.Add("voverlaytext",
5611 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
5612 " : height - pixel height of the text (default=10.0)"
5613 " : font_name - name of font (default=courier)"
5614 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
5615 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
5616 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
5617 __FILE__,VOverlayText,group);
5618 theCommands.Add("vlayerline",
5619 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
5620 __FILE__,VLayerLine,group);
5621 theCommands.Add ("vgrid",
5622 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
5623 " : Mode - rectangular or circular"
5624 " : Type - lines or points",
5625 __FILE__, VGrid, group);
5626 theCommands.Add ("vfps",
5627 "vfps [framesNb=100] : estimate average frame rate for active view",
5628 __FILE__, VFps, group);
5629 theCommands.Add ("vgldebug",
5630 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
5631 " : this function is implemented only for Windows\n"
5632 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
5633 __FILE__, VGlDebug, group);
5634 theCommands.Add ("vvbo",
5635 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
5636 __FILE__, VVbo, group);
5637 theCommands.Add ("vcaps",
5638 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
5639 __FILE__, VCaps, group);
5640 theCommands.Add ("vmemgpu",
5641 "vmemgpu [f]: print system-dependent GPU memory information if available;"
5642 " with f option returns free memory in bytes",
5643 __FILE__, VMemGpu, group);
5644 theCommands.Add ("vreadpixel",
5645 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
5646 " : Read pixel value for active view",
5647 __FILE__, VReadPixel, group);
5648 theCommands.Add("diffimage",
5649 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
5650 __FILE__, VDiffImage, group);
5651 theCommands.Add ("vselect",
5652 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
5653 "- emulates different types of selection:\n"
5654 "- 1) single click selection\n"
5655 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
5656 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
5657 "- 4) any of these selections with shift button pressed",
5658 __FILE__, VSelect, group);
5659 theCommands.Add ("vmoveto",
5661 "- emulates cursor movement to pixel postion (x,y)",
5662 __FILE__, VMoveTo, group);
5663 theCommands.Add("vviewparams",
5664 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
5665 "- gets or sets current view characteristics",
5666 __FILE__,VViewParams, group);
5667 theCommands.Add("vchangeselected",
5668 "vchangeselected shape"
5669 "- adds to shape to selection or remove one from it",
5670 __FILE__, VChangeSelected, group);
5671 theCommands.Add("vzclipping",
5672 "vzclipping [mode] [depth width]\n"
5673 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
5674 "- gets or sets ZClipping mode, width and depth",
5675 __FILE__,VZClipping,group);
5676 theCommands.Add ("vnbselected",
5677 "vnbselected", __FILE__, VNbSelected, group);
5678 theCommands.Add("vantialiasing",
5679 "vantialiasing 1|0",
5680 __FILE__,VAntialiasing,group);
5681 theCommands.Add ("vpurgedisplay",
5683 "- removes structures which don't belong to objects displayed in neutral point",
5684 __FILE__, VPurgeDisplay, group);
5685 theCommands.Add("vsetviewsize",
5686 "vsetviewsize size",
5687 __FILE__,VSetViewSize,group);
5688 theCommands.Add("vmoveview",
5689 "vmoveview Dx Dy Dz [Start = 1|0]",
5690 __FILE__,VMoveView,group);
5691 theCommands.Add("vtranslateview",
5692 "vtranslateview Dx Dy Dz [Start = 1|0)]",
5693 __FILE__,VTranslateView,group);
5694 theCommands.Add("vturnview",
5695 "vturnview Ax Ay Az [Start = 1|0]",
5696 __FILE__,VTurnView,group);
5697 theCommands.Add("vtextureenv",
5698 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
5699 "or user-defined file and optionally applying texture mapping parameters\n"
5701 " vtextureenv off - disables environment mapping\n"
5702 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
5703 " std_texture = (0..7)\n"
5704 " rep = {clamp|repeat}\n"
5705 " mod = {decal|modulate}\n"
5706 " flt = {nearest|bilinear|trilinear}\n"
5707 " ss, st - scale factors for s and t texture coordinates\n"
5708 " ts, tt - translation for s and t texture coordinates\n"
5709 " rot - texture rotation angle in degrees",
5710 __FILE__, VTextureEnv, group);
5711 theCommands.Add("vhlr" ,
5712 "is_enabled={on|off}"
5713 " - Hidden line removal algorithm:"
5714 " - is_enabled: if is on HLR algorithm is applied\n",
5715 __FILE__,VHLR,group);
5716 theCommands.Add("vhlrtype" ,
5717 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
5718 " - Changes the type of HLR algorithm using for shapes."
5719 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
5720 " if equals to polyalgo, polygonal HLR algorithm is applied."
5721 "If shapes are not given HLR algoithm of given type is applied"
5722 " to all shapes in the view\n",
5723 __FILE__,VHLRType,group);
5724 theCommands.Add("vclipplane", "vclipplane usage: \n"
5725 " maxplanes <view_name> - get plane limit for view.\n"
5726 " create <plane_name> - create new plane.\n"
5727 " delete <plane_name> - delete plane.\n"
5728 " clone <source_plane> <plane_name> - clone the plane definition.\n"
5729 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
5730 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
5731 " change <plane_name> on/off - turn clipping on/off.\n"
5732 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
5733 " change <plane_name> capping on/off - turn capping on/off.\n"
5734 " change <plane_name> capping color <r> <g> <b> - set color.\n"
5735 " change <plane name> capping texname <texture> - set texture.\n"
5736 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
5737 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
5738 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
5739 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
5740 " please use VSetTextureMode command to enable texture rendering in view.\n"
5741 , __FILE__, VClipPlane, group);
5742 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
5744 " 0 - no textures enabled in view.\n"
5745 " 1 - only environment textures enabled.\n"
5746 " 2 - all textures enabled.\n"
5747 " this command sets texture details mode for the specified view.\n"
5748 , __FILE__, VSetTextureMode, group);
5749 theCommands.Add("vdefaults",
5750 "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
5751 __FILE__, VDefaults, group);
5752 theCommands.Add("vraytrace",
5754 __FILE__,VRaytrace,group);
5755 theCommands.Add("vclinfo",
5757 __FILE__,VClInfo,group);
5758 theCommands.Add("vsetraytracemode",
5759 "vsetraytracemode [shad=0|1] [refl=0|1] [aa=0|1]",
5760 __FILE__,VSetRaytraceMode,group);