1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
21 #include <OpenGl_GlCore20.hxx>
22 #include <AIS_Shape.hxx>
23 #include <AIS_Drawer.hxx>
24 #include <AIS_InteractiveObject.hxx>
25 #include <AIS_ListOfInteractive.hxx>
26 #include <AIS_ListIteratorOfListOfInteractive.hxx>
28 #include <Graphic3d_AspectMarker3d.hxx>
29 #include <Graphic3d_ExportFormat.hxx>
30 #include <Graphic3d_NameOfTextureEnv.hxx>
31 #include <Graphic3d_TextureEnv.hxx>
32 #include <Graphic3d_TextureParams.hxx>
33 #include <Graphic3d_TypeOfTextureFilter.hxx>
34 #include <Graphic3d_AspectFillArea3d.hxx>
35 #include <ViewerTest.hxx>
36 #include <ViewerTest_EventManager.hxx>
37 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
38 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
39 #include <Visual3d_View.hxx>
40 #include <Visual3d_ViewManager.hxx>
41 #include <V3d_AmbientLight.hxx>
42 #include <V3d_DirectionalLight.hxx>
43 #include <V3d_LayerMgr.hxx>
44 #include <V3d_LayerMgrPointer.hxx>
45 #include <V3d_PositionalLight.hxx>
46 #include <V3d_SpotLight.hxx>
47 #include <NCollection_DoubleMap.hxx>
48 #include <NCollection_List.hxx>
49 #include <NCollection_Vector.hxx>
50 #include <NIS_View.hxx>
51 #include <NIS_Triangulated.hxx>
52 #include <NIS_InteractiveContext.hxx>
53 #include <AIS_InteractiveContext.hxx>
54 #include <Draw_Interpretor.hxx>
56 #include <Draw_Appli.hxx>
57 #include <Aspect_PrintAlgo.hxx>
58 #include <Image_AlienPixMap.hxx>
59 #include <OpenGl_GraphicDriver.hxx>
60 #include <OSD_Timer.hxx>
61 #include <TColStd_HSequenceOfAsciiString.hxx>
62 #include <TColStd_SequenceOfInteger.hxx>
63 #include <TColStd_HSequenceOfReal.hxx>
64 #include <TColgp_Array1OfPnt2d.hxx>
65 #include <TColStd_MapOfAsciiString.hxx>
66 #include <Visual3d_LayerItem.hxx>
67 #include <Aspect_TypeOfLine.hxx>
68 #include <Image_Diff.hxx>
69 #include <Aspect_DisplayConnection.hxx>
73 #include <PrsMgr_PresentableObject.hxx>
74 #include <Graphic3d_ClipPlane.hxx>
75 #include <NCollection_DataMap.hxx>
76 #include <Graphic3d_Texture2Dmanual.hxx>
77 #include <Prs3d_ShadingAspect.hxx>
83 #include <Visual3d_Layer.hxx>
87 #include <WNT_WClass.hxx>
88 #include <WNT_Window.hxx>
91 #define _CRT_SECURE_NO_DEPRECATE
92 #pragma warning (disable:4996)
94 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
95 #include <Cocoa_Window.hxx>
97 #include <Xw_Window.hxx>
98 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
99 #include <X11/Xutil.h>
103 // Auxiliary definitions
104 static const char THE_KEY_DELETE = 127;
106 //==============================================================================
107 // VIEWER GLOBAL VARIABLES
108 //==============================================================================
110 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
111 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
113 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
114 extern const Handle(NIS_InteractiveContext)& TheNISContext();
115 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
117 extern int VErase (Draw_Interpretor& theDI,
118 Standard_Integer theArgNb,
119 const char** theArgVec);
122 static Handle(WNT_Window)& VT_GetWindow() {
123 static Handle(WNT_Window) WNTWin;
126 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
127 static Handle(Cocoa_Window)& VT_GetWindow()
129 static Handle(Cocoa_Window) aWindow;
132 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
133 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
134 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
137 static Handle(Xw_Window)& VT_GetWindow(){
138 static Handle(Xw_Window) XWWin;
142 static void VProcessEvents(ClientData,int);
145 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
147 static Handle(Aspect_DisplayConnection) aDisplayConnection;
148 return aDisplayConnection;
151 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
153 GetDisplayConnection() = theDisplayConnection;
156 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
157 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
159 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
161 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
162 if (!aWindow.IsNull())
163 return aWindow->HWindow();
164 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
165 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
166 if (!aWindow.IsNull())
167 return aWindow->XWindow();
169 return aWindowHandle;
173 static Standard_Boolean MyHLRIsOn = Standard_False;
175 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
176 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
177 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
178 static OpenGl_Caps ViewerTest_myDefaultCaps;
180 #define ZCLIPWIDTH 1.
182 static void OSWindowSetup();
184 //==============================================================================
185 // EVENT GLOBAL VARIABLES
186 //==============================================================================
188 static int Start_Rot = 0;
189 static int ZClipIsOn = 0;
190 int X_Motion = 0; // Current cursor position
192 int X_ButtonPress = 0; // Last ButtonPress position
193 int Y_ButtonPress = 0;
194 Standard_Boolean IsDragged = Standard_False;
195 Standard_Boolean DragFirst = Standard_False;
197 //==============================================================================
200 static LRESULT WINAPI ViewerWindowProc(
205 static LRESULT WINAPI AdvViewerWindowProc(
213 //==============================================================================
216 //==============================================================================
218 const Handle(MMgt_TShared)& ViewerTest::WClass()
220 static Handle(MMgt_TShared) theWClass;
222 if (theWClass.IsNull())
224 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
225 CS_VREDRAW | CS_HREDRAW, 0, 0,
226 ::LoadCursor (NULL, IDC_ARROW));
232 //==============================================================================
233 //function : CreateName
234 //purpose : Create numerical name for new object in theMap
235 //==============================================================================
236 template <typename ObjectType>
237 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
238 const TCollection_AsciiString& theDefaultString)
240 if (theObjectMap.IsEmpty())
241 return theDefaultString + TCollection_AsciiString(1);
243 Standard_Integer aNextKey = 1;
244 Standard_Boolean isFound = Standard_False;
247 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
248 // Look for objects with default names
249 if (theObjectMap.IsBound1(aStringKey))
254 isFound = Standard_True;
257 return theDefaultString + TCollection_AsciiString(aNextKey);
260 //==============================================================================
261 //structure : ViewerTest_Names
262 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
263 //==============================================================================
264 struct ViewerTest_Names
267 TCollection_AsciiString myDriverName;
268 TCollection_AsciiString myViewerName;
269 TCollection_AsciiString myViewName;
273 const TCollection_AsciiString& GetDriverName () const
277 void SetDriverName (const TCollection_AsciiString& theDriverName)
279 myDriverName = theDriverName;
281 const TCollection_AsciiString& GetViewerName () const
285 void SetViewerName (const TCollection_AsciiString& theViewerName)
287 myViewerName = theViewerName;
289 const TCollection_AsciiString& GetViewName () const
293 void SetViewName (const TCollection_AsciiString& theViewName)
295 myViewName = theViewName;
298 //===========================================================================
299 //function : Constructor for ViewerTest_Names
300 //purpose : Get view, viewer, driver names from custom string
301 //===========================================================================
303 ViewerTest_Names (const TCollection_AsciiString& theInputString)
305 TCollection_AsciiString aName(theInputString);
306 if (theInputString.IsEmpty())
308 // Get current configuration
309 if (ViewerTest_myDrivers.IsEmpty())
310 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
311 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
313 myDriverName = ViewerTest_myDrivers.Find2
314 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
316 if(ViewerTest_myContexts.IsEmpty())
318 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
319 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
322 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
324 myViewName = CreateName <Handle(V3d_View)>
325 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
329 // There is at least view name
330 Standard_Integer aParserNumber = 0;
331 for (Standard_Integer i = 0; i < 3; ++i)
333 Standard_Integer aParserPos = aName.SearchFromEnd("/");
337 aName.Split(aParserPos-1);
342 if (aParserNumber == 0)
345 if (!ViewerTest::GetAISContext().IsNull())
347 myDriverName = ViewerTest_myDrivers.Find2
348 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
349 myViewerName = ViewerTest_myContexts.Find2
350 (ViewerTest::GetAISContext());
354 // There is no opened contexts here, need to create names for viewer and driver
355 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
356 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
358 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
359 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
361 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
363 else if (aParserNumber == 1)
365 // Here is viewerName/viewName
366 if (!ViewerTest::GetAISContext().IsNull())
367 myDriverName = ViewerTest_myDrivers.Find2
368 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
371 // There is no opened contexts here, need to create name for driver
372 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
373 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
375 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
377 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
381 //Here is driverName/viewerName/viewName
382 myDriverName = TCollection_AsciiString(aName);
384 TCollection_AsciiString aViewerName(theInputString);
385 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
386 myViewerName = TCollection_AsciiString(aViewerName);
388 myViewName = TCollection_AsciiString(theInputString);
394 //==============================================================================
395 //function : FindContextByView
396 //purpose : Find AIS_InteractiveContext by View
397 //==============================================================================
399 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
401 Handle(AIS_InteractiveContext) anAISContext;
403 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
404 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
406 if (anIter.Value()->CurrentViewer() == theView->Viewer())
407 return anIter.Key2();
413 //==============================================================================
414 //function : SetWindowTitle
415 //purpose : Set window title
416 //==============================================================================
418 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
419 Standard_CString theTitle)
422 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
424 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
425 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
427 if(GetDisplayConnection()->GetDisplay())
430 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
431 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
436 //==============================================================================
437 //function : IsWindowOverlapped
438 //purpose : Check if theWindow overlapp another view
439 //==============================================================================
441 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
442 const Standard_Integer thePxTop,
443 const Standard_Integer thePxRight,
444 const Standard_Integer thePxBottom,
445 TCollection_AsciiString& theViewId)
447 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
448 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
450 Standard_Integer aTop = 0,
454 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
455 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
456 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
457 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
458 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
460 theViewId = anIter.Key1();
461 return Standard_True;
464 return Standard_False;
467 // Workaround: to create and delete non-orthographic views outside ViewerTest
468 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
470 ViewerTest_myViews.UnBind1 (theName);
473 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
474 const Handle(V3d_View)& theView)
476 ViewerTest_myViews.Bind (theName, theView);
479 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
481 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
483 //==============================================================================
484 //function : ViewerInit
485 //purpose : Create the window viewer and initialize all the global variable
486 //==============================================================================
488 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
489 const Standard_Integer thePxTop,
490 const Standard_Integer thePxWidth,
491 const Standard_Integer thePxHeight,
492 Standard_CString theViewName,
493 Standard_CString theDisplayName)
495 // Default position and dimension of the viewer window.
496 // Note that left top corner is set to be sufficiently small to have
497 // window fit in the small screens (actual for remote desktops, see #23003).
498 // The position corresponds to the window's client area, thus some
499 // gap is added for window frame to be visible.
500 Standard_Integer aPxLeft = 20;
501 Standard_Integer aPxTop = 40;
502 Standard_Integer aPxWidth = 409;
503 Standard_Integer aPxHeight = 409;
504 Standard_Boolean toCreateViewer = Standard_False;
506 Handle(OpenGl_GraphicDriver) aGraphicDriver;
507 ViewerTest_Names aViewNames(theViewName);
508 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
509 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
516 aPxWidth = thePxWidth;
517 if (thePxHeight != 0)
518 aPxHeight = thePxHeight;
520 // Get graphic driver (create it or get from another view)
521 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
523 // Get connection string
524 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
525 TCollection_AsciiString aDisplayName(theDisplayName);
526 if (!aDisplayName.IsEmpty())
527 SetDisplayConnection (new Aspect_DisplayConnection ());
529 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
531 (void)theDisplayName; // avoid warning on unused argument
532 SetDisplayConnection (new Aspect_DisplayConnection ());
534 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
535 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
536 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
537 toCreateViewer = Standard_True;
541 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
544 //Dispose the window if input parameters are default
545 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
547 Standard_Integer aTop = 0,
554 // Get screen resolution
555 #if defined(_WIN32) || defined(__WIN32__)
557 GetClientRect(GetDesktopWindow(), &aWindowSize);
558 aScreenHeight = aWindowSize.bottom;
559 aScreenWidth = aWindowSize.right;
560 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
561 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
563 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
564 aScreenWidth = WidthOfScreen(aScreen);
565 aScreenHeight = HeightOfScreen(aScreen);
568 TCollection_AsciiString anOverlappedViewId("");
570 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
572 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
574 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
575 && aRight + 2*aPxWidth + 40 > aScreenWidth)
577 if (aBottom + aPxHeight + 40 > aScreenHeight)
584 aPxTop = aBottom + 40;
587 aPxLeft = aRight + 20;
592 TCollection_AsciiString aTitle("3D View - ");
593 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
595 // Change name of current active window
596 if (!ViewerTest::CurrentView().IsNull())
598 TCollection_AsciiString aTitle("3D View - ");
600 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
601 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
605 Handle(V3d_Viewer) a3DViewer;
606 // If it's the single view, we first look for empty context
607 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
609 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
610 anIter(ViewerTest_myContexts);
612 ViewerTest::SetAISContext (anIter.Value());
613 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
615 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
617 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
618 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
620 else if (a3DViewer.IsNull())
622 toCreateViewer = Standard_True;
623 TCollection_ExtendedString NameOfWindow("Viewer3D");
624 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
626 NameOfWindow = TCollection_ExtendedString("Collector");
628 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
632 if (ViewerTest::GetAISContext().IsNull() ||
633 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
635 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
636 ViewerTest::SetAISContext (aContext);
637 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
641 ViewerTest::ResetEventManager();
646 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
647 Handle(WNT_WClass)::DownCast (WClass()),
648 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
652 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
653 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
655 aPxWidth, aPxHeight);
656 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
658 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
661 aPxWidth, aPxHeight);
663 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
666 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
668 ViewerTest::CurrentView(aView);
669 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
670 TheNISContext()->AttachView (aView);
672 // Setup for X11 or NT
675 // Set parameters for V3d_View and V3d_Viewer
676 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
677 aV3dView->SetComputedMode(Standard_False);
678 MyHLRIsOn = aV3dView->ComputedMode();
679 aV3dView->SetZClippingDepth(0.5);
680 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
682 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
685 a3DViewer->SetDefaultLights();
686 a3DViewer->SetLightOn();
689 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
690 #if TCL_MAJOR_VERSION < 8
691 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
692 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
694 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
695 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
699 VT_GetWindow()->Map();
701 // Set the handle of created view in the event manager
702 ViewerTest::ResetEventManager();
704 ViewerTest::CurrentView()->Redraw();
709 return aViewNames.GetViewName();
712 //==============================================================================
713 //function : RedrawAllViews
714 //purpose : Redraw all created views
715 //==============================================================================
716 void ViewerTest::RedrawAllViews()
718 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
719 for (; aViewIt.More(); aViewIt.Next())
721 const Handle(V3d_View)& aView = aViewIt.Key2();
726 //==============================================================================
728 //purpose : Create the window viewer and initialize all the global variable
729 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
730 //==============================================================================
732 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
736 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
737 << "Type help for more information.\n";
741 TCollection_AsciiString aViewName, aDisplayName;
742 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
743 TCollection_AsciiString aName, aValue;
744 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
746 const TCollection_AsciiString anArg = theArgVec[anArgIt];
747 TCollection_AsciiString anArgCase = anArg;
748 anArgCase.UpperCase();
749 if (ViewerTest::SplitParameter (anArg, aName, aValue))
752 if (aName.IsEqual ("NAME"))
756 else if (aName.IsEqual ("L")
757 || aName.IsEqual ("LEFT"))
759 aPxLeft = aValue.IntegerValue();
761 else if (aName.IsEqual ("T")
762 || aName.IsEqual ("TOP"))
764 aPxTop = aValue.IntegerValue();
766 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
767 else if (aName.IsEqual ("DISP")
768 || aName.IsEqual ("DISPLAY"))
770 aDisplayName = aValue;
773 else if (aName.IsEqual ("W")
774 || aName.IsEqual ("WIDTH"))
776 aPxWidth = aValue.IntegerValue();
778 else if (aName.IsEqual ("H")
779 || aName.IsEqual ("HEIGHT"))
781 aPxHeight = aValue.IntegerValue();
785 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
788 else if (aViewName.IsEmpty())
794 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
798 ViewerTest_Names aViewNames (aViewName);
799 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
801 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
802 theDi.Eval (aCommand.ToCString());
806 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
807 aViewName.ToCString(),
808 aDisplayName.ToCString());
813 //==============================================================================
815 //purpose : hidden lines removal algorithm
816 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
817 //==============================================================================
819 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
821 if (ViewerTest::CurrentView().IsNull())
823 di << argv[0] << ": Call vinit before this command, please.\n";
829 di << argv[0] << ": Wrong number of command arguments.\n"
830 << "Type help " << argv[0] << " for more information.\n";
834 // Enable or disable HLR mode.
835 Standard_Boolean isHLROn =
836 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
838 if (isHLROn != MyHLRIsOn)
841 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
844 // Show or hide hidden lines in HLR mode.
845 Standard_Boolean isCurrentShowHidden
846 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
848 Standard_Boolean isShowHidden =
849 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
850 : isCurrentShowHidden;
853 if (isShowHidden != isCurrentShowHidden)
857 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
861 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
867 AIS_ListOfInteractive aListOfShapes;
868 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
870 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
872 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
882 ViewerTest::CurrentView()->Update();
886 //==============================================================================
887 //function : VHLRType
888 //purpose : change type of using HLR algorithm
889 //==============================================================================
891 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
893 if (ViewerTest::CurrentView().IsNull())
895 di << argv[0] << ": Call vinit before this command, please.\n";
901 di << argv[0] << ": Wrong number of command arguments.\n"
902 << "Type help " << argv[0] << " for more information.\n";
906 Prs3d_TypeOfHLR aTypeOfHLR =
907 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
911 AIS_ListOfInteractive aListOfShapes;
912 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
913 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
914 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
915 anIter.More(); anIter.Next())
917 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
920 if (aShape->TypeOfHLR() != aTypeOfHLR)
921 aShape->SetTypeOfHLR (aTypeOfHLR);
925 ViewerTest::CurrentView()->Update();
930 for (Standard_Integer i = 2; i < argc; ++i)
932 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
933 TCollection_AsciiString aName (argv[i]);
935 if (!aMap.IsBound2 (aName))
937 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
940 Handle(AIS_Shape) anAISObject =
941 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
942 if (anAISObject.IsNull())
944 anAISObject->SetTypeOfHLR (aTypeOfHLR);
946 anAISObject->Redisplay();
948 ViewerTest::CurrentView()->Update();
954 //==============================================================================
955 //function : FindViewIdByWindowHandle
956 //purpose : Find theView Id in the map of views by window handle
957 //==============================================================================
958 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
959 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
961 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
962 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
964 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
965 if (aWindowHandle == theWindowHandle)
966 return anIter.Key1();
968 return TCollection_AsciiString("");
972 //==============================================================================
973 //function : ActivateView
974 //purpose : Make the view active
975 //==============================================================================
977 void ActivateView (const TCollection_AsciiString& theViewName)
979 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
982 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
983 if (!anAISContext.IsNull())
985 if (!ViewerTest::CurrentView().IsNull())
987 TCollection_AsciiString aTitle("3D View - ");
988 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
989 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
992 ViewerTest::CurrentView (aView);
993 // Update degenerate mode
994 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
995 ViewerTest::SetAISContext (anAISContext);
996 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
997 aTitle = aTitle + theViewName + "(*)";
998 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
999 #if defined(_WIN32) || defined(__WIN32__)
1000 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1001 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1002 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1004 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1006 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1007 ViewerTest::CurrentView()->Redraw();
1012 //==============================================================================
1013 //function : RemoveView
1015 //==============================================================================
1016 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1017 const Standard_Boolean theToRemoveContext)
1019 if (!ViewerTest_myViews.IsBound2 (theView))
1024 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1025 RemoveView (aViewName, theToRemoveContext);
1028 //==============================================================================
1029 //function : RemoveView
1030 //purpose : Close and remove view from display, clear maps if neccessary
1031 //==============================================================================
1032 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1034 if (!ViewerTest_myViews.IsBound1(theViewName))
1036 cout << "Wrong view name\n";
1040 // Activate another view if it's active now
1041 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1043 if (ViewerTest_myViews.Extent() > 1)
1045 TCollection_AsciiString aNewViewName;
1046 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1047 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1048 if (anIter.Key1() != theViewName)
1050 aNewViewName = anIter.Key1();
1053 ActivateView (aNewViewName);
1057 Handle(V3d_View) anEmptyView;
1058 #if defined(_WIN32) || defined(__WIN32__)
1059 Handle(WNT_Window) anEmptyWindow;
1060 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1061 Handle(Cocoa_Window) anEmptyWindow;
1063 Handle(Xw_Window) anEmptyWindow;
1065 VT_GetWindow() = anEmptyWindow;
1066 ViewerTest::CurrentView (anEmptyView);
1067 if (isContextRemoved)
1069 Handle(AIS_InteractiveContext) anEmptyContext;
1070 ViewerTest::SetAISContext(anEmptyContext);
1076 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1077 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1079 // Remove view resources
1080 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1081 ViewerTest_myViews.UnBind1(theViewName);
1084 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1085 XFlush (GetDisplayConnection()->GetDisplay());
1088 // Keep context opened only if the closed view is last to avoid
1089 // unused empty contexts
1090 if (!aCurrentContext.IsNull())
1092 // Check if there are more difined views in the viewer
1093 aCurrentContext->CurrentViewer()->InitDefinedViews();
1094 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1096 // Remove driver if there is no viewers that use it
1097 Standard_Boolean isRemoveDriver = Standard_True;
1098 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1099 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1101 if (aCurrentContext != anIter.Key2() &&
1102 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1104 isRemoveDriver = Standard_False;
1110 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1111 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1112 #if TCL_MAJOR_VERSION < 8
1113 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1115 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1120 ViewerTest_myContexts.UnBind2(aCurrentContext);
1123 cout << "3D View - " << theViewName << " was deleted.\n";
1127 //==============================================================================
1129 //purpose : Remove the view defined by its name
1130 //==============================================================================
1132 static int VClose (Draw_Interpretor& /*theDi*/,
1133 Standard_Integer theArgsNb,
1134 const char** theArgVec)
1136 NCollection_List<TCollection_AsciiString> aViewList;
1139 TCollection_AsciiString anArg (theArgVec[1]);
1141 if (anArg.IsEqual ("ALL")
1142 || anArg.IsEqual ("*"))
1144 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1145 anIter.More(); anIter.Next())
1147 aViewList.Append (anIter.Key1());
1149 if (aViewList.IsEmpty())
1151 std::cout << "No view to close\n";
1157 ViewerTest_Names aViewName (theArgVec[1]);
1158 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1160 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1163 aViewList.Append (aViewName.GetViewName());
1168 // close active view
1169 if (ViewerTest::CurrentView().IsNull())
1171 std::cerr << "No active view!\n";
1174 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1177 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1178 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1179 anIter.More(); anIter.Next())
1181 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1187 //==============================================================================
1188 //function : VActivate
1189 //purpose : Activate the view defined by its ID
1190 //==============================================================================
1192 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1196 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1197 << "Usage: " << theArgVec[0] << " ViewID\n";
1202 theDi.Eval("vviewlist");
1206 TCollection_AsciiString aNameString(theArgVec[1]);
1207 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1209 TCollection_AsciiString aTitle("3D View - ");
1210 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1211 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1212 Handle(V3d_View) anEmptyView;
1213 #if defined(_WIN32) || defined(__WIN32__)
1214 Handle(WNT_Window) anEmptyWindow;
1215 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1216 Handle(Cocoa_Window) anEmptyWindow;
1218 Handle(Xw_Window) anEmptyWindow;
1220 VT_GetWindow() = anEmptyWindow;
1221 ViewerTest::CurrentView (anEmptyView);
1222 ViewerTest::ResetEventManager();
1223 theDi << theArgVec[0] << ": all views are inactive\n";
1227 ViewerTest_Names aViewNames(aNameString);
1229 // Check if this view exists in the viewer with the driver
1230 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1232 theDi << "Wrong view name\n";
1236 // Check if it is active already
1237 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1239 theDi << theArgVec[0] << ": the view is active already\n";
1243 ActivateView (aViewNames.GetViewName());
1247 //==============================================================================
1248 //function : VViewList
1249 //purpose : Print current list of views per viewer and graphic driver ID
1250 // shared between viewers
1251 //==============================================================================
1253 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1257 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1258 << "Usage: " << theArgVec[0] << " name";
1261 if (ViewerTest_myContexts.Size() < 1)
1264 Standard_Boolean isTreeView =
1265 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1268 theDi << theArgVec[0] <<":\n";
1270 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1271 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1274 theDi << aDriverIter.Key1() << ":\n";
1276 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1277 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1279 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1283 TCollection_AsciiString aContextName(aContextIter.Key1());
1284 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1287 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1288 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1290 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1292 TCollection_AsciiString aViewName(aViewIter.Key1());
1295 if (aViewIter.Value() == ViewerTest::CurrentView())
1296 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1298 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1302 theDi << aViewName << " ";
1312 //==============================================================================
1313 //function : VT_ProcessKeyPress
1314 //purpose : Handle KeyPress event from a CString
1315 //==============================================================================
1316 void VT_ProcessKeyPress (const char* buf_ret)
1318 //cout << "KeyPress" << endl;
1319 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1320 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1321 // Letter in alphabetic order
1323 if (!strcasecmp (buf_ret, "A"))
1326 aView->SetProj(V3d_XposYnegZpos);
1328 else if (!strcasecmp (buf_ret, "D"))
1333 else if (!strcasecmp (buf_ret, "F"))
1336 if (aNisView.IsNull())
1339 aNisView->FitAll3d();
1341 else if (!strcasecmp (buf_ret, "H"))
1344 cout << "HLR" << endl;
1345 aView->SetComputedMode (!aView->ComputedMode());
1346 MyHLRIsOn = aView->ComputedMode();
1348 else if (!strcasecmp (buf_ret, "P"))
1351 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1352 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1353 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1355 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1356 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1358 AIS_ListOfInteractive aListOfShapes;
1359 aContext->DisplayedObjects(aListOfShapes);
1360 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1361 anIter.More(); anIter.Next())
1363 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1364 if (aShape.IsNull())
1366 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1367 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1369 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1370 aShape->Redisplay();
1375 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1377 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1378 if (aShape.IsNull())
1380 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1381 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1383 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1384 aShape->Redisplay();
1388 aContext->UpdateCurrentViewer();
1391 else if (!strcasecmp (buf_ret, "S"))
1393 std::cout << "setup Shaded display mode" << std::endl;
1395 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1396 if(Ctx->NbCurrents()==0 ||
1397 Ctx->NbSelected()==0)
1398 Ctx->SetDisplayMode(AIS_Shaded);
1400 if(Ctx->HasOpenedContext()){
1401 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1402 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1405 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1406 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1408 Ctx->UpdateCurrentViewer();
1411 else if (!strcasecmp (buf_ret, "U"))
1413 // Unset display mode
1414 std::cout << "reset display mode to defaults" << std::endl;
1416 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1417 if(Ctx->NbCurrents()==0 ||
1418 Ctx->NbSelected()==0)
1419 Ctx->SetDisplayMode(AIS_WireFrame);
1421 if(Ctx->HasOpenedContext()){
1422 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1423 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1426 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1427 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1429 Ctx->UpdateCurrentViewer();
1433 else if (!strcasecmp (buf_ret, "T"))
1436 aView->SetProj(V3d_Zpos);
1438 else if (!strcasecmp (buf_ret, "B"))
1441 aView->SetProj(V3d_Zneg);
1443 else if (!strcasecmp (buf_ret, "L"))
1446 aView->SetProj(V3d_Xneg);
1448 else if (!strcasecmp (buf_ret, "R"))
1451 aView->SetProj(V3d_Xpos);
1453 else if (!strcasecmp (buf_ret, "W"))
1455 std::cout << "setup WireFrame display mode" << std::endl;
1456 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1457 if(Ctx->NbCurrents()==0 ||
1458 Ctx->NbSelected()==0)
1459 Ctx->SetDisplayMode(AIS_WireFrame);
1461 if(Ctx->HasOpenedContext()){
1462 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1463 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1466 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1467 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1469 Ctx->UpdateCurrentViewer();
1472 else if (!strcasecmp (buf_ret, "Z"))
1476 cout << "ZClipping OFF" << endl;
1479 aView->SetZClippingType(V3d_OFF);
1483 cout << "ZClipping ON" << endl;
1486 aView->SetZClippingType(V3d_FRONT);
1490 else if (!strcasecmp (buf_ret, ","))
1492 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1494 else if (!strcasecmp (buf_ret, "."))
1496 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1498 else if (*buf_ret == THE_KEY_DELETE)
1500 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1502 && aCtx->NbCurrents() > 0
1503 && aCtx->NbSelected() > 0)
1505 Draw_Interprete ("verase");
1511 Standard_Integer Num = Draw::Atoi(buf_ret);
1512 if(Num>=0 && Num<=7)
1513 ViewerTest::StandardModeActivation(Num);
1517 //==============================================================================
1518 //function : VT_ProcessExpose
1519 //purpose : Redraw the View on an Expose Event
1520 //==============================================================================
1521 void VT_ProcessExpose()
1523 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1524 if (!aView3d.IsNull())
1530 //==============================================================================
1531 //function : VT_ProcessConfigure
1532 //purpose : Resize the View on an Configure Event
1533 //==============================================================================
1534 void VT_ProcessConfigure()
1536 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1537 if (aView3d.IsNull())
1542 aView3d->MustBeResized();
1547 //==============================================================================
1548 //function : VT_ProcessButton1Press
1550 //==============================================================================
1551 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1552 const char** theArgVec,
1553 Standard_Boolean theToPick,
1554 Standard_Boolean theIsShift)
1558 Standard_Real X, Y, Z;
1559 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1561 Draw::Set (theArgVec[1], X);
1562 Draw::Set (theArgVec[2], Y);
1563 Draw::Set (theArgVec[3], Z);
1568 ViewerTest::CurrentEventManager()->ShiftSelect();
1572 ViewerTest::CurrentEventManager()->Select();
1575 return Standard_False;
1578 //==============================================================================
1579 //function : VT_ProcessButton1Release
1580 //purpose : End selecting
1581 //==============================================================================
1582 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1586 IsDragged = Standard_False;
1587 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1590 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1591 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1595 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1596 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1601 //==============================================================================
1602 //function : VT_ProcessButton3Press
1603 //purpose : Start Rotation
1604 //==============================================================================
1605 void VT_ProcessButton3Press()
1610 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1612 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1615 //==============================================================================
1616 //function : VT_ProcessButton3Release
1617 //purpose : End rotation
1618 //==============================================================================
1619 void VT_ProcessButton3Release()
1626 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1631 //==============================================================================
1632 //function : ProcessZClipMotion
1634 //==============================================================================
1636 void ProcessZClipMotion()
1638 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1639 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1640 static Standard_Real CurZPos = 0.;
1642 //Quantity_Length VDX, VDY;
1643 //a3DView->Size(VDX,VDY);
1644 //Standard_Real VDZ = a3DView->ZSize();
1645 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1647 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1649 // Front = Depth + width/2.
1650 Standard_Real D = 0.5;
1651 Standard_Real W = 0.1;
1657 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1659 a3DView->SetZClippingType(V3d_OFF);
1660 a3DView->SetZClippingDepth(D);
1661 a3DView->SetZClippingWidth(W);
1662 a3DView->SetZClippingType(V3d_FRONT);
1666 X_ButtonPress = X_Motion;
1667 Y_ButtonPress = Y_Motion;
1671 //==============================================================================
1672 //function : ProcessControlButton1Motion
1674 //==============================================================================
1676 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1677 static void ProcessControlButton1Motion()
1679 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1681 X_ButtonPress = X_Motion;
1682 Y_ButtonPress = Y_Motion;
1686 //==============================================================================
1687 //function : VT_ProcessControlButton2Motion
1689 //==============================================================================
1690 void VT_ProcessControlButton2Motion()
1692 Standard_Integer aDx = X_Motion - X_ButtonPress;
1693 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1695 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1697 ViewerTest::CurrentView()->Pan (aDx, aDy);
1699 X_ButtonPress = X_Motion;
1700 Y_ButtonPress = Y_Motion;
1703 //==============================================================================
1704 //function : VT_ProcessControlButton3Motion
1705 //purpose : Rotation
1706 //==============================================================================
1707 void VT_ProcessControlButton3Motion()
1711 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1715 //==============================================================================
1716 //function : VT_ProcessMotion
1718 //==============================================================================
1719 void VT_ProcessMotion()
1721 //pre-hilights detected objects at mouse position
1723 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1724 EM->MoveTo(X_Motion, Y_Motion);
1728 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1730 Xpix = X_Motion;Ypix=Y_Motion;
1733 //==============================================================================
1734 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1735 //purpose : Switches to an axonometric, top, left and other views
1736 //==============================================================================
1738 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1740 if ( ViewerTest::CurrentView().IsNull() )
1742 di<<"Call vinit before this command, please"<<"\n";
1746 ViewerTest::CurrentView()->SetProj(ori);
1750 //==============================================================================
1752 //purpose : Switch to an Axonometric view
1753 //Draw arg : No args
1754 //==============================================================================
1756 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1758 return ViewProject(di, V3d_XposYnegZpos);
1761 //==============================================================================
1763 //purpose : Switch to a Top View
1764 //Draw arg : No args
1765 //==============================================================================
1767 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1769 return ViewProject(di, V3d_Zpos);
1772 //==============================================================================
1773 //function : VBottom
1774 //purpose : Switch to a Bottom View
1775 //Draw arg : No args
1776 //==============================================================================
1778 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1780 return ViewProject(di, V3d_Zneg);
1783 //==============================================================================
1785 //purpose : Switch to a Left View
1786 //Draw arg : No args
1787 //==============================================================================
1789 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1791 return ViewProject(di, V3d_Ypos);
1794 //==============================================================================
1796 //purpose : Switch to a Right View
1797 //Draw arg : No args
1798 //==============================================================================
1800 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1802 return ViewProject(di, V3d_Yneg);
1805 //==============================================================================
1807 //purpose : Switch to a Front View
1808 //Draw arg : No args
1809 //==============================================================================
1811 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1813 return ViewProject(di, V3d_Xpos);
1816 //==============================================================================
1818 //purpose : Switch to a Back View
1819 //Draw arg : No args
1820 //==============================================================================
1822 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1824 return ViewProject(di, V3d_Xneg);
1827 //==============================================================================
1829 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1830 //Draw arg : No args
1831 //==============================================================================
1833 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1836 di << "Q : Quit the application" << "\n";
1838 di << "========================="<<"\n";
1839 di << "F : FitAll" << "\n";
1840 di << "T : TopView" << "\n";
1841 di << "B : BottomView" << "\n";
1842 di << "R : RightView" << "\n";
1843 di << "L : LeftView" << "\n";
1844 di << "A : AxonometricView" << "\n";
1845 di << "D : ResetView" << "\n";
1847 di << "========================="<<"\n";
1848 di << "S : Shading" << "\n";
1849 di << "W : Wireframe" << "\n";
1850 di << "H : HidelLineRemoval" << "\n";
1851 di << "U : Unset display mode" << "\n";
1852 di << "Delete : Remove selection from viewer" << "\n";
1854 di << "========================="<<"\n";
1855 di << "Selection mode "<<"\n";
1856 di << "0 : Shape" <<"\n";
1857 di << "1 : Vertex" <<"\n";
1858 di << "2 : Edge" <<"\n";
1859 di << "3 : Wire" <<"\n";
1860 di << "4 : Face" <<"\n";
1861 di << "5 : Shell" <<"\n";
1862 di << "6 : Solid" <<"\n";
1863 di << "7 : Compound" <<"\n";
1865 di << "========================="<<"\n";
1866 di << "Z : Switch Z clipping On/Off" << "\n";
1867 di << ", : Hilight next detected" << "\n";
1868 di << ". : Hilight previous detected" << "\n";
1875 static Standard_Boolean Ppick = 0;
1876 static Standard_Integer Pargc = 0;
1877 static const char** Pargv = NULL;
1880 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1885 if (!ViewerTest_myViews.IsEmpty()) {
1887 WPARAM fwKeys = wParam;
1892 // Delete view from map of views
1893 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1898 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1899 || ViewerTest::CurrentView().IsNull())
1901 // Activate inactive window
1902 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1904 ActivateView (FindViewIdByWindowHandle(hwnd));
1911 HDC hdc = GetDC( hwnd );
1912 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1913 SetROP2( hdc, R2_NOT );
1914 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1915 ReleaseDC( hwnd, hdc );
1916 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1918 IsDragged = Standard_False;
1919 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1921 case WM_LBUTTONDOWN:
1922 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1924 IsDragged = Standard_True;
1925 DragFirst = Standard_True;
1926 X_ButtonPress = LOWORD(lParam);
1927 Y_ButtonPress = HIWORD(lParam);
1929 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1936 HDC hdc = GetDC( hwnd );
1938 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1939 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1940 SetROP2( hdc, R2_NOT );
1943 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1945 DragFirst = Standard_False;
1946 X_Motion = LOWORD(lParam);
1947 Y_Motion = HIWORD(lParam);
1949 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1951 SelectObject( hdc, anObj );
1953 ReleaseDC( hwnd, hdc );
1956 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1960 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1964 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1968 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1975 if ( !ViewerTest::CurrentView().IsNull() ) {
1980 BeginPaint(hwnd, &ps);
1981 EndPaint(hwnd, &ps);
1986 VT_ProcessConfigure();
1990 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1993 c[0] = (char) wParam;
1995 if (wParam == VK_DELETE)
1997 c[0] = THE_KEY_DELETE;
1999 VT_ProcessKeyPress (c);
2007 VT_ProcessButton3Release();
2010 case WM_LBUTTONDOWN:
2011 case WM_MBUTTONDOWN:
2012 case WM_RBUTTONDOWN:
2014 WPARAM fwKeys = wParam;
2018 X_ButtonPress = LOWORD(lParam);
2019 Y_ButtonPress = HIWORD(lParam);
2021 if (Msg == WM_LBUTTONDOWN)
2023 if (fwKeys & MK_CONTROL)
2025 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2029 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2032 else if (Msg == WM_RBUTTONDOWN)
2035 VT_ProcessButton3Press();
2042 //cout << "\t WM_MOUSEMOVE" << endl;
2043 WPARAM fwKeys = wParam;
2044 X_Motion = LOWORD(lParam);
2045 Y_Motion = HIWORD(lParam);
2048 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2050 X_ButtonPress = LOWORD(lParam);
2051 Y_ButtonPress = HIWORD(lParam);
2053 if ( fwKeys & MK_RBUTTON ) {
2055 VT_ProcessButton3Press();
2059 if ( fwKeys & MK_CONTROL ) {
2060 if ( fwKeys & MK_LBUTTON ) {
2061 ProcessControlButton1Motion();
2063 else if ( fwKeys & MK_MBUTTON ||
2064 ((fwKeys&MK_LBUTTON) &&
2065 (fwKeys&MK_RBUTTON) ) ){
2066 VT_ProcessControlButton2Motion();
2068 else if ( fwKeys & MK_RBUTTON ) {
2069 VT_ProcessControlButton3Motion();
2073 else if ( fwKeys & MK_SHIFT ) {
2074 if ( fwKeys & MK_MBUTTON ||
2075 ((fwKeys&MK_LBUTTON) &&
2076 (fwKeys&MK_RBUTTON) ) ) {
2077 cout << "ProcessZClipMotion()" << endl;
2078 ProcessZClipMotion();
2082 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2084 if ((fwKeys & MK_MBUTTON
2085 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2087 ProcessZClipMotion();
2098 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2103 return DefWindowProc( hwnd, Msg, wParam, lParam );
2109 //==============================================================================
2110 //function : ViewerMainLoop
2111 //purpose : Get a Event on the view and dispatch it
2112 //==============================================================================
2115 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2117 Ppick = (argc > 0)? 1 : 0;
2125 cout << "Start picking" << endl;
2127 while ( Ppick == 1 ) {
2128 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2129 if (GetMessage(&msg, NULL, 0, 0) ) {
2130 TranslateMessage(&msg);
2131 DispatchMessage(&msg);
2135 cout << "Picking done" << endl;
2141 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2143 int min( int a, int b )
2151 int max( int a, int b )
2159 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2162 static XEvent aReport;
2163 Standard_Boolean pick = argc > 0;
2164 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2165 XNextEvent (aDisplay, &aReport);
2167 // Handle event for the chosen display connection
2168 switch (aReport.type) {
2171 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2174 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2180 // Activate inactive view
2181 Window aWindow = GetWindowHandle(VT_GetWindow());
2182 if(aWindow != aReport.xfocus.window)
2184 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2193 case ConfigureNotify:
2195 VT_ProcessConfigure();
2204 XComposeStatus status_in_out;
2206 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2207 (char *) buf_ret , 10 ,
2208 &ks_ret , &status_in_out ) ;
2211 buf_ret[ret_len] = '\0' ;
2215 VT_ProcessKeyPress (buf_ret);
2221 X_ButtonPress = aReport.xbutton.x;
2222 Y_ButtonPress = aReport.xbutton.y;
2224 if (aReport.xbutton.button == Button1)
2226 if (aReport.xbutton.state & ControlMask)
2228 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2232 IsDragged = Standard_True;
2233 DragFirst = Standard_True;
2236 else if (aReport.xbutton.button == Button3)
2239 VT_ProcessButton3Press();
2249 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2250 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2251 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2254 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2255 if( aContext.IsNull() )
2257 cout << "The context is null. Please use vinit before createmesh" << endl;
2261 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2262 if( aReport.xbutton.button==1 )
2266 aContext->ShiftSelect();
2275 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2276 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2277 ViewerTest::CurrentView());
2281 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2282 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2283 ViewerTest::CurrentView() );
2286 VT_ProcessButton3Release();
2288 IsDragged = Standard_False;
2291 VT_ProcessButton3Release();
2296 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2302 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2303 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2304 XSetFunction( aDisplay, gc, GXinvert );
2307 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2309 X_Motion = aReport.xmotion.x;
2310 Y_Motion = aReport.xmotion.y;
2311 DragFirst = Standard_False;
2313 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2317 X_Motion = aReport.xmotion.x;
2318 Y_Motion = aReport.xmotion.y;
2320 // remove all the ButtonMotionMaskr
2321 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2323 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2324 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2326 Quantity_Length VDX, VDY;
2328 ViewerTest::CurrentView()->Size(VDX,VDY);
2329 Standard_Real VDZ =0 ;
2330 VDZ = ViewerTest::CurrentView()->ZSize();
2332 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2334 Quantity_Length dx = 0 ;
2335 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2339 dx = dx / VDX * VDZ;
2343 ViewerTest::CurrentView()->Redraw();
2347 if ( aReport.xmotion.state & ControlMask ) {
2348 if ( aReport.xmotion.state & Button1Mask ) {
2349 ProcessControlButton1Motion();
2351 else if ( aReport.xmotion.state & Button2Mask ) {
2352 VT_ProcessControlButton2Motion();
2354 else if ( aReport.xmotion.state & Button3Mask ) {
2355 VT_ProcessControlButton3Motion();
2369 //==============================================================================
2370 //function : VProcessEvents
2371 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2372 // event in the Viewer window
2373 //==============================================================================
2375 static void VProcessEvents(ClientData,int)
2377 NCollection_Vector<int> anEventNumbers;
2378 // Get number of messages from every display
2379 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2380 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2382 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2384 // Handle events for every display
2385 int anEventIter = 0;
2386 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2387 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2389 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2390 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2392 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2393 int anEventResult = ViewerMainLoop( 0, NULL);
2394 // If window is closed or context was not found finish current event processing loop
2400 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2405 //==============================================================================
2406 //function : OSWindowSetup
2407 //purpose : Setup for the X11 window to be able to cath the event
2408 //==============================================================================
2411 static void OSWindowSetup()
2413 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2416 Window window = VT_GetWindow()->XWindow();
2417 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2418 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2419 XSynchronize(aDisplay, 1);
2421 // X11 : For keyboard on SUN
2423 wmhints.flags = InputHint;
2426 XSetWMHints( aDisplay, window, &wmhints);
2428 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2429 ButtonPressMask | ButtonReleaseMask |
2430 StructureNotifyMask |
2432 Button1MotionMask | Button2MotionMask |
2433 Button3MotionMask | FocusChangeMask
2435 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2436 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2438 XSynchronize(aDisplay, 0);
2447 //==============================================================================
2450 //purpose : Fitall, no DRAW arguments
2451 //Draw arg : No args
2452 //==============================================================================
2454 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2456 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2457 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2458 if (V.IsNull() == Standard_False) {
2460 } else if (aView.IsNull() == Standard_False) {
2466 //==============================================================================
2468 //purpose : ZFitall, no DRAW arguments
2469 //Draw arg : No args
2470 //==============================================================================
2471 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2473 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2475 if (aCurrentView.IsNull())
2477 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2483 aCurrentView->ZFitAll();
2484 aCurrentView->Redraw();
2488 Standard_Real aScale = 1.0;
2492 aScale = Draw::Atoi (theArgVec[1]);
2495 aCurrentView->ZFitAll (aScale);
2496 aCurrentView->Redraw();
2501 //==============================================================================
2502 //function : VRepaint
2504 //==============================================================================
2505 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2507 Handle(V3d_View) V = ViewerTest::CurrentView();
2508 if ( !V.IsNull() ) V->Redraw(); return 0;
2511 //==============================================================================
2513 //purpose : Remove all the object from the viewer
2514 //Draw arg : No args
2515 //==============================================================================
2517 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2519 Handle(V3d_View) V = ViewerTest::CurrentView();
2521 ViewerTest::Clear();
2525 //==============================================================================
2528 //==============================================================================
2530 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2531 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2534 di << argv[0] << "Invalid number of arguments" << "\n";
2538 while (ViewerMainLoop( argc, argv)) {
2544 //==============================================================================
2546 //purpose : Load image as background
2547 //==============================================================================
2549 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2551 if (argc < 2 || argc > 3)
2553 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2554 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2558 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2559 if(AISContext.IsNull())
2561 di << "use 'vinit' command before " << argv[0] << "\n";
2565 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2568 const char* szType = argv[2];
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";
2581 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2582 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2587 //==============================================================================
2588 //function : VSetBgMode
2589 //purpose : Change background image fill type
2590 //==============================================================================
2592 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2596 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2597 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2601 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2602 if(AISContext.IsNull())
2604 di << "use 'vinit' command before " << argv[0] << "\n";
2607 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2608 const char* szType = argv[1];
2609 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2610 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2611 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2612 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2615 di << "Wrong fill type : " << szType << "\n";
2616 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2619 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2620 V3dView->SetBgImageStyle(aFillType, Standard_True);
2624 //==============================================================================
2625 //function : VSetGradientBg
2626 //purpose : Mount gradient background
2627 //==============================================================================
2628 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2632 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2633 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2634 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2635 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2639 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2640 if(AISContext.IsNull())
2642 di << "use 'vinit' command before " << argv[0] << "\n";
2648 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2649 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2650 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2651 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2653 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2654 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2655 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2657 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2658 int aType = Draw::Atoi(argv[7]);
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->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2676 //==============================================================================
2677 //function : VSetGradientBgMode
2678 //purpose : Change gradient background fill style
2679 //==============================================================================
2680 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2684 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2685 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2686 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2690 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2691 if(AISContext.IsNull())
2693 di << "use 'vinit' command before " << argv[0] << "\n";
2698 int aType = Draw::Atoi(argv[1]);
2699 if( aType < 0 || aType > 8 )
2701 di << "Wrong fill type " << "\n";
2702 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2703 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2707 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2709 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2710 V3dView->SetBgGradientStyle( aMethod, 1 );
2716 //==============================================================================
2717 //function : VSetColorBg
2718 //purpose : Set color background
2719 //==============================================================================
2720 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2724 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2725 di << "R,G,B = [0..255]" << "\n";
2729 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2730 if(AISContext.IsNull())
2732 di << "use 'vinit' command before " << argv[0] << "\n";
2738 Standard_Real R = Draw::Atof(argv[1])/255.;
2739 Standard_Real G = Draw::Atof(argv[2])/255.;
2740 Standard_Real B = Draw::Atof(argv[3])/255.;
2741 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2743 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2744 V3dView->SetBackgroundColor( aColor );
2751 //==============================================================================
2753 //purpose : View Scaling
2754 //==============================================================================
2756 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2758 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2759 if ( V3dView.IsNull() ) return 1;
2762 di << argv[0] << "Invalid number of arguments" << "\n";
2765 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2768 //==============================================================================
2769 //function : VTestZBuffTrihedron
2770 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2771 //==============================================================================
2773 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2775 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2776 if ( V3dView.IsNull() ) return 1;
2778 V3dView->ZBufferTriedronSetup();
2781 // Set up default trihedron parameters
2782 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2786 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2787 const char* aPosType = argv[1];
2789 if ( strcmp(aPosType, "center") == 0 )
2791 aPosition = Aspect_TOTP_CENTER;
2793 if (strcmp(aPosType, "left_lower") == 0)
2795 aPosition = Aspect_TOTP_LEFT_LOWER;
2797 if (strcmp(aPosType, "left_upper") == 0)
2799 aPosition = Aspect_TOTP_LEFT_UPPER;
2801 if (strcmp(aPosType, "right_lower") == 0)
2803 aPosition = Aspect_TOTP_RIGHT_LOWER;
2805 if (strcmp(aPosType, "right_upper") == 0)
2807 aPosition = Aspect_TOTP_RIGHT_UPPER;
2810 di << argv[1] << " Invalid type of alignment" << "\n";
2811 di << "Must be one of [ center, left_lower," << "\n";
2812 di << "left_upper, right_lower, right_upper ]" << "\n";
2816 Standard_Real R = Draw::Atof(argv[2])/255.;
2817 Standard_Real G = Draw::Atof(argv[3])/255.;
2818 Standard_Real B = Draw::Atof(argv[4])/255.;
2819 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2821 Standard_Real aScale = Draw::Atof(argv[5]);
2825 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2829 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2830 const char* aPresType = argv[6];
2832 if ( strcmp(aPresType, "wireframe") == 0 )
2834 aPresentation = V3d_WIREFRAME;
2836 if (strcmp(aPresType, "zbuffer") == 0)
2838 aPresentation = V3d_ZBUFFER;
2841 di << argv[6] << " Invalid type of visualization" << "\n";
2842 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2846 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2850 di << argv[0] << " Invalid number of arguments" << "\n";
2859 //==============================================================================
2860 //function : VRotate
2861 //purpose : Camera Rotating
2862 //==============================================================================
2864 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2865 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2866 if ( V3dView.IsNull() ) {
2871 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2873 } else if ( argc == 7 ) {
2874 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]) );
2877 di << argv[0] << " Invalid number of arguments" << "\n";
2882 //==============================================================================
2884 //purpose : View zoom in / out (relative to current zoom)
2885 //==============================================================================
2887 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2888 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2889 if ( V3dView.IsNull() ) {
2894 Standard_Real coef = Draw::Atof(argv[1]);
2895 if ( coef <= 0.0 ) {
2896 di << argv[1] << "Invalid value" << "\n";
2899 V3dView->SetZoom( Draw::Atof(argv[1]) );
2902 di << argv[0] << " Invalid number of arguments" << "\n";
2907 //==============================================================================
2909 //purpose : View panning (in pixels)
2910 //==============================================================================
2912 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2913 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2914 if ( V3dView.IsNull() ) return 1;
2917 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2920 di << argv[0] << " Invalid number of arguments" << "\n";
2926 //==============================================================================
2927 //function : VExport
2928 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2929 //==============================================================================
2931 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2933 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2934 if (V3dView.IsNull())
2939 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2943 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2944 TCollection_AsciiString aFormatStr;
2946 TCollection_AsciiString aFileName (argv[1]);
2947 Standard_Integer aLen = aFileName.Length();
2951 aFormatStr = TCollection_AsciiString (argv[2]);
2955 if (aFileName.Value (aLen - 2) == '.')
2957 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2959 else if (aFileName.Value (aLen - 3) == '.')
2961 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2965 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2971 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2975 aFormatStr.UpperCase();
2976 if (aFormatStr == "PS")
2977 anExpFormat = Graphic3d_EF_PostScript;
2978 else if (aFormatStr == "EPS")
2979 anExpFormat = Graphic3d_EF_EnhPostScript;
2980 else if (aFormatStr == "TEX")
2981 anExpFormat = Graphic3d_EF_TEX;
2982 else if (aFormatStr == "PDF")
2983 anExpFormat = Graphic3d_EF_PDF;
2984 else if (aFormatStr == "SVG")
2985 anExpFormat = Graphic3d_EF_SVG;
2986 else if (aFormatStr == "PGF")
2987 anExpFormat = Graphic3d_EF_PGF;
2988 else if (aFormatStr == "EMF")
2989 anExpFormat = Graphic3d_EF_EMF;
2992 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2997 if (!V3dView->View()->Export (argv[1], anExpFormat))
2999 di << "Error: export of image to " << aFormatStr << " failed!\n";
3002 catch (Standard_Failure)
3004 di << "Error: export of image to " << aFormatStr << " failed";
3005 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3010 //==============================================================================
3011 //function : VColorScale
3012 //purpose : representation color scale
3013 //==============================================================================
3014 #include <V3d_ColorScale.hxx>
3016 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3018 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
3020 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
3024 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3025 if(aContext.IsNull()) {
3026 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
3030 Standard_Real minRange = 0. , maxRange = 100. ;
3032 Standard_Integer numIntervals = 10 ;
3033 Standard_Integer textHeight = 16;
3034 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
3035 Standard_Real X = 0., Y = 0. ;
3041 minRange = Draw::Atof( argv[1] );
3042 maxRange = Draw::Atof( argv[2] );
3043 numIntervals = Draw::Atoi( argv[3] );
3046 textHeight = Draw::Atoi( argv[4] );
3048 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
3051 X = Draw::Atof( argv[6] );
3052 Y = Draw::Atof( argv[7] );
3055 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3056 if ( curView.IsNull( ) )
3058 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3059 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3060 if( ! aCS.IsNull( ) )
3062 aCS->SetPosition( X , Y );
3063 aCS->SetHeight( 0.95) ;
3064 aCS->SetTextHeight( textHeight );
3065 aCS->SetRange( minRange , maxRange );
3066 aCS->SetNumberOfIntervals( numIntervals );
3067 aCS->SetLabelPosition( position );
3068 if( !curView->ColorScaleIsDisplayed() )
3069 curView->ColorScaleDisplay( );
3074 //==============================================================================
3075 //function : VGraduatedTrihedron
3076 //purpose : Displays a graduated trihedron
3077 //==============================================================================
3079 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3081 const char *str = arg;
3084 unsigned short c1 = *str++;
3085 unsigned short c2 = *str++;
3086 if (!c1 || !c2) break;
3087 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3091 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3094 if (argc != 2 && argc < 5)
3096 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3097 di<<"Usage: type help "<<argv[0]<<"\n";
3098 return 1; //TCL_ERROR
3101 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3103 // Create 3D view if it doesn't exist
3104 if ( aV3dView.IsNull() )
3106 ViewerTest::ViewerInit();
3107 aV3dView = ViewerTest::CurrentView();
3108 if( aV3dView.IsNull() )
3110 di << "Error: Cannot create a 3D view\n";
3111 return 1; //TCL_ERROR
3115 // Erase (==0) or display (!=0)
3116 const int display = Draw::Atoi(argv[1]);
3121 TCollection_AsciiString font;
3123 font.AssignCat("Courier");
3125 font.AssignCat(argv[5]);
3127 // Text is multibyte
3128 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3131 TCollection_ExtendedString xname, yname, zname;
3136 AddMultibyteString(xname, argv[2]);
3137 AddMultibyteString(yname, argv[3]);
3138 AddMultibyteString(zname, argv[4]);
3154 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3155 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3156 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3157 Standard_True/*drawgrid*/,
3158 Standard_True/*drawaxes*/,
3159 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3160 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3161 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3162 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3163 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3164 Quantity_NOC_WHITE/*gridcolor*/,
3165 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3166 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3169 aV3dView->GraduatedTrihedronErase();
3171 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3177 //==============================================================================
3178 //function : VPrintView
3179 //purpose : Test printing algorithm, print the view to image file with given
3180 // width and height. Printing implemented only for WNT.
3181 //==============================================================================
3182 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3186 di << "Printing implemented only for wnt!\n";
3190 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3191 Handle(V3d_View) aView = NULL;
3192 aContextAIS = ViewerTest::GetAISContext();
3193 if (!aContextAIS.IsNull())
3195 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3196 Vwr->InitActiveViews();
3197 if(Vwr->MoreActiveViews())
3198 aView = Vwr->ActiveView();
3204 di << "Call vinit before!\n";
3209 di << "Use: " << argv[0];
3210 di << " width height filename [print algo=0] [tile_width tile_height]\n";
3211 di << "width, height of the intermediate buffer for operation\n";
3212 di << "algo : {0|1}\n";
3213 di << " 0 - stretch algorithm\n";
3214 di << " 1 - tile algorithm\n";
3215 di << "test printing algorithms into an intermediate buffer\n";
3216 di << "using specific tile size if provided\n";
3217 di << "with saving output to an image file\n";
3221 // get the input params
3222 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3223 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3224 Standard_Integer aMode = 0;
3225 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3227 aMode = Draw::Atoi (argv[4]);
3229 Standard_Integer aTileWidth = 0;
3230 Standard_Integer aTileHeight = 0;
3231 Standard_Boolean isTileSizeProvided = Standard_False;
3234 isTileSizeProvided = Standard_True;
3235 aTileWidth = Draw::Atoi (argv[5]);
3236 aTileHeight = Draw::Atoi (argv[6]);
3239 // check the input parameters
3240 if (aWidth <= 0 || aHeight <= 0)
3242 di << "Width and height must be positive values!\n";
3245 if (aMode != 0 && aMode != 1)
3248 // define compatible bitmap
3249 HDC anDC = CreateCompatibleDC(0);
3250 BITMAPINFO aBitmapData;
3251 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3252 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3253 aBitmapData.bmiHeader.biWidth = aWidth ;
3254 aBitmapData.bmiHeader.biHeight = aHeight;
3255 aBitmapData.bmiHeader.biPlanes = 1;
3256 aBitmapData.bmiHeader.biBitCount = 24;
3257 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3258 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3259 aBitmapData.bmiHeader.biClrUsed = 0;
3260 aBitmapData.bmiHeader.biClrImportant = 0;
3261 aBitmapData.bmiHeader.biCompression = BI_RGB;
3262 aBitmapData.bmiHeader.biSizeImage = 0;
3264 // Create Device Independent Bitmap
3265 void* aBitsOut = NULL;
3266 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3267 &aBitsOut, NULL, 0);
3268 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3270 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3271 if (aBitsOut != NULL)
3274 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3277 if (isTileSizeProvided)
3279 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
3280 Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
3281 aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight);
3283 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
3285 Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
3286 aView->View()->FBORelease (aNewBuffer);
3287 aCView->ptrFBO = anOldBuffer;
3291 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
3295 // succesfully printed into an intermediate buffer
3298 Image_PixMap aWrapper;
3299 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3300 aWrapper.SetTopDown (false);
3302 Image_AlienPixMap anImageBitmap;
3303 anImageBitmap.InitCopy (aWrapper);
3304 isSaved = anImageBitmap.Save (aFileName);
3308 di << "Print operation failed due to printing errors or\n";
3309 di << "insufficient memory available\n";
3310 di << "Please, try to use smaller dimensions for this test\n";
3311 di << "command, as it allocates intermediate buffer for storing\n";
3312 di << "the result\n";
3317 di << "Can't allocate memory for intermediate buffer\n";
3318 di << "Please use smaller dimensions\n";
3323 SelectObject (anDC, anOldBitmap);
3324 DeleteObject (aMemoryBitmap);
3330 di << "Save to file operation failed. This operation may fail\n";
3331 di << "if you don't have enough available memory, then you can\n";
3332 di << "use smaller dimensions for the output file\n";
3341 //==============================================================================
3342 //function : VZLayer
3343 //purpose : Test z layer operations for v3d viewer
3344 //==============================================================================
3345 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3347 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3348 if (aContextAIS.IsNull())
3350 di << "Call vinit before!\n";
3355 di << "Use: vzlayer ";
3356 di << " add/del/get/settings/enable/disable [id]\n";
3357 di << " add - add new z layer to viewer and print its id\n";
3358 di << " del - del z layer by its id\n";
3359 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3360 di << " settings - print status of z layer settings\n";
3361 di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n";
3362 di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n";
3363 di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n";
3364 di << "\nWhere id is the layer identificator\n";
3365 di << "\nExamples:\n";
3366 di << " vzlayer add\n";
3367 di << " vzlayer enable poffset 1\n";
3368 di << " vzlayer disable depthtest 1\n";
3369 di << " vzlayer del 1\n";
3373 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3374 if (aViewer.IsNull())
3376 di << "No active viewer!\n";
3380 // perform operation
3381 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3384 Standard_Integer aNewId;
3385 if (!aViewer->AddZLayer (aNewId))
3387 di << "Impossible to add new z layer!\n";
3391 di << "New z layer added with index: " << aNewId << "\n";
3393 else if (anOp == "del")
3397 di << "Please also provide as argument id of z layer to remove\n";
3401 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3402 if (!aViewer->RemoveZLayer (aDelId))
3404 di << "Impossible to remove the z layer or invalid id!\n";
3408 di << "Z layer " << aDelId << " has been removed\n";
3410 else if (anOp == "get")
3412 TColStd_SequenceOfInteger anIds;
3413 aViewer->GetAllZLayers (anIds);
3414 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3416 di << anIds.Value (aSeqIdx) << " ";
3421 else if (anOp == "settings")
3425 di << "Please also provide an id\n";
3429 Standard_Integer anId = Draw::Atoi (argv[2]);
3430 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
3432 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
3433 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
3434 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
3435 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
3438 else if (anOp == "enable")
3442 di << "Please also provide an option to enable\n";
3448 di << "Please also provide a layer id\n";
3452 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
3453 Standard_Integer anId = Draw::Atoi (argv[3]);
3454 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
3456 if (aSubOp == "depthtest" || aSubOp == "test")
3458 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
3460 else if (aSubOp == "depthwrite" || aSubOp == "write")
3462 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
3464 else if (aSubOp == "depthclear" || aSubOp == "clear")
3466 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
3468 else if (aSubOp == "depthoffset" || aSubOp == "offset")
3472 di << "Please also provide a factor and units values for depth offset\n";
3473 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
3477 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
3478 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
3479 anId = Draw::Atoi (argv[5]);
3480 aSettings = aViewer->ZLayerSettings (anId);
3482 aSettings.DepthOffsetFactor = aFactor;
3483 aSettings.DepthOffsetUnits = aUnits;
3485 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
3487 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
3489 aSettings.SetDepthOffsetPositive();
3491 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
3493 aSettings.SetDepthOffsetNegative();
3496 aViewer->SetZLayerSettings (anId, aSettings);
3498 else if (anOp == "disable")
3502 di << "Please also provide an option to disable\n";
3508 di << "Please also provide a layer id\n";
3512 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
3513 Standard_Integer anId = Draw::Atoi (argv[3]);
3514 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
3516 if (aSubOp == "depthtest" || aSubOp == "test")
3518 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
3520 else if (aSubOp == "depthwrite" || aSubOp == "write")
3522 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
3524 else if (aSubOp == "depthclear" || aSubOp == "clear")
3526 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
3528 else if (aSubOp == "depthoffset" || aSubOp == "offset")
3530 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
3533 aViewer->SetZLayerSettings (anId, aSettings);
3537 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
3544 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3546 // this class provides a presentation of text item in v3d view under-/overlayer
3547 class V3d_TextItem : public Visual3d_LayerItem
3552 DEFINE_STANDARD_RTTI(V3d_TextItem)
3555 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3556 const Standard_Real theX1,
3557 const Standard_Real theY1,
3558 const Standard_Real theHeight,
3559 const TCollection_AsciiString& theFontName,
3560 const Quantity_Color& theColor,
3561 const Quantity_Color& theSubtitleColor,
3562 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3563 const Handle(Visual3d_Layer)& theLayer);
3566 Standard_EXPORT void RedrawLayerPrs();
3572 TCollection_AsciiString myText;
3573 Standard_Real myHeight;
3574 Handle(Visual3d_Layer) myLayer;
3575 Quantity_Color myColor;
3576 Quantity_Color mySubtitleColor;
3577 Aspect_TypeOfDisplayText myType;
3578 TCollection_AsciiString myFontName;
3581 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3582 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3584 // create and add to display the text item
3585 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3586 const Standard_Real theX1,
3587 const Standard_Real theY1,
3588 const Standard_Real theHeight,
3589 const TCollection_AsciiString& theFontName,
3590 const Quantity_Color& theColor,
3591 const Quantity_Color& theSubtitleColor,
3592 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3593 const Handle(Visual3d_Layer)& theLayer)
3594 : myX1 (theX1), myY1 (theY1),
3596 myHeight (theHeight),
3599 mySubtitleColor (theSubtitleColor),
3600 myType (theTypeOfDisplay),
3601 myFontName (theFontName)
3603 if (!myLayer.IsNull ())
3604 myLayer->AddLayerItem (this);
3608 void V3d_TextItem::RedrawLayerPrs ()
3610 if (myLayer.IsNull ())
3613 myLayer->SetColor (myColor);
3614 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3615 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3618 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3620 // The Visual3d_LayerItem line item for "vlayerline" command
3621 // it provides a presentation of line with user-defined
3622 // linewidth, linetype and transparency.
3623 class V3d_LineItem : public Visual3d_LayerItem
3627 DEFINE_STANDARD_RTTI(V3d_LineItem)
3630 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3631 Standard_Real X2, Standard_Real Y2,
3632 V3d_LayerMgrPointer theLayerMgr,
3633 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3634 Standard_Real theWidth = 0.5,
3635 Standard_Real theTransp = 1.0);
3638 Standard_EXPORT void RedrawLayerPrs();
3642 Standard_Real myX1, myY1, myX2, myY2;
3643 V3d_LayerMgrPointer myLayerMgr;
3644 Aspect_TypeOfLine myType;
3645 Standard_Real myWidth;
3646 Standard_Real myTransparency;
3649 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3650 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3652 // default constructor for line item
3653 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3654 Standard_Real X2, Standard_Real Y2,
3655 V3d_LayerMgrPointer theLayerMgr,
3656 Aspect_TypeOfLine theType,
3657 Standard_Real theWidth,
3658 Standard_Real theTransp) :
3659 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3660 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3662 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3663 myLayerMgr->Overlay()->AddLayerItem (this);
3667 void V3d_LineItem::RedrawLayerPrs ()
3669 Handle (Visual3d_Layer) aOverlay;
3672 aOverlay = myLayerMgr->Overlay();
3674 if (!aOverlay.IsNull())
3676 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3677 aOverlay->SetColor(aColor);
3678 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3679 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3680 aOverlay->BeginPolyline();
3681 aOverlay->AddVertex(myX1, myY1);
3682 aOverlay->AddVertex(myX2, myY2);
3683 aOverlay->ClosePrimitive();
3687 //=============================================================================
3688 //function : VLayerLine
3689 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3690 // : linewidth, transparency coefficient
3691 //============================================================================
3692 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3694 // get the active view
3695 Handle(V3d_View) aView = ViewerTest::CurrentView();
3698 di << "Call vinit before!\n";
3703 di << "Use: " << argv[0];
3704 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3705 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3706 di << " 0 - solid \n";
3707 di << " 1 - dashed \n";
3708 di << " 2 - dot \n";
3709 di << " 3 - dashdot\n";
3710 di << " transparency : { 0.0 - 1.0 } \n";
3711 di << " 0.0 - transparent\n";
3712 di << " 1.0 - visible \n";
3716 // get the input params
3717 Standard_Real X1 = Draw::Atof(argv[1]);
3718 Standard_Real Y1 = Draw::Atof(argv[2]);
3719 Standard_Real X2 = Draw::Atof(argv[3]);
3720 Standard_Real Y2 = Draw::Atof(argv[4]);
3722 Standard_Real aWidth = 0.5;
3723 Standard_Integer aType = 0;
3724 Standard_Real aTransparency = 1.0;
3728 aWidth = Draw::Atof(argv[5]);
3732 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3737 aTransparency = Draw::Atof(argv[7]);
3738 if (aTransparency < 0 || aTransparency > 1.0)
3739 aTransparency = 1.0;
3742 // select appropriate line type
3743 Aspect_TypeOfLine aLineType;
3747 aLineType = Aspect_TOL_DASH;
3751 aLineType = Aspect_TOL_DOT;
3755 aLineType = Aspect_TOL_DOTDASH;
3759 aLineType = Aspect_TOL_SOLID;
3762 // replace layer manager
3763 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3764 aView->SetLayerMgr(aMgr);
3767 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3773 aView->MustBeResized();
3779 //=======================================================================
3780 //function : VOverlayText
3781 //purpose : Test text displaying in view overlay
3782 //=======================================================================
3783 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3785 // get the active view
3786 Handle(V3d_View) aView = ViewerTest::CurrentView();
3789 di << "No active view. Please call vinit.\n";
3792 else if (argc < 4 || argc > 13)
3794 di << "Use: " << argv[0];
3795 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3796 di << "[background_color: R G B]\n";
3797 di << " height - pixel height of the text (default=10.0)\n";
3798 di << " font_name - name of font (default=courier)\n";
3799 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3800 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
3801 di << " background_color- R G B values used for subtitle and decal text\n";
3802 di << "(default=255.0 255.0 255.0)\n";
3806 TCollection_AsciiString aText (argv[1]);
3807 Standard_Real aPosX = Draw::Atof(argv[2]);
3808 Standard_Real aPosY = Draw::Atof(argv[3]);
3809 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3812 TCollection_AsciiString aFontName = "Courier";
3814 aFontName = TCollection_AsciiString (argv[5]);
3817 Quantity_Parameter aColorRed = 1.0;
3818 Quantity_Parameter aColorGreen = 1.0;
3819 Quantity_Parameter aColorBlue = 1.0;
3822 aColorRed = Draw::Atof (argv[6])/255.;
3823 aColorGreen = Draw::Atof (argv[7])/255.;
3824 aColorBlue = Draw::Atof (argv[8])/255.;
3828 TCollection_AsciiString aDispStr;
3830 aDispStr = TCollection_AsciiString (argv[9]);
3832 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3833 if (aDispStr.IsEqual ("subtitle"))
3834 aTextType = Aspect_TODT_SUBTITLE;
3835 else if (aDispStr.IsEqual ("decal"))
3836 aTextType = Aspect_TODT_DEKALE;
3837 else if (aDispStr.IsEqual ("blend"))
3838 aTextType = Aspect_TODT_BLEND;
3839 else if (aDispStr.IsEqual ("dimension"))
3840 aTextType = Aspect_TODT_DIMENSION;
3843 Quantity_Parameter aSubRed = 1.0;
3844 Quantity_Parameter aSubGreen = 1.0;
3845 Quantity_Parameter aSubBlue = 1.0;
3848 aSubRed = Draw::Atof (argv[10])/255.;
3849 aSubGreen = Draw::Atof (argv[11])/255.;
3850 aSubBlue = Draw::Atof (argv[12])/255.;
3853 // check fo current overlay
3854 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3855 if (anOverlay.IsNull ())
3857 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3858 anOverlay = aMgr->Overlay ();
3859 aView->SetLayerMgr (aMgr);
3862 Quantity_Color aTextColor (aColorRed, aColorGreen,
3863 aColorBlue, Quantity_TOC_RGB);
3864 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3865 aSubBlue, Quantity_TOC_RGB);
3868 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3869 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3872 aView->MustBeResized();
3878 //==============================================================================
3881 //==============================================================================
3883 static int VGrid (Draw_Interpretor& /*theDI*/,
3884 Standard_Integer theArgNb,
3885 const char** theArgVec)
3887 // get the active view
3888 Handle(V3d_View) aView = ViewerTest::CurrentView();
3889 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3890 if (aView.IsNull() || aViewer.IsNull())
3892 std::cerr << "No active view. Please call vinit.\n";
3896 Aspect_GridType aType = aViewer->GridType();
3897 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3899 Standard_Integer anIter = 1;
3900 for (; anIter < theArgNb; ++anIter)
3902 const char* aValue = theArgVec[anIter];
3905 aType = Aspect_GT_Rectangular;
3907 else if (*aValue == 'c')
3909 aType = Aspect_GT_Circular;
3911 else if (*aValue == 'l')
3913 aMode = Aspect_GDM_Lines;
3915 else if (*aValue == 'p')
3917 aMode = Aspect_GDM_Points;
3919 else if (strcmp (aValue, "off" ) == 0)
3921 aViewer->DeactivateGrid();
3930 Standard_Integer aTail = (theArgNb - anIter);
3933 aViewer->ActivateGrid (aType, aMode);
3936 else if (aTail != 2 && aTail != 5)
3938 std::cerr << "Incorrect arguments number! Usage:\n"
3939 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3943 Quantity_Length anOriginX, anOriginY;
3944 Quantity_PlaneAngle aRotAngle;
3945 if (aType == Aspect_GT_Rectangular)
3947 Quantity_Length aRStepX, aRStepY;
3948 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3950 anOriginX = Draw::Atof (theArgVec[anIter++]);
3951 anOriginY = Draw::Atof (theArgVec[anIter++]);
3954 aRStepX = Draw::Atof (theArgVec[anIter++]);
3955 aRStepY = Draw::Atof (theArgVec[anIter++]);
3956 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3958 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3959 aViewer->ActivateGrid (aType, aMode);
3961 else if (aType == Aspect_GT_Circular)
3963 Quantity_Length aRadiusStep;
3964 Standard_Integer aDivisionNumber;
3965 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3967 anOriginX = Draw::Atof (theArgVec[anIter++]);
3968 anOriginY = Draw::Atof (theArgVec[anIter++]);
3971 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3972 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3973 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3976 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3977 aViewer->ActivateGrid (aType, aMode);
3983 //==============================================================================
3986 //==============================================================================
3988 static int VFps (Draw_Interpretor& theDI,
3989 Standard_Integer theArgNb,
3990 const char** theArgVec)
3992 // get the active view
3993 Handle(V3d_View) aView = ViewerTest::CurrentView();
3996 std::cerr << "No active view. Please call vinit.\n";
4000 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
4003 std::cerr << "Incorrect arguments!\n";
4007 // the time is meaningless for first call
4008 // due to async OpenGl rendering
4011 // redraw view in loop to estimate average values
4014 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
4020 const Standard_Real aTime = aTimer.ElapsedTime();
4021 aTimer.OSD_Chronometer::Show (aCpu);
4023 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
4024 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
4026 // return statistics
4027 theDI << "FPS: " << aFpsAver << "\n"
4028 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
4033 //==============================================================================
4034 //function : VGlDebug
4036 //==============================================================================
4038 static int VGlDebug (Draw_Interpretor& theDI,
4039 Standard_Integer theArgNb,
4040 const char** theArgVec)
4044 Handle(V3d_View) aView = ViewerTest::CurrentView();
4047 std::cerr << "No active view. Please call vinit.\n";
4051 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
4052 "GL_ARB_debug_output");
4053 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
4054 theDI << (isActive ? "1" : "0");
4058 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
4062 //==============================================================================
4065 //==============================================================================
4067 static int VVbo (Draw_Interpretor& theDI,
4068 Standard_Integer theArgNb,
4069 const char** theArgVec)
4071 const Standard_Boolean toSet = (theArgNb > 1);
4072 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
4075 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
4079 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4080 if (aContextAIS.IsNull())
4084 std::cerr << "No active view!\n";
4088 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
4089 if (!aDriver.IsNull())
4093 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
4097 aDriver->ChangeOptions().vboDisable = toUseVbo;
4104 //==============================================================================
4107 //==============================================================================
4109 static int VCaps (Draw_Interpretor& theDI,
4110 Standard_Integer theArgNb,
4111 const char** theArgVec)
4113 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
4114 Handle(OpenGl_GraphicDriver) aDriver;
4115 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4116 if (!aContextAIS.IsNull())
4118 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
4119 aCaps = &aDriver->ChangeOptions();
4124 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
4125 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
4126 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
4130 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4132 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
4133 if (anArg.Search ("vbo=") > -1)
4135 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
4137 else if (anArg.Search ("sprites=") > -1)
4139 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
4141 else if (anArg.Search ("soft=") > -1)
4143 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
4147 std::cerr << "Unknown argument: " << anArg << "\n";
4150 if (aCaps != &ViewerTest_myDefaultCaps)
4152 ViewerTest_myDefaultCaps = *aCaps;
4157 //==============================================================================
4158 //function : VMemGpu
4160 //==============================================================================
4162 static int VMemGpu (Draw_Interpretor& theDI,
4163 Standard_Integer theArgNb,
4164 const char** theArgVec)
4167 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4168 if (aContextAIS.IsNull())
4170 std::cerr << "No active view. Please call vinit.\n";
4174 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
4175 if (aDriver.IsNull())
4177 std::cerr << "Graphic driver not available.\n";
4181 Standard_Size aFreeBytes = 0;
4182 TCollection_AsciiString anInfo;
4183 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
4185 std::cerr << "Information not available.\n";
4189 if (theArgNb > 1 && *theArgVec[1] == 'f')
4191 theDI << Standard_Real (aFreeBytes);
4201 // ==============================================================================
4202 // function : VReadPixel
4204 // ==============================================================================
4205 static int VReadPixel (Draw_Interpretor& theDI,
4206 Standard_Integer theArgNb,
4207 const char** theArgVec)
4209 // get the active view
4210 Handle(V3d_View) aView = ViewerTest::CurrentView();
4213 std::cerr << "No active view. Please call vinit.\n";
4216 else if (theArgNb < 3)
4218 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4222 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4223 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4225 Standard_Integer aWidth, aHeight;
4226 aView->Window()->Size (aWidth, aHeight);
4227 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4228 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4229 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4231 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4235 Standard_Boolean toShowName = Standard_False;
4236 Standard_Boolean toShowHls = Standard_False;
4237 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4239 const char* aParam = theArgVec[anIter];
4240 if ( strcasecmp( aParam, "rgb" ) == 0 )
4242 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4243 aBufferType = Graphic3d_BT_RGB;
4245 else if ( strcasecmp( aParam, "hls" ) == 0 )
4247 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4248 aBufferType = Graphic3d_BT_RGB;
4249 toShowHls = Standard_True;
4251 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4253 aFormat = Image_PixMap::ImgRGBF;
4254 aBufferType = Graphic3d_BT_RGB;
4256 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4258 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4259 aBufferType = Graphic3d_BT_RGBA;
4261 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4263 aFormat = Image_PixMap::ImgRGBAF;
4264 aBufferType = Graphic3d_BT_RGBA;
4266 else if ( strcasecmp( aParam, "depth" ) == 0 )
4268 aFormat = Image_PixMap::ImgGrayF;
4269 aBufferType = Graphic3d_BT_Depth;
4271 else if ( strcasecmp( aParam, "name" ) == 0 )
4273 toShowName = Standard_True;
4277 Image_PixMap anImage;
4278 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4280 std::cerr << "Image allocation failed\n";
4283 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4285 std::cerr << "Image dump failed\n";
4289 Quantity_Parameter anAlpha;
4290 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4293 if (aBufferType == Graphic3d_BT_RGBA)
4295 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
4299 theDI << Quantity_Color::StringName (aColor.Name());
4304 switch (aBufferType)
4307 case Graphic3d_BT_RGB:
4311 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
4315 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
4319 case Graphic3d_BT_RGBA:
4321 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
4324 case Graphic3d_BT_Depth:
4326 theDI << aColor.Red();
4335 //==============================================================================
4336 //function : VDiffImage
4337 //purpose : The draw-command compares two images.
4338 //==============================================================================
4340 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4344 theDI << "Not enough arguments.\n";
4349 const char* anImgPathRef = theArgVec[1];
4350 const char* anImgPathNew = theArgVec[2];
4352 // get string tolerance and check its validity
4353 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4354 if (aTolColor < 0.0)
4356 if (aTolColor > 1.0)
4359 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4360 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4362 // image file of difference
4363 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4365 // compare the images
4366 Image_Diff aComparer;
4367 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4372 aComparer.SetColorTolerance (aTolColor);
4373 aComparer.SetBorderFilterOn (isBorderFilterOn);
4374 Standard_Integer aDiffColorsNb = aComparer.Compare();
4375 theDI << aDiffColorsNb << "\n";
4377 // save image of difference
4378 if (aDiffImagePath != NULL)
4380 aComparer.SaveDiffImage (aDiffImagePath);
4386 //=======================================================================
4387 //function : VSelect
4388 //purpose : Emulates different types of selection by mouse:
4389 // 1) single click selection
4390 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4391 // 3) selection with polygon having corners at
4392 // pixel positions (x1,y1),...,(xn,yn)
4393 // 4) any of these selections with shift button pressed
4394 //=======================================================================
4395 static Standard_Integer VSelect (Draw_Interpretor& di,
4396 Standard_Integer argc,
4401 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4405 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4406 if(myAIScontext.IsNull())
4408 di << "use 'vinit' command before " << argv[0] << "\n";
4411 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4412 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4413 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4416 if(isShiftSelection)
4417 aCurrentEventManager->ShiftSelect();
4419 aCurrentEventManager->Select();
4423 if(isShiftSelection)
4424 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4426 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4430 Standard_Integer anUpper = 0;
4432 if(isShiftSelection)
4433 anUpper = (argc-1)/2;
4436 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4438 for(Standard_Integer i=1;i<=anUpper;++i)
4439 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4441 if(isShiftSelection)
4442 aCurrentEventManager->ShiftSelect(aPolyline);
4444 aCurrentEventManager->Select(aPolyline);
4449 //=======================================================================
4450 //function : VMoveTo
4451 //purpose : Emulates cursor movement to defined pixel position
4452 //=======================================================================
4453 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4454 Standard_Integer argc,
4459 di << "Usage : " << argv[0] << " x y" << "\n";
4463 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4464 if(aContext.IsNull())
4466 di << "use 'vinit' command before " << argv[0] << "\n";
4469 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4473 //=================================================================================================
4474 //function : VViewParams
4475 //purpose : Gets or sets AIS View characteristics
4476 //=================================================================================================
4477 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4479 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
4480 if (anAISView.IsNull())
4482 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
4488 // print all of the available view parameters
4489 Quantity_Factor anAISViewScale = anAISView->Scale();
4491 Standard_Real anAISViewProjX = 0.0;
4492 Standard_Real anAISViewProjY = 0.0;
4493 Standard_Real anAISViewProjZ = 0.0;
4494 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4496 Standard_Real anAISViewUpX = 0.0;
4497 Standard_Real anAISViewUpY = 0.0;
4498 Standard_Real anAISViewUpZ = 0.0;
4499 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4501 Standard_Real anAISViewAtX = 0.0;
4502 Standard_Real anAISViewAtY = 0.0;
4503 Standard_Real anAISViewAtZ = 0.0;
4504 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4506 Standard_Real anAISViewEyeX = 0.0;
4507 Standard_Real anAISViewEyeY = 0.0;
4508 Standard_Real anAISViewEyeZ = 0.0;
4509 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
4511 theDi << "Scale of current view: " << anAISViewScale << "\n";
4512 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4513 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4514 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4515 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
4519 // -------------------------
4520 // Parse options and values
4521 // -------------------------
4523 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
4524 TCollection_AsciiString aParseKey;
4525 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4527 TCollection_AsciiString anArg (theArgVec [anArgIt]);
4529 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4532 aParseKey.Remove (1);
4533 aParseKey.UpperCase();
4534 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4538 if (aParseKey.IsEmpty())
4540 std::cout << theArgVec[0] << ": values should be passed with key.\n";
4541 std::cout << "Type help for more information.\n";
4545 aMapOfKeysByValues(aParseKey)->Append (anArg);
4548 // ---------------------------------------------
4549 // Change or print parameters, order plays role
4550 // ---------------------------------------------
4552 // Check arguments for validity
4553 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
4554 for (; aMapIt.More(); aMapIt.Next())
4556 const TCollection_AsciiString& aKey = aMapIt.Key();
4557 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
4559 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
4560 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
4561 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
4562 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
4563 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
4564 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
4565 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
4567 TCollection_AsciiString aLowerKey;
4570 aLowerKey.LowerCase();
4571 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
4572 std::cout << "Type help for more information.\n";
4577 Handle(TColStd_HSequenceOfAsciiString) aValues;
4579 // Change view parameters in proper order
4580 if (aMapOfKeysByValues.Find ("SCALE", aValues))
4582 if (aValues->IsEmpty())
4584 theDi << "Scale: " << anAISView->Scale() << "\n";
4588 anAISView->SetScale (aValues->Value(1).RealValue());
4591 if (aMapOfKeysByValues.Find ("SIZE", aValues))
4593 if (aValues->IsEmpty())
4595 Standard_Real aSizeX = 0.0;
4596 Standard_Real aSizeY = 0.0;
4597 anAISView->Size (aSizeX, aSizeY);
4598 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
4602 anAISView->SetSize (aValues->Value(1).RealValue());
4605 if (aMapOfKeysByValues.Find ("EYE", aValues))
4607 if (aValues->IsEmpty())
4609 Standard_Real anEyeX = 0.0;
4610 Standard_Real anEyeY = 0.0;
4611 Standard_Real anEyeZ = 0.0;
4612 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
4613 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
4617 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4620 if (aMapOfKeysByValues.Find ("AT", aValues))
4622 if (aValues->IsEmpty())
4624 Standard_Real anAtX = 0.0;
4625 Standard_Real anAtY = 0.0;
4626 Standard_Real anAtZ = 0.0;
4627 anAISView->At (anAtX, anAtY, anAtZ);
4628 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
4632 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4635 if (aMapOfKeysByValues.Find ("PROJ", aValues))
4637 if (aValues->IsEmpty())
4639 Standard_Real aProjX = 0.0;
4640 Standard_Real aProjY = 0.0;
4641 Standard_Real aProjZ = 0.0;
4642 anAISView->Proj (aProjX, aProjY, aProjZ);
4643 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
4647 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4650 if (aMapOfKeysByValues.Find ("UP", aValues))
4652 if (aValues->IsEmpty())
4654 Standard_Real anUpX = 0.0;
4655 Standard_Real anUpY = 0.0;
4656 Standard_Real anUpZ = 0.0;
4657 anAISView->Up (anUpX, anUpY, anUpZ);
4658 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
4662 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4665 if (aMapOfKeysByValues.Find ("CENTER", aValues))
4667 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
4673 //=======================================================================
4674 //function : VChangeSelected
4675 //purpose : Adds the shape to selection or remove one from it
4676 //=======================================================================
4677 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4678 Standard_Integer argc,
4683 di<<"Usage : " << argv[0] << " shape \n";
4687 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4688 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4689 TCollection_AsciiString aName(argv[1]);
4690 Handle(AIS_InteractiveObject) anAISObject;
4692 if(!aMap.IsBound2(aName))
4694 di<<"Use 'vdisplay' before";
4699 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4700 if(anAISObject.IsNull()){
4701 di<<"No interactive object \n";
4705 if(aContext->HasOpenedContext())
4707 aContext->AddOrRemoveSelected(anAISObject);
4711 aContext->AddOrRemoveCurrentObject(anAISObject);
4717 //=======================================================================
4718 //function : VZClipping
4719 //purpose : Gets or sets ZClipping mode, width and depth
4720 //=======================================================================
4721 static Standard_Integer VZClipping (Draw_Interpretor& di,
4722 Standard_Integer argc,
4727 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4728 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4731 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4732 if(aContext.IsNull())
4734 di << "use 'vinit' command before " << argv[0] << "\n";
4737 Handle(V3d_View) aView = ViewerTest::CurrentView();
4738 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4741 TCollection_AsciiString aZClippingModeString;
4742 Quantity_Length aDepth, aWidth;
4743 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4744 switch (aZClippingMode)
4747 aZClippingModeString.Copy("OFF");
4750 aZClippingModeString.Copy("BACK");
4753 aZClippingModeString.Copy("FRONT");
4756 aZClippingModeString.Copy("SLICE");
4759 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4762 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4763 << "ZClipping depth = " << aDepth << "\n"
4764 << "ZClipping width = " << aWidth << "\n";
4770 Standard_Integer aStatus = 0;
4771 if ( strcmp (argv [1], "OFF") == 0 ) {
4773 aZClippingMode = V3d_OFF;
4775 if ( strcmp (argv [1], "BACK") == 0 ) {
4777 aZClippingMode = V3d_BACK;
4779 if ( strcmp (argv [1], "FRONT") == 0 ) {
4781 aZClippingMode = V3d_FRONT;
4783 if ( strcmp (argv [1], "SLICE") == 0 ) {
4785 aZClippingMode = V3d_SLICE;
4789 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4790 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4793 aView->SetZClippingType(aZClippingMode);
4797 Quantity_Length aDepth = 0., aWidth = 1.;
4800 aDepth = atof(argv[1]);
4801 aWidth = atof(argv[2]);
4805 aDepth = atof(argv[2]);
4806 aWidth = atof(argv[3]);
4809 if(aDepth<0. || aDepth>1.)
4811 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4812 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4815 if(aWidth<0. || aWidth>1.)
4817 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4818 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4822 aView->SetZClippingDepth(aDepth);
4823 aView->SetZClippingWidth(aWidth);
4830 //=======================================================================
4831 //function : VNbSelected
4832 //purpose : Returns number of selected objects
4833 //=======================================================================
4834 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4835 Standard_Integer argc,
4840 di << "Usage : " << argv[0] << "\n";
4843 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4844 if(aContext.IsNull())
4846 di << "use 'vinit' command before " << argv[0] << "\n";
4849 di << aContext->NbSelected() << "\n";
4853 //=======================================================================
4854 //function : VAntialiasing
4855 //purpose : Switches altialiasing on or off
4856 //=======================================================================
4857 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4858 Standard_Integer argc,
4863 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4867 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4868 if(aContext.IsNull())
4870 di << "use 'vinit' command before " << argv[0] << "\n";
4874 Handle(V3d_View) aView = ViewerTest::CurrentView();
4876 if((argc == 2) && (atof(argv[1]) == 0))
4877 aView->SetAntialiasingOff();
4879 aView->SetAntialiasingOn();
4884 //=======================================================================
4885 //function : VPurgeDisplay
4886 //purpose : Switches altialiasing on or off
4887 //=======================================================================
4888 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4889 Standard_Integer argc,
4894 di << "Usage : " << argv[0] << "\n";
4897 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4898 if (aContext.IsNull())
4900 di << "use 'vinit' command before " << argv[0] << "\n";
4903 aContext->CloseAllContexts(Standard_False);
4904 di << aContext->PurgeDisplay() << "\n";
4908 //=======================================================================
4909 //function : VSetViewSize
4911 //=======================================================================
4912 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4913 Standard_Integer argc,
4916 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4917 if(aContext.IsNull())
4919 di << "use 'vinit' command before " << argv[0] << "\n";
4924 di<<"Usage : " << argv[0] << " Size\n";
4927 Standard_Real aSize = atof(argv[1]);
4930 di<<"Bad Size value : " << aSize << "\n";
4934 Handle(V3d_View) aView = ViewerTest::CurrentView();
4935 aView->SetSize(aSize);
4939 //=======================================================================
4940 //function : VMoveView
4942 //=======================================================================
4943 static Standard_Integer VMoveView (Draw_Interpretor& di,
4944 Standard_Integer argc,
4947 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4948 if(aContext.IsNull())
4950 di << "use 'vinit' command before " << argv[0] << "\n";
4953 if(argc < 4 || argc > 5)
4955 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4958 Standard_Real Dx = atof(argv[1]);
4959 Standard_Real Dy = atof(argv[2]);
4960 Standard_Real Dz = atof(argv[3]);
4961 Standard_Boolean aStart = Standard_True;
4964 aStart = (atoi(argv[4]) > 0);
4967 Handle(V3d_View) aView = ViewerTest::CurrentView();
4968 aView->Move(Dx,Dy,Dz,aStart);
4972 //=======================================================================
4973 //function : VTranslateView
4975 //=======================================================================
4976 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4977 Standard_Integer argc,
4980 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4981 if(aContext.IsNull())
4983 di << "use 'vinit' command before " << argv[0] << "\n";
4986 if(argc < 4 || argc > 5)
4988 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4991 Standard_Real Dx = atof(argv[1]);
4992 Standard_Real Dy = atof(argv[2]);
4993 Standard_Real Dz = atof(argv[3]);
4994 Standard_Boolean aStart = Standard_True;
4997 aStart = (atoi(argv[4]) > 0);
5000 Handle(V3d_View) aView = ViewerTest::CurrentView();
5001 aView->Translate(Dx,Dy,Dz,aStart);
5005 //=======================================================================
5006 //function : VTurnView
5008 //=======================================================================
5009 static Standard_Integer VTurnView (Draw_Interpretor& di,
5010 Standard_Integer argc,
5013 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5014 if(aContext.IsNull()) {
5015 di << "use 'vinit' command before " << argv[0] << "\n";
5018 if(argc < 4 || argc > 5){
5019 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
5022 Standard_Real Ax = atof(argv[1]);
5023 Standard_Real Ay = atof(argv[2]);
5024 Standard_Real Az = atof(argv[3]);
5025 Standard_Boolean aStart = Standard_True;
5028 aStart = (atoi(argv[4]) > 0);
5031 Handle(V3d_View) aView = ViewerTest::CurrentView();
5032 aView->Turn(Ax,Ay,Az,aStart);
5036 //==============================================================================
5037 //function : VTextureEnv
5038 //purpose : ENables or disables environment mapping
5039 //==============================================================================
5040 class OCC_TextureEnv : public Graphic3d_TextureEnv
5043 OCC_TextureEnv(const Standard_CString FileName);
5044 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
5045 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
5046 const Standard_Boolean theModulateFlag,
5047 const Graphic3d_TypeOfTextureFilter theFilter,
5048 const Standard_ShortReal theXScale,
5049 const Standard_ShortReal theYScale,
5050 const Standard_ShortReal theXShift,
5051 const Standard_ShortReal theYShift,
5052 const Standard_ShortReal theAngle);
5053 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
5055 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
5056 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
5057 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
5059 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
5060 : Graphic3d_TextureEnv(theFileName)
5064 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
5065 : Graphic3d_TextureEnv(theTexId)
5069 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
5070 const Standard_Boolean theModulateFlag,
5071 const Graphic3d_TypeOfTextureFilter theFilter,
5072 const Standard_ShortReal theXScale,
5073 const Standard_ShortReal theYScale,
5074 const Standard_ShortReal theXShift,
5075 const Standard_ShortReal theYShift,
5076 const Standard_ShortReal theAngle)
5078 myParams->SetRepeat (theRepeatFlag);
5079 myParams->SetModulate (theModulateFlag);
5080 myParams->SetFilter (theFilter);
5081 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
5082 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
5083 myParams->SetRotation (theAngle);
5086 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
5088 // get the active view
5089 Handle(V3d_View) aView = ViewerTest::CurrentView();
5092 std::cerr << "No active view. Please call vinit.\n";
5096 // Checking the input arguments
5097 Standard_Boolean anEnableFlag = Standard_False;
5098 Standard_Boolean isOk = theArgNb >= 2;
5101 TCollection_AsciiString anEnableOpt(theArgVec[1]);
5102 anEnableFlag = anEnableOpt.IsEqual("on");
5103 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
5107 isOk = (theArgNb == 3 || theArgNb == 11);
5110 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5111 isOk = (!aTextureOpt.IsIntegerValue() ||
5112 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
5114 if (isOk && theArgNb == 11)
5116 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
5117 aModulateOpt(theArgVec[4]),
5118 aFilterOpt (theArgVec[5]),
5119 aSScaleOpt (theArgVec[6]),
5120 aTScaleOpt (theArgVec[7]),
5121 aSTransOpt (theArgVec[8]),
5122 aTTransOpt (theArgVec[9]),
5123 anAngleOpt (theArgVec[10]);
5124 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
5125 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
5126 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
5127 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
5128 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
5129 anAngleOpt.IsRealValue());
5136 std::cerr << "Usage :" << std::endl;
5137 std::cerr << theArgVec[0] << " off" << std::endl;
5138 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;
5144 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5145 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
5146 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
5147 new OCC_TextureEnv(theArgVec[2]);
5151 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
5152 aTexEnv->SetTextureParameters(
5153 aRepeatOpt. IsEqual("repeat"),
5154 aModulateOpt.IsEqual("modulate"),
5155 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
5156 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
5157 Graphic3d_TOTF_TRILINEAR,
5158 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
5159 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
5160 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
5161 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
5162 (Standard_ShortReal)Draw::Atof(theArgVec[10])
5165 aView->SetTextureEnv(aTexEnv);
5166 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
5168 else // Disabling environment mapping
5170 aView->SetSurfaceDetail(V3d_TEX_NONE);
5171 Handle(Graphic3d_TextureEnv) aTexture;
5172 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
5179 //===============================================================================================
5180 //function : VClipPlane
5182 //===============================================================================================
5183 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5185 // use short-cut for created clip planes map of created (or "registered by name") clip planes
5186 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
5187 static MapOfPlanes aRegPlanes;
5191 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
5195 TCollection_AsciiString aCommand (theArgVec[1]);
5197 // print maximum number of planes for current viewer
5198 if (aCommand == "maxplanes")
5202 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
5206 TCollection_AsciiString aViewName (theArgVec[2]);
5208 if (!ViewerTest_myViews.IsBound1 (aViewName))
5210 theDi << theArgVec[0] << ": view is not found.\n";
5214 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5216 theDi << theArgVec[0] << ": "
5217 << aView->Viewer()->Driver()->InquirePlaneLimit()
5218 << " plane slots provided by driver."
5219 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
5224 // create / delete plane instance
5225 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
5229 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
5233 Standard_Boolean toCreate = (aCommand == "create");
5234 Standard_Boolean toClone = (aCommand == "clone");
5235 TCollection_AsciiString aPlane (theArgVec[2]);
5239 if (aRegPlanes.IsBound (aPlane))
5241 theDi << theArgVec[0] << ": plane name is in use.\n";
5245 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
5247 else if (toClone) // toClone
5249 if (!aRegPlanes.IsBound (aPlane))
5251 theDi << theArgVec[0] << ": no such plane.\n";
5257 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
5261 TCollection_AsciiString aClone (theArgVec[3]);
5262 if (aRegPlanes.IsBound (aClone))
5264 theDi << theArgVec[0] << ": plane name is in use.\n";
5268 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5270 aRegPlanes.Bind (aClone, aClipPlane->Clone());
5274 if (!aRegPlanes.IsBound (aPlane))
5276 theDi << theArgVec[0] << ": no such plane.\n";
5280 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
5281 aRegPlanes.UnBind (aPlane);
5283 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
5284 for (; anIObjIt.More(); anIObjIt.Next())
5286 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
5287 aPrs->RemoveClipPlane(aClipPlane);
5290 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
5291 for (; aViewIt.More(); aViewIt.Next())
5293 const Handle(V3d_View)& aView = aViewIt.Key2();
5294 aView->RemoveClipPlane(aClipPlane);
5297 ViewerTest::RedrawAllViews();
5303 // set / unset plane command
5304 if (aCommand == "set" || aCommand == "unset")
5308 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5312 Standard_Boolean toSet = (aCommand == "set");
5313 TCollection_AsciiString aPlane (theArgVec [2]);
5314 if (!aRegPlanes.IsBound (aPlane))
5316 theDi << theArgVec[0] << ": no such plane.\n";
5320 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5322 TCollection_AsciiString aTarget (theArgVec [3]);
5323 if (aTarget != "object" && aTarget != "view")
5325 theDi << theArgVec[0] << ": invalid target.\n";
5329 if (aTarget == "object" || aTarget == "view")
5333 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5337 Standard_Boolean isObject = (aTarget == "object");
5339 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
5341 TCollection_AsciiString anEntityName (theArgVec[anIt]);
5342 if (isObject) // to object
5344 if (!GetMapOfAIS().IsBound2 (anEntityName))
5346 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
5350 Handle(AIS_InteractiveObject) aIObj =
5351 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
5354 aIObj->AddClipPlane (aClipPlane);
5356 aIObj->RemoveClipPlane (aClipPlane);
5360 if (!ViewerTest_myViews.IsBound1 (anEntityName))
5362 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
5366 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
5368 aView->AddClipPlane (aClipPlane);
5370 aView->RemoveClipPlane (aClipPlane);
5374 ViewerTest::RedrawAllViews();
5380 // change plane command
5381 if (aCommand == "change")
5385 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5389 TCollection_AsciiString aPlane (theArgVec [2]);
5390 if (!aRegPlanes.IsBound (aPlane))
5392 theDi << theArgVec[0] << ": no such plane.\n";
5396 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5398 TCollection_AsciiString aChangeArg (theArgVec [3]);
5399 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5401 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5405 if (aChangeArg == "on" || aChangeArg == "off") // on / off
5407 aClipPlane->SetOn (aChangeArg == "on");
5409 else if (aChangeArg == "equation") // change equation
5413 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5417 Standard_Real aCoeffA = atof (theArgVec [4]);
5418 Standard_Real aCoeffB = atof (theArgVec [5]);
5419 Standard_Real aCoeffC = atof (theArgVec [6]);
5420 Standard_Real aCoeffD = atof (theArgVec [7]);
5421 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5423 else if (aChangeArg == "capping") // change capping aspects
5427 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5431 TCollection_AsciiString aCappingArg (theArgVec [4]);
5432 if (aCappingArg != "on" && aCappingArg != "off" &&
5433 aCappingArg != "color" && aCappingArg != "texname" &&
5434 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5435 aCappingArg != "texrotate" && aCappingArg != "hatch")
5437 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5441 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5443 aClipPlane->SetCapping (aCappingArg == "on");
5445 else if (aCappingArg == "color") // color aspect for capping
5449 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5453 Standard_Real aRed = atof (theArgVec [5]);
5454 Standard_Real aGrn = atof (theArgVec [6]);
5455 Standard_Real aBlu = atof (theArgVec [7]);
5457 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5458 aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
5459 aClipPlane->SetCappingMaterial (aMat);
5461 else if (aCappingArg == "texname") // texture name
5465 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5469 TCollection_AsciiString aTextureName (theArgVec [5]);
5471 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5472 if (!aTexture->IsDone ())
5474 aClipPlane->SetCappingTexture (NULL);
5478 aTexture->EnableModulate();
5479 aTexture->EnableRepeat();
5480 aClipPlane->SetCappingTexture (aTexture);
5483 else if (aCappingArg == "texscale") // texture scale
5485 if (aClipPlane->CappingTexture().IsNull())
5487 theDi << theArgVec[0] << ": no texture is set.\n";
5493 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5497 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5498 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5500 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5502 else if (aCappingArg == "texorigin") // texture origin
5504 if (aClipPlane->CappingTexture().IsNull())
5506 theDi << theArgVec[0] << ": no texture is set.\n";
5512 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5516 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5517 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5519 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5521 else if (aCappingArg == "texrotate") // texture rotation
5523 if (aClipPlane->CappingTexture().IsNull())
5525 theDi << theArgVec[0] << ": no texture is set.\n";
5531 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5535 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5537 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5539 else if (aCappingArg == "hatch") // hatch style
5543 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5547 TCollection_AsciiString aHatchStr (theArgVec [5]);
5548 if (aHatchStr == "on")
5550 aClipPlane->SetCappingHatchOn();
5552 else if (aHatchStr == "off")
5554 aClipPlane->SetCappingHatchOff();
5558 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5563 ViewerTest::RedrawAllViews();
5568 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5572 //===============================================================================================
5573 //function : VSetTextureMode
5575 //===============================================================================================
5576 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5580 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5584 TCollection_AsciiString aViewName (theArgVec[1]);
5585 if (!ViewerTest_myViews.IsBound1 (aViewName))
5587 theDi << theArgVec[0] << ": view is not found.\n";
5591 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5592 switch (atoi (theArgVec[2]))
5594 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5595 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5596 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5598 theDi << theArgVec[0] << ": invalid mode.\n";
5606 //===============================================================================================
5607 //function : VZRange
5609 //===============================================================================================
5610 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5612 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
5614 if (aCurrentView.IsNull())
5616 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
5620 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
5624 theDi << "ZNear: " << aCamera->ZNear() << "\n";
5625 theDi << "ZFar: " << aCamera->ZFar() << "\n";
5631 Standard_Real aNewZNear = atof (theArgVec[1]);
5632 Standard_Real aNewZFar = atof (theArgVec[2]);
5634 if (aNewZNear >= aNewZFar)
5636 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
5640 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
5642 std::cout << theArgVec[0] << ": invalid arguments: ";
5643 std::cout << "znear, zfar should be positive for perspective camera.\n";
5647 aCamera->SetZRange (aNewZNear, aNewZFar);
5651 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
5655 aCurrentView->Redraw();
5660 //===============================================================================================
5661 //function : VAutoZFit
5663 //===============================================================================================
5664 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5666 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
5668 if (aCurrentView.IsNull())
5670 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
5674 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
5678 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
5684 theDi << "Auto z-fit mode: " << "\n"
5685 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
5686 << "Scale: " << aScale << "\n";
5690 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
5694 aScale = Draw::Atoi (theArgVec[2]);
5697 aCurrentView->SetAutoZFitMode (isOn, aScale);
5698 aCurrentView->AutoZFit();
5699 aCurrentView->Redraw();
5704 //===============================================================================================
5705 //function : VChangeCamera
5707 //===============================================================================================
5708 static int VChangeCamera (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5710 if (ViewerTest::CurrentView().IsNull())
5712 theDi << theArgVec[0] << ": Call vinit before this command, please.\n";
5716 const char anErrorMessage[] = ": wrong command arguments. Type help for more information.\n";
5719 theDi << theArgVec[0] << anErrorMessage;
5723 Handle(Graphic3d_Camera) aCamera = ViewerTest::CurrentView()->Camera();
5725 TCollection_AsciiString aCommand (theArgVec[1]);
5726 TCollection_AsciiString aValue (theArgVec[2]);
5728 aCommand.LowerCase();
5731 if (aCommand == "proj")
5733 if (aValue == "ortho")
5735 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
5737 else if (aValue == "persp")
5739 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
5741 else if (aValue == "left")
5743 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
5745 else if (aValue == "right")
5747 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
5749 else if (aValue == "stereo")
5751 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
5755 theDi << theArgVec[0] << anErrorMessage;
5759 else if (aCommand == "dist")
5761 aCamera->SetDistance (aValue.RealValue());
5763 else if (aCommand == "iod")
5765 aCamera->SetIOD (aCamera->GetIODType(), aValue.RealValue());
5767 else if (aCommand == "zfocus")
5769 aCamera->SetZFocus (aCamera->ZFocusType(), aValue.RealValue());
5771 else if (aCommand == "fov")
5773 aCamera->SetFOVy (aValue.RealValue());
5775 else if (aCommand == "zfocustype")
5777 if (aValue == "absolute")
5779 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
5781 else if (aValue == "relative")
5783 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
5787 theDi << theArgVec[0] << anErrorMessage;
5791 else if (aCommand == "iodtype")
5793 if (aValue == "absolute")
5795 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
5797 else if (aValue == "relative")
5799 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
5803 theDi << theArgVec[0] << anErrorMessage;
5809 theDi << theArgVec[0] << anErrorMessage;
5813 ViewerTest::CurrentView()->AutoZFit();
5814 ViewerTest::CurrentView()->Redraw();
5819 //==============================================================================
5820 //function : VStereo
5822 //==============================================================================
5824 static int VStereo (Draw_Interpretor& theDI,
5825 Standard_Integer theArgNb,
5826 const char** theArgVec)
5830 Handle(V3d_View) aView = ViewerTest::CurrentView();
5833 std::cerr << "No active view. Please call vinit.\n";
5837 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
5838 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
5842 ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0;
5846 //===============================================================================================
5847 //function : VDefaults
5849 //===============================================================================================
5850 static int VDefaults (Draw_Interpretor& theDi,
5851 Standard_Integer theArgsNb,
5852 const char** theArgVec)
5854 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5857 std::cerr << "No active viewer!\n";
5861 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
5864 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
5866 theDi << "DeflType: relative\n"
5867 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
5871 theDi << "DeflType: absolute\n"
5872 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
5874 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
5878 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5880 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5881 TCollection_AsciiString aKey, aValue;
5882 if (!ViewerTest::SplitParameter (anArg, aKey, aValue)
5883 || aValue.IsEmpty())
5885 std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
5890 if (aKey == "ABSDEFL"
5891 || aKey == "ABSOLUTEDEFLECTION"
5893 || aKey == "DEFLECTION")
5895 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
5896 aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
5898 else if (aKey == "RELDEFL"
5899 || aKey == "RELATIVEDEFLECTION"
5900 || aKey == "DEVCOEFF"
5901 || aKey == "DEVIATIONCOEFF"
5902 || aKey == "DEVIATIONCOEFFICIENT")
5904 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
5905 aDefParams->SetDeviationCoefficient (aValue.RealValue());
5907 else if (aKey == "ANGDEFL"
5908 || aKey == "ANGULARDEFL"
5909 || aKey == "ANGULARDEFLECTION")
5911 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
5912 aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
5916 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
5923 //! Auxiliary method
5924 inline void addLight (const Handle(V3d_Light)& theLightNew,
5925 const Standard_Boolean theIsGlobal)
5927 if (theLightNew.IsNull())
5934 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
5938 ViewerTest::CurrentView()->SetLightOn (theLightNew);
5942 //! Auxiliary method
5943 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
5945 TCollection_AsciiString anArgNextCase (theArgNext);
5946 anArgNextCase.UpperCase();
5947 if (anArgNextCase.Length() > 5
5948 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
5950 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
5954 return theArgNext.IntegerValue();
5958 //===============================================================================================
5961 //===============================================================================================
5962 static int VLight (Draw_Interpretor& theDi,
5963 Standard_Integer theArgsNb,
5964 const char** theArgVec)
5966 Handle(V3d_View) aView = ViewerTest::CurrentView();
5967 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5969 || aViewer.IsNull())
5971 std::cerr << "No active viewer!\n";
5975 Standard_Real anXYZ[3];
5976 Quantity_Coefficient anAtten[2];
5979 // print lights info
5980 Standard_Integer aLightId = 0;
5981 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
5983 Handle(V3d_Light) aLight = aView->ActiveLight();
5984 const Quantity_Color aColor = aLight->Color();
5985 theDi << "Light" << aLightId << "\n";
5986 switch (aLight->Type())
5990 theDi << " Type: Ambient\n";
5993 case V3d_DIRECTIONAL:
5995 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
5996 theDi << " Type: Directional\n";
5997 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5998 if (!aLightDir.IsNull())
6000 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6001 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6002 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
6003 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6007 case V3d_POSITIONAL:
6009 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
6010 theDi << " Type: Positional\n";
6011 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
6012 if (!aLightPos.IsNull())
6014 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6015 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6016 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6017 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
6023 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
6024 theDi << " Type: Spot\n";
6025 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
6026 if (!aLightSpot.IsNull())
6028 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6029 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6030 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
6031 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6032 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6033 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
6034 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
6035 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
6041 theDi << " Type: UNKNOWN\n";
6045 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
6049 Handle(V3d_Light) aLightNew;
6050 Handle(V3d_Light) aLightOld;
6051 Standard_Boolean isGlobal = Standard_True;
6052 Standard_Boolean toCreate = Standard_False;
6053 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
6055 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
6056 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
6057 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
6058 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
6059 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
6061 TCollection_AsciiString aName, aValue;
6062 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
6063 TCollection_AsciiString anArgCase (anArg);
6064 anArgCase.UpperCase();
6065 if (anArgCase.IsEqual ("NEW")
6066 || anArgCase.IsEqual ("ADD")
6067 || anArgCase.IsEqual ("CREATE"))
6069 toCreate = Standard_True;
6071 else if (anArgCase.IsEqual ("GLOB")
6072 || anArgCase.IsEqual ("GLOBAL"))
6074 isGlobal = Standard_True;
6076 else if (anArgCase.IsEqual ("LOC")
6077 || anArgCase.IsEqual ("LOCAL"))
6079 isGlobal = Standard_False;
6081 else if (anArgCase.IsEqual ("DEF")
6082 || anArgCase.IsEqual ("DEFAULTS"))
6084 toCreate = Standard_False;
6085 aViewer->SetDefaultLights();
6087 else if (anArgCase.IsEqual ("CLR")
6088 || anArgCase.IsEqual ("CLEAR"))
6090 toCreate = Standard_False;
6091 aView->InitActiveLights();
6092 while (aView->MoreActiveLights())
6094 aViewer->DelLight (aView->ActiveLight());
6095 aView->InitActiveLights();
6098 else if (anArgCase.IsEqual ("AMB")
6099 || anArgCase.IsEqual ("AMBIENT")
6100 || anArgCase.IsEqual ("AMBLIGHT"))
6102 addLight (aLightNew, isGlobal);
6105 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6108 toCreate = Standard_False;
6109 aLightNew = new V3d_AmbientLight (aViewer);
6111 else if (anArgCase.IsEqual ("DIRECTIONAL")
6112 || anArgCase.IsEqual ("DIRLIGHT"))
6114 addLight (aLightNew, isGlobal);
6117 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6120 toCreate = Standard_False;
6121 aLightNew = new V3d_DirectionalLight (aViewer);
6123 else if (anArgCase.IsEqual ("SPOT")
6124 || anArgCase.IsEqual ("SPOTLIGHT"))
6126 addLight (aLightNew, isGlobal);
6129 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6132 toCreate = Standard_False;
6133 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
6135 else if (anArgCase.IsEqual ("POSLIGHT")
6136 || anArgCase.IsEqual ("POSITIONAL"))
6138 addLight (aLightNew, isGlobal);
6141 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6144 toCreate = Standard_False;
6145 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
6147 else if (anArgCase.IsEqual ("CHANGE"))
6149 addLight (aLightNew, isGlobal);
6150 aLightNew.Nullify();
6151 if (++anArgIt >= theArgsNb)
6153 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6157 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
6158 Standard_Integer aLightIt = 0;
6159 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6161 if (aLightIt == aLightId)
6163 aLightOld = aView->ActiveLight();
6168 if (aLightOld.IsNull())
6170 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
6174 else if (anArgCase.IsEqual ("DEL")
6175 || anArgCase.IsEqual ("DELETE"))
6177 Handle(V3d_Light) aLightDel;
6178 if (++anArgIt >= theArgsNb)
6180 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6184 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6185 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
6186 Standard_Integer aLightIt = 0;
6187 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6189 aLightDel = aView->ActiveLight();
6190 if (aLightIt == aLightDelId)
6195 if (!aLightDel.IsNull())
6197 aViewer->DelLight (aLightDel);
6200 else if (anArgCase.IsEqual ("COLOR")
6201 || anArgCase.IsEqual ("COLOUR"))
6203 if (++anArgIt >= theArgsNb)
6205 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6209 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6210 anArgNext.UpperCase();
6211 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
6212 if (!aLightCurr.IsNull())
6214 aLightCurr->SetColor (aColor);
6217 else if (anArgCase.IsEqual ("POS")
6218 || anArgCase.IsEqual ("POSITION"))
6220 if ((anArgIt + 3) >= theArgsNb)
6222 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6226 anXYZ[0] = Atof (theArgVec[++anArgIt]);
6227 anXYZ[1] = Atof (theArgVec[++anArgIt]);
6228 anXYZ[2] = Atof (theArgVec[++anArgIt]);
6229 if (!aLightDir.IsNull())
6231 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6233 else if (!aLightPos.IsNull())
6235 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6237 else if (!aLightSpot.IsNull())
6239 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6243 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6247 else if (anArgCase.IsEqual ("DIR")
6248 || anArgCase.IsEqual ("DIRECTION"))
6250 if ((anArgIt + 3) >= theArgsNb)
6252 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6256 anXYZ[0] = Atof (theArgVec[++anArgIt]);
6257 anXYZ[1] = Atof (theArgVec[++anArgIt]);
6258 anXYZ[2] = Atof (theArgVec[++anArgIt]);
6259 if (!aLightDir.IsNull())
6261 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
6263 else if (!aLightSpot.IsNull())
6265 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
6269 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6273 else if (anArgCase.IsEqual ("ANG")
6274 || anArgCase.IsEqual ("ANGLE"))
6276 if (++anArgIt >= theArgsNb)
6278 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6282 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
6284 if (!aLightSpot.IsNull())
6286 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
6289 else if (anArgCase.IsEqual ("CONSTATTEN")
6290 || anArgCase.IsEqual ("CONSTATTENUATION"))
6292 if (++anArgIt >= theArgsNb)
6294 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6298 if (!aLightPos.IsNull())
6300 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6301 anAtten[0] = Atof (theArgVec[anArgIt]);
6302 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
6304 else if (!aLightSpot.IsNull())
6306 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6307 anAtten[0] = Atof (theArgVec[anArgIt]);
6308 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
6312 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6316 else if (anArgCase.IsEqual ("LINATTEN")
6317 || anArgCase.IsEqual ("LINEARATTEN")
6318 || anArgCase.IsEqual ("LINEARATTENUATION"))
6320 if (++anArgIt >= theArgsNb)
6322 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6326 if (!aLightPos.IsNull())
6328 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6329 anAtten[1] = Atof (theArgVec[anArgIt]);
6330 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
6332 else if (!aLightSpot.IsNull())
6334 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6335 anAtten[1] = Atof (theArgVec[anArgIt]);
6336 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
6340 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6344 else if (anArgCase.IsEqual ("EXP")
6345 || anArgCase.IsEqual ("EXPONENT")
6346 || anArgCase.IsEqual ("SPOTEXP")
6347 || anArgCase.IsEqual ("SPOTEXPONENT"))
6349 if (++anArgIt >= theArgsNb)
6351 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6355 if (!aLightSpot.IsNull())
6357 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
6361 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6365 else if (anArgCase.IsEqual ("HEAD")
6366 || anArgCase.IsEqual ("HEADLIGHT"))
6368 if (++anArgIt >= theArgsNb)
6370 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6374 if (aLightAmb.IsNull()
6375 && !aLightCurr.IsNull())
6377 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
6381 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6387 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
6391 addLight (aLightNew, isGlobal);
6392 aViewer->UpdateLights();
6397 inline Standard_Boolean parseOnOff (Standard_CString theArg,
6398 Standard_Boolean& theIsOn)
6400 TCollection_AsciiString aFlag (theArg);
6404 theIsOn = Standard_True;
6405 return Standard_True;
6407 else if (aFlag == "off")
6409 theIsOn = Standard_False;
6410 return Standard_True;
6412 return Standard_False;
6415 //=======================================================================
6416 //function : VRenderParams
6417 //purpose : Enables/disables rendering features
6418 //=======================================================================
6420 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
6421 Standard_Integer theArgNb,
6422 const char** theArgVec)
6424 Handle(V3d_View) aView = ViewerTest::CurrentView();
6427 std::cerr << "Error: no active viewer!\n";
6431 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
6435 theDI << "renderMode: ";
6436 switch (aParams.Method)
6438 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
6439 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
6442 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
6443 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
6444 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
6445 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
6446 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
6450 Standard_Boolean toPrint = Standard_False;
6451 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6453 Standard_CString anArg (theArgVec[anArgIter]);
6454 TCollection_AsciiString aFlag (anArg);
6456 if (aFlag == "-echo"
6457 || aFlag == "-print")
6459 toPrint = Standard_True;
6461 else if (aFlag == "-mode"
6462 || aFlag == "-rendermode"
6463 || aFlag == "-render_mode")
6467 switch (aParams.Method)
6469 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
6470 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
6476 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
6480 else if (aFlag == "-ray"
6481 || aFlag == "-raytrace")
6485 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
6489 aParams.Method = Graphic3d_RM_RAYTRACING;
6491 else if (aFlag == "-rast"
6492 || aFlag == "-raster"
6493 || aFlag == "-rasterization")
6497 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
6501 aParams.Method = Graphic3d_RM_RASTERIZATION;
6503 else if (aFlag == "-raydepth"
6504 || aFlag == "-ray_depth")
6508 theDI << aParams.RaytracingDepth << " ";
6511 else if (++anArgIter >= theArgNb)
6513 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
6517 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
6518 if (aDepth < 1 || aDepth > 10)
6520 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
6525 aParams.RaytracingDepth = aDepth;
6528 else if (aFlag == "-shad"
6529 || aFlag == "-shadows")
6533 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
6537 Standard_Boolean toEnable = Standard_True;
6538 if (++anArgIter < theArgNb
6539 && !parseOnOff (theArgVec[anArgIter], toEnable))
6543 aParams.IsShadowEnabled = toEnable;
6545 else if (aFlag == "-refl"
6546 || aFlag == "-reflections")
6550 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
6554 Standard_Boolean toEnable = Standard_True;
6555 if (++anArgIter < theArgNb
6556 && !parseOnOff (theArgVec[anArgIter], toEnable))
6560 aParams.IsReflectionEnabled = toEnable;
6562 else if (aFlag == "-fsaa")
6566 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
6570 Standard_Boolean toEnable = Standard_True;
6571 if (++anArgIter < theArgNb
6572 && !parseOnOff (theArgVec[anArgIter], toEnable))
6576 aParams.IsAntialiasingEnabled = toEnable;
6578 else if (aFlag == "-gleam")
6582 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
6586 Standard_Boolean toEnable = Standard_True;
6587 if (++anArgIter < theArgNb
6588 && !parseOnOff (theArgVec[anArgIter], toEnable))
6592 aParams.IsTransparentShadowEnabled = toEnable;
6596 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
6605 //=======================================================================
6606 //function : VFrustumCulling
6607 //purpose : enables/disables view volume's culling.
6608 //=======================================================================
6609 static int VFrustumCulling (Draw_Interpretor& theDI,
6610 Standard_Integer theArgNb,
6611 const char** theArgVec)
6613 Handle(V3d_View) aView = ViewerTest::CurrentView();
6616 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
6622 theDI << (aView->IsCullingEnabled() ? "on" : "off");
6625 else if (theArgNb != 2)
6627 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
6631 TCollection_AsciiString aModeStr (theArgVec[1]);
6632 aModeStr.LowerCase();
6633 Standard_Boolean toEnable = 0;
6634 if (aModeStr == "on")
6638 else if (aModeStr == "off")
6644 toEnable = Draw::Atoi (theArgVec[1]) != 0;
6647 aView->SetFrustumCulling (toEnable);
6652 //=======================================================================
6653 //function : ViewerCommands
6655 //=======================================================================
6657 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
6660 const char *group = "ZeViewer";
6661 theCommands.Add("vinit",
6662 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
6663 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
6665 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
6667 " - Creates new View window with specified name view_name.\n"
6668 "By default the new view is created in the viewer and in"
6669 " graphic driver shared with active view.\n"
6670 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
6671 "If driverName isn't specified the driver will be shared with active view.\n"
6672 "If viewerName isn't specified the viewer will be shared with active view.\n"
6673 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
6674 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
6675 "is used in creation of graphic driver\n"
6677 " - l, t: pixel position of left top corner of the window\n"
6678 " - w,h: width and heigth of window respectively.\n"
6679 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
6680 __FILE__,VInit,group);
6681 theCommands.Add("vclose" ,
6682 "[view_id [keep_context=0|1]]\n"
6683 "or vclose ALL - to remove all created views\n"
6684 " - removes view(viewer window) defined by its view_id.\n"
6685 " - keep_context: by default 0; if 1 and the last view is deleted"
6686 " the current context is not removed.",
6687 __FILE__,VClose,group);
6688 theCommands.Add("vactivate" ,
6690 " - activates view(viewer window) defined by its view_id",
6691 __FILE__,VActivate,group);
6692 theCommands.Add("vviewlist",
6693 "vviewlist [format={tree, long}]"
6694 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
6695 " - format: format of result output, if tree the output is a tree view;"
6696 "otherwise it's a list of full view names. By default format = tree",
6697 __FILE__,VViewList,group);
6698 theCommands.Add("vhelp" ,
6699 "vhelp : display help on the viewer commands",
6700 __FILE__,VHelp,group);
6701 theCommands.Add("vtop" ,
6702 "vtop or <T> : Top view" ,
6703 __FILE__,VTop,group);
6704 theCommands.Add("vbottom" ,
6705 "vbottom : Bottom view" ,
6706 __FILE__,VBottom,group);
6707 theCommands.Add("vleft" ,
6708 "vleft : Left view" ,
6709 __FILE__,VLeft,group);
6710 theCommands.Add("vright" ,
6711 "vright : Right view" ,
6712 __FILE__,VRight,group);
6713 theCommands.Add("vaxo" ,
6714 " vaxo or <A> : Axonometric view ",
6715 __FILE__,VAxo,group);
6716 theCommands.Add("vfront" ,
6717 "vfront : Front view" ,
6718 __FILE__,VFront,group);
6719 theCommands.Add("vback" ,
6720 "vback : Back view" ,
6721 __FILE__,VBack,group);
6722 theCommands.Add("vpick" ,
6723 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
6725 theCommands.Add("vfit" ,
6726 "vfit or <F> : vfit",
6727 __FILE__,VFit,group);
6728 theCommands.Add ("vzfit", "vzfit [scale]\n"
6729 " Matches Z near, Z far view volume planes to the displayed objects.\n"
6730 " \"scale\" - specifies factor to scale computed z range.\n",
6731 __FILE__, VZFit, group);
6732 theCommands.Add("vrepaint",
6733 "vrepaint : vrepaint, force redraw",
6734 __FILE__,VRepaint,group);
6735 theCommands.Add("vclear",
6737 __FILE__,VClear,group);
6738 theCommands.Add("vsetbg",
6739 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
6740 __FILE__,VSetBg,group);
6741 theCommands.Add("vsetbgmode",
6742 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
6743 __FILE__,VSetBgMode,group);
6744 theCommands.Add("vsetgradientbg",
6745 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
6746 __FILE__,VSetGradientBg,group);
6747 theCommands.Add("vsetgrbgmode",
6748 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
6749 __FILE__,VSetGradientBgMode,group);
6750 theCommands.Add("vsetcolorbg",
6751 "vsetcolorbg : vsetcolorbg r g b : Set background color",
6752 __FILE__,VSetColorBg,group);
6753 theCommands.Add("vscale",
6754 "vscale : vscale X Y Z",
6755 __FILE__,VScale,group);
6756 theCommands.Add("vzbufftrihedron",
6757 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
6758 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
6759 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
6760 __FILE__,VTestZBuffTrihedron,group);
6761 theCommands.Add("vrotate",
6762 "vrotate : vrotate AX AY AZ [X Y Z]",
6763 __FILE__,VRotate,group);
6764 theCommands.Add("vzoom",
6765 "vzoom : vzoom coef",
6766 __FILE__,VZoom,group);
6767 theCommands.Add("vpan",
6768 "vpan : vpan dx dy",
6769 __FILE__,VPan,group);
6770 theCommands.Add("vexport",
6771 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
6772 " : exports the view to a vector file of a given format"
6773 " : notice that EMF format requires patched gl2ps",
6774 __FILE__,VExport,group);
6775 theCommands.Add("vcolorscale",
6776 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
6777 __FILE__,VColorScale,group);
6778 theCommands.Add("vgraduatedtrihedron",
6779 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
6780 __FILE__,VGraduatedTrihedron,group);
6781 theCommands.Add("vprintview" ,
6782 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
6783 __FILE__,VPrintView,group);
6784 theCommands.Add("vzlayer",
6785 "vzlayer add/del/get/settings/enable/disable [id]\n"
6786 " add - add new z layer to viewer and print its id\n"
6787 " del - del z layer by its id\n"
6788 " get - print sequence of z layers in increasing order of their overlay level\n"
6789 " settings - print status of z layer settings\n"
6790 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
6791 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
6792 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
6793 "\nWhere id is the layer identificator\n"
6796 " vzlayer enable poffset 1\n"
6797 " vzlayer disable depthtest 1\n"
6799 __FILE__,VZLayer,group);
6800 theCommands.Add("voverlaytext",
6801 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
6802 " : height - pixel height of the text (default=10.0)"
6803 " : font_name - name of font (default=courier)"
6804 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
6805 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
6806 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
6807 __FILE__,VOverlayText,group);
6808 theCommands.Add("vlayerline",
6809 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
6810 __FILE__,VLayerLine,group);
6811 theCommands.Add ("vgrid",
6812 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
6813 " : Mode - rectangular or circular"
6814 " : Type - lines or points",
6815 __FILE__, VGrid, group);
6816 theCommands.Add ("vfps",
6817 "vfps [framesNb=100] : estimate average frame rate for active view",
6818 __FILE__, VFps, group);
6819 theCommands.Add ("vgldebug",
6820 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
6821 " : this function is implemented only for Windows\n"
6822 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
6823 __FILE__, VGlDebug, group);
6824 theCommands.Add ("vvbo",
6825 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
6826 __FILE__, VVbo, group);
6827 theCommands.Add ("vstereo",
6828 "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects",
6829 __FILE__, VStereo, group);
6830 theCommands.Add ("vcaps",
6831 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
6832 __FILE__, VCaps, group);
6833 theCommands.Add ("vmemgpu",
6834 "vmemgpu [f]: print system-dependent GPU memory information if available;"
6835 " with f option returns free memory in bytes",
6836 __FILE__, VMemGpu, group);
6837 theCommands.Add ("vreadpixel",
6838 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
6839 " : Read pixel value for active view",
6840 __FILE__, VReadPixel, group);
6841 theCommands.Add("diffimage",
6842 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
6843 __FILE__, VDiffImage, group);
6844 theCommands.Add ("vselect",
6845 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
6846 "- emulates different types of selection:\n"
6847 "- 1) single click selection\n"
6848 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
6849 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
6850 "- 4) any of these selections with shift button pressed",
6851 __FILE__, VSelect, group);
6852 theCommands.Add ("vmoveto",
6854 "- emulates cursor movement to pixel postion (x,y)",
6855 __FILE__, VMoveTo, group);
6856 theCommands.Add ("vviewparams", "vviewparams usage:\n"
6858 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
6859 " [-proj [x y z]] [-center x y] [-size sx]\n"
6860 "- Gets or sets current view parameters.\n"
6861 "- If called without arguments, all view parameters are printed.\n"
6862 "- The options are:\n"
6863 " -scale [s] : prints or sets viewport relative scale.\n"
6864 " -eye [x y z] : prints or sets eye location.\n"
6865 " -at [x y z] : prints or sets center of look.\n"
6866 " -up [x y z] : prints or sets direction of up vector.\n"
6867 " -proj [x y z] : prints or sets direction of look.\n"
6868 " -center x y : sets location of center of the screen in pixels.\n"
6869 " -size [sx] : prints viewport projection width and height sizes\n"
6870 " : or changes the size of its maximum dimension.\n",
6871 __FILE__, VViewParams, group);
6872 theCommands.Add("vchangeselected",
6873 "vchangeselected shape"
6874 "- adds to shape to selection or remove one from it",
6875 __FILE__, VChangeSelected, group);
6876 theCommands.Add("vzclipping",
6877 "vzclipping [mode] [depth width]\n"
6878 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
6879 "- gets or sets ZClipping mode, width and depth",
6880 __FILE__,VZClipping,group);
6881 theCommands.Add ("vnbselected",
6882 "vnbselected", __FILE__, VNbSelected, group);
6883 theCommands.Add ("vchangecamera",
6884 " changes camera parameters \n"
6885 "- vchangecamera [param_type] [value]\n"
6886 "- vchangecamera proj {ortho/persp/left/right/stereo}\n"
6887 " Projection type including left and right stereo parts.\n"
6888 "- vchangecamera dist [real]\n"
6889 " Sets distance from target point to camera eye (moving eye).\n"
6890 "- vchangecamera iod [real]\n"
6891 " Intraocular distance value.\n"
6892 "- vchangecamera zfocus [real]\n"
6893 " Stereographic focus value.\n"
6894 "- vchangecamera fov [real]\n"
6895 " Field Of View value (in degrees).\n"
6896 "- vchangecamera zfocustype {absolute/relative}\n"
6897 " Stereographic focus definition type (absolute value or coefficient).\n"
6898 "- vchangecamera iodtype {absolute/relative}\n"
6899 " Intraocular distance definition type (absolute value or coefficient).\n",
6900 __FILE__, VChangeCamera, group);
6901 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
6902 "- vautozfit [on={1|0}] [scale]\n"
6903 " Prints or changes parameters of automatic z-fit mode:\n"
6904 " \"on\" - turns automatic z-fit on or off\n"
6905 " \"scale\" - specifies factor to scale computed z range.\n",
6906 __FILE__, VAutoZFit, group);
6907 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
6908 " vzrange - without parameters shows current values\n"
6909 " vzrange [znear] [zfar] - applies provided values to view",
6910 __FILE__,VZRange, group);
6911 theCommands.Add("vantialiasing",
6912 "vantialiasing 1|0",
6913 __FILE__,VAntialiasing,group);
6914 theCommands.Add ("vpurgedisplay",
6916 "- removes structures which don't belong to objects displayed in neutral point",
6917 __FILE__, VPurgeDisplay, group);
6918 theCommands.Add("vsetviewsize",
6919 "vsetviewsize size",
6920 __FILE__,VSetViewSize,group);
6921 theCommands.Add("vmoveview",
6922 "vmoveview Dx Dy Dz [Start = 1|0]",
6923 __FILE__,VMoveView,group);
6924 theCommands.Add("vtranslateview",
6925 "vtranslateview Dx Dy Dz [Start = 1|0)]",
6926 __FILE__,VTranslateView,group);
6927 theCommands.Add("vturnview",
6928 "vturnview Ax Ay Az [Start = 1|0]",
6929 __FILE__,VTurnView,group);
6930 theCommands.Add("vtextureenv",
6931 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
6932 "or user-defined file and optionally applying texture mapping parameters\n"
6934 " vtextureenv off - disables environment mapping\n"
6935 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
6936 " std_texture = (0..7)\n"
6937 " rep = {clamp|repeat}\n"
6938 " mod = {decal|modulate}\n"
6939 " flt = {nearest|bilinear|trilinear}\n"
6940 " ss, st - scale factors for s and t texture coordinates\n"
6941 " ts, tt - translation for s and t texture coordinates\n"
6942 " rot - texture rotation angle in degrees",
6943 __FILE__, VTextureEnv, group);
6944 theCommands.Add("vhlr" ,
6945 "is_enabled={on|off} [show_hidden={1|0}]"
6946 " - Hidden line removal algorithm:"
6947 " - is_enabled: if is on HLR algorithm is applied\n"
6948 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
6949 __FILE__,VHLR,group);
6950 theCommands.Add("vhlrtype" ,
6951 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
6952 " - Changes the type of HLR algorithm using for shapes."
6953 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
6954 " if equals to polyalgo, polygonal HLR algorithm is applied."
6955 "If shapes are not given HLR algoithm of given type is applied"
6956 " to all shapes in the view\n",
6957 __FILE__,VHLRType,group);
6958 theCommands.Add("vclipplane", "vclipplane usage: \n"
6959 " maxplanes <view_name> - get plane limit for view.\n"
6960 " create <plane_name> - create new plane.\n"
6961 " delete <plane_name> - delete plane.\n"
6962 " clone <source_plane> <plane_name> - clone the plane definition.\n"
6963 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
6964 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
6965 " change <plane_name> on/off - turn clipping on/off.\n"
6966 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
6967 " change <plane_name> capping on/off - turn capping on/off.\n"
6968 " change <plane_name> capping color <r> <g> <b> - set color.\n"
6969 " change <plane name> capping texname <texture> - set texture.\n"
6970 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
6971 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
6972 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
6973 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
6974 " please use VSetTextureMode command to enable texture rendering in view.\n"
6975 , __FILE__, VClipPlane, group);
6976 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
6978 " 0 - no textures enabled in view.\n"
6979 " 1 - only environment textures enabled.\n"
6980 " 2 - all textures enabled.\n"
6981 " this command sets texture details mode for the specified view.\n"
6982 , __FILE__, VSetTextureMode, group);
6983 theCommands.Add("vdefaults",
6984 "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
6985 __FILE__, VDefaults, group);
6986 theCommands.Add("vlight",
6987 "tool to manage light sources, without arguments shows list of lights."
6988 "\n Main commands: "
6989 "\n 'clear' to clear lights"
6990 "\n '{def}aults' to load deafault lights"
6991 "\n 'add' (or 'new') <type> to add any light source"
6992 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
6993 "\n 'change' <lightId> to edit light source with specified lightId"
6994 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
6995 "\n {pos}ition X Y Z"
6996 "\n {dir}ection X Y Z (for directional light or for spotlight)"
6997 "\n color colorName"
6998 "\n {head}light 0|1"
6999 "\n {constAtten}uation value"
7000 "\n {linearAtten}uation value"
7002 "\n {spotexp}onent value"
7004 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
7005 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
7006 __FILE__, VLight, group);
7007 theCommands.Add("vrenderparams",
7008 "\n Manages rendering parameters: "
7009 "\n '-rayTrace' Enables GPU ray-tracing"
7010 "\n '-raster' Disables GPU ray-tracing"
7011 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
7012 "\n '-shadows on|off' Enables/disables shadows rendering"
7013 "\n '-reflections on|off' Enables/disables specular reflections"
7014 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
7015 "\n '-gleam on|off' Enables/disables transparency shadow effects",
7016 __FILE__, VRenderParams, group);
7017 theCommands.Add("vfrustumculling",
7018 "vfrustumculling [toEnable]: enables/disables objects clipping",
7019 __FILE__,VFrustumCulling,group);