1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <OpenGl_GlCore20.hxx>
19 #include <AIS_Animation.hxx>
20 #include <AIS_AnimationCamera.hxx>
21 #include <AIS_AnimationObject.hxx>
22 #include <AIS_ColorScale.hxx>
23 #include <AIS_Manipulator.hxx>
24 #include <AIS_RubberBand.hxx>
25 #include <AIS_Shape.hxx>
26 #include <AIS_InteractiveObject.hxx>
27 #include <AIS_ListOfInteractive.hxx>
28 #include <AIS_ListIteratorOfListOfInteractive.hxx>
30 #include <Draw_ProgressIndicator.hxx>
31 #include <Graphic3d_ArrayOfPolylines.hxx>
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_ExportFormat.hxx>
34 #include <Graphic3d_NameOfTextureEnv.hxx>
35 #include <Graphic3d_GraduatedTrihedron.hxx>
36 #include <Graphic3d_TextureEnv.hxx>
37 #include <Graphic3d_TextureParams.hxx>
38 #include <Graphic3d_TypeOfTextureFilter.hxx>
39 #include <Graphic3d_AspectFillArea3d.hxx>
40 #include <ViewerTest.hxx>
41 #include <ViewerTest_AutoUpdater.hxx>
42 #include <ViewerTest_EventManager.hxx>
43 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
44 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_CmdParser.hxx>
46 #include <V3d_AmbientLight.hxx>
47 #include <V3d_DirectionalLight.hxx>
48 #include <V3d_PositionalLight.hxx>
49 #include <V3d_SpotLight.hxx>
50 #include <Message_ProgressSentry.hxx>
51 #include <NCollection_DoubleMap.hxx>
52 #include <NCollection_List.hxx>
53 #include <NCollection_Vector.hxx>
54 #include <AIS_InteractiveContext.hxx>
55 #include <Draw_Interpretor.hxx>
57 #include <Draw_Appli.hxx>
58 #include <Image_AlienPixMap.hxx>
59 #include <Image_VideoRecorder.hxx>
60 #include <OpenGl_GraphicDriver.hxx>
61 #include <OSD_Timer.hxx>
62 #include <TColStd_HSequenceOfAsciiString.hxx>
63 #include <TColStd_SequenceOfInteger.hxx>
64 #include <TColStd_HSequenceOfReal.hxx>
65 #include <TColgp_Array1OfPnt2d.hxx>
66 #include <TColStd_MapOfAsciiString.hxx>
67 #include <Aspect_TypeOfLine.hxx>
68 #include <Image_Diff.hxx>
69 #include <Aspect_DisplayConnection.hxx>
73 #include <PrsMgr_PresentableObject.hxx>
74 #include <Graphic3d_ClipPlane.hxx>
75 #include <NCollection_DataMap.hxx>
76 #include <Graphic3d_Texture2Dmanual.hxx>
77 #include <Prs3d_ShadingAspect.hxx>
78 #include <Prs3d_Drawer.hxx>
79 #include <Prs3d_LineAspect.hxx>
80 #include <Prs3d_Root.hxx>
81 #include <Prs3d_Text.hxx>
82 #include <Select3D_SensitivePrimitiveArray.hxx>
91 #include <WNT_WClass.hxx>
92 #include <WNT_Window.hxx>
93 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
94 #include <Cocoa_Window.hxx>
96 #include <Xw_Window.hxx>
97 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
98 #include <X11/Xutil.h>
102 // Auxiliary definitions
103 static const char THE_KEY_DELETE = 127;
104 static const char THE_KEY_ESCAPE = 27;
106 //==============================================================================
107 // VIEWER GLOBAL VARIABLES
108 //==============================================================================
110 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
111 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
113 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
114 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
116 extern int VErase (Draw_Interpretor& theDI,
117 Standard_Integer theArgNb,
118 const char** theArgVec);
121 static Handle(WNT_Window)& VT_GetWindow() {
122 static Handle(WNT_Window) WNTWin;
125 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
126 static Handle(Cocoa_Window)& VT_GetWindow()
128 static Handle(Cocoa_Window) aWindow;
131 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
132 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
133 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
136 static Handle(Xw_Window)& VT_GetWindow(){
137 static Handle(Xw_Window) XWWin;
141 static void VProcessEvents(ClientData,int);
144 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
146 static Handle(Aspect_DisplayConnection) aDisplayConnection;
147 return aDisplayConnection;
150 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
152 GetDisplayConnection() = theDisplayConnection;
155 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
156 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
158 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
160 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
161 if (!aWindow.IsNull())
162 return aWindow->HWindow();
163 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
164 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
165 if (!aWindow.IsNull())
166 return aWindow->XWindow();
168 return aWindowHandle;
172 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
173 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
174 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
175 static OpenGl_Caps ViewerTest_myDefaultCaps;
177 static void OSWindowSetup();
181 Quantity_Color FlatColor;
182 Quantity_Color GradientColor1;
183 Quantity_Color GradientColor2;
184 Aspect_GradientFillMethod FillMethod;
185 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
187 //==============================================================================
188 // EVENT GLOBAL VARIABLES
189 //==============================================================================
191 static int Start_Rot = 0;
192 Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
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 = Standard_False;
199 Standard_Boolean TheIsAnimating = Standard_False;
200 Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
201 Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
204 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
206 static Handle(AIS_RubberBand) aBand;
209 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
210 aBand->SetDisplayMode (0);
215 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
217 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
219 static ViewerTest_MapOfAISManipulators aMap;
223 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
225 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
226 for (; anIt.More(); anIt.Next())
228 if (anIt.Value()->HasActiveMode())
236 //==============================================================================
239 static LRESULT WINAPI ViewerWindowProc(
244 static LRESULT WINAPI AdvViewerWindowProc(
252 //==============================================================================
255 //==============================================================================
257 const Handle(Standard_Transient)& ViewerTest::WClass()
259 static Handle(Standard_Transient) theWClass;
261 if (theWClass.IsNull())
263 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
264 CS_VREDRAW | CS_HREDRAW, 0, 0,
265 ::LoadCursorW (NULL, IDC_ARROW));
271 //==============================================================================
272 //function : CreateName
273 //purpose : Create numerical name for new object in theMap
274 //==============================================================================
275 template <typename ObjectType>
276 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
277 const TCollection_AsciiString& theDefaultString)
279 if (theObjectMap.IsEmpty())
280 return theDefaultString + TCollection_AsciiString(1);
282 Standard_Integer aNextKey = 1;
283 Standard_Boolean isFound = Standard_False;
286 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
287 // Look for objects with default names
288 if (theObjectMap.IsBound1(aStringKey))
293 isFound = Standard_True;
296 return theDefaultString + TCollection_AsciiString(aNextKey);
299 //==============================================================================
300 //structure : ViewerTest_Names
301 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
302 //==============================================================================
303 struct ViewerTest_Names
306 TCollection_AsciiString myDriverName;
307 TCollection_AsciiString myViewerName;
308 TCollection_AsciiString myViewName;
312 const TCollection_AsciiString& GetDriverName () const
316 void SetDriverName (const TCollection_AsciiString& theDriverName)
318 myDriverName = theDriverName;
320 const TCollection_AsciiString& GetViewerName () const
324 void SetViewerName (const TCollection_AsciiString& theViewerName)
326 myViewerName = theViewerName;
328 const TCollection_AsciiString& GetViewName () const
332 void SetViewName (const TCollection_AsciiString& theViewName)
334 myViewName = theViewName;
337 //===========================================================================
338 //function : Constructor for ViewerTest_Names
339 //purpose : Get view, viewer, driver names from custom string
340 //===========================================================================
342 ViewerTest_Names (const TCollection_AsciiString& theInputString)
344 TCollection_AsciiString aName(theInputString);
345 if (theInputString.IsEmpty())
347 // Get current configuration
348 if (ViewerTest_myDrivers.IsEmpty())
349 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
350 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
352 myDriverName = ViewerTest_myDrivers.Find2
353 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
355 if(ViewerTest_myContexts.IsEmpty())
357 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
358 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
362 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
365 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
369 // There is at least view name
370 Standard_Integer aParserNumber = 0;
371 for (Standard_Integer i = 0; i < 3; ++i)
373 Standard_Integer aParserPos = aName.SearchFromEnd("/");
377 aName.Split(aParserPos-1);
382 if (aParserNumber == 0)
385 if (!ViewerTest::GetAISContext().IsNull())
387 myDriverName = ViewerTest_myDrivers.Find2
388 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
389 myViewerName = ViewerTest_myContexts.Find2
390 (ViewerTest::GetAISContext());
394 // There is no opened contexts here, need to create names for viewer and driver
395 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
396 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
398 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
399 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
401 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
403 else if (aParserNumber == 1)
405 // Here is viewerName/viewName
406 if (!ViewerTest::GetAISContext().IsNull())
407 myDriverName = ViewerTest_myDrivers.Find2
408 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
411 // There is no opened contexts here, need to create name for driver
412 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
413 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
415 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
417 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
421 //Here is driverName/viewerName/viewName
422 myDriverName = TCollection_AsciiString(aName);
424 TCollection_AsciiString aViewerName(theInputString);
425 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
426 myViewerName = TCollection_AsciiString(aViewerName);
428 myViewName = TCollection_AsciiString(theInputString);
434 //==============================================================================
435 //function : FindContextByView
436 //purpose : Find AIS_InteractiveContext by View
437 //==============================================================================
439 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
441 Handle(AIS_InteractiveContext) anAISContext;
443 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
444 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
446 if (anIter.Value()->CurrentViewer() == theView->Viewer())
447 return anIter.Key2();
453 //==============================================================================
454 //function : SetWindowTitle
455 //purpose : Set window title
456 //==============================================================================
458 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
459 Standard_CString theTitle)
462 const TCollection_ExtendedString theTitleW (theTitle);
463 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
464 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
465 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
467 if(GetDisplayConnection()->GetDisplay())
470 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
471 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
476 //==============================================================================
477 //function : IsWindowOverlapped
478 //purpose : Check if theWindow overlapp another view
479 //==============================================================================
481 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
482 const Standard_Integer thePxTop,
483 const Standard_Integer thePxRight,
484 const Standard_Integer thePxBottom,
485 TCollection_AsciiString& theViewId)
487 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
488 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
490 Standard_Integer aTop = 0,
494 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
495 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
496 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
497 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
498 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
500 theViewId = anIter.Key1();
501 return Standard_True;
504 return Standard_False;
507 // Workaround: to create and delete non-orthographic views outside ViewerTest
508 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
510 ViewerTest_myViews.UnBind1 (theName);
513 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
514 const Handle(V3d_View)& theView)
516 ViewerTest_myViews.Bind (theName, theView);
519 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
521 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
523 //==============================================================================
524 //function : ViewerInit
525 //purpose : Create the window viewer and initialize all the global variable
526 //==============================================================================
528 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
529 const Standard_Integer thePxTop,
530 const Standard_Integer thePxWidth,
531 const Standard_Integer thePxHeight,
532 Standard_CString theViewName,
533 Standard_CString theDisplayName)
535 // Default position and dimension of the viewer window.
536 // Note that left top corner is set to be sufficiently small to have
537 // window fit in the small screens (actual for remote desktops, see #23003).
538 // The position corresponds to the window's client area, thus some
539 // gap is added for window frame to be visible.
540 Standard_Integer aPxLeft = 20;
541 Standard_Integer aPxTop = 40;
542 Standard_Integer aPxWidth = 409;
543 Standard_Integer aPxHeight = 409;
544 Standard_Boolean toCreateViewer = Standard_False;
546 Handle(OpenGl_GraphicDriver) aGraphicDriver;
547 ViewerTest_Names aViewNames(theViewName);
548 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
549 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
556 aPxWidth = thePxWidth;
557 if (thePxHeight != 0)
558 aPxHeight = thePxHeight;
560 // Get graphic driver (create it or get from another view)
561 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
563 // Get connection string
564 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
565 TCollection_AsciiString aDisplayName(theDisplayName);
566 if (!aDisplayName.IsEmpty())
567 SetDisplayConnection (new Aspect_DisplayConnection ());
569 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
571 (void)theDisplayName; // avoid warning on unused argument
572 SetDisplayConnection (new Aspect_DisplayConnection ());
575 if (Draw_VirtualWindows)
577 // don't waste the time waiting for VSync when window is not displayed on the screen
578 ViewerTest_myDefaultCaps.swapInterval = 0;
579 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
580 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
582 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
583 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
585 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
586 toCreateViewer = Standard_True;
590 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
593 //Dispose the window if input parameters are default
594 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
596 Standard_Integer aTop = 0,
603 // Get screen resolution
604 #if defined(_WIN32) || defined(__WIN32__)
606 GetClientRect(GetDesktopWindow(), &aWindowSize);
607 aScreenHeight = aWindowSize.bottom;
608 aScreenWidth = aWindowSize.right;
609 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
610 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
612 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
613 aScreenWidth = WidthOfScreen(aScreen);
614 aScreenHeight = HeightOfScreen(aScreen);
617 TCollection_AsciiString anOverlappedViewId("");
619 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
621 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
623 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
624 && aRight + 2*aPxWidth + 40 > aScreenWidth)
626 if (aBottom + aPxHeight + 40 > aScreenHeight)
633 aPxTop = aBottom + 40;
636 aPxLeft = aRight + 20;
641 TCollection_AsciiString aTitle("3D View - ");
642 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
644 // Change name of current active window
645 if (!ViewerTest::CurrentView().IsNull())
647 TCollection_AsciiString anActiveWindowTitle("3D View - ");
648 anActiveWindowTitle = anActiveWindowTitle
649 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
650 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
654 Handle(V3d_Viewer) a3DViewer;
655 // If it's the single view, we first look for empty context
656 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
658 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
659 anIter(ViewerTest_myContexts);
661 ViewerTest::SetAISContext (anIter.Value());
662 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
664 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
666 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
667 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
669 else if (a3DViewer.IsNull())
671 toCreateViewer = Standard_True;
672 a3DViewer = new V3d_Viewer(aGraphicDriver);
673 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
674 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
675 ViewerTest_DefaultBackground.GradientColor2,
676 ViewerTest_DefaultBackground.FillMethod);
680 if (ViewerTest::GetAISContext().IsNull() ||
681 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
683 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
684 ViewerTest::SetAISContext (aContext);
685 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
689 ViewerTest::ResetEventManager();
694 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
695 Handle(WNT_WClass)::DownCast (WClass()),
696 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
700 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
701 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
703 aPxWidth, aPxHeight);
704 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
706 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
709 aPxWidth, aPxHeight);
711 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
714 Handle(V3d_View) aView = a3DViewer->CreateView();
715 aView->SetWindow (VT_GetWindow());
716 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
718 ViewerTest::CurrentView(aView);
719 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
721 // Setup for X11 or NT
724 // Set parameters for V3d_View and V3d_Viewer
725 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
726 aV3dView->SetComputedMode(Standard_False);
728 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
731 a3DViewer->SetDefaultLights();
732 a3DViewer->SetLightOn();
735 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
736 #if TCL_MAJOR_VERSION < 8
737 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
738 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
740 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
741 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
745 VT_GetWindow()->Map();
747 // Set the handle of created view in the event manager
748 ViewerTest::ResetEventManager();
750 ViewerTest::CurrentView()->Redraw();
755 return aViewNames.GetViewName();
758 //==============================================================================
759 //function : RedrawAllViews
760 //purpose : Redraw all created views
761 //==============================================================================
762 void ViewerTest::RedrawAllViews()
764 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
765 for (; aViewIt.More(); aViewIt.Next())
767 const Handle(V3d_View)& aView = aViewIt.Key2();
772 //==============================================================================
774 //purpose : Create the window viewer and initialize all the global variable
775 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
776 //==============================================================================
778 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
780 TCollection_AsciiString aViewName, aDisplayName;
781 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
782 TCollection_AsciiString aName, aValue;
783 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
785 const TCollection_AsciiString anArg = theArgVec[anArgIt];
786 TCollection_AsciiString anArgCase = anArg;
787 anArgCase.LowerCase();
788 if (anArgIt + 1 < theArgsNb
789 && anArgCase == "-name")
791 aViewName = theArgVec[++anArgIt];
793 else if (anArgIt + 1 < theArgsNb
794 && (anArgCase == "-left"
795 || anArgCase == "-l"))
797 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
799 else if (anArgIt + 1 < theArgsNb
800 && (anArgCase == "-top"
801 || anArgCase == "-t"))
803 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
805 else if (anArgIt + 1 < theArgsNb
806 && (anArgCase == "-width"
807 || anArgCase == "-w"))
809 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
811 else if (anArgIt + 1 < theArgsNb
812 && (anArgCase == "-height"
813 || anArgCase == "-h"))
815 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
817 else if (anArgCase == "-exitonclose")
819 Draw_ToExitOnCloseView = true;
820 if (anArgIt + 1 < theArgsNb
821 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
826 else if (anArgCase == "-closeonescape"
827 || anArgCase == "-closeonesc")
829 Draw_ToCloseViewOnEsc = true;
830 if (anArgIt + 1 < theArgsNb
831 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
836 else if (anArgIt + 1 < theArgsNb
837 && (anArgCase == "-disp"
838 || anArgCase == "-display"))
840 aDisplayName = theArgVec[++anArgIt];
843 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
850 else if (aName == "l"
853 aPxLeft = aValue.IntegerValue();
855 else if (aName == "t"
858 aPxTop = aValue.IntegerValue();
860 else if (aName == "disp"
861 || aName == "display")
863 aDisplayName = aValue;
865 else if (aName == "w"
868 aPxWidth = aValue.IntegerValue();
870 else if (aName == "h"
871 || aName == "height")
873 aPxHeight = aValue.IntegerValue();
877 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
881 else if (aViewName.IsEmpty())
887 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
892 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
893 if (!aDisplayName.IsEmpty())
895 aDisplayName.Clear();
896 std::cout << "Warning: display parameter will be ignored.\n";
900 ViewerTest_Names aViewNames (aViewName);
901 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
903 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
904 theDi.Eval (aCommand.ToCString());
908 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
909 aViewName.ToCString(),
910 aDisplayName.ToCString());
915 //! Parse HLR algo type.
916 static Standard_Boolean parseHlrAlgoType (const char* theName,
917 Prs3d_TypeOfHLR& theType)
919 TCollection_AsciiString aName (theName);
921 if (aName == "polyalgo")
923 theType = Prs3d_TOH_PolyAlgo;
925 else if (aName == "algo")
927 theType = Prs3d_TOH_Algo;
931 return Standard_False;
933 return Standard_True;
936 //==============================================================================
938 //purpose : hidden lines removal algorithm
939 //==============================================================================
941 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
943 const Handle(V3d_View) aView = ViewerTest::CurrentView();
944 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
947 std::cerr << "Error: No opened viewer!\n";
951 Standard_Boolean hasHlrOnArg = Standard_False;
952 Standard_Boolean hasShowHiddenArg = Standard_False;
953 Standard_Boolean isHLROn = Standard_False;
954 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
955 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
956 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
957 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
959 TCollection_AsciiString anArg (argv[anArgIter]);
961 if (anUpdateTool.parseRedrawMode (anArg))
965 else if (anArg == "-showhidden"
966 && anArgIter + 1 < argc
967 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
970 hasShowHiddenArg = Standard_True;
973 else if ((anArg == "-type"
975 || anArg == "-algotype")
976 && anArgIter + 1 < argc
977 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
982 else if (!hasHlrOnArg
983 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
985 hasHlrOnArg = Standard_True;
989 else if (!hasShowHiddenArg
990 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
992 hasShowHiddenArg = Standard_True;
997 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
1003 di << "HLR: " << aView->ComputedMode() << "\n";
1004 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1006 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1008 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1009 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1010 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1012 anUpdateTool.Invalidate();
1016 Standard_Boolean toRecompute = Standard_False;
1017 if (aTypeOfHLR != Prs3d_TOH_NotSet
1018 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
1020 toRecompute = Standard_True;
1021 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1023 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1025 toRecompute = Standard_True;
1028 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
1032 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
1037 if (aView->ComputedMode() && isHLROn && toRecompute)
1039 AIS_ListOfInteractive aListOfShapes;
1040 aCtx->DisplayedObjects (aListOfShapes);
1041 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
1043 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
1045 aCtx->Redisplay (aShape, Standard_False);
1050 aView->SetComputedMode (isHLROn);
1054 //==============================================================================
1055 //function : VHLRType
1056 //purpose : change type of using HLR algorithm
1057 //==============================================================================
1059 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1061 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1062 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1065 std::cerr << "Error: No opened viewer!\n";
1069 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1070 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1071 AIS_ListOfInteractive aListOfShapes;
1072 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1074 TCollection_AsciiString anArg (argv[anArgIter]);
1076 if (anUpdateTool.parseRedrawMode (anArg))
1080 else if ((anArg == "-type"
1082 || anArg == "-algotype")
1083 && anArgIter + 1 < argc
1084 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1090 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1091 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1097 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1098 TCollection_AsciiString aName (argv[anArgIter]);
1099 if (!aMap.IsBound2 (aName))
1101 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1105 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1106 if (aShape.IsNull())
1108 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1111 aListOfShapes.Append (aShape);
1115 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1117 std::cout << "Syntax error: wrong number of arguments!\n";
1121 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1124 aCtx->DisplayedObjects (aListOfShapes);
1125 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1128 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1130 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1131 if (aShape.IsNull())
1136 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1137 && aView->ComputedMode();
1139 || aShape->TypeOfHLR() != aTypeOfHLR)
1141 aShape->SetTypeOfHLR (aTypeOfHLR);
1145 aCtx->Redisplay (aShape, Standard_False);
1151 //==============================================================================
1152 //function : FindViewIdByWindowHandle
1153 //purpose : Find theView Id in the map of views by window handle
1154 //==============================================================================
1155 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1156 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1158 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1159 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1161 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1162 if (aWindowHandle == theWindowHandle)
1163 return anIter.Key1();
1165 return TCollection_AsciiString("");
1169 //==============================================================================
1170 //function : ActivateView
1171 //purpose : Make the view active
1172 //==============================================================================
1174 void ActivateView (const TCollection_AsciiString& theViewName)
1176 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1177 if (!aView.IsNull())
1179 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1180 if (!anAISContext.IsNull())
1182 if (!ViewerTest::CurrentView().IsNull())
1184 TCollection_AsciiString aTitle("3D View - ");
1185 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1186 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1189 ViewerTest::CurrentView (aView);
1190 ViewerTest::SetAISContext (anAISContext);
1191 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
1192 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1194 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1195 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1196 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1198 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1200 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1201 ViewerTest::CurrentView()->Redraw();
1206 //==============================================================================
1207 //function : RemoveView
1209 //==============================================================================
1210 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1211 const Standard_Boolean theToRemoveContext)
1213 if (!ViewerTest_myViews.IsBound2 (theView))
1218 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1219 RemoveView (aViewName, theToRemoveContext);
1222 //==============================================================================
1223 //function : RemoveView
1224 //purpose : Close and remove view from display, clear maps if neccessary
1225 //==============================================================================
1226 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1228 if (!ViewerTest_myViews.IsBound1(theViewName))
1230 cout << "Wrong view name\n";
1234 // Activate another view if it's active now
1235 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1237 if (ViewerTest_myViews.Extent() > 1)
1239 TCollection_AsciiString aNewViewName;
1240 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1241 anIter.More(); anIter.Next())
1243 if (anIter.Key1() != theViewName)
1245 aNewViewName = anIter.Key1();
1249 ActivateView (aNewViewName);
1253 Handle(V3d_View) anEmptyView;
1254 #if defined(_WIN32) || defined(__WIN32__)
1255 Handle(WNT_Window) anEmptyWindow;
1256 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1257 Handle(Cocoa_Window) anEmptyWindow;
1259 Handle(Xw_Window) anEmptyWindow;
1261 VT_GetWindow() = anEmptyWindow;
1262 ViewerTest::CurrentView (anEmptyView);
1263 if (isContextRemoved)
1265 Handle(AIS_InteractiveContext) anEmptyContext;
1266 ViewerTest::SetAISContext(anEmptyContext);
1272 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1273 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1275 // Remove view resources
1276 ViewerTest_myViews.UnBind1(theViewName);
1277 aView->Window()->Unmap();
1280 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1281 XFlush (GetDisplayConnection()->GetDisplay());
1284 // Keep context opened only if the closed view is last to avoid
1285 // unused empty contexts
1286 if (!aCurrentContext.IsNull())
1288 // Check if there are more difined views in the viewer
1289 aCurrentContext->CurrentViewer()->InitDefinedViews();
1290 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1292 // Remove driver if there is no viewers that use it
1293 Standard_Boolean isRemoveDriver = Standard_True;
1294 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1295 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1297 if (aCurrentContext != anIter.Key2() &&
1298 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1300 isRemoveDriver = Standard_False;
1305 aCurrentContext->RemoveAll (Standard_False);
1308 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1309 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1310 #if TCL_MAJOR_VERSION < 8
1311 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1313 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1318 ViewerTest_myContexts.UnBind2(aCurrentContext);
1321 cout << "3D View - " << theViewName << " was deleted.\n";
1322 if (Draw_ToExitOnCloseView)
1324 Draw_Interprete ("exit");
1328 //==============================================================================
1330 //purpose : Remove the view defined by its name
1331 //==============================================================================
1333 static int VClose (Draw_Interpretor& /*theDi*/,
1334 Standard_Integer theArgsNb,
1335 const char** theArgVec)
1337 NCollection_List<TCollection_AsciiString> aViewList;
1340 TCollection_AsciiString anArg (theArgVec[1]);
1342 if (anArg.IsEqual ("ALL")
1343 || anArg.IsEqual ("*"))
1345 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1346 anIter.More(); anIter.Next())
1348 aViewList.Append (anIter.Key1());
1350 if (aViewList.IsEmpty())
1352 std::cout << "No view to close\n";
1358 ViewerTest_Names aViewName (theArgVec[1]);
1359 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1361 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1364 aViewList.Append (aViewName.GetViewName());
1369 // close active view
1370 if (ViewerTest::CurrentView().IsNull())
1372 std::cerr << "No active view!\n";
1375 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1378 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1379 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1380 anIter.More(); anIter.Next())
1382 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1388 //==============================================================================
1389 //function : VActivate
1390 //purpose : Activate the view defined by its ID
1391 //==============================================================================
1393 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1397 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1398 << "Usage: " << theArgVec[0] << " ViewID\n";
1403 theDi.Eval("vviewlist");
1407 TCollection_AsciiString aNameString(theArgVec[1]);
1408 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1410 TCollection_AsciiString aTitle("3D View - ");
1411 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1412 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1413 Handle(V3d_View) anEmptyView;
1414 #if defined(_WIN32) || defined(__WIN32__)
1415 Handle(WNT_Window) anEmptyWindow;
1416 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1417 Handle(Cocoa_Window) anEmptyWindow;
1419 Handle(Xw_Window) anEmptyWindow;
1421 VT_GetWindow() = anEmptyWindow;
1422 ViewerTest::CurrentView (anEmptyView);
1423 ViewerTest::ResetEventManager();
1424 theDi << theArgVec[0] << ": all views are inactive\n";
1428 ViewerTest_Names aViewNames(aNameString);
1430 // Check if this view exists in the viewer with the driver
1431 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1433 theDi << "Wrong view name\n";
1437 // Check if it is active already
1438 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1440 theDi << theArgVec[0] << ": the view is active already\n";
1444 ActivateView (aViewNames.GetViewName());
1448 //==============================================================================
1449 //function : VViewList
1450 //purpose : Print current list of views per viewer and graphic driver ID
1451 // shared between viewers
1452 //==============================================================================
1454 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1458 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1459 << "Usage: " << theArgVec[0] << " name";
1462 if (ViewerTest_myContexts.Size() < 1)
1465 Standard_Boolean isTreeView =
1466 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1470 theDi << theArgVec[0] <<":\n";
1473 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1474 aDriverIter.More(); aDriverIter.Next())
1477 theDi << aDriverIter.Key1() << ":\n";
1479 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1480 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1482 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1486 TCollection_AsciiString aContextName(aContextIter.Key1());
1487 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1490 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1491 aViewIter.More(); aViewIter.Next())
1493 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1495 TCollection_AsciiString aViewName(aViewIter.Key1());
1498 if (aViewIter.Value() == ViewerTest::CurrentView())
1499 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1501 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1505 theDi << aViewName << " ";
1515 //==============================================================================
1516 //function : VT_ProcessKeyPress
1517 //purpose : Handle KeyPress event from a CString
1518 //==============================================================================
1519 void VT_ProcessKeyPress (const char* buf_ret)
1521 //cout << "KeyPress" << endl;
1522 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1523 // Letter in alphabetic order
1525 if (!strcasecmp (buf_ret, "A"))
1528 aView->SetProj(V3d_XposYnegZpos);
1530 else if (!strcasecmp (buf_ret, "D"))
1535 else if (!strcasecmp (buf_ret, "F"))
1537 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1539 ViewerTest::GetAISContext()->FitSelected (aView);
1547 else if (!strcasecmp (buf_ret, "H"))
1550 std::cout << "HLR" << std::endl;
1551 aView->SetComputedMode (!aView->ComputedMode());
1554 else if (!strcasecmp (buf_ret, "P"))
1557 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1558 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1559 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1561 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1562 if (aContext->NbSelected()==0)
1564 AIS_ListOfInteractive aListOfShapes;
1565 aContext->DisplayedObjects(aListOfShapes);
1566 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1567 anIter.More(); anIter.Next())
1569 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1570 if (aShape.IsNull())
1572 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1573 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1575 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1576 aContext->Redisplay (aShape, Standard_False);
1581 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1583 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1584 if (aShape.IsNull())
1586 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1587 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1589 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1590 aContext->Redisplay (aShape, Standard_False);
1594 aContext->UpdateCurrentViewer();
1597 else if (!strcasecmp (buf_ret, "S"))
1599 std::cout << "setup Shaded display mode" << std::endl;
1601 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1602 if(Ctx->NbSelected()==0)
1603 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
1605 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1606 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1607 Ctx->UpdateCurrentViewer();
1610 else if (!strcasecmp (buf_ret, "U"))
1612 // Unset display mode
1613 std::cout << "reset display mode to defaults" << std::endl;
1615 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1616 if(Ctx->NbSelected()==0)
1617 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1619 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1620 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1621 Ctx->UpdateCurrentViewer();
1625 else if (!strcasecmp (buf_ret, "T"))
1628 aView->SetProj(V3d_Zpos);
1630 else if (!strcasecmp (buf_ret, "B"))
1633 aView->SetProj(V3d_Zneg);
1635 else if (!strcasecmp (buf_ret, "L"))
1638 aView->SetProj(V3d_Xneg);
1640 else if (!strcasecmp (buf_ret, "R"))
1643 aView->SetProj(V3d_Xpos);
1645 else if (!strcasecmp (buf_ret, "W"))
1647 std::cout << "setup WireFrame display mode" << std::endl;
1648 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1649 if(Ctx->NbSelected()==0)
1650 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1652 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1653 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1654 Ctx->UpdateCurrentViewer();
1657 else if (!strcasecmp (buf_ret, ","))
1659 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1661 else if (!strcasecmp (buf_ret, "."))
1663 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1665 else if (!strcasecmp (buf_ret, "/"))
1667 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1668 if (aCamera->IsStereo())
1670 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1674 else if (!strcasecmp (buf_ret, "*"))
1676 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1677 if (aCamera->IsStereo())
1679 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1683 else if (*buf_ret == THE_KEY_DELETE)
1685 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1687 && aCtx->NbSelected() > 0)
1689 Draw_Interprete ("verase");
1692 else if (*buf_ret == THE_KEY_ESCAPE)
1694 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1696 && Draw_ToCloseViewOnEsc)
1698 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1704 Standard_Integer Num = Draw::Atoi(buf_ret);
1705 if(Num>=0 && Num<=7)
1706 ViewerTest::StandardModeActivation(Num);
1710 //==============================================================================
1711 //function : VT_ProcessExpose
1712 //purpose : Redraw the View on an Expose Event
1713 //==============================================================================
1714 void VT_ProcessExpose()
1716 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1717 if (!aView3d.IsNull())
1723 //==============================================================================
1724 //function : VT_ProcessConfigure
1725 //purpose : Resize the View on an Configure Event
1726 //==============================================================================
1727 void VT_ProcessConfigure()
1729 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1730 if (aView3d.IsNull())
1735 aView3d->MustBeResized();
1740 //==============================================================================
1741 //function : VT_ProcessButton1Press
1743 //==============================================================================
1744 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1745 const char** theArgVec,
1746 Standard_Boolean theToPick,
1747 Standard_Boolean theIsShift)
1751 TheIsAnimating = Standard_False;
1752 return Standard_False;
1757 Standard_Real X, Y, Z;
1758 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1760 Draw::Set (theArgVec[1], X);
1761 Draw::Set (theArgVec[2], Y);
1762 Draw::Set (theArgVec[3], Z);
1767 ViewerTest::CurrentEventManager()->ShiftSelect();
1771 ViewerTest::CurrentEventManager()->Select();
1774 return Standard_False;
1777 //==============================================================================
1778 //function : VT_ProcessButton1Release
1779 //purpose : End selecting
1780 //==============================================================================
1781 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1785 IsDragged = Standard_False;
1786 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1789 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1790 X_Motion, Y_Motion);
1794 EM->Select (X_ButtonPress, Y_ButtonPress,
1795 X_Motion, Y_Motion);
1800 //==============================================================================
1801 //function : VT_ProcessButton3Press
1802 //purpose : Start Rotation
1803 //==============================================================================
1804 void VT_ProcessButton3Press()
1807 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1808 if (HasHlrOnBeforeRotation)
1810 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1812 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1815 //==============================================================================
1816 //function : VT_ProcessButton3Release
1817 //purpose : End rotation
1818 //==============================================================================
1819 void VT_ProcessButton3Release()
1824 if (HasHlrOnBeforeRotation)
1826 HasHlrOnBeforeRotation = Standard_False;
1827 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1828 ViewerTest::CurrentView()->Redraw();
1833 //==============================================================================
1834 //function : ProcessControlButton1Motion
1836 //==============================================================================
1838 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1839 static void ProcessControlButton1Motion()
1841 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1843 X_ButtonPress = X_Motion;
1844 Y_ButtonPress = Y_Motion;
1848 //==============================================================================
1849 //function : VT_ProcessControlButton2Motion
1851 //==============================================================================
1852 void VT_ProcessControlButton2Motion()
1854 Standard_Integer aDx = X_Motion - X_ButtonPress;
1855 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1857 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1859 ViewerTest::CurrentView()->Pan (aDx, aDy);
1861 X_ButtonPress = X_Motion;
1862 Y_ButtonPress = Y_Motion;
1865 //==============================================================================
1866 //function : VT_ProcessControlButton3Motion
1867 //purpose : Rotation
1868 //==============================================================================
1869 void VT_ProcessControlButton3Motion()
1873 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1877 //==============================================================================
1878 //function : VT_ProcessMotion
1880 //==============================================================================
1881 void VT_ProcessMotion()
1883 //pre-hilights detected objects at mouse position
1885 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1886 EM->MoveTo(X_Motion, Y_Motion);
1890 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1892 Xpix = X_Motion;Ypix=Y_Motion;
1895 //==============================================================================
1896 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1897 //purpose : Switches to an axonometric, top, left and other views
1898 //==============================================================================
1900 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1902 if ( ViewerTest::CurrentView().IsNull() )
1904 di<<"Call vinit before this command, please\n";
1908 ViewerTest::CurrentView()->SetProj(ori);
1912 //==============================================================================
1914 //purpose : Switch to an Axonometric view
1915 //Draw arg : No args
1916 //==============================================================================
1918 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1920 return ViewProject(di, V3d_XposYnegZpos);
1923 //==============================================================================
1925 //purpose : Switch to a Top View
1926 //Draw arg : No args
1927 //==============================================================================
1929 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1931 return ViewProject(di, V3d_Zpos);
1934 //==============================================================================
1935 //function : VBottom
1936 //purpose : Switch to a Bottom View
1937 //Draw arg : No args
1938 //==============================================================================
1940 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1942 return ViewProject(di, V3d_Zneg);
1945 //==============================================================================
1947 //purpose : Switch to a Left View
1948 //Draw arg : No args
1949 //==============================================================================
1951 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1953 return ViewProject(di, V3d_Xneg);
1956 //==============================================================================
1958 //purpose : Switch to a Right View
1959 //Draw arg : No args
1960 //==============================================================================
1962 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1964 return ViewProject(di, V3d_Xpos);
1967 //==============================================================================
1969 //purpose : Switch to a Front View
1970 //Draw arg : No args
1971 //==============================================================================
1973 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1975 return ViewProject(di, V3d_Yneg);
1978 //==============================================================================
1980 //purpose : Switch to a Back View
1981 //Draw arg : No args
1982 //==============================================================================
1984 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1986 return ViewProject(di, V3d_Ypos);
1989 //==============================================================================
1991 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1992 //Draw arg : No args
1993 //==============================================================================
1995 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1998 di << "Q : Quit the application\n";
2000 di << "=========================\n";
2001 di << "F : FitAll\n";
2002 di << "T : TopView\n";
2003 di << "B : BottomView\n";
2004 di << "R : RightView\n";
2005 di << "L : LeftView\n";
2006 di << "A : AxonometricView\n";
2007 di << "D : ResetView\n";
2009 di << "=========================\n";
2010 di << "S : Shading\n";
2011 di << "W : Wireframe\n";
2012 di << "H : HidelLineRemoval\n";
2013 di << "U : Unset display mode\n";
2014 di << "Delete : Remove selection from viewer\n";
2016 di << "=========================\n";
2017 di << "Selection mode \n";
2018 di << "0 : Shape\n";
2019 di << "1 : Vertex\n";
2023 di << "5 : Shell\n";
2024 di << "6 : Solid\n";
2025 di << "7 : Compound\n";
2027 di << "=========================\n";
2028 di << "Z : Switch Z clipping On/Off\n";
2029 di << ", : Hilight next detected\n";
2030 di << ". : Hilight previous detected\n";
2037 static Standard_Boolean Ppick = 0;
2038 static Standard_Integer Pargc = 0;
2039 static const char** Pargv = NULL;
2042 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2047 if (!ViewerTest_myViews.IsEmpty()) {
2049 WPARAM fwKeys = wParam;
2054 // Delete view from map of views
2055 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2060 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2061 || ViewerTest::CurrentView().IsNull())
2063 // Activate inactive window
2064 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2066 ActivateView (FindViewIdByWindowHandle(hwnd));
2072 if (IsDragged && !DragFirst)
2074 if (!GetActiveAISManipulator().IsNull())
2076 GetActiveAISManipulator()->StopTransform();
2077 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2080 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2082 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2083 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2086 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
2088 IsDragged = Standard_False;
2089 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2092 if (IsDragged && !DragFirst)
2094 if (!GetActiveAISManipulator().IsNull())
2096 GetActiveAISManipulator()->StopTransform (Standard_False);
2097 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2099 IsDragged = Standard_False;
2101 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2103 case WM_LBUTTONDOWN:
2104 if (!GetActiveAISManipulator().IsNull())
2106 IsDragged = ( fwKeys == MK_LBUTTON );
2110 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2115 DragFirst = Standard_True;
2116 X_ButtonPress = LOWORD(lParam);
2117 Y_ButtonPress = HIWORD(lParam);
2119 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2124 X_Motion = LOWORD (lParam);
2125 Y_Motion = HIWORD (lParam);
2126 if (!GetActiveAISManipulator().IsNull())
2130 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2134 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2135 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2140 bool toRedraw = false;
2141 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2143 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2148 if (GetClientRect (hwnd, &aRect))
2150 int aHeight = aRect.bottom - aRect.top;
2151 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2152 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2157 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2161 DragFirst = Standard_False;
2164 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2168 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2172 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2176 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2182 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2185 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2192 BeginPaint(hwnd, &ps);
2193 EndPaint(hwnd, &ps);
2198 VT_ProcessConfigure();
2203 switch (aView->RenderingParams().StereoMode)
2205 case Graphic3d_StereoMode_RowInterlaced:
2206 case Graphic3d_StereoMode_ColumnInterlaced:
2207 case Graphic3d_StereoMode_ChessBoard:
2208 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2216 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2219 c[0] = (char) wParam;
2221 if (wParam == VK_DELETE)
2223 c[0] = THE_KEY_DELETE;
2225 else if (wParam == VK_ESCAPE)
2227 c[0] = THE_KEY_ESCAPE;
2230 else if (wParam == VK_OEM_COMMA)
2235 else if (wParam == VK_OEM_PERIOD)
2239 else if (wParam == VK_DIVIDE)
2244 else if (wParam == VK_MULTIPLY)
2248 VT_ProcessKeyPress (c);
2256 VT_ProcessButton3Release();
2259 case WM_LBUTTONDOWN:
2260 case WM_MBUTTONDOWN:
2261 case WM_RBUTTONDOWN:
2263 WPARAM fwKeys = wParam;
2267 X_ButtonPress = LOWORD(lParam);
2268 Y_ButtonPress = HIWORD(lParam);
2270 if (Msg == WM_LBUTTONDOWN)
2272 if ((fwKeys & MK_CONTROL) != 0)
2274 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2278 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2281 else if (Msg == WM_RBUTTONDOWN)
2284 VT_ProcessButton3Press();
2291 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2292 if (wParam & MK_CONTROL)
2294 if (aView->Camera()->IsStereo())
2296 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2300 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2307 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2314 //cout << "\t WM_MOUSEMOVE" << endl;
2315 WPARAM fwKeys = wParam;
2316 X_Motion = LOWORD(lParam);
2317 Y_Motion = HIWORD(lParam);
2320 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2323 X_ButtonPress = LOWORD(lParam);
2324 Y_ButtonPress = HIWORD(lParam);
2326 if ((fwKeys & MK_RBUTTON) != 0) {
2328 VT_ProcessButton3Press();
2332 if ((fwKeys & MK_CONTROL) != 0)
2334 if ((fwKeys & MK_LBUTTON) != 0)
2336 ProcessControlButton1Motion();
2338 else if ((fwKeys & MK_MBUTTON) != 0
2339 || ((fwKeys & MK_LBUTTON) != 0
2340 && (fwKeys & MK_RBUTTON) != 0))
2342 VT_ProcessControlButton2Motion();
2344 else if ((fwKeys & MK_RBUTTON) != 0)
2346 VT_ProcessControlButton3Motion();
2349 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2357 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2362 //==============================================================================
2363 //function : ViewerMainLoop
2364 //purpose : Get a Event on the view and dispatch it
2365 //==============================================================================
2368 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2370 Ppick = (argc > 0)? 1 : 0;
2378 cout << "Start picking" << endl;
2380 while ( Ppick == 1 ) {
2381 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2382 if (GetMessageW (&msg, NULL, 0, 0))
2384 TranslateMessage (&msg);
2385 DispatchMessageW (&msg);
2389 cout << "Picking done" << endl;
2395 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2397 int min( int a, int b )
2405 int max( int a, int b )
2413 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2416 static XEvent aReport;
2417 Standard_Boolean pick = argc > 0;
2418 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2419 XNextEvent (aDisplay, &aReport);
2421 // Handle event for the chosen display connection
2422 switch (aReport.type) {
2425 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2428 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2434 // Activate inactive view
2435 Window aWindow = GetWindowHandle(VT_GetWindow());
2436 if(aWindow != aReport.xfocus.window)
2438 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2447 case ConfigureNotify:
2449 VT_ProcessConfigure();
2458 XComposeStatus status_in_out;
2460 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2461 (char *) buf_ret , 10 ,
2462 &ks_ret , &status_in_out ) ;
2465 buf_ret[ret_len] = '\0' ;
2469 VT_ProcessKeyPress (buf_ret);
2475 X_ButtonPress = aReport.xbutton.x;
2476 Y_ButtonPress = aReport.xbutton.y;
2478 if (aReport.xbutton.button == Button1)
2480 if (aReport.xbutton.state & ControlMask)
2482 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2486 IsDragged = Standard_True;
2487 DragFirst = Standard_True;
2490 else if (aReport.xbutton.button == Button3)
2493 VT_ProcessButton3Press();
2503 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2505 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2506 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2510 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2511 if( aContext.IsNull() )
2513 cout << "The context is null. Please use vinit before createmesh" << endl;
2517 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2518 if( aReport.xbutton.button==1 )
2522 aContext->ShiftSelect (Standard_True);
2526 aContext->Select (Standard_True);
2531 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2532 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2533 ViewerTest::CurrentView(), Standard_True);
2537 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2538 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2539 ViewerTest::CurrentView(), Standard_True);
2542 VT_ProcessButton3Release();
2544 IsDragged = Standard_False;
2547 VT_ProcessButton3Release();
2552 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2560 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2562 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2566 X_Motion = aReport.xmotion.x;
2567 Y_Motion = aReport.xmotion.y;
2568 DragFirst = Standard_False;
2570 Window aWindow = GetWindowHandle(VT_GetWindow());
2573 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2574 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2575 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2576 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2577 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2581 X_Motion = aReport.xmotion.x;
2582 Y_Motion = aReport.xmotion.y;
2584 // remove all the ButtonMotionMaskr
2585 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2587 if ( aReport.xmotion.state & ControlMask ) {
2588 if ( aReport.xmotion.state & Button1Mask ) {
2589 ProcessControlButton1Motion();
2591 else if ( aReport.xmotion.state & Button2Mask ) {
2592 VT_ProcessControlButton2Motion();
2594 else if ( aReport.xmotion.state & Button3Mask ) {
2595 VT_ProcessControlButton3Motion();
2609 //==============================================================================
2610 //function : VProcessEvents
2611 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2612 // event in the Viewer window
2613 //==============================================================================
2615 static void VProcessEvents(ClientData,int)
2617 NCollection_Vector<int> anEventNumbers;
2618 // Get number of messages from every display
2619 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2620 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2622 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2624 // Handle events for every display
2625 int anEventIter = 0;
2626 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2627 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2629 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2630 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2632 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2633 int anEventResult = ViewerMainLoop( 0, NULL);
2634 // If window is closed or context was not found finish current event processing loop
2640 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2645 //==============================================================================
2646 //function : OSWindowSetup
2647 //purpose : Setup for the X11 window to be able to cath the event
2648 //==============================================================================
2651 static void OSWindowSetup()
2653 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2656 Window window = VT_GetWindow()->XWindow();
2657 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2658 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2659 XSynchronize(aDisplay, 1);
2661 // X11 : For keyboard on SUN
2663 wmhints.flags = InputHint;
2666 XSetWMHints( aDisplay, window, &wmhints);
2668 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2669 ButtonPressMask | ButtonReleaseMask |
2670 StructureNotifyMask |
2672 Button1MotionMask | Button2MotionMask |
2673 Button3MotionMask | FocusChangeMask
2675 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2676 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2678 XSynchronize(aDisplay, 0);
2686 //==============================================================================
2689 //==============================================================================
2691 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
2693 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2696 std::cout << "Error: no active viewer!\n";
2700 Standard_Boolean toFit = Standard_True;
2701 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2702 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2704 TCollection_AsciiString anArg (theArgv[anArgIter]);
2706 if (anUpdateTool.parseRedrawMode (anArg))
2710 else if (anArg == "-selected")
2712 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2713 toFit = Standard_False;
2717 std::cout << "Syntax error at '" << anArg << "'\n";
2723 aView->FitAll (0.01, Standard_False);
2728 //=======================================================================
2729 //function : VFitArea
2730 //purpose : Fit view to show area located between two points
2731 // : given in world 2D or 3D coordinates.
2732 //=======================================================================
2733 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2735 Handle(V3d_View) aView = ViewerTest::CurrentView();
2738 std::cerr << theArgVec[0] << "Error: No active view.\n";
2743 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2744 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2748 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2749 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2750 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2751 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2753 else if (theArgNb == 7)
2755 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2756 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2757 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2758 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2759 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2760 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2764 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2765 theDI.PrintHelp(theArgVec[0]);
2769 // Convert model coordinates to view space
2770 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2771 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2772 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2774 // Determine fit area
2775 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2776 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2778 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2780 if (aDiagonal < Precision::Confusion())
2782 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2786 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2790 //==============================================================================
2792 //purpose : ZFitall, no DRAW arguments
2793 //Draw arg : No args
2794 //==============================================================================
2795 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2797 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2799 if (aCurrentView.IsNull())
2801 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2807 aCurrentView->ZFitAll();
2808 aCurrentView->Redraw();
2812 Standard_Real aScale = 1.0;
2816 aScale = Draw::Atoi (theArgVec[1]);
2819 aCurrentView->ZFitAll (aScale);
2820 aCurrentView->Redraw();
2825 //==============================================================================
2826 //function : VRepaint
2828 //==============================================================================
2829 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
2831 Handle(V3d_View) aView = ViewerTest::CurrentView();
2834 std::cout << "Error: no active viewer!\n";
2838 Standard_Boolean isImmediateUpdate = Standard_False;
2839 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2841 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2843 if (anArg == "-immediate")
2845 isImmediateUpdate = Standard_True;
2846 if (anArgIter + 1 < theArgNb
2847 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2854 std::cout << "Syntax error at '" << anArg << "'\n";
2858 if (isImmediateUpdate)
2860 aView->RedrawImmediate();
2869 //==============================================================================
2871 //purpose : Remove all the object from the viewer
2872 //Draw arg : No args
2873 //==============================================================================
2875 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2877 Handle(V3d_View) V = ViewerTest::CurrentView();
2879 ViewerTest::Clear();
2883 //==============================================================================
2886 //==============================================================================
2888 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2889 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2892 di << argv[0] << "Invalid number of arguments\n";
2896 while (ViewerMainLoop( argc, argv)) {
2902 //==============================================================================
2904 //purpose : Load image as background
2905 //==============================================================================
2907 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2909 if (argc < 2 || argc > 3)
2911 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
2912 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
2916 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2917 if(AISContext.IsNull())
2919 di << "use 'vinit' command before " << argv[0] << "\n";
2923 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2926 const char* szType = argv[2];
2927 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2928 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2929 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2930 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2933 di << "Wrong fill type : " << szType << "\n";
2934 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2939 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2940 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2945 //==============================================================================
2946 //function : VSetBgMode
2947 //purpose : Change background image fill type
2948 //==============================================================================
2950 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2954 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
2955 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
2959 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2960 if(AISContext.IsNull())
2962 di << "use 'vinit' command before " << argv[0] << "\n";
2965 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2966 const char* szType = argv[1];
2967 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2968 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2969 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2970 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2973 di << "Wrong fill type : " << szType << "\n";
2974 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2977 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2978 V3dView->SetBgImageStyle(aFillType, Standard_True);
2982 //==============================================================================
2983 //function : VSetGradientBg
2984 //purpose : Mount gradient background
2985 //==============================================================================
2986 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2990 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
2991 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
2992 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2993 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2997 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2998 if(AISContext.IsNull())
3000 di << "use 'vinit' command before " << argv[0] << "\n";
3006 Standard_Real R1 = Draw::Atof(argv[1])/255.;
3007 Standard_Real G1 = Draw::Atof(argv[2])/255.;
3008 Standard_Real B1 = Draw::Atof(argv[3])/255.;
3009 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
3011 Standard_Real R2 = Draw::Atof(argv[4])/255.;
3012 Standard_Real G2 = Draw::Atof(argv[5])/255.;
3013 Standard_Real B2 = Draw::Atof(argv[6])/255.;
3015 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
3016 int aType = Draw::Atoi(argv[7]);
3017 if( aType < 0 || aType > 8 )
3019 di << "Wrong fill type \n";
3020 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3021 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3025 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3027 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3028 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
3034 //==============================================================================
3035 //function : VSetGradientBgMode
3036 //purpose : Change gradient background fill style
3037 //==============================================================================
3038 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3042 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
3043 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3044 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3048 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3049 if(AISContext.IsNull())
3051 di << "use 'vinit' command before " << argv[0] << "\n";
3056 int aType = Draw::Atoi(argv[1]);
3057 if( aType < 0 || aType > 8 )
3059 di << "Wrong fill type \n";
3060 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3061 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3065 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3067 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3068 V3dView->SetBgGradientStyle( aMethod, 1 );
3074 //==============================================================================
3075 //function : VSetColorBg
3076 //purpose : Set color background
3077 //==============================================================================
3078 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3082 di << "Usage : " << argv[0] << " R G B : Set color background\n";
3083 di << "R,G,B = [0..255]\n";
3087 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3088 if(AISContext.IsNull())
3090 di << "use 'vinit' command before " << argv[0] << "\n";
3096 Standard_Real R = Draw::Atof(argv[1])/255.;
3097 Standard_Real G = Draw::Atof(argv[2])/255.;
3098 Standard_Real B = Draw::Atof(argv[3])/255.;
3099 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
3101 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3102 V3dView->SetBackgroundColor( aColor );
3109 //==============================================================================
3110 //function : VSetDefaultBg
3111 //purpose : Set default viewer background fill color
3112 //==============================================================================
3113 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3118 std::cout << "Error: wrong syntax! See usage:\n";
3119 theDI.PrintHelp (theArgVec[0]);
3123 ViewerTest_DefaultBackground.FillMethod =
3124 theArgNb == 4 ? Aspect_GFM_NONE
3125 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
3129 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
3130 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
3131 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
3132 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
3136 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
3137 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
3138 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
3139 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
3141 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
3142 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
3143 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
3144 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
3147 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
3148 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
3150 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
3151 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
3152 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
3153 ViewerTest_DefaultBackground.GradientColor2,
3154 ViewerTest_DefaultBackground.FillMethod);
3160 //==============================================================================
3162 //purpose : View Scaling
3163 //==============================================================================
3165 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3167 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3168 if ( V3dView.IsNull() ) return 1;
3171 di << argv[0] << "Invalid number of arguments\n";
3174 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
3177 //==============================================================================
3178 //function : VZBuffTrihedron
3180 //==============================================================================
3182 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3183 Standard_Integer theArgNb,
3184 const char** theArgVec)
3186 Handle(V3d_View) aView = ViewerTest::CurrentView();
3189 std::cout << "Error: no active viewer!\n";
3193 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
3195 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3196 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3197 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3198 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3199 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3200 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3201 Standard_Real aScale = 0.1;
3202 Standard_Real aSizeRatio = 0.8;
3203 Standard_Real anArrowDiam = 0.05;
3204 Standard_Integer aNbFacets = 12;
3205 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3207 Standard_CString anArg = theArgVec[anArgIter];
3208 TCollection_AsciiString aFlag (anArg);
3210 if (anUpdateTool.parseRedrawMode (aFlag))
3214 else if (aFlag == "-on")
3218 else if (aFlag == "-off")
3220 aView->TriedronErase();
3223 else if (aFlag == "-pos"
3224 || aFlag == "-position"
3225 || aFlag == "-corner")
3227 if (++anArgIter >= theArgNb)
3229 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3233 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3234 aPosName.LowerCase();
3235 if (aPosName == "center")
3237 aPosition = Aspect_TOTP_CENTER;
3239 else if (aPosName == "left_lower"
3240 || aPosName == "lower_left"
3241 || aPosName == "leftlower"
3242 || aPosName == "lowerleft")
3244 aPosition = Aspect_TOTP_LEFT_LOWER;
3246 else if (aPosName == "left_upper"
3247 || aPosName == "upper_left"
3248 || aPosName == "leftupper"
3249 || aPosName == "upperleft")
3251 aPosition = Aspect_TOTP_LEFT_UPPER;
3253 else if (aPosName == "right_lower"
3254 || aPosName == "lower_right"
3255 || aPosName == "rightlower"
3256 || aPosName == "lowerright")
3258 aPosition = Aspect_TOTP_RIGHT_LOWER;
3260 else if (aPosName == "right_upper"
3261 || aPosName == "upper_right"
3262 || aPosName == "rightupper"
3263 || aPosName == "upperright")
3265 aPosition = Aspect_TOTP_RIGHT_UPPER;
3269 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3273 else if (aFlag == "-type")
3275 if (++anArgIter >= theArgNb)
3277 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3281 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3282 aTypeName.LowerCase();
3283 if (aTypeName == "wireframe"
3284 || aTypeName == "wire")
3286 aVisType = V3d_WIREFRAME;
3288 else if (aTypeName == "zbuffer"
3289 || aTypeName == "shaded")
3291 aVisType = V3d_ZBUFFER;
3295 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3298 else if (aFlag == "-scale")
3300 if (++anArgIter >= theArgNb)
3302 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3306 aScale = Draw::Atof (theArgVec[anArgIter]);
3308 else if (aFlag == "-size"
3309 || aFlag == "-sizeratio")
3311 if (++anArgIter >= theArgNb)
3313 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3317 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3319 else if (aFlag == "-arrowdiam"
3320 || aFlag == "-arrowdiameter")
3322 if (++anArgIter >= theArgNb)
3324 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3328 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3330 else if (aFlag == "-nbfacets")
3332 if (++anArgIter >= theArgNb)
3334 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3338 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3340 else if (aFlag == "-colorlabel"
3341 || aFlag == "-colorlabels")
3343 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3344 theArgVec + anArgIter + 1,
3348 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3351 anArgIter += aNbParsed;
3353 else if (aFlag == "-colorarrowx")
3355 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3356 theArgVec + anArgIter + 1,
3360 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3363 anArgIter += aNbParsed;
3365 else if (aFlag == "-colorarrowy")
3367 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3368 theArgVec + anArgIter + 1,
3372 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3375 anArgIter += aNbParsed;
3377 else if (aFlag == "-colorarrowz")
3379 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3380 theArgVec + anArgIter + 1,
3384 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3387 anArgIter += aNbParsed;
3391 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3396 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3397 aSizeRatio, anArrowDiam, aNbFacets);
3398 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3403 //==============================================================================
3404 //function : VRotate
3405 //purpose : Camera Rotating
3406 //==============================================================================
3408 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3410 Handle(V3d_View) aView = ViewerTest::CurrentView();
3413 std::cout << "No active view!\n";
3417 Standard_Boolean hasFlags = Standard_False;
3418 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3420 Standard_CString anArg (theArgVec[anArgIter]);
3421 TCollection_AsciiString aFlag (anArg);
3423 if (aFlag == "-mousestart"
3424 || aFlag == "-mousefrom")
3426 hasFlags = Standard_True;
3427 if (anArgIter + 2 >= theArgNb)
3429 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3433 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3434 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3435 aView->StartRotation (anX, anY);
3437 else if (aFlag == "-mousemove")
3439 hasFlags = Standard_True;
3440 if (anArgIter + 2 >= theArgNb)
3442 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3446 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3447 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3448 aView->Rotation (anX, anY);
3450 else if (theArgNb != 4
3453 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3462 else if (theArgNb == 4)
3464 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3465 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3466 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3467 aView->Rotate (anAX, anAY, anAZ);
3470 else if (theArgNb == 7)
3472 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3473 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3474 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3476 Standard_Real anX = Draw::Atof (theArgVec[4]);
3477 Standard_Real anY = Draw::Atof (theArgVec[5]);
3478 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3480 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3484 std::cout << "Error: Invalid number of arguments\n";
3488 //==============================================================================
3490 //purpose : View zoom in / out (relative to current zoom)
3491 //====================================