0030476: Visualization, Path Tracing - Adaptive Screen Sampling leads to unstable...
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
CommitLineData
b311480e 1// Created on: 1998-09-01
2// Created by: Robert COUBLANC
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
58655684 17#include <OpenGl_GlCore20.hxx>
1beb58d7 18
19#include <AIS_Animation.hxx>
20#include <AIS_AnimationCamera.hxx>
21#include <AIS_AnimationObject.hxx>
30a1b24e 22#include <AIS_CameraFrustum.hxx>
7a324550 23#include <AIS_ColorScale.hxx>
625e1958 24#include <AIS_Manipulator.hxx>
b12e1c7b 25#include <AIS_RubberBand.hxx>
0a768f56 26#include <AIS_Shape.hxx>
0a768f56 27#include <AIS_InteractiveObject.hxx>
28#include <AIS_ListOfInteractive.hxx>
29#include <AIS_ListIteratorOfListOfInteractive.hxx>
8a590580 30#include <Aspect_Grid.hxx>
0a768f56 31#include <DBRep.hxx>
08f8a185 32#include <Draw_ProgressIndicator.hxx>
61b0191c 33#include <Graphic3d_ArrayOfPolylines.hxx>
2bd4c032 34#include <Graphic3d_AspectMarker3d.hxx>
269294d6 35#include <Graphic3d_NameOfTextureEnv.hxx>
a79f67f8 36#include <Graphic3d_GraduatedTrihedron.hxx>
269294d6 37#include <Graphic3d_TextureEnv.hxx>
38#include <Graphic3d_TextureParams.hxx>
39#include <Graphic3d_TypeOfTextureFilter.hxx>
4269bd1b 40#include <Graphic3d_AspectFillArea3d.hxx>
7fd59977 41#include <ViewerTest.hxx>
8625ef7e 42#include <ViewerTest_AutoUpdater.hxx>
7fd59977 43#include <ViewerTest_EventManager.hxx>
4754e164 44#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
4269bd1b 45#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
625e1958 46#include <ViewerTest_CmdParser.hxx>
12381341 47#include <V3d_AmbientLight.hxx>
48#include <V3d_DirectionalLight.hxx>
12381341 49#include <V3d_PositionalLight.hxx>
50#include <V3d_SpotLight.hxx>
08f8a185 51#include <Message_ProgressSentry.hxx>
18d715bd 52#include <NCollection_DoubleMap.hxx>
53#include <NCollection_List.hxx>
54#include <NCollection_Vector.hxx>
7fd59977 55#include <AIS_InteractiveContext.hxx>
56#include <Draw_Interpretor.hxx>
57#include <Draw.hxx>
58#include <Draw_Appli.hxx>
692613e5 59#include <Image_AlienPixMap.hxx>
08f8a185 60#include <Image_VideoRecorder.hxx>
58655684 61#include <OpenGl_GraphicDriver.hxx>
208e6839 62#include <OSD_Timer.hxx>
900f7229 63#include <TColStd_HSequenceOfAsciiString.hxx>
59f45b7c 64#include <TColStd_SequenceOfInteger.hxx>
4754e164 65#include <TColStd_HSequenceOfReal.hxx>
66#include <TColgp_Array1OfPnt2d.hxx>
197ac94e 67#include <TColStd_MapOfAsciiString.hxx>
20637bd2 68#include <Aspect_TypeOfLine.hxx>
692613e5 69#include <Image_Diff.hxx>
dc3fe572 70#include <Aspect_DisplayConnection.hxx>
4269bd1b 71#include <gp_Pnt.hxx>
72#include <gp_Dir.hxx>
73#include <gp_Pln.hxx>
74#include <PrsMgr_PresentableObject.hxx>
75#include <Graphic3d_ClipPlane.hxx>
76#include <NCollection_DataMap.hxx>
77#include <Graphic3d_Texture2Dmanual.hxx>
78#include <Prs3d_ShadingAspect.hxx>
6262338c 79#include <Prs3d_Drawer.hxx>
61b0191c 80#include <Prs3d_LineAspect.hxx>
81#include <Prs3d_Root.hxx>
fd3f6bd0 82#include <Prs3d_Text.hxx>
83#include <Select3D_SensitivePrimitiveArray.hxx>
7fd59977 84
57c28b61 85#ifdef _WIN32
25289ec1 86#undef DrawText
87#endif
88
692613e5 89#include <cstdlib>
25289ec1 90
58655684 91#if defined(_WIN32)
4fe56619 92 #include <WNT_WClass.hxx>
93 #include <WNT_Window.hxx>
4fe56619 94#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 95 #include <Cocoa_Window.hxx>
7fd59977 96#else
4fe56619 97 #include <Xw_Window.hxx>
98 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
99 #include <X11/Xutil.h>
100 #include <tk.h>
7fd59977 101#endif
102
b514beda 103// Auxiliary definitions
104static const char THE_KEY_DELETE = 127;
fd3f6bd0 105static const char THE_KEY_ESCAPE = 27;
7fd59977 106
107//==============================================================================
108// VIEWER GLOBAL VARIABLES
109//==============================================================================
110
111Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
b514beda 112Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
7fd59977 113
114Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
4754e164 115extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
7fd59977 116
b514beda 117extern int VErase (Draw_Interpretor& theDI,
118 Standard_Integer theArgNb,
119 const char** theArgVec);
120
58655684 121#if defined(_WIN32)
7fd59977 122static Handle(WNT_Window)& VT_GetWindow() {
123 static Handle(WNT_Window) WNTWin;
124 return WNTWin;
125}
4fe56619 126#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 127static Handle(Cocoa_Window)& VT_GetWindow()
128{
129 static Handle(Cocoa_Window) aWindow;
130 return aWindow;
131}
132extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
18d715bd 133extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
134extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
135
7fd59977 136#else
7fd59977 137static Handle(Xw_Window)& VT_GetWindow(){
138 static Handle(Xw_Window) XWWin;
139 return XWWin;
140}
7fd59977 141
142static void VProcessEvents(ClientData,int);
143#endif
144
18d715bd 145static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
146{
147 static Handle(Aspect_DisplayConnection) aDisplayConnection;
148 return aDisplayConnection;
149}
150
151static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
152{
153 GetDisplayConnection() = theDisplayConnection;
154}
155
58655684 156#if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 157Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
dc3fe572 158{
0ebaa4db 159 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
58655684 160#if defined(_WIN32)
18d715bd 161 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
162 if (!aWindow.IsNull())
163 return aWindow->HWindow();
164#elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
165 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
166 if (!aWindow.IsNull())
167 return aWindow->XWindow();
168#endif
169 return aWindowHandle;
dc3fe572 170}
18d715bd 171#endif
dc3fe572 172
2e93433e 173//! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events
174class ViewerTest_V3dView : public V3d_View
175{
176 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_V3dView, V3d_View)
177public:
178 //! Initializes the view.
179 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC,
180 bool theIs2dMode = false)
181 : V3d_View (theViewer, theType), myIs2dMode (theIs2dMode) {}
182
183 //! Initializes the view by copying.
184 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
185 : V3d_View (theViewer, theView), myIs2dMode (false)
186 {
187 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView))
188 {
189 myIs2dMode = aV3dView->IsViewIn2DMode();
190 }
191 }
192
193 //! Returns true if 2D mode is set for the view
194 bool IsViewIn2DMode() const { return myIs2dMode; }
195
196 //! Sets 2D mode for the view
197 void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; }
198
199public:
200
201 //! Returns true if active view in 2D mode.
202 static bool IsCurrentViewIn2DMode()
203 {
204 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
205 {
206 return aV3dView->IsViewIn2DMode();
207 }
208 return false;
209 }
210
211 //! Set if active view in 2D mode.
212 static void SetCurrentView2DMode (bool theIs2d)
213 {
214 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
215 {
216 aV3dView->SetView2DMode (theIs2d);
217 }
218 }
219
220private:
221
222 Standard_Boolean myIs2dMode; //!< 2D mode flag
223
224};
225
18d715bd 226NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
58655684 227static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
18d715bd 228static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
58655684 229static OpenGl_Caps ViewerTest_myDefaultCaps;
18d715bd 230
7fd59977 231static void OSWindowSetup();
232
f42753ed 233static struct
234{
235 Quantity_Color FlatColor;
236 Quantity_Color GradientColor1;
237 Quantity_Color GradientColor2;
238 Aspect_GradientFillMethod FillMethod;
239} ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
240
7fd59977 241//==============================================================================
242// EVENT GLOBAL VARIABLES
243//==============================================================================
244
245static int Start_Rot = 0;
1eeef710 246Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
4fe56619 247int X_Motion = 0; // Current cursor position
248int Y_Motion = 0;
249int X_ButtonPress = 0; // Last ButtonPress position
250int Y_ButtonPress = 0;
251Standard_Boolean IsDragged = Standard_False;
8abada55 252Standard_Boolean DragFirst = Standard_False;
1beb58d7 253Standard_Boolean TheIsAnimating = Standard_False;
fd3f6bd0 254Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
255Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
7fd59977 256
b12e1c7b 257
258Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
259{
260 static Handle(AIS_RubberBand) aBand;
261 if (aBand.IsNull())
262 {
69adb9ce 263 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
264 aBand->SetDisplayMode (0);
b12e1c7b 265 }
266 return aBand;
267}
268
625e1958 269typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
270
271Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
272{
273 static ViewerTest_MapOfAISManipulators aMap;
274 return aMap;
275}
276
277Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
278{
279 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
280 for (; anIt.More(); anIt.Next())
281 {
282 if (anIt.Value()->HasActiveMode())
283 {
284 return anIt.Value();
285 }
286 }
287 return NULL;
288}
289
7fd59977 290//==============================================================================
291
57c28b61 292#ifdef _WIN32
7fd59977 293static LRESULT WINAPI ViewerWindowProc(
294 HWND hwnd,
295 UINT uMsg,
296 WPARAM wParam,
297 LPARAM lParam );
298static LRESULT WINAPI AdvViewerWindowProc(
299 HWND hwnd,
300 UINT uMsg,
301 WPARAM wParam,
302 LPARAM lParam );
303#endif
304
305
306//==============================================================================
307//function : WClass
308//purpose :
309//==============================================================================
310
ad03c234 311const Handle(Standard_Transient)& ViewerTest::WClass()
7fd59977 312{
ad03c234 313 static Handle(Standard_Transient) theWClass;
58655684 314#if defined(_WIN32)
4fe56619 315 if (theWClass.IsNull())
316 {
7c65581d 317 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
ad03c234 318 CS_VREDRAW | CS_HREDRAW, 0, 0,
c85a994a 319 ::LoadCursor (NULL, IDC_ARROW));
7fd59977 320 }
321#endif
322 return theWClass;
323}
324
18d715bd 325//==============================================================================
326//function : CreateName
327//purpose : Create numerical name for new object in theMap
328//==============================================================================
329template <typename ObjectType>
330TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
331 const TCollection_AsciiString& theDefaultString)
332{
333 if (theObjectMap.IsEmpty())
334 return theDefaultString + TCollection_AsciiString(1);
335
336 Standard_Integer aNextKey = 1;
337 Standard_Boolean isFound = Standard_False;
338 while (!isFound)
339 {
340 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
341 // Look for objects with default names
342 if (theObjectMap.IsBound1(aStringKey))
343 {
344 aNextKey++;
345 }
346 else
347 isFound = Standard_True;
348 }
349
350 return theDefaultString + TCollection_AsciiString(aNextKey);
351}
352
353//==============================================================================
354//structure : ViewerTest_Names
355//purpose : Allow to operate with full view name: driverName/viewerName/viewName
356//==============================================================================
357struct ViewerTest_Names
358{
359private:
360 TCollection_AsciiString myDriverName;
361 TCollection_AsciiString myViewerName;
362 TCollection_AsciiString myViewName;
363
364public:
365
366 const TCollection_AsciiString& GetDriverName () const
367 {
368 return myDriverName;
369 }
370 void SetDriverName (const TCollection_AsciiString& theDriverName)
371 {
372 myDriverName = theDriverName;
373 }
374 const TCollection_AsciiString& GetViewerName () const
375 {
376 return myViewerName;
377 }
378 void SetViewerName (const TCollection_AsciiString& theViewerName)
379 {
380 myViewerName = theViewerName;
381 }
382 const TCollection_AsciiString& GetViewName () const
383 {
384 return myViewName;
385 }
386 void SetViewName (const TCollection_AsciiString& theViewName)
387 {
388 myViewName = theViewName;
389 }
390
391 //===========================================================================
392 //function : Constructor for ViewerTest_Names
393 //purpose : Get view, viewer, driver names from custom string
394 //===========================================================================
395
396 ViewerTest_Names (const TCollection_AsciiString& theInputString)
397 {
398 TCollection_AsciiString aName(theInputString);
399 if (theInputString.IsEmpty())
400 {
401 // Get current configuration
402 if (ViewerTest_myDrivers.IsEmpty())
403 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
404 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
405 else
406 myDriverName = ViewerTest_myDrivers.Find2
407 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
408
409 if(ViewerTest_myContexts.IsEmpty())
410 {
411 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
412 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
413 }
414 else
c48e2889 415 {
18d715bd 416 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
c48e2889 417 }
18d715bd 418
c48e2889 419 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
18d715bd 420 }
421 else
422 {
423 // There is at least view name
424 Standard_Integer aParserNumber = 0;
425 for (Standard_Integer i = 0; i < 3; ++i)
426 {
427 Standard_Integer aParserPos = aName.SearchFromEnd("/");
428 if(aParserPos != -1)
429 {
430 aParserNumber++;
431 aName.Split(aParserPos-1);
432 }
433 else
434 break;
435 }
436 if (aParserNumber == 0)
437 {
438 // Only view name
439 if (!ViewerTest::GetAISContext().IsNull())
440 {
441 myDriverName = ViewerTest_myDrivers.Find2
442 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
443 myViewerName = ViewerTest_myContexts.Find2
444 (ViewerTest::GetAISContext());
445 }
446 else
447 {
448 // There is no opened contexts here, need to create names for viewer and driver
449 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
450 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
451
452 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
453 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
454 }
455 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
456 }
457 else if (aParserNumber == 1)
458 {
459 // Here is viewerName/viewName
460 if (!ViewerTest::GetAISContext().IsNull())
461 myDriverName = ViewerTest_myDrivers.Find2
462 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
463 else
464 {
465 // There is no opened contexts here, need to create name for driver
466 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
467 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
468 }
469 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
470
471 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
472 }
473 else
474 {
475 //Here is driverName/viewerName/viewName
476 myDriverName = TCollection_AsciiString(aName);
477
478 TCollection_AsciiString aViewerName(theInputString);
479 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
480 myViewerName = TCollection_AsciiString(aViewerName);
481
482 myViewName = TCollection_AsciiString(theInputString);
483 }
484 }
485 }
486};
487
488//==============================================================================
489//function : FindContextByView
490//purpose : Find AIS_InteractiveContext by View
491//==============================================================================
492
493Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
494{
495 Handle(AIS_InteractiveContext) anAISContext;
496
497 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
498 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
499 {
500 if (anIter.Value()->CurrentViewer() == theView->Viewer())
501 return anIter.Key2();
502 }
503 return anAISContext;
504}
505
506
507//==============================================================================
508//function : SetWindowTitle
509//purpose : Set window title
510//==============================================================================
511
512void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
513 Standard_CString theTitle)
514{
58655684 515#if defined(_WIN32)
ad03c234 516 const TCollection_ExtendedString theTitleW (theTitle);
517 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
18d715bd 518#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
519 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
520#else
521 if(GetDisplayConnection()->GetDisplay())
522 {
523 Window aWindow =
524 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
525 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
526 }
527#endif
528}
529
530//==============================================================================
531//function : IsWindowOverlapped
532//purpose : Check if theWindow overlapp another view
533//==============================================================================
534
535Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
536 const Standard_Integer thePxTop,
537 const Standard_Integer thePxRight,
538 const Standard_Integer thePxBottom,
539 TCollection_AsciiString& theViewId)
540{
541 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
542 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
543 {
544 Standard_Integer aTop = 0,
545 aLeft = 0,
546 aRight = 0,
547 aBottom = 0;
548 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
549 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
550 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
551 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
552 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
553 {
554 theViewId = anIter.Key1();
555 return Standard_True;
556 }
557 }
558 return Standard_False;
559}
560
561// Workaround: to create and delete non-orthographic views outside ViewerTest
562void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
563{
564 ViewerTest_myViews.UnBind1 (theName);
565}
566
567void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
568 const Handle(V3d_View)& theView)
569{
570 ViewerTest_myViews.Bind (theName, theView);
571}
572
573TCollection_AsciiString ViewerTest::GetCurrentViewName ()
574{
575 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
576}
7fd59977 577//==============================================================================
578//function : ViewerInit
579//purpose : Create the window viewer and initialize all the global variable
580//==============================================================================
581
18d715bd 582TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
583 const Standard_Integer thePxTop,
584 const Standard_Integer thePxWidth,
585 const Standard_Integer thePxHeight,
9e04ccdc 586 const TCollection_AsciiString& theViewName,
587 const TCollection_AsciiString& theDisplayName,
588 const Handle(V3d_View)& theViewToClone)
7fd59977 589{
8c3c9904 590 // Default position and dimension of the viewer window.
4fe56619 591 // Note that left top corner is set to be sufficiently small to have
8c3c9904 592 // window fit in the small screens (actual for remote desktops, see #23003).
4fe56619 593 // The position corresponds to the window's client area, thus some
8c3c9904 594 // gap is added for window frame to be visible.
595 Standard_Integer aPxLeft = 20;
596 Standard_Integer aPxTop = 40;
7fd59977 597 Standard_Integer aPxWidth = 409;
598 Standard_Integer aPxHeight = 409;
18d715bd 599 Standard_Boolean toCreateViewer = Standard_False;
9e04ccdc 600 if (!theViewToClone.IsNull())
601 {
602 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
603 }
18d715bd 604
58655684 605 Handle(OpenGl_GraphicDriver) aGraphicDriver;
18d715bd 606 ViewerTest_Names aViewNames(theViewName);
607 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
608 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
609
610 if (thePxLeft != 0)
611 aPxLeft = thePxLeft;
612 if (thePxTop != 0)
613 aPxTop = thePxTop;
614 if (thePxWidth != 0)
615 aPxWidth = thePxWidth;
616 if (thePxHeight != 0)
7fd59977 617 aPxHeight = thePxHeight;
4269bd1b 618
18d715bd 619 // Get graphic driver (create it or get from another view)
620 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
621 {
622 // Get connection string
58655684 623 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 624 TCollection_AsciiString aDisplayName(theDisplayName);
498ce76b 625 if (!aDisplayName.IsEmpty())
18d715bd 626 SetDisplayConnection (new Aspect_DisplayConnection ());
627 else
628 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
18d715bd 629 #else
498ce76b 630 (void)theDisplayName; // avoid warning on unused argument
18d715bd 631 SetDisplayConnection (new Aspect_DisplayConnection ());
632 #endif
14cb22a1 633
634 if (Draw_VirtualWindows)
635 {
636 // don't waste the time waiting for VSync when window is not displayed on the screen
637 ViewerTest_myDefaultCaps.swapInterval = 0;
638 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
639 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
640 }
65993a95 641 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
58655684 642 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
14cb22a1 643
18d715bd 644 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
645 toCreateViewer = Standard_True;
646 }
647 else
648 {
58655684 649 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
7fd59977 650 }
651
18d715bd 652 //Dispose the window if input parameters are default
653 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
7fd59977 654 {
18d715bd 655 Standard_Integer aTop = 0,
656 aLeft = 0,
657 aRight = 0,
658 aBottom = 0,
659 aScreenWidth = 0,
660 aScreenHeight = 0;
661
662 // Get screen resolution
663#if defined(_WIN32) || defined(__WIN32__)
664 RECT aWindowSize;
665 GetClientRect(GetDesktopWindow(), &aWindowSize);
666 aScreenHeight = aWindowSize.bottom;
667 aScreenWidth = aWindowSize.right;
668#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
669 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
670#else
671 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
672 aScreenWidth = WidthOfScreen(aScreen);
673 aScreenHeight = HeightOfScreen(aScreen);
674#endif
675
676 TCollection_AsciiString anOverlappedViewId("");
773f53f1 677
678 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
dc3fe572 679 {
18d715bd 680 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
681
682 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
683 && aRight + 2*aPxWidth + 40 > aScreenWidth)
684 {
685 if (aBottom + aPxHeight + 40 > aScreenHeight)
686 {
687 aPxLeft = 20;
688 aPxTop = 40;
689 break;
690 }
691 aPxLeft = 20;
692 aPxTop = aBottom + 40;
693 }
694 else
695 aPxLeft = aRight + 20;
dc3fe572 696 }
18d715bd 697 }
698
699 // Get viewer name
700 TCollection_AsciiString aTitle("3D View - ");
701 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
702
703 // Change name of current active window
704 if (!ViewerTest::CurrentView().IsNull())
705 {
51740958 706 TCollection_AsciiString anActiveWindowTitle("3D View - ");
707 anActiveWindowTitle = anActiveWindowTitle
18d715bd 708 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
51740958 709 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
18d715bd 710 }
711
712 // Create viewer
eb4320f2 713 Handle(V3d_Viewer) a3DViewer;
18d715bd 714 // If it's the single view, we first look for empty context
715 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
716 {
717 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
718 anIter(ViewerTest_myContexts);
719 if (anIter.More())
720 ViewerTest::SetAISContext (anIter.Value());
721 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 722 }
723 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
724 {
725 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
726 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 727 }
eb4320f2 728 else if (a3DViewer.IsNull())
18d715bd 729 {
730 toCreateViewer = Standard_True;
6a24c6de 731 a3DViewer = new V3d_Viewer(aGraphicDriver);
f42753ed 732 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
733 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
734 ViewerTest_DefaultBackground.GradientColor2,
735 ViewerTest_DefaultBackground.FillMethod);
18d715bd 736 }
737
738 // AIS context setup
739 if (ViewerTest::GetAISContext().IsNull() ||
740 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
741 {
e79a94b9 742 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
18d715bd 743 ViewerTest::SetAISContext (aContext);
744 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
745 }
746 else
e79a94b9 747 {
18d715bd 748 ViewerTest::ResetEventManager();
e79a94b9 749 }
18d715bd 750
751 // Create window
e79a94b9 752#if defined(_WIN32)
753 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
754 Handle(WNT_WClass)::DownCast (WClass()),
62e1beed 755 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
e79a94b9 756 aPxLeft, aPxTop,
757 aPxWidth, aPxHeight,
758 Quantity_NOC_BLACK);
4fe56619 759#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
e79a94b9 760 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
761 aPxLeft, aPxTop,
762 aPxWidth, aPxHeight);
763 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
7fd59977 764#else
e79a94b9 765 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
766 aTitle.ToCString(),
767 aPxLeft, aPxTop,
768 aPxWidth, aPxHeight);
7fd59977 769#endif
18d715bd 770 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
7fd59977 771
d09dda09 772 // View setup
9e04ccdc 773 Handle(V3d_View) aView;
774 if (!theViewToClone.IsNull())
775 {
2e93433e 776 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
9e04ccdc 777 }
778 else
779 {
2e93433e 780 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
9e04ccdc 781 }
782
d09dda09 783 aView->SetWindow (VT_GetWindow());
c3282ec1 784 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
4269bd1b 785
18d715bd 786 ViewerTest::CurrentView(aView);
787 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
7fd59977 788
18d715bd 789 // Setup for X11 or NT
790 OSWindowSetup();
7fd59977 791
18d715bd 792 // Set parameters for V3d_View and V3d_Viewer
793 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
794 aV3dView->SetComputedMode(Standard_False);
7fd59977 795
18d715bd 796 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
797 if (toCreateViewer)
798 {
7fd59977 799 a3DViewer->SetDefaultLights();
800 a3DViewer->SetLightOn();
18d715bd 801 }
7fd59977 802
e79a94b9 803 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4fe56619 804 #if TCL_MAJOR_VERSION < 8
18d715bd 805 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 806 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 807 #else
18d715bd 808 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 809 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 810 #endif
811 #endif
7fd59977 812
7fd59977 813 VT_GetWindow()->Map();
4269bd1b 814
18d715bd 815 // Set the handle of created view in the event manager
816 ViewerTest::ResetEventManager();
817
4fe56619 818 ViewerTest::CurrentView()->Redraw();
18d715bd 819
820 aView.Nullify();
821 a3DViewer.Nullify();
18d715bd 822
823 return aViewNames.GetViewName();
824}
825
4269bd1b 826//==============================================================================
827//function : RedrawAllViews
828//purpose : Redraw all created views
829//==============================================================================
830void ViewerTest::RedrawAllViews()
831{
832 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
833 for (; aViewIt.More(); aViewIt.Next())
834 {
835 const Handle(V3d_View)& aView = aViewIt.Key2();
836 aView->Redraw();
837 }
838}
839
7fd59977 840//==============================================================================
841//function : Vinit
842//purpose : Create the window viewer and initialize all the global variable
e79a94b9 843// Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
7fd59977 844//==============================================================================
845
18d715bd 846static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 847{
e79a94b9 848 TCollection_AsciiString aViewName, aDisplayName;
849 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
9e04ccdc 850 Handle(V3d_View) aCopyFrom;
e79a94b9 851 TCollection_AsciiString aName, aValue;
2e93433e 852 int is2dMode = -1;
e79a94b9 853 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
18d715bd 854 {
e79a94b9 855 const TCollection_AsciiString anArg = theArgVec[anArgIt];
856 TCollection_AsciiString anArgCase = anArg;
fd3f6bd0 857 anArgCase.LowerCase();
858 if (anArgIt + 1 < theArgsNb
859 && anArgCase == "-name")
860 {
861 aViewName = theArgVec[++anArgIt];
862 }
863 else if (anArgIt + 1 < theArgsNb
864 && (anArgCase == "-left"
865 || anArgCase == "-l"))
866 {
867 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
868 }
869 else if (anArgIt + 1 < theArgsNb
870 && (anArgCase == "-top"
871 || anArgCase == "-t"))
872 {
873 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
874 }
875 else if (anArgIt + 1 < theArgsNb
876 && (anArgCase == "-width"
877 || anArgCase == "-w"))
878 {
879 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
880 }
881 else if (anArgIt + 1 < theArgsNb
882 && (anArgCase == "-height"
883 || anArgCase == "-h"))
18d715bd 884 {
fd3f6bd0 885 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
886 }
887 else if (anArgCase == "-exitonclose")
888 {
889 Draw_ToExitOnCloseView = true;
890 if (anArgIt + 1 < theArgsNb
891 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
892 {
893 ++anArgIt;
894 }
895 }
896 else if (anArgCase == "-closeonescape"
897 || anArgCase == "-closeonesc")
898 {
899 Draw_ToCloseViewOnEsc = true;
900 if (anArgIt + 1 < theArgsNb
901 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
902 {
903 ++anArgIt;
904 }
905 }
2e93433e 906 else if (anArgCase == "-2d_mode"
907 || anArgCase == "-2dmode"
908 || anArgCase == "-2d")
909 {
910 bool toEnable = true;
911 if (anArgIt + 1 < theArgsNb
912 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
913 {
914 ++anArgIt;
915 }
916 is2dMode = toEnable ? 1 : 0;
917 }
fd3f6bd0 918 else if (anArgIt + 1 < theArgsNb
919 && (anArgCase == "-disp"
920 || anArgCase == "-display"))
921 {
922 aDisplayName = theArgVec[++anArgIt];
923 }
9e04ccdc 924 else if (!ViewerTest::CurrentView().IsNull()
925 && aCopyFrom.IsNull()
926 && (anArgCase == "-copy"
927 || anArgCase == "-clone"
928 || anArgCase == "-cloneactive"
929 || anArgCase == "-cloneactiveview"))
930 {
931 aCopyFrom = ViewerTest::CurrentView();
932 }
fd3f6bd0 933 // old syntax
934 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
935 {
936 aName.LowerCase();
937 if (aName == "name")
18d715bd 938 {
939 aViewName = aValue;
940 }
fd3f6bd0 941 else if (aName == "l"
942 || aName == "left")
e79a94b9 943 {
18d715bd 944 aPxLeft = aValue.IntegerValue();
e79a94b9 945 }
fd3f6bd0 946 else if (aName == "t"
947 || aName == "top")
e79a94b9 948 {
18d715bd 949 aPxTop = aValue.IntegerValue();
e79a94b9 950 }
fd3f6bd0 951 else if (aName == "disp"
952 || aName == "display")
e79a94b9 953 {
18d715bd 954 aDisplayName = aValue;
e79a94b9 955 }
fd3f6bd0 956 else if (aName == "w"
957 || aName == "width")
e79a94b9 958 {
18d715bd 959 aPxWidth = aValue.IntegerValue();
e79a94b9 960 }
fd3f6bd0 961 else if (aName == "h"
962 || aName == "height")
e79a94b9 963 {
18d715bd 964 aPxHeight = aValue.IntegerValue();
e79a94b9 965 }
18d715bd 966 else
967 {
fd3f6bd0 968 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
969 return 1;
18d715bd 970 }
971 }
e79a94b9 972 else if (aViewName.IsEmpty())
973 {
974 aViewName = anArg;
975 }
976 else
977 {
fd3f6bd0 978 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
979 return 1;
e79a94b9 980 }
18d715bd 981 }
982
fd3f6bd0 983#if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
984 if (!aDisplayName.IsEmpty())
985 {
986 aDisplayName.Clear();
987 std::cout << "Warning: display parameter will be ignored.\n";
988 }
989#endif
990
18d715bd 991 ViewerTest_Names aViewNames (aViewName);
e79a94b9 992 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
18d715bd 993 {
e79a94b9 994 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
995 theDi.Eval (aCommand.ToCString());
2e93433e 996 if (is2dMode != -1)
997 {
998 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
999 }
18d715bd 1000 return 0;
1001 }
1002
1003 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
9e04ccdc 1004 aViewName, aDisplayName, aCopyFrom);
2e93433e 1005 if (is2dMode != -1)
1006 {
1007 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1008 }
e79a94b9 1009 theDi << aViewId;
7fd59977 1010 return 0;
1011}
1012
1eeef710 1013//! Parse HLR algo type.
1014static Standard_Boolean parseHlrAlgoType (const char* theName,
1015 Prs3d_TypeOfHLR& theType)
1016{
1017 TCollection_AsciiString aName (theName);
1018 aName.LowerCase();
1019 if (aName == "polyalgo")
1020 {
1021 theType = Prs3d_TOH_PolyAlgo;
1022 }
1023 else if (aName == "algo")
1024 {
1025 theType = Prs3d_TOH_Algo;
1026 }
1027 else
1028 {
1029 return Standard_False;
1030 }
1031 return Standard_True;
1032}
1033
0a768f56 1034//==============================================================================
1035//function : VHLR
1036//purpose : hidden lines removal algorithm
1037//==============================================================================
1038
1039static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1040{
1eeef710 1041 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1042 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1043 if (aView.IsNull())
0a768f56 1044 {
1eeef710 1045 std::cerr << "Error: No opened viewer!\n";
0a768f56 1046 return 1;
1047 }
1048
1eeef710 1049 Standard_Boolean hasHlrOnArg = Standard_False;
1050 Standard_Boolean hasShowHiddenArg = Standard_False;
1051 Standard_Boolean isHLROn = Standard_False;
1052 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
1053 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1054 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1055 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
0a768f56 1056 {
1eeef710 1057 TCollection_AsciiString anArg (argv[anArgIter]);
1058 anArg.LowerCase();
1059 if (anUpdateTool.parseRedrawMode (anArg))
1060 {
1061 continue;
1062 }
1063 else if (anArg == "-showhidden"
1064 && anArgIter + 1 < argc
1065 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
1066 {
1067 ++anArgIter;
1068 hasShowHiddenArg = Standard_True;
1069 continue;
1070 }
1071 else if ((anArg == "-type"
1072 || anArg == "-algo"
1073 || anArg == "-algotype")
1074 && anArgIter + 1 < argc
1075 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1076 {
1077 ++anArgIter;
1078 continue;
1079 }
1080 else if (!hasHlrOnArg
1081 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
1082 {
1083 hasHlrOnArg = Standard_True;
1084 continue;
1085 }
1086 // old syntax
1087 else if (!hasShowHiddenArg
1088 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
1089 {
1090 hasShowHiddenArg = Standard_True;
1091 continue;
1092 }
1093 else
1094 {
1095 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
1096 return 1;
1097 }
0a768f56 1098 }
1eeef710 1099 if (!hasHlrOnArg)
0a768f56 1100 {
1eeef710 1101 di << "HLR: " << aView->ComputedMode() << "\n";
1102 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1103 di << "HlrAlgo: ";
1104 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1105 {
1106 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1107 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1108 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1109 }
1110 anUpdateTool.Invalidate();
1111 return 0;
0a768f56 1112 }
1113
1eeef710 1114 Standard_Boolean toRecompute = Standard_False;
1115 if (aTypeOfHLR != Prs3d_TOH_NotSet
1116 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
e9224045 1117 {
1eeef710 1118 toRecompute = Standard_True;
1119 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1120 }
1121 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1122 {
1123 toRecompute = Standard_True;
1124 if (toShowHidden)
e9224045 1125 {
1eeef710 1126 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
e9224045 1127 }
1128 else
1129 {
1eeef710 1130 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
e9224045 1131 }
1eeef710 1132 }
e9224045 1133
1eeef710 1134 // redisplay shapes
1135 if (aView->ComputedMode() && isHLROn && toRecompute)
1136 {
1137 AIS_ListOfInteractive aListOfShapes;
1138 aCtx->DisplayedObjects (aListOfShapes);
1139 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
e9224045 1140 {
1eeef710 1141 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
e9224045 1142 {
1eeef710 1143 aCtx->Redisplay (aShape, Standard_False);
e9224045 1144 }
1145 }
1146 }
0a768f56 1147
1eeef710 1148 aView->SetComputedMode (isHLROn);
0a768f56 1149 return 0;
1150}
1151
1152//==============================================================================
1153//function : VHLRType
1154//purpose : change type of using HLR algorithm
1155//==============================================================================
1156
1eeef710 1157static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
0a768f56 1158{
1eeef710 1159 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1160 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1161 if (aView.IsNull())
0a768f56 1162 {
1eeef710 1163 std::cerr << "Error: No opened viewer!\n";
0a768f56 1164 return 1;
1165 }
1166
1eeef710 1167 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1168 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1169 AIS_ListOfInteractive aListOfShapes;
1170 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
0a768f56 1171 {
1eeef710 1172 TCollection_AsciiString anArg (argv[anArgIter]);
1173 anArg.LowerCase();
1174 if (anUpdateTool.parseRedrawMode (anArg))
0a768f56 1175 {
1eeef710 1176 continue;
0a768f56 1177 }
1eeef710 1178 else if ((anArg == "-type"
1179 || anArg == "-algo"
1180 || anArg == "-algotype")
1181 && anArgIter + 1 < argc
1182 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1183 {
1184 ++anArgIter;
1185 continue;
1186 }
1187 // old syntax
1188 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1189 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1190 {
1191 continue;
1192 }
1193 else
0a768f56 1194 {
1195 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1eeef710 1196 TCollection_AsciiString aName (argv[anArgIter]);
0a768f56 1197 if (!aMap.IsBound2 (aName))
1198 {
1eeef710 1199 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1200 return 1;
0a768f56 1201 }
1eeef710 1202
1203 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1204 if (aShape.IsNull())
1205 {
1206 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1207 return 1;
1208 }
1209 aListOfShapes.Append (aShape);
1210 continue;
0a768f56 1211 }
1eeef710 1212 }
1213 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1214 {
1215 std::cout << "Syntax error: wrong number of arguments!\n";
1216 return 1;
1217 }
1218
1219 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1220 if (isGlobal)
1221 {
1222 aCtx->DisplayedObjects (aListOfShapes);
1223 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
0a768f56 1224 }
1225
1eeef710 1226 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1227 {
1228 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1229 if (aShape.IsNull())
1230 {
1231 continue;
1232 }
1233
1234 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1235 && aView->ComputedMode();
1236 if (!isGlobal
1237 || aShape->TypeOfHLR() != aTypeOfHLR)
1238 {
1239 aShape->SetTypeOfHLR (aTypeOfHLR);
1240 }
1241 if (toUpdateShape)
1242 {
1243 aCtx->Redisplay (aShape, Standard_False);
1244 }
1245 }
0a768f56 1246 return 0;
1247}
1248
18d715bd 1249//==============================================================================
1250//function : FindViewIdByWindowHandle
1251//purpose : Find theView Id in the map of views by window handle
1252//==============================================================================
1253#if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1254TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1255{
1256 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1257 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1258 {
1259 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1260 if (aWindowHandle == theWindowHandle)
1261 return anIter.Key1();
1262 }
1263 return TCollection_AsciiString("");
1264}
1265#endif
1266
e084dbbc 1267//! Make the view active
1268void ActivateView (const TCollection_AsciiString& theViewName,
1269 Standard_Boolean theToUpdate = Standard_True)
18d715bd 1270{
1271 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
e084dbbc 1272 if (aView.IsNull())
18d715bd 1273 {
e084dbbc 1274 return;
1275 }
18d715bd 1276
e084dbbc 1277 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1278 if (!anAISContext.IsNull())
1279 {
1280 if (!ViewerTest::CurrentView().IsNull())
1281 {
1282 TCollection_AsciiString aTitle("3D View - ");
1283 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
18d715bd 1284 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
e084dbbc 1285 }
1286
1287 ViewerTest::CurrentView (aView);
1288 ViewerTest::SetAISContext (anAISContext);
1289 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
1290 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1eeef710 1291#if defined(_WIN32)
e084dbbc 1292 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
18d715bd 1293#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
e084dbbc 1294 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
18d715bd 1295#else
e084dbbc 1296 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
18d715bd 1297#endif
e084dbbc 1298 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1299 if (theToUpdate)
1300 {
18d715bd 1301 ViewerTest::CurrentView()->Redraw();
1302 }
1303 }
1304}
1305
0e93d9e5 1306//==============================================================================
1307//function : RemoveView
1308//purpose :
1309//==============================================================================
1310void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1311 const Standard_Boolean theToRemoveContext)
1312{
1313 if (!ViewerTest_myViews.IsBound2 (theView))
1314 {
1315 return;
1316 }
1317
1318 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1319 RemoveView (aViewName, theToRemoveContext);
1320}
1321
18d715bd 1322//==============================================================================
1323//function : RemoveView
1324//purpose : Close and remove view from display, clear maps if neccessary
1325//==============================================================================
1326void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1327{
1328 if (!ViewerTest_myViews.IsBound1(theViewName))
1329 {
1330 cout << "Wrong view name\n";
1331 return;
1332 }
1333
1334 // Activate another view if it's active now
1335 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1336 {
1337 if (ViewerTest_myViews.Extent() > 1)
1338 {
1339 TCollection_AsciiString aNewViewName;
c48e2889 1340 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1341 anIter.More(); anIter.Next())
1342 {
18d715bd 1343 if (anIter.Key1() != theViewName)
1344 {
1345 aNewViewName = anIter.Key1();
1346 break;
1347 }
c48e2889 1348 }
1349 ActivateView (aNewViewName);
18d715bd 1350 }
1351 else
1352 {
e084dbbc 1353 VT_GetWindow().Nullify();
1354 ViewerTest::CurrentView (Handle(V3d_View)());
18d715bd 1355 if (isContextRemoved)
1356 {
1357 Handle(AIS_InteractiveContext) anEmptyContext;
1358 ViewerTest::SetAISContext(anEmptyContext);
1359 }
1360 }
1361 }
1362
1363 // Delete view
1364 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1365 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1366
1367 // Remove view resources
18d715bd 1368 ViewerTest_myViews.UnBind1(theViewName);
851dacdb 1369 aView->Window()->Unmap();
18d715bd 1370 aView->Remove();
1371
1372#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1373 XFlush (GetDisplayConnection()->GetDisplay());
1374#endif
1375
1376 // Keep context opened only if the closed view is last to avoid
1377 // unused empty contexts
1378 if (!aCurrentContext.IsNull())
1379 {
1380 // Check if there are more difined views in the viewer
1381 aCurrentContext->CurrentViewer()->InitDefinedViews();
1382 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1383 {
1384 // Remove driver if there is no viewers that use it
1385 Standard_Boolean isRemoveDriver = Standard_True;
1386 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1387 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1388 {
1389 if (aCurrentContext != anIter.Key2() &&
1390 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1391 {
1392 isRemoveDriver = Standard_False;
1393 break;
1394 }
1395 }
2ec85268 1396
1397 aCurrentContext->RemoveAll (Standard_False);
18d715bd 1398 if(isRemoveDriver)
1399 {
1400 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1401 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1402 #if TCL_MAJOR_VERSION < 8
1403 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1404 #else
1405 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1406 #endif
1407 #endif
1408 }
1409
1410 ViewerTest_myContexts.UnBind2(aCurrentContext);
1411 }
1412 }
1413 cout << "3D View - " << theViewName << " was deleted.\n";
fd3f6bd0 1414 if (Draw_ToExitOnCloseView)
1415 {
1416 Draw_Interprete ("exit");
1417 }
18d715bd 1418}
1419
1420//==============================================================================
1421//function : VClose
1422//purpose : Remove the view defined by its name
1423//==============================================================================
1424
d0cc1cb7 1425static int VClose (Draw_Interpretor& /*theDi*/,
1426 Standard_Integer theArgsNb,
1427 const char** theArgVec)
18d715bd 1428{
18d715bd 1429 NCollection_List<TCollection_AsciiString> aViewList;
d0cc1cb7 1430 if (theArgsNb > 1)
18d715bd 1431 {
d0cc1cb7 1432 TCollection_AsciiString anArg (theArgVec[1]);
1433 anArg.UpperCase();
1434 if (anArg.IsEqual ("ALL")
1435 || anArg.IsEqual ("*"))
1436 {
1437 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1438 anIter.More(); anIter.Next())
1439 {
1440 aViewList.Append (anIter.Key1());
1441 }
1442 if (aViewList.IsEmpty())
1443 {
1444 std::cout << "No view to close\n";
1445 return 0;
1446 }
1447 }
1448 else
18d715bd 1449 {
d0cc1cb7 1450 ViewerTest_Names aViewName (theArgVec[1]);
1451 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1452 {
1453 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1454 return 1;
1455 }
1456 aViewList.Append (aViewName.GetViewName());
18d715bd 1457 }
1458 }
1459 else
1460 {
d0cc1cb7 1461 // close active view
1462 if (ViewerTest::CurrentView().IsNull())
1463 {
1464 std::cerr << "No active view!\n";
1465 return 1;
1466 }
1467 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
18d715bd 1468 }
1469
d0cc1cb7 1470 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
18d715bd 1471 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1472 anIter.More(); anIter.Next())
1473 {
d0cc1cb7 1474 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
18d715bd 1475 }
1476
1477 return 0;
1478}
1479
1480//==============================================================================
1481//function : VActivate
1482//purpose : Activate the view defined by its ID
1483//==============================================================================
1484
1485static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1486{
e084dbbc 1487 if (theArgsNb == 1)
18d715bd 1488 {
1489 theDi.Eval("vviewlist");
1490 return 0;
1491 }
1492
e084dbbc 1493 TCollection_AsciiString aNameString;
1494 Standard_Boolean toUpdate = Standard_True;
1495 Standard_Boolean toActivate = Standard_True;
1496 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
18d715bd 1497 {
e084dbbc 1498 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1499 anArg.LowerCase();
1500 if (toUpdate
1501 && anArg == "-noupdate")
1502 {
1503 toUpdate = Standard_False;
1504 }
1505 else if (toActivate
1506 && aNameString.IsEmpty()
1507 && anArg == "none")
1508 {
1509 TCollection_AsciiString aTitle("3D View - ");
1510 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1511 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1512 VT_GetWindow().Nullify();
1513 ViewerTest::CurrentView (Handle(V3d_View)());
1514 ViewerTest::ResetEventManager();
1515 theDi << theArgVec[0] << ": all views are inactive\n";
1516 toActivate = Standard_False;
1517 }
1518 else if (toActivate
1519 && aNameString.IsEmpty())
1520 {
1521 aNameString = theArgVec[anArgIter];
1522 }
1523 else
1524 {
1525 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
1526 return 1;
1527 }
18d715bd 1528 }
1529
e084dbbc 1530 if (!toActivate)
1531 {
1532 return 0;
1533 }
1534 else if (aNameString.IsEmpty())
1535 {
1536 std::cout << "Syntax error: wrong number of arguments\n";
1537 return 1;
1538 }
18d715bd 1539
1540 // Check if this view exists in the viewer with the driver
e084dbbc 1541 ViewerTest_Names aViewNames (aNameString);
18d715bd 1542 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1543 {
e084dbbc 1544 theDi << "Syntax error: wrong view name '" << aNameString << "'\n";
18d715bd 1545 return 1;
1546 }
1547
1548 // Check if it is active already
1549 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1550 {
1551 theDi << theArgVec[0] << ": the view is active already\n";
1552 return 0;
1553 }
1554
e084dbbc 1555 ActivateView (aViewNames.GetViewName(), toUpdate);
18d715bd 1556 return 0;
1557}
1558
1559//==============================================================================
1560//function : VViewList
1561//purpose : Print current list of views per viewer and graphic driver ID
1562// shared between viewers
1563//==============================================================================
1564
1565static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1566{
1567 if (theArgsNb > 2)
1568 {
1569 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
29cb310a 1570 << "Usage: " << theArgVec[0] << " name";
18d715bd 1571 return 1;
1572 }
1573 if (ViewerTest_myContexts.Size() < 1)
1574 return 0;
1575
18d715bd 1576 Standard_Boolean isTreeView =
29cb310a 1577 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
18d715bd 1578
1579 if (isTreeView)
c48e2889 1580 {
18d715bd 1581 theDi << theArgVec[0] <<":\n";
c48e2889 1582 }
18d715bd 1583
c48e2889 1584 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1585 aDriverIter.More(); aDriverIter.Next())
1586 {
1587 if (isTreeView)
1588 theDi << aDriverIter.Key1() << ":\n";
18d715bd 1589
c48e2889 1590 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1591 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1592 {
1593 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
18d715bd 1594 {
c48e2889 1595 if (isTreeView)
18d715bd 1596 {
c48e2889 1597 TCollection_AsciiString aContextName(aContextIter.Key1());
1598 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1599 }
18d715bd 1600
c48e2889 1601 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1602 aViewIter.More(); aViewIter.Next())
1603 {
1604 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
18d715bd 1605 {
c48e2889 1606 TCollection_AsciiString aViewName(aViewIter.Key1());
1607 if (isTreeView)
18d715bd 1608 {
c48e2889 1609 if (aViewIter.Value() == ViewerTest::CurrentView())
1610 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
18d715bd 1611 else
c48e2889 1612 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1613 }
1614 else
1615 {
1616 theDi << aViewName << " ";
18d715bd 1617 }
1618 }
1619 }
1620 }
1621 }
c48e2889 1622 }
18d715bd 1623 return 0;
1624}
1625
7fd59977 1626//==============================================================================
4fe56619 1627//function : VT_ProcessKeyPress
7fd59977 1628//purpose : Handle KeyPress event from a CString
1629//==============================================================================
4fe56619 1630void VT_ProcessKeyPress (const char* buf_ret)
7fd59977 1631{
1632 //cout << "KeyPress" << endl;
1633 const Handle(V3d_View) aView = ViewerTest::CurrentView();
7fd59977 1634 // Letter in alphabetic order
1635
2e93433e 1636 if (!strcasecmp (buf_ret, "A")
1637 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1638 {
7fd59977 1639 // AXO
1640 aView->SetProj(V3d_XposYnegZpos);
1641 }
2e93433e 1642 else if (!strcasecmp (buf_ret, "D")
1643 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1644 {
7fd59977 1645 // Reset
1646 aView->Reset();
1647 }
b514beda 1648 else if (!strcasecmp (buf_ret, "F"))
1649 {
b586500b 1650 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1651 {
1652 ViewerTest::GetAISContext()->FitSelected (aView);
1653 }
1654 else
1655 {
1656 // FitAll
1657 aView->FitAll();
1658 }
7fd59977 1659 }
b514beda 1660 else if (!strcasecmp (buf_ret, "H"))
1661 {
7fd59977 1662 // HLR
1eeef710 1663 std::cout << "HLR" << std::endl;
de75ed09 1664 aView->SetComputedMode (!aView->ComputedMode());
1eeef710 1665 aView->Redraw();
7fd59977 1666 }
b514beda 1667 else if (!strcasecmp (buf_ret, "P"))
1668 {
0a768f56 1669 // Type of HLR
1670 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1671 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1672 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1673 else
1674 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
c3282ec1 1675 if (aContext->NbSelected()==0)
0a768f56 1676 {
1677 AIS_ListOfInteractive aListOfShapes;
1678 aContext->DisplayedObjects(aListOfShapes);
1679 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1680 anIter.More(); anIter.Next())
1681 {
1682 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1683 if (aShape.IsNull())
1684 continue;
1685 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1686 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1687 else
1688 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1689 aContext->Redisplay (aShape, Standard_False);
0a768f56 1690 }
1691 }
1692 else
1693 {
c3282ec1 1694 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
0a768f56 1695 {
c3282ec1 1696 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
0a768f56 1697 if (aShape.IsNull())
1698 continue;
1699 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1700 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1701 else
1702 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1703 aContext->Redisplay (aShape, Standard_False);
0a768f56 1704 }
1705 }
1706
1707 aContext->UpdateCurrentViewer();
4269bd1b 1708
0a768f56 1709 }
b514beda 1710 else if (!strcasecmp (buf_ret, "S"))
1711 {
1712 std::cout << "setup Shaded display mode" << std::endl;
4fe56619 1713
7fd59977 1714 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1715 if(Ctx->NbSelected()==0)
0577ae8c 1716 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
7fd59977 1717 else{
c3282ec1 1718 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1719 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
7fd59977 1720 Ctx->UpdateCurrentViewer();
1721 }
1722 }
b514beda 1723 else if (!strcasecmp (buf_ret, "U"))
1724 {
41811896 1725 // Unset display mode
b514beda 1726 std::cout << "reset display mode to defaults" << std::endl;
4fe56619 1727
7fd59977 1728 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1729 if(Ctx->NbSelected()==0)
0577ae8c 1730 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 1731 else{
c3282ec1 1732 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1733 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
7fd59977 1734 Ctx->UpdateCurrentViewer();
1735 }
1736
1737 }
2e93433e 1738 else if (!strcasecmp (buf_ret, "T")
1739 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1740 {
7fd59977 1741 // Top
1742 aView->SetProj(V3d_Zpos);
1743 }
2e93433e 1744 else if (!strcasecmp (buf_ret, "B")
1745 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1746 {
41811896 1747 // Bottom
7fd59977 1748 aView->SetProj(V3d_Zneg);
1749 }
2e93433e 1750 else if (!strcasecmp (buf_ret, "L")
1751 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1752 {
41811896 1753 // Left
7fd59977 1754 aView->SetProj(V3d_Xneg);
1755 }
2e93433e 1756 else if (!strcasecmp (buf_ret, "R")
1757 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1758 {
41811896 1759 // Right
7fd59977 1760 aView->SetProj(V3d_Xpos);
1761 }
b514beda 1762 else if (!strcasecmp (buf_ret, "W"))
1763 {
1764 std::cout << "setup WireFrame display mode" << std::endl;
7fd59977 1765 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1766 if(Ctx->NbSelected()==0)
0577ae8c 1767 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 1768 else{
c3282ec1 1769 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1770 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
7fd59977 1771 Ctx->UpdateCurrentViewer();
1772 }
1773 }
b514beda 1774 else if (!strcasecmp (buf_ret, ","))
1775 {
7fd59977 1776 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
7fd59977 1777 }
b514beda 1778 else if (!strcasecmp (buf_ret, "."))
1779 {
7fd59977 1780 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1781 }
f978241f 1782 else if (!strcasecmp (buf_ret, "/"))
1783 {
1784 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1785 if (aCamera->IsStereo())
1786 {
1787 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1788 aView->Redraw();
1789 }
1790 }
1791 else if (!strcasecmp (buf_ret, "*"))
1792 {
1793 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1794 if (aCamera->IsStereo())
1795 {
1796 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1797 aView->Redraw();
1798 }
1799 }
b514beda 1800 else if (*buf_ret == THE_KEY_DELETE)
1801 {
1802 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1803 if (!aCtx.IsNull()
b514beda 1804 && aCtx->NbSelected() > 0)
1805 {
1806 Draw_Interprete ("verase");
1807 }
1808 }
fd3f6bd0 1809 else if (*buf_ret == THE_KEY_ESCAPE)
1810 {
1811 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1812 if (!aCtx.IsNull()
1813 && Draw_ToCloseViewOnEsc)
1814 {
1815 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1816 }
1817 }
b514beda 1818 else
1819 {
1820 // Number
8c088c52 1821 const Standard_Integer aSelMode = Draw::Atoi(buf_ret);
1822 if (aSelMode >= 0 && aSelMode <= 7)
1823 {
1824 bool toEnable = true;
1825 if (const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext())
1826 {
1827 AIS_ListOfInteractive aPrsList;
1828 aCtx->DisplayedObjects (aPrsList);
1829 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
1830 {
1831 TColStd_ListOfInteger aModes;
1832 aCtx->ActivatedModes (aPrsIter.Value(), aModes);
1833 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
1834 {
1835 if (aModeIter.Value() == aSelMode)
1836 {
1837 toEnable = false;
1838 }
1839 }
1840 }
1841 }
1842 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
1843 Draw_Interprete (aCmd.ToCString());
1844 }
7fd59977 1845 }
1846}
1847
1848//==============================================================================
4fe56619 1849//function : VT_ProcessExpose
7fd59977 1850//purpose : Redraw the View on an Expose Event
1851//==============================================================================
4fe56619 1852void VT_ProcessExpose()
1853{
1854 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1855 if (!aView3d.IsNull())
1856 {
1857 aView3d->Redraw();
1858 }
7fd59977 1859}
1860
1861//==============================================================================
4fe56619 1862//function : VT_ProcessConfigure
7fd59977 1863//purpose : Resize the View on an Configure Event
1864//==============================================================================
4fe56619 1865void VT_ProcessConfigure()
7fd59977 1866{
4fe56619 1867 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1868 if (aView3d.IsNull())
1869 {
1870 return;
1871 }
1872
1873 aView3d->MustBeResized();
1874 aView3d->Update();
1875 aView3d->Redraw();
7fd59977 1876}
1877
1878//==============================================================================
4fe56619 1879//function : VT_ProcessButton1Press
7fd59977 1880//purpose : Picking
1881//==============================================================================
e79a94b9 1882Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1883 const char** theArgVec,
1884 Standard_Boolean theToPick,
1885 Standard_Boolean theIsShift)
7fd59977 1886{
1beb58d7 1887 if (TheIsAnimating)
1888 {
1889 TheIsAnimating = Standard_False;
1890 return Standard_False;
1891 }
1892
e79a94b9 1893 if (theToPick)
1894 {
7fd59977 1895 Standard_Real X, Y, Z;
e79a94b9 1896 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
7fd59977 1897
e79a94b9 1898 Draw::Set (theArgVec[1], X);
1899 Draw::Set (theArgVec[2], Y);
1900 Draw::Set (theArgVec[3], Z);
1901 }
7fd59977 1902
e79a94b9 1903 if (theIsShift)
1904 {
1905 ViewerTest::CurrentEventManager()->ShiftSelect();
1906 }
7fd59977 1907 else
e79a94b9 1908 {
1909 ViewerTest::CurrentEventManager()->Select();
1910 }
7fd59977 1911
e79a94b9 1912 return Standard_False;
7fd59977 1913}
1914
1915//==============================================================================
4fe56619 1916//function : VT_ProcessButton1Release
1917//purpose : End selecting
7fd59977 1918//==============================================================================
4fe56619 1919void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1920{
1921 if (IsDragged)
1922 {
1923 IsDragged = Standard_False;
1924 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1925 if (theIsShift)
1926 {
2157d6ac 1927 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1928 X_Motion, Y_Motion);
4fe56619 1929 }
1930 else
1931 {
2157d6ac 1932 EM->Select (X_ButtonPress, Y_ButtonPress,
1933 X_Motion, Y_Motion);
4fe56619 1934 }
1935 }
1936}
7fd59977 1937
4fe56619 1938//==============================================================================
1939//function : VT_ProcessButton3Press
1940//purpose : Start Rotation
1941//==============================================================================
1942void VT_ProcessButton3Press()
1943{
2e93433e 1944 if (ViewerTest_V3dView::IsCurrentViewIn2DMode())
1945 {
1946 return;
1947 }
1948
7fd59977 1949 Start_Rot = 1;
1eeef710 1950 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1951 if (HasHlrOnBeforeRotation)
de75ed09 1952 {
1953 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1954 }
7fd59977 1955 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
7fd59977 1956}
4fe56619 1957
7fd59977 1958//==============================================================================
4fe56619 1959//function : VT_ProcessButton3Release
1960//purpose : End rotation
7fd59977 1961//==============================================================================
4fe56619 1962void VT_ProcessButton3Release()
1963{
1964 if (Start_Rot)
1965 {
7fd59977 1966 Start_Rot = 0;
1eeef710 1967 if (HasHlrOnBeforeRotation)
de75ed09 1968 {
1eeef710 1969 HasHlrOnBeforeRotation = Standard_False;
de75ed09 1970 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1eeef710 1971 ViewerTest::CurrentView()->Redraw();
de75ed09 1972 }
7fd59977 1973 }
7fd59977 1974}
1975
7fd59977 1976//==============================================================================
1977//function : ProcessControlButton1Motion
1978//purpose : Zoom
1979//==============================================================================
1980
900f7229 1981#if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 1982static void ProcessControlButton1Motion()
1983{
1984 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1985
1986 X_ButtonPress = X_Motion;
1987 Y_ButtonPress = Y_Motion;
1988}
900f7229 1989#endif
7fd59977 1990
1991//==============================================================================
4fe56619 1992//function : VT_ProcessControlButton2Motion
1993//purpose : Panning
7fd59977 1994//==============================================================================
4fe56619 1995void VT_ProcessControlButton2Motion()
7fd59977 1996{
197ac94e 1997 Standard_Integer aDx = X_Motion - X_ButtonPress;
1998 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
7fd59977 1999
197ac94e 2000 aDy = -aDy; // Xwindow Y axis is from top to Bottom
7fd59977 2001
197ac94e 2002 ViewerTest::CurrentView()->Pan (aDx, aDy);
7fd59977 2003
2004 X_ButtonPress = X_Motion;
2005 Y_ButtonPress = Y_Motion;
2006}
2007
2008//==============================================================================
4fe56619 2009//function : VT_ProcessControlButton3Motion
7fd59977 2010//purpose : Rotation
2011//==============================================================================
4fe56619 2012void VT_ProcessControlButton3Motion()
7fd59977 2013{
4fe56619 2014 if (Start_Rot)
2015 {
2016 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
2017 }
7fd59977 2018}
2019
2020//==============================================================================
4fe56619 2021//function : VT_ProcessMotion
2022//purpose :
7fd59977 2023//==============================================================================
4fe56619 2024void VT_ProcessMotion()
7fd59977 2025{
2026 //pre-hilights detected objects at mouse position
2027
2028 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
2029 EM->MoveTo(X_Motion, Y_Motion);
2030}
2031
2032
2033void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
2034{
2035 Xpix = X_Motion;Ypix=Y_Motion;
2036}
2037
44b8f2d6 2038//==============================================================================
2039//function : ViewProject: implements VAxo, VTop, VLeft, ...
2040//purpose : Switches to an axonometric, top, left and other views
2041//==============================================================================
2042
2043static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
2044{
4fe56619 2045 if ( ViewerTest::CurrentView().IsNull() )
44b8f2d6 2046 {
586db386 2047 di<<"Call vinit before this command, please\n";
44b8f2d6 2048 return 1;
2049 }
2050
2051 ViewerTest::CurrentView()->SetProj(ori);
2052 return 0;
2053}
2054
7fd59977 2055//==============================================================================
2056//function : VAxo
2057//purpose : Switch to an Axonometric view
2058//Draw arg : No args
2059//==============================================================================
2060
2061static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
44b8f2d6 2062{
2063 return ViewProject(di, V3d_XposYnegZpos);
7fd59977 2064}
2065
2066//==============================================================================
2067//function : VTop
2068//purpose : Switch to a Top View
2069//Draw arg : No args
2070//==============================================================================
2071
2072static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
2073{
44b8f2d6 2074 return ViewProject(di, V3d_Zpos);
2075}
7fd59977 2076
44b8f2d6 2077//==============================================================================
2078//function : VBottom
2079//purpose : Switch to a Bottom View
2080//Draw arg : No args
2081//==============================================================================
7fd59977 2082
44b8f2d6 2083static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
2084{
2085 return ViewProject(di, V3d_Zneg);
2086}
7fd59977 2087
44b8f2d6 2088//==============================================================================
2089//function : VLeft
2090//purpose : Switch to a Left View
2091//Draw arg : No args
2092//==============================================================================
2093
2094static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
2095{
27af3052 2096 return ViewProject(di, V3d_Xneg);
44b8f2d6 2097}
2098
2099//==============================================================================
2100//function : VRight
2101//purpose : Switch to a Right View
2102//Draw arg : No args
2103//==============================================================================
2104
2105static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
2106{
27af3052 2107 return ViewProject(di, V3d_Xpos);
44b8f2d6 2108}
7fd59977 2109
44b8f2d6 2110//==============================================================================
2111//function : VFront
2112//purpose : Switch to a Front View
2113//Draw arg : No args
2114//==============================================================================
2115
2116static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
2117{
27af3052 2118 return ViewProject(di, V3d_Yneg);
44b8f2d6 2119}
2120
2121//==============================================================================
2122//function : VBack
2123//purpose : Switch to a Back View
2124//Draw arg : No args
2125//==============================================================================
2126
2127static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
2128{
27af3052 2129 return ViewProject(di, V3d_Ypos);
7fd59977 2130}
2131
2132//==============================================================================
2133//function : VHelp
2134//purpose : Dsiplay help on viewer Keyboead and mouse commands
2135//Draw arg : No args
2136//==============================================================================
2137
2138static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2139{
2140
586db386 2141 di << "Q : Quit the application\n";
2142
2143 di << "=========================\n";
2144 di << "F : FitAll\n";
2145 di << "T : TopView\n";
2146 di << "B : BottomView\n";
2147 di << "R : RightView\n";
2148 di << "L : LeftView\n";
2149 di << "A : AxonometricView\n";
2150 di << "D : ResetView\n";
2151
2152 di << "=========================\n";
2153 di << "S : Shading\n";
2154 di << "W : Wireframe\n";
2155 di << "H : HidelLineRemoval\n";
2156 di << "U : Unset display mode\n";
2157 di << "Delete : Remove selection from viewer\n";
2158
2159 di << "=========================\n";
2160 di << "Selection mode \n";
2161 di << "0 : Shape\n";
2162 di << "1 : Vertex\n";
2163 di << "2 : Edge\n";
2164 di << "3 : Wire\n";
2165 di << "4 : Face\n";
2166 di << "5 : Shell\n";
2167 di << "6 : Solid\n";
2168 di << "7 : Compound\n";
2169
2170 di << "=========================\n";
2171 di << "Z : Switch Z clipping On/Off\n";
2172 di << ", : Hilight next detected\n";
2173 di << ". : Hilight previous detected\n";
7fd59977 2174
2175 return 0;
2176}
2177
57c28b61 2178#ifdef _WIN32
7fd59977 2179
2180static Standard_Boolean Ppick = 0;
2181static Standard_Integer Pargc = 0;
2182static const char** Pargv = NULL;
2183
2184
2185static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2186 UINT Msg,
2187 WPARAM wParam,
2188 LPARAM lParam )
2189{
18d715bd 2190 if (!ViewerTest_myViews.IsEmpty()) {
7fd59977 2191
2192 WPARAM fwKeys = wParam;
2193
2194 switch( Msg ) {
18d715bd 2195 case WM_CLOSE:
2196 {
2197 // Delete view from map of views
2198 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2199 return 0;
2200 }
2201 break;
2202 case WM_ACTIVATE:
2203 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2204 || ViewerTest::CurrentView().IsNull())
2205 {
2206 // Activate inactive window
2207 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2208 {
2209 ActivateView (FindViewIdByWindowHandle(hwnd));
2210 }
2211 }
2212 break;
625e1958 2213
7fd59977 2214 case WM_LBUTTONUP:
625e1958 2215 if (IsDragged && !DragFirst)
7fd59977 2216 {
625e1958 2217 if (!GetActiveAISManipulator().IsNull())
2218 {
2219 GetActiveAISManipulator()->StopTransform();
0577ae8c 2220 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
625e1958 2221 }
2222
b12e1c7b 2223 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2224 {
2225 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2226 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2227 }
2228
dde68833 2229 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
7fd59977 2230 }
8abada55 2231 IsDragged = Standard_False;
7fd59977 2232 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2233
625e1958 2234 case WM_RBUTTONUP:
2235 if (IsDragged && !DragFirst)
2236 {
2237 if (!GetActiveAISManipulator().IsNull())
2238 {
2239 GetActiveAISManipulator()->StopTransform (Standard_False);
0577ae8c 2240 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
625e1958 2241 }
2242 IsDragged = Standard_False;
2243 }
2244 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2245
7fd59977 2246 case WM_LBUTTONDOWN:
625e1958 2247 if (!GetActiveAISManipulator().IsNull())
2248 {
2249 IsDragged = ( fwKeys == MK_LBUTTON );
2250 }
2251 else
2252 {
2253 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2254 }
2255
2256 if (IsDragged)
7fd59977 2257 {
7fd59977 2258 DragFirst = Standard_True;
4fe56619 2259 X_ButtonPress = LOWORD(lParam);
2260 Y_ButtonPress = HIWORD(lParam);
7fd59977 2261 }
2262 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2263
7fd59977 2264 case WM_MOUSEMOVE:
b12e1c7b 2265 if (IsDragged)
7fd59977 2266 {
b12e1c7b 2267 X_Motion = LOWORD (lParam);
2268 Y_Motion = HIWORD (lParam);
625e1958 2269 if (!GetActiveAISManipulator().IsNull())
b12e1c7b 2270 {
625e1958 2271 if (DragFirst)
2272 {
2273 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2274 }
2275 else
2276 {
2277 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2278 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2279 }
69adb9ce 2280 }
625e1958 2281 else
69adb9ce 2282 {
625e1958 2283 bool toRedraw = false;
2284 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2285 {
2286 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2287 toRedraw = true;
2288 }
2289
2290 RECT aRect;
2291 if (GetClientRect (hwnd, &aRect))
2292 {
2293 int aHeight = aRect.bottom - aRect.top;
2294 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
68dcee02 2295 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
625e1958 2296 toRedraw = true;
2297 }
2298 if (toRedraw)
2299 {
2300 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2301 }
b12e1c7b 2302 }
625e1958 2303
2304 DragFirst = Standard_False;
7fd59977 2305 }
2306 else
2307 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2308 break;
2309
2310 default:
2311 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2312 }
2313 return 0;
2314 }
2315 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2316}
2317
2318
2319static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2320 UINT Msg,
2321 WPARAM wParam,
2322 LPARAM lParam )
2323{
7fd59977 2324 static int Up = 1;
f978241f 2325 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2326 if (aView.IsNull())
2327 {
ad03c234 2328 return DefWindowProcW (hwnd, Msg, wParam, lParam);
f978241f 2329 }
7fd59977 2330
7fd59977 2331 PAINTSTRUCT ps;
2332
2333 switch( Msg ) {
7fd59977 2334 case WM_PAINT:
7fd59977 2335 BeginPaint(hwnd, &ps);
2336 EndPaint(hwnd, &ps);
4fe56619 2337 VT_ProcessExpose();
7fd59977 2338 break;
2339
2340 case WM_SIZE:
4fe56619 2341 VT_ProcessConfigure();
7fd59977 2342 break;
f978241f 2343 case WM_MOVE:
2344 case WM_MOVING:
2345 case WM_SIZING:
2346 switch (aView->RenderingParams().StereoMode)
2347 {
2348 case Graphic3d_StereoMode_RowInterlaced:
2349 case Graphic3d_StereoMode_ColumnInterlaced:
2350 case Graphic3d_StereoMode_ChessBoard:
2351 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2352 break;
2353 default:
2354 break;
2355 }
2356 break;
7fd59977 2357
2358 case WM_KEYDOWN:
4fe56619 2359 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2360 {
7fd59977 2361 char c[2];
2362 c[0] = (char) wParam;
2363 c[1] = '\0';
b514beda 2364 if (wParam == VK_DELETE)
2365 {
2366 c[0] = THE_KEY_DELETE;
2367 }
fd3f6bd0 2368 else if (wParam == VK_ESCAPE)
2369 {
2370 c[0] = THE_KEY_ESCAPE;
2371 }
4ca4bbe8 2372 // comma
2373 else if (wParam == VK_OEM_COMMA)
2374 {
2375 c[0] = ',';
2376 }
2377 // dot
2378 else if (wParam == VK_OEM_PERIOD)
2379 {
2380 c[0] = '.';
2381 }
f978241f 2382 else if (wParam == VK_DIVIDE)
2383 {
2384 c[0] = '/';
2385 }
2386 // dot
2387 else if (wParam == VK_MULTIPLY)
2388 {
2389 c[0] = '*';
2390 }
4fe56619 2391 VT_ProcessKeyPress (c);
7fd59977 2392 }
2393 break;
2394
2395 case WM_LBUTTONUP:
2396 case WM_MBUTTONUP:
2397 case WM_RBUTTONUP:
7fd59977 2398 Up = 1;
4fe56619 2399 VT_ProcessButton3Release();
7fd59977 2400 break;
2401
2402 case WM_LBUTTONDOWN:
2403 case WM_MBUTTONDOWN:
2404 case WM_RBUTTONDOWN:
2405 {
7fd59977 2406 WPARAM fwKeys = wParam;
2407
2408 Up = 0;
2409
2410 X_ButtonPress = LOWORD(lParam);
2411 Y_ButtonPress = HIWORD(lParam);
2412
4fe56619 2413 if (Msg == WM_LBUTTONDOWN)
2414 {
dde68833 2415 if ((fwKeys & MK_CONTROL) != 0)
4fe56619 2416 {
dde68833 2417 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
4fe56619 2418 }
2419 else
2420 {
dde68833 2421 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
4fe56619 2422 }
7fd59977 2423 }
4fe56619 2424 else if (Msg == WM_RBUTTONDOWN)
2425 {
7fd59977 2426 // Start rotation
4fe56619 2427 VT_ProcessButton3Press();
7fd59977 2428 }
2429 }
2430 break;
2431
f978241f 2432 case WM_MOUSEWHEEL:
2433 {
2434 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2435 if (wParam & MK_CONTROL)
2436 {
2437 if (aView->Camera()->IsStereo())
2438 {
2439 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2440 if (aFocus > 0.2
2441 && aFocus < 2.0)
2442 {
2443 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2444 aView->Redraw();
2445 }
2446 }
2447 }
2448 else
2449 {
2450 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2451 }
2452 break;
2453 }
2454
7fd59977 2455 case WM_MOUSEMOVE:
2456 {
2457 //cout << "\t WM_MOUSEMOVE" << endl;
2458 WPARAM fwKeys = wParam;
2459 X_Motion = LOWORD(lParam);
2460 Y_Motion = HIWORD(lParam);
2461
2462 if ( Up &&
dde68833 2463 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2464 {
7fd59977 2465 Up = 0;
2466 X_ButtonPress = LOWORD(lParam);
2467 Y_ButtonPress = HIWORD(lParam);
2468
dde68833 2469 if ((fwKeys & MK_RBUTTON) != 0) {
7fd59977 2470 // Start rotation
4fe56619 2471 VT_ProcessButton3Press();
7fd59977 2472 }
2473 }
2474
dde68833 2475 if ((fwKeys & MK_CONTROL) != 0)
2476 {
2477 if ((fwKeys & MK_LBUTTON) != 0)
2478 {
7fd59977 2479 ProcessControlButton1Motion();
2480 }
dde68833 2481 else if ((fwKeys & MK_MBUTTON) != 0
2482 || ((fwKeys & MK_LBUTTON) != 0
2483 && (fwKeys & MK_RBUTTON) != 0))
2484 {
2485 VT_ProcessControlButton2Motion();
2486 }
2487 else if ((fwKeys & MK_RBUTTON) != 0)
2488 {
4fe56619 2489 VT_ProcessControlButton3Motion();
7fd59977 2490 }
2491 }
08398024 2492 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2493 {
89a929ea 2494 VT_ProcessMotion();
08398024 2495 }
7fd59977 2496 }
2497 break;
2498
2499 default:
ad03c234 2500 return DefWindowProcW (hwnd, Msg, wParam, lParam);
7fd59977 2501 }
2502 return 0L;
7fd59977 2503}
2504
7fd59977 2505//==============================================================================
2506//function : ViewerMainLoop
2507//purpose : Get a Event on the view and dispatch it
2508//==============================================================================
2509
2510
8263fcd3 2511int ViewerMainLoop(Standard_Integer argc, const char** argv)
7fd59977 2512{
7fd59977 2513 Ppick = (argc > 0)? 1 : 0;
2514 Pargc = argc;
2515 Pargv = argv;
2516
2517 if ( Ppick ) {
2518 MSG msg;
2519 msg.wParam = 1;
2520
2521 cout << "Start picking" << endl;
2522
7fd59977 2523 while ( Ppick == 1 ) {
4fe56619 2524 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
ad03c234 2525 if (GetMessageW (&msg, NULL, 0, 0))
2526 {
2527 TranslateMessage (&msg);
2528 DispatchMessageW (&msg);
7fd59977 2529 }
2530 }
2531
2532 cout << "Picking done" << endl;
2533 }
2534
2535 return Ppick;
2536}
2537
4fe56619 2538#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 2539
2540int min( int a, int b )
2541{
2542 if( a<b )
2543 return a;
2544 else
2545 return b;
2546}
2547
2548int max( int a, int b )
2549{
2550 if( a>b )
2551 return a;
2552 else
2553 return b;
2554}
2555
2556int ViewerMainLoop(Standard_Integer argc, const char** argv)
2557
4269bd1b 2558{
18d715bd 2559 static XEvent aReport;
2560 Standard_Boolean pick = argc > 0;
2561 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2562 XNextEvent (aDisplay, &aReport);
7fd59977 2563
18d715bd 2564 // Handle event for the chosen display connection
2565 switch (aReport.type) {
2566 case ClientMessage:
2567 {
eb1ebea4 2568 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
18d715bd 2569 {
2570 // Close the window
2571 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2572 }
2573 }
2574 return 0;
2575 case FocusIn:
2576 {
2577 // Activate inactive view
2578 Window aWindow = GetWindowHandle(VT_GetWindow());
2579 if(aWindow != aReport.xfocus.window)
2580 {
2581 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2582 }
2583 }
2584 break;
7fd59977 2585 case Expose:
2586 {
4fe56619 2587 VT_ProcessExpose();
7fd59977 2588 }
2589 break;
2590 case ConfigureNotify:
2591 {
4fe56619 2592 VT_ProcessConfigure();
7fd59977 2593 }
2594 break;
2595 case KeyPress:
2596 {
2597
2598 KeySym ks_ret ;
2599 char buf_ret[11] ;
2600 int ret_len ;
2601 XComposeStatus status_in_out;
2602
18d715bd 2603 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
7fd59977 2604 (char *) buf_ret , 10 ,
2605 &ks_ret , &status_in_out ) ;
2606
2607
2608 buf_ret[ret_len] = '\0' ;
2609
4fe56619 2610 if (ret_len)
2611 {
2612 VT_ProcessKeyPress (buf_ret);
7fd59977 2613 }
2614 }
2615 break;
2616 case ButtonPress:
7fd59977 2617 {
18d715bd 2618 X_ButtonPress = aReport.xbutton.x;
2619 Y_ButtonPress = aReport.xbutton.y;
7fd59977 2620
18d715bd 2621 if (aReport.xbutton.button == Button1)
4fe56619 2622 {
18d715bd 2623 if (aReport.xbutton.state & ControlMask)
4fe56619 2624 {
18d715bd 2625 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
4fe56619 2626 }
7fd59977 2627 else
2628 {
2629 IsDragged = Standard_True;
7fd59977 2630 DragFirst = Standard_True;
2631 }
4fe56619 2632 }
18d715bd 2633 else if (aReport.xbutton.button == Button3)
4fe56619 2634 {
7fd59977 2635 // Start rotation
4fe56619 2636 VT_ProcessButton3Press();
2637 }
7fd59977 2638 }
2639 break;
2640 case ButtonRelease:
2641 {
7fd59977 2642 if( IsDragged )
2643 {
2644 if( !DragFirst )
2645 {
b12e1c7b 2646 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2647 {
2648 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2649 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2650 }
7fd59977 2651 }
2652
2653 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2654 if( aContext.IsNull() )
2655 {
2656 cout << "The context is null. Please use vinit before createmesh" << endl;
2657 return 0;
2658 }
2659
18d715bd 2660 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2661 if( aReport.xbutton.button==1 )
7fd59977 2662 if( DragFirst )
2663 if( ShiftPressed )
2664 {
0577ae8c 2665 aContext->ShiftSelect (Standard_True);
7fd59977 2666 }
2667 else
2668 {
0577ae8c 2669 aContext->Select (Standard_True);
7fd59977 2670 }
2671 else
2672 if( ShiftPressed )
2673 {
0577ae8c 2674 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2675 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2676 ViewerTest::CurrentView(), Standard_True);
7fd59977 2677 }
2678 else
2679 {
0577ae8c 2680 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2681 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2682 ViewerTest::CurrentView(), Standard_True);
7fd59977 2683 }
2684 else
4fe56619 2685 VT_ProcessButton3Release();
7fd59977 2686
2687 IsDragged = Standard_False;
2688 }
2689 else
4fe56619 2690 VT_ProcessButton3Release();
7fd59977 2691 }
2692 break;
2693 case MotionNotify:
2694 {
08398024 2695 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2696 {
2697 break;
2698 }
7fd59977 2699 if( IsDragged )
2700 {
7fd59977 2701 if( !DragFirst )
b12e1c7b 2702 {
2703 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2704 {
2705 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
b12e1c7b 2706 }
2707 }
7fd59977 2708
18d715bd 2709 X_Motion = aReport.xmotion.x;
2710 Y_Motion = aReport.xmotion.y;
7fd59977 2711 DragFirst = Standard_False;
2712
b12e1c7b 2713 Window aWindow = GetWindowHandle(VT_GetWindow());
2714 Window aRoot;
2715 int anX, anY;
2716 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2717 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2718 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
68dcee02 2719 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
b12e1c7b 2720 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
7fd59977 2721 }
2722 else
2723 {
18d715bd 2724 X_Motion = aReport.xmotion.x;
2725 Y_Motion = aReport.xmotion.y;
7fd59977 2726
18d715bd 2727 // remove all the ButtonMotionMaskr
2728 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
7fd59977 2729
18d715bd 2730 if ( aReport.xmotion.state & ControlMask ) {
2731 if ( aReport.xmotion.state & Button1Mask ) {
7fd59977 2732 ProcessControlButton1Motion();
2733 }
18d715bd 2734 else if ( aReport.xmotion.state & Button2Mask ) {
4fe56619 2735 VT_ProcessControlButton2Motion();
7fd59977 2736 }
18d715bd 2737 else if ( aReport.xmotion.state & Button3Mask ) {
4fe56619 2738 VT_ProcessControlButton3Motion();
7fd59977 2739 }
2740 }
4fe56619 2741 else
2742 {
2743 VT_ProcessMotion();
7fd59977 2744 }
2745 }
2746 }
2747 break;
2748}
7fd59977 2749return pick;
2750}
2751
2752//==============================================================================
2753//function : VProcessEvents
2754//purpose : call by Tk_CreateFileHandler() to be able to manage the
2755// event in the Viewer window
2756//==============================================================================
2757
2758static void VProcessEvents(ClientData,int)
2759{
18d715bd 2760 NCollection_Vector<int> anEventNumbers;
2761 // Get number of messages from every display
2762 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2763 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2764 {
2765 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
4269bd1b 2766 }
18d715bd 2767 // Handle events for every display
2768 int anEventIter = 0;
2769 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2770 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2771 {
4269bd1b 2772 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
18d715bd 2773 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2774 {
2775 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2776 int anEventResult = ViewerMainLoop( 0, NULL);
2777 // If window is closed or context was not found finish current event processing loop
2778 if (!anEventResult)
2779 return;
2780 }
7fd59977 2781 }
4269bd1b 2782
18d715bd 2783 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
4269bd1b 2784
7fd59977 2785}
2786#endif
2787
2788//==============================================================================
2789//function : OSWindowSetup
2790//purpose : Setup for the X11 window to be able to cath the event
2791//==============================================================================
2792
2793
2794static void OSWindowSetup()
2795{
4fe56619 2796#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2797 // X11
2798
2799 Window window = VT_GetWindow()->XWindow();
18d715bd 2800 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2801 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2802 XSynchronize(aDisplay, 1);
7fd59977 2803
2804 // X11 : For keyboard on SUN
2805 XWMHints wmhints;
2806 wmhints.flags = InputHint;
2807 wmhints.input = 1;
2808
18d715bd 2809 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 2810
18d715bd 2811 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
7fd59977 2812 ButtonPressMask | ButtonReleaseMask |
2813 StructureNotifyMask |
2814 PointerMotionMask |
2815 Button1MotionMask | Button2MotionMask |
18d715bd 2816 Button3MotionMask | FocusChangeMask
7fd59977 2817 );
18d715bd 2818 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2819 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 2820
18d715bd 2821 XSynchronize(aDisplay, 0);
7fd59977 2822
2823#else
57c28b61 2824 // _WIN32
7fd59977 2825#endif
2826
2827}
2828
7fd59977 2829//==============================================================================
2830//function : VFit
1beb58d7 2831//purpose :
7fd59977 2832//==============================================================================
2833
1beb58d7 2834static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
7fd59977 2835{
1beb58d7 2836 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2837 if (aView.IsNull())
b586500b 2838 {
1beb58d7 2839 std::cout << "Error: no active viewer!\n";
2840 return 1;
b586500b 2841 }
2842
1beb58d7 2843 Standard_Boolean toFit = Standard_True;
2844 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2845 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
b586500b 2846 {
1beb58d7 2847 TCollection_AsciiString anArg (theArgv[anArgIter]);
b586500b 2848 anArg.LowerCase();
1beb58d7 2849 if (anUpdateTool.parseRedrawMode (anArg))
b586500b 2850 {
1beb58d7 2851 continue;
2852 }
2853 else if (anArg == "-selected")
2854 {
2855 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2856 toFit = Standard_False;
2857 }
2858 else
2859 {
2860 std::cout << "Syntax error at '" << anArg << "'\n";
b586500b 2861 }
2862 }
2863
1beb58d7 2864 if (toFit)
2865 {
2866 aView->FitAll (0.01, Standard_False);
7fd59977 2867 }
2868 return 0;
2869}
2870
6262a303 2871//=======================================================================
2872//function : VFitArea
2873//purpose : Fit view to show area located between two points
2874// : given in world 2D or 3D coordinates.
2875//=======================================================================
2876static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2877{
2878 Handle(V3d_View) aView = ViewerTest::CurrentView();
2879 if (aView.IsNull())
2880 {
2881 std::cerr << theArgVec[0] << "Error: No active view.\n";
2882 return 1;
2883 }
2884
2885 // Parse arguments.
2886 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2887 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2888
2889 if (theArgNb == 5)
2890 {
2891 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2892 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2893 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2894 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2895 }
2896 else if (theArgNb == 7)
2897 {
2898 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2899 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2900 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2901 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2902 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2903 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2904 }
2905 else
2906 {
2907 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2908 theDI.PrintHelp(theArgVec[0]);
2909 return 1;
2910 }
2911
2912 // Convert model coordinates to view space
2913 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2914 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2915 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2916
2917 // Determine fit area
2918 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2919 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2920
2921 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2922
2923 if (aDiagonal < Precision::Confusion())
2924 {
2925 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2926 return 1;
2927 }
2928
2929 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2930 return 0;
2931}
2932
7fd59977 2933//==============================================================================
2934//function : VZFit
2935//purpose : ZFitall, no DRAW arguments
2936//Draw arg : No args
2937//==============================================================================
197ac94e 2938static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 2939{
197ac94e 2940 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2941
2942 if (aCurrentView.IsNull())
2943 {
2944 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2945 return 1;
2946 }
2947
2948 if (theArgsNb == 1)
2949 {
c357e426 2950 aCurrentView->ZFitAll();
197ac94e 2951 aCurrentView->Redraw();
2952 return 0;
2953 }
2954
2955 Standard_Real aScale = 1.0;
2956
2957 if (theArgsNb >= 2)
2958 {
2959 aScale = Draw::Atoi (theArgVec[1]);
2960 }
2961
c357e426 2962 aCurrentView->ZFitAll (aScale);
197ac94e 2963 aCurrentView->Redraw();
7fd59977 2964
197ac94e 2965 return 0;
2966}
7fd59977 2967
197ac94e 2968//==============================================================================
2969//function : VRepaint
2970//purpose :
2971//==============================================================================
56689b27 2972static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
7fd59977 2973{
56689b27 2974 Handle(V3d_View) aView = ViewerTest::CurrentView();
2975 if (aView.IsNull())
2976 {
2977 std::cout << "Error: no active viewer!\n";
2978 return 1;
2979 }
2980
2981 Standard_Boolean isImmediateUpdate = Standard_False;
2982 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2983 {
2984 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2985 anArg.LowerCase();
2986 if (anArg == "-immediate")
2987 {
2988 isImmediateUpdate = Standard_True;
2989 if (anArgIter + 1 < theArgNb
2990 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2991 {
2992 ++anArgIter;
2993 }
2994 }
2995 else
2996 {
2997 std::cout << "Syntax error at '" << anArg << "'\n";
2998 }
2999 }
3000
3001 if (isImmediateUpdate)
3002 {
3003 aView->RedrawImmediate();
3004 }
3005 else
3006 {
3007 aView->Redraw();
3008 }
3009 return 0;
7fd59977 3010}
3011
7fd59977 3012//==============================================================================
3013//function : VClear
3014//purpose : Remove all the object from the viewer
3015//Draw arg : No args
3016//==============================================================================
3017
3018static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3019{
3020 Handle(V3d_View) V = ViewerTest::CurrentView();
3021 if(!V.IsNull())
3022 ViewerTest::Clear();
3023 return 0;
3024}
3025
3026//==============================================================================
3027//function : VPick
3028//purpose :
3029//==============================================================================
3030
3031static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3032{ if (ViewerTest::CurrentView().IsNull() ) return 1;
3033
3034if ( argc < 4 ) {
586db386 3035 di << argv[0] << "Invalid number of arguments\n";
7fd59977 3036 return 1;
3037}
3038
3039while (ViewerMainLoop( argc, argv)) {
3040}
3041
3042return 0;
3043}
3044
7fd59977 3045//==============================================================================
3046//function : VSetBg
3047//purpose : Load image as background
3048//==============================================================================
3049
3050static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3051{
3052 if (argc < 2 || argc > 3)
3053 {
586db386 3054 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
3055 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
7fd59977 3056 return 1;
3057 }
3058
3059 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3060 if(AISContext.IsNull())
3061 {
3062 di << "use 'vinit' command before " << argv[0] << "\n";
3063 return 1;
3064 }
3065
3066 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
3067 if (argc == 3)
3068 {
3069 const char* szType = argv[2];
3070 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3071 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3072 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3073 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3074 else
3075 {
3076 di << "Wrong fill type : " << szType << "\n";
586db386 3077 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
7fd59977 3078 return 1;
3079 }
3080 }
3081
3082 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3083 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
3084
3085 return 0;
3086}
3087
f8b2ed36 3088//==============================================================================
3089//function : VSetBgMode
3090//purpose : Change background image fill type
3091//==============================================================================
3092
3093static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3094{
3095 if (argc != 2)
3096 {
586db386 3097 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
3098 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
f8b2ed36 3099 return 1;
3100 }
3101
3102 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3103 if(AISContext.IsNull())
3104 {
3105 di << "use 'vinit' command before " << argv[0] << "\n";
3106 return 1;
3107 }
1d47d8d0 3108 Aspect_FillMethod aFillType = Aspect_FM_NONE;
3109 const char* szType = argv[1];
3110 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3111 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3112 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3113 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3114 else
f8b2ed36 3115 {
1d47d8d0 3116 di << "Wrong fill type : " << szType << "\n";
586db386 3117 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
1d47d8d0 3118 return 1;
f8b2ed36 3119 }
f8b2ed36 3120 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3121 V3dView->SetBgImageStyle(aFillType, Standard_True);
f8b2ed36 3122 return 0;
3123}
3124
7fd59977 3125//==============================================================================
3126//function : VSetGradientBg
3127//purpose : Mount gradient background
3128//==============================================================================
3129static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3130{
3131 if (argc != 8 )
3132 {
586db386 3133 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
3134 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
3135 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3136 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
7fd59977 3137 return 1;
3138 }
3139
3140 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3141 if(AISContext.IsNull())
3142 {
3143 di << "use 'vinit' command before " << argv[0] << "\n";
3144 return 1;
3145 }
3146 if (argc == 8)
3147 {
3148
91322f44 3149 Standard_Real R1 = Draw::Atof(argv[1])/255.;
3150 Standard_Real G1 = Draw::Atof(argv[2])/255.;
3151 Standard_Real B1 = Draw::Atof(argv[3])/255.;
7fd59977 3152 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
3153
91322f44 3154 Standard_Real R2 = Draw::Atof(argv[4])/255.;
3155 Standard_Real G2 = Draw::Atof(argv[5])/255.;
3156 Standard_Real B2 = Draw::Atof(argv[6])/255.;
7fd59977 3157
3158 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
91322f44 3159 int aType = Draw::Atoi(argv[7]);
7fd59977 3160 if( aType < 0 || aType > 8 )
3161 {
586db386 3162 di << "Wrong fill type \n";
3163 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3164 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
7fd59977 3165 return 1;
3166 }
3167
3168 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3169
3170 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3171 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
3172 }
3173
3174 return 0;
3175}
3176
f8b2ed36 3177//==============================================================================
3178//function : VSetGradientBgMode
3179//purpose : Change gradient background fill style
3180//==============================================================================
3181static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3182{
3183 if (argc != 2 )
3184 {
586db386 3185 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
3186 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3187 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
f8b2ed36 3188 return 1;
3189 }
3190
3191 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3192 if(AISContext.IsNull())
3193 {
3194 di << "use 'vinit' command before " << argv[0] << "\n";
3195 return 1;
3196 }
3197 if (argc == 2)
3198 {
91322f44 3199 int aType = Draw::Atoi(argv[1]);
f8b2ed36 3200 if( aType < 0 || aType > 8 )
3201 {
586db386 3202 di << "Wrong fill type \n";
3203 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3204 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
f8b2ed36 3205 return 1;
3206 }
3207
3208 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3209
3210 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3211 V3dView->SetBgGradientStyle( aMethod, 1 );
3212 }
3213
3214 return 0;
3215}
3216
3217//==============================================================================
3218//function : VSetColorBg
3219//purpose : Set color background
3220//==============================================================================
3221static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3222{
3223 if (argc != 4 )
3224 {
586db386 3225 di << "Usage : " << argv[0] << " R G B : Set color background\n";
3226 di << "R,G,B = [0..255]\n";
f8b2ed36 3227 return 1;
3228 }
3229
3230 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3231 if(AISContext.IsNull())
3232 {
3233 di << "use 'vinit' command before " << argv[0] << "\n";
3234 return 1;
3235 }
3236 if (argc == 4)
3237 {
3238
91322f44 3239 Standard_Real R = Draw::Atof(argv[1])/255.;
3240 Standard_Real G = Draw::Atof(argv[2])/255.;
3241 Standard_Real B = Draw::Atof(argv[3])/255.;
f8b2ed36 3242 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
3243
3244 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3245 V3dView->SetBackgroundColor( aColor );
3246 V3dView->Update();
3247 }
3248
3249 return 0;
3250}
3251
f42753ed 3252//==============================================================================
3253//function : VSetDefaultBg
3254//purpose : Set default viewer background fill color
3255//==============================================================================
3256static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3257{
3258 if (theArgNb != 4
3259 && theArgNb != 8)
3260 {
3261 std::cout << "Error: wrong syntax! See usage:\n";
3262 theDI.PrintHelp (theArgVec[0]);
3263 return 1;
3264 }
3265
3266 ViewerTest_DefaultBackground.FillMethod =
3267 theArgNb == 4 ? Aspect_GFM_NONE
3268 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
3269
3270 if (theArgNb == 4)
3271 {
3272 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
3273 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
3274 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
3275 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
3276 }
3277 else
3278 {
3279 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
3280 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
3281 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
3282 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
3283
3284 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
3285 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
3286 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
3287 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
3288 }
3289
3290 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
3291 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
3292 {
3293 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
3294 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
3295 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
3296 ViewerTest_DefaultBackground.GradientColor2,
3297 ViewerTest_DefaultBackground.FillMethod);
3298 }
3299
3300 return 0;
3301}
3302
7fd59977 3303//==============================================================================
3304//function : VScale
3305//purpose : View Scaling
3306//==============================================================================
3307
3308static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3309{
3310 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3311 if ( V3dView.IsNull() ) return 1;
3312
3313 if ( argc != 4 ) {
586db386 3314 di << argv[0] << "Invalid number of arguments\n";
7fd59977 3315 return 1;
3316 }
91322f44 3317 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
7fd59977 3318 return 0;
3319}
3320//==============================================================================
536d98e2 3321//function : VZBuffTrihedron
3322//purpose :
7fd59977 3323//==============================================================================
3324
536d98e2 3325static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3326 Standard_Integer theArgNb,
3327 const char** theArgVec)
7fd59977 3328{
536d98e2 3329 Handle(V3d_View) aView = ViewerTest::CurrentView();
3330 if (aView.IsNull())
3331 {
3332 std::cout << "Error: no active viewer!\n";
3333 return 1;
3334 }
7fd59977 3335
536d98e2 3336 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7c8a8fcc 3337
536d98e2 3338 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3339 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3340 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3341 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3342 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3343 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3344 Standard_Real aScale = 0.1;
3345 Standard_Real aSizeRatio = 0.8;
3346 Standard_Real anArrowDiam = 0.05;
3347 Standard_Integer aNbFacets = 12;
3348 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7c8a8fcc 3349 {
536d98e2 3350 Standard_CString anArg = theArgVec[anArgIter];
3351 TCollection_AsciiString aFlag (anArg);
3352 aFlag.LowerCase();
3353 if (anUpdateTool.parseRedrawMode (aFlag))
7c8a8fcc 3354 {
536d98e2 3355 continue;
3356 }
3357 else if (aFlag == "-on")
7c8a8fcc 3358 {
536d98e2 3359 continue;
3360 }
3361 else if (aFlag == "-off")
7c8a8fcc 3362 {
536d98e2 3363 aView->TriedronErase();
3364 return 0;
3365 }
3366 else if (aFlag == "-pos"
3367 || aFlag == "-position"
3368 || aFlag == "-corner")
7c8a8fcc 3369 {
536d98e2 3370 if (++anArgIter >= theArgNb)
3371 {
3372 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3373 return 1;
3374 }
3375
3376 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3377 aPosName.LowerCase();
3378 if (aPosName == "center")
3379 {
3380 aPosition = Aspect_TOTP_CENTER;
3381 }
3382 else if (aPosName == "left_lower"
3383 || aPosName == "lower_left"
3384 || aPosName == "leftlower"
3385 || aPosName == "lowerleft")
3386 {
3387 aPosition = Aspect_TOTP_LEFT_LOWER;
3388 }
3389 else if (aPosName == "left_upper"
3390 || aPosName == "upper_left"
3391 || aPosName == "leftupper"
3392 || aPosName == "upperleft")
3393 {
3394 aPosition = Aspect_TOTP_LEFT_UPPER;
3395 }
3396 else if (aPosName == "right_lower"
3397 || aPosName == "lower_right"
3398 || aPosName == "rightlower"
3399 || aPosName == "lowerright")
3400 {
3401 aPosition = Aspect_TOTP_RIGHT_LOWER;
3402 }
3403 else if (aPosName == "right_upper"
3404 || aPosName == "upper_right"
3405 || aPosName == "rightupper"
3406 || aPosName == "upperright")
3407 {
3408 aPosition = Aspect_TOTP_RIGHT_UPPER;
3409 }
3410 else
3411 {
3412 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3413 return 1;
3414 }
3415 }
3416 else if (aFlag == "-type")
7c8a8fcc 3417 {
536d98e2 3418 if (++anArgIter >= theArgNb)
3419 {
3420 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3421 return 1;
3422 }
3423
3424 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3425 aTypeName.LowerCase();
3426 if (aTypeName == "wireframe"
3427 || aTypeName == "wire")
3428 {
3429 aVisType = V3d_WIREFRAME;
3430 }
3431 else if (aTypeName == "zbuffer"
3432 || aTypeName == "shaded")
3433 {
3434 aVisType = V3d_ZBUFFER;
3435 }
3436 else
3437 {
3438 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3439 }
3440 }
3441 else if (aFlag == "-scale")
7c8a8fcc 3442 {
536d98e2 3443 if (++anArgIter >= theArgNb)
3444 {
3445 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3446 return 1;
3447 }
3448
3449 aScale = Draw::Atof (theArgVec[anArgIter]);
7c8a8fcc 3450 }
536d98e2 3451 else if (aFlag == "-size"
3452 || aFlag == "-sizeratio")
3453 {
3454 if (++anArgIter >= theArgNb)
3455 {
3456 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3457 return 1;
3458 }
7c8a8fcc 3459
536d98e2 3460 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3461 }
3462 else if (aFlag == "-arrowdiam"
3463 || aFlag == "-arrowdiameter")
3464 {
3465 if (++anArgIter >= theArgNb)
3466 {
3467 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3468 return 1;
3469 }
7c8a8fcc 3470
536d98e2 3471 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3472 }
3473 else if (aFlag == "-nbfacets")
3474 {
3475 if (++anArgIter >= theArgNb)
3476 {
3477 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3478 return 1;
3479 }
7c8a8fcc 3480
536d98e2 3481 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3482 }
3483 else if (aFlag == "-colorlabel"
3484 || aFlag == "-colorlabels")
7c8a8fcc 3485 {
536d98e2 3486 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3487 theArgVec + anArgIter + 1,
3488 aLabelsColor);
3489 if (aNbParsed == 0)
3490 {
3491 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3492 return 1;
3493 }
3494 anArgIter += aNbParsed;
7c8a8fcc 3495 }
536d98e2 3496 else if (aFlag == "-colorarrowx")
7c8a8fcc 3497 {
536d98e2 3498 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3499 theArgVec + anArgIter + 1,
3500 anArrowColorX);
3501 if (aNbParsed == 0)
3502 {
3503 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3504 return 1;
3505 }
3506 anArgIter += aNbParsed;
3507 }
3508 else if (aFlag == "-colorarrowy")
7c8a8fcc 3509 {
536d98e2 3510 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3511 theArgVec + anArgIter + 1,
3512 anArrowColorY);
3513 if (aNbParsed == 0)
3514 {
3515 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3516 return 1;
3517 }
3518 anArgIter += aNbParsed;
3519 }
3520 else if (aFlag == "-colorarrowz")
7c8a8fcc 3521 {
536d98e2 3522 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3523 theArgVec + anArgIter + 1,
3524 anArrowColorZ);
3525 if (aNbParsed == 0)
3526 {
3527 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3528 return 1;
3529 }
3530 anArgIter += aNbParsed;
3531 }
3532 else
3533 {
3534 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
7c8a8fcc 3535 return 1;
3536 }
7c8a8fcc 3537 }
3538
536d98e2 3539 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3540 aSizeRatio, anArrowDiam, aNbFacets);
3541 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
c357e426 3542 aView->ZFitAll();
7fd59977 3543 return 0;
3544}
3545
3546//==============================================================================
3547//function : VRotate
3548//purpose : Camera Rotating
3549//==============================================================================
3550
4af098ba 3551static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3552{
3553 Handle(V3d_View) aView = ViewerTest::CurrentView();
3554 if (aView.IsNull())
3555 {
3556 std::cout << "No active view!\n";
7fd59977 3557 return 1;
3558 }
3559
4af098ba 3560 Standard_Boolean hasFlags = Standard_False;
3561 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3562 {
3563 Standard_CString anArg (theArgVec[anArgIter]);
3564 TCollection_AsciiString aFlag (anArg);
3565 aFlag.LowerCase();
3566 if (aFlag == "-mousestart"
3567 || aFlag == "-mousefrom")
3568 {
3569 hasFlags = Standard_True;
3570 if (anArgIter + 2 >= theArgNb)
3571 {
3572 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3573 return 1;
3574 }
3575
3576 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3577 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3578 aView->StartRotation (anX, anY);
3579 }
3580 else if (aFlag == "-mousemove")
3581 {
3582 hasFlags = Standard_True;
3583 if (anArgIter + 2 >= theArgNb)
3584 {
3585 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3586 return 1;
3587 }
3588
3589 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3590 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3591 aView->Rotation (anX, anY);
3592 }
3593 else if (theArgNb != 4
3594 && theArgNb != 7)
3595 {
3596 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3597 return 1;
3598 }
3599 }
3600
3601 if (hasFlags)
3602 {
7fd59977 3603 return 0;
4af098ba 3604 }
3605 else if (theArgNb == 4)
3606 {
3607 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3608 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3609 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3610 aView->Rotate (anAX, anAY, anAZ);
3611 return 0;
3612 }
3613 else if (theArgNb == 7)
3614 {
3615 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3616 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3617 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3618
3619 Standard_Real anX = Draw::Atof (theArgVec[4]);
3620 Standard_Real anY = Draw::Atof (theArgVec[5]);
3621 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3622
3623 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
7fd59977 3624 return 0;
7fd59977 3625 }
4af098ba 3626
3627 std::cout << "Error: Invalid number of arguments\n";
3628 return 1;
7fd59977 3629}
3630
3631//==============================================================================
3632//function : VZoom
3633//purpose : View zoom in / out (relative to current zoom)
3634//==============================================================================
3635
3636static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3637 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3638 if ( V3dView.IsNull() ) {
3639 return 1;
3640 }
3641
3642 if ( argc == 2 ) {
91322f44 3643 Standard_Real coef = Draw::Atof(argv[1]);
7fd59977 3644 if ( coef <= 0.0 ) {
586db386 3645 di << argv[1] << "Invalid value\n";
7fd59977 3646 return 1;
3647 }
91322f44 3648 V3dView->SetZoom( Draw::Atof(argv[1]) );
7fd59977 3649 return 0;
3650 } else {
586db386 3651 di << argv[0] << " Invalid number of arguments\n";
7fd59977 3652 return 1;
3653 }
3654}
3655
3656//==============================================================================
3657//function : VPan
3658//purpose : View panning (in pixels)
3659//==============================================================================
3660
3661static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3662 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3663 if ( V3dView.IsNull() ) return 1;
3664
3665 if ( argc == 3 ) {
91322f44 3666 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
7fd59977 3667 return 0;
3668 } else {
586db386 3669 di << argv[0] << " Invalid number of arguments\n";
7fd59977 3670 return 1;
3671 }
3672}
3673
49e1a5c7 3674//==============================================================================
3675//function : VPlace
3676//purpose : Place the point (in pixels) at the center of the window
3677//==============================================================================
3678static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3679{
3680 Handle(V3d_View) aView = ViewerTest::CurrentView();
3681 if (aView.IsNull())
3682 {
3683 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3684 return 1;
3685 }
3686
3687 if (theArgNb != 3)
3688 {
3689 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3690 return 1;
3691 }
3692
3693 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3694
3695 return 0;
3696}
7fd59977 3697
71215351 3698static int VColorScale (Draw_Interpretor& theDI,
3699 Standard_Integer theArgNb,
3700 const char** theArgVec)
3701{
7fd59977 3702 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
71215351 3703 Handle(V3d_View) aView = ViewerTest::CurrentView();
3704 if (aContext.IsNull())
3705 {
3706 std::cout << "Error: no active view!\n";
3707 return 1;
7fd59977 3708 }
24a88697 3709 if (theArgNb <= 1)
3710 {
3711 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3712 return 1;
3713 }
7fd59977 3714
4b3d6eb1 3715 Handle(AIS_ColorScale) aColorScale;
7a324550 3716 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
71215351 3717 {
4b3d6eb1 3718 // find existing object
3719 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3720 if (aColorScale.IsNull())
7a324550 3721 {
3722 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3723 return 1;
3724 }
3725 }
71215351 3726
7a324550 3727 if (theArgNb <= 2)
3728 {
4b3d6eb1 3729 if (aColorScale.IsNull())
3730 {
3731 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
3732 return 1;
3733 }
3734
7a324550 3735 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
4b3d6eb1 3736 << "Min range: " << aColorScale->GetMin() << "\n"
3737 << "Max range: " << aColorScale->GetMax() << "\n"
3738 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
3739 << "Text height: " << aColorScale->GetTextHeight() << "\n"
3740 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
3741 << "Color scale title: " << aColorScale->GetTitle() << "\n"
71215351 3742 << "Label position: ";
4b3d6eb1 3743 switch (aColorScale->GetLabelPosition())
71215351 3744 {
3745 case Aspect_TOCSP_NONE:
3746 theDI << "None\n";
3747 break;
3748 case Aspect_TOCSP_LEFT:
3749 theDI << "Left\n";
3750 break;
3751 case Aspect_TOCSP_RIGHT:
3752 theDI << "Right\n";
3753 break;
3754 case Aspect_TOCSP_CENTER:
3755 theDI << "Center\n";
3756 break;
3757 }
3758 return 0;
3759 }
71215351 3760
4b3d6eb1 3761 if (aColorScale.IsNull())
3762 {
3763 aColorScale = new AIS_ColorScale();
3764 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3765 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3766 }
3767
3768 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
7a324550 3769 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
71215351 3770 {
3771 Standard_CString anArg = theArgVec[anArgIter];
3772 TCollection_AsciiString aFlag (anArg);
3773 aFlag.LowerCase();
3774 if (anUpdateTool.parseRedrawMode (aFlag))
3775 {
3776 continue;
3777 }
3778 else if (aFlag == "-range")
3779 {
3780 if (anArgIter + 3 >= theArgNb)
3781 {
3782 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3783 return 1;
3784 }
3785
4b3d6eb1 3786 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
3787 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
3788 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
3789 if (!aRangeMin.IsRealValue()
3790 || !aRangeMax.IsRealValue())
71215351 3791 {
4b3d6eb1 3792 std::cout << "Error: the range values should be real!\n";
71215351 3793 return 1;
3794 }
4b3d6eb1 3795 else if (!aNbIntervals.IsIntegerValue())
71215351 3796 {
3797 std::cout << "Error: the number of intervals should be integer!\n";
3798 return 1;
3799 }
3800
4b3d6eb1 3801 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
3802 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
71215351 3803 }
3804 else if (aFlag == "-font")
3805 {
3806 if (anArgIter + 1 >= theArgNb)
3807 {
3808 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3809 return 1;
3810 }
51740958 3811 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3812 if (!aFontArg.IsIntegerValue())
71215351 3813 {
3814 std::cout << "Error: HeightFont value should be integer!\n";
3815 return 1;
3816 }
3817
4b3d6eb1 3818 aColorScale->SetTextHeight (aFontArg.IntegerValue());
71215351 3819 anArgIter += 1;
3820 }
3821 else if (aFlag == "-textpos")
3822 {
3823 if (anArgIter + 1 >= theArgNb)
3824 {
3825 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3826 return 1;
3827 }
4b3d6eb1 3828
51740958 3829 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3830 aTextPosArg.LowerCase();
4b3d6eb1 3831 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
51740958 3832 if (aTextPosArg == "none")
71215351 3833 {
3834 aLabPosition = Aspect_TOCSP_NONE;
3835 }
51740958 3836 else if (aTextPosArg == "left")
71215351 3837 {
3838 aLabPosition = Aspect_TOCSP_LEFT;
3839 }
51740958 3840 else if (aTextPosArg == "right")
71215351 3841 {
3842 aLabPosition = Aspect_TOCSP_RIGHT;
3843 }
51740958 3844 else if (aTextPosArg == "center")
71215351 3845 {
3846 aLabPosition = Aspect_TOCSP_CENTER;
3847 }
3848 else
3849 {
51740958 3850 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
71215351 3851 return 1;
3852 }
4b3d6eb1 3853 aColorScale->SetLabelPosition (aLabPosition);
71215351 3854 }
24a88697 3855 else if (aFlag == "-logarithmic"
3856 || aFlag == "-log")
3857 {
3858 if (anArgIter + 1 >= theArgNb)
3859 {
3860 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3861 return 1;
3862 }
4b3d6eb1 3863
24a88697 3864 Standard_Boolean IsLog;
3865 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3866 {
3867 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3868 return 1;
3869 }
4b3d6eb1 3870 aColorScale->SetLogarithmic (IsLog);
3871 }
3872 else if (aFlag == "-huerange"
3873 || aFlag == "-hue")
3874 {
3875 if (anArgIter + 2 >= theArgNb)
3876 {
3877 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3878 return 1;
3879 }
3880
3881 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
3882 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
3883 aColorScale->SetHueRange (aHueMin, aHueMax);
3884 }
3885 else if (aFlag == "-colorrange")
3886 {
3887 Quantity_Color aColorMin, aColorMax;
3888 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3889 theArgVec + (anArgIter + 1),
3890 aColorMin);
3891 anArgIter += aNbParsed1;
3892 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3893 theArgVec + (anArgIter + 1),
3894 aColorMax);
3895 anArgIter += aNbParsed2;
3896 if (aNbParsed1 == 0
3897 || aNbParsed2 == 0)
3898 {
3899 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3900 return 1;
3901 }
3902
3903 aColorScale->SetColorRange (aColorMin, aColorMax);
3904 }
3905 else if (aFlag == "-reversed"
3906 || aFlag == "-inverted"
3907 || aFlag == "-topdown"
3908 || aFlag == "-bottomup")
3909 {
3910 Standard_Boolean toEnable = Standard_True;
3911 if (anArgIter + 1 < theArgNb
3912 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
3913 {
3914 ++anArgIter;
3915 }
3916 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
3917 }
3918 else if (aFlag == "-smooth"
3919 || aFlag == "-smoothtransition")
3920 {
3921 Standard_Boolean toEnable = Standard_True;
3922 if (anArgIter + 1 < theArgNb
3923 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3924 {
3925 ++anArgIter;
3926 }
3927 aColorScale->SetSmoothTransition (toEnable);
24a88697 3928 }
71215351 3929 else if (aFlag == "-xy")
3930 {
3931 if (anArgIter + 2 >= theArgNb)
3932 {
3933 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3934 return 1;
3935 }
3936
4b3d6eb1 3937 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
3938 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
3939 if (!anX.IsIntegerValue()
3940 || !anY.IsIntegerValue())
71215351 3941 {
b4b2ecca 3942 std::cout << "Error: coordinates should be integer values!\n";
71215351 3943 return 1;
3944 }
3945
4b3d6eb1 3946 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
b4b2ecca 3947 }
3948 else if (aFlag == "-width"
4b3d6eb1 3949 || aFlag == "-w"
3950 || aFlag == "-breadth")
b4b2ecca 3951 {
3952 if (anArgIter + 1 >= theArgNb)
3953 {
3954 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3955 return 1;
3956 }
3957
4b3d6eb1 3958 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
3959 if (!aBreadth.IsIntegerValue())
b4b2ecca 3960 {
3961 std::cout << "Error: a width should be an integer value!\n";
3962 return 1;
3963 }
4b3d6eb1 3964 aColorScale->SetBreadth (aBreadth.IntegerValue());
b4b2ecca 3965 }
3966 else if (aFlag == "-height"
3967 || aFlag == "-h")
3968 {
3969 if (anArgIter + 1 >= theArgNb)
3970 {
3971 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3972 return 1;
3973 }
3974
4b3d6eb1 3975 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
3976 if (!aHeight.IsIntegerValue())
b4b2ecca 3977 {
3978 std::cout << "Error: a width should be an integer value!\n";
3979 return 1;
3980 }
4b3d6eb1 3981 aColorScale->SetHeight (aHeight.IntegerValue());
71215351 3982 }
3983 else if (aFlag == "-color")
3984 {
4b3d6eb1 3985 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
71215351 3986 {
3987 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3988 return 1;
3989 }
4b3d6eb1 3990 else if (anArgIter + 2 >= theArgNb)
71215351 3991 {
4b3d6eb1 3992 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3993 return 1;
71215351 3994 }
3995
4b3d6eb1 3996 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
71215351 3997 if (!anInd.IsIntegerValue())
3998 {
3999 std::cout << "Error: Index value should be integer!\n";
4000 return 1;
4001 }
4b3d6eb1 4002 const Standard_Integer anIndex = anInd.IntegerValue();
4003 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
71215351 4004 {
4b3d6eb1 4005 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
71215351 4006 return 1;
4007 }
4008
4b3d6eb1 4009 Quantity_Color aColor;
4010 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4011 theArgVec + (anArgIter + 1),
4012 aColor);
4013 if (aNbParsed == 0)
71215351 4014 {
4b3d6eb1 4015 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
71215351 4016 return 1;
4017 }
4b3d6eb1 4018 aColorScale->SetIntervalColor (aColor, anIndex);
4019 aColorScale->SetColorType (Aspect_TOCSD_USER);
4020 anArgIter += aNbParsed;
71215351 4021 }
4022 else if (aFlag == "-label")
4023 {
4b3d6eb1 4024 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
71215351 4025 {
4026 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
4027 return 1;
4028 }
4029 else if (anArgIter + 2 >= theArgNb)
4030 {
4031 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4032 return 1;
4033 }
4034
4035 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4b3d6eb1 4036 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
71215351 4037 {
4b3d6eb1 4038 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
71215351 4039 return 1;
4040 }
4041
4042 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4b3d6eb1 4043 aColorScale->SetLabel (aText, anIndex);
4044 aColorScale->SetLabelType (Aspect_TOCSD_USER);
71215351 4045 anArgIter += 2;
4046 }
4b3d6eb1 4047 else if (aFlag == "-labelat"
4048 || aFlag == "-labat"
4049 || aFlag == "-labelatborder"
4050 || aFlag == "-labatborder"
4051 || aFlag == "-labelatcenter"
4052 || aFlag == "-labatcenter")
71215351 4053 {
4b3d6eb1 4054 Standard_Boolean toEnable = Standard_True;
4055 if (aFlag == "-labelat"
4056 || aFlag == "-labat")
71215351 4057 {
4b3d6eb1 4058 Standard_Integer aLabAtBorder = -1;
4059 if (++anArgIter >= theArgNb)
71215351 4060 {
4b3d6eb1 4061 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4062 anAtBorder.LowerCase();
4063 if (anAtBorder == "border")
71215351 4064 {
4b3d6eb1 4065 aLabAtBorder = 1;
71215351 4066 }
4b3d6eb1 4067 else if (anAtBorder == "center")
71215351 4068 {
4b3d6eb1 4069 aLabAtBorder = 0;
71215351 4070 }
71215351 4071 }
4b3d6eb1 4072 if (aLabAtBorder == -1)
4073 {
4074 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4075 return 1;
4076 }
4077 toEnable = (aLabAtBorder == 1);
4078 }
4079 else if (anArgIter + 1 < theArgNb
4080 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4081 {
4082 ++anArgIter;
71215351 4083 }
4b3d6eb1 4084 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4085 || aFlag == "-labatcenter"
4086 ? !toEnable
4087 : toEnable);
4088 }
4089 else if (aFlag == "-colors")
4090 {
4091 Aspect_SequenceOfColor aSeq;
4092 for (;;)
4093 {
4094 Quantity_Color aColor;
4095 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4096 theArgVec + (anArgIter + 1),
4097 aColor);
4098 if (aNbParsed == 0)
4099 {
4100 break;
4101 }
4102 anArgIter += aNbParsed;
4103 aSeq.Append (aColor);
4104 }
4105 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
71215351 4106 {
4107 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4b3d6eb1 4108 << aColorScale->GetNumberOfIntervals() << " intervals\n";
71215351 4109 return 1;
4110 }
4111
4b3d6eb1 4112 aColorScale->SetColors (aSeq);
4113 aColorScale->SetColorType (Aspect_TOCSD_USER);
71215351 4114 }
4b3d6eb1 4115 else if (aFlag == "-labels"
4116 || aFlag == "-freelabels")
71215351 4117 {
4b3d6eb1 4118 if (anArgIter + 1 >= theArgNb)
4119 {
4120 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4121 return 1;
4122 }
4123
4124 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4125 ? aColorScale->GetNumberOfIntervals() + 1
4126 : aColorScale->GetNumberOfIntervals();
4127 if (aFlag == "-freelabels")
4128 {
4129 ++anArgIter;
4130 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4131 }
4132 if (anArgIter + aNbLabels >= theArgNb)
71215351 4133 {
4b3d6eb1 4134 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
71215351 4135 return 1;
4136 }
4137
4138 TColStd_SequenceOfExtendedString aSeq;
4b3d6eb1 4139 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
71215351 4140 {
4b3d6eb1 4141 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
71215351 4142 }
4b3d6eb1 4143 aColorScale->SetLabels (aSeq);
4144 aColorScale->SetLabelType (Aspect_TOCSD_USER);
71215351 4145 }
4146 else if (aFlag == "-title")
4147 {
4148 if (anArgIter + 1 >= theArgNb)
4149 {
4150 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4151 return 1;
4152 }
4153
4154 Standard_Boolean isTwoArgs = Standard_False;
4155 if (anArgIter + 2 < theArgNb)
4156 {
4157 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4158 aSecondArg.LowerCase();
4b3d6eb1 4159 Standard_DISABLE_DEPRECATION_WARNINGS
71215351 4160 if (aSecondArg == "none")
4161 {
4b3d6eb1 4162 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
71215351 4163 isTwoArgs = Standard_True;
4164 }
4165 else if (aSecondArg == "left")
4166 {
4b3d6eb1 4167 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
71215351 4168 isTwoArgs = Standard_True;
4169 }
4170 else if (aSecondArg == "right")
4171 {
4b3d6eb1 4172 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
71215351 4173 isTwoArgs = Standard_True;
4174 }
4175 else if (aSecondArg == "center")
4176 {
4b3d6eb1 4177 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
71215351 4178 isTwoArgs = Standard_True;
4179 }
4b3d6eb1 4180 Standard_ENABLE_DEPRECATION_WARNINGS
71215351 4181 }
4182
4b3d6eb1 4183 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
71215351 4184 if (isTwoArgs)
4185 {
4186 anArgIter += 1;
4187 }
4188 anArgIter += 1;
4189 }
4190 else if (aFlag == "-demoversion"
4191 || aFlag == "-demo")
4192 {
4b3d6eb1 4193 aColorScale->SetPosition (0, 0);
4194 aColorScale->SetTextHeight (16);
4195 aColorScale->SetRange (0.0, 100.0);
4196 aColorScale->SetNumberOfIntervals (10);
4197 aColorScale->SetBreadth (0);
4198 aColorScale->SetHeight (0);
4199 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4200 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4201 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
71215351 4202 }
d5514578 4203 else if (aFlag == "-findcolor")
4204 {
4205 if (anArgIter + 1 >= theArgNb)
4206 {
4207 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4208 return 1;
4209 }
4210
4211 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4212
4213 if (!anArg1.IsRealValue())
4214 {
4215 std::cout << "Error: the value should be real!\n";
4216 return 1;
4217 }
4218
4219 Quantity_Color aColor;
4b3d6eb1 4220 aColorScale->FindColor (anArg1.RealValue(), aColor);
d5514578 4221 theDI << Quantity_Color::StringName (aColor.Name());
4222 return 0;
4223 }
71215351 4224 else
4225 {
4226 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4227 return 1;
4228 }
4229 }
4b3d6eb1 4230
4231 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4232 aView->Window()->Size (aWinWidth, aWinHeight);
4233 if (aColorScale->GetBreadth() == 0)
b4b2ecca 4234 {
4b3d6eb1 4235 aColorScale->SetBreadth (aWinWidth);
b4b2ecca 4236 }
4b3d6eb1 4237 if (aColorScale->GetHeight() == 0)
4238 {
4239 aColorScale->SetHeight (aWinHeight);
4240 }
4241 aColorScale->SetToUpdate();
4242 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
7fd59977 4243 return 0;
4244}
4245
4246//==============================================================================
4247//function : VGraduatedTrihedron
a79f67f8 4248//purpose : Displays or hides a graduated trihedron
7fd59977 4249//==============================================================================
a79f67f8 4250static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4251 Quantity_Color& theColor)
13a22457 4252{
a79f67f8 4253 Quantity_NameOfColor aColorName;
4254 TCollection_AsciiString aVal = theValue;
4255 aVal.UpperCase();
4256 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
13a22457 4257 {
a79f67f8 4258 return Standard_False;
13a22457 4259 }
a79f67f8 4260 theColor = Quantity_Color (aColorName);
4261 return Standard_True;
13a22457
S
4262}
4263
a79f67f8 4264static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
7fd59977 4265{
a79f67f8 4266 if (theArgNum < 2)
13a22457 4267 {
a79f67f8 4268 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4269 << theArgs[0] <<"' for more information.\n";
4270 return 1; //TCL_ERROR
13a22457 4271 }
7fd59977 4272
a79f67f8 4273 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4274 TCollection_AsciiString aParseKey;
4275 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4276 {
4277 TCollection_AsciiString anArg (theArgs [anArgIt]);
4278
4279 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4280 {
4281 aParseKey = anArg;
4282 aParseKey.Remove (1);
4283 aParseKey.LowerCase();
4284 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4285 continue;
4286 }
13a22457 4287
a79f67f8 4288 if (aParseKey.IsEmpty())
4289 {
4290 continue;
4291 }
4292
4293 aMapOfArgs(aParseKey)->Append (anArg);
4294 }
4295
4296 // Check parameters
4297 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4298 aMapIt.More(); aMapIt.Next())
7fd59977 4299 {
a79f67f8 4300 const TCollection_AsciiString& aKey = aMapIt.Key();
4301 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4302
4303 // Bool key, without arguments
4304 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4305 && anArgs->IsEmpty())
4306 {
4307 continue;
4308 }
4309
4310 // One argument
4311 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4312 && anArgs->Length() == 1)
4313 {
4314 continue;
4315 }
4316
4317 // On/off arguments
4318 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4319 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
536d98e2 4320 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4321 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
a79f67f8 4322 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4323 {
4324 continue;
4325 }
4326
4327 // One string argument
4328 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4329 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4330 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4331 {
4332 continue;
4333 }
4334
4335 // One integer argument
4336 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4337 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4338 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4339 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4340 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4341 {
4342 continue;
4343 }
4344
4345 // One real argument
4346 if ( aKey.IsEqual ("arrowlength")
4347 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4348 {
4349 continue;
4350 }
4351
4352 // Two string arguments
4353 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4354 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
13a22457 4355 {
a79f67f8 4356 continue;
13a22457 4357 }
a79f67f8 4358
4359 TCollection_AsciiString aLowerKey;
4360 aLowerKey = "-";
4361 aLowerKey += aKey;
4362 aLowerKey.LowerCase();
4363 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4364 std::cout << "Type help for more information.\n";
4365 return 1;
7fd59977 4366 }
4367
a79f67f8 4368 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4369 if (anAISContext.IsNull())
4370 {
586db386 4371 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
a79f67f8 4372 return 1;
4373 }
7fd59977 4374
a79f67f8 4375 Standard_Boolean toDisplay = Standard_True;
4376 Quantity_Color aColor;
4377 Graphic3d_GraduatedTrihedron aTrihedronData;
4378 // Process parameters
4379 Handle(TColStd_HSequenceOfAsciiString) aValues;
4380 if (aMapOfArgs.Find ("off", aValues))
7fd59977 4381 {
a79f67f8 4382 toDisplay = Standard_False;
4383 }
13a22457 4384
a79f67f8 4385 // AXES NAMES
4386 if (aMapOfArgs.Find ("xname", aValues))
4387 {
4388 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4389 }
4390 if (aMapOfArgs.Find ("yname", aValues))
4391 {
4392 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4393 }
4394 if (aMapOfArgs.Find ("zname", aValues))
4395 {
4396 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4397 }
4398 if (aMapOfArgs.Find ("xdrawname", aValues))
4399 {
536d98e2 4400 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4401 }
4402 if (aMapOfArgs.Find ("ydrawname", aValues))
4403 {
536d98e2 4404 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4405 }
4406 if (aMapOfArgs.Find ("zdrawname", aValues))
4407 {
536d98e2 4408 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4409 }
4410 if (aMapOfArgs.Find ("xnameoffset", aValues))
4411 {
4412 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4413 }
4414 if (aMapOfArgs.Find ("ynameoffset", aValues))
4415 {
4416 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4417 }
4418 if (aMapOfArgs.Find ("znameoffset", aValues))
4419 {
4420 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4421 }
13a22457 4422
a79f67f8 4423 // COLORS
4424 if (aMapOfArgs.Find ("xnamecolor", aValues))
4425 {
4426 if (!GetColor (aValues->Value(1), aColor))
13a22457 4427 {
a79f67f8 4428 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4429 return 1;
13a22457 4430 }
a79f67f8 4431 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4432 }
4433 if (aMapOfArgs.Find ("ynamecolor", aValues))
4434 {
4435 if (!GetColor (aValues->Value(1), aColor))
13a22457 4436 {
a79f67f8 4437 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4438 return 1;
4439 }
4440 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4441 }
4442 if (aMapOfArgs.Find ("znamecolor", aValues))
4443 {
4444 if (!GetColor (aValues->Value(1), aColor))
4445 {
4446 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4447 return 1;
4448 }
4449 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4450 }
4451 if (aMapOfArgs.Find ("xcolor", aValues))
4452 {
4453 if (!GetColor (aValues->Value(1), aColor))
4454 {
4455 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4456 return 1;
4457 }
4458 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4459 }
4460 if (aMapOfArgs.Find ("ycolor", aValues))
4461 {
4462 if (!GetColor (aValues->Value(1), aColor))
4463 {
4464 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4465 return 1;
4466 }
4467 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4468 }
4469 if (aMapOfArgs.Find ("zcolor", aValues))
4470 {
4471 if (!GetColor (aValues->Value(1), aColor))
4472 {
4473 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4474 return 1;
4475 }
4476 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4477 }
4478
4479 // TICKMARKS
4480 if (aMapOfArgs.Find ("xticks", aValues))
4481 {
536d98e2 4482 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4483 }
4484 if (aMapOfArgs.Find ("yticks", aValues))
4485 {
536d98e2 4486 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4487 }
4488 if (aMapOfArgs.Find ("zticks", aValues))
4489 {
536d98e2 4490 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4491 }
4492 if (aMapOfArgs.Find ("xticklength", aValues))
4493 {
536d98e2 4494 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4495 }
4496 if (aMapOfArgs.Find ("yticklength", aValues))
4497 {
536d98e2 4498 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4499 }
4500 if (aMapOfArgs.Find ("zticklength", aValues))
4501 {
536d98e2 4502 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4503 }
4504 if (aMapOfArgs.Find ("xdrawticks", aValues))
4505 {
536d98e2 4506 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4507 }
4508 if (aMapOfArgs.Find ("ydrawticks", aValues))
4509 {
536d98e2 4510 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4511 }
4512 if (aMapOfArgs.Find ("zdrawticks", aValues))
4513 {
536d98e2 4514 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4515 }
4516
4517 // VALUES
4518 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4519 {
536d98e2 4520 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4521 }
4522 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4523 {
536d98e2 4524 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4525 }
4526 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4527 {
536d98e2 4528 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4529 }
4530 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4531 {
4532 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4533 }
4534 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4535 {
4536 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4537 }
4538 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4539 {
4540 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4541 }
4542
4543 // ARROWS
4544 if (aMapOfArgs.Find ("arrowlength", aValues))
4545 {
536d98e2 4546 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
a79f67f8 4547 }
4548
4549 // FONTS
4550 if (aMapOfArgs.Find ("namefont", aValues))
4551 {
4552 aTrihedronData.SetNamesFont (aValues->Value(1));
4553 }
4554 if (aMapOfArgs.Find ("valuesfont", aValues))
4555 {
4556 aTrihedronData.SetValuesFont (aValues->Value(1));
4557 }
4558
536d98e2 4559 if (aMapOfArgs.Find ("drawgrid", aValues))
4560 {
4561 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4562 }
4563 if (aMapOfArgs.Find ("drawaxes", aValues))
4564 {
4565 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4566 }
4567
a79f67f8 4568 // The final step: display of erase trihedron
4569 if (toDisplay)
4570 {
4571 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
13a22457 4572 }
7fd59977 4573 else
a79f67f8 4574 {
4575 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4576 }
7fd59977 4577
4578 ViewerTest::GetAISContext()->UpdateCurrentViewer();
a79f67f8 4579 ViewerTest::CurrentView()->Redraw();
13a22457 4580
7fd59977 4581 return 0;
4582}
4583
3bffef55 4584//==============================================================================
4585//function : VTile
4586//purpose :
4587//==============================================================================
4588static int VTile (Draw_Interpretor& theDI,
4589 Standard_Integer theArgNb,
4590 const char** theArgVec)
4591{
4592 Handle(V3d_View) aView = ViewerTest::CurrentView();
4593 if (aView.IsNull())
4594 {
4595 std::cerr << "Error: no active viewer.\n";
4596 return 1;
4597 }
4598
4599 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4600 if (theArgNb < 2)
4601 {
4602 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4603 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4604 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4605 return 0;
4606 }
4607
4608 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4609 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4610 {
4611 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4612 anArg.LowerCase();
4613 if (anArg == "-lowerleft"
4614 || anArg == "-upperleft")
4615 {
4616 if (anArgIter + 3 < theArgNb)
4617 {
4618 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4619 return 1;
4620 }
4621 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4622 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4623 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4624 }
4625 else if (anArg == "-total"
4626 || anArg == "-totalsize"
4627 || anArg == "-viewsize")
4628 {
4629 if (anArgIter + 3 < theArgNb)
4630 {
4631 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4632 return 1;
4633 }
4634 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4635 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4636 if (aTile.TotalSize.x() < 1
4637 || aTile.TotalSize.y() < 1)
4638 {
4639 std::cerr << "Error: total size is incorrect.\n";
4640 return 1;
4641 }
4642 }
4643 else if (anArg == "-tilesize")
4644 {
4645 if (anArgIter + 3 < theArgNb)
4646 {
4647 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4648 return 1;
4649 }
4650
4651 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4652 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4653 if (aTile.TileSize.x() < 1
4654 || aTile.TileSize.y() < 1)
4655 {
4656 std::cerr << "Error: tile size is incorrect.\n";
4657 return 1;
4658 }
4659 }
4660 else if (anArg == "-unset")
4661 {
4662 aView->Camera()->SetTile (Graphic3d_CameraTile());
4663 aView->Redraw();
4664 return 0;
4665 }
4666 }
4667
4668 if (aTile.TileSize.x() < 1
4669 || aTile.TileSize.y() < 1)
4670 {
4671 std::cerr << "Error: tile size is undefined.\n";
4672 return 1;
4673 }
4674 else if (aTile.TotalSize.x() < 1
4675 || aTile.TotalSize.y() < 1)
4676 {
4677 std::cerr << "Error: total size is undefined.\n";
4678 return 1;
4679 }
4680
4681 aView->Camera()->SetTile (aTile);
4682 aView->Redraw();
4683 return 0;
4684}
4685
7c3ef2f7 4686//! Format ZLayer ID.
4687inline const char* formZLayerId (const Standard_Integer theLayerId)
4688{
4689 switch (theLayerId)
4690 {
4691 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4692 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4693 case Graphic3d_ZLayerId_Top: return "[TOP]";
4694 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4695 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4696 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4697 }
4698 return "";
4699}
4700
4701//! Print the ZLayer information.
4702inline void printZLayerInfo (Draw_Interpretor& theDI,
4703 const Graphic3d_ZLayerSettings& theLayer)
4704{
4705 if (!theLayer.Name().IsEmpty())
4706 {
4707 theDI << " Name: " << theLayer.Name() << "\n";
4708 }
4709 if (theLayer.IsImmediate())
4710 {
4711 theDI << " Immediate: TRUE\n";
4712 }
4713 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4ecf34cc 4714 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
4715 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
7c3ef2f7 4716 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4717 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4718 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4719 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4720 {
4721 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4722 }
4723}
4724
59f45b7c 4725//==============================================================================
4726//function : VZLayer
4727//purpose : Test z layer operations for v3d viewer
4728//==============================================================================
7c3ef2f7 4729static int VZLayer (Draw_Interpretor& theDI,
4730 Standard_Integer theArgNb,
4731 const char** theArgVec)
59f45b7c 4732{
7c3ef2f7 4733 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
59f45b7c 4734 if (aContextAIS.IsNull())
4735 {
7c3ef2f7 4736 std::cout << "No active viewer!\n";
59f45b7c 4737 return 1;
4738 }
4739
4740 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
7c3ef2f7 4741 if (theArgNb < 2)
59f45b7c 4742 {
7c3ef2f7 4743 TColStd_SequenceOfInteger aLayers;
4744 aViewer->GetAllZLayers (aLayers);
4745 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4746 {
4747 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4748 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4749 printZLayerInfo (theDI, aSettings);
4750 }
59f45b7c 4751 return 1;
4752 }
4753
7c3ef2f7 4754 Standard_Integer anArgIter = 1;
4755 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4756 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4757 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
59f45b7c 4758 {
7c3ef2f7 4759 ++anArgIter;
4760 }
59f45b7c 4761
7c3ef2f7 4762 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4763 if (aFirstArg.IsIntegerValue())
4764 {
4765 ++anArgIter;
4766 aLayerId = aFirstArg.IntegerValue();
59f45b7c 4767 }
7c3ef2f7 4768 else
59f45b7c 4769 {
7c3ef2f7 4770 aFirstArg.LowerCase();
4771 if (aFirstArg == "default"
4772 || aFirstArg == "def")
59f45b7c 4773 {
7c3ef2f7 4774 aLayerId = Graphic3d_ZLayerId_Default;
4775 ++anArgIter;
59f45b7c 4776 }
7c3ef2f7 4777 else if (aFirstArg == "top")
59f45b7c 4778 {
7c3ef2f7 4779 aLayerId = Graphic3d_ZLayerId_Top;
4780 ++anArgIter;
59f45b7c 4781 }
7c3ef2f7 4782 else if (aFirstArg == "topmost")
a1954302 4783 {
7c3ef2f7 4784 aLayerId = Graphic3d_ZLayerId_Topmost;
4785 ++anArgIter;
a1954302 4786 }
7c3ef2f7 4787 else if (aFirstArg == "overlay"
4788 || aFirstArg == "toposd")
59f45b7c 4789 {
7c3ef2f7 4790 aLayerId = Graphic3d_ZLayerId_TopOSD;
4791 ++anArgIter;
59f45b7c 4792 }
7c3ef2f7 4793 else if (aFirstArg == "underlay"
4794 || aFirstArg == "botosd")
c5751993 4795 {
7c3ef2f7 4796 aLayerId = Graphic3d_ZLayerId_BotOSD;
4797 ++anArgIter;
c5751993 4798 }
7c3ef2f7 4799 else
c5751993 4800 {
7c3ef2f7 4801 TColStd_SequenceOfInteger aLayers;
4802 aViewer->GetAllZLayers (aLayers);
4803 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4804 {
4805 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4806 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False))
4807 {
4808 aLayerId = aLayeriter.Value();
4809 ++anArgIter;
4810 break;
4811 }
4812 }
c5751993 4813 }
7c3ef2f7 4814 }
c5751993 4815
7c3ef2f7 4816 for (; anArgIter < theArgNb; ++anArgIter)
4817 {
4818 // perform operation
4819 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4820 anArg.LowerCase();
4821 if (anUpdateTool.parseRedrawMode (anArg))
c5751993 4822 {
7c3ef2f7 4823 //
c5751993 4824 }
7c3ef2f7 4825 else if (anArg == "-add"
4826 || anArg == "add")
c5751993 4827 {
7c3ef2f7 4828 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4829 if (!aViewer->AddZLayer (aLayerId))
4830 {
4831 std::cout << "Error: can not add a new z layer!\n";
4832 return 0;
4833 }
4834
4835 theDI << aLayerId;
c5751993 4836 }
7c3ef2f7 4837 else if (anArg == "-del"
4838 || anArg == "-delete"
4839 || anArg == "del")
c5751993 4840 {
7c3ef2f7 4841 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4842 {
4843 if (++anArgIter >= theArgNb)
4844 {
4845 std::cout << "Syntax error: id of z layer to remove is missing\n";
4846 return 1;
4847 }
4848
4849 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4850 }
4851
4852 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4853 || aLayerId == Graphic3d_ZLayerId_Default
4854 || aLayerId == Graphic3d_ZLayerId_Top
4855 || aLayerId == Graphic3d_ZLayerId_Topmost
4856 || aLayerId == Graphic3d_ZLayerId_TopOSD
4857 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4858 {
4859 std::cout << "Syntax error: standard Z layer can not be removed\n";
4860 return 1;
4861 }
4862
4863 // move all object displayed in removing layer to default layer
4864 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4865 anObjIter.More(); anObjIter.Next())
4866 {
8f521168 4867 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
7c3ef2f7 4868 if (aPrs.IsNull()
4869 || aPrs->ZLayer() != aLayerId)
4870 {
4871 continue;
4872 }
4873 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4874 }
4875
4876 if (!aViewer->RemoveZLayer (aLayerId))
4877 {
4878 std::cout << "Z layer can not be removed!\n";
4879 }
4880 else
4881 {
4882 theDI << aLayerId << " ";
4883 }
c5751993 4884 }
7c3ef2f7 4885 else if (anArg == "-get"
4886 || anArg == "get")
c5751993 4887 {
7c3ef2f7 4888 TColStd_SequenceOfInteger aLayers;
4889 aViewer->GetAllZLayers (aLayers);
4890 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4891 {
4892 theDI << aLayeriter.Value() << " ";
4893 }
4894
4895 theDI << "\n";
c5751993 4896 }
7c3ef2f7 4897 else if (anArg == "-name")
c5751993 4898 {
7c3ef2f7 4899 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
c5751993 4900 {
7c3ef2f7 4901 std::cout << "Syntax error: id of Z layer is missing\n";
c5751993 4902 return 1;
4903 }
4904
7c3ef2f7 4905 if (++anArgIter >= theArgNb)
4906 {
4907 std::cout << "Syntax error: name is missing\n";
4908 return 1;
4909 }
c5751993 4910
7c3ef2f7 4911 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4912 aSettings.SetName (theArgVec[anArgIter]);
4913 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 4914 }
7c3ef2f7 4915 else if (anArg == "-origin")
c5751993 4916 {
7c3ef2f7 4917 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4918 {
4919 std::cout << "Syntax error: id of Z layer is missing\n";
4920 return 1;
4921 }
4922
4923 if (anArgIter + 2 >= theArgNb)
4924 {
4925 std::cout << "Syntax error: origin coordinates are missing\n";
4926 return 1;
4927 }
4928
4929 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4930 gp_XYZ anOrigin;
4931 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4932 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4933 anOrigin.SetZ (0.0);
4934 if (anArgIter + 3 < theArgNb)
4935 {
4936 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4937 anArgIter += 3;
4938 }
4939 else
4940 {
4941 anArgIter += 2;
4942 }
4943 aSettings.SetOrigin (anOrigin);
4944 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 4945 }
4ecf34cc 4946 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4947 && anArgIter + 1 < theArgNb
4948 && (anArg == "-cullingdistance"
4949 || anArg == "-cullingdist"
4950 || anArg == "-culldistance"
4951 || anArg == "-culldist"
4952 || anArg == "-distcull"
4953 || anArg == "-distculling"
4954 || anArg == "-distanceculling"))
4955 {
4956 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4957 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
4958 aSettings.SetCullingDistance (aDist);
4959 aViewer->SetZLayerSettings (aLayerId, aSettings);
4960 }
4961 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4962 && anArgIter + 1 < theArgNb
4963 && (anArg == "-cullingsize"
4964 || anArg == "-cullsize"
4965 || anArg == "-sizecull"
4966 || anArg == "-sizeculling"))
4967 {
4968 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4969 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
4970 aSettings.SetCullingSize (aSize);
4971 aViewer->SetZLayerSettings (aLayerId, aSettings);
4972 }
7c3ef2f7 4973 else if (anArg == "-settings"
4974 || anArg == "settings")
c5751993 4975 {
7c3ef2f7 4976 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4977 {
4978 if (++anArgIter >= theArgNb)
4979 {
4980 std::cout << "Syntax error: id of Z layer is missing\n";
4981 return 1;
4982 }
4983
4984 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4985 }
4986
4987 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4988 printZLayerInfo (theDI, aSettings);
c5751993 4989 }
7c3ef2f7 4990 else if (anArg == "-enable"
4991 || anArg == "enable"
4992 || anArg == "-disable"
4993 || anArg == "disable")
83da37b1 4994 {
7c3ef2f7 4995 const Standard_Boolean toEnable = anArg == "-enable"
4996 || anArg == "enable";
4997 if (++anArgIter >= theArgNb)
4998 {
4999 std::cout << "Syntax error: option name is missing\n";
5000 return 1;
5001 }
c5751993 5002
7c3ef2f7 5003 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
5004 aSubOp.LowerCase();
5005 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5006 {
5007 if (++anArgIter >= theArgNb)
5008 {
5009 std::cout << "Syntax error: id of Z layer is missing\n";
5010 return 1;
5011 }
c5751993 5012
7c3ef2f7 5013 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5014 }
c5751993 5015
7c3ef2f7 5016 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5017 if (aSubOp == "depthtest"
5018 || aSubOp == "test")
5019 {
5020 aSettings.SetEnableDepthTest (toEnable);
5021 }
5022 else if (aSubOp == "depthwrite"
5023 || aSubOp == "write")
5024 {
5025 aSettings.SetEnableDepthWrite (toEnable);
5026 }
5027 else if (aSubOp == "depthclear"
5028 || aSubOp == "clear")
5029 {
5030 aSettings.SetClearDepth (toEnable);
5031 }
5032 else if (aSubOp == "depthoffset"
5033 || aSubOp == "offset")
5034 {
5035 Graphic3d_PolygonOffset aParams;
5036 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5037 if (toEnable)
5038 {
5039 if (anArgIter + 2 >= theArgNb)
5040 {
5041 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5042 return 1;
5043 }
c5751993 5044
7c3ef2f7 5045 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5046 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5047 }
5048 aSettings.SetPolygonOffset (aParams);
5049 }
5050 else if (aSubOp == "positiveoffset"
5051 || aSubOp == "poffset")
5052 {
5053 if (toEnable)
5054 {
5055 aSettings.SetDepthOffsetPositive();
5056 }
5057 else
5058 {
5059 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5060 }
5061 }
5062 else if (aSubOp == "negativeoffset"
5063 || aSubOp == "noffset")
5064 {
5065 if (toEnable)
5066 {
5067 aSettings.SetDepthOffsetNegative();
5068 }
5069 else
5070 {
5071 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5072 }
5073 }
5074 else if (aSubOp == "textureenv")
5075 {
5076 aSettings.SetEnvironmentTexture (toEnable);
5077 }
5078
5079 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 5080 }
7c3ef2f7 5081 else
83da37b1 5082 {
7c3ef2f7 5083 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5084 return 1;
83da37b1 5085 }
59f45b7c 5086 }
5087
5088 return 0;
5089}
5090
c357e426 5091// The interactive presentation of 2d layer item
5092// for "vlayerline" command it provides a presentation of
5093// line with user-defined linewidth, linetype and transparency.
61b0191c 5094class V3d_LineItem : public AIS_InteractiveObject
20637bd2 5095{
5096public:
5097 // CASCADE RTTI
92efcf78 5098 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
4fe56619 5099
20637bd2 5100 // constructor
5101 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5102 Standard_Real X2, Standard_Real Y2,
20637bd2 5103 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5104 Standard_Real theWidth = 0.5,
5105 Standard_Real theTransp = 1.0);
5106
61b0191c 5107 private:
5108
5109 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5110 const Handle(Prs3d_Presentation)& thePresentation,
79104795 5111 const Standard_Integer theMode) Standard_OVERRIDE;
61b0191c 5112
5113 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
79104795 5114 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5115 {}
20637bd2 5116
5117private:
5118
5119 Standard_Real myX1, myY1, myX2, myY2;
eafb234b 5120 Aspect_TypeOfLine myType;
20637bd2 5121 Standard_Real myWidth;
20637bd2 5122};
5123
20637bd2 5124// default constructor for line item
4fe56619 5125V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
20637bd2 5126 Standard_Real X2, Standard_Real Y2,
20637bd2 5127 Aspect_TypeOfLine theType,
5128 Standard_Real theWidth,
5129 Standard_Real theTransp) :
61b0191c 5130 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5131 myType(theType), myWidth(theWidth)
20637bd2 5132{
61b0191c 5133 SetTransparency (1-theTransp);
20637bd2 5134}
5135
5136// render line
61b0191c 5137void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5138 const Handle(Prs3d_Presentation)& thePresentation,
5139 const Standard_Integer /*theMode*/)
20637bd2 5140{
61b0191c 5141 thePresentation->Clear();
5142 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
5143 Standard_Integer aWidth, aHeight;
5144 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5145 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5146 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5147 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5148 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5149 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5150 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5151 aGroup->AddPrimitiveArray (aPrim);
20637bd2 5152}
5153
5154//=============================================================================
5155//function : VLayerLine
5156//purpose : Draws line in the v3d view layer with given attributes: linetype,
5157// : linewidth, transparency coefficient
5158//============================================================================
5159static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5160{
5161 // get the active view
5162 Handle(V3d_View) aView = ViewerTest::CurrentView();
5163 if (aView.IsNull())
5164 {
5165 di << "Call vinit before!\n";
5166 return 1;
5167 }
5168 else if (argc < 5)
5169 {
5170 di << "Use: " << argv[0];
5171 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5172 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5173 di << " 0 - solid \n";
5174 di << " 1 - dashed \n";
5175 di << " 2 - dot \n";
5176 di << " 3 - dashdot\n";
5177 di << " transparency : { 0.0 - 1.0 } \n";
5178 di << " 0.0 - transparent\n";
5179 di << " 1.0 - visible \n";
5180 return 1;
5181 }
5182
61b0191c 5183 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
20637bd2 5184 // get the input params
91322f44 5185 Standard_Real X1 = Draw::Atof(argv[1]);
5186 Standard_Real Y1 = Draw::Atof(argv[2]);
5187 Standard_Real X2 = Draw::Atof(argv[3]);
5188 Standard_Real Y2 = Draw::Atof(argv[4]);
20637bd2 5189
3a4a3962 5190 Standard_Real aWidth = 0.5;
5191 Standard_Real aTransparency = 1.0;
20637bd2 5192
5193 // has width
5194 if (argc > 5)
91322f44 5195 aWidth = Draw::Atof(argv[5]);
20637bd2 5196
3a4a3962 5197 // select appropriate line type
5198 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5199 if (argc > 6
5200 && !ViewerTest::ParseLineType (argv[6], aLineType))
5201 {
5202 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5203 return 1;
5204 }
20637bd2 5205
5206 // has transparency
5207 if (argc > 7)
5208 {
91322f44 5209 aTransparency = Draw::Atof(argv[7]);
4fe56619 5210 if (aTransparency < 0 || aTransparency > 1.0)
20637bd2 5211 aTransparency = 1.0;
5212 }
5213
61b0191c 5214 static Handle (V3d_LineItem) aLine;
5215 if (!aLine.IsNull())
25289ec1 5216 {
0577ae8c 5217 aContext->Erase (aLine, Standard_False);
25289ec1 5218 }
61b0191c 5219 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5220 aLineType, aWidth,
5221 aTransparency);
25289ec1 5222
778cd667 5223 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
61b0191c 5224 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5225 aLine->SetToUpdate();
5226 aContext->Display (aLine, Standard_True);
25289ec1 5227
5228 return 0;
5229}
5230
61b0191c 5231
2bd4c032 5232//==============================================================================
5233//function : VGrid
5234//purpose :
5235//==============================================================================
5236
35e08fe8 5237static int VGrid (Draw_Interpretor& /*theDI*/,
2bd4c032 5238 Standard_Integer theArgNb,
5239 const char** theArgVec)
5240{
5241 // get the active view
5242 Handle(V3d_View) aView = ViewerTest::CurrentView();
5243 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5244 if (aView.IsNull() || aViewer.IsNull())
5245 {
5246 std::cerr << "No active view. Please call vinit.\n";
5247 return 1;
5248 }
5249
5250 Aspect_GridType aType = aViewer->GridType();
5251 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
224f48fa 5252 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2bd4c032 5253 Standard_Integer anIter = 1;
5254 for (; anIter < theArgNb; ++anIter)
5255 {
5256 const char* aValue = theArgVec[anIter];
224f48fa 5257 if (anUpdateTool.parseRedrawMode (aValue))
5258 {
5259 continue;
5260 }
5261 else if (*aValue == 'r')
2bd4c032 5262 {
5263 aType = Aspect_GT_Rectangular;
5264 }
5265 else if (*aValue == 'c')
5266 {
5267 aType = Aspect_GT_Circular;
5268 }
5269 else if (*aValue == 'l')
5270 {
5271 aMode = Aspect_GDM_Lines;
5272 }
5273 else if (*aValue == 'p')
5274 {
5275 aMode = Aspect_GDM_Points;
5276 }
5277 else if (strcmp (aValue, "off" ) == 0)
5278 {
5279 aViewer->DeactivateGrid();
5280 return 0;
5281 }
5282 else
5283 {
5284 break;
5285 }
5286 }
5287
5288 Standard_Integer aTail = (theArgNb - anIter);
5289 if (aTail == 0)
5290 {
5291 aViewer->ActivateGrid (aType, aMode);
5292 return 0;
5293 }
5294 else if (aTail != 2 && aTail != 5)
5295 {
5296 std::cerr << "Incorrect arguments number! Usage:\n"
5297 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
5298 return 1;
5299 }
5300
ee2be2a8 5301 Standard_Real anOriginX, anOriginY, aRotAngle;
2bd4c032 5302 if (aType == Aspect_GT_Rectangular)
5303 {
ee2be2a8 5304 Standard_Real aRStepX, aRStepY;
2bd4c032 5305 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5306
91322f44 5307 anOriginX = Draw::Atof (theArgVec[anIter++]);
5308 anOriginY = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5309 if (aTail == 5)
5310 {
91322f44 5311 aRStepX = Draw::Atof (theArgVec[anIter++]);
5312 aRStepY = Draw::Atof (theArgVec[anIter++]);
5313 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5314 }
5315 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5316 aViewer->ActivateGrid (aType, aMode);
5317 }
5318 else if (aType == Aspect_GT_Circular)
5319 {
ee2be2a8 5320 Standard_Real aRadiusStep;
2bd4c032 5321 Standard_Integer aDivisionNumber;
5322 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5323
91322f44 5324 anOriginX = Draw::Atof (theArgVec[anIter++]);
5325 anOriginY = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5326 if (aTail == 5)
5327 {
91322f44 5328 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
5329 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
5330 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5331 }
5332
5333 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5334 aViewer->ActivateGrid (aType, aMode);
5335 }
5336
5337 return 0;
5338}
5339
c40b7d58 5340//==============================================================================
5341//function : VPriviledgedPlane
5342//purpose :
5343//==============================================================================
5344
5345static int VPriviledgedPlane (Draw_Interpretor& theDI,
5346 Standard_Integer theArgNb,
5347 const char** theArgVec)
5348{
5349 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5350 {
5351 std::cerr << "Error: wrong number of arguments! See usage:\n";
5352 theDI.PrintHelp (theArgVec[0]);
5353 return 1;
5354 }
5355
5356 // get the active viewer
5357 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5358 if (aViewer.IsNull())
5359 {
5360 std::cerr << "Error: no active viewer. Please call vinit.\n";
5361 return 1;
5362 }
5363
5364 if (theArgNb == 1)
5365 {
5366 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5367 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5368 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5369 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5370 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5371 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5372 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5373 return 0;
5374 }
5375
5376 Standard_Integer anArgIdx = 1;
5377 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5378 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5379 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5380 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5381 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5382 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5383
5384 gp_Ax3 aPriviledgedPlane;
5385 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5386 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5387 if (theArgNb > 7)
5388 {
5389 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5390 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5391 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5392 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5393 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5394 }
5395 else
5396 {
5397 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5398 }
5399
5400 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5401
5402 return 0;
5403}
5404
f25b82d6 5405//==============================================================================
5406//function : VConvert
5407//purpose :
5408//==============================================================================
5409
5410static int VConvert (Draw_Interpretor& theDI,
5411 Standard_Integer theArgNb,
5412 const char** theArgVec)
5413{
5414 // get the active view
5415 Handle(V3d_View) aView = ViewerTest::CurrentView();
5416 if (aView.IsNull())
5417 {
c40b7d58 5418 std::cerr << "Error: no active view. Please call vinit.\n";
f25b82d6 5419 return 1;
5420 }
5421
5422 enum { Model, Ray, View, Window, Grid } aMode = Model;
5423
5424 // access coordinate arguments
5425 TColStd_SequenceOfReal aCoord;
5426 Standard_Integer anArgIdx = 1;
5427 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5428 {
5429 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5430 if (!anArg.IsRealValue())
5431 {
5432 break;
5433 }
5434 aCoord.Append (anArg.RealValue());
5435 }
5436
5437 // non-numeric argument too early
5438 if (aCoord.IsEmpty())
5439 {
5440 std::cerr << "Error: wrong number of arguments! See usage:\n";
5441 theDI.PrintHelp (theArgVec[0]);
5442 return 1;
5443 }
5444
5445 // collect all other arguments and options
5446 for (; anArgIdx < theArgNb; ++anArgIdx)
5447 {
5448 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5449 anArg.LowerCase();
5450 if (anArg == "window") aMode = Window;
5451 else if (anArg == "view") aMode = View;
5452 else if (anArg == "grid") aMode = Grid;
5453 else if (anArg == "ray") aMode = Ray;
5454 else
5455 {
5456 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5457 theDI.PrintHelp (theArgVec[0]);
5458 return 1;
5459 }
5460 }
5461
5462 // complete input checks
5463 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5464 (aCoord.Length() == 2 && theArgNb > 4) ||
5465 (aCoord.Length() == 3 && theArgNb > 5))
5466 {
5467 std::cerr << "Error: wrong number of arguments! See usage:\n";
5468 theDI.PrintHelp (theArgVec[0]);
5469 return 1;
5470 }
5471
5472 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5473 Standard_Integer aXYp[2] = {0, 0};
5474
5475 // convert one-dimensional coordinate
5476 if (aCoord.Length() == 1)
5477 {
5478 switch (aMode)
5479 {
ee2be2a8 5480 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
5481 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
f25b82d6 5482 default:
5483 std::cerr << "Error: wrong arguments! See usage:\n";
5484 theDI.PrintHelp (theArgVec[0]);
5485 return 1;
5486 }
5487 }
5488
5489 // convert 2D coordinates from projection or view reference space
5490 if (aCoord.Length() == 2)
5491 {
5492 switch (aMode)
5493 {
5494 case Model :
5495 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5496 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5497 return 0;
5498
5499 case View :
5500 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5501 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5502 return 0;
5503
5504 case Window :
ee2be2a8 5505 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
f25b82d6 5506 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5507 return 0;
5508
5509 case Grid :
5510 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5511 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5512 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5513 return 0;
5514
5515 case Ray :
5516 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5517 (Standard_Integer) aCoord (2),
5518 aXYZ[0], aXYZ[1], aXYZ[2],
5519 aXYZ[3], aXYZ[4], aXYZ[5]);
5520 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5521 return 0;
5522
5523 default:
5524 std::cerr << "Error: wrong arguments! See usage:\n";
5525 theDI.PrintHelp (theArgVec[0]);
5526 return 1;
5527 }
5528 }
5529
5530 // convert 3D coordinates from view reference space
5531 else if (aCoord.Length() == 3)
5532 {
5533 switch (aMode)
5534 {
5535 case Window :
5536 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5537 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5538 return 0;
5539
5540 case Grid :
5541 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5542 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5543 return 0;
5544
5545 default:
5546 std::cerr << "Error: wrong arguments! See usage:\n";
5547 theDI.PrintHelp (theArgVec[0]);
5548 return 1;
5549 }
5550 }
5551
5552 return 0;
5553}
5554
208e6839 5555//==============================================================================
5556//function : VFps
5557//purpose :
5558//==============================================================================
5559
5560static int VFps (Draw_Interpretor& theDI,
5561 Standard_Integer theArgNb,
5562 const char** theArgVec)
5563{
5564 // get the active view
5565 Handle(V3d_View) aView = ViewerTest::CurrentView();
5566 if (aView.IsNull())
5567 {
5568 std::cerr << "No active view. Please call vinit.\n";
5569 return 1;
5570 }
5571
e084dbbc 5572 Standard_Integer aFramesNb = -1;
5573 Standard_Real aDuration = -1.0;
5574 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
208e6839 5575 {
e084dbbc 5576 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5577 anArg.LowerCase();
5578 if (aDuration < 0.0
5579 && anArgIter + 1 < theArgNb
5580 && (anArg == "-duration"
5581 || anArg == "-dur"
5582 || anArg == "-time"))
5583 {
5584 aDuration = Draw::Atof (theArgVec[++anArgIter]);
5585 }
5586 else if (aFramesNb < 0
5587 && anArg.IsIntegerValue())
5588 {
5589 aFramesNb = anArg.IntegerValue();
5590 if (aFramesNb <= 0)
5591 {
5592 std::cerr << "Syntax error at '" << anArg << "'\n";
5593 return 1;
5594 }
5595 }
5596 else
5597 {
5598 std::cerr << "Syntax error at '" << anArg << "'\n";
5599 return 1;
5600 }
5601 }
5602 if (aFramesNb < 0 && aDuration < 0.0)
5603 {
5604 aFramesNb = 100;
208e6839 5605 }
5606
5607 // the time is meaningless for first call
5608 // due to async OpenGl rendering
5609 aView->Redraw();
5610
5611 // redraw view in loop to estimate average values
5612 OSD_Timer aTimer;
5613 aTimer.Start();
e084dbbc 5614 Standard_Integer aFrameIter = 1;
5615 for (;; ++aFrameIter)
208e6839 5616 {
5617 aView->Redraw();
e084dbbc 5618 if ((aFramesNb > 0
5619 && aFrameIter >= aFramesNb)
5620 || (aDuration > 0.0
5621 && aTimer.ElapsedTime() >= aDuration))
5622 {
5623 break;
5624 }
208e6839 5625 }
5626 aTimer.Stop();
5627 Standard_Real aCpu;
5628 const Standard_Real aTime = aTimer.ElapsedTime();
5629 aTimer.OSD_Chronometer::Show (aCpu);
5630
e084dbbc 5631 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
5632 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
208e6839 5633
5634 // return statistics
5635 theDI << "FPS: " << aFpsAver << "\n"
5636 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5637
8c820969 5638 // compute additional statistics in ray-tracing mode
e084dbbc 5639 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
8c820969 5640 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5641 {
e084dbbc 5642 Graphic3d_Vec2i aWinSize (0, 0);
5643 aView->Window()->Size (aWinSize.x(), aWinSize.y());
8c820969 5644
5645 // 1 shadow ray and 1 secondary ray pew each bounce
e084dbbc 5646 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
8c820969 5647 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5648 }
5649
208e6839 5650 return 0;
5651}
5652
84e84755 5653//! Auxiliary function for parsing glsl dump level argument.
5654static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
5655 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
5656{
5657 TCollection_AsciiString aTypeStr (theArg);
5658 aTypeStr.LowerCase();
5659 if (aTypeStr == "off"
5660 || aTypeStr == "0")
5661 {
5662 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5663 }
5664 else if (aTypeStr == "short")
5665 {
5666 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
5667 }
5668 else if (aTypeStr == "full"
5669 || aTypeStr == "1")
5670 {
5671 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
5672 }
5673 else
5674 {
5675 return Standard_False;
5676 }
5677 return Standard_True;
5678}
5679
58655684 5680//==============================================================================
5681//function : VGlDebug
5682//purpose :
5683//==============================================================================
5684
5685static int VGlDebug (Draw_Interpretor& theDI,
5686 Standard_Integer theArgNb,
5687 const char** theArgVec)
5688{
aaf512f1 5689 Handle(OpenGl_GraphicDriver) aDriver;
5690 Handle(V3d_View) aView = ViewerTest::CurrentView();
5691 if (!aView.IsNull())
5692 {
5693 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5694 }
c87535af 5695 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5696 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5697
58655684 5698 if (theArgNb < 2)
5699 {
c87535af 5700 TCollection_AsciiString aDebActive, aSyncActive;
5701 if (aCaps == NULL)
58655684 5702 {
c87535af 5703 aCaps = aDefCaps;
5704 }
5705 else
5706 {
5707 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5708 "GL_ARB_debug_output");
5709 aDebActive = isActive ? " (active)" : " (inactive)";
5710 if (isActive)
5711 {
5712 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5713 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5714 }
58655684 5715 }
5716
84e84755 5717 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
5718 + "glslSourceCode: "
5719 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
5720 ? "Off"
5721 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
5722 ? "Short"
5723 : "Full")
5724 + "\n";
5725 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5726 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5727 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
5728 << aGlslCodeDebugStatus
5729 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
58655684 5730 return 0;
5731 }
5732
c87535af 5733 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
aaf512f1 5734 {
c87535af 5735 Standard_CString anArg = theArgVec[anArgIter];
5736 TCollection_AsciiString anArgCase (anArg);
5737 anArgCase.LowerCase();
5738 Standard_Boolean toEnableDebug = Standard_True;
5739 if (anArgCase == "-glsl"
5740 || anArgCase == "-glslwarn"
5741 || anArgCase == "-glslwarns"
5742 || anArgCase == "-glslwarnings")
5743 {
5744 Standard_Boolean toShowWarns = Standard_True;
5745 if (++anArgIter < theArgNb
a5565a3c 5746 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
c87535af 5747 {
5748 --anArgIter;
5749 }
5750 aDefCaps->glslWarnings = toShowWarns;
5751 if (aCaps != NULL)
5752 {
5753 aCaps->glslWarnings = toShowWarns;
5754 }
5755 }
5756 else if (anArgCase == "-extra"
5757 || anArgCase == "-extramsg"
5758 || anArgCase == "-extramessages")
5759 {
5760 Standard_Boolean toShow = Standard_True;
5761 if (++anArgIter < theArgNb
a5565a3c 5762 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
c87535af 5763 {
5764 --anArgIter;
5765 }
5766 aDefCaps->suppressExtraMsg = !toShow;
5767 if (aCaps != NULL)
5768 {
5769 aCaps->suppressExtraMsg = !toShow;
5770 }
5771 }
5772 else if (anArgCase == "-noextra"
5773 || anArgCase == "-noextramsg"
5774 || anArgCase == "-noextramessages")
5775 {
5776 Standard_Boolean toSuppress = Standard_True;
5777 if (++anArgIter < theArgNb
a5565a3c 5778 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
c87535af 5779 {
5780 --anArgIter;
5781 }
5782 aDefCaps->suppressExtraMsg = toSuppress;
5783 if (aCaps != NULL)
5784 {
5785 aCaps->suppressExtraMsg = toSuppress;
5786 }
5787 }
5788 else if (anArgCase == "-sync")
5789 {
5790 Standard_Boolean toSync = Standard_True;
5791 if (++anArgIter < theArgNb
a5565a3c 5792 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
c87535af 5793 {
5794 --anArgIter;
5795 }
5796 aDefCaps->contextSyncDebug = toSync;
5797 if (toSync)
5798 {
5799 aDefCaps->contextDebug = Standard_True;
5800 }
5801 }
84e84755 5802 else if (anArgCase == "-glslsourcecode"
5803 || anArgCase == "-glslcode")
5804 {
5805 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
5806 if (++anArgIter < theArgNb
5807 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
5808 {
5809 --anArgIter;
5810 }
5811 aDefCaps->glslDumpLevel = aGslsDumpLevel;
5812 if (aCaps != NULL)
5813 {
5814 aCaps->glslDumpLevel = aGslsDumpLevel;
5815 }
5816 }
c87535af 5817 else if (anArgCase == "-debug")
5818 {
5819 if (++anArgIter < theArgNb
a5565a3c 5820 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
c87535af 5821 {
5822 --anArgIter;
5823 }
5824 aDefCaps->contextDebug = toEnableDebug;
5825 }
a5565a3c 5826 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
c87535af 5827 && (anArgIter + 1 == theArgNb))
5828 {
5829 // simple alias to turn on almost everything
5830 aDefCaps->contextDebug = toEnableDebug;
5831 aDefCaps->contextSyncDebug = toEnableDebug;
5832 aDefCaps->glslWarnings = toEnableDebug;
3b4c6945 5833 if (!toEnableDebug)
5834 {
5835 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5836 }
84e84755 5837 aDefCaps->suppressExtraMsg = !toEnableDebug;
5838 if (aCaps != NULL)
5839 {
5840 aCaps->contextDebug = toEnableDebug;
5841 aCaps->contextSyncDebug = toEnableDebug;
5842 aCaps->glslWarnings = toEnableDebug;
3b4c6945 5843 if (!toEnableDebug)
5844 {
5845 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5846 }
84e84755 5847 aCaps->suppressExtraMsg = !toEnableDebug;
5848 }
c87535af 5849 }
5850 else
5851 {
5852 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5853 return 1;
5854 }
aaf512f1 5855 }
5856
58655684 5857 return 0;
5858}
208e6839 5859
5860//==============================================================================
5861//function : VVbo
5862//purpose :
5863//==============================================================================
5864
58655684 5865static int VVbo (Draw_Interpretor& theDI,
208e6839 5866 Standard_Integer theArgNb,
5867 const char** theArgVec)
5868{
58655684 5869 const Standard_Boolean toSet = (theArgNb > 1);
5870 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5871 if (toSet)
208e6839 5872 {
58655684 5873 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
208e6839 5874 }
5875
58655684 5876 // get the context
5877 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5878 if (aContextAIS.IsNull())
208e6839 5879 {
58655684 5880 if (!toSet)
5881 {
5882 std::cerr << "No active view!\n";
5883 }
208e6839 5884 return 1;
5885 }
58655684 5886 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5887 if (!aDriver.IsNull())
208e6839 5888 {
58655684 5889 if (!toSet)
5890 {
5891 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5892 }
5893 else
5894 {
5895 aDriver->ChangeOptions().vboDisable = toUseVbo;
5896 }
208e6839 5897 }
5898
208e6839 5899 return 0;
5900}
5901
a577aaab 5902//==============================================================================
5903//function : VCaps
5904//purpose :
5905//==============================================================================
5906
5907static int VCaps (Draw_Interpretor& theDI,
5908 Standard_Integer theArgNb,
5909 const char** theArgVec)
5910{
5911 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5912 Handle(OpenGl_GraphicDriver) aDriver;
8625ef7e 5913 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5914 if (!aContext.IsNull())
a577aaab 5915 {
8625ef7e 5916 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
a577aaab 5917 aCaps = &aDriver->ChangeOptions();
5918 }
5919
5920 if (theArgNb < 2)
5921 {
5922 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5923 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
abe46077 5924 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
8625ef7e 5925 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
f978241f 5926 theDI << "VSync: " << aCaps->swapInterval << "\n";
4e1523ef 5927 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
f978241f 5928 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
56689b27 5929 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
a577aaab 5930 return 0;
5931 }
5932
8625ef7e 5933 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
a577aaab 5934 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5935 {
8625ef7e 5936 Standard_CString anArg = theArgVec[anArgIter];
5937 TCollection_AsciiString anArgCase (anArg);
5938 anArgCase.LowerCase();
5939 if (anUpdateTool.parseRedrawMode (anArg))
5940 {
5941 continue;
5942 }
f978241f 5943 else if (anArgCase == "-vsync"
5944 || anArgCase == "-swapinterval")
5945 {
5946 Standard_Boolean toEnable = Standard_True;
5947 if (++anArgIter < theArgNb
a5565a3c 5948 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 5949 {
5950 --anArgIter;
5951 }
5952 aCaps->swapInterval = toEnable;
5953 }
8625ef7e 5954 else if (anArgCase == "-ffp")
5955 {
5956 Standard_Boolean toEnable = Standard_True;
5957 if (++anArgIter < theArgNb
a5565a3c 5958 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5959 {
5960 --anArgIter;
5961 }
5962 aCaps->ffpEnable = toEnable;
5963 }
5964 else if (anArgCase == "-vbo")
a577aaab 5965 {
8625ef7e 5966 Standard_Boolean toEnable = Standard_True;
5967 if (++anArgIter < theArgNb
a5565a3c 5968 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5969 {
5970 --anArgIter;
5971 }
5972 aCaps->vboDisable = !toEnable;
a577aaab 5973 }
8625ef7e 5974 else if (anArgCase == "-sprite"
5975 || anArgCase == "-sprites")
a577aaab 5976 {
8625ef7e 5977 Standard_Boolean toEnable = Standard_True;
5978 if (++anArgIter < theArgNb
a5565a3c 5979 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5980 {
5981 --anArgIter;
5982 }
5983 aCaps->pntSpritesDisable = !toEnable;
a577aaab 5984 }
8625ef7e 5985 else if (anArgCase == "-softmode")
abe46077 5986 {
8625ef7e 5987 Standard_Boolean toEnable = Standard_True;
5988 if (++anArgIter < theArgNb
a5565a3c 5989 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5990 {
5991 --anArgIter;
5992 }
5993 aCaps->contextNoAccel = toEnable;
5994 }
56689b27 5995 else if (anArgCase == "-winbuffer"
5996 || anArgCase == "-windowbuffer"
5997 || anArgCase == "-usewinbuffer"
5998 || anArgCase == "-usewindowbuffer"
5999 || anArgCase == "-usesystembuffer")
6000 {
6001 Standard_Boolean toEnable = Standard_True;
6002 if (++anArgIter < theArgNb
6003 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6004 {
6005 --anArgIter;
6006 }
6007 aCaps->useSystemBuffer = toEnable;
6008 }
8625ef7e 6009 else if (anArgCase == "-accel"
6010 || anArgCase == "-acceleration")
6011 {
6012 Standard_Boolean toEnable = Standard_True;
6013 if (++anArgIter < theArgNb
a5565a3c 6014 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 6015 {
6016 --anArgIter;
6017 }
6018 aCaps->contextNoAccel = !toEnable;
abe46077 6019 }
4e1523ef 6020 else if (anArgCase == "-compat"
6021 || anArgCase == "-compatprofile"
6022 || anArgCase == "-compatible"
6023 || anArgCase == "-compatibleprofile")
6024 {
6025 Standard_Boolean toEnable = Standard_True;
6026 if (++anArgIter < theArgNb
a5565a3c 6027 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
4e1523ef 6028 {
6029 --anArgIter;
6030 }
6031 aCaps->contextCompatible = toEnable;
6032 if (!aCaps->contextCompatible)
6033 {
6034 aCaps->ffpEnable = Standard_False;
6035 }
6036 }
6037 else if (anArgCase == "-core"
6038 || anArgCase == "-coreprofile")
6039 {
6040 Standard_Boolean toEnable = Standard_True;
6041 if (++anArgIter < theArgNb
a5565a3c 6042 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
4e1523ef 6043 {
6044 --anArgIter;
6045 }
6046 aCaps->contextCompatible = !toEnable;
6047 if (!aCaps->contextCompatible)
6048 {
6049 aCaps->ffpEnable = Standard_False;
6050 }
6051 }
f978241f 6052 else if (anArgCase == "-stereo"
6053 || anArgCase == "-quadbuffer")
6054 {
6055 Standard_Boolean toEnable = Standard_True;
6056 if (++anArgIter < theArgNb
a5565a3c 6057 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 6058 {
6059 --anArgIter;
6060 }
6061 aCaps->contextStereo = toEnable;
6062 }
a577aaab 6063 else
6064 {
8625ef7e 6065 std::cout << "Error: unknown argument '" << anArg << "'\n";
6066 return 1;
a577aaab 6067 }
6068 }
6069 if (aCaps != &ViewerTest_myDefaultCaps)
6070 {
6071 ViewerTest_myDefaultCaps = *aCaps;
6072 }
6073 return 0;
6074}
6075
f0430952 6076//==============================================================================
6077//function : VMemGpu
6078//purpose :
6079//==============================================================================
6080
6081static int VMemGpu (Draw_Interpretor& theDI,
6082 Standard_Integer theArgNb,
6083 const char** theArgVec)
6084{
6085 // get the context
6086 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6087 if (aContextAIS.IsNull())
6088 {
6089 std::cerr << "No active view. Please call vinit.\n";
6090 return 1;
6091 }
6092
dc3fe572 6093 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
f0430952 6094 if (aDriver.IsNull())
6095 {
6096 std::cerr << "Graphic driver not available.\n";
6097 return 1;
6098 }
6099
6100 Standard_Size aFreeBytes = 0;
6101 TCollection_AsciiString anInfo;
6102 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
6103 {
6104 std::cerr << "Information not available.\n";
6105 return 1;
6106 }
6107
6108 if (theArgNb > 1 && *theArgVec[1] == 'f')
6109 {
6110 theDI << Standard_Real (aFreeBytes);
6111 }
6112 else
6113 {
6114 theDI << anInfo;
6115 }
6116
6117 return 0;
6118}
6119
85e096c3 6120// ==============================================================================
6121// function : VReadPixel
6122// purpose :
6123// ==============================================================================
6124static int VReadPixel (Draw_Interpretor& theDI,
6125 Standard_Integer theArgNb,
6126 const char** theArgVec)
6127{
6128 // get the active view
6129 Handle(V3d_View) aView = ViewerTest::CurrentView();
6130 if (aView.IsNull())
6131 {
6132 std::cerr << "No active view. Please call vinit.\n";
6133 return 1;
6134 }
6135 else if (theArgNb < 3)
6136 {
6137 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
6138 return 1;
6139 }
6140
dc858f4c 6141 Image_Format aFormat = Image_Format_RGBA;
6142 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
692613e5 6143
85e096c3 6144 Standard_Integer aWidth, aHeight;
6145 aView->Window()->Size (aWidth, aHeight);
91322f44 6146 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
6147 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
85e096c3 6148 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
6149 {
6150 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
6151 return 1;
6152 }
6153
6154 Standard_Boolean toShowName = Standard_False;
6155 Standard_Boolean toShowHls = Standard_False;
6156 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
6157 {
dc858f4c 6158 TCollection_AsciiString aParam (theArgVec[anIter]);
6159 aParam.LowerCase();
6160 if (aParam == "rgb")
85e096c3 6161 {
dc858f4c 6162 aFormat = Image_Format_RGB;
692613e5 6163 aBufferType = Graphic3d_BT_RGB;
85e096c3 6164 }
dc858f4c 6165 else if (aParam == "hls")
85e096c3 6166 {
dc858f4c 6167 aFormat = Image_Format_RGB;
692613e5 6168 aBufferType = Graphic3d_BT_RGB;
85e096c3 6169 toShowHls = Standard_True;
6170 }
dc858f4c 6171 else if (aParam == "rgbf")
85e096c3 6172 {
dc858f4c 6173 aFormat = Image_Format_RGBF;
692613e5 6174 aBufferType = Graphic3d_BT_RGB;
85e096c3 6175 }
dc858f4c 6176 else if (aParam == "rgba")
85e096c3 6177 {
dc858f4c 6178 aFormat = Image_Format_RGBA;
692613e5 6179 aBufferType = Graphic3d_BT_RGBA;
85e096c3 6180 }
dc858f4c 6181 else if (aParam == "rgbaf")
85e096c3 6182 {
dc858f4c 6183 aFormat = Image_Format_RGBAF;
692613e5 6184 aBufferType = Graphic3d_BT_RGBA;
85e096c3 6185 }
dc858f4c 6186 else if (aParam == "depth")
85e096c3 6187 {
dc858f4c 6188 aFormat = Image_Format_GrayF;
692613e5 6189 aBufferType = Graphic3d_BT_Depth;
85e096c3 6190 }
dc858f4c 6191 else if (aParam == "name")
85e096c3 6192 {
6193 toShowName = Standard_True;
6194 }
6195 }
6196
692613e5 6197 Image_PixMap anImage;
6198 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
6199 {
6200 std::cerr << "Image allocation failed\n";
6201 return 1;
6202 }
6203 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
85e096c3 6204 {
6205 std::cerr << "Image dump failed\n";
6206 return 1;
6207 }
6208
68beaa3c 6209 // redirect possible warning messages that could have been added by ToPixMap
6210 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
6211 // contaminate result of the command
6212 Standard_CString aWarnLog = theDI.Result();
6213 if (aWarnLog != NULL && aWarnLog[0] != '\0')
6214 {
6215 std::cout << aWarnLog << std::endl;
6216 }
6217 theDI.Reset();
6218
e958a649 6219 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
85e096c3 6220 if (toShowName)
6221 {
692613e5 6222 if (aBufferType == Graphic3d_BT_RGBA)
85e096c3 6223 {
e958a649 6224 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
85e096c3 6225 }
6226 else
6227 {
e958a649 6228 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
85e096c3 6229 }
6230 }
6231 else
6232 {
6233 switch (aBufferType)
6234 {
6235 default:
692613e5 6236 case Graphic3d_BT_RGB:
85e096c3 6237 {
6238 if (toShowHls)
6239 {
e958a649 6240 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
85e096c3 6241 }
6242 else
6243 {
e958a649 6244 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
85e096c3 6245 }
6246 break;
6247 }
692613e5 6248 case Graphic3d_BT_RGBA:
85e096c3 6249 {
e958a649 6250 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
85e096c3 6251 break;
6252 }
692613e5 6253 case Graphic3d_BT_Depth:
85e096c3 6254 {
e958a649 6255 theDI << aColor.GetRGB().Red();
85e096c3 6256 break;
6257 }
6258 }
6259 }
6260
6261 return 0;
6262}
6263
fd3f6bd0 6264//! Auxiliary presentation for an image plane.
6265class ViewerTest_ImagePrs : public AIS_InteractiveObject
6266{
6267public:
6268 //! Main constructor.
6269 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
6270 const Standard_Real theWidth,
6271 const Standard_Real theHeight,
6272 const TCollection_AsciiString& theLabel)
6273 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
6274 {
6275 SetDisplayMode (0);
6276 SetHilightMode (1);
6277 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
6278 {
6279 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6280 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
6281 Graphic3d_MaterialAspect aMat;
6282 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
6283 aMat.SetAmbient (1.0);
6284 aMat.SetDiffuse (1.0);
6285 aMat.SetSpecular (1.0);
6286 aMat.SetEmissive (1.0);
6287 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
6288 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
6289 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
6290 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
6291 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6292 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
6293 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6294 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6295 aFillAspect->SetFrontMaterial (aMat);
6296 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
6297 aFillAspect->SetTextureMapOn();
6298 }
6299 {
6300 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
6301 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
6302 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
6303 myDrawer->SetTextAspect (aTextAspect);
6304 }
6305 {
6306 const gp_Dir aNorm (0.0, 0.0, 1.0);
6307 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
6308 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
6309 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
6310 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
6311 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
6312 myTris->AddEdge (1);
6313 myTris->AddEdge (2);
6314 myTris->AddEdge (3);
6315 myTris->AddEdge (3);
6316 myTris->AddEdge (2);
6317 myTris->AddEdge (4);
6318
6319 myRect = new Graphic3d_ArrayOfPolylines (4);
6320 myRect->AddVertex (myTris->Vertice (1));
6321 myRect->AddVertex (myTris->Vertice (3));
6322 myRect->AddVertex (myTris->Vertice (4));
6323 myRect->AddVertex (myTris->Vertice (2));
6324 }
6325 }
6326
6327 //! Returns TRUE for accepted display modes.
6328 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
6329
6330 //! Compute presentation.
6331 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
6332 {
6333 switch (theMode)
6334 {
6335 case 0:
6336 {
6337 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6338 aGroup->AddPrimitiveArray (myTris);
6339 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
6340 aGroup->AddPrimitiveArray (myRect);
6341 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6342 return;
6343 }
6344 case 1:
6345 {
6346 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
6347 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6348 aGroup->AddPrimitiveArray (myRect);
6349 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6350 return;
6351 }
6352 }
6353 }
6354
6355 //! Compute selection.
6356 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
6357 {
6358 if (theMode == 0)
6359 {
6360 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
6361 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
6362 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
6363 theSel->Add (aSensitive);
6364 }
6365 }
6366
6367private:
6368 Handle(Graphic3d_ArrayOfTriangles) myTris;
6369 Handle(Graphic3d_ArrayOfPolylines) myRect;
6370 TCollection_AsciiString myLabel;
6371 Standard_Real myWidth;
6372 Standard_Real myHeight;
6373};
6374
692613e5 6375//==============================================================================
6376//function : VDiffImage
6377//purpose : The draw-command compares two images.
6378//==============================================================================
6379
6380static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
6381{
fd3f6bd0 6382 if (theArgNb < 3)
692613e5 6383 {
fd3f6bd0 6384 std::cout << "Syntax error: not enough arguments.\n";
692613e5 6385 return 1;
6386 }
6387
fd3f6bd0 6388 Standard_Integer anArgIter = 1;
6389 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
6390 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
6391 TCollection_AsciiString aDiffImagePath;
6392 Standard_Real aTolColor = -1.0;
6393 Standard_Integer toBlackWhite = -1;
6394 Standard_Integer isBorderFilterOn = -1;
6395 Standard_Boolean isOldSyntax = Standard_False;
6396 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
6397 for (; anArgIter < theArgNb; ++anArgIter)
6398 {
6399 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6400 anArg.LowerCase();
6401 if (anArgIter + 1 < theArgNb
6402 && (anArg == "-toleranceofcolor"
6403 || anArg == "-tolerancecolor"
6404 || anArg == "-tolerance"
6405 || anArg == "-toler"))
6406 {
6407 aTolColor = Atof (theArgVec[++anArgIter]);
6408 if (aTolColor < 0.0 || aTolColor > 1.0)
6409 {
6410 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6411 return 1;
6412 }
6413 }
6414 else if (anArg == "-blackwhite")
6415 {
6416 Standard_Boolean toEnable = Standard_True;
6417 if (anArgIter + 1 < theArgNb
6418 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6419 {
6420 ++anArgIter;
6421 }
6422 toBlackWhite = toEnable ? 1 : 0;
6423 }
6424 else if (anArg == "-borderfilter")
6425 {
6426 Standard_Boolean toEnable = Standard_True;
6427 if (anArgIter + 1 < theArgNb
6428 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6429 {
6430 ++anArgIter;
6431 }
6432 isBorderFilterOn = toEnable ? 1 : 0;
6433 }
6434 else if (anArg == "-exitonclose")
6435 {
6436 Draw_ToExitOnCloseView = true;
6437 if (anArgIter + 1 < theArgNb
6438 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToExitOnCloseView))
6439 {
6440 ++anArgIter;
6441 }
6442 }
6443 else if (anArg == "-closeonescape"
6444 || anArg == "-closeonesc")
6445 {
6446 Draw_ToCloseViewOnEsc = true;
6447 if (anArgIter + 1 < theArgNb
6448 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToCloseViewOnEsc))
6449 {
6450 ++anArgIter;
6451 }
6452 }
6453 else if (anArgIter + 3 < theArgNb
6454 && anArg == "-display")
6455 {
6456 aViewName = theArgVec[++anArgIter];
6457 aPrsNameRef = theArgVec[++anArgIter];
6458 aPrsNameNew = theArgVec[++anArgIter];
6459 if (anArgIter + 1 < theArgNb
6460 && *theArgVec[anArgIter + 1] != '-')
6461 {
6462 aPrsNameDiff = theArgVec[++anArgIter];
6463 }
6464 }
6465 else if (aTolColor < 0.0
6466 && anArg.IsRealValue())
6467 {
6468 isOldSyntax = Standard_True;
6469 aTolColor = anArg.RealValue();
6470 if (aTolColor < 0.0 || aTolColor > 1.0)
6471 {
6472 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6473 return 1;
6474 }
6475 }
6476 else if (isOldSyntax
6477 && toBlackWhite == -1
6478 && (anArg == "0" || anArg == "1"))
6479 {
6480 toBlackWhite = anArg == "1" ? 1 : 0;
6481 }
6482 else if (isOldSyntax
6483 && isBorderFilterOn == -1
6484 && (anArg == "0" || anArg == "1"))
6485 {
6486 isBorderFilterOn = anArg == "1" ? 1 : 0;
6487 }
6488 else if (aDiffImagePath.IsEmpty())
6489 {
6490 aDiffImagePath = theArgVec[anArgIter];
6491 }
6492 else
6493 {
6494 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6495 return 1;
6496 }
6497 }
692613e5 6498
fd3f6bd0 6499 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
6500 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
6501 if (!anImgRef->Load (anImgPathRef))
6502 {
6503 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
6504 return 1;
6505 }
6506 if (!anImgNew->Load (anImgPathNew))
6507 {
6508 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
6509 return 1;
6510 }
692613e5 6511
6512 // compare the images
6513 Image_Diff aComparer;
fd3f6bd0 6514 Standard_Integer aDiffColorsNb = -1;
6515 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
692613e5 6516 {
fd3f6bd0 6517 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
6518 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
6519 aDiffColorsNb = aComparer.Compare();
6520 theDI << aDiffColorsNb << "\n";
692613e5 6521 }
6522
692613e5 6523 // save image of difference
fd3f6bd0 6524 Handle(Image_AlienPixMap) aDiff;
6525 if (aDiffColorsNb > 0
6526 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
6527 {
6528 aDiff = new Image_AlienPixMap();
6529 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
6530 {
6531 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
6532 return 1;
6533 }
6534 aComparer.SaveDiffImage (*aDiff);
6535 if (!aDiffImagePath.IsEmpty()
6536 && !aDiff->Save (aDiffImagePath))
6537 {
6538 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
6539 return 1;
6540 }
6541 }
6542
6543 if (aViewName.IsEmpty())
6544 {
6545 return 0;
6546 }
6547
6548 ViewerTest_Names aViewNames (aViewName);
6549 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
6550 {
6551 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
6552 theDI.Eval (aCommand.ToCString());
6553 }
6554
6555 Standard_Integer aPxLeft = 0;
6556 Standard_Integer aPxTop = 0;
6557 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
6558 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
6559 ? int(anImgRef->SizeY() * 2)
6560 : int(anImgRef->SizeY());
6561 TCollection_AsciiString aDisplayName;
9e04ccdc 6562 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
6563 aViewName, aDisplayName);
fd3f6bd0 6564
6565 Standard_Real aRatio = anImgRef->Ratio();
6566 Standard_Real aSizeX = 1.0;
6567 Standard_Real aSizeY = aSizeX / aRatio;
692613e5 6568 {
fd3f6bd0 6569 OSD_Path aPath (anImgPathRef);
6570 TCollection_AsciiString aLabelRef;
6571 if (!aPath.Name().IsEmpty())
6572 {
6573 aLabelRef = aPath.Name() + aPath.Extension();
6574 }
6575 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
6576
6577 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
6578 gp_Trsf aTrsfRef;
6579 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
6580 anImgRefPrs->SetLocalTransformation (aTrsfRef);
6581 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
692613e5 6582 }
fd3f6bd0 6583 {
6584 OSD_Path aPath (anImgPathNew);
6585 TCollection_AsciiString aLabelNew;
6586 if (!aPath.Name().IsEmpty())
6587 {
6588 aLabelNew = aPath.Name() + aPath.Extension();
6589 }
6590 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
692613e5 6591
fd3f6bd0 6592 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
6593 gp_Trsf aTrsfRef;
6594 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
6595 anImgNewPrs->SetLocalTransformation (aTrsfRef);
6596 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
6597 }
6598 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
6599 if (!aDiff.IsNull())
6600 {
6601 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
6602 gp_Trsf aTrsfDiff;
6603 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
6604 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
6605 }
6606 if (!aPrsNameDiff.IsEmpty())
6607 {
6608 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
6609 }
6610 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
6611 ViewerTest::CurrentView()->FitAll();
692613e5 6612 return 0;
6613}
6614
4754e164 6615//=======================================================================
6616//function : VSelect
6617//purpose : Emulates different types of selection by mouse:
6618// 1) single click selection
6619// 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
6620// 3) selection with polygon having corners at
dc3fe572 6621// pixel positions (x1,y1),...,(xn,yn)
4754e164 6622// 4) any of these selections with shift button pressed
6623//=======================================================================
6624static Standard_Integer VSelect (Draw_Interpretor& di,
6625 Standard_Integer argc,
6626 const char ** argv)
6627{
dc3fe572 6628 if(argc < 3)
4754e164 6629 {
586db386 6630 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
4754e164 6631 return 1;
6632 }
6633
6634 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
dc3fe572 6635 if(myAIScontext.IsNull())
4754e164 6636 {
6637 di << "use 'vinit' command before " << argv[0] << "\n";
6638 return 1;
6639 }
2157d6ac 6640
6641 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
6642 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
6643 TCollection_AsciiString anArg;
6644 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
6645 anArg.LowerCase();
6646 if (anArg == "-allowoverlap")
6647 {
6648 Standard_Boolean isValidated = isShiftSelection ? argc == 8
6649 : argc == 7;
6650 if (!isValidated)
6651 {
6652 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
6653 return 1;
6654 }
6655
6656 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
dde68833 6657 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
2157d6ac 6658 aCoordsNb -= 2;
6659 }
6660
4754e164 6661 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
6662 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
2157d6ac 6663 if(aCoordsNb == 2)
4754e164 6664 {
6665 if(isShiftSelection)
6666 aCurrentEventManager->ShiftSelect();
6667 else
6668 aCurrentEventManager->Select();
6669 }
2157d6ac 6670 else if(aCoordsNb == 4)
4754e164 6671 {
6672 if(isShiftSelection)
2157d6ac 6673 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
4754e164 6674 else
2157d6ac 6675 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
4754e164 6676 }
6677 else
6678 {
2157d6ac 6679 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
4754e164 6680
2157d6ac 6681 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
4754e164 6682 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
6683
6684 if(isShiftSelection)
6685 aCurrentEventManager->ShiftSelect(aPolyline);
6686 else
6687 aCurrentEventManager->Select(aPolyline);
6688 }
6689 return 0;
6690}
6691
6692//=======================================================================
6693//function : VMoveTo
dc3fe572 6694//purpose : Emulates cursor movement to defined pixel position
4754e164 6695//=======================================================================
8a590580 6696static Standard_Integer VMoveTo (Draw_Interpretor& ,
6697 Standard_Integer theNbArgs,
6698 const char** theArgVec)
4754e164 6699{
8a590580 6700 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
6701 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
6702 if (aContext.IsNull())
4754e164 6703 {
8a590580 6704 std::cout << "Error: no active View\n";
4754e164 6705 return 1;
6706 }
6707
8a590580 6708 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
6709 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4754e164 6710 {
8a590580 6711 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
6712 anArgStr.LowerCase();
6713 if (anArgStr == "-reset"
6714 || anArgStr == "-clear")
6715 {
6716 if (anArgIter + 1 < theNbArgs)
6717 {
6718 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
6719 return 1;
6720 }
6721
6722 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
6723 && aContext->CurrentViewer()->GridEcho();
6724 if (toEchoGrid)
6725 {
6726 aContext->CurrentViewer()->HideGridEcho (aView);
6727 }
6728 if (aContext->ClearDetected() || toEchoGrid)
6729 {
6730 aContext->CurrentViewer()->RedrawImmediate();
6731 }
6732 return 0;
6733 }
6734 else if (aMousePos.x() == IntegerLast()
6735 && anArgStr.IsIntegerValue())
6736 {
6737 aMousePos.x() = anArgStr.IntegerValue();
6738 }
6739 else if (aMousePos.y() == IntegerLast()
6740 && anArgStr.IsIntegerValue())
6741 {
6742 aMousePos.y() = anArgStr.IntegerValue();
6743 }
6744 else
6745 {
6746 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6747 return 1;
6748 }
6749 }
6750
6751 if (aMousePos.x() == IntegerLast()
6752 || aMousePos.y() == IntegerLast())
6753 {
6754 std::cout << "Syntax error: wrong number of arguments\n";
4754e164 6755 return 1;
6756 }
8a590580 6757
6758 ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y());
4754e164 6759 return 0;
6760}
6761
1beb58d7 6762namespace
6763{
6764 //! Global map storing all animations registered in ViewerTest.
6765 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
6766
6767 //! The animation calling the Draw Harness command.
6768 class ViewerTest_AnimationProc : public AIS_Animation
6769 {
6770 public:
6771
6772 //! Main constructor.
6773 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6774 Draw_Interpretor* theDI,
6775 const TCollection_AsciiString& theCommand)
6776 : AIS_Animation (theAnimationName),
6777 myDrawInter(theDI),
6778 myCommand (theCommand)
6779 {
6780 //
6781 }
6782
6783 protected:
6784
6785 //! Evaluate the command.
6786 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6787 {
6788 TCollection_AsciiString aCmd = myCommand;
6789 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6790 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6791 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6792 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6793 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6794 myDrawInter->Eval (aCmd.ToCString());
6795 }
6796
6797 //! Find the keyword in the command and replace it with value.
6798 //! @return the position of the keyword to pass value
6799 void replace (TCollection_AsciiString& theCmd,
6800 const TCollection_AsciiString& theKey,
6801 const TCollection_AsciiString& theVal)
6802 {
6803 TCollection_AsciiString aCmd (theCmd);
6804 aCmd.LowerCase();
6805 const Standard_Integer aPos = aCmd.Search (theKey);
6806 if (aPos == -1)
6807 {
6808 return;
6809 }
6810
6811 TCollection_AsciiString aPart1, aPart2;
6812 Standard_Integer aPart1To = aPos - 1;
6813 if (aPart1To >= 1
6814 && aPart1To <= theCmd.Length())
6815 {
6816 aPart1 = theCmd.SubString (1, aPart1To);
6817 }
6818
6819 Standard_Integer aPart2From = aPos + theKey.Length();
6820 if (aPart2From >= 1
6821 && aPart2From <= theCmd.Length())
6822 {
6823 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
6824 }
6825
6826 theCmd = aPart1 + theVal + aPart2;
6827 }
6828
6829 protected:
6830
6831 Draw_Interpretor* myDrawInter;
6832 TCollection_AsciiString myCommand;
6833
6834 };
6835
6836 //! Replace the animation with the new one.
6837 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
6838 Handle(AIS_Animation)& theAnimation,
6839 const Handle(AIS_Animation)& theAnimationNew)
6840 {
6841 theAnimationNew->CopyFrom (theAnimation);
6842 if (!theParentAnimation.IsNull())
6843 {
6844 theParentAnimation->Replace (theAnimation, theAnimationNew);
6845 }
6846 else
6847 {
6848 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
6849 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
6850 }
6851 theAnimation = theAnimationNew;
6852 }
6853
6854 //! Parse the point.
6855 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
6856 {
6857 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
6858 if (!anXYZ[0].IsRealValue()
6859 || !anXYZ[1].IsRealValue()
6860 || !anXYZ[2].IsRealValue())
6861 {
6862 return Standard_False;
6863 }
6864
6865 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
6866 return Standard_True;
6867 }
6868
6869 //! Parse the quaternion.
6870 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
6871 {
6872 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
6873 if (!anXYZW[0].IsRealValue()
6874 || !anXYZW[1].IsRealValue()
6875 || !anXYZW[2].IsRealValue()
6876 || !anXYZW[3].IsRealValue())
6877 {
6878 return Standard_False;
6879 }
6880
6881 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
6882 return Standard_True;
6883 }
6884
08f8a185 6885 //! Auxiliary class for flipping image upside-down.
6886 class ImageFlipper
6887 {
6888 public:
6889
6890 //! Empty constructor.
6891 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
6892
6893 //! Perform flipping.
6894 Standard_Boolean FlipY (Image_PixMap& theImage)
6895 {
6896 if (theImage.IsEmpty()
6897 || theImage.SizeX() == 0
6898 || theImage.SizeY() == 0)
6899 {
6900 return Standard_False;
6901 }
6902
6903 const Standard_Size aRowSize = theImage.SizeRowBytes();
6904 if (myTmp.Size() < aRowSize
6905 && !myTmp.Allocate (aRowSize))
6906 {
6907 return Standard_False;
6908 }
6909
6910 // for odd height middle row should be left as is
6911 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
6912 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
6913 {
6914 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
6915 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
6916 memcpy (myTmp.ChangeData(), aTop, aRowSize);
6917 memcpy (aTop, aBot, aRowSize);
6918 memcpy (aBot, myTmp.Data(), aRowSize);
6919 }
6920 return Standard_True;
6921 }
6922
6923 private:
6924 NCollection_Buffer myTmp;
6925 };
6926
1beb58d7 6927}
6928
197ac94e 6929//=================================================================================================
4754e164 6930//function : VViewParams
dc3fe572 6931//purpose : Gets or sets AIS View characteristics
197ac94e 6932//=================================================================================================
6933static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4754e164 6934{
1beb58d7 6935 Handle(V3d_View) aView = ViewerTest::CurrentView();
6936 if (aView.IsNull())
4754e164 6937 {
197ac94e 6938 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
4754e164 6939 return 1;
6940 }
197ac94e 6941
1beb58d7 6942 Standard_Boolean toSetProj = Standard_False;
6943 Standard_Boolean toSetUp = Standard_False;
6944 Standard_Boolean toSetAt = Standard_False;
6945 Standard_Boolean toSetEye = Standard_False;
6946 Standard_Boolean toSetScale = Standard_False;
6947 Standard_Boolean toSetSize = Standard_False;
6948 Standard_Boolean toSetCenter2d = Standard_False;
ee2be2a8 6949 Standard_Real aViewScale = aView->Scale();
6950 Standard_Real aViewSize = 1.0;
1beb58d7 6951 Graphic3d_Vec2i aCenter2d;
6952 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
6953 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
6954 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
6955 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
6956 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
197ac94e 6957 if (theArgsNb == 1)
4754e164 6958 {
197ac94e 6959 // print all of the available view parameters
1beb58d7 6960 char aText[4096];
6961 Sprintf (aText,
6962 "Scale: %g\n"
6963 "Proj: %12g %12g %12g\n"
6964 "Up: %12g %12g %12g\n"
6965 "At: %12g %12g %12g\n"
6966 "Eye: %12g %12g %12g\n",
6967 aViewScale,
6968 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6969 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6970 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
6971 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6972 theDi << aText;
197ac94e 6973 return 0;
4754e164 6974 }
197ac94e 6975
1beb58d7 6976 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
6977 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
197ac94e 6978 {
1beb58d7 6979 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6980 anArg.LowerCase();
6981 if (anUpdateTool.parseRedrawMode (anArg))
197ac94e 6982 {
197ac94e 6983 continue;
6984 }
1beb58d7 6985 else if (anArg == "-cmd"
6986 || anArg == "-command"
6987 || anArg == "-args")
6988 {
6989 char aText[4096];
6990 Sprintf (aText,
6991 "-scale %g "
6992 "-proj %g %g %g "
6993 "-up %g %g %g "
6994 "-at %g %g %g\n",
6995 aViewScale,
6996 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6997 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6998 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6999 theDi << aText;
7000 }
7001 else if (anArg == "-scale"
7002 || anArg == "-size")
7003 {
7004 if (anArgIter + 1 < theArgsNb
7005 && *theArgVec[anArgIter + 1] != '-')
7006 {
7007 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
7008 if (aValueArg.IsRealValue())
7009 {
7010 ++anArgIter;
7011 if (anArg == "-scale")
7012 {
7013 toSetScale = Standard_True;
7014 aViewScale = aValueArg.RealValue();
7015 }
7016 else if (anArg == "-size")
7017 {
7018 toSetSize = Standard_True;
7019 aViewSize = aValueArg.RealValue();
7020 }
7021 continue;
7022 }
7023 }
7024 if (anArg == "-scale")
7025 {
7026 theDi << "Scale: " << aView->Scale() << "\n";
7027 }
7028 else if (anArg == "-size")
7029 {
7030 Graphic3d_Vec2d aSizeXY;
7031 aView->Size (aSizeXY.x(), aSizeXY.y());
7032 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
7033 }
7034 }
7035 else if (anArg == "-eye"
7036 || anArg == "-at"
7037 || anArg == "-up"
7038 || anArg == "-proj")
7039 {
7040 if (anArgIter + 3 < theArgsNb)
7041 {
7042 gp_XYZ anXYZ;
7043 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
7044 {
7045 anArgIter += 3;
7046 if (anArg == "-eye")
7047 {
7048 toSetEye = Standard_True;
7049 aViewEye = anXYZ;
7050 }
7051 else if (anArg == "-at")
7052 {
7053 toSetAt = Standard_True;
7054 aViewAt = anXYZ;
7055 }
7056 else if (anArg == "-up")
7057 {
7058 toSetUp = Standard_True;
7059 aViewUp = anXYZ;
7060 }
7061 else if (anArg == "-proj")
7062 {
7063 toSetProj = Standard_True;
7064 aViewProj = anXYZ;
7065 }
7066 continue;
7067 }
7068 }
197ac94e 7069
1beb58d7 7070 if (anArg == "-eye")
7071 {
7072 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
7073 }
7074 else if (anArg == "-at")
7075 {
7076 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
7077 }
7078 else if (anArg == "-up")
7079 {
7080 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
7081 }
7082 else if (anArg == "-proj")
7083 {
7084 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
7085 }
7086 }
7087 else if (anArg == "-center")
3dfe95cd 7088 {
1beb58d7 7089 if (anArgIter + 2 < theArgsNb)
7090 {
7091 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
7092 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
7093 if (anX.IsIntegerValue()
7094 && anY.IsIntegerValue())
7095 {
7096 toSetCenter2d = Standard_True;
7097 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
7098 }
7099 }
7100 }
7101 else
7102 {
7103 std::cout << "Syntax error at '" << anArg << "'\n";
3dfe95cd 7104 return 1;
7105 }
1beb58d7 7106 }
3dfe95cd 7107
1beb58d7 7108 // change view parameters in proper order
7109 if (toSetScale)
7110 {
7111 aView->SetScale (aViewScale);
7112 }
7113 if (toSetSize)
7114 {
7115 aView->SetSize (aViewSize);
7116 }
7117 if (toSetEye)
7118 {
7119 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7120 }
7121 if (toSetAt)
7122 {
7123 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7124 }
7125 if (toSetProj)
7126 {
7127 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
7128 }
7129 if (toSetUp)
7130 {
7131 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
7132 }
7133 if (toSetCenter2d)
7134 {
7135 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
197ac94e 7136 }
7137
1beb58d7 7138 return 0;
7139}
197ac94e 7140
2e93433e 7141//==============================================================================
7142//function : V2DMode
7143//purpose :
7144//==============================================================================
7145static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
7146{
7147 bool is2dMode = true;
7148 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
7149 if (aV3dView.IsNull())
7150 {
7151 std::cout << "Error: no active view.\n";
7152 return 1;
7153 }
7154 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7155 {
7156 const TCollection_AsciiString anArg = theArgVec[anArgIt];
7157 TCollection_AsciiString anArgCase = anArg;
7158 anArgCase.LowerCase();
7159 if (anArgIt + 1 < theArgsNb
7160 && anArgCase == "-name")
7161 {
7162 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
7163 TCollection_AsciiString aViewName = aViewNames.GetViewName();
7164 if (!ViewerTest_myViews.IsBound1 (aViewName))
7165 {
7166 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
7167 return 1;
7168 }
7169 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
7170 }
7171 else if (anArgCase == "-mode")
7172 {
7173 if (anArgIt + 1 < theArgsNb
7174 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
7175 {
7176 ++anArgIt;
7177 }
7178 }
7179 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
7180 {
7181 //
7182 }
7183 else
7184 {
7185 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
7186 return 1;
7187 }
7188 }
7189
7190 aV3dView->SetView2DMode (is2dMode);
7191 return 0;
7192}
7193
1beb58d7 7194//==============================================================================
7195//function : VAnimation
7196//purpose :
7197//==============================================================================
7198static Standard_Integer VAnimation (Draw_Interpretor& theDI,
7199 Standard_Integer theArgNb,
7200 const char** theArgVec)
7201{
7202 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
7203 if (theArgNb < 2)
4754e164 7204 {
1beb58d7 7205 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
7206 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
7207 {
7208 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
197ac94e 7209 }
1beb58d7 7210 return 0;
7211 }
7212 if (aCtx.IsNull())
7213 {
7214 std::cout << "Error: no active view\n";
7215 return 1;
4754e164 7216 }
197ac94e 7217
1beb58d7 7218 Standard_Integer anArgIter = 1;
7219 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
7220 if (aNameArg.IsEmpty())
7221 {
7222 std::cout << "Syntax error: animation name is not defined.\n";
7223 return 1;
7224 }
7225
7226 TCollection_AsciiString aNameArgLower = aNameArg;
7227 aNameArgLower.LowerCase();
7228 if (aNameArgLower == "-reset"
7229 || aNameArgLower == "-clear")
7230 {
7231 ViewerTest_AnimationTimelineMap.Clear();
7232 return 0;
7233 }
7234 else if (aNameArg.Value (1) == '-')
7235 {
7236 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
7237 return 1;
7238 }
197ac94e 7239
1beb58d7 7240 const char* aNameSplitter = "/";
7241 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
7242 if (aSplitPos == -1)
197ac94e 7243 {
1beb58d7 7244 aNameSplitter = ".";
7245 aSplitPos = aNameArg.Search (aNameSplitter);
7246 }
7247
7248 // find existing or create a new animation by specified name within syntax "parent.child".
7249 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
7250 for (; !aNameArg.IsEmpty();)
7251 {
7252 TCollection_AsciiString aNameParent;
7253 if (aSplitPos != -1)
197ac94e 7254 {
1beb58d7 7255 if (aSplitPos == aNameArg.Length())
7256 {
7257 std::cout << "Syntax error: animation name is not defined.\n";
7258 return 1;
7259 }
7260
7261 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
7262 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
7263
7264 aSplitPos = aNameArg.Search (aNameSplitter);
197ac94e 7265 }
7266 else
7267 {
1beb58d7 7268 aNameParent = aNameArg;
7269 aNameArg.Clear();
197ac94e 7270 }
1beb58d7 7271
7272 if (anAnimation.IsNull())
3dfe95cd 7273 {
1beb58d7 7274 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
7275 {
7276 anAnimation = new AIS_Animation (aNameParent);
7277 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
7278 }
7279 aRootAnimation = anAnimation;
3dfe95cd 7280 }
7281 else
7282 {
1beb58d7 7283 aParentAnimation = anAnimation;
7284 anAnimation = aParentAnimation->Find (aNameParent);
7285 if (anAnimation.IsNull())
7286 {
7287 anAnimation = new AIS_Animation (aNameParent);
7288 aParentAnimation->Add (anAnimation);
7289 }
3dfe95cd 7290 }
7291 }
1beb58d7 7292
7293 if (anArgIter >= theArgNb)
197ac94e 7294 {
1beb58d7 7295 // just print the list of children
7296 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
197ac94e 7297 {
1beb58d7 7298 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
197ac94e 7299 }
1beb58d7 7300 return 0;
197ac94e 7301 }
1beb58d7 7302
bf7b2ceb 7303 // animation parameters
1beb58d7 7304 Standard_Boolean toPlay = Standard_False;
7305 Standard_Real aPlaySpeed = 1.0;
7306 Standard_Real aPlayStartTime = anAnimation->StartPts();
7307 Standard_Real aPlayDuration = anAnimation->Duration();
1beb58d7 7308 Standard_Boolean isFreeCamera = Standard_False;
7309 Standard_Boolean isLockLoop = Standard_False;
08f8a185 7310
7311 // video recording parameters
7312 TCollection_AsciiString aRecFile;
7313 Image_VideoParams aRecParams;
7314
1beb58d7 7315 Handle(V3d_View) aView = ViewerTest::CurrentView();
7316 for (; anArgIter < theArgNb; ++anArgIter)
197ac94e 7317 {
1beb58d7 7318 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7319 anArg.LowerCase();
bf7b2ceb 7320 // general options
1beb58d7 7321 if (anArg == "-reset"
7322 || anArg == "-clear")
197ac94e 7323 {
1beb58d7 7324 anAnimation->Clear();
7325 }
7326 else if (anArg == "-remove"
7327 || anArg == "-del"
7328 || anArg == "-delete")
7329 {
7330 if (!aParentAnimation.IsNull())
7331 {
7332 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
7333 }
7334 else
7335 {
7336 aParentAnimation->Remove (anAnimation);
7337 }
7338 }
bf7b2ceb 7339 // playback options
1beb58d7 7340 else if (anArg == "-play")
7341 {
7342 toPlay = Standard_True;
7343 if (++anArgIter < theArgNb)
7344 {
7345 if (*theArgVec[anArgIter] == '-')
7346 {
7347 --anArgIter;
7348 continue;
7349 }
7350 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
7351
7352 if (++anArgIter < theArgNb)
7353 {
7354 if (*theArgVec[anArgIter] == '-')
7355 {
7356 --anArgIter;
7357 continue;
7358 }
7359 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7360 }
7361 }
7362 }
7363 else if (anArg == "-resume")
7364 {
7365 toPlay = Standard_True;
7366 aPlayStartTime = anAnimation->ElapsedTime();
7367 if (++anArgIter < theArgNb)
7368 {
7369 if (*theArgVec[anArgIter] == '-')
7370 {
7371 --anArgIter;
7372 continue;
7373 }
7374
7375 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7376 }
7377 }
7378 else if (anArg == "-playspeed"
7379 || anArg == "-speed")
7380 {
7381 if (++anArgIter >= theArgNb)
7382 {
7383 std::cout << "Syntax error at " << anArg << ".\n";
7384 return 1;
7385 }
7386 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
7387 }
7388 else if (anArg == "-lock"
7389 || anArg == "-lockloop"
7390 || anArg == "-playlockloop")
7391 {
7392 isLockLoop = Standard_True;
7393 }
7394 else if (anArg == "-freecamera"
7395 || anArg == "-playfreecamera"
7396 || anArg == "-freelook")
7397 {
7398 isFreeCamera = Standard_True;
7399 }
08f8a185 7400 // video recodring options
7401 else if (anArg == "-rec"
7402 || anArg == "-record")
7403 {
7404 if (++anArgIter >= theArgNb)
7405 {
7406 std::cout << "Syntax error at " << anArg << ".\n";
7407 return 1;
7408 }
7409
7410 aRecFile = theArgVec[anArgIter];
7411 if (aRecParams.FpsNum <= 0)
7412 {
7413 aRecParams.FpsNum = 24;
7414 }
7415
7416 if (anArgIter + 2 < theArgNb
7417 && *theArgVec[anArgIter + 1] != '-'
7418 && *theArgVec[anArgIter + 2] != '-')
7419 {
7420 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
7421 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
7422 if (aWidthArg .IsIntegerValue()
7423 && aHeightArg.IsIntegerValue())
7424 {
7425 aRecParams.Width = aWidthArg .IntegerValue();
7426 aRecParams.Height = aHeightArg.IntegerValue();
7427 anArgIter += 2;
7428 }
7429 }
7430 }
1beb58d7 7431 else if (anArg == "-fps")
7432 {
7433 if (++anArgIter >= theArgNb)
7434 {
7435 std::cout << "Syntax error at " << anArg << ".\n";
7436 return 1;
7437 }
bf7b2ceb 7438
7439 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
7440 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
7441 if (aSplitIndex == 0)
7442 {
08f8a185 7443 aRecParams.FpsNum = aFpsArg.IntegerValue();
bf7b2ceb 7444 }
7445 else
7446 {
7447 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
7448 aFpsArg.Split (aFpsArg.Length() - 1);
7449 const TCollection_AsciiString aNumStr = aFpsArg;
08f8a185 7450 aRecParams.FpsNum = aNumStr.IntegerValue();
7451 aRecParams.FpsDen = aDenStr.IntegerValue();
7452 if (aRecParams.FpsDen < 1)
bf7b2ceb 7453 {
7454 std::cout << "Syntax error at " << anArg << ".\n";
7455 return 1;
7456 }
7457 }
1beb58d7 7458 }
08f8a185 7459 else if (anArg == "-format")
7460 {
7461 if (++anArgIter >= theArgNb)
7462 {
7463 std::cout << "Syntax error at " << anArg << ".\n";
7464 return 1;
7465 }
7466 aRecParams.Format = theArgVec[anArgIter];
7467 }
7468 else if (anArg == "-pix_fmt"
7469 || anArg == "-pixfmt"
7470 || anArg == "-pixelformat")
7471 {
7472 if (++anArgIter >= theArgNb)
7473 {
7474 std::cout << "Syntax error at " << anArg << ".\n";
7475 return 1;
7476 }
7477 aRecParams.PixelFormat = theArgVec[anArgIter];
7478 }
7479 else if (anArg == "-codec"
7480 || anArg == "-vcodec"
7481 || anArg == "-videocodec")
7482 {
7483 if (++anArgIter >= theArgNb)
7484 {
7485 std::cout << "Syntax error at " << anArg << ".\n";
7486 return 1;
7487 }
7488 aRecParams.VideoCodec = theArgVec[anArgIter];
7489 }
7490 else if (anArg == "-crf"
7491 || anArg == "-preset"
7492 || anArg == "-qp")
7493 {
7494 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
7495 if (++anArgIter >= theArgNb)
7496 {
7497 std::cout << "Syntax error at " << anArg << ".\n";
7498 return 1;
7499 }
7500
7501 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
7502 }
bf7b2ceb 7503 // animation definition options
1beb58d7 7504 else if (anArg == "-start"
7505 || anArg == "-starttime"
7506 || anArg == "-startpts")
7507 {
7508 if (++anArgIter >= theArgNb)
7509 {
7510 std::cout << "Syntax error at " << anArg << ".\n";
7511 return 1;
7512 }
7513
7514 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
7515 aRootAnimation->UpdateTotalDuration();
7516 }
7517 else if (anArg == "-end"
7518 || anArg == "-endtime"
7519 || anArg == "-endpts")
7520 {
7521 if (++anArgIter >= theArgNb)
7522 {
7523 std::cout << "Syntax error at " << anArg << ".\n";
7524 return 1;
7525 }
7526
7527 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
7528 aRootAnimation->UpdateTotalDuration();
7529 }
7530 else if (anArg == "-dur"
7531 || anArg == "-duration")
7532 {
7533 if (++anArgIter >= theArgNb)
7534 {
7535 std::cout << "Syntax error at " << anArg << ".\n";
7536 return 1;
7537 }
7538
7539 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
7540 aRootAnimation->UpdateTotalDuration();
7541 }
7542 else if (anArg == "-command"
7543 || anArg == "-cmd"
7544 || anArg == "-invoke"
7545 || anArg == "-eval"
7546 || anArg == "-proc")
7547 {
7548 if (++anArgIter >= theArgNb)
7549 {
7550 std::cout << "Syntax error at " << anArg << ".\n";
7551 return 1;
7552 }
7553
7554 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
7555 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
7556 }
7557 else if (anArg == "-objecttrsf"
7558 || anArg == "-objectransformation"
7559 || anArg == "-objtransformation"
7560 || anArg == "-objtrsf"
7561 || anArg == "-object"
7562 || anArg == "-obj")
7563 {
7564 if (++anArgIter >= theArgNb)
7565 {
7566 std::cout << "Syntax error at " << anArg << ".\n";
7567 return 1;
7568 }
7569
7570 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
7571 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
8f521168 7572 Handle(AIS_InteractiveObject) anObject;
7573 if (!aMapOfAIS.Find2 (anObjName, anObject))
1beb58d7 7574 {
7575 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
7576 return 1;
7577 }
7578
1beb58d7 7579 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
7580 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
7581 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
7582 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
7583 Standard_Boolean isTrsfSet = Standard_False;
7584 Standard_Integer aTrsfArgIter = anArgIter + 1;
7585 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
7586 {
7587 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
7588 aTrsfArg.LowerCase();
7589 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
7590 if (aTrsfArg.StartsWith ("-rotation")
7591 || aTrsfArg.StartsWith ("-rot"))
7592 {
7593 isTrsfSet = Standard_True;
7594 if (aTrsfArgIter + 4 >= theArgNb
7595 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
7596 {
7597 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7598 return 1;
7599 }
7600 aTrsfArgIter += 4;
7601 }
7602 else if (aTrsfArg.StartsWith ("-location")
7603 || aTrsfArg.StartsWith ("-loc"))
7604 {
7605 isTrsfSet = Standard_True;
7606 if (aTrsfArgIter + 3 >= theArgNb
7607 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
7608 {
7609 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7610 return 1;
7611 }
7612 aTrsfArgIter += 3;
7613 }
7614 else if (aTrsfArg.StartsWith ("-scale"))
7615 {
7616 isTrsfSet = Standard_True;
7617 if (++aTrsfArgIter >= theArgNb)
7618 {
7619 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7620 return 1;
7621 }
7622
7623 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
7624 if (!aScaleStr.IsRealValue())
7625 {
7626 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7627 return 1;
7628 }
7629 aScales[anIndex] = aScaleStr.RealValue();
7630 }
7631 else
7632 {
7633 anArgIter = aTrsfArgIter - 1;
7634 break;
7635 }
7636 }
7637 if (!isTrsfSet)
7638 {
7639 std::cout << "Syntax error at " << anArg << ".\n";
7640 return 1;
7641 }
7642 else if (aTrsfArgIter >= theArgNb)
7643 {
7644 anArgIter = theArgNb;
7645 }
7646
7647 aTrsfs[0].SetRotation (aRotQuats[0]);
7648 aTrsfs[1].SetRotation (aRotQuats[1]);
7649 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
7650 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
7651 aTrsfs[0].SetScaleFactor (aScales[0]);
7652 aTrsfs[1].SetScaleFactor (aScales[1]);
7653
7654 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
7655 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
7656 }
7657 else if (anArg == "-viewtrsf"
7658 || anArg == "-view")
7659 {
7660 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
7661 if (aCamAnimation.IsNull())
7662 {
7663 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
7664 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
7665 }
7666
7667 Handle(Graphic3d_Camera) aCams[2] =
7668 {
7669 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
7670 new Graphic3d_Camera (aCamAnimation->View()->Camera())
7671 };
7672
7673 Standard_Boolean isTrsfSet = Standard_False;
7674 Standard_Integer aViewArgIter = anArgIter + 1;
7675 for (; aViewArgIter < theArgNb; ++aViewArgIter)
7676 {
7677 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
7678 aViewArg.LowerCase();
7679 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
7680 if (aViewArg.StartsWith ("-scale"))
7681 {
7682 isTrsfSet = Standard_True;
7683 if (++aViewArgIter >= theArgNb)
7684 {
7685 std::cout << "Syntax error at " << anArg << ".\n";
7686 return 1;
7687 }
7688
7689 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
7690 if (!aScaleStr.IsRealValue())
7691 {
7692 std::cout << "Syntax error at " << aViewArg << ".\n";
7693 return 1;
7694 }
7695 Standard_Real aScale = aScaleStr.RealValue();
7696 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
7697 aCams[anIndex]->SetScale (aScale);
7698 }
7699 else if (aViewArg.StartsWith ("-eye")
7700 || aViewArg.StartsWith ("-center")
7701 || aViewArg.StartsWith ("-at")
7702 || aViewArg.StartsWith ("-up"))
7703 {
7704 isTrsfSet = Standard_True;
7705 gp_XYZ anXYZ;
7706 if (aViewArgIter + 3 >= theArgNb
7707 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
7708 {
7709 std::cout << "Syntax error at " << aViewArg << ".\n";
7710 return 1;
7711 }
7712 aViewArgIter += 3;
7713
7714 if (aViewArg.StartsWith ("-eye"))
7715 {
7716 aCams[anIndex]->SetEye (anXYZ);
7717 }
7718 else if (aViewArg.StartsWith ("-center")
7719 || aViewArg.StartsWith ("-at"))
7720 {
7721 aCams[anIndex]->SetCenter (anXYZ);
7722 }
7723 else if (aViewArg.StartsWith ("-up"))
7724 {
7725 aCams[anIndex]->SetUp (anXYZ);
7726 }
7727 }
7728 else
7729 {
7730 anArgIter = aViewArgIter - 1;
7731 break;
7732 }
7733 }
7734 if (!isTrsfSet)
7735 {
7736 std::cout << "Syntax error at " << anArg << ".\n";
7737 return 1;
7738 }
7739 else if (aViewArgIter >= theArgNb)
7740 {
7741 anArgIter = theArgNb;
7742 }
7743
7744 aCamAnimation->SetCameraStart(aCams[0]);
7745 aCamAnimation->SetCameraEnd (aCams[1]);
197ac94e 7746 }
7747 else
7748 {
1beb58d7 7749 std::cout << "Syntax error at " << anArg << ".\n";
7750 return 1;
197ac94e 7751 }
7752 }
1beb58d7 7753
08f8a185 7754 if (!toPlay && aRecFile.IsEmpty())
197ac94e 7755 {
1beb58d7 7756 return 0;
7757 }
7758
7759 // Start animation timeline and process frame updating.
7760 TheIsAnimating = Standard_True;
7761 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
7762 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
bf7b2ceb 7763 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
1beb58d7 7764 if (isFreeCamera)
7765 {
7766 aView->Camera()->Copy (aCameraBack);
7767 }
7768
7769 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
08f8a185 7770 if (aRecParams.FpsNum <= 0)
1beb58d7 7771 {
7772 while (!anAnimation->IsStopped())
197ac94e 7773 {
1beb58d7 7774 aCameraBack->Copy (aView->Camera());
7775 const Standard_Real aPts = anAnimation->UpdateTimer();
7776 if (isFreeCamera)
7777 {
7778 aView->Camera()->Copy (aCameraBack);
7779 }
7780
7781 if (aPts >= anUpperPts)
7782 {
7783 anAnimation->Pause();
7784 break;
7785 }
7786
7787 if (aView->IsInvalidated())
7788 {
7789 aView->Redraw();
7790 }
7791 else
7792 {
7793 aView->RedrawImmediate();
7794 }
7795
7796 if (!isLockLoop)
7797 {
7798 // handle user events
7799 theDI.Eval ("after 1 set waiter 1");
7800 theDI.Eval ("vwait waiter");
7801 }
7802 if (!TheIsAnimating)
7803 {
7804 anAnimation->Pause();
7805 theDI << aPts;
7806 break;
7807 }
7808 }
7809
7810 if (aView->IsInvalidated())
7811 {
7812 aView->Redraw();
197ac94e 7813 }
7814 else
7815 {
1beb58d7 7816 aView->RedrawImmediate();
197ac94e 7817 }
7818 }
1beb58d7 7819 else
197ac94e 7820 {
bf7b2ceb 7821 OSD_Timer aPerfTimer;
7822 aPerfTimer.Start();
1beb58d7 7823
08f8a185 7824 Handle(Image_VideoRecorder) aRecorder;
7825 ImageFlipper aFlipper;
7826 Handle(Draw_ProgressIndicator) aProgress;
7827 if (!aRecFile.IsEmpty())
7828 {
7829 if (aRecParams.Width <= 0
7830 || aRecParams.Height <= 0)
7831 {
7832 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
7833 }
7834
7835 aRecorder = new Image_VideoRecorder();
7836 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
7837 {
7838 std::cout << "Error: failed to open video file for recording\n";
7839 return 0;
7840 }
7841
7842 aProgress = new Draw_ProgressIndicator (theDI, 1);
7843 }
7844
1beb58d7 7845 // Manage frame-rated animation here
7846 Standard_Real aPts = aPlayStartTime;
bf7b2ceb 7847 int64_t aNbFrames = 0;
08f8a185 7848 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
7849 Standard_Integer aSecondsProgress = 0;
7850 for (; aPts <= anUpperPts && aPSentry.More();)
197ac94e 7851 {
08f8a185 7852 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
bf7b2ceb 7853 aPts = aPlayStartTime + aRecPts;
7854 ++aNbFrames;
1beb58d7 7855 if (!anAnimation->Update (aPts))
7856 {
7857 break;
7858 }
7859
08f8a185 7860 if (!aRecorder.IsNull())
7861 {
7862 V3d_ImageDumpOptions aDumpParams;
7863 aDumpParams.Width = aRecParams.Width;
7864 aDumpParams.Height = aRecParams.Height;
7865 aDumpParams.BufferType = Graphic3d_BT_RGBA;
7866 aDumpParams.StereoOptions = V3d_SDO_MONO;
7867 aDumpParams.ToAdjustAspect = Standard_True;
7868 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
7869 {
7870 std::cout << "Error: view dump is failed!\n";
7871 return 0;
7872 }
7873 aFlipper.FlipY (aRecorder->ChangeFrame());
7874 if (!aRecorder->PushFrame())
7875 {
7876 return 0;
7877 }
7878 }
7879 else
7880 {
7881 aView->Redraw();
7882 }
7883
7884 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
7885 {
7886 aPSentry.Next();
7887 ++aSecondsProgress;
7888 }
197ac94e 7889 }
bf7b2ceb 7890
7891 aPerfTimer.Stop();
1beb58d7 7892 anAnimation->Stop();
bf7b2ceb 7893 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
7894 theDI << "Average FPS: " << aRecFps << "\n"
7895 << "Nb. Frames: " << Standard_Real(aNbFrames);
7896
7897 aView->Redraw();
197ac94e 7898 }
7899
1beb58d7 7900 aView->SetImmediateUpdate (wasImmediateUpdate);
7901 TheIsAnimating = Standard_False;
4754e164 7902 return 0;
7903}
7904
1beb58d7 7905
4754e164 7906//=======================================================================
7907//function : VChangeSelected
dc3fe572 7908//purpose : Adds the shape to selection or remove one from it
4754e164 7909//=======================================================================
7910static Standard_Integer VChangeSelected (Draw_Interpretor& di,
7911 Standard_Integer argc,
7912 const char ** argv)
7913{
7914 if(argc != 2)
7915 {
7916 di<<"Usage : " << argv[0] << " shape \n";
7917 return 1;
7918 }
7919 //get AIS_Shape:
4754e164 7920 TCollection_AsciiString aName(argv[1]);
7921 Handle(AIS_InteractiveObject) anAISObject;
8f521168 7922 if (!GetMapOfAIS().Find2 (aName, anAISObject)
7923 || anAISObject.IsNull())
4754e164 7924 {
7925 di<<"Use 'vdisplay' before";
7926 return 1;
7927 }
4754e164 7928
8f521168 7929 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
4754e164 7930 return 0;
7931}
7932
4754e164 7933//=======================================================================
7934//function : VNbSelected
dc3fe572 7935//purpose : Returns number of selected objects
4754e164 7936//=======================================================================
7937static Standard_Integer VNbSelected (Draw_Interpretor& di,
7938 Standard_Integer argc,
7939 const char ** argv)
7940{
7941 if(argc != 1)
7942 {
7943 di << "Usage : " << argv[0] << "\n";
7944 return 1;
7945 }
7946 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7947 if(aContext.IsNull())
7948 {
7949 di << "use 'vinit' command before " << argv[0] << "\n";
7950 return 1;
7951 }
7952 di << aContext->NbSelected() << "\n";
7953 return 0;
7954}
7955
4754e164 7956//=======================================================================
7957//function : VPurgeDisplay
dc3fe572 7958//purpose : Switches altialiasing on or off
4754e164 7959//=======================================================================
7960static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
7961 Standard_Integer argc,
7962 const char ** argv)
7963{
eb4320f2 7964 if (argc > 1)
4754e164 7965 {
eb4320f2 7966 di << "Usage : " << argv[0] << "\n";
4754e164 7967 return 1;
7968 }
4754e164 7969 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7970 if (aContext.IsNull())
7971 {
7972 di << "use 'vinit' command before " << argv[0] << "\n";
7973 return 1;
7974 }
404c8936 7975
eb4320f2 7976 di << aContext->PurgeDisplay() << "\n";
4754e164 7977 return 0;
7978}
7979
7980//=======================================================================
7981//function : VSetViewSize
7982//purpose :
7983//=======================================================================
7984static Standard_Integer VSetViewSize (Draw_Interpretor& di,
7985 Standard_Integer argc,
7986 const char ** argv)
7987{
7988 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7989 if(aContext.IsNull())
7990 {
7991 di << "use 'vinit' command before " << argv[0] << "\n";
7992 return 1;
7993 }
7994 if(argc != 2)
7995 {
7996 di<<"Usage : " << argv[0] << " Size\n";
7997 return 1;
7998 }
6b62b2da 7999 Standard_Real aSize = Draw::Atof (argv[1]);
4754e164 8000 if (aSize <= 0.)
8001 {
8002 di<<"Bad Size value : " << aSize << "\n";
8003 return 1;
8004 }
8005
8006 Handle(V3d_View) aView = ViewerTest::CurrentView();
8007 aView->SetSize(aSize);
8008 return 0;
8009}
8010
8011//=======================================================================
8012//function : VMoveView
8013//purpose :
8014//=======================================================================
8015static Standard_Integer VMoveView (Draw_Interpretor& di,
8016 Standard_Integer argc,
8017 const char ** argv)
8018{
8019 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8020 if(aContext.IsNull())
8021 {
8022 di << "use 'vinit' command before " << argv[0] << "\n";
8023 return 1;
8024 }
8025 if(argc < 4 || argc > 5)
8026 {
8027 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8028 return 1;
8029 }
6b62b2da 8030 Standard_Real Dx = Draw::Atof (argv[1]);
8031 Standard_Real Dy = Draw::Atof (argv[2]);
8032 Standard_Real Dz = Draw::Atof (argv[3]);
4754e164 8033 Standard_Boolean aStart = Standard_True;
8034 if (argc == 5)
8035 {
6b62b2da 8036 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 8037 }
8038
8039 Handle(V3d_View) aView = ViewerTest::CurrentView();
8040 aView->Move(Dx,Dy,Dz,aStart);
8041 return 0;
8042}
8043
8044//=======================================================================
8045//function : VTranslateView
8046//purpose :
8047//=======================================================================
8048static Standard_Integer VTranslateView (Draw_Interpretor& di,
8049 Standard_Integer argc,
8050 const char ** argv)
8051{
8052 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8053 if(aContext.IsNull())
8054 {
8055 di << "use 'vinit' command before " << argv[0] << "\n";
8056 return 1;
8057 }
8058 if(argc < 4 || argc > 5)
8059 {
8060 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8061 return 1;
8062 }
6b62b2da 8063 Standard_Real Dx = Draw::Atof (argv[1]);
8064 Standard_Real Dy = Draw::Atof (argv[2]);
8065 Standard_Real Dz = Draw::Atof (argv[3]);
4754e164 8066 Standard_Boolean aStart = Standard_True;
dc3fe572 8067 if (argc == 5)
4754e164 8068 {
6b62b2da 8069 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 8070 }
8071
8072 Handle(V3d_View) aView = ViewerTest::CurrentView();
8073 aView->Translate(Dx,Dy,Dz,aStart);
8074 return 0;
8075}
8076
8077//=======================================================================
8078//function : VTurnView
8079//purpose :
8080//=======================================================================
8081static Standard_Integer VTurnView (Draw_Interpretor& di,
8082 Standard_Integer argc,
8083 const char ** argv)
8084{
8085 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8086 if(aContext.IsNull()) {
8087 di << "use 'vinit' command before " << argv[0] << "\n";
8088 return 1;
8089 }
8090 if(argc < 4 || argc > 5){
8091 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
8092 return 1;
8093 }
6b62b2da 8094 Standard_Real Ax = Draw::Atof (argv[1]);
8095 Standard_Real Ay = Draw::Atof (argv[2]);
8096 Standard_Real Az = Draw::Atof (argv[3]);
4754e164 8097 Standard_Boolean aStart = Standard_True;
dc3fe572 8098 if (argc == 5)
4754e164 8099 {
6b62b2da 8100 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 8101 }
8102
8103 Handle(V3d_View) aView = ViewerTest::CurrentView();
8104 aView->Turn(Ax,Ay,Az,aStart);
8105 return 0;
8106}
8107
269294d6 8108//==============================================================================
8109//function : VTextureEnv
8110//purpose : ENables or disables environment mapping
8111//==============================================================================
8112class OCC_TextureEnv : public Graphic3d_TextureEnv
8113{
8114public:
8115 OCC_TextureEnv(const Standard_CString FileName);
8116 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
8117 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
8118 const Standard_Boolean theModulateFlag,
8119 const Graphic3d_TypeOfTextureFilter theFilter,
8120 const Standard_ShortReal theXScale,
8121 const Standard_ShortReal theYScale,
8122 const Standard_ShortReal theXShift,
8123 const Standard_ShortReal theYShift,
8124 const Standard_ShortReal theAngle);
68858c7d 8125 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
269294d6 8126};
a3f6f591 8127DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
ec357c5c 8128
269294d6 8129OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
8130 : Graphic3d_TextureEnv(theFileName)
8131{
8132}
8133
8134OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
8135 : Graphic3d_TextureEnv(theTexId)
8136{
8137}
8138
8139void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
8140 const Standard_Boolean theModulateFlag,
8141 const Graphic3d_TypeOfTextureFilter theFilter,
8142 const Standard_ShortReal theXScale,
8143 const Standard_ShortReal theYScale,
8144 const Standard_ShortReal theXShift,
8145 const Standard_ShortReal theYShift,
8146 const Standard_ShortReal theAngle)
8147{
8148 myParams->SetRepeat (theRepeatFlag);
8149 myParams->SetModulate (theModulateFlag);
8150 myParams->SetFilter (theFilter);
8151 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
8152 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
8153 myParams->SetRotation (theAngle);
8154}
8155
35e08fe8 8156static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
269294d6 8157{
8158 // get the active view
8159 Handle(V3d_View) aView = ViewerTest::CurrentView();
8160 if (aView.IsNull())
8161 {
8162 std::cerr << "No active view. Please call vinit.\n";
8163 return 1;
8164 }
8165
8166 // Checking the input arguments
8167 Standard_Boolean anEnableFlag = Standard_False;
8168 Standard_Boolean isOk = theArgNb >= 2;
8169 if (isOk)
8170 {
8171 TCollection_AsciiString anEnableOpt(theArgVec[1]);
8172 anEnableFlag = anEnableOpt.IsEqual("on");
8173 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
8174 }
8175 if (anEnableFlag)
8176 {
8177 isOk = (theArgNb == 3 || theArgNb == 11);
8178 if (isOk)
8179 {
8180 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8181 isOk = (!aTextureOpt.IsIntegerValue() ||
8182 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
8183
8184 if (isOk && theArgNb == 11)
8185 {
8186 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
8187 aModulateOpt(theArgVec[4]),
8188 aFilterOpt (theArgVec[5]),
8189 aSScaleOpt (theArgVec[6]),
8190 aTScaleOpt (theArgVec[7]),
8191 aSTransOpt (theArgVec[8]),
8192 aTTransOpt (theArgVec[9]),
8193 anAngleOpt (theArgVec[10]);
8194 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
8195 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
8196 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
8197 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
8198 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
8199 anAngleOpt.IsRealValue());
8200 }
8201 }
8202 }
8203
8204 if (!isOk)
8205 {
8206 std::cerr << "Usage :" << std::endl;
8207 std::cerr << theArgVec[0] << " off" << std::endl;
8208 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;
8209 return 1;
8210 }
8211
8212 if (anEnableFlag)
8213 {
8214 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8215 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
8216 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
8217 new OCC_TextureEnv(theArgVec[2]);
8218
8219 if (theArgNb == 11)
8220 {
8221 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
8222 aTexEnv->SetTextureParameters(
8223 aRepeatOpt. IsEqual("repeat"),
8224 aModulateOpt.IsEqual("modulate"),
8225 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
8226 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
8227 Graphic3d_TOTF_TRILINEAR,
8228 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
8229 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
8230 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
8231 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
8232 (Standard_ShortReal)Draw::Atof(theArgVec[10])
8233 );
8234 }
8235 aView->SetTextureEnv(aTexEnv);
269294d6 8236 }
8237 else // Disabling environment mapping
8238 {
269294d6 8239 Handle(Graphic3d_TextureEnv) aTexture;
8240 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
8241 }
8242
8243 aView->Redraw();
8244 return 0;
8245}
8246
3e05329c 8247namespace
8248{
8249 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
8250
8251 //! Remove registered clipping plane from all views and objects.
8252 static void removePlane (MapOfPlanes& theRegPlanes,
8253 const TCollection_AsciiString& theName)
8254 {
8255 Handle(Graphic3d_ClipPlane) aClipPlane;
8256 if (!theRegPlanes.Find (theName, aClipPlane))
8257 {
8258 std::cout << "Warning: no such plane.\n";
8259 return;
8260 }
8261
8262 theRegPlanes.UnBind (theName);
8263 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
8264 anIObjIt.More(); anIObjIt.Next())
8265 {
8f521168 8266 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
3e05329c 8267 aPrs->RemoveClipPlane (aClipPlane);
8268 }
8269
8270 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
8271 aViewIt.More(); aViewIt.Next())
8272 {
8273 const Handle(V3d_View)& aView = aViewIt.Key2();
8274 aView->RemoveClipPlane(aClipPlane);
8275 }
8276
8277 ViewerTest::RedrawAllViews();
8278 }
8279}
8280
4269bd1b 8281//===============================================================================================
8282//function : VClipPlane
8283//purpose :
8284//===============================================================================================
8285static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8286{
8287 // use short-cut for created clip planes map of created (or "registered by name") clip planes
4269bd1b 8288 static MapOfPlanes aRegPlanes;
8289
8290 if (theArgsNb < 2)
8291 {
3e05329c 8292 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
8293 {
8294 theDi << aPlaneIter.Key() << " ";
8295 }
8296 return 0;
4269bd1b 8297 }
8298
8299 TCollection_AsciiString aCommand (theArgVec[1]);
3e05329c 8300 aCommand.LowerCase();
8301 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
8302 if (anActiveView.IsNull())
8303 {
8304 std::cout << "Error: no active view.\n";
8305 return 1;
8306 }
4269bd1b 8307
8308 // print maximum number of planes for current viewer
3e05329c 8309 if (aCommand == "-maxplanes"
8310 || aCommand == "maxplanes")
4269bd1b 8311 {
3e05329c 8312 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
8313 << " plane slots provided by driver.\n";
4269bd1b 8314 return 0;
8315 }
8316
8317 // create / delete plane instance
3e05329c 8318 if (aCommand == "-create"
8319 || aCommand == "create"
8320 || aCommand == "-delete"
8321 || aCommand == "delete"
8322 || aCommand == "-clone"
8323 || aCommand == "clone")
4269bd1b 8324 {
8325 if (theArgsNb < 3)
8326 {
3e05329c 8327 std::cout << "Syntax error: plane name is required.\n";
4269bd1b 8328 return 1;
8329 }
8330
3e05329c 8331 Standard_Boolean toCreate = aCommand == "-create"
8332 || aCommand == "create";
8333 Standard_Boolean toClone = aCommand == "-clone"
8334 || aCommand == "clone";
8335 Standard_Boolean toDelete = aCommand == "-delete"
8336 || aCommand == "delete";
4269bd1b 8337 TCollection_AsciiString aPlane (theArgVec[2]);
8338
8339 if (toCreate)
8340 {
8341 if (aRegPlanes.IsBound (aPlane))
8342 {
3e05329c 8343 std::cout << "Warning: existing plane has been overridden.\n";
8344 toDelete = true;
8345 }
8346 else
8347 {
8348 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8349 return 0;
4269bd1b 8350 }
4269bd1b 8351 }
8352 else if (toClone) // toClone
8353 {
8354 if (!aRegPlanes.IsBound (aPlane))
8355 {
3e05329c 8356 std::cout << "Error: no such plane.\n";
4269bd1b 8357 return 1;
8358 }
3e05329c 8359 else if (theArgsNb < 4)
4269bd1b 8360 {
3e05329c 8361 std::cout << "Syntax error: enter name for new plane.\n";
4269bd1b 8362 return 1;
8363 }
8364
8365 TCollection_AsciiString aClone (theArgVec[3]);
8366 if (aRegPlanes.IsBound (aClone))
8367 {
3e05329c 8368 std::cout << "Error: plane name is in use.\n";
4269bd1b 8369 return 1;
8370 }
8371
8372 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
8373
8374 aRegPlanes.Bind (aClone, aClipPlane->Clone());
3e05329c 8375 return 0;
4269bd1b 8376 }
4269bd1b 8377
3e05329c 8378 if (toDelete)
8379 {
8380 if (aPlane == "ALL"
8381 || aPlane == "all"
8382 || aPlane == "*")
4269bd1b 8383 {
3e05329c 8384 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
8385 {
8386 aPlane = aPlaneIter.Key();
8387 removePlane (aRegPlanes, aPlane);
8388 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
8389 }
4269bd1b 8390 }
3e05329c 8391 else
4269bd1b 8392 {
3e05329c 8393 removePlane (aRegPlanes, aPlane);
4269bd1b 8394 }
4269bd1b 8395 }
8396
3e05329c 8397 if (toCreate)
8398 {
8399 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8400 }
4269bd1b 8401 return 0;
8402 }
8403
8404 // set / unset plane command
3e05329c 8405 if (aCommand == "set"
8406 || aCommand == "unset")
4269bd1b 8407 {
3e05329c 8408 if (theArgsNb < 5)
4269bd1b 8409 {
3e05329c 8410 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 8411 return 1;
8412 }
8413
3e05329c 8414 // redirect to new syntax
8415 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
8416 anArgVec.SetValue (1, theArgVec[0]);
8417 anArgVec.SetValue (2, theArgVec[2]);
8418 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
8419 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
4269bd1b 8420 {
3e05329c 8421 anArgVec.SetValue (anIt, theArgVec[anIt]);
4269bd1b 8422 }
8423
3e05329c 8424 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
4269bd1b 8425 }
8426
8427 // change plane command
3e05329c 8428 TCollection_AsciiString aPlaneName;
8429 Handle(Graphic3d_ClipPlane) aClipPlane;
8430 Standard_Integer anArgIter = 0;
8431 if (aCommand == "-change"
8432 || aCommand == "change")
4269bd1b 8433 {
3e05329c 8434 // old syntax support
8435 if (theArgsNb < 3)
4269bd1b 8436 {
3e05329c 8437 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 8438 return 1;
8439 }
8440
3e05329c 8441 anArgIter = 3;
8442 aPlaneName = theArgVec[2];
8443 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
4269bd1b 8444 {
3e05329c 8445 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
4269bd1b 8446 return 1;
8447 }
3e05329c 8448 }
8449 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
8450 {
8451 anArgIter = 2;
8452 aPlaneName = theArgVec[1];
8453 }
8454 else
8455 {
8456 anArgIter = 2;
8457 aPlaneName = theArgVec[1];
8458 aClipPlane = new Graphic3d_ClipPlane();
8459 aRegPlanes.Bind (aPlaneName, aClipPlane);
8460 theDi << "Created new plane " << aPlaneName << ".\n";
8461 }
4269bd1b 8462
3e05329c 8463 if (theArgsNb - anArgIter < 1)
8464 {
8465 std::cout << "Syntax error: need more arguments.\n";
8466 return 1;
8467 }
4269bd1b 8468
3e05329c 8469 for (; anArgIter < theArgsNb; ++anArgIter)
8470 {
8471 const char** aChangeArgs = theArgVec + anArgIter;
8472 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
8473 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
8474 aChangeArg.LowerCase();
4269bd1b 8475
3e05329c 8476 Standard_Boolean toEnable = Standard_True;
8477 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
4269bd1b 8478 {
3e05329c 8479 aClipPlane->SetOn (toEnable);
4269bd1b 8480 }
25c35042 8481 else if (aChangeArg.StartsWith ("-equation")
8482 || aChangeArg.StartsWith ("equation"))
4269bd1b 8483 {
3e05329c 8484 if (aNbChangeArgs < 5)
4269bd1b 8485 {
3e05329c 8486 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 8487 return 1;
8488 }
8489
25c35042 8490 Standard_Integer aSubIndex = 1;
8491 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
8492 if (aPrefixLen < aChangeArg.Length())
8493 {
8494 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
8495 if (!aSubStr.IsIntegerValue()
8496 || aSubStr.IntegerValue() <= 0)
8497 {
8498 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8499 return 1;
8500 }
8501 aSubIndex = aSubStr.IntegerValue();
8502 }
8503
8504 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
8505 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
8506 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
8507 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
8508 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8509 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
8510 {
8511 if (aSubPln->ChainNextPlane().IsNull())
8512 {
8513 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8514 }
8515 aSubPln = aSubPln->ChainNextPlane();
8516 }
8517 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8518 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
3e05329c 8519 anArgIter += 4;
4269bd1b 8520 }
25c35042 8521 else if ((aChangeArg == "-boxinterior"
8522 || aChangeArg == "-boxint"
8523 || aChangeArg == "-box")
8524 && aNbChangeArgs >= 7)
8525 {
8526 Graphic3d_BndBox3d aBndBox;
8527 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
8528 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
8529 anArgIter += 6;
8530
8531 Standard_Integer aNbSubPlanes = 6;
8532 const Graphic3d_Vec3d aDirArray[6] =
8533 {
8534 Graphic3d_Vec3d (-1, 0, 0),
8535 Graphic3d_Vec3d ( 1, 0, 0),
8536 Graphic3d_Vec3d ( 0,-1, 0),
8537 Graphic3d_Vec3d ( 0, 1, 0),
8538 Graphic3d_Vec3d ( 0, 0,-1),
8539 Graphic3d_Vec3d ( 0, 0, 1),
8540 };
8541 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8542 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
8543 {
8544 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
8545 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
8546 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
8547 if (aSubPlaneIter + 1 == aNbSubPlanes)
8548 {
8549 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8550 }
8551 else
8552 {
8553 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8554 }
8555 aSubPln = aSubPln->ChainNextPlane();
8556 }
8557 }
3e05329c 8558 else if (aChangeArg == "-capping"
8559 || aChangeArg == "capping")
4269bd1b 8560 {
3e05329c 8561 if (aNbChangeArgs < 2)
4269bd1b 8562 {
3e05329c 8563 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 8564 return 1;
8565 }
8566
3e05329c 8567 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
4269bd1b 8568 {
3e05329c 8569 aClipPlane->SetCapping (toEnable);
8570 anArgIter += 1;
8571 }
8572 else
8573 {
8574 // just skip otherwise (old syntax)
8575 }
8576 }
8577 else if (aChangeArg == "-useobjectmaterial"
8578 || aChangeArg == "-useobjectmat"
8579 || aChangeArg == "-useobjmat"
8580 || aChangeArg == "-useobjmaterial")
8581 {
8582 if (aNbChangeArgs < 2)
8583 {
8584 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 8585 return 1;
8586 }
8587
3e05329c 8588 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
4269bd1b 8589 {
3e05329c 8590 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
8591 anArgIter += 1;
4269bd1b 8592 }
3e05329c 8593 }
8594 else if (aChangeArg == "-useobjecttexture"
8595 || aChangeArg == "-useobjecttex"
8596 || aChangeArg == "-useobjtexture"
8597 || aChangeArg == "-useobjtex")
8598 {
8599 if (aNbChangeArgs < 2)
4269bd1b 8600 {
3e05329c 8601 std::cout << "Syntax error: need more arguments.\n";
8602 return 1;
8603 }
4269bd1b 8604
3e05329c 8605 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8606 {
8607 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
8608 anArgIter += 1;
8609 }
8610 }
8611 else if (aChangeArg == "-useobjectshader"
8612 || aChangeArg == "-useobjshader")
8613 {
8614 if (aNbChangeArgs < 2)
8615 {
8616 std::cout << "Syntax error: need more arguments.\n";
8617 return 1;
8618 }
4269bd1b 8619
3e05329c 8620 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8621 {
8622 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
8623 anArgIter += 1;
4269bd1b 8624 }
3e05329c 8625 }
8626 else if (aChangeArg == "-color"
8627 || aChangeArg == "color")
8628 {
8629 Quantity_Color aColor;
8630 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
8631 aChangeArgs + 1,
8632 aColor);
8633 if (aNbParsed == 0)
4269bd1b 8634 {
3e05329c 8635 std::cout << "Syntax error: need more arguments.\n";
8636 return 1;
8637 }
4269bd1b 8638
3e05329c 8639 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8640 aMat.SetAmbientColor (aColor);
8641 aMat.SetDiffuseColor (aColor);
8642 aClipPlane->SetCappingMaterial (aMat);
8643 anArgIter += aNbParsed;
8644 }
1b661a81 8645 else if ((aChangeArg == "-transparency"
8646 || aChangeArg == "-transp")
8647 && aNbChangeArgs >= 2)
8648 {
8649 TCollection_AsciiString aValStr (aChangeArgs[1]);
8650 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
8651 if (aValStr.IsRealValue())
8652 {
8653 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8654 aMat.SetTransparency ((float )aValStr.RealValue());
8655 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
8656 aClipPlane->SetCappingMaterial (aMat);
8657 }
8658 else
8659 {
8660 aValStr.LowerCase();
8661 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
8662 if (aValStr == "opaque")
8663 {
8664 aMode = Graphic3d_AlphaMode_Opaque;
8665 }
8666 else if (aValStr == "mask")
8667 {
8668 aMode = Graphic3d_AlphaMode_Mask;
8669 }
8670 else if (aValStr == "blend")
8671 {
8672 aMode = Graphic3d_AlphaMode_Blend;
8673 }
8674 else if (aValStr == "blendauto")
8675 {
8676 aMode = Graphic3d_AlphaMode_BlendAuto;
8677 }
8678 else
8679 {
8680 std::cout << "Syntax error at '" << aValStr << "'\n";
8681 return 1;
8682 }
8683 anAspect->SetAlphaMode (aMode);
8684 aClipPlane->SetCappingAspect (anAspect);
8685 }
8686 anArgIter += 1;
8687 }
3e05329c 8688 else if (aChangeArg == "-texname"
8689 || aChangeArg == "texname")
8690 {
8691 if (aNbChangeArgs < 2)
8692 {
8693 std::cout << "Syntax error: need more arguments.\n";
8694 return 1;
8695 }
4269bd1b 8696
3e05329c 8697 TCollection_AsciiString aTextureName (aChangeArgs[1]);
8698 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
8699 if (!aTexture->IsDone())
8700 {
8701 aClipPlane->SetCappingTexture (NULL);
4269bd1b 8702 }
3e05329c 8703 else
4269bd1b 8704 {
3e05329c 8705 aTexture->EnableModulate();
8706 aTexture->EnableRepeat();
8707 aClipPlane->SetCappingTexture (aTexture);
8708 }
8709 anArgIter += 1;
8710 }
8711 else if (aChangeArg == "-texscale"
8712 || aChangeArg == "texscale")
8713 {
8714 if (aClipPlane->CappingTexture().IsNull())
8715 {
8716 std::cout << "Error: no texture is set.\n";
8717 return 1;
8718 }
4269bd1b 8719
3e05329c 8720 if (aNbChangeArgs < 3)
8721 {
8722 std::cout << "Syntax error: need more arguments.\n";
8723 return 1;
8724 }
4269bd1b 8725
3e05329c 8726 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8727 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8728 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
8729 anArgIter += 2;
8730 }
8731 else if (aChangeArg == "-texorigin"
8732 || aChangeArg == "texorigin") // texture origin
8733 {
8734 if (aClipPlane->CappingTexture().IsNull())
8735 {
8736 std::cout << "Error: no texture is set.\n";
8737 return 1;
8738 }
4269bd1b 8739
3e05329c 8740 if (aNbChangeArgs < 3)
8741 {
8742 std::cout << "Syntax error: need more arguments.\n";
8743 return 1;
4269bd1b 8744 }
3e05329c 8745
8746 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8747 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8748
8749 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
8750 anArgIter += 2;
8751 }
8752 else if (aChangeArg == "-texrotate"
8753 || aChangeArg == "texrotate") // texture rotation
8754 {
8755 if (aClipPlane->CappingTexture().IsNull())
4269bd1b 8756 {
3e05329c 8757 std::cout << "Error: no texture is set.\n";
8758 return 1;
8759 }
4269bd1b 8760
3e05329c 8761 if (aNbChangeArgs < 2)
8762 {
8763 std::cout << "Syntax error: need more arguments.\n";
8764 return 1;
8765 }
4269bd1b 8766
3e05329c 8767 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8768 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8769 anArgIter += 1;
8770 }
8771 else if (aChangeArg == "-hatch"
8772 || aChangeArg == "hatch")
8773 {
8774 if (aNbChangeArgs < 2)
8775 {
8776 std::cout << "Syntax error: need more arguments.\n";
8777 return 1;
8778 }
4269bd1b 8779
3e05329c 8780 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8781 aHatchStr.LowerCase();
8782 if (aHatchStr == "on")
8783 {
8784 aClipPlane->SetCappingHatchOn();
8785 }
8786 else if (aHatchStr == "off")
8787 {
8788 aClipPlane->SetCappingHatchOff();
4269bd1b 8789 }
3e05329c 8790 else
4269bd1b 8791 {
3e05329c 8792 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8793 }
8794 anArgIter += 1;
8795 }
8796 else if (aChangeArg == "-delete"
8797 || aChangeArg == "delete")
8798 {
8799 removePlane (aRegPlanes, aPlaneName);
8800 return 0;
8801 }
8802 else if (aChangeArg == "-set"
32ca7711 8803 || aChangeArg == "-unset"
8804 || aChangeArg == "-setoverrideglobal")
3e05329c 8805 {
8806 // set / unset plane command
32ca7711 8807 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
8808 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
3e05329c 8809 Standard_Integer anIt = 1;
8810 for (; anIt < aNbChangeArgs; ++anIt)
8811 {
8812 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8813 if (anEntityName.IsEmpty()
8814 || anEntityName.Value (1) == '-')
4269bd1b 8815 {
3e05329c 8816 break;
4269bd1b 8817 }
32ca7711 8818 else if (!toOverrideGlobal
8819 && ViewerTest_myViews.IsBound1 (anEntityName))
4269bd1b 8820 {
3e05329c 8821 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
8822 if (toSet)
8823 {
8824 aView->AddClipPlane (aClipPlane);
8825 }
8826 else
8827 {
8828 aView->RemoveClipPlane (aClipPlane);
8829 }
8830 continue;
4269bd1b 8831 }
3e05329c 8832 else if (GetMapOfAIS().IsBound2 (anEntityName))
4269bd1b 8833 {
8f521168 8834 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
3e05329c 8835 if (toSet)
8836 {
8837 aIObj->AddClipPlane (aClipPlane);
8838 }
8839 else
8840 {
8841 aIObj->RemoveClipPlane (aClipPlane);
8842 }
32ca7711 8843 if (!aIObj->ClipPlanes().IsNull())
8844 {
8845 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
8846 }
4269bd1b 8847 }
3e05329c 8848 else
4269bd1b 8849 {
3e05329c 8850 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
8851 return 1;
4269bd1b 8852 }
3e05329c 8853 }
8854
8855 if (anIt == 1)
8856 {
8857 // apply to active view
8858 if (toSet)
4269bd1b 8859 {
3e05329c 8860 anActiveView->AddClipPlane (aClipPlane);
4269bd1b 8861 }
8862 else
8863 {
3e05329c 8864 anActiveView->RemoveClipPlane (aClipPlane);
4269bd1b 8865 }
8866 }
3e05329c 8867 else
8868 {
8869 anArgIter = anArgIter + anIt - 1;
8870 }
8871 }
8872 else
8873 {
8874 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8875 return 1;
4269bd1b 8876 }
4269bd1b 8877 }
8878
3e05329c 8879 ViewerTest::RedrawAllViews();
8880 return 0;
4269bd1b 8881}
8882
b5ac8292 8883//===============================================================================================
8884//function : VZRange
8885//purpose :
8886//===============================================================================================
8887static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8888{
197ac94e 8889 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8890
8891 if (aCurrentView.IsNull())
b5ac8292 8892 {
197ac94e 8893 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 8894 return 1;
8895 }
8896
197ac94e 8897 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
b5ac8292 8898
8899 if (theArgsNb < 2)
8900 {
8901 theDi << "ZNear: " << aCamera->ZNear() << "\n";
8902 theDi << "ZFar: " << aCamera->ZFar() << "\n";
8903 return 0;
8904 }
8905
8906 if (theArgsNb == 3)
8907 {
6b62b2da 8908 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
8909 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
197ac94e 8910
8911 if (aNewZNear >= aNewZFar)
8912 {
8913 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
8914 return 1;
8915 }
8916
8917 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
8918 {
8919 std::cout << theArgVec[0] << ": invalid arguments: ";
8920 std::cout << "znear, zfar should be positive for perspective camera.\n";
8921 return 1;
8922 }
8923
8924 aCamera->SetZRange (aNewZNear, aNewZFar);
b5ac8292 8925 }
8926 else
8927 {
197ac94e 8928 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
b5ac8292 8929 return 1;
8930 }
8931
197ac94e 8932 aCurrentView->Redraw();
8933
b5ac8292 8934 return 0;
8935}
8936
8937//===============================================================================================
8938//function : VAutoZFit
8939//purpose :
8940//===============================================================================================
8941static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8942{
197ac94e 8943 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8944
8945 if (aCurrentView.IsNull())
b5ac8292 8946 {
197ac94e 8947 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 8948 return 1;
8949 }
8950
c357e426 8951 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
197ac94e 8952
8953 if (theArgsNb > 3)
b5ac8292 8954 {
197ac94e 8955 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8956 return 1;
b5ac8292 8957 }
8958
197ac94e 8959 if (theArgsNb < 2)
b5ac8292 8960 {
586db386 8961 theDi << "Auto z-fit mode: \n"
c357e426 8962 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
197ac94e 8963 << "Scale: " << aScale << "\n";
8964 return 0;
b5ac8292 8965 }
197ac94e 8966
8967 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
8968
8969 if (theArgsNb >= 3)
b5ac8292 8970 {
197ac94e 8971 aScale = Draw::Atoi (theArgVec[2]);
b5ac8292 8972 }
8973
c357e426 8974 aCurrentView->SetAutoZFitMode (isOn, aScale);
8975 aCurrentView->AutoZFit();
197ac94e 8976 aCurrentView->Redraw();
8977
b5ac8292 8978 return 0;
8979}
8980
6b62b2da 8981//! Auxiliary function to print projection type
8982inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
8983{
8984 switch (theProjType)
8985 {
8986 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
8987 case Graphic3d_Camera::Projection_Perspective: return "perspective";
8988 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
8989 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
8990 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
8991 }
8992 return "UNKNOWN";
8993}
8994
b5ac8292 8995//===============================================================================================
6b62b2da 8996//function : VCamera
b5ac8292 8997//purpose :
8998//===============================================================================================
6b62b2da 8999static int VCamera (Draw_Interpretor& theDI,
9000 Standard_Integer theArgsNb,
9001 const char** theArgVec)
b5ac8292 9002{
6b62b2da 9003 Handle(V3d_View) aView = ViewerTest::CurrentView();
9004 if (aView.IsNull())
b5ac8292 9005 {
6b62b2da 9006 std::cout << "Error: no active view.\n";
b5ac8292 9007 return 1;
9008 }
9009
6b62b2da 9010 Handle(Graphic3d_Camera) aCamera = aView->Camera();
9011 if (theArgsNb < 2)
b5ac8292 9012 {
6b62b2da 9013 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
9014 theDI << "FOVy: " << aCamera->FOVy() << "\n";
9015 theDI << "Distance: " << aCamera->Distance() << "\n";
9016 theDI << "IOD: " << aCamera->IOD() << "\n";
9017 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
9018 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
9019 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
9020 return 0;
b5ac8292 9021 }
9022
30a1b24e 9023 TCollection_AsciiString aPrsName;
6b62b2da 9024 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
b5ac8292 9025 {
6b62b2da 9026 Standard_CString anArg = theArgVec[anArgIter];
9027 TCollection_AsciiString anArgCase (anArg);
9028 anArgCase.LowerCase();
9029 if (anArgCase == "-proj"
9030 || anArgCase == "-projection"
9031 || anArgCase == "-projtype"
9032 || anArgCase == "-projectiontype")
9033 {
9034 theDI << projTypeName (aCamera->ProjectionType()) << " ";
9035 }
9036 else if (anArgCase == "-ortho"
9037 || anArgCase == "-orthographic")
b5ac8292 9038 {
9039 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
6b62b2da 9040 }
9041 else if (anArgCase == "-persp"
9042 || anArgCase == "-perspective"
9043 || anArgCase == "-perspmono"
9044 || anArgCase == "-perspectivemono"
9045 || anArgCase == "-mono")
b5ac8292 9046 {
9047 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9048 }
6b62b2da 9049 else if (anArgCase == "-stereo"
9050 || anArgCase == "-stereoscopic"
9051 || anArgCase == "-perspstereo"
9052 || anArgCase == "-perspectivestereo")
9053 {
9054 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9055 }
9056 else if (anArgCase == "-left"
9057 || anArgCase == "-lefteye"
9058 || anArgCase == "-monoleft"
9059 || anArgCase == "-monolefteye"
9060 || anArgCase == "-perpsleft"
9061 || anArgCase == "-perpslefteye")
b5ac8292 9062 {
9063 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
9064 }
6b62b2da 9065 else if (anArgCase == "-right"
9066 || anArgCase == "-righteye"
9067 || anArgCase == "-monoright"
9068 || anArgCase == "-monorighteye"
9069 || anArgCase == "-perpsright")
b5ac8292 9070 {
9071 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
9072 }
6b62b2da 9073 else if (anArgCase == "-dist"
9074 || anArgCase == "-distance")
b5ac8292 9075 {
6b62b2da 9076 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9077 if (anArgValue != NULL
9078 && *anArgValue != '-')
9079 {
9080 ++anArgIter;
9081 aCamera->SetDistance (Draw::Atof (anArgValue));
9082 continue;
9083 }
9084 theDI << aCamera->Distance() << " ";
b5ac8292 9085 }
6b62b2da 9086 else if (anArgCase == "-iod")
b5ac8292 9087 {
6b62b2da 9088 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9089 if (anArgValue != NULL
9090 && *anArgValue != '-')
9091 {
9092 ++anArgIter;
9093 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
9094 continue;
9095 }
9096 theDI << aCamera->IOD() << " ";
b5ac8292 9097 }
6b62b2da 9098 else if (anArgCase == "-iodtype")
b5ac8292 9099 {
6b62b2da 9100 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9101 TCollection_AsciiString anValueCase (anArgValue);
9102 anValueCase.LowerCase();
9103 if (anValueCase == "abs"
9104 || anValueCase == "absolute")
9105 {
9106 ++anArgIter;
9107 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
9108 continue;
9109 }
9110 else if (anValueCase == "rel"
9111 || anValueCase == "relative")
9112 {
9113 ++anArgIter;
9114 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
9115 continue;
9116 }
9117 else if (*anArgValue != '-')
9118 {
9119 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
9120 return 1;
9121 }
9122 switch (aCamera->GetIODType())
9123 {
9124 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
9125 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
9126 }
b5ac8292 9127 }
6b62b2da 9128 else if (anArgCase == "-zfocus")
b5ac8292 9129 {
6b62b2da 9130 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9131 if (anArgValue != NULL
9132 && *anArgValue != '-')
9133 {
9134 ++anArgIter;
9135 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
9136 continue;
9137 }
9138 theDI << aCamera->ZFocus() << " ";
b5ac8292 9139 }
6b62b2da 9140 else if (anArgCase == "-zfocustype")
b5ac8292 9141 {
6b62b2da 9142 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9143 TCollection_AsciiString anValueCase (anArgValue);
9144 anValueCase.LowerCase();
9145 if (anValueCase == "abs"
9146 || anValueCase == "absolute")
9147 {
9148 ++anArgIter;
9149 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
9150 continue;
9151 }
9152 else if (anValueCase == "rel"
9153 || anValueCase == "relative")
9154 {
9155 ++anArgIter;
9156 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
9157 continue;
9158 }
9159 else if (*anArgValue != '-')
9160 {
9161 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
9162 return 1;
9163 }
9164 switch (aCamera->ZFocusType())
9165 {
9166 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
9167 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
9168 }
9169 }
9170 else if (anArgCase == "-fov"
9171 || anArgCase == "-fovy")
b5ac8292 9172 {
6b62b2da 9173 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9174 if (anArgValue != NULL
9175 && *anArgValue != '-')
9176 {
9177 ++anArgIter;
9178 aCamera->SetFOVy (Draw::Atof (anArgValue));
9179 continue;
9180 }
9181 theDI << aCamera->FOVy() << " ";
b5ac8292 9182 }
30a1b24e 9183 else if (aPrsName.IsEmpty()
9184 && !anArgCase.StartsWith ("-"))
9185 {
9186 aPrsName = anArg;
9187 }
b5ac8292 9188 else
9189 {
6b62b2da 9190 std::cout << "Error: unknown argument '" << anArg << "'\n";
b5ac8292 9191 return 1;
9192 }
9193 }
b5ac8292 9194
30a1b24e 9195 if (aPrsName.IsEmpty()
9196 || theArgsNb > 2)
9197 {
9198 aView->AutoZFit();
9199 aView->Redraw();
9200 }
9201
9202 if (!aPrsName.IsEmpty())
9203 {
9204 Handle(AIS_CameraFrustum) aCameraFrustum;
9205 if (GetMapOfAIS().IsBound2 (aPrsName))
9206 {
9207 // find existing object
9208 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
9209 if (aCameraFrustum.IsNull())
9210 {
9211 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
9212 return 1;
9213 }
9214 }
9215
9216 if (aCameraFrustum.IsNull())
9217 {
9218 aCameraFrustum = new AIS_CameraFrustum();
9219 }
9220 else
9221 {
9222 // not include displayed object of old camera frustum in the new one.
9223 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
9224 aView->ZFitAll();
9225 }
9226 aCameraFrustum->SetCameraFrustum (aView->Camera());
9227
9228 ViewerTest::Display (aPrsName, aCameraFrustum);
9229 }
b5ac8292 9230
9231 return 0;
9232}
9233
f978241f 9234//! Parse stereo output mode
9235inline Standard_Boolean parseStereoMode (Standard_CString theArg,
9236 Graphic3d_StereoMode& theMode)
9237{
9238 TCollection_AsciiString aFlag (theArg);
9239 aFlag.LowerCase();
9240 if (aFlag == "quadbuffer")
9241 {
9242 theMode = Graphic3d_StereoMode_QuadBuffer;
9243 }
9244 else if (aFlag == "anaglyph")
9245 {
9246 theMode = Graphic3d_StereoMode_Anaglyph;
9247 }
9248 else if (aFlag == "row"
9249 || aFlag == "rowinterlaced")
9250 {
9251 theMode = Graphic3d_StereoMode_RowInterlaced;
9252 }
9253 else if (aFlag == "col"
9254 || aFlag == "colinterlaced"
9255 || aFlag == "columninterlaced")
9256 {
9257 theMode = Graphic3d_StereoMode_ColumnInterlaced;
9258 }
9259 else if (aFlag == "chess"
9260 || aFlag == "chessboard")
9261 {
9262 theMode = Graphic3d_StereoMode_ChessBoard;
9263 }
9264 else if (aFlag == "sbs"
9265 || aFlag == "sidebyside")
9266 {
9267 theMode = Graphic3d_StereoMode_SideBySide;
9268 }
9269 else if (aFlag == "ou"
9270 || aFlag == "overunder")
9271 {
9272 theMode = Graphic3d_StereoMode_OverUnder;
9273 }
9274 else if (aFlag == "pageflip"
9275 || aFlag == "softpageflip")
9276 {
9277 theMode = Graphic3d_StereoMode_SoftPageFlip;
9278 }
9279 else
9280 {
9281 return Standard_False;
9282 }
9283 return Standard_True;
9284}
9285
9286//! Parse anaglyph filter
9287inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
9288 Graphic3d_RenderingParams::Anaglyph& theFilter)
9289{
9290 TCollection_AsciiString aFlag (theArg);
9291 aFlag.LowerCase();
9292 if (aFlag == "redcyansimple")
9293 {
9294 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9295 }
9296 else if (aFlag == "redcyan"
9297 || aFlag == "redcyanoptimized")
9298 {
9299 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
9300 }
9301 else if (aFlag == "yellowbluesimple")
9302 {
9303 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
9304 }
9305 else if (aFlag == "yellowblue"
9306 || aFlag == "yellowblueoptimized")
9307 {
9308 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
9309 }
9310 else if (aFlag == "greenmagenta"
9311 || aFlag == "greenmagentasimple")
9312 {
9313 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
9314 }
9315 else
9316 {
9317 return Standard_False;
9318 }
9319 return Standard_True;
9320}
9321
b5ac8292 9322//==============================================================================
9323//function : VStereo
9324//purpose :
9325//==============================================================================
9326
9327static int VStereo (Draw_Interpretor& theDI,
9328 Standard_Integer theArgNb,
9329 const char** theArgVec)
9330{
f978241f 9331 Handle(V3d_View) aView = ViewerTest::CurrentView();
b5ac8292 9332 if (theArgNb < 2)
9333 {
b5ac8292 9334 if (aView.IsNull())
9335 {
f978241f 9336 std::cout << "Error: no active viewer!\n";
b5ac8292 9337 return 0;
9338 }
9339
9340 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
9341 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
bf02aa7d 9342 if (isActive)
9343 {
9344 TCollection_AsciiString aMode;
9345 switch (aView->RenderingParams().StereoMode)
9346 {
9347 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
9348 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
9349 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
9350 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
9351 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
9352 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
9353 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
9354 case Graphic3d_StereoMode_Anaglyph :
9355 aMode = "anaglyph";
9356 switch (aView->RenderingParams().AnaglyphFilter)
9357 {
9358 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
9359 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
9360 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
9361 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
9362 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
9363 default: break;
9364 }
9365 default: break;
9366 }
9367 theDI << "Mode " << aMode << "\n";
9368 }
b5ac8292 9369 return 0;
9370 }
9371
f978241f 9372 Handle(Graphic3d_Camera) aCamera;
9373 Graphic3d_RenderingParams* aParams = NULL;
9374 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
9375 if (!aView.IsNull())
9376 {
9377 aParams = &aView->ChangeRenderingParams();
9378 aMode = aParams->StereoMode;
9379 aCamera = aView->Camera();
9380 }
9381
9382 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9383 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9384 {
9385 Standard_CString anArg = theArgVec[anArgIter];
9386 TCollection_AsciiString aFlag (anArg);
9387 aFlag.LowerCase();
9388 if (anUpdateTool.parseRedrawMode (aFlag))
9389 {
9390 continue;
9391 }
9392 else if (aFlag == "0"
9393 || aFlag == "off")
9394 {
9395 if (++anArgIter < theArgNb)
9396 {
9397 std::cout << "Error: wrong number of arguments!\n";
9398 return 1;
9399 }
9400
9401 if (!aCamera.IsNull()
9402 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
9403 {
9404 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9405 }
9406 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
9407 return 0;
9408 }
9409 else if (aFlag == "1"
9410 || aFlag == "on")
9411 {
9412 if (++anArgIter < theArgNb)
9413 {
9414 std::cout << "Error: wrong number of arguments!\n";
9415 return 1;
9416 }
9417
9418 if (!aCamera.IsNull())
9419 {
9420 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9421 }
9422 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9423 return 0;
9424 }
9425 else if (aFlag == "-reverse"
9426 || aFlag == "-reversed"
9427 || aFlag == "-swap")
9428 {
9429 Standard_Boolean toEnable = Standard_True;
9430 if (++anArgIter < theArgNb
a5565a3c 9431 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 9432 {
9433 --anArgIter;
9434 }
9435 aParams->ToReverseStereo = toEnable;
9436 }
9437 else if (aFlag == "-noreverse"
9438 || aFlag == "-noswap")
9439 {
9440 Standard_Boolean toDisable = Standard_True;
9441 if (++anArgIter < theArgNb
a5565a3c 9442 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
f978241f 9443 {
9444 --anArgIter;
9445 }
9446 aParams->ToReverseStereo = !toDisable;
9447 }
9448 else if (aFlag == "-mode"
9449 || aFlag == "-stereomode")
9450 {
9451 if (++anArgIter >= theArgNb
9452 || !parseStereoMode (theArgVec[anArgIter], aMode))
9453 {
9454 std::cout << "Error: syntax error at '" << anArg << "'\n";
9455 return 1;
9456 }
9457
9458 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9459 {
9460 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9461 }
9462 }
9463 else if (aFlag == "-anaglyph"
9464 || aFlag == "-anaglyphfilter")
9465 {
9466 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9467 if (++anArgIter >= theArgNb
9468 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
9469 {
9470 std::cout << "Error: syntax error at '" << anArg << "'\n";
9471 return 1;
9472 }
9473
9474 aMode = Graphic3d_StereoMode_Anaglyph;
9475 aParams->AnaglyphFilter = aFilter;
9476 }
9477 else if (parseStereoMode (anArg, aMode)) // short syntax
9478 {
9479 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9480 {
9481 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9482 }
9483 }
9484 else
9485 {
9486 std::cout << "Error: syntax error at '" << anArg << "'\n";
9487 return 1;
9488 }
9489 }
9490
9491 if (!aView.IsNull())
9492 {
9493 aParams->StereoMode = aMode;
9494 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9495 }
b5ac8292 9496 return 0;
9497}
9498
392ac980 9499//===============================================================================================
9500//function : VDefaults
9501//purpose :
9502//===============================================================================================
9503static int VDefaults (Draw_Interpretor& theDi,
9504 Standard_Integer theArgsNb,
9505 const char** theArgVec)
9506{
9507 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9508 if (aCtx.IsNull())
9509 {
9510 std::cerr << "No active viewer!\n";
9511 return 1;
9512 }
9513
9514 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
9515 if (theArgsNb < 2)
9516 {
9517 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
9518 {
9519 theDi << "DeflType: relative\n"
9520 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
9521 }
9522 else
9523 {
9524 theDi << "DeflType: absolute\n"
9525 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
9526 }
9527 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
4c513386 9528 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
392ac980 9529 return 0;
9530 }
9531
9532 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9533 {
9534 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4c513386 9535 anArg.UpperCase();
9536 if (anArg == "-ABSDEFL"
9537 || anArg == "-ABSOLUTEDEFLECTION"
9538 || anArg == "-DEFL"
9539 || anArg == "-DEFLECTION")
392ac980 9540 {
4c513386 9541 if (++anArgIter >= theArgsNb)
9542 {
9543 std::cout << "Error: wrong syntax at " << anArg << "\n";
9544 return 1;
9545 }
392ac980 9546 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
4c513386 9547 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
392ac980 9548 }
4c513386 9549 else if (anArg == "-RELDEFL"
9550 || anArg == "-RELATIVEDEFLECTION"
9551 || anArg == "-DEVCOEFF"
9552 || anArg == "-DEVIATIONCOEFF"
9553 || anArg == "-DEVIATIONCOEFFICIENT")
392ac980 9554 {
4c513386 9555 if (++anArgIter >= theArgsNb)
9556 {
9557 std::cout << "Error: wrong syntax at " << anArg << "\n";
9558 return 1;
9559 }
392ac980 9560 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
4c513386 9561 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
392ac980 9562 }
4c513386 9563 else if (anArg == "-ANGDEFL"
9564 || anArg == "-ANGULARDEFL"
9565 || anArg == "-ANGULARDEFLECTION")
392ac980 9566 {
4c513386 9567 if (++anArgIter >= theArgsNb)
9568 {
9569 std::cout << "Error: wrong syntax at " << anArg << "\n";
9570 return 1;
9571 }
392ac980 9572 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
4c513386 9573 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
9574 }
385c43e7 9575 else if (anArg == "-AUTOTR"
9576 || anArg == "-AUTOTRIANG"
9577 || anArg == "-AUTOTRIANGULATION")
4c513386 9578 {
9579 if (++anArgIter >= theArgsNb)
9580 {
9581 std::cout << "Error: wrong syntax at " << anArg << "\n";
9582 return 1;
9583 }
9584 TCollection_AsciiString aValue (theArgVec[anArgIter]);
9585 aValue.LowerCase();
9586 if (aValue == "on"
9587 || aValue == "1")
9588 {
9589 aDefParams->SetAutoTriangulation (Standard_True);
9590 }
9591 else if (aValue == "off"
9592 || aValue == "0")
9593 {
9594 aDefParams->SetAutoTriangulation (Standard_False);
9595 }
392ac980 9596 }
9597 else
9598 {
9599 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
9600 }
9601 }
9602
9603 return 0;
9604}
9605
12381341 9606//! Auxiliary method
9607inline void addLight (const Handle(V3d_Light)& theLightNew,
992ed6b3 9608 const Graphic3d_ZLayerId theLayer,
12381341 9609 const Standard_Boolean theIsGlobal)
9610{
9611 if (theLightNew.IsNull())
9612 {
9613 return;
9614 }
9615
992ed6b3 9616 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9617 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
12381341 9618 {
992ed6b3 9619 aViewer->AddLight (theLightNew);
9620 if (theIsGlobal)
9621 {
9622 aViewer->SetLightOn (theLightNew);
9623 }
9624 else
9625 {
9626 ViewerTest::CurrentView()->SetLightOn (theLightNew);
9627 }
12381341 9628 }
9629 else
9630 {
992ed6b3 9631 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
9632 if (aSettings.Lights().IsNull())
9633 {
9634 aSettings.SetLights (new Graphic3d_LightSet());
9635 }
9636 aSettings.Lights()->Add (theLightNew);
9637 aViewer->SetZLayerSettings (theLayer, aSettings);
12381341 9638 }
9639}
9640
9641//! Auxiliary method
9642inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
9643{
9644 TCollection_AsciiString anArgNextCase (theArgNext);
9645 anArgNextCase.UpperCase();
9646 if (anArgNextCase.Length() > 5
9647 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
9648 {
9649 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
9650 }
9651 else
9652 {
9653 return theArgNext.IntegerValue();
9654 }
9655}
9656
9657//===============================================================================================
9658//function : VLight
9659//purpose :
9660//===============================================================================================
9661static int VLight (Draw_Interpretor& theDi,
9662 Standard_Integer theArgsNb,
9663 const char** theArgVec)
9664{
9665 Handle(V3d_View) aView = ViewerTest::CurrentView();
9666 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9667 if (aView.IsNull()
9668 || aViewer.IsNull())
9669 {
9670 std::cerr << "No active viewer!\n";
9671 return 1;
9672 }
9673
ee2be2a8 9674 Standard_Real anXYZ[3] = {};
9675 Standard_Real anAtten[2] = {};
12381341 9676 if (theArgsNb < 2)
9677 {
9678 // print lights info
9679 Standard_Integer aLightId = 0;
6a24c6de 9680 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
12381341 9681 {
6a24c6de 9682 Handle(V3d_Light) aLight = aLightIter.Value();
12381341 9683 const Quantity_Color aColor = aLight->Color();
992ed6b3 9684 theDi << "Light #" << aLightId
9685 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
9686 << " [" << aLight->GetId() << "]" << "\n";
12381341 9687 switch (aLight->Type())
9688 {
9689 case V3d_AMBIENT:
9690 {
189f85a3 9691 theDi << " Type: Ambient\n";
9692 theDi << " Intensity: " << aLight->Intensity() << "\n";
12381341 9693 break;
9694 }
9695 case V3d_DIRECTIONAL:
9696 {
189f85a3 9697 theDi << " Type: Directional\n";
9698 theDi << " Intensity: " << aLight->Intensity() << "\n";
9699 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9700 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
992ed6b3 9701 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9702 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
12381341 9703 break;
9704 }
9705 case V3d_POSITIONAL:
9706 {
189f85a3 9707 theDi << " Type: Positional\n";
9708 theDi << " Intensity: " << aLight->Intensity() << "\n";
9709 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9710 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
992ed6b3 9711 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9712 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9713 aLight->Attenuation (anAtten[0], anAtten[1]);
9714 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
12381341 9715 break;
9716 }
9717 case V3d_SPOT:
9718 {
189f85a3 9719 theDi << " Type: Spot\n";
9720 theDi << " Intensity: " << aLight->Intensity() << "\n";
9721 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
992ed6b3 9722 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9723 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9724 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9725 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9726 aLight->Attenuation (anAtten[0], anAtten[1]);
9727 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9728 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
9729 theDi << " Exponent: " << aLight->Concentration() << "\n";
12381341 9730 break;
9731 }
9732 default:
9733 {
189f85a3 9734 theDi << " Type: UNKNOWN\n";
12381341 9735 break;
9736 }
9737 }
992ed6b3 9738 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
12381341 9739 }
9740 }
9741
9742 Handle(V3d_Light) aLightNew;
9743 Handle(V3d_Light) aLightOld;
992ed6b3 9744 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
12381341 9745 Standard_Boolean isGlobal = Standard_True;
9746 Standard_Boolean toCreate = Standard_False;
761d8807 9747 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
12381341 9748 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
9749 {
992ed6b3 9750 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
12381341 9751
9752 TCollection_AsciiString aName, aValue;
9753 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
9754 TCollection_AsciiString anArgCase (anArg);
9755 anArgCase.UpperCase();
761d8807 9756 if (anUpdateTool.parseRedrawMode (anArg))
9757 {
9758 continue;
9759 }
9760
12381341 9761 if (anArgCase.IsEqual ("NEW")
9762 || anArgCase.IsEqual ("ADD")
992ed6b3 9763 || anArgCase.IsEqual ("CREATE")
9764 || anArgCase.IsEqual ("-NEW")
9765 || anArgCase.IsEqual ("-ADD")
9766 || anArgCase.IsEqual ("-CREATE"))
12381341 9767 {
9768 toCreate = Standard_True;
9769 }
992ed6b3 9770 else if (anArgCase.IsEqual ("-LAYER")
9771 || anArgCase.IsEqual ("-ZLAYER"))
9772 {
9773 if (++anArgIt >= theArgsNb)
9774 {
9775 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9776 return 1;
9777 }
9778
9779 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
9780 aValStr.LowerCase();
9781 if (aValStr == "default"
9782 || aValStr == "def")
9783 {
9784 aLayer = Graphic3d_ZLayerId_Default;
9785 }
9786 else if (aValStr == "top")
9787 {
9788 aLayer = Graphic3d_ZLayerId_Top;
9789 }
9790 else if (aValStr == "topmost")
9791 {
9792 aLayer = Graphic3d_ZLayerId_Topmost;
9793 }
9794 else if (aValStr == "toposd"
9795 || aValStr == "osd")
9796 {
9797 aLayer = Graphic3d_ZLayerId_TopOSD;
9798 }
9799 else if (aValStr == "botosd"
9800 || aValStr == "bottom")
9801 {
9802 aLayer = Graphic3d_ZLayerId_BotOSD;
9803 }
9804 else if (aValStr.IsIntegerValue())
9805 {
9806 aLayer = Draw::Atoi (theArgVec[anArgIt]);
9807 }
9808 else
9809 {
9810 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
9811 return 1;
9812 }
9813 }
12381341 9814 else if (anArgCase.IsEqual ("GLOB")
992ed6b3 9815 || anArgCase.IsEqual ("GLOBAL")
9816 || anArgCase.IsEqual ("-GLOB")
9817 || anArgCase.IsEqual ("-GLOBAL"))
12381341 9818 {
9819 isGlobal = Standard_True;
9820 }
9821 else if (anArgCase.IsEqual ("LOC")
992ed6b3 9822 || anArgCase.IsEqual ("LOCAL")
9823 || anArgCase.IsEqual ("-LOC")
9824 || anArgCase.IsEqual ("-LOCAL"))
12381341 9825 {
9826 isGlobal = Standard_False;
9827 }
4fe9ad57 9828 else if (anArgCase.IsEqual ("DEF")
992ed6b3 9829 || anArgCase.IsEqual ("DEFAULTS")
9830 || anArgCase.IsEqual ("-DEF")
9831 || anArgCase.IsEqual ("-DEFAULTS"))
4fe9ad57 9832 {
9833 toCreate = Standard_False;
9834 aViewer->SetDefaultLights();
9835 }
9836 else if (anArgCase.IsEqual ("CLR")
992ed6b3 9837 || anArgCase.IsEqual ("CLEAR")
9838 || anArgCase.IsEqual ("-CLR")
9839 || anArgCase.IsEqual ("-CLEAR"))
4fe9ad57 9840 {
9841 toCreate = Standard_False;
992ed6b3 9842
9843 TColStd_SequenceOfInteger aLayers;
9844 aViewer->GetAllZLayers (aLayers);
9845 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4fe9ad57 9846 {
992ed6b3 9847 if (aLayeriter.Value() == aLayer
9848 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9849 {
9850 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9851 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9852 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9853 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9854 {
9855 break;
9856 }
9857 }
9858 }
9859
9860 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
9861 {
9862 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
9863 {
9864 Handle(V3d_Light) aLight = aLightIter.Value();
9865 aViewer->DelLight (aLight);
9866 aLightIter = aView->ActiveLightIterator();
9867 }
4fe9ad57 9868 }
9869 }
12381341 9870 else if (anArgCase.IsEqual ("AMB")
9871 || anArgCase.IsEqual ("AMBIENT")
9872 || anArgCase.IsEqual ("AMBLIGHT"))
9873 {
12381341 9874 if (!toCreate)
9875 {
9876 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9877 return 1;
9878 }
992ed6b3 9879
9880 addLight (aLightNew, aLayer, isGlobal);
12381341 9881 toCreate = Standard_False;
992ed6b3 9882 aLightNew = new V3d_AmbientLight();
12381341 9883 }
9884 else if (anArgCase.IsEqual ("DIRECTIONAL")
9885 || anArgCase.IsEqual ("DIRLIGHT"))
9886 {
12381341 9887 if (!toCreate)
9888 {
9889 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9890 return 1;
9891 }
992ed6b3 9892
9893 addLight (aLightNew, aLayer, isGlobal);
12381341 9894 toCreate = Standard_False;
992ed6b3 9895 aLightNew = new V3d_DirectionalLight();
12381341 9896 }
9897 else if (anArgCase.IsEqual ("SPOT")
9898 || anArgCase.IsEqual ("SPOTLIGHT"))
9899 {
12381341 9900 if (!toCreate)
9901 {
9902 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9903 return 1;
9904 }
992ed6b3 9905
9906 addLight (aLightNew, aLayer, isGlobal);
12381341 9907 toCreate = Standard_False;
992ed6b3 9908 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
12381341 9909 }
9910 else if (anArgCase.IsEqual ("POSLIGHT")
9911 || anArgCase.IsEqual ("POSITIONAL"))
9912 {
12381341 9913 if (!toCreate)
9914 {
9915 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9916 return 1;
9917 }
992ed6b3 9918
9919 addLight (aLightNew, aLayer, isGlobal);
12381341 9920 toCreate = Standard_False;
992ed6b3 9921 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
12381341 9922 }
992ed6b3 9923 else if (anArgCase.IsEqual ("CHANGE")
9924 || anArgCase.IsEqual ("-CHANGE"))
12381341 9925 {
12381341 9926 if (++anArgIt >= theArgsNb)
9927 {
9928 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9929 return 1;
9930 }
9931
992ed6b3 9932 addLight (aLightNew, aLayer, isGlobal);
9933 aLightNew.Nullify();
12381341 9934 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
9935 Standard_Integer aLightIt = 0;
6a24c6de 9936 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
12381341 9937 {
9938 if (aLightIt == aLightId)
9939 {
6a24c6de 9940 aLightOld = aLightIter.Value();
12381341 9941 break;
9942 }
9943 }
9944
9945 if (aLightOld.IsNull())
9946 {
9947 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
9948 return 1;
9949 }
9950 }
9951 else if (anArgCase.IsEqual ("DEL")
992ed6b3 9952 || anArgCase.IsEqual ("DELETE")
9953 || anArgCase.IsEqual ("-DEL")
9954 || anArgCase.IsEqual ("-DELETE"))
12381341 9955 {
9956 Handle(V3d_Light) aLightDel;
9957 if (++anArgIt >= theArgsNb)
9958 {
9959 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9960 return 1;
9961 }
9962
9963 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9964 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
9965 Standard_Integer aLightIt = 0;
6a24c6de 9966 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
12381341 9967 {
6a24c6de 9968 aLightDel = aLightIter.Value();
12381341 9969 if (aLightIt == aLightDelId)
9970 {
9971 break;
9972 }
9973 }
992ed6b3 9974 if (aLightDel.IsNull())
9975 {
9976 continue;
9977 }
9978
9979 TColStd_SequenceOfInteger aLayers;
9980 aViewer->GetAllZLayers (aLayers);
9981 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9982 {
9983 if (aLayeriter.Value() == aLayer
9984 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9985 {
9986 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9987 if (!aSettings.Lights().IsNull())
9988 {
9989 aSettings.Lights()->Remove (aLightDel);
9990 if (aSettings.Lights()->IsEmpty())
9991 {
9992 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9993 }
9994 }
9995 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9996 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9997 {
9998 break;
9999 }
10000 }
10001 }
10002
10003 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
12381341 10004 {
10005 aViewer->DelLight (aLightDel);
10006 }
10007 }
10008 else if (anArgCase.IsEqual ("COLOR")
992ed6b3 10009 || anArgCase.IsEqual ("COLOUR")
10010 || anArgCase.IsEqual ("-COLOR")
10011 || anArgCase.IsEqual ("-COLOUR"))
12381341 10012 {
992ed6b3 10013 if (++anArgIt >= theArgsNb
10014 || aLightCurr.IsNull())
12381341 10015 {
10016 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10017 return 1;
10018 }
10019
10020 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10021 anArgNext.UpperCase();
10022 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
992ed6b3 10023 aLightCurr->SetColor (aColor);
12381341 10024 }
10025 else if (anArgCase.IsEqual ("POS")
992ed6b3 10026 || anArgCase.IsEqual ("POSITION")
10027 || anArgCase.IsEqual ("-POS")
10028 || anArgCase.IsEqual ("-POSITION"))
12381341 10029 {
992ed6b3 10030 if ((anArgIt + 3) >= theArgsNb
10031 || aLightCurr.IsNull()
10032 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10033 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 10034 {
10035 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10036 return 1;
10037 }
10038
10039 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10040 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10041 anXYZ[2] = Atof (theArgVec[++anArgIt]);
992ed6b3 10042 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
12381341 10043 }
10044 else if (anArgCase.IsEqual ("DIR")
992ed6b3 10045 || anArgCase.IsEqual ("DIRECTION")
10046 || anArgCase.IsEqual ("-DIR")
10047 || anArgCase.IsEqual ("-DIRECTION"))
12381341 10048 {
992ed6b3 10049 if ((anArgIt + 3) >= theArgsNb
10050 || aLightCurr.IsNull()
10051 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
10052 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 10053 {
10054 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10055 return 1;
10056 }
10057
10058 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10059 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10060 anXYZ[2] = Atof (theArgVec[++anArgIt]);
992ed6b3 10061 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
12381341 10062 }
189f85a3 10063 else if (anArgCase.IsEqual ("SM")
992ed6b3 10064 || anArgCase.IsEqual ("SMOOTHNESS")
10065 || anArgCase.IsEqual ("-SM")
10066 || anArgCase.IsEqual ("-SMOOTHNESS"))
189f85a3 10067 {
992ed6b3 10068 if (++anArgIt >= theArgsNb
10069 || aLightCurr.IsNull())
189f85a3 10070 {
10071 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10072 return 1;
10073 }
10074
992ed6b3 10075 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10076 if (Abs (aSmoothness) <= ShortRealEpsilon())
189f85a3 10077 {
10078 aLightCurr->SetIntensity (1.f);
10079 }
992ed6b3 10080 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
189f85a3 10081 {
10082 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
10083 }
10084 else
10085 {
10086 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
10087 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
10088 }
10089
992ed6b3 10090 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
189f85a3 10091 {
992ed6b3 10092 aLightCurr->SetSmoothRadius (aSmoothness);
189f85a3 10093 }
992ed6b3 10094 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
189f85a3 10095 {
992ed6b3 10096 aLightCurr->SetSmoothAngle (aSmoothness);
189f85a3 10097 }
10098 }
10099 else if (anArgCase.IsEqual ("INT")
992ed6b3 10100 || anArgCase.IsEqual ("INTENSITY")
10101 || anArgCase.IsEqual ("-INT")
10102 || anArgCase.IsEqual ("-INTENSITY"))
189f85a3 10103 {
992ed6b3 10104 if (++anArgIt >= theArgsNb
10105 || aLightCurr.IsNull())
189f85a3 10106 {
10107 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10108 return 1;
10109 }
10110
992ed6b3 10111 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10112 aLightCurr->SetIntensity (aIntensity);
189f85a3 10113 }
4fe9ad57 10114 else if (anArgCase.IsEqual ("ANG")
992ed6b3 10115 || anArgCase.IsEqual ("ANGLE")
10116 || anArgCase.IsEqual ("-ANG")
10117 || anArgCase.IsEqual ("-ANGLE"))
4fe9ad57 10118 {
992ed6b3 10119 if (++anArgIt >= theArgsNb
10120 || aLightCurr.IsNull()
10121 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
4fe9ad57 10122 {
10123 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10124 return 1;
10125 }
10126
992ed6b3 10127 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10128 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
4fe9ad57 10129 }
12381341 10130 else if (anArgCase.IsEqual ("CONSTATTEN")
992ed6b3 10131 || anArgCase.IsEqual ("CONSTATTENUATION")
10132 || anArgCase.IsEqual ("-CONSTATTEN")
10133 || anArgCase.IsEqual ("-CONSTATTENUATION"))
12381341 10134 {
992ed6b3 10135 if (++anArgIt >= theArgsNb
10136 || aLightCurr.IsNull()
10137 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10138 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 10139 {
10140 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10141 return 1;
10142 }
10143
992ed6b3 10144 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10145 anAtten[0] = Atof (theArgVec[anArgIt]);
10146 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
12381341 10147 }
10148 else if (anArgCase.IsEqual ("LINATTEN")
10149 || anArgCase.IsEqual ("LINEARATTEN")
992ed6b3 10150 || anArgCase.IsEqual ("LINEARATTENUATION")
10151 || anArgCase.IsEqual ("-LINATTEN")
10152 || anArgCase.IsEqual ("-LINEARATTEN")
10153 || anArgCase.IsEqual ("-LINEARATTENUATION"))
12381341 10154 {
992ed6b3 10155 if (++anArgIt >= theArgsNb
10156 || aLightCurr.IsNull()
10157 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10158 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 10159 {
10160 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10161 return 1;
10162 }
10163
992ed6b3 10164 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10165 anAtten[1] = Atof (theArgVec[anArgIt]);
10166 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
12381341 10167 }
10168 else if (anArgCase.IsEqual ("EXP")
10169 || anArgCase.IsEqual ("EXPONENT")
10170 || anArgCase.IsEqual ("SPOTEXP")
992ed6b3 10171 || anArgCase.IsEqual ("SPOTEXPONENT")
10172 || anArgCase.IsEqual ("-EXP")
10173 || anArgCase.IsEqual ("-EXPONENT")
10174 || anArgCase.IsEqual ("-SPOTEXP")
10175 || anArgCase.IsEqual ("-SPOTEXPONENT"))
12381341 10176 {
992ed6b3 10177 if (++anArgIt >= theArgsNb
10178 || aLightCurr.IsNull()
10179 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
12381341 10180 {
10181 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10182 return 1;
10183 }
10184
992ed6b3 10185 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
12381341 10186 }
10187 else if (anArgCase.IsEqual ("HEAD")
992ed6b3 10188 || anArgCase.IsEqual ("HEADLIGHT")
10189 || anArgCase.IsEqual ("-HEAD")
10190 || anArgCase.IsEqual ("-HEADLIGHT"))
12381341 10191 {
992ed6b3 10192 if (aLightCurr.IsNull()
10193 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
12381341 10194 {
10195 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10196 return 1;
10197 }
10198
992ed6b3 10199 Standard_Boolean isHeadLight = Standard_True;
10200 if (anArgIt + 1 < theArgsNb
10201 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
12381341 10202 {
992ed6b3 10203 ++anArgIt;
12381341 10204 }
992ed6b3 10205 aLightCurr->SetHeadlight (isHeadLight);
12381341 10206 }
10207 else
10208 {
10209 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
10210 }
10211 }
10212
992ed6b3 10213 addLight (aLightNew, aLayer, isGlobal);
12381341 10214 return 0;
10215}
10216
15669413 10217//! Read Graphic3d_RenderingParams::PerfCounters flag.
10218static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
10219 Standard_Boolean& theToReset,
10220 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
10221 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
10222{
10223 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
10224 TCollection_AsciiString aVal = theValue;
10225 Standard_Boolean toReverse = Standard_False;
10226 if (aVal == "none")
10227 {
10228 theToReset = Standard_True;
10229 return Standard_True;
10230 }
10231 else if (aVal.StartsWith ("-"))
10232 {
10233 toReverse = Standard_True;
10234 aVal = aVal.SubString (2, aVal.Length());
10235 }
10236 else if (aVal.StartsWith ("no"))
10237 {
10238 toReverse = Standard_True;
10239 aVal = aVal.SubString (3, aVal.Length());
10240 }
10241 else if (aVal.StartsWith ("+"))
10242 {
10243 aVal = aVal.SubString (2, aVal.Length());
10244 }
10245 else
10246 {
10247 theToReset = Standard_True;
10248 }
10249
10250 if ( aVal == "fps"
10251 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
10252 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
10253 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
10254 else if (aVal == "structs"
10255 || aVal == "structures"
10256 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
10257 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
10258 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
10259 else if (aVal == "tris"
10260 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
10261 else if (aVal == "pnts"
10262 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
10263 else if (aVal == "mem"
10264 || aVal == "gpumem"
10265 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
5e30547b 10266 else if (aVal == "skipimmediate"
10267 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
10268 else if (aVal == "frametime"
10269 || aVal == "frametimers"
10270 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
15669413 10271 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
10272 else if (aVal == "extended"
10273 || aVal == "verbose"
10274 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
5e30547b 10275 else if (aVal == "full"
10276 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
15669413 10277 else
10278 {
10279 return Standard_False;
10280 }
10281
10282 if (toReverse)
10283 {
10284 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
10285 }
10286 else
10287 {
10288 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
10289 }
10290 return Standard_True;
10291}
10292
10293//! Read Graphic3d_RenderingParams::PerfCounters flags.
10294static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
10295 Graphic3d_RenderingParams::PerfCounters& theFlags)
10296{
10297 TCollection_AsciiString aValue = theValue;
10298 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
10299 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
10300 Standard_Boolean toReset = Standard_False;
10301 for (;;)
10302 {
10303 Standard_Integer aSplitPos = aValue.Search ("|");
10304 if (aSplitPos <= 0)
10305 {
10306 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
10307 {
10308 return Standard_False;
10309 }
10310 if (toReset)
10311 {
10312 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
10313 }
10314 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
10315 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
10316 return Standard_True;
10317 }
10318
10319 if (aSplitPos > 1)
10320 {
10321 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
10322 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
10323 {
10324 return Standard_False;
10325 }
10326 }
10327 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
10328 }
10329}
10330
e276548b 10331//=======================================================================
bc8c79bb 10332//function : VRenderParams
10333//purpose : Enables/disables rendering features
e276548b 10334//=======================================================================
10335
bc8c79bb 10336static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
10337 Standard_Integer theArgNb,
10338 const char** theArgVec)
e276548b 10339{
7ae4a307 10340 Handle(V3d_View) aView = ViewerTest::CurrentView();
10341 if (aView.IsNull())
e276548b 10342 {
bc8c79bb 10343 std::cerr << "Error: no active viewer!\n";
e276548b 10344 return 1;
10345 }
bc8c79bb 10346
10347 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
6b62b2da 10348 TCollection_AsciiString aCmdName (theArgVec[0]);
10349 aCmdName.LowerCase();
10350 if (aCmdName == "vraytrace")
10351 {
10352 if (theArgNb == 1)
10353 {
10354 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
10355 return 0;
10356 }
10357 else if (theArgNb == 2)
10358 {
10359 TCollection_AsciiString aValue (theArgVec[1]);
10360 aValue.LowerCase();
10361 if (aValue == "on"
10362 || aValue == "1")
10363 {
10364 aParams.Method = Graphic3d_RM_RAYTRACING;
10365 aView->Redraw();
10366 return 0;
10367 }
10368 else if (aValue == "off"
10369 || aValue == "0")
10370 {
10371 aParams.Method = Graphic3d_RM_RASTERIZATION;
10372 aView->Redraw();
10373 return 0;
10374 }
10375 else
10376 {
10377 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
10378 return 1;
10379 }
10380 }
10381 else
10382 {
10383 std::cout << "Error: wrong number of arguments\n";
10384 return 1;
10385 }
10386 }
bc8c79bb 10387
10388 if (theArgNb < 2)
e276548b 10389 {
bc8c79bb 10390 theDI << "renderMode: ";
10391 switch (aParams.Method)
10392 {
10393 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10394 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
10395 }
10396 theDI << "\n";
a1073ae2 10397 theDI << "transparency: ";
10398 switch (aParams.TransparencyMethod)
10399 {
10400 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
10401 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
10402 << TCollection_AsciiString (aParams.OitDepthFactor); break;
10403 }
10404 theDI << "\n";
b4327ba8 10405 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
56689b27 10406 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
b4327ba8 10407 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
10408 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
10409 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
10410 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
10411 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
10412 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
10413 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
10414 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
10415 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
10416 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
b09447ed 10417 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
4eaaf9d8 10418 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
66d1cdc6 10419 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
8625ef7e 10420 theDI << "shadingModel: ";
10421 switch (aView->ShadingModel())
10422 {
dc89236f 10423 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10424 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
10425 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
10426 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
10427 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
8625ef7e 10428 }
15669413 10429 {
10430 theDI << "perfCounters:";
10431 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
10432 {
10433 theDI << " fps";
10434 }
10435 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
10436 {
10437 theDI << " cpu";
10438 }
10439 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
10440 {
10441 theDI << " structs";
10442 }
10443 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
10444 {
10445 theDI << " groups";
10446 }
10447 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
10448 {
10449 theDI << " arrays";
10450 }
10451 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
10452 {
10453 theDI << " tris";
10454 }
10455 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
10456 {
10457 theDI << " pnts";
10458 }
10459 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
10460 {
10461 theDI << " gpumem";
10462 }
5e30547b 10463 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
10464 {
10465 theDI << " frameTime";
10466 }
10467 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
10468 {
10469 theDI << " skipimmediate";
10470 }
15669413 10471 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
10472 {
10473 theDI << " none";
10474 }
10475 theDI << "\n";
10476 }
f88457e6 10477 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
c40eb6b9 10478 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
0e3025bc 10479 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
10480 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
10481 "noUpdate") << "\n";
8625ef7e 10482 theDI << "\n";
bc8c79bb 10483 return 0;
e276548b 10484 }
10485
bc8c79bb 10486 Standard_Boolean toPrint = Standard_False;
8625ef7e 10487 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
e276548b 10488 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10489 {
bc8c79bb 10490 Standard_CString anArg (theArgVec[anArgIter]);
10491 TCollection_AsciiString aFlag (anArg);
10492 aFlag.LowerCase();
8625ef7e 10493 if (anUpdateTool.parseRedrawMode (aFlag))
10494 {
10495 continue;
10496 }
10497 else if (aFlag == "-echo"
10498 || aFlag == "-print")
e276548b 10499 {
bc8c79bb 10500 toPrint = Standard_True;
8625ef7e 10501 anUpdateTool.Invalidate();
e276548b 10502 }
bc8c79bb 10503 else if (aFlag == "-mode"
10504 || aFlag == "-rendermode"
10505 || aFlag == "-render_mode")
e276548b 10506 {
bc8c79bb 10507 if (toPrint)
10508 {
10509 switch (aParams.Method)
10510 {
10511 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10512 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
10513 }
10514 continue;
10515 }
e276548b 10516 else
bc8c79bb 10517 {
10518 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10519 return 1;
10520 }
10521 }
10522 else if (aFlag == "-ray"
10523 || aFlag == "-raytrace")
10524 {
10525 if (toPrint)
10526 {
10527 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
10528 continue;
10529 }
10530
10531 aParams.Method = Graphic3d_RM_RAYTRACING;
e276548b 10532 }
bc8c79bb 10533 else if (aFlag == "-rast"
10534 || aFlag == "-raster"
10535 || aFlag == "-rasterization")
e276548b 10536 {
bc8c79bb 10537 if (toPrint)
10538 {
10539 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
10540 continue;
10541 }
10542
10543 aParams.Method = Graphic3d_RM_RASTERIZATION;
10544 }
3c4b62a4 10545 else if (aFlag == "-msaa")
10546 {
10547 if (toPrint)
10548 {
10549 theDI << aParams.NbMsaaSamples << " ";
10550 continue;
10551 }
10552 else if (++anArgIter >= theArgNb)
10553 {
10554 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10555 return 1;
10556 }
10557
10558 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
10559 if (aNbSamples < 0)
10560 {
10561 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
10562 return 1;
10563 }
10564 else
10565 {
10566 aParams.NbMsaaSamples = aNbSamples;
10567 }
10568 }
a1073ae2 10569 else if (aFlag == "-oit")
10570 {
10571 if (toPrint)
10572 {
10573 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
10574 {
10575 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
10576 }
10577 else
10578 {
10579 theDI << "off" << " ";
10580 }
10581 continue;
10582 }
10583 else if (++anArgIter >= theArgNb)
10584 {
10585 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10586 return 1;
10587 }
10588
10589 TCollection_AsciiString aParam = theArgVec[anArgIter];
10590 aParam.LowerCase();
10591 if (aParam.IsRealValue())
10592 {
10593 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10594 if (aWeight < 0.f || aWeight > 1.f)
10595 {
10596 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
10597 return 1;
10598 }
10599
10600 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
10601 aParams.OitDepthFactor = aWeight;
10602 }
10603 else if (aParam == "off")
10604 {
10605 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
10606 }
10607 else
10608 {
10609 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10610 return 1;
10611 }
10612 }
f88457e6 10613 else if (aFlag == "-depthprepass")
10614 {
10615 if (toPrint)
10616 {
10617 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
10618 continue;
10619 }
10620 aParams.ToEnableDepthPrepass = Standard_True;
10621 if (anArgIter + 1 < theArgNb
10622 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
10623 {
10624 ++anArgIter;
10625 }
10626 }
c40eb6b9 10627 else if (aFlag == "-samplealphatocoverage"
10628 || aFlag == "-alphatocoverage")
10629 {
10630 if (toPrint)
10631 {
10632 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
10633 continue;
10634 }
10635 aParams.ToEnableAlphaToCoverage = Standard_True;
10636 if (anArgIter + 1 < theArgNb
10637 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
10638 {
10639 ++anArgIter;
10640 }
10641 }
56689b27 10642 else if (aFlag == "-rendscale"
10643 || aFlag == "-renderscale"
10644 || aFlag == "-renderresolutionscale")
10645 {
10646 if (toPrint)
10647 {
10648 theDI << aParams.RenderResolutionScale << " ";
10649 continue;
10650 }
10651 else if (++anArgIter >= theArgNb)
10652 {
10653 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10654 return 1;
10655 }
10656
10657 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
10658 if (aScale < 0.01)
10659 {
10660 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
10661 return 1;
10662 }
10663 else
10664 {
10665 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
10666 }
10667 }
bc8c79bb 10668 else if (aFlag == "-raydepth"
10669 || aFlag == "-ray_depth")
10670 {
10671 if (toPrint)
10672 {
10673 theDI << aParams.RaytracingDepth << " ";
10674 continue;
10675 }
10676 else if (++anArgIter >= theArgNb)
10677 {
10678 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10679 return 1;
10680 }
10681
10682 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
189f85a3 10683
10684 // We allow RaytracingDepth be more than 10 in case of GI enabled
10685 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
bc8c79bb 10686 {
10687 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
10688 return 1;
10689 }
e276548b 10690 else
bc8c79bb 10691 {
10692 aParams.RaytracingDepth = aDepth;
10693 }
10694 }
10695 else if (aFlag == "-shad"
10696 || aFlag == "-shadows")
10697 {
10698 if (toPrint)
10699 {
10700 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
10701 continue;
10702 }
10703
10704 Standard_Boolean toEnable = Standard_True;
10705 if (++anArgIter < theArgNb
a5565a3c 10706 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 10707 {
10708 --anArgIter;
10709 }
10710 aParams.IsShadowEnabled = toEnable;
10711 }
10712 else if (aFlag == "-refl"
10713 || aFlag == "-reflections")
10714 {
10715 if (toPrint)
10716 {
10717 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
10718 continue;
10719 }
10720
10721 Standard_Boolean toEnable = Standard_True;
10722 if (++anArgIter < theArgNb
a5565a3c 10723 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 10724 {
10725 --anArgIter;
10726 }
10727 aParams.IsReflectionEnabled = toEnable;
10728 }
10729 else if (aFlag == "-fsaa")
10730 {
10731 if (toPrint)
10732 {
10733 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
10734 continue;
10735 }
10736
10737 Standard_Boolean toEnable = Standard_True;
10738 if (++anArgIter < theArgNb
a5565a3c 10739 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 10740 {
10741 --anArgIter;
10742 }
10743 aParams.IsAntialiasingEnabled = toEnable;
10744 }
10745 else if (aFlag == "-gleam")
10746 {
10747 if (toPrint)
10748 {
10749 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
10750 continue;
10751 }
10752
10753 Standard_Boolean toEnable = Standard_True;
10754 if (++anArgIter < theArgNb
a5565a3c 10755 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 10756 {
10757 --anArgIter;
10758 }
10759 aParams.IsTransparentShadowEnabled = toEnable;
e276548b 10760 }
189f85a3 10761 else if (aFlag == "-gi")
10762 {
10763 if (toPrint)
10764 {
10765 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
10766 continue;
10767 }
10768
10769 Standard_Boolean toEnable = Standard_True;
10770 if (++anArgIter < theArgNb
a5565a3c 10771 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
189f85a3 10772 {
10773 --anArgIter;
10774 }
10775 aParams.IsGlobalIlluminationEnabled = toEnable;
10776 if (!toEnable)
10777 {
10778 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
10779 }
10780 }
8c820969 10781 else if (aFlag == "-blockedrng"
10782 || aFlag == "-brng")
10783 {
10784 if (toPrint)
10785 {
10786 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
10787 continue;
10788 }
10789
10790 Standard_Boolean toEnable = Standard_True;
10791 if (++anArgIter < theArgNb
a5565a3c 10792 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8c820969 10793 {
10794 --anArgIter;
10795 }
10796 aParams.CoherentPathTracingMode = toEnable;
10797 }
b09447ed 10798 else if (aFlag == "-maxrad")
10799 {
10800 if (toPrint)
10801 {
10802 theDI << aParams.RadianceClampingValue << " ";
10803 continue;
10804 }
10805 else if (++anArgIter >= theArgNb)
10806 {
10807 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10808 return 1;
10809 }
10810
10811 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
10812 if (!aMaxRadStr.IsRealValue())
10813 {
10814 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10815 return 1;
10816 }
10817
10818 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
10819 if (aMaxRadiance <= 0.0)
10820 {
10821 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
10822 return 1;
10823 }
10824 else
10825 {
10826 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
10827 }
10828 }
3a9b5dc8 10829 else if (aFlag == "-iss")
10830 {
10831 if (toPrint)
10832 {
10833 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
10834 continue;
10835 }
10836
10837 Standard_Boolean toEnable = Standard_True;
10838 if (++anArgIter < theArgNb
10839 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10840 {
10841 --anArgIter;
10842 }
10843 aParams.AdaptiveScreenSampling = toEnable;
10844 }
e084dbbc 10845 else if (aFlag == "-issatomic")
10846 {
10847 if (toPrint)
10848 {
10849 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
10850 continue;
10851 }
10852
10853 Standard_Boolean toEnable = Standard_True;
10854 if (++anArgIter < theArgNb
10855 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10856 {
10857 --anArgIter;
10858 }
10859 aParams.AdaptiveScreenSamplingAtomic = toEnable;
10860 }
3a9b5dc8 10861 else if (aFlag == "-issd")
10862 {
10863 if (toPrint)
10864 {
10865 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
10866 continue;
10867 }
10868
10869 Standard_Boolean toEnable = Standard_True;
10870 if (++anArgIter < theArgNb
10871 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10872 {
10873 --anArgIter;
10874 }
10875 aParams.ShowSamplingTiles = toEnable;
10876 }
66d1cdc6 10877 else if (aFlag == "-tilesize")
10878 {
10879 if (toPrint)
10880 {
10881 theDI << aParams.RayTracingTileSize << " ";
10882 continue;
10883 }
10884 else if (++anArgIter >= theArgNb)
10885 {
10886 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10887 return 1;
10888 }
10889
10890 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
10891 if (aTileSize < 1)
10892 {
10893 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
10894 return 1;
10895 }
10896 aParams.RayTracingTileSize = aTileSize;
10897 }
4eaaf9d8 10898 else if (aFlag == "-nbtiles")
10899 {
10900 if (toPrint)
10901 {
10902 theDI << aParams.NbRayTracingTiles << " ";
10903 continue;
10904 }
10905 else if (++anArgIter >= theArgNb)
10906 {
10907 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10908 return 1;
10909 }
10910
10911 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
66d1cdc6 10912 if (aNbTiles < -1)
4eaaf9d8 10913 {
10914 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
4eaaf9d8 10915 return 1;
10916 }
66d1cdc6 10917 else if (aNbTiles > 0
10918 && (aNbTiles < 64
10919 || aNbTiles > 1024))
4eaaf9d8 10920 {
66d1cdc6 10921 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
4eaaf9d8 10922 }
66d1cdc6 10923 aParams.NbRayTracingTiles = aNbTiles;
4eaaf9d8 10924 }
189f85a3 10925 else if (aFlag == "-env")
10926 {
10927 if (toPrint)
10928 {
10929 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
10930 continue;
10931 }
10932
10933 Standard_Boolean toEnable = Standard_True;
10934 if (++anArgIter < theArgNb
a5565a3c 10935 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
189f85a3 10936 {
10937 --anArgIter;
10938 }
10939 aParams.UseEnvironmentMapBackground = toEnable;
10940 }
b4327ba8 10941 else if (aFlag == "-twoside")
10942 {
10943 if (toPrint)
10944 {
10945 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
10946 continue;
10947 }
10948
10949 Standard_Boolean toEnable = Standard_True;
10950 if (++anArgIter < theArgNb
10951 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10952 {
10953 --anArgIter;
10954 }
10955 aParams.TwoSidedBsdfModels = toEnable;
10956 }
8625ef7e 10957 else if (aFlag == "-shademodel"
10958 || aFlag == "-shadingmodel"
10959 || aFlag == "-shading")
10960 {
10961 if (toPrint)
10962 {
10963 switch (aView->ShadingModel())
10964 {
dc89236f 10965 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10966 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
10967 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
10968 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
10969 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
8625ef7e 10970 }
10971 continue;
10972 }
10973
10974 if (++anArgIter >= theArgNb)
10975 {
10976 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10977 }
10978
dc89236f 10979 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
10980 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
10981 && aModel != Graphic3d_TOSM_DEFAULT)
8625ef7e 10982 {
dc89236f 10983 aView->SetShadingModel (aModel);
8625ef7e 10984 }
10985 else
10986 {
dc89236f 10987 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
8625ef7e 10988 return 1;
10989 }
10990 }
4b1c8733 10991 else if (aFlag == "-resolution")
10992 {
10993 if (++anArgIter >= theArgNb)
10994 {
10995 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10996 return 1;
10997 }
10998
10999 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
11000 if (aResolution.IsIntegerValue())
11001 {
11002 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
11003 }
11004 else
11005 {
11006 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11007 return 1;
11008 }
11009 }
d877e610 11010 else if (aFlag == "-rebuildglsl"
11011 || aFlag == "-rebuild")
11012 {
11013 if (toPrint)
11014 {
11015 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
11016 continue;
11017 }
11018
11019 Standard_Boolean toEnable = Standard_True;
11020 if (++anArgIter < theArgNb
11021 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11022 {
11023 --anArgIter;
11024 }
11025 aParams.RebuildRayTracingShaders = toEnable;
11026 }
b27ab03d 11027 else if (aFlag == "-focal")
11028 {
11029 if (++anArgIter >= theArgNb)
11030 {
11031 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11032 return 1;
11033 }
11034
11035 TCollection_AsciiString aParam (theArgVec[anArgIter]);
11036 if (aParam.IsRealValue())
11037 {
11038 float aFocalDist = static_cast<float> (aParam.RealValue());
11039 if (aFocalDist < 0)
11040 {
11041 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
11042 return 1;
11043 }
11044 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
11045 }
11046 else
11047 {
11048 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11049 return 1;
11050 }
11051 }
11052 else if (aFlag == "-aperture")
11053 {
11054 if (++anArgIter >= theArgNb)
11055 {
11056 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11057 return 1;
11058 }
11059
11060 TCollection_AsciiString aParam(theArgVec[anArgIter]);
11061 if (aParam.IsRealValue())
11062 {
11063 float aApertureSize = static_cast<float> (aParam.RealValue());
11064 if (aApertureSize < 0)
11065 {
11066 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
11067 return 1;
11068 }
11069 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
11070 }
11071 else
11072 {
11073 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11074 return 1;
11075 }
11076 }
eb85ed36 11077 else if (aFlag == "-exposure")
11078 {
11079 if (++anArgIter >= theArgNb)
11080 {
11081 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11082 return 1;
11083 }
11084
11085 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
11086 if (anExposure.IsRealValue())
11087 {
11088 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
11089 }
11090 else
11091 {
11092 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11093 return 1;
11094 }
11095 }
11096 else if (aFlag == "-whitepoint")
11097 {
11098 if (++anArgIter >= theArgNb)
11099 {
11100 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11101 return 1;
11102 }
11103
11104 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
11105 if (aWhitePoint.IsRealValue())
11106 {
11107 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
11108 }
11109 else
11110 {
11111 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11112 return 1;
11113 }
11114 }
11115 else if (aFlag == "-tonemapping")
11116 {
11117 if (++anArgIter >= theArgNb)
11118 {
11119 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11120 return 1;
11121 }
11122
11123 TCollection_AsciiString aMode (theArgVec[anArgIter]);
11124 aMode.LowerCase();
11125
11126 if (aMode == "disabled")
11127 {
11128 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
11129 }
11130 else if (aMode == "filmic")
11131 {
11132 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
11133 }
11134 else
11135 {
11136 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11137 return 1;
11138 }
11139 }
15669413 11140 else if (aFlag == "-performancestats"
11141 || aFlag == "-performancecounters"
11142 || aFlag == "-perfstats"
11143 || aFlag == "-perfcounters"
11144 || aFlag == "-stats")
11145 {
11146 if (++anArgIter >= theArgNb)
11147 {
11148 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11149 return 1;
11150 }
11151
11152 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
11153 aFlagsStr.LowerCase();
11154 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
11155 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
11156 {
11157 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11158 return 1;
11159 }
11160 aView->ChangeRenderingParams().CollectedStats = aFlags;
11161 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
11162 }
11163 else if (aFlag == "-perfupdateinterval"
11164 || aFlag == "-statsupdateinterval")
11165 {
11166 if (++anArgIter >= theArgNb)
11167 {
11168 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11169 return 1;
11170 }
11171 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11172 }
5e30547b 11173 else if (aFlag == "-perfchart"
11174 || aFlag == "-statschart")
11175 {
11176 if (++anArgIter >= theArgNb)
11177 {
11178 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11179 return 1;
11180 }
11181 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
11182 }
11183 else if (aFlag == "-perfchartmax"
11184 || aFlag == "-statschartmax")
11185 {
11186 if (++anArgIter >= theArgNb)
11187 {
11188 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11189 return 1;
11190 }
11191 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11192 }
0e3025bc 11193 else if (aFlag == "-frustumculling"
11194 || aFlag == "-culling")
11195 {
11196 if (toPrint)
11197 {
11198 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
11199 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
11200 "noUpdate") << " ";
11201 continue;
11202 }
11203
11204 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
11205 if (++anArgIter < theArgNb)
11206 {
11207 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
11208 aStateStr.LowerCase();
11209 bool toEnable = true;
11210 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
11211 {
11212 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
11213 }
11214 else if (aStateStr == "noupdate"
11215 || aStateStr == "freeze")
11216 {
11217 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
11218 }
11219 else
11220 {
11221 --anArgIter;
11222 }
11223 }
11224 aParams.FrustumCullingState = aState;
11225 }
e276548b 11226 else
11227 {
bc8c79bb 11228 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
11229 return 1;
e276548b 11230 }
11231 }
189f85a3 11232
11233 return 0;
11234}
11235
79b544e6 11236//=======================================================================
11237//function : searchInfo
11238//purpose :
11239//=======================================================================
11240inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
11241 const TCollection_AsciiString& theKey)
11242{
11243 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
11244 {
11245 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
11246 {
11247 return anIter.Value();
11248 }
11249 }
11250 return TCollection_AsciiString();
11251}
11252
11253//=======================================================================
11254//function : VStatProfiler
11255//purpose :
11256//=======================================================================
11257static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
11258 Standard_Integer theArgNb,
11259 const char** theArgVec)
11260{
11261 Handle(V3d_View) aView = ViewerTest::CurrentView();
11262 if (aView.IsNull())
11263 {
11264 std::cerr << "Error: no active viewer!\n";
11265 return 1;
11266 }
11267
11268 Standard_Boolean toRedraw = Standard_True;
11269 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
11270 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
11271 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
11272 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11273 {
11274 Standard_CString anArg (theArgVec[anArgIter]);
11275 TCollection_AsciiString aFlag (anArg);
11276 aFlag.LowerCase();
11277 if (aFlag == "-noredraw")
11278 {
11279 toRedraw = Standard_False;
11280 }
11281 else
11282 {
11283 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
11284 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11285 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
11286 else if (aFlag == "alllayers"
11287 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
11288 else if (aFlag == "allstructs"
11289 || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
11290 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
11291 else if (aFlag == "allarrays"
11292 || aFlag == "fillarrays"
11293 || aFlag == "linearrays"
11294 || aFlag == "pointarrays"
11295 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11296 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
11297 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
11298 else if (aFlag == "geommem"
11299 || aFlag == "texturemem"
11300 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11301 else if (aFlag == "elapsedframe"
11302 || aFlag == "cpuframeaverage"
11303 || aFlag == "cpupickingaverage"
11304 || aFlag == "cpucullingaverage"
11305 || aFlag == "cpudynaverage"
11306 || aFlag == "cpuframemax"
11307 || aFlag == "cpupickingmax"
11308 || aFlag == "cpucullingmax"
11309 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11310 else
11311 {
11312 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
11313 continue;
11314 }
11315
11316 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
11317 }
11318 }
11319
11320 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
11321 {
11322 aView->ChangeRenderingParams().CollectedStats =
11323 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
11324
11325 if (toRedraw)
11326 {
11327 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
11328 aView->Redraw();
11329 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
11330 }
11331
11332 TColStd_IndexedDataMapOfStringString aDict;
11333 aView->StatisticInformation (aDict);
11334
11335 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
11336
11337 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11338 {
11339 Standard_CString anArg(theArgVec[anArgIter]);
11340 TCollection_AsciiString aFlag(anArg);
11341 aFlag.LowerCase();
11342 if (aFlag == "fps")
11343 {
11344 theDI << searchInfo (aDict, "FPS") << " ";
11345 }
11346 else if (aFlag == "cpu")
11347 {
11348 theDI << searchInfo (aDict, "CPU FPS") << " ";
11349 }
11350 else if (aFlag == "alllayers")
11351 {
11352 theDI << searchInfo (aDict, "Layers") << " ";
11353 }
11354 else if (aFlag == "layers")
11355 {
11356 theDI << searchInfo (aDict, "Rendered layers") << " ";
11357 }
11358 else if (aFlag == "allstructs")
11359 {
11360 theDI << searchInfo (aDict, "Structs") << " ";
11361 }
11362 else if (aFlag == "structs")
11363 {
11364 theDI << searchInfo (aDict, "Rendered structs") << " ";
11365 }
11366 else if (aFlag == "groups")
11367 {
11368 theDI << searchInfo (aDict, "Rendered groups") << " ";
11369 }
11370 else if (aFlag == "allarrays")
11371 {
11372 theDI << searchInfo (aDict, "Rendered arrays") << " ";
11373 }
11374 else if (aFlag == "fillarrays")
11375 {
11376 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
11377 }
11378 else if (aFlag == "linearrays")
11379 {
11380 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
11381 }
11382 else if (aFlag == "pointarrays")
11383 {
11384 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
11385 }
11386 else if (aFlag == "textarrays")
11387 {
11388 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
11389 }
11390 else if (aFlag == "triangles")
11391 {
11392 theDI << searchInfo (aDict, "Rendered triangles") << " ";
11393 }
11394 else if (aFlag == "points")
11395 {
11396 theDI << searchInfo (aDict, "Rendered points") << " ";
11397 }
11398 else if (aFlag == "geommem")
11399 {
11400 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
11401 }
11402 else if (aFlag == "texturemem")
11403 {
11404 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
11405 }
11406 else if (aFlag == "framemem")
11407 {
11408 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
11409 }
11410 else if (aFlag == "elapsedframe")
11411 {
11412 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
11413 }
11414 else if (aFlag == "cpuframe_average")
11415 {
11416 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
11417 }
11418 else if (aFlag == "cpupicking_average")
11419 {
11420 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
11421 }
11422 else if (aFlag == "cpuculling_average")
11423 {
11424 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
11425 }
11426 else if (aFlag == "cpudyn_average")
11427 {
11428 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
11429 }
11430 else if (aFlag == "cpuframe_max")
11431 {
11432 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
11433 }
11434 else if (aFlag == "cpupicking_max")
11435 {
11436 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
11437 }
11438 else if (aFlag == "cpuculling_max")
11439 {
11440 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
11441 }
11442 else if (aFlag == "cpudyn_max")
11443 {
11444 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
11445 }
11446 }
11447 }
11448 else
11449 {
11450 if (toRedraw)
11451 {
11452 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
11453 aView->Redraw();
11454 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
11455 }
11456 theDI << "Statistic info:\n" << aView->StatisticInformation();
11457 }
11458 return 0;
11459}
11460
189f85a3 11461//=======================================================================
11462//function : VProgressiveMode
11463//purpose :
11464//=======================================================================
11465#if defined(_WIN32)
11466static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
11467 Standard_Integer /*theNbArgs*/,
11468 const char** /*theArgs*/)
11469{
11470 Handle(V3d_View) aView = ViewerTest::CurrentView();
11471 if (aView.IsNull())
11472 {
11473 std::cerr << "Error: no active viewer!\n";
11474 return 1;
11475 }
11476
11477 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
11478
11479 for (;;)
11480 {
11481 aView->Redraw();
11482
11483 Standard_Boolean toExit = Standard_False;
11484
11485 MSG aMsg;
ad03c234 11486 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
189f85a3 11487 {
11488 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
11489 {
11490 toExit = Standard_True;
11491 }
11492
11493 TranslateMessage (&aMsg);
ad03c234 11494 DispatchMessageW (&aMsg);
189f85a3 11495 }
11496
11497 if (toExit)
11498 {
11499 break;
11500 }
11501 }
11502
e276548b 11503 return 0;
11504}
189f85a3 11505#endif
e276548b 11506
0717ddc1 11507//=======================================================================
11508//function : VXRotate
11509//purpose :
11510//=======================================================================
11511static Standard_Integer VXRotate (Draw_Interpretor& di,
11512 Standard_Integer argc,
11513 const char ** argv)
11514{
11515 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
11516 if (aContext.IsNull())
11517 {
586db386 11518 di << argv[0] << "ERROR : use 'vinit' command before \n";
0717ddc1 11519 return 1;
11520 }
11521
11522 if (argc != 3)
11523 {
586db386 11524 di << "ERROR : Usage : " << argv[0] << " name angle\n";
0717ddc1 11525 return 1;
11526 }
11527
11528 TCollection_AsciiString aName (argv[1]);
11529 Standard_Real anAngle = Draw::Atof (argv[2]);
11530
11531 // find object
11532 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
11533 Handle(AIS_InteractiveObject) anIObj;
8f521168 11534 if (!aMap.Find2 (aName, anIObj))
0717ddc1 11535 {
586db386 11536 di << "Use 'vdisplay' before\n";
0717ddc1 11537 return 1;
11538 }
0717ddc1 11539
8f521168 11540 gp_Trsf aTransform;
11541 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
11542 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
0717ddc1 11543
8f521168 11544 aContext->SetLocation (anIObj, aTransform);
11545 aContext->UpdateCurrentViewer();
0717ddc1 11546 return 0;
11547}
11548
625e1958 11549//===============================================================================================
11550//class : ViewerTest_AISManipulator
11551//purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
11552//===============================================================================================
11553DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11554
11555class ViewerTest_AISManipulator : public AIS_Manipulator
11556{
11557public:
11558
11559 ViewerTest_AISManipulator() : AIS_Manipulator()
11560 {
11561 GetMapOfAISManipulators().Add (this);
11562 }
11563
11564 virtual ~ViewerTest_AISManipulator()
11565 {
11566 GetMapOfAISManipulators().Remove (this);
11567 }
11568
11569 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11570};
11571
11572IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11573IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11574
11575//===============================================================================================
11576//function : VManipulator
11577//purpose :
11578//===============================================================================================
11579static int VManipulator (Draw_Interpretor& theDi,
11580 Standard_Integer theArgsNb,
11581 const char** theArgVec)
11582{
11583 Handle(V3d_View) aView = ViewerTest::CurrentView();
11584 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
11585 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
11586 if (aView.IsNull()
11587 || aViewer.IsNull())
11588 {
11589 std::cerr << "No active viewer!\n";
11590 return 1;
11591 }
11592
11593 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
11594 Standard_Integer anArgIter = 1;
11595 for (; anArgIter < theArgsNb; ++anArgIter)
11596 {
11597 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
11598 }
11599
11600 ViewerTest_CmdParser aCmd;
11601 aCmd.AddDescription ("Manages manipulator for interactive objects:");
11602 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
11603 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
11604 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
11605 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
11606 aCmd.AddOption ("detach", "... - detach manipulator");
11607
11608 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
11609 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
11610 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
11611
11612 aCmd.AddOption ("move", "... x y z - move object");
11613 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
11614 aCmd.AddOption ("scale", "... factor - scale object");
11615
11616 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
11617 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
11618 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
11619 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
11620 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
11621 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
11622 aCmd.AddOption ("size", "... size - set size of manipulator");
11623 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
11624
11625 aCmd.Parse (theArgsNb, theArgVec);
11626
11627 if (aCmd.HasOption ("help"))
11628 {
11629 theDi.PrintHelp (theArgVec[0]);
11630 return 0;
11631 }
11632
11633 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
11634
11635 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
11636
11637 if (aName.IsEmpty())
11638 {
11639 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
11640 return 1;
11641 }
11642
11643 // ----------------------------------
11644 // detach existing manipulator object
11645 // ----------------------------------
11646
11647 if (aCmd.HasOption ("detach"))
11648 {
11649 if (!aMapAIS.IsBound2 (aName))
11650 {
11651 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
11652 return 1;
11653 }
11654
11655 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11656 if (aManipulator.IsNull())
11657 {
11658 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11659 return 1;
11660 }
11661
11662 aManipulator->Detach();
11663 aMapAIS.UnBind2 (aName);
0577ae8c 11664 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
625e1958 11665
11666 return 0;
11667 }
11668
11669 // -----------------------------------------------
11670 // find or create manipulator if it does not exist
11671 // -----------------------------------------------
11672
11673 Handle(AIS_Manipulator) aManipulator;
11674 if (!aMapAIS.IsBound2 (aName))
11675 {
11676 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
11677
11678 aManipulator = new ViewerTest_AISManipulator();
11679 aMapAIS.Bind (aManipulator, aName);
11680 }
11681 else
11682 {
11683 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11684 if (aManipulator.IsNull())
11685 {
11686 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11687 return 1;
11688 }
11689 }
11690
11691 // -----------------------------------------
11692 // change properties of manipulator instance
11693 // -----------------------------------------
11694
11695 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
11696 {
11697 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
11698 }
11699 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
11700 {
11701 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
11702 }
11703 if (aCmd.HasOption ("followRotation", 1, Standard_True))
11704 {
11705 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
11706 }
11707 if (aCmd.HasOption ("gap", 1, Standard_True))
11708 {
11709 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
11710 }
11711 if (aCmd.HasOption ("part", 3, Standard_True))
11712 {
11713 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
11714 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
11715 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
11716 if (aMode < 1 || aMode > 3)
11717 {
11718 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
11719 return 1;
11720 }
11721
11722 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
11723 }
11724 if (aCmd.HasOption ("pos", 3, Standard_True))
11725 {
11726 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
11727 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
11728 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
11729
11730 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
11731 }
11732 if (aCmd.HasOption ("size", 1, Standard_True))
11733 {
11734 aManipulator->SetSize (aCmd.ArgFloat ("size"));
11735 }
11736 if (aCmd.HasOption ("zoomable", 1, Standard_True))
11737 {
11738 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
11739
11740 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
11741 {
11742 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
11743 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
11744 }
11745 }
11746
11747 // ---------------------------------------------------
11748 // attach, detach or access manipulator from an object
11749 // ---------------------------------------------------
11750
11751 if (aCmd.HasOption ("attach"))
11752 {
11753 // Find an object and attach manipulator to it
11754 if (!aCmd.HasOption ("attach", 1, Standard_True))
11755 {
11756 return 1;
11757 }
11758
11759 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
8f521168 11760 Handle(AIS_InteractiveObject) anObject;
11761 if (!aMapAIS.Find2 (anObjName, anObject))
625e1958 11762 {
11763 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
11764 return 1;
11765 }
11766
8f521168 11767 for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next())
625e1958 11768 {
11769 if (anIt.Value()->IsAttached()
11770 && anIt.Value()->Object() == anObject)
11771 {
11772 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
11773 return 1;
11774 }
11775 }
11776
11777 AIS_Manipulator::OptionsForAttach anOptions;
11778 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
11779 {
11780 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
11781 }
11782 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
11783 {
11784 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
11785 }
11786 if (aCmd.HasOption ("enableModes", 1, Standard_True))
11787 {
11788 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
11789 }
11790
11791 aManipulator->Attach (anObject, anOptions);
11792 }
11793
11794 // --------------------------------------
11795 // apply transformation using manipulator
11796 // --------------------------------------
11797
11798 if (aCmd.HasOption ("startTransform", 2, Standard_True))
11799 {
11800 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
11801 }
11802 if (aCmd.HasOption ("transform", 2, Standard_True))
11803 {
11804 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
11805 }
11806 if (aCmd.HasOption ("stopTransform"))
11807 {
11808 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
11809
11810 aManipulator->StopTransform (toApply);
11811 }
11812
11813 gp_Trsf aT;
11814 if (aCmd.HasOption ("move", 3, Standard_True))
11815 {
11816 aT.SetTranslationPart (aCmd.ArgVec ("move"));
11817 }
11818 if (aCmd.HasOption ("rotate", 7, Standard_True))
11819 {
11820 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
11821 }
11822 if (aCmd.HasOption ("scale", 1))
11823 {
11824 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
11825 }
11826
11827 if (aT.Form() != gp_Identity)
11828 {
11829 aManipulator->Transform (aT);
11830 }
11831
0577ae8c 11832 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
625e1958 11833
11834 return 0;
11835}
11836
8e5fb5ea 11837//===============================================================================================
11838//function : VSelectionProperties
11839//purpose :
11840//===============================================================================================
11841static int VSelectionProperties (Draw_Interpretor& theDi,
11842 Standard_Integer theArgsNb,
11843 const char** theArgVec)
11844{
11845 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
11846 if (aCtx.IsNull())
11847 {
11848 std::cerr << "No active viewer!\n";
11849 return 1;
11850 }
11851
be3d8cbc 11852 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
11853 {
11854 // handle obsolete alias
11855 bool toEnable = true;
11856 if (theArgsNb < 2)
11857 {
11858 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
11859 return 0;
11860 }
11861 else if (theArgsNb != 2
11862 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
11863 {
11864 std::cout << "Syntax error: wrong number of parameters.";
11865 return 1;
11866 }
11867 if (toEnable != aCtx->ToHilightSelected())
11868 {
11869 aCtx->ClearDetected();
11870 aCtx->SetToHilightSelected (toEnable);
11871 }
11872 return 0;
11873 }
11874
f838dac4 11875 Standard_Boolean toPrint = theArgsNb == 1;
11876 Standard_Boolean toRedraw = Standard_False;
11877 Standard_Integer anArgIter = 1;
11878 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
11879 if (anArgIter < theArgsNb)
11880 {
11881 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
11882 anArgFirst.LowerCase();
11883 ++anArgIter;
11884 if (anArgFirst == "dynhighlight"
11885 || anArgFirst == "dynhilight"
11886 || anArgFirst == "dynamichighlight"
11887 || anArgFirst == "dynamichilight")
11888 {
11889 aType = Prs3d_TypeOfHighlight_Dynamic;
11890 }
11891 else if (anArgFirst == "localdynhighlight"
11892 || anArgFirst == "localdynhilight"
11893 || anArgFirst == "localdynamichighlight"
11894 || anArgFirst == "localdynamichilight")
11895 {
11896 aType = Prs3d_TypeOfHighlight_LocalDynamic;
11897 }
11898 else if (anArgFirst == "selhighlight"
11899 || anArgFirst == "selhilight"
11900 || anArgFirst == "selectedhighlight"
11901 || anArgFirst == "selectedhilight")
11902 {
11903 aType = Prs3d_TypeOfHighlight_Selected;
11904 }
11905 else if (anArgFirst == "localselhighlight"
11906 || anArgFirst == "localselhilight"
11907 || anArgFirst == "localselectedhighlight"
11908 || anArgFirst == "localselectedhilight")
11909 {
11910 aType = Prs3d_TypeOfHighlight_LocalSelected;
11911 }
11912 else
11913 {
11914 --anArgIter;
11915 }
11916 }
11917 for (; anArgIter < theArgsNb; ++anArgIter)
11918 {
11919 TCollection_AsciiString anArg (theArgVec[anArgIter]);
11920 anArg.LowerCase();
11921 if (anArg == "-help")
11922 {
11923 theDi.PrintHelp (theArgVec[0]);
11924 return 0;
11925 }
11926 else if (anArg == "-print")
11927 {
11928 toPrint = Standard_True;
11929 }
11930 else if (anArg == "-autoactivate")
11931 {
11932 Standard_Boolean toEnable = Standard_True;
11933 if (anArgIter + 1 < theArgsNb
11934 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11935 {
11936 ++anArgIter;
11937 }
11938 aCtx->SetAutoActivateSelection (toEnable);
11939 }
be3d8cbc 11940 else if (anArg == "-automatichighlight"
11941 || anArg == "-automatichilight"
11942 || anArg == "-autohighlight"
11943 || anArg == "-autohilight")
11944 {
11945 Standard_Boolean toEnable = Standard_True;
11946 if (anArgIter + 1 < theArgsNb
11947 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11948 {
11949 ++anArgIter;
11950 }
11951 aCtx->ClearSelected (false);
11952 aCtx->ClearDetected();
11953 aCtx->SetAutomaticHilight (toEnable);
11954 toRedraw = true;
11955 }
11956 else if (anArg == "-highlightselected"
11957 || anArg == "-hilightselected")
11958 {
11959 Standard_Boolean toEnable = Standard_True;
11960 if (anArgIter + 1 < theArgsNb
11961 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11962 {
11963 ++anArgIter;
11964 }
11965 aCtx->ClearDetected();
11966 aCtx->SetToHilightSelected (toEnable);
11967 toRedraw = true;
11968 }
14c4193d 11969 else if (anArg == "-pickstrategy"
11970 || anArg == "-pickingstrategy")
11971 {
11972 if (++anArgIter >= theArgsNb)
11973 {
11974 std::cout << "Syntax error: type of highlighting is undefined\n";
11975 return 1;
11976 }
11977
11978 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11979 TCollection_AsciiString aVal (theArgVec[anArgIter]);
11980 aVal.LowerCase();
11981 if (aVal == "first"
11982 || aVal == "firstaccepted"
11983 || aVal == "firstacceptable")
11984 {
11985 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11986 }
11987 else if (aVal == "topmost"
11988 || aVal == "onlyTopmost")
11989 {
11990 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
11991 }
11992 else
11993 {
11994 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
11995 return 1;
11996 }
11997
11998 aCtx->SetPickingStrategy (aStrategy);
11999 }
f838dac4 12000 else if (anArg == "-pixtol"
12001 && anArgIter + 1 < theArgsNb)
12002 {
12003 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
12004 }
12005 else if ((anArg == "-mode"
12006 || anArg == "-dispmode")
12007 && anArgIter + 1 < theArgsNb)
12008 {
12009 if (aType == Prs3d_TypeOfHighlight_None)
12010 {
12011 std::cout << "Syntax error: type of highlighting is undefined\n";
12012 return 1;
12013 }
8e5fb5ea 12014
f838dac4 12015 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
12016 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12017 aStyle->SetDisplayMode (aDispMode);
12018 toRedraw = Standard_True;
12019 }
12020 else if (anArg == "-layer"
12021 && anArgIter + 1 < theArgsNb)
12022 {
12023 if (aType == Prs3d_TypeOfHighlight_None)
12024 {
12025 std::cout << "Syntax error: type of highlighting is undefined\n";
12026 return 1;
12027 }
8e5fb5ea 12028
f838dac4 12029 const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]);
12030 if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN)
12031 {
12032 TColStd_SequenceOfInteger aLayers;
12033 aCtx->CurrentViewer()->GetAllZLayers (aLayers);
12034 if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end())
12035 {
12036 std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n";
12037 return 1;
12038 }
12039 }
8e5fb5ea 12040
f838dac4 12041 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12042 aStyle->SetZLayer (aNewLayer);
12043 toRedraw = Standard_True;
12044 }
12045 else if (anArg == "-hicolor"
12046 || anArg == "-selcolor"
12047 || anArg == "-color")
12048 {
12049 if (anArg.StartsWith ("-hi"))
12050 {
12051 aType = Prs3d_TypeOfHighlight_Dynamic;
12052 }
12053 else if (anArg.StartsWith ("-sel"))
12054 {
12055 aType = Prs3d_TypeOfHighlight_Selected;
12056 }
12057 else if (aType == Prs3d_TypeOfHighlight_None)
12058 {
12059 std::cout << "Syntax error: type of highlighting is undefined\n";
12060 return 1;
12061 }
8e5fb5ea 12062
f838dac4 12063 Quantity_Color aColor;
12064 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
12065 theArgVec + anArgIter + 1,
12066 aColor);
12067 if (aNbParsed == 0)
12068 {
12069 std::cout << "Syntax error: need more arguments.\n";
12070 return 1;
12071 }
12072 anArgIter += aNbParsed;
8e5fb5ea 12073
f838dac4 12074 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12075 aStyle->SetColor (aColor);
12076 toRedraw = Standard_True;
12077 }
12078 else if ((anArg == "-transp"
12079 || anArg == "-transparency"
12080 || anArg == "-hitransp"
12081 || anArg == "-seltransp"
12082 || anArg == "-hitransplocal"
12083 || anArg == "-seltransplocal")
12084 && anArgIter + 1 < theArgsNb)
12085 {
12086 if (anArg.StartsWith ("-hi"))
12087 {
12088 aType = Prs3d_TypeOfHighlight_Dynamic;
12089 }
12090 else if (anArg.StartsWith ("-sel"))
12091 {
12092 aType = Prs3d_TypeOfHighlight_Selected;
12093 }
12094 else if (aType == Prs3d_TypeOfHighlight_None)
12095 {
12096 std::cout << "Syntax error: type of highlighting is undefined\n";
12097 return 1;
12098 }
8e5fb5ea 12099
f838dac4 12100 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
12101 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12102 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
12103 toRedraw = Standard_True;
12104 }
12105 else if ((anArg == "-mat"
12106 || anArg == "-material")
12107 && anArgIter + 1 < theArgsNb)
12108 {
12109 if (aType == Prs3d_TypeOfHighlight_None)
12110 {
12111 std::cout << "Syntax error: type of highlighting is undefined\n";
12112 return 1;
12113 }
8e5fb5ea 12114
f838dac4 12115 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12116 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
12117 if (aMatName != Graphic3d_NOM_DEFAULT)
12118 {
12119 ++anArgIter;
12120 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
12121 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
12122 Graphic3d_MaterialAspect aMat (aMatName);
12123 aMat.SetColor (aStyle->Color());
12124 aMat.SetTransparency (aStyle->Transparency());
12125 anAspect->SetFrontMaterial (aMat);
12126 anAspect->SetInteriorColor (aStyle->Color());
12127 aStyle->SetBasicFillAreaAspect (anAspect);
12128 }
12129 else
12130 {
12131 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
12132 }
12133 toRedraw = Standard_True;
12134 }
12135 else
12136 {
12137 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
12138 }
8e5fb5ea 12139 }
12140
f838dac4 12141 if (toPrint)
8e5fb5ea 12142 {
f838dac4 12143 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
12144 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
8e5fb5ea 12145 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
be3d8cbc 12146 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
12147 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
8e5fb5ea 12148 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
f838dac4 12149 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
12150 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
12151 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
12152 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
12153 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
12154 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
12155 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
12156 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
8e5fb5ea 12157 }
12158
12159 if (aCtx->NbSelected() != 0 && toRedraw)
12160 {
12161 aCtx->HilightSelected (Standard_True);
12162 }
12163
12164 return 0;
12165}
12166
decdee7d 12167//===============================================================================================
12168//function : VDumpSelectionImage
12169//purpose :
12170//===============================================================================================
12171static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
12172 Standard_Integer theArgsNb,
12173 const char** theArgVec)
12174{
12175 if (theArgsNb < 2)
12176 {
12177 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
12178 return 1;
12179 }
12180
12181 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
12182 if (aContext.IsNull())
12183 {
12184 std::cout << "Error: no active view.\n";
12185 return 1;
12186 }
12187
12188 TCollection_AsciiString aFile;
12189 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
dc858f4c 12190 Image_Format anImgFormat = Image_Format_BGR;
decdee7d 12191 Standard_Integer aPickedIndex = 1;
12192 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
12193 {
12194 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12195 aParam.LowerCase();
12196 if (aParam == "-type")
12197 {
12198 if (++anArgIter >= theArgsNb)
12199 {
12200 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
12201 return 1;
12202 }
12203
12204 TCollection_AsciiString aValue (theArgVec[anArgIter]);
12205 aValue.LowerCase();
12206 if (aValue == "depth"
12207 || aValue == "normdepth"
12208 || aValue == "normalizeddepth")
12209 {
12210 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
dc858f4c 12211 anImgFormat = Image_Format_GrayF;
decdee7d 12212 }
12213 if (aValue == "depthinverted"
12214 || aValue == "normdepthinverted"
12215 || aValue == "normalizeddepthinverted"
12216 || aValue == "inverted")
12217 {
12218 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
dc858f4c 12219 anImgFormat = Image_Format_GrayF;
decdee7d 12220 }
12221 else if (aValue == "unnormdepth"
12222 || aValue == "unnormalizeddepth")
12223 {
12224 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
dc858f4c 12225 anImgFormat = Image_Format_GrayF;
decdee7d 12226 }
12227 else if (aValue == "objectcolor"
12228 || aValue == "object"
12229 || aValue == "color")
12230 {
12231 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
12232 }
12233 else if (aValue == "entitycolor"
12234 || aValue == "entity")
12235 {
12236 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
12237 }
12238 else if (aValue == "ownercolor"
12239 || aValue == "owner")
12240 {
12241 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
12242 }
12243 else if (aValue == "selectionmodecolor"
12244 || aValue == "selectionmode"
12245 || aValue == "selmodecolor"
12246 || aValue == "selmode")
12247 {
12248 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
12249 }
12250 }
12251 else if (aParam == "-picked"
12252 || aParam == "-pickeddepth"
12253 || aParam == "-pickedindex")
12254 {
12255 if (++anArgIter >= theArgsNb)
12256 {
12257 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
12258 return 1;
12259 }
12260
12261 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
12262 }
12263 else if (aFile.IsEmpty())
12264 {
12265 aFile = theArgVec[anArgIter];
12266 }
12267 else
12268 {
12269 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
12270 return 1;
12271 }
12272 }
12273 if (aFile.IsEmpty())
12274 {
12275 std::cout << "Syntax error: image file name is missing.\n";
12276 return 1;
12277 }
12278
12279 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
12280 Standard_Integer aWidth = 0, aHeight = 0;
12281 aView->Window()->Size (aWidth, aHeight);
12282
12283 Image_AlienPixMap aPixMap;
12284 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
12285 {
12286 std::cout << "Error: can't allocate image.\n";
12287 return 1;
12288 }
12289 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
12290 {
12291 std::cout << "Error: can't generate selection image.\n";
12292 return 1;
12293 }
12294 if (!aPixMap.Save (aFile))
12295 {
12296 std::cout << "Error: can't save selection image.\n";
12297 return 0;
12298 }
12299 return 0;
12300}
12301
7fd59977 12302//=======================================================================
12303//function : ViewerCommands
12304//purpose :
12305//=======================================================================
12306
12307void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
12308{
12309
12310 const char *group = "ZeViewer";
18d715bd 12311 theCommands.Add("vinit",
fd3f6bd0 12312 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
2e93433e 12313 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
fd3f6bd0 12314 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
12315 "\n\t\t: [-display displayName]"
12316 #endif
12317 "\n\t\t: Creates new View window with specified name viewName."
12318 "\n\t\t: By default the new view is created in the viewer and in"
12319 "\n\t\t: graphic driver shared with active view."
12320 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
12321 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
12322 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
12323#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
12324 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
12325 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
18d715bd 12326#endif
fd3f6bd0 12327 "\n\t\t: -left, -top pixel position of left top corner of the window."
12328 "\n\t\t: -width, -height width and heigth of window respectively."
9e04ccdc 12329 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
fd3f6bd0 12330 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
12331 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
2e93433e 12332 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
fd3f6bd0 12333 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
7fd59977 12334 __FILE__,VInit,group);
18d715bd 12335 theCommands.Add("vclose" ,
d0cc1cb7 12336 "[view_id [keep_context=0|1]]\n"
18d715bd 12337 "or vclose ALL - to remove all created views\n"
12338 " - removes view(viewer window) defined by its view_id.\n"
12339 " - keep_context: by default 0; if 1 and the last view is deleted"
12340 " the current context is not removed.",
12341 __FILE__,VClose,group);
12342 theCommands.Add("vactivate" ,
e084dbbc 12343 "vactivate view_id [-noUpdate]"
18d715bd 12344 " - activates view(viewer window) defined by its view_id",
12345 __FILE__,VActivate,group);
12346 theCommands.Add("vviewlist",
12347 "vviewlist [format={tree, long}]"
12348 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
12349 " - format: format of result output, if tree the output is a tree view;"
12350 "otherwise it's a list of full view names. By default format = tree",
12351 __FILE__,VViewList,group);
7fd59977 12352 theCommands.Add("vhelp" ,
12353 "vhelp : display help on the viewer commands",
12354 __FILE__,VHelp,group);
12355 theCommands.Add("vtop" ,
27af3052 12356 "vtop or <T> : Top view. Orientation +X+Y" ,
7fd59977 12357 __FILE__,VTop,group);
44b8f2d6 12358 theCommands.Add("vbottom" ,
27af3052 12359 "vbottom : Bottom view. Orientation +X-Y" ,
44b8f2d6 12360 __FILE__,VBottom,group);
12361 theCommands.Add("vleft" ,
27af3052 12362 "vleft : Left view. Orientation -Y+Z" ,
44b8f2d6 12363 __FILE__,VLeft,group);
12364 theCommands.Add("vright" ,
27af3052 12365 "vright : Right view. Orientation +Y+Z" ,
44b8f2d6 12366 __FILE__,VRight,group);
7fd59977 12367 theCommands.Add("vaxo" ,
27af3052 12368 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
7fd59977 12369 __FILE__,VAxo,group);
44b8f2d6 12370 theCommands.Add("vfront" ,
27af3052 12371 "vfront : Front view. Orientation +X+Z" ,
44b8f2d6 12372 __FILE__,VFront,group);
12373 theCommands.Add("vback" ,
27af3052 12374 "vback : Back view. Orientation -X+Z" ,
44b8f2d6 12375 __FILE__,VBack,group);
7fd59977 12376 theCommands.Add("vpick" ,
12377 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
12378 VPick,group);
1beb58d7 12379 theCommands.Add("vfit",
12380 "vfit or <F> [-selected] [-noupdate]"
b586500b 12381 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
7fd59977 12382 __FILE__,VFit,group);
6262a303 12383 theCommands.Add ("vfitarea",
12384 "vfitarea x1 y1 x2 y2"
12385 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
12386 "\n\t\t: Fit view to show area located between two points"
12387 "\n\t\t: given in world 2D or 3D corrdinates.",
12388 __FILE__, VFitArea, group);
197ac94e 12389 theCommands.Add ("vzfit", "vzfit [scale]\n"
12390 " Matches Z near, Z far view volume planes to the displayed objects.\n"
12391 " \"scale\" - specifies factor to scale computed z range.\n",
12392 __FILE__, VZFit, group);
7fd59977 12393 theCommands.Add("vrepaint",
56689b27 12394 "vrepaint [-immediate]"
12395 "\n\t\t: force redraw",
7fd59977 12396 __FILE__,VRepaint,group);
12397 theCommands.Add("vclear",
faea8b40 12398 "vclear : vclear"
12399 "\n\t\t: remove all the object from the viewer",
7fd59977 12400 __FILE__,VClear,group);
12401 theCommands.Add("vsetbg",
12402 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
12403 __FILE__,VSetBg,group);
f8b2ed36 12404 theCommands.Add("vsetbgmode",
12405 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
12406 __FILE__,VSetBgMode,group);
7fd59977 12407 theCommands.Add("vsetgradientbg",
f8b2ed36 12408 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
7fd59977 12409 __FILE__,VSetGradientBg,group);
f8b2ed36 12410 theCommands.Add("vsetgrbgmode",
12411 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
12412 __FILE__,VSetGradientBgMode,group);
12413 theCommands.Add("vsetcolorbg",
12414 "vsetcolorbg : vsetcolorbg r g b : Set background color",
12415 __FILE__,VSetColorBg,group);
f42753ed 12416 theCommands.Add("vsetdefaultbg",
12417 "vsetdefaultbg r g b\n"
12418 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
12419 "\n\t\t: Set default viewer background fill color (flat/gradient).",
12420 __FILE__,VSetDefaultBg,group);
7fd59977 12421 theCommands.Add("vscale",
12422 "vscale : vscale X Y Z",
12423 __FILE__,VScale,group);
12424 theCommands.Add("vzbufftrihedron",
536d98e2 12425 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
12426 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
12427 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
12428 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
12429 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
12430 "\n\t\t: Displays a trihedron",
12431 __FILE__,VZBuffTrihedron,group);
7fd59977 12432 theCommands.Add("vrotate",
4af098ba 12433 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
12434 "\n : Option -mouseStart starts rotation according to the mouse position"
12435 "\n : Option -mouseMove continues rotation with angle computed"
12436 "\n : from last and new mouse position."
12437 "\n : vrotate AX AY AZ [X Y Z]",
7fd59977 12438 __FILE__,VRotate,group);
12439 theCommands.Add("vzoom",
12440 "vzoom : vzoom coef",
12441 __FILE__,VZoom,group);
12442 theCommands.Add("vpan",
12443 "vpan : vpan dx dy",
12444 __FILE__,VPan,group);
7fd59977 12445 theCommands.Add("vcolorscale",
4b3d6eb1 12446 "vcolorscale name [-noupdate|-update] [-demo]"
12447 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
12448 "\n\t\t: [-font HeightFont=20]"
12449 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
12450 "\n\t\t: [-smoothTransition {on|off}=off]"
12451 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
12452 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
12453 "\n\t\t: [-textpos {left|right|center|none}=right]"
12454 "\n\t\t: [-labelAtBorder {on|off}=on]"
12455 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
12456 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
12457 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
12458 "\n\t\t: [-xy Left=0 Bottom=0]"
12459 "\n\t\t: -demo - displays a color scale with demonstratio values"
12460 "\n\t\t: -colors - set colors for all intervals"
12461 "\n\t\t: -color - set color for specific interval"
12462 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
12463 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
12464 "\n\t\t: at border means the value inbetween neighbor intervals,"
12465 "\n\t\t: at center means the center value within current interval"
12466 "\n\t\t: -labels - set labels for all intervals"
12467 "\n\t\t: -freeLabels - same as -labels but does not require"
12468 "\n\t\t: matching the number of intervals"
12469 "\n\t\t: -label - set label for specific interval"
12470 "\n\t\t: -title - set title"
12471 "\n\t\t: -reversed - setup smooth color transition between intervals"
12472 "\n\t\t: -smoothTransition - swap colorscale direction"
12473 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
12474 __FILE__, VColorScale, group);
7fd59977 12475 theCommands.Add("vgraduatedtrihedron",
a79f67f8 12476 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
12477 "\t[-namefont Name] [-valuesfont Name]\n"
12478 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
12479 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
12480 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
12481 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
12482 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
12483 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
12484 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
12485 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
12486 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
536d98e2 12487 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
a79f67f8 12488 " - Displays or erases graduated trihedron"
12489 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
12490 " - namefont - font of axes names. Default: Arial\n"
12491 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
12492 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
12493 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
12494 " - valuesfont - font of axes values. Default: Arial\n"
12495 " - xcolor, ycolor, zcolor - color of axis and values\n"
12496 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
12497 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
7fd59977 12498 __FILE__,VGraduatedTrihedron,group);
3bffef55 12499 theCommands.Add("vtile" ,
12500 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
12501 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
12502 "\n\t\t: -totalSize the size of virtual bigger viewport"
12503 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
12504 "\n\t\t: -lowerLeft tile offset as lower left corner"
12505 "\n\t\t: -upperLeft tile offset as upper left corner",
12506 __FILE__, VTile, group);
59f45b7c 12507 theCommands.Add("vzlayer",
7c3ef2f7 12508 "vzlayer [layerId]"
12509 "\n\t\t: [-add|-delete|-get|-settings]"
4ecf34cc 12510 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
7c3ef2f7 12511 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
12512 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
12513 "\n\t\t: ZLayer list management:"
12514 "\n\t\t: -add add new z layer to viewer and print its id"
12515 "\n\t\t: -delete delete z layer"
12516 "\n\t\t: -get print sequence of z layers"
12517 "\n\t\t: -settings print status of z layer settings"
12518 "\n\t\t: -disable disables given setting"
12519 "\n\t\t: -enable enables given setting",
59f45b7c 12520 __FILE__,VZLayer,group);
20637bd2 12521 theCommands.Add("vlayerline",
12522 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
12523 __FILE__,VLayerLine,group);
2bd4c032 12524 theCommands.Add ("vgrid",
12525 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
12526 " : Mode - rectangular or circular"
12527 " : Type - lines or points",
12528 __FILE__, VGrid, group);
c40b7d58 12529 theCommands.Add ("vpriviledgedplane",
12530 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
12531 "\n\t\t: Ox, Oy, Oz - plane origin"
12532 "\n\t\t: Nx, Ny, Nz - plane normal direction"
12533 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
12534 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
12535 __FILE__, VPriviledgedPlane, group);
f25b82d6 12536 theCommands.Add ("vconvert",
12537 "vconvert v [Mode={window|view}]"
12538 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
12539 "\n\t\t: vconvert x y z [Mode={window|grid}]"
12540 "\n\t\t: window - convert to window coordinates, pixels"
12541 "\n\t\t: view - convert to view projection plane"
12542 "\n\t\t: grid - convert to model coordinates, given on grid"
12543 "\n\t\t: ray - convert projection ray to model coordiantes"
12544 "\n\t\t: - vconvert v window : convert view to window;"
12545 "\n\t\t: - vconvert v view : convert window to view;"
12546 "\n\t\t: - vconvert x y window : convert view to window;"
12547 "\n\t\t: - vconvert x y view : convert window to view;"
12548 "\n\t\t: - vconvert x y : convert window to model;"
12549 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
12550 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
12551 "\n\t\t: - vconvert x y z window : convert model to window;"
12552 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
12553 "\n\t\t: Converts the given coordinates to window/view/model space.",
12554 __FILE__, VConvert, group);
208e6839 12555 theCommands.Add ("vfps",
e084dbbc 12556 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
208e6839 12557 __FILE__, VFps, group);
58655684 12558 theCommands.Add ("vgldebug",
c87535af 12559 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
84e84755 12560 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
c87535af 12561 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
12562 "\n\t\t: Debug context can be requested only on Windows"
12563 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
12564 "\n\t\t: -sync - request synchronized debug GL context"
12565 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
12566 "\n\t\t: which are suppressed by default,"
84e84755 12567 "\n\t\t: -glslCode - log GLSL program source code,"
12568 "\n\t\t: which are suppressed by default,"
c87535af 12569 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
12570 "\n\t\t: which are suppressed by default",
58655684 12571 __FILE__, VGlDebug, group);
208e6839 12572 theCommands.Add ("vvbo",
58655684 12573 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
208e6839 12574 __FILE__, VVbo, group);
b5ac8292 12575 theCommands.Add ("vstereo",
f978241f 12576 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
12577 "\n\t\t: [-anaglyph Filter]"
12578 "\n\t\t: Control stereo output mode. Available modes for -mode:"
12579 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
12580 "\n\t\t: requires driver support."
12581 "\n\t\t: Should be called BEFORE vinit!"
12582 "\n\t\t: anaglyph - Anaglyph glasses"
12583 "\n\t\t: rowInterlaced - row-interlaced display"
12584 "\n\t\t: columnInterlaced - column-interlaced display"
12585 "\n\t\t: chessBoard - chess-board output"
12586 "\n\t\t: sideBySide - horizontal pair"
12587 "\n\t\t: overUnder - vertical pair"
12588 "\n\t\t: Available Anaglyph filters for -anaglyph:"
12589 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
12590 "\n\t\t: greenMagentaSimple",
b5ac8292 12591 __FILE__, VStereo, group);
a577aaab 12592 theCommands.Add ("vcaps",
8625ef7e 12593 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
1dfe71a6 12594 "\n\t\t: [-compatibleProfile {0|1}]"
56689b27 12595 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
f978241f 12596 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
8625ef7e 12597 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
12598 "\n\t\t: Modify particular graphic driver options:"
12599 "\n\t\t: FFP - use fixed-function pipeline instead of"
12600 "\n\t\t: built-in GLSL programs"
4e1523ef 12601 "\n\t\t: (requires compatible profile)"
8625ef7e 12602 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
12603 "\n\t\t: arrays to GPU memory)"
12604 "\n\t\t: sprite - use textured sprites instead of bitmaps"
f978241f 12605 "\n\t\t: vsync - switch VSync on or off"
56689b27 12606 "\n\t\t: winBuffer - allow using window buffer for rendering"
4e1523ef 12607 "\n\t\t: Context creation options:"
12608 "\n\t\t: softMode - software OpenGL implementation"
12609 "\n\t\t: compatibleProfile - backward-compatible profile"
f978241f 12610 "\n\t\t: quadbuffer - QuadBuffer"
8625ef7e 12611 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
12612 "\n\t\t: rendering paths producing the same visual result when"
12613 "\n\t\t: possible."
12614 "\n\t\t: Command is intended for testing old hardware compatibility.",
a577aaab 12615 __FILE__, VCaps, group);
f0430952 12616 theCommands.Add ("vmemgpu",
12617 "vmemgpu [f]: print system-dependent GPU memory information if available;"
12618 " with f option returns free memory in bytes",
12619 __FILE__, VMemGpu, group);
85e096c3 12620 theCommands.Add ("vreadpixel",
12621 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
12622 " : Read pixel value for active view",
12623 __FILE__, VReadPixel, group);
692613e5 12624 theCommands.Add("diffimage",
fd3f6bd0 12625 "diffimage imageFile1 imageFile2 [diffImageFile]"
12626 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
12627 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
12628 "\n\t\t: Compare two images by content and generate difference image."
12629 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
12630 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
692613e5 12631 __FILE__, VDiffImage, group);
4754e164 12632 theCommands.Add ("vselect",
2157d6ac 12633 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
4754e164 12634 "- emulates different types of selection:\n"
12635 "- 1) single click selection\n"
12636 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
12637 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
faea8b40 12638 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
12639 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
12640 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
2157d6ac 12641 " (partial inclusion - overlap - is not allowed by default)\n"
12642 "- 5) any of these selections with shift button pressed",
4754e164 12643 __FILE__, VSelect, group);
12644 theCommands.Add ("vmoveto",
8a590580 12645 "vmoveto [x y] [-reset]"
12646 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
12647 "\n\t\t: -reset resets current highlighting",
4754e164 12648 __FILE__, VMoveTo, group);
1beb58d7 12649 theCommands.Add ("vviewparams",
12650 "vviewparams [-args] [-scale [s]]"
12651 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
12652 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
12653 "\n\t\t: Manage current view parameters or prints all"
12654 "\n\t\t: current values when called without argument."
12655 "\n\t\t: -scale [s] prints or sets viewport relative scale"
12656 "\n\t\t: -eye [x y z] prints or sets eye location"
12657 "\n\t\t: -at [x y z] prints or sets center of look"
12658 "\n\t\t: -up [x y z] prints or sets direction of up vector"
12659 "\n\t\t: -proj [x y z] prints or sets direction of look"
12660 "\n\t\t: -center x y sets location of center of the screen in pixels"
12661 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
12662 "\n\t\t: or changes the size of its maximum dimension"
12663 "\n\t\t: -args prints vviewparams arguments for restoring current view",
197ac94e 12664 __FILE__, VViewParams, group);
1beb58d7 12665
2e93433e 12666 theCommands.Add("v2dmode",
12667 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
12668 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
12669 "\n\t\t: mode - switches On/Off rotation mode"
12670 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
12671 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
12672 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
12673 "\n\t\t: View camera position might be changed only by commands.",
12674 __FILE__, V2DMode, group);
12675
1beb58d7 12676 theCommands.Add("vanimation", "Alias for vanim",
12677 __FILE__, VAnimation, group);
12678
12679 theCommands.Add("vanim",
12680 "List existing animations:"
12681 "\n\t\t: vanim"
12682 "\n\t\t: Animation playback:"
12683 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
12684 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
12685 "\n\t\t: -speed playback speed (1.0 is normal speed)"
12686 "\n\t\t: -freeLook skip camera animations"
12687 "\n\t\t: -lockLoop disable any interactions"
12688 "\n\t\t:"
12689 "\n\t\t: Animation definition:"
12690 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
12691 "\n\t\t: [start TimeSec] [duration TimeSec]"
12692 "\n\t\t:"
12693 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
12694 "\n\t\t: specifies nested animations."
12695 "\n\t\t: There is no syntax to explicitly add new animation,"
12696 "\n\t\t: and all non-existing animations within the name will be"
12697 "\n\t\t: implicitly created on first use (including parents)."
12698 "\n\t\t:"
12699 "\n\t\t: Each animation might define the SINGLE action (see below),"
12700 "\n\t\t: like camera transition, object transformation or custom callback."
12701 "\n\t\t: Child animations can be used for defining concurrent actions."
12702 "\n\t\t:"
12703 "\n\t\t: Camera animation:"
12704 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
12705 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
12706 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
12707 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12708 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
12709 "\n\t\t: -atX camera Center positions pair"
12710 "\n\t\t: -upX camera Up directions pair"
12711 "\n\t\t: -scaleX camera Scale factors pair"
12712 "\n\t\t: Object animation:"
12713 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
12714 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
12715 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12716 "\n\t\t: -locX object Location points pair (translation)"
12717 "\n\t\t: -rotX object Orientations pair (quaternions)"
12718 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
12719 "\n\t\t: Custom callback:"
12720 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
12721 "\n\t\t: %Pts overall animation presentation timestamp"
12722 "\n\t\t: %LocalPts local animation timestamp"
12723 "\n\t\t: %Normalized local animation normalized value in range 0..1"
08f8a185 12724 "\n\t\t:"
12725 "\n\t\t: Video recording:"
12726 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
12727 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
12728 "\n\t\t: [-crf Value] [-preset Preset]"
12729 "\n\t\t: -fps video framerate"
12730 "\n\t\t: -format file format, container (matroska, etc.)"
12731 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
12732 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
12733 "\n\t\t: -crf constant rate factor (specific to codec)"
12734 "\n\t\t: -preset codec parameters preset (specific to codec)"
1beb58d7 12735 __FILE__, VAnimation, group);
12736
4754e164 12737 theCommands.Add("vchangeselected",
dc3fe572 12738 "vchangeselected shape"
4754e164 12739 "- adds to shape to selection or remove one from it",
12740 __FILE__, VChangeSelected, group);
4754e164 12741 theCommands.Add ("vnbselected",
faea8b40 12742 "vnbselected"
12743 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
6b62b2da 12744 theCommands.Add ("vcamera",
30a1b24e 12745 "vcamera [PrsName] [-ortho] [-projtype]"
6b62b2da 12746 "\n\t\t: [-persp]"
12747 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
12748 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
12749 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
12750 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
30a1b24e 12751 "\n\t\t: Manages camera parameters."
12752 "\n\t\t: Displays frustum when presntation name PrsName is specified."
6b62b2da 12753 "\n\t\t: Prints current value when option called without argument."
12754 "\n\t\t: Orthographic camera:"
12755 "\n\t\t: -ortho activate orthographic projection"
12756 "\n\t\t: Perspective camera:"
12757 "\n\t\t: -persp activate perspective projection (mono)"
12758 "\n\t\t: -fovy field of view in y axis, in degrees"
12759 "\n\t\t: -distance distance of eye from camera center"
12760 "\n\t\t: Stereoscopic camera:"
12761 "\n\t\t: -stereo perspective projection (stereo)"
12762 "\n\t\t: -leftEye perspective projection (left eye)"
12763 "\n\t\t: -rightEye perspective projection (right eye)"
12764 "\n\t\t: -iod intraocular distance value"
12765 "\n\t\t: -iodType distance type, absolute or relative"
12766 "\n\t\t: -zfocus stereographic focus value"
12767 "\n\t\t: -zfocusType focus type, absolute or relative",
12768 __FILE__, VCamera, group);
b5ac8292 12769 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
197ac94e 12770 "- vautozfit [on={1|0}] [scale]\n"
12771 " Prints or changes parameters of automatic z-fit mode:\n"
12772 " \"on\" - turns automatic z-fit on or off\n"
12773 " \"scale\" - specifies factor to scale computed z range.\n",
12774 __FILE__, VAutoZFit, group);
b5ac8292 12775 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
12776 " vzrange - without parameters shows current values\n"
12777 " vzrange [znear] [zfar] - applies provided values to view",
12778 __FILE__,VZRange, group);
4754e164 12779 theCommands.Add ("vpurgedisplay",
eb4320f2 12780 "vpurgedisplay"
4754e164 12781 "- removes structures which don't belong to objects displayed in neutral point",
12782 __FILE__, VPurgeDisplay, group);
12783 theCommands.Add("vsetviewsize",
12784 "vsetviewsize size",
12785 __FILE__,VSetViewSize,group);
12786 theCommands.Add("vmoveview",
12787 "vmoveview Dx Dy Dz [Start = 1|0]",
12788 __FILE__,VMoveView,group);
12789 theCommands.Add("vtranslateview",
12790 "vtranslateview Dx Dy Dz [Start = 1|0)]",
12791 __FILE__,VTranslateView,group);
12792 theCommands.Add("vturnview",
12793 "vturnview Ax Ay Az [Start = 1|0]",
12794 __FILE__,VTurnView,group);
269294d6 12795 theCommands.Add("vtextureenv",
12796 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
12797 "or user-defined file and optionally applying texture mapping parameters\n"
12798 " Usage:\n"
12799 " vtextureenv off - disables environment mapping\n"
12800 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
12801 " std_texture = (0..7)\n"
12802 " rep = {clamp|repeat}\n"
12803 " mod = {decal|modulate}\n"
12804 " flt = {nearest|bilinear|trilinear}\n"
12805 " ss, st - scale factors for s and t texture coordinates\n"
12806 " ts, tt - translation for s and t texture coordinates\n"
12807 " rot - texture rotation angle in degrees",
12808 __FILE__, VTextureEnv, group);
1eeef710 12809 theCommands.Add("vhlr",
12810 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
12811 "\n\t\t: Hidden Line Removal algorithm."
12812 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
12813 "\n\t\t: -algoType type of HLR algorithm.\n",
0a768f56 12814 __FILE__,VHLR,group);
1eeef710 12815 theCommands.Add("vhlrtype",
12816 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
12817 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
12818 "\n\t\t: 'algo' - exact HLR algorithm is applied"
12819 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
12820 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
0a768f56 12821 __FILE__,VHLRType,group);
3e05329c 12822 theCommands.Add("vclipplane",
12823 "vclipplane planeName [{0|1}]"
25c35042 12824 "\n\t\t: [-equation1 A B C D]"
12825 "\n\t\t: [-equation2 A B C D]"
12826 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
32ca7711 12827 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
3e05329c 12828 "\n\t\t: [-maxPlanes]"
12829 "\n\t\t: [-capping {0|1}]"
1b661a81 12830 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
3e05329c 12831 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
12832 "\n\t\t: [-texRotate Angle]"
12833 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
12834 "\n\t\t: [-useObjShader {0|1}]"
12835 "\n\t\t: Clipping planes management:"
12836 "\n\t\t: -maxPlanes print plane limit for view"
12837 "\n\t\t: -delete delete plane with given name"
12838 "\n\t\t: {off|on|0|1} turn clipping on/off"
12839 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
12840 "\n\t\t: applied to active View when list is omitted"
12841 "\n\t\t: -equation A B C D change plane equation"
12842 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
12843 "\n\t\t: Capping options:"
12844 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
12845 "\n\t\t: -color R G B set capping color"
1b661a81 12846 "\n\t\t: -transparency Value set capping transparency 0..1"
3e05329c 12847 "\n\t\t: -texName Texture set capping texture"
12848 "\n\t\t: -texScale SX SY set capping tex scale"
12849 "\n\t\t: -texOrigin TX TY set capping tex origin"
12850 "\n\t\t: -texRotate Angle set capping tex rotation"
12851 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
12852 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
12853 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
12854 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
12855 __FILE__, VClipPlane, group);
392ac980 12856 theCommands.Add("vdefaults",
4c513386 12857 "vdefaults [-absDefl value]"
12858 "\n\t\t: [-devCoeff value]"
12859 "\n\t\t: [-angDefl value]"
12860 "\n\t\t: [-autoTriang {off/on | 0/1}]"
12861 , __FILE__, VDefaults, group);
12381341 12862 theCommands.Add("vlight",
816d03ee 12863 "tool to manage light sources, without arguments shows list of lights."
12864 "\n Main commands: "
992ed6b3 12865 "\n '-clear' to clear lights"
12866 "\n '-{def}aults' to load deafault lights"
12867 "\n '-add' <type> to add any light source"
816d03ee 12868 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
12869 "\n 'change' <lightId> to edit light source with specified lightId"
12870 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
992ed6b3 12871 "\n -layer Id"
12872 "\n -{pos}ition X Y Z"
12873 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
12874 "\n -color colorName"
12875 "\n -{head}light 0|1"
12876 "\n -{sm}oothness value"
12877 "\n -{int}ensity value"
12878 "\n -{constAtten}uation value"
12879 "\n -{linearAtten}uation value"
12880 "\n -angle angleDeg"
12881 "\n -{spotexp}onent value"
12882 "\n -local|-global"
12883 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
12884 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
12381341 12885 __FILE__, VLight, group);
6b62b2da 12886 theCommands.Add("vraytrace",
12887 "vraytrace [0|1]"
189f85a3 12888 "\n\t\t: Turns on/off ray-tracing renderer."
6b62b2da 12889 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
12890 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
12891 __FILE__, VRenderParams, group);
bc8c79bb 12892 theCommands.Add("vrenderparams",
12893 "\n Manages rendering parameters: "
a1073ae2 12894 "\n '-raster' Disables GPU ray-tracing"
12895 "\n '-msaa 0..4' Specifies number of samples for MSAA"
12896 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
f88457e6 12897 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
c40eb6b9 12898 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
a1073ae2 12899 "\n '-rendScale value Rendering resolution scale factor"
12900 "\n '-rayTrace' Enables GPU ray-tracing"
12901 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
12902 "\n '-shadows on|off' Enables/disables shadows rendering"
12903 "\n '-reflections on|off' Enables/disables specular reflections"
12904 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
12905 "\n '-gleam on|off' Enables/disables transparency shadow effects"
12906 "\n '-gi on|off' Enables/disables global illumination effects"
12907 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
12908 "\n '-env on|off' Enables/disables environment map background"
12909 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
12910 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
12911 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
12912 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
66d1cdc6 12913 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
12914 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
a1073ae2 12915 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
12916 "\n '-shadingModel model' Controls shading model from enumeration"
12917 "\n color, flat, gouraud, phong"
12918 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
b27ab03d 12919 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
12920 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
eb85ed36 12921 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
12922 "\n '-whitepoint value' White point value for filmic tone mapping"
12923 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
5e30547b 12924 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points"
12925 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
15669413 12926 "\n Show/hide performance counters (flags can be combined)"
12927 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
5e30547b 12928 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
12929 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
0e3025bc 12930 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
12931 "\n set state to check structures culled previously."
8625ef7e 12932 "\n Unlike vcaps, these parameters dramatically change visual properties."
12933 "\n Command is intended to control presentation quality depending on"
12934 "\n hardware capabilities and performance.",
bc8c79bb 12935 __FILE__, VRenderParams, group);
79b544e6 12936 theCommands.Add("vstatprofiler",
12937 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
12938 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
12939 "\n |triagles|points|geomMem|textureMem|frameMem"
12940 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
12941 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
12942 "\n [-noredraw]"
12943 "\n\t\t: Prints rendering statistics."
12944 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
12945 "\n\t\t: else - print all performance counters set previously."
12946 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
12947 __FILE__, VStatProfiler, group);
49e1a5c7 12948 theCommands.Add ("vplace",
12949 "vplace dx dy"
12950 "\n\t\t: Places the point (in pixels) at the center of the window",
12951 __FILE__, VPlace, group);
0717ddc1 12952 theCommands.Add("vxrotate",
12953 "vxrotate",
12954 __FILE__,VXRotate,group);
12955
625e1958 12956 theCommands.Add("vmanipulator",
12957 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
12958 "\n tool to create and manage AIS manipulators."
12959 "\n Options: "
12960 "\n '-attach AISObject' attach manipulator to AISObject"
12961 "\n '-adjustPosition {0|1}' adjust position when attaching"
12962 "\n '-adjustSize {0|1}' adjust size when attaching"
12963 "\n '-enableModes {0|1}' enable modes when attaching"
12964 "\n '-detach' detach manipulator"
12965 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
12966 "\n '-transform mouse_x mouse_y' - invoke transformation"
12967 "\n '-stopTransform [abort]' - invoke stop of transformation"
12968 "\n '-move x y z' - move attached object"
12969 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
12970 "\n '-scale factor' - scale attached object"
12971 "\n '-autoActivate {0|1}' - set activation on detection"
12972 "\n '-followTranslation {0|1}' - set following translation transform"
12973 "\n '-followRotation {0|1}' - set following rotation transform"
12974 "\n '-gap value' - set gap between sub-parts"
12975 "\n '-part axis mode {0|1}' - set visual part"
12976 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
12977 "\n '-size value' - set size of manipulator"
12978 "\n '-zoomable {0|1}' - set zoom persistence",
12979 __FILE__, VManipulator, group);
12980
8e5fb5ea 12981 theCommands.Add("vselprops",
f838dac4 12982 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
8e5fb5ea 12983 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
12984 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
be3d8cbc 12985 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
12986 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
14c4193d 12987 "\n -pickStrategy {first|topmost} : defines picking strategy"
12988 "\n 'first' to pick first acceptable (default)"
12989 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
8e5fb5ea 12990 "\n -pixTol value : sets up pixel tolerance"
f838dac4 12991 "\n -dispMode dispMode : sets display mode for highlighting"
12992 "\n -layer ZLayer : sets ZLayer for highlighting"
12993 "\n -color {name|r g b} : sets highlight color"
12994 "\n -transp value : sets transparency coefficient for highlight"
12995 "\n -material material : sets highlight material"
8e5fb5ea 12996 "\n -print : prints current state of all mentioned parameters",
12997 __FILE__, VSelectionProperties, group);
be3d8cbc 12998 theCommands.Add ("vhighlightselected",
12999 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
13000 __FILE__, VSelectionProperties, group);
8e5fb5ea 13001
decdee7d 13002 theCommands.Add ("vseldump",
13003 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
13004 "\n\t\t: Generate an image based on detection results:"
13005 "\n\t\t: depth normalized depth values"
13006 "\n\t\t: unnormDepth unnormalized depth values"
13007 "\n\t\t: object color of detected object"
13008 "\n\t\t: owner color of detected owner"
13009 "\n\t\t: selMode color of selection mode"
13010 "\n\t\t: entity color of etected entity",
13011 __FILE__, VDumpSelectionImage, group);
13012
189f85a3 13013#if defined(_WIN32)
13014 theCommands.Add("vprogressive",
13015 "vprogressive",
13016 __FILE__, VProgressiveMode, group);
13017#endif
7fd59977 13018}