1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
25 #include <OpenGl_GlCore20.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_Drawer.hxx>
28 #include <AIS_InteractiveObject.hxx>
29 #include <AIS_ListOfInteractive.hxx>
30 #include <AIS_ListIteratorOfListOfInteractive.hxx>
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_ExportFormat.hxx>
34 #include <Graphic3d_NameOfTextureEnv.hxx>
35 #include <Graphic3d_TextureEnv.hxx>
36 #include <Graphic3d_TextureParams.hxx>
37 #include <Graphic3d_TypeOfTextureFilter.hxx>
38 #include <Graphic3d_AspectFillArea3d.hxx>
39 #include <ViewerTest.hxx>
40 #include <ViewerTest_EventManager.hxx>
41 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
42 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
43 #include <Visual3d_View.hxx>
44 #include <Visual3d_ViewManager.hxx>
45 #include <V3d_AmbientLight.hxx>
46 #include <V3d_DirectionalLight.hxx>
47 #include <V3d_LayerMgr.hxx>
48 #include <V3d_LayerMgrPointer.hxx>
49 #include <V3d_PositionalLight.hxx>
50 #include <V3d_SpotLight.hxx>
51 #include <NCollection_DoubleMap.hxx>
52 #include <NCollection_List.hxx>
53 #include <NCollection_Vector.hxx>
54 #include <NIS_View.hxx>
55 #include <NIS_Triangulated.hxx>
56 #include <NIS_InteractiveContext.hxx>
57 #include <AIS_InteractiveContext.hxx>
58 #include <Draw_Interpretor.hxx>
60 #include <Draw_Appli.hxx>
61 #include <Aspect_PrintAlgo.hxx>
62 #include <Image_AlienPixMap.hxx>
63 #include <OpenGl_GraphicDriver.hxx>
64 #include <OSD_Timer.hxx>
65 #include <TColStd_SequenceOfInteger.hxx>
66 #include <TColStd_HSequenceOfReal.hxx>
67 #include <TColgp_Array1OfPnt2d.hxx>
68 #include <Visual3d_LayerItem.hxx>
69 #include <Aspect_TypeOfLine.hxx>
70 #include <Image_Diff.hxx>
71 #include <Aspect_DisplayConnection.hxx>
72 #include <Graphic3d.hxx>
76 #include <PrsMgr_PresentableObject.hxx>
77 #include <Graphic3d_ClipPlane.hxx>
78 #include <NCollection_DataMap.hxx>
79 #include <Graphic3d_Texture2Dmanual.hxx>
80 #include <Prs3d_ShadingAspect.hxx>
86 #include <Visual3d_Layer.hxx>
90 #include <WNT_WClass.hxx>
91 #include <WNT_Window.hxx>
94 #define _CRT_SECURE_NO_DEPRECATE
95 #pragma warning (disable:4996)
97 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
98 #include <Cocoa_Window.hxx>
100 #include <Xw_Window.hxx>
101 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
102 #include <X11/Xutil.h>
106 // Auxiliary definitions
107 static const char THE_KEY_DELETE = 127;
109 //==============================================================================
110 // VIEWER GLOBAL VARIABLES
111 //==============================================================================
113 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
114 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
116 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
117 extern const Handle(NIS_InteractiveContext)& TheNISContext();
118 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
120 extern int VErase (Draw_Interpretor& theDI,
121 Standard_Integer theArgNb,
122 const char** theArgVec);
125 static Handle(WNT_Window)& VT_GetWindow() {
126 static Handle(WNT_Window) WNTWin;
129 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
130 static Handle(Cocoa_Window)& VT_GetWindow()
132 static Handle(Cocoa_Window) aWindow;
135 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
136 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
137 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
140 static Handle(Xw_Window)& VT_GetWindow(){
141 static Handle(Xw_Window) XWWin;
145 static void VProcessEvents(ClientData,int);
148 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
150 static Handle(Aspect_DisplayConnection) aDisplayConnection;
151 return aDisplayConnection;
154 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
156 GetDisplayConnection() = theDisplayConnection;
159 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
160 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
162 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
164 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
165 if (!aWindow.IsNull())
166 return aWindow->HWindow();
167 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
168 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
169 if (!aWindow.IsNull())
170 return aWindow->XWindow();
172 return aWindowHandle;
176 static Standard_Boolean MyHLRIsOn = Standard_False;
178 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
179 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
180 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
181 static OpenGl_Caps ViewerTest_myDefaultCaps;
183 #define ZCLIPWIDTH 1.
185 static void OSWindowSetup();
187 //==============================================================================
188 // EVENT GLOBAL VARIABLES
189 //==============================================================================
191 static int Start_Rot = 0;
192 static int ZClipIsOn = 0;
193 int X_Motion = 0; // Current cursor position
195 int X_ButtonPress = 0; // Last ButtonPress position
196 int Y_ButtonPress = 0;
197 Standard_Boolean IsDragged = Standard_False;
198 Standard_Boolean DragFirst;
200 //==============================================================================
203 static LRESULT WINAPI ViewerWindowProc(
208 static LRESULT WINAPI AdvViewerWindowProc(
216 //==============================================================================
219 //==============================================================================
221 const Handle(MMgt_TShared)& ViewerTest::WClass()
223 static Handle(MMgt_TShared) theWClass;
225 if (theWClass.IsNull())
227 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
228 CS_VREDRAW | CS_HREDRAW, 0, 0,
229 ::LoadCursor (NULL, IDC_ARROW));
235 //==============================================================================
236 //function : CreateName
237 //purpose : Create numerical name for new object in theMap
238 //==============================================================================
239 template <typename ObjectType>
240 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
241 const TCollection_AsciiString& theDefaultString)
243 if (theObjectMap.IsEmpty())
244 return theDefaultString + TCollection_AsciiString(1);
246 Standard_Integer aNextKey = 1;
247 Standard_Boolean isFound = Standard_False;
250 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
251 // Look for objects with default names
252 if (theObjectMap.IsBound1(aStringKey))
257 isFound = Standard_True;
260 return theDefaultString + TCollection_AsciiString(aNextKey);
263 //==============================================================================
264 //structure : ViewerTest_Names
265 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
266 //==============================================================================
267 struct ViewerTest_Names
270 TCollection_AsciiString myDriverName;
271 TCollection_AsciiString myViewerName;
272 TCollection_AsciiString myViewName;
276 const TCollection_AsciiString& GetDriverName () const
280 void SetDriverName (const TCollection_AsciiString& theDriverName)
282 myDriverName = theDriverName;
284 const TCollection_AsciiString& GetViewerName () const
288 void SetViewerName (const TCollection_AsciiString& theViewerName)
290 myViewerName = theViewerName;
292 const TCollection_AsciiString& GetViewName () const
296 void SetViewName (const TCollection_AsciiString& theViewName)
298 myViewName = theViewName;
301 //===========================================================================
302 //function : Constructor for ViewerTest_Names
303 //purpose : Get view, viewer, driver names from custom string
304 //===========================================================================
306 ViewerTest_Names (const TCollection_AsciiString& theInputString)
308 TCollection_AsciiString aName(theInputString);
309 if (theInputString.IsEmpty())
311 // Get current configuration
312 if (ViewerTest_myDrivers.IsEmpty())
313 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
314 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
316 myDriverName = ViewerTest_myDrivers.Find2
317 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
319 if(ViewerTest_myContexts.IsEmpty())
321 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
322 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
325 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
327 myViewName = CreateName <Handle(V3d_View)>
328 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
332 // There is at least view name
333 Standard_Integer aParserNumber = 0;
334 for (Standard_Integer i = 0; i < 3; ++i)
336 Standard_Integer aParserPos = aName.SearchFromEnd("/");
340 aName.Split(aParserPos-1);
345 if (aParserNumber == 0)
348 if (!ViewerTest::GetAISContext().IsNull())
350 myDriverName = ViewerTest_myDrivers.Find2
351 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
352 myViewerName = ViewerTest_myContexts.Find2
353 (ViewerTest::GetAISContext());
357 // There is no opened contexts here, need to create names for viewer and driver
358 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
359 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
361 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
362 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
364 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
366 else if (aParserNumber == 1)
368 // Here is viewerName/viewName
369 if (!ViewerTest::GetAISContext().IsNull())
370 myDriverName = ViewerTest_myDrivers.Find2
371 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
374 // There is no opened contexts here, need to create name for driver
375 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
376 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
378 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
380 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
384 //Here is driverName/viewerName/viewName
385 myDriverName = TCollection_AsciiString(aName);
387 TCollection_AsciiString aViewerName(theInputString);
388 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
389 myViewerName = TCollection_AsciiString(aViewerName);
391 myViewName = TCollection_AsciiString(theInputString);
397 //==============================================================================
398 //function : FindContextByView
399 //purpose : Find AIS_InteractiveContext by View
400 //==============================================================================
402 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
404 Handle(AIS_InteractiveContext) anAISContext;
406 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
407 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
409 if (anIter.Value()->CurrentViewer() == theView->Viewer())
410 return anIter.Key2();
416 //==============================================================================
417 //function : SetWindowTitle
418 //purpose : Set window title
419 //==============================================================================
421 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
422 Standard_CString theTitle)
425 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
427 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
428 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
430 if(GetDisplayConnection()->GetDisplay())
433 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
434 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
439 //==============================================================================
440 //function : IsWindowOverlapped
441 //purpose : Check if theWindow overlapp another view
442 //==============================================================================
444 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
445 const Standard_Integer thePxTop,
446 const Standard_Integer thePxRight,
447 const Standard_Integer thePxBottom,
448 TCollection_AsciiString& theViewId)
450 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
451 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
453 Standard_Integer aTop = 0,
457 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
458 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
459 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
460 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
461 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
463 theViewId = anIter.Key1();
464 return Standard_True;
467 return Standard_False;
470 // Workaround: to create and delete non-orthographic views outside ViewerTest
471 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
473 ViewerTest_myViews.UnBind1 (theName);
476 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
477 const Handle(V3d_View)& theView)
479 ViewerTest_myViews.Bind (theName, theView);
482 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
484 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
486 //==============================================================================
487 //function : ViewerInit
488 //purpose : Create the window viewer and initialize all the global variable
489 //==============================================================================
491 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
492 const Standard_Integer thePxTop,
493 const Standard_Integer thePxWidth,
494 const Standard_Integer thePxHeight,
495 Standard_CString theViewName,
496 Standard_CString theDisplayName)
498 // Default position and dimension of the viewer window.
499 // Note that left top corner is set to be sufficiently small to have
500 // window fit in the small screens (actual for remote desktops, see #23003).
501 // The position corresponds to the window's client area, thus some
502 // gap is added for window frame to be visible.
503 Standard_Integer aPxLeft = 20;
504 Standard_Integer aPxTop = 40;
505 Standard_Integer aPxWidth = 409;
506 Standard_Integer aPxHeight = 409;
507 Standard_Boolean toCreateViewer = Standard_False;
509 Handle(OpenGl_GraphicDriver) aGraphicDriver;
510 ViewerTest_Names aViewNames(theViewName);
511 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
512 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
519 aPxWidth = thePxWidth;
520 if (thePxHeight != 0)
521 aPxHeight = thePxHeight;
523 // Get graphic driver (create it or get from another view)
524 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
526 // Get connection string
527 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
528 TCollection_AsciiString aDisplayName(theDisplayName);
529 if (!aDisplayName.IsEmpty())
530 SetDisplayConnection (new Aspect_DisplayConnection ());
532 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
534 (void)theDisplayName; // avoid warning on unused argument
535 SetDisplayConnection (new Aspect_DisplayConnection ());
537 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
538 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
539 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
540 toCreateViewer = Standard_True;
544 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
547 //Dispose the window if input parameters are default
548 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
550 Standard_Integer aTop = 0,
557 // Get screen resolution
558 #if defined(_WIN32) || defined(__WIN32__)
560 GetClientRect(GetDesktopWindow(), &aWindowSize);
561 aScreenHeight = aWindowSize.bottom;
562 aScreenWidth = aWindowSize.right;
563 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
564 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
566 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
567 aScreenWidth = WidthOfScreen(aScreen);
568 aScreenHeight = HeightOfScreen(aScreen);
571 TCollection_AsciiString anOverlappedViewId("");
573 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
575 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
577 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
578 && aRight + 2*aPxWidth + 40 > aScreenWidth)
580 if (aBottom + aPxHeight + 40 > aScreenHeight)
587 aPxTop = aBottom + 40;
590 aPxLeft = aRight + 20;
595 TCollection_AsciiString aTitle("3D View - ");
596 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
598 // Change name of current active window
599 if (!ViewerTest::CurrentView().IsNull())
601 TCollection_AsciiString aTitle("3D View - ");
603 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
604 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
608 Handle(V3d_Viewer) a3DViewer;
609 // If it's the single view, we first look for empty context
610 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
612 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
613 anIter(ViewerTest_myContexts);
615 ViewerTest::SetAISContext (anIter.Value());
616 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
618 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
620 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
621 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
623 else if (a3DViewer.IsNull())
625 toCreateViewer = Standard_True;
626 TCollection_ExtendedString NameOfWindow("Viewer3D");
627 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
629 NameOfWindow = TCollection_ExtendedString("Collector");
631 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
635 if (ViewerTest::GetAISContext().IsNull() ||
636 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
638 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
639 ViewerTest::SetAISContext (aContext);
640 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
644 ViewerTest::ResetEventManager();
649 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
650 Handle(WNT_WClass)::DownCast (WClass()),
651 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
655 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
656 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
658 aPxWidth, aPxHeight);
659 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
661 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
664 aPxWidth, aPxHeight);
666 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
669 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
671 ViewerTest::CurrentView(aView);
672 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
673 TheNISContext()->AttachView (aView);
675 // Setup for X11 or NT
678 // Set parameters for V3d_View and V3d_Viewer
679 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
680 aV3dView->SetComputedMode(Standard_False);
681 MyHLRIsOn = aV3dView->ComputedMode();
682 aV3dView->SetZClippingDepth(0.5);
683 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
685 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
688 a3DViewer->SetDefaultLights();
689 a3DViewer->SetLightOn();
692 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
693 #if TCL_MAJOR_VERSION < 8
694 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
695 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
697 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
698 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
702 VT_GetWindow()->Map();
704 // Set the handle of created view in the event manager
705 ViewerTest::ResetEventManager();
707 ViewerTest::CurrentView()->Redraw();
712 return aViewNames.GetViewName();
715 //==============================================================================
716 //function : RedrawAllViews
717 //purpose : Redraw all created views
718 //==============================================================================
719 void ViewerTest::RedrawAllViews()
721 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
722 for (; aViewIt.More(); aViewIt.Next())
724 const Handle(V3d_View)& aView = aViewIt.Key2();
729 //==============================================================================
730 //function : splitParameter
731 //purpose : Split parameter string to parameter name an parameter value
732 //==============================================================================
733 Standard_Boolean splitParameter (const TCollection_AsciiString& theString,
734 TCollection_AsciiString& theName,
735 TCollection_AsciiString& theValue)
737 Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
738 if (aParamNameEnd == 0)
739 return Standard_False;
740 TCollection_AsciiString aString(theString);
741 if (aParamNameEnd != 0)
743 theValue = aString.Split(aParamNameEnd);
744 aString.Split(aString.Length()-1);
747 return Standard_True;
750 //==============================================================================
752 //purpose : Create the window viewer and initialize all the global variable
753 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
754 //==============================================================================
756 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
760 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
761 << "Type help for more information.\n";
765 TCollection_AsciiString aViewName, aDisplayName;
766 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
767 TCollection_AsciiString aName, aValue;
768 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
770 const TCollection_AsciiString anArg = theArgVec[anArgIt];
771 TCollection_AsciiString anArgCase = anArg;
772 anArgCase.UpperCase();
773 if (splitParameter (anArg, aName, aValue))
776 if (aName.IsEqual ("NAME"))
780 else if (aName.IsEqual ("L")
781 || aName.IsEqual ("LEFT"))
783 aPxLeft = aValue.IntegerValue();
785 else if (aName.IsEqual ("T")
786 || aName.IsEqual ("TOP"))
788 aPxTop = aValue.IntegerValue();
790 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
791 else if (aName.IsEqual ("DISP")
792 || aName.IsEqual ("DISPLAY"))
794 aDisplayName = aValue;
797 else if (aName.IsEqual ("W")
798 || aName.IsEqual ("WIDTH"))
800 aPxWidth = aValue.IntegerValue();
802 else if (aName.IsEqual ("H")
803 || aName.IsEqual ("HEIGHT"))
805 aPxHeight = aValue.IntegerValue();
809 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
812 else if (aViewName.IsEmpty())
818 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
822 ViewerTest_Names aViewNames (aViewName);
823 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
825 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
826 theDi.Eval (aCommand.ToCString());
830 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
831 aViewName.ToCString(),
832 aDisplayName.ToCString());
837 //==============================================================================
839 //purpose : hidden lines removal algorithm
840 //==============================================================================
842 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
844 if (ViewerTest::CurrentView().IsNull())
846 di << argv[0] << ": Call vinit before this command, please.\n";
852 di << argv[0] << ": Wrong number of command arguments.\n"
853 << "Type help " << argv[0] << " for more information.\n";
857 Standard_Boolean isHLROn =
858 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
860 if (isHLROn == MyHLRIsOn)
866 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
871 //==============================================================================
872 //function : VHLRType
873 //purpose : change type of using HLR algorithm
874 //==============================================================================
876 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
878 if (ViewerTest::CurrentView().IsNull())
880 di << argv[0] << ": Call vinit before this command, please.\n";
886 di << argv[0] << ": Wrong number of command arguments.\n"
887 << "Type help " << argv[0] << " for more information.\n";
891 Prs3d_TypeOfHLR aTypeOfHLR =
892 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
896 AIS_ListOfInteractive aListOfShapes;
897 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
898 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
899 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
900 anIter.More(); anIter.Next())
902 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
905 if (aShape->TypeOfHLR() != aTypeOfHLR)
906 aShape->SetTypeOfHLR (aTypeOfHLR);
910 ViewerTest::CurrentView()->Update();
915 for (Standard_Integer i = 2; i < argc; ++i)
917 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
918 TCollection_AsciiString aName (argv[i]);
920 if (!aMap.IsBound2 (aName))
922 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
925 Handle(AIS_Shape) anAISObject =
926 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
927 if (anAISObject.IsNull())
929 anAISObject->SetTypeOfHLR (aTypeOfHLR);
931 anAISObject->Redisplay();
933 ViewerTest::CurrentView()->Update();
939 //==============================================================================
940 //function : FindViewIdByWindowHandle
941 //purpose : Find theView Id in the map of views by window handle
942 //==============================================================================
943 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
944 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
946 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
947 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
949 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
950 if (aWindowHandle == theWindowHandle)
951 return anIter.Key1();
953 return TCollection_AsciiString("");
957 //==============================================================================
958 //function : ActivateView
959 //purpose : Make the view active
960 //==============================================================================
962 void ActivateView (const TCollection_AsciiString& theViewName)
964 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
967 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
968 if (!anAISContext.IsNull())
970 if (!ViewerTest::CurrentView().IsNull())
972 TCollection_AsciiString aTitle("3D View - ");
973 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
974 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
977 ViewerTest::CurrentView (aView);
978 // Update degenerate mode
979 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
980 ViewerTest::SetAISContext (anAISContext);
981 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
982 aTitle = aTitle + theViewName + "(*)";
983 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
984 #if defined(_WIN32) || defined(__WIN32__)
985 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
986 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
987 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
989 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
991 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
992 ViewerTest::CurrentView()->Redraw();
997 //==============================================================================
998 //function : RemoveView
999 //purpose : Close and remove view from display, clear maps if neccessary
1000 //==============================================================================
1001 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1003 if (!ViewerTest_myViews.IsBound1(theViewName))
1005 cout << "Wrong view name\n";
1009 // Activate another view if it's active now
1010 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1012 if (ViewerTest_myViews.Extent() > 1)
1014 TCollection_AsciiString aNewViewName;
1015 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1016 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1017 if (anIter.Key1() != theViewName)
1019 aNewViewName = anIter.Key1();
1022 ActivateView (aNewViewName);
1026 Handle(V3d_View) anEmptyView;
1027 #if defined(_WIN32) || defined(__WIN32__)
1028 Handle(WNT_Window) anEmptyWindow;
1029 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1030 Handle(Cocoa_Window) anEmptyWindow;
1032 Handle(Xw_Window) anEmptyWindow;
1034 VT_GetWindow() = anEmptyWindow;
1035 ViewerTest::CurrentView (anEmptyView);
1036 if (isContextRemoved)
1038 Handle(AIS_InteractiveContext) anEmptyContext;
1039 ViewerTest::SetAISContext(anEmptyContext);
1045 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1046 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1048 // Remove view resources
1049 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1050 ViewerTest_myViews.UnBind1(theViewName);
1053 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1054 XFlush (GetDisplayConnection()->GetDisplay());
1057 // Keep context opened only if the closed view is last to avoid
1058 // unused empty contexts
1059 if (!aCurrentContext.IsNull())
1061 // Check if there are more difined views in the viewer
1062 aCurrentContext->CurrentViewer()->InitDefinedViews();
1063 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1065 // Remove driver if there is no viewers that use it
1066 Standard_Boolean isRemoveDriver = Standard_True;
1067 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1068 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1070 if (aCurrentContext != anIter.Key2() &&
1071 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1073 isRemoveDriver = Standard_False;
1079 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1080 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1081 #if TCL_MAJOR_VERSION < 8
1082 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1084 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1089 ViewerTest_myContexts.UnBind2(aCurrentContext);
1092 cout << "3D View - " << theViewName << " was deleted.\n";
1096 //==============================================================================
1098 //purpose : Remove the view defined by its name
1099 //==============================================================================
1101 static int VClose (Draw_Interpretor& /*theDi*/,
1102 Standard_Integer theArgsNb,
1103 const char** theArgVec)
1105 NCollection_List<TCollection_AsciiString> aViewList;
1108 TCollection_AsciiString anArg (theArgVec[1]);
1110 if (anArg.IsEqual ("ALL")
1111 || anArg.IsEqual ("*"))
1113 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1114 anIter.More(); anIter.Next())
1116 aViewList.Append (anIter.Key1());
1118 if (aViewList.IsEmpty())
1120 std::cout << "No view to close\n";
1126 ViewerTest_Names aViewName (theArgVec[1]);
1127 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1129 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1132 aViewList.Append (aViewName.GetViewName());
1137 // close active view
1138 if (ViewerTest::CurrentView().IsNull())
1140 std::cerr << "No active view!\n";
1143 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1146 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1147 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1148 anIter.More(); anIter.Next())
1150 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1156 //==============================================================================
1157 //function : VActivate
1158 //purpose : Activate the view defined by its ID
1159 //==============================================================================
1161 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1165 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1166 << "Usage: " << theArgVec[0] << " ViewID\n";
1171 theDi.Eval("vviewlist");
1175 TCollection_AsciiString aNameString(theArgVec[1]);
1176 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1178 TCollection_AsciiString aTitle("3D View - ");
1179 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1180 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1181 Handle(V3d_View) anEmptyView;
1182 #if defined(_WIN32) || defined(__WIN32__)
1183 Handle(WNT_Window) anEmptyWindow;
1184 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1185 Handle(Cocoa_Window) anEmptyWindow;
1187 Handle(Xw_Window) anEmptyWindow;
1189 VT_GetWindow() = anEmptyWindow;
1190 ViewerTest::CurrentView (anEmptyView);
1191 ViewerTest::ResetEventManager();
1192 theDi << theArgVec[0] << ": all views are inactive\n";
1196 ViewerTest_Names aViewNames(aNameString);
1198 // Check if this view exists in the viewer with the driver
1199 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1201 theDi << "Wrong view name\n";
1205 // Check if it is active already
1206 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1208 theDi << theArgVec[0] << ": the view is active already\n";
1212 ActivateView (aViewNames.GetViewName());
1216 //==============================================================================
1217 //function : VViewList
1218 //purpose : Print current list of views per viewer and graphic driver ID
1219 // shared between viewers
1220 //==============================================================================
1222 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1226 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1227 << "Usage: " << theArgVec[0] << " name";
1230 if (ViewerTest_myContexts.Size() < 1)
1233 Standard_Boolean isTreeView =
1234 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1237 theDi << theArgVec[0] <<":\n";
1239 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1240 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1243 theDi << aDriverIter.Key1() << ":\n";
1245 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1246 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1248 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1252 TCollection_AsciiString aContextName(aContextIter.Key1());
1253 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1256 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1257 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1259 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1261 TCollection_AsciiString aViewName(aViewIter.Key1());
1264 if (aViewIter.Value() == ViewerTest::CurrentView())
1265 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1267 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1271 theDi << aViewName << " ";
1281 //==============================================================================
1282 //function : VT_ProcessKeyPress
1283 //purpose : Handle KeyPress event from a CString
1284 //==============================================================================
1285 void VT_ProcessKeyPress (const char* buf_ret)
1287 //cout << "KeyPress" << endl;
1288 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1289 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1290 // Letter in alphabetic order
1292 if (!strcasecmp (buf_ret, "A"))
1295 aView->SetProj(V3d_XposYnegZpos);
1297 else if (!strcasecmp (buf_ret, "D"))
1302 else if (!strcasecmp (buf_ret, "F"))
1305 if (aNisView.IsNull())
1308 aNisView->FitAll3d();
1310 else if (!strcasecmp (buf_ret, "H"))
1313 cout << "HLR" << endl;
1314 aView->SetComputedMode (!aView->ComputedMode());
1315 MyHLRIsOn = aView->ComputedMode();
1317 else if (!strcasecmp (buf_ret, "P"))
1320 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1321 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1322 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1324 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1325 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1327 AIS_ListOfInteractive aListOfShapes;
1328 aContext->DisplayedObjects(aListOfShapes);
1329 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1330 anIter.More(); anIter.Next())
1332 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1333 if (aShape.IsNull())
1335 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1336 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1338 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1339 aShape->Redisplay();
1344 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1346 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1347 if (aShape.IsNull())
1349 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1350 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1352 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1353 aShape->Redisplay();
1357 aContext->UpdateCurrentViewer();
1360 else if (!strcasecmp (buf_ret, "S"))
1362 std::cout << "setup Shaded display mode" << std::endl;
1364 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1365 if(Ctx->NbCurrents()==0 ||
1366 Ctx->NbSelected()==0)
1367 Ctx->SetDisplayMode(AIS_Shaded);
1369 if(Ctx->HasOpenedContext()){
1370 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1371 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1374 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1375 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1377 Ctx->UpdateCurrentViewer();
1380 else if (!strcasecmp (buf_ret, "U"))
1382 // Unset display mode
1383 std::cout << "reset display mode to defaults" << std::endl;
1385 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1386 if(Ctx->NbCurrents()==0 ||
1387 Ctx->NbSelected()==0)
1388 Ctx->SetDisplayMode(AIS_WireFrame);
1390 if(Ctx->HasOpenedContext()){
1391 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1392 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1395 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1396 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1398 Ctx->UpdateCurrentViewer();
1402 else if (!strcasecmp (buf_ret, "T"))
1405 aView->SetProj(V3d_Zpos);
1407 else if (!strcasecmp (buf_ret, "B"))
1410 aView->SetProj(V3d_Zneg);
1412 else if (!strcasecmp (buf_ret, "L"))
1415 aView->SetProj(V3d_Xneg);
1417 else if (!strcasecmp (buf_ret, "R"))
1420 aView->SetProj(V3d_Xpos);
1422 else if (!strcasecmp (buf_ret, "W"))
1424 std::cout << "setup WireFrame display mode" << std::endl;
1425 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1426 if(Ctx->NbCurrents()==0 ||
1427 Ctx->NbSelected()==0)
1428 Ctx->SetDisplayMode(AIS_WireFrame);
1430 if(Ctx->HasOpenedContext()){
1431 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1432 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1435 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1436 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1438 Ctx->UpdateCurrentViewer();
1441 else if (!strcasecmp (buf_ret, "Z"))
1445 cout << "ZClipping OFF" << endl;
1448 aView->SetZClippingType(V3d_OFF);
1452 cout << "ZClipping ON" << endl;
1455 aView->SetZClippingType(V3d_FRONT);
1459 else if (!strcasecmp (buf_ret, ","))
1461 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1463 else if (!strcasecmp (buf_ret, "."))
1465 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1467 else if (*buf_ret == THE_KEY_DELETE)
1469 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1471 && aCtx->NbCurrents() > 0
1472 && aCtx->NbSelected() > 0)
1474 Draw_Interprete ("verase");
1480 Standard_Integer Num = Draw::Atoi(buf_ret);
1481 if(Num>=0 && Num<=7)
1482 ViewerTest::StandardModeActivation(Num);
1486 //==============================================================================
1487 //function : VT_ProcessExpose
1488 //purpose : Redraw the View on an Expose Event
1489 //==============================================================================
1490 void VT_ProcessExpose()
1492 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1493 if (!aView3d.IsNull())
1499 //==============================================================================
1500 //function : VT_ProcessConfigure
1501 //purpose : Resize the View on an Configure Event
1502 //==============================================================================
1503 void VT_ProcessConfigure()
1505 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1506 if (aView3d.IsNull())
1511 aView3d->MustBeResized();
1516 //==============================================================================
1517 //function : VT_ProcessButton1Press
1519 //==============================================================================
1520 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1521 const char** theArgVec,
1522 Standard_Boolean theToPick,
1523 Standard_Boolean theIsShift)
1527 Standard_Real X, Y, Z;
1528 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1530 Draw::Set (theArgVec[1], X);
1531 Draw::Set (theArgVec[2], Y);
1532 Draw::Set (theArgVec[3], Z);
1537 ViewerTest::CurrentEventManager()->ShiftSelect();
1541 ViewerTest::CurrentEventManager()->Select();
1544 return Standard_False;
1547 //==============================================================================
1548 //function : VT_ProcessButton1Release
1549 //purpose : End selecting
1550 //==============================================================================
1551 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1555 IsDragged = Standard_False;
1556 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1559 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1560 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1564 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1565 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1570 //==============================================================================
1571 //function : VT_ProcessButton3Press
1572 //purpose : Start Rotation
1573 //==============================================================================
1574 void VT_ProcessButton3Press()
1579 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1581 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1584 //==============================================================================
1585 //function : VT_ProcessButton3Release
1586 //purpose : End rotation
1587 //==============================================================================
1588 void VT_ProcessButton3Release()
1595 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1600 //==============================================================================
1601 //function : ProcessZClipMotion
1603 //==============================================================================
1605 void ProcessZClipMotion()
1607 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1608 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1609 static Standard_Real CurZPos = 0.;
1611 //Quantity_Length VDX, VDY;
1612 //a3DView->Size(VDX,VDY);
1613 //Standard_Real VDZ = a3DView->ZSize();
1614 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1616 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1618 // Front = Depth + width/2.
1619 Standard_Real D = 0.5;
1620 Standard_Real W = 0.1;
1626 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1628 a3DView->SetZClippingType(V3d_OFF);
1629 a3DView->SetZClippingDepth(D);
1630 a3DView->SetZClippingWidth(W);
1631 a3DView->SetZClippingType(V3d_FRONT);
1635 X_ButtonPress = X_Motion;
1636 Y_ButtonPress = Y_Motion;
1640 //==============================================================================
1641 //function : ProcessControlButton1Motion
1643 //==============================================================================
1645 static void ProcessControlButton1Motion()
1647 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1649 X_ButtonPress = X_Motion;
1650 Y_ButtonPress = Y_Motion;
1653 //==============================================================================
1654 //function : VT_ProcessControlButton2Motion
1656 //==============================================================================
1657 void VT_ProcessControlButton2Motion()
1659 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1660 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1662 dy = -dy; // Xwindow Y axis is from top to Bottom
1664 ViewerTest::CurrentView()->Panning( dx, dy );
1666 X_ButtonPress = X_Motion;
1667 Y_ButtonPress = Y_Motion;
1670 //==============================================================================
1671 //function : VT_ProcessControlButton3Motion
1672 //purpose : Rotation
1673 //==============================================================================
1674 void VT_ProcessControlButton3Motion()
1678 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1682 //==============================================================================
1683 //function : VT_ProcessMotion
1685 //==============================================================================
1686 void VT_ProcessMotion()
1688 //pre-hilights detected objects at mouse position
1690 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1691 EM->MoveTo(X_Motion, Y_Motion);
1695 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1697 Xpix = X_Motion;Ypix=Y_Motion;
1700 //==============================================================================
1701 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1702 //purpose : Switches to an axonometric, top, left and other views
1703 //==============================================================================
1705 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1707 if ( ViewerTest::CurrentView().IsNull() )
1709 di<<"Call vinit before this command, please"<<"\n";
1713 ViewerTest::CurrentView()->SetProj(ori);
1717 //==============================================================================
1719 //purpose : Switch to an Axonometric view
1720 //Draw arg : No args
1721 //==============================================================================
1723 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1725 return ViewProject(di, V3d_XposYnegZpos);
1728 //==============================================================================
1730 //purpose : Switch to a Top View
1731 //Draw arg : No args
1732 //==============================================================================
1734 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1736 return ViewProject(di, V3d_Zpos);
1739 //==============================================================================
1740 //function : VBottom
1741 //purpose : Switch to a Bottom View
1742 //Draw arg : No args
1743 //==============================================================================
1745 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1747 return ViewProject(di, V3d_Zneg);
1750 //==============================================================================
1752 //purpose : Switch to a Left View
1753 //Draw arg : No args
1754 //==============================================================================
1756 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1758 return ViewProject(di, V3d_Ypos);
1761 //==============================================================================
1763 //purpose : Switch to a Right View
1764 //Draw arg : No args
1765 //==============================================================================
1767 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1769 return ViewProject(di, V3d_Yneg);
1772 //==============================================================================
1774 //purpose : Switch to a Front View
1775 //Draw arg : No args
1776 //==============================================================================
1778 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1780 return ViewProject(di, V3d_Xpos);
1783 //==============================================================================
1785 //purpose : Switch to a Back View
1786 //Draw arg : No args
1787 //==============================================================================
1789 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1791 return ViewProject(di, V3d_Xneg);
1794 //==============================================================================
1796 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1797 //Draw arg : No args
1798 //==============================================================================
1800 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1803 di << "Q : Quit the application" << "\n";
1805 di << "========================="<<"\n";
1806 di << "F : FitAll" << "\n";
1807 di << "T : TopView" << "\n";
1808 di << "B : BottomView" << "\n";
1809 di << "R : RightView" << "\n";
1810 di << "L : LeftView" << "\n";
1811 di << "A : AxonometricView" << "\n";
1812 di << "D : ResetView" << "\n";
1814 di << "========================="<<"\n";
1815 di << "S : Shading" << "\n";
1816 di << "W : Wireframe" << "\n";
1817 di << "H : HidelLineRemoval" << "\n";
1818 di << "U : Unset display mode" << "\n";
1819 di << "Delete : Remove selection from viewer" << "\n";
1821 di << "========================="<<"\n";
1822 di << "Selection mode "<<"\n";
1823 di << "0 : Shape" <<"\n";
1824 di << "1 : Vertex" <<"\n";
1825 di << "2 : Edge" <<"\n";
1826 di << "3 : Wire" <<"\n";
1827 di << "4 : Face" <<"\n";
1828 di << "5 : Shell" <<"\n";
1829 di << "6 : Solid" <<"\n";
1830 di << "7 : Compound" <<"\n";
1832 di << "========================="<<"\n";
1833 di << "Z : Switch Z clipping On/Off" << "\n";
1834 di << ", : Hilight next detected" << "\n";
1835 di << ". : Hilight previous detected" << "\n";
1842 static Standard_Boolean Ppick = 0;
1843 static Standard_Integer Pargc = 0;
1844 static const char** Pargv = NULL;
1847 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1852 if (!ViewerTest_myViews.IsEmpty()) {
1854 WPARAM fwKeys = wParam;
1859 // Delete view from map of views
1860 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1865 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1866 || ViewerTest::CurrentView().IsNull())
1868 // Activate inactive window
1869 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1871 ActivateView (FindViewIdByWindowHandle(hwnd));
1876 IsDragged = Standard_False;
1879 HDC hdc = GetDC( hwnd );
1880 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1881 SetROP2( hdc, R2_NOT );
1882 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1883 ReleaseDC( hwnd, hdc );
1885 const Handle(ViewerTest_EventManager) EM =
1886 ViewerTest::CurrentEventManager();
1887 if ( fwKeys & MK_SHIFT )
1888 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1889 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1891 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1892 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1894 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1896 case WM_LBUTTONDOWN:
1897 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1899 IsDragged = Standard_True;
1900 DragFirst = Standard_True;
1901 X_ButtonPress = LOWORD(lParam);
1902 Y_ButtonPress = HIWORD(lParam);
1904 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1911 HDC hdc = GetDC( hwnd );
1913 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1914 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1915 SetROP2( hdc, R2_NOT );
1918 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1920 DragFirst = Standard_False;
1921 X_Motion = LOWORD(lParam);
1922 Y_Motion = HIWORD(lParam);
1924 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1926 SelectObject( hdc, anObj );
1928 ReleaseDC( hwnd, hdc );
1931 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1935 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1939 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1943 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1950 if ( !ViewerTest::CurrentView().IsNull() ) {
1955 BeginPaint(hwnd, &ps);
1956 EndPaint(hwnd, &ps);
1961 VT_ProcessConfigure();
1965 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1968 c[0] = (char) wParam;
1970 if (wParam == VK_DELETE)
1972 c[0] = THE_KEY_DELETE;
1974 VT_ProcessKeyPress (c);
1982 VT_ProcessButton3Release();
1985 case WM_LBUTTONDOWN:
1986 case WM_MBUTTONDOWN:
1987 case WM_RBUTTONDOWN:
1989 WPARAM fwKeys = wParam;
1993 X_ButtonPress = LOWORD(lParam);
1994 Y_ButtonPress = HIWORD(lParam);
1996 if (Msg == WM_LBUTTONDOWN)
1998 if (fwKeys & MK_CONTROL)
2000 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2004 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2007 else if (Msg == WM_RBUTTONDOWN)
2010 VT_ProcessButton3Press();
2017 //cout << "\t WM_MOUSEMOVE" << endl;
2018 WPARAM fwKeys = wParam;
2019 X_Motion = LOWORD(lParam);
2020 Y_Motion = HIWORD(lParam);
2023 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2025 X_ButtonPress = LOWORD(lParam);
2026 Y_ButtonPress = HIWORD(lParam);
2028 if ( fwKeys & MK_RBUTTON ) {
2030 VT_ProcessButton3Press();
2034 if ( fwKeys & MK_CONTROL ) {
2035 if ( fwKeys & MK_LBUTTON ) {
2036 ProcessControlButton1Motion();
2038 else if ( fwKeys & MK_MBUTTON ||
2039 ((fwKeys&MK_LBUTTON) &&
2040 (fwKeys&MK_RBUTTON) ) ){
2041 VT_ProcessControlButton2Motion();
2043 else if ( fwKeys & MK_RBUTTON ) {
2044 VT_ProcessControlButton3Motion();
2048 else if ( fwKeys & MK_SHIFT ) {
2049 if ( fwKeys & MK_MBUTTON ||
2050 ((fwKeys&MK_LBUTTON) &&
2051 (fwKeys&MK_RBUTTON) ) ) {
2052 cout << "ProcessZClipMotion()" << endl;
2053 ProcessZClipMotion();
2057 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2059 if ((fwKeys & MK_MBUTTON
2060 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2062 ProcessZClipMotion();
2073 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2078 return DefWindowProc( hwnd, Msg, wParam, lParam );
2084 //==============================================================================
2085 //function : ViewerMainLoop
2086 //purpose : Get a Event on the view and dispatch it
2087 //==============================================================================
2090 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2092 Ppick = (argc > 0)? 1 : 0;
2100 cout << "Start picking" << endl;
2102 while ( Ppick == 1 ) {
2103 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2104 if (GetMessage(&msg, NULL, 0, 0) ) {
2105 TranslateMessage(&msg);
2106 DispatchMessage(&msg);
2110 cout << "Picking done" << endl;
2116 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2118 int min( int a, int b )
2126 int max( int a, int b )
2134 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2137 static XEvent aReport;
2138 Standard_Boolean pick = argc > 0;
2139 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2140 XNextEvent (aDisplay, &aReport);
2142 // Handle event for the chosen display connection
2143 switch (aReport.type) {
2146 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2149 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2155 // Activate inactive view
2156 Window aWindow = GetWindowHandle(VT_GetWindow());
2157 if(aWindow != aReport.xfocus.window)
2159 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2168 case ConfigureNotify:
2170 VT_ProcessConfigure();
2179 XComposeStatus status_in_out;
2181 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2182 (char *) buf_ret , 10 ,
2183 &ks_ret , &status_in_out ) ;
2186 buf_ret[ret_len] = '\0' ;
2190 VT_ProcessKeyPress (buf_ret);
2196 X_ButtonPress = aReport.xbutton.x;
2197 Y_ButtonPress = aReport.xbutton.y;
2199 if (aReport.xbutton.button == Button1)
2201 if (aReport.xbutton.state & ControlMask)
2203 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2207 IsDragged = Standard_True;
2208 DragFirst = Standard_True;
2211 else if (aReport.xbutton.button == Button3)
2214 VT_ProcessButton3Press();
2224 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2225 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2226 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2229 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2230 if( aContext.IsNull() )
2232 cout << "The context is null. Please use vinit before createmesh" << endl;
2236 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2237 if( aReport.xbutton.button==1 )
2241 aContext->ShiftSelect();
2250 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2251 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2252 ViewerTest::CurrentView());
2256 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2257 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2258 ViewerTest::CurrentView() );
2261 VT_ProcessButton3Release();
2263 IsDragged = Standard_False;
2266 VT_ProcessButton3Release();
2271 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2277 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2278 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2279 XSetFunction( aDisplay, gc, GXinvert );
2282 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2284 X_Motion = aReport.xmotion.x;
2285 Y_Motion = aReport.xmotion.y;
2286 DragFirst = Standard_False;
2288 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2292 X_Motion = aReport.xmotion.x;
2293 Y_Motion = aReport.xmotion.y;
2295 // remove all the ButtonMotionMaskr
2296 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2298 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2299 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2301 Quantity_Length VDX, VDY;
2303 ViewerTest::CurrentView()->Size(VDX,VDY);
2304 Standard_Real VDZ =0 ;
2305 VDZ = ViewerTest::CurrentView()->ZSize();
2307 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2309 Quantity_Length dx = 0 ;
2310 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2314 dx = dx / VDX * VDZ;
2318 ViewerTest::CurrentView()->Redraw();
2322 if ( aReport.xmotion.state & ControlMask ) {
2323 if ( aReport.xmotion.state & Button1Mask ) {
2324 ProcessControlButton1Motion();
2326 else if ( aReport.xmotion.state & Button2Mask ) {
2327 VT_ProcessControlButton2Motion();
2329 else if ( aReport.xmotion.state & Button3Mask ) {
2330 VT_ProcessControlButton3Motion();
2344 //==============================================================================
2345 //function : VProcessEvents
2346 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2347 // event in the Viewer window
2348 //==============================================================================
2350 static void VProcessEvents(ClientData,int)
2352 NCollection_Vector<int> anEventNumbers;
2353 // Get number of messages from every display
2354 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2355 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2357 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2359 // Handle events for every display
2360 int anEventIter = 0;
2361 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2362 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2364 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2365 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2367 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2368 int anEventResult = ViewerMainLoop( 0, NULL);
2369 // If window is closed or context was not found finish current event processing loop
2375 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2380 //==============================================================================
2381 //function : OSWindowSetup
2382 //purpose : Setup for the X11 window to be able to cath the event
2383 //==============================================================================
2386 static void OSWindowSetup()
2388 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2391 Window window = VT_GetWindow()->XWindow();
2392 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2393 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2394 XSynchronize(aDisplay, 1);
2396 // X11 : For keyboard on SUN
2398 wmhints.flags = InputHint;
2401 XSetWMHints( aDisplay, window, &wmhints);
2403 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2404 ButtonPressMask | ButtonReleaseMask |
2405 StructureNotifyMask |
2407 Button1MotionMask | Button2MotionMask |
2408 Button3MotionMask | FocusChangeMask
2410 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2411 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2413 XSynchronize(aDisplay, 0);
2422 //==============================================================================
2425 //purpose : Fitall, no DRAW arguments
2426 //Draw arg : No args
2427 //==============================================================================
2429 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2431 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2432 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2433 if (V.IsNull() == Standard_False) {
2435 } else if (aView.IsNull() == Standard_False) {
2441 //==============================================================================
2443 //purpose : ZFitall, no DRAW arguments
2444 //Draw arg : No args
2445 //==============================================================================
2447 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2449 Handle(V3d_View) V = ViewerTest::CurrentView();
2450 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2453 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2455 Handle(V3d_View) V = ViewerTest::CurrentView();
2456 if ( !V.IsNull() ) V->Redraw(); return 0;
2460 //==============================================================================
2462 //purpose : Remove all the object from the viewer
2463 //Draw arg : No args
2464 //==============================================================================
2466 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2468 Handle(V3d_View) V = ViewerTest::CurrentView();
2470 ViewerTest::Clear();
2474 //==============================================================================
2477 //==============================================================================
2479 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2480 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2483 di << argv[0] << "Invalid number of arguments" << "\n";
2487 while (ViewerMainLoop( argc, argv)) {
2493 //==============================================================================
2494 //function : InitViewerTest
2495 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2496 //==============================================================================
2498 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2500 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2501 ViewerTest::SetAISContext(theContext);
2502 aViewer->InitActiveViews();
2503 Handle(V3d_View) aView = aViewer->ActiveView();
2504 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2505 ViewerTest::ResetEventManager();
2506 Handle(Aspect_Window) aWindow = aView->Window();
2507 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2509 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2511 static int aFirst = 1;
2513 #if TCL_MAJOR_VERSION < 8
2514 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2515 TK_READABLE, VProcessEvents, (ClientData) 0);
2517 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2518 TK_READABLE, VProcessEvents, (ClientData) 0);
2525 //==============================================================================
2527 //purpose : Load image as background
2528 //==============================================================================
2530 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2532 if (argc < 2 || argc > 3)
2534 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2535 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2539 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2540 if(AISContext.IsNull())
2542 di << "use 'vinit' command before " << argv[0] << "\n";
2546 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2549 const char* szType = argv[2];
2550 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2551 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2552 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2553 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2556 di << "Wrong fill type : " << szType << "\n";
2557 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2562 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2563 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2568 //==============================================================================
2569 //function : VSetBgMode
2570 //purpose : Change background image fill type
2571 //==============================================================================
2573 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2577 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2578 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2582 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2583 if(AISContext.IsNull())
2585 di << "use 'vinit' command before " << argv[0] << "\n";
2588 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2589 const char* szType = argv[1];
2590 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2591 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2592 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2593 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2596 di << "Wrong fill type : " << szType << "\n";
2597 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2600 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2601 V3dView->SetBgImageStyle(aFillType, Standard_True);
2605 //==============================================================================
2606 //function : VSetGradientBg
2607 //purpose : Mount gradient background
2608 //==============================================================================
2609 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2613 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2614 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2615 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2616 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2620 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2621 if(AISContext.IsNull())
2623 di << "use 'vinit' command before " << argv[0] << "\n";
2629 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2630 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2631 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2632 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2634 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2635 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2636 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2638 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2639 int aType = Draw::Atoi(argv[7]);
2640 if( aType < 0 || aType > 8 )
2642 di << "Wrong fill type " << "\n";
2643 di << "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 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2650 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2651 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2657 //==============================================================================
2658 //function : VSetGradientBgMode
2659 //purpose : Change gradient background fill style
2660 //==============================================================================
2661 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2665 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2666 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2667 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2671 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2672 if(AISContext.IsNull())
2674 di << "use 'vinit' command before " << argv[0] << "\n";
2679 int aType = Draw::Atoi(argv[1]);
2680 if( aType < 0 || aType > 8 )
2682 di << "Wrong fill type " << "\n";
2683 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2684 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2688 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2690 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2691 V3dView->SetBgGradientStyle( aMethod, 1 );
2697 //==============================================================================
2698 //function : VSetColorBg
2699 //purpose : Set color background
2700 //==============================================================================
2701 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2705 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2706 di << "R,G,B = [0..255]" << "\n";
2710 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2711 if(AISContext.IsNull())
2713 di << "use 'vinit' command before " << argv[0] << "\n";
2719 Standard_Real R = Draw::Atof(argv[1])/255.;
2720 Standard_Real G = Draw::Atof(argv[2])/255.;
2721 Standard_Real B = Draw::Atof(argv[3])/255.;
2722 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2724 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2725 V3dView->SetBackgroundColor( aColor );
2732 //==============================================================================
2734 //purpose : View Scaling
2735 //==============================================================================
2737 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2739 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2740 if ( V3dView.IsNull() ) return 1;
2743 di << argv[0] << "Invalid number of arguments" << "\n";
2746 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2749 //==============================================================================
2750 //function : VTestZBuffTrihedron
2751 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2752 //==============================================================================
2754 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2756 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2757 if ( V3dView.IsNull() ) return 1;
2759 V3dView->ZBufferTriedronSetup();
2762 // Set up default trihedron parameters
2763 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2767 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2768 const char* aPosType = argv[1];
2770 if ( strcmp(aPosType, "center") == 0 )
2772 aPosition = Aspect_TOTP_CENTER;
2774 if (strcmp(aPosType, "left_lower") == 0)
2776 aPosition = Aspect_TOTP_LEFT_LOWER;
2778 if (strcmp(aPosType, "left_upper") == 0)
2780 aPosition = Aspect_TOTP_LEFT_UPPER;
2782 if (strcmp(aPosType, "right_lower") == 0)
2784 aPosition = Aspect_TOTP_RIGHT_LOWER;
2786 if (strcmp(aPosType, "right_upper") == 0)
2788 aPosition = Aspect_TOTP_RIGHT_UPPER;
2791 di << argv[1] << " Invalid type of alignment" << "\n";
2792 di << "Must be one of [ center, left_lower," << "\n";
2793 di << "left_upper, right_lower, right_upper ]" << "\n";
2797 Standard_Real R = Draw::Atof(argv[2])/255.;
2798 Standard_Real G = Draw::Atof(argv[3])/255.;
2799 Standard_Real B = Draw::Atof(argv[4])/255.;
2800 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2802 Standard_Real aScale = Draw::Atof(argv[5]);
2806 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2810 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2811 const char* aPresType = argv[6];
2813 if ( strcmp(aPresType, "wireframe") == 0 )
2815 aPresentation = V3d_WIREFRAME;
2817 if (strcmp(aPresType, "zbuffer") == 0)
2819 aPresentation = V3d_ZBUFFER;
2822 di << argv[6] << " Invalid type of visualization" << "\n";
2823 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2827 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2831 di << argv[0] << " Invalid number of arguments" << "\n";
2840 //==============================================================================
2841 //function : VRotate
2842 //purpose : Camera Rotating
2843 //==============================================================================
2845 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2846 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2847 if ( V3dView.IsNull() ) {
2852 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2854 } else if ( argc == 7 ) {
2855 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]) );
2858 di << argv[0] << " Invalid number of arguments" << "\n";
2863 //==============================================================================
2865 //purpose : View zoom in / out (relative to current zoom)
2866 //==============================================================================
2868 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2869 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2870 if ( V3dView.IsNull() ) {
2875 Standard_Real coef = Draw::Atof(argv[1]);
2876 if ( coef <= 0.0 ) {
2877 di << argv[1] << "Invalid value" << "\n";
2880 V3dView->SetZoom( Draw::Atof(argv[1]) );
2883 di << argv[0] << " Invalid number of arguments" << "\n";
2888 //==============================================================================
2890 //purpose : View panning (in pixels)
2891 //==============================================================================
2893 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2894 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2895 if ( V3dView.IsNull() ) return 1;
2898 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2901 di << argv[0] << " Invalid number of arguments" << "\n";
2907 //==============================================================================
2908 //function : VExport
2909 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2910 //==============================================================================
2912 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2914 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2915 if (V3dView.IsNull())
2920 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2924 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2925 TCollection_AsciiString aFormatStr;
2927 TCollection_AsciiString aFileName (argv[1]);
2928 Standard_Integer aLen = aFileName.Length();
2932 aFormatStr = TCollection_AsciiString (argv[2]);
2936 if (aFileName.Value (aLen - 2) == '.')
2938 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2940 else if (aFileName.Value (aLen - 3) == '.')
2942 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2946 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2952 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2956 aFormatStr.UpperCase();
2957 if (aFormatStr == "PS")
2958 anExpFormat = Graphic3d_EF_PostScript;
2959 else if (aFormatStr == "EPS")
2960 anExpFormat = Graphic3d_EF_EnhPostScript;
2961 else if (aFormatStr == "TEX")
2962 anExpFormat = Graphic3d_EF_TEX;
2963 else if (aFormatStr == "PDF")
2964 anExpFormat = Graphic3d_EF_PDF;
2965 else if (aFormatStr == "SVG")
2966 anExpFormat = Graphic3d_EF_SVG;
2967 else if (aFormatStr == "PGF")
2968 anExpFormat = Graphic3d_EF_PGF;
2969 else if (aFormatStr == "EMF")
2970 anExpFormat = Graphic3d_EF_EMF;
2973 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2978 if (!V3dView->View()->Export (argv[1], anExpFormat))
2980 di << "Error: export of image to " << aFormatStr << " failed!\n";
2983 catch (Standard_Failure)
2985 di << "Error: export of image to " << aFormatStr << " failed";
2986 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2991 //==============================================================================
2992 //function : VColorScale
2993 //purpose : representation color scale
2994 //==============================================================================
2995 #include <V3d_ColorScale.hxx>
2997 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2999 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
3001 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
3005 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3006 if(aContext.IsNull()) {
3007 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
3011 Standard_Real minRange = 0. , maxRange = 100. ;
3013 Standard_Integer numIntervals = 10 ;
3014 Standard_Integer textHeight = 16;
3015 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
3016 Standard_Real X = 0., Y = 0. ;
3022 minRange = Draw::Atof( argv[1] );
3023 maxRange = Draw::Atof( argv[2] );
3024 numIntervals = Draw::Atoi( argv[3] );
3027 textHeight = Draw::Atoi( argv[4] );
3029 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
3032 X = Draw::Atof( argv[6] );
3033 Y = Draw::Atof( argv[7] );
3036 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3037 if ( curView.IsNull( ) )
3039 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3040 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3041 if( ! aCS.IsNull( ) )
3043 aCS->SetPosition( X , Y );
3044 aCS->SetHeight( 0.95) ;
3045 aCS->SetTextHeight( textHeight );
3046 aCS->SetRange( minRange , maxRange );
3047 aCS->SetNumberOfIntervals( numIntervals );
3048 aCS->SetLabelPosition( position );
3049 if( !curView->ColorScaleIsDisplayed() )
3050 curView->ColorScaleDisplay( );
3055 //==============================================================================
3056 //function : VGraduatedTrihedron
3057 //purpose : Displays a graduated trihedron
3058 //==============================================================================
3060 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3062 const char *str = arg;
3065 unsigned short c1 = *str++;
3066 unsigned short c2 = *str++;
3067 if (!c1 || !c2) break;
3068 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3072 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3075 if (argc != 2 && argc < 5)
3077 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3078 di<<"Usage: type help "<<argv[0]<<"\n";
3079 return 1; //TCL_ERROR
3082 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3084 // Create 3D view if it doesn't exist
3085 if ( aV3dView.IsNull() )
3087 ViewerTest::ViewerInit();
3088 aV3dView = ViewerTest::CurrentView();
3089 if( aV3dView.IsNull() )
3091 di << "Error: Cannot create a 3D view\n";
3092 return 1; //TCL_ERROR
3096 // Erase (==0) or display (!=0)
3097 const int display = Draw::Atoi(argv[1]);
3102 TCollection_AsciiString font;
3104 font.AssignCat("Courier");
3106 font.AssignCat(argv[5]);
3108 // Text is multibyte
3109 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3112 TCollection_ExtendedString xname, yname, zname;
3117 AddMultibyteString(xname, argv[2]);
3118 AddMultibyteString(yname, argv[3]);
3119 AddMultibyteString(zname, argv[4]);
3135 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3136 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3137 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3138 Standard_True/*drawgrid*/,
3139 Standard_True/*drawaxes*/,
3140 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3141 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3142 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3143 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3144 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3145 Quantity_NOC_WHITE/*gridcolor*/,
3146 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3147 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3150 aV3dView->GraduatedTrihedronErase();
3152 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3158 //==============================================================================
3159 //function : VPrintView
3160 //purpose : Test printing algorithm, print the view to image file with given
3161 // width and height. Printing implemented only for WNT.
3162 //==============================================================================
3163 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3167 di << "Printing implemented only for wnt!\n";
3171 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3172 Handle(V3d_View) aView = NULL;
3173 aContextAIS = ViewerTest::GetAISContext();
3174 if (!aContextAIS.IsNull())
3176 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3177 Vwr->InitActiveViews();
3178 if(Vwr->MoreActiveViews())
3179 aView = Vwr->ActiveView();
3185 di << "Call vinit before!\n";
3190 di << "Use: " << argv[0];
3191 di << " width height filename [print algo=0]\n";
3192 di << "width, height of the intermediate buffer for operation\n";
3193 di << "algo : {0|1}\n";
3194 di << " 0 - stretch algorithm\n";
3195 di << " 1 - tile algorithm\n";
3196 di << "test printing algorithms into an intermediate buffer\n";
3197 di << "with saving output to an image file\n";
3201 // get the input params
3202 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3203 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3204 Standard_Integer aMode = 0;
3205 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3207 aMode = Draw::Atoi (argv[4]);
3209 // check the input parameters
3210 if (aWidth <= 0 || aHeight <= 0)
3212 di << "Width and height must be positive values!\n";
3215 if (aMode != 0 && aMode != 1)
3218 // define compatible bitmap
3219 HDC anDC = CreateCompatibleDC(0);
3220 BITMAPINFO aBitmapData;
3221 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3222 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3223 aBitmapData.bmiHeader.biWidth = aWidth ;
3224 aBitmapData.bmiHeader.biHeight = aHeight;
3225 aBitmapData.bmiHeader.biPlanes = 1;
3226 aBitmapData.bmiHeader.biBitCount = 24;
3227 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3228 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3229 aBitmapData.bmiHeader.biClrUsed = 0;
3230 aBitmapData.bmiHeader.biClrImportant = 0;
3231 aBitmapData.bmiHeader.biCompression = BI_RGB;
3232 aBitmapData.bmiHeader.biSizeImage = 0;
3234 // Create Device Independent Bitmap
3235 void* aBitsOut = NULL;
3236 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3237 &aBitsOut, NULL, 0);
3238 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3240 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3241 if (aBitsOut != NULL)
3244 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3246 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3248 // succesfully printed into an intermediate buffer
3251 Image_PixMap aWrapper;
3252 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3253 aWrapper.SetTopDown (false);
3255 Image_AlienPixMap anImageBitmap;
3256 anImageBitmap.InitCopy (aWrapper);
3257 isSaved = anImageBitmap.Save (aFileName);
3261 di << "Print operation failed due to printing errors or\n";
3262 di << "insufficient memory available\n";
3263 di << "Please, try to use smaller dimensions for this test\n";
3264 di << "command, as it allocates intermediate buffer for storing\n";
3265 di << "the result\n";
3270 di << "Can't allocate memory for intermediate buffer\n";
3271 di << "Please use smaller dimensions\n";
3276 SelectObject (anDC, anOldBitmap);
3277 DeleteObject (aMemoryBitmap);
3283 di << "Save to file operation failed. This operation may fail\n";
3284 di << "if you don't have enough available memory, then you can\n";
3285 di << "use smaller dimensions for the output file\n";
3294 //==============================================================================
3295 //function : VZLayer
3296 //purpose : Test z layer operations for v3d viewer
3297 //==============================================================================
3298 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3300 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3301 if (aContextAIS.IsNull())
3303 di << "Call vinit before!\n";
3308 di << "Use: vzlayer " << argv[0];
3309 di << " add/del/get [id]\n";
3310 di << " add - add new z layer to viewer and print its id\n";
3311 di << " del - del z layer by its id\n";
3312 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3313 di << "id - the layer identificator value defined when removing z layer\n";
3317 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3318 if (aViewer.IsNull())
3320 di << "No active viewer!\n";
3324 // perform operation
3325 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3328 Standard_Integer aNewId;
3329 if (!aViewer->AddZLayer (aNewId))
3331 di << "Impossible to add new z layer!\n";
3335 di << "New z layer added with index: " << aNewId << "\n";
3337 else if (anOp == "del")
3341 di << "Please also provide as argument id of z layer to remove\n";
3345 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3346 if (!aViewer->RemoveZLayer (aDelId))
3348 di << "Impossible to remove the z layer or invalid id!\n";
3352 di << "Z layer " << aDelId << " has been removed\n";
3354 else if (anOp == "get")
3356 TColStd_SequenceOfInteger anIds;
3357 aViewer->GetAllZLayers (anIds);
3358 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3360 di << anIds.Value (aSeqIdx) << " ";
3367 di << "Invalid operation, please use { add / del / get }\n";
3374 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3376 // this class provides a presentation of text item in v3d view under-/overlayer
3377 class V3d_TextItem : public Visual3d_LayerItem
3382 DEFINE_STANDARD_RTTI(V3d_TextItem)
3385 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3386 const Standard_Real theX1,
3387 const Standard_Real theY1,
3388 const Standard_Real theHeight,
3389 const TCollection_AsciiString& theFontName,
3390 const Quantity_Color& theColor,
3391 const Quantity_Color& theSubtitleColor,
3392 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3393 const Handle(Visual3d_Layer)& theLayer);
3396 Standard_EXPORT void RedrawLayerPrs();
3402 TCollection_AsciiString myText;
3403 Standard_Real myHeight;
3404 Handle(Visual3d_Layer) myLayer;
3405 Quantity_Color myColor;
3406 Quantity_Color mySubtitleColor;
3407 Aspect_TypeOfDisplayText myType;
3408 TCollection_AsciiString myFontName;
3411 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3412 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3414 // create and add to display the text item
3415 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3416 const Standard_Real theX1,
3417 const Standard_Real theY1,
3418 const Standard_Real theHeight,
3419 const TCollection_AsciiString& theFontName,
3420 const Quantity_Color& theColor,
3421 const Quantity_Color& theSubtitleColor,
3422 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3423 const Handle(Visual3d_Layer)& theLayer)
3424 : myX1 (theX1), myY1 (theY1),
3426 myHeight (theHeight),
3429 mySubtitleColor (theSubtitleColor),
3430 myType (theTypeOfDisplay),
3431 myFontName (theFontName)
3433 if (!myLayer.IsNull ())
3434 myLayer->AddLayerItem (this);
3438 void V3d_TextItem::RedrawLayerPrs ()
3440 if (myLayer.IsNull ())
3443 myLayer->SetColor (myColor);
3444 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3445 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3448 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3450 // The Visual3d_LayerItem line item for "vlayerline" command
3451 // it provides a presentation of line with user-defined
3452 // linewidth, linetype and transparency.
3453 class V3d_LineItem : public Visual3d_LayerItem
3457 DEFINE_STANDARD_RTTI(V3d_LineItem)
3460 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3461 Standard_Real X2, Standard_Real Y2,
3462 V3d_LayerMgrPointer theLayerMgr,
3463 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3464 Standard_Real theWidth = 0.5,
3465 Standard_Real theTransp = 1.0);
3468 Standard_EXPORT void RedrawLayerPrs();
3472 Standard_Real myX1, myY1, myX2, myY2;
3473 V3d_LayerMgrPointer myLayerMgr;
3474 Aspect_TypeOfLine myType;
3475 Standard_Real myWidth;
3476 Standard_Real myTransparency;
3479 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3480 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3482 // default constructor for line item
3483 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3484 Standard_Real X2, Standard_Real Y2,
3485 V3d_LayerMgrPointer theLayerMgr,
3486 Aspect_TypeOfLine theType,
3487 Standard_Real theWidth,
3488 Standard_Real theTransp) :
3489 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3490 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3492 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3493 myLayerMgr->Overlay()->AddLayerItem (this);
3497 void V3d_LineItem::RedrawLayerPrs ()
3499 Handle (Visual3d_Layer) aOverlay;
3502 aOverlay = myLayerMgr->Overlay();
3504 if (!aOverlay.IsNull())
3506 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3507 aOverlay->SetColor(aColor);
3508 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3509 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3510 aOverlay->BeginPolyline();
3511 aOverlay->AddVertex(myX1, myY1);
3512 aOverlay->AddVertex(myX2, myY2);
3513 aOverlay->ClosePrimitive();
3517 //=============================================================================
3518 //function : VLayerLine
3519 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3520 // : linewidth, transparency coefficient
3521 //============================================================================
3522 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3524 // get the active view
3525 Handle(V3d_View) aView = ViewerTest::CurrentView();
3528 di << "Call vinit before!\n";
3533 di << "Use: " << argv[0];
3534 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3535 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3536 di << " 0 - solid \n";
3537 di << " 1 - dashed \n";
3538 di << " 2 - dot \n";
3539 di << " 3 - dashdot\n";
3540 di << " transparency : { 0.0 - 1.0 } \n";
3541 di << " 0.0 - transparent\n";
3542 di << " 1.0 - visible \n";
3546 // get the input params
3547 Standard_Real X1 = Draw::Atof(argv[1]);
3548 Standard_Real Y1 = Draw::Atof(argv[2]);
3549 Standard_Real X2 = Draw::Atof(argv[3]);
3550 Standard_Real Y2 = Draw::Atof(argv[4]);
3552 Standard_Real aWidth = 0.5;
3553 Standard_Integer aType = 0;
3554 Standard_Real aTransparency = 1.0;
3558 aWidth = Draw::Atof(argv[5]);
3562 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3567 aTransparency = Draw::Atof(argv[7]);
3568 if (aTransparency < 0 || aTransparency > 1.0)
3569 aTransparency = 1.0;
3572 // select appropriate line type
3573 Aspect_TypeOfLine aLineType;
3577 aLineType = Aspect_TOL_DASH;
3581 aLineType = Aspect_TOL_DOT;
3585 aLineType = Aspect_TOL_DOTDASH;
3589 aLineType = Aspect_TOL_SOLID;
3592 // replace layer manager
3593 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3594 aView->SetLayerMgr(aMgr);
3597 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3603 aView->MustBeResized();
3609 //=======================================================================
3610 //function : VOverlayText
3611 //purpose : Test text displaying in view overlay
3612 //=======================================================================
3613 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3615 // get the active view
3616 Handle(V3d_View) aView = ViewerTest::CurrentView();
3619 di << "No active view. Please call vinit.\n";
3622 else if (argc < 4 || argc > 13)
3624 di << "Use: " << argv[0];
3625 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3626 di << "[background_color: R G B]\n";
3627 di << " height - pixel height of the text (default=10.0)\n";
3628 di << " font_name - name of font (default=courier)\n";
3629 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3630 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
3631 di << " background_color- R G B values used for subtitle and decal text\n";
3632 di << "(default=255.0 255.0 255.0)\n";
3636 TCollection_AsciiString aText (argv[1]);
3637 Standard_Real aPosX = Draw::Atof(argv[2]);
3638 Standard_Real aPosY = Draw::Atof(argv[3]);
3639 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3642 TCollection_AsciiString aFontName = "Courier";
3644 aFontName = TCollection_AsciiString (argv[5]);
3647 Quantity_Parameter aColorRed = 1.0;
3648 Quantity_Parameter aColorGreen = 1.0;
3649 Quantity_Parameter aColorBlue = 1.0;
3652 aColorRed = Draw::Atof (argv[6])/255.;
3653 aColorGreen = Draw::Atof (argv[7])/255.;
3654 aColorBlue = Draw::Atof (argv[8])/255.;
3658 TCollection_AsciiString aDispStr;
3660 aDispStr = TCollection_AsciiString (argv[9]);
3662 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3663 if (aDispStr.IsEqual ("subtitle"))
3664 aTextType = Aspect_TODT_SUBTITLE;
3665 else if (aDispStr.IsEqual ("decal"))
3666 aTextType = Aspect_TODT_DEKALE;
3667 else if (aDispStr.IsEqual ("blend"))
3668 aTextType = Aspect_TODT_BLEND;
3669 else if (aDispStr.IsEqual ("dimension"))
3670 aTextType = Aspect_TODT_DIMENSION;
3673 Quantity_Parameter aSubRed = 1.0;
3674 Quantity_Parameter aSubGreen = 1.0;
3675 Quantity_Parameter aSubBlue = 1.0;
3678 aSubRed = Draw::Atof (argv[10])/255.;
3679 aSubGreen = Draw::Atof (argv[11])/255.;
3680 aSubBlue = Draw::Atof (argv[12])/255.;
3683 // check fo current overlay
3684 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3685 if (anOverlay.IsNull ())
3687 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3688 anOverlay = aMgr->Overlay ();
3689 aView->SetLayerMgr (aMgr);
3692 Quantity_Color aTextColor (aColorRed, aColorGreen,
3693 aColorBlue, Quantity_TOC_RGB);
3694 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3695 aSubBlue, Quantity_TOC_RGB);
3698 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3699 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3702 aView->MustBeResized();
3708 //==============================================================================
3711 //==============================================================================
3713 static int VGrid (Draw_Interpretor& /*theDI*/,
3714 Standard_Integer theArgNb,
3715 const char** theArgVec)
3717 // get the active view
3718 Handle(V3d_View) aView = ViewerTest::CurrentView();
3719 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3720 if (aView.IsNull() || aViewer.IsNull())
3722 std::cerr << "No active view. Please call vinit.\n";
3726 Aspect_GridType aType = aViewer->GridType();
3727 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3729 Standard_Integer anIter = 1;
3730 for (; anIter < theArgNb; ++anIter)
3732 const char* aValue = theArgVec[anIter];
3735 aType = Aspect_GT_Rectangular;
3737 else if (*aValue == 'c')
3739 aType = Aspect_GT_Circular;
3741 else if (*aValue == 'l')
3743 aMode = Aspect_GDM_Lines;
3745 else if (*aValue == 'p')
3747 aMode = Aspect_GDM_Points;
3749 else if (strcmp (aValue, "off" ) == 0)
3751 aViewer->DeactivateGrid();
3760 Standard_Integer aTail = (theArgNb - anIter);
3763 aViewer->ActivateGrid (aType, aMode);
3766 else if (aTail != 2 && aTail != 5)
3768 std::cerr << "Incorrect arguments number! Usage:\n"
3769 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3773 Quantity_Length anOriginX, anOriginY;
3774 Quantity_PlaneAngle aRotAngle;
3775 if (aType == Aspect_GT_Rectangular)
3777 Quantity_Length aRStepX, aRStepY;
3778 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3780 anOriginX = Draw::Atof (theArgVec[anIter++]);
3781 anOriginY = Draw::Atof (theArgVec[anIter++]);
3784 aRStepX = Draw::Atof (theArgVec[anIter++]);
3785 aRStepY = Draw::Atof (theArgVec[anIter++]);
3786 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3788 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3789 aViewer->ActivateGrid (aType, aMode);
3791 else if (aType == Aspect_GT_Circular)
3793 Quantity_Length aRadiusStep;
3794 Standard_Integer aDivisionNumber;
3795 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3797 anOriginX = Draw::Atof (theArgVec[anIter++]);
3798 anOriginY = Draw::Atof (theArgVec[anIter++]);
3801 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3802 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3803 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3806 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3807 aViewer->ActivateGrid (aType, aMode);
3813 //==============================================================================
3816 //==============================================================================
3818 static int VFps (Draw_Interpretor& theDI,
3819 Standard_Integer theArgNb,
3820 const char** theArgVec)
3822 // get the active view
3823 Handle(V3d_View) aView = ViewerTest::CurrentView();
3826 std::cerr << "No active view. Please call vinit.\n";
3830 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3833 std::cerr << "Incorrect arguments!\n";
3837 // the time is meaningless for first call
3838 // due to async OpenGl rendering
3841 // redraw view in loop to estimate average values
3844 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3850 const Standard_Real aTime = aTimer.ElapsedTime();
3851 aTimer.OSD_Chronometer::Show (aCpu);
3853 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3854 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3856 // return statistics
3857 theDI << "FPS: " << aFpsAver << "\n"
3858 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3863 //==============================================================================
3864 //function : VGlDebug
3866 //==============================================================================
3868 static int VGlDebug (Draw_Interpretor& theDI,
3869 Standard_Integer theArgNb,
3870 const char** theArgVec)
3874 Handle(V3d_View) aView = ViewerTest::CurrentView();
3877 std::cerr << "No active view. Please call vinit.\n";
3881 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3882 "GL_ARB_debug_output");
3883 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3884 theDI << (isActive ? "1" : "0");
3888 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3892 //==============================================================================
3895 //==============================================================================
3897 static int VVbo (Draw_Interpretor& theDI,
3898 Standard_Integer theArgNb,
3899 const char** theArgVec)
3901 const Standard_Boolean toSet = (theArgNb > 1);
3902 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3905 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
3909 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3910 if (aContextAIS.IsNull())
3914 std::cerr << "No active view!\n";
3918 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3919 if (!aDriver.IsNull())
3923 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3927 aDriver->ChangeOptions().vboDisable = toUseVbo;
3934 //==============================================================================
3937 //==============================================================================
3939 static int VCaps (Draw_Interpretor& theDI,
3940 Standard_Integer theArgNb,
3941 const char** theArgVec)
3943 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
3944 Handle(OpenGl_GraphicDriver) aDriver;
3945 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3946 if (!aContextAIS.IsNull())
3948 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3949 aCaps = &aDriver->ChangeOptions();
3954 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
3955 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
3956 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
3960 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3962 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
3963 if (anArg.Search ("vbo=") > -1)
3965 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3967 else if (anArg.Search ("sprites=") > -1)
3969 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3971 else if (anArg.Search ("soft=") > -1)
3973 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
3977 std::cerr << "Unknown argument: " << anArg << "\n";
3980 if (aCaps != &ViewerTest_myDefaultCaps)
3982 ViewerTest_myDefaultCaps = *aCaps;
3987 //==============================================================================
3988 //function : VMemGpu
3990 //==============================================================================
3992 static int VMemGpu (Draw_Interpretor& theDI,
3993 Standard_Integer theArgNb,
3994 const char** theArgVec)
3997 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3998 if (aContextAIS.IsNull())
4000 std::cerr << "No active view. Please call vinit.\n";
4004 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
4005 if (aDriver.IsNull())
4007 std::cerr << "Graphic driver not available.\n";
4011 Standard_Size aFreeBytes = 0;
4012 TCollection_AsciiString anInfo;
4013 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
4015 std::cerr << "Information not available.\n";
4019 if (theArgNb > 1 && *theArgVec[1] == 'f')
4021 theDI << Standard_Real (aFreeBytes);
4031 // ==============================================================================
4032 // function : VReadPixel
4034 // ==============================================================================
4035 static int VReadPixel (Draw_Interpretor& theDI,
4036 Standard_Integer theArgNb,
4037 const char** theArgVec)
4039 // get the active view
4040 Handle(V3d_View) aView = ViewerTest::CurrentView();
4043 std::cerr << "No active view. Please call vinit.\n";
4046 else if (theArgNb < 3)
4048 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4052 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4053 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4055 Standard_Integer aWidth, aHeight;
4056 aView->Window()->Size (aWidth, aHeight);
4057 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4058 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4059 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4061 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4065 Standard_Boolean toShowName = Standard_False;
4066 Standard_Boolean toShowHls = Standard_False;
4067 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4069 const char* aParam = theArgVec[anIter];
4070 if ( strcasecmp( aParam, "rgb" ) == 0 )
4072 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4073 aBufferType = Graphic3d_BT_RGB;
4075 else if ( strcasecmp( aParam, "hls" ) == 0 )
4077 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4078 aBufferType = Graphic3d_BT_RGB;
4079 toShowHls = Standard_True;
4081 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4083 aFormat = Image_PixMap::ImgRGBF;
4084 aBufferType = Graphic3d_BT_RGB;
4086 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4088 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4089 aBufferType = Graphic3d_BT_RGBA;
4091 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4093 aFormat = Image_PixMap::ImgRGBAF;
4094 aBufferType = Graphic3d_BT_RGBA;
4096 else if ( strcasecmp( aParam, "depth" ) == 0 )
4098 aFormat = Image_PixMap::ImgGrayF;