1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 // Robert Boehne 30 May 2000 : Dec Osf
28 #include <OpenGl_GlCore20.hxx>
29 #include <AIS_Shape.hxx>
30 #include <AIS_Drawer.hxx>
31 #include <AIS_InteractiveObject.hxx>
32 #include <AIS_ListOfInteractive.hxx>
33 #include <AIS_ListIteratorOfListOfInteractive.hxx>
35 #include <Graphic3d_AspectMarker3d.hxx>
36 #include <Graphic3d_ExportFormat.hxx>
37 #include <Graphic3d_NameOfTextureEnv.hxx>
38 #include <Graphic3d_TextureEnv.hxx>
39 #include <Graphic3d_TextureParams.hxx>
40 #include <Graphic3d_TypeOfTextureFilter.hxx>
41 #include <ViewerTest.hxx>
42 #include <ViewerTest_EventManager.hxx>
43 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
44 #include <Visual3d_View.hxx>
45 #include <Visual3d_ViewManager.hxx>
46 #include <V3d_LayerMgr.hxx>
47 #include <NCollection_DoubleMap.hxx>
48 #include <NCollection_List.hxx>
49 #include <NCollection_Vector.hxx>
50 #include <NIS_View.hxx>
51 #include <NIS_Triangulated.hxx>
52 #include <NIS_InteractiveContext.hxx>
53 #include <AIS_InteractiveContext.hxx>
54 #include <Draw_Interpretor.hxx>
56 #include <Draw_Appli.hxx>
57 #include <Aspect_PrintAlgo.hxx>
58 #include <Image_AlienPixMap.hxx>
59 #include <OpenGl_GraphicDriver.hxx>
60 #include <OSD_Timer.hxx>
61 #include <TColStd_SequenceOfInteger.hxx>
62 #include <TColStd_HSequenceOfReal.hxx>
63 #include <TColgp_Array1OfPnt2d.hxx>
64 #include <Visual3d_LayerItem.hxx>
65 #include <V3d_LayerMgr.hxx>
66 #include <V3d_LayerMgrPointer.hxx>
67 #include <Aspect_TypeOfLine.hxx>
68 #include <Image_Diff.hxx>
69 #include <Aspect_DisplayConnection.hxx>
70 #include <Graphic3d.hxx>
76 #include <Visual3d_Layer.hxx>
80 #include <WNT_WClass.hxx>
81 #include <WNT_Window.hxx>
84 #define _CRT_SECURE_NO_DEPRECATE
85 #pragma warning (disable:4996)
87 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
88 #include <Cocoa_Window.hxx>
91 #include <Xw_Window.hxx>
92 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
93 #include <X11/Xutil.h>
97 //==============================================================================
99 //==============================================================================
100 // VIEWER GLOBAL VARIABLES
101 //==============================================================================
103 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
105 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
106 extern const Handle(NIS_InteractiveContext)& TheNISContext();
107 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
110 static Handle(WNT_Window)& VT_GetWindow() {
111 static Handle(WNT_Window) WNTWin;
114 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
115 static Handle(Cocoa_Window)& VT_GetWindow()
117 static Handle(Cocoa_Window) aWindow;
120 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
121 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
122 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
125 static Handle(Xw_Window)& VT_GetWindow(){
126 static Handle(Xw_Window) XWWin;
130 static void VProcessEvents(ClientData,int);
133 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
135 static Handle(Aspect_DisplayConnection) aDisplayConnection;
136 return aDisplayConnection;
139 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
141 GetDisplayConnection() = theDisplayConnection;
144 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
145 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
147 Aspect_Handle aWindowHandle = NULL;
149 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
150 if (!aWindow.IsNull())
151 return aWindow->HWindow();
152 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
153 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
154 if (!aWindow.IsNull())
155 return aWindow->XWindow();
157 return aWindowHandle;
161 static Standard_Boolean MyHLRIsOn = Standard_False;
163 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
164 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
165 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
166 static OpenGl_Caps ViewerTest_myDefaultCaps;
168 #define ZCLIPWIDTH 1.
170 static void OSWindowSetup();
172 //==============================================================================
173 // EVENT GLOBAL VARIABLES
174 //==============================================================================
176 static int Start_Rot = 0;
177 static int ZClipIsOn = 0;
178 int X_Motion = 0; // Current cursor position
180 int X_ButtonPress = 0; // Last ButtonPress position
181 int Y_ButtonPress = 0;
182 Standard_Boolean IsDragged = Standard_False;
183 Standard_Boolean DragFirst;
185 //==============================================================================
188 static LRESULT WINAPI ViewerWindowProc(
193 static LRESULT WINAPI AdvViewerWindowProc(
201 //==============================================================================
204 //==============================================================================
206 const Handle(MMgt_TShared)& ViewerTest::WClass()
208 static Handle(MMgt_TShared) theWClass;
210 if (theWClass.IsNull())
212 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
213 CS_VREDRAW | CS_HREDRAW, 0, 0,
214 ::LoadCursor (NULL, IDC_ARROW));
220 //==============================================================================
221 //function : CreateName
222 //purpose : Create numerical name for new object in theMap
223 //==============================================================================
224 template <typename ObjectType>
225 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
226 const TCollection_AsciiString& theDefaultString)
228 if (theObjectMap.IsEmpty())
229 return theDefaultString + TCollection_AsciiString(1);
231 Standard_Integer aNextKey = 1;
232 Standard_Boolean isFound = Standard_False;
235 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
236 // Look for objects with default names
237 if (theObjectMap.IsBound1(aStringKey))
242 isFound = Standard_True;
245 return theDefaultString + TCollection_AsciiString(aNextKey);
248 //==============================================================================
249 //structure : ViewerTest_Names
250 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
251 //==============================================================================
252 struct ViewerTest_Names
255 TCollection_AsciiString myDriverName;
256 TCollection_AsciiString myViewerName;
257 TCollection_AsciiString myViewName;
261 const TCollection_AsciiString& GetDriverName () const
265 void SetDriverName (const TCollection_AsciiString& theDriverName)
267 myDriverName = theDriverName;
269 const TCollection_AsciiString& GetViewerName () const
273 void SetViewerName (const TCollection_AsciiString& theViewerName)
275 myViewerName = theViewerName;
277 const TCollection_AsciiString& GetViewName () const
281 void SetViewName (const TCollection_AsciiString& theViewName)
283 myViewName = theViewName;
286 //===========================================================================
287 //function : Constructor for ViewerTest_Names
288 //purpose : Get view, viewer, driver names from custom string
289 //===========================================================================
291 ViewerTest_Names (const TCollection_AsciiString& theInputString)
293 TCollection_AsciiString aName(theInputString);
294 if (theInputString.IsEmpty())
296 // Get current configuration
297 if (ViewerTest_myDrivers.IsEmpty())
298 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
299 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
301 myDriverName = ViewerTest_myDrivers.Find2
302 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
304 if(ViewerTest_myContexts.IsEmpty())
306 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
307 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
310 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
312 myViewName = CreateName <Handle(V3d_View)>
313 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
317 // There is at least view name
318 Standard_Integer aParserNumber = 0;
319 for (Standard_Integer i = 0; i < 3; ++i)
321 Standard_Integer aParserPos = aName.SearchFromEnd("/");
325 aName.Split(aParserPos-1);
330 if (aParserNumber == 0)
333 if (!ViewerTest::GetAISContext().IsNull())
335 myDriverName = ViewerTest_myDrivers.Find2
336 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
337 myViewerName = ViewerTest_myContexts.Find2
338 (ViewerTest::GetAISContext());
342 // There is no opened contexts here, need to create names for viewer and driver
343 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
344 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
346 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
347 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
349 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
351 else if (aParserNumber == 1)
353 // Here is viewerName/viewName
354 if (!ViewerTest::GetAISContext().IsNull())
355 myDriverName = ViewerTest_myDrivers.Find2
356 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
359 // There is no opened contexts here, need to create name for driver
360 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
361 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
363 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
365 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
369 //Here is driverName/viewerName/viewName
370 myDriverName = TCollection_AsciiString(aName);
372 TCollection_AsciiString aViewerName(theInputString);
373 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
374 myViewerName = TCollection_AsciiString(aViewerName);
376 myViewName = TCollection_AsciiString(theInputString);
382 //==============================================================================
383 //function : FindContextByView
384 //purpose : Find AIS_InteractiveContext by View
385 //==============================================================================
387 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
389 Handle(AIS_InteractiveContext) anAISContext;
391 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
392 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
394 if (anIter.Value()->CurrentViewer() == theView->Viewer())
395 return anIter.Key2();
401 //==============================================================================
402 //function : SetWindowTitle
403 //purpose : Set window title
404 //==============================================================================
406 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
407 Standard_CString theTitle)
410 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
412 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
413 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
415 if(GetDisplayConnection()->GetDisplay())
418 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
419 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
424 //==============================================================================
425 //function : IsWindowOverlapped
426 //purpose : Check if theWindow overlapp another view
427 //==============================================================================
429 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
430 const Standard_Integer thePxTop,
431 const Standard_Integer thePxRight,
432 const Standard_Integer thePxBottom,
433 TCollection_AsciiString& theViewId)
435 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
436 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
438 Standard_Integer aTop = 0,
442 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
443 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
444 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
445 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
446 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
448 theViewId = anIter.Key1();
449 return Standard_True;
452 return Standard_False;
455 // Workaround: to create and delete non-orthographic views outside ViewerTest
456 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
458 ViewerTest_myViews.UnBind1 (theName);
461 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
462 const Handle(V3d_View)& theView)
464 ViewerTest_myViews.Bind (theName, theView);
467 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
469 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
471 //==============================================================================
472 //function : ViewerInit
473 //purpose : Create the window viewer and initialize all the global variable
474 //==============================================================================
476 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
477 const Standard_Integer thePxTop,
478 const Standard_Integer thePxWidth,
479 const Standard_Integer thePxHeight,
480 Standard_CString theViewName,
481 Standard_CString theDisplayName)
483 // Default position and dimension of the viewer window.
484 // Note that left top corner is set to be sufficiently small to have
485 // window fit in the small screens (actual for remote desktops, see #23003).
486 // The position corresponds to the window's client area, thus some
487 // gap is added for window frame to be visible.
488 Standard_Integer aPxLeft = 20;
489 Standard_Integer aPxTop = 40;
490 Standard_Integer aPxWidth = 409;
491 Standard_Integer aPxHeight = 409;
492 Standard_Boolean toCreateViewer = Standard_False;
494 Handle(OpenGl_GraphicDriver) aGraphicDriver;
495 ViewerTest_Names aViewNames(theViewName);
496 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
497 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
504 aPxWidth = thePxWidth;
505 if (thePxHeight != 0)
506 aPxHeight = thePxHeight;
508 // Get graphic driver (create it or get from another view)
509 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
511 // Get connection string
512 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
513 TCollection_AsciiString aDisplayName(theDisplayName);
514 if (!aDisplayName.IsEmpty())
515 SetDisplayConnection (new Aspect_DisplayConnection ());
517 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
519 (void)theDisplayName; // avoid warning on unused argument
520 SetDisplayConnection (new Aspect_DisplayConnection ());
522 aGraphicDriver = new OpenGl_GraphicDriver();
523 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
524 aGraphicDriver->Begin (GetDisplayConnection());
525 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
526 toCreateViewer = Standard_True;
530 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
533 //Dispose the window if input parameters are default
534 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
536 Standard_Integer aTop = 0,
543 // Get screen resolution
544 #if defined(_WIN32) || defined(__WIN32__)
546 GetClientRect(GetDesktopWindow(), &aWindowSize);
547 aScreenHeight = aWindowSize.bottom;
548 aScreenWidth = aWindowSize.right;
549 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
550 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
552 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
553 aScreenWidth = WidthOfScreen(aScreen);
554 aScreenHeight = HeightOfScreen(aScreen);
557 TCollection_AsciiString anOverlappedViewId("");
559 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
561 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
563 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
564 && aRight + 2*aPxWidth + 40 > aScreenWidth)
566 if (aBottom + aPxHeight + 40 > aScreenHeight)
573 aPxTop = aBottom + 40;
576 aPxLeft = aRight + 20;
581 TCollection_AsciiString aTitle("3D View - ");
582 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
584 // Change name of current active window
585 if (!ViewerTest::CurrentView().IsNull())
587 TCollection_AsciiString aTitle("3D View - ");
589 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
590 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
594 Handle(V3d_Viewer) a3DViewer, a3DCollector;
595 // If it's the single view, we first look for empty context
596 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
598 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
599 anIter(ViewerTest_myContexts);
601 ViewerTest::SetAISContext (anIter.Value());
602 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
603 a3DCollector= ViewerTest::GetAISContext()->Collector();
605 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
607 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
608 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
609 a3DCollector= ViewerTest::GetAISContext()->Collector();
611 else if (a3DViewer.IsNull() || a3DCollector.IsNull())
613 toCreateViewer = Standard_True;
614 TCollection_ExtendedString NameOfWindow("Viewer3D");
615 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
617 NameOfWindow = TCollection_ExtendedString("Collector");
618 a3DCollector = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
620 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
621 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
625 if (ViewerTest::GetAISContext().IsNull() ||
626 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
628 Handle(AIS_InteractiveContext) aContext =
629 new AIS_InteractiveContext(a3DViewer, a3DCollector);
630 ViewerTest::SetAISContext (aContext);
631 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
634 ViewerTest::ResetEventManager();
637 #if defined(_WIN32) || defined(__WIN32__)
638 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
639 Handle(WNT_WClass)::DownCast (WClass()),
644 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
645 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
647 aPxWidth, aPxHeight);
648 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
650 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
653 aPxWidth, aPxHeight);
655 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
658 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
660 ViewerTest::CurrentView(aView);
661 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
662 TheNISContext()->AttachView (aView);
664 // Setup for X11 or NT
667 // Set parameters for V3d_View and V3d_Viewer
668 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
669 aV3dView->SetComputedMode(Standard_False);
670 MyHLRIsOn = aV3dView->ComputedMode();
671 aV3dView->SetZClippingDepth(0.5);
672 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
674 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
677 a3DViewer->SetDefaultLights();
678 a3DViewer->SetLightOn();
681 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
682 #if TCL_MAJOR_VERSION < 8
683 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
684 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
686 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
687 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
691 VT_GetWindow()->Map();
693 // Set the handle of created view in the event manager
694 ViewerTest::ResetEventManager();
696 ViewerTest::CurrentView()->Redraw();
700 a3DCollector.Nullify();
702 return aViewNames.GetViewName();
705 //==============================================================================
706 //function : SplitParameter
707 //purpose : Split parameter string to parameter name an patameter value
708 //==============================================================================
709 Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
710 TCollection_AsciiString& theName,
711 TCollection_AsciiString& theValue)
713 Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
714 if (aParamNameEnd == 0)
715 return Standard_False;
716 TCollection_AsciiString aString(theString);
717 if (aParamNameEnd != 0)
719 theValue = aString.Split(aParamNameEnd);
720 aString.Split(aString.Length()-1);
723 return Standard_True;
726 //==============================================================================
728 //purpose : Create the window viewer and initialize all the global variable
729 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
730 //==============================================================================
732 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
736 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
737 << "Type help for more information.\n";
740 TCollection_AsciiString aViewName (""),
742 Standard_Integer aPxLeft = 0,
747 for (Standard_Integer i = 1; i < theArgsNb; ++i)
749 TCollection_AsciiString aName = "", aValue = "";
750 if(!SplitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
752 // In case of syntax: vinit ViewName
753 aViewName = theArgVec[1];
761 else if (aName == "l" || aName == "left")
762 aPxLeft = aValue.IntegerValue();
763 else if (aName == "t" || aName == "top")
764 aPxTop = aValue.IntegerValue();
765 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
766 else if (aName == "display")
767 aDisplayName = aValue;
769 else if (aName == "w" || aName == "width")
770 aPxWidth = aValue.IntegerValue();
771 else if (aName == "h" || aName == "height")
772 aPxHeight = aValue.IntegerValue();
775 theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n";
780 ViewerTest_Names aViewNames (aViewName);
781 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
783 TCollection_AsciiString aCommand("vactivate ");
784 aCommand = aCommand + aViewNames.GetViewName();
785 theDi.Eval(aCommand.ToCString());
789 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
790 aViewName.ToCString(),
791 aDisplayName.ToCString());
792 cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n";
796 //==============================================================================
798 //purpose : hidden lines removal algorithm
799 //==============================================================================
801 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
803 if (ViewerTest::CurrentView().IsNull())
805 di << argv[0] << ": Call vinit before this command, please.\n";
811 di << argv[0] << ": Wrong number of command arguments.\n"
812 << "Type help " << argv[0] << " for more information.\n";
816 Standard_Boolean isHLROn =
817 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
819 if (isHLROn == MyHLRIsOn)
825 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
830 //==============================================================================
831 //function : VHLRType
832 //purpose : change type of using HLR algorithm
833 //==============================================================================
835 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
837 if (ViewerTest::CurrentView().IsNull())
839 di << argv[0] << ": Call vinit before this command, please.\n";
845 di << argv[0] << ": Wrong number of command arguments.\n"
846 << "Type help " << argv[0] << " for more information.\n";
850 Prs3d_TypeOfHLR aTypeOfHLR =
851 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
855 AIS_ListOfInteractive aListOfShapes;
856 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
857 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
858 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
859 anIter.More(); anIter.Next())
861 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
864 if (aShape->TypeOfHLR() != aTypeOfHLR)
865 aShape->SetTypeOfHLR (aTypeOfHLR);
869 ViewerTest::CurrentView()->Update();
874 for (Standard_Integer i = 2; i < argc; ++i)
876 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
877 TCollection_AsciiString aName (argv[i]);
879 if (!aMap.IsBound2 (aName))
881 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
884 Handle(AIS_Shape) anAISObject =
885 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
886 if (anAISObject.IsNull())
888 anAISObject->SetTypeOfHLR (aTypeOfHLR);
890 anAISObject->Redisplay();
892 ViewerTest::CurrentView()->Update();
898 //==============================================================================
899 //function : FindViewIdByWindowHandle
900 //purpose : Find theView Id in the map of views by window handle
901 //==============================================================================
902 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
903 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
905 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
906 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
908 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
909 if (aWindowHandle == theWindowHandle)
910 return anIter.Key1();
912 return TCollection_AsciiString("");
916 //==============================================================================
917 //function : ActivateView
918 //purpose : Make the view active
919 //==============================================================================
921 void ActivateView (const TCollection_AsciiString& theViewName)
923 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
926 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
927 if (!anAISContext.IsNull())
929 if (!ViewerTest::CurrentView().IsNull())
931 TCollection_AsciiString aTitle("3D View - ");
932 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
933 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
936 ViewerTest::CurrentView (aView);
937 // Update degenerate mode
938 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
939 ViewerTest::SetAISContext (anAISContext);
940 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
941 aTitle = aTitle + theViewName + "(*)";
942 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
943 #if defined(_WIN32) || defined(__WIN32__)
944 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
945 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
946 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
948 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
950 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
951 ViewerTest::CurrentView()->Redraw();
956 //==============================================================================
957 //function : RemoveView
958 //purpose : Close and remove view from display, clear maps if neccessary
959 //==============================================================================
960 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
962 if (!ViewerTest_myViews.IsBound1(theViewName))
964 cout << "Wrong view name\n";
968 // Activate another view if it's active now
969 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
971 if (ViewerTest_myViews.Extent() > 1)
973 TCollection_AsciiString aNewViewName;
974 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
975 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
976 if (anIter.Key1() != theViewName)
978 aNewViewName = anIter.Key1();
981 ActivateView (aNewViewName);
985 Handle(V3d_View) anEmptyView;
986 #if defined(_WIN32) || defined(__WIN32__)
987 Handle(WNT_Window) anEmptyWindow;
988 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
989 Handle(Cocoa_Window) anEmptyWindow;
991 Handle(Xw_Window) anEmptyWindow;
993 VT_GetWindow() = anEmptyWindow;
994 ViewerTest::CurrentView (anEmptyView);
995 if (isContextRemoved)
997 Handle(AIS_InteractiveContext) anEmptyContext;
998 ViewerTest::SetAISContext(anEmptyContext);
1004 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1005 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1007 // Remove view resources
1008 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1009 ViewerTest_myViews.UnBind1(theViewName);
1012 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1013 XFlush (GetDisplayConnection()->GetDisplay());
1016 // Keep context opened only if the closed view is last to avoid
1017 // unused empty contexts
1018 if (!aCurrentContext.IsNull())
1020 // Check if there are more difined views in the viewer
1021 aCurrentContext->CurrentViewer()->InitDefinedViews();
1022 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1024 // Remove driver if there is no viewers that use it
1025 Standard_Boolean isRemoveDriver = Standard_True;
1026 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1027 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1029 if (aCurrentContext != anIter.Key2() &&
1030 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1032 isRemoveDriver = Standard_False;
1038 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1039 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1040 #if TCL_MAJOR_VERSION < 8
1041 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1043 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1048 ViewerTest_myContexts.UnBind2(aCurrentContext);
1051 cout << "3D View - " << theViewName << " was deleted.\n";
1055 //==============================================================================
1057 //purpose : Remove the view defined by its name
1058 //==============================================================================
1060 static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1064 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
1065 << "Type help " << theArgVec[0] << " for more information.\n";
1069 if (ViewerTest_myViews.IsEmpty())
1071 theDi << theArgVec[0] <<": there is no views to close.\n";
1075 TCollection_AsciiString anInputString(theArgVec[1]);
1077 // Create list to iterate and remove views from the map of views
1078 NCollection_List<TCollection_AsciiString> aViewList;
1079 if ( strcasecmp( anInputString.ToCString(), "ALL" ) == 0 )
1081 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
1082 anIter.More(); anIter.Next())
1084 aViewList.Append(anIter.Key1());
1089 ViewerTest_Names aViewNames(anInputString);
1090 aViewList.Append(aViewNames.GetViewName());
1093 Standard_Boolean isContextRemoved = (theArgsNb == 3 && atoi(theArgVec[2])==1) ? Standard_False : Standard_True;
1094 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1095 anIter.More(); anIter.Next())
1097 ViewerTest::RemoveView(anIter.Value(), isContextRemoved);
1103 //==============================================================================
1104 //function : VActivate
1105 //purpose : Activate the view defined by its ID
1106 //==============================================================================
1108 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1112 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1113 << "Usage: " << theArgVec[0] << " ViewID\n";
1118 theDi.Eval("vviewlist");
1122 TCollection_AsciiString aNameString(theArgVec[1]);
1123 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1125 TCollection_AsciiString aTitle("3D View - ");
1126 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1127 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1128 Handle(V3d_View) anEmptyView;
1129 #if defined(_WIN32) || defined(__WIN32__)
1130 Handle(WNT_Window) anEmptyWindow;
1131 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1132 Handle(Cocoa_Window) anEmptyWindow;
1134 Handle(Xw_Window) anEmptyWindow;
1136 VT_GetWindow() = anEmptyWindow;
1137 ViewerTest::CurrentView (anEmptyView);
1138 ViewerTest::ResetEventManager();
1139 theDi << theArgVec[0] << ": all views are inactive\n";
1143 ViewerTest_Names aViewNames(aNameString);
1145 // Check if this view exists in the viewer with the driver
1146 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1148 theDi << "Wrong view name\n";
1152 // Check if it is active already
1153 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1155 theDi << theArgVec[0] << ": the view is active already\n";
1159 ActivateView (aViewNames.GetViewName());
1163 //==============================================================================
1164 //function : VViewList
1165 //purpose : Print current list of views per viewer and graphic driver ID
1166 // shared between viewers
1167 //==============================================================================
1169 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1173 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1174 << "Usage: " << theArgVec[0] << " name";
1177 if (ViewerTest_myContexts.Size() < 1)
1180 Standard_Boolean isTreeView =
1181 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1184 theDi << theArgVec[0] <<":\n";
1186 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1187 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1190 theDi << aDriverIter.Key1() << ":\n";
1192 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1193 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1195 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1199 TCollection_AsciiString aContextName(aContextIter.Key1());
1200 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1203 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1204 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1206 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1208 TCollection_AsciiString aViewName(aViewIter.Key1());
1211 if (aViewIter.Value() == ViewerTest::CurrentView())
1212 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1214 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1218 theDi << aViewName << " ";
1228 //==============================================================================
1229 //function : VT_ProcessKeyPress
1230 //purpose : Handle KeyPress event from a CString
1231 //==============================================================================
1232 void VT_ProcessKeyPress (const char* buf_ret)
1234 //cout << "KeyPress" << endl;
1235 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1236 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1237 // Letter in alphabetic order
1239 if ( !strcasecmp(buf_ret, "A") ) {
1241 aView->SetProj(V3d_XposYnegZpos);
1243 else if ( !strcasecmp(buf_ret, "D") ) {
1247 else if ( !strcasecmp(buf_ret, "F") ) {
1249 if (aNisView.IsNull())
1252 aNisView->FitAll3d();
1254 else if ( !strcasecmp(buf_ret, "H") ) {
1256 cout << "HLR" << endl;
1257 aView->SetComputedMode (!aView->ComputedMode());
1258 MyHLRIsOn = aView->ComputedMode();
1260 else if ( !strcasecmp(buf_ret, "P") ) {
1262 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1263 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1264 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1266 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1267 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1269 AIS_ListOfInteractive aListOfShapes;
1270 aContext->DisplayedObjects(aListOfShapes);
1271 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1272 anIter.More(); anIter.Next())
1274 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1275 if (aShape.IsNull())
1277 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1278 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1280 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1281 aShape->Redisplay();
1286 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1288 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1289 if (aShape.IsNull())
1291 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1292 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1294 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1295 aShape->Redisplay();
1299 aContext->UpdateCurrentViewer();
1302 else if ( !strcasecmp(buf_ret, "S") ) {
1304 cout << "passage en mode 1 (shading pour les shapes)" << endl;
1306 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1307 if(Ctx->NbCurrents()==0 ||
1308 Ctx->NbSelected()==0)
1309 Ctx->SetDisplayMode(AIS_Shaded);
1311 if(Ctx->HasOpenedContext()){
1312 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1313 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1316 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1317 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1319 Ctx->UpdateCurrentViewer();
1322 else if ( !strcasecmp(buf_ret, "U") ) {
1323 // Unset display mode
1324 cout<<"passage au mode par defaut"<<endl;
1326 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1327 if(Ctx->NbCurrents()==0 ||
1328 Ctx->NbSelected()==0)
1329 Ctx->SetDisplayMode(AIS_WireFrame);
1331 if(Ctx->HasOpenedContext()){
1332 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1333 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1336 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1337 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1339 Ctx->UpdateCurrentViewer();
1343 else if ( !strcasecmp(buf_ret, "T") ) {
1345 aView->SetProj(V3d_Zpos);
1347 else if ( !strcasecmp(buf_ret, "B") ) {
1349 aView->SetProj(V3d_Zneg);
1351 else if ( !strcasecmp(buf_ret, "L") ) {
1353 aView->SetProj(V3d_Xneg);
1355 else if ( !strcasecmp(buf_ret, "R") ) {
1357 aView->SetProj(V3d_Xpos);
1360 else if ( !strcasecmp(buf_ret, "W") ) {
1362 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
1363 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1364 if(Ctx->NbCurrents()==0 ||
1365 Ctx->NbSelected()==0)
1366 Ctx->SetDisplayMode(AIS_WireFrame);
1368 if(Ctx->HasOpenedContext()){
1369 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1370 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1373 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1374 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1376 Ctx->UpdateCurrentViewer();
1379 else if ( !strcasecmp(buf_ret, "Z") ) {
1383 cout << "ZClipping OFF" << endl;
1386 aView->SetZClippingType(V3d_OFF);
1390 cout << "ZClipping ON" << endl;
1393 aView->SetZClippingType(V3d_FRONT);
1397 else if ( !strcasecmp(buf_ret, ",") ) {
1398 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1402 else if ( !strcasecmp(buf_ret, ".") ) {
1403 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1407 Standard_Integer Num = Draw::Atoi(buf_ret);
1408 if(Num>=0 && Num<=7)
1409 ViewerTest::StandardModeActivation(Num);
1413 //==============================================================================
1414 //function : VT_ProcessExpose
1415 //purpose : Redraw the View on an Expose Event
1416 //==============================================================================
1417 void VT_ProcessExpose()
1419 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1420 if (!aView3d.IsNull())
1426 //==============================================================================
1427 //function : VT_ProcessConfigure
1428 //purpose : Resize the View on an Configure Event
1429 //==============================================================================
1430 void VT_ProcessConfigure()
1432 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1433 if (aView3d.IsNull())
1438 aView3d->MustBeResized();
1443 //==============================================================================
1444 //function : VT_ProcessButton1Press
1446 //==============================================================================
1447 Standard_Boolean VT_ProcessButton1Press(
1450 Standard_Boolean pick,
1451 Standard_Boolean shift)
1453 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1455 Standard_Real X, Y, Z;
1457 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1459 Draw::Set(argv[1], X);
1460 Draw::Set(argv[2], Y);
1461 Draw::Set(argv[3], Z);}
1472 //==============================================================================
1473 //function : VT_ProcessButton1Release
1474 //purpose : End selecting
1475 //==============================================================================
1476 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1480 IsDragged = Standard_False;
1481 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1484 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1485 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1489 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1490 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1495 //==============================================================================
1496 //function : VT_ProcessButton3Press
1497 //purpose : Start Rotation
1498 //==============================================================================
1499 void VT_ProcessButton3Press()
1504 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1506 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1509 //==============================================================================
1510 //function : VT_ProcessButton3Release
1511 //purpose : End rotation
1512 //==============================================================================
1513 void VT_ProcessButton3Release()
1520 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1525 //==============================================================================
1526 //function : ProcessZClipMotion
1528 //==============================================================================
1530 void ProcessZClipMotion()
1532 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1533 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1534 static Standard_Real CurZPos = 0.;
1536 //Quantity_Length VDX, VDY;
1537 //a3DView->Size(VDX,VDY);
1538 //Standard_Real VDZ = a3DView->ZSize();
1539 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1541 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1543 // Front = Depth + width/2.
1544 Standard_Real D = 0.5;
1545 Standard_Real W = 0.1;
1551 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1553 a3DView->SetZClippingType(V3d_OFF);
1554 a3DView->SetZClippingDepth(D);
1555 a3DView->SetZClippingWidth(W);
1556 a3DView->SetZClippingType(V3d_FRONT);
1560 X_ButtonPress = X_Motion;
1561 Y_ButtonPress = Y_Motion;
1565 //==============================================================================
1566 //function : ProcessControlButton1Motion
1568 //==============================================================================
1570 static void ProcessControlButton1Motion()
1572 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1574 X_ButtonPress = X_Motion;
1575 Y_ButtonPress = Y_Motion;
1578 //==============================================================================
1579 //function : VT_ProcessControlButton2Motion
1581 //==============================================================================
1582 void VT_ProcessControlButton2Motion()
1584 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1585 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1587 dy = -dy; // Xwindow Y axis is from top to Bottom
1589 ViewerTest::CurrentView()->Panning( dx, dy );
1591 X_ButtonPress = X_Motion;
1592 Y_ButtonPress = Y_Motion;
1595 //==============================================================================
1596 //function : VT_ProcessControlButton3Motion
1597 //purpose : Rotation
1598 //==============================================================================
1599 void VT_ProcessControlButton3Motion()
1603 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1607 //==============================================================================
1608 //function : VT_ProcessMotion
1610 //==============================================================================
1611 void VT_ProcessMotion()
1613 //pre-hilights detected objects at mouse position
1615 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1616 EM->MoveTo(X_Motion, Y_Motion);
1620 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1622 Xpix = X_Motion;Ypix=Y_Motion;
1625 //==============================================================================
1626 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1627 //purpose : Switches to an axonometric, top, left and other views
1628 //==============================================================================
1630 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1632 if ( ViewerTest::CurrentView().IsNull() )
1634 di<<"Call vinit before this command, please"<<"\n";
1638 ViewerTest::CurrentView()->SetProj(ori);
1642 //==============================================================================
1644 //purpose : Switch to an Axonometric view
1645 //Draw arg : No args
1646 //==============================================================================
1648 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1650 return ViewProject(di, V3d_XposYnegZpos);
1653 //==============================================================================
1655 //purpose : Switch to a Top View
1656 //Draw arg : No args
1657 //==============================================================================
1659 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1661 return ViewProject(di, V3d_Zpos);
1664 //==============================================================================
1665 //function : VBottom
1666 //purpose : Switch to a Bottom View
1667 //Draw arg : No args
1668 //==============================================================================
1670 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1672 return ViewProject(di, V3d_Zneg);
1675 //==============================================================================
1677 //purpose : Switch to a Left View
1678 //Draw arg : No args
1679 //==============================================================================
1681 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1683 return ViewProject(di, V3d_Ypos);
1686 //==============================================================================
1688 //purpose : Switch to a Right View
1689 //Draw arg : No args
1690 //==============================================================================
1692 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1694 return ViewProject(di, V3d_Yneg);
1697 //==============================================================================
1699 //purpose : Switch to a Front View
1700 //Draw arg : No args
1701 //==============================================================================
1703 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1705 return ViewProject(di, V3d_Xpos);
1708 //==============================================================================
1710 //purpose : Switch to a Back View
1711 //Draw arg : No args
1712 //==============================================================================
1714 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1716 return ViewProject(di, V3d_Xneg);
1719 //==============================================================================
1721 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1722 //Draw arg : No args
1723 //==============================================================================
1725 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1728 di << "Q : Quit the application" << "\n";
1730 di << "========================="<<"\n";
1731 di << "F : FitAll" << "\n";
1732 di << "T : TopView" << "\n";
1733 di << "B : BottomView" << "\n";
1734 di << "R : RightView" << "\n";
1735 di << "L : LeftView" << "\n";
1736 di << "A : AxonometricView" << "\n";
1737 di << "D : ResetView" << "\n";
1739 di << "========================="<<"\n";
1740 di << "S : Shading" << "\n";
1741 di << "W : Wireframe" << "\n";
1742 di << "H : HidelLineRemoval" << "\n";
1743 di << "U : Unset display mode" << "\n";
1745 di << "========================="<<"\n";
1746 di << "Selection mode "<<"\n";
1747 di << "0 : Shape" <<"\n";
1748 di << "1 : Vertex" <<"\n";
1749 di << "2 : Edge" <<"\n";
1750 di << "3 : Wire" <<"\n";
1751 di << "4 : Face" <<"\n";
1752 di << "5 : Shell" <<"\n";
1753 di << "6 : Solid" <<"\n";
1754 di << "7 : Compound" <<"\n";
1756 di << "========================="<<"\n";
1757 di << "Z : Switch Z clipping On/Off" << "\n";
1758 di << ", : Hilight next detected" << "\n";
1759 di << ". : Hilight previous detected" << "\n";
1766 static Standard_Boolean Ppick = 0;
1767 static Standard_Integer Pargc = 0;
1768 static const char** Pargv = NULL;
1771 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1776 if (!ViewerTest_myViews.IsEmpty()) {
1778 WPARAM fwKeys = wParam;
1783 // Delete view from map of views
1784 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1789 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1790 || ViewerTest::CurrentView().IsNull())
1792 // Activate inactive window
1793 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1795 ActivateView (FindViewIdByWindowHandle(hwnd));
1800 IsDragged = Standard_False;
1803 HDC hdc = GetDC( hwnd );
1804 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1805 SetROP2( hdc, R2_NOT );
1806 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1807 ReleaseDC( hwnd, hdc );
1809 const Handle(ViewerTest_EventManager) EM =
1810 ViewerTest::CurrentEventManager();
1811 if ( fwKeys & MK_SHIFT )
1812 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1813 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1815 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1816 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1818 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1820 case WM_LBUTTONDOWN:
1821 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1823 IsDragged = Standard_True;
1824 DragFirst = Standard_True;
1825 X_ButtonPress = LOWORD(lParam);
1826 Y_ButtonPress = HIWORD(lParam);
1828 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1835 HDC hdc = GetDC( hwnd );
1837 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1838 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1839 SetROP2( hdc, R2_NOT );
1842 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1844 DragFirst = Standard_False;
1845 X_Motion = LOWORD(lParam);
1846 Y_Motion = HIWORD(lParam);
1848 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1850 SelectObject( hdc, anObj );
1852 ReleaseDC( hwnd, hdc );
1855 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1859 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1863 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1867 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1874 if ( !ViewerTest::CurrentView().IsNull() ) {
1879 BeginPaint(hwnd, &ps);
1880 EndPaint(hwnd, &ps);
1885 VT_ProcessConfigure();
1889 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1892 c[0] = (char) wParam;
1894 VT_ProcessKeyPress (c);
1902 VT_ProcessButton3Release();
1905 case WM_LBUTTONDOWN:
1906 case WM_MBUTTONDOWN:
1907 case WM_RBUTTONDOWN:
1909 WPARAM fwKeys = wParam;
1913 X_ButtonPress = LOWORD(lParam);
1914 Y_ButtonPress = HIWORD(lParam);
1916 if (Msg == WM_LBUTTONDOWN)
1918 if (fwKeys & MK_CONTROL)
1920 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1924 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1927 else if (Msg == WM_RBUTTONDOWN)
1930 VT_ProcessButton3Press();
1937 //cout << "\t WM_MOUSEMOVE" << endl;
1938 WPARAM fwKeys = wParam;
1939 X_Motion = LOWORD(lParam);
1940 Y_Motion = HIWORD(lParam);
1943 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1945 X_ButtonPress = LOWORD(lParam);
1946 Y_ButtonPress = HIWORD(lParam);
1948 if ( fwKeys & MK_RBUTTON ) {
1950 VT_ProcessButton3Press();
1954 if ( fwKeys & MK_CONTROL ) {
1955 if ( fwKeys & MK_LBUTTON ) {
1956 ProcessControlButton1Motion();
1958 else if ( fwKeys & MK_MBUTTON ||
1959 ((fwKeys&MK_LBUTTON) &&
1960 (fwKeys&MK_RBUTTON) ) ){
1961 VT_ProcessControlButton2Motion();
1963 else if ( fwKeys & MK_RBUTTON ) {
1964 VT_ProcessControlButton3Motion();
1968 else if ( fwKeys & MK_SHIFT ) {
1969 if ( fwKeys & MK_MBUTTON ||
1970 ((fwKeys&MK_LBUTTON) &&
1971 (fwKeys&MK_RBUTTON) ) ) {
1972 cout << "ProcessZClipMotion()" << endl;
1973 ProcessZClipMotion();
1977 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
1979 if ((fwKeys & MK_MBUTTON
1980 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
1982 ProcessZClipMotion();
1993 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
1998 return DefWindowProc( hwnd, Msg, wParam, lParam );
2004 //==============================================================================
2005 //function : ViewerMainLoop
2006 //purpose : Get a Event on the view and dispatch it
2007 //==============================================================================
2010 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2012 Ppick = (argc > 0)? 1 : 0;
2020 cout << "Start picking" << endl;
2022 while ( Ppick == 1 ) {
2023 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2024 if (GetMessage(&msg, NULL, 0, 0) ) {
2025 TranslateMessage(&msg);
2026 DispatchMessage(&msg);
2030 cout << "Picking done" << endl;
2036 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2038 int min( int a, int b )
2046 int max( int a, int b )
2054 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2057 static XEvent aReport;
2058 Standard_Boolean pick = argc > 0;
2059 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2060 XNextEvent (aDisplay, &aReport);
2062 // Handle event for the chosen display connection
2063 switch (aReport.type) {
2066 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2069 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2075 // Activate inactive view
2076 Window aWindow = GetWindowHandle(VT_GetWindow());
2077 if(aWindow != aReport.xfocus.window)
2079 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2088 case ConfigureNotify:
2090 VT_ProcessConfigure();
2099 XComposeStatus status_in_out;
2101 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2102 (char *) buf_ret , 10 ,
2103 &ks_ret , &status_in_out ) ;
2106 buf_ret[ret_len] = '\0' ;
2110 VT_ProcessKeyPress (buf_ret);
2116 X_ButtonPress = aReport.xbutton.x;
2117 Y_ButtonPress = aReport.xbutton.y;
2119 if (aReport.xbutton.button == Button1)
2121 if (aReport.xbutton.state & ControlMask)
2123 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2127 IsDragged = Standard_True;
2128 DragFirst = Standard_True;
2131 else if (aReport.xbutton.button == Button3)
2134 VT_ProcessButton3Press();
2144 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2145 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2146 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2149 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2150 if( aContext.IsNull() )
2152 cout << "The context is null. Please use vinit before createmesh" << endl;
2156 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2157 if( aReport.xbutton.button==1 )
2161 aContext->ShiftSelect();
2170 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2171 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2172 ViewerTest::CurrentView());
2176 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2177 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2178 ViewerTest::CurrentView() );
2181 VT_ProcessButton3Release();
2183 IsDragged = Standard_False;
2186 VT_ProcessButton3Release();
2191 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2197 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2198 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2199 XSetFunction( aDisplay, gc, GXinvert );
2202 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2204 X_Motion = aReport.xmotion.x;
2205 Y_Motion = aReport.xmotion.y;
2206 DragFirst = Standard_False;
2208 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2212 X_Motion = aReport.xmotion.x;
2213 Y_Motion = aReport.xmotion.y;
2215 // remove all the ButtonMotionMaskr
2216 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2218 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2219 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2221 Quantity_Length VDX, VDY;
2223 ViewerTest::CurrentView()->Size(VDX,VDY);
2224 Standard_Real VDZ =0 ;
2225 VDZ = ViewerTest::CurrentView()->ZSize();
2227 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2229 Quantity_Length dx = 0 ;
2230 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2234 dx = dx / VDX * VDZ;
2238 ViewerTest::CurrentView()->Redraw();
2242 if ( aReport.xmotion.state & ControlMask ) {
2243 if ( aReport.xmotion.state & Button1Mask ) {
2244 ProcessControlButton1Motion();
2246 else if ( aReport.xmotion.state & Button2Mask ) {
2247 VT_ProcessControlButton2Motion();
2249 else if ( aReport.xmotion.state & Button3Mask ) {
2250 VT_ProcessControlButton3Motion();
2264 //==============================================================================
2265 //function : VProcessEvents
2266 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2267 // event in the Viewer window
2268 //==============================================================================
2270 static void VProcessEvents(ClientData,int)
2272 NCollection_Vector<int> anEventNumbers;
2273 // Get number of messages from every display
2274 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2275 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2277 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2279 // Handle events for every display
2280 int anEventIter = 0;
2281 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2282 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2284 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2285 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2287 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2288 int anEventResult = ViewerMainLoop( 0, NULL);
2289 // If window is closed or context was not found finish current event processing loop
2295 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2300 //==============================================================================
2301 //function : OSWindowSetup
2302 //purpose : Setup for the X11 window to be able to cath the event
2303 //==============================================================================
2306 static void OSWindowSetup()
2308 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2311 Window window = VT_GetWindow()->XWindow();
2312 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2313 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2314 XSynchronize(aDisplay, 1);
2316 // X11 : For keyboard on SUN
2318 wmhints.flags = InputHint;
2321 XSetWMHints( aDisplay, window, &wmhints);
2323 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2324 ButtonPressMask | ButtonReleaseMask |
2325 StructureNotifyMask |
2327 Button1MotionMask | Button2MotionMask |
2328 Button3MotionMask | FocusChangeMask
2330 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2331 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2333 XSynchronize(aDisplay, 0);
2342 //==============================================================================
2345 //purpose : Fitall, no DRAW arguments
2346 //Draw arg : No args
2347 //==============================================================================
2349 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2351 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2352 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2353 if (V.IsNull() == Standard_False) {
2355 } else if (aView.IsNull() == Standard_False) {
2361 //==============================================================================
2363 //purpose : ZFitall, no DRAW arguments
2364 //Draw arg : No args
2365 //==============================================================================
2367 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2369 Handle(V3d_View) V = ViewerTest::CurrentView();
2370 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2373 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2375 Handle(V3d_View) V = ViewerTest::CurrentView();
2376 if ( !V.IsNull() ) V->Redraw(); return 0;
2380 //==============================================================================
2382 //purpose : Remove all the object from the viewer
2383 //Draw arg : No args
2384 //==============================================================================
2386 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2388 Handle(V3d_View) V = ViewerTest::CurrentView();
2390 ViewerTest::Clear();
2394 //==============================================================================
2397 //==============================================================================
2399 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2400 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2403 di << argv[0] << "Invalid number of arguments" << "\n";
2407 while (ViewerMainLoop( argc, argv)) {
2413 //==============================================================================
2414 //function : InitViewerTest
2415 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2416 //==============================================================================
2418 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2420 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2421 ViewerTest::SetAISContext(theContext);
2422 aViewer->InitActiveViews();
2423 Handle(V3d_View) aView = aViewer->ActiveView();
2424 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2425 ViewerTest::ResetEventManager();
2426 Handle(Aspect_Window) aWindow = aView->Window();
2427 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2429 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2431 static int aFirst = 1;
2433 #if TCL_MAJOR_VERSION < 8
2434 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2435 TK_READABLE, VProcessEvents, (ClientData) 0);
2437 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2438 TK_READABLE, VProcessEvents, (ClientData) 0);
2445 //==============================================================================
2447 //purpose : Load image as background
2448 //==============================================================================
2450 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2452 if (argc < 2 || argc > 3)
2454 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2455 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2459 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2460 if(AISContext.IsNull())
2462 di << "use 'vinit' command before " << argv[0] << "\n";
2466 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2469 const char* szType = argv[2];
2470 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2471 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2472 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2473 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2476 di << "Wrong fill type : " << szType << "\n";
2477 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2482 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2483 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2488 //==============================================================================
2489 //function : VSetBgMode
2490 //purpose : Change background image fill type
2491 //==============================================================================
2493 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2497 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2498 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2502 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2503 if(AISContext.IsNull())
2505 di << "use 'vinit' command before " << argv[0] << "\n";
2508 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2509 const char* szType = argv[1];
2510 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2511 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2512 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2513 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2516 di << "Wrong fill type : " << szType << "\n";
2517 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2520 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2521 V3dView->SetBgImageStyle(aFillType, Standard_True);
2525 //==============================================================================
2526 //function : VSetGradientBg
2527 //purpose : Mount gradient background
2528 //==============================================================================
2529 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2533 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2534 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2535 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2536 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2540 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2541 if(AISContext.IsNull())
2543 di << "use 'vinit' command before " << argv[0] << "\n";
2549 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2550 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2551 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2552 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2554 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2555 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2556 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2558 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2559 int aType = Draw::Atoi(argv[7]);
2560 if( aType < 0 || aType > 8 )
2562 di << "Wrong fill type " << "\n";
2563 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2564 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2568 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2570 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2571 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2577 //==============================================================================
2578 //function : VSetGradientBgMode
2579 //purpose : Change gradient background fill style
2580 //==============================================================================
2581 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2585 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2586 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2587 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2591 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2592 if(AISContext.IsNull())
2594 di << "use 'vinit' command before " << argv[0] << "\n";
2599 int aType = Draw::Atoi(argv[1]);
2600 if( aType < 0 || aType > 8 )
2602 di << "Wrong fill type " << "\n";
2603 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2604 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2608 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2610 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2611 V3dView->SetBgGradientStyle( aMethod, 1 );
2617 //==============================================================================
2618 //function : VSetColorBg
2619 //purpose : Set color background
2620 //==============================================================================
2621 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2625 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2626 di << "R,G,B = [0..255]" << "\n";
2630 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2631 if(AISContext.IsNull())
2633 di << "use 'vinit' command before " << argv[0] << "\n";
2639 Standard_Real R = Draw::Atof(argv[1])/255.;
2640 Standard_Real G = Draw::Atof(argv[2])/255.;
2641 Standard_Real B = Draw::Atof(argv[3])/255.;
2642 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2644 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2645 V3dView->SetBackgroundColor( aColor );
2652 //==============================================================================
2654 //purpose : View Scaling
2655 //==============================================================================
2657 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2659 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2660 if ( V3dView.IsNull() ) return 1;
2663 di << argv[0] << "Invalid number of arguments" << "\n";
2666 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2669 //==============================================================================
2670 //function : VTestZBuffTrihedron
2671 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2672 //==============================================================================
2674 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2676 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2677 if ( V3dView.IsNull() ) return 1;
2679 V3dView->ZBufferTriedronSetup();
2682 // Set up default trihedron parameters
2683 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2687 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2688 const char* aPosType = argv[1];
2690 if ( strcmp(aPosType, "center") == 0 )
2692 aPosition = Aspect_TOTP_CENTER;
2694 if (strcmp(aPosType, "left_lower") == 0)
2696 aPosition = Aspect_TOTP_LEFT_LOWER;
2698 if (strcmp(aPosType, "left_upper") == 0)
2700 aPosition = Aspect_TOTP_LEFT_UPPER;
2702 if (strcmp(aPosType, "right_lower") == 0)
2704 aPosition = Aspect_TOTP_RIGHT_LOWER;
2706 if (strcmp(aPosType, "right_upper") == 0)
2708 aPosition = Aspect_TOTP_RIGHT_UPPER;
2711 di << argv[1] << " Invalid type of alignment" << "\n";
2712 di << "Must be one of [ center, left_lower," << "\n";
2713 di << "left_upper, right_lower, right_upper ]" << "\n";
2717 Standard_Real R = Draw::Atof(argv[2])/255.;
2718 Standard_Real G = Draw::Atof(argv[3])/255.;
2719 Standard_Real B = Draw::Atof(argv[4])/255.;
2720 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2722 Standard_Real aScale = Draw::Atof(argv[5]);
2726 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2730 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2731 const char* aPresType = argv[6];
2733 if ( strcmp(aPresType, "wireframe") == 0 )
2735 aPresentation = V3d_WIREFRAME;
2737 if (strcmp(aPresType, "zbuffer") == 0)
2739 aPresentation = V3d_ZBUFFER;
2742 di << argv[6] << " Invalid type of visualization" << "\n";
2743 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2747 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2751 di << argv[0] << " Invalid number of arguments" << "\n";
2760 //==============================================================================
2761 //function : VRotate
2762 //purpose : Camera Rotating
2763 //==============================================================================
2765 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2766 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2767 if ( V3dView.IsNull() ) {
2772 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2774 } else if ( argc == 7 ) {
2775 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]) );
2778 di << argv[0] << " Invalid number of arguments" << "\n";
2783 //==============================================================================
2785 //purpose : View zoom in / out (relative to current zoom)
2786 //==============================================================================
2788 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2789 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2790 if ( V3dView.IsNull() ) {
2795 Standard_Real coef = Draw::Atof(argv[1]);
2796 if ( coef <= 0.0 ) {
2797 di << argv[1] << "Invalid value" << "\n";
2800 V3dView->SetZoom( Draw::Atof(argv[1]) );
2803 di << argv[0] << " Invalid number of arguments" << "\n";
2808 //==============================================================================
2810 //purpose : View panning (in pixels)
2811 //==============================================================================
2813 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2814 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2815 if ( V3dView.IsNull() ) return 1;
2818 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2821 di << argv[0] << " Invalid number of arguments" << "\n";
2827 //==============================================================================
2828 //function : VExport
2829 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2830 //==============================================================================
2832 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2834 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2835 if (V3dView.IsNull())
2840 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2844 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2845 TCollection_AsciiString aFormatStr;
2847 TCollection_AsciiString aFileName (argv[1]);
2848 Standard_Integer aLen = aFileName.Length();
2852 aFormatStr = TCollection_AsciiString (argv[2]);
2856 if (aFileName.Value (aLen - 2) == '.')
2858 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2860 else if (aFileName.Value (aLen - 3) == '.')
2862 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2866 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2872 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2876 aFormatStr.UpperCase();
2877 if (aFormatStr == "PS")
2878 anExpFormat = Graphic3d_EF_PostScript;
2879 else if (aFormatStr == "EPS")
2880 anExpFormat = Graphic3d_EF_EnhPostScript;
2881 else if (aFormatStr == "TEX")
2882 anExpFormat = Graphic3d_EF_TEX;
2883 else if (aFormatStr == "PDF")
2884 anExpFormat = Graphic3d_EF_PDF;
2885 else if (aFormatStr == "SVG")
2886 anExpFormat = Graphic3d_EF_SVG;
2887 else if (aFormatStr == "PGF")
2888 anExpFormat = Graphic3d_EF_PGF;
2889 else if (aFormatStr == "EMF")
2890 anExpFormat = Graphic3d_EF_EMF;
2893 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2898 if (!V3dView->View()->Export (argv[1], anExpFormat))
2900 di << "Error: export of image to " << aFormatStr << " failed!\n";
2903 catch (Standard_Failure)
2905 di << "Error: export of image to " << aFormatStr << " failed";
2906 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2911 //==============================================================================
2912 //function : VColorScale
2913 //purpose : representation color scale
2914 //==============================================================================
2915 #include <V3d_ColorScale.hxx>
2917 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2919 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2921 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2925 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2926 if(aContext.IsNull()) {
2927 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2931 Standard_Real minRange = 0. , maxRange = 100. ;
2933 Standard_Integer numIntervals = 10 ;
2934 Standard_Integer textHeight = 16;
2935 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2936 Standard_Real X = 0., Y = 0. ;
2942 minRange = Draw::Atof( argv[1] );
2943 maxRange = Draw::Atof( argv[2] );
2944 numIntervals = Draw::Atoi( argv[3] );
2947 textHeight = Draw::Atoi( argv[4] );
2949 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2952 X = Draw::Atof( argv[6] );
2953 Y = Draw::Atof( argv[7] );
2956 Handle(V3d_View) curView = ViewerTest::CurrentView( );
2957 if ( curView.IsNull( ) )
2959 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2960 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2961 if( ! aCS.IsNull( ) )
2963 aCS->SetPosition( X , Y );
2964 aCS->SetHeight( 0.95) ;
2965 aCS->SetTextHeight( textHeight );
2966 aCS->SetRange( minRange , maxRange );
2967 aCS->SetNumberOfIntervals( numIntervals );
2968 aCS->SetLabelPosition( position );
2969 if( !curView->ColorScaleIsDisplayed() )
2970 curView->ColorScaleDisplay( );
2975 //==============================================================================
2976 //function : VGraduatedTrihedron
2977 //purpose : Displays a graduated trihedron
2978 //==============================================================================
2980 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2982 const char *str = arg;
2985 unsigned short c1 = *str++;
2986 unsigned short c2 = *str++;
2987 if (!c1 || !c2) break;
2988 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2992 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2995 if (argc != 2 && argc < 5)
2997 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2998 di<<"Usage: type help "<<argv[0]<<"\n";
2999 return 1; //TCL_ERROR
3002 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3004 // Create 3D view if it doesn't exist
3005 if ( aV3dView.IsNull() )
3007 ViewerTest::ViewerInit();
3008 aV3dView = ViewerTest::CurrentView();
3009 if( aV3dView.IsNull() )
3011 di << "Error: Cannot create a 3D view\n";
3012 return 1; //TCL_ERROR
3016 // Erase (==0) or display (!=0)
3017 const int display = Draw::Atoi(argv[1]);
3022 TCollection_AsciiString font;
3024 font.AssignCat("Courier");
3026 font.AssignCat(argv[5]);
3028 // Text is multibyte
3029 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3032 TCollection_ExtendedString xname, yname, zname;
3037 AddMultibyteString(xname, argv[2]);
3038 AddMultibyteString(yname, argv[3]);
3039 AddMultibyteString(zname, argv[4]);
3055 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3056 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3057 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3058 Standard_True/*drawgrid*/,
3059 Standard_True/*drawaxes*/,
3060 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3061 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3062 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3063 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3064 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3065 Quantity_NOC_WHITE/*gridcolor*/,
3066 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3067 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3070 aV3dView->GraduatedTrihedronErase();
3072 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3078 //==============================================================================
3079 //function : VPrintView
3080 //purpose : Test printing algorithm, print the view to image file with given
3081 // width and height. Printing implemented only for WNT.
3082 //==============================================================================
3083 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3087 di << "Printing implemented only for wnt!\n";
3091 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3092 Handle(V3d_View) aView = NULL;
3093 aContextAIS = ViewerTest::GetAISContext();
3094 if (!aContextAIS.IsNull())
3096 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3097 Vwr->InitActiveViews();
3098 if(Vwr->MoreActiveViews())
3099 aView = Vwr->ActiveView();
3105 di << "Call vinit before!\n";
3110 di << "Use: " << argv[0];
3111 di << " width height filename [print algo=0]\n";
3112 di << "width, height of the intermediate buffer for operation\n";
3113 di << "algo : {0|1}\n";
3114 di << " 0 - stretch algorithm\n";
3115 di << " 1 - tile algorithm\n";
3116 di << "test printing algorithms into an intermediate buffer\n";
3117 di << "with saving output to an image file\n";
3121 // get the input params
3122 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3123 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3124 Standard_Integer aMode = 0;
3125 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3127 aMode = Draw::Atoi (argv[4]);
3129 // check the input parameters
3130 if (aWidth <= 0 || aHeight <= 0)
3132 di << "Width and height must be positive values!\n";
3135 if (aMode != 0 && aMode != 1)
3138 // define compatible bitmap
3139 HDC anDC = CreateCompatibleDC(0);
3140 BITMAPINFO aBitmapData;
3141 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3142 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3143 aBitmapData.bmiHeader.biWidth = aWidth ;
3144 aBitmapData.bmiHeader.biHeight = aHeight;
3145 aBitmapData.bmiHeader.biPlanes = 1;
3146 aBitmapData.bmiHeader.biBitCount = 24;
3147 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3148 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3149 aBitmapData.bmiHeader.biClrUsed = 0;
3150 aBitmapData.bmiHeader.biClrImportant = 0;
3151 aBitmapData.bmiHeader.biCompression = BI_RGB;
3152 aBitmapData.bmiHeader.biSizeImage = 0;
3154 // Create Device Independent Bitmap
3155 void* aBitsOut = NULL;
3156 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3157 &aBitsOut, NULL, 0);
3158 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3160 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3161 if (aBitsOut != NULL)
3164 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3166 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3168 // succesfully printed into an intermediate buffer
3171 Image_PixMap aWrapper;
3172 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3173 aWrapper.SetTopDown (false);
3175 Image_AlienPixMap anImageBitmap;
3176 anImageBitmap.InitCopy (aWrapper);
3177 isSaved = anImageBitmap.Save (aFileName);
3181 di << "Print operation failed due to printing errors or\n";
3182 di << "insufficient memory available\n";
3183 di << "Please, try to use smaller dimensions for this test\n";
3184 di << "command, as it allocates intermediate buffer for storing\n";
3185 di << "the result\n";
3190 di << "Can't allocate memory for intermediate buffer\n";
3191 di << "Please use smaller dimensions\n";
3196 SelectObject (anDC, anOldBitmap);
3197 DeleteObject (aMemoryBitmap);
3203 di << "Save to file operation failed. This operation may fail\n";
3204 di << "if you don't have enough available memory, then you can\n";
3205 di << "use smaller dimensions for the output file\n";
3214 //==============================================================================
3215 //function : VZLayer
3216 //purpose : Test z layer operations for v3d viewer
3217 //==============================================================================
3218 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3220 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3221 if (aContextAIS.IsNull())
3223 di << "Call vinit before!\n";
3228 di << "Use: vzlayer " << argv[0];
3229 di << " add/del/get [id]\n";
3230 di << " add - add new z layer to viewer and print its id\n";
3231 di << " del - del z layer by its id\n";
3232 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3233 di << "id - the layer identificator value defined when removing z layer\n";
3237 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3238 if (aViewer.IsNull())
3240 di << "No active viewer!\n";
3244 // perform operation
3245 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3248 Standard_Integer aNewId;
3249 if (!aViewer->AddZLayer (aNewId))
3251 di << "Impossible to add new z layer!\n";
3255 di << "New z layer added with index: " << aNewId << "\n";
3257 else if (anOp == "del")
3261 di << "Please also provide as argument id of z layer to remove\n";
3265 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3266 if (!aViewer->RemoveZLayer (aDelId))
3268 di << "Impossible to remove the z layer or invalid id!\n";
3272 di << "Z layer " << aDelId << " has been removed\n";
3274 else if (anOp == "get")
3276 TColStd_SequenceOfInteger anIds;
3277 aViewer->GetAllZLayers (anIds);
3278 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3280 di << anIds.Value (aSeqIdx) << " ";
3287 di << "Invalid operation, please use { add / del / get }\n";
3294 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3296 // this class provides a presentation of text item in v3d view under-/overlayer
3297 class V3d_TextItem : public Visual3d_LayerItem
3302 DEFINE_STANDARD_RTTI(V3d_TextItem)
3305 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3306 const Standard_Real theX1,
3307 const Standard_Real theY1,
3308 const Standard_Real theHeight,
3309 const TCollection_AsciiString& theFontName,
3310 const Quantity_Color& theColor,
3311 const Quantity_Color& theSubtitleColor,
3312 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3313 const Handle(Visual3d_Layer)& theLayer);
3316 Standard_EXPORT void RedrawLayerPrs();
3322 Standard_Real myHeight;
3323 TCollection_AsciiString myText;
3324 TCollection_AsciiString myFontName;
3325 Quantity_Color myColor;
3326 Quantity_Color mySubtitleColor;
3327 Aspect_TypeOfDisplayText myType;
3328 Handle(Visual3d_Layer) myLayer;
3332 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3333 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3335 // create and add to display the text item
3336 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3337 const Standard_Real theX1,
3338 const Standard_Real theY1,
3339 const Standard_Real theHeight,
3340 const TCollection_AsciiString& theFontName,
3341 const Quantity_Color& theColor,
3342 const Quantity_Color& theSubtitleColor,
3343 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3344 const Handle(Visual3d_Layer)& theLayer)
3345 : myX1 (theX1), myY1 (theY1),
3347 myHeight (theHeight),
3350 mySubtitleColor (theSubtitleColor),
3351 myType (theTypeOfDisplay),
3352 myFontName (theFontName)
3354 if (!myLayer.IsNull ())
3355 myLayer->AddLayerItem (this);
3359 void V3d_TextItem::RedrawLayerPrs ()
3361 if (myLayer.IsNull ())
3364 myLayer->SetColor (myColor);
3365 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3366 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3369 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3371 // The Visual3d_LayerItem line item for "vlayerline" command
3372 // it provides a presentation of line with user-defined
3373 // linewidth, linetype and transparency.
3374 class V3d_LineItem : public Visual3d_LayerItem
3378 DEFINE_STANDARD_RTTI(V3d_LineItem)
3381 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3382 Standard_Real X2, Standard_Real Y2,
3383 V3d_LayerMgrPointer theLayerMgr,
3384 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3385 Standard_Real theWidth = 0.5,
3386 Standard_Real theTransp = 1.0);
3389 Standard_EXPORT void RedrawLayerPrs();
3393 Standard_Real myX1, myY1, myX2, myY2;
3394 Standard_Real myWidth;
3395 Standard_Real myTransparency;
3396 Aspect_TypeOfLine myType;
3397 V3d_LayerMgrPointer myLayerMgr;
3400 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3401 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3403 // default constructor for line item
3404 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3405 Standard_Real X2, Standard_Real Y2,
3406 V3d_LayerMgrPointer theLayerMgr,
3407 Aspect_TypeOfLine theType,
3408 Standard_Real theWidth,
3409 Standard_Real theTransp) :
3410 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3411 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3413 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3414 myLayerMgr->Overlay()->AddLayerItem (this);
3418 void V3d_LineItem::RedrawLayerPrs ()
3420 Handle (Visual3d_Layer) aOverlay;
3423 aOverlay = myLayerMgr->Overlay();
3425 if (!aOverlay.IsNull())
3427 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3428 aOverlay->SetColor(aColor);
3429 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3430 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3431 aOverlay->BeginPolyline();
3432 aOverlay->AddVertex(myX1, myY1);
3433 aOverlay->AddVertex(myX2, myY2);
3434 aOverlay->ClosePrimitive();
3438 //=============================================================================
3439 //function : VLayerLine
3440 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3441 // : linewidth, transparency coefficient
3442 //============================================================================
3443 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3445 // get the active view
3446 Handle(V3d_View) aView = ViewerTest::CurrentView();
3449 di << "Call vinit before!\n";
3454 di << "Use: " << argv[0];
3455 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3456 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3457 di << " 0 - solid \n";
3458 di << " 1 - dashed \n";
3459 di << " 2 - dot \n";
3460 di << " 3 - dashdot\n";
3461 di << " transparency : { 0.0 - 1.0 } \n";
3462 di << " 0.0 - transparent\n";
3463 di << " 1.0 - visible \n";
3467 // get the input params
3468 Standard_Real X1 = Draw::Atof(argv[1]);
3469 Standard_Real Y1 = Draw::Atof(argv[2]);
3470 Standard_Real X2 = Draw::Atof(argv[3]);
3471 Standard_Real Y2 = Draw::Atof(argv[4]);
3473 Standard_Real aWidth = 0.5;
3474 Standard_Integer aType = 0;
3475 Standard_Real aTransparency = 1.0;
3479 aWidth = Draw::Atof(argv[5]);
3483 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3488 aTransparency = Draw::Atof(argv[7]);
3489 if (aTransparency < 0 || aTransparency > 1.0)
3490 aTransparency = 1.0;
3493 // select appropriate line type
3494 Aspect_TypeOfLine aLineType;
3498 aLineType = Aspect_TOL_DASH;
3502 aLineType = Aspect_TOL_DOT;
3506 aLineType = Aspect_TOL_DOTDASH;
3510 aLineType = Aspect_TOL_SOLID;
3513 // replace layer manager
3514 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3515 aView->SetLayerMgr(aMgr);
3518 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3524 aView->MustBeResized();
3530 //=======================================================================
3531 //function : VOverlayText
3532 //purpose : Test text displaying in view overlay
3533 //=======================================================================
3534 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3536 // get the active view
3537 Handle(V3d_View) aView = ViewerTest::CurrentView();
3540 di << "No active view. Please call vinit.\n";
3543 else if (argc < 4 || argc > 13)
3545 di << "Use: " << argv[0];
3546 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3547 di << "[background_color: R G B]\n";
3548 di << " height - pixel height of the text (default=10.0)\n";
3549 di << " font_name - name of font (default=courier)\n";
3550 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3551 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
3552 di << " background_color- R G B values used for subtitle and decal text\n";
3553 di << "(default=255.0 255.0 255.0)\n";
3557 TCollection_AsciiString aText (argv[1]);
3558 Standard_Real aPosX = Draw::Atof(argv[2]);
3559 Standard_Real aPosY = Draw::Atof(argv[3]);
3560 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3563 TCollection_AsciiString aFontName = "Courier";
3565 aFontName = TCollection_AsciiString (argv[5]);
3568 Quantity_Parameter aColorRed = 1.0;
3569 Quantity_Parameter aColorGreen = 1.0;
3570 Quantity_Parameter aColorBlue = 1.0;
3573 aColorRed = Draw::Atof (argv[6])/255.;
3574 aColorGreen = Draw::Atof (argv[7])/255.;
3575 aColorBlue = Draw::Atof (argv[8])/255.;
3579 TCollection_AsciiString aDispStr;
3581 aDispStr = TCollection_AsciiString (argv[9]);
3583 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3584 if (aDispStr.IsEqual ("subtitle"))
3585 aTextType = Aspect_TODT_SUBTITLE;
3586 else if (aDispStr.IsEqual ("decal"))
3587 aTextType = Aspect_TODT_DEKALE;
3588 else if (aDispStr.IsEqual ("blend"))
3589 aTextType = Aspect_TODT_BLEND;
3592 Quantity_Parameter aSubRed = 1.0;
3593 Quantity_Parameter aSubGreen = 1.0;
3594 Quantity_Parameter aSubBlue = 1.0;
3597 aSubRed = Draw::Atof (argv[10])/255.;
3598 aSubGreen = Draw::Atof (argv[11])/255.;
3599 aSubBlue = Draw::Atof (argv[12])/255.;
3602 // check fo current overlay
3603 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3604 if (anOverlay.IsNull ())
3606 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3607 anOverlay = aMgr->Overlay ();
3608 aView->SetLayerMgr (aMgr);
3611 Quantity_Color aTextColor (aColorRed, aColorGreen,
3612 aColorBlue, Quantity_TOC_RGB);
3613 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3614 aSubBlue, Quantity_TOC_RGB);
3617 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3618 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3621 aView->MustBeResized();
3627 //==============================================================================
3630 //==============================================================================
3632 static int VGrid (Draw_Interpretor& /*theDI*/,
3633 Standard_Integer theArgNb,
3634 const char** theArgVec)
3636 // get the active view
3637 Handle(V3d_View) aView = ViewerTest::CurrentView();
3638 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3639 if (aView.IsNull() || aViewer.IsNull())
3641 std::cerr << "No active view. Please call vinit.\n";
3645 Aspect_GridType aType = aViewer->GridType();
3646 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3648 Standard_Integer anIter = 1;
3649 for (; anIter < theArgNb; ++anIter)
3651 const char* aValue = theArgVec[anIter];
3654 aType = Aspect_GT_Rectangular;
3656 else if (*aValue == 'c')
3658 aType = Aspect_GT_Circular;
3660 else if (*aValue == 'l')
3662 aMode = Aspect_GDM_Lines;
3664 else if (*aValue == 'p')
3666 aMode = Aspect_GDM_Points;
3668 else if (strcmp (aValue, "off" ) == 0)
3670 aViewer->DeactivateGrid();
3679 Standard_Integer aTail = (theArgNb - anIter);
3682 aViewer->ActivateGrid (aType, aMode);
3685 else if (aTail != 2 && aTail != 5)
3687 std::cerr << "Incorrect arguments number! Usage:\n"
3688 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3692 Quantity_Length anOriginX, anOriginY;
3693 Quantity_PlaneAngle aRotAngle;
3694 if (aType == Aspect_GT_Rectangular)
3696 Quantity_Length aRStepX, aRStepY;
3697 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3699 anOriginX = Draw::Atof (theArgVec[anIter++]);
3700 anOriginY = Draw::Atof (theArgVec[anIter++]);
3703 aRStepX = Draw::Atof (theArgVec[anIter++]);
3704 aRStepY = Draw::Atof (theArgVec[anIter++]);
3705 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3707 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3708 aViewer->ActivateGrid (aType, aMode);
3710 else if (aType == Aspect_GT_Circular)
3712 Quantity_Length aRadiusStep;
3713 Standard_Integer aDivisionNumber;
3714 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3716 anOriginX = Draw::Atof (theArgVec[anIter++]);
3717 anOriginY = Draw::Atof (theArgVec[anIter++]);
3720 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3721 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3722 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3725 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3726 aViewer->ActivateGrid (aType, aMode);
3732 //==============================================================================
3735 //==============================================================================
3737 static int VFps (Draw_Interpretor& theDI,
3738 Standard_Integer theArgNb,
3739 const char** theArgVec)
3741 // get the active view
3742 Handle(V3d_View) aView = ViewerTest::CurrentView();
3745 std::cerr << "No active view. Please call vinit.\n";
3749 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3752 std::cerr << "Incorrect arguments!\n";
3756 // the time is meaningless for first call
3757 // due to async OpenGl rendering
3760 // redraw view in loop to estimate average values
3763 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3769 const Standard_Real aTime = aTimer.ElapsedTime();
3770 aTimer.OSD_Chronometer::Show (aCpu);
3772 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3773 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3775 // return statistics
3776 theDI << "FPS: " << aFpsAver << "\n"
3777 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3782 //==============================================================================
3783 //function : VGlDebug
3785 //==============================================================================
3787 static int VGlDebug (Draw_Interpretor& theDI,
3788 Standard_Integer theArgNb,
3789 const char** theArgVec)
3793 Handle(V3d_View) aView = ViewerTest::CurrentView();
3796 std::cerr << "No active view. Please call vinit.\n";
3800 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3801 "GL_ARB_debug_output");
3802 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3803 theDI << (isActive ? "1" : "0");
3807 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3811 //==============================================================================
3814 //==============================================================================
3816 static int VVbo (Draw_Interpretor& theDI,
3817 Standard_Integer theArgNb,
3818 const char** theArgVec)
3820 const Standard_Boolean toSet = (theArgNb > 1);
3821 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3824 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
3828 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3829 if (aContextAIS.IsNull())
3833 std::cerr << "No active view!\n";
3837 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3838 if (!aDriver.IsNull())
3842 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3846 aDriver->ChangeOptions().vboDisable = toUseVbo;
3853 //==============================================================================
3856 //==============================================================================
3858 static int VCaps (Draw_Interpretor& theDI,
3859 Standard_Integer theArgNb,
3860 const char** theArgVec)
3862 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
3863 Handle(OpenGl_GraphicDriver) aDriver;
3864 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3865 if (!aContextAIS.IsNull())
3867 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3868 aCaps = &aDriver->ChangeOptions();
3873 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
3874 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
3878 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3880 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
3881 if (anArg.Search ("vbo=") > -1)
3883 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3885 else if (anArg.Search ("sprites=") > -1)
3887 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3891 std::cerr << "Unknown argument: " << anArg << "\n";
3894 if (aCaps != &ViewerTest_myDefaultCaps)
3896 ViewerTest_myDefaultCaps = *aCaps;
3901 //==============================================================================
3902 //function : VMemGpu
3904 //==============================================================================
3906 static int VMemGpu (Draw_Interpretor& theDI,
3907 Standard_Integer theArgNb,
3908 const char** theArgVec)
3911 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3912 if (aContextAIS.IsNull())
3914 std::cerr << "No active view. Please call vinit.\n";
3918 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3919 if (aDriver.IsNull())
3921 std::cerr << "Graphic driver not available.\n";
3925 Standard_Size aFreeBytes = 0;
3926 TCollection_AsciiString anInfo;
3927 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3929 std::cerr << "Information not available.\n";
3933 if (theArgNb > 1 && *theArgVec[1] == 'f')
3935 theDI << Standard_Real (aFreeBytes);
3945 // ==============================================================================
3946 // function : VReadPixel
3948 // ==============================================================================
3949 static int VReadPixel (Draw_Interpretor& theDI,
3950 Standard_Integer theArgNb,
3951 const char** theArgVec)
3953 // get the active view
3954 Handle(V3d_View) aView = ViewerTest::CurrentView();
3957 std::cerr << "No active view. Please call vinit.\n";
3960 else if (theArgNb < 3)
3962 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
3966 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3967 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
3969 Standard_Integer aWidth, aHeight;
3970 aView->Window()->Size (aWidth, aHeight);
3971 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
3972 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
3973 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
3975 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
3979 Standard_Boolean toShowName = Standard_False;
3980 Standard_Boolean toShowHls = Standard_False;
3981 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
3983 const char* aParam = theArgVec[anIter];
3984 if ( strcasecmp( aParam, "rgb" ) == 0 )
3986 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
3987 aBufferType = Graphic3d_BT_RGB;
3989 else if ( strcasecmp( aParam, "hls" ) == 0 )
3991 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
3992 aBufferType = Graphic3d_BT_RGB;
3993 toShowHls = Standard_True;
3995 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
3997 aFormat = Image_PixMap::ImgRGBF;
3998 aBufferType = Graphic3d_BT_RGB;
4000 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4002 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4003 aBufferType = Graphic3d_BT_RGBA;
4005 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4007 aFormat = Image_PixMap::ImgRGBAF;
4008 aBufferType = Graphic3d_BT_RGBA;
4010 else if ( strcasecmp( aParam, "depth" ) == 0 )
4012 aFormat = Image_PixMap::ImgGrayF;
4013 aBufferType = Graphic3d_BT_Depth;
4015 else if ( strcasecmp( aParam, "name" ) == 0 )
4017 toShowName = Standard_True;
4021 Image_PixMap anImage;
4022 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4024 std::cerr << "Image allocation failed\n";
4027 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4029 std::cerr << "Image dump failed\n";
4033 Quantity_Parameter anAlpha;
4034 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4037 if (aBufferType == Graphic3d_BT_RGBA)
4039 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
4043 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
4048 switch (aBufferType)
4051 case Graphic3d_BT_RGB:
4055 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
4059 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
4063 case Graphic3d_BT_RGBA:
4065 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
4068 case Graphic3d_BT_Depth:
4070 theDI << aColor.Red() << "\n";
4079 //==============================================================================
4080 //function : VDiffImage
4081 //purpose : The draw-command compares two images.
4082 //==============================================================================
4084 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4088 theDI << "Not enough arguments.\n";
4093 const char* anImgPathRef = theArgVec[1];
4094 const char* anImgPathNew = theArgVec[2];
4096 // get string tolerance and check its validity
4097 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4098 if (aTolColor < 0.0)
4100 if (aTolColor > 1.0)
4103 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4104 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4106 // image file of difference
4107 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4109 // compare the images
4110 Image_Diff aComparer;
4111 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4116 aComparer.SetColorTolerance (aTolColor);
4117 aComparer.SetBorderFilterOn (isBorderFilterOn);
4118 Standard_Integer aDiffColorsNb = aComparer.Compare();
4119 theDI << aDiffColorsNb << "\n";
4121 // save image of difference
4122 if (aDiffImagePath != NULL)
4124 aComparer.SaveDiffImage (aDiffImagePath);
4130 //=======================================================================
4131 //function : VSelect
4132 //purpose : Emulates different types of selection by mouse:
4133 // 1) single click selection
4134 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4135 // 3) selection with polygon having corners at
4136 // pixel positions (x1,y1),...,(xn,yn)
4137 // 4) any of these selections with shift button pressed
4138 //=======================================================================
4139 static Standard_Integer VSelect (Draw_Interpretor& di,
4140 Standard_Integer argc,
4145 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4149 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4150 if(myAIScontext.IsNull())
4152 di << "use 'vinit' command before " << argv[0] << "\n";
4155 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4156 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4157 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4160 if(isShiftSelection)
4161 aCurrentEventManager->ShiftSelect();
4163 aCurrentEventManager->Select();
4167 if(isShiftSelection)
4168 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4170 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4174 Standard_Integer anUpper = 0;
4176 if(isShiftSelection)
4177 anUpper = (argc-1)/2;
4180 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4182 for(Standard_Integer i=1;i<=anUpper;++i)
4183 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4185 if(isShiftSelection)
4186 aCurrentEventManager->ShiftSelect(aPolyline);
4188 aCurrentEventManager->Select(aPolyline);
4193 //=======================================================================
4194 //function : VMoveTo
4195 //purpose : Emulates cursor movement to defined pixel position
4196 //=======================================================================
4197 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4198 Standard_Integer argc,
4203 di << "Usage : " << argv[0] << " x y" << "\n";
4207 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4208 if(aContext.IsNull())
4210 di << "use 'vinit' command before " << argv[0] << "\n";
4213 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4217 //=======================================================================
4218 //function : VViewParams
4219 //purpose : Gets or sets AIS View characteristics
4220 //=======================================================================
4221 static Standard_Integer VViewParams (Draw_Interpretor& di,
4222 Standard_Integer argc,
4225 if ( argc != 1 && argc != 13)
4227 di << "Usage : " << argv[0] << "\n";
4230 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
4231 if ( anAISView.IsNull () )
4233 di << "use 'vinit' command before " << argv[0] << "\n";
4237 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
4238 Standard_Real anAISViewCenterCoordinateX = 0.0;
4239 Standard_Real anAISViewCenterCoordinateY = 0.0;
4240 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4241 Standard_Real anAISViewProjX = 0.0;
4242 Standard_Real anAISViewProjY = 0.0;
4243 Standard_Real anAISViewProjZ = 0.0;
4244 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4245 Standard_Real anAISViewUpX = 0.0;
4246 Standard_Real anAISViewUpY = 0.0;
4247 Standard_Real anAISViewUpZ = 0.0;
4248 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4249 Standard_Real anAISViewAtX = 0.0;
4250 Standard_Real anAISViewAtY = 0.0;
4251 Standard_Real anAISViewAtZ = 0.0;
4252 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4253 di << "Scale of current view: " << anAISViewScale << "\n";
4254 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
4255 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4256 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4257 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4261 Quantity_Factor anAISViewScale = atof (argv [1]);
4262 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
4263 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
4264 Standard_Real anAISViewProjX = atof (argv [4]);
4265 Standard_Real anAISViewProjY = atof (argv [5]);
4266 Standard_Real anAISViewProjZ = atof (argv [6]);
4267 Standard_Real anAISViewUpX = atof (argv [7]);
4268 Standard_Real anAISViewUpY = atof (argv [8]);
4269 Standard_Real anAISViewUpZ = atof (argv [9]);
4270 Standard_Real anAISViewAtX = atof (argv [10]);
4271 Standard_Real anAISViewAtY = atof (argv [11]);
4272 Standard_Real anAISViewAtZ = atof (argv [12]);
4273 anAISView -> V3d_View::SetScale (anAISViewScale);
4274 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4275 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4276 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4277 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4282 //=======================================================================
4283 //function : VChangeSelected
4284 //purpose : Adds the shape to selection or remove one from it
4285 //=======================================================================
4286 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4287 Standard_Integer argc,
4292 di<<"Usage : " << argv[0] << " shape \n";
4296 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4297 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4298 TCollection_AsciiString aName(argv[1]);
4299 Handle(AIS_InteractiveObject) anAISObject;
4301 if(!aMap.IsBound2(aName))
4303 di<<"Use 'vdisplay' before";
4308 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4309 if(anAISObject.IsNull()){
4310 di<<"No interactive object \n";
4314 if(aContext->HasOpenedContext())
4316 aContext->AddOrRemoveSelected(anAISObject);
4320 aContext->AddOrRemoveCurrentObject(anAISObject);
4326 //=======================================================================
4327 //function : VZClipping
4328 //purpose : Gets or sets ZClipping mode, width and depth
4329 //=======================================================================
4330 static Standard_Integer VZClipping (Draw_Interpretor& di,
4331 Standard_Integer argc,
4336 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4337 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4340 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4341 if(aContext.IsNull())
4343 di << "use 'vinit' command before " << argv[0] << "\n";
4346 Handle(V3d_View) aView = ViewerTest::CurrentView();
4347 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4350 TCollection_AsciiString aZClippingModeString;
4351 Quantity_Length aDepth, aWidth;
4352 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4353 switch (aZClippingMode)
4356 aZClippingModeString.Copy("OFF");
4359 aZClippingModeString.Copy("BACK");
4362 aZClippingModeString.Copy("FRONT");
4365 aZClippingModeString.Copy("SLICE");
4368 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4371 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4372 << "ZClipping depth = " << aDepth << "\n"
4373 << "ZClipping width = " << aWidth << "\n";
4379 Standard_Integer aStatus = 0;
4380 if ( strcmp (argv [1], "OFF") == 0 ) {
4382 aZClippingMode = V3d_OFF;
4384 if ( strcmp (argv [1], "BACK") == 0 ) {
4386 aZClippingMode = V3d_BACK;
4388 if ( strcmp (argv [1], "FRONT") == 0 ) {
4390 aZClippingMode = V3d_FRONT;
4392 if ( strcmp (argv [1], "SLICE") == 0 ) {
4394 aZClippingMode = V3d_SLICE;
4398 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4399 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4402 aView->SetZClippingType(aZClippingMode);
4406 Quantity_Length aDepth = 0., aWidth = 1.;
4409 aDepth = atof(argv[1]);
4410 aWidth = atof(argv[2]);
4414 aDepth = atof(argv[2]);
4415 aWidth = atof(argv[3]);
4418 if(aDepth<0. || aDepth>1.)
4420 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4421 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4424 if(aWidth<0. || aWidth>1.)
4426 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4427 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4431 aView->SetZClippingDepth(aDepth);
4432 aView->SetZClippingWidth(aWidth);
4439 //=======================================================================
4440 //function : VNbSelected
4441 //purpose : Returns number of selected objects
4442 //=======================================================================
4443 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4444 Standard_Integer argc,
4449 di << "Usage : " << argv[0] << "\n";
4452 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4453 if(aContext.IsNull())
4455 di << "use 'vinit' command before " << argv[0] << "\n";
4458 di << aContext->NbSelected() << "\n";
4462 //=======================================================================
4463 //function : VAntialiasing
4464 //purpose : Switches altialiasing on or off
4465 //=======================================================================
4466 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4467 Standard_Integer argc,
4472 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4476 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4477 if(aContext.IsNull())
4479 di << "use 'vinit' command before " << argv[0] << "\n";
4483 Handle(V3d_View) aView = ViewerTest::CurrentView();
4485 if((argc == 2) && (atof(argv[1]) == 0))
4486 aView->SetAntialiasingOff();
4488 aView->SetAntialiasingOn();
4493 //=======================================================================
4494 //function : VPurgeDisplay
4495 //purpose : Switches altialiasing on or off
4496 //=======================================================================
4497 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4498 Standard_Integer argc,
4503 di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
4506 Standard_Boolean isCollectorToo = Standard_False;
4509 isCollectorToo = (atoi(argv [1]) != 0);
4511 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4512 if (aContext.IsNull())
4514 di << "use 'vinit' command before " << argv[0] << "\n";
4517 aContext->CloseAllContexts(Standard_False);
4518 di << aContext->PurgeDisplay(isCollectorToo) << "\n";
4522 //=======================================================================
4523 //function : VSetViewSize
4525 //=======================================================================
4526 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4527 Standard_Integer argc,
4530 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4531 if(aContext.IsNull())
4533 di << "use 'vinit' command before " << argv[0] << "\n";
4538 di<<"Usage : " << argv[0] << " Size\n";
4541 Standard_Real aSize = atof(argv[1]);
4544 di<<"Bad Size value : " << aSize << "\n";
4548 Handle(V3d_View) aView = ViewerTest::CurrentView();
4549 aView->SetSize(aSize);
4553 //=======================================================================
4554 //function : VMoveView
4556 //=======================================================================
4557 static Standard_Integer VMoveView (Draw_Interpretor& di,
4558 Standard_Integer argc,
4561 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4562 if(aContext.IsNull())
4564 di << "use 'vinit' command before " << argv[0] << "\n";
4567 if(argc < 4 || argc > 5)
4569 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4572 Standard_Real Dx = atof(argv[1]);
4573 Standard_Real Dy = atof(argv[2]);
4574 Standard_Real Dz = atof(argv[3]);
4575 Standard_Boolean aStart = Standard_True;
4578 aStart = (atoi(argv[4]) > 0);
4581 Handle(V3d_View) aView = ViewerTest::CurrentView();
4582 aView->Move(Dx,Dy,Dz,aStart);
4586 //=======================================================================
4587 //function : VTranslateView
4589 //=======================================================================
4590 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4591 Standard_Integer argc,
4594 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4595 if(aContext.IsNull())
4597 di << "use 'vinit' command before " << argv[0] << "\n";
4600 if(argc < 4 || argc > 5)
4602 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4605 Standard_Real Dx = atof(argv[1]);
4606 Standard_Real Dy = atof(argv[2]);
4607 Standard_Real Dz = atof(argv[3]);
4608 Standard_Boolean aStart = Standard_True;
4611 aStart = (atoi(argv[4]) > 0);
4614 Handle(V3d_View) aView = ViewerTest::CurrentView();
4615 aView->Translate(Dx,Dy,Dz,aStart);
4619 //=======================================================================
4620 //function : VTurnView
4622 //=======================================================================
4623 static Standard_Integer VTurnView (Draw_Interpretor& di,
4624 Standard_Integer argc,
4627 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4628 if(aContext.IsNull()) {
4629 di << "use 'vinit' command before " << argv[0] << "\n";
4632 if(argc < 4 || argc > 5){
4633 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4636 Standard_Real Ax = atof(argv[1]);
4637 Standard_Real Ay = atof(argv[2]);
4638 Standard_Real Az = atof(argv[3]);
4639 Standard_Boolean aStart = Standard_True;
4642 aStart = (atoi(argv[4]) > 0);
4645 Handle(V3d_View) aView = ViewerTest::CurrentView();
4646 aView->Turn(Ax,Ay,Az,aStart);
4650 //==============================================================================
4651 //function : VTextureEnv
4652 //purpose : ENables or disables environment mapping
4653 //==============================================================================
4654 class OCC_TextureEnv : public Graphic3d_TextureEnv
4657 OCC_TextureEnv(const Standard_CString FileName);
4658 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4659 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4660 const Standard_Boolean theModulateFlag,
4661 const Graphic3d_TypeOfTextureFilter theFilter,
4662 const Standard_ShortReal theXScale,
4663 const Standard_ShortReal theYScale,
4664 const Standard_ShortReal theXShift,
4665 const Standard_ShortReal theYShift,
4666 const Standard_ShortReal theAngle);
4667 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4669 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4670 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4671 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4673 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4674 : Graphic3d_TextureEnv(theFileName)
4678 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4679 : Graphic3d_TextureEnv(theTexId)
4683 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4684 const Standard_Boolean theModulateFlag,
4685 const Graphic3d_TypeOfTextureFilter theFilter,
4686 const Standard_ShortReal theXScale,
4687 const Standard_ShortReal theYScale,
4688 const Standard_ShortReal theXShift,
4689 const Standard_ShortReal theYShift,
4690 const Standard_ShortReal theAngle)
4692 myParams->SetRepeat (theRepeatFlag);
4693 myParams->SetModulate (theModulateFlag);
4694 myParams->SetFilter (theFilter);
4695 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
4696 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4697 myParams->SetRotation (theAngle);
4700 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4702 // get the active view
4703 Handle(V3d_View) aView = ViewerTest::CurrentView();
4706 std::cerr << "No active view. Please call vinit.\n";
4710 // Checking the input arguments
4711 Standard_Boolean anEnableFlag = Standard_False;
4712 Standard_Boolean isOk = theArgNb >= 2;
4715 TCollection_AsciiString anEnableOpt(theArgVec[1]);
4716 anEnableFlag = anEnableOpt.IsEqual("on");
4717 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
4721 isOk = (theArgNb == 3 || theArgNb == 11);
4724 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4725 isOk = (!aTextureOpt.IsIntegerValue() ||
4726 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
4728 if (isOk && theArgNb == 11)
4730 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
4731 aModulateOpt(theArgVec[4]),
4732 aFilterOpt (theArgVec[5]),
4733 aSScaleOpt (theArgVec[6]),
4734 aTScaleOpt (theArgVec[7]),
4735 aSTransOpt (theArgVec[8]),
4736 aTTransOpt (theArgVec[9]),
4737 anAngleOpt (theArgVec[10]);
4738 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
4739 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
4740 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
4741 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
4742 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
4743 anAngleOpt.IsRealValue());
4750 std::cerr << "Usage :" << std::endl;
4751 std::cerr << theArgVec[0] << " off" << std::endl;
4752 std::cerr << theArgVec[0] << " on {index_of_std_texture(0..7)|texture_file_name} [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} scale_s scale_t translation_s translation_t rotation_degrees]" << std::endl;
4758 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4759 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
4760 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
4761 new OCC_TextureEnv(theArgVec[2]);
4765 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
4766 aTexEnv->SetTextureParameters(
4767 aRepeatOpt. IsEqual("repeat"),
4768 aModulateOpt.IsEqual("modulate"),
4769 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
4770 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
4771 Graphic3d_TOTF_TRILINEAR,
4772 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
4773 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
4774 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
4775 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
4776 (Standard_ShortReal)Draw::Atof(theArgVec[10])
4779 aView->SetTextureEnv(aTexEnv);
4780 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
4782 else // Disabling environment mapping
4784 aView->SetSurfaceDetail(V3d_TEX_NONE);
4785 Handle(Graphic3d_TextureEnv) aTexture;
4786 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
4793 //=======================================================================
4794 //function : ViewerCommands
4796 //=======================================================================
4798 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
4801 const char *group = "ZeViewer";
4802 theCommands.Add("vinit",
4803 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4804 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
4806 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
4808 " - Creates new View window with specified name view_name.\n"
4809 "By default the new view is created in the viewer and in"
4810 " graphic driver shared with active view.\n"
4811 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
4812 "If driverName isn't specified the driver will be shared with active view.\n"
4813 "If viewerName isn't specified the viewer will be shared with active view.\n"
4814 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4815 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
4816 "is used in creation of graphic driver\n"
4818 " - l, t: pixel position of left top corner of the window\n"
4819 " - w,h: width and heigth of window respectively.\n"
4820 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
4821 __FILE__,VInit,group);
4822 theCommands.Add("vclose" ,
4823 "view_id [keep_context=0|1]\n"
4824 "or vclose ALL - to remove all created views\n"
4825 " - removes view(viewer window) defined by its view_id.\n"
4826 " - keep_context: by default 0; if 1 and the last view is deleted"
4827 " the current context is not removed.",
4828 __FILE__,VClose,group);
4829 theCommands.Add("vactivate" ,
4831 " - activates view(viewer window) defined by its view_id",
4832 __FILE__,VActivate,group);
4833 theCommands.Add("vviewlist",
4834 "vviewlist [format={tree, long}]"
4835 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
4836 " - format: format of result output, if tree the output is a tree view;"
4837 "otherwise it's a list of full view names. By default format = tree",
4838 __FILE__,VViewList,group);
4839 theCommands.Add("vhelp" ,
4840 "vhelp : display help on the viewer commands",
4841 __FILE__,VHelp,group);
4842 theCommands.Add("vtop" ,
4843 "vtop or <T> : Top view" ,
4844 __FILE__,VTop,group);
4845 theCommands.Add("vbottom" ,
4846 "vbottom : Bottom view" ,
4847 __FILE__,VBottom,group);
4848 theCommands.Add("vleft" ,
4849 "vleft : Left view" ,
4850 __FILE__,VLeft,group);
4851 theCommands.Add("vright" ,
4852 "vright : Right view" ,
4853 __FILE__,VRight,group);
4854 theCommands.Add("vaxo" ,
4855 " vaxo or <A> : Axonometric view ",
4856 __FILE__,VAxo,group);
4857 theCommands.Add("vfront" ,
4858 "vfront : Front view" ,
4859 __FILE__,VFront,group);
4860 theCommands.Add("vback" ,
4861 "vback : Back view" ,
4862 __FILE__,VBack,group);
4863 theCommands.Add("vpick" ,
4864 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
4866 theCommands.Add("vfit" ,
4867 "vfit or <F> : vfit",
4868 __FILE__,VFit,group);
4869 theCommands.Add("vzfit" ,
4871 __FILE__,VZFit,group);
4872 theCommands.Add("vrepaint",
4873 "vrepaint : vrepaint, force redraw",
4874 __FILE__,VRepaint,group);
4875 theCommands.Add("vclear",
4877 __FILE__,VClear,group);
4878 theCommands.Add("vsetbg",
4879 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
4880 __FILE__,VSetBg,group);
4881 theCommands.Add("vsetbgmode",
4882 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
4883 __FILE__,VSetBgMode,group);
4884 theCommands.Add("vsetgradientbg",
4885 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
4886 __FILE__,VSetGradientBg,group);
4887 theCommands.Add("vsetgrbgmode",
4888 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
4889 __FILE__,VSetGradientBgMode,group);
4890 theCommands.Add("vsetcolorbg",
4891 "vsetcolorbg : vsetcolorbg r g b : Set background color",
4892 __FILE__,VSetColorBg,group);
4893 theCommands.Add("vscale",
4894 "vscale : vscale X Y Z",
4895 __FILE__,VScale,group);
4896 theCommands.Add("vzbufftrihedron",
4897 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
4898 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
4899 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
4900 __FILE__,VTestZBuffTrihedron,group);
4901 theCommands.Add("vrotate",
4902 "vrotate : vrotate AX AY AZ [X Y Z]",
4903 __FILE__,VRotate,group);
4904 theCommands.Add("vzoom",
4905 "vzoom : vzoom coef",
4906 __FILE__,VZoom,group);
4907 theCommands.Add("vpan",
4908 "vpan : vpan dx dy",
4909 __FILE__,VPan,group);
4910 theCommands.Add("vexport",
4911 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
4912 " : exports the view to a vector file of a given format"
4913 " : notice that EMF format requires patched gl2ps",
4914 __FILE__,VExport,group);
4915 theCommands.Add("vcolorscale",
4916 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
4917 __FILE__,VColorScale,group);
4918 theCommands.Add("vgraduatedtrihedron",
4919 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
4920 __FILE__,VGraduatedTrihedron,group);
4921 theCommands.Add("vprintview" ,
4922 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
4923 __FILE__,VPrintView,group);
4924 theCommands.Add("vzlayer",
4925 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
4926 __FILE__,VZLayer,group);
4927 theCommands.Add("voverlaytext",
4928 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
4929 " : height - pixel height of the text (default=10.0)"
4930 " : font_name - name of font (default=courier)"
4931 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
4932 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
4933 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
4934 __FILE__,VOverlayText,group);
4935 theCommands.Add("vlayerline",
4936 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
4937 __FILE__,VLayerLine,group);
4938 theCommands.Add ("vgrid",
4939 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
4940 " : Mode - rectangular or circular"
4941 " : Type - lines or points",
4942 __FILE__, VGrid, group);
4943 theCommands.Add ("vfps",
4944 "vfps [framesNb=100] : estimate average frame rate for active view",
4945 __FILE__, VFps, group);
4946 theCommands.Add ("vgldebug",
4947 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
4948 " : this function is implemented only for Windows\n"
4949 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
4950 __FILE__, VGlDebug, group);
4951 theCommands.Add ("vvbo",
4952 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
4953 __FILE__, VVbo, group);
4954 theCommands.Add ("vcaps",
4955 "vcaps [vbo={0|1}] [sprites={0|1}] : modify particular graphic driver options",
4956 __FILE__, VCaps, group);
4957 theCommands.Add ("vmemgpu",
4958 "vmemgpu [f]: print system-dependent GPU memory information if available;"
4959 " with f option returns free memory in bytes",
4960 __FILE__, VMemGpu, group);
4961 theCommands.Add ("vreadpixel",
4962 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
4963 " : Read pixel value for active view",
4964 __FILE__, VReadPixel, group);
4965 theCommands.Add("diffimage",
4966 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
4967 __FILE__, VDiffImage, group);
4968 theCommands.Add ("vselect",
4969 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
4970 "- emulates different types of selection:\n"
4971 "- 1) single click selection\n"
4972 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
4973 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
4974 "- 4) any of these selections with shift button pressed",
4975 __FILE__, VSelect, group);
4976 theCommands.Add ("vmoveto",
4978 "- emulates cursor movement to pixel postion (x,y)",
4979 __FILE__, VMoveTo, group);
4980 theCommands.Add("vviewparams",
4981 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
4982 "- gets or sets current view characteristics",
4983 __FILE__,VViewParams, group);
4984 theCommands.Add("vchangeselected",
4985 "vchangeselected shape"
4986 "- adds to shape to selection or remove one from it",
4987 __FILE__, VChangeSelected, group);
4988 theCommands.Add("vzclipping",
4989 "vzclipping [mode] [depth width]\n"
4990 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
4991 "- gets or sets ZClipping mode, width and depth",
4992 __FILE__,VZClipping,group);
4993 theCommands.Add ("vnbselected",
4994 "vnbselected", __FILE__, VNbSelected, group);
4995 theCommands.Add("vantialiasing",
4996 "vantialiasing 1|0",
4997 __FILE__,VAntialiasing,group);
4998 theCommands.Add ("vpurgedisplay",
4999 "vpurgedisplay [CollectorToo = 0|1]"
5000 "- removes structures which don't belong to objects displayed in neutral point",
5001 __FILE__, VPurgeDisplay, group);
5002 theCommands.Add("vsetviewsize",
5003 "vsetviewsize size",
5004 __FILE__,VSetViewSize,group);
5005 theCommands.Add("vmoveview",
5006 "vmoveview Dx Dy Dz [Start = 1|0]",
5007 __FILE__,VMoveView,group);
5008 theCommands.Add("vtranslateview",
5009 "vtranslateview Dx Dy Dz [Start = 1|0)]",
5010 __FILE__,VTranslateView,group);
5011 theCommands.Add("vturnview",
5012 "vturnview Ax Ay Az [Start = 1|0]",
5013 __FILE__,VTurnView,group);
5014 theCommands.Add("vtextureenv",
5015 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
5016 "or user-defined file and optionally applying texture mapping parameters\n"
5018 " vtextureenv off - disables environment mapping\n"
5019 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
5020 " std_texture = (0..7)\n"
5021 " rep = {clamp|repeat}\n"
5022 " mod = {decal|modulate}\n"
5023 " flt = {nearest|bilinear|trilinear}\n"
5024 " ss, st - scale factors for s and t texture coordinates\n"
5025 " ts, tt - translation for s and t texture coordinates\n"
5026 " rot - texture rotation angle in degrees",
5027 __FILE__, VTextureEnv, group);
5028 theCommands.Add("vhlr" ,
5029 "is_enabled={on|off}"
5030 " - Hidden line removal algorithm:"
5031 " - is_enabled: if is on HLR algorithm is applied\n",
5032 __FILE__,VHLR,group);
5033 theCommands.Add("vhlrtype" ,
5034 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
5035 " - Changes the type of HLR algorithm using for shapes."
5036 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
5037 " if equals to polyalgo, polygonal HLR algorithm is applied."
5038 "If shapes are not given HLR algoithm of given type is applied"
5039 " to all shapes in the view\n",
5040 __FILE__,VHLRType,group);