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_Shape.hxx>
19 #include <AIS_InteractiveObject.hxx>
20 #include <AIS_ListOfInteractive.hxx>
21 #include <AIS_ListIteratorOfListOfInteractive.hxx>
23 #include <Graphic3d_AspectMarker3d.hxx>
24 #include <Graphic3d_ExportFormat.hxx>
25 #include <Graphic3d_NameOfTextureEnv.hxx>
26 #include <Graphic3d_GraduatedTrihedron.hxx>
27 #include <Graphic3d_TextureEnv.hxx>
28 #include <Graphic3d_TextureParams.hxx>
29 #include <Graphic3d_TypeOfTextureFilter.hxx>
30 #include <Graphic3d_AspectFillArea3d.hxx>
31 #include <ViewerTest.hxx>
32 #include <ViewerTest_AutoUpdater.hxx>
33 #include <ViewerTest_EventManager.hxx>
34 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
35 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
36 #include <Visual3d_View.hxx>
37 #include <Visual3d_ViewManager.hxx>
38 #include <V3d_AmbientLight.hxx>
39 #include <V3d_ColorScale.hxx>
40 #include <V3d_DirectionalLight.hxx>
41 #include <V3d_LayerMgr.hxx>
42 #include <V3d_LayerMgrPointer.hxx>
43 #include <V3d_PositionalLight.hxx>
44 #include <V3d_SpotLight.hxx>
45 #include <NCollection_DoubleMap.hxx>
46 #include <NCollection_List.hxx>
47 #include <NCollection_Vector.hxx>
48 #include <AIS_InteractiveContext.hxx>
49 #include <Draw_Interpretor.hxx>
51 #include <Draw_Appli.hxx>
52 #include <Aspect_PrintAlgo.hxx>
53 #include <Image_AlienPixMap.hxx>
54 #include <OpenGl_GraphicDriver.hxx>
55 #include <OSD_Timer.hxx>
56 #include <TColStd_HSequenceOfAsciiString.hxx>
57 #include <TColStd_SequenceOfInteger.hxx>
58 #include <TColStd_HSequenceOfReal.hxx>
59 #include <TColgp_Array1OfPnt2d.hxx>
60 #include <TColStd_MapOfAsciiString.hxx>
61 #include <Visual3d_LayerItem.hxx>
62 #include <Aspect_TypeOfLine.hxx>
63 #include <Image_Diff.hxx>
64 #include <Aspect_DisplayConnection.hxx>
68 #include <PrsMgr_PresentableObject.hxx>
69 #include <Graphic3d_ClipPlane.hxx>
70 #include <NCollection_DataMap.hxx>
71 #include <Graphic3d_Texture2Dmanual.hxx>
72 #include <Prs3d_ShadingAspect.hxx>
73 #include <Prs3d_Drawer.hxx>
79 #include <Visual3d_Layer.hxx>
83 #include <WNT_WClass.hxx>
84 #include <WNT_Window.hxx>
87 #define _CRT_SECURE_NO_DEPRECATE
88 #pragma warning (disable:4996)
90 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
91 #include <Cocoa_Window.hxx>
93 #include <Xw_Window.hxx>
94 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
95 #include <X11/Xutil.h>
99 inline Standard_Boolean parseOnOff (Standard_CString theArg,
100 Standard_Boolean& theIsOn)
102 TCollection_AsciiString aFlag (theArg);
107 theIsOn = Standard_True;
108 return Standard_True;
110 else if (aFlag == "off"
113 theIsOn = Standard_False;
114 return Standard_True;
116 return Standard_False;
119 // Auxiliary definitions
120 static const char THE_KEY_DELETE = 127;
122 //==============================================================================
123 // VIEWER GLOBAL VARIABLES
124 //==============================================================================
126 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
127 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
129 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
130 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
132 extern int VErase (Draw_Interpretor& theDI,
133 Standard_Integer theArgNb,
134 const char** theArgVec);
137 static Handle(WNT_Window)& VT_GetWindow() {
138 static Handle(WNT_Window) WNTWin;
141 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
142 static Handle(Cocoa_Window)& VT_GetWindow()
144 static Handle(Cocoa_Window) aWindow;
147 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
148 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
149 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
152 static Handle(Xw_Window)& VT_GetWindow(){
153 static Handle(Xw_Window) XWWin;
157 static void VProcessEvents(ClientData,int);
160 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
162 static Handle(Aspect_DisplayConnection) aDisplayConnection;
163 return aDisplayConnection;
166 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
168 GetDisplayConnection() = theDisplayConnection;
171 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
172 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
174 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
176 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
177 if (!aWindow.IsNull())
178 return aWindow->HWindow();
179 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
180 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
181 if (!aWindow.IsNull())
182 return aWindow->XWindow();
184 return aWindowHandle;
188 static Standard_Boolean MyHLRIsOn = Standard_False;
190 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
191 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
192 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
193 static OpenGl_Caps ViewerTest_myDefaultCaps;
195 #define ZCLIPWIDTH 1.
197 static void OSWindowSetup();
199 //==============================================================================
200 // EVENT GLOBAL VARIABLES
201 //==============================================================================
203 static int Start_Rot = 0;
204 static int ZClipIsOn = 0;
205 int X_Motion = 0; // Current cursor position
207 int X_ButtonPress = 0; // Last ButtonPress position
208 int Y_ButtonPress = 0;
209 Standard_Boolean IsDragged = Standard_False;
210 Standard_Boolean DragFirst = Standard_False;
212 //==============================================================================
215 static LRESULT WINAPI ViewerWindowProc(
220 static LRESULT WINAPI AdvViewerWindowProc(
228 //==============================================================================
231 //==============================================================================
233 const Handle(MMgt_TShared)& ViewerTest::WClass()
235 static Handle(MMgt_TShared) theWClass;
237 if (theWClass.IsNull())
239 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
240 CS_VREDRAW | CS_HREDRAW, 0, 0,
241 ::LoadCursor (NULL, IDC_ARROW));
247 //==============================================================================
248 //function : CreateName
249 //purpose : Create numerical name for new object in theMap
250 //==============================================================================
251 template <typename ObjectType>
252 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
253 const TCollection_AsciiString& theDefaultString)
255 if (theObjectMap.IsEmpty())
256 return theDefaultString + TCollection_AsciiString(1);
258 Standard_Integer aNextKey = 1;
259 Standard_Boolean isFound = Standard_False;
262 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
263 // Look for objects with default names
264 if (theObjectMap.IsBound1(aStringKey))
269 isFound = Standard_True;
272 return theDefaultString + TCollection_AsciiString(aNextKey);
275 //==============================================================================
276 //structure : ViewerTest_Names
277 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
278 //==============================================================================
279 struct ViewerTest_Names
282 TCollection_AsciiString myDriverName;
283 TCollection_AsciiString myViewerName;
284 TCollection_AsciiString myViewName;
288 const TCollection_AsciiString& GetDriverName () const
292 void SetDriverName (const TCollection_AsciiString& theDriverName)
294 myDriverName = theDriverName;
296 const TCollection_AsciiString& GetViewerName () const
300 void SetViewerName (const TCollection_AsciiString& theViewerName)
302 myViewerName = theViewerName;
304 const TCollection_AsciiString& GetViewName () const
308 void SetViewName (const TCollection_AsciiString& theViewName)
310 myViewName = theViewName;
313 //===========================================================================
314 //function : Constructor for ViewerTest_Names
315 //purpose : Get view, viewer, driver names from custom string
316 //===========================================================================
318 ViewerTest_Names (const TCollection_AsciiString& theInputString)
320 TCollection_AsciiString aName(theInputString);
321 if (theInputString.IsEmpty())
323 // Get current configuration
324 if (ViewerTest_myDrivers.IsEmpty())
325 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
326 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
328 myDriverName = ViewerTest_myDrivers.Find2
329 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
331 if(ViewerTest_myContexts.IsEmpty())
333 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
334 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
337 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
339 myViewName = CreateName <Handle(V3d_View)>
340 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
344 // There is at least view name
345 Standard_Integer aParserNumber = 0;
346 for (Standard_Integer i = 0; i < 3; ++i)
348 Standard_Integer aParserPos = aName.SearchFromEnd("/");
352 aName.Split(aParserPos-1);
357 if (aParserNumber == 0)
360 if (!ViewerTest::GetAISContext().IsNull())
362 myDriverName = ViewerTest_myDrivers.Find2
363 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
364 myViewerName = ViewerTest_myContexts.Find2
365 (ViewerTest::GetAISContext());
369 // There is no opened contexts here, need to create names for viewer and driver
370 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
371 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
373 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
374 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
376 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
378 else if (aParserNumber == 1)
380 // Here is viewerName/viewName
381 if (!ViewerTest::GetAISContext().IsNull())
382 myDriverName = ViewerTest_myDrivers.Find2
383 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
386 // There is no opened contexts here, need to create name for driver
387 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
388 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
390 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
392 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
396 //Here is driverName/viewerName/viewName
397 myDriverName = TCollection_AsciiString(aName);
399 TCollection_AsciiString aViewerName(theInputString);
400 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
401 myViewerName = TCollection_AsciiString(aViewerName);
403 myViewName = TCollection_AsciiString(theInputString);
409 //==============================================================================
410 //function : FindContextByView
411 //purpose : Find AIS_InteractiveContext by View
412 //==============================================================================
414 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
416 Handle(AIS_InteractiveContext) anAISContext;
418 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
419 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
421 if (anIter.Value()->CurrentViewer() == theView->Viewer())
422 return anIter.Key2();
428 //==============================================================================
429 //function : SetWindowTitle
430 //purpose : Set window title
431 //==============================================================================
433 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
434 Standard_CString theTitle)
437 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
439 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
440 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
442 if(GetDisplayConnection()->GetDisplay())
445 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
446 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
451 //==============================================================================
452 //function : IsWindowOverlapped
453 //purpose : Check if theWindow overlapp another view
454 //==============================================================================
456 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
457 const Standard_Integer thePxTop,
458 const Standard_Integer thePxRight,
459 const Standard_Integer thePxBottom,
460 TCollection_AsciiString& theViewId)
462 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
463 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
465 Standard_Integer aTop = 0,
469 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
470 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
471 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
472 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
473 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
475 theViewId = anIter.Key1();
476 return Standard_True;
479 return Standard_False;
482 // Workaround: to create and delete non-orthographic views outside ViewerTest
483 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
485 ViewerTest_myViews.UnBind1 (theName);
488 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
489 const Handle(V3d_View)& theView)
491 ViewerTest_myViews.Bind (theName, theView);
494 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
496 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
498 //==============================================================================
499 //function : ViewerInit
500 //purpose : Create the window viewer and initialize all the global variable
501 //==============================================================================
503 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
504 const Standard_Integer thePxTop,
505 const Standard_Integer thePxWidth,
506 const Standard_Integer thePxHeight,
507 Standard_CString theViewName,
508 Standard_CString theDisplayName)
510 // Default position and dimension of the viewer window.
511 // Note that left top corner is set to be sufficiently small to have
512 // window fit in the small screens (actual for remote desktops, see #23003).
513 // The position corresponds to the window's client area, thus some
514 // gap is added for window frame to be visible.
515 Standard_Integer aPxLeft = 20;
516 Standard_Integer aPxTop = 40;
517 Standard_Integer aPxWidth = 409;
518 Standard_Integer aPxHeight = 409;
519 Standard_Boolean toCreateViewer = Standard_False;
521 Handle(OpenGl_GraphicDriver) aGraphicDriver;
522 ViewerTest_Names aViewNames(theViewName);
523 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
524 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
531 aPxWidth = thePxWidth;
532 if (thePxHeight != 0)
533 aPxHeight = thePxHeight;
535 // Get graphic driver (create it or get from another view)
536 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
538 // Get connection string
539 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
540 TCollection_AsciiString aDisplayName(theDisplayName);
541 if (!aDisplayName.IsEmpty())
542 SetDisplayConnection (new Aspect_DisplayConnection ());
544 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
546 (void)theDisplayName; // avoid warning on unused argument
547 SetDisplayConnection (new Aspect_DisplayConnection ());
549 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
550 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
551 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
552 toCreateViewer = Standard_True;
556 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
559 //Dispose the window if input parameters are default
560 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
562 Standard_Integer aTop = 0,
569 // Get screen resolution
570 #if defined(_WIN32) || defined(__WIN32__)
572 GetClientRect(GetDesktopWindow(), &aWindowSize);
573 aScreenHeight = aWindowSize.bottom;
574 aScreenWidth = aWindowSize.right;
575 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
576 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
578 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
579 aScreenWidth = WidthOfScreen(aScreen);
580 aScreenHeight = HeightOfScreen(aScreen);
583 TCollection_AsciiString anOverlappedViewId("");
585 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
587 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
589 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
590 && aRight + 2*aPxWidth + 40 > aScreenWidth)
592 if (aBottom + aPxHeight + 40 > aScreenHeight)
599 aPxTop = aBottom + 40;
602 aPxLeft = aRight + 20;
607 TCollection_AsciiString aTitle("3D View - ");
608 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
610 // Change name of current active window
611 if (!ViewerTest::CurrentView().IsNull())
613 TCollection_AsciiString aTitle("3D View - ");
615 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
616 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
620 Handle(V3d_Viewer) a3DViewer;
621 // If it's the single view, we first look for empty context
622 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
624 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
625 anIter(ViewerTest_myContexts);
627 ViewerTest::SetAISContext (anIter.Value());
628 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
630 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
632 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
633 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
635 else if (a3DViewer.IsNull())
637 toCreateViewer = Standard_True;
638 TCollection_ExtendedString NameOfWindow("Viewer3D");
639 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
641 NameOfWindow = TCollection_ExtendedString("Collector");
643 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
647 if (ViewerTest::GetAISContext().IsNull() ||
648 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
650 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
651 ViewerTest::SetAISContext (aContext);
652 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
656 ViewerTest::ResetEventManager();
661 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
662 Handle(WNT_WClass)::DownCast (WClass()),
663 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
667 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
668 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
670 aPxWidth, aPxHeight);
671 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
673 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
676 aPxWidth, aPxHeight);
678 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
681 Handle(V3d_View) aView = a3DViewer->CreateView();
682 aView->SetWindow (VT_GetWindow());
684 ViewerTest::CurrentView(aView);
685 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
687 // Setup for X11 or NT
690 // Set parameters for V3d_View and V3d_Viewer
691 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
692 aV3dView->SetComputedMode(Standard_False);
693 MyHLRIsOn = aV3dView->ComputedMode();
694 aV3dView->SetZClippingDepth(0.5);
695 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
697 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
700 a3DViewer->SetDefaultLights();
701 a3DViewer->SetLightOn();
704 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
705 #if TCL_MAJOR_VERSION < 8
706 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
707 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
709 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
710 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
714 VT_GetWindow()->Map();
716 // Set the handle of created view in the event manager
717 ViewerTest::ResetEventManager();
719 ViewerTest::CurrentView()->Redraw();
724 return aViewNames.GetViewName();
727 //==============================================================================
728 //function : RedrawAllViews
729 //purpose : Redraw all created views
730 //==============================================================================
731 void ViewerTest::RedrawAllViews()
733 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
734 for (; aViewIt.More(); aViewIt.Next())
736 const Handle(V3d_View)& aView = aViewIt.Key2();
741 //==============================================================================
743 //purpose : Create the window viewer and initialize all the global variable
744 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
745 //==============================================================================
747 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
751 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
752 << "Type help for more information.\n";
756 TCollection_AsciiString aViewName, aDisplayName;
757 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
758 TCollection_AsciiString aName, aValue;
759 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
761 const TCollection_AsciiString anArg = theArgVec[anArgIt];
762 TCollection_AsciiString anArgCase = anArg;
763 anArgCase.UpperCase();
764 if (ViewerTest::SplitParameter (anArg, aName, aValue))
767 if (aName.IsEqual ("NAME"))
771 else if (aName.IsEqual ("L")
772 || aName.IsEqual ("LEFT"))
774 aPxLeft = aValue.IntegerValue();
776 else if (aName.IsEqual ("T")
777 || aName.IsEqual ("TOP"))
779 aPxTop = aValue.IntegerValue();
781 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
782 else if (aName.IsEqual ("DISP")
783 || aName.IsEqual ("DISPLAY"))
785 aDisplayName = aValue;
788 else if (aName.IsEqual ("W")
789 || aName.IsEqual ("WIDTH"))
791 aPxWidth = aValue.IntegerValue();
793 else if (aName.IsEqual ("H")
794 || aName.IsEqual ("HEIGHT"))
796 aPxHeight = aValue.IntegerValue();
800 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
803 else if (aViewName.IsEmpty())
809 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
813 ViewerTest_Names aViewNames (aViewName);
814 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
816 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
817 theDi.Eval (aCommand.ToCString());
821 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
822 aViewName.ToCString(),
823 aDisplayName.ToCString());
828 //==============================================================================
830 //purpose : hidden lines removal algorithm
831 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
832 //==============================================================================
834 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
836 if (ViewerTest::CurrentView().IsNull())
838 di << argv[0] << ": Call vinit before this command, please.\n";
844 di << argv[0] << ": Wrong number of command arguments.\n"
845 << "Type help " << argv[0] << " for more information.\n";
849 // Enable or disable HLR mode.
850 Standard_Boolean isHLROn =
851 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
853 if (isHLROn != MyHLRIsOn)
856 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
859 // Show or hide hidden lines in HLR mode.
860 Standard_Boolean isCurrentShowHidden
861 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
863 Standard_Boolean isShowHidden =
864 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
865 : isCurrentShowHidden;
868 if (isShowHidden != isCurrentShowHidden)
872 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
876 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
882 AIS_ListOfInteractive aListOfShapes;
883 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
885 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
887 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
892 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
897 ViewerTest::CurrentView()->Update();
901 //==============================================================================
902 //function : VHLRType
903 //purpose : change type of using HLR algorithm
904 //==============================================================================
906 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
908 if (ViewerTest::CurrentView().IsNull())
910 di << argv[0] << ": Call vinit before this command, please.\n";
916 di << argv[0] << ": Wrong number of command arguments.\n"
917 << "Type help " << argv[0] << " for more information.\n";
921 Prs3d_TypeOfHLR aTypeOfHLR =
922 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
926 AIS_ListOfInteractive aListOfShapes;
927 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
928 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
929 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
930 anIter.More(); anIter.Next())
932 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
935 if (aShape->TypeOfHLR() != aTypeOfHLR)
936 aShape->SetTypeOfHLR (aTypeOfHLR);
938 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
940 ViewerTest::CurrentView()->Update();
945 for (Standard_Integer i = 2; i < argc; ++i)
947 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
948 TCollection_AsciiString aName (argv[i]);
950 if (!aMap.IsBound2 (aName))
952 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
955 Handle(AIS_Shape) anAISObject =
956 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
957 if (anAISObject.IsNull())
959 anAISObject->SetTypeOfHLR (aTypeOfHLR);
961 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
963 ViewerTest::CurrentView()->Update();
969 //==============================================================================
970 //function : FindViewIdByWindowHandle
971 //purpose : Find theView Id in the map of views by window handle
972 //==============================================================================
973 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
974 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
976 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
977 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
979 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
980 if (aWindowHandle == theWindowHandle)
981 return anIter.Key1();
983 return TCollection_AsciiString("");
987 //==============================================================================
988 //function : ActivateView
989 //purpose : Make the view active
990 //==============================================================================
992 void ActivateView (const TCollection_AsciiString& theViewName)
994 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
997 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
998 if (!anAISContext.IsNull())
1000 if (!ViewerTest::CurrentView().IsNull())
1002 TCollection_AsciiString aTitle("3D View - ");
1003 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1004 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1007 ViewerTest::CurrentView (aView);
1008 // Update degenerate mode
1009 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
1010 ViewerTest::SetAISContext (anAISContext);
1011 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1012 aTitle = aTitle + theViewName + "(*)";
1013 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1014 #if defined(_WIN32) || defined(__WIN32__)
1015 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1016 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1017 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1019 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1021 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1022 ViewerTest::CurrentView()->Redraw();
1027 //==============================================================================
1028 //function : RemoveView
1030 //==============================================================================
1031 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1032 const Standard_Boolean theToRemoveContext)
1034 if (!ViewerTest_myViews.IsBound2 (theView))
1039 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1040 RemoveView (aViewName, theToRemoveContext);
1043 //==============================================================================
1044 //function : RemoveView
1045 //purpose : Close and remove view from display, clear maps if neccessary
1046 //==============================================================================
1047 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1049 if (!ViewerTest_myViews.IsBound1(theViewName))
1051 cout << "Wrong view name\n";
1055 // Activate another view if it's active now
1056 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1058 if (ViewerTest_myViews.Extent() > 1)
1060 TCollection_AsciiString aNewViewName;
1061 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1062 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1063 if (anIter.Key1() != theViewName)
1065 aNewViewName = anIter.Key1();
1068 ActivateView (aNewViewName);
1072 Handle(V3d_View) anEmptyView;
1073 #if defined(_WIN32) || defined(__WIN32__)
1074 Handle(WNT_Window) anEmptyWindow;
1075 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1076 Handle(Cocoa_Window) anEmptyWindow;
1078 Handle(Xw_Window) anEmptyWindow;
1080 VT_GetWindow() = anEmptyWindow;
1081 ViewerTest::CurrentView (anEmptyView);
1082 if (isContextRemoved)
1084 Handle(AIS_InteractiveContext) anEmptyContext;
1085 ViewerTest::SetAISContext(anEmptyContext);
1091 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1092 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1094 // Remove view resources
1095 ViewerTest_myViews.UnBind1(theViewName);
1098 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1099 XFlush (GetDisplayConnection()->GetDisplay());
1102 // Keep context opened only if the closed view is last to avoid
1103 // unused empty contexts
1104 if (!aCurrentContext.IsNull())
1106 // Check if there are more difined views in the viewer
1107 aCurrentContext->CurrentViewer()->InitDefinedViews();
1108 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1110 // Remove driver if there is no viewers that use it
1111 Standard_Boolean isRemoveDriver = Standard_True;
1112 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1113 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1115 if (aCurrentContext != anIter.Key2() &&
1116 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1118 isRemoveDriver = Standard_False;
1124 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1125 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1126 #if TCL_MAJOR_VERSION < 8
1127 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1129 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1134 ViewerTest_myContexts.UnBind2(aCurrentContext);
1137 cout << "3D View - " << theViewName << " was deleted.\n";
1141 //==============================================================================
1143 //purpose : Remove the view defined by its name
1144 //==============================================================================
1146 static int VClose (Draw_Interpretor& /*theDi*/,
1147 Standard_Integer theArgsNb,
1148 const char** theArgVec)
1150 NCollection_List<TCollection_AsciiString> aViewList;
1153 TCollection_AsciiString anArg (theArgVec[1]);
1155 if (anArg.IsEqual ("ALL")
1156 || anArg.IsEqual ("*"))
1158 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1159 anIter.More(); anIter.Next())
1161 aViewList.Append (anIter.Key1());
1163 if (aViewList.IsEmpty())
1165 std::cout << "No view to close\n";
1171 ViewerTest_Names aViewName (theArgVec[1]);
1172 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1174 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1177 aViewList.Append (aViewName.GetViewName());
1182 // close active view
1183 if (ViewerTest::CurrentView().IsNull())
1185 std::cerr << "No active view!\n";
1188 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1191 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1192 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1193 anIter.More(); anIter.Next())
1195 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1201 //==============================================================================
1202 //function : VActivate
1203 //purpose : Activate the view defined by its ID
1204 //==============================================================================
1206 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1210 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1211 << "Usage: " << theArgVec[0] << " ViewID\n";
1216 theDi.Eval("vviewlist");
1220 TCollection_AsciiString aNameString(theArgVec[1]);
1221 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1223 TCollection_AsciiString aTitle("3D View - ");
1224 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1225 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1226 Handle(V3d_View) anEmptyView;
1227 #if defined(_WIN32) || defined(__WIN32__)
1228 Handle(WNT_Window) anEmptyWindow;
1229 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1230 Handle(Cocoa_Window) anEmptyWindow;
1232 Handle(Xw_Window) anEmptyWindow;
1234 VT_GetWindow() = anEmptyWindow;
1235 ViewerTest::CurrentView (anEmptyView);
1236 ViewerTest::ResetEventManager();
1237 theDi << theArgVec[0] << ": all views are inactive\n";
1241 ViewerTest_Names aViewNames(aNameString);
1243 // Check if this view exists in the viewer with the driver
1244 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1246 theDi << "Wrong view name\n";
1250 // Check if it is active already
1251 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1253 theDi << theArgVec[0] << ": the view is active already\n";
1257 ActivateView (aViewNames.GetViewName());
1261 //==============================================================================
1262 //function : VViewList
1263 //purpose : Print current list of views per viewer and graphic driver ID
1264 // shared between viewers
1265 //==============================================================================
1267 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1271 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1272 << "Usage: " << theArgVec[0] << " name";
1275 if (ViewerTest_myContexts.Size() < 1)
1278 Standard_Boolean isTreeView =
1279 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1282 theDi << theArgVec[0] <<":\n";
1284 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1285 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1288 theDi << aDriverIter.Key1() << ":\n";
1290 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1291 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1293 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1297 TCollection_AsciiString aContextName(aContextIter.Key1());
1298 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1301 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1302 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1304 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1306 TCollection_AsciiString aViewName(aViewIter.Key1());
1309 if (aViewIter.Value() == ViewerTest::CurrentView())
1310 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1312 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1316 theDi << aViewName << " ";
1326 //==============================================================================
1327 //function : VT_ProcessKeyPress
1328 //purpose : Handle KeyPress event from a CString
1329 //==============================================================================
1330 void VT_ProcessKeyPress (const char* buf_ret)
1332 //cout << "KeyPress" << endl;
1333 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1334 // Letter in alphabetic order
1336 if (!strcasecmp (buf_ret, "A"))
1339 aView->SetProj(V3d_XposYnegZpos);
1341 else if (!strcasecmp (buf_ret, "D"))
1346 else if (!strcasecmp (buf_ret, "F"))
1348 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1350 ViewerTest::GetAISContext()->FitSelected (aView);
1358 else if (!strcasecmp (buf_ret, "H"))
1361 cout << "HLR" << endl;
1362 aView->SetComputedMode (!aView->ComputedMode());
1363 MyHLRIsOn = aView->ComputedMode();
1365 else if (!strcasecmp (buf_ret, "P"))
1368 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1369 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1370 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1372 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1373 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1375 AIS_ListOfInteractive aListOfShapes;
1376 aContext->DisplayedObjects(aListOfShapes);
1377 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1378 anIter.More(); anIter.Next())
1380 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1381 if (aShape.IsNull())
1383 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1384 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1386 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1387 aContext->Redisplay (aShape, Standard_False);
1392 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1394 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1395 if (aShape.IsNull())
1397 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1398 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1400 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1401 aContext->Redisplay (aShape, Standard_False);
1405 aContext->UpdateCurrentViewer();
1408 else if (!strcasecmp (buf_ret, "S"))
1410 std::cout << "setup Shaded display mode" << std::endl;
1412 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1413 if(Ctx->NbCurrents()==0 ||
1414 Ctx->NbSelected()==0)
1415 Ctx->SetDisplayMode(AIS_Shaded);
1417 if(Ctx->HasOpenedContext()){
1418 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1419 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1422 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1423 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1425 Ctx->UpdateCurrentViewer();
1428 else if (!strcasecmp (buf_ret, "U"))
1430 // Unset display mode
1431 std::cout << "reset display mode to defaults" << std::endl;
1433 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1434 if(Ctx->NbCurrents()==0 ||
1435 Ctx->NbSelected()==0)
1436 Ctx->SetDisplayMode(AIS_WireFrame);
1438 if(Ctx->HasOpenedContext()){
1439 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1440 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1443 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1444 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1446 Ctx->UpdateCurrentViewer();
1450 else if (!strcasecmp (buf_ret, "T"))
1453 aView->SetProj(V3d_Zpos);
1455 else if (!strcasecmp (buf_ret, "B"))
1458 aView->SetProj(V3d_Zneg);
1460 else if (!strcasecmp (buf_ret, "L"))
1463 aView->SetProj(V3d_Xneg);
1465 else if (!strcasecmp (buf_ret, "R"))
1468 aView->SetProj(V3d_Xpos);
1470 else if (!strcasecmp (buf_ret, "W"))
1472 std::cout << "setup WireFrame display mode" << std::endl;
1473 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1474 if(Ctx->NbCurrents()==0 ||
1475 Ctx->NbSelected()==0)
1476 Ctx->SetDisplayMode(AIS_WireFrame);
1478 if(Ctx->HasOpenedContext()){
1479 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1480 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1483 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1484 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1486 Ctx->UpdateCurrentViewer();
1489 else if (!strcasecmp (buf_ret, "Z"))
1493 cout << "ZClipping OFF" << endl;
1496 aView->SetZClippingType(V3d_OFF);
1500 cout << "ZClipping ON" << endl;
1503 aView->SetZClippingType(V3d_FRONT);
1507 else if (!strcasecmp (buf_ret, ","))
1509 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1511 else if (!strcasecmp (buf_ret, "."))
1513 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1515 else if (!strcasecmp (buf_ret, "/"))
1517 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1518 if (aCamera->IsStereo())
1520 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1524 else if (!strcasecmp (buf_ret, "*"))
1526 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1527 if (aCamera->IsStereo())
1529 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1533 else if (*buf_ret == THE_KEY_DELETE)
1535 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1537 && aCtx->NbCurrents() > 0
1538 && aCtx->NbSelected() > 0)
1540 Draw_Interprete ("verase");
1546 Standard_Integer Num = Draw::Atoi(buf_ret);
1547 if(Num>=0 && Num<=7)
1548 ViewerTest::StandardModeActivation(Num);
1552 //==============================================================================
1553 //function : VT_ProcessExpose
1554 //purpose : Redraw the View on an Expose Event
1555 //==============================================================================
1556 void VT_ProcessExpose()
1558 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1559 if (!aView3d.IsNull())
1565 //==============================================================================
1566 //function : VT_ProcessConfigure
1567 //purpose : Resize the View on an Configure Event
1568 //==============================================================================
1569 void VT_ProcessConfigure()
1571 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1572 if (aView3d.IsNull())
1577 aView3d->MustBeResized();
1582 //==============================================================================
1583 //function : VT_ProcessButton1Press
1585 //==============================================================================
1586 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1587 const char** theArgVec,
1588 Standard_Boolean theToPick,
1589 Standard_Boolean theIsShift)
1593 Standard_Real X, Y, Z;
1594 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1596 Draw::Set (theArgVec[1], X);
1597 Draw::Set (theArgVec[2], Y);
1598 Draw::Set (theArgVec[3], Z);
1603 ViewerTest::CurrentEventManager()->ShiftSelect();
1607 ViewerTest::CurrentEventManager()->Select();
1610 return Standard_False;
1613 //==============================================================================
1614 //function : VT_ProcessButton1Release
1615 //purpose : End selecting
1616 //==============================================================================
1617 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1621 IsDragged = Standard_False;
1622 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1625 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1626 X_Motion, Y_Motion);
1630 EM->Select (X_ButtonPress, Y_ButtonPress,
1631 X_Motion, Y_Motion);
1636 //==============================================================================
1637 //function : VT_ProcessButton3Press
1638 //purpose : Start Rotation
1639 //==============================================================================
1640 void VT_ProcessButton3Press()
1645 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1647 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1650 //==============================================================================
1651 //function : VT_ProcessButton3Release
1652 //purpose : End rotation
1653 //==============================================================================
1654 void VT_ProcessButton3Release()
1661 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1666 //==============================================================================
1667 //function : ProcessZClipMotion
1669 //==============================================================================
1671 void ProcessZClipMotion()
1673 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1674 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1676 //Quantity_Length VDX, VDY;
1677 //a3DView->Size(VDX,VDY);
1678 //Standard_Real VDZ = a3DView->ZSize();
1679 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1681 Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress);
1683 // Front = Depth + width/2.
1684 Standard_Real aDepth = 0.5;
1685 Standard_Real aWidth = 0.1;
1686 a3DView->ZClipping(aDepth,aWidth);
1690 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1692 a3DView->SetZClippingDepth(aDepth);
1696 X_ButtonPress = X_Motion;
1697 Y_ButtonPress = Y_Motion;
1701 //==============================================================================
1702 //function : ProcessControlButton1Motion
1704 //==============================================================================
1706 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1707 static void ProcessControlButton1Motion()
1709 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1711 X_ButtonPress = X_Motion;
1712 Y_ButtonPress = Y_Motion;
1716 //==============================================================================
1717 //function : VT_ProcessControlButton2Motion
1719 //==============================================================================
1720 void VT_ProcessControlButton2Motion()
1722 Standard_Integer aDx = X_Motion - X_ButtonPress;
1723 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1725 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1727 ViewerTest::CurrentView()->Pan (aDx, aDy);
1729 X_ButtonPress = X_Motion;
1730 Y_ButtonPress = Y_Motion;
1733 //==============================================================================
1734 //function : VT_ProcessControlButton3Motion
1735 //purpose : Rotation
1736 //==============================================================================
1737 void VT_ProcessControlButton3Motion()
1741 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1745 //==============================================================================
1746 //function : VT_ProcessMotion
1748 //==============================================================================
1749 void VT_ProcessMotion()
1751 //pre-hilights detected objects at mouse position
1753 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1754 EM->MoveTo(X_Motion, Y_Motion);
1758 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1760 Xpix = X_Motion;Ypix=Y_Motion;
1763 //==============================================================================
1764 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1765 //purpose : Switches to an axonometric, top, left and other views
1766 //==============================================================================
1768 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1770 if ( ViewerTest::CurrentView().IsNull() )
1772 di<<"Call vinit before this command, please"<<"\n";
1776 ViewerTest::CurrentView()->SetProj(ori);
1780 //==============================================================================
1782 //purpose : Switch to an Axonometric view
1783 //Draw arg : No args
1784 //==============================================================================
1786 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1788 return ViewProject(di, V3d_XposYnegZpos);
1791 //==============================================================================
1793 //purpose : Switch to a Top View
1794 //Draw arg : No args
1795 //==============================================================================
1797 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1799 return ViewProject(di, V3d_Zpos);
1802 //==============================================================================
1803 //function : VBottom
1804 //purpose : Switch to a Bottom View
1805 //Draw arg : No args
1806 //==============================================================================
1808 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1810 return ViewProject(di, V3d_Zneg);
1813 //==============================================================================
1815 //purpose : Switch to a Left View
1816 //Draw arg : No args
1817 //==============================================================================
1819 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1821 return ViewProject(di, V3d_Ypos);
1824 //==============================================================================
1826 //purpose : Switch to a Right View
1827 //Draw arg : No args
1828 //==============================================================================
1830 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1832 return ViewProject(di, V3d_Yneg);
1835 //==============================================================================
1837 //purpose : Switch to a Front View
1838 //Draw arg : No args
1839 //==============================================================================
1841 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1843 return ViewProject(di, V3d_Xpos);
1846 //==============================================================================
1848 //purpose : Switch to a Back View
1849 //Draw arg : No args
1850 //==============================================================================
1852 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1854 return ViewProject(di, V3d_Xneg);
1857 //==============================================================================
1859 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1860 //Draw arg : No args
1861 //==============================================================================
1863 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1866 di << "Q : Quit the application" << "\n";
1868 di << "========================="<<"\n";
1869 di << "F : FitAll" << "\n";
1870 di << "T : TopView" << "\n";
1871 di << "B : BottomView" << "\n";
1872 di << "R : RightView" << "\n";
1873 di << "L : LeftView" << "\n";
1874 di << "A : AxonometricView" << "\n";
1875 di << "D : ResetView" << "\n";
1877 di << "========================="<<"\n";
1878 di << "S : Shading" << "\n";
1879 di << "W : Wireframe" << "\n";
1880 di << "H : HidelLineRemoval" << "\n";
1881 di << "U : Unset display mode" << "\n";
1882 di << "Delete : Remove selection from viewer" << "\n";
1884 di << "========================="<<"\n";
1885 di << "Selection mode "<<"\n";
1886 di << "0 : Shape" <<"\n";
1887 di << "1 : Vertex" <<"\n";
1888 di << "2 : Edge" <<"\n";
1889 di << "3 : Wire" <<"\n";
1890 di << "4 : Face" <<"\n";
1891 di << "5 : Shell" <<"\n";
1892 di << "6 : Solid" <<"\n";
1893 di << "7 : Compound" <<"\n";
1895 di << "========================="<<"\n";
1896 di << "Z : Switch Z clipping On/Off" << "\n";
1897 di << ", : Hilight next detected" << "\n";
1898 di << ". : Hilight previous detected" << "\n";
1905 static Standard_Boolean Ppick = 0;
1906 static Standard_Integer Pargc = 0;
1907 static const char** Pargv = NULL;
1910 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1915 if (!ViewerTest_myViews.IsEmpty()) {
1917 WPARAM fwKeys = wParam;
1922 // Delete view from map of views
1923 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1928 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1929 || ViewerTest::CurrentView().IsNull())
1931 // Activate inactive window
1932 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1934 ActivateView (FindViewIdByWindowHandle(hwnd));
1941 HDC hdc = GetDC( hwnd );
1942 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1943 SetROP2( hdc, R2_NOT );
1944 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1945 ReleaseDC( hwnd, hdc );
1946 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1948 IsDragged = Standard_False;
1949 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1951 case WM_LBUTTONDOWN:
1952 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1954 IsDragged = Standard_True;
1955 DragFirst = Standard_True;
1956 X_ButtonPress = LOWORD(lParam);
1957 Y_ButtonPress = HIWORD(lParam);
1959 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1966 HDC hdc = GetDC( hwnd );
1968 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1969 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1970 SetROP2( hdc, R2_NOT );
1973 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1975 DragFirst = Standard_False;
1976 X_Motion = LOWORD(lParam);
1977 Y_Motion = HIWORD(lParam);
1979 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1981 SelectObject( hdc, anObj );
1983 ReleaseDC( hwnd, hdc );
1986 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1990 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1994 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1998 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2004 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2007 return DefWindowProc( hwnd, Msg, wParam, lParam );
2014 BeginPaint(hwnd, &ps);
2015 EndPaint(hwnd, &ps);
2020 VT_ProcessConfigure();
2025 switch (aView->RenderingParams().StereoMode)
2027 case Graphic3d_StereoMode_RowInterlaced:
2028 case Graphic3d_StereoMode_ColumnInterlaced:
2029 case Graphic3d_StereoMode_ChessBoard:
2030 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2038 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2041 c[0] = (char) wParam;
2043 if (wParam == VK_DELETE)
2045 c[0] = THE_KEY_DELETE;
2048 else if (wParam == VK_OEM_COMMA)
2053 else if (wParam == VK_OEM_PERIOD)
2057 else if (wParam == VK_DIVIDE)
2062 else if (wParam == VK_MULTIPLY)
2066 VT_ProcessKeyPress (c);
2074 VT_ProcessButton3Release();
2077 case WM_LBUTTONDOWN:
2078 case WM_MBUTTONDOWN:
2079 case WM_RBUTTONDOWN:
2081 WPARAM fwKeys = wParam;
2085 X_ButtonPress = LOWORD(lParam);
2086 Y_ButtonPress = HIWORD(lParam);
2088 if (Msg == WM_LBUTTONDOWN)
2090 if (fwKeys & MK_CONTROL)
2092 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2096 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2099 else if (Msg == WM_RBUTTONDOWN)
2102 VT_ProcessButton3Press();
2109 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2110 if (wParam & MK_CONTROL)
2112 if (aView->Camera()->IsStereo())
2114 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2118 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2125 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2132 //cout << "\t WM_MOUSEMOVE" << endl;
2133 WPARAM fwKeys = wParam;
2134 X_Motion = LOWORD(lParam);
2135 Y_Motion = HIWORD(lParam);
2138 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2140 X_ButtonPress = LOWORD(lParam);
2141 Y_ButtonPress = HIWORD(lParam);
2143 if ( fwKeys & MK_RBUTTON ) {
2145 VT_ProcessButton3Press();
2149 if ( fwKeys & MK_CONTROL ) {
2150 if ( fwKeys & MK_LBUTTON ) {
2151 ProcessControlButton1Motion();
2153 else if ( fwKeys & MK_MBUTTON ||
2154 ((fwKeys&MK_LBUTTON) &&
2155 (fwKeys&MK_RBUTTON) ) ){
2156 VT_ProcessControlButton2Motion();
2158 else if ( fwKeys & MK_RBUTTON ) {
2159 VT_ProcessControlButton3Motion();
2163 else if ( fwKeys & MK_SHIFT ) {
2164 if ( fwKeys & MK_MBUTTON ||
2165 ((fwKeys&MK_LBUTTON) &&
2166 (fwKeys&MK_RBUTTON) ) ) {
2167 cout << "ProcessZClipMotion()" << endl;
2168 ProcessZClipMotion();
2172 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2174 if ((fwKeys & MK_MBUTTON
2175 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2177 ProcessZClipMotion();
2188 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2196 //==============================================================================
2197 //function : ViewerMainLoop
2198 //purpose : Get a Event on the view and dispatch it
2199 //==============================================================================
2202 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2204 Ppick = (argc > 0)? 1 : 0;
2212 cout << "Start picking" << endl;
2214 while ( Ppick == 1 ) {
2215 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2216 if (GetMessage(&msg, NULL, 0, 0) ) {
2217 TranslateMessage(&msg);
2218 DispatchMessage(&msg);
2222 cout << "Picking done" << endl;
2228 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2230 int min( int a, int b )
2238 int max( int a, int b )
2246 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2249 static XEvent aReport;
2250 Standard_Boolean pick = argc > 0;
2251 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2252 XNextEvent (aDisplay, &aReport);
2254 // Handle event for the chosen display connection
2255 switch (aReport.type) {
2258 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2261 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2267 // Activate inactive view
2268 Window aWindow = GetWindowHandle(VT_GetWindow());
2269 if(aWindow != aReport.xfocus.window)
2271 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2280 case ConfigureNotify:
2282 VT_ProcessConfigure();
2291 XComposeStatus status_in_out;
2293 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2294 (char *) buf_ret , 10 ,
2295 &ks_ret , &status_in_out ) ;
2298 buf_ret[ret_len] = '\0' ;
2302 VT_ProcessKeyPress (buf_ret);
2308 X_ButtonPress = aReport.xbutton.x;
2309 Y_ButtonPress = aReport.xbutton.y;
2311 if (aReport.xbutton.button == Button1)
2313 if (aReport.xbutton.state & ControlMask)
2315 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2319 IsDragged = Standard_True;
2320 DragFirst = Standard_True;
2323 else if (aReport.xbutton.button == Button3)
2326 VT_ProcessButton3Press();
2336 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2337 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2338 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2341 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2342 if( aContext.IsNull() )
2344 cout << "The context is null. Please use vinit before createmesh" << endl;
2348 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2349 if( aReport.xbutton.button==1 )
2353 aContext->ShiftSelect();
2362 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2363 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2364 ViewerTest::CurrentView());
2368 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2369 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2370 ViewerTest::CurrentView() );
2373 VT_ProcessButton3Release();
2375 IsDragged = Standard_False;
2378 VT_ProcessButton3Release();
2383 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2389 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2390 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2391 XSetFunction( aDisplay, gc, GXinvert );
2394 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2396 X_Motion = aReport.xmotion.x;
2397 Y_Motion = aReport.xmotion.y;
2398 DragFirst = Standard_False;
2400 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2404 X_Motion = aReport.xmotion.x;
2405 Y_Motion = aReport.xmotion.y;
2407 // remove all the ButtonMotionMaskr
2408 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2410 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2411 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2413 Quantity_Length VDX, VDY;
2415 ViewerTest::CurrentView()->Size(VDX,VDY);
2416 Standard_Real VDZ =0 ;
2417 VDZ = ViewerTest::CurrentView()->ZSize();
2419 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2421 Quantity_Length dx = 0 ;
2422 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2426 dx = dx / VDX * VDZ;
2430 ViewerTest::CurrentView()->Redraw();
2434 if ( aReport.xmotion.state & ControlMask ) {
2435 if ( aReport.xmotion.state & Button1Mask ) {
2436 ProcessControlButton1Motion();
2438 else if ( aReport.xmotion.state & Button2Mask ) {
2439 VT_ProcessControlButton2Motion();
2441 else if ( aReport.xmotion.state & Button3Mask ) {
2442 VT_ProcessControlButton3Motion();
2456 //==============================================================================
2457 //function : VProcessEvents
2458 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2459 // event in the Viewer window
2460 //==============================================================================
2462 static void VProcessEvents(ClientData,int)
2464 NCollection_Vector<int> anEventNumbers;
2465 // Get number of messages from every display
2466 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2467 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2469 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2471 // Handle events for every display
2472 int anEventIter = 0;
2473 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2474 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2476 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2477 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2479 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2480 int anEventResult = ViewerMainLoop( 0, NULL);
2481 // If window is closed or context was not found finish current event processing loop
2487 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2492 //==============================================================================
2493 //function : OSWindowSetup
2494 //purpose : Setup for the X11 window to be able to cath the event
2495 //==============================================================================
2498 static void OSWindowSetup()
2500 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2503 Window window = VT_GetWindow()->XWindow();
2504 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2505 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2506 XSynchronize(aDisplay, 1);
2508 // X11 : For keyboard on SUN
2510 wmhints.flags = InputHint;
2513 XSetWMHints( aDisplay, window, &wmhints);
2515 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2516 ButtonPressMask | ButtonReleaseMask |
2517 StructureNotifyMask |
2519 Button1MotionMask | Button2MotionMask |
2520 Button3MotionMask | FocusChangeMask
2522 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2523 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2525 XSynchronize(aDisplay, 0);
2533 //==============================================================================
2536 //purpose : Fitall, no DRAW arguments
2537 //Draw arg : No args
2538 //==============================================================================
2540 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv)
2544 std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl;
2547 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2551 TCollection_AsciiString anArg (theArgv[1]);
2553 if (anArg == "-selected")
2555 ViewerTest::GetAISContext()->FitSelected (aView);
2559 if (aView.IsNull() == Standard_False) {
2566 //=======================================================================
2567 //function : VFitArea
2568 //purpose : Fit view to show area located between two points
2569 // : given in world 2D or 3D coordinates.
2570 //=======================================================================
2571 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2573 Handle(V3d_View) aView = ViewerTest::CurrentView();
2576 std::cerr << theArgVec[0] << "Error: No active view.\n";
2581 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2582 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2586 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2587 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2588 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2589 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2591 else if (theArgNb == 7)
2593 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2594 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2595 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2596 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2597 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2598 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2602 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2603 theDI.PrintHelp(theArgVec[0]);
2607 // Convert model coordinates to view space
2608 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2609 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2610 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2612 // Determine fit area
2613 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2614 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2616 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2618 if (aDiagonal < Precision::Confusion())
2620 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2624 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2628 //==============================================================================
2630 //purpose : ZFitall, no DRAW arguments
2631 //Draw arg : No args
2632 //==============================================================================
2633 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2635 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2637 if (aCurrentView.IsNull())
2639 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2645 aCurrentView->View()->ZFitAll();
2646 aCurrentView->Redraw();
2650 Standard_Real aScale = 1.0;
2654 aScale = Draw::Atoi (theArgVec[1]);
2657 aCurrentView->View()->ZFitAll (aScale);
2658 aCurrentView->Redraw();
2663 //==============================================================================
2664 //function : VRepaint
2666 //==============================================================================
2667 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2669 Handle(V3d_View) V = ViewerTest::CurrentView();
2670 if ( !V.IsNull() ) V->Redraw(); return 0;
2673 //==============================================================================
2675 //purpose : Remove all the object from the viewer
2676 //Draw arg : No args
2677 //==============================================================================
2679 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2681 Handle(V3d_View) V = ViewerTest::CurrentView();
2683 ViewerTest::Clear();
2687 //==============================================================================
2690 //==============================================================================
2692 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2693 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2696 di << argv[0] << "Invalid number of arguments" << "\n";
2700 while (ViewerMainLoop( argc, argv)) {
2706 //==============================================================================
2708 //purpose : Load image as background
2709 //==============================================================================
2711 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2713 if (argc < 2 || argc > 3)
2715 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2716 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2720 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2721 if(AISContext.IsNull())
2723 di << "use 'vinit' command before " << argv[0] << "\n";
2727 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2730 const char* szType = argv[2];
2731 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2732 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2733 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2734 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2737 di << "Wrong fill type : " << szType << "\n";
2738 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2743 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2744 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2749 //==============================================================================
2750 //function : VSetBgMode
2751 //purpose : Change background image fill type
2752 //==============================================================================
2754 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2758 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2759 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2763 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2764 if(AISContext.IsNull())
2766 di << "use 'vinit' command before " << argv[0] << "\n";
2769 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2770 const char* szType = argv[1];
2771 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2772 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2773 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2774 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2777 di << "Wrong fill type : " << szType << "\n";
2778 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2781 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2782 V3dView->SetBgImageStyle(aFillType, Standard_True);
2786 //==============================================================================
2787 //function : VSetGradientBg
2788 //purpose : Mount gradient background
2789 //==============================================================================
2790 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2794 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2795 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2796 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2797 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2801 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2802 if(AISContext.IsNull())
2804 di << "use 'vinit' command before " << argv[0] << "\n";
2810 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2811 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2812 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2813 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2815 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2816 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2817 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2819 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2820 int aType = Draw::Atoi(argv[7]);
2821 if( aType < 0 || aType > 8 )
2823 di << "Wrong fill type " << "\n";
2824 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2825 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2829 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2831 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2832 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2838 //==============================================================================
2839 //function : VSetGradientBgMode
2840 //purpose : Change gradient background fill style
2841 //==============================================================================
2842 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2846 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2847 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2848 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2852 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2853 if(AISContext.IsNull())
2855 di << "use 'vinit' command before " << argv[0] << "\n";
2860 int aType = Draw::Atoi(argv[1]);
2861 if( aType < 0 || aType > 8 )
2863 di << "Wrong fill type " << "\n";
2864 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2865 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2869 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2871 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2872 V3dView->SetBgGradientStyle( aMethod, 1 );
2878 //==============================================================================
2879 //function : VSetColorBg
2880 //purpose : Set color background
2881 //==============================================================================
2882 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2886 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2887 di << "R,G,B = [0..255]" << "\n";
2891 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2892 if(AISContext.IsNull())
2894 di << "use 'vinit' command before " << argv[0] << "\n";
2900 Standard_Real R = Draw::Atof(argv[1])/255.;
2901 Standard_Real G = Draw::Atof(argv[2])/255.;
2902 Standard_Real B = Draw::Atof(argv[3])/255.;
2903 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2905 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2906 V3dView->SetBackgroundColor( aColor );
2913 //==============================================================================
2915 //purpose : View Scaling
2916 //==============================================================================
2918 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2920 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2921 if ( V3dView.IsNull() ) return 1;
2924 di << argv[0] << "Invalid number of arguments" << "\n";
2927 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2930 //==============================================================================
2931 //function : VZBuffTrihedron
2933 //==============================================================================
2935 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2936 Standard_Integer theArgNb,
2937 const char** theArgVec)
2939 Handle(V3d_View) aView = ViewerTest::CurrentView();
2942 std::cout << "Error: no active viewer!\n";
2946 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2948 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2949 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2950 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2951 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2952 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2953 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2954 Standard_Real aScale = 0.1;
2955 Standard_Real aSizeRatio = 0.8;
2956 Standard_Real anArrowDiam = 0.05;
2957 Standard_Integer aNbFacets = 12;
2958 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2960 Standard_CString anArg = theArgVec[anArgIter];
2961 TCollection_AsciiString aFlag (anArg);
2963 if (anUpdateTool.parseRedrawMode (aFlag))
2967 else if (aFlag == "-on")
2971 else if (aFlag == "-off")
2973 aView->TriedronErase();
2976 else if (aFlag == "-pos"
2977 || aFlag == "-position"
2978 || aFlag == "-corner")
2980 if (++anArgIter >= theArgNb)
2982 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2986 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
2987 aPosName.LowerCase();
2988 if (aPosName == "center")
2990 aPosition = Aspect_TOTP_CENTER;
2992 else if (aPosName == "left_lower"
2993 || aPosName == "lower_left"
2994 || aPosName == "leftlower"
2995 || aPosName == "lowerleft")
2997 aPosition = Aspect_TOTP_LEFT_LOWER;
2999 else if (aPosName == "left_upper"
3000 || aPosName == "upper_left"
3001 || aPosName == "leftupper"
3002 || aPosName == "upperleft")
3004 aPosition = Aspect_TOTP_LEFT_UPPER;
3006 else if (aPosName == "right_lower"
3007 || aPosName == "lower_right"
3008 || aPosName == "rightlower"
3009 || aPosName == "lowerright")
3011 aPosition = Aspect_TOTP_RIGHT_LOWER;
3013 else if (aPosName == "right_upper"
3014 || aPosName == "upper_right"
3015 || aPosName == "rightupper"
3016 || aPosName == "upperright")
3018 aPosition = Aspect_TOTP_RIGHT_UPPER;
3022 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3026 else if (aFlag == "-type")
3028 if (++anArgIter >= theArgNb)
3030 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3034 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3035 aTypeName.LowerCase();
3036 if (aTypeName == "wireframe"
3037 || aTypeName == "wire")
3039 aVisType = V3d_WIREFRAME;
3041 else if (aTypeName == "zbuffer"
3042 || aTypeName == "shaded")
3044 aVisType = V3d_ZBUFFER;
3048 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3051 else if (aFlag == "-scale")
3053 if (++anArgIter >= theArgNb)
3055 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3059 aScale = Draw::Atof (theArgVec[anArgIter]);
3061 else if (aFlag == "-size"
3062 || aFlag == "-sizeratio")
3064 if (++anArgIter >= theArgNb)
3066 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3070 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3072 else if (aFlag == "-arrowdiam"
3073 || aFlag == "-arrowdiameter")
3075 if (++anArgIter >= theArgNb)
3077 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3081 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3083 else if (aFlag == "-nbfacets")
3085 if (++anArgIter >= theArgNb)
3087 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3091 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3093 else if (aFlag == "-colorlabel"
3094 || aFlag == "-colorlabels")
3096 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3097 theArgVec + anArgIter + 1,
3101 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3104 anArgIter += aNbParsed;
3106 else if (aFlag == "-colorarrowx")
3108 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3109 theArgVec + anArgIter + 1,
3113 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3116 anArgIter += aNbParsed;
3118 else if (aFlag == "-colorarrowy")
3120 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3121 theArgVec + anArgIter + 1,
3125 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3128 anArgIter += aNbParsed;
3130 else if (aFlag == "-colorarrowz")
3132 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3133 theArgVec + anArgIter + 1,
3137 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3140 anArgIter += aNbParsed;
3144 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3149 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3150 aSizeRatio, anArrowDiam, aNbFacets);
3151 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3152 aView->View()->ZFitAll();
3156 //==============================================================================
3157 //function : VRotate
3158 //purpose : Camera Rotating
3159 //==============================================================================
3161 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3163 Handle(V3d_View) aView = ViewerTest::CurrentView();
3166 std::cout << "No active view!\n";
3170 Standard_Boolean hasFlags = Standard_False;
3171 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3173 Standard_CString anArg (theArgVec[anArgIter]);
3174 TCollection_AsciiString aFlag (anArg);
3176 if (aFlag == "-mousestart"
3177 || aFlag == "-mousefrom")
3179 hasFlags = Standard_True;
3180 if (anArgIter + 2 >= theArgNb)
3182 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3186 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3187 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3188 aView->StartRotation (anX, anY);
3190 else if (aFlag == "-mousemove")
3192 hasFlags = Standard_True;
3193 if (anArgIter + 2 >= theArgNb)
3195 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3199 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3200 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3201 aView->Rotation (anX, anY);
3203 else if (theArgNb != 4
3206 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3215 else if (theArgNb == 4)
3217 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3218 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3219 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3220 aView->Rotate (anAX, anAY, anAZ);
3223 else if (theArgNb == 7)
3225 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3226 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3227 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3229 Standard_Real anX = Draw::Atof (theArgVec[4]);
3230 Standard_Real anY = Draw::Atof (theArgVec[5]);
3231 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3233 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3237 std::cout << "Error: Invalid number of arguments\n";
3241 //==============================================================================
3243 //purpose : View zoom in / out (relative to current zoom)
3244 //==============================================================================
3246 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3247 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3248 if ( V3dView.IsNull() ) {
3253 Standard_Real coef = Draw::Atof(argv[1]);
3254 if ( coef <= 0.0 ) {
3255 di << argv[1] << "Invalid value" << "\n";
3258 V3dView->SetZoom( Draw::Atof(argv[1]) );
3261 di << argv[0] << " Invalid number of arguments" << "\n";
3266 //==============================================================================
3268 //purpose : View panning (in pixels)
3269 //==============================================================================
3271 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3272 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3273 if ( V3dView.IsNull() ) return 1;
3276 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3279 di << argv[0] << " Invalid number of arguments" << "\n";
3284 //==============================================================================
3286 //purpose : Place the point (in pixels) at the center of the window
3287 //==============================================================================
3288 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3290 Handle(V3d_View) aView = ViewerTest::CurrentView();
3293 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3299 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3303 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3308 //==============================================================================
3309 //function : VExport
3310 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3311 //==============================================================================
3313 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3315 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3316 if (V3dView.IsNull())
3321 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3325 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3326 TCollection_AsciiString aFormatStr;
3328 TCollection_AsciiString aFileName (argv[1]);
3329 Standard_Integer aLen = aFileName.Length();
3333 aFormatStr = TCollection_AsciiString (argv[2]);
3337 if (aFileName.Value (aLen - 2) == '.')
3339 aFormatStr = aFileName.SubString (aLen - 1, aLen);
3341 else if (aFileName.Value (aLen - 3) == '.')
3343 aFormatStr = aFileName.SubString (aLen - 2, aLen);
3347 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3353 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3357 aFormatStr.UpperCase();
3358 if (aFormatStr == "PS")
3359 anExpFormat = Graphic3d_EF_PostScript;
3360 else if (aFormatStr == "EPS")
3361 anExpFormat = Graphic3d_EF_EnhPostScript;
3362 else if (aFormatStr == "TEX")
3363 anExpFormat = Graphic3d_EF_TEX;
3364 else if (aFormatStr == "PDF")
3365 anExpFormat = Graphic3d_EF_PDF;
3366 else if (aFormatStr == "SVG")
3367 anExpFormat = Graphic3d_EF_SVG;
3368 else if (aFormatStr == "PGF")
3369 anExpFormat = Graphic3d_EF_PGF;
3370 else if (aFormatStr == "EMF")
3371 anExpFormat = Graphic3d_EF_EMF;
3374 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3379 if (!V3dView->View()->Export (argv[1], anExpFormat))
3381 di << "Error: export of image to " << aFormatStr << " failed!\n";
3384 catch (Standard_Failure)
3386 di << "Error: export of image to " << aFormatStr << " failed";
3387 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3392 //==============================================================================
3393 //function : VColorScale
3394 //purpose : representation color scale
3395 //==============================================================================
3397 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3398 const TCollection_AsciiString& theGreen,
3399 const TCollection_AsciiString& theBlue,
3400 Standard_Real& theRedValue,
3401 Standard_Real& theGreenValue,
3402 Standard_Real& theBlueValue)
3404 if (!theRed.IsRealValue()
3405 || !theGreen.IsRealValue()
3406 || !theBlue.IsRealValue())
3408 std::cout << "Error: RGB color values should be real!\n";
3409 return Standard_True;
3411 theRedValue = theRed .RealValue();
3412 theGreenValue = theGreen.RealValue();
3413 theBlueValue = theBlue .RealValue();
3414 if (theRedValue < 0.0 || theRedValue > 1.0
3415 || theGreenValue < 0.0 || theGreenValue > 1.0
3416 || theBlueValue < 0.0 || theBlueValue > 1.0)
3418 std::cout << "Error: RGB color values should be within range 0..1!\n";
3419 return Standard_True;
3421 return Standard_False;
3424 static int VColorScale (Draw_Interpretor& theDI,
3425 Standard_Integer theArgNb,
3426 const char** theArgVec)
3428 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3429 Handle(V3d_View) aView = ViewerTest::CurrentView();
3430 if (aContext.IsNull())
3432 std::cout << "Error: no active view!\n";
3436 Handle(V3d_ColorScale) aCS = Handle(V3d_ColorScale)::DownCast (aView->ColorScale());
3439 std::cout << "Error: color scale is undefined!\n";
3443 Standard_Real aMinRange = aCS->GetMin();
3444 Standard_Real aMaxRange = aCS->GetMax();
3445 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3446 Standard_Integer aTextHeight = aCS->GetTextHeight();
3447 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3448 gp_XY aPos (aCS->GetXPosition(), aCS->GetYPosition());
3450 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3454 theDI << "Current color scale parameters:\n"
3455 << "Min range: " << aMinRange << "\n"
3456 << "Max range: " << aMaxRange << "\n"
3457 << "Number of intervals: " << aNbIntervals << "\n"
3458 << "Text height: " << aTextHeight << "\n"
3459 << "Color scale position: " << aPos.X() <<" "<< aPos.Y()<< "\n"
3460 << "Color scale title: " << aCS->GetTitle() << "\n"
3461 << "Label position: ";
3462 switch (aLabPosition)
3464 case Aspect_TOCSP_NONE:
3467 case Aspect_TOCSP_LEFT:
3470 case Aspect_TOCSP_RIGHT:
3473 case Aspect_TOCSP_CENTER:
3474 theDI << "Center\n";
3479 Standard_CString aFirstArg = theArgVec[1];