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 <NIS_View.hxx>
49 #include <NIS_Triangulated.hxx>
50 #include <NIS_InteractiveContext.hxx>
51 #include <AIS_InteractiveContext.hxx>
52 #include <Draw_Interpretor.hxx>
54 #include <Draw_Appli.hxx>
55 #include <Aspect_PrintAlgo.hxx>
56 #include <Image_AlienPixMap.hxx>
57 #include <OpenGl_GraphicDriver.hxx>
58 #include <OSD_Timer.hxx>
59 #include <TColStd_HSequenceOfAsciiString.hxx>
60 #include <TColStd_SequenceOfInteger.hxx>
61 #include <TColStd_HSequenceOfReal.hxx>
62 #include <TColgp_Array1OfPnt2d.hxx>
63 #include <TColStd_MapOfAsciiString.hxx>
64 #include <Visual3d_LayerItem.hxx>
65 #include <Aspect_TypeOfLine.hxx>
66 #include <Image_Diff.hxx>
67 #include <Aspect_DisplayConnection.hxx>
71 #include <PrsMgr_PresentableObject.hxx>
72 #include <Graphic3d_ClipPlane.hxx>
73 #include <NCollection_DataMap.hxx>
74 #include <Graphic3d_Texture2Dmanual.hxx>
75 #include <Prs3d_ShadingAspect.hxx>
76 #include <Prs3d_Drawer.hxx>
82 #include <Visual3d_Layer.hxx>
86 #include <WNT_WClass.hxx>
87 #include <WNT_Window.hxx>
90 #define _CRT_SECURE_NO_DEPRECATE
91 #pragma warning (disable:4996)
93 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
94 #include <Cocoa_Window.hxx>
96 #include <Xw_Window.hxx>
97 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
98 #include <X11/Xutil.h>
102 inline Standard_Boolean parseOnOff (Standard_CString theArg,
103 Standard_Boolean& theIsOn)
105 TCollection_AsciiString aFlag (theArg);
110 theIsOn = Standard_True;
111 return Standard_True;
113 else if (aFlag == "off"
116 theIsOn = Standard_False;
117 return Standard_True;
119 return Standard_False;
122 // Auxiliary definitions
123 static const char THE_KEY_DELETE = 127;
125 //==============================================================================
126 // VIEWER GLOBAL VARIABLES
127 //==============================================================================
129 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
130 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
132 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
133 extern const Handle(NIS_InteractiveContext)& TheNISContext();
134 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
136 extern int VErase (Draw_Interpretor& theDI,
137 Standard_Integer theArgNb,
138 const char** theArgVec);
141 static Handle(WNT_Window)& VT_GetWindow() {
142 static Handle(WNT_Window) WNTWin;
145 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
146 static Handle(Cocoa_Window)& VT_GetWindow()
148 static Handle(Cocoa_Window) aWindow;
151 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
152 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
153 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
156 static Handle(Xw_Window)& VT_GetWindow(){
157 static Handle(Xw_Window) XWWin;
161 static void VProcessEvents(ClientData,int);
164 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
166 static Handle(Aspect_DisplayConnection) aDisplayConnection;
167 return aDisplayConnection;
170 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
172 GetDisplayConnection() = theDisplayConnection;
175 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
176 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
178 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
180 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
181 if (!aWindow.IsNull())
182 return aWindow->HWindow();
183 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
184 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
185 if (!aWindow.IsNull())
186 return aWindow->XWindow();
188 return aWindowHandle;
192 static Standard_Boolean MyHLRIsOn = Standard_False;
194 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
195 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
196 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
197 static OpenGl_Caps ViewerTest_myDefaultCaps;
199 #define ZCLIPWIDTH 1.
201 static void OSWindowSetup();
203 //==============================================================================
204 // EVENT GLOBAL VARIABLES
205 //==============================================================================
207 static int Start_Rot = 0;
208 static int ZClipIsOn = 0;
209 int X_Motion = 0; // Current cursor position
211 int X_ButtonPress = 0; // Last ButtonPress position
212 int Y_ButtonPress = 0;
213 Standard_Boolean IsDragged = Standard_False;
214 Standard_Boolean DragFirst = Standard_False;
216 //==============================================================================
219 static LRESULT WINAPI ViewerWindowProc(
224 static LRESULT WINAPI AdvViewerWindowProc(
232 //==============================================================================
235 //==============================================================================
237 const Handle(MMgt_TShared)& ViewerTest::WClass()
239 static Handle(MMgt_TShared) theWClass;
241 if (theWClass.IsNull())
243 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
244 CS_VREDRAW | CS_HREDRAW, 0, 0,
245 ::LoadCursor (NULL, IDC_ARROW));
251 //==============================================================================
252 //function : CreateName
253 //purpose : Create numerical name for new object in theMap
254 //==============================================================================
255 template <typename ObjectType>
256 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
257 const TCollection_AsciiString& theDefaultString)
259 if (theObjectMap.IsEmpty())
260 return theDefaultString + TCollection_AsciiString(1);
262 Standard_Integer aNextKey = 1;
263 Standard_Boolean isFound = Standard_False;
266 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
267 // Look for objects with default names
268 if (theObjectMap.IsBound1(aStringKey))
273 isFound = Standard_True;
276 return theDefaultString + TCollection_AsciiString(aNextKey);
279 //==============================================================================
280 //structure : ViewerTest_Names
281 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
282 //==============================================================================
283 struct ViewerTest_Names
286 TCollection_AsciiString myDriverName;
287 TCollection_AsciiString myViewerName;
288 TCollection_AsciiString myViewName;
292 const TCollection_AsciiString& GetDriverName () const
296 void SetDriverName (const TCollection_AsciiString& theDriverName)
298 myDriverName = theDriverName;
300 const TCollection_AsciiString& GetViewerName () const
304 void SetViewerName (const TCollection_AsciiString& theViewerName)
306 myViewerName = theViewerName;
308 const TCollection_AsciiString& GetViewName () const
312 void SetViewName (const TCollection_AsciiString& theViewName)
314 myViewName = theViewName;
317 //===========================================================================
318 //function : Constructor for ViewerTest_Names
319 //purpose : Get view, viewer, driver names from custom string
320 //===========================================================================
322 ViewerTest_Names (const TCollection_AsciiString& theInputString)
324 TCollection_AsciiString aName(theInputString);
325 if (theInputString.IsEmpty())
327 // Get current configuration
328 if (ViewerTest_myDrivers.IsEmpty())
329 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
330 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
332 myDriverName = ViewerTest_myDrivers.Find2
333 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
335 if(ViewerTest_myContexts.IsEmpty())
337 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
338 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
341 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
343 myViewName = CreateName <Handle(V3d_View)>
344 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
348 // There is at least view name
349 Standard_Integer aParserNumber = 0;
350 for (Standard_Integer i = 0; i < 3; ++i)
352 Standard_Integer aParserPos = aName.SearchFromEnd("/");
356 aName.Split(aParserPos-1);
361 if (aParserNumber == 0)
364 if (!ViewerTest::GetAISContext().IsNull())
366 myDriverName = ViewerTest_myDrivers.Find2
367 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
368 myViewerName = ViewerTest_myContexts.Find2
369 (ViewerTest::GetAISContext());
373 // There is no opened contexts here, need to create names for viewer and driver
374 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
375 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
377 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
378 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
380 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
382 else if (aParserNumber == 1)
384 // Here is viewerName/viewName
385 if (!ViewerTest::GetAISContext().IsNull())
386 myDriverName = ViewerTest_myDrivers.Find2
387 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
390 // There is no opened contexts here, need to create name for driver
391 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
392 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
394 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
396 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
400 //Here is driverName/viewerName/viewName
401 myDriverName = TCollection_AsciiString(aName);
403 TCollection_AsciiString aViewerName(theInputString);
404 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
405 myViewerName = TCollection_AsciiString(aViewerName);
407 myViewName = TCollection_AsciiString(theInputString);
413 //==============================================================================
414 //function : FindContextByView
415 //purpose : Find AIS_InteractiveContext by View
416 //==============================================================================
418 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
420 Handle(AIS_InteractiveContext) anAISContext;
422 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
423 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
425 if (anIter.Value()->CurrentViewer() == theView->Viewer())
426 return anIter.Key2();
432 //==============================================================================
433 //function : SetWindowTitle
434 //purpose : Set window title
435 //==============================================================================
437 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
438 Standard_CString theTitle)
441 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
443 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
444 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
446 if(GetDisplayConnection()->GetDisplay())
449 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
450 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
455 //==============================================================================
456 //function : IsWindowOverlapped
457 //purpose : Check if theWindow overlapp another view
458 //==============================================================================
460 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
461 const Standard_Integer thePxTop,
462 const Standard_Integer thePxRight,
463 const Standard_Integer thePxBottom,
464 TCollection_AsciiString& theViewId)
466 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
467 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
469 Standard_Integer aTop = 0,
473 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
474 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
475 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
476 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
477 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
479 theViewId = anIter.Key1();
480 return Standard_True;
483 return Standard_False;
486 // Workaround: to create and delete non-orthographic views outside ViewerTest
487 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
489 ViewerTest_myViews.UnBind1 (theName);
492 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
493 const Handle(V3d_View)& theView)
495 ViewerTest_myViews.Bind (theName, theView);
498 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
500 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
502 //==============================================================================
503 //function : ViewerInit
504 //purpose : Create the window viewer and initialize all the global variable
505 //==============================================================================
507 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
508 const Standard_Integer thePxTop,
509 const Standard_Integer thePxWidth,
510 const Standard_Integer thePxHeight,
511 Standard_CString theViewName,
512 Standard_CString theDisplayName)
514 // Default position and dimension of the viewer window.
515 // Note that left top corner is set to be sufficiently small to have
516 // window fit in the small screens (actual for remote desktops, see #23003).
517 // The position corresponds to the window's client area, thus some
518 // gap is added for window frame to be visible.
519 Standard_Integer aPxLeft = 20;
520 Standard_Integer aPxTop = 40;
521 Standard_Integer aPxWidth = 409;
522 Standard_Integer aPxHeight = 409;
523 Standard_Boolean toCreateViewer = Standard_False;
525 Handle(OpenGl_GraphicDriver) aGraphicDriver;
526 ViewerTest_Names aViewNames(theViewName);
527 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
528 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
535 aPxWidth = thePxWidth;
536 if (thePxHeight != 0)
537 aPxHeight = thePxHeight;
539 // Get graphic driver (create it or get from another view)
540 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
542 // Get connection string
543 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
544 TCollection_AsciiString aDisplayName(theDisplayName);
545 if (!aDisplayName.IsEmpty())
546 SetDisplayConnection (new Aspect_DisplayConnection ());
548 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
550 (void)theDisplayName; // avoid warning on unused argument
551 SetDisplayConnection (new Aspect_DisplayConnection ());
553 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
554 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
555 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
556 toCreateViewer = Standard_True;
560 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
563 //Dispose the window if input parameters are default
564 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
566 Standard_Integer aTop = 0,
573 // Get screen resolution
574 #if defined(_WIN32) || defined(__WIN32__)
576 GetClientRect(GetDesktopWindow(), &aWindowSize);
577 aScreenHeight = aWindowSize.bottom;
578 aScreenWidth = aWindowSize.right;
579 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
580 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
582 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
583 aScreenWidth = WidthOfScreen(aScreen);
584 aScreenHeight = HeightOfScreen(aScreen);
587 TCollection_AsciiString anOverlappedViewId("");
589 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
591 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
593 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
594 && aRight + 2*aPxWidth + 40 > aScreenWidth)
596 if (aBottom + aPxHeight + 40 > aScreenHeight)
603 aPxTop = aBottom + 40;
606 aPxLeft = aRight + 20;
611 TCollection_AsciiString aTitle("3D View - ");
612 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
614 // Change name of current active window
615 if (!ViewerTest::CurrentView().IsNull())
617 TCollection_AsciiString aTitle("3D View - ");
619 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
620 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
624 Handle(V3d_Viewer) a3DViewer;
625 // If it's the single view, we first look for empty context
626 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
628 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
629 anIter(ViewerTest_myContexts);
631 ViewerTest::SetAISContext (anIter.Value());
632 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
634 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
636 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
637 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
639 else if (a3DViewer.IsNull())
641 toCreateViewer = Standard_True;
642 TCollection_ExtendedString NameOfWindow("Viewer3D");
643 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
645 NameOfWindow = TCollection_ExtendedString("Collector");
647 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
651 if (ViewerTest::GetAISContext().IsNull() ||
652 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
654 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
655 ViewerTest::SetAISContext (aContext);
656 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
660 ViewerTest::ResetEventManager();
665 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
666 Handle(WNT_WClass)::DownCast (WClass()),
667 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
671 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
672 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
674 aPxWidth, aPxHeight);
675 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
677 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
680 aPxWidth, aPxHeight);
682 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
685 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
687 ViewerTest::CurrentView(aView);
688 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
689 TheNISContext()->AttachView (aView);
691 // Setup for X11 or NT
694 // Set parameters for V3d_View and V3d_Viewer
695 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
696 aV3dView->SetComputedMode(Standard_False);
697 MyHLRIsOn = aV3dView->ComputedMode();
698 aV3dView->SetZClippingDepth(0.5);
699 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
701 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
704 a3DViewer->SetDefaultLights();
705 a3DViewer->SetLightOn();
708 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
709 #if TCL_MAJOR_VERSION < 8
710 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
711 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
713 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
714 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
718 VT_GetWindow()->Map();
720 // Set the handle of created view in the event manager
721 ViewerTest::ResetEventManager();
723 ViewerTest::CurrentView()->Redraw();
728 return aViewNames.GetViewName();
731 //==============================================================================
732 //function : RedrawAllViews
733 //purpose : Redraw all created views
734 //==============================================================================
735 void ViewerTest::RedrawAllViews()
737 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
738 for (; aViewIt.More(); aViewIt.Next())
740 const Handle(V3d_View)& aView = aViewIt.Key2();
745 //==============================================================================
747 //purpose : Create the window viewer and initialize all the global variable
748 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
749 //==============================================================================
751 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
755 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
756 << "Type help for more information.\n";
760 TCollection_AsciiString aViewName, aDisplayName;
761 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
762 TCollection_AsciiString aName, aValue;
763 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
765 const TCollection_AsciiString anArg = theArgVec[anArgIt];
766 TCollection_AsciiString anArgCase = anArg;
767 anArgCase.UpperCase();
768 if (ViewerTest::SplitParameter (anArg, aName, aValue))
771 if (aName.IsEqual ("NAME"))
775 else if (aName.IsEqual ("L")
776 || aName.IsEqual ("LEFT"))
778 aPxLeft = aValue.IntegerValue();
780 else if (aName.IsEqual ("T")
781 || aName.IsEqual ("TOP"))
783 aPxTop = aValue.IntegerValue();
785 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
786 else if (aName.IsEqual ("DISP")
787 || aName.IsEqual ("DISPLAY"))
789 aDisplayName = aValue;
792 else if (aName.IsEqual ("W")
793 || aName.IsEqual ("WIDTH"))
795 aPxWidth = aValue.IntegerValue();
797 else if (aName.IsEqual ("H")
798 || aName.IsEqual ("HEIGHT"))
800 aPxHeight = aValue.IntegerValue();
804 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
807 else if (aViewName.IsEmpty())
813 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
817 ViewerTest_Names aViewNames (aViewName);
818 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
820 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
821 theDi.Eval (aCommand.ToCString());
825 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
826 aViewName.ToCString(),
827 aDisplayName.ToCString());
832 //==============================================================================
834 //purpose : hidden lines removal algorithm
835 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
836 //==============================================================================
838 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
840 if (ViewerTest::CurrentView().IsNull())
842 di << argv[0] << ": Call vinit before this command, please.\n";
848 di << argv[0] << ": Wrong number of command arguments.\n"
849 << "Type help " << argv[0] << " for more information.\n";
853 // Enable or disable HLR mode.
854 Standard_Boolean isHLROn =
855 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
857 if (isHLROn != MyHLRIsOn)
860 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
863 // Show or hide hidden lines in HLR mode.
864 Standard_Boolean isCurrentShowHidden
865 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
867 Standard_Boolean isShowHidden =
868 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
869 : isCurrentShowHidden;
872 if (isShowHidden != isCurrentShowHidden)
876 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
880 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
886 AIS_ListOfInteractive aListOfShapes;
887 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
889 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
891 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
896 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
901 ViewerTest::CurrentView()->Update();
905 //==============================================================================
906 //function : VHLRType
907 //purpose : change type of using HLR algorithm
908 //==============================================================================
910 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
912 if (ViewerTest::CurrentView().IsNull())
914 di << argv[0] << ": Call vinit before this command, please.\n";
920 di << argv[0] << ": Wrong number of command arguments.\n"
921 << "Type help " << argv[0] << " for more information.\n";
925 Prs3d_TypeOfHLR aTypeOfHLR =
926 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
930 AIS_ListOfInteractive aListOfShapes;
931 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
932 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
933 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
934 anIter.More(); anIter.Next())
936 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
939 if (aShape->TypeOfHLR() != aTypeOfHLR)
940 aShape->SetTypeOfHLR (aTypeOfHLR);
942 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
944 ViewerTest::CurrentView()->Update();
949 for (Standard_Integer i = 2; i < argc; ++i)
951 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
952 TCollection_AsciiString aName (argv[i]);
954 if (!aMap.IsBound2 (aName))
956 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
959 Handle(AIS_Shape) anAISObject =
960 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
961 if (anAISObject.IsNull())
963 anAISObject->SetTypeOfHLR (aTypeOfHLR);
965 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
967 ViewerTest::CurrentView()->Update();
973 //==============================================================================
974 //function : FindViewIdByWindowHandle
975 //purpose : Find theView Id in the map of views by window handle
976 //==============================================================================
977 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
978 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
980 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
981 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
983 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
984 if (aWindowHandle == theWindowHandle)
985 return anIter.Key1();
987 return TCollection_AsciiString("");
991 //==============================================================================
992 //function : ActivateView
993 //purpose : Make the view active
994 //==============================================================================
996 void ActivateView (const TCollection_AsciiString& theViewName)
998 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1001 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1002 if (!anAISContext.IsNull())
1004 if (!ViewerTest::CurrentView().IsNull())
1006 TCollection_AsciiString aTitle("3D View - ");
1007 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1008 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1011 ViewerTest::CurrentView (aView);
1012 // Update degenerate mode
1013 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
1014 ViewerTest::SetAISContext (anAISContext);
1015 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1016 aTitle = aTitle + theViewName + "(*)";
1017 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1018 #if defined(_WIN32) || defined(__WIN32__)
1019 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1020 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1021 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1023 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1025 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1026 ViewerTest::CurrentView()->Redraw();
1031 //==============================================================================
1032 //function : RemoveView
1034 //==============================================================================
1035 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1036 const Standard_Boolean theToRemoveContext)
1038 if (!ViewerTest_myViews.IsBound2 (theView))
1043 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1044 RemoveView (aViewName, theToRemoveContext);
1047 //==============================================================================
1048 //function : RemoveView
1049 //purpose : Close and remove view from display, clear maps if neccessary
1050 //==============================================================================
1051 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1053 if (!ViewerTest_myViews.IsBound1(theViewName))
1055 cout << "Wrong view name\n";
1059 // Activate another view if it's active now
1060 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1062 if (ViewerTest_myViews.Extent() > 1)
1064 TCollection_AsciiString aNewViewName;
1065 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1066 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1067 if (anIter.Key1() != theViewName)
1069 aNewViewName = anIter.Key1();
1072 ActivateView (aNewViewName);
1076 Handle(V3d_View) anEmptyView;
1077 #if defined(_WIN32) || defined(__WIN32__)
1078 Handle(WNT_Window) anEmptyWindow;
1079 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1080 Handle(Cocoa_Window) anEmptyWindow;
1082 Handle(Xw_Window) anEmptyWindow;
1084 VT_GetWindow() = anEmptyWindow;
1085 ViewerTest::CurrentView (anEmptyView);
1086 if (isContextRemoved)
1088 Handle(AIS_InteractiveContext) anEmptyContext;
1089 ViewerTest::SetAISContext(anEmptyContext);
1095 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1096 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1098 // Remove view resources
1099 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1100 ViewerTest_myViews.UnBind1(theViewName);
1103 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1104 XFlush (GetDisplayConnection()->GetDisplay());
1107 // Keep context opened only if the closed view is last to avoid
1108 // unused empty contexts
1109 if (!aCurrentContext.IsNull())
1111 // Check if there are more difined views in the viewer
1112 aCurrentContext->CurrentViewer()->InitDefinedViews();
1113 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1115 // Remove driver if there is no viewers that use it
1116 Standard_Boolean isRemoveDriver = Standard_True;
1117 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1118 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1120 if (aCurrentContext != anIter.Key2() &&
1121 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1123 isRemoveDriver = Standard_False;
1129 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1130 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1131 #if TCL_MAJOR_VERSION < 8
1132 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1134 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1139 ViewerTest_myContexts.UnBind2(aCurrentContext);
1142 cout << "3D View - " << theViewName << " was deleted.\n";
1146 //==============================================================================
1148 //purpose : Remove the view defined by its name
1149 //==============================================================================
1151 static int VClose (Draw_Interpretor& /*theDi*/,
1152 Standard_Integer theArgsNb,
1153 const char** theArgVec)
1155 NCollection_List<TCollection_AsciiString> aViewList;
1158 TCollection_AsciiString anArg (theArgVec[1]);
1160 if (anArg.IsEqual ("ALL")
1161 || anArg.IsEqual ("*"))
1163 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1164 anIter.More(); anIter.Next())
1166 aViewList.Append (anIter.Key1());
1168 if (aViewList.IsEmpty())
1170 std::cout << "No view to close\n";
1176 ViewerTest_Names aViewName (theArgVec[1]);
1177 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1179 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1182 aViewList.Append (aViewName.GetViewName());
1187 // close active view
1188 if (ViewerTest::CurrentView().IsNull())
1190 std::cerr << "No active view!\n";
1193 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1196 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1197 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1198 anIter.More(); anIter.Next())
1200 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1206 //==============================================================================
1207 //function : VActivate
1208 //purpose : Activate the view defined by its ID
1209 //==============================================================================
1211 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1215 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1216 << "Usage: " << theArgVec[0] << " ViewID\n";
1221 theDi.Eval("vviewlist");
1225 TCollection_AsciiString aNameString(theArgVec[1]);
1226 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1228 TCollection_AsciiString aTitle("3D View - ");
1229 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1230 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1231 Handle(V3d_View) anEmptyView;
1232 #if defined(_WIN32) || defined(__WIN32__)
1233 Handle(WNT_Window) anEmptyWindow;
1234 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1235 Handle(Cocoa_Window) anEmptyWindow;
1237 Handle(Xw_Window) anEmptyWindow;
1239 VT_GetWindow() = anEmptyWindow;
1240 ViewerTest::CurrentView (anEmptyView);
1241 ViewerTest::ResetEventManager();
1242 theDi << theArgVec[0] << ": all views are inactive\n";
1246 ViewerTest_Names aViewNames(aNameString);
1248 // Check if this view exists in the viewer with the driver
1249 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1251 theDi << "Wrong view name\n";
1255 // Check if it is active already
1256 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1258 theDi << theArgVec[0] << ": the view is active already\n";
1262 ActivateView (aViewNames.GetViewName());
1266 //==============================================================================
1267 //function : VViewList
1268 //purpose : Print current list of views per viewer and graphic driver ID
1269 // shared between viewers
1270 //==============================================================================
1272 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1276 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1277 << "Usage: " << theArgVec[0] << " name";
1280 if (ViewerTest_myContexts.Size() < 1)
1283 Standard_Boolean isTreeView =
1284 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1287 theDi << theArgVec[0] <<":\n";
1289 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1290 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1293 theDi << aDriverIter.Key1() << ":\n";
1295 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1296 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1298 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1302 TCollection_AsciiString aContextName(aContextIter.Key1());
1303 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1306 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1307 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1309 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1311 TCollection_AsciiString aViewName(aViewIter.Key1());
1314 if (aViewIter.Value() == ViewerTest::CurrentView())
1315 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1317 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1321 theDi << aViewName << " ";
1331 //==============================================================================
1332 //function : VT_ProcessKeyPress
1333 //purpose : Handle KeyPress event from a CString
1334 //==============================================================================
1335 void VT_ProcessKeyPress (const char* buf_ret)
1337 //cout << "KeyPress" << endl;
1338 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1339 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1340 // Letter in alphabetic order
1342 if (!strcasecmp (buf_ret, "A"))
1345 aView->SetProj(V3d_XposYnegZpos);
1347 else if (!strcasecmp (buf_ret, "D"))
1352 else if (!strcasecmp (buf_ret, "F"))
1355 if (aNisView.IsNull())
1358 aNisView->FitAll3d();
1360 else if (!strcasecmp (buf_ret, "H"))
1363 cout << "HLR" << endl;
1364 aView->SetComputedMode (!aView->ComputedMode());
1365 MyHLRIsOn = aView->ComputedMode();
1367 else if (!strcasecmp (buf_ret, "P"))
1370 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1371 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1372 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1374 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1375 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1377 AIS_ListOfInteractive aListOfShapes;
1378 aContext->DisplayedObjects(aListOfShapes);
1379 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1380 anIter.More(); anIter.Next())
1382 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1383 if (aShape.IsNull())
1385 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1386 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1388 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1389 aContext->Redisplay (aShape, Standard_False);
1394 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1396 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1397 if (aShape.IsNull())
1399 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1400 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1402 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1403 aContext->Redisplay (aShape, Standard_False);
1407 aContext->UpdateCurrentViewer();
1410 else if (!strcasecmp (buf_ret, "S"))
1412 std::cout << "setup Shaded display mode" << std::endl;
1414 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1415 if(Ctx->NbCurrents()==0 ||
1416 Ctx->NbSelected()==0)
1417 Ctx->SetDisplayMode(AIS_Shaded);
1419 if(Ctx->HasOpenedContext()){
1420 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1421 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1424 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1425 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1427 Ctx->UpdateCurrentViewer();
1430 else if (!strcasecmp (buf_ret, "U"))
1432 // Unset display mode
1433 std::cout << "reset display mode to defaults" << std::endl;
1435 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1436 if(Ctx->NbCurrents()==0 ||
1437 Ctx->NbSelected()==0)
1438 Ctx->SetDisplayMode(AIS_WireFrame);
1440 if(Ctx->HasOpenedContext()){
1441 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1442 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1445 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1446 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1448 Ctx->UpdateCurrentViewer();
1452 else if (!strcasecmp (buf_ret, "T"))
1455 aView->SetProj(V3d_Zpos);
1457 else if (!strcasecmp (buf_ret, "B"))
1460 aView->SetProj(V3d_Zneg);
1462 else if (!strcasecmp (buf_ret, "L"))
1465 aView->SetProj(V3d_Xneg);
1467 else if (!strcasecmp (buf_ret, "R"))
1470 aView->SetProj(V3d_Xpos);
1472 else if (!strcasecmp (buf_ret, "W"))
1474 std::cout << "setup WireFrame display mode" << std::endl;
1475 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1476 if(Ctx->NbCurrents()==0 ||
1477 Ctx->NbSelected()==0)
1478 Ctx->SetDisplayMode(AIS_WireFrame);
1480 if(Ctx->HasOpenedContext()){
1481 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1482 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1485 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1486 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1488 Ctx->UpdateCurrentViewer();
1491 else if (!strcasecmp (buf_ret, "Z"))
1495 cout << "ZClipping OFF" << endl;
1498 aView->SetZClippingType(V3d_OFF);
1502 cout << "ZClipping ON" << endl;
1505 aView->SetZClippingType(V3d_FRONT);
1509 else if (!strcasecmp (buf_ret, ","))
1511 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1513 else if (!strcasecmp (buf_ret, "."))
1515 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1517 else if (*buf_ret == THE_KEY_DELETE)
1519 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1521 && aCtx->NbCurrents() > 0
1522 && aCtx->NbSelected() > 0)
1524 Draw_Interprete ("verase");
1530 Standard_Integer Num = Draw::Atoi(buf_ret);
1531 if(Num>=0 && Num<=7)
1532 ViewerTest::StandardModeActivation(Num);
1536 //==============================================================================
1537 //function : VT_ProcessExpose
1538 //purpose : Redraw the View on an Expose Event
1539 //==============================================================================
1540 void VT_ProcessExpose()
1542 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1543 if (!aView3d.IsNull())
1549 //==============================================================================
1550 //function : VT_ProcessConfigure
1551 //purpose : Resize the View on an Configure Event
1552 //==============================================================================
1553 void VT_ProcessConfigure()
1555 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1556 if (aView3d.IsNull())
1561 aView3d->MustBeResized();
1566 //==============================================================================
1567 //function : VT_ProcessButton1Press
1569 //==============================================================================
1570 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1571 const char** theArgVec,
1572 Standard_Boolean theToPick,
1573 Standard_Boolean theIsShift)
1577 Standard_Real X, Y, Z;
1578 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1580 Draw::Set (theArgVec[1], X);
1581 Draw::Set (theArgVec[2], Y);
1582 Draw::Set (theArgVec[3], Z);
1587 ViewerTest::CurrentEventManager()->ShiftSelect();
1591 ViewerTest::CurrentEventManager()->Select();
1594 return Standard_False;
1597 //==============================================================================
1598 //function : VT_ProcessButton1Release
1599 //purpose : End selecting
1600 //==============================================================================
1601 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1605 IsDragged = Standard_False;
1606 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1609 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1610 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1614 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1615 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1620 //==============================================================================
1621 //function : VT_ProcessButton3Press
1622 //purpose : Start Rotation
1623 //==============================================================================
1624 void VT_ProcessButton3Press()
1629 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1631 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1634 //==============================================================================
1635 //function : VT_ProcessButton3Release
1636 //purpose : End rotation
1637 //==============================================================================
1638 void VT_ProcessButton3Release()
1645 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1650 //==============================================================================
1651 //function : ProcessZClipMotion
1653 //==============================================================================
1655 void ProcessZClipMotion()
1657 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1658 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1659 static Standard_Real CurZPos = 0.;
1661 //Quantity_Length VDX, VDY;
1662 //a3DView->Size(VDX,VDY);
1663 //Standard_Real VDZ = a3DView->ZSize();
1664 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1666 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1668 // Front = Depth + width/2.
1669 Standard_Real D = 0.5;
1670 Standard_Real W = 0.1;
1676 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1678 a3DView->SetZClippingType(V3d_OFF);
1679 a3DView->SetZClippingDepth(D);
1680 a3DView->SetZClippingWidth(W);
1681 a3DView->SetZClippingType(V3d_FRONT);
1685 X_ButtonPress = X_Motion;
1686 Y_ButtonPress = Y_Motion;
1690 //==============================================================================
1691 //function : ProcessControlButton1Motion
1693 //==============================================================================
1695 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1696 static void ProcessControlButton1Motion()
1698 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1700 X_ButtonPress = X_Motion;
1701 Y_ButtonPress = Y_Motion;
1705 //==============================================================================
1706 //function : VT_ProcessControlButton2Motion
1708 //==============================================================================
1709 void VT_ProcessControlButton2Motion()
1711 Standard_Integer aDx = X_Motion - X_ButtonPress;
1712 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1714 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1716 ViewerTest::CurrentView()->Pan (aDx, aDy);
1718 X_ButtonPress = X_Motion;
1719 Y_ButtonPress = Y_Motion;
1722 //==============================================================================
1723 //function : VT_ProcessControlButton3Motion
1724 //purpose : Rotation
1725 //==============================================================================
1726 void VT_ProcessControlButton3Motion()
1730 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1734 //==============================================================================
1735 //function : VT_ProcessMotion
1737 //==============================================================================
1738 void VT_ProcessMotion()
1740 //pre-hilights detected objects at mouse position
1742 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1743 EM->MoveTo(X_Motion, Y_Motion);
1747 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1749 Xpix = X_Motion;Ypix=Y_Motion;
1752 //==============================================================================
1753 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1754 //purpose : Switches to an axonometric, top, left and other views
1755 //==============================================================================
1757 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1759 if ( ViewerTest::CurrentView().IsNull() )
1761 di<<"Call vinit before this command, please"<<"\n";
1765 ViewerTest::CurrentView()->SetProj(ori);
1769 //==============================================================================
1771 //purpose : Switch to an Axonometric view
1772 //Draw arg : No args
1773 //==============================================================================
1775 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1777 return ViewProject(di, V3d_XposYnegZpos);
1780 //==============================================================================
1782 //purpose : Switch to a Top View
1783 //Draw arg : No args
1784 //==============================================================================
1786 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1788 return ViewProject(di, V3d_Zpos);
1791 //==============================================================================
1792 //function : VBottom
1793 //purpose : Switch to a Bottom View
1794 //Draw arg : No args
1795 //==============================================================================
1797 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1799 return ViewProject(di, V3d_Zneg);
1802 //==============================================================================
1804 //purpose : Switch to a Left View
1805 //Draw arg : No args
1806 //==============================================================================
1808 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1810 return ViewProject(di, V3d_Ypos);
1813 //==============================================================================
1815 //purpose : Switch to a Right View
1816 //Draw arg : No args
1817 //==============================================================================
1819 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1821 return ViewProject(di, V3d_Yneg);
1824 //==============================================================================
1826 //purpose : Switch to a Front View
1827 //Draw arg : No args
1828 //==============================================================================
1830 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1832 return ViewProject(di, V3d_Xpos);
1835 //==============================================================================
1837 //purpose : Switch to a Back View
1838 //Draw arg : No args
1839 //==============================================================================
1841 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1843 return ViewProject(di, V3d_Xneg);
1846 //==============================================================================
1848 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1849 //Draw arg : No args
1850 //==============================================================================
1852 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1855 di << "Q : Quit the application" << "\n";
1857 di << "========================="<<"\n";
1858 di << "F : FitAll" << "\n";
1859 di << "T : TopView" << "\n";
1860 di << "B : BottomView" << "\n";
1861 di << "R : RightView" << "\n";
1862 di << "L : LeftView" << "\n";
1863 di << "A : AxonometricView" << "\n";
1864 di << "D : ResetView" << "\n";
1866 di << "========================="<<"\n";
1867 di << "S : Shading" << "\n";
1868 di << "W : Wireframe" << "\n";
1869 di << "H : HidelLineRemoval" << "\n";
1870 di << "U : Unset display mode" << "\n";
1871 di << "Delete : Remove selection from viewer" << "\n";
1873 di << "========================="<<"\n";
1874 di << "Selection mode "<<"\n";
1875 di << "0 : Shape" <<"\n";
1876 di << "1 : Vertex" <<"\n";
1877 di << "2 : Edge" <<"\n";
1878 di << "3 : Wire" <<"\n";
1879 di << "4 : Face" <<"\n";
1880 di << "5 : Shell" <<"\n";
1881 di << "6 : Solid" <<"\n";
1882 di << "7 : Compound" <<"\n";
1884 di << "========================="<<"\n";
1885 di << "Z : Switch Z clipping On/Off" << "\n";
1886 di << ", : Hilight next detected" << "\n";
1887 di << ". : Hilight previous detected" << "\n";
1894 static Standard_Boolean Ppick = 0;
1895 static Standard_Integer Pargc = 0;
1896 static const char** Pargv = NULL;
1899 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1904 if (!ViewerTest_myViews.IsEmpty()) {
1906 WPARAM fwKeys = wParam;
1911 // Delete view from map of views
1912 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1917 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1918 || ViewerTest::CurrentView().IsNull())
1920 // Activate inactive window
1921 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1923 ActivateView (FindViewIdByWindowHandle(hwnd));
1930 HDC hdc = GetDC( hwnd );
1931 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1932 SetROP2( hdc, R2_NOT );
1933 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1934 ReleaseDC( hwnd, hdc );
1935 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1937 IsDragged = Standard_False;
1938 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1940 case WM_LBUTTONDOWN:
1941 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1943 IsDragged = Standard_True;
1944 DragFirst = Standard_True;
1945 X_ButtonPress = LOWORD(lParam);
1946 Y_ButtonPress = HIWORD(lParam);
1948 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1955 HDC hdc = GetDC( hwnd );
1957 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1958 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1959 SetROP2( hdc, R2_NOT );
1962 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1964 DragFirst = Standard_False;
1965 X_Motion = LOWORD(lParam);
1966 Y_Motion = HIWORD(lParam);
1968 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1970 SelectObject( hdc, anObj );
1972 ReleaseDC( hwnd, hdc );
1975 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1979 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1983 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1987 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1994 if ( !ViewerTest::CurrentView().IsNull() ) {
1999 BeginPaint(hwnd, &ps);
2000 EndPaint(hwnd, &ps);
2005 VT_ProcessConfigure();
2009 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2012 c[0] = (char) wParam;
2014 if (wParam == VK_DELETE)
2016 c[0] = THE_KEY_DELETE;
2019 else if (wParam == VK_OEM_COMMA)
2024 else if (wParam == VK_OEM_PERIOD)
2028 VT_ProcessKeyPress (c);
2036 VT_ProcessButton3Release();
2039 case WM_LBUTTONDOWN:
2040 case WM_MBUTTONDOWN:
2041 case WM_RBUTTONDOWN:
2043 WPARAM fwKeys = wParam;
2047 X_ButtonPress = LOWORD(lParam);
2048 Y_ButtonPress = HIWORD(lParam);
2050 if (Msg == WM_LBUTTONDOWN)
2052 if (fwKeys & MK_CONTROL)
2054 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2058 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2061 else if (Msg == WM_RBUTTONDOWN)
2064 VT_ProcessButton3Press();
2071 //cout << "\t WM_MOUSEMOVE" << endl;
2072 WPARAM fwKeys = wParam;
2073 X_Motion = LOWORD(lParam);
2074 Y_Motion = HIWORD(lParam);
2077 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2079 X_ButtonPress = LOWORD(lParam);
2080 Y_ButtonPress = HIWORD(lParam);
2082 if ( fwKeys & MK_RBUTTON ) {
2084 VT_ProcessButton3Press();
2088 if ( fwKeys & MK_CONTROL ) {
2089 if ( fwKeys & MK_LBUTTON ) {
2090 ProcessControlButton1Motion();
2092 else if ( fwKeys & MK_MBUTTON ||
2093 ((fwKeys&MK_LBUTTON) &&
2094 (fwKeys&MK_RBUTTON) ) ){
2095 VT_ProcessControlButton2Motion();
2097 else if ( fwKeys & MK_RBUTTON ) {
2098 VT_ProcessControlButton3Motion();
2102 else if ( fwKeys & MK_SHIFT ) {
2103 if ( fwKeys & MK_MBUTTON ||
2104 ((fwKeys&MK_LBUTTON) &&
2105 (fwKeys&MK_RBUTTON) ) ) {
2106 cout << "ProcessZClipMotion()" << endl;
2107 ProcessZClipMotion();
2111 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2113 if ((fwKeys & MK_MBUTTON
2114 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2116 ProcessZClipMotion();
2127 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2132 return DefWindowProc( hwnd, Msg, wParam, lParam );
2138 //==============================================================================
2139 //function : ViewerMainLoop
2140 //purpose : Get a Event on the view and dispatch it
2141 //==============================================================================
2144 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2146 Ppick = (argc > 0)? 1 : 0;
2154 cout << "Start picking" << endl;
2156 while ( Ppick == 1 ) {
2157 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2158 if (GetMessage(&msg, NULL, 0, 0) ) {
2159 TranslateMessage(&msg);
2160 DispatchMessage(&msg);
2164 cout << "Picking done" << endl;
2170 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2172 int min( int a, int b )
2180 int max( int a, int b )
2188 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2191 static XEvent aReport;
2192 Standard_Boolean pick = argc > 0;
2193 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2194 XNextEvent (aDisplay, &aReport);
2196 // Handle event for the chosen display connection
2197 switch (aReport.type) {
2200 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2203 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2209 // Activate inactive view
2210 Window aWindow = GetWindowHandle(VT_GetWindow());
2211 if(aWindow != aReport.xfocus.window)
2213 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2222 case ConfigureNotify:
2224 VT_ProcessConfigure();
2233 XComposeStatus status_in_out;
2235 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2236 (char *) buf_ret , 10 ,
2237 &ks_ret , &status_in_out ) ;
2240 buf_ret[ret_len] = '\0' ;
2244 VT_ProcessKeyPress (buf_ret);
2250 X_ButtonPress = aReport.xbutton.x;
2251 Y_ButtonPress = aReport.xbutton.y;
2253 if (aReport.xbutton.button == Button1)
2255 if (aReport.xbutton.state & ControlMask)
2257 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2261 IsDragged = Standard_True;
2262 DragFirst = Standard_True;
2265 else if (aReport.xbutton.button == Button3)
2268 VT_ProcessButton3Press();
2278 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2279 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2280 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2283 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2284 if( aContext.IsNull() )
2286 cout << "The context is null. Please use vinit before createmesh" << endl;
2290 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2291 if( aReport.xbutton.button==1 )
2295 aContext->ShiftSelect();
2304 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2305 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2306 ViewerTest::CurrentView());
2310 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2311 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2312 ViewerTest::CurrentView() );
2315 VT_ProcessButton3Release();
2317 IsDragged = Standard_False;
2320 VT_ProcessButton3Release();
2325 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2331 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2332 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2333 XSetFunction( aDisplay, gc, GXinvert );
2336 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2338 X_Motion = aReport.xmotion.x;
2339 Y_Motion = aReport.xmotion.y;
2340 DragFirst = Standard_False;
2342 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2346 X_Motion = aReport.xmotion.x;
2347 Y_Motion = aReport.xmotion.y;
2349 // remove all the ButtonMotionMaskr
2350 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2352 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2353 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2355 Quantity_Length VDX, VDY;
2357 ViewerTest::CurrentView()->Size(VDX,VDY);
2358 Standard_Real VDZ =0 ;
2359 VDZ = ViewerTest::CurrentView()->ZSize();
2361 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2363 Quantity_Length dx = 0 ;
2364 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2368 dx = dx / VDX * VDZ;
2372 ViewerTest::CurrentView()->Redraw();
2376 if ( aReport.xmotion.state & ControlMask ) {
2377 if ( aReport.xmotion.state & Button1Mask ) {
2378 ProcessControlButton1Motion();
2380 else if ( aReport.xmotion.state & Button2Mask ) {
2381 VT_ProcessControlButton2Motion();
2383 else if ( aReport.xmotion.state & Button3Mask ) {
2384 VT_ProcessControlButton3Motion();
2398 //==============================================================================
2399 //function : VProcessEvents
2400 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2401 // event in the Viewer window
2402 //==============================================================================
2404 static void VProcessEvents(ClientData,int)
2406 NCollection_Vector<int> anEventNumbers;
2407 // Get number of messages from every display
2408 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2409 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2411 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2413 // Handle events for every display
2414 int anEventIter = 0;
2415 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2416 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2418 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2419 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2421 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2422 int anEventResult = ViewerMainLoop( 0, NULL);
2423 // If window is closed or context was not found finish current event processing loop
2429 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2434 //==============================================================================
2435 //function : OSWindowSetup
2436 //purpose : Setup for the X11 window to be able to cath the event
2437 //==============================================================================
2440 static void OSWindowSetup()
2442 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2445 Window window = VT_GetWindow()->XWindow();
2446 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2447 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2448 XSynchronize(aDisplay, 1);
2450 // X11 : For keyboard on SUN
2452 wmhints.flags = InputHint;
2455 XSetWMHints( aDisplay, window, &wmhints);
2457 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2458 ButtonPressMask | ButtonReleaseMask |
2459 StructureNotifyMask |
2461 Button1MotionMask | Button2MotionMask |
2462 Button3MotionMask | FocusChangeMask
2464 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2465 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2467 XSynchronize(aDisplay, 0);
2476 //==============================================================================
2479 //purpose : Fitall, no DRAW arguments
2480 //Draw arg : No args
2481 //==============================================================================
2483 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2485 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2486 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2487 if (V.IsNull() == Standard_False) {
2489 } else if (aView.IsNull() == Standard_False) {
2495 //=======================================================================
2496 //function : VFitArea
2497 //purpose : Fit view to show area located between two points
2498 // : given in world 2D or 3D coordinates.
2499 //=======================================================================
2500 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2502 Handle(V3d_View) aView = ViewerTest::CurrentView();
2505 std::cerr << theArgVec[0] << "Error: No active view.\n";
2510 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2511 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2515 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2516 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2517 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2518 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2520 else if (theArgNb == 7)
2522 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2523 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2524 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2525 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2526 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2527 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2531 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2532 theDI.PrintHelp(theArgVec[0]);
2536 // Convert model coordinates to view space
2537 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2538 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2539 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2541 // Determine fit area
2542 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2543 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2545 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2547 if (aDiagonal < Precision::Confusion())
2549 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2553 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2557 //==============================================================================
2559 //purpose : ZFitall, no DRAW arguments
2560 //Draw arg : No args
2561 //==============================================================================
2562 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2564 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2566 if (aCurrentView.IsNull())
2568 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2574 aCurrentView->View()->ZFitAll();
2575 aCurrentView->Redraw();
2579 Standard_Real aScale = 1.0;
2583 aScale = Draw::Atoi (theArgVec[1]);
2586 aCurrentView->View()->ZFitAll (aScale);
2587 aCurrentView->Redraw();
2592 //==============================================================================
2593 //function : VRepaint
2595 //==============================================================================
2596 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2598 Handle(V3d_View) V = ViewerTest::CurrentView();
2599 if ( !V.IsNull() ) V->Redraw(); return 0;
2602 //==============================================================================
2604 //purpose : Remove all the object from the viewer
2605 //Draw arg : No args
2606 //==============================================================================
2608 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2610 Handle(V3d_View) V = ViewerTest::CurrentView();
2612 ViewerTest::Clear();
2616 //==============================================================================
2619 //==============================================================================
2621 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2622 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2625 di << argv[0] << "Invalid number of arguments" << "\n";
2629 while (ViewerMainLoop( argc, argv)) {
2635 //==============================================================================
2637 //purpose : Load image as background
2638 //==============================================================================
2640 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2642 if (argc < 2 || argc > 3)
2644 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2645 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2649 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2650 if(AISContext.IsNull())
2652 di << "use 'vinit' command before " << argv[0] << "\n";
2656 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2659 const char* szType = argv[2];
2660 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2661 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2662 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2663 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2666 di << "Wrong fill type : " << szType << "\n";
2667 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2672 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2673 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2678 //==============================================================================
2679 //function : VSetBgMode
2680 //purpose : Change background image fill type
2681 //==============================================================================
2683 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2687 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2688 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2692 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2693 if(AISContext.IsNull())
2695 di << "use 'vinit' command before " << argv[0] << "\n";
2698 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2699 const char* szType = argv[1];
2700 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2701 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2702 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2703 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2706 di << "Wrong fill type : " << szType << "\n";
2707 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2710 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2711 V3dView->SetBgImageStyle(aFillType, Standard_True);
2715 //==============================================================================
2716 //function : VSetGradientBg
2717 //purpose : Mount gradient background
2718 //==============================================================================
2719 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2723 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2724 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2725 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2726 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2730 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2731 if(AISContext.IsNull())
2733 di << "use 'vinit' command before " << argv[0] << "\n";
2739 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2740 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2741 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2742 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2744 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2745 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2746 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2748 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2749 int aType = Draw::Atoi(argv[7]);
2750 if( aType < 0 || aType > 8 )
2752 di << "Wrong fill type " << "\n";
2753 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2754 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2758 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2760 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2761 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2767 //==============================================================================
2768 //function : VSetGradientBgMode
2769 //purpose : Change gradient background fill style
2770 //==============================================================================
2771 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2775 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2776 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2777 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2781 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2782 if(AISContext.IsNull())
2784 di << "use 'vinit' command before " << argv[0] << "\n";
2789 int aType = Draw::Atoi(argv[1]);
2790 if( aType < 0 || aType > 8 )
2792 di << "Wrong fill type " << "\n";
2793 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2794 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2798 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2800 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2801 V3dView->SetBgGradientStyle( aMethod, 1 );
2807 //==============================================================================
2808 //function : VSetColorBg
2809 //purpose : Set color background
2810 //==============================================================================
2811 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2815 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2816 di << "R,G,B = [0..255]" << "\n";
2820 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2821 if(AISContext.IsNull())
2823 di << "use 'vinit' command before " << argv[0] << "\n";
2829 Standard_Real R = Draw::Atof(argv[1])/255.;
2830 Standard_Real G = Draw::Atof(argv[2])/255.;
2831 Standard_Real B = Draw::Atof(argv[3])/255.;
2832 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2834 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2835 V3dView->SetBackgroundColor( aColor );
2842 //==============================================================================
2844 //purpose : View Scaling
2845 //==============================================================================
2847 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2849 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2850 if ( V3dView.IsNull() ) return 1;
2853 di << argv[0] << "Invalid number of arguments" << "\n";
2856 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2859 //==============================================================================
2860 //function : VTestZBuffTrihedron
2861 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2862 //==============================================================================
2864 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2866 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2867 if ( V3dView.IsNull() ) return 1;
2869 V3dView->ZBufferTriedronSetup();
2872 // Set up default trihedron parameters
2873 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2877 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2878 const char* aPosType = argv[1];
2880 if ( strcmp(aPosType, "center") == 0 )
2882 aPosition = Aspect_TOTP_CENTER;
2884 if (strcmp(aPosType, "left_lower") == 0)
2886 aPosition = Aspect_TOTP_LEFT_LOWER;
2888 if (strcmp(aPosType, "left_upper") == 0)
2890 aPosition = Aspect_TOTP_LEFT_UPPER;
2892 if (strcmp(aPosType, "right_lower") == 0)
2894 aPosition = Aspect_TOTP_RIGHT_LOWER;
2896 if (strcmp(aPosType, "right_upper") == 0)
2898 aPosition = Aspect_TOTP_RIGHT_UPPER;
2901 di << argv[1] << " Invalid type of alignment" << "\n";
2902 di << "Must be one of [ center, left_lower," << "\n";
2903 di << "left_upper, right_lower, right_upper ]" << "\n";
2907 Standard_Real R = Draw::Atof(argv[2])/255.;
2908 Standard_Real G = Draw::Atof(argv[3])/255.;
2909 Standard_Real B = Draw::Atof(argv[4])/255.;
2910 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2912 Standard_Real aScale = Draw::Atof(argv[5]);
2916 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2920 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2921 const char* aPresType = argv[6];
2923 if ( strcmp(aPresType, "wireframe") == 0 )
2925 aPresentation = V3d_WIREFRAME;
2927 if (strcmp(aPresType, "zbuffer") == 0)
2929 aPresentation = V3d_ZBUFFER;
2932 di << argv[6] << " Invalid type of visualization" << "\n";
2933 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2937 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2941 di << argv[0] << " Invalid number of arguments" << "\n";
2945 V3dView->View()->ZFitAll();
2950 //==============================================================================
2951 //function : VRotate
2952 //purpose : Camera Rotating
2953 //==============================================================================
2955 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
2957 Handle(V3d_View) aView = ViewerTest::CurrentView();
2960 std::cout << "No active view!\n";
2964 Standard_Boolean hasFlags = Standard_False;
2965 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2967 Standard_CString anArg (theArgVec[anArgIter]);
2968 TCollection_AsciiString aFlag (anArg);
2970 if (aFlag == "-mousestart"
2971 || aFlag == "-mousefrom")
2973 hasFlags = Standard_True;
2974 if (anArgIter + 2 >= theArgNb)
2976 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
2980 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
2981 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
2982 aView->StartRotation (anX, anY);
2984 else if (aFlag == "-mousemove")
2986 hasFlags = Standard_True;
2987 if (anArgIter + 2 >= theArgNb)
2989 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
2993 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
2994 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
2995 aView->Rotation (anX, anY);
2997 else if (theArgNb != 4
3000 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3009 else if (theArgNb == 4)
3011 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3012 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3013 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3014 aView->Rotate (anAX, anAY, anAZ);
3017 else if (theArgNb == 7)
3019 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3020 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3021 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3023 Standard_Real anX = Draw::Atof (theArgVec[4]);
3024 Standard_Real anY = Draw::Atof (theArgVec[5]);
3025 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3027 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3031 std::cout << "Error: Invalid number of arguments\n";
3035 //==============================================================================
3037 //purpose : View zoom in / out (relative to current zoom)
3038 //==============================================================================
3040 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3041 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3042 if ( V3dView.IsNull() ) {
3047 Standard_Real coef = Draw::Atof(argv[1]);
3048 if ( coef <= 0.0 ) {
3049 di << argv[1] << "Invalid value" << "\n";
3052 V3dView->SetZoom( Draw::Atof(argv[1]) );
3055 di << argv[0] << " Invalid number of arguments" << "\n";
3060 //==============================================================================
3062 //purpose : View panning (in pixels)
3063 //==============================================================================
3065 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3066 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3067 if ( V3dView.IsNull() ) return 1;
3070 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3073 di << argv[0] << " Invalid number of arguments" << "\n";
3078 //==============================================================================
3080 //purpose : Place the point (in pixels) at the center of the window
3081 //==============================================================================
3082 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3084 Handle(V3d_View) aView = ViewerTest::CurrentView();
3087 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3093 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3097 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3102 //==============================================================================
3103 //function : VExport
3104 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3105 //==============================================================================
3107 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3109 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3110 if (V3dView.IsNull())
3115 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3119 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3120 TCollection_AsciiString aFormatStr;
3122 TCollection_AsciiString aFileName (argv[1]);
3123 Standard_Integer aLen = aFileName.Length();
3127 aFormatStr = TCollection_AsciiString (argv[2]);
3131 if (aFileName.Value (aLen - 2) == '.')
3133 aFormatStr = aFileName.SubString (aLen - 1, aLen);
3135 else if (aFileName.Value (aLen - 3) == '.')
3137 aFormatStr = aFileName.SubString (aLen - 2, aLen);
3141 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3147 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3151 aFormatStr.UpperCase();
3152 if (aFormatStr == "PS")
3153 anExpFormat = Graphic3d_EF_PostScript;
3154 else if (aFormatStr == "EPS")
3155 anExpFormat = Graphic3d_EF_EnhPostScript;
3156 else if (aFormatStr == "TEX")
3157 anExpFormat = Graphic3d_EF_TEX;
3158 else if (aFormatStr == "PDF")
3159 anExpFormat = Graphic3d_EF_PDF;
3160 else if (aFormatStr == "SVG")
3161 anExpFormat = Graphic3d_EF_SVG;
3162 else if (aFormatStr == "PGF")
3163 anExpFormat = Graphic3d_EF_PGF;
3164 else if (aFormatStr == "EMF")
3165 anExpFormat = Graphic3d_EF_EMF;
3168 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3173 if (!V3dView->View()->Export (argv[1], anExpFormat))
3175 di << "Error: export of image to " << aFormatStr << " failed!\n";
3178 catch (Standard_Failure)
3180 di << "Error: export of image to " << aFormatStr << " failed";
3181 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3186 //==============================================================================
3187 //function : VColorScale
3188 //purpose : representation color scale
3189 //==============================================================================
3191 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3192 const TCollection_AsciiString& theGreen,
3193 const TCollection_AsciiString& theBlue,
3194 Standard_Real& theRedValue,
3195 Standard_Real& theGreenValue,
3196 Standard_Real& theBlueValue)
3198 if (!theRed.IsRealValue()
3199 || !theGreen.IsRealValue()
3200 || !theBlue.IsRealValue())
3202 std::cout << "Error: RGB color values should be real!\n";
3203 return Standard_True;
3205 theRedValue = theRed .RealValue();
3206 theGreenValue = theGreen.RealValue();
3207 theBlueValue = theBlue .RealValue();
3208 if (theRedValue < 0.0 || theRedValue > 1.0
3209 || theGreenValue < 0.0 || theGreenValue > 1.0
3210 || theBlueValue < 0.0 || theBlueValue > 1.0)
3212 std::cout << "Error: RGB color values should be within range 0..1!\n";
3213 return Standard_True;
3215 return Standard_False;
3218 static int VColorScale (Draw_Interpretor& theDI,
3219 Standard_Integer theArgNb,
3220 const char** theArgVec)
3222 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3223 Handle(V3d_View) aView = ViewerTest::CurrentView();
3224 if (aContext.IsNull())
3226 std::cout << "Error: no active view!\n";
3230 Handle(V3d_ColorScale) aCS = Handle(V3d_ColorScale)::DownCast (aView->ColorScale());
3233 std::cout << "Error: color scale is undefined!\n";
3237 Standard_Real aMinRange = aCS->GetMin();
3238 Standard_Real aMaxRange = aCS->GetMax();
3239 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3240 Standard_Integer aTextHeight = aCS->GetTextHeight();
3241 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3242 gp_XY aPos (aCS->GetXPosition(), aCS->GetYPosition());
3244 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3248 theDI << "Current color scale parameters:\n"
3249 << "Min range: " << aMinRange << "\n"
3250 << "Max range: " << aMaxRange << "\n"
3251 << "Number of intervals: " << aNbIntervals << "\n"
3252 << "Text height: " << aTextHeight << "\n"
3253 << "Color scale position: " << aPos.X() <<" "<< aPos.Y()<< "\n"
3254 << "Color scale title: " << aCS->GetTitle() << "\n"
3255 << "Label position: ";
3256 switch (aLabPosition)
3258 case Aspect_TOCSP_NONE:
3261 case Aspect_TOCSP_LEFT:
3264 case Aspect_TOCSP_RIGHT:
3267 case Aspect_TOCSP_CENTER:
3268 theDI << "Center\n";
3273 Standard_CString aFirstArg = theArgVec[1];
3274 TCollection_AsciiString aFlag (aFirstArg);
3276 if (aFlag == "-hide" ||
3281 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3284 if (!aView->ColorScaleIsDisplayed())
3286 std::cout << "Error: color scale is not displayed!\n";
3291 aView->ColorScaleErase();
3295 else if (aFlag == "-show" ||
3296 aFlag == "-display")
3300 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3303 aView->ColorScaleDisplay();
3307 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3309 Standard_CString anArg = theArgVec[anArgIter];
3310 TCollection_AsciiString aFlag (anArg);
3312 if (anUpdateTool.parseRedrawMode (aFlag))
3316 else if (aFlag == "-range")
3318 if (anArgIter + 3 >= theArgNb)
3320 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3324 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3325 TCollection_AsciiString anArg2 (theArgVec[++anArgIter]);
3326 TCollection_AsciiString anArg3 (theArgVec[++anArgIter]);
3327 if (!anArg1.IsRealValue())
3329 std::cout << "Error: the minRange value should be real!\n";
3332 else if (!anArg2.IsRealValue())
3334 std::cout << "Error: the maxRange value should be real!\n";
3337 else if (!anArg3.IsIntegerValue())
3339 std::cout << "Error: the number of intervals should be integer!\n";
3343 aMinRange = anArg1.RealValue();
3344 aMaxRange = anArg2.RealValue();
3345 aNbIntervals = anArg3.IntegerValue();
3347 else if (aFlag == "-font")
3349 if (anArgIter + 1 >= theArgNb)
3351 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3354 TCollection_AsciiString anArg (theArgVec[anArgIter + 1]);
3355 if (!anArg.IsIntegerValue())
3357 std::cout << "Error: HeightFont value should be integer!\n";
3361 aTextHeight = anArg.IntegerValue();
3364 else if (aFlag == "-textpos")
3366 if (anArgIter + 1 >= theArgNb)
3368 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3371 TCollection_AsciiString anArg (theArgVec[++anArgIter]);
3373 if (anArg == "none")
3375 aLabPosition = Aspect_TOCSP_NONE;
3377 else if (anArg == "left")
3379 aLabPosition = Aspect_TOCSP_LEFT;
3381 else if (anArg == "right")
3383 aLabPosition = Aspect_TOCSP_RIGHT;
3385 else if (anArg == "center")
3387 aLabPosition = Aspect_TOCSP_CENTER;
3391 std::cout << "Error: unknown position '" << anArg << "'!\n";
3395 else if (aFlag == "-xy")
3397 if (anArgIter + 2 >= theArgNb)
3399 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3403 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3404 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3405 if (!aX.IsRealValue()
3406 || !aY.IsRealValue())
3408 std::cout << "Error: coordinates should be real values!\n";
3412 aPos.SetCoord (aX.RealValue(), aY.RealValue());
3414 else if (aFlag == "-color")
3416 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3418 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3422 Quantity_NameOfColor aColorName;
3423 if (anArgIter + 4 >= theArgNb)
3425 if (anArgIter + 2 >= theArgNb)
3427 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3430 else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3432 std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
3437 TCollection_AsciiString anInd (theArgVec[anArgIter + 1]);
3438 if (!anInd.IsIntegerValue())
3440 std::cout << "Error: Index value should be integer!\n";
3444 Standard_Integer anIndex = anInd.IntegerValue();
3446 || anIndex > aNbIntervals - 1)
3448 std::cout << "Error: Index value should be within range 0..." << (aNbIntervals - 1) <<"!\n";
3452 if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3454 aCS->SetColor (Quantity_Color (aColorName), anIndex);
3455 aCS->SetColorType(Aspect_TOCSD_USER);
3460 TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
3461 TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
3462 TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
3463 Standard_Real aRedValue,aGreenValue, aBlueValue;
3464 if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3468 aCS->SetColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
3469 aCS->SetColorType (Aspect_TOCSD_USER);
3472 else if (aFlag == "-label")
3474 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3476 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3479 else if (anArgIter + 2 >= theArgNb)
3481 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3485 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3487 || anIndex > aNbIntervals)
3489 std::cout << "Error: Index value should be within range 0..." << aNbIntervals <<"!\n";