1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <OpenGl_GlCore20.hxx>
18 #include <AIS_Shape.hxx>
19 #include <AIS_Drawer.hxx>
20 #include <AIS_InteractiveObject.hxx>
21 #include <AIS_ListOfInteractive.hxx>
22 #include <AIS_ListIteratorOfListOfInteractive.hxx>
24 #include <Graphic3d_AspectMarker3d.hxx>
25 #include <Graphic3d_ExportFormat.hxx>
26 #include <Graphic3d_NameOfTextureEnv.hxx>
27 #include <Graphic3d_TextureEnv.hxx>
28 #include <Graphic3d_TextureParams.hxx>
29 #include <Graphic3d_TypeOfTextureFilter.hxx>
30 #include <Graphic3d_AspectFillArea3d.hxx>
31 #include <ViewerTest.hxx>
32 #include <ViewerTest_EventManager.hxx>
33 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
34 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
35 #include <Visual3d_View.hxx>
36 #include <Visual3d_ViewManager.hxx>
37 #include <V3d_AmbientLight.hxx>
38 #include <V3d_DirectionalLight.hxx>
39 #include <V3d_LayerMgr.hxx>
40 #include <V3d_LayerMgrPointer.hxx>
41 #include <V3d_PositionalLight.hxx>
42 #include <V3d_SpotLight.hxx>
43 #include <NCollection_DoubleMap.hxx>
44 #include <NCollection_List.hxx>
45 #include <NCollection_Vector.hxx>
46 #include <NIS_View.hxx>
47 #include <NIS_Triangulated.hxx>
48 #include <NIS_InteractiveContext.hxx>
49 #include <AIS_InteractiveContext.hxx>
50 #include <Draw_Interpretor.hxx>
52 #include <Draw_Appli.hxx>
53 #include <Aspect_PrintAlgo.hxx>
54 #include <Image_AlienPixMap.hxx>
55 #include <OpenGl_GraphicDriver.hxx>
56 #include <OSD_Timer.hxx>
57 #include <TColStd_HSequenceOfAsciiString.hxx>
58 #include <TColStd_SequenceOfInteger.hxx>
59 #include <TColStd_HSequenceOfReal.hxx>
60 #include <TColgp_Array1OfPnt2d.hxx>
61 #include <TColStd_MapOfAsciiString.hxx>
62 #include <Visual3d_LayerItem.hxx>
63 #include <Aspect_TypeOfLine.hxx>
64 #include <Image_Diff.hxx>
65 #include <Aspect_DisplayConnection.hxx>
69 #include <PrsMgr_PresentableObject.hxx>
70 #include <Graphic3d_ClipPlane.hxx>
71 #include <NCollection_DataMap.hxx>
72 #include <Graphic3d_Texture2Dmanual.hxx>
73 #include <Prs3d_ShadingAspect.hxx>
79 #include <Visual3d_Layer.hxx>
83 #include <WNT_WClass.hxx>
84 #include <WNT_Window.hxx>
87 #define _CRT_SECURE_NO_DEPRECATE
88 #pragma warning (disable:4996)
90 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
91 #include <Cocoa_Window.hxx>
93 #include <Xw_Window.hxx>
94 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
95 #include <X11/Xutil.h>
99 // Auxiliary definitions
100 static const char THE_KEY_DELETE = 127;
102 //==============================================================================
103 // VIEWER GLOBAL VARIABLES
104 //==============================================================================
106 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
107 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
109 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
110 extern const Handle(NIS_InteractiveContext)& TheNISContext();
111 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
113 extern int VErase (Draw_Interpretor& theDI,
114 Standard_Integer theArgNb,
115 const char** theArgVec);
118 static Handle(WNT_Window)& VT_GetWindow() {
119 static Handle(WNT_Window) WNTWin;
122 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
123 static Handle(Cocoa_Window)& VT_GetWindow()
125 static Handle(Cocoa_Window) aWindow;
128 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
129 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
130 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
133 static Handle(Xw_Window)& VT_GetWindow(){
134 static Handle(Xw_Window) XWWin;
138 static void VProcessEvents(ClientData,int);
141 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
143 static Handle(Aspect_DisplayConnection) aDisplayConnection;
144 return aDisplayConnection;
147 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
149 GetDisplayConnection() = theDisplayConnection;
152 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
153 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
155 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
157 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
158 if (!aWindow.IsNull())
159 return aWindow->HWindow();
160 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
161 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
162 if (!aWindow.IsNull())
163 return aWindow->XWindow();
165 return aWindowHandle;
169 static Standard_Boolean MyHLRIsOn = Standard_False;
171 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
172 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
173 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
174 static OpenGl_Caps ViewerTest_myDefaultCaps;
176 #define ZCLIPWIDTH 1.
178 static void OSWindowSetup();
180 //==============================================================================
181 // EVENT GLOBAL VARIABLES
182 //==============================================================================
184 static int Start_Rot = 0;
185 static int ZClipIsOn = 0;
186 int X_Motion = 0; // Current cursor position
188 int X_ButtonPress = 0; // Last ButtonPress position
189 int Y_ButtonPress = 0;
190 Standard_Boolean IsDragged = Standard_False;
191 Standard_Boolean DragFirst = Standard_False;
193 //==============================================================================
196 static LRESULT WINAPI ViewerWindowProc(
201 static LRESULT WINAPI AdvViewerWindowProc(
209 //==============================================================================
212 //==============================================================================
214 const Handle(MMgt_TShared)& ViewerTest::WClass()
216 static Handle(MMgt_TShared) theWClass;
218 if (theWClass.IsNull())
220 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
221 CS_VREDRAW | CS_HREDRAW, 0, 0,
222 ::LoadCursor (NULL, IDC_ARROW));
228 //==============================================================================
229 //function : CreateName
230 //purpose : Create numerical name for new object in theMap
231 //==============================================================================
232 template <typename ObjectType>
233 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
234 const TCollection_AsciiString& theDefaultString)
236 if (theObjectMap.IsEmpty())
237 return theDefaultString + TCollection_AsciiString(1);
239 Standard_Integer aNextKey = 1;
240 Standard_Boolean isFound = Standard_False;
243 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
244 // Look for objects with default names
245 if (theObjectMap.IsBound1(aStringKey))
250 isFound = Standard_True;
253 return theDefaultString + TCollection_AsciiString(aNextKey);
256 //==============================================================================
257 //structure : ViewerTest_Names
258 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
259 //==============================================================================
260 struct ViewerTest_Names
263 TCollection_AsciiString myDriverName;
264 TCollection_AsciiString myViewerName;
265 TCollection_AsciiString myViewName;
269 const TCollection_AsciiString& GetDriverName () const
273 void SetDriverName (const TCollection_AsciiString& theDriverName)
275 myDriverName = theDriverName;
277 const TCollection_AsciiString& GetViewerName () const
281 void SetViewerName (const TCollection_AsciiString& theViewerName)
283 myViewerName = theViewerName;
285 const TCollection_AsciiString& GetViewName () const
289 void SetViewName (const TCollection_AsciiString& theViewName)
291 myViewName = theViewName;
294 //===========================================================================
295 //function : Constructor for ViewerTest_Names
296 //purpose : Get view, viewer, driver names from custom string
297 //===========================================================================
299 ViewerTest_Names (const TCollection_AsciiString& theInputString)
301 TCollection_AsciiString aName(theInputString);
302 if (theInputString.IsEmpty())
304 // Get current configuration
305 if (ViewerTest_myDrivers.IsEmpty())
306 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
307 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
309 myDriverName = ViewerTest_myDrivers.Find2
310 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
312 if(ViewerTest_myContexts.IsEmpty())
314 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
315 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
318 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
320 myViewName = CreateName <Handle(V3d_View)>
321 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
325 // There is at least view name
326 Standard_Integer aParserNumber = 0;
327 for (Standard_Integer i = 0; i < 3; ++i)
329 Standard_Integer aParserPos = aName.SearchFromEnd("/");
333 aName.Split(aParserPos-1);
338 if (aParserNumber == 0)
341 if (!ViewerTest::GetAISContext().IsNull())
343 myDriverName = ViewerTest_myDrivers.Find2
344 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
345 myViewerName = ViewerTest_myContexts.Find2
346 (ViewerTest::GetAISContext());
350 // There is no opened contexts here, need to create names for viewer and driver
351 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
352 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
354 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
355 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
357 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
359 else if (aParserNumber == 1)
361 // Here is viewerName/viewName
362 if (!ViewerTest::GetAISContext().IsNull())
363 myDriverName = ViewerTest_myDrivers.Find2
364 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
367 // There is no opened contexts here, need to create name for driver
368 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
369 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
371 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
373 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
377 //Here is driverName/viewerName/viewName
378 myDriverName = TCollection_AsciiString(aName);
380 TCollection_AsciiString aViewerName(theInputString);
381 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
382 myViewerName = TCollection_AsciiString(aViewerName);
384 myViewName = TCollection_AsciiString(theInputString);
390 //==============================================================================
391 //function : FindContextByView
392 //purpose : Find AIS_InteractiveContext by View
393 //==============================================================================
395 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
397 Handle(AIS_InteractiveContext) anAISContext;
399 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
400 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
402 if (anIter.Value()->CurrentViewer() == theView->Viewer())
403 return anIter.Key2();
409 //==============================================================================
410 //function : SetWindowTitle
411 //purpose : Set window title
412 //==============================================================================
414 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
415 Standard_CString theTitle)
418 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
420 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
421 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
423 if(GetDisplayConnection()->GetDisplay())
426 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
427 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
432 //==============================================================================
433 //function : IsWindowOverlapped
434 //purpose : Check if theWindow overlapp another view
435 //==============================================================================
437 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
438 const Standard_Integer thePxTop,
439 const Standard_Integer thePxRight,
440 const Standard_Integer thePxBottom,
441 TCollection_AsciiString& theViewId)
443 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
444 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
446 Standard_Integer aTop = 0,
450 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
451 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
452 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
453 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
454 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
456 theViewId = anIter.Key1();
457 return Standard_True;
460 return Standard_False;
463 // Workaround: to create and delete non-orthographic views outside ViewerTest
464 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
466 ViewerTest_myViews.UnBind1 (theName);
469 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
470 const Handle(V3d_View)& theView)
472 ViewerTest_myViews.Bind (theName, theView);
475 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
477 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
479 //==============================================================================
480 //function : ViewerInit
481 //purpose : Create the window viewer and initialize all the global variable
482 //==============================================================================
484 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
485 const Standard_Integer thePxTop,
486 const Standard_Integer thePxWidth,
487 const Standard_Integer thePxHeight,
488 Standard_CString theViewName,
489 Standard_CString theDisplayName)
491 // Default position and dimension of the viewer window.
492 // Note that left top corner is set to be sufficiently small to have
493 // window fit in the small screens (actual for remote desktops, see #23003).
494 // The position corresponds to the window's client area, thus some
495 // gap is added for window frame to be visible.
496 Standard_Integer aPxLeft = 20;
497 Standard_Integer aPxTop = 40;
498 Standard_Integer aPxWidth = 409;
499 Standard_Integer aPxHeight = 409;
500 Standard_Boolean toCreateViewer = Standard_False;
502 Handle(OpenGl_GraphicDriver) aGraphicDriver;
503 ViewerTest_Names aViewNames(theViewName);
504 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
505 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
512 aPxWidth = thePxWidth;
513 if (thePxHeight != 0)
514 aPxHeight = thePxHeight;
516 // Get graphic driver (create it or get from another view)
517 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
519 // Get connection string
520 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
521 TCollection_AsciiString aDisplayName(theDisplayName);
522 if (!aDisplayName.IsEmpty())
523 SetDisplayConnection (new Aspect_DisplayConnection ());
525 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
527 (void)theDisplayName; // avoid warning on unused argument
528 SetDisplayConnection (new Aspect_DisplayConnection ());
530 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
531 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
532 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
533 toCreateViewer = Standard_True;
537 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
540 //Dispose the window if input parameters are default
541 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
543 Standard_Integer aTop = 0,
550 // Get screen resolution
551 #if defined(_WIN32) || defined(__WIN32__)
553 GetClientRect(GetDesktopWindow(), &aWindowSize);
554 aScreenHeight = aWindowSize.bottom;
555 aScreenWidth = aWindowSize.right;
556 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
557 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
559 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
560 aScreenWidth = WidthOfScreen(aScreen);
561 aScreenHeight = HeightOfScreen(aScreen);
564 TCollection_AsciiString anOverlappedViewId("");
566 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
568 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
570 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
571 && aRight + 2*aPxWidth + 40 > aScreenWidth)
573 if (aBottom + aPxHeight + 40 > aScreenHeight)
580 aPxTop = aBottom + 40;
583 aPxLeft = aRight + 20;
588 TCollection_AsciiString aTitle("3D View - ");
589 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
591 // Change name of current active window
592 if (!ViewerTest::CurrentView().IsNull())
594 TCollection_AsciiString aTitle("3D View - ");
596 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
597 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
601 Handle(V3d_Viewer) a3DViewer;
602 // If it's the single view, we first look for empty context
603 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
605 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
606 anIter(ViewerTest_myContexts);
608 ViewerTest::SetAISContext (anIter.Value());
609 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
611 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
613 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
614 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
616 else if (a3DViewer.IsNull())
618 toCreateViewer = Standard_True;
619 TCollection_ExtendedString NameOfWindow("Viewer3D");
620 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
622 NameOfWindow = TCollection_ExtendedString("Collector");
624 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
628 if (ViewerTest::GetAISContext().IsNull() ||
629 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
631 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
632 ViewerTest::SetAISContext (aContext);
633 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
637 ViewerTest::ResetEventManager();
642 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
643 Handle(WNT_WClass)::DownCast (WClass()),
644 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
648 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
649 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
651 aPxWidth, aPxHeight);
652 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
654 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
657 aPxWidth, aPxHeight);
659 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
662 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
664 ViewerTest::CurrentView(aView);
665 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
666 TheNISContext()->AttachView (aView);
668 // Setup for X11 or NT
671 // Set parameters for V3d_View and V3d_Viewer
672 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
673 aV3dView->SetComputedMode(Standard_False);
674 MyHLRIsOn = aV3dView->ComputedMode();
675 aV3dView->SetZClippingDepth(0.5);
676 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
678 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
681 a3DViewer->SetDefaultLights();
682 a3DViewer->SetLightOn();
685 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
686 #if TCL_MAJOR_VERSION < 8
687 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
688 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
690 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
691 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
695 VT_GetWindow()->Map();
697 // Set the handle of created view in the event manager
698 ViewerTest::ResetEventManager();
700 ViewerTest::CurrentView()->Redraw();
705 return aViewNames.GetViewName();
708 //==============================================================================
709 //function : RedrawAllViews
710 //purpose : Redraw all created views
711 //==============================================================================
712 void ViewerTest::RedrawAllViews()
714 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
715 for (; aViewIt.More(); aViewIt.Next())
717 const Handle(V3d_View)& aView = aViewIt.Key2();
722 //==============================================================================
724 //purpose : Create the window viewer and initialize all the global variable
725 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
726 //==============================================================================
728 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
732 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
733 << "Type help for more information.\n";
737 TCollection_AsciiString aViewName, aDisplayName;
738 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
739 TCollection_AsciiString aName, aValue;
740 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
742 const TCollection_AsciiString anArg = theArgVec[anArgIt];
743 TCollection_AsciiString anArgCase = anArg;
744 anArgCase.UpperCase();
745 if (ViewerTest::SplitParameter (anArg, aName, aValue))
748 if (aName.IsEqual ("NAME"))
752 else if (aName.IsEqual ("L")
753 || aName.IsEqual ("LEFT"))
755 aPxLeft = aValue.IntegerValue();
757 else if (aName.IsEqual ("T")
758 || aName.IsEqual ("TOP"))
760 aPxTop = aValue.IntegerValue();
762 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
763 else if (aName.IsEqual ("DISP")
764 || aName.IsEqual ("DISPLAY"))
766 aDisplayName = aValue;
769 else if (aName.IsEqual ("W")
770 || aName.IsEqual ("WIDTH"))
772 aPxWidth = aValue.IntegerValue();
774 else if (aName.IsEqual ("H")
775 || aName.IsEqual ("HEIGHT"))
777 aPxHeight = aValue.IntegerValue();
781 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
784 else if (aViewName.IsEmpty())
790 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
794 ViewerTest_Names aViewNames (aViewName);
795 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
797 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
798 theDi.Eval (aCommand.ToCString());
802 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
803 aViewName.ToCString(),
804 aDisplayName.ToCString());
809 //==============================================================================
811 //purpose : hidden lines removal algorithm
812 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
813 //==============================================================================
815 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
817 if (ViewerTest::CurrentView().IsNull())
819 di << argv[0] << ": Call vinit before this command, please.\n";
825 di << argv[0] << ": Wrong number of command arguments.\n"
826 << "Type help " << argv[0] << " for more information.\n";
830 // Enable or disable HLR mode.
831 Standard_Boolean isHLROn =
832 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
834 if (isHLROn != MyHLRIsOn)
837 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
840 // Show or hide hidden lines in HLR mode.
841 Standard_Boolean isCurrentShowHidden
842 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
844 Standard_Boolean isShowHidden =
845 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
846 : isCurrentShowHidden;
849 if (isShowHidden != isCurrentShowHidden)
853 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
857 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
863 AIS_ListOfInteractive aListOfShapes;
864 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
866 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
868 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
878 ViewerTest::CurrentView()->Update();
882 //==============================================================================
883 //function : VHLRType
884 //purpose : change type of using HLR algorithm
885 //==============================================================================
887 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
889 if (ViewerTest::CurrentView().IsNull())
891 di << argv[0] << ": Call vinit before this command, please.\n";
897 di << argv[0] << ": Wrong number of command arguments.\n"
898 << "Type help " << argv[0] << " for more information.\n";
902 Prs3d_TypeOfHLR aTypeOfHLR =
903 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
907 AIS_ListOfInteractive aListOfShapes;
908 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
909 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
910 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
911 anIter.More(); anIter.Next())
913 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
916 if (aShape->TypeOfHLR() != aTypeOfHLR)
917 aShape->SetTypeOfHLR (aTypeOfHLR);
921 ViewerTest::CurrentView()->Update();
926 for (Standard_Integer i = 2; i < argc; ++i)
928 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
929 TCollection_AsciiString aName (argv[i]);
931 if (!aMap.IsBound2 (aName))
933 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
936 Handle(AIS_Shape) anAISObject =
937 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
938 if (anAISObject.IsNull())
940 anAISObject->SetTypeOfHLR (aTypeOfHLR);
942 anAISObject->Redisplay();
944 ViewerTest::CurrentView()->Update();
950 //==============================================================================
951 //function : FindViewIdByWindowHandle
952 //purpose : Find theView Id in the map of views by window handle
953 //==============================================================================
954 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
955 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
957 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
958 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
960 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
961 if (aWindowHandle == theWindowHandle)
962 return anIter.Key1();
964 return TCollection_AsciiString("");
968 //==============================================================================
969 //function : ActivateView
970 //purpose : Make the view active
971 //==============================================================================
973 void ActivateView (const TCollection_AsciiString& theViewName)
975 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
978 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
979 if (!anAISContext.IsNull())
981 if (!ViewerTest::CurrentView().IsNull())
983 TCollection_AsciiString aTitle("3D View - ");
984 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
985 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
988 ViewerTest::CurrentView (aView);
989 // Update degenerate mode
990 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
991 ViewerTest::SetAISContext (anAISContext);
992 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
993 aTitle = aTitle + theViewName + "(*)";
994 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
995 #if defined(_WIN32) || defined(__WIN32__)
996 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
997 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
998 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1000 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1002 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1003 ViewerTest::CurrentView()->Redraw();
1008 //==============================================================================
1009 //function : RemoveView
1011 //==============================================================================
1012 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1013 const Standard_Boolean theToRemoveContext)
1015 if (!ViewerTest_myViews.IsBound2 (theView))
1020 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1021 RemoveView (aViewName, theToRemoveContext);
1024 //==============================================================================
1025 //function : RemoveView
1026 //purpose : Close and remove view from display, clear maps if neccessary
1027 //==============================================================================
1028 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1030 if (!ViewerTest_myViews.IsBound1(theViewName))
1032 cout << "Wrong view name\n";
1036 // Activate another view if it's active now
1037 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1039 if (ViewerTest_myViews.Extent() > 1)
1041 TCollection_AsciiString aNewViewName;
1042 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1043 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1044 if (anIter.Key1() != theViewName)
1046 aNewViewName = anIter.Key1();
1049 ActivateView (aNewViewName);
1053 Handle(V3d_View) anEmptyView;
1054 #if defined(_WIN32) || defined(__WIN32__)
1055 Handle(WNT_Window) anEmptyWindow;
1056 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1057 Handle(Cocoa_Window) anEmptyWindow;
1059 Handle(Xw_Window) anEmptyWindow;
1061 VT_GetWindow() = anEmptyWindow;
1062 ViewerTest::CurrentView (anEmptyView);
1063 if (isContextRemoved)
1065 Handle(AIS_InteractiveContext) anEmptyContext;
1066 ViewerTest::SetAISContext(anEmptyContext);
1072 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1073 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1075 // Remove view resources
1076 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1077 ViewerTest_myViews.UnBind1(theViewName);
1080 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1081 XFlush (GetDisplayConnection()->GetDisplay());
1084 // Keep context opened only if the closed view is last to avoid
1085 // unused empty contexts
1086 if (!aCurrentContext.IsNull())
1088 // Check if there are more difined views in the viewer
1089 aCurrentContext->CurrentViewer()->InitDefinedViews();
1090 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1092 // Remove driver if there is no viewers that use it
1093 Standard_Boolean isRemoveDriver = Standard_True;
1094 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1095 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1097 if (aCurrentContext != anIter.Key2() &&
1098 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1100 isRemoveDriver = Standard_False;
1106 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1107 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1108 #if TCL_MAJOR_VERSION < 8
1109 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1111 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1116 ViewerTest_myContexts.UnBind2(aCurrentContext);
1119 cout << "3D View - " << theViewName << " was deleted.\n";
1123 //==============================================================================
1125 //purpose : Remove the view defined by its name
1126 //==============================================================================
1128 static int VClose (Draw_Interpretor& /*theDi*/,
1129 Standard_Integer theArgsNb,
1130 const char** theArgVec)
1132 NCollection_List<TCollection_AsciiString> aViewList;
1135 TCollection_AsciiString anArg (theArgVec[1]);
1137 if (anArg.IsEqual ("ALL")
1138 || anArg.IsEqual ("*"))
1140 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1141 anIter.More(); anIter.Next())
1143 aViewList.Append (anIter.Key1());
1145 if (aViewList.IsEmpty())
1147 std::cout << "No view to close\n";
1153 ViewerTest_Names aViewName (theArgVec[1]);
1154 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1156 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1159 aViewList.Append (aViewName.GetViewName());
1164 // close active view
1165 if (ViewerTest::CurrentView().IsNull())
1167 std::cerr << "No active view!\n";
1170 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1173 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1174 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1175 anIter.More(); anIter.Next())
1177 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1183 //==============================================================================
1184 //function : VActivate
1185 //purpose : Activate the view defined by its ID
1186 //==============================================================================
1188 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1192 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1193 << "Usage: " << theArgVec[0] << " ViewID\n";
1198 theDi.Eval("vviewlist");
1202 TCollection_AsciiString aNameString(theArgVec[1]);
1203 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1205 TCollection_AsciiString aTitle("3D View - ");
1206 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1207 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1208 Handle(V3d_View) anEmptyView;
1209 #if defined(_WIN32) || defined(__WIN32__)
1210 Handle(WNT_Window) anEmptyWindow;
1211 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1212 Handle(Cocoa_Window) anEmptyWindow;
1214 Handle(Xw_Window) anEmptyWindow;
1216 VT_GetWindow() = anEmptyWindow;
1217 ViewerTest::CurrentView (anEmptyView);
1218 ViewerTest::ResetEventManager();
1219 theDi << theArgVec[0] << ": all views are inactive\n";
1223 ViewerTest_Names aViewNames(aNameString);
1225 // Check if this view exists in the viewer with the driver
1226 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1228 theDi << "Wrong view name\n";
1232 // Check if it is active already
1233 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1235 theDi << theArgVec[0] << ": the view is active already\n";
1239 ActivateView (aViewNames.GetViewName());
1243 //==============================================================================
1244 //function : VViewList
1245 //purpose : Print current list of views per viewer and graphic driver ID
1246 // shared between viewers
1247 //==============================================================================
1249 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1253 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1254 << "Usage: " << theArgVec[0] << " name";
1257 if (ViewerTest_myContexts.Size() < 1)
1260 Standard_Boolean isTreeView =
1261 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1264 theDi << theArgVec[0] <<":\n";
1266 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1267 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1270 theDi << aDriverIter.Key1() << ":\n";
1272 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1273 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1275 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1279 TCollection_AsciiString aContextName(aContextIter.Key1());
1280 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1283 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1284 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1286 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1288 TCollection_AsciiString aViewName(aViewIter.Key1());
1291 if (aViewIter.Value() == ViewerTest::CurrentView())
1292 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1294 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1298 theDi << aViewName << " ";
1308 //==============================================================================
1309 //function : VT_ProcessKeyPress
1310 //purpose : Handle KeyPress event from a CString
1311 //==============================================================================
1312 void VT_ProcessKeyPress (const char* buf_ret)
1314 //cout << "KeyPress" << endl;
1315 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1316 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1317 // Letter in alphabetic order
1319 if (!strcasecmp (buf_ret, "A"))
1322 aView->SetProj(V3d_XposYnegZpos);
1324 else if (!strcasecmp (buf_ret, "D"))
1329 else if (!strcasecmp (buf_ret, "F"))
1332 if (aNisView.IsNull())
1335 aNisView->FitAll3d();
1337 else if (!strcasecmp (buf_ret, "H"))
1340 cout << "HLR" << endl;
1341 aView->SetComputedMode (!aView->ComputedMode());
1342 MyHLRIsOn = aView->ComputedMode();
1344 else if (!strcasecmp (buf_ret, "P"))
1347 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1348 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1349 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1351 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1352 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1354 AIS_ListOfInteractive aListOfShapes;
1355 aContext->DisplayedObjects(aListOfShapes);
1356 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1357 anIter.More(); anIter.Next())
1359 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1360 if (aShape.IsNull())
1362 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1363 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1365 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1366 aShape->Redisplay();
1371 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1373 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1374 if (aShape.IsNull())
1376 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1377 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1379 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1380 aShape->Redisplay();
1384 aContext->UpdateCurrentViewer();
1387 else if (!strcasecmp (buf_ret, "S"))
1389 std::cout << "setup Shaded display mode" << std::endl;
1391 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1392 if(Ctx->NbCurrents()==0 ||
1393 Ctx->NbSelected()==0)
1394 Ctx->SetDisplayMode(AIS_Shaded);
1396 if(Ctx->HasOpenedContext()){
1397 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1398 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1401 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1402 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1404 Ctx->UpdateCurrentViewer();
1407 else if (!strcasecmp (buf_ret, "U"))
1409 // Unset display mode
1410 std::cout << "reset display mode to defaults" << std::endl;
1412 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1413 if(Ctx->NbCurrents()==0 ||
1414 Ctx->NbSelected()==0)
1415 Ctx->SetDisplayMode(AIS_WireFrame);
1417 if(Ctx->HasOpenedContext()){
1418 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1419 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1422 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1423 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1425 Ctx->UpdateCurrentViewer();
1429 else if (!strcasecmp (buf_ret, "T"))
1432 aView->SetProj(V3d_Zpos);
1434 else if (!strcasecmp (buf_ret, "B"))
1437 aView->SetProj(V3d_Zneg);
1439 else if (!strcasecmp (buf_ret, "L"))
1442 aView->SetProj(V3d_Xneg);
1444 else if (!strcasecmp (buf_ret, "R"))
1447 aView->SetProj(V3d_Xpos);
1449 else if (!strcasecmp (buf_ret, "W"))
1451 std::cout << "setup WireFrame display mode" << std::endl;
1452 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1453 if(Ctx->NbCurrents()==0 ||
1454 Ctx->NbSelected()==0)
1455 Ctx->SetDisplayMode(AIS_WireFrame);
1457 if(Ctx->HasOpenedContext()){
1458 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1459 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1462 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1463 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1465 Ctx->UpdateCurrentViewer();
1468 else if (!strcasecmp (buf_ret, "Z"))
1472 cout << "ZClipping OFF" << endl;
1475 aView->SetZClippingType(V3d_OFF);
1479 cout << "ZClipping ON" << endl;
1482 aView->SetZClippingType(V3d_FRONT);
1486 else if (!strcasecmp (buf_ret, ","))
1488 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1490 else if (!strcasecmp (buf_ret, "."))
1492 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1494 else if (*buf_ret == THE_KEY_DELETE)
1496 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1498 && aCtx->NbCurrents() > 0
1499 && aCtx->NbSelected() > 0)
1501 Draw_Interprete ("verase");
1507 Standard_Integer Num = Draw::Atoi(buf_ret);
1508 if(Num>=0 && Num<=7)
1509 ViewerTest::StandardModeActivation(Num);
1513 //==============================================================================
1514 //function : VT_ProcessExpose
1515 //purpose : Redraw the View on an Expose Event
1516 //==============================================================================
1517 void VT_ProcessExpose()
1519 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1520 if (!aView3d.IsNull())
1526 //==============================================================================
1527 //function : VT_ProcessConfigure
1528 //purpose : Resize the View on an Configure Event
1529 //==============================================================================
1530 void VT_ProcessConfigure()
1532 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1533 if (aView3d.IsNull())
1538 aView3d->MustBeResized();
1543 //==============================================================================
1544 //function : VT_ProcessButton1Press
1546 //==============================================================================
1547 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1548 const char** theArgVec,
1549 Standard_Boolean theToPick,
1550 Standard_Boolean theIsShift)
1554 Standard_Real X, Y, Z;
1555 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1557 Draw::Set (theArgVec[1], X);
1558 Draw::Set (theArgVec[2], Y);
1559 Draw::Set (theArgVec[3], Z);
1564 ViewerTest::CurrentEventManager()->ShiftSelect();
1568 ViewerTest::CurrentEventManager()->Select();
1571 return Standard_False;
1574 //==============================================================================
1575 //function : VT_ProcessButton1Release
1576 //purpose : End selecting
1577 //==============================================================================
1578 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1582 IsDragged = Standard_False;
1583 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1586 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1587 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1591 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1592 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1597 //==============================================================================
1598 //function : VT_ProcessButton3Press
1599 //purpose : Start Rotation
1600 //==============================================================================
1601 void VT_ProcessButton3Press()
1606 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1608 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1611 //==============================================================================
1612 //function : VT_ProcessButton3Release
1613 //purpose : End rotation
1614 //==============================================================================
1615 void VT_ProcessButton3Release()
1622 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1627 //==============================================================================
1628 //function : ProcessZClipMotion
1630 //==============================================================================
1632 void ProcessZClipMotion()
1634 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1635 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1636 static Standard_Real CurZPos = 0.;
1638 //Quantity_Length VDX, VDY;
1639 //a3DView->Size(VDX,VDY);
1640 //Standard_Real VDZ = a3DView->ZSize();
1641 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1643 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1645 // Front = Depth + width/2.
1646 Standard_Real D = 0.5;
1647 Standard_Real W = 0.1;
1653 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1655 a3DView->SetZClippingType(V3d_OFF);
1656 a3DView->SetZClippingDepth(D);
1657 a3DView->SetZClippingWidth(W);
1658 a3DView->SetZClippingType(V3d_FRONT);
1662 X_ButtonPress = X_Motion;
1663 Y_ButtonPress = Y_Motion;
1667 //==============================================================================
1668 //function : ProcessControlButton1Motion
1670 //==============================================================================
1672 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1673 static void ProcessControlButton1Motion()
1675 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1677 X_ButtonPress = X_Motion;
1678 Y_ButtonPress = Y_Motion;
1682 //==============================================================================
1683 //function : VT_ProcessControlButton2Motion
1685 //==============================================================================
1686 void VT_ProcessControlButton2Motion()
1688 Standard_Integer aDx = X_Motion - X_ButtonPress;
1689 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1691 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1693 ViewerTest::CurrentView()->Pan (aDx, aDy);
1695 X_ButtonPress = X_Motion;
1696 Y_ButtonPress = Y_Motion;
1699 //==============================================================================
1700 //function : VT_ProcessControlButton3Motion
1701 //purpose : Rotation
1702 //==============================================================================
1703 void VT_ProcessControlButton3Motion()
1707 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1711 //==============================================================================
1712 //function : VT_ProcessMotion
1714 //==============================================================================
1715 void VT_ProcessMotion()
1717 //pre-hilights detected objects at mouse position
1719 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1720 EM->MoveTo(X_Motion, Y_Motion);
1724 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1726 Xpix = X_Motion;Ypix=Y_Motion;
1729 //==============================================================================
1730 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1731 //purpose : Switches to an axonometric, top, left and other views
1732 //==============================================================================
1734 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1736 if ( ViewerTest::CurrentView().IsNull() )
1738 di<<"Call vinit before this command, please"<<"\n";
1742 ViewerTest::CurrentView()->SetProj(ori);
1746 //==============================================================================
1748 //purpose : Switch to an Axonometric view
1749 //Draw arg : No args
1750 //==============================================================================
1752 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1754 return ViewProject(di, V3d_XposYnegZpos);
1757 //==============================================================================
1759 //purpose : Switch to a Top View
1760 //Draw arg : No args
1761 //==============================================================================
1763 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1765 return ViewProject(di, V3d_Zpos);
1768 //==============================================================================
1769 //function : VBottom
1770 //purpose : Switch to a Bottom View
1771 //Draw arg : No args
1772 //==============================================================================
1774 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1776 return ViewProject(di, V3d_Zneg);
1779 //==============================================================================
1781 //purpose : Switch to a Left View
1782 //Draw arg : No args
1783 //==============================================================================
1785 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1787 return ViewProject(di, V3d_Ypos);
1790 //==============================================================================
1792 //purpose : Switch to a Right View
1793 //Draw arg : No args
1794 //==============================================================================
1796 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1798 return ViewProject(di, V3d_Yneg);
1801 //==============================================================================
1803 //purpose : Switch to a Front View
1804 //Draw arg : No args
1805 //==============================================================================
1807 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1809 return ViewProject(di, V3d_Xpos);
1812 //==============================================================================
1814 //purpose : Switch to a Back View
1815 //Draw arg : No args
1816 //==============================================================================
1818 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1820 return ViewProject(di, V3d_Xneg);
1823 //==============================================================================
1825 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1826 //Draw arg : No args
1827 //==============================================================================
1829 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1832 di << "Q : Quit the application" << "\n";
1834 di << "========================="<<"\n";
1835 di << "F : FitAll" << "\n";
1836 di << "T : TopView" << "\n";
1837 di << "B : BottomView" << "\n";
1838 di << "R : RightView" << "\n";
1839 di << "L : LeftView" << "\n";
1840 di << "A : AxonometricView" << "\n";
1841 di << "D : ResetView" << "\n";
1843 di << "========================="<<"\n";
1844 di << "S : Shading" << "\n";
1845 di << "W : Wireframe" << "\n";
1846 di << "H : HidelLineRemoval" << "\n";
1847 di << "U : Unset display mode" << "\n";
1848 di << "Delete : Remove selection from viewer" << "\n";
1850 di << "========================="<<"\n";
1851 di << "Selection mode "<<"\n";
1852 di << "0 : Shape" <<"\n";
1853 di << "1 : Vertex" <<"\n";
1854 di << "2 : Edge" <<"\n";
1855 di << "3 : Wire" <<"\n";
1856 di << "4 : Face" <<"\n";
1857 di << "5 : Shell" <<"\n";
1858 di << "6 : Solid" <<"\n";
1859 di << "7 : Compound" <<"\n";
1861 di << "========================="<<"\n";
1862 di << "Z : Switch Z clipping On/Off" << "\n";
1863 di << ", : Hilight next detected" << "\n";
1864 di << ". : Hilight previous detected" << "\n";
1871 static Standard_Boolean Ppick = 0;
1872 static Standard_Integer Pargc = 0;
1873 static const char** Pargv = NULL;
1876 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1881 if (!ViewerTest_myViews.IsEmpty()) {
1883 WPARAM fwKeys = wParam;
1888 // Delete view from map of views
1889 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1894 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1895 || ViewerTest::CurrentView().IsNull())
1897 // Activate inactive window
1898 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1900 ActivateView (FindViewIdByWindowHandle(hwnd));
1907 HDC hdc = GetDC( hwnd );
1908 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1909 SetROP2( hdc, R2_NOT );
1910 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1911 ReleaseDC( hwnd, hdc );
1912 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1914 IsDragged = Standard_False;
1915 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1917 case WM_LBUTTONDOWN:
1918 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1920 IsDragged = Standard_True;
1921 DragFirst = Standard_True;
1922 X_ButtonPress = LOWORD(lParam);
1923 Y_ButtonPress = HIWORD(lParam);
1925 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1932 HDC hdc = GetDC( hwnd );
1934 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1935 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1936 SetROP2( hdc, R2_NOT );
1939 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1941 DragFirst = Standard_False;
1942 X_Motion = LOWORD(lParam);
1943 Y_Motion = HIWORD(lParam);
1945 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1947 SelectObject( hdc, anObj );
1949 ReleaseDC( hwnd, hdc );
1952 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1956 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1960 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1964 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1971 if ( !ViewerTest::CurrentView().IsNull() ) {
1976 BeginPaint(hwnd, &ps);
1977 EndPaint(hwnd, &ps);
1982 VT_ProcessConfigure();
1986 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1989 c[0] = (char) wParam;
1991 if (wParam == VK_DELETE)
1993 c[0] = THE_KEY_DELETE;
1995 VT_ProcessKeyPress (c);
2003 VT_ProcessButton3Release();
2006 case WM_LBUTTONDOWN:
2007 case WM_MBUTTONDOWN:
2008 case WM_RBUTTONDOWN:
2010 WPARAM fwKeys = wParam;
2014 X_ButtonPress = LOWORD(lParam);
2015 Y_ButtonPress = HIWORD(lParam);
2017 if (Msg == WM_LBUTTONDOWN)
2019 if (fwKeys & MK_CONTROL)
2021 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2025 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2028 else if (Msg == WM_RBUTTONDOWN)
2031 VT_ProcessButton3Press();
2038 //cout << "\t WM_MOUSEMOVE" << endl;
2039 WPARAM fwKeys = wParam;
2040 X_Motion = LOWORD(lParam);
2041 Y_Motion = HIWORD(lParam);
2044 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2046 X_ButtonPress = LOWORD(lParam);
2047 Y_ButtonPress = HIWORD(lParam);
2049 if ( fwKeys & MK_RBUTTON ) {
2051 VT_ProcessButton3Press();
2055 if ( fwKeys & MK_CONTROL ) {
2056 if ( fwKeys & MK_LBUTTON ) {
2057 ProcessControlButton1Motion();
2059 else if ( fwKeys & MK_MBUTTON ||
2060 ((fwKeys&MK_LBUTTON) &&
2061 (fwKeys&MK_RBUTTON) ) ){
2062 VT_ProcessControlButton2Motion();
2064 else if ( fwKeys & MK_RBUTTON ) {
2065 VT_ProcessControlButton3Motion();
2069 else if ( fwKeys & MK_SHIFT ) {
2070 if ( fwKeys & MK_MBUTTON ||
2071 ((fwKeys&MK_LBUTTON) &&
2072 (fwKeys&MK_RBUTTON) ) ) {
2073 cout << "ProcessZClipMotion()" << endl;
2074 ProcessZClipMotion();
2078 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2080 if ((fwKeys & MK_MBUTTON
2081 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2083 ProcessZClipMotion();
2094 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2099 return DefWindowProc( hwnd, Msg, wParam, lParam );
2105 //==============================================================================
2106 //function : ViewerMainLoop
2107 //purpose : Get a Event on the view and dispatch it
2108 //==============================================================================
2111 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2113 Ppick = (argc > 0)? 1 : 0;
2121 cout << "Start picking" << endl;
2123 while ( Ppick == 1 ) {
2124 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2125 if (GetMessage(&msg, NULL, 0, 0) ) {
2126 TranslateMessage(&msg);
2127 DispatchMessage(&msg);
2131 cout << "Picking done" << endl;
2137 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2139 int min( int a, int b )
2147 int max( int a, int b )
2155 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2158 static XEvent aReport;
2159 Standard_Boolean pick = argc > 0;
2160 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2161 XNextEvent (aDisplay, &aReport);
2163 // Handle event for the chosen display connection
2164 switch (aReport.type) {
2167 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2170 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2176 // Activate inactive view
2177 Window aWindow = GetWindowHandle(VT_GetWindow());
2178 if(aWindow != aReport.xfocus.window)
2180 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2189 case ConfigureNotify:
2191 VT_ProcessConfigure();
2200 XComposeStatus status_in_out;
2202 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2203 (char *) buf_ret , 10 ,
2204 &ks_ret , &status_in_out ) ;
2207 buf_ret[ret_len] = '\0' ;
2211 VT_ProcessKeyPress (buf_ret);
2217 X_ButtonPress = aReport.xbutton.x;
2218 Y_ButtonPress = aReport.xbutton.y;
2220 if (aReport.xbutton.button == Button1)
2222 if (aReport.xbutton.state & ControlMask)
2224 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2228 IsDragged = Standard_True;
2229 DragFirst = Standard_True;
2232 else if (aReport.xbutton.button == Button3)
2235 VT_ProcessButton3Press();
2245 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2246 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2247 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2250 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2251 if( aContext.IsNull() )
2253 cout << "The context is null. Please use vinit before createmesh" << endl;
2257 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2258 if( aReport.xbutton.button==1 )
2262 aContext->ShiftSelect();
2271 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2272 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2273 ViewerTest::CurrentView());
2277 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2278 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2279 ViewerTest::CurrentView() );
2282 VT_ProcessButton3Release();
2284 IsDragged = Standard_False;
2287 VT_ProcessButton3Release();
2292 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2298 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2299 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2300 XSetFunction( aDisplay, gc, GXinvert );
2303 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2305 X_Motion = aReport.xmotion.x;
2306 Y_Motion = aReport.xmotion.y;
2307 DragFirst = Standard_False;
2309 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2313 X_Motion = aReport.xmotion.x;
2314 Y_Motion = aReport.xmotion.y;
2316 // remove all the ButtonMotionMaskr
2317 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2319 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2320 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2322 Quantity_Length VDX, VDY;
2324 ViewerTest::CurrentView()->Size(VDX,VDY);
2325 Standard_Real VDZ =0 ;
2326 VDZ = ViewerTest::CurrentView()->ZSize();
2328 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2330 Quantity_Length dx = 0 ;
2331 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2335 dx = dx / VDX * VDZ;
2339 ViewerTest::CurrentView()->Redraw();
2343 if ( aReport.xmotion.state & ControlMask ) {
2344 if ( aReport.xmotion.state & Button1Mask ) {
2345 ProcessControlButton1Motion();
2347 else if ( aReport.xmotion.state & Button2Mask ) {
2348 VT_ProcessControlButton2Motion();
2350 else if ( aReport.xmotion.state & Button3Mask ) {
2351 VT_ProcessControlButton3Motion();
2365 //==============================================================================
2366 //function : VProcessEvents
2367 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2368 // event in the Viewer window
2369 //==============================================================================
2371 static void VProcessEvents(ClientData,int)
2373 NCollection_Vector<int> anEventNumbers;
2374 // Get number of messages from every display
2375 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2376 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2378 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2380 // Handle events for every display
2381 int anEventIter = 0;
2382 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2383 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2385 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2386 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2388 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2389 int anEventResult = ViewerMainLoop( 0, NULL);
2390 // If window is closed or context was not found finish current event processing loop
2396 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2401 //==============================================================================
2402 //function : OSWindowSetup
2403 //purpose : Setup for the X11 window to be able to cath the event
2404 //==============================================================================
2407 static void OSWindowSetup()
2409 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2412 Window window = VT_GetWindow()->XWindow();
2413 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2414 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2415 XSynchronize(aDisplay, 1);
2417 // X11 : For keyboard on SUN
2419 wmhints.flags = InputHint;
2422 XSetWMHints( aDisplay, window, &wmhints);
2424 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2425 ButtonPressMask | ButtonReleaseMask |
2426 StructureNotifyMask |
2428 Button1MotionMask | Button2MotionMask |
2429 Button3MotionMask | FocusChangeMask
2431 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2432 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2434 XSynchronize(aDisplay, 0);
2443 //==============================================================================
2446 //purpose : Fitall, no DRAW arguments
2447 //Draw arg : No args
2448 //==============================================================================
2450 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2452 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2453 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2454 if (V.IsNull() == Standard_False) {
2456 } else if (aView.IsNull() == Standard_False) {
2462 //==============================================================================
2464 //purpose : ZFitall, no DRAW arguments
2465 //Draw arg : No args
2466 //==============================================================================
2467 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2469 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2471 if (aCurrentView.IsNull())
2473 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2479 aCurrentView->View()->ZFitAll();
2480 aCurrentView->Redraw();
2484 Standard_Real aScale = 1.0;
2488 aScale = Draw::Atoi (theArgVec[1]);
2491 aCurrentView->View()->ZFitAll (aScale);
2492 aCurrentView->Redraw();
2497 //==============================================================================
2498 //function : VRepaint
2500 //==============================================================================
2501 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2503 Handle(V3d_View) V = ViewerTest::CurrentView();
2504 if ( !V.IsNull() ) V->Redraw(); return 0;
2507 //==============================================================================
2509 //purpose : Remove all the object from the viewer
2510 //Draw arg : No args
2511 //==============================================================================
2513 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2515 Handle(V3d_View) V = ViewerTest::CurrentView();
2517 ViewerTest::Clear();
2521 //==============================================================================
2524 //==============================================================================
2526 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2527 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2530 di << argv[0] << "Invalid number of arguments" << "\n";
2534 while (ViewerMainLoop( argc, argv)) {
2540 //==============================================================================
2542 //purpose : Load image as background
2543 //==============================================================================
2545 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2547 if (argc < 2 || argc > 3)
2549 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2550 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2554 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2555 if(AISContext.IsNull())
2557 di << "use 'vinit' command before " << argv[0] << "\n";
2561 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2564 const char* szType = argv[2];
2565 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2566 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2567 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2568 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2571 di << "Wrong fill type : " << szType << "\n";
2572 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2577 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2578 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2583 //==============================================================================
2584 //function : VSetBgMode
2585 //purpose : Change background image fill type
2586 //==============================================================================
2588 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2592 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2593 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2597 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2598 if(AISContext.IsNull())
2600 di << "use 'vinit' command before " << argv[0] << "\n";
2603 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2604 const char* szType = argv[1];
2605 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2606 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2607 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2608 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2611 di << "Wrong fill type : " << szType << "\n";
2612 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2615 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2616 V3dView->SetBgImageStyle(aFillType, Standard_True);
2620 //==============================================================================
2621 //function : VSetGradientBg
2622 //purpose : Mount gradient background
2623 //==============================================================================
2624 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2628 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2629 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2630 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2631 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2635 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2636 if(AISContext.IsNull())
2638 di << "use 'vinit' command before " << argv[0] << "\n";
2644 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2645 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2646 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2647 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2649 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2650 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2651 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2653 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2654 int aType = Draw::Atoi(argv[7]);
2655 if( aType < 0 || aType > 8 )
2657 di << "Wrong fill type " << "\n";
2658 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2659 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2663 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2665 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2666 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2672 //==============================================================================
2673 //function : VSetGradientBgMode
2674 //purpose : Change gradient background fill style
2675 //==============================================================================
2676 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2680 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2681 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2682 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2686 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2687 if(AISContext.IsNull())
2689 di << "use 'vinit' command before " << argv[0] << "\n";
2694 int aType = Draw::Atoi(argv[1]);
2695 if( aType < 0 || aType > 8 )
2697 di << "Wrong fill type " << "\n";
2698 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2699 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2703 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2705 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2706 V3dView->SetBgGradientStyle( aMethod, 1 );
2712 //==============================================================================
2713 //function : VSetColorBg
2714 //purpose : Set color background
2715 //==============================================================================
2716 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2720 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2721 di << "R,G,B = [0..255]" << "\n";
2725 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2726 if(AISContext.IsNull())
2728 di << "use 'vinit' command before " << argv[0] << "\n";
2734 Standard_Real R = Draw::Atof(argv[1])/255.;
2735 Standard_Real G = Draw::Atof(argv[2])/255.;
2736 Standard_Real B = Draw::Atof(argv[3])/255.;
2737 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2739 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2740 V3dView->SetBackgroundColor( aColor );
2747 //==============================================================================
2749 //purpose : View Scaling
2750 //==============================================================================
2752 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2754 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2755 if ( V3dView.IsNull() ) return 1;
2758 di << argv[0] << "Invalid number of arguments" << "\n";
2761 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2764 //==============================================================================
2765 //function : VTestZBuffTrihedron
2766 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2767 //==============================================================================
2769 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2771 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2772 if ( V3dView.IsNull() ) return 1;
2774 V3dView->ZBufferTriedronSetup();
2777 // Set up default trihedron parameters
2778 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2782 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2783 const char* aPosType = argv[1];
2785 if ( strcmp(aPosType, "center") == 0 )
2787 aPosition = Aspect_TOTP_CENTER;
2789 if (strcmp(aPosType, "left_lower") == 0)
2791 aPosition = Aspect_TOTP_LEFT_LOWER;
2793 if (strcmp(aPosType, "left_upper") == 0)
2795 aPosition = Aspect_TOTP_LEFT_UPPER;
2797 if (strcmp(aPosType, "right_lower") == 0)
2799 aPosition = Aspect_TOTP_RIGHT_LOWER;
2801 if (strcmp(aPosType, "right_upper") == 0)
2803 aPosition = Aspect_TOTP_RIGHT_UPPER;
2806 di << argv[1] << " Invalid type of alignment" << "\n";
2807 di << "Must be one of [ center, left_lower," << "\n";
2808 di << "left_upper, right_lower, right_upper ]" << "\n";
2812 Standard_Real R = Draw::Atof(argv[2])/255.;
2813 Standard_Real G = Draw::Atof(argv[3])/255.;
2814 Standard_Real B = Draw::Atof(argv[4])/255.;
2815 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2817 Standard_Real aScale = Draw::Atof(argv[5]);
2821 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2825 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2826 const char* aPresType = argv[6];
2828 if ( strcmp(aPresType, "wireframe") == 0 )
2830 aPresentation = V3d_WIREFRAME;
2832 if (strcmp(aPresType, "zbuffer") == 0)
2834 aPresentation = V3d_ZBUFFER;
2837 di << argv[6] << " Invalid type of visualization" << "\n";
2838 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2842 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2846 di << argv[0] << " Invalid number of arguments" << "\n";
2850 V3dView->View()->ZFitAll();
2855 //==============================================================================
2856 //function : VRotate
2857 //purpose : Camera Rotating
2858 //==============================================================================
2860 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2861 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2862 if ( V3dView.IsNull() ) {
2867 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2869 } else if ( argc == 7 ) {
2870 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]) );
2873 di << argv[0] << " Invalid number of arguments" << "\n";
2878 //==============================================================================
2880 //purpose : View zoom in / out (relative to current zoom)
2881 //==============================================================================
2883 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2884 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2885 if ( V3dView.IsNull() ) {
2890 Standard_Real coef = Draw::Atof(argv[1]);
2891 if ( coef <= 0.0 ) {
2892 di << argv[1] << "Invalid value" << "\n";
2895 V3dView->SetZoom( Draw::Atof(argv[1]) );
2898 di << argv[0] << " Invalid number of arguments" << "\n";
2903 //==============================================================================
2905 //purpose : View panning (in pixels)
2906 //==============================================================================
2908 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2909 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2910 if ( V3dView.IsNull() ) return 1;
2913 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2916 di << argv[0] << " Invalid number of arguments" << "\n";
2922 //==============================================================================
2923 //function : VExport
2924 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2925 //==============================================================================
2927 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2929 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2930 if (V3dView.IsNull())
2935 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2939 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2940 TCollection_AsciiString aFormatStr;
2942 TCollection_AsciiString aFileName (argv[1]);
2943 Standard_Integer aLen = aFileName.Length();
2947 aFormatStr = TCollection_AsciiString (argv[2]);
2951 if (aFileName.Value (aLen - 2) == '.')
2953 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2955 else if (aFileName.Value (aLen - 3) == '.')
2957 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2961 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2967 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2971 aFormatStr.UpperCase();
2972 if (aFormatStr == "PS")
2973 anExpFormat = Graphic3d_EF_PostScript;
2974 else if (aFormatStr == "EPS")
2975 anExpFormat = Graphic3d_EF_EnhPostScript;
2976 else if (aFormatStr == "TEX")
2977 anExpFormat = Graphic3d_EF_TEX;
2978 else if (aFormatStr == "PDF")
2979 anExpFormat = Graphic3d_EF_PDF;
2980 else if (aFormatStr == "SVG")
2981 anExpFormat = Graphic3d_EF_SVG;
2982 else if (aFormatStr == "PGF")
2983 anExpFormat = Graphic3d_EF_PGF;
2984 else if (aFormatStr == "EMF")
2985 anExpFormat = Graphic3d_EF_EMF;
2988 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2993 if (!V3dView->View()->Export (argv[1], anExpFormat))
2995 di << "Error: export of image to " << aFormatStr << " failed!\n";
2998 catch (Standard_Failure)
3000 di << "Error: export of image to " << aFormatStr << " failed";
3001 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3006 //==============================================================================
3007 //function : VColorScale
3008 //purpose : representation color scale
3009 //==============================================================================
3010 #include <V3d_ColorScale.hxx>
3012 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3014 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
3016 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
3020 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3021 if(aContext.IsNull()) {
3022 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
3026 Standard_Real minRange = 0. , maxRange = 100. ;
3028 Standard_Integer numIntervals = 10 ;
3029 Standard_Integer textHeight = 16;
3030 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
3031 Standard_Real X = 0., Y = 0. ;
3037 minRange = Draw::Atof( argv[1] );
3038 maxRange = Draw::Atof( argv[2] );
3039 numIntervals = Draw::Atoi( argv[3] );
3042 textHeight = Draw::Atoi( argv[4] );
3044 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
3047 X = Draw::Atof( argv[6] );
3048 Y = Draw::Atof( argv[7] );
3051 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3052 if ( curView.IsNull( ) )
3054 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3055 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3056 if( ! aCS.IsNull( ) )
3058 aCS->SetPosition( X , Y );
3059 aCS->SetHeight( 0.95) ;
3060 aCS->SetTextHeight( textHeight );
3061 aCS->SetRange( minRange , maxRange );
3062 aCS->SetNumberOfIntervals( numIntervals );
3063 aCS->SetLabelPosition( position );
3064 if( !curView->ColorScaleIsDisplayed() )
3065 curView->ColorScaleDisplay( );
3070 //==============================================================================
3071 //function : VGraduatedTrihedron
3072 //purpose : Displays a graduated trihedron
3073 //==============================================================================
3075 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3077 const char *str = arg;
3080 unsigned short c1 = *str++;
3081 unsigned short c2 = *str++;
3082 if (!c1 || !c2) break;
3083 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3087 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3090 if (argc != 2 && argc < 5)
3092 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3093 di<<"Usage: type help "<<argv[0]<<"\n";
3094 return 1; //TCL_ERROR
3097 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3099 // Create 3D view if it doesn't exist
3100 if ( aV3dView.IsNull() )
3102 ViewerTest::ViewerInit();
3103 aV3dView = ViewerTest::CurrentView();
3104 if( aV3dView.IsNull() )
3106 di << "Error: Cannot create a 3D view\n";
3107 return 1; //TCL_ERROR
3111 // Erase (==0) or display (!=0)
3112 const int display = Draw::Atoi(argv[1]);
3117 TCollection_AsciiString font;
3119 font.AssignCat("Courier");
3121 font.AssignCat(argv[5]);
3123 // Text is multibyte
3124 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3127 TCollection_ExtendedString xname, yname, zname;
3132 AddMultibyteString(xname, argv[2]);
3133 AddMultibyteString(yname, argv[3]);
3134 AddMultibyteString(zname, argv[4]);
3150 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3151 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3152 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3153 Standard_True/*drawgrid*/,
3154 Standard_True/*drawaxes*/,
3155 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3156 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3157 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3158 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3159 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3160 Quantity_NOC_WHITE/*gridcolor*/,
3161 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3162 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3165 aV3dView->GraduatedTrihedronErase();
3167 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3173 //==============================================================================
3174 //function : VPrintView
3175 //purpose : Test printing algorithm, print the view to image file with given
3176 // width and height. Printing implemented only for WNT.
3177 //==============================================================================
3178 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3182 di << "Printing implemented only for wnt!\n";
3186 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3187 Handle(V3d_View) aView = NULL;
3188 aContextAIS = ViewerTest::GetAISContext();
3189 if (!aContextAIS.IsNull())
3191 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3192 Vwr->InitActiveViews();
3193 if(Vwr->MoreActiveViews())
3194 aView = Vwr->ActiveView();
3200 di << "Call vinit before!\n";
3205 di << "Use: " << argv[0];
3206 di << " width height filename [print algo=0] [tile_width tile_height]\n";
3207 di << "width, height of the intermediate buffer for operation\n";
3208 di << "algo : {0|1}\n";
3209 di << " 0 - stretch algorithm\n";
3210 di << " 1 - tile algorithm\n";
3211 di << "test printing algorithms into an intermediate buffer\n";
3212 di << "using specific tile size if provided\n";
3213 di << "with saving output to an image file\n";
3217 // get the input params
3218 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3219 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3220 Standard_Integer aMode = 0;
3221 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3223 aMode = Draw::Atoi (argv[4]);
3225 Standard_Integer aTileWidth = 0;
3226 Standard_Integer aTileHeight = 0;
3227 Standard_Boolean isTileSizeProvided = Standard_False;
3230 isTileSizeProvided = Standard_True;
3231 aTileWidth = Draw::Atoi (argv[5]);
3232 aTileHeight = Draw::Atoi (argv[6]);
3235 // check the input parameters
3236 if (aWidth <= 0 || aHeight <= 0)
3238 di << "Width and height must be positive values!\n";
3241 if (aMode != 0 && aMode != 1)
3244 // define compatible bitmap
3245 HDC anDC = CreateCompatibleDC(0);
3246 BITMAPINFO aBitmapData;
3247 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3248 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3249 aBitmapData.bmiHeader.biWidth = aWidth ;
3250 aBitmapData.bmiHeader.biHeight = aHeight;
3251 aBitmapData.bmiHeader.biPlanes = 1;
3252 aBitmapData.bmiHeader.biBitCount = 24;
3253 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3254 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3255 aBitmapData.bmiHeader.biClrUsed = 0;
3256 aBitmapData.bmiHeader.biClrImportant = 0;
3257 aBitmapData.bmiHeader.biCompression = BI_RGB;
3258 aBitmapData.bmiHeader.biSizeImage = 0;
3260 // Create Device Independent Bitmap
3261 void* aBitsOut = NULL;
3262 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3263 &aBitsOut, NULL, 0);
3264 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3266 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3267 if (aBitsOut != NULL)
3270 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3273 if (isTileSizeProvided)
3275 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
3276 Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
3277 aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight);
3279 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
3281 Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
3282 aView->View()->FBORelease (aNewBuffer);
3283 aCView->ptrFBO = anOldBuffer;
3287 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
3291 // succesfully printed into an intermediate buffer
3294 Image_PixMap aWrapper;
3295 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3296 aWrapper.SetTopDown (false);
3298 Image_AlienPixMap anImageBitmap;
3299 anImageBitmap.InitCopy (aWrapper);
3300 isSaved = anImageBitmap.Save (aFileName);
3304 di << "Print operation failed due to printing errors or\n";
3305 di << "insufficient memory available\n";
3306 di << "Please, try to use smaller dimensions for this test\n";
3307 di << "command, as it allocates intermediate buffer for storing\n";
3308 di << "the result\n";
3313 di << "Can't allocate memory for intermediate buffer\n";
3314 di << "Please use smaller dimensions\n";
3319 SelectObject (anDC, anOldBitmap);
3320 DeleteObject (aMemoryBitmap);
3326 di << "Save to file operation failed. This operation may fail\n";
3327 di << "if you don't have enough available memory, then you can\n";
3328 di << "use smaller dimensions for the output file\n";
3337 //==============================================================================
3338 //function : VZLayer
3339 //purpose : Test z layer operations for v3d viewer
3340 //==============================================================================
3341 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3343 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3344 if (aContextAIS.IsNull())
3346 di << "Call vinit before!\n";
3351 di << "Use: vzlayer ";
3352 di << " add/del/get/settings/enable/disable [id]\n";
3353 di << " add - add new z layer to viewer and print its id\n";
3354 di << " del - del z layer by its id\n";
3355 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3356 di << " settings - print status of z layer settings\n";
3357 di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n";
3358 di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n";
3359 di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n";
3360 di << "\nWhere id is the layer identificator\n";
3361 di << "\nExamples:\n";
3362 di << " vzlayer add\n";
3363 di << " vzlayer enable poffset 1\n";
3364 di << " vzlayer disable depthtest 1\n";
3365 di << " vzlayer del 1\n";
3369 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3370 if (aViewer.IsNull())
3372 di << "No active viewer!\n";
3376 // perform operation
3377 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3380 Standard_Integer aNewId;
3381 if (!aViewer->AddZLayer (aNewId))
3383 di << "Impossible to add new z layer!\n";
3387 di << "New z layer added with index: " << aNewId << "\n";
3389 else if (anOp == "del")
3393 di << "Please also provide as argument id of z layer to remove\n";
3397 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3398 if (!aViewer->RemoveZLayer (aDelId))
3400 di << "Impossible to remove the z layer or invalid id!\n";
3404 di << "Z layer " << aDelId << " has been removed\n";
3406 else if (anOp == "get")
3408 TColStd_SequenceOfInteger anIds;
3409 aViewer->GetAllZLayers (anIds);
3410 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3412 di << anIds.Value (aSeqIdx) << " ";
3417 else if (anOp == "settings")
3421 di << "Please also provide an id\n";
3425 Standard_Integer anId = Draw::Atoi (argv[2]);
3426 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
3428 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
3429 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
3430 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
3431 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
3434 else if (anOp == "enable")
3438 di << "Please also provide an option to enable\n";
3444 di << "Please also provide a layer id\n";
3448 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
3449 Standard_Integer anId = Draw::Atoi (argv[3]);
3450 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
3452 if (aSubOp == "depthtest" || aSubOp == "test")
3454 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
3456 else if (aSubOp == "depthwrite" || aSubOp == "write")
3458 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
3460 else if (aSubOp == "depthclear" || aSubOp == "clear")
3462 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
3464 else if (aSubOp == "depthoffset" || aSubOp == "offset")
3468 di << "Please also provide a factor and units values for depth offset\n";
3469 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
3473 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
3474 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
3475 anId = Draw::Atoi (argv[5]);
3476 aSettings = aViewer->ZLayerSettings (anId);
3478 aSettings.DepthOffsetFactor = aFactor;
3479 aSettings.DepthOffsetUnits = aUnits;
3481 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
3483 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
3485 aSettings.SetDepthOffsetPositive();
3487 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
3489 aSettings.SetDepthOffsetNegative();
3492 aViewer->SetZLayerSettings (anId, aSettings);
3494 else if (anOp == "disable")
3498 di << "Please also provide an option to disable\n";
3504 di << "Please also provide a layer id\n";
3508 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
3509 Standard_Integer anId = Draw::Atoi (argv[3]);
3510 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
3512 if (aSubOp == "depthtest" || aSubOp == "test")
3514 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
3516 else if (aSubOp == "depthwrite" || aSubOp == "write")
3518 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
3520 else if (aSubOp == "depthclear" || aSubOp == "clear")
3522 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
3524 else if (aSubOp == "depthoffset" || aSubOp == "offset")
3526 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
3529 aViewer->SetZLayerSettings (anId, aSettings);
3533 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
3540 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3542 // this class provides a presentation of text item in v3d view under-/overlayer
3543 class V3d_TextItem : public Visual3d_LayerItem
3548 DEFINE_STANDARD_RTTI(V3d_TextItem)
3551 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3552 const Standard_Real theX1,
3553 const Standard_Real theY1,
3554 const Standard_Real theHeight,
3555 const TCollection_AsciiString& theFontName,
3556 const Quantity_Color& theColor,
3557 const Quantity_Color& theSubtitleColor,
3558 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3559 const Handle(Visual3d_Layer)& theLayer);
3562 Standard_EXPORT void RedrawLayerPrs();
3568 TCollection_AsciiString myText;
3569 Standard_Real myHeight;
3570 Handle(Visual3d_Layer) myLayer;
3571 Quantity_Color myColor;
3572 Quantity_Color mySubtitleColor;
3573 Aspect_TypeOfDisplayText myType;
3574 TCollection_AsciiString myFontName;
3577 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3578 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3580 // create and add to display the text item
3581 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3582 const Standard_Real theX1,
3583 const Standard_Real theY1,
3584 const Standard_Real theHeight,
3585 const TCollection_AsciiString& theFontName,
3586 const Quantity_Color& theColor,
3587 const Quantity_Color& theSubtitleColor,
3588 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3589 const Handle(Visual3d_Layer)& theLayer)
3590 : myX1 (theX1), myY1 (theY1),
3592 myHeight (theHeight),
3595 mySubtitleColor (theSubtitleColor),
3596 myType (theTypeOfDisplay),
3597 myFontName (theFontName)
3599 if (!myLayer.IsNull ())
3600 myLayer->AddLayerItem (this);
3604 void V3d_TextItem::RedrawLayerPrs ()
3606 if (myLayer.IsNull ())
3609 myLayer->SetColor (myColor);
3610 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3611 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3614 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3616 // The Visual3d_LayerItem line item for "vlayerline" command
3617 // it provides a presentation of line with user-defined
3618 // linewidth, linetype and transparency.
3619 class V3d_LineItem : public Visual3d_LayerItem
3623 DEFINE_STANDARD_RTTI(V3d_LineItem)
3626 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3627 Standard_Real X2, Standard_Real Y2,
3628 V3d_LayerMgrPointer theLayerMgr,
3629 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3630 Standard_Real theWidth = 0.5,
3631 Standard_Real theTransp = 1.0);
3634 Standard_EXPORT void RedrawLayerPrs();
3638 Standard_Real myX1, myY1, myX2, myY2;
3639 V3d_LayerMgrPointer myLayerMgr;
3640 Aspect_TypeOfLine myType;
3641 Standard_Real myWidth;
3642 Standard_Real myTransparency;
3645 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3646 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3648 // default constructor for line item
3649 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3650 Standard_Real X2, Standard_Real Y2,
3651 V3d_LayerMgrPointer theLayerMgr,
3652 Aspect_TypeOfLine theType,
3653 Standard_Real theWidth,
3654 Standard_Real theTransp) :
3655 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3656 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3658 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3659 myLayerMgr->Overlay()->AddLayerItem (this);
3663 void V3d_LineItem::RedrawLayerPrs ()
3665 Handle (Visual3d_Layer) aOverlay;
3668 aOverlay = myLayerMgr->Overlay();
3670 if (!aOverlay.IsNull())
3672 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3673 aOverlay->SetColor(aColor);
3674 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3675 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3676 aOverlay->BeginPolyline();
3677 aOverlay->AddVertex(myX1, myY1);
3678 aOverlay->AddVertex(myX2, myY2);
3679 aOverlay->ClosePrimitive();
3683 //=============================================================================
3684 //function : VLayerLine
3685 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3686 // : linewidth, transparency coefficient
3687 //============================================================================
3688 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3690 // get the active view
3691 Handle(V3d_View) aView = ViewerTest::CurrentView();
3694 di << "Call vinit before!\n";
3699 di << "Use: " << argv[0];
3700 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3701 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3702 di << " 0 - solid \n";
3703 di << " 1 - dashed \n";
3704 di << " 2 - dot \n";
3705 di << " 3 - dashdot\n";
3706 di << " transparency : { 0.0 - 1.0 } \n";
3707 di << " 0.0 - transparent\n";
3708 di << " 1.0 - visible \n";
3712 // get the input params
3713 Standard_Real X1 = Draw::Atof(argv[1]);
3714 Standard_Real Y1 = Draw::Atof(argv[2]);
3715 Standard_Real X2 = Draw::Atof(argv[3]);
3716 Standard_Real Y2 = Draw::Atof(argv[4]);
3718 Standard_Real aWidth = 0.5;
3719 Standard_Integer aType = 0;
3720 Standard_Real aTransparency = 1.0;
3724 aWidth = Draw::Atof(argv[5]);
3728 aType = (Standard_Integer) Draw::Atoi(argv[6]);
3733 aTransparency = Draw::Atof(argv[7]);
3734 if (aTransparency < 0 || aTransparency > 1.0)
3735 aTransparency = 1.0;
3738 // select appropriate line type
3739 Aspect_TypeOfLine aLineType;
3743 aLineType = Aspect_TOL_DASH;
3747 aLineType = Aspect_TOL_DOT;
3751 aLineType = Aspect_TOL_DOTDASH;
3755 aLineType = Aspect_TOL_SOLID;
3758 // replace layer manager
3759 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3760 aView->SetLayerMgr(aMgr);
3763 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3769 aView->MustBeResized();
3775 //=======================================================================
3776 //function : VOverlayText
3777 //purpose : Test text displaying in view overlay
3778 //=======================================================================
3779 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3781 // get the active view
3782 Handle(V3d_View) aView = ViewerTest::CurrentView();
3785 di << "No active view. Please call vinit.\n";
3788 else if (argc < 4 || argc > 13)
3790 di << "Use: " << argv[0];
3791 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3792 di << "[background_color: R G B]\n";
3793 di << " height - pixel height of the text (default=10.0)\n";
3794 di << " font_name - name of font (default=courier)\n";
3795 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3796 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
3797 di << " background_color- R G B values used for subtitle and decal text\n";
3798 di << "(default=255.0 255.0 255.0)\n";
3802 TCollection_AsciiString aText (argv[1]);
3803 Standard_Real aPosX = Draw::Atof(argv[2]);
3804 Standard_Real aPosY = Draw::Atof(argv[3]);
3805 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3808 TCollection_AsciiString aFontName = "Courier";
3810 aFontName = TCollection_AsciiString (argv[5]);
3813 Quantity_Parameter aColorRed = 1.0;
3814 Quantity_Parameter aColorGreen = 1.0;
3815 Quantity_Parameter aColorBlue = 1.0;
3818 aColorRed = Draw::Atof (argv[6])/255.;
3819 aColorGreen = Draw::Atof (argv[7])/255.;
3820 aColorBlue = Draw::Atof (argv[8])/255.;
3824 TCollection_AsciiString aDispStr;
3826 aDispStr = TCollection_AsciiString (argv[9]);
3828 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3829 if (aDispStr.IsEqual ("subtitle"))
3830 aTextType = Aspect_TODT_SUBTITLE;
3831 else if (aDispStr.IsEqual ("decal"))
3832 aTextType = Aspect_TODT_DEKALE;
3833 else if (aDispStr.IsEqual ("blend"))
3834 aTextType = Aspect_TODT_BLEND;
3835 else if (aDispStr.IsEqual ("dimension"))
3836 aTextType = Aspect_TODT_DIMENSION;
3839 Quantity_Parameter aSubRed = 1.0;
3840 Quantity_Parameter aSubGreen = 1.0;
3841 Quantity_Parameter aSubBlue = 1.0;
3844 aSubRed = Draw::Atof (argv[10])/255.;
3845 aSubGreen = Draw::Atof (argv[11])/255.;
3846 aSubBlue = Draw::Atof (argv[12])/255.;
3849 // check fo current overlay
3850 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3851 if (anOverlay.IsNull ())
3853 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3854 anOverlay = aMgr->Overlay ();
3855 aView->SetLayerMgr (aMgr);
3858 Quantity_Color aTextColor (aColorRed, aColorGreen,
3859 aColorBlue, Quantity_TOC_RGB);
3860 Quantity_Color aSubtColor (aSubRed, aSubGreen,
3861 aSubBlue, Quantity_TOC_RGB);
3864 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3865 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3868 aView->MustBeResized();
3874 //==============================================================================
3877 //==============================================================================
3879 static int VGrid (Draw_Interpretor& /*theDI*/,
3880 Standard_Integer theArgNb,
3881 const char** theArgVec)
3883 // get the active view
3884 Handle(V3d_View) aView = ViewerTest::CurrentView();
3885 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3886 if (aView.IsNull() || aViewer.IsNull())
3888 std::cerr << "No active view. Please call vinit.\n";
3892 Aspect_GridType aType = aViewer->GridType();
3893 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3895 Standard_Integer anIter = 1;
3896 for (; anIter < theArgNb; ++anIter)
3898 const char* aValue = theArgVec[anIter];
3901 aType = Aspect_GT_Rectangular;
3903 else if (*aValue == 'c')
3905 aType = Aspect_GT_Circular;
3907 else if (*aValue == 'l')
3909 aMode = Aspect_GDM_Lines;
3911 else if (*aValue == 'p')
3913 aMode = Aspect_GDM_Points;
3915 else if (strcmp (aValue, "off" ) == 0)
3917 aViewer->DeactivateGrid();
3926 Standard_Integer aTail = (theArgNb - anIter);
3929 aViewer->ActivateGrid (aType, aMode);
3932 else if (aTail != 2 && aTail != 5)
3934 std::cerr << "Incorrect arguments number! Usage:\n"
3935 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3939 Quantity_Length anOriginX, anOriginY;
3940 Quantity_PlaneAngle aRotAngle;
3941 if (aType == Aspect_GT_Rectangular)
3943 Quantity_Length aRStepX, aRStepY;
3944 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3946 anOriginX = Draw::Atof (theArgVec[anIter++]);
3947 anOriginY = Draw::Atof (theArgVec[anIter++]);
3950 aRStepX = Draw::Atof (theArgVec[anIter++]);
3951 aRStepY = Draw::Atof (theArgVec[anIter++]);
3952 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3954 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3955 aViewer->ActivateGrid (aType, aMode);
3957 else if (aType == Aspect_GT_Circular)
3959 Quantity_Length aRadiusStep;
3960 Standard_Integer aDivisionNumber;
3961 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3963 anOriginX = Draw::Atof (theArgVec[anIter++]);
3964 anOriginY = Draw::Atof (theArgVec[anIter++]);
3967 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3968 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3969 aRotAngle = Draw::Atof (theArgVec[anIter++]);
3972 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3973 aViewer->ActivateGrid (aType, aMode);
3979 //==============================================================================
3982 //==============================================================================
3984 static int VFps (Draw_Interpretor& theDI,
3985 Standard_Integer theArgNb,
3986 const char** theArgVec)
3988 // get the active view
3989 Handle(V3d_View) aView = ViewerTest::CurrentView();
3992 std::cerr << "No active view. Please call vinit.\n";
3996 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3999 std::cerr << "Incorrect arguments!\n";
4003 // the time is meaningless for first call
4004 // due to async OpenGl rendering
4007 // redraw view in loop to estimate average values
4010 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
4016 const Standard_Real aTime = aTimer.ElapsedTime();
4017 aTimer.OSD_Chronometer::Show (aCpu);
4019 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
4020 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
4022 // return statistics
4023 theDI << "FPS: " << aFpsAver << "\n"
4024 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
4029 //==============================================================================
4030 //function : VGlDebug
4032 //==============================================================================
4034 static int VGlDebug (Draw_Interpretor& theDI,
4035 Standard_Integer theArgNb,
4036 const char** theArgVec)
4040 Handle(V3d_View) aView = ViewerTest::CurrentView();
4043 std::cerr << "No active view. Please call vinit.\n";
4047 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
4048 "GL_ARB_debug_output");
4049 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
4050 theDI << (isActive ? "1" : "0");
4054 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
4058 //==============================================================================
4061 //==============================================================================
4063 static int VVbo (Draw_Interpretor& theDI,
4064 Standard_Integer theArgNb,
4065 const char** theArgVec)
4067 const Standard_Boolean toSet = (theArgNb > 1);
4068 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
4071 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
4075 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4076 if (aContextAIS.IsNull())
4080 std::cerr << "No active view!\n";
4084 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
4085 if (!aDriver.IsNull())
4089 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
4093 aDriver->ChangeOptions().vboDisable = toUseVbo;
4100 //==============================================================================
4103 //==============================================================================
4105 static int VCaps (Draw_Interpretor& theDI,
4106 Standard_Integer theArgNb,
4107 const char** theArgVec)
4109 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
4110 Handle(OpenGl_GraphicDriver) aDriver;
4111 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4112 if (!aContextAIS.IsNull())
4114 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
4115 aCaps = &aDriver->ChangeOptions();
4120 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
4121 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
4122 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
4126 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4128 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
4129 if (anArg.Search ("vbo=") > -1)
4131 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
4133 else if (anArg.Search ("sprites=") > -1)
4135 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
4137 else if (anArg.Search ("soft=") > -1)
4139 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
4143 std::cerr << "Unknown argument: " << anArg << "\n";
4146 if (aCaps != &ViewerTest_myDefaultCaps)
4148 ViewerTest_myDefaultCaps = *aCaps;
4153 //==============================================================================
4154 //function : VMemGpu
4156 //==============================================================================
4158 static int VMemGpu (Draw_Interpretor& theDI,
4159 Standard_Integer theArgNb,
4160 const char** theArgVec)
4163 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4164 if (aContextAIS.IsNull())
4166 std::cerr << "No active view. Please call vinit.\n";
4170 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
4171 if (aDriver.IsNull())
4173 std::cerr << "Graphic driver not available.\n";
4177 Standard_Size aFreeBytes = 0;
4178 TCollection_AsciiString anInfo;
4179 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
4181 std::cerr << "Information not available.\n";
4185 if (theArgNb > 1 && *theArgVec[1] == 'f')
4187 theDI << Standard_Real (aFreeBytes);
4197 // ==============================================================================
4198 // function : VReadPixel
4200 // ==============================================================================
4201 static int VReadPixel (Draw_Interpretor& theDI,
4202 Standard_Integer theArgNb,
4203 const char** theArgVec)
4205 // get the active view
4206 Handle(V3d_View) aView = ViewerTest::CurrentView();
4209 std::cerr << "No active view. Please call vinit.\n";
4212 else if (theArgNb < 3)
4214 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4218 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4219 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4221 Standard_Integer aWidth, aHeight;
4222 aView->Window()->Size (aWidth, aHeight);
4223 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4224 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4225 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4227 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4231 Standard_Boolean toShowName = Standard_False;
4232 Standard_Boolean toShowHls = Standard_False;
4233 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4235 const char* aParam = theArgVec[anIter];
4236 if ( strcasecmp( aParam, "rgb" ) == 0 )
4238 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4239 aBufferType = Graphic3d_BT_RGB;
4241 else if ( strcasecmp( aParam, "hls" ) == 0 )
4243 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4244 aBufferType = Graphic3d_BT_RGB;
4245 toShowHls = Standard_True;
4247 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4249 aFormat = Image_PixMap::ImgRGBF;
4250 aBufferType = Graphic3d_BT_RGB;
4252 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4254 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4255 aBufferType = Graphic3d_BT_RGBA;
4257 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4259 aFormat = Image_PixMap::ImgRGBAF;
4260 aBufferType = Graphic3d_BT_RGBA;
4262 else if ( strcasecmp( aParam, "depth" ) == 0 )
4264 aFormat = Image_PixMap::ImgGrayF;
4265 aBufferType = Graphic3d_BT_Depth;
4267 else if ( strcasecmp( aParam, "name" ) == 0 )
4269 toShowName = Standard_True;
4273 Image_PixMap anImage;
4274 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4276 std::cerr << "Image allocation failed\n";
4279 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4281 std::cerr << "Image dump failed\n";
4285 Quantity_Parameter anAlpha;
4286 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4289 if (aBufferType == Graphic3d_BT_RGBA)
4291 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
4295 theDI << Quantity_Color::StringName (aColor.Name());
4300 switch (aBufferType)
4303 case Graphic3d_BT_RGB:
4307 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
4311 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
4315 case Graphic3d_BT_RGBA:
4317 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
4320 case Graphic3d_BT_Depth:
4322 theDI << aColor.Red();
4331 //==============================================================================
4332 //function : VDiffImage
4333 //purpose : The draw-command compares two images.
4334 //==============================================================================
4336 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4340 theDI << "Not enough arguments.\n";
4345 const char* anImgPathRef = theArgVec[1];
4346 const char* anImgPathNew = theArgVec[2];
4348 // get string tolerance and check its validity
4349 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4350 if (aTolColor < 0.0)
4352 if (aTolColor > 1.0)
4355 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4356 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4358 // image file of difference
4359 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4361 // compare the images
4362 Image_Diff aComparer;
4363 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4368 aComparer.SetColorTolerance (aTolColor);
4369 aComparer.SetBorderFilterOn (isBorderFilterOn);
4370 Standard_Integer aDiffColorsNb = aComparer.Compare();
4371 theDI << aDiffColorsNb << "\n";
4373 // save image of difference
4374 if (aDiffImagePath != NULL)
4376 aComparer.SaveDiffImage (aDiffImagePath);
4382 //=======================================================================
4383 //function : VSelect
4384 //purpose : Emulates different types of selection by mouse:
4385 // 1) single click selection
4386 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4387 // 3) selection with polygon having corners at
4388 // pixel positions (x1,y1),...,(xn,yn)
4389 // 4) any of these selections with shift button pressed
4390 //=======================================================================
4391 static Standard_Integer VSelect (Draw_Interpretor& di,
4392 Standard_Integer argc,
4397 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4401 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4402 if(myAIScontext.IsNull())
4404 di << "use 'vinit' command before " << argv[0] << "\n";
4407 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4408 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4409 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4412 if(isShiftSelection)
4413 aCurrentEventManager->ShiftSelect();
4415 aCurrentEventManager->Select();
4419 if(isShiftSelection)
4420 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4422 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4426 Standard_Integer anUpper = 0;
4428 if(isShiftSelection)
4429 anUpper = (argc-1)/2;
4432 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4434 for(Standard_Integer i=1;i<=anUpper;++i)
4435 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4437 if(isShiftSelection)
4438 aCurrentEventManager->ShiftSelect(aPolyline);
4440 aCurrentEventManager->Select(aPolyline);
4445 //=======================================================================
4446 //function : VMoveTo
4447 //purpose : Emulates cursor movement to defined pixel position
4448 //=======================================================================
4449 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4450 Standard_Integer argc,
4455 di << "Usage : " << argv[0] << " x y" << "\n";
4459 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4460 if(aContext.IsNull())
4462 di << "use 'vinit' command before " << argv[0] << "\n";
4465 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4469 //=================================================================================================
4470 //function : VViewParams
4471 //purpose : Gets or sets AIS View characteristics
4472 //=================================================================================================
4473 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4475 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
4476 if (anAISView.IsNull())
4478 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
4484 // print all of the available view parameters
4485 Quantity_Factor anAISViewScale = anAISView->Scale();
4487 Standard_Real anAISViewProjX = 0.0;
4488 Standard_Real anAISViewProjY = 0.0;
4489 Standard_Real anAISViewProjZ = 0.0;
4490 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4492 Standard_Real anAISViewUpX = 0.0;
4493 Standard_Real anAISViewUpY = 0.0;
4494 Standard_Real anAISViewUpZ = 0.0;
4495 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4497 Standard_Real anAISViewAtX = 0.0;
4498 Standard_Real anAISViewAtY = 0.0;
4499 Standard_Real anAISViewAtZ = 0.0;
4500 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4502 Standard_Real anAISViewEyeX = 0.0;
4503 Standard_Real anAISViewEyeY = 0.0;
4504 Standard_Real anAISViewEyeZ = 0.0;
4505 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
4507 theDi << "Scale of current view: " << anAISViewScale << "\n";
4508 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4509 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4510 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4511 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
4515 // -------------------------
4516 // Parse options and values
4517 // -------------------------
4519 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
4520 TCollection_AsciiString aParseKey;
4521 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4523 TCollection_AsciiString anArg (theArgVec [anArgIt]);
4525 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4528 aParseKey.Remove (1);
4529 aParseKey.UpperCase();
4530 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4534 if (aParseKey.IsEmpty())
4536 std::cout << theArgVec[0] << ": values should be passed with key.\n";
4537 std::cout << "Type help for more information.\n";
4541 aMapOfKeysByValues(aParseKey)->Append (anArg);
4544 // ---------------------------------------------
4545 // Change or print parameters, order plays role
4546 // ---------------------------------------------
4548 // Check arguments for validity
4549 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
4550 for (; aMapIt.More(); aMapIt.Next())
4552 const TCollection_AsciiString& aKey = aMapIt.Key();
4553 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
4555 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
4556 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
4557 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
4558 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
4559 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
4560 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
4561 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
4563 TCollection_AsciiString aLowerKey;
4566 aLowerKey.LowerCase();
4567 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
4568 std::cout << "Type help for more information.\n";
4573 Handle(TColStd_HSequenceOfAsciiString) aValues;
4575 // Change view parameters in proper order
4576 if (aMapOfKeysByValues.Find ("SCALE", aValues))
4578 if (aValues->IsEmpty())
4580 theDi << "Scale: " << anAISView->Scale() << "\n";
4584 anAISView->SetScale (aValues->Value(1).RealValue());
4587 if (aMapOfKeysByValues.Find ("SIZE", aValues))
4589 if (aValues->IsEmpty())
4591 Standard_Real aSizeX = 0.0;
4592 Standard_Real aSizeY = 0.0;
4593 anAISView->Size (aSizeX, aSizeY);
4594 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
4598 anAISView->SetSize (aValues->Value(1).RealValue());
4601 if (aMapOfKeysByValues.Find ("EYE", aValues))
4603 if (aValues->IsEmpty())
4605 Standard_Real anEyeX = 0.0;
4606 Standard_Real anEyeY = 0.0;
4607 Standard_Real anEyeZ = 0.0;
4608 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
4609 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
4613 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4616 if (aMapOfKeysByValues.Find ("AT", aValues))
4618 if (aValues->IsEmpty())
4620 Standard_Real anAtX = 0.0;
4621 Standard_Real anAtY = 0.0;
4622 Standard_Real anAtZ = 0.0;
4623 anAISView->At (anAtX, anAtY, anAtZ);
4624 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
4628 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4631 if (aMapOfKeysByValues.Find ("PROJ", aValues))
4633 if (aValues->IsEmpty())
4635 Standard_Real aProjX = 0.0;
4636 Standard_Real aProjY = 0.0;
4637 Standard_Real aProjZ = 0.0;
4638 anAISView->Proj (aProjX, aProjY, aProjZ);
4639 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
4643 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4646 if (aMapOfKeysByValues.Find ("UP", aValues))
4648 if (aValues->IsEmpty())
4650 Standard_Real anUpX = 0.0;
4651 Standard_Real anUpY = 0.0;
4652 Standard_Real anUpZ = 0.0;
4653 anAISView->Up (anUpX, anUpY, anUpZ);
4654 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
4658 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
4661 if (aMapOfKeysByValues.Find ("CENTER", aValues))
4663 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
4669 //=======================================================================
4670 //function : VChangeSelected
4671 //purpose : Adds the shape to selection or remove one from it
4672 //=======================================================================
4673 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4674 Standard_Integer argc,
4679 di<<"Usage : " << argv[0] << " shape \n";
4683 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4684 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4685 TCollection_AsciiString aName(argv[1]);
4686 Handle(AIS_InteractiveObject) anAISObject;
4688 if(!aMap.IsBound2(aName))
4690 di<<"Use 'vdisplay' before";
4695 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4696 if(anAISObject.IsNull()){
4697 di<<"No interactive object \n";
4701 if(aContext->HasOpenedContext())
4703 aContext->AddOrRemoveSelected(anAISObject);
4707 aContext->AddOrRemoveCurrentObject(anAISObject);
4713 //=======================================================================
4714 //function : VZClipping
4715 //purpose : Gets or sets ZClipping mode, width and depth
4716 //=======================================================================
4717 static Standard_Integer VZClipping (Draw_Interpretor& di,
4718 Standard_Integer argc,
4723 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4724 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4727 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4728 if(aContext.IsNull())
4730 di << "use 'vinit' command before " << argv[0] << "\n";
4733 Handle(V3d_View) aView = ViewerTest::CurrentView();
4734 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4737 TCollection_AsciiString aZClippingModeString;
4738 Quantity_Length aDepth, aWidth;
4739 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4740 switch (aZClippingMode)
4743 aZClippingModeString.Copy("OFF");
4746 aZClippingModeString.Copy("BACK");
4749 aZClippingModeString.Copy("FRONT");
4752 aZClippingModeString.Copy("SLICE");
4755 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4758 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4759 << "ZClipping depth = " << aDepth << "\n"
4760 << "ZClipping width = " << aWidth << "\n";
4766 Standard_Integer aStatus = 0;
4767 if ( strcmp (argv [1], "OFF") == 0 ) {
4769 aZClippingMode = V3d_OFF;
4771 if ( strcmp (argv [1], "BACK") == 0 ) {
4773 aZClippingMode = V3d_BACK;
4775 if ( strcmp (argv [1], "FRONT") == 0 ) {
4777 aZClippingMode = V3d_FRONT;
4779 if ( strcmp (argv [1], "SLICE") == 0 ) {
4781 aZClippingMode = V3d_SLICE;
4785 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4786 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4789 aView->SetZClippingType(aZClippingMode);
4793 Quantity_Length aDepth = 0., aWidth = 1.;
4796 aDepth = atof(argv[1]);
4797 aWidth = atof(argv[2]);
4801 aDepth = atof(argv[2]);
4802 aWidth = atof(argv[3]);
4805 if(aDepth<0. || aDepth>1.)
4807 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4808 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4811 if(aWidth<0. || aWidth>1.)
4813 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4814 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4818 aView->SetZClippingDepth(aDepth);
4819 aView->SetZClippingWidth(aWidth);
4826 //=======================================================================
4827 //function : VNbSelected
4828 //purpose : Returns number of selected objects
4829 //=======================================================================
4830 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4831 Standard_Integer argc,
4836 di << "Usage : " << argv[0] << "\n";
4839 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4840 if(aContext.IsNull())
4842 di << "use 'vinit' command before " << argv[0] << "\n";
4845 di << aContext->NbSelected() << "\n";
4849 //=======================================================================
4850 //function : VAntialiasing
4851 //purpose : Switches altialiasing on or off
4852 //=======================================================================
4853 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4854 Standard_Integer argc,
4859 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4863 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4864 if(aContext.IsNull())
4866 di << "use 'vinit' command before " << argv[0] << "\n";
4870 Handle(V3d_View) aView = ViewerTest::CurrentView();
4872 if((argc == 2) && (atof(argv[1]) == 0))
4873 aView->SetAntialiasingOff();
4875 aView->SetAntialiasingOn();
4880 //=======================================================================
4881 //function : VPurgeDisplay
4882 //purpose : Switches altialiasing on or off
4883 //=======================================================================
4884 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4885 Standard_Integer argc,
4890 di << "Usage : " << argv[0] << "\n";
4893 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4894 if (aContext.IsNull())
4896 di << "use 'vinit' command before " << argv[0] << "\n";
4899 aContext->CloseAllContexts(Standard_False);
4900 di << aContext->PurgeDisplay() << "\n";
4904 //=======================================================================
4905 //function : VSetViewSize
4907 //=======================================================================
4908 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4909 Standard_Integer argc,
4912 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4913 if(aContext.IsNull())
4915 di << "use 'vinit' command before " << argv[0] << "\n";
4920 di<<"Usage : " << argv[0] << " Size\n";
4923 Standard_Real aSize = atof(argv[1]);
4926 di<<"Bad Size value : " << aSize << "\n";
4930 Handle(V3d_View) aView = ViewerTest::CurrentView();
4931 aView->SetSize(aSize);
4935 //=======================================================================
4936 //function : VMoveView
4938 //=======================================================================
4939 static Standard_Integer VMoveView (Draw_Interpretor& di,
4940 Standard_Integer argc,
4943 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4944 if(aContext.IsNull())
4946 di << "use 'vinit' command before " << argv[0] << "\n";
4949 if(argc < 4 || argc > 5)
4951 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4954 Standard_Real Dx = atof(argv[1]);
4955 Standard_Real Dy = atof(argv[2]);
4956 Standard_Real Dz = atof(argv[3]);
4957 Standard_Boolean aStart = Standard_True;
4960 aStart = (atoi(argv[4]) > 0);
4963 Handle(V3d_View) aView = ViewerTest::CurrentView();
4964 aView->Move(Dx,Dy,Dz,aStart);
4968 //=======================================================================
4969 //function : VTranslateView
4971 //=======================================================================
4972 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4973 Standard_Integer argc,
4976 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4977 if(aContext.IsNull())
4979 di << "use 'vinit' command before " << argv[0] << "\n";
4982 if(argc < 4 || argc > 5)
4984 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4987 Standard_Real Dx = atof(argv[1]);
4988 Standard_Real Dy = atof(argv[2]);
4989 Standard_Real Dz = atof(argv[3]);
4990 Standard_Boolean aStart = Standard_True;
4993 aStart = (atoi(argv[4]) > 0);
4996 Handle(V3d_View) aView = ViewerTest::CurrentView();
4997 aView->Translate(Dx,Dy,Dz,aStart);
5001 //=======================================================================
5002 //function : VTurnView
5004 //=======================================================================
5005 static Standard_Integer VTurnView (Draw_Interpretor& di,
5006 Standard_Integer argc,
5009 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5010 if(aContext.IsNull()) {
5011 di << "use 'vinit' command before " << argv[0] << "\n";
5014 if(argc < 4 || argc > 5){
5015 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
5018 Standard_Real Ax = atof(argv[1]);
5019 Standard_Real Ay = atof(argv[2]);
5020 Standard_Real Az = atof(argv[3]);
5021 Standard_Boolean aStart = Standard_True;
5024 aStart = (atoi(argv[4]) > 0);
5027 Handle(V3d_View) aView = ViewerTest::CurrentView();
5028 aView->Turn(Ax,Ay,Az,aStart);
5032 //==============================================================================
5033 //function : VTextureEnv
5034 //purpose : ENables or disables environment mapping
5035 //==============================================================================
5036 class OCC_TextureEnv : public Graphic3d_TextureEnv
5039 OCC_TextureEnv(const Standard_CString FileName);
5040 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
5041 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
5042 const Standard_Boolean theModulateFlag,
5043 const Graphic3d_TypeOfTextureFilter theFilter,
5044 const Standard_ShortReal theXScale,
5045 const Standard_ShortReal theYScale,
5046 const Standard_ShortReal theXShift,
5047 const Standard_ShortReal theYShift,
5048 const Standard_ShortReal theAngle);
5049 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
5051 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
5052 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
5053 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
5055 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
5056 : Graphic3d_TextureEnv(theFileName)
5060 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
5061 : Graphic3d_TextureEnv(theTexId)
5065 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
5066 const Standard_Boolean theModulateFlag,
5067 const Graphic3d_TypeOfTextureFilter theFilter,
5068 const Standard_ShortReal theXScale,
5069 const Standard_ShortReal theYScale,
5070 const Standard_ShortReal theXShift,
5071 const Standard_ShortReal theYShift,
5072 const Standard_ShortReal theAngle)
5074 myParams->SetRepeat (theRepeatFlag);
5075 myParams->SetModulate (theModulateFlag);
5076 myParams->SetFilter (theFilter);
5077 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
5078 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
5079 myParams->SetRotation (theAngle);
5082 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
5084 // get the active view
5085 Handle(V3d_View) aView = ViewerTest::CurrentView();
5088 std::cerr << "No active view. Please call vinit.\n";
5092 // Checking the input arguments
5093 Standard_Boolean anEnableFlag = Standard_False;
5094 Standard_Boolean isOk = theArgNb >= 2;
5097 TCollection_AsciiString anEnableOpt(theArgVec[1]);
5098 anEnableFlag = anEnableOpt.IsEqual("on");
5099 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
5103 isOk = (theArgNb == 3 || theArgNb == 11);
5106 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5107 isOk = (!aTextureOpt.IsIntegerValue() ||
5108 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
5110 if (isOk && theArgNb == 11)
5112 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
5113 aModulateOpt(theArgVec[4]),
5114 aFilterOpt (theArgVec[5]),
5115 aSScaleOpt (theArgVec[6]),
5116 aTScaleOpt (theArgVec[7]),
5117 aSTransOpt (theArgVec[8]),
5118 aTTransOpt (theArgVec[9]),
5119 anAngleOpt (theArgVec[10]);
5120 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
5121 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
5122 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
5123 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
5124 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
5125 anAngleOpt.IsRealValue());
5132 std::cerr << "Usage :" << std::endl;
5133 std::cerr << theArgVec[0] << " off" << std::endl;
5134 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;
5140 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5141 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
5142 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
5143 new OCC_TextureEnv(theArgVec[2]);
5147 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
5148 aTexEnv->SetTextureParameters(
5149 aRepeatOpt. IsEqual("repeat"),
5150 aModulateOpt.IsEqual("modulate"),
5151 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
5152 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
5153 Graphic3d_TOTF_TRILINEAR,
5154 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
5155 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
5156 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
5157 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
5158 (Standard_ShortReal)Draw::Atof(theArgVec[10])
5161 aView->SetTextureEnv(aTexEnv);
5162 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
5164 else // Disabling environment mapping
5166 aView->SetSurfaceDetail(V3d_TEX_NONE);
5167 Handle(Graphic3d_TextureEnv) aTexture;
5168 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
5175 //===============================================================================================
5176 //function : VClipPlane
5178 //===============================================================================================
5179 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5181 // use short-cut for created clip planes map of created (or "registered by name") clip planes
5182 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
5183 static MapOfPlanes aRegPlanes;
5187 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
5191 TCollection_AsciiString aCommand (theArgVec[1]);
5193 // print maximum number of planes for current viewer
5194 if (aCommand == "maxplanes")
5198 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
5202 TCollection_AsciiString aViewName (theArgVec[2]);
5204 if (!ViewerTest_myViews.IsBound1 (aViewName))
5206 theDi << theArgVec[0] << ": view is not found.\n";
5210 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5212 theDi << theArgVec[0] << ": "
5213 << aView->Viewer()->Driver()->InquirePlaneLimit()
5214 << " plane slots provided by driver."
5215 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
5220 // create / delete plane instance
5221 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
5225 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
5229 Standard_Boolean toCreate = (aCommand == "create");
5230 Standard_Boolean toClone = (aCommand == "clone");
5231 TCollection_AsciiString aPlane (theArgVec[2]);
5235 if (aRegPlanes.IsBound (aPlane))
5237 theDi << theArgVec[0] << ": plane name is in use.\n";
5241 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
5243 else if (toClone) // toClone
5245 if (!aRegPlanes.IsBound (aPlane))
5247 theDi << theArgVec[0] << ": no such plane.\n";
5253 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
5257 TCollection_AsciiString aClone (theArgVec[3]);
5258 if (aRegPlanes.IsBound (aClone))
5260 theDi << theArgVec[0] << ": plane name is in use.\n";
5264 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5266 aRegPlanes.Bind (aClone, aClipPlane->Clone());
5270 if (!aRegPlanes.IsBound (aPlane))
5272 theDi << theArgVec[0] << ": no such plane.\n";
5276 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
5277 aRegPlanes.UnBind (aPlane);
5279 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
5280 for (; anIObjIt.More(); anIObjIt.Next())
5282 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
5283 aPrs->RemoveClipPlane(aClipPlane);
5286 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
5287 for (; aViewIt.More(); aViewIt.Next())
5289 const Handle(V3d_View)& aView = aViewIt.Key2();
5290 aView->RemoveClipPlane(aClipPlane);
5293 ViewerTest::RedrawAllViews();
5299 // set / unset plane command
5300 if (aCommand == "set" || aCommand == "unset")
5304 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5308 Standard_Boolean toSet = (aCommand == "set");
5309 TCollection_AsciiString aPlane (theArgVec [2]);
5310 if (!aRegPlanes.IsBound (aPlane))
5312 theDi << theArgVec[0] << ": no such plane.\n";
5316 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5318 TCollection_AsciiString aTarget (theArgVec [3]);
5319 if (aTarget != "object" && aTarget != "view")
5321 theDi << theArgVec[0] << ": invalid target.\n";
5325 if (aTarget == "object" || aTarget == "view")
5329 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5333 Standard_Boolean isObject = (aTarget == "object");
5335 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
5337 TCollection_AsciiString anEntityName (theArgVec[anIt]);
5338 if (isObject) // to object
5340 if (!GetMapOfAIS().IsBound2 (anEntityName))
5342 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
5346 Handle(AIS_InteractiveObject) aIObj =
5347 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
5350 aIObj->AddClipPlane (aClipPlane);
5352 aIObj->RemoveClipPlane (aClipPlane);
5356 if (!ViewerTest_myViews.IsBound1 (anEntityName))
5358 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
5362 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
5364 aView->AddClipPlane (aClipPlane);
5366 aView->RemoveClipPlane (aClipPlane);
5370 ViewerTest::RedrawAllViews();
5376 // change plane command
5377 if (aCommand == "change")
5381 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5385 TCollection_AsciiString aPlane (theArgVec [2]);
5386 if (!aRegPlanes.IsBound (aPlane))
5388 theDi << theArgVec[0] << ": no such plane.\n";
5392 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5394 TCollection_AsciiString aChangeArg (theArgVec [3]);
5395 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5397 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5401 if (aChangeArg == "on" || aChangeArg == "off") // on / off
5403 aClipPlane->SetOn (aChangeArg == "on");
5405 else if (aChangeArg == "equation") // change equation
5409 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5413 Standard_Real aCoeffA = atof (theArgVec [4]);
5414 Standard_Real aCoeffB = atof (theArgVec [5]);
5415 Standard_Real aCoeffC = atof (theArgVec [6]);
5416 Standard_Real aCoeffD = atof (theArgVec [7]);
5417 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5419 else if (aChangeArg == "capping") // change capping aspects
5423 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5427 TCollection_AsciiString aCappingArg (theArgVec [4]);
5428 if (aCappingArg != "on" && aCappingArg != "off" &&
5429 aCappingArg != "color" && aCappingArg != "texname" &&
5430 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5431 aCappingArg != "texrotate" && aCappingArg != "hatch")
5433 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5437 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5439 aClipPlane->SetCapping (aCappingArg == "on");
5441 else if (aCappingArg == "color") // color aspect for capping
5445 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5449 Standard_Real aRed = atof (theArgVec [5]);
5450 Standard_Real aGrn = atof (theArgVec [6]);
5451 Standard_Real aBlu = atof (theArgVec [7]);
5453 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5454 Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB);
5455 aMat.SetAmbientColor (aColor);
5456 aMat.SetDiffuseColor (aColor);
5457 aClipPlane->SetCappingMaterial (aMat);
5459 else if (aCappingArg == "texname") // texture name
5463 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5467 TCollection_AsciiString aTextureName (theArgVec [5]);
5469 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5470 if (!aTexture->IsDone ())
5472 aClipPlane->SetCappingTexture (NULL);
5476 aTexture->EnableModulate();
5477 aTexture->EnableRepeat();
5478 aClipPlane->SetCappingTexture (aTexture);
5481 else if (aCappingArg == "texscale") // texture scale
5483 if (aClipPlane->CappingTexture().IsNull())
5485 theDi << theArgVec[0] << ": no texture is set.\n";
5491 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5495 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5496 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5498 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5500 else if (aCappingArg == "texorigin") // texture origin
5502 if (aClipPlane->CappingTexture().IsNull())
5504 theDi << theArgVec[0] << ": no texture is set.\n";
5510 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5514 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5515 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5517 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5519 else if (aCappingArg == "texrotate") // texture rotation
5521 if (aClipPlane->CappingTexture().IsNull())
5523 theDi << theArgVec[0] << ": no texture is set.\n";
5529 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5533 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5535 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5537 else if (aCappingArg == "hatch") // hatch style
5541 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5545 TCollection_AsciiString aHatchStr (theArgVec [5]);
5546 if (aHatchStr == "on")
5548 aClipPlane->SetCappingHatchOn();
5550 else if (aHatchStr == "off")
5552 aClipPlane->SetCappingHatchOff();
5556 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5561 ViewerTest::RedrawAllViews();
5566 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5570 //===============================================================================================
5571 //function : VSetTextureMode
5573 //===============================================================================================
5574 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5578 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5582 TCollection_AsciiString aViewName (theArgVec[1]);
5583 if (!ViewerTest_myViews.IsBound1 (aViewName))
5585 theDi << theArgVec[0] << ": view is not found.\n";
5589 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5590 switch (atoi (theArgVec[2]))
5592 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5593 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5594 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5596 theDi << theArgVec[0] << ": invalid mode.\n";
5604 //===============================================================================================
5605 //function : VZRange
5607 //===============================================================================================
5608 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5610 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
5612 if (aCurrentView.IsNull())
5614 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
5618 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
5622 theDi << "ZNear: " << aCamera->ZNear() << "\n";
5623 theDi << "ZFar: " << aCamera->ZFar() << "\n";
5629 Standard_Real aNewZNear = atof (theArgVec[1]);
5630 Standard_Real aNewZFar = atof (theArgVec[2]);
5632 if (aNewZNear >= aNewZFar)
5634 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
5638 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
5640 std::cout << theArgVec[0] << ": invalid arguments: ";
5641 std::cout << "znear, zfar should be positive for perspective camera.\n";
5645 aCamera->SetZRange (aNewZNear, aNewZFar);
5649 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
5653 aCurrentView->Redraw();
5658 //===============================================================================================
5659 //function : VAutoZFit
5661 //===============================================================================================
5662 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5664 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
5666 if (aCurrentView.IsNull())
5668 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
5672 Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor();
5676 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
5682 theDi << "Auto z-fit mode: " << "\n"
5683 << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n"
5684 << "Scale: " << aScale << "\n";
5688 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
5692 aScale = Draw::Atoi (theArgVec[2]);
5695 aCurrentView->View()->SetAutoZFitMode (isOn, aScale);
5696 aCurrentView->View()->AutoZFit();
5697 aCurrentView->Redraw();
5702 //===============================================================================================
5703 //function : VChangeCamera
5705 //===============================================================================================
5706 static int VChangeCamera (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5708 if (ViewerTest::CurrentView().IsNull())
5710 theDi << theArgVec[0] << ": Call vinit before this command, please.\n";
5714 const char anErrorMessage[] = ": wrong command arguments. Type help for more information.\n";
5717 theDi << theArgVec[0] << anErrorMessage;
5721 Handle(Graphic3d_Camera) aCamera = ViewerTest::CurrentView()->Camera();
5723 TCollection_AsciiString aCommand (theArgVec[1]);
5724 TCollection_AsciiString aValue (theArgVec[2]);
5726 aCommand.LowerCase();
5729 if (aCommand == "proj")
5731 if (aValue == "ortho")
5733 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
5735 else if (aValue == "persp")
5737 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
5739 else if (aValue == "left")
5741 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
5743 else if (aValue == "right")
5745 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
5747 else if (aValue == "stereo")
5749 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
5753 theDi << theArgVec[0] << anErrorMessage;
5757 else if (aCommand == "dist")
5759 aCamera->SetDistance (aValue.RealValue());
5761 else if (aCommand == "iod")
5763 aCamera->SetIOD (aCamera->GetIODType(), aValue.RealValue());
5765 else if (aCommand == "zfocus")
5767 aCamera->SetZFocus (aCamera->ZFocusType(), aValue.RealValue());
5769 else if (aCommand == "fov")
5771 aCamera->SetFOVy (aValue.RealValue());
5773 else if (aCommand == "zfocustype")
5775 if (aValue == "absolute")
5777 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
5779 else if (aValue == "relative")
5781 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
5785 theDi << theArgVec[0] << anErrorMessage;
5789 else if (aCommand == "iodtype")
5791 if (aValue == "absolute")
5793 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
5795 else if (aValue == "relative")
5797 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
5801 theDi << theArgVec[0] << anErrorMessage;
5807 theDi << theArgVec[0] << anErrorMessage;
5811 ViewerTest::CurrentView()->View()->AutoZFit();
5812 ViewerTest::CurrentView()->Redraw();
5817 //==============================================================================
5818 //function : VStereo
5820 //==============================================================================
5822 static int VStereo (Draw_Interpretor& theDI,
5823 Standard_Integer theArgNb,
5824 const char** theArgVec)
5828 Handle(V3d_View) aView = ViewerTest::CurrentView();
5831 std::cerr << "No active view. Please call vinit.\n";
5835 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
5836 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
5840 ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0;
5844 //===============================================================================================
5845 //function : VDefaults
5847 //===============================================================================================
5848 static int VDefaults (Draw_Interpretor& theDi,
5849 Standard_Integer theArgsNb,
5850 const char** theArgVec)
5852 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5855 std::cerr << "No active viewer!\n";
5859 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
5862 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
5864 theDi << "DeflType: relative\n"
5865 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
5869 theDi << "DeflType: absolute\n"
5870 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
5872 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
5876 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5878 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5879 TCollection_AsciiString aKey, aValue;
5880 if (!ViewerTest::SplitParameter (anArg, aKey, aValue)
5881 || aValue.IsEmpty())
5883 std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
5888 if (aKey == "ABSDEFL"
5889 || aKey == "ABSOLUTEDEFLECTION"
5891 || aKey == "DEFLECTION")
5893 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
5894 aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
5896 else if (aKey == "RELDEFL"
5897 || aKey == "RELATIVEDEFLECTION"
5898 || aKey == "DEVCOEFF"
5899 || aKey == "DEVIATIONCOEFF"
5900 || aKey == "DEVIATIONCOEFFICIENT")
5902 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
5903 aDefParams->SetDeviationCoefficient (aValue.RealValue());
5905 else if (aKey == "ANGDEFL"
5906 || aKey == "ANGULARDEFL"
5907 || aKey == "ANGULARDEFLECTION")
5909 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
5910 aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
5914 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
5921 //! Auxiliary method
5922 inline void addLight (const Handle(V3d_Light)& theLightNew,
5923 const Standard_Boolean theIsGlobal)
5925 if (theLightNew.IsNull())
5932 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
5936 ViewerTest::CurrentView()->SetLightOn (theLightNew);
5940 //! Auxiliary method
5941 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
5943 TCollection_AsciiString anArgNextCase (theArgNext);
5944 anArgNextCase.UpperCase();
5945 if (anArgNextCase.Length() > 5
5946 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
5948 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
5952 return theArgNext.IntegerValue();
5956 //===============================================================================================
5959 //===============================================================================================
5960 static int VLight (Draw_Interpretor& theDi,
5961 Standard_Integer theArgsNb,
5962 const char** theArgVec)
5964 Handle(V3d_View) aView = ViewerTest::CurrentView();
5965 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5967 || aViewer.IsNull())
5969 std::cerr << "No active viewer!\n";
5973 Standard_Real anXYZ[3];
5974 Quantity_Coefficient anAtten[2];
5977 // print lights info
5978 Standard_Integer aLightId = 0;
5979 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
5981 Handle(V3d_Light) aLight = aView->ActiveLight();
5982 const Quantity_Color aColor = aLight->Color();
5983 theDi << "Light" << aLightId << "\n";
5984 switch (aLight->Type())
5988 theDi << " Type: Ambient\n";
5991 case V3d_DIRECTIONAL:
5993 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
5994 theDi << " Type: Directional\n";
5995 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5996 if (!aLightDir.IsNull())
5998 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5999 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6000 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
6001 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6005 case V3d_POSITIONAL:
6007 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
6008 theDi << " Type: Positional\n";
6009 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
6010 if (!aLightPos.IsNull())
6012 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6013 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6014 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6015 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
6021 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
6022 theDi << " Type: Spot\n";
6023 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
6024 if (!aLightSpot.IsNull())
6026 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6027 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6028 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
6029 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6030 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6031 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
6032 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
6033 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
6039 theDi << " Type: UNKNOWN\n";
6043 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
6047 Handle(V3d_Light) aLightNew;
6048 Handle(V3d_Light) aLightOld;
6049 Standard_Boolean isGlobal = Standard_True;
6050 Standard_Boolean toCreate = Standard_False;
6051 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
6053 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
6054 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
6055 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
6056 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
6057 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
6059 TCollection_AsciiString aName, aValue;
6060 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
6061 TCollection_AsciiString anArgCase (anArg);
6062 anArgCase.UpperCase();
6063 if (anArgCase.IsEqual ("NEW")
6064 || anArgCase.IsEqual ("ADD")
6065 || anArgCase.IsEqual ("CREATE"))
6067 toCreate = Standard_True;
6069 else if (anArgCase.IsEqual ("GLOB")
6070 || anArgCase.IsEqual ("GLOBAL"))
6072 isGlobal = Standard_True;
6074 else if (anArgCase.IsEqual ("LOC")
6075 || anArgCase.IsEqual ("LOCAL"))
6077 isGlobal = Standard_False;
6079 else if (anArgCase.IsEqual ("DEF")
6080 || anArgCase.IsEqual ("DEFAULTS"))
6082 toCreate = Standard_False;
6083 aViewer->SetDefaultLights();
6085 else if (anArgCase.IsEqual ("CLR")
6086 || anArgCase.IsEqual ("CLEAR"))
6088 toCreate = Standard_False;
6089 aView->InitActiveLights();
6090 while (aView->MoreActiveLights())
6092 aViewer->DelLight (aView->ActiveLight());
6093 aView->InitActiveLights();
6096 else if (anArgCase.IsEqual ("AMB")
6097 || anArgCase.IsEqual ("AMBIENT")
6098 || anArgCase.IsEqual ("AMBLIGHT"))
6100 addLight (aLightNew, isGlobal);
6103 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6106 toCreate = Standard_False;
6107 aLightNew = new V3d_AmbientLight (aViewer);
6109 else if (anArgCase.IsEqual ("DIRECTIONAL")
6110 || anArgCase.IsEqual ("DIRLIGHT"))
6112 addLight (aLightNew, isGlobal);
6115 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6118 toCreate = Standard_False;
6119 aLightNew = new V3d_DirectionalLight (aViewer);
6121 else if (anArgCase.IsEqual ("SPOT")
6122 || anArgCase.IsEqual ("SPOTLIGHT"))
6124 addLight (aLightNew, isGlobal);
6127 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6130 toCreate = Standard_False;
6131 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
6133 else if (anArgCase.IsEqual ("POSLIGHT")
6134 || anArgCase.IsEqual ("POSITIONAL"))
6136 addLight (aLightNew, isGlobal);
6139 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6142 toCreate = Standard_False;
6143 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
6145 else if (anArgCase.IsEqual ("CHANGE"))
6147 addLight (aLightNew, isGlobal);
6148 aLightNew.Nullify();
6149 if (++anArgIt >= theArgsNb)
6151 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6155 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
6156 Standard_Integer aLightIt = 0;
6157 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6159 if (aLightIt == aLightId)
6161 aLightOld = aView->ActiveLight();
6166 if (aLightOld.IsNull())
6168 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
6172 else if (anArgCase.IsEqual ("DEL")
6173 || anArgCase.IsEqual ("DELETE"))
6175 Handle(V3d_Light) aLightDel;
6176 if (++anArgIt >= theArgsNb)
6178 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6182 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6183 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
6184 Standard_Integer aLightIt = 0;
6185 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6187 aLightDel = aView->ActiveLight();
6188 if (aLightIt == aLightDelId)
6193 if (!aLightDel.IsNull())
6195 aViewer->DelLight (aLightDel);
6198 else if (anArgCase.IsEqual ("COLOR")
6199 || anArgCase.IsEqual ("COLOUR"))
6201 if (++anArgIt >= theArgsNb)
6203 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6207 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6208 anArgNext.UpperCase();
6209 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
6210 if (!aLightCurr.IsNull())
6212 aLightCurr->SetColor (aColor);
6215 else if (anArgCase.IsEqual ("POS")
6216 || anArgCase.IsEqual ("POSITION"))
6218 if ((anArgIt + 3) >= theArgsNb)
6220 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6224 anXYZ[0] = Atof (theArgVec[++anArgIt]);
6225 anXYZ[1] = Atof (theArgVec[++anArgIt]);
6226 anXYZ[2] = Atof (theArgVec[++anArgIt]);
6227 if (!aLightDir.IsNull())
6229 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6231 else if (!aLightPos.IsNull())
6233 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6235 else if (!aLightSpot.IsNull())
6237 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6241 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6245 else if (anArgCase.IsEqual ("DIR")
6246 || anArgCase.IsEqual ("DIRECTION"))
6248 if ((anArgIt + 3) >= theArgsNb)
6250 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6254 anXYZ[0] = Atof (theArgVec[++anArgIt]);
6255 anXYZ[1] = Atof (theArgVec[++anArgIt]);
6256 anXYZ[2] = Atof (theArgVec[++anArgIt]);
6257 if (!aLightDir.IsNull())
6259 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
6261 else if (!aLightSpot.IsNull())
6263 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
6267 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6271 else if (anArgCase.IsEqual ("ANG")
6272 || anArgCase.IsEqual ("ANGLE"))
6274 if (++anArgIt >= theArgsNb)
6276 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6280 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
6282 if (!aLightSpot.IsNull())
6284 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
6287 else if (anArgCase.IsEqual ("CONSTATTEN")
6288 || anArgCase.IsEqual ("CONSTATTENUATION"))
6290 if (++anArgIt >= theArgsNb)
6292 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6296 if (!aLightPos.IsNull())
6298 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6299 anAtten[0] = Atof (theArgVec[anArgIt]);
6300 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
6302 else if (!aLightSpot.IsNull())
6304 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6305 anAtten[0] = Atof (theArgVec[anArgIt]);
6306 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
6310 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6314 else if (anArgCase.IsEqual ("LINATTEN")
6315 || anArgCase.IsEqual ("LINEARATTEN")
6316 || anArgCase.IsEqual ("LINEARATTENUATION"))
6318 if (++anArgIt >= theArgsNb)
6320 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6324 if (!aLightPos.IsNull())
6326 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6327 anAtten[1] = Atof (theArgVec[anArgIt]);
6328 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
6330 else if (!aLightSpot.IsNull())
6332 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6333 anAtten[1] = Atof (theArgVec[anArgIt]);
6334 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
6338 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6342 else if (anArgCase.IsEqual ("EXP")
6343 || anArgCase.IsEqual ("EXPONENT")
6344 || anArgCase.IsEqual ("SPOTEXP")
6345 || anArgCase.IsEqual ("SPOTEXPONENT"))
6347 if (++anArgIt >= theArgsNb)
6349 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6353 if (!aLightSpot.IsNull())
6355 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
6359 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6363 else if (anArgCase.IsEqual ("HEAD")
6364 || anArgCase.IsEqual ("HEADLIGHT"))
6366 if (++anArgIt >= theArgsNb)
6368 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6372 if (aLightAmb.IsNull()
6373 && !aLightCurr.IsNull())
6375 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
6379 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6385 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
6389 addLight (aLightNew, isGlobal);
6390 aViewer->UpdateLights();
6395 inline Standard_Boolean parseOnOff (Standard_CString theArg,
6396 Standard_Boolean& theIsOn)
6398 TCollection_AsciiString aFlag (theArg);
6402 theIsOn = Standard_True;
6403 return Standard_True;
6405 else if (aFlag == "off")
6407 theIsOn = Standard_False;
6408 return Standard_True;
6410 return Standard_False;
6413 //=======================================================================
6414 //function : VRenderParams
6415 //purpose : Enables/disables rendering features
6416 //=======================================================================
6418 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
6419 Standard_Integer theArgNb,
6420 const char** theArgVec)
6422 Handle(V3d_View) aView = ViewerTest::CurrentView();
6425 std::cerr << "Error: no active viewer!\n";
6429 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
6433 theDI << "renderMode: ";
6434 switch (aParams.Method)
6436 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
6437 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
6440 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
6441 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
6442 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
6443 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
6444 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
6448 Standard_Boolean toPrint = Standard_False;
6449 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6451 Standard_CString anArg (theArgVec[anArgIter]);
6452 TCollection_AsciiString aFlag (anArg);
6454 if (aFlag == "-echo"
6455 || aFlag == "-print")
6457 toPrint = Standard_True;
6459 else if (aFlag == "-mode"
6460 || aFlag == "-rendermode"
6461 || aFlag == "-render_mode")
6465 switch (aParams.Method)
6467 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
6468 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
6474 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
6478 else if (aFlag == "-ray"
6479 || aFlag == "-raytrace")
6483 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
6487 aParams.Method = Graphic3d_RM_RAYTRACING;
6489 else if (aFlag == "-rast"
6490 || aFlag == "-raster"
6491 || aFlag == "-rasterization")
6495 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
6499 aParams.Method = Graphic3d_RM_RASTERIZATION;
6501 else if (aFlag == "-raydepth"
6502 || aFlag == "-ray_depth")
6506 theDI << aParams.RaytracingDepth << " ";
6509 else if (++anArgIter >= theArgNb)
6511 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
6515 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
6516 if (aDepth < 1 || aDepth > 10)
6518 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
6523 aParams.RaytracingDepth = aDepth;
6526 else if (aFlag == "-shad"
6527 || aFlag == "-shadows")
6531 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
6535 Standard_Boolean toEnable = Standard_True;
6536 if (++anArgIter < theArgNb
6537 && !parseOnOff (theArgVec[anArgIter], toEnable))
6541 aParams.IsShadowEnabled = toEnable;
6543 else if (aFlag == "-refl"
6544 || aFlag == "-reflections")
6548 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
6552 Standard_Boolean toEnable = Standard_True;
6553 if (++anArgIter < theArgNb
6554 && !parseOnOff (theArgVec[anArgIter], toEnable))
6558 aParams.IsReflectionEnabled = toEnable;
6560 else if (aFlag == "-fsaa")
6564 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
6568 Standard_Boolean toEnable = Standard_True;
6569 if (++anArgIter < theArgNb
6570 && !parseOnOff (theArgVec[anArgIter], toEnable))
6574 aParams.IsAntialiasingEnabled = toEnable;
6576 else if (aFlag == "-gleam")
6580 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
6584 Standard_Boolean toEnable = Standard_True;
6585 if (++anArgIter < theArgNb
6586 && !parseOnOff (theArgVec[anArgIter], toEnable))
6590 aParams.IsTransparentShadowEnabled = toEnable;
6594 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
6603 //=======================================================================
6604 //function : VFrustumCulling
6605 //purpose : enables/disables view volume's culling.
6606 //=======================================================================
6607 static int VFrustumCulling (Draw_Interpretor& theDI,
6608 Standard_Integer theArgNb,
6609 const char** theArgVec)
6611 Handle(V3d_View) aView = ViewerTest::CurrentView();
6614 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
6620 theDI << (aView->IsCullingEnabled() ? "on" : "off");
6623 else if (theArgNb != 2)
6625 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
6629 TCollection_AsciiString aModeStr (theArgVec[1]);
6630 aModeStr.LowerCase();
6631 Standard_Boolean toEnable = 0;
6632 if (aModeStr == "on")
6636 else if (aModeStr == "off")
6642 toEnable = Draw::Atoi (theArgVec[1]) != 0;
6645 aView->SetFrustumCulling (toEnable);
6650 //=======================================================================
6651 //function : VHighlightSelected
6653 //=======================================================================
6654 static int VHighlightSelected (Draw_Interpretor& theDI,
6655 Standard_Integer theArgNb,
6656 const char** theArgVec)
6658 if (ViewerTest::GetAISContext().IsNull())
6660 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
6664 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6668 theDI << (aContext->ToHilightSelected() ? "on" : "off");
6674 std::cout << theArgVec[0] << " error : wrong number of parameters."
6675 << "Type 'help" << theArgVec[0] << "' for more information.";
6680 TCollection_AsciiString aMode (theArgVec[1]);
6682 Standard_Boolean toEnable = Standard_False;
6683 if (aMode.IsEqual ("on"))
6685 toEnable = Standard_True;
6687 else if (aMode.IsEqual ("off"))
6689 toEnable = Standard_False;
6693 toEnable = Draw::Atoi (theArgVec[1]) != 0;
6696 if (toEnable != aContext->ToHilightSelected())
6698 aContext->SetToHilightSelected (toEnable);
6700 // Move cursor to null position and back to process updating of detection
6701 // and highlighting of selected object immediatly.
6702 Standard_Integer aPixX = 0;
6703 Standard_Integer aPixY = 0;
6704 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
6706 anEventManager->GetCurrentPosition (aPixX, aPixY);
6707 anEventManager->MoveTo (0, 0);
6708 anEventManager->MoveTo (aPixX, aPixY);
6714 //=======================================================================
6715 //function : VXRotate
6717 //=======================================================================
6718 static Standard_Integer VXRotate (Draw_Interpretor& di,
6719 Standard_Integer argc,
6722 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6723 if (aContext.IsNull())
6725 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
6731 di << "ERROR : Usage : " << argv[0] << " name angle" << "\n";
6735 TCollection_AsciiString aName (argv[1]);
6736 Standard_Real anAngle = Draw::Atof (argv[2]);
6739 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6740 Handle(AIS_InteractiveObject) anIObj;
6741 if (!aMap.IsBound2 (aName) )
6743 di << "Use 'vdisplay' before" << "\n";
6748 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
6751 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
6752 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
6754 aContext->SetLocation (anIObj, aTransform);
6755 aContext->UpdateCurrentViewer();
6761 //=======================================================================
6762 //function : ViewerCommands
6764 //=======================================================================
6766 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
6769 const char *group = "ZeViewer";
6770 theCommands.Add("vinit",
6771 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
6772 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
6774 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
6776 " - Creates new View window with specified name view_name.\n"
6777 "By default the new view is created in the viewer and in"
6778 " graphic driver shared with active view.\n"
6779 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
6780 "If driverName isn't specified the driver will be shared with active view.\n"
6781 "If viewerName isn't specified the viewer will be shared with active view.\n"
6782 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
6783 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
6784 "is used in creation of graphic driver\n"
6786 " - l, t: pixel position of left top corner of the window\n"
6787 " - w,h: width and heigth of window respectively.\n"
6788 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
6789 __FILE__,VInit,group);
6790 theCommands.Add("vclose" ,
6791 "[view_id [keep_context=0|1]]\n"
6792 "or vclose ALL - to remove all created views\n"
6793 " - removes view(viewer window) defined by its view_id.\n"
6794 " - keep_context: by default 0; if 1 and the last view is deleted"
6795 " the current context is not removed.",
6796 __FILE__,VClose,group);
6797 theCommands.Add("vactivate" ,
6799 " - activates view(viewer window) defined by its view_id",
6800 __FILE__,VActivate,group);
6801 theCommands.Add("vviewlist",
6802 "vviewlist [format={tree, long}]"
6803 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
6804 " - format: format of result output, if tree the output is a tree view;"
6805 "otherwise it's a list of full view names. By default format = tree",
6806 __FILE__,VViewList,group);
6807 theCommands.Add("vhelp" ,
6808 "vhelp : display help on the viewer commands",
6809 __FILE__,VHelp,group);
6810 theCommands.Add("vtop" ,
6811 "vtop or <T> : Top view" ,
6812 __FILE__,VTop,group);
6813 theCommands.Add("vbottom" ,
6814 "vbottom : Bottom view" ,
6815 __FILE__,VBottom,group);
6816 theCommands.Add("vleft" ,
6817 "vleft : Left view" ,
6818 __FILE__,VLeft,group);
6819 theCommands.Add("vright" ,
6820 "vright : Right view" ,
6821 __FILE__,VRight,group);
6822 theCommands.Add("vaxo" ,
6823 " vaxo or <A> : Axonometric view ",
6824 __FILE__,VAxo,group);
6825 theCommands.Add("vfront" ,
6826 "vfront : Front view" ,
6827 __FILE__,VFront,group);
6828 theCommands.Add("vback" ,
6829 "vback : Back view" ,
6830 __FILE__,VBack,group);
6831 theCommands.Add("vpick" ,
6832 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
6834 theCommands.Add("vfit" ,
6835 "vfit or <F> : vfit",
6836 __FILE__,VFit,group);
6837 theCommands.Add ("vzfit", "vzfit [scale]\n"
6838 " Matches Z near, Z far view volume planes to the displayed objects.\n"
6839 " \"scale\" - specifies factor to scale computed z range.\n",
6840 __FILE__, VZFit, group);
6841 theCommands.Add("vrepaint",
6842 "vrepaint : vrepaint, force redraw",
6843 __FILE__,VRepaint,group);
6844 theCommands.Add("vclear",
6846 __FILE__,VClear,group);
6847 theCommands.Add("vsetbg",
6848 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
6849 __FILE__,VSetBg,group);
6850 theCommands.Add("vsetbgmode",
6851 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
6852 __FILE__,VSetBgMode,group);
6853 theCommands.Add("vsetgradientbg",
6854 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
6855 __FILE__,VSetGradientBg,group);
6856 theCommands.Add("vsetgrbgmode",
6857 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
6858 __FILE__,VSetGradientBgMode,group);
6859 theCommands.Add("vsetcolorbg",
6860 "vsetcolorbg : vsetcolorbg r g b : Set background color",
6861 __FILE__,VSetColorBg,group);
6862 theCommands.Add("vscale",
6863 "vscale : vscale X Y Z",
6864 __FILE__,VScale,group);
6865 theCommands.Add("vzbufftrihedron",
6866 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
6867 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
6868 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
6869 __FILE__,VTestZBuffTrihedron,group);
6870 theCommands.Add("vrotate",
6871 "vrotate : vrotate AX AY AZ [X Y Z]",
6872 __FILE__,VRotate,group);
6873 theCommands.Add("vzoom",
6874 "vzoom : vzoom coef",
6875 __FILE__,VZoom,group);
6876 theCommands.Add("vpan",
6877 "vpan : vpan dx dy",
6878 __FILE__,VPan,group);
6879 theCommands.Add("vexport",
6880 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
6881 " : exports the view to a vector file of a given format"
6882 " : notice that EMF format requires patched gl2ps",
6883 __FILE__,VExport,group);
6884 theCommands.Add("vcolorscale",
6885 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
6886 __FILE__,VColorScale,group);
6887 theCommands.Add("vgraduatedtrihedron",
6888 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
6889 __FILE__,VGraduatedTrihedron,group);
6890 theCommands.Add("vprintview" ,
6891 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
6892 __FILE__,VPrintView,group);
6893 theCommands.Add("vzlayer",
6894 "vzlayer add/del/get/settings/enable/disable [id]\n"
6895 " add - add new z layer to viewer and print its id\n"
6896 " del - del z layer by its id\n"
6897 " get - print sequence of z layers in increasing order of their overlay level\n"
6898 " settings - print status of z layer settings\n"
6899 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
6900 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
6901 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
6902 "\nWhere id is the layer identificator\n"
6905 " vzlayer enable poffset 1\n"
6906 " vzlayer disable depthtest 1\n"
6908 __FILE__,VZLayer,group);
6909 theCommands.Add("voverlaytext",
6910 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
6911 " : height - pixel height of the text (default=10.0)"
6912 " : font_name - name of font (default=courier)"
6913 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
6914 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
6915 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
6916 __FILE__,VOverlayText,group);
6917 theCommands.Add("vlayerline",
6918 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
6919 __FILE__,VLayerLine,group);
6920 theCommands.Add ("vgrid",
6921 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
6922 " : Mode - rectangular or circular"
6923 " : Type - lines or points",
6924 __FILE__, VGrid, group);
6925 theCommands.Add ("vfps",
6926 "vfps [framesNb=100] : estimate average frame rate for active view",
6927 __FILE__, VFps, group);
6928 theCommands.Add ("vgldebug",
6929 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
6930 " : this function is implemented only for Windows\n"
6931 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
6932 __FILE__, VGlDebug, group);
6933 theCommands.Add ("vvbo",
6934 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
6935 __FILE__, VVbo, group);
6936 theCommands.Add ("vstereo",
6937 "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects",
6938 __FILE__, VStereo, group);
6939 theCommands.Add ("vcaps",
6940 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
6941 __FILE__, VCaps, group);
6942 theCommands.Add ("vmemgpu",
6943 "vmemgpu [f]: print system-dependent GPU memory information if available;"
6944 " with f option returns free memory in bytes",
6945 __FILE__, VMemGpu, group);
6946 theCommands.Add ("vreadpixel",
6947 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
6948 " : Read pixel value for active view",
6949 __FILE__, VReadPixel, group);
6950 theCommands.Add("diffimage",
6951 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
6952 __FILE__, VDiffImage, group);
6953 theCommands.Add ("vselect",
6954 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
6955 "- emulates different types of selection:\n"
6956 "- 1) single click selection\n"
6957 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
6958 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
6959 "- 4) any of these selections with shift button pressed",
6960 __FILE__, VSelect, group);
6961 theCommands.Add ("vmoveto",
6963 "- emulates cursor movement to pixel postion (x,y)",
6964 __FILE__, VMoveTo, group);
6965 theCommands.Add ("vviewparams", "vviewparams usage:\n"
6967 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
6968 " [-proj [x y z]] [-center x y] [-size sx]\n"
6969 "- Gets or sets current view parameters.\n"
6970 "- If called without arguments, all view parameters are printed.\n"
6971 "- The options are:\n"
6972 " -scale [s] : prints or sets viewport relative scale.\n"
6973 " -eye [x y z] : prints or sets eye location.\n"
6974 " -at [x y z] : prints or sets center of look.\n"
6975 " -up [x y z] : prints or sets direction of up vector.\n"
6976 " -proj [x y z] : prints or sets direction of look.\n"
6977 " -center x y : sets location of center of the screen in pixels.\n"
6978 " -size [sx] : prints viewport projection width and height sizes\n"
6979 " : or changes the size of its maximum dimension.\n",
6980 __FILE__, VViewParams, group);
6981 theCommands.Add("vchangeselected",
6982 "vchangeselected shape"
6983 "- adds to shape to selection or remove one from it",
6984 __FILE__, VChangeSelected, group);
6985 theCommands.Add("vzclipping",
6986 "vzclipping [mode] [depth width]\n"
6987 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
6988 "- gets or sets ZClipping mode, width and depth",
6989 __FILE__,VZClipping,group);
6990 theCommands.Add ("vnbselected",
6991 "vnbselected", __FILE__, VNbSelected, group);
6992 theCommands.Add ("vchangecamera",
6993 " changes camera parameters \n"
6994 "- vchangecamera [param_type] [value]\n"
6995 "- vchangecamera proj {ortho/persp/left/right/stereo}\n"
6996 " Projection type including left and right stereo parts.\n"
6997 "- vchangecamera dist [real]\n"
6998 " Sets distance from target point to camera eye (moving eye).\n"
6999 "- vchangecamera iod [real]\n"
7000 " Intraocular distance value.\n"
7001 "- vchangecamera zfocus [real]\n"
7002 " Stereographic focus value.\n"
7003 "- vchangecamera fov [real]\n"
7004 " Field Of View value (in degrees).\n"
7005 "- vchangecamera zfocustype {absolute/relative}\n"
7006 " Stereographic focus definition type (absolute value or coefficient).\n"
7007 "- vchangecamera iodtype {absolute/relative}\n"
7008 " Intraocular distance definition type (absolute value or coefficient).\n",
7009 __FILE__, VChangeCamera, group);
7010 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
7011 "- vautozfit [on={1|0}] [scale]\n"
7012 " Prints or changes parameters of automatic z-fit mode:\n"
7013 " \"on\" - turns automatic z-fit on or off\n"
7014 " \"scale\" - specifies factor to scale computed z range.\n",
7015 __FILE__, VAutoZFit, group);
7016 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
7017 " vzrange - without parameters shows current values\n"
7018 " vzrange [znear] [zfar] - applies provided values to view",
7019 __FILE__,VZRange, group);
7020 theCommands.Add("vantialiasing",
7021 "vantialiasing 1|0",
7022 __FILE__,VAntialiasing,group);
7023 theCommands.Add ("vpurgedisplay",
7025 "- removes structures which don't belong to objects displayed in neutral point",
7026 __FILE__, VPurgeDisplay, group);
7027 theCommands.Add("vsetviewsize",
7028 "vsetviewsize size",
7029 __FILE__,VSetViewSize,group);
7030 theCommands.Add("vmoveview",
7031 "vmoveview Dx Dy Dz [Start = 1|0]",
7032 __FILE__,VMoveView,group);
7033 theCommands.Add("vtranslateview",
7034 "vtranslateview Dx Dy Dz [Start = 1|0)]",
7035 __FILE__,VTranslateView,group);
7036 theCommands.Add("vturnview",
7037 "vturnview Ax Ay Az [Start = 1|0]",
7038 __FILE__,VTurnView,group);
7039 theCommands.Add("vtextureenv",
7040 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
7041 "or user-defined file and optionally applying texture mapping parameters\n"
7043 " vtextureenv off - disables environment mapping\n"
7044 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
7045 " std_texture = (0..7)\n"
7046 " rep = {clamp|repeat}\n"
7047 " mod = {decal|modulate}\n"
7048 " flt = {nearest|bilinear|trilinear}\n"
7049 " ss, st - scale factors for s and t texture coordinates\n"
7050 " ts, tt - translation for s and t texture coordinates\n"
7051 " rot - texture rotation angle in degrees",
7052 __FILE__, VTextureEnv, group);
7053 theCommands.Add("vhlr" ,
7054 "is_enabled={on|off} [show_hidden={1|0}]"
7055 " - Hidden line removal algorithm:"
7056 " - is_enabled: if is on HLR algorithm is applied\n"
7057 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
7058 __FILE__,VHLR,group);
7059 theCommands.Add("vhlrtype" ,
7060 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
7061 " - Changes the type of HLR algorithm using for shapes."
7062 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
7063 " if equals to polyalgo, polygonal HLR algorithm is applied."
7064 "If shapes are not given HLR algoithm of given type is applied"
7065 " to all shapes in the view\n",
7066 __FILE__,VHLRType,group);
7067 theCommands.Add("vclipplane", "vclipplane usage: \n"
7068 " maxplanes <view_name> - get plane limit for view.\n"
7069 " create <plane_name> - create new plane.\n"
7070 " delete <plane_name> - delete plane.\n"
7071 " clone <source_plane> <plane_name> - clone the plane definition.\n"
7072 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
7073 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
7074 " change <plane_name> on/off - turn clipping on/off.\n"
7075 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
7076 " change <plane_name> capping on/off - turn capping on/off.\n"
7077 " change <plane_name> capping color <r> <g> <b> - set color.\n"
7078 " change <plane name> capping texname <texture> - set texture.\n"
7079 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
7080 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
7081 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
7082 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
7083 " please use VSetTextureMode command to enable texture rendering in view.\n"
7084 , __FILE__, VClipPlane, group);
7085 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
7087 " 0 - no textures enabled in view.\n"
7088 " 1 - only environment textures enabled.\n"
7089 " 2 - all textures enabled.\n"
7090 " this command sets texture details mode for the specified view.\n"
7091 , __FILE__, VSetTextureMode, group);
7092 theCommands.Add("vdefaults",
7093 "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
7094 __FILE__, VDefaults, group);
7095 theCommands.Add("vlight",
7096 "tool to manage light sources, without arguments shows list of lights."
7097 "\n Main commands: "
7098 "\n 'clear' to clear lights"
7099 "\n '{def}aults' to load deafault lights"
7100 "\n 'add' (or 'new') <type> to add any light source"
7101 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
7102 "\n 'change' <lightId> to edit light source with specified lightId"
7103 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
7104 "\n {pos}ition X Y Z"
7105 "\n {dir}ection X Y Z (for directional light or for spotlight)"
7106 "\n color colorName"
7107 "\n {head}light 0|1"
7108 "\n {constAtten}uation value"
7109 "\n {linearAtten}uation value"
7111 "\n {spotexp}onent value"
7113 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
7114 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
7115 __FILE__, VLight, group);
7116 theCommands.Add("vrenderparams",
7117 "\n Manages rendering parameters: "
7118 "\n '-rayTrace' Enables GPU ray-tracing"
7119 "\n '-raster' Disables GPU ray-tracing"
7120 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
7121 "\n '-shadows on|off' Enables/disables shadows rendering"
7122 "\n '-reflections on|off' Enables/disables specular reflections"
7123 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
7124 "\n '-gleam on|off' Enables/disables transparency shadow effects",
7125 __FILE__, VRenderParams, group);
7126 theCommands.Add("vfrustumculling",
7127 "vfrustumculling [toEnable]: enables/disables objects clipping",
7128 __FILE__,VFrustumCulling,group);
7129 theCommands.Add("vhighlightselected",
7130 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
7131 "Without arguments it shows if highlighting of selected objects is enabled now.",
7132 __FILE__,VHighlightSelected,group);
7135 theCommands.Add("vxrotate",
7137 __FILE__,VXRotate,group);