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_CameraFrustum.hxx>
23 #include <AIS_ColorScale.hxx>
24 #include <AIS_Manipulator.hxx>
25 #include <AIS_RubberBand.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_InteractiveObject.hxx>
28 #include <AIS_ListOfInteractive.hxx>
29 #include <AIS_ListIteratorOfListOfInteractive.hxx>
30 #include <Aspect_Grid.hxx>
32 #include <Draw_ProgressIndicator.hxx>
33 #include <Graphic3d_ArrayOfPolylines.hxx>
34 #include <Graphic3d_AspectMarker3d.hxx>
35 #include <Graphic3d_NameOfTextureEnv.hxx>
36 #include <Graphic3d_GraduatedTrihedron.hxx>
37 #include <Graphic3d_TextureEnv.hxx>
38 #include <Graphic3d_TextureParams.hxx>
39 #include <Graphic3d_TypeOfTextureFilter.hxx>
40 #include <Graphic3d_AspectFillArea3d.hxx>
41 #include <ViewerTest.hxx>
42 #include <ViewerTest_AutoUpdater.hxx>
43 #include <ViewerTest_EventManager.hxx>
44 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
46 #include <ViewerTest_CmdParser.hxx>
47 #include <V3d_AmbientLight.hxx>
48 #include <V3d_DirectionalLight.hxx>
49 #include <V3d_PositionalLight.hxx>
50 #include <V3d_SpotLight.hxx>
51 #include <Message_ProgressSentry.hxx>
52 #include <NCollection_DoubleMap.hxx>
53 #include <NCollection_List.hxx>
54 #include <NCollection_Vector.hxx>
55 #include <AIS_InteractiveContext.hxx>
56 #include <Draw_Interpretor.hxx>
58 #include <Draw_Appli.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <Image_VideoRecorder.hxx>
61 #include <OpenGl_GraphicDriver.hxx>
62 #include <OSD_Timer.hxx>
63 #include <TColStd_HSequenceOfAsciiString.hxx>
64 #include <TColStd_SequenceOfInteger.hxx>
65 #include <TColStd_HSequenceOfReal.hxx>
66 #include <TColgp_Array1OfPnt2d.hxx>
67 #include <TColStd_MapOfAsciiString.hxx>
68 #include <Aspect_TypeOfLine.hxx>
69 #include <Image_Diff.hxx>
70 #include <Aspect_DisplayConnection.hxx>
74 #include <PrsMgr_PresentableObject.hxx>
75 #include <Graphic3d_ClipPlane.hxx>
76 #include <NCollection_DataMap.hxx>
77 #include <Graphic3d_Texture2Dmanual.hxx>
78 #include <Prs3d_ShadingAspect.hxx>
79 #include <Prs3d_Drawer.hxx>
80 #include <Prs3d_LineAspect.hxx>
81 #include <Prs3d_Root.hxx>
82 #include <Prs3d_Text.hxx>
83 #include <Select3D_SensitivePrimitiveArray.hxx>
92 #include <WNT_WClass.hxx>
93 #include <WNT_Window.hxx>
94 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
95 #include <Cocoa_Window.hxx>
97 #include <Xw_Window.hxx>
98 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
99 #include <X11/Xutil.h>
103 // Auxiliary definitions
104 static const char THE_KEY_DELETE = 127;
105 static const char THE_KEY_ESCAPE = 27;
107 //==============================================================================
108 // VIEWER GLOBAL VARIABLES
109 //==============================================================================
111 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
112 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
114 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
115 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
117 extern int VErase (Draw_Interpretor& theDI,
118 Standard_Integer theArgNb,
119 const char** theArgVec);
122 static Handle(WNT_Window)& VT_GetWindow() {
123 static Handle(WNT_Window) WNTWin;
126 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
127 static Handle(Cocoa_Window)& VT_GetWindow()
129 static Handle(Cocoa_Window) aWindow;
132 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
133 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
134 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
137 static Handle(Xw_Window)& VT_GetWindow(){
138 static Handle(Xw_Window) XWWin;
142 static void VProcessEvents(ClientData,int);
145 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
147 static Handle(Aspect_DisplayConnection) aDisplayConnection;
148 return aDisplayConnection;
151 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
153 GetDisplayConnection() = theDisplayConnection;
156 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
157 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
159 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
161 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
162 if (!aWindow.IsNull())
163 return aWindow->HWindow();
164 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
165 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
166 if (!aWindow.IsNull())
167 return aWindow->XWindow();
169 return aWindowHandle;
173 //! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events
174 class ViewerTest_V3dView : public V3d_View
176 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_V3dView, V3d_View)
178 //! Initializes the view.
179 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC,
180 bool theIs2dMode = false)
181 : V3d_View (theViewer, theType), myIs2dMode (theIs2dMode) {}
183 //! Initializes the view by copying.
184 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
185 : V3d_View (theViewer, theView), myIs2dMode (false)
187 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView))
189 myIs2dMode = aV3dView->IsViewIn2DMode();
193 //! Returns true if 2D mode is set for the view
194 bool IsViewIn2DMode() const { return myIs2dMode; }
196 //! Sets 2D mode for the view
197 void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; }
201 //! Returns true if active view in 2D mode.
202 static bool IsCurrentViewIn2DMode()
204 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
206 return aV3dView->IsViewIn2DMode();
211 //! Set if active view in 2D mode.
212 static void SetCurrentView2DMode (bool theIs2d)
214 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
216 aV3dView->SetView2DMode (theIs2d);
222 Standard_Boolean myIs2dMode; //!< 2D mode flag
226 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
227 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
228 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
229 static OpenGl_Caps ViewerTest_myDefaultCaps;
231 static void OSWindowSetup();
235 Quantity_Color FlatColor;
236 Quantity_Color GradientColor1;
237 Quantity_Color GradientColor2;
238 Aspect_GradientFillMethod FillMethod;
239 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
241 //==============================================================================
242 // EVENT GLOBAL VARIABLES
243 //==============================================================================
245 static int Start_Rot = 0;
246 Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
247 int X_Motion = 0; // Current cursor position
249 int X_ButtonPress = 0; // Last ButtonPress position
250 int Y_ButtonPress = 0;
251 Standard_Boolean IsDragged = Standard_False;
252 Standard_Boolean DragFirst = Standard_False;
253 Standard_Boolean TheIsAnimating = Standard_False;
254 Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
255 Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
258 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
260 static Handle(AIS_RubberBand) aBand;
263 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
264 aBand->SetDisplayMode (0);
269 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
271 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
273 static ViewerTest_MapOfAISManipulators aMap;
277 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
279 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
280 for (; anIt.More(); anIt.Next())
282 if (anIt.Value()->HasActiveMode())
290 //==============================================================================
293 static LRESULT WINAPI ViewerWindowProc(
298 static LRESULT WINAPI AdvViewerWindowProc(
306 //==============================================================================
309 //==============================================================================
311 const Handle(Standard_Transient)& ViewerTest::WClass()
313 static Handle(Standard_Transient) theWClass;
315 if (theWClass.IsNull())
317 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
318 CS_VREDRAW | CS_HREDRAW, 0, 0,
319 ::LoadCursor (NULL, IDC_ARROW));
325 //==============================================================================
326 //function : CreateName
327 //purpose : Create numerical name for new object in theMap
328 //==============================================================================
329 template <typename ObjectType>
330 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
331 const TCollection_AsciiString& theDefaultString)
333 if (theObjectMap.IsEmpty())
334 return theDefaultString + TCollection_AsciiString(1);
336 Standard_Integer aNextKey = 1;
337 Standard_Boolean isFound = Standard_False;
340 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
341 // Look for objects with default names
342 if (theObjectMap.IsBound1(aStringKey))
347 isFound = Standard_True;
350 return theDefaultString + TCollection_AsciiString(aNextKey);
353 //==============================================================================
354 //structure : ViewerTest_Names
355 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
356 //==============================================================================
357 struct ViewerTest_Names
360 TCollection_AsciiString myDriverName;
361 TCollection_AsciiString myViewerName;
362 TCollection_AsciiString myViewName;
366 const TCollection_AsciiString& GetDriverName () const
370 void SetDriverName (const TCollection_AsciiString& theDriverName)
372 myDriverName = theDriverName;
374 const TCollection_AsciiString& GetViewerName () const
378 void SetViewerName (const TCollection_AsciiString& theViewerName)
380 myViewerName = theViewerName;
382 const TCollection_AsciiString& GetViewName () const
386 void SetViewName (const TCollection_AsciiString& theViewName)
388 myViewName = theViewName;
391 //===========================================================================
392 //function : Constructor for ViewerTest_Names
393 //purpose : Get view, viewer, driver names from custom string
394 //===========================================================================
396 ViewerTest_Names (const TCollection_AsciiString& theInputString)
398 TCollection_AsciiString aName(theInputString);
399 if (theInputString.IsEmpty())
401 // Get current configuration
402 if (ViewerTest_myDrivers.IsEmpty())
403 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
404 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
406 myDriverName = ViewerTest_myDrivers.Find2
407 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
409 if(ViewerTest_myContexts.IsEmpty())
411 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
412 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
416 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
419 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
423 // There is at least view name
424 Standard_Integer aParserNumber = 0;
425 for (Standard_Integer i = 0; i < 3; ++i)
427 Standard_Integer aParserPos = aName.SearchFromEnd("/");
431 aName.Split(aParserPos-1);
436 if (aParserNumber == 0)
439 if (!ViewerTest::GetAISContext().IsNull())
441 myDriverName = ViewerTest_myDrivers.Find2
442 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
443 myViewerName = ViewerTest_myContexts.Find2
444 (ViewerTest::GetAISContext());
448 // There is no opened contexts here, need to create names for viewer and driver
449 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
450 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
452 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
453 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
455 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
457 else if (aParserNumber == 1)
459 // Here is viewerName/viewName
460 if (!ViewerTest::GetAISContext().IsNull())
461 myDriverName = ViewerTest_myDrivers.Find2
462 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
465 // There is no opened contexts here, need to create name for driver
466 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
467 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
469 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
471 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
475 //Here is driverName/viewerName/viewName
476 myDriverName = TCollection_AsciiString(aName);
478 TCollection_AsciiString aViewerName(theInputString);
479 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
480 myViewerName = TCollection_AsciiString(aViewerName);
482 myViewName = TCollection_AsciiString(theInputString);
488 //==============================================================================
489 //function : FindContextByView
490 //purpose : Find AIS_InteractiveContext by View
491 //==============================================================================
493 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
495 Handle(AIS_InteractiveContext) anAISContext;
497 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
498 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
500 if (anIter.Value()->CurrentViewer() == theView->Viewer())
501 return anIter.Key2();
507 //==============================================================================
508 //function : SetWindowTitle
509 //purpose : Set window title
510 //==============================================================================
512 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
513 Standard_CString theTitle)
516 const TCollection_ExtendedString theTitleW (theTitle);
517 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
518 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
519 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
521 if(GetDisplayConnection()->GetDisplay())
524 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
525 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
530 //==============================================================================
531 //function : IsWindowOverlapped
532 //purpose : Check if theWindow overlapp another view
533 //==============================================================================
535 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
536 const Standard_Integer thePxTop,
537 const Standard_Integer thePxRight,
538 const Standard_Integer thePxBottom,
539 TCollection_AsciiString& theViewId)
541 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
542 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
544 Standard_Integer aTop = 0,
548 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
549 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
550 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
551 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
552 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
554 theViewId = anIter.Key1();
555 return Standard_True;
558 return Standard_False;
561 // Workaround: to create and delete non-orthographic views outside ViewerTest
562 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
564 ViewerTest_myViews.UnBind1 (theName);
567 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
568 const Handle(V3d_View)& theView)
570 ViewerTest_myViews.Bind (theName, theView);
573 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
575 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
577 //==============================================================================
578 //function : ViewerInit
579 //purpose : Create the window viewer and initialize all the global variable
580 //==============================================================================
582 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
583 const Standard_Integer thePxTop,
584 const Standard_Integer thePxWidth,
585 const Standard_Integer thePxHeight,
586 const TCollection_AsciiString& theViewName,
587 const TCollection_AsciiString& theDisplayName,
588 const Handle(V3d_View)& theViewToClone)
590 // Default position and dimension of the viewer window.
591 // Note that left top corner is set to be sufficiently small to have
592 // window fit in the small screens (actual for remote desktops, see #23003).
593 // The position corresponds to the window's client area, thus some
594 // gap is added for window frame to be visible.
595 Standard_Integer aPxLeft = 20;
596 Standard_Integer aPxTop = 40;
597 Standard_Integer aPxWidth = 409;
598 Standard_Integer aPxHeight = 409;
599 Standard_Boolean toCreateViewer = Standard_False;
600 if (!theViewToClone.IsNull())
602 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
605 Handle(OpenGl_GraphicDriver) aGraphicDriver;
606 ViewerTest_Names aViewNames(theViewName);
607 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
608 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
615 aPxWidth = thePxWidth;
616 if (thePxHeight != 0)
617 aPxHeight = thePxHeight;
619 // Get graphic driver (create it or get from another view)
620 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
622 // Get connection string
623 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
624 TCollection_AsciiString aDisplayName(theDisplayName);
625 if (!aDisplayName.IsEmpty())
626 SetDisplayConnection (new Aspect_DisplayConnection ());
628 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
630 (void)theDisplayName; // avoid warning on unused argument
631 SetDisplayConnection (new Aspect_DisplayConnection ());
634 if (Draw_VirtualWindows)
636 // don't waste the time waiting for VSync when window is not displayed on the screen
637 ViewerTest_myDefaultCaps.swapInterval = 0;
638 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
639 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
641 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
642 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
644 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
645 toCreateViewer = Standard_True;
649 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
652 //Dispose the window if input parameters are default
653 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
655 Standard_Integer aTop = 0,
662 // Get screen resolution
663 #if defined(_WIN32) || defined(__WIN32__)
665 GetClientRect(GetDesktopWindow(), &aWindowSize);
666 aScreenHeight = aWindowSize.bottom;
667 aScreenWidth = aWindowSize.right;
668 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
669 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
671 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
672 aScreenWidth = WidthOfScreen(aScreen);
673 aScreenHeight = HeightOfScreen(aScreen);
676 TCollection_AsciiString anOverlappedViewId("");
678 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
680 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
682 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
683 && aRight + 2*aPxWidth + 40 > aScreenWidth)
685 if (aBottom + aPxHeight + 40 > aScreenHeight)
692 aPxTop = aBottom + 40;
695 aPxLeft = aRight + 20;
700 TCollection_AsciiString aTitle("3D View - ");
701 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
703 // Change name of current active window
704 if (!ViewerTest::CurrentView().IsNull())
706 TCollection_AsciiString anActiveWindowTitle("3D View - ");
707 anActiveWindowTitle = anActiveWindowTitle
708 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
709 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
713 Handle(V3d_Viewer) a3DViewer;
714 // If it's the single view, we first look for empty context
715 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
717 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
718 anIter(ViewerTest_myContexts);
720 ViewerTest::SetAISContext (anIter.Value());
721 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
723 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
725 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
726 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
728 else if (a3DViewer.IsNull())
730 toCreateViewer = Standard_True;
731 a3DViewer = new V3d_Viewer(aGraphicDriver);
732 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
733 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
734 ViewerTest_DefaultBackground.GradientColor2,
735 ViewerTest_DefaultBackground.FillMethod);
739 if (ViewerTest::GetAISContext().IsNull() ||
740 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
742 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
743 ViewerTest::SetAISContext (aContext);
744 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
748 ViewerTest::ResetEventManager();
753 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
754 Handle(WNT_WClass)::DownCast (WClass()),
755 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
759 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
760 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
762 aPxWidth, aPxHeight);
763 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
765 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
768 aPxWidth, aPxHeight);
770 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
773 Handle(V3d_View) aView;
774 if (!theViewToClone.IsNull())
776 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
780 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
783 aView->SetWindow (VT_GetWindow());
784 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
786 ViewerTest::CurrentView(aView);
787 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
789 // Setup for X11 or NT
792 // Set parameters for V3d_View and V3d_Viewer
793 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
794 aV3dView->SetComputedMode(Standard_False);
796 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
799 a3DViewer->SetDefaultLights();
800 a3DViewer->SetLightOn();
803 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
804 #if TCL_MAJOR_VERSION < 8
805 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
806 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
808 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
809 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
813 VT_GetWindow()->Map();
815 // Set the handle of created view in the event manager
816 ViewerTest::ResetEventManager();
818 ViewerTest::CurrentView()->Redraw();
823 return aViewNames.GetViewName();
826 //==============================================================================
827 //function : RedrawAllViews
828 //purpose : Redraw all created views
829 //==============================================================================
830 void ViewerTest::RedrawAllViews()
832 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
833 for (; aViewIt.More(); aViewIt.Next())
835 const Handle(V3d_View)& aView = aViewIt.Key2();
840 //==============================================================================
842 //purpose : Create the window viewer and initialize all the global variable
843 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
844 //==============================================================================
846 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
848 TCollection_AsciiString aViewName, aDisplayName;
849 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
850 Handle(V3d_View) aCopyFrom;
851 TCollection_AsciiString aName, aValue;
853 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
855 const TCollection_AsciiString anArg = theArgVec[anArgIt];
856 TCollection_AsciiString anArgCase = anArg;
857 anArgCase.LowerCase();
858 if (anArgIt + 1 < theArgsNb
859 && anArgCase == "-name")
861 aViewName = theArgVec[++anArgIt];
863 else if (anArgIt + 1 < theArgsNb
864 && (anArgCase == "-left"
865 || anArgCase == "-l"))
867 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
869 else if (anArgIt + 1 < theArgsNb
870 && (anArgCase == "-top"
871 || anArgCase == "-t"))
873 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
875 else if (anArgIt + 1 < theArgsNb
876 && (anArgCase == "-width"
877 || anArgCase == "-w"))
879 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
881 else if (anArgIt + 1 < theArgsNb
882 && (anArgCase == "-height"
883 || anArgCase == "-h"))
885 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
887 else if (anArgCase == "-exitonclose")
889 Draw_ToExitOnCloseView = true;
890 if (anArgIt + 1 < theArgsNb
891 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
896 else if (anArgCase == "-closeonescape"
897 || anArgCase == "-closeonesc")
899 Draw_ToCloseViewOnEsc = true;
900 if (anArgIt + 1 < theArgsNb
901 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
906 else if (anArgCase == "-2d_mode"
907 || anArgCase == "-2dmode"
908 || anArgCase == "-2d")
910 bool toEnable = true;
911 if (anArgIt + 1 < theArgsNb
912 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
916 is2dMode = toEnable ? 1 : 0;
918 else if (anArgIt + 1 < theArgsNb
919 && (anArgCase == "-disp"
920 || anArgCase == "-display"))
922 aDisplayName = theArgVec[++anArgIt];
924 else if (!ViewerTest::CurrentView().IsNull()
925 && aCopyFrom.IsNull()
926 && (anArgCase == "-copy"
927 || anArgCase == "-clone"
928 || anArgCase == "-cloneactive"
929 || anArgCase == "-cloneactiveview"))
931 aCopyFrom = ViewerTest::CurrentView();
934 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
941 else if (aName == "l"
944 aPxLeft = aValue.IntegerValue();
946 else if (aName == "t"
949 aPxTop = aValue.IntegerValue();
951 else if (aName == "disp"
952 || aName == "display")
954 aDisplayName = aValue;
956 else if (aName == "w"
959 aPxWidth = aValue.IntegerValue();
961 else if (aName == "h"
962 || aName == "height")
964 aPxHeight = aValue.IntegerValue();
968 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
972 else if (aViewName.IsEmpty())
978 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
983 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
984 if (!aDisplayName.IsEmpty())
986 aDisplayName.Clear();
987 std::cout << "Warning: display parameter will be ignored.\n";
991 ViewerTest_Names aViewNames (aViewName);
992 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
994 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
995 theDi.Eval (aCommand.ToCString());
998 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1003 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
1004 aViewName, aDisplayName, aCopyFrom);
1007 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1013 //! Parse HLR algo type.
1014 static Standard_Boolean parseHlrAlgoType (const char* theName,
1015 Prs3d_TypeOfHLR& theType)
1017 TCollection_AsciiString aName (theName);
1019 if (aName == "polyalgo")
1021 theType = Prs3d_TOH_PolyAlgo;
1023 else if (aName == "algo")
1025 theType = Prs3d_TOH_Algo;
1029 return Standard_False;
1031 return Standard_True;
1034 //==============================================================================
1036 //purpose : hidden lines removal algorithm
1037 //==============================================================================
1039 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1041 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1042 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1045 std::cerr << "Error: No opened viewer!\n";
1049 Standard_Boolean hasHlrOnArg = Standard_False;
1050 Standard_Boolean hasShowHiddenArg = Standard_False;
1051 Standard_Boolean isHLROn = Standard_False;
1052 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
1053 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1054 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1055 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1057 TCollection_AsciiString anArg (argv[anArgIter]);
1059 if (anUpdateTool.parseRedrawMode (anArg))
1063 else if (anArg == "-showhidden"
1064 && anArgIter + 1 < argc
1065 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
1068 hasShowHiddenArg = Standard_True;
1071 else if ((anArg == "-type"
1073 || anArg == "-algotype")
1074 && anArgIter + 1 < argc
1075 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1080 else if (!hasHlrOnArg
1081 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
1083 hasHlrOnArg = Standard_True;
1087 else if (!hasShowHiddenArg
1088 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
1090 hasShowHiddenArg = Standard_True;
1095 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
1101 di << "HLR: " << aView->ComputedMode() << "\n";
1102 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1104 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1106 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1107 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1108 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1110 anUpdateTool.Invalidate();
1114 Standard_Boolean toRecompute = Standard_False;
1115 if (aTypeOfHLR != Prs3d_TOH_NotSet
1116 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
1118 toRecompute = Standard_True;
1119 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1121 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1123 toRecompute = Standard_True;
1126 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
1130 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
1135 if (aView->ComputedMode() && isHLROn && toRecompute)
1137 AIS_ListOfInteractive aListOfShapes;
1138 aCtx->DisplayedObjects (aListOfShapes);
1139 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
1141 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
1143 aCtx->Redisplay (aShape, Standard_False);
1148 aView->SetComputedMode (isHLROn);
1152 //==============================================================================
1153 //function : VHLRType
1154 //purpose : change type of using HLR algorithm
1155 //==============================================================================
1157 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1159 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1160 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1163 std::cerr << "Error: No opened viewer!\n";
1167 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1168 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1169 AIS_ListOfInteractive aListOfShapes;
1170 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1172 TCollection_AsciiString anArg (argv[anArgIter]);
1174 if (anUpdateTool.parseRedrawMode (anArg))
1178 else if ((anArg == "-type"
1180 || anArg == "-algotype")
1181 && anArgIter + 1 < argc
1182 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1188 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1189 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1195 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1196 TCollection_AsciiString aName (argv[anArgIter]);
1197 if (!aMap.IsBound2 (aName))
1199 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1203 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1204 if (aShape.IsNull())
1206 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1209 aListOfShapes.Append (aShape);
1213 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1215 std::cout << "Syntax error: wrong number of arguments!\n";
1219 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1222 aCtx->DisplayedObjects (aListOfShapes);
1223 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1226 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1228 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1229 if (aShape.IsNull())
1234 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1235 && aView->ComputedMode();
1237 || aShape->TypeOfHLR() != aTypeOfHLR)
1239 aShape->SetTypeOfHLR (aTypeOfHLR);
1243 aCtx->Redisplay (aShape, Standard_False);
1249 //==============================================================================
1250 //function : FindViewIdByWindowHandle
1251 //purpose : Find theView Id in the map of views by window handle
1252 //==============================================================================
1253 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1254 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1256 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1257 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1259 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1260 if (aWindowHandle == theWindowHandle)
1261 return anIter.Key1();
1263 return TCollection_AsciiString("");
1267 //==============================================================================
1268 //function : ActivateView
1269 //purpose : Make the view active
1270 //==============================================================================
1272 void ActivateView (const TCollection_AsciiString& theViewName)
1274 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1275 if (!aView.IsNull())
1277 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1278 if (!anAISContext.IsNull())
1280 if (!ViewerTest::CurrentView().IsNull())
1282 TCollection_AsciiString aTitle("3D View - ");
1283 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1284 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1287 ViewerTest::CurrentView (aView);
1288 ViewerTest::SetAISContext (anAISContext);
1289 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
1290 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1292 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1293 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1294 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1296 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1298 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1299 ViewerTest::CurrentView()->Redraw();
1304 //==============================================================================
1305 //function : RemoveView
1307 //==============================================================================
1308 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1309 const Standard_Boolean theToRemoveContext)
1311 if (!ViewerTest_myViews.IsBound2 (theView))
1316 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1317 RemoveView (aViewName, theToRemoveContext);
1320 //==============================================================================
1321 //function : RemoveView
1322 //purpose : Close and remove view from display, clear maps if neccessary
1323 //==============================================================================
1324 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1326 if (!ViewerTest_myViews.IsBound1(theViewName))
1328 cout << "Wrong view name\n";
1332 // Activate another view if it's active now
1333 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1335 if (ViewerTest_myViews.Extent() > 1)
1337 TCollection_AsciiString aNewViewName;
1338 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1339 anIter.More(); anIter.Next())
1341 if (anIter.Key1() != theViewName)
1343 aNewViewName = anIter.Key1();
1347 ActivateView (aNewViewName);
1351 Handle(V3d_View) anEmptyView;
1352 #if defined(_WIN32) || defined(__WIN32__)
1353 Handle(WNT_Window) anEmptyWindow;
1354 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1355 Handle(Cocoa_Window) anEmptyWindow;
1357 Handle(Xw_Window) anEmptyWindow;
1359 VT_GetWindow() = anEmptyWindow;
1360 ViewerTest::CurrentView (anEmptyView);
1361 if (isContextRemoved)
1363 Handle(AIS_InteractiveContext) anEmptyContext;
1364 ViewerTest::SetAISContext(anEmptyContext);
1370 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1371 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1373 // Remove view resources
1374 ViewerTest_myViews.UnBind1(theViewName);
1375 aView->Window()->Unmap();
1378 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1379 XFlush (GetDisplayConnection()->GetDisplay());
1382 // Keep context opened only if the closed view is last to avoid
1383 // unused empty contexts
1384 if (!aCurrentContext.IsNull())
1386 // Check if there are more difined views in the viewer
1387 aCurrentContext->CurrentViewer()->InitDefinedViews();
1388 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1390 // Remove driver if there is no viewers that use it
1391 Standard_Boolean isRemoveDriver = Standard_True;
1392 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1393 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1395 if (aCurrentContext != anIter.Key2() &&
1396 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1398 isRemoveDriver = Standard_False;
1403 aCurrentContext->RemoveAll (Standard_False);
1406 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1407 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1408 #if TCL_MAJOR_VERSION < 8
1409 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1411 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1416 ViewerTest_myContexts.UnBind2(aCurrentContext);
1419 cout << "3D View - " << theViewName << " was deleted.\n";
1420 if (Draw_ToExitOnCloseView)
1422 Draw_Interprete ("exit");
1426 //==============================================================================
1428 //purpose : Remove the view defined by its name
1429 //==============================================================================
1431 static int VClose (Draw_Interpretor& /*theDi*/,
1432 Standard_Integer theArgsNb,
1433 const char** theArgVec)
1435 NCollection_List<TCollection_AsciiString> aViewList;
1438 TCollection_AsciiString anArg (theArgVec[1]);
1440 if (anArg.IsEqual ("ALL")
1441 || anArg.IsEqual ("*"))
1443 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1444 anIter.More(); anIter.Next())
1446 aViewList.Append (anIter.Key1());
1448 if (aViewList.IsEmpty())
1450 std::cout << "No view to close\n";
1456 ViewerTest_Names aViewName (theArgVec[1]);
1457 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1459 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1462 aViewList.Append (aViewName.GetViewName());
1467 // close active view
1468 if (ViewerTest::CurrentView().IsNull())
1470 std::cerr << "No active view!\n";
1473 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1476 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1477 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1478 anIter.More(); anIter.Next())
1480 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1486 //==============================================================================
1487 //function : VActivate
1488 //purpose : Activate the view defined by its ID
1489 //==============================================================================
1491 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1495 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1496 << "Usage: " << theArgVec[0] << " ViewID\n";
1501 theDi.Eval("vviewlist");
1505 TCollection_AsciiString aNameString(theArgVec[1]);
1506 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1508 TCollection_AsciiString aTitle("3D View - ");
1509 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1510 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1511 Handle(V3d_View) anEmptyView;
1512 #if defined(_WIN32) || defined(__WIN32__)
1513 Handle(WNT_Window) anEmptyWindow;
1514 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1515 Handle(Cocoa_Window) anEmptyWindow;
1517 Handle(Xw_Window) anEmptyWindow;
1519 VT_GetWindow() = anEmptyWindow;
1520 ViewerTest::CurrentView (anEmptyView);
1521 ViewerTest::ResetEventManager();
1522 theDi << theArgVec[0] << ": all views are inactive\n";
1526 ViewerTest_Names aViewNames(aNameString);
1528 // Check if this view exists in the viewer with the driver
1529 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1531 theDi << "Wrong view name\n";
1535 // Check if it is active already
1536 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1538 theDi << theArgVec[0] << ": the view is active already\n";
1542 ActivateView (aViewNames.GetViewName());
1546 //==============================================================================
1547 //function : VViewList
1548 //purpose : Print current list of views per viewer and graphic driver ID
1549 // shared between viewers
1550 //==============================================================================
1552 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1556 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1557 << "Usage: " << theArgVec[0] << " name";
1560 if (ViewerTest_myContexts.Size() < 1)
1563 Standard_Boolean isTreeView =
1564 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1568 theDi << theArgVec[0] <<":\n";
1571 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1572 aDriverIter.More(); aDriverIter.Next())
1575 theDi << aDriverIter.Key1() << ":\n";
1577 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1578 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1580 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1584 TCollection_AsciiString aContextName(aContextIter.Key1());
1585 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1588 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1589 aViewIter.More(); aViewIter.Next())
1591 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1593 TCollection_AsciiString aViewName(aViewIter.Key1());
1596 if (aViewIter.Value() == ViewerTest::CurrentView())
1597 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1599 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1603 theDi << aViewName << " ";
1613 //==============================================================================
1614 //function : VT_ProcessKeyPress
1615 //purpose : Handle KeyPress event from a CString
1616 //==============================================================================
1617 void VT_ProcessKeyPress (const char* buf_ret)
1619 //cout << "KeyPress" << endl;
1620 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1621 // Letter in alphabetic order
1623 if (!strcasecmp (buf_ret, "A")
1624 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1627 aView->SetProj(V3d_XposYnegZpos);
1629 else if (!strcasecmp (buf_ret, "D")
1630 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1635 else if (!strcasecmp (buf_ret, "F"))
1637 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1639 ViewerTest::GetAISContext()->FitSelected (aView);
1647 else if (!strcasecmp (buf_ret, "H"))
1650 std::cout << "HLR" << std::endl;
1651 aView->SetComputedMode (!aView->ComputedMode());
1654 else if (!strcasecmp (buf_ret, "P"))
1657 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1658 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1659 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1661 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1662 if (aContext->NbSelected()==0)
1664 AIS_ListOfInteractive aListOfShapes;
1665 aContext->DisplayedObjects(aListOfShapes);
1666 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1667 anIter.More(); anIter.Next())
1669 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1670 if (aShape.IsNull())
1672 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1673 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1675 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1676 aContext->Redisplay (aShape, Standard_False);
1681 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1683 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1684 if (aShape.IsNull())
1686 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1687 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1689 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1690 aContext->Redisplay (aShape, Standard_False);
1694 aContext->UpdateCurrentViewer();
1697 else if (!strcasecmp (buf_ret, "S"))
1699 std::cout << "setup Shaded display mode" << std::endl;
1701 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1702 if(Ctx->NbSelected()==0)
1703 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
1705 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1706 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1707 Ctx->UpdateCurrentViewer();
1710 else if (!strcasecmp (buf_ret, "U"))
1712 // Unset display mode
1713 std::cout << "reset display mode to defaults" << std::endl;
1715 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1716 if(Ctx->NbSelected()==0)
1717 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1719 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1720 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1721 Ctx->UpdateCurrentViewer();
1725 else if (!strcasecmp (buf_ret, "T")
1726 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1729 aView->SetProj(V3d_Zpos);
1731 else if (!strcasecmp (buf_ret, "B")
1732 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1735 aView->SetProj(V3d_Zneg);
1737 else if (!strcasecmp (buf_ret, "L")
1738 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1741 aView->SetProj(V3d_Xneg);
1743 else if (!strcasecmp (buf_ret, "R")
1744 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1747 aView->SetProj(V3d_Xpos);
1749 else if (!strcasecmp (buf_ret, "W"))
1751 std::cout << "setup WireFrame display mode" << std::endl;
1752 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1753 if(Ctx->NbSelected()==0)
1754 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1756 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1757 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1758 Ctx->UpdateCurrentViewer();
1761 else if (!strcasecmp (buf_ret, ","))
1763 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1765 else if (!strcasecmp (buf_ret, "."))
1767 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1769 else if (!strcasecmp (buf_ret, "/"))
1771 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1772 if (aCamera->IsStereo())
1774 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1778 else if (!strcasecmp (buf_ret, "*"))
1780 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1781 if (aCamera->IsStereo())
1783 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1787 else if (*buf_ret == THE_KEY_DELETE)
1789 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1791 && aCtx->NbSelected() > 0)
1793 Draw_Interprete ("verase");
1796 else if (*buf_ret == THE_KEY_ESCAPE)
1798 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1800 && Draw_ToCloseViewOnEsc)
1802 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1808 const Standard_Integer aSelMode = Draw::Atoi(buf_ret);
1809 if (aSelMode >= 0 && aSelMode <= 7)
1811 bool toEnable = true;
1812 if (const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext())
1814 AIS_ListOfInteractive aPrsList;
1815 aCtx->DisplayedObjects (aPrsList);
1816 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
1818 TColStd_ListOfInteger aModes;
1819 aCtx->ActivatedModes (aPrsIter.Value(), aModes);
1820 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
1822 if (aModeIter.Value() == aSelMode)
1829 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
1830 Draw_Interprete (aCmd.ToCString());
1835 //==============================================================================
1836 //function : VT_ProcessExpose
1837 //purpose : Redraw the View on an Expose Event
1838 //==============================================================================
1839 void VT_ProcessExpose()
1841 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1842 if (!aView3d.IsNull())
1848 //==============================================================================
1849 //function : VT_ProcessConfigure
1850 //purpose : Resize the View on an Configure Event
1851 //==============================================================================
1852 void VT_ProcessConfigure()
1854 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1855 if (aView3d.IsNull())
1860 aView3d->MustBeResized();
1865 //==============================================================================
1866 //function : VT_ProcessButton1Press
1868 //==============================================================================
1869 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1870 const char** theArgVec,
1871 Standard_Boolean theToPick,
1872 Standard_Boolean theIsShift)
1876 TheIsAnimating = Standard_False;
1877 return Standard_False;
1882 Standard_Real X, Y, Z;
1883 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1885 Draw::Set (theArgVec[1], X);
1886 Draw::Set (theArgVec[2], Y);
1887 Draw::Set (theArgVec[3], Z);
1892 ViewerTest::CurrentEventManager()->ShiftSelect();
1896 ViewerTest::CurrentEventManager()->Select();
1899 return Standard_False;
1902 //==============================================================================
1903 //function : VT_ProcessButton1Release
1904 //purpose : End selecting
1905 //==============================================================================
1906 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1910 IsDragged = Standard_False;
1911 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1914 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1915 X_Motion, Y_Motion);
1919 EM->Select (X_ButtonPress, Y_ButtonPress,
1920 X_Motion, Y_Motion);
1925 //==============================================================================
1926 //function : VT_ProcessButton3Press
1927 //purpose : Start Rotation
1928 //==============================================================================
1929 void VT_ProcessButton3Press()
1931 if (ViewerTest_V3dView::IsCurrentViewIn2DMode())
1937 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1938 if (HasHlrOnBeforeRotation)
1940 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1942 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1945 //==============================================================================
1946 //function : VT_ProcessButton3Release
1947 //purpose : End rotation
1948 //==============================================================================
1949 void VT_ProcessButton3Release()
1954 if (HasHlrOnBeforeRotation)
1956 HasHlrOnBeforeRotation = Standard_False;
1957 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1958 ViewerTest::CurrentView()->Redraw();
1963 //==============================================================================
1964 //function : ProcessControlButton1Motion
1966 //==============================================================================
1968 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1969 static void ProcessControlButton1Motion()
1971 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1973 X_ButtonPress = X_Motion;
1974 Y_ButtonPress = Y_Motion;
1978 //==============================================================================
1979 //function : VT_ProcessControlButton2Motion
1981 //==============================================================================
1982 void VT_ProcessControlButton2Motion()
1984 Standard_Integer aDx = X_Motion - X_ButtonPress;
1985 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1987 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1989 ViewerTest::CurrentView()->Pan (aDx, aDy);
1991 X_ButtonPress = X_Motion;
1992 Y_ButtonPress = Y_Motion;
1995 //==============================================================================
1996 //function : VT_ProcessControlButton3Motion
1997 //purpose : Rotation
1998 //==============================================================================
1999 void VT_ProcessControlButton3Motion()
2003 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
2007 //==============================================================================
2008 //function : VT_ProcessMotion
2010 //==============================================================================
2011 void VT_ProcessMotion()
2013 //pre-hilights detected objects at mouse position
2015 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
2016 EM->MoveTo(X_Motion, Y_Motion);
2020 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
2022 Xpix = X_Motion;Ypix=Y_Motion;
2025 //==============================================================================
2026 //function : ViewProject: implements VAxo, VTop, VLeft, ...
2027 //purpose : Switches to an axonometric, top, left and other views
2028 //==============================================================================
2030 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
2032 if ( ViewerTest::CurrentView().IsNull() )
2034 di<<"Call vinit before this command, please\n";
2038 ViewerTest::CurrentView()->SetProj(ori);
2042 //==============================================================================
2044 //purpose : Switch to an Axonometric view
2045 //Draw arg : No args
2046 //==============================================================================
2048 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
2050 return ViewProject(di, V3d_XposYnegZpos);
2053 //==============================================================================
2055 //purpose : Switch to a Top View
2056 //Draw arg : No args
2057 //==============================================================================
2059 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
2061 return ViewProject(di, V3d_Zpos);
2064 //==============================================================================
2065 //function : VBottom
2066 //purpose : Switch to a Bottom View
2067 //Draw arg : No args
2068 //==============================================================================
2070 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
2072 return ViewProject(di, V3d_Zneg);
2075 //==============================================================================
2077 //purpose : Switch to a Left View
2078 //Draw arg : No args
2079 //==============================================================================
2081 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
2083 return ViewProject(di, V3d_Xneg);
2086 //==============================================================================
2088 //purpose : Switch to a Right View
2089 //Draw arg : No args
2090 //==============================================================================
2092 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
2094 return ViewProject(di, V3d_Xpos);
2097 //==============================================================================
2099 //purpose : Switch to a Front View
2100 //Draw arg : No args
2101 //==============================================================================
2103 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
2105 return ViewProject(di, V3d_Yneg);
2108 //==============================================================================
2110 //purpose : Switch to a Back View
2111 //Draw arg : No args
2112 //==============================================================================
2114 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
2116 return ViewProject(di, V3d_Ypos);
2119 //==============================================================================
2121 //purpose : Dsiplay help on viewer Keyboead and mouse commands
2122 //Draw arg : No args
2123 //==============================================================================
2125 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2128 di << "Q : Quit the application\n";
2130 di << "=========================\n";
2131 di << "F : FitAll\n";
2132 di << "T : TopView\n";
2133 di << "B : BottomView\n";
2134 di << "R : RightView\n";
2135 di << "L : LeftView\n";
2136 di << "A : AxonometricView\n";
2137 di << "D : ResetView\n";
2139 di << "=========================\n";
2140 di << "S : Shading\n";
2141 di << "W : Wireframe\n";
2142 di << "H : HidelLineRemoval\n";
2143 di << "U : Unset display mode\n";
2144 di << "Delete : Remove selection from viewer\n";
2146 di << "=========================\n";
2147 di << "Selection mode \n";
2148 di << "0 : Shape\n";
2149 di << "1 : Vertex\n";
2153 di << "5 : Shell\n";
2154 di << "6 : Solid\n";
2155 di << "7 : Compound\n";
2157 di << "=========================\n";
2158 di << "Z : Switch Z clipping On/Off\n";
2159 di << ", : Hilight next detected\n";
2160 di << ". : Hilight previous detected\n";
2167 static Standard_Boolean Ppick = 0;
2168 static Standard_Integer Pargc = 0;
2169 static const char** Pargv = NULL;
2172 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2177 if (!ViewerTest_myViews.IsEmpty()) {
2179 WPARAM fwKeys = wParam;
2184 // Delete view from map of views
2185 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2190 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2191 || ViewerTest::CurrentView().IsNull())
2193 // Activate inactive window
2194 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2196 ActivateView (FindViewIdByWindowHandle(hwnd));
2202 if (IsDragged && !DragFirst)
2204 if (!GetActiveAISManipulator().IsNull())
2206 GetActiveAISManipulator()->StopTransform();
2207 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2210 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2212 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2213 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2216 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
2218 IsDragged = Standard_False;
2219 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2222 if (IsDragged && !DragFirst)
2224 if (!GetActiveAISManipulator().IsNull())
2226 GetActiveAISManipulator()->StopTransform (Standard_False);
2227 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2229 IsDragged = Standard_False;
2231 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2233 case WM_LBUTTONDOWN:
2234 if (!GetActiveAISManipulator().IsNull())
2236 IsDragged = ( fwKeys == MK_LBUTTON );
2240 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2245 DragFirst = Standard_True;
2246 X_ButtonPress = LOWORD(lParam);
2247 Y_ButtonPress = HIWORD(lParam);
2249 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2254 X_Motion = LOWORD (lParam);
2255 Y_Motion = HIWORD (lParam);
2256 if (!GetActiveAISManipulator().IsNull())
2260 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2264 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2265 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2270 bool toRedraw = false;
2271 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2273 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2278 if (GetClientRect (hwnd, &aRect))
2280 int aHeight = aRect.bottom - aRect.top;
2281 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2282 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
2287 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2291 DragFirst = Standard_False;
2294 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2298 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2302 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2306 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2312 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2315 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2322 BeginPaint(hwnd, &ps);
2323 EndPaint(hwnd, &ps);
2328 VT_ProcessConfigure();
2333 switch (aView->RenderingParams().StereoMode)
2335 case Graphic3d_StereoMode_RowInterlaced:
2336 case Graphic3d_StereoMode_ColumnInterlaced:
2337 case Graphic3d_StereoMode_ChessBoard:
2338 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2346 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2349 c[0] = (char) wParam;
2351 if (wParam == VK_DELETE)
2353 c[0] = THE_KEY_DELETE;
2355 else if (wParam == VK_ESCAPE)
2357 c[0] = THE_KEY_ESCAPE;
2360 else if (wParam == VK_OEM_COMMA)
2365 else if (wParam == VK_OEM_PERIOD)
2369 else if (wParam == VK_DIVIDE)
2374 else if (wParam == VK_MULTIPLY)
2378 VT_ProcessKeyPress (c);
2386 VT_ProcessButton3Release();
2389 case WM_LBUTTONDOWN:
2390 case WM_MBUTTONDOWN:
2391 case WM_RBUTTONDOWN:
2393 WPARAM fwKeys = wParam;
2397 X_ButtonPress = LOWORD(lParam);
2398 Y_ButtonPress = HIWORD(lParam);
2400 if (Msg == WM_LBUTTONDOWN)
2402 if ((fwKeys & MK_CONTROL) != 0)
2404 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2408 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2411 else if (Msg == WM_RBUTTONDOWN)
2414 VT_ProcessButton3Press();
2421 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2422 if (wParam & MK_CONTROL)
2424 if (aView->Camera()->IsStereo())
2426 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2430 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2437 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2444 //cout << "\t WM_MOUSEMOVE" << endl;
2445 WPARAM fwKeys = wParam;
2446 X_Motion = LOWORD(lParam);
2447 Y_Motion = HIWORD(lParam);
2450 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2453 X_ButtonPress = LOWORD(lParam);
2454 Y_ButtonPress = HIWORD(lParam);
2456 if ((fwKeys & MK_RBUTTON) != 0) {
2458 VT_ProcessButton3Press();
2462 if ((fwKeys & MK_CONTROL) != 0)
2464 if ((fwKeys & MK_LBUTTON) != 0)
2466 ProcessControlButton1Motion();
2468 else if ((fwKeys & MK_MBUTTON) != 0
2469 || ((fwKeys & MK_LBUTTON) != 0
2470 && (fwKeys & MK_RBUTTON) != 0))
2472 VT_ProcessControlButton2Motion();
2474 else if ((fwKeys & MK_RBUTTON) != 0)
2476 VT_ProcessControlButton3Motion();
2479 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2487 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2492 //==============================================================================
2493 //function : ViewerMainLoop
2494 //purpose : Get a Event on the view and dispatch it
2495 //==============================================================================
2498 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2500 Ppick = (argc > 0)? 1 : 0;
2508 cout << "Start picking" << endl;
2510 while ( Ppick == 1 ) {
2511 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2512 if (GetMessageW (&msg, NULL, 0, 0))
2514 TranslateMessage (&msg);
2515 DispatchMessageW (&msg);
2519 cout << "Picking done" << endl;
2525 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2527 int min( int a, int b )
2535 int max( int a, int b )
2543 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2546 static XEvent aReport;
2547 Standard_Boolean pick = argc > 0;
2548 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2549 XNextEvent (aDisplay, &aReport);
2551 // Handle event for the chosen display connection
2552 switch (aReport.type) {
2555 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2558 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2564 // Activate inactive view
2565 Window aWindow = GetWindowHandle(VT_GetWindow());
2566 if(aWindow != aReport.xfocus.window)
2568 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2577 case ConfigureNotify:
2579 VT_ProcessConfigure();
2588 XComposeStatus status_in_out;
2590 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2591 (char *) buf_ret , 10 ,
2592 &ks_ret , &status_in_out ) ;
2595 buf_ret[ret_len] = '\0' ;
2599 VT_ProcessKeyPress (buf_ret);
2605 X_ButtonPress = aReport.xbutton.x;
2606 Y_ButtonPress = aReport.xbutton.y;
2608 if (aReport.xbutton.button == Button1)
2610 if (aReport.xbutton.state & ControlMask)
2612 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2616 IsDragged = Standard_True;
2617 DragFirst = Standard_True;
2620 else if (aReport.xbutton.button == Button3)
2623 VT_ProcessButton3Press();
2633 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2635 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2636 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2640 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2641 if( aContext.IsNull() )
2643 cout << "The context is null. Please use vinit before createmesh" << endl;
2647 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2648 if( aReport.xbutton.button==1 )
2652 aContext->ShiftSelect (Standard_True);
2656 aContext->Select (Standard_True);
2661 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2662 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2663 ViewerTest::CurrentView(), Standard_True);
2667 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2668 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2669 ViewerTest::CurrentView(), Standard_True);
2672 VT_ProcessButton3Release();
2674 IsDragged = Standard_False;
2677 VT_ProcessButton3Release();
2682 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2690 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2692 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2696 X_Motion = aReport.xmotion.x;
2697 Y_Motion = aReport.xmotion.y;
2698 DragFirst = Standard_False;
2700 Window aWindow = GetWindowHandle(VT_GetWindow());
2703 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2704 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2705 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2706 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
2707 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2711 X_Motion = aReport.xmotion.x;
2712 Y_Motion = aReport.xmotion.y;
2714 // remove all the ButtonMotionMaskr
2715 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2717 if ( aReport.xmotion.state & ControlMask ) {
2718 if ( aReport.xmotion.state & Button1Mask ) {
2719 ProcessControlButton1Motion();
2721 else if ( aReport.xmotion.state & Button2Mask ) {
2722 VT_ProcessControlButton2Motion();
2724 else if ( aReport.xmotion.state & Button3Mask ) {
2725 VT_ProcessControlButton3Motion();
2739 //==============================================================================
2740 //function : VProcessEvents
2741 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2742 // event in the Viewer window
2743 //==============================================================================
2745 static void VProcessEvents(ClientData,int)
2747 NCollection_Vector<int> anEventNumbers;
2748 // Get number of messages from every display
2749 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2750 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2752 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2754 // Handle events for every display
2755 int anEventIter = 0;
2756 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2757 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2759 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2760 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2762 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2763 int anEventResult = ViewerMainLoop( 0, NULL);
2764 // If window is closed or context was not found finish current event processing loop
2770 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2775 //==============================================================================
2776 //function : OSWindowSetup
2777 //purpose : Setup for the X11 window to be able to cath the event
2778 //==============================================================================
2781 static void OSWindowSetup()
2783 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2786 Window window = VT_GetWindow()->XWindow();
2787 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2788 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2789 XSynchronize(aDisplay, 1);
2791 // X11 : For keyboard on SUN
2793 wmhints.flags = InputHint;
2796 XSetWMHints( aDisplay, window, &wmhints);
2798 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2799 ButtonPressMask | ButtonReleaseMask |
2800 StructureNotifyMask |
2802 Button1MotionMask | Button2MotionMask |
2803 Button3MotionMask | FocusChangeMask
2805 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2806 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2808 XSynchronize(aDisplay, 0);
2816 //==============================================================================
2819 //==============================================================================
2821 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
2823 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2826 std::cout << "Error: no active viewer!\n";
2830 Standard_Boolean toFit = Standard_True;
2831 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2832 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2834 TCollection_AsciiString anArg (theArgv[anArgIter]);
2836 if (anUpdateTool.parseRedrawMode (anArg))
2840 else if (anArg == "-selected")
2842 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2843 toFit = Standard_False;
2847 std::cout << "Syntax error at '" << anArg << "'\n";
2853 aView->FitAll (0.01, Standard_False);
2858 //=======================================================================
2859 //function : VFitArea
2860 //purpose : Fit view to show area located between two points
2861 // : given in world 2D or 3D coordinates.
2862 //=======================================================================
2863 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2865 Handle(V3d_View) aView = ViewerTest::CurrentView();
2868 std::cerr << theArgVec[0] << "Error: No active view.\n";
2873 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2874 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2878 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2879 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2880 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2881 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2883 else if (theArgNb == 7)
2885 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2886 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2887 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2888 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2889 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2890 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2894 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2895 theDI.PrintHelp(theArgVec[0]);
2899 // Convert model coordinates to view space
2900 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2901 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2902 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2904 // Determine fit area
2905 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2906 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2908 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2910 if (aDiagonal < Precision::Confusion())
2912 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2916 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2920 //==============================================================================
2922 //purpose : ZFitall, no DRAW arguments
2923 //Draw arg : No args
2924 //==============================================================================
2925 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2927 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2929 if (aCurrentView.IsNull())
2931 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2937 aCurrentView->ZFitAll();
2938 aCurrentView->Redraw();
2942 Standard_Real aScale = 1.0;
2946 aScale = Draw::Atoi (theArgVec[1]);
2949 aCurrentView->ZFitAll (aScale);
2950 aCurrentView->Redraw();
2955 //==============================================================================
2956 //function : VRepaint
2958 //==============================================================================
2959 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
2961 Handle(V3d_View) aView = ViewerTest::CurrentView();
2964 std::cout << "Error: no active viewer!\n";
2968 Standard_Boolean isImmediateUpdate = Standard_False;
2969 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2971 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2973 if (anArg == "-immediate")
2975 isImmediateUpdate = Standard_True;
2976 if (anArgIter + 1 < theArgNb
2977 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2984 std::cout << "Syntax error at '" << anArg << "'\n";
2988 if (isImmediateUpdate)
2990 aView->RedrawImmediate();
2999 //==============================================================================
3001 //purpose : Remove all the object from the viewer
3002 //Draw arg : No args
3003 //==============================================================================
3005 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3007 Handle(V3d_View) V = ViewerTest::CurrentView();
3009 ViewerTest::Clear();
3013 //==============================================================================
3016 //==============================================================================
3018 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3019 { if (ViewerTest::CurrentView().IsNull() ) return 1;
3022 di << argv[0] << "Invalid number of arguments\n";
3026 while (ViewerMainLoop( argc, argv)) {
3032 //==============================================================================
3034 //purpose : Load image as background
3035 //==============================================================================
3037 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3039 if (argc < 2 || argc > 3)
3041 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
3042 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
3046 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3047 if(AISContext.IsNull())
3049 di << "use 'vinit' command before " << argv[0] << "\n";
3053 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
3056 const char* szType = argv[2];
3057 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3058 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3059 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3060 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3063 di << "Wrong fill type : " << szType << "\n";
3064 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
3069 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3070 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
3075 //==============================================================================
3076 //function : VSetBgMode
3077 //purpose : Change background image fill type
3078 //==============================================================================
3080 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3084 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
3085 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
3089 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3090 if(AISContext.IsNull())
3092 di << "use 'vinit' command before " << argv[0] << "\n";
3095 Aspect_FillMethod aFillType = Aspect_FM_NONE;
3096 const char* szType = argv[1];
3097 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3098 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3099 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3100 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3103 di << "Wrong fill type : " << szType << "\n";
3104 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
3107 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3108 V3dView->SetBgImageStyle(aFillType, Standard_True);
3112 //==============================================================================
3113 //function : VSetGradientBg
3114 //purpose : Mount gradient background
3115 //==============================================================================
3116 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3120 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
3121 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
3122 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3123 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3127 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3128 if(AISContext.IsNull())
3130 di << "use 'vinit' command before " << argv[0] << "\n";
3136 Standard_Real R1 = Draw::Atof(argv[1])/255.;
3137 Standard_Real G1 = Draw::Atof(argv[2])/255.;
3138 Standard_Real B1 = Draw::Atof(argv[3])/255.;
3139 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
3141 Standard_Real R2 = Draw::Atof(argv[4])/255.;
3142 Standard_Real G2 = Draw::Atof(argv[5])/255.;
3143 Standard_Real B2 = Draw::Atof(argv[6])/255.;
3145 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
3146 int aType = Draw::Atoi(argv[7]);
3147 if( aType < 0 || aType > 8 )
3149 di << "Wrong fill type \n";
3150 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3151 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3155 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3157 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3158 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
3164 //==============================================================================
3165 //function : VSetGradientBgMode
3166 //purpose : Change gradient background fill style
3167 //==============================================================================
3168 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3172 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
3173 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3174 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3178 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3179 if(AISContext.IsNull())
3181 di << "use 'vinit' command before " << argv[0] << "\n";
3186 int aType = Draw::Atoi(argv[1]);
3187 if( aType < 0 || aType > 8 )
3189 di << "Wrong fill type \n";
3190 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3191 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3195 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3197 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3198 V3dView->SetBgGradientStyle( aMethod, 1 );
3204 //==============================================================================
3205 //function : VSetColorBg
3206 //purpose : Set color background
3207 //==============================================================================
3208 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3212 di << "Usage : " << argv[0] << " R G B : Set color background\n";
3213 di << "R,G,B = [0..255]\n";
3217 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3218 if(AISContext.IsNull())
3220 di << "use 'vinit' command before " << argv[0] << "\n";
3226 Standard_Real R = Draw::Atof(argv[1])/255.;
3227 Standard_Real G = Draw::Atof(argv[2])/255.;
3228 Standard_Real B = Draw::Atof(argv[3])/255.;
3229 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
3231 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3232 V3dView->SetBackgroundColor( aColor );
3239 //==============================================================================
3240 //function : VSetDefaultBg
3241 //purpose : Set default viewer background fill color
3242 //==============================================================================
3243 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3248 std::cout << "Error: wrong syntax! See usage:\n";
3249 theDI.PrintHelp (theArgVec[0]);
3253 ViewerTest_DefaultBackground.FillMethod =
3254 theArgNb == 4 ? Aspect_GFM_NONE
3255 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
3259 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
3260 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
3261 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
3262 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
3266 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
3267 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
3268 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
3269 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
3271 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
3272 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
3273 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
3274 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
3277 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
3278 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
3280 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
3281 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
3282 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
3283 ViewerTest_DefaultBackground.GradientColor2,
3284 ViewerTest_DefaultBackground.FillMethod);
3290 //==============================================================================
3292 //purpose : View Scaling
3293 //==============================================================================
3295 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3297 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3298 if ( V3dView.IsNull() ) return 1;
3301 di << argv[0] << "Invalid number of arguments\n";
3304 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
3307 //==============================================================================
3308 //function : VZBuffTrihedron
3310 //==============================================================================
3312 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3313 Standard_Integer theArgNb,
3314 const char** theArgVec)
3316 Handle(V3d_View) aView = ViewerTest::CurrentView();
3319 std::cout << "Error: no active viewer!\n";
3323 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
3325 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3326 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3327 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3328 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3329 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3330 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3331 Standard_Real aScale = 0.1;
3332 Standard_Real aSizeRatio = 0.8;
3333 Standard_Real anArrowDiam = 0.05;
3334 Standard_Integer aNbFacets = 12;
3335 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3337 Standard_CString anArg = theArgVec[anArgIter];
3338 TCollection_AsciiString aFlag (anArg);
3340 if (anUpdateTool.parseRedrawMode (aFlag))
3344 else if (aFlag == "-on")
3348 else if (aFlag == "-off")
3350 aView->TriedronErase();
3353 else if (aFlag == "-pos"
3354 || aFlag == "-position"
3355 || aFlag == "-corner")
3357 if (++anArgIter >= theArgNb)
3359 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3363 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3364 aPosName.LowerCase();
3365 if (aPosName == "center")
3367 aPosition = Aspect_TOTP_CENTER;
3369 else if (aPosName == "left_lower"
3370 || aPosName == "lower_left"
3371 || aPosName == "leftlower"
3372 || aPosName == "lowerleft")
3374 aPosition = Aspect_TOTP_LEFT_LOWER;
3376 else if (aPosName == "left_upper"
3377 || aPosName == "upper_left"
3378 || aPosName == "leftupper"
3379 || aPosName == "upperleft")
3381 aPosition = Aspect_TOTP_LEFT_UPPER;
3383 else if (aPosName == "right_lower"
3384 || aPosName == "lower_right"
3385 || aPosName == "rightlower"
3386 || aPosName == "lowerright")
3388 aPosition = Aspect_TOTP_RIGHT_LOWER;
3390 else if (aPosName == "right_upper"
3391 || aPosName == "upper_right"
3392 || aPosName == "rightupper"
3393 || aPosName == "upperright")
3395 aPosition = Aspect_TOTP_RIGHT_UPPER;
3399 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3403 else if (aFlag == "-type")
3405 if (++anArgIter >= theArgNb)
3407 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3411 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3412 aTypeName.LowerCase();
3413 if (aTypeName == "wireframe"
3414 || aTypeName == "wire")
3416 aVisType = V3d_WIREFRAME;
3418 else if (aTypeName == "zbuffer"
3419 || aTypeName == "shaded")
3421 aVisType = V3d_ZBUFFER;
3425 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3428 else if (aFlag == "-scale")
3430 if (++anArgIter >= theArgNb)
3432 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3436 aScale = Draw::Atof (theArgVec[anArgIter]);
3438 else if (aFlag == "-size"
3439 || aFlag == "-sizeratio")
3441 if (++anArgIter >= theArgNb)
3443 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3447 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3449 else if (aFlag == "-arrowdiam"
3450 || aFlag == "-arrowdiameter")
3452 if (++anArgIter >= theArgNb)
3454 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3458 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3460 else if (aFlag == "-nbfacets")
3462 if (++anArgIter >= theArgNb)
3464 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3468 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3470 else if (aFlag == "-colorlabel"
3471 || aFlag == "-colorlabels")
3473 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3474 theArgVec + anArgIter + 1,
3478 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3481 anArgIter += aNbParsed;
3483 else if (aFlag == "-colorarrowx")
3485 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3486 theArgVec + anArgIter + 1,
3490 std::cerr << "Error: wrong syntax at '" << anArg << "'\n&q