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>
18 #include <AIS_ColorScale.hxx>
19 #include <AIS_Shape.hxx>
20 #include <AIS_InteractiveObject.hxx>
21 #include <AIS_ListOfInteractive.hxx>
22 #include <AIS_ListIteratorOfListOfInteractive.hxx>
24 #include <Graphic3d_ArrayOfPolylines.hxx>
25 #include <Graphic3d_AspectMarker3d.hxx>
26 #include <Graphic3d_ExportFormat.hxx>
27 #include <Graphic3d_NameOfTextureEnv.hxx>
28 #include <Graphic3d_GraduatedTrihedron.hxx>
29 #include <Graphic3d_TextureEnv.hxx>
30 #include <Graphic3d_TextureParams.hxx>
31 #include <Graphic3d_TypeOfTextureFilter.hxx>
32 #include <Graphic3d_AspectFillArea3d.hxx>
33 #include <ViewerTest.hxx>
34 #include <ViewerTest_AutoUpdater.hxx>
35 #include <ViewerTest_EventManager.hxx>
36 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
37 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
38 #include <Visual3d_View.hxx>
39 #include <Visual3d_ViewManager.hxx>
40 #include <V3d_AmbientLight.hxx>
41 #include <V3d_DirectionalLight.hxx>
42 #include <V3d_PositionalLight.hxx>
43 #include <V3d_SpotLight.hxx>
44 #include <NCollection_DoubleMap.hxx>
45 #include <NCollection_List.hxx>
46 #include <NCollection_Vector.hxx>
47 #include <AIS_InteractiveContext.hxx>
48 #include <Draw_Interpretor.hxx>
50 #include <Draw_Appli.hxx>
51 #include <Aspect_PrintAlgo.hxx>
52 #include <Image_AlienPixMap.hxx>
53 #include <OpenGl_GraphicDriver.hxx>
54 #include <OSD_Timer.hxx>
55 #include <TColStd_HSequenceOfAsciiString.hxx>
56 #include <TColStd_SequenceOfInteger.hxx>
57 #include <TColStd_HSequenceOfReal.hxx>
58 #include <TColgp_Array1OfPnt2d.hxx>
59 #include <TColStd_MapOfAsciiString.hxx>
60 #include <Aspect_TypeOfLine.hxx>
61 #include <Image_Diff.hxx>
62 #include <Aspect_DisplayConnection.hxx>
66 #include <PrsMgr_PresentableObject.hxx>
67 #include <Graphic3d_ClipPlane.hxx>
68 #include <NCollection_DataMap.hxx>
69 #include <Graphic3d_Texture2Dmanual.hxx>
70 #include <Prs3d_ShadingAspect.hxx>
71 #include <Prs3d_Drawer.hxx>
72 #include <Prs3d_LineAspect.hxx>
73 #include <Prs3d_Root.hxx>
82 #include <WNT_WClass.hxx>
83 #include <WNT_Window.hxx>
86 #define _CRT_SECURE_NO_DEPRECATE
87 #pragma warning (disable:4996)
89 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
90 #include <Cocoa_Window.hxx>
92 #include <Xw_Window.hxx>
93 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
94 #include <X11/Xutil.h>
98 // Auxiliary definitions
99 static const char THE_KEY_DELETE = 127;
101 //==============================================================================
102 // VIEWER GLOBAL VARIABLES
103 //==============================================================================
105 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
106 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
108 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
109 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
111 extern int VErase (Draw_Interpretor& theDI,
112 Standard_Integer theArgNb,
113 const char** theArgVec);
116 static Handle(WNT_Window)& VT_GetWindow() {
117 static Handle(WNT_Window) WNTWin;
120 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
121 static Handle(Cocoa_Window)& VT_GetWindow()
123 static Handle(Cocoa_Window) aWindow;
126 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
127 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
128 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
131 static Handle(Xw_Window)& VT_GetWindow(){
132 static Handle(Xw_Window) XWWin;
136 static void VProcessEvents(ClientData,int);
139 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
141 static Handle(Aspect_DisplayConnection) aDisplayConnection;
142 return aDisplayConnection;
145 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
147 GetDisplayConnection() = theDisplayConnection;
150 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
151 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
153 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
155 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
156 if (!aWindow.IsNull())
157 return aWindow->HWindow();
158 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
159 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
160 if (!aWindow.IsNull())
161 return aWindow->XWindow();
163 return aWindowHandle;
167 static Standard_Boolean MyHLRIsOn = Standard_False;
169 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
170 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
171 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
172 static OpenGl_Caps ViewerTest_myDefaultCaps;
174 #define ZCLIPWIDTH 1.
176 static void OSWindowSetup();
180 Quantity_Color FlatColor;
181 Quantity_Color GradientColor1;
182 Quantity_Color GradientColor2;
183 Aspect_GradientFillMethod FillMethod;
184 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
186 //==============================================================================
187 // EVENT GLOBAL VARIABLES
188 //==============================================================================
190 static int Start_Rot = 0;
191 static int ZClipIsOn = 0;
192 int X_Motion = 0; // Current cursor position
194 int X_ButtonPress = 0; // Last ButtonPress position
195 int Y_ButtonPress = 0;
196 Standard_Boolean IsDragged = Standard_False;
197 Standard_Boolean DragFirst = Standard_False;
199 //==============================================================================
202 static LRESULT WINAPI ViewerWindowProc(
207 static LRESULT WINAPI AdvViewerWindowProc(
215 //==============================================================================
218 //==============================================================================
220 const Handle(MMgt_TShared)& ViewerTest::WClass()
222 static Handle(MMgt_TShared) theWClass;
224 if (theWClass.IsNull())
226 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
227 CS_VREDRAW | CS_HREDRAW, 0, 0,
228 ::LoadCursor (NULL, IDC_ARROW));
234 //==============================================================================
235 //function : CreateName
236 //purpose : Create numerical name for new object in theMap
237 //==============================================================================
238 template <typename ObjectType>
239 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
240 const TCollection_AsciiString& theDefaultString)
242 if (theObjectMap.IsEmpty())
243 return theDefaultString + TCollection_AsciiString(1);
245 Standard_Integer aNextKey = 1;
246 Standard_Boolean isFound = Standard_False;
249 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
250 // Look for objects with default names
251 if (theObjectMap.IsBound1(aStringKey))
256 isFound = Standard_True;
259 return theDefaultString + TCollection_AsciiString(aNextKey);
262 //==============================================================================
263 //structure : ViewerTest_Names
264 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
265 //==============================================================================
266 struct ViewerTest_Names
269 TCollection_AsciiString myDriverName;
270 TCollection_AsciiString myViewerName;
271 TCollection_AsciiString myViewName;
275 const TCollection_AsciiString& GetDriverName () const
279 void SetDriverName (const TCollection_AsciiString& theDriverName)
281 myDriverName = theDriverName;
283 const TCollection_AsciiString& GetViewerName () const
287 void SetViewerName (const TCollection_AsciiString& theViewerName)
289 myViewerName = theViewerName;
291 const TCollection_AsciiString& GetViewName () const
295 void SetViewName (const TCollection_AsciiString& theViewName)
297 myViewName = theViewName;
300 //===========================================================================
301 //function : Constructor for ViewerTest_Names
302 //purpose : Get view, viewer, driver names from custom string
303 //===========================================================================
305 ViewerTest_Names (const TCollection_AsciiString& theInputString)
307 TCollection_AsciiString aName(theInputString);
308 if (theInputString.IsEmpty())
310 // Get current configuration
311 if (ViewerTest_myDrivers.IsEmpty())
312 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
313 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
315 myDriverName = ViewerTest_myDrivers.Find2
316 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
318 if(ViewerTest_myContexts.IsEmpty())
320 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
321 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
324 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
326 myViewName = CreateName <Handle(V3d_View)>
327 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
331 // There is at least view name
332 Standard_Integer aParserNumber = 0;
333 for (Standard_Integer i = 0; i < 3; ++i)
335 Standard_Integer aParserPos = aName.SearchFromEnd("/");
339 aName.Split(aParserPos-1);
344 if (aParserNumber == 0)
347 if (!ViewerTest::GetAISContext().IsNull())
349 myDriverName = ViewerTest_myDrivers.Find2
350 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
351 myViewerName = ViewerTest_myContexts.Find2
352 (ViewerTest::GetAISContext());
356 // There is no opened contexts here, need to create names for viewer and driver
357 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
358 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
360 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
361 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
363 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
365 else if (aParserNumber == 1)
367 // Here is viewerName/viewName
368 if (!ViewerTest::GetAISContext().IsNull())
369 myDriverName = ViewerTest_myDrivers.Find2
370 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
373 // There is no opened contexts here, need to create name for driver
374 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
375 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
377 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
379 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
383 //Here is driverName/viewerName/viewName
384 myDriverName = TCollection_AsciiString(aName);
386 TCollection_AsciiString aViewerName(theInputString);
387 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
388 myViewerName = TCollection_AsciiString(aViewerName);
390 myViewName = TCollection_AsciiString(theInputString);
396 //==============================================================================
397 //function : FindContextByView
398 //purpose : Find AIS_InteractiveContext by View
399 //==============================================================================
401 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
403 Handle(AIS_InteractiveContext) anAISContext;
405 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
406 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
408 if (anIter.Value()->CurrentViewer() == theView->Viewer())
409 return anIter.Key2();
415 //==============================================================================
416 //function : SetWindowTitle
417 //purpose : Set window title
418 //==============================================================================
420 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
421 Standard_CString theTitle)
424 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
426 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
427 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
429 if(GetDisplayConnection()->GetDisplay())
432 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
433 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
438 //==============================================================================
439 //function : IsWindowOverlapped
440 //purpose : Check if theWindow overlapp another view
441 //==============================================================================
443 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
444 const Standard_Integer thePxTop,
445 const Standard_Integer thePxRight,
446 const Standard_Integer thePxBottom,
447 TCollection_AsciiString& theViewId)
449 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
450 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
452 Standard_Integer aTop = 0,
456 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
457 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
458 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
459 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
460 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
462 theViewId = anIter.Key1();
463 return Standard_True;
466 return Standard_False;
469 // Workaround: to create and delete non-orthographic views outside ViewerTest
470 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
472 ViewerTest_myViews.UnBind1 (theName);
475 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
476 const Handle(V3d_View)& theView)
478 ViewerTest_myViews.Bind (theName, theView);
481 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
483 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
485 //==============================================================================
486 //function : ViewerInit
487 //purpose : Create the window viewer and initialize all the global variable
488 //==============================================================================
490 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
491 const Standard_Integer thePxTop,
492 const Standard_Integer thePxWidth,
493 const Standard_Integer thePxHeight,
494 Standard_CString theViewName,
495 Standard_CString theDisplayName)
497 // Default position and dimension of the viewer window.
498 // Note that left top corner is set to be sufficiently small to have
499 // window fit in the small screens (actual for remote desktops, see #23003).
500 // The position corresponds to the window's client area, thus some
501 // gap is added for window frame to be visible.
502 Standard_Integer aPxLeft = 20;
503 Standard_Integer aPxTop = 40;
504 Standard_Integer aPxWidth = 409;
505 Standard_Integer aPxHeight = 409;
506 Standard_Boolean toCreateViewer = Standard_False;
508 Handle(OpenGl_GraphicDriver) aGraphicDriver;
509 ViewerTest_Names aViewNames(theViewName);
510 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
511 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
518 aPxWidth = thePxWidth;
519 if (thePxHeight != 0)
520 aPxHeight = thePxHeight;
522 // Get graphic driver (create it or get from another view)
523 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
525 // Get connection string
526 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
527 TCollection_AsciiString aDisplayName(theDisplayName);
528 if (!aDisplayName.IsEmpty())
529 SetDisplayConnection (new Aspect_DisplayConnection ());
531 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
533 (void)theDisplayName; // avoid warning on unused argument
534 SetDisplayConnection (new Aspect_DisplayConnection ());
536 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
537 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
538 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
539 toCreateViewer = Standard_True;
543 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
546 //Dispose the window if input parameters are default
547 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
549 Standard_Integer aTop = 0,
556 // Get screen resolution
557 #if defined(_WIN32) || defined(__WIN32__)
559 GetClientRect(GetDesktopWindow(), &aWindowSize);
560 aScreenHeight = aWindowSize.bottom;
561 aScreenWidth = aWindowSize.right;
562 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
563 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
565 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
566 aScreenWidth = WidthOfScreen(aScreen);
567 aScreenHeight = HeightOfScreen(aScreen);
570 TCollection_AsciiString anOverlappedViewId("");
572 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
574 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
576 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
577 && aRight + 2*aPxWidth + 40 > aScreenWidth)
579 if (aBottom + aPxHeight + 40 > aScreenHeight)
586 aPxTop = aBottom + 40;
589 aPxLeft = aRight + 20;
594 TCollection_AsciiString aTitle("3D View - ");
595 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
597 // Change name of current active window
598 if (!ViewerTest::CurrentView().IsNull())
600 TCollection_AsciiString anActiveWindowTitle("3D View - ");
601 anActiveWindowTitle = anActiveWindowTitle
602 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
603 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
607 Handle(V3d_Viewer) a3DViewer;
608 // If it's the single view, we first look for empty context
609 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
611 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
612 anIter(ViewerTest_myContexts);
614 ViewerTest::SetAISContext (anIter.Value());
615 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
617 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
619 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
620 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
622 else if (a3DViewer.IsNull())
624 toCreateViewer = Standard_True;
625 TCollection_ExtendedString NameOfWindow("Viewer3D");
626 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
627 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
628 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
629 ViewerTest_DefaultBackground.GradientColor2,
630 ViewerTest_DefaultBackground.FillMethod);
634 if (ViewerTest::GetAISContext().IsNull() ||
635 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
637 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
638 ViewerTest::SetAISContext (aContext);
639 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
643 ViewerTest::ResetEventManager();
648 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
649 Handle(WNT_WClass)::DownCast (WClass()),
650 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
654 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
655 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
657 aPxWidth, aPxHeight);
658 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
660 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
663 aPxWidth, aPxHeight);
665 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
668 Handle(V3d_View) aView = a3DViewer->CreateView();
669 aView->SetWindow (VT_GetWindow());
670 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
672 ViewerTest::CurrentView(aView);
673 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
675 // Setup for X11 or NT
678 // Set parameters for V3d_View and V3d_Viewer
679 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
680 aV3dView->SetComputedMode(Standard_False);
681 MyHLRIsOn = aV3dView->ComputedMode();
682 aV3dView->SetZClippingDepth(0.5);
683 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
685 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
688 a3DViewer->SetDefaultLights();
689 a3DViewer->SetLightOn();
692 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
693 #if TCL_MAJOR_VERSION < 8
694 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
695 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
697 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
698 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
702 VT_GetWindow()->Map();
704 // Set the handle of created view in the event manager
705 ViewerTest::ResetEventManager();
707 ViewerTest::CurrentView()->Redraw();
712 return aViewNames.GetViewName();
715 //==============================================================================
716 //function : RedrawAllViews
717 //purpose : Redraw all created views
718 //==============================================================================
719 void ViewerTest::RedrawAllViews()
721 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
722 for (; aViewIt.More(); aViewIt.Next())
724 const Handle(V3d_View)& aView = aViewIt.Key2();
729 //==============================================================================
731 //purpose : Create the window viewer and initialize all the global variable
732 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
733 //==============================================================================
735 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
739 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
740 << "Type help for more information.\n";
744 TCollection_AsciiString aViewName, aDisplayName;
745 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
746 TCollection_AsciiString aName, aValue;
747 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
749 const TCollection_AsciiString anArg = theArgVec[anArgIt];
750 TCollection_AsciiString anArgCase = anArg;
751 anArgCase.UpperCase();
752 if (ViewerTest::SplitParameter (anArg, aName, aValue))
755 if (aName.IsEqual ("NAME"))
759 else if (aName.IsEqual ("L")
760 || aName.IsEqual ("LEFT"))
762 aPxLeft = aValue.IntegerValue();
764 else if (aName.IsEqual ("T")
765 || aName.IsEqual ("TOP"))
767 aPxTop = aValue.IntegerValue();
769 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
770 else if (aName.IsEqual ("DISP")
771 || aName.IsEqual ("DISPLAY"))
773 aDisplayName = aValue;
776 else if (aName.IsEqual ("W")
777 || aName.IsEqual ("WIDTH"))
779 aPxWidth = aValue.IntegerValue();
781 else if (aName.IsEqual ("H")
782 || aName.IsEqual ("HEIGHT"))
784 aPxHeight = aValue.IntegerValue();
788 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
791 else if (aViewName.IsEmpty())
797 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
801 ViewerTest_Names aViewNames (aViewName);
802 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
804 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
805 theDi.Eval (aCommand.ToCString());
809 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
810 aViewName.ToCString(),
811 aDisplayName.ToCString());
816 //==============================================================================
818 //purpose : hidden lines removal algorithm
819 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
820 //==============================================================================
822 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
824 if (ViewerTest::CurrentView().IsNull())
826 di << argv[0] << ": Call vinit before this command, please.\n";
832 di << argv[0] << ": Wrong number of command arguments.\n"
833 << "Type help " << argv[0] << " for more information.\n";
837 // Enable or disable HLR mode.
838 Standard_Boolean isHLROn =
839 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
841 if (isHLROn != MyHLRIsOn)
844 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
847 // Show or hide hidden lines in HLR mode.
848 Standard_Boolean isCurrentShowHidden
849 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
851 Standard_Boolean isShowHidden =
852 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
853 : isCurrentShowHidden;
856 if (isShowHidden != isCurrentShowHidden)
860 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
864 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
870 AIS_ListOfInteractive aListOfShapes;
871 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
873 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
875 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
880 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
885 ViewerTest::CurrentView()->Update();
889 //==============================================================================
890 //function : VHLRType
891 //purpose : change type of using HLR algorithm
892 //==============================================================================
894 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
896 if (ViewerTest::CurrentView().IsNull())
898 di << argv[0] << ": Call vinit before this command, please.\n";
904 di << argv[0] << ": Wrong number of command arguments.\n"
905 << "Type help " << argv[0] << " for more information.\n";
909 Prs3d_TypeOfHLR aTypeOfHLR =
910 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
914 AIS_ListOfInteractive aListOfShapes;
915 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
916 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
917 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
918 anIter.More(); anIter.Next())
920 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
923 if (aShape->TypeOfHLR() != aTypeOfHLR)
924 aShape->SetTypeOfHLR (aTypeOfHLR);
926 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
928 ViewerTest::CurrentView()->Update();
933 for (Standard_Integer i = 2; i < argc; ++i)
935 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
936 TCollection_AsciiString aName (argv[i]);
938 if (!aMap.IsBound2 (aName))
940 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
943 Handle(AIS_Shape) anAISObject =
944 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
945 if (anAISObject.IsNull())
947 anAISObject->SetTypeOfHLR (aTypeOfHLR);
949 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
951 ViewerTest::CurrentView()->Update();
957 //==============================================================================
958 //function : FindViewIdByWindowHandle
959 //purpose : Find theView Id in the map of views by window handle
960 //==============================================================================
961 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
962 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
964 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
965 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
967 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
968 if (aWindowHandle == theWindowHandle)
969 return anIter.Key1();
971 return TCollection_AsciiString("");
975 //==============================================================================
976 //function : ActivateView
977 //purpose : Make the view active
978 //==============================================================================
980 void ActivateView (const TCollection_AsciiString& theViewName)
982 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
985 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
986 if (!anAISContext.IsNull())
988 if (!ViewerTest::CurrentView().IsNull())
990 TCollection_AsciiString aTitle("3D View - ");
991 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
992 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
995 ViewerTest::CurrentView (aView);
996 // Update degenerate mode
997 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
998 ViewerTest::SetAISContext (anAISContext);
999 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1000 aTitle = aTitle + theViewName + "(*)";
1001 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1002 #if defined(_WIN32) || defined(__WIN32__)
1003 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1004 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1005 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1007 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1009 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1010 ViewerTest::CurrentView()->Redraw();
1015 //==============================================================================
1016 //function : RemoveView
1018 //==============================================================================
1019 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1020 const Standard_Boolean theToRemoveContext)
1022 if (!ViewerTest_myViews.IsBound2 (theView))
1027 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1028 RemoveView (aViewName, theToRemoveContext);
1031 //==============================================================================
1032 //function : RemoveView
1033 //purpose : Close and remove view from display, clear maps if neccessary
1034 //==============================================================================
1035 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1037 if (!ViewerTest_myViews.IsBound1(theViewName))
1039 cout << "Wrong view name\n";
1043 // Activate another view if it's active now
1044 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1046 if (ViewerTest_myViews.Extent() > 1)
1048 TCollection_AsciiString aNewViewName;
1049 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1050 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1051 if (anIter.Key1() != theViewName)
1053 aNewViewName = anIter.Key1();
1056 ActivateView (aNewViewName);
1060 Handle(V3d_View) anEmptyView;
1061 #if defined(_WIN32) || defined(__WIN32__)
1062 Handle(WNT_Window) anEmptyWindow;
1063 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1064 Handle(Cocoa_Window) anEmptyWindow;
1066 Handle(Xw_Window) anEmptyWindow;
1068 VT_GetWindow() = anEmptyWindow;
1069 ViewerTest::CurrentView (anEmptyView);
1070 if (isContextRemoved)
1072 Handle(AIS_InteractiveContext) anEmptyContext;
1073 ViewerTest::SetAISContext(anEmptyContext);
1079 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1080 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1082 // Remove view resources
1083 ViewerTest_myViews.UnBind1(theViewName);
1086 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1087 XFlush (GetDisplayConnection()->GetDisplay());
1090 // Keep context opened only if the closed view is last to avoid
1091 // unused empty contexts
1092 if (!aCurrentContext.IsNull())
1094 // Check if there are more difined views in the viewer
1095 aCurrentContext->CurrentViewer()->InitDefinedViews();
1096 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1098 // Remove driver if there is no viewers that use it
1099 Standard_Boolean isRemoveDriver = Standard_True;
1100 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1101 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1103 if (aCurrentContext != anIter.Key2() &&
1104 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1106 isRemoveDriver = Standard_False;
1112 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1113 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1114 #if TCL_MAJOR_VERSION < 8
1115 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1117 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1122 ViewerTest_myContexts.UnBind2(aCurrentContext);
1125 cout << "3D View - " << theViewName << " was deleted.\n";
1129 //==============================================================================
1131 //purpose : Remove the view defined by its name
1132 //==============================================================================
1134 static int VClose (Draw_Interpretor& /*theDi*/,
1135 Standard_Integer theArgsNb,
1136 const char** theArgVec)
1138 NCollection_List<TCollection_AsciiString> aViewList;
1141 TCollection_AsciiString anArg (theArgVec[1]);
1143 if (anArg.IsEqual ("ALL")
1144 || anArg.IsEqual ("*"))
1146 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1147 anIter.More(); anIter.Next())
1149 aViewList.Append (anIter.Key1());
1151 if (aViewList.IsEmpty())
1153 std::cout << "No view to close\n";
1159 ViewerTest_Names aViewName (theArgVec[1]);
1160 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1162 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1165 aViewList.Append (aViewName.GetViewName());
1170 // close active view
1171 if (ViewerTest::CurrentView().IsNull())
1173 std::cerr << "No active view!\n";
1176 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1179 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1180 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1181 anIter.More(); anIter.Next())
1183 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1189 //==============================================================================
1190 //function : VActivate
1191 //purpose : Activate the view defined by its ID
1192 //==============================================================================
1194 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1198 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1199 << "Usage: " << theArgVec[0] << " ViewID\n";
1204 theDi.Eval("vviewlist");
1208 TCollection_AsciiString aNameString(theArgVec[1]);
1209 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1211 TCollection_AsciiString aTitle("3D View - ");
1212 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1213 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1214 Handle(V3d_View) anEmptyView;
1215 #if defined(_WIN32) || defined(__WIN32__)
1216 Handle(WNT_Window) anEmptyWindow;
1217 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1218 Handle(Cocoa_Window) anEmptyWindow;
1220 Handle(Xw_Window) anEmptyWindow;
1222 VT_GetWindow() = anEmptyWindow;
1223 ViewerTest::CurrentView (anEmptyView);
1224 ViewerTest::ResetEventManager();
1225 theDi << theArgVec[0] << ": all views are inactive\n";
1229 ViewerTest_Names aViewNames(aNameString);
1231 // Check if this view exists in the viewer with the driver
1232 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1234 theDi << "Wrong view name\n";
1238 // Check if it is active already
1239 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1241 theDi << theArgVec[0] << ": the view is active already\n";
1245 ActivateView (aViewNames.GetViewName());
1249 //==============================================================================
1250 //function : VViewList
1251 //purpose : Print current list of views per viewer and graphic driver ID
1252 // shared between viewers
1253 //==============================================================================
1255 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1259 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1260 << "Usage: " << theArgVec[0] << " name";
1263 if (ViewerTest_myContexts.Size() < 1)
1266 Standard_Boolean isTreeView =
1267 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1270 theDi << theArgVec[0] <<":\n";
1272 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1273 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1276 theDi << aDriverIter.Key1() << ":\n";
1278 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1279 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1281 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1285 TCollection_AsciiString aContextName(aContextIter.Key1());
1286 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1289 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1290 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1292 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1294 TCollection_AsciiString aViewName(aViewIter.Key1());
1297 if (aViewIter.Value() == ViewerTest::CurrentView())
1298 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1300 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1304 theDi << aViewName << " ";
1314 //==============================================================================
1315 //function : VT_ProcessKeyPress
1316 //purpose : Handle KeyPress event from a CString
1317 //==============================================================================
1318 void VT_ProcessKeyPress (const char* buf_ret)
1320 //cout << "KeyPress" << endl;
1321 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1322 // Letter in alphabetic order
1324 if (!strcasecmp (buf_ret, "A"))
1327 aView->SetProj(V3d_XposYnegZpos);
1329 else if (!strcasecmp (buf_ret, "D"))
1334 else if (!strcasecmp (buf_ret, "F"))
1336 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1338 ViewerTest::GetAISContext()->FitSelected (aView);
1346 else if (!strcasecmp (buf_ret, "H"))
1349 cout << "HLR" << endl;
1350 aView->SetComputedMode (!aView->ComputedMode());
1351 MyHLRIsOn = aView->ComputedMode();
1353 else if (!strcasecmp (buf_ret, "P"))
1356 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1357 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1358 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1360 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1361 if (aContext->NbSelected()==0)
1363 AIS_ListOfInteractive aListOfShapes;
1364 aContext->DisplayedObjects(aListOfShapes);
1365 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1366 anIter.More(); anIter.Next())
1368 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1369 if (aShape.IsNull())
1371 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1372 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1374 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1375 aContext->Redisplay (aShape, Standard_False);
1380 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1382 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1383 if (aShape.IsNull())
1385 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1386 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1388 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1389 aContext->Redisplay (aShape, Standard_False);
1393 aContext->UpdateCurrentViewer();
1396 else if (!strcasecmp (buf_ret, "S"))
1398 std::cout << "setup Shaded display mode" << std::endl;
1400 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1401 if(Ctx->NbSelected()==0)
1402 Ctx->SetDisplayMode(AIS_Shaded);
1404 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1405 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1406 Ctx->UpdateCurrentViewer();
1409 else if (!strcasecmp (buf_ret, "U"))
1411 // Unset display mode
1412 std::cout << "reset display mode to defaults" << std::endl;
1414 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1415 if(Ctx->NbSelected()==0)
1416 Ctx->SetDisplayMode(AIS_WireFrame);
1418 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1419 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1420 Ctx->UpdateCurrentViewer();
1424 else if (!strcasecmp (buf_ret, "T"))
1427 aView->SetProj(V3d_Zpos);
1429 else if (!strcasecmp (buf_ret, "B"))
1432 aView->SetProj(V3d_Zneg);
1434 else if (!strcasecmp (buf_ret, "L"))
1437 aView->SetProj(V3d_Xneg);
1439 else if (!strcasecmp (buf_ret, "R"))
1442 aView->SetProj(V3d_Xpos);
1444 else if (!strcasecmp (buf_ret, "W"))
1446 std::cout << "setup WireFrame display mode" << std::endl;
1447 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1448 if(Ctx->NbSelected()==0)
1449 Ctx->SetDisplayMode(AIS_WireFrame);
1451 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1452 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1453 Ctx->UpdateCurrentViewer();
1456 else if (!strcasecmp (buf_ret, "Z"))
1460 cout << "ZClipping OFF" << endl;
1463 aView->SetZClippingType(V3d_OFF);
1467 cout << "ZClipping ON" << endl;
1470 aView->SetZClippingType(V3d_FRONT);
1474 else if (!strcasecmp (buf_ret, ","))
1476 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1478 else if (!strcasecmp (buf_ret, "."))
1480 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1482 else if (!strcasecmp (buf_ret, "/"))
1484 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1485 if (aCamera->IsStereo())
1487 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1491 else if (!strcasecmp (buf_ret, "*"))
1493 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1494 if (aCamera->IsStereo())
1496 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1500 else if (*buf_ret == THE_KEY_DELETE)
1502 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1504 && aCtx->NbSelected() > 0)
1506 Draw_Interprete ("verase");
1512 Standard_Integer Num = Draw::Atoi(buf_ret);
1513 if(Num>=0 && Num<=7)
1514 ViewerTest::StandardModeActivation(Num);
1518 //==============================================================================
1519 //function : VT_ProcessExpose
1520 //purpose : Redraw the View on an Expose Event
1521 //==============================================================================
1522 void VT_ProcessExpose()
1524 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1525 if (!aView3d.IsNull())
1531 //==============================================================================
1532 //function : VT_ProcessConfigure
1533 //purpose : Resize the View on an Configure Event
1534 //==============================================================================
1535 void VT_ProcessConfigure()
1537 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1538 if (aView3d.IsNull())
1543 aView3d->MustBeResized();
1548 //==============================================================================
1549 //function : VT_ProcessButton1Press
1551 //==============================================================================
1552 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1553 const char** theArgVec,
1554 Standard_Boolean theToPick,
1555 Standard_Boolean theIsShift)
1559 Standard_Real X, Y, Z;
1560 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1562 Draw::Set (theArgVec[1], X);
1563 Draw::Set (theArgVec[2], Y);
1564 Draw::Set (theArgVec[3], Z);
1569 ViewerTest::CurrentEventManager()->ShiftSelect();
1573 ViewerTest::CurrentEventManager()->Select();
1576 return Standard_False;
1579 //==============================================================================
1580 //function : VT_ProcessButton1Release
1581 //purpose : End selecting
1582 //==============================================================================
1583 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1587 IsDragged = Standard_False;
1588 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1591 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1592 X_Motion, Y_Motion);
1596 EM->Select (X_ButtonPress, Y_ButtonPress,
1597 X_Motion, Y_Motion);
1602 //==============================================================================
1603 //function : VT_ProcessButton3Press
1604 //purpose : Start Rotation
1605 //==============================================================================
1606 void VT_ProcessButton3Press()
1611 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1613 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1616 //==============================================================================
1617 //function : VT_ProcessButton3Release
1618 //purpose : End rotation
1619 //==============================================================================
1620 void VT_ProcessButton3Release()
1627 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1632 //==============================================================================
1633 //function : ProcessZClipMotion
1635 //==============================================================================
1637 void ProcessZClipMotion()
1639 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1640 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1642 //Quantity_Length VDX, VDY;
1643 //a3DView->Size(VDX,VDY);
1644 //Standard_Real VDZ = a3DView->ZSize();
1645 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1647 Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress);
1649 // Front = Depth + width/2.
1650 Standard_Real aDepth = 0.5;
1651 Standard_Real aWidth = 0.1;
1652 a3DView->ZClipping(aDepth,aWidth);
1656 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1658 a3DView->SetZClippingDepth(aDepth);
1662 X_ButtonPress = X_Motion;
1663 Y_ButtonPress = Y_Motion;
1667 //==============================================================================
1668 //function : ProcessControlButton1Motion
1670 //==============================================================================
1672 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1673 static void ProcessControlButton1Motion()
1675 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1677 X_ButtonPress = X_Motion;
1678 Y_ButtonPress = Y_Motion;
1682 //==============================================================================
1683 //function : VT_ProcessControlButton2Motion
1685 //==============================================================================
1686 void VT_ProcessControlButton2Motion()
1688 Standard_Integer aDx = X_Motion - X_ButtonPress;
1689 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1691 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1693 ViewerTest::CurrentView()->Pan (aDx, aDy);
1695 X_ButtonPress = X_Motion;
1696 Y_ButtonPress = Y_Motion;
1699 //==============================================================================
1700 //function : VT_ProcessControlButton3Motion
1701 //purpose : Rotation
1702 //==============================================================================
1703 void VT_ProcessControlButton3Motion()
1707 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1711 //==============================================================================
1712 //function : VT_ProcessMotion
1714 //==============================================================================
1715 void VT_ProcessMotion()
1717 //pre-hilights detected objects at mouse position
1719 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1720 EM->MoveTo(X_Motion, Y_Motion);
1724 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1726 Xpix = X_Motion;Ypix=Y_Motion;
1729 //==============================================================================
1730 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1731 //purpose : Switches to an axonometric, top, left and other views
1732 //==============================================================================
1734 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1736 if ( ViewerTest::CurrentView().IsNull() )
1738 di<<"Call vinit before this command, please"<<"\n";
1742 ViewerTest::CurrentView()->SetProj(ori);
1746 //==============================================================================
1748 //purpose : Switch to an Axonometric view
1749 //Draw arg : No args
1750 //==============================================================================
1752 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1754 return ViewProject(di, V3d_XposYnegZpos);
1757 //==============================================================================
1759 //purpose : Switch to a Top View
1760 //Draw arg : No args
1761 //==============================================================================
1763 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1765 return ViewProject(di, V3d_Zpos);
1768 //==============================================================================
1769 //function : VBottom
1770 //purpose : Switch to a Bottom View
1771 //Draw arg : No args
1772 //==============================================================================
1774 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1776 return ViewProject(di, V3d_Zneg);
1779 //==============================================================================
1781 //purpose : Switch to a Left View
1782 //Draw arg : No args
1783 //==============================================================================
1785 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1787 return ViewProject(di, V3d_Xneg);
1790 //==============================================================================
1792 //purpose : Switch to a Right View
1793 //Draw arg : No args
1794 //==============================================================================
1796 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1798 return ViewProject(di, V3d_Xpos);
1801 //==============================================================================
1803 //purpose : Switch to a Front View
1804 //Draw arg : No args
1805 //==============================================================================
1807 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1809 return ViewProject(di, V3d_Yneg);
1812 //==============================================================================
1814 //purpose : Switch to a Back View
1815 //Draw arg : No args
1816 //==============================================================================
1818 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1820 return ViewProject(di, V3d_Ypos);
1823 //==============================================================================
1825 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1826 //Draw arg : No args
1827 //==============================================================================
1829 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1832 di << "Q : Quit the application" << "\n";
1834 di << "========================="<<"\n";
1835 di << "F : FitAll" << "\n";
1836 di << "T : TopView" << "\n";
1837 di << "B : BottomView" << "\n";
1838 di << "R : RightView" << "\n";
1839 di << "L : LeftView" << "\n";
1840 di << "A : AxonometricView" << "\n";
1841 di << "D : ResetView" << "\n";
1843 di << "========================="<<"\n";
1844 di << "S : Shading" << "\n";
1845 di << "W : Wireframe" << "\n";
1846 di << "H : HidelLineRemoval" << "\n";
1847 di << "U : Unset display mode" << "\n";
1848 di << "Delete : Remove selection from viewer" << "\n";
1850 di << "========================="<<"\n";
1851 di << "Selection mode "<<"\n";
1852 di << "0 : Shape" <<"\n";
1853 di << "1 : Vertex" <<"\n";
1854 di << "2 : Edge" <<"\n";
1855 di << "3 : Wire" <<"\n";
1856 di << "4 : Face" <<"\n";
1857 di << "5 : Shell" <<"\n";
1858 di << "6 : Solid" <<"\n";
1859 di << "7 : Compound" <<"\n";
1861 di << "========================="<<"\n";
1862 di << "Z : Switch Z clipping On/Off" << "\n";
1863 di << ", : Hilight next detected" << "\n";
1864 di << ". : Hilight previous detected" << "\n";
1871 static Standard_Boolean Ppick = 0;
1872 static Standard_Integer Pargc = 0;
1873 static const char** Pargv = NULL;
1876 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1881 if (!ViewerTest_myViews.IsEmpty()) {
1883 WPARAM fwKeys = wParam;
1888 // Delete view from map of views
1889 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1894 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1895 || ViewerTest::CurrentView().IsNull())
1897 // Activate inactive window
1898 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1900 ActivateView (FindViewIdByWindowHandle(hwnd));
1907 HDC hdc = GetDC( hwnd );
1908 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1909 SetROP2( hdc, R2_NOT );
1910 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1911 ReleaseDC( hwnd, hdc );
1912 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1914 IsDragged = Standard_False;
1915 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1917 case WM_LBUTTONDOWN:
1918 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1920 IsDragged = Standard_True;
1921 DragFirst = Standard_True;
1922 X_ButtonPress = LOWORD(lParam);
1923 Y_ButtonPress = HIWORD(lParam);
1925 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1932 HDC hdc = GetDC( hwnd );
1934 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1935 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1936 SetROP2( hdc, R2_NOT );
1939 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1941 DragFirst = Standard_False;
1942 X_Motion = LOWORD(lParam);
1943 Y_Motion = HIWORD(lParam);
1945 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1947 SelectObject( hdc, anObj );
1949 ReleaseDC( hwnd, hdc );
1952 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1956 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1960 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1964 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1970 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
1973 return DefWindowProc( hwnd, Msg, wParam, lParam );
1980 BeginPaint(hwnd, &ps);
1981 EndPaint(hwnd, &ps);
1986 VT_ProcessConfigure();
1991 switch (aView->RenderingParams().StereoMode)
1993 case Graphic3d_StereoMode_RowInterlaced:
1994 case Graphic3d_StereoMode_ColumnInterlaced:
1995 case Graphic3d_StereoMode_ChessBoard:
1996 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2004 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2007 c[0] = (char) wParam;
2009 if (wParam == VK_DELETE)
2011 c[0] = THE_KEY_DELETE;
2014 else if (wParam == VK_OEM_COMMA)
2019 else if (wParam == VK_OEM_PERIOD)
2023 else if (wParam == VK_DIVIDE)
2028 else if (wParam == VK_MULTIPLY)
2032 VT_ProcessKeyPress (c);
2040 VT_ProcessButton3Release();
2043 case WM_LBUTTONDOWN:
2044 case WM_MBUTTONDOWN:
2045 case WM_RBUTTONDOWN:
2047 WPARAM fwKeys = wParam;
2051 X_ButtonPress = LOWORD(lParam);
2052 Y_ButtonPress = HIWORD(lParam);
2054 if (Msg == WM_LBUTTONDOWN)
2056 if (fwKeys & MK_CONTROL)
2058 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2062 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2065 else if (Msg == WM_RBUTTONDOWN)
2068 VT_ProcessButton3Press();
2075 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2076 if (wParam & MK_CONTROL)
2078 if (aView->Camera()->IsStereo())
2080 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2084 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2091 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2098 //cout << "\t WM_MOUSEMOVE" << endl;
2099 WPARAM fwKeys = wParam;
2100 X_Motion = LOWORD(lParam);
2101 Y_Motion = HIWORD(lParam);
2104 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2106 X_ButtonPress = LOWORD(lParam);
2107 Y_ButtonPress = HIWORD(lParam);
2109 if ( fwKeys & MK_RBUTTON ) {
2111 VT_ProcessButton3Press();
2115 if ( fwKeys & MK_CONTROL ) {
2116 if ( fwKeys & MK_LBUTTON ) {
2117 ProcessControlButton1Motion();
2119 else if ( fwKeys & MK_MBUTTON ||
2120 ((fwKeys&MK_LBUTTON) &&
2121 (fwKeys&MK_RBUTTON) ) ){
2122 VT_ProcessControlButton2Motion();
2124 else if ( fwKeys & MK_RBUTTON ) {
2125 VT_ProcessControlButton3Motion();
2129 else if ( fwKeys & MK_SHIFT ) {
2130 if ( fwKeys & MK_MBUTTON ||
2131 ((fwKeys&MK_LBUTTON) &&
2132 (fwKeys&MK_RBUTTON) ) ) {
2133 cout << "ProcessZClipMotion()" << endl;
2134 ProcessZClipMotion();
2138 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2140 if ((fwKeys & MK_MBUTTON
2141 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2143 ProcessZClipMotion();
2154 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2162 //==============================================================================
2163 //function : ViewerMainLoop
2164 //purpose : Get a Event on the view and dispatch it
2165 //==============================================================================
2168 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2170 Ppick = (argc > 0)? 1 : 0;
2178 cout << "Start picking" << endl;
2180 while ( Ppick == 1 ) {
2181 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2182 if (GetMessage(&msg, NULL, 0, 0) ) {
2183 TranslateMessage(&msg);
2184 DispatchMessage(&msg);
2188 cout << "Picking done" << endl;
2194 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2196 int min( int a, int b )
2204 int max( int a, int b )
2212 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2215 static XEvent aReport;
2216 Standard_Boolean pick = argc > 0;
2217 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2218 XNextEvent (aDisplay, &aReport);
2220 // Handle event for the chosen display connection
2221 switch (aReport.type) {
2224 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2227 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2233 // Activate inactive view
2234 Window aWindow = GetWindowHandle(VT_GetWindow());
2235 if(aWindow != aReport.xfocus.window)
2237 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2246 case ConfigureNotify:
2248 VT_ProcessConfigure();
2257 XComposeStatus status_in_out;
2259 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2260 (char *) buf_ret , 10 ,
2261 &ks_ret , &status_in_out ) ;
2264 buf_ret[ret_len] = '\0' ;
2268 VT_ProcessKeyPress (buf_ret);
2274 X_ButtonPress = aReport.xbutton.x;
2275 Y_ButtonPress = aReport.xbutton.y;
2277 if (aReport.xbutton.button == Button1)
2279 if (aReport.xbutton.state & ControlMask)
2281 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2285 IsDragged = Standard_True;
2286 DragFirst = Standard_True;
2289 else if (aReport.xbutton.button == Button3)
2292 VT_ProcessButton3Press();
2302 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2303 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2304 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2307 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2308 if( aContext.IsNull() )
2310 cout << "The context is null. Please use vinit before createmesh" << endl;
2314 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2315 if( aReport.xbutton.button==1 )
2319 aContext->ShiftSelect();
2328 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2329 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2330 ViewerTest::CurrentView());
2334 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2335 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2336 ViewerTest::CurrentView() );
2339 VT_ProcessButton3Release();
2341 IsDragged = Standard_False;
2344 VT_ProcessButton3Release();
2349 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2355 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2356 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2357 XSetFunction( aDisplay, gc, GXinvert );
2360 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2362 X_Motion = aReport.xmotion.x;
2363 Y_Motion = aReport.xmotion.y;
2364 DragFirst = Standard_False;
2366 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2370 X_Motion = aReport.xmotion.x;
2371 Y_Motion = aReport.xmotion.y;
2373 // remove all the ButtonMotionMaskr
2374 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2376 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2377 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2379 Quantity_Length VDX, VDY;
2381 ViewerTest::CurrentView()->Size(VDX,VDY);
2382 Standard_Real VDZ =0 ;
2383 VDZ = ViewerTest::CurrentView()->ZSize();
2385 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2387 Quantity_Length dx = 0 ;
2388 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2392 dx = dx / VDX * VDZ;
2396 ViewerTest::CurrentView()->Redraw();
2400 if ( aReport.xmotion.state & ControlMask ) {
2401 if ( aReport.xmotion.state & Button1Mask ) {
2402 ProcessControlButton1Motion();
2404 else if ( aReport.xmotion.state & Button2Mask ) {
2405 VT_ProcessControlButton2Motion();
2407 else if ( aReport.xmotion.state & Button3Mask ) {
2408 VT_ProcessControlButton3Motion();
2422 //==============================================================================
2423 //function : VProcessEvents
2424 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2425 // event in the Viewer window
2426 //==============================================================================
2428 static void VProcessEvents(ClientData,int)
2430 NCollection_Vector<int> anEventNumbers;
2431 // Get number of messages from every display
2432 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2433 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2435 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2437 // Handle events for every display
2438 int anEventIter = 0;
2439 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2440 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2442 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2443 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2445 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2446 int anEventResult = ViewerMainLoop( 0, NULL);
2447 // If window is closed or context was not found finish current event processing loop
2453 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2458 //==============================================================================
2459 //function : OSWindowSetup
2460 //purpose : Setup for the X11 window to be able to cath the event
2461 //==============================================================================
2464 static void OSWindowSetup()
2466 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2469 Window window = VT_GetWindow()->XWindow();
2470 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2471 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2472 XSynchronize(aDisplay, 1);
2474 // X11 : For keyboard on SUN
2476 wmhints.flags = InputHint;
2479 XSetWMHints( aDisplay, window, &wmhints);
2481 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2482 ButtonPressMask | ButtonReleaseMask |
2483 StructureNotifyMask |
2485 Button1MotionMask | Button2MotionMask |
2486 Button3MotionMask | FocusChangeMask
2488 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2489 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2491 XSynchronize(aDisplay, 0);
2499 //==============================================================================
2502 //purpose : Fitall, no DRAW arguments
2503 //Draw arg : No args
2504 //==============================================================================
2506 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv)
2510 std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl;
2513 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2517 TCollection_AsciiString anArg (theArgv[1]);
2519 if (anArg == "-selected")
2521 ViewerTest::GetAISContext()->FitSelected (aView);
2525 if (aView.IsNull() == Standard_False) {
2532 //=======================================================================
2533 //function : VFitArea
2534 //purpose : Fit view to show area located between two points
2535 // : given in world 2D or 3D coordinates.
2536 //=======================================================================
2537 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2539 Handle(V3d_View) aView = ViewerTest::CurrentView();
2542 std::cerr << theArgVec[0] << "Error: No active view.\n";
2547 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2548 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2552 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2553 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2554 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2555 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2557 else if (theArgNb == 7)
2559 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2560 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2561 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2562 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2563 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2564 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2568 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2569 theDI.PrintHelp(theArgVec[0]);
2573 // Convert model coordinates to view space
2574 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2575 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2576 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2578 // Determine fit area
2579 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2580 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2582 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2584 if (aDiagonal < Precision::Confusion())
2586 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2590 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2594 //==============================================================================
2596 //purpose : ZFitall, no DRAW arguments
2597 //Draw arg : No args
2598 //==============================================================================
2599 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2601 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2603 if (aCurrentView.IsNull())
2605 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2611 aCurrentView->View()->ZFitAll();
2612 aCurrentView->Redraw();
2616 Standard_Real aScale = 1.0;
2620 aScale = Draw::Atoi (theArgVec[1]);
2623 aCurrentView->View()->ZFitAll (aScale);
2624 aCurrentView->Redraw();
2629 //==============================================================================
2630 //function : VRepaint
2632 //==============================================================================
2633 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2635 Handle(V3d_View) V = ViewerTest::CurrentView();
2636 if ( !V.IsNull() ) V->Redraw(); return 0;
2639 //==============================================================================
2641 //purpose : Remove all the object from the viewer
2642 //Draw arg : No args
2643 //==============================================================================
2645 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2647 Handle(V3d_View) V = ViewerTest::CurrentView();
2649 ViewerTest::Clear();
2653 //==============================================================================
2656 //==============================================================================
2658 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2659 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2662 di << argv[0] << "Invalid number of arguments" << "\n";
2666 while (ViewerMainLoop( argc, argv)) {
2672 //==============================================================================
2674 //purpose : Load image as background
2675 //==============================================================================
2677 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2679 if (argc < 2 || argc > 3)
2681 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2682 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2686 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2687 if(AISContext.IsNull())
2689 di << "use 'vinit' command before " << argv[0] << "\n";
2693 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2696 const char* szType = argv[2];
2697 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2698 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2699 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2700 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2703 di << "Wrong fill type : " << szType << "\n";
2704 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2709 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2710 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2715 //==============================================================================
2716 //function : VSetBgMode
2717 //purpose : Change background image fill type
2718 //==============================================================================
2720 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2724 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2725 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2729 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2730 if(AISContext.IsNull())
2732 di << "use 'vinit' command before " << argv[0] << "\n";
2735 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2736 const char* szType = argv[1];
2737 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2738 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2739 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2740 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2743 di << "Wrong fill type : " << szType << "\n";
2744 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2747 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2748 V3dView->SetBgImageStyle(aFillType, Standard_True);
2752 //==============================================================================
2753 //function : VSetGradientBg
2754 //purpose : Mount gradient background
2755 //==============================================================================
2756 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2760 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2761 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2762 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2763 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2767 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2768 if(AISContext.IsNull())
2770 di << "use 'vinit' command before " << argv[0] << "\n";
2776 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2777 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2778 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2779 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2781 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2782 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2783 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2785 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2786 int aType = Draw::Atoi(argv[7]);
2787 if( aType < 0 || aType > 8 )
2789 di << "Wrong fill type " << "\n";
2790 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2791 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2795 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2797 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2798 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2804 //==============================================================================
2805 //function : VSetGradientBgMode
2806 //purpose : Change gradient background fill style
2807 //==============================================================================
2808 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2812 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2813 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2814 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2818 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2819 if(AISContext.IsNull())
2821 di << "use 'vinit' command before " << argv[0] << "\n";
2826 int aType = Draw::Atoi(argv[1]);
2827 if( aType < 0 || aType > 8 )
2829 di << "Wrong fill type " << "\n";
2830 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2831 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2835 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2837 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2838 V3dView->SetBgGradientStyle( aMethod, 1 );
2844 //==============================================================================
2845 //function : VSetColorBg
2846 //purpose : Set color background
2847 //==============================================================================
2848 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2852 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2853 di << "R,G,B = [0..255]" << "\n";
2857 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2858 if(AISContext.IsNull())
2860 di << "use 'vinit' command before " << argv[0] << "\n";
2866 Standard_Real R = Draw::Atof(argv[1])/255.;
2867 Standard_Real G = Draw::Atof(argv[2])/255.;
2868 Standard_Real B = Draw::Atof(argv[3])/255.;
2869 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2871 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2872 V3dView->SetBackgroundColor( aColor );
2879 //==============================================================================
2880 //function : VSetDefaultBg
2881 //purpose : Set default viewer background fill color
2882 //==============================================================================
2883 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2888 std::cout << "Error: wrong syntax! See usage:\n";
2889 theDI.PrintHelp (theArgVec[0]);
2893 ViewerTest_DefaultBackground.FillMethod =
2894 theArgNb == 4 ? Aspect_GFM_NONE
2895 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
2899 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
2900 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
2901 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
2902 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
2906 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
2907 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
2908 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
2909 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
2911 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
2912 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
2913 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
2914 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
2917 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2918 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
2920 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
2921 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
2922 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
2923 ViewerTest_DefaultBackground.GradientColor2,
2924 ViewerTest_DefaultBackground.FillMethod);
2930 //==============================================================================
2932 //purpose : View Scaling
2933 //==============================================================================
2935 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2937 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2938 if ( V3dView.IsNull() ) return 1;
2941 di << argv[0] << "Invalid number of arguments" << "\n";
2944 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2947 //==============================================================================
2948 //function : VZBuffTrihedron
2950 //==============================================================================
2952 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2953 Standard_Integer theArgNb,
2954 const char** theArgVec)
2956 Handle(V3d_View) aView = ViewerTest::CurrentView();
2959 std::cout << "Error: no active viewer!\n";
2963 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2965 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2966 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2967 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2968 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2969 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2970 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2971 Standard_Real aScale = 0.1;
2972 Standard_Real aSizeRatio = 0.8;
2973 Standard_Real anArrowDiam = 0.05;
2974 Standard_Integer aNbFacets = 12;
2975 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2977 Standard_CString anArg = theArgVec[anArgIter];
2978 TCollection_AsciiString aFlag (anArg);
2980 if (anUpdateTool.parseRedrawMode (aFlag))
2984 else if (aFlag == "-on")
2988 else if (aFlag == "-off")
2990 aView->TriedronErase();
2993 else if (aFlag == "-pos"
2994 || aFlag == "-position"
2995 || aFlag == "-corner")
2997 if (++anArgIter >= theArgNb)
2999 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3003 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3004 aPosName.LowerCase();
3005 if (aPosName == "center")
3007 aPosition = Aspect_TOTP_CENTER;
3009 else if (aPosName == "left_lower"
3010 || aPosName == "lower_left"
3011 || aPosName == "leftlower"
3012 || aPosName == "lowerleft")
3014 aPosition = Aspect_TOTP_LEFT_LOWER;
3016 else if (aPosName == "left_upper"
3017 || aPosName == "upper_left"
3018 || aPosName == "leftupper"
3019 || aPosName == "upperleft")
3021 aPosition = Aspect_TOTP_LEFT_UPPER;
3023 else if (aPosName == "right_lower"
3024 || aPosName == "lower_right"
3025 || aPosName == "rightlower"
3026 || aPosName == "lowerright")
3028 aPosition = Aspect_TOTP_RIGHT_LOWER;
3030 else if (aPosName == "right_upper"
3031 || aPosName == "upper_right"
3032 || aPosName == "rightupper"
3033 || aPosName == "upperright")
3035 aPosition = Aspect_TOTP_RIGHT_UPPER;
3039 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3043 else if (aFlag == "-type")
3045 if (++anArgIter >= theArgNb)
3047 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3051 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3052 aTypeName.LowerCase();
3053 if (aTypeName == "wireframe"
3054 || aTypeName == "wire")
3056 aVisType = V3d_WIREFRAME;
3058 else if (aTypeName == "zbuffer"
3059 || aTypeName == "shaded")
3061 aVisType = V3d_ZBUFFER;
3065 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3068 else if (aFlag == "-scale")
3070 if (++anArgIter >= theArgNb)
3072 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3076 aScale = Draw::Atof (theArgVec[anArgIter]);
3078 else if (aFlag == "-size"
3079 || aFlag == "-sizeratio")
3081 if (++anArgIter >= theArgNb)
3083 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3087 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3089 else if (aFlag == "-arrowdiam"
3090 || aFlag == "-arrowdiameter")
3092 if (++anArgIter >= theArgNb)
3094 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3098 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3100 else if (aFlag == "-nbfacets")
3102 if (++anArgIter >= theArgNb)
3104 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3108 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3110 else if (aFlag == "-colorlabel"
3111 || aFlag == "-colorlabels")
3113 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3114 theArgVec + anArgIter + 1,
3118 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3121 anArgIter += aNbParsed;
3123 else if (aFlag == "-colorarrowx")
3125 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3126 theArgVec + anArgIter + 1,
3130 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3133 anArgIter += aNbParsed;
3135 else if (aFlag == "-colorarrowy")
3137 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3138 theArgVec + anArgIter + 1,
3142 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3145 anArgIter += aNbParsed;
3147 else if (aFlag == "-colorarrowz")
3149 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3150 theArgVec + anArgIter + 1,
3154 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3157 anArgIter += aNbParsed;
3161 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3166 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3167 aSizeRatio, anArrowDiam, aNbFacets);
3168 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3169 aView->View()->ZFitAll();
3173 //==============================================================================
3174 //function : VRotate
3175 //purpose : Camera Rotating
3176 //==============================================================================
3178 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3180 Handle(V3d_View) aView = ViewerTest::CurrentView();
3183 std::cout << "No active view!\n";
3187 Standard_Boolean hasFlags = Standard_False;
3188 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3190 Standard_CString anArg (theArgVec[anArgIter]);
3191 TCollection_AsciiString aFlag (anArg);
3193 if (aFlag == "-mousestart"
3194 || aFlag == "-mousefrom")
3196 hasFlags = Standard_True;
3197 if (anArgIter + 2 >= theArgNb)
3199 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3203 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3204 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3205 aView->StartRotation (anX, anY);
3207 else if (aFlag == "-mousemove")
3209 hasFlags = Standard_True;
3210 if (anArgIter + 2 >= theArgNb)
3212 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3216 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3217 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3218 aView->Rotation (anX, anY);
3220 else if (theArgNb != 4
3223 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3232 else if (theArgNb == 4)
3234 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3235 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3236 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3237 aView->Rotate (anAX, anAY, anAZ);
3240 else if (theArgNb == 7)
3242 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3243 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3244 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3246 Standard_Real anX = Draw::Atof (theArgVec[4]);
3247 Standard_Real anY = Draw::Atof (theArgVec[5]);
3248 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3250 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3254 std::cout << "Error: Invalid number of arguments\n";
3258 //==============================================================================
3260 //purpose : View zoom in / out (relative to current zoom)
3261 //==============================================================================
3263 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3264 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3265 if ( V3dView.IsNull() ) {
3270 Standard_Real coef = Draw::Atof(argv[1]);
3271 if ( coef <= 0.0 ) {
3272 di << argv[1] << "Invalid value" << "\n";
3275 V3dView->SetZoom( Draw::Atof(argv[1]) );
3278 di << argv[0] << " Invalid number of arguments" << "\n";
3283 //==============================================================================
3285 //purpose : View panning (in pixels)
3286 //==============================================================================
3288 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3289 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3290 if ( V3dView.IsNull() ) return 1;
3293 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3296 di << argv[0] << " Invalid number of arguments" << "\n";
3301 //==============================================================================
3303 //purpose : Place the point (in pixels) at the center of the window
3304 //==============================================================================
3305 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3307 Handle(V3d_View) aView = ViewerTest::CurrentView();
3310 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3316 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3320 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3325 //==============================================================================
3326 //function : VExport
3327 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3328 //==============================================================================
3330 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3332 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3333 if (V3dView.IsNull())
3338 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3342 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3343 TCollection_AsciiString aFormatStr;
3345 TCollection_AsciiString aFileName (argv[1]);
3346 Standard_Integer aLen = aFileName.Length();
3350 aFormatStr = TCollection_AsciiString (argv[2]);
3354 if (aFileName.Value (aLen - 2) == '.')
3356 aFormatStr = aFileName.ToCString() + aLen - 2;
3358 else if (aFileName.Value (aLen - 3) == '.')
3360 aFormatStr = aFileName.ToCString() + aLen - 3;
3364 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3370 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3374 aFormatStr.UpperCase();
3375 if (aFormatStr == "PS")
3376 anExpFormat = Graphic3d_EF_PostScript;
3377 else if (aFormatStr == "EPS")
3378 anExpFormat = Graphic3d_EF_EnhPostScript;
3379 else if (aFormatStr == "TEX")
3380 anExpFormat = Graphic3d_EF_TEX;
3381 else if (aFormatStr == "PDF")
3382 anExpFormat = Graphic3d_EF_PDF;
3383 else if (aFormatStr == "SVG")
3384 anExpFormat = Graphic3d_EF_SVG;
3385 else if (aFormatStr == "PGF")
3386 anExpFormat = Graphic3d_EF_PGF;
3387 else if (aFormatStr == "EMF")
3388 anExpFormat = Graphic3d_EF_EMF;
3391 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3396 if (!V3dView->View()->Export (argv[1], anExpFormat))
3398 di << "Error: export of image to " << aFormatStr << " failed!\n";
3401 catch (Standard_Failure)
3403 di << "Error: export of image to " << aFormatStr << " failed";
3404 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3409 //==============================================================================
3410 //function : VColorScale
3411 //purpose : representation color scale
3412 //==============================================================================
3414 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3415 const TCollection_AsciiString& theGreen,
3416 const TCollection_AsciiString& theBlue,
3417 Standard_Real& theRedValue,
3418 Standard_Real& theGreenValue,
3419 Standard_Real& theBlueValue)
3421 if (!theRed.IsRealValue()
3422 || !theGreen.IsRealValue()
3423 || !theBlue.IsRealValue())
3425 std::cout << "Error: RGB color values should be real!\n";
3426 return Standard_True;
3428 theRedValue = theRed .RealValue();
3429 theGreenValue = theGreen.RealValue();
3430 theBlueValue = theBlue .RealValue();
3431 if (theRedValue < 0.0 || theRedValue > 1.0
3432 || theGreenValue < 0.0 || theGreenValue > 1.0
3433 || theBlueValue < 0.0 || theBlueValue > 1.0)
3435 std::cout << "Error: RGB color values should be within range 0..1!\n";
3436 return Standard_True;
3438 return Standard_False;
3441 static int VColorScale (Draw_Interpretor& theDI,
3442 Standard_Integer theArgNb,
3443 const char** theArgVec)
3445 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3446 Handle(V3d_View) aView = ViewerTest::CurrentView();
3447 if (aContext.IsNull())
3449 std::cout << "Error: no active view!\n";
3453 Handle(AIS_ColorScale) aCS;
3455 Handle(AIS_InteractiveObject) anIObj;
3456 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3458 aCS = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3461 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3467 aCS = new AIS_ColorScale();
3468 GetMapOfAIS().Bind (aCS,theArgVec[1]);
3471 if (aCS->ZLayer() != Graphic3d_ZLayerId_TopOSD)
3473 aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3475 if (aCS->GetTransformPersistenceMode() != Graphic3d_TMF_2d)
3477 aCS->SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt (-1,-1,0));
3480 Standard_Real aMinRange = aCS->GetMin();
3481 Standard_Real aMaxRange = aCS->GetMax();
3482 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3483 Standard_Integer aTextHeight = aCS->GetTextHeight();
3484 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();