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.
25 #include <OpenGl_GlCore20.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_Drawer.hxx>
28 #include <AIS_InteractiveObject.hxx>
29 #include <AIS_ListOfInteractive.hxx>
30 #include <AIS_ListIteratorOfListOfInteractive.hxx>
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_ExportFormat.hxx>
34 #include <Graphic3d_NameOfTextureEnv.hxx>
35 #include <Graphic3d_TextureEnv.hxx>
36 #include <Graphic3d_TextureParams.hxx>
37 #include <Graphic3d_TypeOfTextureFilter.hxx>
38 #include <Graphic3d_AspectFillArea3d.hxx>
39 #include <ViewerTest.hxx>
40 #include <ViewerTest_EventManager.hxx>
41 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
42 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
43 #include <Visual3d_View.hxx>
44 #include <Visual3d_ViewManager.hxx>
45 #include <V3d_AmbientLight.hxx>
46 #include <V3d_DirectionalLight.hxx>
47 #include <V3d_LayerMgr.hxx>
48 #include <V3d_LayerMgrPointer.hxx>
49 #include <V3d_PositionalLight.hxx>
50 #include <V3d_SpotLight.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 <OpenGl_GraphicDriver.hxx>
64 #include <OSD_Timer.hxx>
65 #include <TColStd_SequenceOfInteger.hxx>
66 #include <TColStd_HSequenceOfReal.hxx>
67 #include <TColgp_Array1OfPnt2d.hxx>
68 #include <Visual3d_LayerItem.hxx>
69 #include <Aspect_TypeOfLine.hxx>
70 #include <Image_Diff.hxx>
71 #include <Aspect_DisplayConnection.hxx>
72 #include <Graphic3d.hxx>
76 #include <PrsMgr_PresentableObject.hxx>
77 #include <Graphic3d_ClipPlane.hxx>
78 #include <NCollection_DataMap.hxx>
79 #include <Graphic3d_Texture2Dmanual.hxx>
80 #include <Prs3d_ShadingAspect.hxx>
86 #include <Visual3d_Layer.hxx>
90 #include <WNT_WClass.hxx>
91 #include <WNT_Window.hxx>
94 #define _CRT_SECURE_NO_DEPRECATE
95 #pragma warning (disable:4996)
97 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
98 #include <Cocoa_Window.hxx>
100 #include <Xw_Window.hxx>
101 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
102 #include <X11/Xutil.h>
106 // Auxiliary definitions
107 static const char THE_KEY_DELETE = 127;
109 //==============================================================================
110 // VIEWER GLOBAL VARIABLES
111 //==============================================================================
113 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
114 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
116 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
117 extern const Handle(NIS_InteractiveContext)& TheNISContext();
118 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
120 extern int VErase (Draw_Interpretor& theDI,
121 Standard_Integer theArgNb,
122 const char** theArgVec);
125 static Handle(WNT_Window)& VT_GetWindow() {
126 static Handle(WNT_Window) WNTWin;
129 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
130 static Handle(Cocoa_Window)& VT_GetWindow()
132 static Handle(Cocoa_Window) aWindow;
135 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
136 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
137 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
140 static Handle(Xw_Window)& VT_GetWindow(){
141 static Handle(Xw_Window) XWWin;
145 static void VProcessEvents(ClientData,int);
148 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
150 static Handle(Aspect_DisplayConnection) aDisplayConnection;
151 return aDisplayConnection;
154 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
156 GetDisplayConnection() = theDisplayConnection;
159 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
160 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
162 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
164 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
165 if (!aWindow.IsNull())
166 return aWindow->HWindow();
167 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
168 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
169 if (!aWindow.IsNull())
170 return aWindow->XWindow();
172 return aWindowHandle;
176 static Standard_Boolean MyHLRIsOn = Standard_False;
178 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
179 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
180 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
181 static OpenGl_Caps ViewerTest_myDefaultCaps;
183 #define ZCLIPWIDTH 1.
185 static void OSWindowSetup();
187 //==============================================================================
188 // EVENT GLOBAL VARIABLES
189 //==============================================================================
191 static int Start_Rot = 0;
192 static int ZClipIsOn = 0;
193 int X_Motion = 0; // Current cursor position
195 int X_ButtonPress = 0; // Last ButtonPress position
196 int Y_ButtonPress = 0;
197 Standard_Boolean IsDragged = Standard_False;
198 Standard_Boolean DragFirst;
200 //==============================================================================
203 static LRESULT WINAPI ViewerWindowProc(
208 static LRESULT WINAPI AdvViewerWindowProc(
216 //==============================================================================
219 //==============================================================================
221 const Handle(MMgt_TShared)& ViewerTest::WClass()
223 static Handle(MMgt_TShared) theWClass;
225 if (theWClass.IsNull())
227 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
228 CS_VREDRAW | CS_HREDRAW, 0, 0,
229 ::LoadCursor (NULL, IDC_ARROW));
235 //==============================================================================
236 //function : CreateName
237 //purpose : Create numerical name for new object in theMap
238 //==============================================================================
239 template <typename ObjectType>
240 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
241 const TCollection_AsciiString& theDefaultString)
243 if (theObjectMap.IsEmpty())
244 return theDefaultString + TCollection_AsciiString(1);
246 Standard_Integer aNextKey = 1;
247 Standard_Boolean isFound = Standard_False;
250 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
251 // Look for objects with default names
252 if (theObjectMap.IsBound1(aStringKey))
257 isFound = Standard_True;
260 return theDefaultString + TCollection_AsciiString(aNextKey);
263 //==============================================================================
264 //structure : ViewerTest_Names
265 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
266 //==============================================================================
267 struct ViewerTest_Names
270 TCollection_AsciiString myDriverName;
271 TCollection_AsciiString myViewerName;
272 TCollection_AsciiString myViewName;
276 const TCollection_AsciiString& GetDriverName () const
280 void SetDriverName (const TCollection_AsciiString& theDriverName)
282 myDriverName = theDriverName;
284 const TCollection_AsciiString& GetViewerName () const
288 void SetViewerName (const TCollection_AsciiString& theViewerName)
290 myViewerName = theViewerName;
292 const TCollection_AsciiString& GetViewName () const
296 void SetViewName (const TCollection_AsciiString& theViewName)
298 myViewName = theViewName;
301 //===========================================================================
302 //function : Constructor for ViewerTest_Names
303 //purpose : Get view, viewer, driver names from custom string
304 //===========================================================================
306 ViewerTest_Names (const TCollection_AsciiString& theInputString)
308 TCollection_AsciiString aName(theInputString);
309 if (theInputString.IsEmpty())
311 // Get current configuration
312 if (ViewerTest_myDrivers.IsEmpty())
313 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
314 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
316 myDriverName = ViewerTest_myDrivers.Find2
317 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
319 if(ViewerTest_myContexts.IsEmpty())
321 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
322 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
325 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
327 myViewName = CreateName <Handle(V3d_View)>
328 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
332 // There is at least view name
333 Standard_Integer aParserNumber = 0;
334 for (Standard_Integer i = 0; i < 3; ++i)
336 Standard_Integer aParserPos = aName.SearchFromEnd("/");
340 aName.Split(aParserPos-1);
345 if (aParserNumber == 0)
348 if (!ViewerTest::GetAISContext().IsNull())
350 myDriverName = ViewerTest_myDrivers.Find2
351 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
352 myViewerName = ViewerTest_myContexts.Find2
353 (ViewerTest::GetAISContext());
357 // There is no opened contexts here, need to create names for viewer and driver
358 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
359 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
361 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
362 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
364 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
366 else if (aParserNumber == 1)
368 // Here is viewerName/viewName
369 if (!ViewerTest::GetAISContext().IsNull())
370 myDriverName = ViewerTest_myDrivers.Find2
371 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
374 // There is no opened contexts here, need to create name for driver
375 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
376 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
378 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
380 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
384 //Here is driverName/viewerName/viewName
385 myDriverName = TCollection_AsciiString(aName);
387 TCollection_AsciiString aViewerName(theInputString);
388 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
389 myViewerName = TCollection_AsciiString(aViewerName);
391 myViewName = TCollection_AsciiString(theInputString);
397 //==============================================================================
398 //function : FindContextByView
399 //purpose : Find AIS_InteractiveContext by View
400 //==============================================================================
402 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
404 Handle(AIS_InteractiveContext) anAISContext;
406 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
407 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
409 if (anIter.Value()->CurrentViewer() == theView->Viewer())
410 return anIter.Key2();
416 //==============================================================================
417 //function : SetWindowTitle
418 //purpose : Set window title
419 //==============================================================================
421 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
422 Standard_CString theTitle)
425 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
427 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
428 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
430 if(GetDisplayConnection()->GetDisplay())
433 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
434 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
439 //==============================================================================
440 //function : IsWindowOverlapped
441 //purpose : Check if theWindow overlapp another view
442 //==============================================================================
444 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
445 const Standard_Integer thePxTop,
446 const Standard_Integer thePxRight,
447 const Standard_Integer thePxBottom,
448 TCollection_AsciiString& theViewId)
450 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
451 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
453 Standard_Integer aTop = 0,
457 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
458 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
459 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
460 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
461 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
463 theViewId = anIter.Key1();
464 return Standard_True;
467 return Standard_False;
470 // Workaround: to create and delete non-orthographic views outside ViewerTest
471 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
473 ViewerTest_myViews.UnBind1 (theName);
476 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
477 const Handle(V3d_View)& theView)
479 ViewerTest_myViews.Bind (theName, theView);
482 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
484 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
486 //==============================================================================
487 //function : ViewerInit
488 //purpose : Create the window viewer and initialize all the global variable
489 //==============================================================================
491 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
492 const Standard_Integer thePxTop,
493 const Standard_Integer thePxWidth,
494 const Standard_Integer thePxHeight,
495 Standard_CString theViewName,
496 Standard_CString theDisplayName)
498 // Default position and dimension of the viewer window.
499 // Note that left top corner is set to be sufficiently small to have
500 // window fit in the small screens (actual for remote desktops, see #23003).
501 // The position corresponds to the window's client area, thus some
502 // gap is added for window frame to be visible.
503 Standard_Integer aPxLeft = 20;
504 Standard_Integer aPxTop = 40;
505 Standard_Integer aPxWidth = 409;
506 Standard_Integer aPxHeight = 409;
507 Standard_Boolean toCreateViewer = Standard_False;
509 Handle(OpenGl_GraphicDriver) aGraphicDriver;
510 ViewerTest_Names aViewNames(theViewName);
511 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
512 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
519 aPxWidth = thePxWidth;
520 if (thePxHeight != 0)
521 aPxHeight = thePxHeight;
523 // Get graphic driver (create it or get from another view)
524 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
526 // Get connection string
527 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
528 TCollection_AsciiString aDisplayName(theDisplayName);
529 if (!aDisplayName.IsEmpty())
530 SetDisplayConnection (new Aspect_DisplayConnection ());
532 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
534 (void)theDisplayName; // avoid warning on unused argument
535 SetDisplayConnection (new Aspect_DisplayConnection ());
537 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
538 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
539 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
540 toCreateViewer = Standard_True;
544 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
547 //Dispose the window if input parameters are default
548 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
550 Standard_Integer aTop = 0,
557 // Get screen resolution
558 #if defined(_WIN32) || defined(__WIN32__)
560 GetClientRect(GetDesktopWindow(), &aWindowSize);
561 aScreenHeight = aWindowSize.bottom;
562 aScreenWidth = aWindowSize.right;
563 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
564 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
566 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
567 aScreenWidth = WidthOfScreen(aScreen);
568 aScreenHeight = HeightOfScreen(aScreen);
571 TCollection_AsciiString anOverlappedViewId("");
573 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
575 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
577 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
578 && aRight + 2*aPxWidth + 40 > aScreenWidth)
580 if (aBottom + aPxHeight + 40 > aScreenHeight)
587 aPxTop = aBottom + 40;
590 aPxLeft = aRight + 20;
595 TCollection_AsciiString aTitle("3D View - ");
596 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
598 // Change name of current active window
599 if (!ViewerTest::CurrentView().IsNull())
601 TCollection_AsciiString aTitle("3D View - ");
603 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
604 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
608 Handle(V3d_Viewer) a3DViewer;
609 // If it's the single view, we first look for empty context
610 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
612 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
613 anIter(ViewerTest_myContexts);
615 ViewerTest::SetAISContext (anIter.Value());
616 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
618 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
620 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
621 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
623 else if (a3DViewer.IsNull())
625 toCreateViewer = Standard_True;
626 TCollection_ExtendedString NameOfWindow("Viewer3D");
627 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
629 NameOfWindow = TCollection_ExtendedString("Collector");
631 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
635 if (ViewerTest::GetAISContext().IsNull() ||
636 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
638 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
639 ViewerTest::SetAISContext (aContext);
640 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
644 ViewerTest::ResetEventManager();
649 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
650 Handle(WNT_WClass)::DownCast (WClass()),
651 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
655 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
656 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
658 aPxWidth, aPxHeight);
659 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
661 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
664 aPxWidth, aPxHeight);
666 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
669 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
671 ViewerTest::CurrentView(aView);
672 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
673 TheNISContext()->AttachView (aView);
675 // Setup for X11 or NT
678 // Set parameters for V3d_View and V3d_Viewer
679 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
680 aV3dView->SetComputedMode(Standard_False);
681 MyHLRIsOn = aV3dView->ComputedMode();
682 aV3dView->SetZClippingDepth(0.5);
683 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
685 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
688 a3DViewer->SetDefaultLights();
689 a3DViewer->SetLightOn();
692 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
693 #if TCL_MAJOR_VERSION < 8
694 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
695 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
697 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
698 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
702 VT_GetWindow()->Map();
704 // Set the handle of created view in the event manager
705 ViewerTest::ResetEventManager();
707 ViewerTest::CurrentView()->Redraw();
712 return aViewNames.GetViewName();
715 //==============================================================================
716 //function : RedrawAllViews
717 //purpose : Redraw all created views
718 //==============================================================================
719 void ViewerTest::RedrawAllViews()
721 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
722 for (; aViewIt.More(); aViewIt.Next())
724 const Handle(V3d_View)& aView = aViewIt.Key2();
729 //==============================================================================
731 //purpose : Create the window viewer and initialize all the global variable
732 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
733 //==============================================================================
735 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
739 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
740 << "Type help for more information.\n";
744 TCollection_AsciiString aViewName, aDisplayName;
745 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
746 TCollection_AsciiString aName, aValue;
747 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
749 const TCollection_AsciiString anArg = theArgVec[anArgIt];
750 TCollection_AsciiString anArgCase = anArg;
751 anArgCase.UpperCase();
752 if (ViewerTest::SplitParameter (anArg, aName, aValue))
755 if (aName.IsEqual ("NAME"))
759 else if (aName.IsEqual ("L")
760 || aName.IsEqual ("LEFT"))
762 aPxLeft = aValue.IntegerValue();
764 else if (aName.IsEqual ("T")
765 || aName.IsEqual ("TOP"))
767 aPxTop = aValue.IntegerValue();
769 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
770 else if (aName.IsEqual ("DISP")
771 || aName.IsEqual ("DISPLAY"))
773 aDisplayName = aValue;
776 else if (aName.IsEqual ("W")
777 || aName.IsEqual ("WIDTH"))
779 aPxWidth = aValue.IntegerValue();
781 else if (aName.IsEqual ("H")
782 || aName.IsEqual ("HEIGHT"))
784 aPxHeight = aValue.IntegerValue();
788 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
791 else if (aViewName.IsEmpty())
797 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
801 ViewerTest_Names aViewNames (aViewName);
802 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
804 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
805 theDi.Eval (aCommand.ToCString());
809 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
810 aViewName.ToCString(),
811 aDisplayName.ToCString());
816 //==============================================================================
818 //purpose : hidden lines removal algorithm
819 //==============================================================================
821 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
823 if (ViewerTest::CurrentView().IsNull())
825 di << argv[0] << ": Call vinit before this command, please.\n";
831 di << argv[0] << ": Wrong number of command arguments.\n"
832 << "Type help " << argv[0] << " for more information.\n";
836 Standard_Boolean isHLROn =
837 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
839 if (isHLROn == MyHLRIsOn)
845 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
850 //==============================================================================
851 //function : VHLRType
852 //purpose : change type of using HLR algorithm
853 //==============================================================================
855 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
857 if (ViewerTest::CurrentView().IsNull())
859 di << argv[0] << ": Call vinit before this command, please.\n";
865 di << argv[0] << ": Wrong number of command arguments.\n"
866 << "Type help " << argv[0] << " for more information.\n";
870 Prs3d_TypeOfHLR aTypeOfHLR =
871 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
875 AIS_ListOfInteractive aListOfShapes;
876 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
877 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
878 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
879 anIter.More(); anIter.Next())
881 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
884 if (aShape->TypeOfHLR() != aTypeOfHLR)
885 aShape->SetTypeOfHLR (aTypeOfHLR);
889 ViewerTest::CurrentView()->Update();
894 for (Standard_Integer i = 2; i < argc; ++i)
896 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
897 TCollection_AsciiString aName (argv[i]);
899 if (!aMap.IsBound2 (aName))
901 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
904 Handle(AIS_Shape) anAISObject =
905 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
906 if (anAISObject.IsNull())
908 anAISObject->SetTypeOfHLR (aTypeOfHLR);
910 anAISObject->Redisplay();
912 ViewerTest::CurrentView()->Update();
918 //==============================================================================
919 //function : FindViewIdByWindowHandle
920 //purpose : Find theView Id in the map of views by window handle
921 //==============================================================================
922 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
923 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
925 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
926 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
928 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
929 if (aWindowHandle == theWindowHandle)
930 return anIter.Key1();
932 return TCollection_AsciiString("");
936 //==============================================================================
937 //function : ActivateView
938 //purpose : Make the view active
939 //==============================================================================
941 void ActivateView (const TCollection_AsciiString& theViewName)
943 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
946 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
947 if (!anAISContext.IsNull())
949 if (!ViewerTest::CurrentView().IsNull())
951 TCollection_AsciiString aTitle("3D View - ");
952 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
953 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
956 ViewerTest::CurrentView (aView);
957 // Update degenerate mode
958 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
959 ViewerTest::SetAISContext (anAISContext);
960 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
961 aTitle = aTitle + theViewName + "(*)";
962 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
963 #if defined(_WIN32) || defined(__WIN32__)
964 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
965 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
966 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
968 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
970 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
971 ViewerTest::CurrentView()->Redraw();
976 //==============================================================================
977 //function : RemoveView
978 //purpose : Close and remove view from display, clear maps if neccessary
979 //==============================================================================
980 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
982 if (!ViewerTest_myViews.IsBound1(theViewName))
984 cout << "Wrong view name\n";
988 // Activate another view if it's active now
989 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
991 if (ViewerTest_myViews.Extent() > 1)
993 TCollection_AsciiString aNewViewName;
994 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
995 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
996 if (anIter.Key1() != theViewName)
998 aNewViewName = anIter.Key1();
1001 ActivateView (aNewViewName);
1005 Handle(V3d_View) anEmptyView;
1006 #if defined(_WIN32) || defined(__WIN32__)
1007 Handle(WNT_Window) anEmptyWindow;
1008 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1009 Handle(Cocoa_Window) anEmptyWindow;
1011 Handle(Xw_Window) anEmptyWindow;
1013 VT_GetWindow() = anEmptyWindow;
1014 ViewerTest::CurrentView (anEmptyView);
1015 if (isContextRemoved)
1017 Handle(AIS_InteractiveContext) anEmptyContext;
1018 ViewerTest::SetAISContext(anEmptyContext);
1024 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1025 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1027 // Remove view resources
1028 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1029 ViewerTest_myViews.UnBind1(theViewName);
1032 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1033 XFlush (GetDisplayConnection()->GetDisplay());
1036 // Keep context opened only if the closed view is last to avoid
1037 // unused empty contexts
1038 if (!aCurrentContext.IsNull())
1040 // Check if there are more difined views in the viewer
1041 aCurrentContext->CurrentViewer()->InitDefinedViews();
1042 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1044 // Remove driver if there is no viewers that use it
1045 Standard_Boolean isRemoveDriver = Standard_True;
1046 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1047 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1049 if (aCurrentContext != anIter.Key2() &&
1050 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1052 isRemoveDriver = Standard_False;
1058 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1059 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1060 #if TCL_MAJOR_VERSION < 8
1061 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1063 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1068 ViewerTest_myContexts.UnBind2(aCurrentContext);
1071 cout << "3D View - " << theViewName << " was deleted.\n";
1075 //==============================================================================
1077 //purpose : Remove the view defined by its name
1078 //==============================================================================
1080 static int VClose (Draw_Interpretor& /*theDi*/,
1081 Standard_Integer theArgsNb,
1082 const char** theArgVec)
1084 NCollection_List<TCollection_AsciiString> aViewList;
1087 TCollection_AsciiString anArg (theArgVec[1]);
1089 if (anArg.IsEqual ("ALL")
1090 || anArg.IsEqual ("*"))
1092 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1093 anIter.More(); anIter.Next())
1095 aViewList.Append (anIter.Key1());
1097 if (aViewList.IsEmpty())
1099 std::cout << "No view to close\n";
1105 ViewerTest_Names aViewName (theArgVec[1]);
1106 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1108 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1111 aViewList.Append (aViewName.GetViewName());
1116 // close active view
1117 if (ViewerTest::CurrentView().IsNull())
1119 std::cerr << "No active view!\n";
1122 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1125 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1126 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1127 anIter.More(); anIter.Next())
1129 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1135 //==============================================================================
1136 //function : VActivate
1137 //purpose : Activate the view defined by its ID
1138 //==============================================================================
1140 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1144 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1145 << "Usage: " << theArgVec[0] << " ViewID\n";
1150 theDi.Eval("vviewlist");
1154 TCollection_AsciiString aNameString(theArgVec[1]);
1155 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1157 TCollection_AsciiString aTitle("3D View - ");
1158 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1159 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1160 Handle(V3d_View) anEmptyView;
1161 #if defined(_WIN32) || defined(__WIN32__)
1162 Handle(WNT_Window) anEmptyWindow;
1163 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1164 Handle(Cocoa_Window) anEmptyWindow;
1166 Handle(Xw_Window) anEmptyWindow;
1168 VT_GetWindow() = anEmptyWindow;
1169 ViewerTest::CurrentView (anEmptyView);
1170 ViewerTest::ResetEventManager();
1171 theDi << theArgVec[0] << ": all views are inactive\n";
1175 ViewerTest_Names aViewNames(aNameString);
1177 // Check if this view exists in the viewer with the driver
1178 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1180 theDi << "Wrong view name\n";
1184 // Check if it is active already
1185 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1187 theDi << theArgVec[0] << ": the view is active already\n";
1191 ActivateView (aViewNames.GetViewName());
1195 //==============================================================================
1196 //function : VViewList
1197 //purpose : Print current list of views per viewer and graphic driver ID
1198 // shared between viewers
1199 //==============================================================================
1201 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1205 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1206 << "Usage: " << theArgVec[0] << " name";
1209 if (ViewerTest_myContexts.Size() < 1)
1212 Standard_Boolean isTreeView =
1213 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1216 theDi << theArgVec[0] <<":\n";
1218 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1219 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1222 theDi << aDriverIter.Key1() << ":\n";
1224 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1225 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1227 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1231 TCollection_AsciiString aContextName(aContextIter.Key1());
1232 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1235 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1236 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1238 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1240 TCollection_AsciiString aViewName(aViewIter.Key1());
1243 if (aViewIter.Value() == ViewerTest::CurrentView())
1244 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1246 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1250 theDi << aViewName << " ";
1260 //==============================================================================
1261 //function : VT_ProcessKeyPress
1262 //purpose : Handle KeyPress event from a CString
1263 //==============================================================================
1264 void VT_ProcessKeyPress (const char* buf_ret)
1266 //cout << "KeyPress" << endl;
1267 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1268 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1269 // Letter in alphabetic order
1271 if (!strcasecmp (buf_ret, "A"))
1274 aView->SetProj(V3d_XposYnegZpos);
1276 else if (!strcasecmp (buf_ret, "D"))
1281 else if (!strcasecmp (buf_ret, "F"))
1284 if (aNisView.IsNull())
1287 aNisView->FitAll3d();
1289 else if (!strcasecmp (buf_ret, "H"))
1292 cout << "HLR" << endl;
1293 aView->SetComputedMode (!aView->ComputedMode());
1294 MyHLRIsOn = aView->ComputedMode();
1296 else if (!strcasecmp (buf_ret, "P"))
1299 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1300 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1301 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1303 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1304 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1306 AIS_ListOfInteractive aListOfShapes;
1307 aContext->DisplayedObjects(aListOfShapes);
1308 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1309 anIter.More(); anIter.Next())
1311 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1312 if (aShape.IsNull())
1314 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1315 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1317 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1318 aShape->Redisplay();
1323 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1325 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1326 if (aShape.IsNull())
1328 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1329 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1331 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1332 aShape->Redisplay();
1336 aContext->UpdateCurrentViewer();
1339 else if (!strcasecmp (buf_ret, "S"))
1341 std::cout << "setup Shaded display mode" << std::endl;
1343 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1344 if(Ctx->NbCurrents()==0 ||
1345 Ctx->NbSelected()==0)
1346 Ctx->SetDisplayMode(AIS_Shaded);
1348 if(Ctx->HasOpenedContext()){
1349 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1350 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1353 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1354 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1356 Ctx->UpdateCurrentViewer();
1359 else if (!strcasecmp (buf_ret, "U"))
1361 // Unset display mode
1362 std::cout << "reset display mode to defaults" << std::endl;
1364 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1365 if(Ctx->NbCurrents()==0 ||
1366 Ctx->NbSelected()==0)
1367 Ctx->SetDisplayMode(AIS_WireFrame);
1369 if(Ctx->HasOpenedContext()){
1370 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1371 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1374 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1375 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1377 Ctx->UpdateCurrentViewer();
1381 else if (!strcasecmp (buf_ret, "T"))
1384 aView->SetProj(V3d_Zpos);
1386 else if (!strcasecmp (buf_ret, "B"))
1389 aView->SetProj(V3d_Zneg);
1391 else if (!strcasecmp (buf_ret, "L"))
1394 aView->SetProj(V3d_Xneg);
1396 else if (!strcasecmp (buf_ret, "R"))
1399 aView->SetProj(V3d_Xpos);
1401 else if (!strcasecmp (buf_ret, "W"))
1403 std::cout << "setup WireFrame display mode" << std::endl;
1404 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1405 if(Ctx->NbCurrents()==0 ||
1406 Ctx->NbSelected()==0)
1407 Ctx->SetDisplayMode(AIS_WireFrame);
1409 if(Ctx->HasOpenedContext()){
1410 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1411 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1414 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1415 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1417 Ctx->UpdateCurrentViewer();
1420 else if (!strcasecmp (buf_ret, "Z"))
1424 cout << "ZClipping OFF" << endl;
1427 aView->SetZClippingType(V3d_OFF);
1431 cout << "ZClipping ON" << endl;
1434 aView->SetZClippingType(V3d_FRONT);
1438 else if (!strcasecmp (buf_ret, ","))
1440 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1442 else if (!strcasecmp (buf_ret, "."))
1444 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1446 else if (*buf_ret == THE_KEY_DELETE)
1448 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1450 && aCtx->NbCurrents() > 0
1451 && aCtx->NbSelected() > 0)
1453 Draw_Interprete ("verase");
1459 Standard_Integer Num = Draw::Atoi(buf_ret);
1460 if(Num>=0 && Num<=7)
1461 ViewerTest::StandardModeActivation(Num);
1465 //==============================================================================
1466 //function : VT_ProcessExpose
1467 //purpose : Redraw the View on an Expose Event
1468 //==============================================================================
1469 void VT_ProcessExpose()
1471 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1472 if (!aView3d.IsNull())
1478 //==============================================================================
1479 //function : VT_ProcessConfigure
1480 //purpose : Resize the View on an Configure Event
1481 //==============================================================================
1482 void VT_ProcessConfigure()
1484 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1485 if (aView3d.IsNull())
1490 aView3d->MustBeResized();
1495 //==============================================================================
1496 //function : VT_ProcessButton1Press
1498 //==============================================================================
1499 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1500 const char** theArgVec,
1501 Standard_Boolean theToPick,
1502 Standard_Boolean theIsShift)
1506 Standard_Real X, Y, Z;
1507 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1509 Draw::Set (theArgVec[1], X);
1510 Draw::Set (theArgVec[2], Y);
1511 Draw::Set (theArgVec[3], Z);
1516 ViewerTest::CurrentEventManager()->ShiftSelect();
1520 ViewerTest::CurrentEventManager()->Select();
1523 return Standard_False;
1526 //==============================================================================
1527 //function : VT_ProcessButton1Release
1528 //purpose : End selecting
1529 //==============================================================================
1530 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1534 IsDragged = Standard_False;
1535 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1538 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1539 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1543 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1544 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1549 //==============================================================================
1550 //function : VT_ProcessButton3Press
1551 //purpose : Start Rotation
1552 //==============================================================================
1553 void VT_ProcessButton3Press()
1558 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1560 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1563 //==============================================================================
1564 //function : VT_ProcessButton3Release
1565 //purpose : End rotation
1566 //==============================================================================
1567 void VT_ProcessButton3Release()
1574 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1579 //==============================================================================
1580 //function : ProcessZClipMotion
1582 //==============================================================================
1584 void ProcessZClipMotion()
1586 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1587 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1588 static Standard_Real CurZPos = 0.;
1590 //Quantity_Length VDX, VDY;
1591 //a3DView->Size(VDX,VDY);
1592 //Standard_Real VDZ = a3DView->ZSize();
1593 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1595 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1597 // Front = Depth + width/2.
1598 Standard_Real D = 0.5;
1599 Standard_Real W = 0.1;
1605 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1607 a3DView->SetZClippingType(V3d_OFF);
1608 a3DView->SetZClippingDepth(D);
1609 a3DView->SetZClippingWidth(W);
1610 a3DView->SetZClippingType(V3d_FRONT);
1614 X_ButtonPress = X_Motion;
1615 Y_ButtonPress = Y_Motion;
1619 //==============================================================================
1620 //function : ProcessControlButton1Motion
1622 //==============================================================================
1624 static void ProcessControlButton1Motion()
1626 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1628 X_ButtonPress = X_Motion;
1629 Y_ButtonPress = Y_Motion;
1632 //==============================================================================
1633 //function : VT_ProcessControlButton2Motion
1635 //==============================================================================
1636 void VT_ProcessControlButton2Motion()
1638 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1639 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1641 dy = -dy; // Xwindow Y axis is from top to Bottom
1643 ViewerTest::CurrentView()->Panning( dx, dy );
1645 X_ButtonPress = X_Motion;
1646 Y_ButtonPress = Y_Motion;
1649 //==============================================================================
1650 //function : VT_ProcessControlButton3Motion
1651 //purpose : Rotation
1652 //==============================================================================
1653 void VT_ProcessControlButton3Motion()
1657 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1661 //==============================================================================
1662 //function : VT_ProcessMotion
1664 //==============================================================================
1665 void VT_ProcessMotion()
1667 //pre-hilights detected objects at mouse position
1669 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1670 EM->MoveTo(X_Motion, Y_Motion);
1674 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1676 Xpix = X_Motion;Ypix=Y_Motion;
1679 //==============================================================================
1680 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1681 //purpose : Switches to an axonometric, top, left and other views
1682 //==============================================================================
1684 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1686 if ( ViewerTest::CurrentView().IsNull() )
1688 di<<"Call vinit before this command, please"<<"\n";
1692 ViewerTest::CurrentView()->SetProj(ori);
1696 //==============================================================================
1698 //purpose : Switch to an Axonometric view
1699 //Draw arg : No args
1700 //==============================================================================
1702 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1704 return ViewProject(di, V3d_XposYnegZpos);
1707 //==============================================================================
1709 //purpose : Switch to a Top View
1710 //Draw arg : No args
1711 //==============================================================================
1713 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1715 return ViewProject(di, V3d_Zpos);
1718 //==============================================================================
1719 //function : VBottom
1720 //purpose : Switch to a Bottom View
1721 //Draw arg : No args
1722 //==============================================================================
1724 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1726 return ViewProject(di, V3d_Zneg);
1729 //==============================================================================
1731 //purpose : Switch to a Left View
1732 //Draw arg : No args
1733 //==============================================================================
1735 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1737 return ViewProject(di, V3d_Ypos);
1740 //==============================================================================
1742 //purpose : Switch to a Right View
1743 //Draw arg : No args
1744 //==============================================================================
1746 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1748 return ViewProject(di, V3d_Yneg);
1751 //==============================================================================
1753 //purpose : Switch to a Front View
1754 //Draw arg : No args
1755 //==============================================================================
1757 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1759 return ViewProject(di, V3d_Xpos);
1762 //==============================================================================
1764 //purpose : Switch to a Back View
1765 //Draw arg : No args
1766 //==============================================================================
1768 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1770 return ViewProject(di, V3d_Xneg);
1773 //==============================================================================
1775 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1776 //Draw arg : No args
1777 //==============================================================================
1779 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1782 di << "Q : Quit the application" << "\n";
1784 di << "========================="<<"\n";
1785 di << "F : FitAll" << "\n";
1786 di << "T : TopView" << "\n";
1787 di << "B : BottomView" << "\n";
1788 di << "R : RightView" << "\n";
1789 di << "L : LeftView" << "\n";
1790 di << "A : AxonometricView" << "\n";
1791 di << "D : ResetView" << "\n";
1793 di << "========================="<<"\n";
1794 di << "S : Shading" << "\n";
1795 di << "W : Wireframe" << "\n";
1796 di << "H : HidelLineRemoval" << "\n";
1797 di << "U : Unset display mode" << "\n";
1798 di << "Delete : Remove selection from viewer" << "\n";
1800 di << "========================="<<"\n";
1801 di << "Selection mode "<<"\n";
1802 di << "0 : Shape" <<"\n";
1803 di << "1 : Vertex" <<"\n";
1804 di << "2 : Edge" <<"\n";
1805 di << "3 : Wire" <<"\n";
1806 di << "4 : Face" <<"\n";
1807 di << "5 : Shell" <<"\n";
1808 di << "6 : Solid" <<"\n";
1809 di << "7 : Compound" <<"\n";
1811 di << "========================="<<"\n";
1812 di << "Z : Switch Z clipping On/Off" << "\n";
1813 di << ", : Hilight next detected" << "\n";
1814 di << ". : Hilight previous detected" << "\n";
1821 static Standard_Boolean Ppick = 0;
1822 static Standard_Integer Pargc = 0;
1823 static const char** Pargv = NULL;
1826 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1831 if (!ViewerTest_myViews.IsEmpty()) {
1833 WPARAM fwKeys = wParam;
1838 // Delete view from map of views
1839 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1844 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1845 || ViewerTest::CurrentView().IsNull())
1847 // Activate inactive window
1848 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1850 ActivateView (FindViewIdByWindowHandle(hwnd));
1855 IsDragged = Standard_False;
1858 HDC hdc = GetDC( hwnd );
1859 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1860 SetROP2( hdc, R2_NOT );
1861 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1862 ReleaseDC( hwnd, hdc );
1864 const Handle(ViewerTest_EventManager) EM =
1865 ViewerTest::CurrentEventManager();
1866 if ( fwKeys & MK_SHIFT )
1867 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1868 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1870 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1871 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1873 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1875 case WM_LBUTTONDOWN:
1876 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1878 IsDragged = Standard_True;
1879 DragFirst = Standard_True;
1880 X_ButtonPress = LOWORD(lParam);
1881 Y_ButtonPress = HIWORD(lParam);
1883 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1890 HDC hdc = GetDC( hwnd );
1892 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1893 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1894 SetROP2( hdc, R2_NOT );
1897 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1899 DragFirst = Standard_False;
1900 X_Motion = LOWORD(lParam);
1901 Y_Motion = HIWORD(lParam);
1903 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1905 SelectObject( hdc, anObj );
1907 ReleaseDC( hwnd, hdc );
1910 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1914 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1918 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1922 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1929 if ( !ViewerTest::CurrentView().IsNull() ) {
1934 BeginPaint(hwnd, &ps);
1935 EndPaint(hwnd, &ps);
1940 VT_ProcessConfigure();
1944 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1947 c[0] = (char) wParam;
1949 if (wParam == VK_DELETE)
1951 c[0] = THE_KEY_DELETE;
1953 VT_ProcessKeyPress (c);
1961 VT_ProcessButton3Release();
1964 case WM_LBUTTONDOWN:
1965 case WM_MBUTTONDOWN:
1966 case WM_RBUTTONDOWN:
1968 WPARAM fwKeys = wParam;
1972 X_ButtonPress = LOWORD(lParam);
1973 Y_ButtonPress = HIWORD(lParam);
1975 if (Msg == WM_LBUTTONDOWN)
1977 if (fwKeys & MK_CONTROL)
1979 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1983 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1986 else if (Msg == WM_RBUTTONDOWN)
1989 VT_ProcessButton3Press();
1996 //cout << "\t WM_MOUSEMOVE" << endl;
1997 WPARAM fwKeys = wParam;
1998 X_Motion = LOWORD(lParam);
1999 Y_Motion = HIWORD(lParam);
2002 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2004 X_ButtonPress = LOWORD(lParam);
2005 Y_ButtonPress = HIWORD(lParam);
2007 if ( fwKeys & MK_RBUTTON ) {
2009 VT_ProcessButton3Press();
2013 if ( fwKeys & MK_CONTROL ) {
2014 if ( fwKeys & MK_LBUTTON ) {
2015 ProcessControlButton1Motion();
2017 else if ( fwKeys & MK_MBUTTON ||
2018 ((fwKeys&MK_LBUTTON) &&
2019 (fwKeys&MK_RBUTTON) ) ){
2020 VT_ProcessControlButton2Motion();
2022 else if ( fwKeys & MK_RBUTTON ) {
2023 VT_ProcessControlButton3Motion();
2027 else if ( fwKeys & MK_SHIFT ) {
2028 if ( fwKeys & MK_MBUTTON ||
2029 ((fwKeys&MK_LBUTTON) &&
2030 (fwKeys&MK_RBUTTON) ) ) {
2031 cout << "ProcessZClipMotion()" << endl;
2032 ProcessZClipMotion();
2036 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2038 if ((fwKeys & MK_MBUTTON
2039 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2041 ProcessZClipMotion();
2052 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2057 return DefWindowProc( hwnd, Msg, wParam, lParam );
2063 //==============================================================================
2064 //function : ViewerMainLoop
2065 //purpose : Get a Event on the view and dispatch it
2066 //==============================================================================
2069 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2071 Ppick = (argc > 0)? 1 : 0;
2079 cout << "Start picking" << endl;
2081 while ( Ppick == 1 ) {
2082 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2083 if (GetMessage(&msg, NULL, 0, 0) ) {
2084 TranslateMessage(&msg);
2085 DispatchMessage(&msg);
2089 cout << "Picking done" << endl;
2095 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2097 int min( int a, int b )
2105 int max( int a, int b )
2113 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2116 static XEvent aReport;
2117 Standard_Boolean pick = argc > 0;
2118 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2119 XNextEvent (aDisplay, &aReport);
2121 // Handle event for the chosen display connection
2122 switch (aReport.type) {
2125 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2128 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2134 // Activate inactive view
2135 Window aWindow = GetWindowHandle(VT_GetWindow());
2136 if(aWindow != aReport.xfocus.window)
2138 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2147 case ConfigureNotify:
2149 VT_ProcessConfigure();
2158 XComposeStatus status_in_out;
2160 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2161 (char *) buf_ret , 10 ,
2162 &ks_ret , &status_in_out ) ;
2165 buf_ret[ret_len] = '\0' ;
2169 VT_ProcessKeyPress (buf_ret);
2175 X_ButtonPress = aReport.xbutton.x;
2176 Y_ButtonPress = aReport.xbutton.y;
2178 if (aReport.xbutton.button == Button1)
2180 if (aReport.xbutton.state & ControlMask)
2182 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2186 IsDragged = Standard_True;
2187 DragFirst = Standard_True;
2190 else if (aReport.xbutton.button == Button3)
2193 VT_ProcessButton3Press();
2203 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2204 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
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 ) );
2208 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2209 if( aContext.IsNull() )
2211 cout << "The context is null. Please use vinit before createmesh" << endl;
2215 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2216 if( aReport.xbutton.button==1 )
2220 aContext->ShiftSelect();
2229 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2230 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2231 ViewerTest::CurrentView());
2235 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2236 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2237 ViewerTest::CurrentView() );
2240 VT_ProcessButton3Release();
2242 IsDragged = Standard_False;
2245 VT_ProcessButton3Release();
2250 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2256 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2257 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2258 XSetFunction( aDisplay, gc, GXinvert );
2261 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2263 X_Motion = aReport.xmotion.x;
2264 Y_Motion = aReport.xmotion.y;
2265 DragFirst = Standard_False;
2267 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2271 X_Motion = aReport.xmotion.x;
2272 Y_Motion = aReport.xmotion.y;
2274 // remove all the ButtonMotionMaskr
2275 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2277 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2278 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2280 Quantity_Length VDX, VDY;
2282 ViewerTest::CurrentView()->Size(VDX,VDY);
2283 Standard_Real VDZ =0 ;
2284 VDZ = ViewerTest::CurrentView()->ZSize();
2286 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2288 Quantity_Length dx = 0 ;
2289 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2293 dx = dx / VDX * VDZ;
2297 ViewerTest::CurrentView()->Redraw();
2301 if ( aReport.xmotion.state & ControlMask ) {
2302 if ( aReport.xmotion.state & Button1Mask ) {
2303 ProcessControlButton1Motion();
2305 else if ( aReport.xmotion.state & Button2Mask ) {
2306 VT_ProcessControlButton2Motion();
2308 else if ( aReport.xmotion.state & Button3Mask ) {
2309 VT_ProcessControlButton3Motion();
2323 //==============================================================================
2324 //function : VProcessEvents
2325 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2326 // event in the Viewer window
2327 //==============================================================================
2329 static void VProcessEvents(ClientData,int)
2331 NCollection_Vector<int> anEventNumbers;
2332 // Get number of messages from every display
2333 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2334 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2336 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2338 // Handle events for every display
2339 int anEventIter = 0;
2340 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2341 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2343 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2344 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2346 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2347 int anEventResult = ViewerMainLoop( 0, NULL);
2348 // If window is closed or context was not found finish current event processing loop
2354 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2359 //==============================================================================
2360 //function : OSWindowSetup
2361 //purpose : Setup for the X11 window to be able to cath the event
2362 //==============================================================================
2365 static void OSWindowSetup()
2367 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2370 Window window = VT_GetWindow()->XWindow();
2371 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2372 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2373 XSynchronize(aDisplay, 1);
2375 // X11 : For keyboard on SUN
2377 wmhints.flags = InputHint;
2380 XSetWMHints( aDisplay, window, &wmhints);
2382 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2383 ButtonPressMask | ButtonReleaseMask |
2384 StructureNotifyMask |
2386 Button1MotionMask | Button2MotionMask |
2387 Button3MotionMask | FocusChangeMask
2389 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2390 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2392 XSynchronize(aDisplay, 0);
2401 //==============================================================================
2404 //purpose : Fitall, no DRAW arguments
2405 //Draw arg : No args
2406 //==============================================================================
2408 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2410 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2411 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2412 if (V.IsNull() == Standard_False) {
2414 } else if (aView.IsNull() == Standard_False) {
2420 //==============================================================================
2422 //purpose : ZFitall, no DRAW arguments
2423 //Draw arg : No args
2424 //==============================================================================
2426 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2428 Handle(V3d_View) V = ViewerTest::CurrentView();
2429 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2432 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2434 Handle(V3d_View) V = ViewerTest::CurrentView();
2435 if ( !V.IsNull() ) V->Redraw(); return 0;
2439 //==============================================================================
2441 //purpose : Remove all the object from the viewer
2442 //Draw arg : No args
2443 //==============================================================================
2445 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2447 Handle(V3d_View) V = ViewerTest::CurrentView();
2449 ViewerTest::Clear();
2453 //==============================================================================
2456 //==============================================================================
2458 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2459 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2462 di << argv[0] << "Invalid number of arguments" << "\n";
2466 while (ViewerMainLoop( argc, argv)) {
2472 //==============================================================================
2473 //function : InitViewerTest
2474 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2475 //==============================================================================
2477 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2479 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2480 ViewerTest::SetAISContext(theContext);
2481 aViewer->InitActiveViews();
2482 Handle(V3d_View) aView = aViewer->ActiveView();
2483 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2484 ViewerTest::ResetEventManager();
2485 Handle(Aspect_Window) aWindow = aView->Window();
2486 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2488 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2490 static int aFirst = 1;
2492 #if TCL_MAJOR_VERSION < 8
2493 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2494 TK_READABLE, VProcessEvents, (ClientData) 0);
2496 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2497 TK_READABLE, VProcessEvents, (ClientData) 0);
2504 //==============================================================================
2506 //purpose : Load image as background
2507 //==============================================================================
2509 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2511 if (argc < 2 || argc > 3)
2513 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2514 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2518 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2519 if(AISContext.IsNull())
2521 di << "use 'vinit' command before " << argv[0] << "\n";
2525 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2528 const char* szType = argv[2];
2529 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2530 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2531 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2532 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2535 di << "Wrong fill type : " << szType << "\n";
2536 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2541 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2542 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2547 //==============================================================================
2548 //function : VSetBgMode
2549 //purpose : Change background image fill type
2550 //==============================================================================
2552 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2556 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2557 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2561 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2562 if(AISContext.IsNull())
2564 di << "use 'vinit' command before " << argv[0] << "\n";
2567 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2568 const char* szType = argv[1];
2569 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2570 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2571 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2572 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2575 di << "Wrong fill type : " << szType << "\n";
2576 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2579 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2580 V3dView->SetBgImageStyle(aFillType, Standard_True);
2584 //==============================================================================
2585 //function : VSetGradientBg
2586 //purpose : Mount gradient background
2587 //==============================================================================
2588 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2592 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2593 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2594 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2595 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2599 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2600 if(AISContext.IsNull())
2602 di << "use 'vinit' command before " << argv[0] << "\n";
2608 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2609 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2610 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2611 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2613 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2614 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2615 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2617 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2618 int aType = Draw::Atoi(argv[7]);
2619 if( aType < 0 || aType > 8 )
2621 di << "Wrong fill type " << "\n";
2622 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2623 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2627 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2629 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2630 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2636 //==============================================================================
2637 //function : VSetGradientBgMode
2638 //purpose : Change gradient background fill style
2639 //==============================================================================
2640 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2644 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2645 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2646 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2650 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2651 if(AISContext.IsNull())
2653 di << "use 'vinit' command before " << argv[0] << "\n";
2658 int aType = Draw::Atoi(argv[1]);
2659 if( aType < 0 || aType > 8 )
2661 di << "Wrong fill type " << "\n";
2662 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2663 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2667 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2669 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2670 V3dView->SetBgGradientStyle( aMethod, 1 );
2676 //==============================================================================
2677 //function : VSetColorBg
2678 //purpose : Set color background
2679 //==============================================================================
2680 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2684 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2685 di << "R,G,B = [0..255]" << "\n";
2689 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2690 if(AISContext.IsNull())
2692 di << "use 'vinit' command before " << argv[0] << "\n";
2698 Standard_Real R = Draw::Atof(argv[1])/255.;
2699 Standard_Real G = Draw::Atof(argv[2])/255.;
2700 Standard_Real B = Draw::Atof(argv[3])/255.;
2701 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2703 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2704 V3dView->SetBackgroundColor( aColor );
2711 //==============================================================================
2713 //purpose : View Scaling
2714 //==============================================================================
2716 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2718 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2719 if ( V3dView.IsNull() ) return 1;
2722 di << argv[0] << "Invalid number of arguments" << "\n";
2725 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2728 //==============================================================================
2729 //function : VTestZBuffTrihedron
2730 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2731 //==============================================================================
2733 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2735 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2736 if ( V3dView.IsNull() ) return 1;
2738 V3dView->ZBufferTriedronSetup();
2741 // Set up default trihedron parameters
2742 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2746 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2747 const char* aPosType = argv[1];
2749 if ( strcmp(aPosType, "center") == 0 )
2751 aPosition = Aspect_TOTP_CENTER;
2753 if (strcmp(aPosType, "left_lower") == 0)
2755 aPosition = Aspect_TOTP_LEFT_LOWER;
2757 if (strcmp(aPosType, "left_upper") == 0)
2759 aPosition = Aspect_TOTP_LEFT_UPPER;
2761 if (strcmp(aPosType, "right_lower") == 0)
2763 aPosition = Aspect_TOTP_RIGHT_LOWER;
2765 if (strcmp(aPosType, "right_upper") == 0)
2767 aPosition = Aspect_TOTP_RIGHT_UPPER;
2770 di << argv[1] << " Invalid type of alignment" << "\n";
2771 di << "Must be one of [ center, left_lower," << "\n";
2772 di << "left_upper, right_lower, right_upper ]" << "\n";
2776 Standard_Real R = Draw::Atof(argv[2])/255.;
2777 Standard_Real G = Draw::Atof(argv[3])/255.;
2778 Standard_Real B = Draw::Atof(argv[4])/255.;
2779 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2781 Standard_Real aScale = Draw::Atof(argv[5]);
2785 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2789 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2790 const char* aPresType = argv[6];
2792 if ( strcmp(aPresType, "wireframe") == 0 )
2794 aPresentation = V3d_WIREFRAME;
2796 if (strcmp(aPresType, "zbuffer") == 0)
2798 aPresentation = V3d_ZBUFFER;
2801 di << argv[6] << " Invalid type of visualization" << "\n";
2802 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2806 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2810 di << argv[0] << " Invalid number of arguments" << "\n";
2819 //==============================================================================
2820 //function : VRotate
2821 //purpose : Camera Rotating
2822 //==============================================================================
2824 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2825 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2826 if ( V3dView.IsNull() ) {
2831 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2833 } else if ( argc == 7 ) {
2834 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]) );
2837 di << argv[0] << " Invalid number of arguments" << "\n";
2842 //==============================================================================
2844 //purpose : View zoom in / out (relative to current zoom)
2845 //==============================================================================
2847 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2848 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2849 if ( V3dView.IsNull() ) {
2854 Standard_Real coef = Draw::Atof(argv[1]);
2855 if ( coef <= 0.0 ) {
2856 di << argv[1] << "Invalid value" << "\n";
2859 V3dView->SetZoom( Draw::Atof(argv[1]) );
2862 di << argv[0] << " Invalid number of arguments" << "\n";
2867 //==============================================================================
2869 //purpose : View panning (in pixels)
2870 //==============================================================================
2872 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2873 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2874 if ( V3dView.IsNull() ) return 1;
2877 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2880 di << argv[0] << " Invalid number of arguments" << "\n";
2886 //==============================================================================
2887 //function : VExport
2888 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2889 //==============================================================================
2891 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2893 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2894 if (V3dView.IsNull())
2899 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2903 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2904 TCollection_AsciiString aFormatStr;
2906 TCollection_AsciiString aFileName (argv[1]);
2907 Standard_Integer aLen = aFileName.Length();
2911 aFormatStr = TCollection_AsciiString (argv[2]);
2915 if (aFileName.Value (aLen - 2) == '.')
2917 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2919 else if (aFileName.Value (aLen - 3) == '.')
2921 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2925 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2931 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2935 aFormatStr.UpperCase();
2936 if (aFormatStr == "PS")
2937 anExpFormat = Graphic3d_EF_PostScript;
2938 else if (aFormatStr == "EPS")
2939 anExpFormat = Graphic3d_EF_EnhPostScript;
2940 else if (aFormatStr == "TEX")
2941 anExpFormat = Graphic3d_EF_TEX;
2942 else if (aFormatStr == "PDF")
2943 anExpFormat = Graphic3d_EF_PDF;
2944 else if (aFormatStr == "SVG")
2945 anExpFormat = Graphic3d_EF_SVG;
2946 else if (aFormatStr == "PGF")
2947 anExpFormat = Graphic3d_EF_PGF;
2948 else if (aFormatStr == "EMF")
2949 anExpFormat = Graphic3d_EF_EMF;
2952 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2957 if (!V3dView->View()->Export (argv[1], anExpFormat))
2959 di << "Error: export of image to " << aFormatStr << " failed!\n";
2962 catch (Standard_Failure)
2964 di << "Error: export of image to " << aFormatStr << " failed";
2965 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2970 //==============================================================================
2971 //function : VColorScale
2972 //purpose : representation color scale
2973 //==============================================================================
2974 #include <V3d_ColorScale.hxx>
2976 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2978 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2980 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2984 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2985 if(aContext.IsNull()) {
2986 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2990 Standard_Real minRange = 0. , maxRange = 100. ;
2992 Standard_Integer numIntervals = 10 ;
2993 Standard_Integer textHeight = 16;
2994 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2995 Standard_Real X = 0., Y = 0. ;
3001 minRange = Draw::Atof( argv[1] );
3002 maxRange = Draw::Atof( argv[2] );
3003 numIntervals = Draw::Atoi( argv[3] );
3006 textHeight = Draw::Atoi( argv[4] );
3008 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
3011 X = Draw::Atof( argv[6] );
3012 Y = Draw::Atof( argv[7] );
3015 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3016 if ( curView.IsNull( ) )
3018 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3019 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3020 if( ! aCS.IsNull( ) )
3022 aCS->SetPosition( X , Y );
3023 aCS->SetHeight( 0.95) ;
3024 aCS->SetTextHeight( textHeight );
3025 aCS->SetRange( minRange , maxRange );
3026 aCS->SetNumberOfIntervals( numIntervals );
3027 aCS->SetLabelPosition( position );
3028 if( !curView->ColorScaleIsDisplayed() )
3029 curView->ColorScaleDisplay( );
3034 //==============================================================================
3035 //function : VGraduatedTrihedron
3036 //purpose : Displays a graduated trihedron
3037 //==============================================================================
3039 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3041 const char *str = arg;
3044 unsigned short c1 = *str++;
3045 unsigned short c2 = *str++;
3046 if (!c1 || !c2) break;
3047 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3051 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3054 if (argc != 2 && argc < 5)
3056 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3057 di<<"Usage: type help "<<argv[0]<<"\n";
3058 return 1; //TCL_ERROR
3061 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3063 // Create 3D view if it doesn't exist
3064 if ( aV3dView.IsNull() )
3066 ViewerTest::ViewerInit();
3067 aV3dView = ViewerTest::CurrentView();
3068 if( aV3dView.IsNull() )
3070 di << "Error: Cannot create a 3D view\n";
3071 return 1; //TCL_ERROR
3075 // Erase (==0) or display (!=0)
3076 const int display = Draw::Atoi(argv[1]);
3081 TCollection_AsciiString font;
3083 font.AssignCat("Courier");
3085 font.AssignCat(argv[5]);
3087 // Text is multibyte
3088 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3091 TCollection_ExtendedString xname, yname, zname;
3096 AddMultibyteString(xname, argv[2]);
3097 AddMultibyteString(yname, argv[3]);
3098 AddMultibyteString(zname, argv[4]);
3114 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3115 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3116 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3117 Standard_True/*drawgrid*/,
3118 Standard_True/*drawaxes*/,
3119 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3120 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3121 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3122 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3123 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3124 Quantity_NOC_WHITE/*gridcolor*/,
3125 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3126 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3129 aV3dView->GraduatedTrihedronErase();
3131 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3137 //==============================================================================
3138 //function : VPrintView
3139 //purpose : Test printing algorithm, print the view to image file with given
3140 // width and height. Printing implemented only for WNT.
3141 //==============================================================================
3142 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3146 di << "Printing implemented only for wnt!\n";
3150 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3151 Handle(V3d_View) aView = NULL;
3152 aContextAIS = ViewerTest::GetAISContext();
3153 if (!aContextAIS.IsNull())
3155 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3156 Vwr->InitActiveViews();
3157 if(Vwr->MoreActiveViews())
3158 aView = Vwr->ActiveView();
3164 di << "Call vinit before!\n";
3169 di << "Use: " << argv[0];
3170 di << " width height filename [print algo=0]\n";
3171 di << "width, height of the intermediate buffer for operation\n";
3172 di << "algo : {0|1}\n";
3173 di << " 0 - stretch algorithm\n";
3174 di << " 1 - tile algorithm\n";
3175 di << "test printing algorithms into an intermediate buffer\n";
3176 di << "with saving output to an image file\n";
3180 // get the input params
3181 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3182 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3183 Standard_Integer aMode = 0;
3184 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3186 aMode = Draw::Atoi (argv[4]);
3188 // check the input parameters
3189 if (aWidth <= 0 || aHeight <= 0)
3191 di << "Width and height must be positive values!\n";
3194 if (aMode != 0 && aMode != 1)
3197 // define compatible bitmap
3198 HDC anDC = CreateCompatibleDC(0);
3199 BITMAPINFO aBitmapData;
3200 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3201 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3202 aBitmapData.bmiHeader.biWidth = aWidth ;
3203 aBitmapData.bmiHeader.biHeight = aHeight;
3204 aBitmapData.bmiHeader.biPlanes = 1;
3205 aBitmapData.bmiHeader.biBitCount = 24;
3206 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3207 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3208 aBitmapData.bmiHeader.biClrUsed = 0;
3209 aBitmapData.bmiHeader.biClrImportant = 0;
3210 aBitmapData.bmiHeader.biCompression = BI_RGB;
3211 aBitmapData.bmiHeader.biSizeImage = 0;
3213 // Create Device Independent Bitmap
3214 void* aBitsOut = NULL;
3215 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3216 &aBitsOut, NULL, 0);
3217 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3219 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3220 if (aBitsOut != NULL)
3223 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3225 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3227 // succesfully printed into an intermediate buffer
3230 Image_PixMap aWrapper;
3231 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3232 aWrapper.SetTopDown (false);
3234 Image_AlienPixMap anImageBitmap;
3235 anImageBitmap.InitCopy (aWrapper);
3236 isSaved = anImageBitmap.Save (aFileName);
3240 di << "Print operation failed due to printing errors or\n";
3241 di << "insufficient memory available\n";
3242 di << "Please, try to use smaller dimensions for this test\n";
3243 di << "command, as it allocates intermediate buffer for storing\n";
3244 di << "the result\n";
3249 di << "Can't allocate memory for intermediate buffer\n";
3250 di << "Please use smaller dimensions\n";
3255 SelectObject (anDC, anOldBitmap);
3256 DeleteObject (aMemoryBitmap);
3262 di << "Save to file operation failed. This operation may fail\n";
3263 di << "if you don't have enough available memory, then you can\n";
3264 di << "use smaller dimensions for the output file\n";
3273 //==============================================================================
3274 //function : VZLayer
3275 //purpose : Test z layer operations for v3d viewer
3276 //==============================================================================
3277 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3279 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3280 if (aContextAIS.IsNull())
3282 di << "Call vinit before!\n";
3287 di << "Use: vzlayer " << argv[0];
3288 di << " add/del/get [id]\n";
3289 di << " add - add new z layer to viewer and print its id\n";
3290 di << " del - del z layer by its id\n";
3291 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3292 di << "id - the layer identificator value defined when removing z layer\n";
3296 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3297 if (aViewer.IsNull())
3299 di << "No active viewer!\n";
3303 // perform operation
3304 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3307 Standard_Integer aNewId;
3308 if (!aViewer->AddZLayer (aNewId))
3310 di << "Impossible to add new z layer!\n";
3314 di << "New z layer added with index: " << aNewId << "\n";
3316 else if (anOp == "del")
3320 di << "Please also provide as argument id of z layer to remove\n";
3324 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3325 if (!aViewer->RemoveZLayer (aDelId))
3327 di << "Impossible to remove the z layer or invalid id!\n";
3331 di << "Z layer " << aDelId << " has been removed\n";
3333 else if (anOp == "get")
3335 TColStd_SequenceOfInteger anIds;
3336 aViewer->GetAllZLayers (anIds);
3337 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3339 di << anIds.Value (aSeqIdx) << " ";
3346 di << "Invalid operation, please use { add / del / get }\n";
3353 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3355 // this class provides a presentation of text item in v3d view under-/overlayer
3356 class V3d_TextItem : public Visual3d_LayerItem
3361 DEFINE_STANDARD_RTTI(V3d_TextItem)
3364 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3365 const Standard_Real theX1,
3366 const Standard_Real theY1,
3367 const Standard_Real theHeight,
3368 const TCollection_AsciiString& theFontName,
3369 const Quantity_Color& theColor,
3370 const Quantity_Color& theSubtitleColor,
3371 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3372 const Handle(Visual3d_Layer)& theLayer);
3375 Standard_EXPORT void RedrawLayerPrs();
3381 TCollection_AsciiString myText;
3382 Standard_Real myHeight;
3383 Handle(Visual3d_Layer) myLayer;
3384 Quantity_Color myColor;
3385 Quantity_Color mySubtitleColor;
3386 Aspect_TypeOfDisplayText myType;
3387 TCollection_AsciiString myFontName;
3390 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3391 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3393 // create and add to display the text item
3394 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3395 const Standard_Real theX1,
3396 const Standard_Real theY1,
3397 const Standard_Real theHeight,
3398 const TCollection_AsciiString& theFontName,
3399 const Quantity_Color& theColor,
3400 const Quantity_Color& theSubtitleColor,
3401 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3402 const Handle(Visual3d_Layer)& theLayer)
3403 : myX1 (theX1), myY1 (theY1),
3405 myHeight (theHeight),
3408 mySubtitleColor (theSubtitleColor),
3409 myType (theTypeOfDisplay),
3410 myFontName (theFontName)
3412 if (!myLayer.IsNull ())
3413 myLayer->AddLayerItem (this);
3417 void V3d_TextItem::RedrawLayerPrs ()
3419 if (myLayer.IsNull ())
3422 myLayer->SetColor (myColor);
3423 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3424 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3427 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3429 // The Visual3d_LayerItem line item for "vlayerline" command
3430 // it provides a presentation of line with user-defined
3431 // linewidth, linetype and transparency.
3432 class V3d_LineItem : public Visual3d_LayerItem
3436 DEFINE_STANDARD_RTTI(V3d_LineItem)
3439 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3440 Standard_Real X2, Standard_Real Y2,
3441 V3d_LayerMgrPointer theLayerMgr,
3442 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3443 Standard_Real theWidth = 0.5,
3444 Standard_Real theTransp = 1.0);
3447 Standard_EXPORT void RedrawLayerPrs();
3451 Standard_Real myX1, myY1, myX2, myY2;
3452 V3d_LayerMgrPointer myLayerMgr;
3453 Aspect_TypeOfLine myType;
3454 Standard_Real myWidth;
3455 Standard_Real myTransparency;
3458 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3459 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3461 // default constructor for line item
3462 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3463 Standard_Real X2, Standard_Real Y2,
3464 V3d_LayerMgrPointer theLayerMgr,
3465 Aspect_TypeOfLine theType,
3466 Standard_Real theWidth,
3467 Standard_Real theTransp) :
3468 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3469 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3471 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3472 myLayerMgr->Overlay()->AddLayerItem (this);
3476 void V3d_LineItem::RedrawLayerPrs ()
3478 Handle (Visual3d_Layer) aOverlay;
3481 aOverlay = myLayerMgr->Overlay();
3483 if (!aOverlay.IsNull())
3485 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3486 aOverlay->SetColor(aColor);
3487 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3488 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3489 aOverlay->BeginPolyline();
3490 aOverlay->AddVertex(myX1, myY1);
3491 aOverlay->AddVertex(myX2, myY2);
3492 aOverlay->ClosePrimitive();
3496 //=============================================================================
3497 //function : VLayerLine
3498 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3499 // : linewidth, transparency coefficient
3500 //============================================================================
3501 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3503 // get the active view
3504 Handle(V3d_View) aView = ViewerTest::CurrentView();
3507 di << "Call vinit before!\n";
3512 di << "Use: " << argv[0];
3513 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3514 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3515 di << " 0 - solid \n";
3516 di << " 1 - dashed \n";
3517 di << " 2 - dot \n";
3518 di << " 3 - dashdot\n";
3519 di << " transparency : { 0.0 - 1.0 } \n";
3520 di << " 0.0 - transparent\n";
3521 di << " 1.0 - visible \n";
3525 // get the input params
3526 Standard_Real X1 = Draw::Atof(argv[1]);
3527 Standard_Real Y1 = Draw::Atof(argv[2]);
3528 Standard_Real X2 = Draw::Atof(argv[3]);
3529 Standard_Real Y2 = Draw::Atof(argv[4]);
3531 Standard_Real aWidth = 0.5;
3532 Standard_Integer aType = 0;
3533 Standard_Real aTransparency = 1.0;
3537 aWidth = Draw::Atof(argv[5]);
3541 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3546 aTransparency = Draw::Atof(argv[7]);
3547 if (aTransparency < 0 || aTransparency > 1.0)
3548 aTransparency = 1.0;
3551 // select appropriate line type
3552 Aspect_TypeOfLine aLineType;
3556 aLineType = Aspect_TOL_DASH;
3560 aLineType = Aspect_TOL_DOT;
3564 aLineType = Aspect_TOL_DOTDASH;
3568 aLineType = Aspect_TOL_SOLID;
3571 // replace layer manager
3572 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3573 aView->SetLayerMgr(aMgr);
3576 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3582 aView->MustBeResized();
3588 //=======================================================================
3589 //function : VOverlayText
3590 //purpose : Test text displaying in view overlay
3591 //=======================================================================
3592 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3594 // get the active view
3595 Handle(V3d_View) aView = ViewerTest::CurrentView();
3598 di << "No active view. Please call vinit.\n";
3601 else if (argc < 4 || argc > 13)
3603 di << "Use: " << argv[0];
3604 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3605 di << "[background_color: R G B]\n";
3606 di << " height - pixel height of the text (default=10.0)\n";
3607 di << " font_name - name of font (default=courier)\n";
3608 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3609 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
3610 di << " background_color- R G B values used for subtitle and decal text\n";
3611 di << "(default=255.0 255.0 255.0)\n";
3615 TCollection_AsciiString aText (argv[1]);
3616 Standard_Real aPosX = Draw::Atof(argv[2]);
3617 Standard_Real aPosY = Draw::Atof(argv[3]);
3618 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3621 TCollection_AsciiString aFontName = "Courier";
3623 aFontName = TCollection_AsciiString (argv[5]);
3626 Quantity_Parameter aColorRed = 1.0;
3627 Quantity_Parameter aColorGreen = 1.0;
3628 Quantity_Parameter aColorBlue = 1.0;
3631 aColorRed = Draw::Atof (argv[6])/255.;
3632 aColorGreen = Draw::Atof (argv[7])/255.;
3633 aColorBlue = Draw::Atof (argv[8])/255.;
3637 TCollection_AsciiString aDispStr;
3639 aDispStr = TCollection_AsciiString (argv[9]);
3641 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3642 if (aDispStr.IsEqual ("subtitle"))
3643 aTextType = Aspect_TODT_SUBTITLE;
3644 else if (aDispStr.IsEqual ("decal"))
3645 aTextType = Aspect_TODT_DEKALE;
3646 else if (aDispStr.IsEqual ("blend"))
3647 aTextType = Aspect_TODT_BLEND;
3648 else if (aDispStr.IsEqual ("dimension"))
3649 aTextType = Aspect_TODT_DIMENSION;
3652 Quantity_Parameter aSubRed = 1.0;
3653 Quantity_Parameter aSubGreen = 1.0;
3654 Quantity_Parameter aSubBlue = 1.0;
3657 aSubRed = Draw::Atof (argv[10])/255.;
3658 aSubGreen = Draw::Atof (argv[11])/255.;
3659 aSubBlue = Draw::Atof (argv[12])/255.;
3662 // check fo current overlay
3663 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3664 if (anOverlay.IsNull ())
3666 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3667 anOverlay = aMgr->Overlay ();
3668 aView->SetLayerMgr (aMgr);
3671 Quantity_Color aTextColor (aColorRed, aColorGreen,
3672 aColorBlue, Quantity_TOC_RGB);
3673 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3674 aSubBlue, Quantity_TOC_RGB);
3677 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3678 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3681 aView->MustBeResized();
3687 //==============================================================================
3690 //==============================================================================
3692 static int VGrid (Draw_Interpretor& /*theDI*/,
3693 Standard_Integer theArgNb,
3694 const char** theArgVec)
3696 // get the active view
3697 Handle(V3d_View) aView = ViewerTest::CurrentView();
3698 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3699 if (aView.IsNull() || aViewer.IsNull())
3701 std::cerr << "No active view. Please call vinit.\n";
3705 Aspect_GridType aType = aViewer->GridType();
3706 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3708 Standard_Integer anIter = 1;
3709 for (; anIter < theArgNb; ++anIter)
3711 const char* aValue = theArgVec[anIter];
3714 aType = Aspect_GT_Rectangular;
3716 else if (*aValue == 'c')
3718 aType = Aspect_GT_Circular;
3720 else if (*aValue == 'l')
3722 aMode = Aspect_GDM_Lines;
3724 else if (*aValue == 'p')
3726 aMode = Aspect_GDM_Points;
3728 else if (strcmp (aValue, "off" ) == 0)
3730 aViewer->DeactivateGrid();
3739 Standard_Integer aTail = (theArgNb - anIter);
3742 aViewer->ActivateGrid (aType, aMode);
3745 else if (aTail != 2 && aTail != 5)
3747 std::cerr << "Incorrect arguments number! Usage:\n"
3748 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3752 Quantity_Length anOriginX, anOriginY;
3753 Quantity_PlaneAngle aRotAngle;
3754 if (aType == Aspect_GT_Rectangular)
3756 Quantity_Length aRStepX, aRStepY;
3757 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3759 anOriginX = Draw::Atof (theArgVec[anIter++]);
3760 anOriginY = Draw::Atof (theArgVec[anIter++]);
3763 aRStepX = Draw::Atof (theArgVec[anIter++]);
3764 aRStepY = Draw::Atof (theArgVec[anIter++]);
3765 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3767 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3768 aViewer->ActivateGrid (aType, aMode);
3770 else if (aType == Aspect_GT_Circular)
3772 Quantity_Length aRadiusStep;
3773 Standard_Integer aDivisionNumber;
3774 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3776 anOriginX = Draw::Atof (theArgVec[anIter++]);
3777 anOriginY = Draw::Atof (theArgVec[anIter++]);
3780 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3781 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3782 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3785 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3786 aViewer->ActivateGrid (aType, aMode);
3792 //==============================================================================
3795 //==============================================================================
3797 static int VFps (Draw_Interpretor& theDI,
3798 Standard_Integer theArgNb,
3799 const char** theArgVec)
3801 // get the active view
3802 Handle(V3d_View) aView = ViewerTest::CurrentView();
3805 std::cerr << "No active view. Please call vinit.\n";
3809 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3812 std::cerr << "Incorrect arguments!\n";
3816 // the time is meaningless for first call
3817 // due to async OpenGl rendering
3820 // redraw view in loop to estimate average values
3823 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3829 const Standard_Real aTime = aTimer.ElapsedTime();
3830 aTimer.OSD_Chronometer::Show (aCpu);
3832 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3833 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3835 // return statistics
3836 theDI << "FPS: " << aFpsAver << "\n"
3837 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3842 //==============================================================================
3843 //function : VGlDebug
3845 //==============================================================================
3847 static int VGlDebug (Draw_Interpretor& theDI,
3848 Standard_Integer theArgNb,
3849 const char** theArgVec)
3853 Handle(V3d_View) aView = ViewerTest::CurrentView();
3856 std::cerr << "No active view. Please call vinit.\n";
3860 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3861 "GL_ARB_debug_output");
3862 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3863 theDI << (isActive ? "1" : "0");
3867 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3871 //==============================================================================
3874 //==============================================================================
3876 static int VVbo (Draw_Interpretor& theDI,
3877 Standard_Integer theArgNb,
3878 const char** theArgVec)
3880 const Standard_Boolean toSet = (theArgNb > 1);
3881 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3884 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
3888 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3889 if (aContextAIS.IsNull())
3893 std::cerr << "No active view!\n";
3897 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3898 if (!aDriver.IsNull())
3902 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3906 aDriver->ChangeOptions().vboDisable = toUseVbo;
3913 //==============================================================================
3916 //==============================================================================
3918 static int VCaps (Draw_Interpretor& theDI,
3919 Standard_Integer theArgNb,
3920 const char** theArgVec)
3922 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
3923 Handle(OpenGl_GraphicDriver) aDriver;
3924 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3925 if (!aContextAIS.IsNull())
3927 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3928 aCaps = &aDriver->ChangeOptions();
3933 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
3934 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
3935 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
3939 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3941 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
3942 if (anArg.Search ("vbo=") > -1)
3944 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3946 else if (anArg.Search ("sprites=") > -1)
3948 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3950 else if (anArg.Search ("soft=") > -1)
3952 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
3956 std::cerr << "Unknown argument: " << anArg << "\n";
3959 if (aCaps != &ViewerTest_myDefaultCaps)
3961 ViewerTest_myDefaultCaps = *aCaps;
3966 //==============================================================================
3967 //function : VMemGpu
3969 //==============================================================================
3971 static int VMemGpu (Draw_Interpretor& theDI,
3972 Standard_Integer theArgNb,
3973 const char** theArgVec)
3976 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3977 if (aContextAIS.IsNull())
3979 std::cerr << "No active view. Please call vinit.\n";
3983 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3984 if (aDriver.IsNull())
3986 std::cerr << "Graphic driver not available.\n";
3990 Standard_Size aFreeBytes = 0;
3991 TCollection_AsciiString anInfo;
3992 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3994 std::cerr << "Information not available.\n";
3998 if (theArgNb > 1 && *theArgVec[1] == 'f')
4000 theDI << Standard_Real (aFreeBytes);
4010 // ==============================================================================
4011 // function : VReadPixel
4013 // ==============================================================================
4014 static int VReadPixel (Draw_Interpretor& theDI,
4015 Standard_Integer theArgNb,
4016 const char** theArgVec)
4018 // get the active view
4019 Handle(V3d_View) aView = ViewerTest::CurrentView();
4022 std::cerr << "No active view. Please call vinit.\n";
4025 else if (theArgNb < 3)
4027 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4031 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4032 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4034 Standard_Integer aWidth, aHeight;
4035 aView->Window()->Size (aWidth, aHeight);
4036 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4037 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4038 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4040 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4044 Standard_Boolean toShowName = Standard_False;
4045 Standard_Boolean toShowHls = Standard_False;
4046 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4048 const char* aParam = theArgVec[anIter];
4049 if ( strcasecmp( aParam, "rgb" ) == 0 )
4051 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4052 aBufferType = Graphic3d_BT_RGB;
4054 else if ( strcasecmp( aParam, "hls" ) == 0 )
4056 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4057 aBufferType = Graphic3d_BT_RGB;
4058 toShowHls = Standard_True;
4060 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4062 aFormat = Image_PixMap::ImgRGBF;
4063 aBufferType = Graphic3d_BT_RGB;
4065 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4067 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4068 aBufferType = Graphic3d_BT_RGBA;
4070 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4072 aFormat = Image_PixMap::ImgRGBAF;
4073 aBufferType = Graphic3d_BT_RGBA;
4075 else if ( strcasecmp( aParam, "depth" ) == 0 )
4077 aFormat = Image_PixMap::ImgGrayF;
4078 aBufferType = Graphic3d_BT_Depth;
4080 else if ( strcasecmp( aParam, "name" ) == 0 )
4082 toShowName = Standard_True;
4086 Image_PixMap anImage;
4087 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4089 std::cerr << "Image allocation failed\n";
4092 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4094 std::cerr << "Image dump failed\n";
4098 Quantity_Parameter anAlpha;
4099 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4102 if (aBufferType == Graphic3d_BT_RGBA)
4104 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
4108 theDI << Quantity_Color::StringName (aColor.Name());
4113 switch (aBufferType)
4116 case Graphic3d_BT_RGB:
4120 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
4124 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
4128 case Graphic3d_BT_RGBA:
4130 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
4133 case Graphic3d_BT_Depth:
4135 theDI << aColor.Red();
4144 //==============================================================================
4145 //function : VDiffImage
4146 //purpose : The draw-command compares two images.
4147 //==============================================================================
4149 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4153 theDI << "Not enough arguments.\n";
4158 const char* anImgPathRef = theArgVec[1];
4159 const char* anImgPathNew = theArgVec[2];
4161 // get string tolerance and check its validity
4162 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4163 if (aTolColor < 0.0)
4165 if (aTolColor > 1.0)
4168 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4169 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4171 // image file of difference
4172 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4174 // compare the images
4175 Image_Diff aComparer;
4176 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4181 aComparer.SetColorTolerance (aTolColor);
4182 aComparer.SetBorderFilterOn (isBorderFilterOn);
4183 Standard_Integer aDiffColorsNb = aComparer.Compare();
4184 theDI << aDiffColorsNb << "\n";
4186 // save image of difference
4187 if (aDiffImagePath != NULL)
4189 aComparer.SaveDiffImage (aDiffImagePath);
4195 //=======================================================================
4196 //function : VSelect
4197 //purpose : Emulates different types of selection by mouse:
4198 // 1) single click selection
4199 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4200 // 3) selection with polygon having corners at
4201 // pixel positions (x1,y1),...,(xn,yn)
4202 // 4) any of these selections with shift button pressed
4203 //=======================================================================
4204 static Standard_Integer VSelect (Draw_Interpretor& di,
4205 Standard_Integer argc,
4210 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4214 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4215 if(myAIScontext.IsNull())
4217 di << "use 'vinit' command before " << argv[0] << "\n";
4220 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4221 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4222 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4225 if(isShiftSelection)
4226 aCurrentEventManager->ShiftSelect();
4228 aCurrentEventManager->Select();
4232 if(isShiftSelection)
4233 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4235 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4239 Standard_Integer anUpper = 0;
4241 if(isShiftSelection)
4242 anUpper = (argc-1)/2;
4245 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4247 for(Standard_Integer i=1;i<=anUpper;++i)
4248 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4250 if(isShiftSelection)
4251 aCurrentEventManager->ShiftSelect(aPolyline);
4253 aCurrentEventManager->Select(aPolyline);
4258 //=======================================================================
4259 //function : VMoveTo
4260 //purpose : Emulates cursor movement to defined pixel position
4261 //=======================================================================
4262 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4263 Standard_Integer argc,
4268 di << "Usage : " << argv[0] << " x y" << "\n";
4272 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4273 if(aContext.IsNull())
4275 di << "use 'vinit' command before " << argv[0] << "\n";
4278 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4282 //=======================================================================
4283 //function : VViewParams
4284 //purpose : Gets or sets AIS View characteristics
4285 //=======================================================================
4286 static Standard_Integer VViewParams (Draw_Interpretor& di,
4287 Standard_Integer argc,
4290 if ( argc != 1 && argc != 13)
4292 di << "Usage : " << argv[0] << "\n";
4295 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
4296 if ( anAISView.IsNull () )
4298 di << "use 'vinit' command before " << argv[0] << "\n";
4302 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
4303 Standard_Real anAISViewCenterCoordinateX = 0.0;
4304 Standard_Real anAISViewCenterCoordinateY = 0.0;
4305 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4306 Standard_Real anAISViewProjX = 0.0;
4307 Standard_Real anAISViewProjY = 0.0;
4308 Standard_Real anAISViewProjZ = 0.0;
4309 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4310 Standard_Real anAISViewUpX = 0.0;
4311 Standard_Real anAISViewUpY = 0.0;
4312 Standard_Real anAISViewUpZ = 0.0;
4313 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4314 Standard_Real anAISViewAtX = 0.0;
4315 Standard_Real anAISViewAtY = 0.0;
4316 Standard_Real anAISViewAtZ = 0.0;
4317 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4318 di << "Scale of current view: " << anAISViewScale << "\n";
4319 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
4320 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4321 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4322 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4326 Quantity_Factor anAISViewScale = atof (argv [1]);
4327 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
4328 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
4329 Standard_Real anAISViewProjX = atof (argv [4]);
4330 Standard_Real anAISViewProjY = atof (argv [5]);
4331 Standard_Real anAISViewProjZ = atof (argv [6]);
4332 Standard_Real anAISViewUpX = atof (argv [7]);
4333 Standard_Real anAISViewUpY = atof (argv [8]);
4334 Standard_Real anAISViewUpZ = atof (argv [9]);
4335 Standard_Real anAISViewAtX = atof (argv [10]);
4336 Standard_Real anAISViewAtY = atof (argv [11]);
4337 Standard_Real anAISViewAtZ = atof (argv [12]);
4338 anAISView -> V3d_View::SetScale (anAISViewScale);
4339 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4340 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4341 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4342 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4347 //=======================================================================
4348 //function : VChangeSelected
4349 //purpose : Adds the shape to selection or remove one from it
4350 //=======================================================================
4351 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4352 Standard_Integer argc,
4357 di<<"Usage : " << argv[0] << " shape \n";
4361 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4362 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4363 TCollection_AsciiString aName(argv[1]);
4364 Handle(AIS_InteractiveObject) anAISObject;
4366 if(!aMap.IsBound2(aName))
4368 di<<"Use 'vdisplay' before";
4373 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4374 if(anAISObject.IsNull()){
4375 di<<"No interactive object \n";
4379 if(aContext->HasOpenedContext())
4381 aContext->AddOrRemoveSelected(anAISObject);
4385 aContext->AddOrRemoveCurrentObject(anAISObject);
4391 //=======================================================================
4392 //function : VZClipping
4393 //purpose : Gets or sets ZClipping mode, width and depth
4394 //=======================================================================
4395 static Standard_Integer VZClipping (Draw_Interpretor& di,
4396 Standard_Integer argc,
4401 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4402 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4405 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4406 if(aContext.IsNull())
4408 di << "use 'vinit' command before " << argv[0] << "\n";
4411 Handle(V3d_View) aView = ViewerTest::CurrentView();
4412 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4415 TCollection_AsciiString aZClippingModeString;
4416 Quantity_Length aDepth, aWidth;
4417 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4418 switch (aZClippingMode)
4421 aZClippingModeString.Copy("OFF");
4424 aZClippingModeString.Copy("BACK");
4427 aZClippingModeString.Copy("FRONT");
4430 aZClippingModeString.Copy("SLICE");
4433 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4436 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4437 << "ZClipping depth = " << aDepth << "\n"
4438 << "ZClipping width = " << aWidth << "\n";
4444 Standard_Integer aStatus = 0;
4445 if ( strcmp (argv [1], "OFF") == 0 ) {
4447 aZClippingMode = V3d_OFF;
4449 if ( strcmp (argv [1], "BACK") == 0 ) {
4451 aZClippingMode = V3d_BACK;
4453 if ( strcmp (argv [1], "FRONT") == 0 ) {
4455 aZClippingMode = V3d_FRONT;
4457 if ( strcmp (argv [1], "SLICE") == 0 ) {
4459 aZClippingMode = V3d_SLICE;
4463 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4464 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4467 aView->SetZClippingType(aZClippingMode);
4471 Quantity_Length aDepth = 0., aWidth = 1.;
4474 aDepth = atof(argv[1]);
4475 aWidth = atof(argv[2]);
4479 aDepth = atof(argv[2]);
4480 aWidth = atof(argv[3]);
4483 if(aDepth<0. || aDepth>1.)
4485 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4486 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4489 if(aWidth<0. || aWidth>1.)
4491 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4492 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4496 aView->SetZClippingDepth(aDepth);
4497 aView->SetZClippingWidth(aWidth);
4504 //=======================================================================
4505 //function : VNbSelected
4506 //purpose : Returns number of selected objects
4507 //=======================================================================
4508 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4509 Standard_Integer argc,
4514 di << "Usage : " << argv[0] << "\n";
4517 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4518 if(aContext.IsNull())
4520 di << "use 'vinit' command before " << argv[0] << "\n";
4523 di << aContext->NbSelected() << "\n";
4527 //=======================================================================
4528 //function : VAntialiasing
4529 //purpose : Switches altialiasing on or off
4530 //=======================================================================
4531 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4532 Standard_Integer argc,
4537 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4541 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4542 if(aContext.IsNull())
4544 di << "use 'vinit' command before " << argv[0] << "\n";
4548 Handle(V3d_View) aView = ViewerTest::CurrentView();
4550 if((argc == 2) && (atof(argv[1]) == 0))
4551 aView->SetAntialiasingOff();
4553 aView->SetAntialiasingOn();
4558 //=======================================================================
4559 //function : VPurgeDisplay
4560 //purpose : Switches altialiasing on or off
4561 //=======================================================================
4562 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4563 Standard_Integer argc,
4568 di << "Usage : " << argv[0] << "\n";
4571 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4572 if (aContext.IsNull())
4574 di << "use 'vinit' command before " << argv[0] << "\n";
4577 aContext->CloseAllContexts(Standard_False);
4578 di << aContext->PurgeDisplay() << "\n";
4582 //=======================================================================
4583 //function : VSetViewSize
4585 //=======================================================================
4586 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4587 Standard_Integer argc,
4590 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4591 if(aContext.IsNull())
4593 di << "use 'vinit' command before " << argv[0] << "\n";
4598 di<<"Usage : " << argv[0] << " Size\n";
4601 Standard_Real aSize = atof(argv[1]);
4604 di<<"Bad Size value : " << aSize << "\n";
4608 Handle(V3d_View) aView = ViewerTest::CurrentView();
4609 aView->SetSize(aSize);
4613 //=======================================================================
4614 //function : VMoveView
4616 //=======================================================================
4617 static Standard_Integer VMoveView (Draw_Interpretor& di,
4618 Standard_Integer argc,
4621 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4622 if(aContext.IsNull())
4624 di << "use 'vinit' command before " << argv[0] << "\n";
4627 if(argc < 4 || argc > 5)
4629 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4632 Standard_Real Dx = atof(argv[1]);
4633 Standard_Real Dy = atof(argv[2]);
4634 Standard_Real Dz = atof(argv[3]);
4635 Standard_Boolean aStart = Standard_True;
4638 aStart = (atoi(argv[4]) > 0);
4641 Handle(V3d_View) aView = ViewerTest::CurrentView();
4642 aView->Move(Dx,Dy,Dz,aStart);
4646 //=======================================================================
4647 //function : VTranslateView
4649 //=======================================================================
4650 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4651 Standard_Integer argc,
4654 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4655 if(aContext.IsNull())
4657 di << "use 'vinit' command before " << argv[0] << "\n";
4660 if(argc < 4 || argc > 5)
4662 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4665 Standard_Real Dx = atof(argv[1]);
4666 Standard_Real Dy = atof(argv[2]);
4667 Standard_Real Dz = atof(argv[3]);
4668 Standard_Boolean aStart = Standard_True;
4671 aStart = (atoi(argv[4]) > 0);
4674 Handle(V3d_View) aView = ViewerTest::CurrentView();
4675 aView->Translate(Dx,Dy,Dz,aStart);
4679 //=======================================================================
4680 //function : VTurnView
4682 //=======================================================================
4683 static Standard_Integer VTurnView (Draw_Interpretor& di,
4684 Standard_Integer argc,
4687 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4688 if(aContext.IsNull()) {
4689 di << "use 'vinit' command before " << argv[0] << "\n";
4692 if(argc < 4 || argc > 5){
4693 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4696 Standard_Real Ax = atof(argv[1]);
4697 Standard_Real Ay = atof(argv[2]);
4698 Standard_Real Az = atof(argv[3]);
4699 Standard_Boolean aStart = Standard_True;
4702 aStart = (atoi(argv[4]) > 0);
4705 Handle(V3d_View) aView = ViewerTest::CurrentView();
4706 aView->Turn(Ax,Ay,Az,aStart);
4710 //==============================================================================
4711 //function : VTextureEnv
4712 //purpose : ENables or disables environment mapping
4713 //==============================================================================
4714 class OCC_TextureEnv : public Graphic3d_TextureEnv
4717 OCC_TextureEnv(const Standard_CString FileName);
4718 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4719 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4720 const Standard_Boolean theModulateFlag,
4721 const Graphic3d_TypeOfTextureFilter theFilter,
4722 const Standard_ShortReal theXScale,
4723 const Standard_ShortReal theYScale,
4724 const Standard_ShortReal theXShift,
4725 const Standard_ShortReal theYShift,
4726 const Standard_ShortReal theAngle);
4727 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4729 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4730 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4731 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4733 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4734 : Graphic3d_TextureEnv(theFileName)
4738 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4739 : Graphic3d_TextureEnv(theTexId)
4743 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4744 const Standard_Boolean theModulateFlag,
4745 const Graphic3d_TypeOfTextureFilter theFilter,
4746 const Standard_ShortReal theXScale,
4747 const Standard_ShortReal theYScale,
4748 const Standard_ShortReal theXShift,
4749 const Standard_ShortReal theYShift,
4750 const Standard_ShortReal theAngle)
4752 myParams->SetRepeat (theRepeatFlag);
4753 myParams->SetModulate (theModulateFlag);
4754 myParams->SetFilter (theFilter);
4755 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
4756 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4757 myParams->SetRotation (theAngle);
4760 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4762 // get the active view
4763 Handle(V3d_View) aView = ViewerTest::CurrentView();
4766 std::cerr << "No active view. Please call vinit.\n";
4770 // Checking the input arguments
4771 Standard_Boolean anEnableFlag = Standard_False;
4772 Standard_Boolean isOk = theArgNb >= 2;
4775 TCollection_AsciiString anEnableOpt(theArgVec[1]);
4776 anEnableFlag = anEnableOpt.IsEqual("on");
4777 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
4781 isOk = (theArgNb == 3 || theArgNb == 11);
4784 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4785 isOk = (!aTextureOpt.IsIntegerValue() ||
4786 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
4788 if (isOk && theArgNb == 11)
4790 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
4791 aModulateOpt(theArgVec[4]),
4792 aFilterOpt (theArgVec[5]),
4793 aSScaleOpt (theArgVec[6]),
4794 aTScaleOpt (theArgVec[7]),
4795 aSTransOpt (theArgVec[8]),
4796 aTTransOpt (theArgVec[9]),
4797 anAngleOpt (theArgVec[10]);
4798 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
4799 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
4800 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
4801 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
4802 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
4803 anAngleOpt.IsRealValue());
4810 std::cerr << "Usage :" << std::endl;
4811 std::cerr << theArgVec[0] << " off" << std::endl;
4812 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;
4818 TCollection_AsciiString aTextureOpt(theArgVec[2]);
4819 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
4820 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
4821 new OCC_TextureEnv(theArgVec[2]);
4825 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
4826 aTexEnv->SetTextureParameters(
4827 aRepeatOpt. IsEqual("repeat"),
4828 aModulateOpt.IsEqual("modulate"),
4829 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
4830 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
4831 Graphic3d_TOTF_TRILINEAR,
4832 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
4833 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
4834 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
4835 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
4836 (Standard_ShortReal)Draw::Atof(theArgVec[10])
4839 aView->SetTextureEnv(aTexEnv);
4840 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
4842 else // Disabling environment mapping
4844 aView->SetSurfaceDetail(V3d_TEX_NONE);
4845 Handle(Graphic3d_TextureEnv) aTexture;
4846 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
4853 //===============================================================================================
4854 //function : VClipPlane
4856 //===============================================================================================
4857 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4859 // use short-cut for created clip planes map of created (or "registered by name") clip planes
4860 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
4861 static MapOfPlanes aRegPlanes;
4865 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
4869 TCollection_AsciiString aCommand (theArgVec[1]);
4871 // print maximum number of planes for current viewer
4872 if (aCommand == "maxplanes")
4876 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
4880 TCollection_AsciiString aViewName (theArgVec[2]);
4882 if (!ViewerTest_myViews.IsBound1 (aViewName))
4884 theDi << theArgVec[0] << ": view is not found.\n";
4888 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
4890 theDi << theArgVec[0] << ": "
4891 << aView->Viewer()->Driver()->InquirePlaneLimit()
4892 << " plane slots provided by driver."
4893 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
4898 // create / delete plane instance
4899 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
4903 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
4907 Standard_Boolean toCreate = (aCommand == "create");
4908 Standard_Boolean toClone = (aCommand == "clone");
4909 TCollection_AsciiString aPlane (theArgVec[2]);
4913 if (aRegPlanes.IsBound (aPlane))
4915 theDi << theArgVec[0] << ": plane name is in use.\n";
4919 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
4921 else if (toClone) // toClone
4923 if (!aRegPlanes.IsBound (aPlane))
4925 theDi << theArgVec[0] << ": no such plane.\n";
4931 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
4935 TCollection_AsciiString aClone (theArgVec[3]);
4936 if (aRegPlanes.IsBound (aClone))
4938 theDi << theArgVec[0] << ": plane name is in use.\n";
4942 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4944 aRegPlanes.Bind (aClone, aClipPlane->Clone());
4948 if (!aRegPlanes.IsBound (aPlane))
4950 theDi << theArgVec[0] << ": no such plane.\n";
4954 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
4955 aRegPlanes.UnBind (aPlane);
4957 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
4958 for (; anIObjIt.More(); anIObjIt.Next())
4960 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
4961 aPrs->RemoveClipPlane(aClipPlane);
4964 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
4965 for (; aViewIt.More(); aViewIt.Next())
4967 const Handle(V3d_View)& aView = aViewIt.Key2();
4968 aView->RemoveClipPlane(aClipPlane);
4971 ViewerTest::RedrawAllViews();
4977 // set / unset plane command
4978 if (aCommand == "set" || aCommand == "unset")
4982 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
4986 Standard_Boolean toSet = (aCommand == "set");
4987 TCollection_AsciiString aPlane (theArgVec [2]);
4988 if (!aRegPlanes.IsBound (aPlane))
4990 theDi << theArgVec[0] << ": no such plane.\n";
4994 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4996 TCollection_AsciiString aTarget (theArgVec [3]);
4997 if (aTarget != "object" && aTarget != "view")
4999 theDi << theArgVec[0] << ": invalid target.\n";
5003 if (aTarget == "object" || aTarget == "view")
5007 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5011 Standard_Boolean isObject = (aTarget == "object");
5013 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
5015 TCollection_AsciiString anEntityName (theArgVec[anIt]);
5016 if (isObject) // to object
5018 if (!GetMapOfAIS().IsBound2 (anEntityName))
5020 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
5024 Handle(AIS_InteractiveObject) aIObj =
5025 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
5028 aIObj->AddClipPlane (aClipPlane);
5030 aIObj->RemoveClipPlane (aClipPlane);
5034 if (!ViewerTest_myViews.IsBound1 (anEntityName))
5036 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
5040 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
5042 aView->AddClipPlane (aClipPlane);
5044 aView->RemoveClipPlane (aClipPlane);
5048 ViewerTest::RedrawAllViews();
5054 // change plane command
5055 if (aCommand == "change")
5059 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5063 TCollection_AsciiString aPlane (theArgVec [2]);
5064 if (!aRegPlanes.IsBound (aPlane))
5066 theDi << theArgVec[0] << ": no such plane.\n";
5070 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5072 TCollection_AsciiString aChangeArg (theArgVec [3]);
5073 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5075 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5079 if (aChangeArg == "on" || aChangeArg == "off") // on / off
5081 aClipPlane->SetOn (aChangeArg == "on");
5083 else if (aChangeArg == "equation") // change equation
5087 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5091 Standard_Real aCoeffA = atof (theArgVec [4]);
5092 Standard_Real aCoeffB = atof (theArgVec [5]);
5093 Standard_Real aCoeffC = atof (theArgVec [6]);
5094 Standard_Real aCoeffD = atof (theArgVec [7]);
5095 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5097 else if (aChangeArg == "capping") // change capping aspects
5101 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5105 TCollection_AsciiString aCappingArg (theArgVec [4]);
5106 if (aCappingArg != "on" && aCappingArg != "off" &&
5107 aCappingArg != "color" && aCappingArg != "texname" &&
5108 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5109 aCappingArg != "texrotate" && aCappingArg != "hatch")
5111 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5115 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5117 aClipPlane->SetCapping (aCappingArg == "on");
5119 else if (aCappingArg == "color") // color aspect for capping
5123 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5127 Standard_Real aRed = atof (theArgVec [5]);
5128 Standard_Real aGrn = atof (theArgVec [6]);
5129 Standard_Real aBlu = atof (theArgVec [7]);
5131 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5132 aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
5133 aClipPlane->SetCappingMaterial (aMat);
5135 else if (aCappingArg == "texname") // texture name
5139 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5143 TCollection_AsciiString aTextureName (theArgVec [5]);
5145 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5146 if (!aTexture->IsDone ())
5148 aClipPlane->SetCappingTexture (NULL);
5152 aTexture->EnableModulate();
5153 aTexture->EnableRepeat();
5154 aClipPlane->SetCappingTexture (aTexture);
5157 else if (aCappingArg == "texscale") // texture scale
5159 if (aClipPlane->CappingTexture().IsNull())
5161 theDi << theArgVec[0] << ": no texture is set.\n";
5167 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5171 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5172 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5174 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5176 else if (aCappingArg == "texorigin") // texture origin
5178 if (aClipPlane->CappingTexture().IsNull())
5180 theDi << theArgVec[0] << ": no texture is set.\n";
5186 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5190 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5191 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5193 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5195 else if (aCappingArg == "texrotate") // texture rotation
5197 if (aClipPlane->CappingTexture().IsNull())
5199 theDi << theArgVec[0] << ": no texture is set.\n";
5205 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5209 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5211 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5213 else if (aCappingArg == "hatch") // hatch style
5217 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5221 TCollection_AsciiString aHatchStr (theArgVec [5]);
5222 if (aHatchStr == "on")
5224 aClipPlane->SetCappingHatchOn();
5226 else if (aHatchStr == "off")
5228 aClipPlane->SetCappingHatchOff();
5232 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5237 ViewerTest::RedrawAllViews();
5242 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5246 //===============================================================================================
5247 //function : VSetTextureMode
5249 //===============================================================================================
5250 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5254 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5258 TCollection_AsciiString aViewName (theArgVec[1]);
5259 if (!ViewerTest_myViews.IsBound1 (aViewName))
5261 theDi << theArgVec[0] << ": view is not found.\n";
5265 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5266 switch (atoi (theArgVec[2]))
5268 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5269 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5270 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5272 theDi << theArgVec[0] << ": invalid mode.\n";
5280 //===============================================================================================
5281 //function : VDefaults
5283 //===============================================================================================
5284 static int VDefaults (Draw_Interpretor& theDi,
5285 Standard_Integer theArgsNb,
5286 const char** theArgVec)
5288 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5291 std::cerr << "No active viewer!\n";
5295 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
5298 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
5300 theDi << "DeflType: relative\n"
5301 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
5305 theDi << "DeflType: absolute\n"
5306 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
5308 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
5312 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5314 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5315 TCollection_AsciiString aKey, aValue;
5316 if (!ViewerTest::SplitParameter (anArg, aKey, aValue)
5317 || aValue.IsEmpty())
5319 std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
5324 if (aKey == "ABSDEFL"
5325 || aKey == "ABSOLUTEDEFLECTION"
5327 || aKey == "DEFLECTION")
5329 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
5330 aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
5332 else if (aKey == "RELDEFL"
5333 || aKey == "RELATIVEDEFLECTION"
5334 || aKey == "DEVCOEFF"
5335 || aKey == "DEVIATIONCOEFF"
5336 || aKey == "DEVIATIONCOEFFICIENT")
5338 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
5339 aDefParams->SetDeviationCoefficient (aValue.RealValue());
5341 else if (aKey == "ANGDEFL"
5342 || aKey == "ANGULARDEFL"
5343 || aKey == "ANGULARDEFLECTION")
5345 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
5346 aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
5350 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
5357 //! Auxiliary method
5358 inline void addLight (const Handle(V3d_Light)& theLightNew,
5359 const Standard_Boolean theIsGlobal)
5361 if (theLightNew.IsNull())
5368 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
5372 ViewerTest::CurrentView()->SetLightOn (theLightNew);
5376 //! Auxiliary method
5377 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
5379 TCollection_AsciiString anArgNextCase (theArgNext);
5380 anArgNextCase.UpperCase();
5381 if (anArgNextCase.Length() > 5
5382 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
5384 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
5388 return theArgNext.IntegerValue();
5392 //===============================================================================================
5395 //===============================================================================================
5396 static int VLight (Draw_Interpretor& theDi,
5397 Standard_Integer theArgsNb,
5398 const char** theArgVec)
5400 Handle(V3d_View) aView = ViewerTest::CurrentView();
5401 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5403 || aViewer.IsNull())
5405 std::cerr << "No active viewer!\n";
5409 Standard_Real anXYZ[3];
5410 Quantity_Coefficient anAtten[2];
5413 // print lights info
5414 Standard_Integer aLightId = 0;
5415 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
5417 Handle(V3d_Light) aLight = aView->ActiveLight();
5418 const Quantity_Color aColor = aLight->Color();
5419 theDi << "Light" << aLightId << "\n";
5420 switch (aLight->Type())
5424 theDi << " Type: Ambient\n";
5427 case V3d_DIRECTIONAL:
5429 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
5430 theDi << " Type: Directional\n";
5431 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5432 if (!aLightDir.IsNull())
5434 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5435 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5436 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
5437 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5441 case V3d_POSITIONAL:
5443 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
5444 theDi << " Type: Positional\n";
5445 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5446 if (!aLightPos.IsNull())
5448 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5449 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5450 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5451 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
5457 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
5458 theDi << " Type: Spot\n";
5459 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5460 if (!aLightSpot.IsNull())
5462 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5463 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5464 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
5465 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5466 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5467 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
5468 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
5469 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
5475 theDi << " Type: UNKNOWN\n";
5479 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
5483 Handle(V3d_Light) aLightNew;
5484 Handle(V3d_Light) aLightOld;
5485 Standard_Boolean isGlobal = Standard_True;
5486 Standard_Boolean toCreate = Standard_False;
5487 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5489 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
5490 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
5491 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
5492 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
5493 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
5495 TCollection_AsciiString aName, aValue;
5496 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
5497 TCollection_AsciiString anArgCase (anArg);
5498 anArgCase.UpperCase();
5499 if (anArgCase.IsEqual ("NEW")
5500 || anArgCase.IsEqual ("ADD")
5501 || anArgCase.IsEqual ("CREATE"))
5503 toCreate = Standard_True;
5505 else if (anArgCase.IsEqual ("GLOB")
5506 || anArgCase.IsEqual ("GLOBAL"))
5508 isGlobal = Standard_True;
5510 else if (anArgCase.IsEqual ("LOC")
5511 || anArgCase.IsEqual ("LOCAL"))
5513 isGlobal = Standard_False;
5515 else if (anArgCase.IsEqual ("DEF")
5516 || anArgCase.IsEqual ("DEFAULTS"))
5518 toCreate = Standard_False;
5519 aViewer->SetDefaultLights();
5521 else if (anArgCase.IsEqual ("CLR")
5522 || anArgCase.IsEqual ("CLEAR"))
5524 toCreate = Standard_False;
5525 aView->InitActiveLights();
5526 while (aView->MoreActiveLights())
5528 aViewer->DelLight (aView->ActiveLight());
5529 aView->InitActiveLights();
5532 else if (anArgCase.IsEqual ("AMB")
5533 || anArgCase.IsEqual ("AMBIENT")
5534 || anArgCase.IsEqual ("AMBLIGHT"))
5536 addLight (aLightNew, isGlobal);
5539 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5542 toCreate = Standard_False;
5543 aLightNew = new V3d_AmbientLight (aViewer);
5545 else if (anArgCase.IsEqual ("DIRECTIONAL")
5546 || anArgCase.IsEqual ("DIRLIGHT"))
5548 addLight (aLightNew, isGlobal);
5551 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5554 toCreate = Standard_False;
5555 aLightNew = new V3d_DirectionalLight (aViewer);
5557 else if (anArgCase.IsEqual ("SPOT")
5558 || anArgCase.IsEqual ("SPOTLIGHT"))
5560 addLight (aLightNew, isGlobal);
5563 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5566 toCreate = Standard_False;
5567 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
5569 else if (anArgCase.IsEqual ("POSLIGHT")
5570 || anArgCase.IsEqual ("POSITIONAL"))
5572 addLight (aLightNew, isGlobal);
5575 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5578 toCreate = Standard_False;
5579 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
5581 else if (anArgCase.IsEqual ("CHANGE"))
5583 addLight (aLightNew, isGlobal);
5584 aLightNew.Nullify();
5585 if (++anArgIt >= theArgsNb)
5587 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5591 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
5592 Standard_Integer aLightIt = 0;
5593 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
5595 if (aLightIt == aLightId)
5597 aLightOld = aView->ActiveLight();
5602 if (aLightOld.IsNull())
5604 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
5608 else if (anArgCase.IsEqual ("DEL")
5609 || anArgCase.IsEqual ("DELETE"))
5611 Handle(V3d_Light) aLightDel;
5612 if (++anArgIt >= theArgsNb)
5614 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5618 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
5619 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
5620 Standard_Integer aLightIt = 0;
5621 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
5623 aLightDel = aView->ActiveLight();
5624 if (aLightIt == aLightDelId)
5629 if (!aLightDel.IsNull())
5631 aViewer->DelLight (aLightDel);
5634 else if (anArgCase.IsEqual ("COLOR")
5635 || anArgCase.IsEqual ("COLOUR"))
5637 if (++anArgIt >= theArgsNb)
5639 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5643 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
5644 anArgNext.UpperCase();
5645 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
5646 if (!aLightCurr.IsNull())
5648 aLightCurr->SetColor (aColor);
5651 else if (anArgCase.IsEqual ("POS")
5652 || anArgCase.IsEqual ("POSITION"))
5654 if ((anArgIt + 3) >= theArgsNb)
5656 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5660 anXYZ[0] = Atof (theArgVec[++anArgIt]);
5661 anXYZ[1] = Atof (theArgVec[++anArgIt]);
5662 anXYZ[2] = Atof (theArgVec[++anArgIt]);
5663 if (!aLightDir.IsNull())
5665 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
5667 else if (!aLightPos.IsNull())
5669 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
5671 else if (!aLightSpot.IsNull())
5673 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
5677 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5681 else if (anArgCase.IsEqual ("DIR")
5682 || anArgCase.IsEqual ("DIRECTION"))
5684 if ((anArgIt + 3) >= theArgsNb)
5686 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5690 anXYZ[0] = Atof (theArgVec[++anArgIt]);
5691 anXYZ[1] = Atof (theArgVec[++anArgIt]);
5692 anXYZ[2] = Atof (theArgVec[++anArgIt]);
5693 if (!aLightDir.IsNull())
5695 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
5697 else if (!aLightSpot.IsNull())
5699 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
5703 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5707 else if (anArgCase.IsEqual ("ANG")
5708 || anArgCase.IsEqual ("ANGLE"))
5710 if (++anArgIt >= theArgsNb)
5712 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5716 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
5718 if (!aLightSpot.IsNull())
5720 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
5723 else if (anArgCase.IsEqual ("CONSTATTEN")
5724 || anArgCase.IsEqual ("CONSTATTENUATION"))
5726 if (++anArgIt >= theArgsNb)
5728 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5732 if (!aLightPos.IsNull())
5734 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5735 anAtten[0] = Atof (theArgVec[anArgIt]);
5736 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
5738 else if (!aLightSpot.IsNull())
5740 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5741 anAtten[0] = Atof (theArgVec[anArgIt]);
5742 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
5746 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5750 else if (anArgCase.IsEqual ("LINATTEN")
5751 || anArgCase.IsEqual ("LINEARATTEN")
5752 || anArgCase.IsEqual ("LINEARATTENUATION"))
5754 if (++anArgIt >= theArgsNb)
5756 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5760 if (!aLightPos.IsNull())
5762 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5763 anAtten[1] = Atof (theArgVec[anArgIt]);
5764 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
5766 else if (!aLightSpot.IsNull())
5768 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5769 anAtten[1] = Atof (theArgVec[anArgIt]);
5770 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
5774 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5778 else if (anArgCase.IsEqual ("EXP")
5779 || anArgCase.IsEqual ("EXPONENT")
5780 || anArgCase.IsEqual ("SPOTEXP")
5781 || anArgCase.IsEqual ("SPOTEXPONENT"))
5783 if (++anArgIt >= theArgsNb)
5785 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5789 if (!aLightSpot.IsNull())
5791 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
5795 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5799 else if (anArgCase.IsEqual ("HEAD")
5800 || anArgCase.IsEqual ("HEADLIGHT"))
5802 if (++anArgIt >= theArgsNb)
5804 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5808 if (aLightAmb.IsNull()
5809 && !aLightCurr.IsNull())
5811 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
5815 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
5821 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
5825 addLight (aLightNew, isGlobal);
5826 aViewer->UpdateLights();
5833 //==============================================================================
5834 //function : VClInfo
5835 //purpose : Prints info about active OpenCL device
5836 //==============================================================================
5838 static Standard_Integer VClInfo (Draw_Interpretor& theDi,
5842 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5843 if (aContextAIS.IsNull())
5845 std::cerr << "Call vinit before!\n";
5849 Handle(OpenGl_GraphicDriver) aDrv = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5850 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
5851 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> anInfo;
5854 || !aDrv->GetOpenClDeviceInfo (*aCView, anInfo))
5856 theDi << "OpenCL device info is unavailable!\n";
5860 theDi << "OpenCL device info:\n";
5861 for (NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator anIter (anInfo);
5862 anIter.More(); anIter.Next())
5864 theDi << anIter.Key() << ": \t" << anIter.Value() << "\n";
5869 //=======================================================================
5870 //function : VRaytrace
5871 //purpose : Enables/disables OpenCL-based ray-tracing
5872 //=======================================================================
5874 static Standard_Integer VRaytrace (Draw_Interpretor& ,
5875 Standard_Integer theArgNb,
5876 const char** theArgVec)
5878 Handle(V3d_View) aView = ViewerTest::CurrentView();
5881 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
5886 || Draw::Atoi (theArgVec[1]))
5888 aView->SetRaytracingMode();
5892 aView->SetRasterizationMode();
5898 //=======================================================================
5899 //function : VSetRaytraceMode
5900 //purpose : Enables/disables features of OpenCL-based ray-tracing
5901 //=======================================================================
5903 static Standard_Integer VSetRaytraceMode (Draw_Interpretor&,
5904 Standard_Integer theArgNb,
5905 const char ** theArgVec)
5907 Handle(V3d_View) aView = ViewerTest::CurrentView();
5910 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
5913 else if (theArgNb < 2)
5915 std::cerr << "Usage : " << theArgVec[0] << " [shad=0|1] [refl=0|1] [aa=0|1]\n";
5919 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5921 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5923 if (anArg.Search ("shad=") > -1)
5925 if (anArg.Token ("=", 2).IntegerValue() != 0)
5926 aView->EnableRaytracedShadows();
5928 aView->DisableRaytracedShadows();
5930 else if (anArg.Search ("refl=") > -1)
5932 if (anArg.Token ("=", 2).IntegerValue() != 0)
5933 aView->EnableRaytracedReflections();
5935 aView->DisableRaytracedReflections();
5937 else if (anArg.Search ("aa=") > -1)
5939 if (anArg.Token ("=", 2).IntegerValue() != 0)
5940 aView->EnableRaytracedAntialiasing();
5942 aView->DisableRaytracedAntialiasing();
5946 std::cerr << "Unknown argument: " << anArg << "\n";
5954 //=======================================================================
5955 //function : ViewerCommands
5957 //=======================================================================
5959 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
5962 const char *group = "ZeViewer";
5963 theCommands.Add("vinit",
5964 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5965 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5967 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5969 " - Creates new View window with specified name view_name.\n"
5970 "By default the new view is created in the viewer and in"
5971 " graphic driver shared with active view.\n"
5972 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
5973 "If driverName isn't specified the driver will be shared with active view.\n"
5974 "If viewerName isn't specified the viewer will be shared with active view.\n"
5975 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5976 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
5977 "is used in creation of graphic driver\n"
5979 " - l, t: pixel position of left top corner of the window\n"
5980 " - w,h: width and heigth of window respectively.\n"
5981 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
5982 __FILE__,VInit,group);
5983 theCommands.Add("vclose" ,
5984 "[view_id [keep_context=0|1]]\n"
5985 "or vclose ALL - to remove all created views\n"
5986 " - removes view(viewer window) defined by its view_id.\n"
5987 " - keep_context: by default 0; if 1 and the last view is deleted"
5988 " the current context is not removed.",
5989 __FILE__,VClose,group);
5990 theCommands.Add("vactivate" ,
5992 " - activates view(viewer window) defined by its view_id",
5993 __FILE__,VActivate,group);
5994 theCommands.Add("vviewlist",
5995 "vviewlist [format={tree, long}]"
5996 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
5997 " - format: format of result output, if tree the output is a tree view;"
5998 "otherwise it's a list of full view names. By default format = tree",
5999 __FILE__,VViewList,group);
6000 theCommands.Add("vhelp" ,
6001 "vhelp : display help on the viewer commands",
6002 __FILE__,VHelp,group);
6003 theCommands.Add("vtop" ,
6004 "vtop or <T> : Top view" ,
6005 __FILE__,VTop,group);
6006 theCommands.Add("vbottom" ,
6007 "vbottom : Bottom view" ,
6008 __FILE__,VBottom,group);
6009 theCommands.Add("vleft" ,
6010 "vleft : Left view" ,
6011 __FILE__,VLeft,group);
6012 theCommands.Add("vright" ,
6013 "vright : Right view" ,
6014 __FILE__,VRight,group);
6015 theCommands.Add("vaxo" ,
6016 " vaxo or <A> : Axonometric view ",
6017 __FILE__,VAxo,group);
6018 theCommands.Add("vfront" ,
6019 "vfront : Front view" ,
6020 __FILE__,VFront,group);
6021 theCommands.Add("vback" ,
6022 "vback : Back view" ,
6023 __FILE__,VBack,group);
6024 theCommands.Add("vpick" ,
6025 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
6027 theCommands.Add("vfit" ,
6028 "vfit or <F> : vfit",
6029 __FILE__,VFit,group);
6030 theCommands.Add("vzfit" ,
6032 __FILE__,VZFit,group);
6033 theCommands.Add("vrepaint",
6034 "vrepaint : vrepaint, force redraw",
6035 __FILE__,VRepaint,group);
6036 theCommands.Add("vclear",
6038 __FILE__,VClear,group);
6039 theCommands.Add("vsetbg",
6040 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
6041 __FILE__,VSetBg,group);
6042 theCommands.Add("vsetbgmode",
6043 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
6044 __FILE__,VSetBgMode,group);
6045 theCommands.Add("vsetgradientbg",
6046 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
6047 __FILE__,VSetGradientBg,group);
6048 theCommands.Add("vsetgrbgmode",
6049 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
6050 __FILE__,VSetGradientBgMode,group);
6051 theCommands.Add("vsetcolorbg",
6052 "vsetcolorbg : vsetcolorbg r g b : Set background color",
6053 __FILE__,VSetColorBg,group);
6054 theCommands.Add("vscale",
6055 "vscale : vscale X Y Z",
6056 __FILE__,VScale,group);
6057 theCommands.Add("vzbufftrihedron",
6058 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
6059 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
6060 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
6061 __FILE__,VTestZBuffTrihedron,group);
6062 theCommands.Add("vrotate",
6063 "vrotate : vrotate AX AY AZ [X Y Z]",
6064 __FILE__,VRotate,group);
6065 theCommands.Add("vzoom",
6066 "vzoom : vzoom coef",
6067 __FILE__,VZoom,group);
6068 theCommands.Add("vpan",
6069 "vpan : vpan dx dy",
6070 __FILE__,VPan,group);
6071 theCommands.Add("vexport",
6072 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
6073 " : exports the view to a vector file of a given format"
6074 " : notice that EMF format requires patched gl2ps",
6075 __FILE__,VExport,group);
6076 theCommands.Add("vcolorscale",
6077 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
6078 __FILE__,VColorScale,group);
6079 theCommands.Add("vgraduatedtrihedron",
6080 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
6081 __FILE__,VGraduatedTrihedron,group);
6082 theCommands.Add("vprintview" ,
6083 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
6084 __FILE__,VPrintView,group);
6085 theCommands.Add("vzlayer",
6086 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
6087 __FILE__,VZLayer,group);
6088 theCommands.Add("voverlaytext",
6089 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
6090 " : height - pixel height of the text (default=10.0)"
6091 " : font_name - name of font (default=courier)"
6092 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
6093 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
6094 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
6095 __FILE__,VOverlayText,group);
6096 theCommands.Add("vlayerline",
6097 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
6098 __FILE__,VLayerLine,group);
6099 theCommands.Add ("vgrid",
6100 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
6101 " : Mode - rectangular or circular"
6102 " : Type - lines or points",
6103 __FILE__, VGrid, group);
6104 theCommands.Add ("vfps",
6105 "vfps [framesNb=100] : estimate average frame rate for active view",
6106 __FILE__, VFps, group);
6107 theCommands.Add ("vgldebug",
6108 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
6109 " : this function is implemented only for Windows\n"
6110 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
6111 __FILE__, VGlDebug, group);
6112 theCommands.Add ("vvbo",
6113 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
6114 __FILE__, VVbo, group);
6115 theCommands.Add ("vcaps",
6116 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
6117 __FILE__, VCaps, group);
6118 theCommands.Add ("vmemgpu",
6119 "vmemgpu [f]: print system-dependent GPU memory information if available;"
6120 " with f option returns free memory in bytes",
6121 __FILE__, VMemGpu, group);
6122 theCommands.Add ("vreadpixel",
6123 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
6124 " : Read pixel value for active view",
6125 __FILE__, VReadPixel, group);
6126 theCommands.Add("diffimage",
6127 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
6128 __FILE__, VDiffImage, group);
6129 theCommands.Add ("vselect",
6130 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
6131 "- emulates different types of selection:\n"
6132 "- 1) single click selection\n"
6133 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
6134 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
6135 "- 4) any of these selections with shift button pressed",
6136 __FILE__, VSelect, group);
6137 theCommands.Add ("vmoveto",
6139 "- emulates cursor movement to pixel postion (x,y)",
6140 __FILE__, VMoveTo, group);
6141 theCommands.Add("vviewparams",
6142 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
6143 "- gets or sets current view characteristics",
6144 __FILE__,VViewParams, group);
6145 theCommands.Add("vchangeselected",
6146 "vchangeselected shape"
6147 "- adds to shape to selection or remove one from it",
6148 __FILE__, VChangeSelected, group);
6149 theCommands.Add("vzclipping",
6150 "vzclipping [mode] [depth width]\n"
6151 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
6152 "- gets or sets ZClipping mode, width and depth",
6153 __FILE__,VZClipping,group);
6154 theCommands.Add ("vnbselected",
6155 "vnbselected", __FILE__, VNbSelected, group);
6156 theCommands.Add("vantialiasing",
6157 "vantialiasing 1|0",
6158 __FILE__,VAntialiasing,group);
6159 theCommands.Add ("vpurgedisplay",
6161 "- removes structures which don't belong to objects displayed in neutral point",
6162 __FILE__, VPurgeDisplay, group);
6163 theCommands.Add("vsetviewsize",
6164 "vsetviewsize size",
6165 __FILE__,VSetViewSize,group);
6166 theCommands.Add("vmoveview",
6167 "vmoveview Dx Dy Dz [Start = 1|0]",
6168 __FILE__,VMoveView,group);
6169 theCommands.Add("vtranslateview",
6170 "vtranslateview Dx Dy Dz [Start = 1|0)]",
6171 __FILE__,VTranslateView,group);
6172 theCommands.Add("vturnview",
6173 "vturnview Ax Ay Az [Start = 1|0]",
6174 __FILE__,VTurnView,group);
6175 theCommands.Add("vtextureenv",
6176 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
6177 "or user-defined file and optionally applying texture mapping parameters\n"
6179 " vtextureenv off - disables environment mapping\n"
6180 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
6181 " std_texture = (0..7)\n"
6182 " rep = {clamp|repeat}\n"
6183 " mod = {decal|modulate}\n"
6184 " flt = {nearest|bilinear|trilinear}\n"
6185 " ss, st - scale factors for s and t texture coordinates\n"
6186 " ts, tt - translation for s and t texture coordinates\n"
6187 " rot - texture rotation angle in degrees",
6188 __FILE__, VTextureEnv, group);
6189 theCommands.Add("vhlr" ,
6190 "is_enabled={on|off}"
6191 " - Hidden line removal algorithm:"
6192 " - is_enabled: if is on HLR algorithm is applied\n",
6193 __FILE__,VHLR,group);
6194 theCommands.Add("vhlrtype" ,
6195 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
6196 " - Changes the type of HLR algorithm using for shapes."
6197 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
6198 " if equals to polyalgo, polygonal HLR algorithm is applied."
6199 "If shapes are not given HLR algoithm of given type is applied"
6200 " to all shapes in the view\n",
6201 __FILE__,VHLRType,group);
6202 theCommands.Add("vclipplane", "vclipplane usage: \n"
6203 " maxplanes <view_name> - get plane limit for view.\n"
6204 " create <plane_name> - create new plane.\n"
6205 " delete <plane_name> - delete plane.\n"
6206 " clone <source_plane> <plane_name> - clone the plane definition.\n"
6207 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
6208 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
6209 " change <plane_name> on/off - turn clipping on/off.\n"
6210 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
6211 " change <plane_name> capping on/off - turn capping on/off.\n"
6212 " change <plane_name> capping color <r> <g> <b> - set color.\n"
6213 " change <plane name> capping texname <texture> - set texture.\n"
6214 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
6215 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
6216 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
6217 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
6218 " please use VSetTextureMode command to enable texture rendering in view.\n"
6219 , __FILE__, VClipPlane, group);
6220 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
6222 " 0 - no textures enabled in view.\n"
6223 " 1 - only environment textures enabled.\n"
6224 " 2 - all textures enabled.\n"
6225 " this command sets texture details mode for the specified view.\n"
6226 , __FILE__, VSetTextureMode, group);
6227 theCommands.Add("vdefaults",
6228 "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
6229 __FILE__, VDefaults, group);
6230 theCommands.Add("vlight",
6231 "vlight [add|new {amb}ient|directional|{spot}light|positional]"
6232 "\n\t\t: [{def}aults] [clear]"
6233 "\n\t\t: [{del}ete|change lightId] [local|global]"
6234 "\n\t\t: [{pos}ition X Y Z] [color colorName] [{head}light 0|1]"
6235 "\n\t\t: [{constAtten}uation value] [{linearAtten}uation value]"
6236 "\n\t\t: [angle angleDeg] [{spotexp}onent value]",
6237 __FILE__, VLight, group);
6238 theCommands.Add("vraytrace",
6240 __FILE__,VRaytrace,group);
6241 theCommands.Add("vclinfo",
6243 __FILE__,VClInfo,group);
6244 theCommands.Add("vsetraytracemode",
6245 "vsetraytracemode [shad=0|1] [refl=0|1] [aa=0|1]",
6246 __FILE__,VSetRaytraceMode,group);