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
32 #include <AIS_Shape.hxx>
33 #include <AIS_Drawer.hxx>
34 #include <AIS_InteractiveObject.hxx>
35 #include <AIS_ListOfInteractive.hxx>
36 #include <AIS_ListIteratorOfListOfInteractive.hxx>
38 #include <Graphic3d_AspectMarker3d.hxx>
39 #include <Graphic3d_GraphicDriver.hxx>
40 #include <Graphic3d_ExportFormat.hxx>
41 #include <Graphic3d_NameOfTextureEnv.hxx>
42 #include <Graphic3d_TextureEnv.hxx>
43 #include <Graphic3d_TextureParams.hxx>
44 #include <Graphic3d_TypeOfTextureFilter.hxx>
45 #include <ViewerTest.hxx>
46 #include <ViewerTest_EventManager.hxx>
47 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
48 #include <Visual3d_View.hxx>
49 #include <Visual3d_ViewManager.hxx>
50 #include <V3d_LayerMgr.hxx>
51 #include <NCollection_DoubleMap.hxx>
52 #include <NCollection_List.hxx>
53 #include <NCollection_Vector.hxx>
54 #include <NIS_View.hxx>
55 #include <NIS_Triangulated.hxx>
56 #include <NIS_InteractiveContext.hxx>
57 #include <AIS_InteractiveContext.hxx>
58 #include <Draw_Interpretor.hxx>
60 #include <Draw_Appli.hxx>
61 #include <Aspect_PrintAlgo.hxx>
62 #include <Image_AlienPixMap.hxx>
63 #include <OSD_Timer.hxx>
64 #include <TColStd_SequenceOfInteger.hxx>
65 #include <TColStd_HSequenceOfReal.hxx>
66 #include <TColgp_Array1OfPnt2d.hxx>
67 #include <Visual3d_LayerItem.hxx>
68 #include <V3d_LayerMgr.hxx>
69 #include <V3d_LayerMgrPointer.hxx>
70 #include <Aspect_TypeOfLine.hxx>
71 #include <Image_Diff.hxx>
72 #include <Aspect_DisplayConnection.hxx>
73 #include <Graphic3d.hxx>
79 #include <Visual3d_Layer.hxx>
82 #if defined(_WIN32) || defined(__WIN32__)
83 #include <WNT_WClass.hxx>
84 #include <WNT_Window.hxx>
87 #define _CRT_SECURE_NO_DEPRECATE
88 #pragma warning (disable:4996)
90 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
91 #include <Cocoa_Window.hxx>
94 #include <Xw_Window.hxx>
95 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
96 #include <X11/Xutil.h>
100 //==============================================================================
102 //==============================================================================
103 // VIEWER GLOBAL VARIABLES
104 //==============================================================================
106 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
108 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
109 extern const Handle(NIS_InteractiveContext)& TheNISContext();
110 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
112 #if defined(_WIN32) || defined(__WIN32__)
113 static Handle(WNT_Window)& VT_GetWindow() {
114 static Handle(WNT_Window) WNTWin;
117 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
118 static Handle(Cocoa_Window)& VT_GetWindow()
120 static Handle(Cocoa_Window) aWindow;
123 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
124 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
125 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
128 static Handle(Xw_Window)& VT_GetWindow(){
129 static Handle(Xw_Window) XWWin;
133 static void VProcessEvents(ClientData,int);
136 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
138 static Handle(Aspect_DisplayConnection) aDisplayConnection;
139 return aDisplayConnection;
142 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
144 GetDisplayConnection() = theDisplayConnection;
147 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
148 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
150 Aspect_Handle aWindowHandle = NULL;
151 #if defined(_WIN32) || defined(__WIN32__)
152 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
153 if (!aWindow.IsNull())
154 return aWindow->HWindow();
155 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
156 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
157 if (!aWindow.IsNull())
158 return aWindow->XWindow();
160 return aWindowHandle;
164 static Standard_Boolean MyHLRIsOn = Standard_False;
166 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
167 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
168 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
171 #define ZCLIPWIDTH 1.
173 static void OSWindowSetup();
175 //==============================================================================
176 // EVENT GLOBAL VARIABLES
177 //==============================================================================
179 static int Start_Rot = 0;
180 static int ZClipIsOn = 0;
181 int X_Motion = 0; // Current cursor position
183 int X_ButtonPress = 0; // Last ButtonPress position
184 int Y_ButtonPress = 0;
185 Standard_Boolean IsDragged = Standard_False;
186 Standard_Boolean DragFirst;
188 //==============================================================================
191 static LRESULT WINAPI ViewerWindowProc(
196 static LRESULT WINAPI AdvViewerWindowProc(
204 //==============================================================================
207 //==============================================================================
209 const Handle(MMgt_TShared)& ViewerTest::WClass()
211 static Handle(MMgt_TShared) theWClass;
212 #if defined(_WIN32) || defined(__WIN32__)
213 if (theWClass.IsNull())
215 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
216 CS_VREDRAW | CS_HREDRAW, 0, 0,
217 ::LoadCursor (NULL, IDC_ARROW));
223 //==============================================================================
224 //function : CreateName
225 //purpose : Create numerical name for new object in theMap
226 //==============================================================================
227 template <typename ObjectType>
228 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
229 const TCollection_AsciiString& theDefaultString)
231 if (theObjectMap.IsEmpty())
232 return theDefaultString + TCollection_AsciiString(1);
234 Standard_Integer aNextKey = 1;
235 Standard_Boolean isFound = Standard_False;
238 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
239 // Look for objects with default names
240 if (theObjectMap.IsBound1(aStringKey))
245 isFound = Standard_True;
248 return theDefaultString + TCollection_AsciiString(aNextKey);
251 //==============================================================================
252 //structure : ViewerTest_Names
253 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
254 //==============================================================================
255 struct ViewerTest_Names
258 TCollection_AsciiString myDriverName;
259 TCollection_AsciiString myViewerName;
260 TCollection_AsciiString myViewName;
264 const TCollection_AsciiString& GetDriverName () const
268 void SetDriverName (const TCollection_AsciiString& theDriverName)
270 myDriverName = theDriverName;
272 const TCollection_AsciiString& GetViewerName () const
276 void SetViewerName (const TCollection_AsciiString& theViewerName)
278 myViewerName = theViewerName;
280 const TCollection_AsciiString& GetViewName () const
284 void SetViewName (const TCollection_AsciiString& theViewName)
286 myViewName = theViewName;
289 //===========================================================================
290 //function : Constructor for ViewerTest_Names
291 //purpose : Get view, viewer, driver names from custom string
292 //===========================================================================
294 ViewerTest_Names (const TCollection_AsciiString& theInputString)
296 TCollection_AsciiString aName(theInputString);
297 if (theInputString.IsEmpty())
299 // Get current configuration
300 if (ViewerTest_myDrivers.IsEmpty())
301 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
302 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
304 myDriverName = ViewerTest_myDrivers.Find2
305 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
307 if(ViewerTest_myContexts.IsEmpty())
309 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
310 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
313 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
315 myViewName = CreateName <Handle(V3d_View)>
316 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
320 // There is at least view name
321 Standard_Integer aParserNumber = 0;
322 for (Standard_Integer i = 0; i < 3; ++i)
324 Standard_Integer aParserPos = aName.SearchFromEnd("/");
328 aName.Split(aParserPos-1);
333 if (aParserNumber == 0)
336 if (!ViewerTest::GetAISContext().IsNull())
338 myDriverName = ViewerTest_myDrivers.Find2
339 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
340 myViewerName = ViewerTest_myContexts.Find2
341 (ViewerTest::GetAISContext());
345 // There is no opened contexts here, need to create names for viewer and driver
346 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
347 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
349 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
350 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
352 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
354 else if (aParserNumber == 1)
356 // Here is viewerName/viewName
357 if (!ViewerTest::GetAISContext().IsNull())
358 myDriverName = ViewerTest_myDrivers.Find2
359 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
362 // There is no opened contexts here, need to create name for driver
363 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
364 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
366 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
368 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
372 //Here is driverName/viewerName/viewName
373 myDriverName = TCollection_AsciiString(aName);
375 TCollection_AsciiString aViewerName(theInputString);
376 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
377 myViewerName = TCollection_AsciiString(aViewerName);
379 myViewName = TCollection_AsciiString(theInputString);
385 //==============================================================================
386 //function : FindContextByView
387 //purpose : Find AIS_InteractiveContext by View
388 //==============================================================================
390 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
392 Handle(AIS_InteractiveContext) anAISContext;
394 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
395 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
397 if (anIter.Value()->CurrentViewer() == theView->Viewer())
398 return anIter.Key2();
404 //==============================================================================
405 //function : SetWindowTitle
406 //purpose : Set window title
407 //==============================================================================
409 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
410 Standard_CString theTitle)
412 #if defined(_WIN32) || defined(__WIN32__)
413 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
415 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
416 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
418 if(GetDisplayConnection()->GetDisplay())
421 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
422 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
427 //==============================================================================
428 //function : IsWindowOverlapped
429 //purpose : Check if theWindow overlapp another view
430 //==============================================================================
432 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
433 const Standard_Integer thePxTop,
434 const Standard_Integer thePxRight,
435 const Standard_Integer thePxBottom,
436 TCollection_AsciiString& theViewId)
438 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
439 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
441 Standard_Integer aTop = 0,
445 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
446 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
447 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
448 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
449 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
451 theViewId = anIter.Key1();
452 return Standard_True;
455 return Standard_False;
458 // Workaround: to create and delete non-orthographic views outside ViewerTest
459 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
461 ViewerTest_myViews.UnBind1 (theName);
464 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
465 const Handle(V3d_View)& theView)
467 ViewerTest_myViews.Bind (theName, theView);
470 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
472 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
474 //==============================================================================
475 //function : ViewerInit
476 //purpose : Create the window viewer and initialize all the global variable
477 //==============================================================================
479 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
480 const Standard_Integer thePxTop,
481 const Standard_Integer thePxWidth,
482 const Standard_Integer thePxHeight,
483 Standard_CString theViewName,
484 Standard_CString theDisplayName)
486 // Default position and dimension of the viewer window.
487 // Note that left top corner is set to be sufficiently small to have
488 // window fit in the small screens (actual for remote desktops, see #23003).
489 // The position corresponds to the window's client area, thus some
490 // gap is added for window frame to be visible.
492 Standard_Integer aPxLeft = 20;
493 Standard_Integer aPxTop = 40;
494 Standard_Integer aPxWidth = 409;
495 Standard_Integer aPxHeight = 409;
496 Standard_Boolean toCreateViewer = Standard_False;
499 Handle(Graphic3d_GraphicDriver) aGraphicDriver;
500 ViewerTest_Names aViewNames(theViewName);
501 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
502 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
509 aPxWidth = thePxWidth;
510 if (thePxHeight != 0)
511 aPxHeight = thePxHeight;
513 // Get graphic driver (create it or get from another view)
514 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
516 // Get connection string
517 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
518 TCollection_AsciiString aDisplayName(theDisplayName);
519 if (aDisplayName.IsEmpty())
520 SetDisplayConnection (new Aspect_DisplayConnection ());
522 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
525 SetDisplayConnection (new Aspect_DisplayConnection ());
527 aGraphicDriver = Graphic3d::InitGraphicDriver (GetDisplayConnection());
528 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
529 toCreateViewer = Standard_True;
533 aGraphicDriver = ViewerTest_myDrivers.Find1(aViewNames.GetDriverName());
536 //Dispose the window if input parameters are default
537 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
539 Standard_Integer aTop = 0,
546 // Get screen resolution
547 #if defined(_WIN32) || defined(__WIN32__)
549 GetClientRect(GetDesktopWindow(), &aWindowSize);
550 aScreenHeight = aWindowSize.bottom;
551 aScreenWidth = aWindowSize.right;
552 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
553 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
555 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
556 aScreenWidth = WidthOfScreen(aScreen);
557 aScreenHeight = HeightOfScreen(aScreen);
560 TCollection_AsciiString anOverlappedViewId("");
562 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
564 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
566 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
567 && aRight + 2*aPxWidth + 40 > aScreenWidth)
569 if (aBottom + aPxHeight + 40 > aScreenHeight)
576 aPxTop = aBottom + 40;
579 aPxLeft = aRight + 20;
584 TCollection_AsciiString aTitle("3D View - ");
585 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
587 // Change name of current active window
588 if (!ViewerTest::CurrentView().IsNull())
590 TCollection_AsciiString aTitle("3D View - ");
592 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
593 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
597 Handle(V3d_Viewer) a3DViewer, a3DCollector;
598 // If it's the single view, we first look for empty context
599 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
601 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
602 anIter(ViewerTest_myContexts);
604 ViewerTest::SetAISContext (anIter.Value());
605 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
606 a3DCollector= ViewerTest::GetAISContext()->Collector();
608 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
610 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
611 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
612 a3DCollector= ViewerTest::GetAISContext()->Collector();
614 else if (a3DViewer.IsNull() || a3DCollector.IsNull())
616 toCreateViewer = Standard_True;
617 TCollection_ExtendedString NameOfWindow("Viewer3D");
618 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
620 NameOfWindow = TCollection_ExtendedString("Collector");
621 a3DCollector = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
623 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
624 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
628 if (ViewerTest::GetAISContext().IsNull() ||
629 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
631 Handle(AIS_InteractiveContext) aContext =
632 new AIS_InteractiveContext(a3DViewer, a3DCollector);
633 ViewerTest::SetAISContext (aContext);
634 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
637 ViewerTest::ResetEventManager();
640 #if defined(_WIN32) || defined(__WIN32__)
641 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
642 Handle(WNT_WClass)::DownCast (WClass()),
647 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
648 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
650 aPxWidth, aPxHeight);
651 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
653 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
656 aPxWidth, aPxHeight);
658 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
661 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
663 ViewerTest::CurrentView(aView);
664 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
665 TheNISContext()->AttachView (aView);
667 // Setup for X11 or NT
670 // Set parameters for V3d_View and V3d_Viewer
671 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
672 aV3dView->SetComputedMode(Standard_False);
673 MyHLRIsOn = aV3dView->ComputedMode();
674 aV3dView->SetZClippingDepth(0.5);
675 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
677 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
680 a3DViewer->SetDefaultLights();
681 a3DViewer->SetLightOn();
684 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
685 #if TCL_MAJOR_VERSION < 8
686 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
687 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
689 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
690 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
694 VT_GetWindow()->Map();
696 // Set the handle of created view in the event manager
697 ViewerTest::ResetEventManager();
699 ViewerTest::CurrentView()->Redraw();
703 a3DCollector.Nullify();
705 return aViewNames.GetViewName();
708 //==============================================================================
709 //function : SplitParameter
710 //purpose : Split parameter string to parameter name an patameter value
711 //==============================================================================
712 Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
713 TCollection_AsciiString& theName,
714 TCollection_AsciiString& theValue)
716 Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
717 if (aParamNameEnd == 0)
718 return Standard_False;
719 TCollection_AsciiString aString(theString);
720 if (aParamNameEnd != 0)
722 theValue = aString.Split(aParamNameEnd);
723 aString.Split(aString.Length()-1);
726 return Standard_True;
729 //==============================================================================
731 //purpose : Create the window viewer and initialize all the global variable
732 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
733 //==============================================================================
735 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
739 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
740 << "Type help for more information.\n";
743 TCollection_AsciiString aViewName (""),
745 Standard_Integer aPxLeft = 0,
750 for (Standard_Integer i = 1; i < theArgsNb; ++i)
752 TCollection_AsciiString aName = "", aValue = "";
753 if(!SplitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
755 // In case of syntax: vinit ViewName
756 aViewName = theArgVec[1];
764 else if (aName == "l" || aName == "left")
765 aPxLeft = aValue.IntegerValue();
766 else if (aName == "t" || aName == "top")
767 aPxTop = aValue.IntegerValue();
768 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
769 else if (aName == "display")
770 aDisplayName = aValue;
772 else if (aName == "w" || aName == "width")
773 aPxWidth = aValue.IntegerValue();
774 else if (aName == "h" || aName == "height")
775 aPxHeight = aValue.IntegerValue();
778 theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n";
783 ViewerTest_Names aViewNames (aViewName);
784 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
786 TCollection_AsciiString aCommand("vactivate ");
787 aCommand = aCommand + aViewNames.GetViewName();
788 theDi.Eval(aCommand.ToCString());
792 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
793 aViewName.ToCString(),
794 aDisplayName.ToCString());
795 cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n";
799 //==============================================================================
801 //purpose : hidden lines removal algorithm
802 //==============================================================================
804 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
806 if (ViewerTest::CurrentView().IsNull())
808 di << argv[0] << ": Call vinit before this command, please.\n";
814 di << argv[0] << ": Wrong number of command arguments.\n"
815 << "Type help " << argv[0] << " for more information.\n";
819 Standard_Boolean isHLROn =
820 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
822 if (isHLROn == MyHLRIsOn)
828 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
833 //==============================================================================
834 //function : VHLRType
835 //purpose : change type of using HLR algorithm
836 //==============================================================================
838 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
840 if (ViewerTest::CurrentView().IsNull())
842 di << argv[0] << ": Call vinit before this command, please.\n";
848 di << argv[0] << ": Wrong number of command arguments.\n"
849 << "Type help " << argv[0] << " for more information.\n";
853 Prs3d_TypeOfHLR aTypeOfHLR =
854 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
858 AIS_ListOfInteractive aListOfShapes;
859 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
860 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
861 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
862 anIter.More(); anIter.Next())
864 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
867 if (aShape->TypeOfHLR() != aTypeOfHLR)
868 aShape->SetTypeOfHLR (aTypeOfHLR);
872 ViewerTest::CurrentView()->Update();
877 for (Standard_Integer i = 2; i < argc; ++i)
879 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
880 TCollection_AsciiString aName (argv[i]);
882 if (!aMap.IsBound2 (aName))
884 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
887 Handle(AIS_Shape) anAISObject =
888 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
889 if (anAISObject.IsNull())
891 anAISObject->SetTypeOfHLR (aTypeOfHLR);
893 anAISObject->Redisplay();
895 ViewerTest::CurrentView()->Update();
901 //==============================================================================
902 //function : FindViewIdByWindowHandle
903 //purpose : Find theView Id in the map of views by window handle
904 //==============================================================================
905 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
906 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
908 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
909 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
911 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
912 if (aWindowHandle == theWindowHandle)
913 return anIter.Key1();
915 return TCollection_AsciiString("");
919 //==============================================================================
920 //function : ActivateView
921 //purpose : Make the view active
922 //==============================================================================
924 void ActivateView (const TCollection_AsciiString& theViewName)
926 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
929 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
930 if (!anAISContext.IsNull())
932 if (!ViewerTest::CurrentView().IsNull())
934 TCollection_AsciiString aTitle("3D View - ");
935 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
936 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
939 ViewerTest::CurrentView (aView);
940 // Update degenerate mode
941 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
942 ViewerTest::SetAISContext (anAISContext);
943 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
944 aTitle = aTitle + theViewName + "(*)";
945 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
946 #if defined(_WIN32) || defined(__WIN32__)
947 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
948 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
949 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
951 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
953 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
954 ViewerTest::CurrentView()->Redraw();
959 //==============================================================================
960 //function : RemoveView
961 //purpose : Close and remove view from display, clear maps if neccessary
962 //==============================================================================
963 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
965 if (!ViewerTest_myViews.IsBound1(theViewName))
967 cout << "Wrong view name\n";
971 // Activate another view if it's active now
972 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
974 if (ViewerTest_myViews.Extent() > 1)
976 TCollection_AsciiString aNewViewName;
977 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
978 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
979 if (anIter.Key1() != theViewName)
981 aNewViewName = anIter.Key1();
984 ActivateView (aNewViewName);
988 Handle(V3d_View) anEmptyView;
989 #if defined(_WIN32) || defined(__WIN32__)
990 Handle(WNT_Window) anEmptyWindow;
991 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
992 Handle(Cocoa_Window) anEmptyWindow;
994 Handle(Xw_Window) anEmptyWindow;
996 VT_GetWindow() = anEmptyWindow;
997 ViewerTest::CurrentView (anEmptyView);
998 if (isContextRemoved)
1000 Handle(AIS_InteractiveContext) anEmptyContext;
1001 ViewerTest::SetAISContext(anEmptyContext);
1007 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1008 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1010 // Remove view resources
1011 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1012 ViewerTest_myViews.UnBind1(theViewName);
1015 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1016 XFlush (GetDisplayConnection()->GetDisplay());
1019 // Keep context opened only if the closed view is last to avoid
1020 // unused empty contexts
1021 if (!aCurrentContext.IsNull())
1023 // Check if there are more difined views in the viewer
1024 aCurrentContext->CurrentViewer()->InitDefinedViews();
1025 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1027 // Remove driver if there is no viewers that use it
1028 Standard_Boolean isRemoveDriver = Standard_True;
1029 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1030 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1032 if (aCurrentContext != anIter.Key2() &&
1033 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1035 isRemoveDriver = Standard_False;
1041 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1042 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1043 #if TCL_MAJOR_VERSION < 8
1044 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1046 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1051 ViewerTest_myContexts.UnBind2(aCurrentContext);
1054 cout << "3D View - " << theViewName << " was deleted.\n";
1058 //==============================================================================
1060 //purpose : Remove the view defined by its name
1061 //==============================================================================
1063 static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1067 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
1068 << "Type help " << theArgVec[0] << " for more information.\n";
1072 if (ViewerTest_myViews.IsEmpty())
1074 theDi << theArgVec[0] <<": there is no views to close.\n";
1078 TCollection_AsciiString anInputString(theArgVec[1]);
1080 // Create list to iterate and remove views from the map of views
1081 NCollection_List<TCollection_AsciiString> aViewList;
1082 if ( strcasecmp( anInputString.ToCString(), "ALL" ) == 0 )
1084 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
1085 anIter.More(); anIter.Next())
1087 aViewList.Append(anIter.Key1());
1092 ViewerTest_Names aViewNames(anInputString);
1093 aViewList.Append(aViewNames.GetViewName());
1096 Standard_Boolean isContextRemoved = (theArgsNb == 3 && atoi(theArgVec[2])==1) ? Standard_False : Standard_True;
1097 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1098 anIter.More(); anIter.Next())
1100 ViewerTest::RemoveView(anIter.Value(), isContextRemoved);
1106 //==============================================================================
1107 //function : VActivate
1108 //purpose : Activate the view defined by its ID
1109 //==============================================================================
1111 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1115 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1116 << "Usage: " << theArgVec[0] << " ViewID\n";
1121 theDi.Eval("vviewlist");
1125 TCollection_AsciiString aNameString(theArgVec[1]);
1126 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1128 TCollection_AsciiString aTitle("3D View - ");
1129 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1130 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1131 Handle(V3d_View) anEmptyView;
1132 #if defined(_WIN32) || defined(__WIN32__)
1133 Handle(WNT_Window) anEmptyWindow;
1134 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1135 Handle(Cocoa_Window) anEmptyWindow;
1137 Handle(Xw_Window) anEmptyWindow;
1139 VT_GetWindow() = anEmptyWindow;
1140 ViewerTest::CurrentView (anEmptyView);
1141 ViewerTest::ResetEventManager();
1142 theDi << theArgVec[0] << ": all views are inactive\n";
1146 ViewerTest_Names aViewNames(aNameString);
1148 // Check if this view exists in the viewer with the driver
1149 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1151 theDi << "Wrong view name\n";
1155 // Check if it is active already
1156 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1158 theDi << theArgVec[0] << ": the view is active already\n";
1162 ActivateView (aViewNames.GetViewName());
1166 //==============================================================================
1167 //function : VViewList
1168 //purpose : Print current list of views per viewer and graphic driver ID
1169 // shared between viewers
1170 //==============================================================================
1172 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1176 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1177 << "Usage: " << theArgVec[0] << " name";
1180 if (ViewerTest_myContexts.Size() < 1)
1183 Standard_Boolean isTreeView =
1184 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1187 theDi << theArgVec[0] <<":\n";
1189 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1190 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1193 theDi << aDriverIter.Key1() << ":\n";
1195 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1196 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1198 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1202 TCollection_AsciiString aContextName(aContextIter.Key1());
1203 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1206 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1207 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1209 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1211 TCollection_AsciiString aViewName(aViewIter.Key1());
1214 if (aViewIter.Value() == ViewerTest::CurrentView())
1215 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1217 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1221 theDi << aViewName << " ";
1231 //==============================================================================
1232 //function : VT_ProcessKeyPress
1233 //purpose : Handle KeyPress event from a CString
1234 //==============================================================================
1235 void VT_ProcessKeyPress (const char* buf_ret)
1237 //cout << "KeyPress" << endl;
1238 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1239 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1240 // Letter in alphabetic order
1242 if ( !strcasecmp(buf_ret, "A") ) {
1244 aView->SetProj(V3d_XposYnegZpos);
1246 else if ( !strcasecmp(buf_ret, "D") ) {
1250 else if ( !strcasecmp(buf_ret, "F") ) {
1252 if (aNisView.IsNull())
1255 aNisView->FitAll3d();
1257 else if ( !strcasecmp(buf_ret, "H") ) {
1259 cout << "HLR" << endl;
1260 aView->SetComputedMode (!aView->ComputedMode());
1261 MyHLRIsOn = aView->ComputedMode();
1263 else if ( !strcasecmp(buf_ret, "P") ) {
1265 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1266 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1267 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1269 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1270 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1272 AIS_ListOfInteractive aListOfShapes;
1273 aContext->DisplayedObjects(aListOfShapes);
1274 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1275 anIter.More(); anIter.Next())
1277 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1278 if (aShape.IsNull())
1280 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1281 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1283 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1284 aShape->Redisplay();
1289 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1291 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1292 if (aShape.IsNull())
1294 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1295 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1297 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1298 aShape->Redisplay();
1302 aContext->UpdateCurrentViewer();
1305 else if ( !strcasecmp(buf_ret, "S") ) {
1307 cout << "passage en mode 1 (shading pour les shapes)" << endl;
1309 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1310 if(Ctx->NbCurrents()==0 ||
1311 Ctx->NbSelected()==0)
1312 Ctx->SetDisplayMode(AIS_Shaded);
1314 if(Ctx->HasOpenedContext()){
1315 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1316 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1319 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1320 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1322 Ctx->UpdateCurrentViewer();
1325 else if ( !strcasecmp(buf_ret, "U") ) {
1326 // Unset display mode
1327 cout<<"passage au mode par defaut"<<endl;
1329 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1330 if(Ctx->NbCurrents()==0 ||
1331 Ctx->NbSelected()==0)
1332 Ctx->SetDisplayMode(AIS_WireFrame);
1334 if(Ctx->HasOpenedContext()){
1335 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1336 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1339 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1340 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1342 Ctx->UpdateCurrentViewer();
1346 else if ( !strcasecmp(buf_ret, "T") ) {
1348 aView->SetProj(V3d_Zpos);
1350 else if ( !strcasecmp(buf_ret, "B") ) {
1352 aView->SetProj(V3d_Zneg);
1354 else if ( !strcasecmp(buf_ret, "L") ) {
1356 aView->SetProj(V3d_Xneg);
1358 else if ( !strcasecmp(buf_ret, "R") ) {
1360 aView->SetProj(V3d_Xpos);
1363 else if ( !strcasecmp(buf_ret, "W") ) {
1365 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
1366 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1367 if(Ctx->NbCurrents()==0 ||
1368 Ctx->NbSelected()==0)
1369 Ctx->SetDisplayMode(AIS_WireFrame);
1371 if(Ctx->HasOpenedContext()){
1372 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1373 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1376 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1377 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1379 Ctx->UpdateCurrentViewer();
1382 else if ( !strcasecmp(buf_ret, "Z") ) {
1386 cout << "ZClipping OFF" << endl;
1389 aView->SetZClippingType(V3d_OFF);
1393 cout << "ZClipping ON" << endl;
1396 aView->SetZClippingType(V3d_FRONT);
1400 else if ( !strcasecmp(buf_ret, ",") ) {
1401 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1405 else if ( !strcasecmp(buf_ret, ".") ) {
1406 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1410 Standard_Integer Num = Draw::Atoi(buf_ret);
1411 if(Num>=0 && Num<=7)
1412 ViewerTest::StandardModeActivation(Num);
1416 //==============================================================================
1417 //function : VT_ProcessExpose
1418 //purpose : Redraw the View on an Expose Event
1419 //==============================================================================
1420 void VT_ProcessExpose()
1422 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1423 if (!aView3d.IsNull())
1429 //==============================================================================
1430 //function : VT_ProcessConfigure
1431 //purpose : Resize the View on an Configure Event
1432 //==============================================================================
1433 void VT_ProcessConfigure()
1435 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1436 if (aView3d.IsNull())
1441 aView3d->MustBeResized();
1446 //==============================================================================
1447 //function : VT_ProcessButton1Press
1449 //==============================================================================
1450 Standard_Boolean VT_ProcessButton1Press(
1453 Standard_Boolean pick,
1454 Standard_Boolean shift)
1456 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1458 Standard_Real X, Y, Z;
1460 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1462 Draw::Set(argv[1], X);
1463 Draw::Set(argv[2], Y);
1464 Draw::Set(argv[3], Z);}
1475 //==============================================================================
1476 //function : VT_ProcessButton1Release
1477 //purpose : End selecting
1478 //==============================================================================
1479 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1483 IsDragged = Standard_False;
1484 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1487 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1488 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1492 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1493 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1498 //==============================================================================
1499 //function : VT_ProcessButton3Press
1500 //purpose : Start Rotation
1501 //==============================================================================
1502 void VT_ProcessButton3Press()
1507 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1509 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1512 //==============================================================================
1513 //function : VT_ProcessButton3Release
1514 //purpose : End rotation
1515 //==============================================================================
1516 void VT_ProcessButton3Release()
1523 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1528 //==============================================================================
1529 //function : ProcessZClipMotion
1531 //==============================================================================
1533 void ProcessZClipMotion()
1535 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1536 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1537 static Standard_Real CurZPos = 0.;
1539 //Quantity_Length VDX, VDY;
1540 //a3DView->Size(VDX,VDY);
1541 //Standard_Real VDZ = a3DView->ZSize();
1542 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1544 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1546 // Front = Depth + width/2.
1547 Standard_Real D = 0.5;
1548 Standard_Real W = 0.1;
1554 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1556 a3DView->SetZClippingType(V3d_OFF);
1557 a3DView->SetZClippingDepth(D);
1558 a3DView->SetZClippingWidth(W);
1559 a3DView->SetZClippingType(V3d_FRONT);
1563 X_ButtonPress = X_Motion;
1564 Y_ButtonPress = Y_Motion;
1568 //==============================================================================
1569 //function : ProcessControlButton1Motion
1571 //==============================================================================
1573 static void ProcessControlButton1Motion()
1575 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1577 X_ButtonPress = X_Motion;
1578 Y_ButtonPress = Y_Motion;
1581 //==============================================================================
1582 //function : VT_ProcessControlButton2Motion
1584 //==============================================================================
1585 void VT_ProcessControlButton2Motion()
1587 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1588 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1590 dy = -dy; // Xwindow Y axis is from top to Bottom
1592 ViewerTest::CurrentView()->Panning( dx, dy );
1594 X_ButtonPress = X_Motion;
1595 Y_ButtonPress = Y_Motion;
1598 //==============================================================================
1599 //function : VT_ProcessControlButton3Motion
1600 //purpose : Rotation
1601 //==============================================================================
1602 void VT_ProcessControlButton3Motion()
1606 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1610 //==============================================================================
1611 //function : VT_ProcessMotion
1613 //==============================================================================
1614 void VT_ProcessMotion()
1616 //pre-hilights detected objects at mouse position
1618 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1619 EM->MoveTo(X_Motion, Y_Motion);
1623 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1625 Xpix = X_Motion;Ypix=Y_Motion;
1628 //==============================================================================
1629 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1630 //purpose : Switches to an axonometric, top, left and other views
1631 //==============================================================================
1633 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1635 if ( ViewerTest::CurrentView().IsNull() )
1637 di<<"Call vinit before this command, please"<<"\n";
1641 ViewerTest::CurrentView()->SetProj(ori);
1645 //==============================================================================
1647 //purpose : Switch to an Axonometric view
1648 //Draw arg : No args
1649 //==============================================================================
1651 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1653 return ViewProject(di, V3d_XposYnegZpos);
1656 //==============================================================================
1658 //purpose : Switch to a Top View
1659 //Draw arg : No args
1660 //==============================================================================
1662 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1664 return ViewProject(di, V3d_Zpos);
1667 //==============================================================================
1668 //function : VBottom
1669 //purpose : Switch to a Bottom View
1670 //Draw arg : No args
1671 //==============================================================================
1673 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1675 return ViewProject(di, V3d_Zneg);
1678 //==============================================================================
1680 //purpose : Switch to a Left View
1681 //Draw arg : No args
1682 //==============================================================================
1684 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1686 return ViewProject(di, V3d_Ypos);
1689 //==============================================================================
1691 //purpose : Switch to a Right View
1692 //Draw arg : No args
1693 //==============================================================================
1695 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1697 return ViewProject(di, V3d_Yneg);
1700 //==============================================================================
1702 //purpose : Switch to a Front View
1703 //Draw arg : No args
1704 //==============================================================================
1706 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1708 return ViewProject(di, V3d_Xpos);
1711 //==============================================================================
1713 //purpose : Switch to a Back View
1714 //Draw arg : No args
1715 //==============================================================================
1717 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1719 return ViewProject(di, V3d_Xneg);
1722 //==============================================================================
1724 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1725 //Draw arg : No args
1726 //==============================================================================
1728 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1731 di << "Q : Quit the application" << "\n";
1733 di << "========================="<<"\n";
1734 di << "F : FitAll" << "\n";
1735 di << "T : TopView" << "\n";
1736 di << "B : BottomView" << "\n";
1737 di << "R : RightView" << "\n";
1738 di << "L : LeftView" << "\n";
1739 di << "A : AxonometricView" << "\n";
1740 di << "D : ResetView" << "\n";
1742 di << "========================="<<"\n";
1743 di << "S : Shading" << "\n";
1744 di << "W : Wireframe" << "\n";
1745 di << "H : HidelLineRemoval" << "\n";
1746 di << "U : Unset display mode" << "\n";
1748 di << "========================="<<"\n";
1749 di << "Selection mode "<<"\n";
1750 di << "0 : Shape" <<"\n";
1751 di << "1 : Vertex" <<"\n";
1752 di << "2 : Edge" <<"\n";
1753 di << "3 : Wire" <<"\n";
1754 di << "4 : Face" <<"\n";
1755 di << "5 : Shell" <<"\n";
1756 di << "6 : Solid" <<"\n";
1757 di << "7 : Compound" <<"\n";
1759 di << "========================="<<"\n";
1760 di << "Z : Switch Z clipping On/Off" << "\n";
1761 di << ", : Hilight next detected" << "\n";
1762 di << ". : Hilight previous detected" << "\n";
1769 static Standard_Boolean Ppick = 0;
1770 static Standard_Integer Pargc = 0;
1771 static const char** Pargv = NULL;
1774 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1779 if (!ViewerTest_myViews.IsEmpty()) {
1781 WPARAM fwKeys = wParam;
1786 // Delete view from map of views
1787 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1792 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1793 || ViewerTest::CurrentView().IsNull())
1795 // Activate inactive window
1796 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1798 ActivateView (FindViewIdByWindowHandle(hwnd));
1803 IsDragged = Standard_False;
1806 HDC hdc = GetDC( hwnd );
1807 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1808 SetROP2( hdc, R2_NOT );
1809 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1810 ReleaseDC( hwnd, hdc );
1812 const Handle(ViewerTest_EventManager) EM =
1813 ViewerTest::CurrentEventManager();
1814 if ( fwKeys & MK_SHIFT )
1815 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1816 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1818 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1819 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1821 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1823 case WM_LBUTTONDOWN:
1824 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1826 IsDragged = Standard_True;
1827 DragFirst = Standard_True;
1828 X_ButtonPress = LOWORD(lParam);
1829 Y_ButtonPress = HIWORD(lParam);
1831 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1838 HDC hdc = GetDC( hwnd );
1840 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1841 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1842 SetROP2( hdc, R2_NOT );
1845 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1847 DragFirst = Standard_False;
1848 X_Motion = LOWORD(lParam);
1849 Y_Motion = HIWORD(lParam);
1851 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1853 SelectObject( hdc, anObj );
1855 ReleaseDC( hwnd, hdc );
1858 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1862 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1866 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1870 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1877 if ( !ViewerTest::CurrentView().IsNull() ) {
1882 BeginPaint(hwnd, &ps);
1883 EndPaint(hwnd, &ps);
1888 VT_ProcessConfigure();
1892 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1895 c[0] = (char) wParam;
1897 VT_ProcessKeyPress (c);
1905 VT_ProcessButton3Release();
1908 case WM_LBUTTONDOWN:
1909 case WM_MBUTTONDOWN:
1910 case WM_RBUTTONDOWN:
1912 WPARAM fwKeys = wParam;
1916 X_ButtonPress = LOWORD(lParam);
1917 Y_ButtonPress = HIWORD(lParam);
1919 if (Msg == WM_LBUTTONDOWN)
1921 if (fwKeys & MK_CONTROL)
1923 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1927 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1930 else if (Msg == WM_RBUTTONDOWN)
1933 VT_ProcessButton3Press();
1940 //cout << "\t WM_MOUSEMOVE" << endl;
1941 WPARAM fwKeys = wParam;
1942 X_Motion = LOWORD(lParam);
1943 Y_Motion = HIWORD(lParam);
1946 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1948 X_ButtonPress = LOWORD(lParam);
1949 Y_ButtonPress = HIWORD(lParam);
1951 if ( fwKeys & MK_RBUTTON ) {
1953 VT_ProcessButton3Press();
1957 if ( fwKeys & MK_CONTROL ) {
1958 if ( fwKeys & MK_LBUTTON ) {
1959 ProcessControlButton1Motion();
1961 else if ( fwKeys & MK_MBUTTON ||
1962 ((fwKeys&MK_LBUTTON) &&
1963 (fwKeys&MK_RBUTTON) ) ){
1964 VT_ProcessControlButton2Motion();
1966 else if ( fwKeys & MK_RBUTTON ) {
1967 VT_ProcessControlButton3Motion();
1971 else if ( fwKeys & MK_SHIFT ) {
1972 if ( fwKeys & MK_MBUTTON ||
1973 ((fwKeys&MK_LBUTTON) &&
1974 (fwKeys&MK_RBUTTON) ) ) {
1975 cout << "ProcessZClipMotion()" << endl;
1976 ProcessZClipMotion();
1981 if ((fwKeys & MK_MBUTTON
1982 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
1984 ProcessZClipMotion();
1994 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
1999 return DefWindowProc( hwnd, Msg, wParam, lParam );
2005 //==============================================================================
2006 //function : ViewerMainLoop
2007 //purpose : Get a Event on the view and dispatch it
2008 //==============================================================================
2011 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2013 Ppick = (argc > 0)? 1 : 0;
2021 cout << "Start picking" << endl;
2023 while ( Ppick == 1 ) {
2024 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2025 if (GetMessage(&msg, NULL, 0, 0) ) {
2026 TranslateMessage(&msg);
2027 DispatchMessage(&msg);
2031 cout << "Picking done" << endl;
2037 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2039 int min( int a, int b )
2047 int max( int a, int b )
2055 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2058 static XEvent aReport;
2059 Standard_Boolean pick = argc > 0;
2060 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2061 XNextEvent (aDisplay, &aReport);
2063 // Handle event for the chosen display connection
2064 switch (aReport.type) {
2067 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2070 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2076 // Activate inactive view
2077 Window aWindow = GetWindowHandle(VT_GetWindow());
2078 if(aWindow != aReport.xfocus.window)
2080 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2089 case ConfigureNotify:
2091 VT_ProcessConfigure();
2100 XComposeStatus status_in_out;
2102 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2103 (char *) buf_ret , 10 ,
2104 &ks_ret , &status_in_out ) ;
2107 buf_ret[ret_len] = '\0' ;
2111 VT_ProcessKeyPress (buf_ret);
2117 X_ButtonPress = aReport.xbutton.x;
2118 Y_ButtonPress = aReport.xbutton.y;
2120 if (aReport.xbutton.button == Button1)
2122 if (aReport.xbutton.state & ControlMask)
2124 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2128 IsDragged = Standard_True;
2129 DragFirst = Standard_True;
2132 else if (aReport.xbutton.button == Button3)
2135 VT_ProcessButton3Press();
2145 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2146 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2147 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2150 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2151 if( aContext.IsNull() )
2153 cout << "The context is null. Please use vinit before createmesh" << endl;
2157 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2158 if( aReport.xbutton.button==1 )
2162 aContext->ShiftSelect();
2171 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2172 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2173 ViewerTest::CurrentView());
2177 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2178 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2179 ViewerTest::CurrentView() );
2182 VT_ProcessButton3Release();
2184 IsDragged = Standard_False;
2187 VT_ProcessButton3Release();
2194 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2195 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2196 XSetFunction( aDisplay, gc, GXinvert );
2199 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2201 X_Motion = aReport.xmotion.x;
2202 Y_Motion = aReport.xmotion.y;
2203 DragFirst = Standard_False;
2205 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2209 X_Motion = aReport.xmotion.x;
2210 Y_Motion = aReport.xmotion.y;
2212 // remove all the ButtonMotionMaskr
2213 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2215 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2216 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2218 Quantity_Length VDX, VDY;
2220 ViewerTest::CurrentView()->Size(VDX,VDY);
2221 Standard_Real VDZ =0 ;
2222 VDZ = ViewerTest::CurrentView()->ZSize();
2224 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2226 Quantity_Length dx = 0 ;
2227 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2231 dx = dx / VDX * VDZ;
2235 ViewerTest::CurrentView()->Redraw();
2239 if ( aReport.xmotion.state & ControlMask ) {
2240 if ( aReport.xmotion.state & Button1Mask ) {
2241 ProcessControlButton1Motion();
2243 else if ( aReport.xmotion.state & Button2Mask ) {
2244 VT_ProcessControlButton2Motion();
2246 else if ( aReport.xmotion.state & Button3Mask ) {
2247 VT_ProcessControlButton3Motion();
2261 //==============================================================================
2262 //function : VProcessEvents
2263 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2264 // event in the Viewer window
2265 //==============================================================================
2267 static void VProcessEvents(ClientData,int)
2269 NCollection_Vector<int> anEventNumbers;
2270 // Get number of messages from every display
2271 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2272 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2274 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2276 // Handle events for every display
2277 int anEventIter = 0;
2278 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2279 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2281 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2282 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2284 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2285 int anEventResult = ViewerMainLoop( 0, NULL);
2286 // If window is closed or context was not found finish current event processing loop
2292 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2297 //==============================================================================
2298 //function : OSWindowSetup
2299 //purpose : Setup for the X11 window to be able to cath the event
2300 //==============================================================================
2303 static void OSWindowSetup()
2305 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2308 Window window = VT_GetWindow()->XWindow();
2309 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2310 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2311 XSynchronize(aDisplay, 1);
2313 // X11 : For keyboard on SUN
2315 wmhints.flags = InputHint;
2318 XSetWMHints( aDisplay, window, &wmhints);
2320 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2321 ButtonPressMask | ButtonReleaseMask |
2322 StructureNotifyMask |
2324 Button1MotionMask | Button2MotionMask |
2325 Button3MotionMask | FocusChangeMask
2327 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2328 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2330 XSynchronize(aDisplay, 0);
2339 //==============================================================================
2342 //purpose : Fitall, no DRAW arguments
2343 //Draw arg : No args
2344 //==============================================================================
2346 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2348 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2349 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2350 if (V.IsNull() == Standard_False) {
2352 } else if (aView.IsNull() == Standard_False) {
2358 //==============================================================================
2360 //purpose : ZFitall, no DRAW arguments
2361 //Draw arg : No args
2362 //==============================================================================
2364 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2366 Handle(V3d_View) V = ViewerTest::CurrentView();
2367 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2370 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2372 Handle(V3d_View) V = ViewerTest::CurrentView();
2373 if ( !V.IsNull() ) V->Redraw(); return 0;
2377 //==============================================================================
2379 //purpose : Remove all the object from the viewer
2380 //Draw arg : No args
2381 //==============================================================================
2383 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2385 Handle(V3d_View) V = ViewerTest::CurrentView();
2387 ViewerTest::Clear();
2391 //==============================================================================
2394 //==============================================================================
2396 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2397 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2400 di << argv[0] << "Invalid number of arguments" << "\n";
2404 while (ViewerMainLoop( argc, argv)) {
2410 //==============================================================================
2411 //function : InitViewerTest
2412 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2413 //==============================================================================
2415 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2417 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2418 ViewerTest::SetAISContext(theContext);
2419 aViewer->InitActiveViews();
2420 Handle(V3d_View) aView = aViewer->ActiveView();
2421 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2422 ViewerTest::ResetEventManager();
2423 Handle(Aspect_Window) aWindow = aView->Window();
2424 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2426 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2428 static int aFirst = 1;
2430 #if TCL_MAJOR_VERSION < 8
2431 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2432 TK_READABLE, VProcessEvents, (ClientData) 0);
2434 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2435 TK_READABLE, VProcessEvents, (ClientData) 0);
2442 //==============================================================================
2444 //purpose : Load image as background
2445 //==============================================================================
2447 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2449 if (argc < 2 || argc > 3)
2451 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2452 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2456 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2457 if(AISContext.IsNull())
2459 di << "use 'vinit' command before " << argv[0] << "\n";
2463 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2466 const char* szType = argv[2];
2467 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2468 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2469 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2470 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2473 di << "Wrong fill type : " << szType << "\n";
2474 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2479 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2480 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2485 //==============================================================================
2486 //function : VSetBgMode
2487 //purpose : Change background image fill type
2488 //==============================================================================
2490 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2494 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2495 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2499 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2500 if(AISContext.IsNull())
2502 di << "use 'vinit' command before " << argv[0] << "\n";
2506 Aspect_FillMethod aFillType;
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";
2522 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2523 V3dView->SetBgImageStyle(aFillType, Standard_True);
2528 //==============================================================================
2529 //function : VSetGradientBg
2530 //purpose : Mount gradient background
2531 //==============================================================================
2532 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2536 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2537 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2538 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2539 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2543 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2544 if(AISContext.IsNull())
2546 di << "use 'vinit' command before " << argv[0] << "\n";
2552 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2553 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2554 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2555 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2557 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2558 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2559 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2561 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2562 int aType = Draw::Atoi(argv[7]);
2563 if( aType < 0 || aType > 8 )
2565 di << "Wrong fill type " << "\n";
2566 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2567 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2571 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2573 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2574 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2580 //==============================================================================
2581 //function : VSetGradientBgMode
2582 //purpose : Change gradient background fill style
2583 //==============================================================================
2584 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2588 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2589 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2590 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2594 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2595 if(AISContext.IsNull())
2597 di << "use 'vinit' command before " << argv[0] << "\n";
2602 int aType = Draw::Atoi(argv[1]);
2603 if( aType < 0 || aType > 8 )
2605 di << "Wrong fill type " << "\n";
2606 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2607 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2611 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2613 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2614 V3dView->SetBgGradientStyle( aMethod, 1 );
2620 //==============================================================================
2621 //function : VSetColorBg
2622 //purpose : Set color background
2623 //==============================================================================
2624 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2628 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2629 di << "R,G,B = [0..255]" << "\n";
2633 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2634 if(AISContext.IsNull())
2636 di << "use 'vinit' command before " << argv[0] << "\n";
2642 Standard_Real R = Draw::Atof(argv[1])/255.;
2643 Standard_Real G = Draw::Atof(argv[2])/255.;
2644 Standard_Real B = Draw::Atof(argv[3])/255.;
2645 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2647 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2648 V3dView->SetBackgroundColor( aColor );
2655 //==============================================================================
2657 //purpose : View Scaling
2658 //==============================================================================
2660 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2662 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2663 if ( V3dView.IsNull() ) return 1;
2666 di << argv[0] << "Invalid number of arguments" << "\n";
2669 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2672 //==============================================================================
2673 //function : VTestZBuffTrihedron
2674 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2675 //==============================================================================
2677 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2679 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2680 if ( V3dView.IsNull() ) return 1;
2682 V3dView->ZBufferTriedronSetup();
2685 // Set up default trihedron parameters
2686 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2690 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2691 const char* aPosType = argv[1];
2693 if ( strcmp(aPosType, "center") == 0 )
2695 aPosition = Aspect_TOTP_CENTER;
2697 if (strcmp(aPosType, "left_lower") == 0)
2699 aPosition = Aspect_TOTP_LEFT_LOWER;
2701 if (strcmp(aPosType, "left_upper") == 0)
2703 aPosition = Aspect_TOTP_LEFT_UPPER;
2705 if (strcmp(aPosType, "right_lower") == 0)
2707 aPosition = Aspect_TOTP_RIGHT_LOWER;
2709 if (strcmp(aPosType, "right_upper") == 0)
2711 aPosition = Aspect_TOTP_RIGHT_UPPER;
2714 di << argv[1] << " Invalid type of alignment" << "\n";
2715 di << "Must be one of [ center, left_lower," << "\n";
2716 di << "left_upper, right_lower, right_upper ]" << "\n";
2720 Standard_Real R = Draw::Atof(argv[2])/255.;
2721 Standard_Real G = Draw::Atof(argv[3])/255.;
2722 Standard_Real B = Draw::Atof(argv[4])/255.;
2723 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2725 Standard_Real aScale = Draw::Atof(argv[5]);
2729 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2733 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2734 const char* aPresType = argv[6];
2736 if ( strcmp(aPresType, "wireframe") == 0 )
2738 aPresentation = V3d_WIREFRAME;
2740 if (strcmp(aPresType, "zbuffer") == 0)
2742 aPresentation = V3d_ZBUFFER;
2745 di << argv[6] << " Invalid type of visualization" << "\n";
2746 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2750 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2754 di << argv[0] << " Invalid number of arguments" << "\n";
2763 //==============================================================================
2764 //function : VRotate
2765 //purpose : Camera Rotating
2766 //==============================================================================
2768 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2769 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2770 if ( V3dView.IsNull() ) {
2775 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2777 } else if ( argc == 7 ) {
2778 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]) );
2781 di << argv[0] << " Invalid number of arguments" << "\n";
2786 //==============================================================================
2788 //purpose : View zoom in / out (relative to current zoom)
2789 //==============================================================================
2791 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2792 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2793 if ( V3dView.IsNull() ) {
2798 Standard_Real coef = Draw::Atof(argv[1]);
2799 if ( coef <= 0.0 ) {
2800 di << argv[1] << "Invalid value" << "\n";
2803 V3dView->SetZoom( Draw::Atof(argv[1]) );
2806 di << argv[0] << " Invalid number of arguments" << "\n";
2811 //==============================================================================
2813 //purpose : View panning (in pixels)
2814 //==============================================================================
2816 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2817 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2818 if ( V3dView.IsNull() ) return 1;
2821 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2824 di << argv[0] << " Invalid number of arguments" << "\n";
2830 //==============================================================================
2831 //function : VExport
2832 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2833 //==============================================================================
2835 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2837 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2838 if (V3dView.IsNull())
2843 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2847 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2848 TCollection_AsciiString aFormatStr;
2850 TCollection_AsciiString aFileName (argv[1]);
2851 Standard_Integer aLen = aFileName.Length();
2855 aFormatStr = TCollection_AsciiString (argv[2]);
2859 if (aFileName.Value (aLen - 2) == '.')
2861 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2863 else if (aFileName.Value (aLen - 3) == '.')
2865 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2869 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2875 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2879 aFormatStr.UpperCase();
2880 if (aFormatStr == "PS")
2881 anExpFormat = Graphic3d_EF_PostScript;
2882 else if (aFormatStr == "EPS")
2883 anExpFormat = Graphic3d_EF_EnhPostScript;
2884 else if (aFormatStr == "TEX")
2885 anExpFormat = Graphic3d_EF_TEX;
2886 else if (aFormatStr == "PDF")
2887 anExpFormat = Graphic3d_EF_PDF;
2888 else if (aFormatStr == "SVG")
2889 anExpFormat = Graphic3d_EF_SVG;
2890 else if (aFormatStr == "PGF")
2891 anExpFormat = Graphic3d_EF_PGF;
2892 else if (aFormatStr == "EMF")
2893 anExpFormat = Graphic3d_EF_EMF;
2896 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2901 if (!V3dView->View()->Export (argv[1], anExpFormat))
2903 di << "Error: export of image to " << aFormatStr << " failed!\n";
2906 catch (Standard_Failure)
2908 di << "Error: export of image to " << aFormatStr << " failed";
2909 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2914 //==============================================================================
2915 //function : VColorScale
2916 //purpose : representation color scale
2917 //==============================================================================
2918 #include <V3d_ColorScale.hxx>
2920 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2922 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2924 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2928 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2929 if(aContext.IsNull()) {
2930 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2934 Standard_Real minRange = 0. , maxRange = 100. ;
2936 Standard_Integer numIntervals = 10 ;
2937 Standard_Integer textHeight = 16;
2938 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2939 Standard_Real X = 0., Y = 0. ;
2945 minRange = Draw::Atof( argv[1] );
2946 maxRange = Draw::Atof( argv[2] );
2947 numIntervals = Draw::Atoi( argv[3] );
2950 textHeight = Draw::Atoi( argv[4] );
2952 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2955 X = Draw::Atof( argv[6] );
2956 Y = Draw::Atof( argv[7] );
2959 Handle(V3d_View) curView = ViewerTest::CurrentView( );
2960 if ( curView.IsNull( ) )
2962 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2963 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2964 if( ! aCS.IsNull( ) )
2966 aCS->SetPosition( X , Y );
2967 aCS->SetHeight( 0.95) ;
2968 aCS->SetTextHeight( textHeight );
2969 aCS->SetRange( minRange , maxRange );
2970 aCS->SetNumberOfIntervals( numIntervals );
2971 aCS->SetLabelPosition( position );
2972 if( !curView->ColorScaleIsDisplayed() )
2973 curView->ColorScaleDisplay( );
2978 //==============================================================================
2979 //function : VGraduatedTrihedron
2980 //purpose : Displays a graduated trihedron
2981 //==============================================================================
2983 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2985 const char *str = arg;
2988 unsigned short c1 = *str++;
2989 unsigned short c2 = *str++;
2990 if (!c1 || !c2) break;
2991 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2995 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2998 if (argc != 2 && argc < 5)
3000 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3001 di<<"Usage: type help "<<argv[0]<<"\n";
3002 return 1; //TCL_ERROR
3005 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3007 // Create 3D view if it doesn't exist
3008 if ( aV3dView.IsNull() )
3010 ViewerTest::ViewerInit();
3011 aV3dView = ViewerTest::CurrentView();
3012 if( aV3dView.IsNull() )
3014 di << "Error: Cannot create a 3D view\n";
3015 return 1; //TCL_ERROR
3019 // Erase (==0) or display (!=0)
3020 const int display = Draw::Atoi(argv[1]);
3025 TCollection_AsciiString font;
3027 font.AssignCat("Courier");
3029 font.AssignCat(argv[5]);
3031 // Text is multibyte
3032 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3035 TCollection_ExtendedString xname, yname, zname;
3040 AddMultibyteString(xname, argv[2]);
3041 AddMultibyteString(yname, argv[3]);
3042 AddMultibyteString(zname, argv[4]);
3058 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3059 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3060 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3061 Standard_True/*drawgrid*/,
3062 Standard_True/*drawaxes*/,
3063 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3064 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3065 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3066 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3067 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3068 Quantity_NOC_WHITE/*gridcolor*/,
3069 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3070 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3073 aV3dView->GraduatedTrihedronErase();
3075 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3081 //==============================================================================
3082 //function : VPrintView
3083 //purpose : Test printing algorithm, print the view to image file with given
3084 // width and height. Printing implemented only for WNT.
3085 //==============================================================================
3086 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3090 di << "Printing implemented only for wnt!\n";
3094 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3095 Handle(V3d_View) aView = NULL;
3096 aContextAIS = ViewerTest::GetAISContext();
3097 if (!aContextAIS.IsNull())
3099 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3100 Vwr->InitActiveViews();
3101 if(Vwr->MoreActiveViews())
3102 aView = Vwr->ActiveView();
3108 di << "Call vinit before!\n";
3113 di << "Use: " << argv[0];
3114 di << " width height filename [print algo=0]\n";
3115 di << "width, height of the intermediate buffer for operation\n";
3116 di << "algo : {0|1}\n";
3117 di << " 0 - stretch algorithm\n";
3118 di << " 1 - tile algorithm\n";
3119 di << "test printing algorithms into an intermediate buffer\n";
3120 di << "with saving output to an image file\n";
3124 // get the input params
3125 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3126 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3127 Standard_Integer aMode = 0;
3128 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3130 aMode = Draw::Atoi (argv[4]);
3132 // check the input parameters
3133 if (aWidth <= 0 || aHeight <= 0)
3135 di << "Width and height must be positive values!\n";
3138 if (aMode != 0 && aMode != 1)
3141 // define compatible bitmap
3142 HDC anDC = CreateCompatibleDC(0);
3143 BITMAPINFO aBitmapData;
3144 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3145 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3146 aBitmapData.bmiHeader.biWidth = aWidth ;
3147 aBitmapData.bmiHeader.biHeight = aHeight;
3148 aBitmapData.bmiHeader.biPlanes = 1;
3149 aBitmapData.bmiHeader.biBitCount = 24;
3150 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3151 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3152 aBitmapData.bmiHeader.biClrUsed = 0;
3153 aBitmapData.bmiHeader.biClrImportant = 0;
3154 aBitmapData.bmiHeader.biCompression = BI_RGB;
3155 aBitmapData.bmiHeader.biSizeImage = 0;
3157 // Create Device Independent Bitmap
3158 void* aBitsOut = NULL;
3159 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3160 &aBitsOut, NULL, 0);
3161 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3163 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3164 if (aBitsOut != NULL)
3167 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3169 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3171 // succesfully printed into an intermediate buffer
3174 Image_PixMap aWrapper;
3175 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3176 aWrapper.SetTopDown (false);
3178 Image_AlienPixMap anImageBitmap;
3179 anImageBitmap.InitCopy (aWrapper);
3180 isSaved = anImageBitmap.Save (aFileName);
3184 di << "Print operation failed due to printing errors or\n";
3185 di << "insufficient memory available\n";
3186 di << "Please, try to use smaller dimensions for this test\n";
3187 di << "command, as it allocates intermediate buffer for storing\n";
3188 di << "the result\n";
3193 di << "Can't allocate memory for intermediate buffer\n";
3194 di << "Please use smaller dimensions\n";
3199 SelectObject (anDC, anOldBitmap);
3200 DeleteObject (aMemoryBitmap);
3206 di << "Save to file operation failed. This operation may fail\n";
3207 di << "if you don't have enough available memory, then you can\n";
3208 di << "use smaller dimensions for the output file\n";
3217 //==============================================================================
3218 //function : VZLayer
3219 //purpose : Test z layer operations for v3d viewer
3220 //==============================================================================
3221 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3223 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3224 if (aContextAIS.IsNull())
3226 di << "Call vinit before!\n";
3231 di << "Use: vzlayer " << argv[0];
3232 di << " add/del/get [id]\n";
3233 di << " add - add new z layer to viewer and print its id\n";
3234 di << " del - del z layer by its id\n";
3235 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3236 di << "id - the layer identificator value defined when removing z layer\n";
3240 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3241 if (aViewer.IsNull())
3243 di << "No active viewer!\n";
3247 // perform operation
3248 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3251 Standard_Integer aNewId;
3252 if (!aViewer->AddZLayer (aNewId))
3254 di << "Impossible to add new z layer!\n";
3258 di << "New z layer added with index: " << aNewId << "\n";
3260 else if (anOp == "del")
3264 di << "Please also provide as argument id of z layer to remove\n";
3268 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3269 if (!aViewer->RemoveZLayer (aDelId))
3271 di << "Impossible to remove the z layer or invalid id!\n";
3275 di << "Z layer " << aDelId << " has been removed\n";
3277 else if (anOp == "get")
3279 TColStd_SequenceOfInteger anIds;
3280 aViewer->GetAllZLayers (anIds);
3281 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3283 di << anIds.Value (aSeqIdx) << " ";
3290 di << "Invalid operation, please use { add / del / get }\n";
3297 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3299 // this class provides a presentation of text item in v3d view under-/overlayer
3300 class V3d_TextItem : public Visual3d_LayerItem
3305 DEFINE_STANDARD_RTTI(V3d_TextItem)
3308 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3309 const Standard_Real theX1,
3310 const Standard_Real theY1,
3311 const Standard_Real theHeight,
3312 const TCollection_AsciiString& theFontName,
3313 const Quantity_Color& theColor,
3314 const Quantity_Color& theSubtitleColor,
3315 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3316 const Handle(Visual3d_Layer)& theLayer);
3319 Standard_EXPORT void RedrawLayerPrs();
3325 Standard_Real myHeight;
3326 TCollection_AsciiString myText;
3327 TCollection_AsciiString myFontName;
3328 Quantity_Color myColor;
3329 Quantity_Color mySubtitleColor;
3330 Aspect_TypeOfDisplayText myType;
3331 Handle(Visual3d_Layer) myLayer;
3335 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3336 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3338 // create and add to display the text item
3339 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3340 const Standard_Real theX1,
3341 const Standard_Real theY1,
3342 const Standard_Real theHeight,
3343 const TCollection_AsciiString& theFontName,
3344 const Quantity_Color& theColor,
3345 const Quantity_Color& theSubtitleColor,
3346 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3347 const Handle(Visual3d_Layer)& theLayer)
3348 : myX1 (theX1), myY1 (theY1),
3350 myHeight (theHeight),
3353 mySubtitleColor (theSubtitleColor),
3354 myType (theTypeOfDisplay),
3355 myFontName (theFontName)
3357 if (!myLayer.IsNull ())
3358 myLayer->AddLayerItem (this);
3362 void V3d_TextItem::RedrawLayerPrs ()
3364 if (myLayer.IsNull ())
3367 myLayer->SetColor (myColor);
3368 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3369 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3372 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3374 // The Visual3d_LayerItem line item for "vlayerline" command
3375 // it provides a presentation of line with user-defined
3376 // linewidth, linetype and transparency.
3377 class V3d_LineItem : public Visual3d_LayerItem
3381 DEFINE_STANDARD_RTTI(V3d_LineItem)
3384 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3385 Standard_Real X2, Standard_Real Y2,
3386 V3d_LayerMgrPointer theLayerMgr,
3387 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3388 Standard_Real theWidth = 0.5,
3389 Standard_Real theTransp = 1.0);
3392 Standard_EXPORT void RedrawLayerPrs();
3396 Standard_Real myX1, myY1, myX2, myY2;
3397 Standard_Real myWidth;
3398 Standard_Real myTransparency;
3399 Aspect_TypeOfLine myType;
3400 V3d_LayerMgrPointer myLayerMgr;
3403 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3404 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3406 // default constructor for line item
3407 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3408 Standard_Real X2, Standard_Real Y2,
3409 V3d_LayerMgrPointer theLayerMgr,
3410 Aspect_TypeOfLine theType,
3411 Standard_Real theWidth,
3412 Standard_Real theTransp) :
3413 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3414 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3416 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3417 myLayerMgr->Overlay()->AddLayerItem (this);
3421 void V3d_LineItem::RedrawLayerPrs ()
3423 Handle (Visual3d_Layer) aOverlay;
3426 aOverlay = myLayerMgr->Overlay();
3428 if (!aOverlay.IsNull())
3430 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3431 aOverlay->SetColor(aColor);
3432 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3433 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3434 aOverlay->BeginPolyline();
3435 aOverlay->AddVertex(myX1, myY1);
3436 aOverlay->AddVertex(myX2, myY2);
3437 aOverlay->ClosePrimitive();
3441 //=============================================================================
3442 //function : VLayerLine
3443 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3444 // : linewidth, transparency coefficient
3445 //============================================================================
3446 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3448 // get the active view
3449 Handle(V3d_View) aView = ViewerTest::CurrentView();
3452 di << "Call vinit before!\n";
3457 di << "Use: " << argv[0];
3458 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3459 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3460 di << " 0 - solid \n";
3461 di << " 1 - dashed \n";
3462 di << " 2 - dot \n";
3463 di << " 3 - dashdot\n";
3464 di << " transparency : { 0.0 - 1.0 } \n";
3465 di << " 0.0 - transparent\n";
3466 di << " 1.0 - visible \n";
3470 // get the input params
3471 Standard_Real X1 = Draw::Atof(argv[1]);
3472 Standard_Real Y1 = Draw::Atof(argv[2]);
3473 Standard_Real X2 = Draw::Atof(argv[3]);
3474 Standard_Real Y2 = Draw::Atof(argv[4]);
3476 Standard_Real aWidth = 0.5;
3477 Standard_Integer aType = 0;
3478 Standard_Real aTransparency = 1.0;
3482 aWidth = Draw::Atof(argv[5]);
3486 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3491 aTransparency = Draw::Atof(argv[7]);
3492 if (aTransparency < 0 || aTransparency > 1.0)
3493 aTransparency = 1.0;
3496 // select appropriate line type
3497 Aspect_TypeOfLine aLineType;
3501 aLineType = Aspect_TOL_DASH;
3505 aLineType = Aspect_TOL_DOT;
3509 aLineType = Aspect_TOL_DOTDASH;
3513 aLineType = Aspect_TOL_SOLID;
3516 // replace layer manager
3517 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3518 aView->SetLayerMgr(aMgr);
3521 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3527 aView->MustBeResized();
3533 //=======================================================================
3534 //function : VOverlayText
3535 //purpose : Test text displaying in view overlay
3536 //=======================================================================
3537 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3539 // get the active view
3540 Handle(V3d_View) aView = ViewerTest::CurrentView();
3543 di << "No active view. Please call vinit.\n";
3546 else if (argc < 4 || argc > 13)
3548 di << "Use: " << argv[0];
3549 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3550 di << "[background_color: R G B]\n";
3551 di << " height - pixel height of the text (default=10.0)\n";
3552 di << " font_name - name of font (default=courier)\n";
3553 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3554 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
3555 di << " background_color- R G B values used for subtitle and decal text\n";
3556 di << "(default=255.0 255.0 255.0)\n";
3560 TCollection_AsciiString aText (argv[1]);
3561 Standard_Real aPosX = Draw::Atof(argv[2]);
3562 Standard_Real aPosY = Draw::Atof(argv[3]);
3563 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3566 TCollection_AsciiString aFontName = "Courier";
3568 aFontName = TCollection_AsciiString (argv[5]);
3571 Quantity_Parameter aColorRed = 1.0;
3572 Quantity_Parameter aColorGreen = 1.0;
3573 Quantity_Parameter aColorBlue = 1.0;
3576 aColorRed = Draw::Atof (argv[6])/255.;
3577 aColorGreen = Draw::Atof (argv[7])/255.;
3578 aColorBlue = Draw::Atof (argv[8])/255.;
3582 TCollection_AsciiString aDispStr;
3584 aDispStr = TCollection_AsciiString (argv[9]);
3586 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3587 if (aDispStr.IsEqual ("subtitle"))
3588 aTextType = Aspect_TODT_SUBTITLE;
3589 else if (aDispStr.IsEqual ("decal"))
3590 aTextType = Aspect_TODT_DEKALE;
3591 else if (aDispStr.IsEqual ("blend"))
3592 aTextType = Aspect_TODT_BLEND;
3595 Quantity_Parameter aSubRed = 1.0;
3596 Quantity_Parameter aSubGreen = 1.0;
3597 Quantity_Parameter aSubBlue = 1.0;
3600 aSubRed = Draw::Atof (argv[10])/255.;
3601 aSubGreen = Draw::Atof (argv[11])/255.;
3602 aSubBlue = Draw::Atof (argv[12])/255.;
3605 // check fo current overlay
3606 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3607 if (anOverlay.IsNull ())
3609 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3610 anOverlay = aMgr->Overlay ();
3611 aView->SetLayerMgr (aMgr);
3614 Quantity_Color aTextColor (aColorRed, aColorGreen,
3615 aColorBlue, Quantity_TOC_RGB);
3616 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3617 aSubBlue, Quantity_TOC_RGB);
3620 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3621 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3624 aView->MustBeResized();
3630 //==============================================================================
3633 //==============================================================================
3635 static int VGrid (Draw_Interpretor& /*theDI*/,
3636 Standard_Integer theArgNb,
3637 const char** theArgVec)
3639 // get the active view
3640 Handle(V3d_View) aView = ViewerTest::CurrentView();
3641 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3642 if (aView.IsNull() || aViewer.IsNull())
3644 std::cerr << "No active view. Please call vinit.\n";
3648 Aspect_GridType aType = aViewer->GridType();
3649 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3651 Standard_Integer anIter = 1;
3652 for (; anIter < theArgNb; ++anIter)
3654 const char* aValue = theArgVec[anIter];
3657 aType = Aspect_GT_Rectangular;
3659 else if (*aValue == 'c')
3661 aType = Aspect_GT_Circular;
3663 else if (*aValue == 'l')
3665 aMode = Aspect_GDM_Lines;
3667 else if (*aValue == 'p')
3669 aMode = Aspect_GDM_Points;
3671 else if (strcmp (aValue, "off" ) == 0)
3673 aViewer->DeactivateGrid();
3682 Standard_Integer aTail = (theArgNb - anIter);
3685 aViewer->ActivateGrid (aType, aMode);
3688 else if (aTail != 2 && aTail != 5)
3690 std::cerr << "Incorrect arguments number! Usage:\n"
3691 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3695 Quantity_Length anOriginX, anOriginY;
3696 Quantity_PlaneAngle aRotAngle;
3697 if (aType == Aspect_GT_Rectangular)
3699 Quantity_Length aRStepX, aRStepY;
3700 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3702 anOriginX = Draw::Atof (theArgVec[anIter++]);
3703 anOriginY = Draw::Atof (theArgVec[anIter++]);
3706 aRStepX = Draw::Atof (theArgVec[anIter++]);
3707 aRStepY = Draw::Atof (theArgVec[anIter++]);
3708 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3710 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3711 aViewer->ActivateGrid (aType, aMode);
3713 else if (aType == Aspect_GT_Circular)
3715 Quantity_Length aRadiusStep;
3716 Standard_Integer aDivisionNumber;
3717 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3719 anOriginX = Draw::Atof (theArgVec[anIter++]);
3720 anOriginY = Draw::Atof (theArgVec[anIter++]);
3723 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3724 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3725 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3728 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3729 aViewer->ActivateGrid (aType, aMode);
3735 //==============================================================================
3738 //==============================================================================
3740 static int VFps (Draw_Interpretor& theDI,
3741 Standard_Integer theArgNb,
3742 const char** theArgVec)
3744 // get the active view
3745 Handle(V3d_View) aView = ViewerTest::CurrentView();
3748 std::cerr << "No active view. Please call vinit.\n";
3752 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3755 std::cerr << "Incorrect arguments!\n";
3759 // the time is meaningless for first call
3760 // due to async OpenGl rendering
3763 // redraw view in loop to estimate average values
3766 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3772 const Standard_Real aTime = aTimer.ElapsedTime();
3773 aTimer.OSD_Chronometer::Show (aCpu);
3775 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3776 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3778 // return statistics
3779 theDI << "FPS: " << aFpsAver << "\n"
3780 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3786 //==============================================================================
3789 //==============================================================================
3791 static int VVbo (Draw_Interpretor& /*theDI*/,
3792 Standard_Integer theArgNb,
3793 const char** theArgVec)
3796 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3797 if (aContextAIS.IsNull())
3799 std::cerr << "No active view. Please call vinit.\n";
3803 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3805 if (aDriver.IsNull())
3807 std::cerr << "Graphic driver not available.\n";
3813 //theDI << "VBO: " << aDriver->ToUseVBO() << "\n";
3815 std::cerr << "Wrong number of arguments.\n";
3819 aDriver->EnableVBO (Draw::Atoi(theArgVec[1]) != 0);
3823 //==============================================================================
3824 //function : VMemGpu
3826 //==============================================================================
3828 static int VMemGpu (Draw_Interpretor& theDI,
3829 Standard_Integer theArgNb,
3830 const char** theArgVec)
3833 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3834 if (aContextAIS.IsNull())
3836 std::cerr << "No active view. Please call vinit.\n";
3840 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3842 if (aDriver.IsNull())
3844 std::cerr << "Graphic driver not available.\n";
3848 Standard_Size aFreeBytes = 0;
3849 TCollection_AsciiString anInfo;
3850 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3852 std::cerr << "Information not available.\n";
3856 if (theArgNb > 1 && *theArgVec[1] == 'f')
3858 theDI << Standard_Real (aFreeBytes);
3868 // ==============================================================================
3869 // function : VReadPixel
3871 // ==============================================================================
3872 static int VReadPixel (Draw_Interpretor& theDI,
3873 Standard_Integer theArgNb,
3874 const char** theArgVec)
3876 // get the active view
3877 Handle(V3d_View) aView = ViewerTest::CurrentView();
3880 std::cerr << "No active view. Please call vinit.\n";
3883 else if (theArgNb < 3)
3885 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
3889 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3890 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
3892 Standard_Integer aWidth, aHeight;
3893 aView->Window()->Size (aWidth, aHeight);
3894 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
3895 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
3896 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
3898 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
3902 Standard_Boolean toShowName = Standard_False;
3903 Standard_Boolean toShowHls = Standard_False;
3904 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
3906 const char* aParam = theArgVec[anIter];
3907 if ( strcasecmp( aParam, "rgb" ) == 0 )
3909 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
3910 aBufferType = Graphic3d_BT_RGB;
3912 else if ( strcasecmp( aParam, "hls" ) == 0 )
3914 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
3915 aBufferType = Graphic3d_BT_RGB;
3916 toShowHls = Standard_True;
3918 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
3920 aFormat = Image_PixMap::ImgRGBF;
3921 aBufferType = Graphic3d_BT_RGB;
3923 else if ( strcasecmp( aParam, "rgba" ) == 0 )
3925 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3926 aBufferType = Graphic3d_BT_RGBA;
3928 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
3930 aFormat = Image_PixMap::ImgRGBAF;
3931 aBufferType = Graphic3d_BT_RGBA;
3933 else if ( strcasecmp( aParam, "depth" ) == 0 )
3935 aFormat = Image_PixMap::ImgGrayF;
3936 aBufferType = Graphic3d_BT_Depth;
3938 else if ( strcasecmp( aParam, "name" ) == 0 )
3940 toShowName = Standard_True;
3944 Image_PixMap anImage;
3945 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
3947 std::cerr << "Image allocation failed\n";
3950 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
3952 std::cerr << "Image dump failed\n";
3956 Quantity_Parameter anAlpha;
3957 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
3960 if (aBufferType == Graphic3d_BT_RGBA)
3962 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
3966 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
3971 switch (aBufferType)
3974 case Graphic3d_BT_RGB:
3978 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
3982 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
3986 case Graphic3d_BT_RGBA:
3988 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
3991 case Graphic3d_BT_Depth:
3993 theDI << aColor.Red() << "\n";
4002 //==============================================================================
4003 //function : VDiffImage
4004 //purpose : The draw-command compares two images.
4005 //==============================================================================
4007 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4011 theDI << "Not enough arguments.\n";
4016 const char* anImgPathRef = theArgVec[1];
4017 const char* anImgPathNew = theArgVec[2];
4019 // get string tolerance and check its validity
4020 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4021 if (aTolColor < 0.0)
4023 if (aTolColor > 1.0)
4026 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4027 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4029 // image file of difference
4030 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4032 // compare the images
4033 Image_Diff aComparer;
4034 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4039 aComparer.SetColorTolerance (aTolColor);
4040 aComparer.SetBorderFilterOn (isBorderFilterOn);
4041 Standard_Integer aDiffColorsNb = aComparer.Compare();
4042 theDI << aDiffColorsNb << "\n";
4044 // save image of difference
4045 if (aDiffImagePath != NULL)
4047 aComparer.SaveDiffImage (aDiffImagePath);
4053 //=======================================================================
4054 //function : VSelect
4055 //purpose : Emulates different types of selection by mouse:
4056 // 1) single click selection
4057 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4058 // 3) selection with polygon having corners at
4059 // pixel positions (x1,y1),...,(xn,yn)
4060 // 4) any of these selections with shift button pressed
4061 //=======================================================================
4062 static Standard_Integer VSelect (Draw_Interpretor& di,
4063 Standard_Integer argc,
4068 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4072 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4073 if(myAIScontext.IsNull())
4075 di << "use 'vinit' command before " << argv[0] << "\n";
4078 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4079 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4080 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4083 if(isShiftSelection)
4084 aCurrentEventManager->ShiftSelect();
4086 aCurrentEventManager->Select();
4090 if(isShiftSelection)
4091 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4093 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4097 Standard_Integer anUpper = 0;
4099 if(isShiftSelection)
4100 anUpper = (argc-1)/2;
4103 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4105 for(Standard_Integer i=1;i<=anUpper;++i)
4106 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4108 if(isShiftSelection)
4109 aCurrentEventManager->ShiftSelect(aPolyline);
4111 aCurrentEventManager->Select(aPolyline);
4116 //=======================================================================
4117 //function : VMoveTo
4118 //purpose : Emulates cursor movement to defined pixel position
4119 //=======================================================================
4120 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4121 Standard_Integer argc,
4126 di << "Usage : " << argv[0] << " x y" << "\n";
4130 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4131 if(aContext.IsNull())
4133 di << "use 'vinit' command before " << argv[0] << "\n";
4136 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4140 //=======================================================================
4141 //function : VViewParams
4142 //purpose : Gets or sets AIS View characteristics
4143 //=======================================================================
4144 static Standard_Integer VViewParams (Draw_Interpretor& di,
4145 Standard_Integer argc,
4148 if ( argc != 1 && argc != 13)
4150 di << "Usage : " << argv[0] << "\n";
4153 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
4154 if ( anAISView.IsNull () )
4156 di << "use 'vinit' command before " << argv[0] << "\n";
4160 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
4161 Standard_Real anAISViewCenterCoordinateX = 0.0;
4162 Standard_Real anAISViewCenterCoordinateY = 0.0;
4163 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4164 Standard_Real anAISViewProjX = 0.0;
4165 Standard_Real anAISViewProjY = 0.0;
4166 Standard_Real anAISViewProjZ = 0.0;
4167 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4168 Standard_Real anAISViewUpX = 0.0;
4169 Standard_Real anAISViewUpY = 0.0;
4170 Standard_Real anAISViewUpZ = 0.0;
4171 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4172 Standard_Real anAISViewAtX = 0.0;
4173 Standard_Real anAISViewAtY = 0.0;
4174 Standard_Real anAISViewAtZ = 0.0;
4175 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4176 di << "Scale of current view: " << anAISViewScale << "\n";
4177 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
4178 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4179 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4180 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4184 Quantity_Factor anAISViewScale = atof (argv [1]);
4185 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
4186 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
4187 Standard_Real anAISViewProjX = atof (argv [4]);
4188 Standard_Real anAISViewProjY = atof (argv [5]);
4189 Standard_Real anAISViewProjZ = atof (argv [6]);
4190 Standard_Real anAISViewUpX = atof (argv [7]);
4191 Standard_Real anAISViewUpY = atof (argv [8]);
4192 Standard_Real anAISViewUpZ = atof (argv [9]);
4193 Standard_Real anAISViewAtX = atof (argv [10]);
4194 Standard_Real anAISViewAtY = atof (argv [11]);
4195 Standard_Real anAISViewAtZ = atof (argv [12]);
4196 anAISView -> V3d_View::SetScale (anAISViewScale);
4197 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4198 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4199 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4200 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4205 //=======================================================================
4206 //function : VChangeSelected
4207 //purpose : Adds the shape to selection or remove one from it
4208 //=======================================================================
4209 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4210 Standard_Integer argc,
4215 di<<"Usage : " << argv[0] << " shape \n";
4219 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4220 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4221 TCollection_AsciiString aName(argv[1]);
4222 Handle(AIS_InteractiveObject) anAISObject;
4224 if(!aMap.IsBound2(aName))
4226 di<<"Use 'vdisplay' before";
4231 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4232 if(anAISObject.IsNull()){
4233 di<<"No interactive object \n";
4237 if(aContext->HasOpenedContext())
4239 aContext->AddOrRemoveSelected(anAISObject);
4243 aContext->AddOrRemoveCurrentObject(anAISObject);
4249 //=======================================================================
4250 //function : VZClipping
4251 //purpose : Gets or sets ZClipping mode, width and depth
4252 //=======================================================================
4253 static Standard_Integer VZClipping (Draw_Interpretor& di,
4254 Standard_Integer argc,
4259 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4260 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4263 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4264 if(aContext.IsNull())
4266 di << "use 'vinit' command before " << argv[0] << "\n";
4269 Handle(V3d_View) aView = ViewerTest::CurrentView();
4270 V3d_TypeOfZclipping aZClippingMode;
4273 TCollection_AsciiString aZClippingModeString;
4274 Quantity_Length aDepth, aWidth;
4275 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4276 switch (aZClippingMode)
4279 aZClippingModeString.Copy("OFF");
4282 aZClippingModeString.Copy("BACK");
4285 aZClippingModeString.Copy("FRONT");
4288 aZClippingModeString.Copy("SLICE");
4291 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4294 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4295 << "ZClipping depth = " << aDepth << "\n"
4296 << "ZClipping width = " << aWidth << "\n";
4302 Standard_Integer aStatus = 0;
4303 if ( strcmp (argv [1], "OFF") == 0 ) {
4305 aZClippingMode = V3d_OFF;
4307 if ( strcmp (argv [1], "BACK") == 0 ) {
4309 aZClippingMode = V3d_BACK;
4311 if ( strcmp (argv [1], "FRONT") == 0 ) {
4313 aZClippingMode = V3d_FRONT;
4315 if ( strcmp (argv [1], "SLICE") == 0 ) {
4317 aZClippingMode = V3d_SLICE;
4321 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4322 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4325 aView->SetZClippingType(aZClippingMode);
4329 Quantity_Length aDepth = 0., aWidth = 1.;
4332 aDepth = atof(argv[1]);
4333 aWidth = atof(argv[2]);
4337 aDepth = atof(argv[2]);
4338 aWidth = atof(argv[3]);
4341 if(aDepth<0. || aDepth>1.)
4343 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4344 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4347 if(aWidth<0. || aWidth>1.)
4349 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4350 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4354 aView->SetZClippingDepth(aDepth);
4355 aView->SetZClippingWidth(aWidth);
4362 //=======================================================================
4363 //function : VNbSelected
4364 //purpose : Returns number of selected objects
4365 //=======================================================================
4366 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4367 Standard_Integer argc,
4372 di << "Usage : " << argv[0] << "\n";
4375 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4376 if(aContext.IsNull())
4378 di << "use 'vinit' command before " << argv[0] << "\n";
4381 di << aContext->NbSelected() << "\n";
4385 //=======================================================================
4386 //function : VAntialiasing
4387 //purpose : Switches altialiasing on or off
4388 //=======================================================================
4389 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4390 Standard_Integer argc,
4395 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4399 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4400 if(aContext.IsNull())
4402 di << "use 'vinit' command before " << argv[0] << "\n";
4406 Handle(V3d_View) aView = ViewerTest::CurrentView();
4408 if((argc == 2) && (atof(argv[1]) == 0))
4409 aView->SetAntialiasingOff();
4411 aView->SetAntialiasingOn();
4416 //=======================================================================
4417 //function : VPurgeDisplay
4418 //purpose : Switches altialiasing on or off
4419 //=======================================================================
4420 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4421 Standard_Integer argc,
4426 di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
4429 Standard_Boolean isCollectorToo = Standard_False;
4432 isCollectorToo = (atoi(argv [1]) != 0);
4434 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4435 if (aContext.IsNull())
4437 di << "use 'vinit' command before " << argv[0] << "\n";
4440 aContext->CloseAllContexts(Standard_False);
4441 di << aContext->PurgeDisplay(isCollectorToo) << "\n";
4445 //=======================================================================
4446 //function : VSetViewSize
4448 //=======================================================================
4449 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4450 Standard_Integer argc,
4453 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4454 if(aContext.IsNull())
4456 di << "use 'vinit' command before " << argv[0] << "\n";
4461 di<<"Usage : " << argv[0] << " Size\n";
4464 Standard_Real aSize = atof(argv[1]);
4467 di<<"Bad Size value : " << aSize << "\n";
4471 Handle(V3d_View) aView = ViewerTest::CurrentView();
4472 aView->SetSize(aSize);
4476 //=======================================================================
4477 //function : VMoveView
4479 //=======================================================================
4480 static Standard_Integer VMoveView (Draw_Interpretor& di,
4481 Standard_Integer argc,
4484 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4485 if(aContext.IsNull())
4487 di << "use 'vinit' command before " << argv[0] << "\n";
4490 if(argc < 4 || argc > 5)
4492 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4495 Standard_Real Dx = atof(argv[1]);
4496 Standard_Real Dy = atof(argv[2]);
4497 Standard_Real Dz = atof(argv[3]);
4498 Standard_Boolean aStart = Standard_True;
4501 aStart = (atoi(argv[4]) > 0);
4504 Handle(V3d_View) aView = ViewerTest::CurrentView();
4505 aView->Move(Dx,Dy,Dz,aStart);
4509 //=======================================================================
4510 //function : VTranslateView
4512 //=======================================================================
4513 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4514 Standard_Integer argc,
4517 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4518 if(aContext.IsNull())
4520 di << "use 'vinit' command before " << argv[0] << "\n";
4523 if(argc < 4 || argc > 5)
4525 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4528 Standard_Real Dx = atof(argv[1]);
4529 Standard_Real Dy = atof(argv[2]);
4530 Standard_Real Dz = atof(argv[3]);
4531 Standard_Boolean aStart = Standard_True;
4534 aStart = (atoi(argv[4]) > 0);
4537 Handle(V3d_View) aView = ViewerTest::CurrentView();
4538 aView->Translate(Dx,Dy,Dz,aStart);
4542 //=======================================================================
4543 //function : VTurnView
4545 //=======================================================================
4546 static Standard_Integer VTurnView (Draw_Interpretor& di,
4547 Standard_Integer argc,
4550 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4551 if(aContext.IsNull()) {
4552 di << "use 'vinit' command before " << argv[0] << "\n";
4555 if(argc < 4 || argc > 5){
4556 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4559 Standard_Real Ax = atof(argv[1]);
4560 Standard_Real Ay = atof(argv[2]);
4561 Standard_Real Az = atof(argv[3]);
4562 Standard_Boolean aStart = Standard_True;
4565 aStart = (atoi(argv[4]) > 0);
4568 Handle(V3d_View) aView = ViewerTest::CurrentView();
4569 aView->Turn(Ax,Ay,Az,aStart);
4573 //==============================================================================
4574 //function : VTextureEnv
4575 //purpose : ENables or disables environment mapping
4576 //==============================================================================
4577 class OCC_TextureEnv : public Graphic3d_TextureEnv
4580 OCC_TextureEnv(const Standard_CString FileName);
4581 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4582 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4583 const Standard_Boolean theModulateFlag,
4584 const Graphic3d_TypeOfTextureFilter theFilter,
4585 const Standard_ShortReal theXScale,
4586 const Standard_ShortReal theYScale,
4587 const Standard_ShortReal theXShift,
4588 const Standard_ShortReal theYShift,
4589 const Standard_ShortReal theAngle);
4590 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4592 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4593 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4594 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4596 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4597 : Graphic3d_TextureEnv(theFileName)
4601 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4602 : Graphic3d_TextureEnv(theTexId)
4606 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4607 const Standard_Boolean theModulateFlag,
4608 const Graphic3d_TypeOfTextureFilter theFilter,
4609 const Standard_ShortReal theXScale,
4610 const Standard_ShortReal theYScale,
4611 const Standard_ShortReal theXShift,
4612 const Standard_ShortReal theYShift,
4613 const Standard_ShortReal theAngle)
4615 myParams->SetRepeat (theRepeatFlag);
4616 myParams->SetModulate (theModulateFlag);
4617 myParams->SetFilter (theFilter);
4618 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
4619 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4620 myParams->SetRotation (theAngle);
4623 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4625 // get the active view
4626 Handle(V3d_View) aView = ViewerTest::CurrentView();
4629 std::cerr << "No active view. Please call vinit.\n";
4633 // Checking the input arguments
4634 Standard_Boolean anEnableFlag = Standard_False;
4635 Standard_Boolean isOk = theArgNb >= 2;
4638 TCollection_AsciiString anEnableOpt(theArgVec[1]);
4639 anEnableFlag = anEnableOpt.IsEqual("on");
4640 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
4644 isOk = (theArgNb == 3 || theArgNb == 11);
4647 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4648 isOk = (!aTextureOpt.IsIntegerValue() ||
4649 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
4651 if (isOk && theArgNb == 11)
4653 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
4654 aModulateOpt(theArgVec[4]),
4655 aFilterOpt (theArgVec[5]),
4656 aSScaleOpt (theArgVec[6]),
4657 aTScaleOpt (theArgVec[7]),
4658 aSTransOpt (theArgVec[8]),
4659 aTTransOpt (theArgVec[9]),
4660 anAngleOpt (theArgVec[10]);
4661 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
4662 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
4663 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
4664 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
4665 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
4666 anAngleOpt.IsRealValue());
4673 std::cerr << "Usage :" << std::endl;
4674 std::cerr << theArgVec[0] << " off" << std::endl;
4675 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;
4681 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4682 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
4683 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
4684 new OCC_TextureEnv(theArgVec[2]);
4688 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
4689 aTexEnv->SetTextureParameters(
4690 aRepeatOpt. IsEqual("repeat"),
4691 aModulateOpt.IsEqual("modulate"),
4692 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
4693 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
4694 Graphic3d_TOTF_TRILINEAR,
4695 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
4696 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
4697 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
4698 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
4699 (Standard_ShortReal)Draw::Atof(theArgVec[10])
4702 aView->SetTextureEnv(aTexEnv);
4703 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
4705 else // Disabling environment mapping
4707 aView->SetSurfaceDetail(V3d_TEX_NONE);
4708 Handle(Graphic3d_TextureEnv) aTexture;
4709 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
4716 //=======================================================================
4717 //function : ViewerCommands
4719 //=======================================================================
4721 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
4724 const char *group = "ZeViewer";
4725 theCommands.Add("vinit",
4726 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4727 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
4729 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
4731 " - Creates new View window with specified name view_name.\n"
4732 "By default the new view is created in the viewer and in"
4733 " graphic driver shared with active view.\n"
4734 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
4735 "If driverName isn't specified the driver will be shared with active view.\n"
4736 "If viewerName isn't specified the viewer will be shared with active view.\n"
4737 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4738 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
4739 "is used in creation of graphic driver\n"
4741 " - l, t: pixel position of left top corner of the window\n"
4742 " - w,h: width and heigth of window respectively.\n"
4743 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
4744 __FILE__,VInit,group);
4745 theCommands.Add("vclose" ,
4746 "view_id [keep_context=0|1]\n"
4747 "or vclose ALL - to remove all created views\n"
4748 " - removes view(viewer window) defined by its view_id.\n"
4749 " - keep_context: by default 0; if 1 and the last view is deleted"
4750 " the current context is not removed.",
4751 __FILE__,VClose,group);
4752 theCommands.Add("vactivate" ,
4754 " - activates view(viewer window) defined by its view_id",
4755 __FILE__,VActivate,group);
4756 theCommands.Add("vviewlist",
4757 "vviewlist [format={tree, long}]"
4758 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
4759 " - format: format of result output, if tree the output is a tree view;"
4760 "otherwise it's a list of full view names. By default format = tree",
4761 __FILE__,VViewList,group);
4762 theCommands.Add("vhelp" ,
4763 "vhelp : display help on the viewer commands",
4764 __FILE__,VHelp,group);
4765 theCommands.Add("vtop" ,
4766 "vtop or <T> : Top view" ,
4767 __FILE__,VTop,group);
4768 theCommands.Add("vbottom" ,
4769 "vbottom : Bottom view" ,
4770 __FILE__,VBottom,group);
4771 theCommands.Add("vleft" ,
4772 "vleft : Left view" ,
4773 __FILE__,VLeft,group);
4774 theCommands.Add("vright" ,
4775 "vright : Right view" ,
4776 __FILE__,VRight,group);
4777 theCommands.Add("vaxo" ,
4778 " vaxo or <A> : Axonometric view ",
4779 __FILE__,VAxo,group);
4780 theCommands.Add("vfront" ,
4781 "vfront : Front view" ,
4782 __FILE__,VFront,group);
4783 theCommands.Add("vback" ,
4784 "vback : Back view" ,
4785 __FILE__,VBack,group);
4786 theCommands.Add("vpick" ,
4787 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
4789 theCommands.Add("vfit" ,
4790 "vfit or <F> : vfit",
4791 __FILE__,VFit,group);
4792 theCommands.Add("vzfit" ,
4794 __FILE__,VZFit,group);
4795 theCommands.Add("vrepaint",
4796 "vrepaint : vrepaint, force redraw",
4797 __FILE__,VRepaint,group);
4798 theCommands.Add("vclear",
4800 __FILE__,VClear,group);
4801 theCommands.Add("vsetbg",
4802 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
4803 __FILE__,VSetBg,group);
4804 theCommands.Add("vsetbgmode",
4805 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
4806 __FILE__,VSetBgMode,group);
4807 theCommands.Add("vsetgradientbg",
4808 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
4809 __FILE__,VSetGradientBg,group);
4810 theCommands.Add("vsetgrbgmode",
4811 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
4812 __FILE__,VSetGradientBgMode,group);
4813 theCommands.Add("vsetcolorbg",
4814 "vsetcolorbg : vsetcolorbg r g b : Set background color",
4815 __FILE__,VSetColorBg,group);
4816 theCommands.Add("vscale",
4817 "vscale : vscale X Y Z",
4818 __FILE__,VScale,group);
4819 theCommands.Add("vzbufftrihedron",
4820 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
4821 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
4822 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
4823 __FILE__,VTestZBuffTrihedron,group);
4824 theCommands.Add("vrotate",
4825 "vrotate : vrotate AX AY AZ [X Y Z]",
4826 __FILE__,VRotate,group);
4827 theCommands.Add("vzoom",
4828 "vzoom : vzoom coef",
4829 __FILE__,VZoom,group);
4830 theCommands.Add("vpan",
4831 "vpan : vpan dx dy",
4832 __FILE__,VPan,group);
4833 theCommands.Add("vexport",
4834 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
4835 " : exports the view to a vector file of a given format"
4836 " : notice that EMF format requires patched gl2ps",
4837 __FILE__,VExport,group);
4838 theCommands.Add("vcolorscale",
4839 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
4840 __FILE__,VColorScale,group);
4841 theCommands.Add("vgraduatedtrihedron",
4842 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
4843 __FILE__,VGraduatedTrihedron,group);
4844 theCommands.Add("vprintview" ,
4845 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
4846 __FILE__,VPrintView,group);
4847 theCommands.Add("vzlayer",
4848 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
4849 __FILE__,VZLayer,group);
4850 theCommands.Add("voverlaytext",
4851 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
4852 " : height - pixel height of the text (default=10.0)"
4853 " : font_name - name of font (default=courier)"
4854 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
4855 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
4856 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
4857 __FILE__,VOverlayText,group);
4858 theCommands.Add("vlayerline",
4859 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
4860 __FILE__,VLayerLine,group);
4861 theCommands.Add ("vgrid",
4862 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
4863 " : Mode - rectangular or circular"
4864 " : Type - lines or points",
4865 __FILE__, VGrid, group);
4866 theCommands.Add ("vfps",
4867 "vfps [framesNb=100] : estimate average frame rate for active view",
4868 __FILE__, VFps, group);
4869 theCommands.Add ("vvbo",
4870 "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects",
4871 __FILE__, VVbo, group);
4872 theCommands.Add ("vmemgpu",
4873 "vmemgpu [f]: print system-dependent GPU memory information if available;"
4874 " with f option returns free memory in bytes",
4875 __FILE__, VMemGpu, group);
4876 theCommands.Add ("vreadpixel",
4877 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
4878 " : Read pixel value for active view",
4879 __FILE__, VReadPixel, group);
4880 theCommands.Add("diffimage",
4881 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
4882 __FILE__, VDiffImage, group);
4883 theCommands.Add ("vselect",
4884 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
4885 "- emulates different types of selection:\n"
4886 "- 1) single click selection\n"
4887 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
4888 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
4889 "- 4) any of these selections with shift button pressed",
4890 __FILE__, VSelect, group);
4891 theCommands.Add ("vmoveto",
4893 "- emulates cursor movement to pixel postion (x,y)",
4894 __FILE__, VMoveTo, group);
4895 theCommands.Add("vviewparams",
4896 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
4897 "- gets or sets current view characteristics",
4898 __FILE__,VViewParams, group);
4899 theCommands.Add("vchangeselected",
4900 "vchangeselected shape"
4901 "- adds to shape to selection or remove one from it",
4902 __FILE__, VChangeSelected, group);
4903 theCommands.Add("vzclipping",
4904 "vzclipping [mode] [depth width]\n"
4905 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
4906 "- gets or sets ZClipping mode, width and depth",
4907 __FILE__,VZClipping,group);
4908 theCommands.Add ("vnbselected",
4909 "vnbselected", __FILE__, VNbSelected, group);
4910 theCommands.Add("vantialiasing",
4911 "vantialiasing 1|0",
4912 __FILE__,VAntialiasing,group);
4913 theCommands.Add ("vpurgedisplay",
4914 "vpurgedisplay [CollectorToo = 0|1]"
4915 "- removes structures which don't belong to objects displayed in neutral point",
4916 __FILE__, VPurgeDisplay, group);
4917 theCommands.Add("vsetviewsize",
4918 "vsetviewsize size",
4919 __FILE__,VSetViewSize,group);
4920 theCommands.Add("vmoveview",
4921 "vmoveview Dx Dy Dz [Start = 1|0]",
4922 __FILE__,VMoveView,group);
4923 theCommands.Add("vtranslateview",
4924 "vtranslateview Dx Dy Dz [Start = 1|0)]",
4925 __FILE__,VTranslateView,group);
4926 theCommands.Add("vturnview",
4927 "vturnview Ax Ay Az [Start = 1|0]",
4928 __FILE__,VTurnView,group);
4929 theCommands.Add("vtextureenv",
4930 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
4931 "or user-defined file and optionally applying texture mapping parameters\n"
4933 " vtextureenv off - disables environment mapping\n"
4934 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
4935 " std_texture = (0..7)\n"
4936 " rep = {clamp|repeat}\n"
4937 " mod = {decal|modulate}\n"
4938 " flt = {nearest|bilinear|trilinear}\n"
4939 " ss, st - scale factors for s and t texture coordinates\n"
4940 " ts, tt - translation for s and t texture coordinates\n"
4941 " rot - texture rotation angle in degrees",
4942 __FILE__, VTextureEnv, group);
4943 theCommands.Add("vhlr" ,
4944 "is_enabled={on|off}"
4945 " - Hidden line removal algorithm:"
4946 " - is_enabled: if is on HLR algorithm is applied\n",
4947 __FILE__,VHLR,group);
4948 theCommands.Add("vhlrtype" ,
4949 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
4950 " - Changes the type of HLR algorithm using for shapes."
4951 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
4952 " if equals to polyalgo, polygonal HLR algorithm is applied."
4953 "If shapes are not given HLR algoithm of given type is applied"
4954 " to all shapes in the view\n",
4955 __FILE__,VHLRType,group);