0025467: Visualization - Possibility to remove AIS_LocalContext class
[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>
7a324550 22#include <AIS_ColorScale.hxx>
625e1958 23#include <AIS_Manipulator.hxx>
b12e1c7b 24#include <AIS_RubberBand.hxx>
0a768f56 25#include <AIS_Shape.hxx>
0a768f56 26#include <AIS_InteractiveObject.hxx>
27#include <AIS_ListOfInteractive.hxx>
28#include <AIS_ListIteratorOfListOfInteractive.hxx>
8a590580 29#include <Aspect_Grid.hxx>
0a768f56 30#include <DBRep.hxx>
08f8a185 31#include <Draw_ProgressIndicator.hxx>
61b0191c 32#include <Graphic3d_ArrayOfPolylines.hxx>
2bd4c032 33#include <Graphic3d_AspectMarker3d.hxx>
269294d6 34#include <Graphic3d_NameOfTextureEnv.hxx>
a79f67f8 35#include <Graphic3d_GraduatedTrihedron.hxx>
269294d6 36#include <Graphic3d_TextureEnv.hxx>
37#include <Graphic3d_TextureParams.hxx>
38#include <Graphic3d_TypeOfTextureFilter.hxx>
4269bd1b 39#include <Graphic3d_AspectFillArea3d.hxx>
7fd59977 40#include <ViewerTest.hxx>
8625ef7e 41#include <ViewerTest_AutoUpdater.hxx>
7fd59977 42#include <ViewerTest_EventManager.hxx>
4754e164 43#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
4269bd1b 44#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
625e1958 45#include <ViewerTest_CmdParser.hxx>
12381341 46#include <V3d_AmbientLight.hxx>
47#include <V3d_DirectionalLight.hxx>
12381341 48#include <V3d_PositionalLight.hxx>
49#include <V3d_SpotLight.hxx>
08f8a185 50#include <Message_ProgressSentry.hxx>
18d715bd 51#include <NCollection_DoubleMap.hxx>
52#include <NCollection_List.hxx>
53#include <NCollection_Vector.hxx>
7fd59977 54#include <AIS_InteractiveContext.hxx>
55#include <Draw_Interpretor.hxx>
56#include <Draw.hxx>
57#include <Draw_Appli.hxx>
692613e5 58#include <Image_AlienPixMap.hxx>
08f8a185 59#include <Image_VideoRecorder.hxx>
58655684 60#include <OpenGl_GraphicDriver.hxx>
208e6839 61#include <OSD_Timer.hxx>
900f7229 62#include <TColStd_HSequenceOfAsciiString.hxx>
59f45b7c 63#include <TColStd_SequenceOfInteger.hxx>
4754e164 64#include <TColStd_HSequenceOfReal.hxx>
65#include <TColgp_Array1OfPnt2d.hxx>
197ac94e 66#include <TColStd_MapOfAsciiString.hxx>
20637bd2 67#include <Aspect_TypeOfLine.hxx>
692613e5 68#include <Image_Diff.hxx>
dc3fe572 69#include <Aspect_DisplayConnection.hxx>
4269bd1b 70#include <gp_Pnt.hxx>
71#include <gp_Dir.hxx>
72#include <gp_Pln.hxx>
73#include <PrsMgr_PresentableObject.hxx>
74#include <Graphic3d_ClipPlane.hxx>
75#include <NCollection_DataMap.hxx>
76#include <Graphic3d_Texture2Dmanual.hxx>
77#include <Prs3d_ShadingAspect.hxx>
6262338c 78#include <Prs3d_Drawer.hxx>
61b0191c 79#include <Prs3d_LineAspect.hxx>
80#include <Prs3d_Root.hxx>
fd3f6bd0 81#include <Prs3d_Text.hxx>
82#include <Select3D_SensitivePrimitiveArray.hxx>
7fd59977 83
57c28b61 84#ifdef _WIN32
25289ec1 85#undef DrawText
86#endif
87
692613e5 88#include <cstdlib>
25289ec1 89
58655684 90#if defined(_WIN32)
4fe56619 91 #include <WNT_WClass.hxx>
92 #include <WNT_Window.hxx>
4fe56619 93#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 94 #include <Cocoa_Window.hxx>
7fd59977 95#else
4fe56619 96 #include <Xw_Window.hxx>
97 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
98 #include <X11/Xutil.h>
99 #include <tk.h>
7fd59977 100#endif
101
b514beda 102// Auxiliary definitions
103static const char THE_KEY_DELETE = 127;
fd3f6bd0 104static const char THE_KEY_ESCAPE = 27;
7fd59977 105
106//==============================================================================
107// VIEWER GLOBAL VARIABLES
108//==============================================================================
109
110Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
b514beda 111Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
7fd59977 112
113Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
4754e164 114extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
7fd59977 115
b514beda 116extern int VErase (Draw_Interpretor& theDI,
117 Standard_Integer theArgNb,
118 const char** theArgVec);
119
58655684 120#if defined(_WIN32)
7fd59977 121static Handle(WNT_Window)& VT_GetWindow() {
122 static Handle(WNT_Window) WNTWin;
123 return WNTWin;
124}
4fe56619 125#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 126static Handle(Cocoa_Window)& VT_GetWindow()
127{
128 static Handle(Cocoa_Window) aWindow;
129 return aWindow;
130}
131extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
18d715bd 132extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
133extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
134
7fd59977 135#else
7fd59977 136static Handle(Xw_Window)& VT_GetWindow(){
137 static Handle(Xw_Window) XWWin;
138 return XWWin;
139}
7fd59977 140
141static void VProcessEvents(ClientData,int);
142#endif
143
18d715bd 144static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
145{
146 static Handle(Aspect_DisplayConnection) aDisplayConnection;
147 return aDisplayConnection;
148}
149
150static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
151{
152 GetDisplayConnection() = theDisplayConnection;
153}
154
58655684 155#if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 156Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
dc3fe572 157{
0ebaa4db 158 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
58655684 159#if defined(_WIN32)
18d715bd 160 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
161 if (!aWindow.IsNull())
162 return aWindow->HWindow();
163#elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
164 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
165 if (!aWindow.IsNull())
166 return aWindow->XWindow();
167#endif
168 return aWindowHandle;
dc3fe572 169}
18d715bd 170#endif
dc3fe572 171
2e93433e 172//! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events
173class ViewerTest_V3dView : public V3d_View
174{
175 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_V3dView, V3d_View)
176public:
177 //! Initializes the view.
178 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC,
179 bool theIs2dMode = false)
180 : V3d_View (theViewer, theType), myIs2dMode (theIs2dMode) {}
181
182 //! Initializes the view by copying.
183 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
184 : V3d_View (theViewer, theView), myIs2dMode (false)
185 {
186 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView))
187 {
188 myIs2dMode = aV3dView->IsViewIn2DMode();
189 }
190 }
191
192 //! Returns true if 2D mode is set for the view
193 bool IsViewIn2DMode() const { return myIs2dMode; }
194
195 //! Sets 2D mode for the view
196 void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; }
197
198public:
199
200 //! Returns true if active view in 2D mode.
201 static bool IsCurrentViewIn2DMode()
202 {
203 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
204 {
205 return aV3dView->IsViewIn2DMode();
206 }
207 return false;
208 }
209
210 //! Set if active view in 2D mode.
211 static void SetCurrentView2DMode (bool theIs2d)
212 {
213 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
214 {
215 aV3dView->SetView2DMode (theIs2d);
216 }
217 }
218
219private:
220
221 Standard_Boolean myIs2dMode; //!< 2D mode flag
222
223};
224
18d715bd 225NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
58655684 226static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
18d715bd 227static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
58655684 228static OpenGl_Caps ViewerTest_myDefaultCaps;
18d715bd 229
7fd59977 230static void OSWindowSetup();
231
f42753ed 232static struct
233{
234 Quantity_Color FlatColor;
235 Quantity_Color GradientColor1;
236 Quantity_Color GradientColor2;
237 Aspect_GradientFillMethod FillMethod;
238} ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
239
7fd59977 240//==============================================================================
241// EVENT GLOBAL VARIABLES
242//==============================================================================
243
244static int Start_Rot = 0;
1eeef710 245Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
4fe56619 246int X_Motion = 0; // Current cursor position
247int Y_Motion = 0;
248int X_ButtonPress = 0; // Last ButtonPress position
249int Y_ButtonPress = 0;
250Standard_Boolean IsDragged = Standard_False;
8abada55 251Standard_Boolean DragFirst = Standard_False;
1beb58d7 252Standard_Boolean TheIsAnimating = Standard_False;
fd3f6bd0 253Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
254Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
7fd59977 255
b12e1c7b 256
257Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
258{
259 static Handle(AIS_RubberBand) aBand;
260 if (aBand.IsNull())
261 {
69adb9ce 262 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
263 aBand->SetDisplayMode (0);
b12e1c7b 264 }
265 return aBand;
266}
267
625e1958 268typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
269
270Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
271{
272 static ViewerTest_MapOfAISManipulators aMap;
273 return aMap;
274}
275
276Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
277{
278 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
279 for (; anIt.More(); anIt.Next())
280 {
281 if (anIt.Value()->HasActiveMode())
282 {
283 return anIt.Value();
284 }
285 }
286 return NULL;
287}
288
7fd59977 289//==============================================================================
290
57c28b61 291#ifdef _WIN32
7fd59977 292static LRESULT WINAPI ViewerWindowProc(
293 HWND hwnd,
294 UINT uMsg,
295 WPARAM wParam,
296 LPARAM lParam );
297static LRESULT WINAPI AdvViewerWindowProc(
298 HWND hwnd,
299 UINT uMsg,
300 WPARAM wParam,
301 LPARAM lParam );
302#endif
303
304
305//==============================================================================
306//function : WClass
307//purpose :
308//==============================================================================
309
ad03c234 310const Handle(Standard_Transient)& ViewerTest::WClass()
7fd59977 311{
ad03c234 312 static Handle(Standard_Transient) theWClass;
58655684 313#if defined(_WIN32)
4fe56619 314 if (theWClass.IsNull())
315 {
7c65581d 316 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
ad03c234 317 CS_VREDRAW | CS_HREDRAW, 0, 0,
c85a994a 318 ::LoadCursor (NULL, IDC_ARROW));
7fd59977 319 }
320#endif
321 return theWClass;
322}
323
18d715bd 324//==============================================================================
325//function : CreateName
326//purpose : Create numerical name for new object in theMap
327//==============================================================================
328template <typename ObjectType>
329TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
330 const TCollection_AsciiString& theDefaultString)
331{
332 if (theObjectMap.IsEmpty())
333 return theDefaultString + TCollection_AsciiString(1);
334
335 Standard_Integer aNextKey = 1;
336 Standard_Boolean isFound = Standard_False;
337 while (!isFound)
338 {
339 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
340 // Look for objects with default names
341 if (theObjectMap.IsBound1(aStringKey))
342 {
343 aNextKey++;
344 }
345 else
346 isFound = Standard_True;
347 }
348
349 return theDefaultString + TCollection_AsciiString(aNextKey);
350}
351
352//==============================================================================
353//structure : ViewerTest_Names
354//purpose : Allow to operate with full view name: driverName/viewerName/viewName
355//==============================================================================
356struct ViewerTest_Names
357{
358private:
359 TCollection_AsciiString myDriverName;
360 TCollection_AsciiString myViewerName;
361 TCollection_AsciiString myViewName;
362
363public:
364
365 const TCollection_AsciiString& GetDriverName () const
366 {
367 return myDriverName;
368 }
369 void SetDriverName (const TCollection_AsciiString& theDriverName)
370 {
371 myDriverName = theDriverName;
372 }
373 const TCollection_AsciiString& GetViewerName () const
374 {
375 return myViewerName;
376 }
377 void SetViewerName (const TCollection_AsciiString& theViewerName)
378 {
379 myViewerName = theViewerName;
380 }
381 const TCollection_AsciiString& GetViewName () const
382 {
383 return myViewName;
384 }
385 void SetViewName (const TCollection_AsciiString& theViewName)
386 {
387 myViewName = theViewName;
388 }
389
390 //===========================================================================
391 //function : Constructor for ViewerTest_Names
392 //purpose : Get view, viewer, driver names from custom string
393 //===========================================================================
394
395 ViewerTest_Names (const TCollection_AsciiString& theInputString)
396 {
397 TCollection_AsciiString aName(theInputString);
398 if (theInputString.IsEmpty())
399 {
400 // Get current configuration
401 if (ViewerTest_myDrivers.IsEmpty())
402 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
403 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
404 else
405 myDriverName = ViewerTest_myDrivers.Find2
406 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
407
408 if(ViewerTest_myContexts.IsEmpty())
409 {
410 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
411 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
412 }
413 else
c48e2889 414 {
18d715bd 415 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
c48e2889 416 }
18d715bd 417
c48e2889 418 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
18d715bd 419 }
420 else
421 {
422 // There is at least view name
423 Standard_Integer aParserNumber = 0;
424 for (Standard_Integer i = 0; i < 3; ++i)
425 {
426 Standard_Integer aParserPos = aName.SearchFromEnd("/");
427 if(aParserPos != -1)
428 {
429 aParserNumber++;
430 aName.Split(aParserPos-1);
431 }
432 else
433 break;
434 }
435 if (aParserNumber == 0)
436 {
437 // Only view name
438 if (!ViewerTest::GetAISContext().IsNull())
439 {
440 myDriverName = ViewerTest_myDrivers.Find2
441 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
442 myViewerName = ViewerTest_myContexts.Find2
443 (ViewerTest::GetAISContext());
444 }
445 else
446 {
447 // There is no opened contexts here, need to create names for viewer and driver
448 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
449 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
450
451 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
452 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
453 }
454 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
455 }
456 else if (aParserNumber == 1)
457 {
458 // Here is viewerName/viewName
459 if (!ViewerTest::GetAISContext().IsNull())
460 myDriverName = ViewerTest_myDrivers.Find2
461 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
462 else
463 {
464 // There is no opened contexts here, need to create name for driver
465 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
466 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
467 }
468 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
469
470 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
471 }
472 else
473 {
474 //Here is driverName/viewerName/viewName
475 myDriverName = TCollection_AsciiString(aName);
476
477 TCollection_AsciiString aViewerName(theInputString);
478 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
479 myViewerName = TCollection_AsciiString(aViewerName);
480
481 myViewName = TCollection_AsciiString(theInputString);
482 }
483 }
484 }
485};
486
487//==============================================================================
488//function : FindContextByView
489//purpose : Find AIS_InteractiveContext by View
490//==============================================================================
491
492Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
493{
494 Handle(AIS_InteractiveContext) anAISContext;
495
496 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
497 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
498 {
499 if (anIter.Value()->CurrentViewer() == theView->Viewer())
500 return anIter.Key2();
501 }
502 return anAISContext;
503}
504
505
506//==============================================================================
507//function : SetWindowTitle
508//purpose : Set window title
509//==============================================================================
510
511void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
512 Standard_CString theTitle)
513{
58655684 514#if defined(_WIN32)
ad03c234 515 const TCollection_ExtendedString theTitleW (theTitle);
516 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
18d715bd 517#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
518 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
519#else
520 if(GetDisplayConnection()->GetDisplay())
521 {
522 Window aWindow =
523 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
524 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
525 }
526#endif
527}
528
529//==============================================================================
530//function : IsWindowOverlapped
531//purpose : Check if theWindow overlapp another view
532//==============================================================================
533
534Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
535 const Standard_Integer thePxTop,
536 const Standard_Integer thePxRight,
537 const Standard_Integer thePxBottom,
538 TCollection_AsciiString& theViewId)
539{
540 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
541 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
542 {
543 Standard_Integer aTop = 0,
544 aLeft = 0,
545 aRight = 0,
546 aBottom = 0;
547 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
548 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
549 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
550 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
551 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
552 {
553 theViewId = anIter.Key1();
554 return Standard_True;
555 }
556 }
557 return Standard_False;
558}
559
560// Workaround: to create and delete non-orthographic views outside ViewerTest
561void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
562{
563 ViewerTest_myViews.UnBind1 (theName);
564}
565
566void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
567 const Handle(V3d_View)& theView)
568{
569 ViewerTest_myViews.Bind (theName, theView);
570}
571
572TCollection_AsciiString ViewerTest::GetCurrentViewName ()
573{
574 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
575}
7fd59977 576//==============================================================================
577//function : ViewerInit
578//purpose : Create the window viewer and initialize all the global variable
579//==============================================================================
580
18d715bd 581TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
582 const Standard_Integer thePxTop,
583 const Standard_Integer thePxWidth,
584 const Standard_Integer thePxHeight,
9e04ccdc 585 const TCollection_AsciiString& theViewName,
586 const TCollection_AsciiString& theDisplayName,
587 const Handle(V3d_View)& theViewToClone)
7fd59977 588{
8c3c9904 589 // Default position and dimension of the viewer window.
4fe56619 590 // Note that left top corner is set to be sufficiently small to have
8c3c9904 591 // window fit in the small screens (actual for remote desktops, see #23003).
4fe56619 592 // The position corresponds to the window's client area, thus some
8c3c9904 593 // gap is added for window frame to be visible.
594 Standard_Integer aPxLeft = 20;
595 Standard_Integer aPxTop = 40;
7fd59977 596 Standard_Integer aPxWidth = 409;
597 Standard_Integer aPxHeight = 409;
18d715bd 598 Standard_Boolean toCreateViewer = Standard_False;
9e04ccdc 599 if (!theViewToClone.IsNull())
600 {
601 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
602 }
18d715bd 603
58655684 604 Handle(OpenGl_GraphicDriver) aGraphicDriver;
18d715bd 605 ViewerTest_Names aViewNames(theViewName);
606 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
607 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
608
609 if (thePxLeft != 0)
610 aPxLeft = thePxLeft;
611 if (thePxTop != 0)
612 aPxTop = thePxTop;
613 if (thePxWidth != 0)
614 aPxWidth = thePxWidth;
615 if (thePxHeight != 0)
7fd59977 616 aPxHeight = thePxHeight;
4269bd1b 617
18d715bd 618 // Get graphic driver (create it or get from another view)
619 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
620 {
621 // Get connection string
58655684 622 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 623 TCollection_AsciiString aDisplayName(theDisplayName);
498ce76b 624 if (!aDisplayName.IsEmpty())
18d715bd 625 SetDisplayConnection (new Aspect_DisplayConnection ());
626 else
627 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
18d715bd 628 #else
498ce76b 629 (void)theDisplayName; // avoid warning on unused argument
18d715bd 630 SetDisplayConnection (new Aspect_DisplayConnection ());
631 #endif
14cb22a1 632
633 if (Draw_VirtualWindows)
634 {
635 // don't waste the time waiting for VSync when window is not displayed on the screen
636 ViewerTest_myDefaultCaps.swapInterval = 0;
637 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
638 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
639 }
65993a95 640 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
58655684 641 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
14cb22a1 642
18d715bd 643 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
644 toCreateViewer = Standard_True;
645 }
646 else
647 {
58655684 648 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
7fd59977 649 }
650
18d715bd 651 //Dispose the window if input parameters are default
652 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
7fd59977 653 {
18d715bd 654 Standard_Integer aTop = 0,
655 aLeft = 0,
656 aRight = 0,
657 aBottom = 0,
658 aScreenWidth = 0,
659 aScreenHeight = 0;
660
661 // Get screen resolution
662#if defined(_WIN32) || defined(__WIN32__)
663 RECT aWindowSize;
664 GetClientRect(GetDesktopWindow(), &aWindowSize);
665 aScreenHeight = aWindowSize.bottom;
666 aScreenWidth = aWindowSize.right;
667#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
668 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
669#else
670 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
671 aScreenWidth = WidthOfScreen(aScreen);
672 aScreenHeight = HeightOfScreen(aScreen);
673#endif
674
675 TCollection_AsciiString anOverlappedViewId("");
773f53f1 676
677 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
dc3fe572 678 {
18d715bd 679 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
680
681 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
682 && aRight + 2*aPxWidth + 40 > aScreenWidth)
683 {
684 if (aBottom + aPxHeight + 40 > aScreenHeight)
685 {
686 aPxLeft = 20;
687 aPxTop = 40;
688 break;
689 }
690 aPxLeft = 20;
691 aPxTop = aBottom + 40;
692 }
693 else
694 aPxLeft = aRight + 20;
dc3fe572 695 }
18d715bd 696 }
697
698 // Get viewer name
699 TCollection_AsciiString aTitle("3D View - ");
700 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
701
702 // Change name of current active window
703 if (!ViewerTest::CurrentView().IsNull())
704 {
51740958 705 TCollection_AsciiString anActiveWindowTitle("3D View - ");
706 anActiveWindowTitle = anActiveWindowTitle
18d715bd 707 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
51740958 708 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
18d715bd 709 }
710
711 // Create viewer
eb4320f2 712 Handle(V3d_Viewer) a3DViewer;
18d715bd 713 // If it's the single view, we first look for empty context
714 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
715 {
716 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
717 anIter(ViewerTest_myContexts);
718 if (anIter.More())
719 ViewerTest::SetAISContext (anIter.Value());
720 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 721 }
722 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
723 {
724 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
725 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 726 }
eb4320f2 727 else if (a3DViewer.IsNull())
18d715bd 728 {
729 toCreateViewer = Standard_True;
6a24c6de 730 a3DViewer = new V3d_Viewer(aGraphicDriver);
f42753ed 731 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
732 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
733 ViewerTest_DefaultBackground.GradientColor2,
734 ViewerTest_DefaultBackground.FillMethod);
18d715bd 735 }
736
737 // AIS context setup
738 if (ViewerTest::GetAISContext().IsNull() ||
739 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
740 {
e79a94b9 741 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
18d715bd 742 ViewerTest::SetAISContext (aContext);
743 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
744 }
745 else
e79a94b9 746 {
18d715bd 747 ViewerTest::ResetEventManager();
e79a94b9 748 }
18d715bd 749
750 // Create window
e79a94b9 751#if defined(_WIN32)
752 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
753 Handle(WNT_WClass)::DownCast (WClass()),
62e1beed 754 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
e79a94b9 755 aPxLeft, aPxTop,
756 aPxWidth, aPxHeight,
757 Quantity_NOC_BLACK);
4fe56619 758#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
e79a94b9 759 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
760 aPxLeft, aPxTop,
761 aPxWidth, aPxHeight);
762 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
7fd59977 763#else
e79a94b9 764 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
765 aTitle.ToCString(),
766 aPxLeft, aPxTop,
767 aPxWidth, aPxHeight);
7fd59977 768#endif
18d715bd 769 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
7fd59977 770
d09dda09 771 // View setup
9e04ccdc 772 Handle(V3d_View) aView;
773 if (!theViewToClone.IsNull())
774 {
2e93433e 775 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
9e04ccdc 776 }
777 else
778 {
2e93433e 779 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
9e04ccdc 780 }
781
d09dda09 782 aView->SetWindow (VT_GetWindow());
c3282ec1 783 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
4269bd1b 784
18d715bd 785 ViewerTest::CurrentView(aView);
786 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
7fd59977 787
18d715bd 788 // Setup for X11 or NT
789 OSWindowSetup();
7fd59977 790
18d715bd 791 // Set parameters for V3d_View and V3d_Viewer
792 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
793 aV3dView->SetComputedMode(Standard_False);
7fd59977 794
18d715bd 795 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
796 if (toCreateViewer)
797 {
7fd59977 798 a3DViewer->SetDefaultLights();
799 a3DViewer->SetLightOn();
18d715bd 800 }
7fd59977 801
e79a94b9 802 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4fe56619 803 #if TCL_MAJOR_VERSION < 8
18d715bd 804 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 805 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 806 #else
18d715bd 807 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 808 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 809 #endif
810 #endif
7fd59977 811
7fd59977 812 VT_GetWindow()->Map();
4269bd1b 813
18d715bd 814 // Set the handle of created view in the event manager
815 ViewerTest::ResetEventManager();
816
4fe56619 817 ViewerTest::CurrentView()->Redraw();
18d715bd 818
819 aView.Nullify();
820 a3DViewer.Nullify();
18d715bd 821
822 return aViewNames.GetViewName();
823}
824
4269bd1b 825//==============================================================================
826//function : RedrawAllViews
827//purpose : Redraw all created views
828//==============================================================================
829void ViewerTest::RedrawAllViews()
830{
831 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
832 for (; aViewIt.More(); aViewIt.Next())
833 {
834 const Handle(V3d_View)& aView = aViewIt.Key2();
835 aView->Redraw();
836 }
837}
838
7fd59977 839//==============================================================================
840//function : Vinit
841//purpose : Create the window viewer and initialize all the global variable
e79a94b9 842// Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
7fd59977 843//==============================================================================
844
18d715bd 845static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 846{
e79a94b9 847 TCollection_AsciiString aViewName, aDisplayName;
848 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
9e04ccdc 849 Handle(V3d_View) aCopyFrom;
e79a94b9 850 TCollection_AsciiString aName, aValue;
2e93433e 851 int is2dMode = -1;
e79a94b9 852 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
18d715bd 853 {
e79a94b9 854 const TCollection_AsciiString anArg = theArgVec[anArgIt];
855 TCollection_AsciiString anArgCase = anArg;
fd3f6bd0 856 anArgCase.LowerCase();
857 if (anArgIt + 1 < theArgsNb
858 && anArgCase == "-name")
859 {
860 aViewName = theArgVec[++anArgIt];
861 }
862 else if (anArgIt + 1 < theArgsNb
863 && (anArgCase == "-left"
864 || anArgCase == "-l"))
865 {
866 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
867 }
868 else if (anArgIt + 1 < theArgsNb
869 && (anArgCase == "-top"
870 || anArgCase == "-t"))
871 {
872 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
873 }
874 else if (anArgIt + 1 < theArgsNb
875 && (anArgCase == "-width"
876 || anArgCase == "-w"))
877 {
878 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
879 }
880 else if (anArgIt + 1 < theArgsNb
881 && (anArgCase == "-height"
882 || anArgCase == "-h"))
18d715bd 883 {
fd3f6bd0 884 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
885 }
886 else if (anArgCase == "-exitonclose")
887 {
888 Draw_ToExitOnCloseView = true;
889 if (anArgIt + 1 < theArgsNb
890 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
891 {
892 ++anArgIt;
893 }
894 }
895 else if (anArgCase == "-closeonescape"
896 || anArgCase == "-closeonesc")
897 {
898 Draw_ToCloseViewOnEsc = true;
899 if (anArgIt + 1 < theArgsNb
900 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
901 {
902 ++anArgIt;
903 }
904 }
2e93433e 905 else if (anArgCase == "-2d_mode"
906 || anArgCase == "-2dmode"
907 || anArgCase == "-2d")
908 {
909 bool toEnable = true;
910 if (anArgIt + 1 < theArgsNb
911 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
912 {
913 ++anArgIt;
914 }
915 is2dMode = toEnable ? 1 : 0;
916 }
fd3f6bd0 917 else if (anArgIt + 1 < theArgsNb
918 && (anArgCase == "-disp"
919 || anArgCase == "-display"))
920 {
921 aDisplayName = theArgVec[++anArgIt];
922 }
9e04ccdc 923 else if (!ViewerTest::CurrentView().IsNull()
924 && aCopyFrom.IsNull()
925 && (anArgCase == "-copy"
926 || anArgCase == "-clone"
927 || anArgCase == "-cloneactive"
928 || anArgCase == "-cloneactiveview"))
929 {
930 aCopyFrom = ViewerTest::CurrentView();
931 }
fd3f6bd0 932 // old syntax
933 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
934 {
935 aName.LowerCase();
936 if (aName == "name")
18d715bd 937 {
938 aViewName = aValue;
939 }
fd3f6bd0 940 else if (aName == "l"
941 || aName == "left")
e79a94b9 942 {
18d715bd 943 aPxLeft = aValue.IntegerValue();
e79a94b9 944 }
fd3f6bd0 945 else if (aName == "t"
946 || aName == "top")
e79a94b9 947 {
18d715bd 948 aPxTop = aValue.IntegerValue();
e79a94b9 949 }
fd3f6bd0 950 else if (aName == "disp"
951 || aName == "display")
e79a94b9 952 {
18d715bd 953 aDisplayName = aValue;
e79a94b9 954 }
fd3f6bd0 955 else if (aName == "w"
956 || aName == "width")
e79a94b9 957 {
18d715bd 958 aPxWidth = aValue.IntegerValue();
e79a94b9 959 }
fd3f6bd0 960 else if (aName == "h"
961 || aName == "height")
e79a94b9 962 {
18d715bd 963 aPxHeight = aValue.IntegerValue();
e79a94b9 964 }
18d715bd 965 else
966 {
fd3f6bd0 967 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
968 return 1;
18d715bd 969 }
970 }
e79a94b9 971 else if (aViewName.IsEmpty())
972 {
973 aViewName = anArg;
974 }
975 else
976 {
fd3f6bd0 977 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
978 return 1;
e79a94b9 979 }
18d715bd 980 }
981
fd3f6bd0 982#if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
983 if (!aDisplayName.IsEmpty())
984 {
985 aDisplayName.Clear();
986 std::cout << "Warning: display parameter will be ignored.\n";
987 }
988#endif
989
18d715bd 990 ViewerTest_Names aViewNames (aViewName);
e79a94b9 991 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
18d715bd 992 {
e79a94b9 993 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
994 theDi.Eval (aCommand.ToCString());
2e93433e 995 if (is2dMode != -1)
996 {
997 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
998 }
18d715bd 999 return 0;
1000 }
1001
1002 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
9e04ccdc 1003 aViewName, aDisplayName, aCopyFrom);
2e93433e 1004 if (is2dMode != -1)
1005 {
1006 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1007 }
e79a94b9 1008 theDi << aViewId;
7fd59977 1009 return 0;
1010}
1011
1eeef710 1012//! Parse HLR algo type.
1013static Standard_Boolean parseHlrAlgoType (const char* theName,
1014 Prs3d_TypeOfHLR& theType)
1015{
1016 TCollection_AsciiString aName (theName);
1017 aName.LowerCase();
1018 if (aName == "polyalgo")
1019 {
1020 theType = Prs3d_TOH_PolyAlgo;
1021 }
1022 else if (aName == "algo")
1023 {
1024 theType = Prs3d_TOH_Algo;
1025 }
1026 else
1027 {
1028 return Standard_False;
1029 }
1030 return Standard_True;
1031}
1032
0a768f56 1033//==============================================================================
1034//function : VHLR
1035//purpose : hidden lines removal algorithm
1036//==============================================================================
1037
1038static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1039{
1eeef710 1040 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1041 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1042 if (aView.IsNull())
0a768f56 1043 {
1eeef710 1044 std::cerr << "Error: No opened viewer!\n";
0a768f56 1045 return 1;
1046 }
1047
1eeef710 1048 Standard_Boolean hasHlrOnArg = Standard_False;
1049 Standard_Boolean hasShowHiddenArg = Standard_False;
1050 Standard_Boolean isHLROn = Standard_False;
1051 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
1052 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1053 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1054 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
0a768f56 1055 {
1eeef710 1056 TCollection_AsciiString anArg (argv[anArgIter]);
1057 anArg.LowerCase();
1058 if (anUpdateTool.parseRedrawMode (anArg))
1059 {
1060 continue;
1061 }
1062 else if (anArg == "-showhidden"
1063 && anArgIter + 1 < argc
1064 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
1065 {
1066 ++anArgIter;
1067 hasShowHiddenArg = Standard_True;
1068 continue;
1069 }
1070 else if ((anArg == "-type"
1071 || anArg == "-algo"
1072 || anArg == "-algotype")
1073 && anArgIter + 1 < argc
1074 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1075 {
1076 ++anArgIter;
1077 continue;
1078 }
1079 else if (!hasHlrOnArg
1080 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
1081 {
1082 hasHlrOnArg = Standard_True;
1083 continue;
1084 }
1085 // old syntax
1086 else if (!hasShowHiddenArg
1087 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
1088 {
1089 hasShowHiddenArg = Standard_True;
1090 continue;
1091 }
1092 else
1093 {
1094 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
1095 return 1;
1096 }
0a768f56 1097 }
1eeef710 1098 if (!hasHlrOnArg)
0a768f56 1099 {
1eeef710 1100 di << "HLR: " << aView->ComputedMode() << "\n";
1101 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1102 di << "HlrAlgo: ";
1103 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1104 {
1105 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1106 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1107 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1108 }
1109 anUpdateTool.Invalidate();
1110 return 0;
0a768f56 1111 }
1112
1eeef710 1113 Standard_Boolean toRecompute = Standard_False;
1114 if (aTypeOfHLR != Prs3d_TOH_NotSet
1115 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
e9224045 1116 {
1eeef710 1117 toRecompute = Standard_True;
1118 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1119 }
1120 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1121 {
1122 toRecompute = Standard_True;
1123 if (toShowHidden)
e9224045 1124 {
1eeef710 1125 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
e9224045 1126 }
1127 else
1128 {
1eeef710 1129 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
e9224045 1130 }
1eeef710 1131 }
e9224045 1132
1eeef710 1133 // redisplay shapes
1134 if (aView->ComputedMode() && isHLROn && toRecompute)
1135 {
1136 AIS_ListOfInteractive aListOfShapes;
1137 aCtx->DisplayedObjects (aListOfShapes);
1138 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
e9224045 1139 {
1eeef710 1140 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
e9224045 1141 {
1eeef710 1142 aCtx->Redisplay (aShape, Standard_False);
e9224045 1143 }
1144 }
1145 }
0a768f56 1146
1eeef710 1147 aView->SetComputedMode (isHLROn);
0a768f56 1148 return 0;
1149}
1150
1151//==============================================================================
1152//function : VHLRType
1153//purpose : change type of using HLR algorithm
1154//==============================================================================
1155
1eeef710 1156static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
0a768f56 1157{
1eeef710 1158 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1159 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1160 if (aView.IsNull())
0a768f56 1161 {
1eeef710 1162 std::cerr << "Error: No opened viewer!\n";
0a768f56 1163 return 1;
1164 }
1165
1eeef710 1166 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1167 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1168 AIS_ListOfInteractive aListOfShapes;
1169 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
0a768f56 1170 {
1eeef710 1171 TCollection_AsciiString anArg (argv[anArgIter]);
1172 anArg.LowerCase();
1173 if (anUpdateTool.parseRedrawMode (anArg))
0a768f56 1174 {
1eeef710 1175 continue;
0a768f56 1176 }
1eeef710 1177 else if ((anArg == "-type"
1178 || anArg == "-algo"
1179 || anArg == "-algotype")
1180 && anArgIter + 1 < argc
1181 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1182 {
1183 ++anArgIter;
1184 continue;
1185 }
1186 // old syntax
1187 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1188 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1189 {
1190 continue;
1191 }
1192 else
0a768f56 1193 {
1194 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1eeef710 1195 TCollection_AsciiString aName (argv[anArgIter]);
0a768f56 1196 if (!aMap.IsBound2 (aName))
1197 {
1eeef710 1198 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1199 return 1;
0a768f56 1200 }
1eeef710 1201
1202 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1203 if (aShape.IsNull())
1204 {
1205 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1206 return 1;
1207 }
1208 aListOfShapes.Append (aShape);
1209 continue;
0a768f56 1210 }
1eeef710 1211 }
1212 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1213 {
1214 std::cout << "Syntax error: wrong number of arguments!\n";
1215 return 1;
1216 }
1217
1218 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1219 if (isGlobal)
1220 {
1221 aCtx->DisplayedObjects (aListOfShapes);
1222 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
0a768f56 1223 }
1224
1eeef710 1225 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1226 {
1227 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1228 if (aShape.IsNull())
1229 {
1230 continue;
1231 }
1232
1233 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1234 && aView->ComputedMode();
1235 if (!isGlobal
1236 || aShape->TypeOfHLR() != aTypeOfHLR)
1237 {
1238 aShape->SetTypeOfHLR (aTypeOfHLR);
1239 }
1240 if (toUpdateShape)
1241 {
1242 aCtx->Redisplay (aShape, Standard_False);
1243 }
1244 }
0a768f56 1245 return 0;
1246}
1247
18d715bd 1248//==============================================================================
1249//function : FindViewIdByWindowHandle
1250//purpose : Find theView Id in the map of views by window handle
1251//==============================================================================
1252#if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1253TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1254{
1255 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1256 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1257 {
1258 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1259 if (aWindowHandle == theWindowHandle)
1260 return anIter.Key1();
1261 }
1262 return TCollection_AsciiString("");
1263}
1264#endif
1265
1266//==============================================================================
1267//function : ActivateView
1268//purpose : Make the view active
1269//==============================================================================
1270
1271void ActivateView (const TCollection_AsciiString& theViewName)
1272{
1273 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1274 if (!aView.IsNull())
1275 {
1276 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1277 if (!anAISContext.IsNull())
1278 {
1279 if (!ViewerTest::CurrentView().IsNull())
1280 {
1281 TCollection_AsciiString aTitle("3D View - ");
1282 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1283 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1284 }
1285
1286 ViewerTest::CurrentView (aView);
18d715bd 1287 ViewerTest::SetAISContext (anAISContext);
1eeef710 1288 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
18d715bd 1289 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1eeef710 1290#if defined(_WIN32)
18d715bd 1291 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1292#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1293 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1294#else
1295 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1296#endif
1297 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1298 ViewerTest::CurrentView()->Redraw();
1299 }
1300 }
1301}
1302
0e93d9e5 1303//==============================================================================
1304//function : RemoveView
1305//purpose :
1306//==============================================================================
1307void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1308 const Standard_Boolean theToRemoveContext)
1309{
1310 if (!ViewerTest_myViews.IsBound2 (theView))
1311 {
1312 return;
1313 }
1314
1315 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1316 RemoveView (aViewName, theToRemoveContext);
1317}
1318
18d715bd 1319//==============================================================================
1320//function : RemoveView
1321//purpose : Close and remove view from display, clear maps if neccessary
1322//==============================================================================
1323void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1324{
1325 if (!ViewerTest_myViews.IsBound1(theViewName))
1326 {
1327 cout << "Wrong view name\n";
1328 return;
1329 }
1330
1331 // Activate another view if it's active now
1332 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1333 {
1334 if (ViewerTest_myViews.Extent() > 1)
1335 {
1336 TCollection_AsciiString aNewViewName;
c48e2889 1337 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1338 anIter.More(); anIter.Next())
1339 {
18d715bd 1340 if (anIter.Key1() != theViewName)
1341 {
1342 aNewViewName = anIter.Key1();
1343 break;
1344 }
c48e2889 1345 }
1346 ActivateView (aNewViewName);
18d715bd 1347 }
1348 else
1349 {
1350 Handle(V3d_View) anEmptyView;
1351#if defined(_WIN32) || defined(__WIN32__)
1352 Handle(WNT_Window) anEmptyWindow;
1353#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1354 Handle(Cocoa_Window) anEmptyWindow;
1355#else
1356 Handle(Xw_Window) anEmptyWindow;
1357#endif
1358 VT_GetWindow() = anEmptyWindow;
1359 ViewerTest::CurrentView (anEmptyView);
1360 if (isContextRemoved)
1361 {
1362 Handle(AIS_InteractiveContext) anEmptyContext;
1363 ViewerTest::SetAISContext(anEmptyContext);
1364 }
1365 }
1366 }
1367
1368 // Delete view
1369 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1370 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1371
1372 // Remove view resources
18d715bd 1373 ViewerTest_myViews.UnBind1(theViewName);
851dacdb 1374 aView->Window()->Unmap();
18d715bd 1375 aView->Remove();
1376
1377#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1378 XFlush (GetDisplayConnection()->GetDisplay());
1379#endif
1380
1381 // Keep context opened only if the closed view is last to avoid
1382 // unused empty contexts
1383 if (!aCurrentContext.IsNull())
1384 {
1385 // Check if there are more difined views in the viewer
1386 aCurrentContext->CurrentViewer()->InitDefinedViews();
1387 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1388 {
1389 // Remove driver if there is no viewers that use it
1390 Standard_Boolean isRemoveDriver = Standard_True;
1391 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1392 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1393 {
1394 if (aCurrentContext != anIter.Key2() &&
1395 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1396 {
1397 isRemoveDriver = Standard_False;
1398 break;
1399 }
1400 }
2ec85268 1401
1402 aCurrentContext->RemoveAll (Standard_False);
18d715bd 1403 if(isRemoveDriver)
1404 {
1405 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1406 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1407 #if TCL_MAJOR_VERSION < 8
1408 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1409 #else
1410 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1411 #endif
1412 #endif
1413 }
1414
1415 ViewerTest_myContexts.UnBind2(aCurrentContext);
1416 }
1417 }
1418 cout << "3D View - " << theViewName << " was deleted.\n";
fd3f6bd0 1419 if (Draw_ToExitOnCloseView)
1420 {
1421 Draw_Interprete ("exit");
1422 }
18d715bd 1423}
1424
1425//==============================================================================
1426//function : VClose
1427//purpose : Remove the view defined by its name
1428//==============================================================================
1429
d0cc1cb7 1430static int VClose (Draw_Interpretor& /*theDi*/,
1431 Standard_Integer theArgsNb,
1432 const char** theArgVec)
18d715bd 1433{
18d715bd 1434 NCollection_List<TCollection_AsciiString> aViewList;
d0cc1cb7 1435 if (theArgsNb > 1)
18d715bd 1436 {
d0cc1cb7 1437 TCollection_AsciiString anArg (theArgVec[1]);
1438 anArg.UpperCase();
1439 if (anArg.IsEqual ("ALL")
1440 || anArg.IsEqual ("*"))
1441 {
1442 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1443 anIter.More(); anIter.Next())
1444 {
1445 aViewList.Append (anIter.Key1());
1446 }
1447 if (aViewList.IsEmpty())
1448 {
1449 std::cout << "No view to close\n";
1450 return 0;
1451 }
1452 }
1453 else
18d715bd 1454 {
d0cc1cb7 1455 ViewerTest_Names aViewName (theArgVec[1]);
1456 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1457 {
1458 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1459 return 1;
1460 }
1461 aViewList.Append (aViewName.GetViewName());
18d715bd 1462 }
1463 }
1464 else
1465 {
d0cc1cb7 1466 // close active view
1467 if (ViewerTest::CurrentView().IsNull())
1468 {
1469 std::cerr << "No active view!\n";
1470 return 1;
1471 }
1472 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
18d715bd 1473 }
1474
d0cc1cb7 1475 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
18d715bd 1476 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1477 anIter.More(); anIter.Next())
1478 {
d0cc1cb7 1479 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
18d715bd 1480 }
1481
1482 return 0;
1483}
1484
1485//==============================================================================
1486//function : VActivate
1487//purpose : Activate the view defined by its ID
1488//==============================================================================
1489
1490static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1491{
1492 if (theArgsNb > 2)
1493 {
1494 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1495 << "Usage: " << theArgVec[0] << " ViewID\n";
1496 return 1;
1497 }
1498 if(theArgsNb == 1)
1499 {
1500 theDi.Eval("vviewlist");
1501 return 0;
1502 }
1503
1504 TCollection_AsciiString aNameString(theArgVec[1]);
29cb310a 1505 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
18d715bd 1506 {
1507 TCollection_AsciiString aTitle("3D View - ");
1508 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1509 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1510 Handle(V3d_View) anEmptyView;
1511#if defined(_WIN32) || defined(__WIN32__)
1512 Handle(WNT_Window) anEmptyWindow;
1513#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1514 Handle(Cocoa_Window) anEmptyWindow;
1515#else
1516 Handle(Xw_Window) anEmptyWindow;
1517#endif
1518 VT_GetWindow() = anEmptyWindow;
1519 ViewerTest::CurrentView (anEmptyView);
1520 ViewerTest::ResetEventManager();
1521 theDi << theArgVec[0] << ": all views are inactive\n";
1522 return 0;
1523 }
1524
1525 ViewerTest_Names aViewNames(aNameString);
1526
1527 // Check if this view exists in the viewer with the driver
1528 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1529 {
1530 theDi << "Wrong view name\n";
1531 return 1;
1532 }
1533
1534 // Check if it is active already
1535 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1536 {
1537 theDi << theArgVec[0] << ": the view is active already\n";
1538 return 0;
1539 }
1540
1541 ActivateView (aViewNames.GetViewName());
1542 return 0;
1543}
1544
1545//==============================================================================
1546//function : VViewList
1547//purpose : Print current list of views per viewer and graphic driver ID
1548// shared between viewers
1549//==============================================================================
1550
1551static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1552{
1553 if (theArgsNb > 2)
1554 {
1555 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
29cb310a 1556 << "Usage: " << theArgVec[0] << " name";
18d715bd 1557 return 1;
1558 }
1559 if (ViewerTest_myContexts.Size() < 1)
1560 return 0;
1561
18d715bd 1562 Standard_Boolean isTreeView =
29cb310a 1563 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
18d715bd 1564
1565 if (isTreeView)
c48e2889 1566 {
18d715bd 1567 theDi << theArgVec[0] <<":\n";
c48e2889 1568 }
18d715bd 1569
c48e2889 1570 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1571 aDriverIter.More(); aDriverIter.Next())
1572 {
1573 if (isTreeView)
1574 theDi << aDriverIter.Key1() << ":\n";
18d715bd 1575
c48e2889 1576 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1577 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1578 {
1579 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
18d715bd 1580 {
c48e2889 1581 if (isTreeView)
18d715bd 1582 {
c48e2889 1583 TCollection_AsciiString aContextName(aContextIter.Key1());
1584 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1585 }
18d715bd 1586
c48e2889 1587 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1588 aViewIter.More(); aViewIter.Next())
1589 {
1590 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
18d715bd 1591 {
c48e2889 1592 TCollection_AsciiString aViewName(aViewIter.Key1());
1593 if (isTreeView)
18d715bd 1594 {
c48e2889 1595 if (aViewIter.Value() == ViewerTest::CurrentView())
1596 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
18d715bd 1597 else
c48e2889 1598 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1599 }
1600 else
1601 {
1602 theDi << aViewName << " ";
18d715bd 1603 }
1604 }
1605 }
1606 }
1607 }
c48e2889 1608 }
18d715bd 1609 return 0;
1610}
1611
7fd59977 1612//==============================================================================
4fe56619 1613//function : VT_ProcessKeyPress
7fd59977 1614//purpose : Handle KeyPress event from a CString
1615//==============================================================================
4fe56619 1616void VT_ProcessKeyPress (const char* buf_ret)
7fd59977 1617{
1618 //cout << "KeyPress" << endl;
1619 const Handle(V3d_View) aView = ViewerTest::CurrentView();
7fd59977 1620 // Letter in alphabetic order
1621
2e93433e 1622 if (!strcasecmp (buf_ret, "A")
1623 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1624 {
7fd59977 1625 // AXO
1626 aView->SetProj(V3d_XposYnegZpos);
1627 }
2e93433e 1628 else if (!strcasecmp (buf_ret, "D")
1629 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1630 {
7fd59977 1631 // Reset
1632 aView->Reset();
1633 }
b514beda 1634 else if (!strcasecmp (buf_ret, "F"))
1635 {
b586500b 1636 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1637 {
1638 ViewerTest::GetAISContext()->FitSelected (aView);
1639 }
1640 else
1641 {
1642 // FitAll
1643 aView->FitAll();
1644 }
7fd59977 1645 }
b514beda 1646 else if (!strcasecmp (buf_ret, "H"))
1647 {
7fd59977 1648 // HLR
1eeef710 1649 std::cout << "HLR" << std::endl;
de75ed09 1650 aView->SetComputedMode (!aView->ComputedMode());
1eeef710 1651 aView->Redraw();
7fd59977 1652 }
b514beda 1653 else if (!strcasecmp (buf_ret, "P"))
1654 {
0a768f56 1655 // Type of HLR
1656 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1657 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1658 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1659 else
1660 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
c3282ec1 1661 if (aContext->NbSelected()==0)
0a768f56 1662 {
1663 AIS_ListOfInteractive aListOfShapes;
1664 aContext->DisplayedObjects(aListOfShapes);
1665 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1666 anIter.More(); anIter.Next())
1667 {
1668 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1669 if (aShape.IsNull())
1670 continue;
1671 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1672 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1673 else
1674 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1675 aContext->Redisplay (aShape, Standard_False);
0a768f56 1676 }
1677 }
1678 else
1679 {
c3282ec1 1680 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
0a768f56 1681 {
c3282ec1 1682 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
0a768f56 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
1693 aContext->UpdateCurrentViewer();
4269bd1b 1694
0a768f56 1695 }
b514beda 1696 else if (!strcasecmp (buf_ret, "S"))
1697 {
1698 std::cout << "setup Shaded display mode" << std::endl;
4fe56619 1699
7fd59977 1700 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1701 if(Ctx->NbSelected()==0)
0577ae8c 1702 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
7fd59977 1703 else{
c3282ec1 1704 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1705 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
7fd59977 1706 Ctx->UpdateCurrentViewer();
1707 }
1708 }
b514beda 1709 else if (!strcasecmp (buf_ret, "U"))
1710 {
41811896 1711 // Unset display mode
b514beda 1712 std::cout << "reset display mode to defaults" << std::endl;
4fe56619 1713
7fd59977 1714 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1715 if(Ctx->NbSelected()==0)
0577ae8c 1716 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 1717 else{
c3282ec1 1718 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1719 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
7fd59977 1720 Ctx->UpdateCurrentViewer();
1721 }
1722
1723 }
2e93433e 1724 else if (!strcasecmp (buf_ret, "T")
1725 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1726 {
7fd59977 1727 // Top
1728 aView->SetProj(V3d_Zpos);
1729 }
2e93433e 1730 else if (!strcasecmp (buf_ret, "B")
1731 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1732 {
41811896 1733 // Bottom
7fd59977 1734 aView->SetProj(V3d_Zneg);
1735 }
2e93433e 1736 else if (!strcasecmp (buf_ret, "L")
1737 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1738 {
41811896 1739 // Left
7fd59977 1740 aView->SetProj(V3d_Xneg);
1741 }
2e93433e 1742 else if (!strcasecmp (buf_ret, "R")
1743 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1744 {
41811896 1745 // Right
7fd59977 1746 aView->SetProj(V3d_Xpos);
1747 }
b514beda 1748 else if (!strcasecmp (buf_ret, "W"))
1749 {
1750 std::cout << "setup WireFrame display mode" << std::endl;
7fd59977 1751 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1752 if(Ctx->NbSelected()==0)
0577ae8c 1753 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 1754 else{
c3282ec1 1755 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1756 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
7fd59977 1757 Ctx->UpdateCurrentViewer();
1758 }
1759 }
b514beda 1760 else if (!strcasecmp (buf_ret, ","))
1761 {
7fd59977 1762 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
7fd59977 1763 }
b514beda 1764 else if (!strcasecmp (buf_ret, "."))
1765 {
7fd59977 1766 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1767 }
f978241f 1768 else if (!strcasecmp (buf_ret, "/"))
1769 {
1770 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1771 if (aCamera->IsStereo())
1772 {
1773 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1774 aView->Redraw();
1775 }
1776 }
1777 else if (!strcasecmp (buf_ret, "*"))
1778 {
1779 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1780 if (aCamera->IsStereo())
1781 {
1782 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1783 aView->Redraw();
1784 }
1785 }
b514beda 1786 else if (*buf_ret == THE_KEY_DELETE)
1787 {
1788 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1789 if (!aCtx.IsNull()
b514beda 1790 && aCtx->NbSelected() > 0)
1791 {
1792 Draw_Interprete ("verase");
1793 }
1794 }
fd3f6bd0 1795 else if (*buf_ret == THE_KEY_ESCAPE)
1796 {
1797 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1798 if (!aCtx.IsNull()
1799 && Draw_ToCloseViewOnEsc)
1800 {
1801 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1802 }
1803 }
b514beda 1804 else
1805 {
1806 // Number
8c088c52 1807 const Standard_Integer aSelMode = Draw::Atoi(buf_ret);
1808 if (aSelMode >= 0 && aSelMode <= 7)
1809 {
1810 bool toEnable = true;
1811 if (const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext())
1812 {
1813 AIS_ListOfInteractive aPrsList;
1814 aCtx->DisplayedObjects (aPrsList);
1815 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
1816 {
1817 TColStd_ListOfInteger aModes;
1818 aCtx->ActivatedModes (aPrsIter.Value(), aModes);
1819 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
1820 {
1821 if (aModeIter.Value() == aSelMode)
1822 {
1823 toEnable = false;
1824 }
1825 }
1826 }
1827 }
1828 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
1829 Draw_Interprete (aCmd.ToCString());
1830 }
7fd59977 1831 }
1832}
1833
1834//==============================================================================
4fe56619 1835//function : VT_ProcessExpose
7fd59977 1836//purpose : Redraw the View on an Expose Event
1837//==============================================================================
4fe56619 1838void VT_ProcessExpose()
1839{
1840 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1841 if (!aView3d.IsNull())
1842 {
1843 aView3d->Redraw();
1844 }
7fd59977 1845}
1846
1847//==============================================================================
4fe56619 1848//function : VT_ProcessConfigure
7fd59977 1849//purpose : Resize the View on an Configure Event
1850//==============================================================================
4fe56619 1851void VT_ProcessConfigure()
7fd59977 1852{
4fe56619 1853 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1854 if (aView3d.IsNull())
1855 {
1856 return;
1857 }
1858
1859 aView3d->MustBeResized();
1860 aView3d->Update();
1861 aView3d->Redraw();
7fd59977 1862}
1863
1864//==============================================================================
4fe56619 1865//function : VT_ProcessButton1Press
7fd59977 1866//purpose : Picking
1867//==============================================================================
e79a94b9 1868Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1869 const char** theArgVec,
1870 Standard_Boolean theToPick,
1871 Standard_Boolean theIsShift)
7fd59977 1872{
1beb58d7 1873 if (TheIsAnimating)
1874 {
1875 TheIsAnimating = Standard_False;
1876 return Standard_False;
1877 }
1878
e79a94b9 1879 if (theToPick)
1880 {
7fd59977 1881 Standard_Real X, Y, Z;
e79a94b9 1882 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
7fd59977 1883
e79a94b9 1884 Draw::Set (theArgVec[1], X);
1885 Draw::Set (theArgVec[2], Y);
1886 Draw::Set (theArgVec[3], Z);
1887 }
7fd59977 1888
e79a94b9 1889 if (theIsShift)
1890 {
1891 ViewerTest::CurrentEventManager()->ShiftSelect();
1892 }
7fd59977 1893 else
e79a94b9 1894 {
1895 ViewerTest::CurrentEventManager()->Select();
1896 }
7fd59977 1897
e79a94b9 1898 return Standard_False;
7fd59977 1899}
1900
1901//==============================================================================
4fe56619 1902//function : VT_ProcessButton1Release
1903//purpose : End selecting
7fd59977 1904//==============================================================================
4fe56619 1905void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1906{
1907 if (IsDragged)
1908 {
1909 IsDragged = Standard_False;
1910 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1911 if (theIsShift)
1912 {
2157d6ac 1913 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1914 X_Motion, Y_Motion);
4fe56619 1915 }
1916 else
1917 {
2157d6ac 1918 EM->Select (X_ButtonPress, Y_ButtonPress,
1919 X_Motion, Y_Motion);
4fe56619 1920 }
1921 }
1922}
7fd59977 1923
4fe56619 1924//==============================================================================
1925//function : VT_ProcessButton3Press
1926//purpose : Start Rotation
1927//==============================================================================
1928void VT_ProcessButton3Press()
1929{
2e93433e 1930 if (ViewerTest_V3dView::IsCurrentViewIn2DMode())
1931 {
1932 return;
1933 }
1934
7fd59977 1935 Start_Rot = 1;
1eeef710 1936 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1937 if (HasHlrOnBeforeRotation)
de75ed09 1938 {
1939 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1940 }
7fd59977 1941 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
7fd59977 1942}
4fe56619 1943
7fd59977 1944//==============================================================================
4fe56619 1945//function : VT_ProcessButton3Release
1946//purpose : End rotation
7fd59977 1947//==============================================================================
4fe56619 1948void VT_ProcessButton3Release()
1949{
1950 if (Start_Rot)
1951 {
7fd59977 1952 Start_Rot = 0;
1eeef710 1953 if (HasHlrOnBeforeRotation)
de75ed09 1954 {
1eeef710 1955 HasHlrOnBeforeRotation = Standard_False;
de75ed09 1956 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1eeef710 1957 ViewerTest::CurrentView()->Redraw();
de75ed09 1958 }
7fd59977 1959 }
7fd59977 1960}
1961
7fd59977 1962//==============================================================================
1963//function : ProcessControlButton1Motion
1964//purpose : Zoom
1965//==============================================================================
1966
900f7229 1967#if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 1968static void ProcessControlButton1Motion()
1969{
1970 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1971
1972 X_ButtonPress = X_Motion;
1973 Y_ButtonPress = Y_Motion;
1974}
900f7229 1975#endif
7fd59977 1976
1977//==============================================================================
4fe56619 1978//function : VT_ProcessControlButton2Motion
1979//purpose : Panning
7fd59977 1980//==============================================================================
4fe56619 1981void VT_ProcessControlButton2Motion()
7fd59977 1982{
197ac94e 1983 Standard_Integer aDx = X_Motion - X_ButtonPress;
1984 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
7fd59977 1985
197ac94e 1986 aDy = -aDy; // Xwindow Y axis is from top to Bottom
7fd59977 1987
197ac94e 1988 ViewerTest::CurrentView()->Pan (aDx, aDy);
7fd59977 1989
1990 X_ButtonPress = X_Motion;
1991 Y_ButtonPress = Y_Motion;
1992}
1993
1994//==============================================================================
4fe56619 1995//function : VT_ProcessControlButton3Motion
7fd59977 1996//purpose : Rotation
1997//==============================================================================
4fe56619 1998void VT_ProcessControlButton3Motion()
7fd59977 1999{
4fe56619 2000 if (Start_Rot)
2001 {
2002 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
2003 }
7fd59977 2004}
2005
2006//==============================================================================
4fe56619 2007//function : VT_ProcessMotion
2008//purpose :
7fd59977 2009//==============================================================================
4fe56619 2010void VT_ProcessMotion()
7fd59977 2011{
2012 //pre-hilights detected objects at mouse position
2013
2014 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
2015 EM->MoveTo(X_Motion, Y_Motion);
2016}
2017
2018
2019void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
2020{
2021 Xpix = X_Motion;Ypix=Y_Motion;
2022}
2023
44b8f2d6 2024//==============================================================================
2025//function : ViewProject: implements VAxo, VTop, VLeft, ...
2026//purpose : Switches to an axonometric, top, left and other views
2027//==============================================================================
2028
2029static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
2030{
4fe56619 2031 if ( ViewerTest::CurrentView().IsNull() )
44b8f2d6 2032 {
586db386 2033 di<<"Call vinit before this command, please\n";
44b8f2d6 2034 return 1;
2035 }
2036
2037 ViewerTest::CurrentView()->SetProj(ori);
2038 return 0;
2039}
2040
7fd59977 2041//==============================================================================
2042//function : VAxo
2043//purpose : Switch to an Axonometric view
2044//Draw arg : No args
2045//==============================================================================
2046
2047static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
44b8f2d6 2048{
2049 return ViewProject(di, V3d_XposYnegZpos);
7fd59977 2050}
2051
2052//==============================================================================
2053//function : VTop
2054//purpose : Switch to a Top View
2055//Draw arg : No args
2056//==============================================================================
2057
2058static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
2059{
44b8f2d6 2060 return ViewProject(di, V3d_Zpos);
2061}
7fd59977 2062
44b8f2d6 2063//==============================================================================
2064//function : VBottom
2065//purpose : Switch to a Bottom View
2066//Draw arg : No args
2067//==============================================================================
7fd59977 2068
44b8f2d6 2069static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
2070{
2071 return ViewProject(di, V3d_Zneg);
2072}
7fd59977 2073
44b8f2d6 2074//==============================================================================
2075//function : VLeft
2076//purpose : Switch to a Left View
2077//Draw arg : No args
2078//==============================================================================
2079
2080static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
2081{
27af3052 2082 return ViewProject(di, V3d_Xneg);
44b8f2d6 2083}
2084
2085//==============================================================================
2086//function : VRight
2087//purpose : Switch to a Right View
2088//Draw arg : No args
2089//==============================================================================
2090
2091static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
2092{
27af3052 2093 return ViewProject(di, V3d_Xpos);
44b8f2d6 2094}
7fd59977 2095
44b8f2d6 2096//==============================================================================
2097//function : VFront
2098//purpose : Switch to a Front View
2099//Draw arg : No args
2100//==============================================================================
2101
2102static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
2103{
27af3052 2104 return ViewProject(di, V3d_Yneg);
44b8f2d6 2105}
2106
2107//==============================================================================
2108//function : VBack
2109//purpose : Switch to a Back View
2110//Draw arg : No args
2111//==============================================================================
2112
2113static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
2114{
27af3052 2115 return ViewProject(di, V3d_Ypos);
7fd59977 2116}
2117
2118//==============================================================================
2119//function : VHelp
2120//purpose : Dsiplay help on viewer Keyboead and mouse commands
2121//Draw arg : No args
2122//==============================================================================
2123
2124static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2125{
2126
586db386 2127 di << "Q : Quit the application\n";
2128
2129 di << "=========================\n";
2130 di << "F : FitAll\n";
2131 di << "T : TopView\n";
2132 di << "B : BottomView\n";
2133 di << "R : RightView\n";
2134 di << "L : LeftView\n";
2135 di << "A : AxonometricView\n";
2136 di << "D : ResetView\n";
2137
2138 di << "=========================\n";
2139 di << "S : Shading\n";
2140 di << "W : Wireframe\n";
2141 di << "H : HidelLineRemoval\n";
2142 di << "U : Unset display mode\n";
2143 di << "Delete : Remove selection from viewer\n";
2144
2145 di << "=========================\n";
2146 di << "Selection mode \n";
2147 di << "0 : Shape\n";
2148 di << "1 : Vertex\n";
2149 di << "2 : Edge\n";
2150 di << "3 : Wire\n";
2151 di << "4 : Face\n";
2152 di << "5 : Shell\n";
2153 di << "6 : Solid\n";
2154 di << "7 : Compound\n";
2155
2156 di << "=========================\n";
2157 di << "Z : Switch Z clipping On/Off\n";
2158 di << ", : Hilight next detected\n";
2159 di << ". : Hilight previous detected\n";
7fd59977 2160
2161 return 0;
2162}
2163
57c28b61 2164#ifdef _WIN32
7fd59977 2165
2166static Standard_Boolean Ppick = 0;
2167static Standard_Integer Pargc = 0;
2168static const char** Pargv = NULL;
2169
2170
2171static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2172 UINT Msg,
2173 WPARAM wParam,
2174 LPARAM lParam )
2175{
18d715bd 2176 if (!ViewerTest_myViews.IsEmpty()) {
7fd59977 2177
2178 WPARAM fwKeys = wParam;
2179
2180 switch( Msg ) {
18d715bd 2181 case WM_CLOSE:
2182 {
2183 // Delete view from map of views
2184 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2185 return 0;
2186 }
2187 break;
2188 case WM_ACTIVATE:
2189 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2190 || ViewerTest::CurrentView().IsNull())
2191 {
2192 // Activate inactive window
2193 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2194 {
2195 ActivateView (FindViewIdByWindowHandle(hwnd));
2196 }
2197 }
2198 break;
625e1958 2199
7fd59977 2200 case WM_LBUTTONUP:
625e1958 2201 if (IsDragged && !DragFirst)
7fd59977 2202 {
625e1958 2203 if (!GetActiveAISManipulator().IsNull())
2204 {
2205 GetActiveAISManipulator()->StopTransform();
0577ae8c 2206 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
625e1958 2207 }
2208
b12e1c7b 2209 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2210 {
2211 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2212 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2213 }
2214
dde68833 2215 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
7fd59977 2216 }
8abada55 2217 IsDragged = Standard_False;
7fd59977 2218 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2219
625e1958 2220 case WM_RBUTTONUP:
2221 if (IsDragged && !DragFirst)
2222 {
2223 if (!GetActiveAISManipulator().IsNull())
2224 {
2225 GetActiveAISManipulator()->StopTransform (Standard_False);
0577ae8c 2226 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
625e1958 2227 }
2228 IsDragged = Standard_False;
2229 }
2230 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2231
7fd59977 2232 case WM_LBUTTONDOWN:
625e1958 2233 if (!GetActiveAISManipulator().IsNull())
2234 {
2235 IsDragged = ( fwKeys == MK_LBUTTON );
2236 }
2237 else
2238 {
2239 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2240 }
2241
2242 if (IsDragged)
7fd59977 2243 {
7fd59977 2244 DragFirst = Standard_True;
4fe56619 2245 X_ButtonPress = LOWORD(lParam);
2246 Y_ButtonPress = HIWORD(lParam);
7fd59977 2247 }
2248 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2249
7fd59977 2250 case WM_MOUSEMOVE:
b12e1c7b 2251 if (IsDragged)
7fd59977 2252 {
b12e1c7b 2253 X_Motion = LOWORD (lParam);
2254 Y_Motion = HIWORD (lParam);
625e1958 2255 if (!GetActiveAISManipulator().IsNull())
b12e1c7b 2256 {
625e1958 2257 if (DragFirst)
2258 {
2259 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2260 }
2261 else
2262 {
2263 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2264 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2265 }
69adb9ce 2266 }
625e1958 2267 else
69adb9ce 2268 {
625e1958 2269 bool toRedraw = false;
2270 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2271 {
2272 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2273 toRedraw = true;
2274 }
2275
2276 RECT aRect;
2277 if (GetClientRect (hwnd, &aRect))
2278 {
2279 int aHeight = aRect.bottom - aRect.top;
2280 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
68dcee02 2281 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
625e1958 2282 toRedraw = true;
2283 }
2284 if (toRedraw)
2285 {
2286 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2287 }
b12e1c7b 2288 }
625e1958 2289
2290 DragFirst = Standard_False;
7fd59977 2291 }
2292 else
2293 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2294 break;
2295
2296 default:
2297 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2298 }
2299 return 0;
2300 }
2301 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2302}
2303
2304
2305static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2306 UINT Msg,
2307 WPARAM wParam,
2308 LPARAM lParam )
2309{
7fd59977 2310 static int Up = 1;
f978241f 2311 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2312 if (aView.IsNull())
2313 {
ad03c234 2314 return DefWindowProcW (hwnd, Msg, wParam, lParam);
f978241f 2315 }
7fd59977 2316
7fd59977 2317 PAINTSTRUCT ps;
2318
2319 switch( Msg ) {
7fd59977 2320 case WM_PAINT:
7fd59977 2321 BeginPaint(hwnd, &ps);
2322 EndPaint(hwnd, &ps);
4fe56619 2323 VT_ProcessExpose();
7fd59977 2324 break;
2325
2326 case WM_SIZE:
4fe56619 2327 VT_ProcessConfigure();
7fd59977 2328 break;
f978241f 2329 case WM_MOVE:
2330 case WM_MOVING:
2331 case WM_SIZING:
2332 switch (aView->RenderingParams().StereoMode)
2333 {
2334 case Graphic3d_StereoMode_RowInterlaced:
2335 case Graphic3d_StereoMode_ColumnInterlaced:
2336 case Graphic3d_StereoMode_ChessBoard:
2337 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2338 break;
2339 default:
2340 break;
2341 }
2342 break;
7fd59977 2343
2344 case WM_KEYDOWN:
4fe56619 2345 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2346 {
7fd59977 2347 char c[2];
2348 c[0] = (char) wParam;
2349 c[1] = '\0';
b514beda 2350 if (wParam == VK_DELETE)
2351 {
2352 c[0] = THE_KEY_DELETE;
2353 }
fd3f6bd0 2354 else if (wParam == VK_ESCAPE)
2355 {
2356 c[0] = THE_KEY_ESCAPE;
2357 }
4ca4bbe8 2358 // comma
2359 else if (wParam == VK_OEM_COMMA)
2360 {
2361 c[0] = ',';
2362 }
2363 // dot
2364 else if (wParam == VK_OEM_PERIOD)
2365 {
2366 c[0] = '.';
2367 }
f978241f 2368 else if (wParam == VK_DIVIDE)
2369 {
2370 c[0] = '/';
2371 }
2372 // dot
2373 else if (wParam == VK_MULTIPLY)
2374 {
2375 c[0] = '*';
2376 }
4fe56619 2377 VT_ProcessKeyPress (c);
7fd59977 2378 }
2379 break;
2380
2381 case WM_LBUTTONUP:
2382 case WM_MBUTTONUP:
2383 case WM_RBUTTONUP:
7fd59977 2384 Up = 1;
4fe56619 2385 VT_ProcessButton3Release();
7fd59977 2386 break;
2387
2388 case WM_LBUTTONDOWN:
2389 case WM_MBUTTONDOWN:
2390 case WM_RBUTTONDOWN:
2391 {
7fd59977 2392 WPARAM fwKeys = wParam;
2393
2394 Up = 0;
2395
2396 X_ButtonPress = LOWORD(lParam);
2397 Y_ButtonPress = HIWORD(lParam);
2398
4fe56619 2399 if (Msg == WM_LBUTTONDOWN)
2400 {
dde68833 2401 if ((fwKeys & MK_CONTROL) != 0)
4fe56619 2402 {
dde68833 2403 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
4fe56619 2404 }
2405 else
2406 {
dde68833 2407 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
4fe56619 2408 }
7fd59977 2409 }
4fe56619 2410 else if (Msg == WM_RBUTTONDOWN)
2411 {
7fd59977 2412 // Start rotation
4fe56619 2413 VT_ProcessButton3Press();
7fd59977 2414 }
2415 }
2416 break;
2417
f978241f 2418 case WM_MOUSEWHEEL:
2419 {
2420 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2421 if (wParam & MK_CONTROL)
2422 {
2423 if (aView->Camera()->IsStereo())
2424 {
2425 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2426 if (aFocus > 0.2
2427 && aFocus < 2.0)
2428 {
2429 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2430 aView->Redraw();
2431 }
2432 }
2433 }
2434 else
2435 {
2436 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2437 }
2438 break;
2439 }
2440
7fd59977 2441 case WM_MOUSEMOVE:
2442 {
2443 //cout << "\t WM_MOUSEMOVE" << endl;
2444 WPARAM fwKeys = wParam;
2445 X_Motion = LOWORD(lParam);
2446 Y_Motion = HIWORD(lParam);
2447
2448 if ( Up &&
dde68833 2449 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2450 {
7fd59977 2451 Up = 0;
2452 X_ButtonPress = LOWORD(lParam);
2453 Y_ButtonPress = HIWORD(lParam);
2454
dde68833 2455 if ((fwKeys & MK_RBUTTON) != 0) {
7fd59977 2456 // Start rotation
4fe56619 2457 VT_ProcessButton3Press();
7fd59977 2458 }
2459 }
2460
dde68833 2461 if ((fwKeys & MK_CONTROL) != 0)
2462 {
2463 if ((fwKeys & MK_LBUTTON) != 0)
2464 {
7fd59977 2465 ProcessControlButton1Motion();
2466 }
dde68833 2467 else if ((fwKeys & MK_MBUTTON) != 0
2468 || ((fwKeys & MK_LBUTTON) != 0
2469 && (fwKeys & MK_RBUTTON) != 0))
2470 {
2471 VT_ProcessControlButton2Motion();
2472 }
2473 else if ((fwKeys & MK_RBUTTON) != 0)
2474 {
4fe56619 2475 VT_ProcessControlButton3Motion();
7fd59977 2476 }
2477 }
08398024 2478 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2479 {
89a929ea 2480 VT_ProcessMotion();
08398024 2481 }
7fd59977 2482 }
2483 break;
2484
2485 default:
ad03c234 2486 return DefWindowProcW (hwnd, Msg, wParam, lParam);
7fd59977 2487 }
2488 return 0L;
7fd59977 2489}
2490
7fd59977 2491//==============================================================================
2492//function : ViewerMainLoop
2493//purpose : Get a Event on the view and dispatch it
2494//==============================================================================
2495
2496
8263fcd3 2497int ViewerMainLoop(Standard_Integer argc, const char** argv)
7fd59977 2498{
7fd59977 2499 Ppick = (argc > 0)? 1 : 0;
2500 Pargc = argc;
2501 Pargv = argv;
2502
2503 if ( Ppick ) {
2504 MSG msg;
2505 msg.wParam = 1;
2506
2507 cout << "Start picking" << endl;
2508
7fd59977 2509 while ( Ppick == 1 ) {
4fe56619 2510 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
ad03c234 2511 if (GetMessageW (&msg, NULL, 0, 0))
2512 {
2513 TranslateMessage (&msg);
2514 DispatchMessageW (&msg);
7fd59977 2515 }
2516 }
2517
2518 cout << "Picking done" << endl;
2519 }
2520
2521 return Ppick;
2522}
2523
4fe56619 2524#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 2525
2526int min( int a, int b )
2527{
2528 if( a<b )
2529 return a;
2530 else
2531 return b;
2532}
2533
2534int max( int a, int b )
2535{
2536 if( a>b )
2537 return a;
2538 else
2539 return b;
2540}
2541
2542int ViewerMainLoop(Standard_Integer argc, const char** argv)
2543
4269bd1b 2544{
18d715bd 2545 static XEvent aReport;
2546 Standard_Boolean pick = argc > 0;
2547 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2548 XNextEvent (aDisplay, &aReport);
7fd59977 2549
18d715bd 2550 // Handle event for the chosen display connection
2551 switch (aReport.type) {
2552 case ClientMessage:
2553 {
eb1ebea4 2554 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
18d715bd 2555 {
2556 // Close the window
2557 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2558 }
2559 }
2560 return 0;
2561 case FocusIn:
2562 {
2563 // Activate inactive view
2564 Window aWindow = GetWindowHandle(VT_GetWindow());
2565 if(aWindow != aReport.xfocus.window)
2566 {
2567 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2568 }
2569 }
2570 break;
7fd59977 2571 case Expose:
2572 {
4fe56619 2573 VT_ProcessExpose();
7fd59977 2574 }
2575 break;
2576 case ConfigureNotify:
2577 {
4fe56619 2578 VT_ProcessConfigure();
7fd59977 2579 }
2580 break;
2581 case KeyPress:
2582 {
2583
2584 KeySym ks_ret ;
2585 char buf_ret[11] ;
2586 int ret_len ;
2587 XComposeStatus status_in_out;
2588
18d715bd 2589 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
7fd59977 2590 (char *) buf_ret , 10 ,
2591 &ks_ret , &status_in_out ) ;
2592
2593
2594 buf_ret[ret_len] = '\0' ;
2595
4fe56619 2596 if (ret_len)
2597 {
2598 VT_ProcessKeyPress (buf_ret);
7fd59977 2599 }
2600 }
2601 break;
2602 case ButtonPress:
7fd59977 2603 {
18d715bd 2604 X_ButtonPress = aReport.xbutton.x;
2605 Y_ButtonPress = aReport.xbutton.y;
7fd59977 2606
18d715bd 2607 if (aReport.xbutton.button == Button1)
4fe56619 2608 {
18d715bd 2609 if (aReport.xbutton.state & ControlMask)
4fe56619 2610 {
18d715bd 2611 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
4fe56619 2612 }
7fd59977 2613 else
2614 {
2615 IsDragged = Standard_True;
7fd59977 2616 DragFirst = Standard_True;
2617 }
4fe56619 2618 }
18d715bd 2619 else if (aReport.xbutton.button == Button3)
4fe56619 2620 {
7fd59977 2621 // Start rotation
4fe56619 2622 VT_ProcessButton3Press();
2623 }
7fd59977 2624 }
2625 break;
2626 case ButtonRelease:
2627 {
7fd59977 2628 if( IsDragged )
2629 {
2630 if( !DragFirst )
2631 {
b12e1c7b 2632 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2633 {
2634 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2635 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2636 }
7fd59977 2637 }
2638
2639 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2640 if( aContext.IsNull() )
2641 {
2642 cout << "The context is null. Please use vinit before createmesh" << endl;
2643 return 0;
2644 }
2645
18d715bd 2646 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2647 if( aReport.xbutton.button==1 )
7fd59977 2648 if( DragFirst )
2649 if( ShiftPressed )
2650 {
0577ae8c 2651 aContext->ShiftSelect (Standard_True);
7fd59977 2652 }
2653 else
2654 {
0577ae8c 2655 aContext->Select (Standard_True);
7fd59977 2656 }
2657 else
2658 if( ShiftPressed )
2659 {
0577ae8c 2660 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2661 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2662 ViewerTest::CurrentView(), Standard_True);
7fd59977 2663 }
2664 else
2665 {
0577ae8c 2666 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2667 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2668 ViewerTest::CurrentView(), Standard_True);
7fd59977 2669 }
2670 else
4fe56619 2671 VT_ProcessButton3Release();
7fd59977 2672
2673 IsDragged = Standard_False;
2674 }
2675 else
4fe56619 2676 VT_ProcessButton3Release();
7fd59977 2677 }
2678 break;
2679 case MotionNotify:
2680 {
08398024 2681 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2682 {
2683 break;
2684 }
7fd59977 2685 if( IsDragged )
2686 {
7fd59977 2687 if( !DragFirst )
b12e1c7b 2688 {
2689 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2690 {
2691 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
b12e1c7b 2692 }
2693 }
7fd59977 2694
18d715bd 2695 X_Motion = aReport.xmotion.x;
2696 Y_Motion = aReport.xmotion.y;
7fd59977 2697 DragFirst = Standard_False;
2698
b12e1c7b 2699 Window aWindow = GetWindowHandle(VT_GetWindow());
2700 Window aRoot;
2701 int anX, anY;
2702 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2703 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2704 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
68dcee02 2705 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
b12e1c7b 2706 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
7fd59977 2707 }
2708 else
2709 {
18d715bd 2710 X_Motion = aReport.xmotion.x;
2711 Y_Motion = aReport.xmotion.y;
7fd59977 2712
18d715bd 2713 // remove all the ButtonMotionMaskr
2714 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
7fd59977 2715
18d715bd 2716 if ( aReport.xmotion.state & ControlMask ) {
2717 if ( aReport.xmotion.state & Button1Mask ) {
7fd59977 2718 ProcessControlButton1Motion();
2719 }
18d715bd 2720 else if ( aReport.xmotion.state & Button2Mask ) {
4fe56619 2721 VT_ProcessControlButton2Motion();
7fd59977 2722 }
18d715bd 2723 else if ( aReport.xmotion.state & Button3Mask ) {
4fe56619 2724 VT_ProcessControlButton3Motion();
7fd59977 2725 }
2726 }
4fe56619 2727 else
2728 {
2729 VT_ProcessMotion();
7fd59977 2730 }
2731 }
2732 }
2733 break;
2734}
7fd59977 2735return pick;
2736}
2737
2738//==============================================================================
2739//function : VProcessEvents
2740//purpose : call by Tk_CreateFileHandler() to be able to manage the
2741// event in the Viewer window
2742//==============================================================================
2743
2744static void VProcessEvents(ClientData,int)
2745{
18d715bd 2746 NCollection_Vector<int> anEventNumbers;
2747 // Get number of messages from every display
2748 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2749 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2750 {
2751 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
4269bd1b 2752 }
18d715bd 2753 // Handle events for every display
2754 int anEventIter = 0;
2755 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2756 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2757 {
4269bd1b 2758 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
18d715bd 2759 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2760 {
2761 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2762 int anEventResult = ViewerMainLoop( 0, NULL);
2763 // If window is closed or context was not found finish current event processing loop
2764 if (!anEventResult)
2765 return;
2766 }
7fd59977 2767 }
4269bd1b 2768
18d715bd 2769 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
4269bd1b 2770
7fd59977 2771}
2772#endif
2773
2774//==============================================================================
2775//function : OSWindowSetup
2776//purpose : Setup for the X11 window to be able to cath the event
2777//==============================================================================
2778
2779
2780static void OSWindowSetup()
2781{
4fe56619 2782#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2783 // X11
2784
2785 Window window = VT_GetWindow()->XWindow();
18d715bd 2786 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2787 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2788 XSynchronize(aDisplay, 1);
7fd59977 2789
2790 // X11 : For keyboard on SUN
2791 XWMHints wmhints;
2792 wmhints.flags = InputHint;
2793 wmhints.input = 1;
2794
18d715bd 2795 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 2796
18d715bd 2797 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
7fd59977 2798 ButtonPressMask | ButtonReleaseMask |
2799 StructureNotifyMask |
2800 PointerMotionMask |
2801 Button1MotionMask | Button2MotionMask |
18d715bd 2802 Button3MotionMask | FocusChangeMask
7fd59977 2803 );
18d715bd 2804 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2805 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 2806
18d715bd 2807 XSynchronize(aDisplay, 0);
7fd59977 2808
2809#else
57c28b61 2810 // _WIN32
7fd59977 2811#endif
2812
2813}
2814
7fd59977 2815//==============================================================================
2816//function : VFit
1beb58d7 2817//purpose :
7fd59977 2818//==============================================================================
2819
1beb58d7 2820static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
7fd59977 2821{
1beb58d7 2822 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2823 if (aView.IsNull())
b586500b 2824 {
1beb58d7 2825 std::cout << "Error: no active viewer!\n";
2826 return 1;
b586500b 2827 }
2828
1beb58d7 2829 Standard_Boolean toFit = Standard_True;
2830 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2831 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
b586500b 2832 {
1beb58d7 2833 TCollection_AsciiString anArg (theArgv[anArgIter]);
b586500b 2834 anArg.LowerCase();
1beb58d7 2835 if (anUpdateTool.parseRedrawMode (anArg))
b586500b 2836 {
1beb58d7 2837 continue;
2838 }
2839 else if (anArg == "-selected")
2840 {
2841 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2842 toFit = Standard_False;
2843 }
2844 else
2845 {
2846 std::cout << "Syntax error at '" << anArg << "'\n";
b586500b 2847 }
2848 }
2849
1beb58d7 2850 if (toFit)
2851 {
2852 aView->FitAll (0.01, Standard_False);
7fd59977 2853 }
2854 return 0;
2855}
2856
6262a303 2857//=======================================================================
2858//function : VFitArea
2859//purpose : Fit view to show area located between two points
2860// : given in world 2D or 3D coordinates.
2861//=======================================================================
2862static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2863{
2864 Handle(V3d_View) aView = ViewerTest::CurrentView();
2865 if (aView.IsNull())
2866 {
2867 std::cerr << theArgVec[0] << "Error: No active view.\n";
2868 return 1;
2869 }
2870
2871 // Parse arguments.
2872 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2873 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2874
2875 if (theArgNb == 5)
2876 {
2877 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2878 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2879 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2880 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2881 }
2882 else if (theArgNb == 7)
2883 {
2884 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2885 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2886 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2887 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2888 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2889 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2890 }
2891 else
2892 {
2893 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2894 theDI.PrintHelp(theArgVec[0]);
2895 return 1;
2896 }
2897
2898 // Convert model coordinates to view space
2899 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2900 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2901 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2902
2903 // Determine fit area
2904 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2905 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2906
2907 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2908
2909 if (aDiagonal < Precision::Confusion())
2910 {
2911 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2912 return 1;
2913 }
2914
2915 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2916 return 0;
2917}
2918
7fd59977 2919//==============================================================================
2920//function : VZFit
2921//purpose : ZFitall, no DRAW arguments
2922//Draw arg : No args
2923//==============================================================================
197ac94e 2924static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 2925{
197ac94e 2926 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2927
2928 if (aCurrentView.IsNull())
2929 {
2930 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2931 return 1;
2932 }
2933
2934 if (theArgsNb == 1)
2935 {
c357e426 2936 aCurrentView->ZFitAll();
197ac94e 2937 aCurrentView->Redraw();
2938 return 0;
2939 }
2940
2941 Standard_Real aScale = 1.0;
2942
2943 if (theArgsNb >= 2)
2944 {
2945 aScale = Draw::Atoi (theArgVec[1]);
2946 }
2947
c357e426 2948 aCurrentView->ZFitAll (aScale);
197ac94e 2949 aCurrentView->Redraw();
7fd59977 2950
197ac94e 2951 return 0;
2952}
7fd59977 2953
197ac94e 2954//==============================================================================
2955//function : VRepaint
2956//purpose :
2957//==============================================================================
56689b27 2958static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
7fd59977 2959{
56689b27 2960 Handle(V3d_View) aView = ViewerTest::CurrentView();
2961 if (aView.IsNull())
2962 {
2963 std::cout << "Error: no active viewer!\n";
2964 return 1;
2965 }
2966
2967 Standard_Boolean isImmediateUpdate = Standard_False;
2968 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2969 {
2970 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2971 anArg.LowerCase();
2972 if (anArg == "-immediate")
2973 {
2974 isImmediateUpdate = Standard_True;
2975 if (anArgIter + 1 < theArgNb
2976 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2977 {
2978 ++anArgIter;
2979 }
2980 }
2981 else
2982 {
2983 std::cout << "Syntax error at '" << anArg << "'\n";
2984 }
2985 }
2986
2987 if (isImmediateUpdate)
2988 {
2989 aView->RedrawImmediate();
2990 }
2991 else
2992 {
2993 aView->Redraw();
2994 }
2995 return 0;
7fd59977 2996}
2997
7fd59977 2998//==============================================================================
2999//function : VClear
3000//purpose : Remove all the object from the viewer
3001//Draw arg : No args
3002//==============================================================================
3003
3004static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3005{
3006 Handle(V3d_View) V = ViewerTest::CurrentView();
3007 if(!V.IsNull())
3008 ViewerTest::Clear();
3009 return 0;
3010}
3011
3012//==============================================================================
3013//function : VPick
3014//purpose :
3015//==============================================================================
3016
3017static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3018{ if (ViewerTest::CurrentView().IsNull() ) return 1;
3019
3020if ( argc < 4 ) {
586db386 3021 di << argv[0] << "Invalid number of arguments\n";
7fd59977 3022 return 1;
3023}
3024
3025while (ViewerMainLoop( argc, argv)) {
3026}
3027
3028return 0;
3029}
3030
7fd59977 3031//==============================================================================
3032//function : VSetBg
3033//purpose : Load image as background
3034//==============================================================================
3035
3036static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3037{
3038 if (argc < 2 || argc > 3)
3039 {
586db386 3040 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
3041 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
7fd59977 3042 return 1;
3043 }
3044
3045 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3046 if(AISContext.IsNull())
3047 {
3048 di << "use 'vinit' command before " << argv[0] << "\n";
3049 return 1;
3050 }
3051
3052 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
3053 if (argc == 3)
3054 {
3055 const char* szType = argv[2];
3056 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3057 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3058 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3059 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3060 else
3061 {
3062 di << "Wrong fill type : " << szType << "\n";
586db386 3063 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
7fd59977 3064 return 1;
3065 }
3066 }
3067
3068 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3069 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
3070
3071 return 0;
3072}
3073
f8b2ed36 3074//==============================================================================
3075//function : VSetBgMode
3076//purpose : Change background image fill type
3077//==============================================================================
3078
3079static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3080{
3081 if (argc != 2)
3082 {
586db386 3083 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
3084 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
f8b2ed36 3085 return 1;
3086 }
3087
3088 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3089 if(AISContext.IsNull())
3090 {
3091 di << "use 'vinit' command before " << argv[0] << "\n";
3092 return 1;
3093 }
1d47d8d0 3094 Aspect_FillMethod aFillType = Aspect_FM_NONE;
3095 const char* szType = argv[1];
3096 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3097 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3098 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3099 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3100 else
f8b2ed36 3101 {
1d47d8d0 3102 di << "Wrong fill type : " << szType << "\n";
586db386 3103 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
1d47d8d0 3104 return 1;
f8b2ed36 3105 }
f8b2ed36 3106 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3107 V3dView->SetBgImageStyle(aFillType, Standard_True);
f8b2ed36 3108 return 0;
3109}
3110
7fd59977 3111//==============================================================================
3112//function : VSetGradientBg
3113//purpose : Mount gradient background
3114//==============================================================================
3115static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3116{
3117 if (argc != 8 )
3118 {
586db386 3119 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
3120 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
3121 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3122 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
7fd59977 3123 return 1;
3124 }
3125
3126 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3127 if(AISContext.IsNull())
3128 {
3129 di << "use 'vinit' command before " << argv[0] << "\n";
3130 return 1;
3131 }
3132 if (argc == 8)
3133 {
3134
91322f44 3135 Standard_Real R1 = Draw::Atof(argv[1])/255.;
3136 Standard_Real G1 = Draw::Atof(argv[2])/255.;
3137 Standard_Real B1 = Draw::Atof(argv[3])/255.;
7fd59977 3138 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
3139
91322f44 3140 Standard_Real R2 = Draw::Atof(argv[4])/255.;
3141 Standard_Real G2 = Draw::Atof(argv[5])/255.;
3142 Standard_Real B2 = Draw::Atof(argv[6])/255.;
7fd59977 3143
3144 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
91322f44 3145 int aType = Draw::Atoi(argv[7]);
7fd59977 3146 if( aType < 0 || aType > 8 )
3147 {
586db386 3148 di << "Wrong fill type \n";
3149 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3150 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
7fd59977 3151 return 1;
3152 }
3153
3154 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3155
3156 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3157 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
3158 }
3159
3160 return 0;
3161}
3162
f8b2ed36 3163//==============================================================================
3164//function : VSetGradientBgMode
3165//purpose : Change gradient background fill style
3166//==============================================================================
3167static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3168{
3169 if (argc != 2 )
3170 {
586db386 3171 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
3172 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3173 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
f8b2ed36 3174 return 1;
3175 }
3176
3177 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3178 if(AISContext.IsNull())
3179 {
3180 di << "use 'vinit' command before " << argv[0] << "\n";
3181 return 1;
3182 }
3183 if (argc == 2)
3184 {
91322f44 3185 int aType = Draw::Atoi(argv[1]);
f8b2ed36 3186 if( aType < 0 || aType > 8 )
3187 {
586db386 3188 di << "Wrong fill type \n";
3189 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3190 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
f8b2ed36 3191 return 1;
3192 }
3193
3194 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3195
3196 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3197 V3dView->SetBgGradientStyle( aMethod, 1 );
3198 }
3199
3200 return 0;
3201}
3202
3203//==============================================================================
3204//function : VSetColorBg
3205//purpose : Set color background
3206//==============================================================================
3207static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3208{
3209 if (argc != 4 )
3210 {
586db386 3211 di << "Usage : " << argv[0] << " R G B : Set color background\n";
3212 di << "R,G,B = [0..255]\n";
f8b2ed36 3213 return 1;
3214 }
3215
3216 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3217 if(AISContext.IsNull())
3218 {
3219 di << "use 'vinit' command before " << argv[0] << "\n";
3220 return 1;
3221 }
3222 if (argc == 4)
3223 {
3224
91322f44 3225 Standard_Real R = Draw::Atof(argv[1])/255.;
3226 Standard_Real G = Draw::Atof(argv[2])/255.;
3227 Standard_Real B = Draw::Atof(argv[3])/255.;
f8b2ed36 3228 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
3229
3230 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3231 V3dView->SetBackgroundColor( aColor );
3232 V3dView->Update();
3233 }
3234
3235 return 0;
3236}
3237
f42753ed 3238//==============================================================================
3239//function : VSetDefaultBg
3240//purpose : Set default viewer background fill color
3241//==============================================================================
3242static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3243{
3244 if (theArgNb != 4
3245 && theArgNb != 8)
3246 {
3247 std::cout << "Error: wrong syntax! See usage:\n";
3248 theDI.PrintHelp (theArgVec[0]);
3249 return 1;
3250 }
3251
3252 ViewerTest_DefaultBackground.FillMethod =
3253 theArgNb == 4 ? Aspect_GFM_NONE
3254 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
3255
3256 if (theArgNb == 4)
3257 {
3258 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
3259 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
3260 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
3261 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
3262 }
3263 else
3264 {
3265 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
3266 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
3267 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
3268 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
3269
3270 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
3271 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
3272 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
3273 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
3274 }
3275
3276 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
3277 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
3278 {
3279 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
3280 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
3281 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
3282 ViewerTest_DefaultBackground.GradientColor2,
3283 ViewerTest_DefaultBackground.FillMethod);
3284 }
3285
3286 return 0;
3287}
3288
7fd59977 3289//==============================================================================
3290//function : VScale
3291//purpose : View Scaling
3292//==============================================================================
3293
3294static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3295{
3296 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3297 if ( V3dView.IsNull() ) return 1;
3298
3299 if ( argc != 4 ) {
586db386 3300 di << argv[0] << "Invalid number of arguments\n";
7fd59977 3301 return 1;
3302 }
91322f44 3303 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
7fd59977 3304 return 0;
3305}
3306//==============================================================================
536d98e2 3307//function : VZBuffTrihedron
3308//purpose :
7fd59977 3309//==============================================================================
3310
536d98e2 3311static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3312 Standard_Integer theArgNb,
3313 const char** theArgVec)
7fd59977 3314{
536d98e2 3315 Handle(V3d_View) aView = ViewerTest::CurrentView();
3316 if (aView.IsNull())
3317 {
3318 std::cout << "Error: no active viewer!\n";
3319 return 1;
3320 }
7fd59977 3321
536d98e2 3322 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7c8a8fcc 3323
536d98e2 3324 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3325 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3326 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3327 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3328 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3329 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3330 Standard_Real aScale = 0.1;
3331 Standard_Real aSizeRatio = 0.8;
3332 Standard_Real anArrowDiam = 0.05;
3333 Standard_Integer aNbFacets = 12;
3334 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7c8a8fcc 3335 {
536d98e2 3336 Standard_CString anArg = theArgVec[anArgIter];
3337 TCollection_AsciiString aFlag (anArg);
3338 aFlag.LowerCase();
3339 if (anUpdateTool.parseRedrawMode (aFlag))
7c8a8fcc 3340 {
536d98e2 3341 continue;
3342 }
3343 else if (aFlag == "-on")
7c8a8fcc 3344 {
536d98e2 3345 continue;
3346 }
3347 else if (aFlag == "-off")
7c8a8fcc 3348 {
536d98e2 3349 aView->TriedronErase();
3350 return 0;
3351 }
3352 else if (aFlag == "-pos"
3353 || aFlag == "-position"
3354 || aFlag == "-corner")
7c8a8fcc 3355 {
536d98e2 3356 if (++anArgIter >= theArgNb)
3357 {
3358 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3359 return 1;
3360 }
3361
3362 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3363 aPosName.LowerCase();
3364 if (aPosName == "center")
3365 {
3366 aPosition = Aspect_TOTP_CENTER;
3367 }
3368 else if (aPosName == "left_lower"
3369 || aPosName == "lower_left"
3370 || aPosName == "leftlower"
3371 || aPosName == "lowerleft")
3372 {
3373 aPosition = Aspect_TOTP_LEFT_LOWER;
3374 }
3375 else if (aPosName == "left_upper"
3376 || aPosName == "upper_left"
3377 || aPosName == "leftupper"
3378 || aPosName == "upperleft")
3379 {
3380 aPosition = Aspect_TOTP_LEFT_UPPER;
3381 }
3382 else if (aPosName == "right_lower"
3383 || aPosName == "lower_right"
3384 || aPosName == "rightlower"
3385 || aPosName == "lowerright")
3386 {
3387 aPosition = Aspect_TOTP_RIGHT_LOWER;
3388 }
3389 else if (aPosName == "right_upper"
3390 || aPosName == "upper_right"
3391 || aPosName == "rightupper"
3392 || aPosName == "upperright")
3393 {
3394 aPosition = Aspect_TOTP_RIGHT_UPPER;
3395 }
3396 else
3397 {
3398 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3399 return 1;
3400 }
3401 }
3402 else if (aFlag == "-type")
7c8a8fcc 3403 {
536d98e2 3404 if (++anArgIter >= theArgNb)
3405 {
3406 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3407 return 1;
3408 }
3409
3410 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3411 aTypeName.LowerCase();
3412 if (aTypeName == "wireframe"
3413 || aTypeName == "wire")
3414 {
3415 aVisType = V3d_WIREFRAME;
3416 }
3417 else if (aTypeName == "zbuffer"
3418 || aTypeName == "shaded")
3419 {
3420 aVisType = V3d_ZBUFFER;
3421 }
3422 else
3423 {
3424 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3425 }
3426 }
3427 else if (aFlag == "-scale")
7c8a8fcc 3428 {
536d98e2 3429 if (++anArgIter >= theArgNb)
3430 {
3431 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3432 return 1;
3433 }
3434
3435 aScale = Draw::Atof (theArgVec[anArgIter]);
7c8a8fcc 3436 }
536d98e2 3437 else if (aFlag == "-size"
3438 || aFlag == "-sizeratio")
3439 {
3440 if (++anArgIter >= theArgNb)
3441 {
3442 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3443 return 1;
3444 }
7c8a8fcc 3445
536d98e2 3446 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3447 }
3448 else if (aFlag == "-arrowdiam"
3449 || aFlag == "-arrowdiameter")
3450 {
3451 if (++anArgIter >= theArgNb)
3452 {
3453 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3454 return 1;
3455 }
7c8a8fcc 3456
536d98e2 3457 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3458 }
3459 else if (aFlag == "-nbfacets")
3460 {
3461 if (++anArgIter >= theArgNb)
3462 {
3463 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3464 return 1;
3465 }
7c8a8fcc 3466
536d98e2 3467 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3468 }
3469 else if (aFlag == "-colorlabel"
3470 || aFlag == "-colorlabels")
7c8a8fcc 3471 {
536d98e2 3472 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3473 theArgVec + anArgIter + 1,
3474 aLabelsColor);
3475 if (aNbParsed == 0)
3476 {
3477 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3478 return 1;
3479 }
3480 anArgIter += aNbParsed;
7c8a8fcc 3481 }
536d98e2 3482 else if (aFlag == "-colorarrowx")
7c8a8fcc 3483 {
536d98e2 3484 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3485 theArgVec + anArgIter + 1,
3486 anArrowColorX);
3487 if (aNbParsed == 0)
3488 {
3489 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3490 return 1;
3491 }
3492 anArgIter += aNbParsed;
3493 }
3494 else if (aFlag == "-colorarrowy")
7c8a8fcc 3495 {
536d98e2 3496 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3497 theArgVec + anArgIter + 1,
3498 anArrowColorY);
3499 if (aNbParsed == 0)
3500 {
3501 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3502 return 1;
3503 }
3504 anArgIter += aNbParsed;
3505 }
3506 else if (aFlag == "-colorarrowz")
7c8a8fcc 3507 {
536d98e2 3508 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3509 theArgVec + anArgIter + 1,
3510 anArrowColorZ);
3511 if (aNbParsed == 0)
3512 {
3513 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3514 return 1;
3515 }
3516 anArgIter += aNbParsed;
3517 }
3518 else
3519 {
3520 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
7c8a8fcc 3521 return 1;
3522 }
7c8a8fcc 3523 }
3524
536d98e2 3525 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3526 aSizeRatio, anArrowDiam, aNbFacets);
3527 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
c357e426 3528 aView->ZFitAll();
7fd59977 3529 return 0;
3530}
3531
3532//==============================================================================
3533//function : VRotate
3534//purpose : Camera Rotating
3535//==============================================================================
3536
4af098ba 3537static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3538{
3539 Handle(V3d_View) aView = ViewerTest::CurrentView();
3540 if (aView.IsNull())
3541 {
3542 std::cout << "No active view!\n";
7fd59977 3543 return 1;
3544 }
3545
4af098ba 3546 Standard_Boolean hasFlags = Standard_False;
3547 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3548 {
3549 Standard_CString anArg (theArgVec[anArgIter]);
3550 TCollection_AsciiString aFlag (anArg);
3551 aFlag.LowerCase();
3552 if (aFlag == "-mousestart"
3553 || aFlag == "-mousefrom")
3554 {
3555 hasFlags = Standard_True;
3556 if (anArgIter + 2 >= theArgNb)
3557 {
3558 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3559 return 1;
3560 }
3561
3562 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3563 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3564 aView->StartRotation (anX, anY);
3565 }
3566 else if (aFlag == "-mousemove")
3567 {
3568 hasFlags = Standard_True;
3569 if (anArgIter + 2 >= theArgNb)
3570 {
3571 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3572 return 1;
3573 }
3574
3575 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3576 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3577 aView->Rotation (anX, anY);
3578 }
3579 else if (theArgNb != 4
3580 && theArgNb != 7)
3581 {
3582 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3583 return 1;
3584 }
3585 }
3586
3587 if (hasFlags)
3588 {
7fd59977 3589 return 0;
4af098ba 3590 }
3591 else if (theArgNb == 4)
3592 {
3593 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3594 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3595 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3596 aView->Rotate (anAX, anAY, anAZ);
3597 return 0;
3598 }
3599 else if (theArgNb == 7)
3600 {
3601 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3602 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3603 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3604
3605 Standard_Real anX = Draw::Atof (theArgVec[4]);
3606 Standard_Real anY = Draw::Atof (theArgVec[5]);
3607 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3608
3609 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
7fd59977 3610 return 0;
7fd59977 3611 }
4af098ba 3612
3613 std::cout << "Error: Invalid number of arguments\n";
3614 return 1;
7fd59977 3615}
3616
3617//==============================================================================
3618//function : VZoom
3619//purpose : View zoom in / out (relative to current zoom)
3620//==============================================================================
3621
3622static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3623 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3624 if ( V3dView.IsNull() ) {
3625 return 1;
3626 }
3627
3628 if ( argc == 2 ) {
91322f44 3629 Standard_Real coef = Draw::Atof(argv[1]);
7fd59977 3630 if ( coef <= 0.0 ) {
586db386 3631 di << argv[1] << "Invalid value\n";
7fd59977 3632 return 1;
3633 }
91322f44 3634 V3dView->SetZoom( Draw::Atof(argv[1]) );
7fd59977 3635 return 0;
3636 } else {
586db386 3637 di << argv[0] << " Invalid number of arguments\n";
7fd59977 3638 return 1;
3639 }
3640}
3641
3642//==============================================================================
3643//function : VPan
3644//purpose : View panning (in pixels)
3645//==============================================================================
3646
3647static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3648 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3649 if ( V3dView.IsNull() ) return 1;
3650
3651 if ( argc == 3 ) {
91322f44 3652 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
7fd59977 3653 return 0;
3654 } else {
586db386 3655 di << argv[0] << " Invalid number of arguments\n";
7fd59977 3656 return 1;
3657 }
3658}
3659
49e1a5c7 3660//==============================================================================
3661//function : VPlace
3662//purpose : Place the point (in pixels) at the center of the window
3663//==============================================================================
3664static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3665{
3666 Handle(V3d_View) aView = ViewerTest::CurrentView();
3667 if (aView.IsNull())
3668 {
3669 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3670 return 1;
3671 }
3672
3673 if (theArgNb != 3)
3674 {
3675 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3676 return 1;
3677 }
3678
3679 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3680
3681 return 0;
3682}
7fd59977 3683
71215351 3684static int VColorScale (Draw_Interpretor& theDI,
3685 Standard_Integer theArgNb,
3686 const char** theArgVec)
3687{
7fd59977 3688 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
71215351 3689 Handle(V3d_View) aView = ViewerTest::CurrentView();
3690 if (aContext.IsNull())
3691 {
3692 std::cout << "Error: no active view!\n";
3693 return 1;
7fd59977 3694 }
24a88697 3695 if (theArgNb <= 1)
3696 {
3697 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3698 return 1;
3699 }
7fd59977 3700
4b3d6eb1 3701 Handle(AIS_ColorScale) aColorScale;
7a324550 3702 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
71215351 3703 {
4b3d6eb1 3704 // find existing object
3705 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3706 if (aColorScale.IsNull())
7a324550 3707 {
3708 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3709 return 1;
3710 }
3711 }
71215351 3712
7a324550 3713 if (theArgNb <= 2)
3714 {
4b3d6eb1 3715 if (aColorScale.IsNull())
3716 {
3717 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
3718 return 1;
3719 }
3720
7a324550 3721 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
4b3d6eb1 3722 << "Min range: " << aColorScale->GetMin() << "\n"
3723 << "Max range: " << aColorScale->GetMax() << "\n"
3724 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
3725 << "Text height: " << aColorScale->GetTextHeight() << "\n"
3726 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
3727 << "Color scale title: " << aColorScale->GetTitle() << "\n"
71215351 3728 << "Label position: ";
4b3d6eb1 3729 switch (aColorScale->GetLabelPosition())
71215351 3730 {
3731 case Aspect_TOCSP_NONE:
3732 theDI << "None\n";
3733 break;
3734 case Aspect_TOCSP_LEFT:
3735 theDI << "Left\n";
3736 break;
3737 case Aspect_TOCSP_RIGHT:
3738 theDI << "Right\n";
3739 break;
3740 case Aspect_TOCSP_CENTER:
3741 theDI << "Center\n";
3742 break;
3743 }
3744 return 0;
3745 }
71215351 3746
4b3d6eb1 3747 if (aColorScale.IsNull())
3748 {
3749 aColorScale = new AIS_ColorScale();
3750 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3751 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3752 }
3753
3754 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
7a324550 3755 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
71215351 3756 {
3757 Standard_CString anArg = theArgVec[anArgIter];
3758 TCollection_AsciiString aFlag (anArg);
3759 aFlag.LowerCase();
3760 if (anUpdateTool.parseRedrawMode (aFlag))
3761 {
3762 continue;
3763 }
3764 else if (aFlag == "-range")
3765 {
3766 if (anArgIter + 3 >= theArgNb)
3767 {
3768 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3769 return 1;
3770 }
3771
4b3d6eb1 3772 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
3773 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
3774 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
3775 if (!aRangeMin.IsRealValue()
3776 || !aRangeMax.IsRealValue())
71215351 3777 {
4b3d6eb1 3778 std::cout << "Error: the range values should be real!\n";
71215351 3779 return 1;
3780 }
4b3d6eb1 3781 else if (!aNbIntervals.IsIntegerValue())
71215351 3782 {
3783 std::cout << "Error: the number of intervals should be integer!\n";
3784 return 1;
3785 }
3786
4b3d6eb1 3787 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
3788 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
71215351 3789 }
3790 else if (aFlag == "-font")
3791 {
3792 if (anArgIter + 1 >= theArgNb)
3793 {
3794 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3795 return 1;
3796 }
51740958 3797 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3798 if (!aFontArg.IsIntegerValue())
71215351 3799 {
3800 std::cout << "Error: HeightFont value should be integer!\n";
3801 return 1;
3802 }
3803
4b3d6eb1 3804 aColorScale->SetTextHeight (aFontArg.IntegerValue());
71215351 3805 anArgIter += 1;
3806 }
3807 else if (aFlag == "-textpos")
3808 {
3809 if (anArgIter + 1 >= theArgNb)
3810 {
3811 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3812 return 1;
3813 }
4b3d6eb1 3814
51740958 3815 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3816 aTextPosArg.LowerCase();
4b3d6eb1 3817 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
51740958 3818 if (aTextPosArg == "none")
71215351 3819 {
3820 aLabPosition = Aspect_TOCSP_NONE;
3821 }
51740958 3822 else if (aTextPosArg == "left")
71215351 3823 {
3824 aLabPosition = Aspect_TOCSP_LEFT;
3825 }
51740958 3826 else if (aTextPosArg == "right")
71215351 3827 {
3828 aLabPosition = Aspect_TOCSP_RIGHT;
3829 }
51740958 3830 else if (aTextPosArg == "center")
71215351 3831 {
3832 aLabPosition = Aspect_TOCSP_CENTER;
3833 }
3834 else
3835 {
51740958 3836 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
71215351 3837 return 1;
3838 }
4b3d6eb1 3839 aColorScale->SetLabelPosition (aLabPosition);
71215351 3840 }
24a88697 3841 else if (aFlag == "-logarithmic"
3842 || aFlag == "-log")
3843 {
3844 if (anArgIter + 1 >= theArgNb)
3845 {
3846 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3847 return 1;
3848 }
4b3d6eb1 3849
24a88697 3850 Standard_Boolean IsLog;
3851 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3852 {
3853 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3854 return 1;
3855 }
4b3d6eb1 3856 aColorScale->SetLogarithmic (IsLog);
3857 }
3858 else if (aFlag == "-huerange"
3859 || aFlag == "-hue")
3860 {
3861 if (anArgIter + 2 >= theArgNb)
3862 {
3863 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3864 return 1;
3865 }
3866
3867 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
3868 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
3869 aColorScale->SetHueRange (aHueMin, aHueMax);
3870 }
3871 else if (aFlag == "-colorrange")
3872 {
3873 Quantity_Color aColorMin, aColorMax;
3874 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3875 theArgVec + (anArgIter + 1),
3876 aColorMin);
3877 anArgIter += aNbParsed1;
3878 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3879 theArgVec + (anArgIter + 1),
3880 aColorMax);
3881 anArgIter += aNbParsed2;
3882 if (aNbParsed1 == 0
3883 || aNbParsed2 == 0)
3884 {
3885 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3886 return 1;
3887 }
3888
3889 aColorScale->SetColorRange (aColorMin, aColorMax);
3890 }
3891 else if (aFlag == "-reversed"
3892 || aFlag == "-inverted"
3893 || aFlag == "-topdown"
3894 || aFlag == "-bottomup")
3895 {
3896 Standard_Boolean toEnable = Standard_True;
3897 if (anArgIter + 1 < theArgNb
3898 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
3899 {
3900 ++anArgIter;
3901 }
3902 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
3903 }
3904 else if (aFlag == "-smooth"
3905 || aFlag == "-smoothtransition")
3906 {
3907 Standard_Boolean toEnable = Standard_True;
3908 if (anArgIter + 1 < theArgNb
3909 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3910 {
3911 ++anArgIter;
3912 }
3913 aColorScale->SetSmoothTransition (toEnable);
24a88697 3914 }
71215351 3915 else if (aFlag == "-xy")
3916 {
3917 if (anArgIter + 2 >= theArgNb)
3918 {
3919 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3920 return 1;
3921 }
3922
4b3d6eb1 3923 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
3924 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
3925 if (!anX.IsIntegerValue()
3926 || !anY.IsIntegerValue())
71215351 3927 {
b4b2ecca 3928 std::cout << "Error: coordinates should be integer values!\n";
71215351 3929 return 1;
3930 }
3931
4b3d6eb1 3932 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
b4b2ecca 3933 }
3934 else if (aFlag == "-width"
4b3d6eb1 3935 || aFlag == "-w"
3936 || aFlag == "-breadth")
b4b2ecca 3937 {
3938 if (anArgIter + 1 >= theArgNb)
3939 {
3940 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3941 return 1;
3942 }
3943
4b3d6eb1 3944 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
3945 if (!aBreadth.IsIntegerValue())
b4b2ecca 3946 {
3947 std::cout << "Error: a width should be an integer value!\n";
3948 return 1;
3949 }
4b3d6eb1 3950 aColorScale->SetBreadth (aBreadth.IntegerValue());
b4b2ecca 3951 }
3952 else if (aFlag == "-height"
3953 || aFlag == "-h")
3954 {
3955 if (anArgIter + 1 >= theArgNb)
3956 {
3957 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3958 return 1;
3959 }
3960
4b3d6eb1 3961 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
3962 if (!aHeight.IsIntegerValue())
b4b2ecca 3963 {
3964 std::cout << "Error: a width should be an integer value!\n";
3965 return 1;
3966 }
4b3d6eb1 3967 aColorScale->SetHeight (aHeight.IntegerValue());
71215351 3968 }
3969 else if (aFlag == "-color")
3970 {
4b3d6eb1 3971 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
71215351 3972 {
3973 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3974 return 1;
3975 }
4b3d6eb1 3976 else if (anArgIter + 2 >= theArgNb)
71215351 3977 {
4b3d6eb1 3978 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3979 return 1;
71215351 3980 }
3981
4b3d6eb1 3982 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
71215351 3983 if (!anInd.IsIntegerValue())
3984 {
3985 std::cout << "Error: Index value should be integer!\n";
3986 return 1;
3987 }
4b3d6eb1 3988 const Standard_Integer anIndex = anInd.IntegerValue();
3989 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
71215351 3990 {
4b3d6eb1 3991 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
71215351 3992 return 1;
3993 }
3994
4b3d6eb1 3995 Quantity_Color aColor;
3996 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3997 theArgVec + (anArgIter + 1),
3998 aColor);
3999 if (aNbParsed == 0)
71215351 4000 {
4b3d6eb1 4001 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
71215351 4002 return 1;
4003 }
4b3d6eb1 4004 aColorScale->SetIntervalColor (aColor, anIndex);
4005 aColorScale->SetColorType (Aspect_TOCSD_USER);
4006 anArgIter += aNbParsed;
71215351 4007 }
4008 else if (aFlag == "-label")
4009 {
4b3d6eb1 4010 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
71215351 4011 {
4012 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
4013 return 1;
4014 }
4015 else if (anArgIter + 2 >= theArgNb)
4016 {
4017 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4018 return 1;
4019 }
4020
4021 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4b3d6eb1 4022 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
71215351 4023 {
4b3d6eb1 4024 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
71215351 4025 return 1;
4026 }
4027
4028 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4b3d6eb1 4029 aColorScale->SetLabel (aText, anIndex);
4030 aColorScale->SetLabelType (Aspect_TOCSD_USER);
71215351 4031 anArgIter += 2;
4032 }
4b3d6eb1 4033 else if (aFlag == "-labelat"
4034 || aFlag == "-labat"
4035 || aFlag == "-labelatborder"
4036 || aFlag == "-labatborder"
4037 || aFlag == "-labelatcenter"
4038 || aFlag == "-labatcenter")
71215351 4039 {
4b3d6eb1 4040 Standard_Boolean toEnable = Standard_True;
4041 if (aFlag == "-labelat"
4042 || aFlag == "-labat")
71215351 4043 {
4b3d6eb1 4044 Standard_Integer aLabAtBorder = -1;
4045 if (++anArgIter >= theArgNb)
71215351 4046 {
4b3d6eb1 4047 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4048 anAtBorder.LowerCase();
4049 if (anAtBorder == "border")
71215351 4050 {
4b3d6eb1 4051 aLabAtBorder = 1;
71215351 4052 }
4b3d6eb1 4053 else if (anAtBorder == "center")
71215351 4054 {
4b3d6eb1 4055 aLabAtBorder = 0;
71215351 4056 }
71215351 4057 }
4b3d6eb1 4058 if (aLabAtBorder == -1)
4059 {
4060 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4061 return 1;
4062 }
4063 toEnable = (aLabAtBorder == 1);
4064 }
4065 else if (anArgIter + 1 < theArgNb
4066 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4067 {
4068 ++anArgIter;
71215351 4069 }
4b3d6eb1 4070 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4071 || aFlag == "-labatcenter"
4072 ? !toEnable
4073 : toEnable);
4074 }
4075 else if (aFlag == "-colors")
4076 {
4077 Aspect_SequenceOfColor aSeq;
4078 for (;;)
4079 {
4080 Quantity_Color aColor;
4081 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4082 theArgVec + (anArgIter + 1),
4083 aColor);
4084 if (aNbParsed == 0)
4085 {
4086 break;
4087 }
4088 anArgIter += aNbParsed;
4089 aSeq.Append (aColor);
4090 }
4091 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
71215351 4092 {
4093 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4b3d6eb1 4094 << aColorScale->GetNumberOfIntervals() << " intervals\n";
71215351 4095 return 1;
4096 }
4097
4b3d6eb1 4098 aColorScale->SetColors (aSeq);
4099 aColorScale->SetColorType (Aspect_TOCSD_USER);
71215351 4100 }
4b3d6eb1 4101 else if (aFlag == "-labels"
4102 || aFlag == "-freelabels")
71215351 4103 {
4b3d6eb1 4104 if (anArgIter + 1 >= theArgNb)
4105 {
4106 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4107 return 1;
4108 }
4109
4110 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4111 ? aColorScale->GetNumberOfIntervals() + 1
4112 : aColorScale->GetNumberOfIntervals();
4113 if (aFlag == "-freelabels")
4114 {
4115 ++anArgIter;
4116 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4117 }
4118 if (anArgIter + aNbLabels >= theArgNb)
71215351 4119 {
4b3d6eb1 4120 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
71215351 4121 return 1;
4122 }
4123
4124 TColStd_SequenceOfExtendedString aSeq;
4b3d6eb1 4125 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
71215351 4126 {
4b3d6eb1 4127 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
71215351 4128 }
4b3d6eb1 4129 aColorScale->SetLabels (aSeq);
4130 aColorScale->SetLabelType (Aspect_TOCSD_USER);
71215351 4131 }
4132 else if (aFlag == "-title")
4133 {
4134 if (anArgIter + 1 >= theArgNb)
4135 {
4136 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4137 return 1;
4138 }
4139
4140 Standard_Boolean isTwoArgs = Standard_False;
4141 if (anArgIter + 2 < theArgNb)
4142 {
4143 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4144 aSecondArg.LowerCase();
4b3d6eb1 4145 Standard_DISABLE_DEPRECATION_WARNINGS
71215351 4146 if (aSecondArg == "none")
4147 {
4b3d6eb1 4148 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
71215351 4149 isTwoArgs = Standard_True;
4150 }
4151 else if (aSecondArg == "left")
4152 {
4b3d6eb1 4153 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
71215351 4154 isTwoArgs = Standard_True;
4155 }
4156 else if (aSecondArg == "right")
4157 {
4b3d6eb1 4158 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
71215351 4159 isTwoArgs = Standard_True;
4160 }
4161 else if (aSecondArg == "center")
4162 {
4b3d6eb1 4163 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
71215351 4164 isTwoArgs = Standard_True;
4165 }
4b3d6eb1 4166 Standard_ENABLE_DEPRECATION_WARNINGS
71215351 4167 }
4168
4b3d6eb1 4169 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
71215351 4170 if (isTwoArgs)
4171 {
4172 anArgIter += 1;
4173 }
4174 anArgIter += 1;
4175 }
4176 else if (aFlag == "-demoversion"
4177 || aFlag == "-demo")
4178 {
4b3d6eb1 4179 aColorScale->SetPosition (0, 0);
4180 aColorScale->SetTextHeight (16);
4181 aColorScale->SetRange (0.0, 100.0);
4182 aColorScale->SetNumberOfIntervals (10);
4183 aColorScale->SetBreadth (0);
4184 aColorScale->SetHeight (0);
4185 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4186 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4187 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
71215351 4188 }
d5514578 4189 else if (aFlag == "-findcolor")
4190 {
4191 if (anArgIter + 1 >= theArgNb)
4192 {
4193 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4194 return 1;
4195 }
4196
4197 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4198
4199 if (!anArg1.IsRealValue())
4200 {
4201 std::cout << "Error: the value should be real!\n";
4202 return 1;
4203 }
4204
4205 Quantity_Color aColor;
4b3d6eb1 4206 aColorScale->FindColor (anArg1.RealValue(), aColor);
d5514578 4207 theDI << Quantity_Color::StringName (aColor.Name());
4208 return 0;
4209 }
71215351 4210 else
4211 {
4212 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4213 return 1;
4214 }
4215 }
4b3d6eb1 4216
4217 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4218 aView->Window()->Size (aWinWidth, aWinHeight);
4219 if (aColorScale->GetBreadth() == 0)
b4b2ecca 4220 {
4b3d6eb1 4221 aColorScale->SetBreadth (aWinWidth);
b4b2ecca 4222 }
4b3d6eb1 4223 if (aColorScale->GetHeight() == 0)
4224 {
4225 aColorScale->SetHeight (aWinHeight);
4226 }
4227 aColorScale->SetToUpdate();
4228 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
7fd59977 4229 return 0;
4230}
4231
4232//==============================================================================
4233//function : VGraduatedTrihedron
a79f67f8 4234//purpose : Displays or hides a graduated trihedron
7fd59977 4235//==============================================================================
a79f67f8 4236static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4237 Quantity_Color& theColor)
13a22457 4238{
a79f67f8 4239 Quantity_NameOfColor aColorName;
4240 TCollection_AsciiString aVal = theValue;
4241 aVal.UpperCase();
4242 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
13a22457 4243 {
a79f67f8 4244 return Standard_False;
13a22457 4245 }
a79f67f8 4246 theColor = Quantity_Color (aColorName);
4247 return Standard_True;
13a22457
S
4248}
4249
a79f67f8 4250static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
7fd59977 4251{
a79f67f8 4252 if (theArgNum < 2)
13a22457 4253 {
a79f67f8 4254 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4255 << theArgs[0] <<"' for more information.\n";
4256 return 1; //TCL_ERROR
13a22457 4257 }
7fd59977 4258
a79f67f8 4259 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4260 TCollection_AsciiString aParseKey;
4261 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4262 {
4263 TCollection_AsciiString anArg (theArgs [anArgIt]);
4264
4265 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4266 {
4267 aParseKey = anArg;
4268 aParseKey.Remove (1);
4269 aParseKey.LowerCase();
4270 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4271 continue;
4272 }
13a22457 4273
a79f67f8 4274 if (aParseKey.IsEmpty())
4275 {
4276 continue;
4277 }
4278
4279 aMapOfArgs(aParseKey)->Append (anArg);
4280 }
4281
4282 // Check parameters
4283 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4284 aMapIt.More(); aMapIt.Next())
7fd59977 4285 {
a79f67f8 4286 const TCollection_AsciiString& aKey = aMapIt.Key();
4287 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4288
4289 // Bool key, without arguments
4290 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4291 && anArgs->IsEmpty())
4292 {
4293 continue;
4294 }
4295
4296 // One argument
4297 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4298 && anArgs->Length() == 1)
4299 {
4300 continue;
4301 }
4302
4303 // On/off arguments
4304 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4305 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
536d98e2 4306 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4307 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
a79f67f8 4308 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4309 {
4310 continue;
4311 }
4312
4313 // One string argument
4314 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4315 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4316 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4317 {
4318 continue;
4319 }
4320
4321 // One integer argument
4322 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4323 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4324 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4325 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4326 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4327 {
4328 continue;
4329 }
4330
4331 // One real argument
4332 if ( aKey.IsEqual ("arrowlength")
4333 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4334 {
4335 continue;
4336 }
4337
4338 // Two string arguments
4339 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4340 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
13a22457 4341 {
a79f67f8 4342 continue;
13a22457 4343 }
a79f67f8 4344
4345 TCollection_AsciiString aLowerKey;
4346 aLowerKey = "-";
4347 aLowerKey += aKey;
4348 aLowerKey.LowerCase();
4349 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4350 std::cout << "Type help for more information.\n";
4351 return 1;
7fd59977 4352 }
4353
a79f67f8 4354 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4355 if (anAISContext.IsNull())
4356 {
586db386 4357 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
a79f67f8 4358 return 1;
4359 }
7fd59977 4360
a79f67f8 4361 Standard_Boolean toDisplay = Standard_True;
4362 Quantity_Color aColor;
4363 Graphic3d_GraduatedTrihedron aTrihedronData;
4364 // Process parameters
4365 Handle(TColStd_HSequenceOfAsciiString) aValues;
4366 if (aMapOfArgs.Find ("off", aValues))
7fd59977 4367 {
a79f67f8 4368 toDisplay = Standard_False;
4369 }
13a22457 4370
a79f67f8 4371 // AXES NAMES
4372 if (aMapOfArgs.Find ("xname", aValues))
4373 {
4374 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4375 }
4376 if (aMapOfArgs.Find ("yname", aValues))
4377 {
4378 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4379 }
4380 if (aMapOfArgs.Find ("zname", aValues))
4381 {
4382 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4383 }
4384 if (aMapOfArgs.Find ("xdrawname", aValues))
4385 {
536d98e2 4386 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4387 }
4388 if (aMapOfArgs.Find ("ydrawname", aValues))
4389 {
536d98e2 4390 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4391 }
4392 if (aMapOfArgs.Find ("zdrawname", aValues))
4393 {
536d98e2 4394 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4395 }
4396 if (aMapOfArgs.Find ("xnameoffset", aValues))
4397 {
4398 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4399 }
4400 if (aMapOfArgs.Find ("ynameoffset", aValues))
4401 {
4402 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4403 }
4404 if (aMapOfArgs.Find ("znameoffset", aValues))
4405 {
4406 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4407 }
13a22457 4408
a79f67f8 4409 // COLORS
4410 if (aMapOfArgs.Find ("xnamecolor", aValues))
4411 {
4412 if (!GetColor (aValues->Value(1), aColor))
13a22457 4413 {
a79f67f8 4414 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4415 return 1;
13a22457 4416 }
a79f67f8 4417 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4418 }
4419 if (aMapOfArgs.Find ("ynamecolor", aValues))
4420 {
4421 if (!GetColor (aValues->Value(1), aColor))
13a22457 4422 {
a79f67f8 4423 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4424 return 1;
4425 }
4426 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4427 }
4428 if (aMapOfArgs.Find ("znamecolor", aValues))
4429 {
4430 if (!GetColor (aValues->Value(1), aColor))
4431 {
4432 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4433 return 1;
4434 }
4435 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4436 }
4437 if (aMapOfArgs.Find ("xcolor", aValues))
4438 {
4439 if (!GetColor (aValues->Value(1), aColor))
4440 {
4441 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4442 return 1;
4443 }
4444 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4445 }
4446 if (aMapOfArgs.Find ("ycolor", aValues))
4447 {
4448 if (!GetColor (aValues->Value(1), aColor))
4449 {
4450 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4451 return 1;
4452 }
4453 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4454 }
4455 if (aMapOfArgs.Find ("zcolor", aValues))
4456 {
4457 if (!GetColor (aValues->Value(1), aColor))
4458 {
4459 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4460 return 1;
4461 }
4462 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4463 }
4464
4465 // TICKMARKS
4466 if (aMapOfArgs.Find ("xticks", aValues))
4467 {
536d98e2 4468 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4469 }
4470 if (aMapOfArgs.Find ("yticks", aValues))
4471 {
536d98e2 4472 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4473 }
4474 if (aMapOfArgs.Find ("zticks", aValues))
4475 {
536d98e2 4476 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4477 }
4478 if (aMapOfArgs.Find ("xticklength", aValues))
4479 {
536d98e2 4480 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4481 }
4482 if (aMapOfArgs.Find ("yticklength", aValues))
4483 {
536d98e2 4484 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4485 }
4486 if (aMapOfArgs.Find ("zticklength", aValues))
4487 {
536d98e2 4488 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4489 }
4490 if (aMapOfArgs.Find ("xdrawticks", aValues))
4491 {
536d98e2 4492 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4493 }
4494 if (aMapOfArgs.Find ("ydrawticks", aValues))
4495 {
536d98e2 4496 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4497 }
4498 if (aMapOfArgs.Find ("zdrawticks", aValues))
4499 {
536d98e2 4500 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4501 }
4502
4503 // VALUES
4504 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4505 {
536d98e2 4506 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4507 }
4508 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4509 {
536d98e2 4510 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4511 }
4512 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4513 {
536d98e2 4514 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4515 }
4516 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4517 {
4518 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4519 }
4520 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4521 {
4522 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4523 }
4524 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4525 {
4526 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4527 }
4528
4529 // ARROWS
4530 if (aMapOfArgs.Find ("arrowlength", aValues))
4531 {
536d98e2 4532 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
a79f67f8 4533 }
4534
4535 // FONTS
4536 if (aMapOfArgs.Find ("namefont", aValues))
4537 {
4538 aTrihedronData.SetNamesFont (aValues->Value(1));
4539 }
4540 if (aMapOfArgs.Find ("valuesfont", aValues))
4541 {
4542 aTrihedronData.SetValuesFont (aValues->Value(1));
4543 }
4544
536d98e2 4545 if (aMapOfArgs.Find ("drawgrid", aValues))
4546 {
4547 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4548 }
4549 if (aMapOfArgs.Find ("drawaxes", aValues))
4550 {
4551 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4552 }
4553
a79f67f8 4554 // The final step: display of erase trihedron
4555 if (toDisplay)
4556 {
4557 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
13a22457 4558 }
7fd59977 4559 else
a79f67f8 4560 {
4561 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4562 }
7fd59977 4563
4564 ViewerTest::GetAISContext()->UpdateCurrentViewer();
a79f67f8 4565 ViewerTest::CurrentView()->Redraw();
13a22457 4566
7fd59977 4567 return 0;
4568}
4569
3bffef55 4570//==============================================================================
4571//function : VTile
4572//purpose :
4573//==============================================================================
4574static int VTile (Draw_Interpretor& theDI,
4575 Standard_Integer theArgNb,
4576 const char** theArgVec)
4577{
4578 Handle(V3d_View) aView = ViewerTest::CurrentView();
4579 if (aView.IsNull())
4580 {
4581 std::cerr << "Error: no active viewer.\n";
4582 return 1;
4583 }
4584
4585 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4586 if (theArgNb < 2)
4587 {
4588 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4589 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4590 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4591 return 0;
4592 }
4593
4594 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4595 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4596 {
4597 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4598 anArg.LowerCase();
4599 if (anArg == "-lowerleft"
4600 || anArg == "-upperleft")
4601 {
4602 if (anArgIter + 3 < theArgNb)
4603 {
4604 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4605 return 1;
4606 }
4607 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4608 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4609 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4610 }
4611 else if (anArg == "-total"
4612 || anArg == "-totalsize"
4613 || anArg == "-viewsize")
4614 {
4615 if (anArgIter + 3 < theArgNb)
4616 {
4617 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4618 return 1;
4619 }
4620 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4621 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4622 if (aTile.TotalSize.x() < 1
4623 || aTile.TotalSize.y() < 1)
4624 {
4625 std::cerr << "Error: total size is incorrect.\n";
4626 return 1;
4627 }
4628 }
4629 else if (anArg == "-tilesize")
4630 {
4631 if (anArgIter + 3 < theArgNb)
4632 {
4633 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4634 return 1;
4635 }
4636
4637 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4638 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4639 if (aTile.TileSize.x() < 1
4640 || aTile.TileSize.y() < 1)
4641 {
4642 std::cerr << "Error: tile size is incorrect.\n";
4643 return 1;
4644 }
4645 }
4646 else if (anArg == "-unset")
4647 {
4648 aView->Camera()->SetTile (Graphic3d_CameraTile());
4649 aView->Redraw();
4650 return 0;
4651 }
4652 }
4653
4654 if (aTile.TileSize.x() < 1
4655 || aTile.TileSize.y() < 1)
4656 {
4657 std::cerr << "Error: tile size is undefined.\n";
4658 return 1;
4659 }
4660 else if (aTile.TotalSize.x() < 1
4661 || aTile.TotalSize.y() < 1)
4662 {
4663 std::cerr << "Error: total size is undefined.\n";
4664 return 1;
4665 }
4666
4667 aView->Camera()->SetTile (aTile);
4668 aView->Redraw();
4669 return 0;
4670}
4671
7c3ef2f7 4672//! Format ZLayer ID.
4673inline const char* formZLayerId (const Standard_Integer theLayerId)
4674{
4675 switch (theLayerId)
4676 {
4677 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4678 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4679 case Graphic3d_ZLayerId_Top: return "[TOP]";
4680 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4681 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4682 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4683 }
4684 return "";
4685}
4686
4687//! Print the ZLayer information.
4688inline void printZLayerInfo (Draw_Interpretor& theDI,
4689 const Graphic3d_ZLayerSettings& theLayer)
4690{
4691 if (!theLayer.Name().IsEmpty())
4692 {
4693 theDI << " Name: " << theLayer.Name() << "\n";
4694 }
4695 if (theLayer.IsImmediate())
4696 {
4697 theDI << " Immediate: TRUE\n";
4698 }
4699 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4ecf34cc 4700 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
4701 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
7c3ef2f7 4702 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4703 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4704 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4705 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4706 {
4707 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4708 }
4709}
4710
59f45b7c 4711//==============================================================================
4712//function : VZLayer
4713//purpose : Test z layer operations for v3d viewer
4714//==============================================================================
7c3ef2f7 4715static int VZLayer (Draw_Interpretor& theDI,
4716 Standard_Integer theArgNb,
4717 const char** theArgVec)
59f45b7c 4718{
7c3ef2f7 4719 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
59f45b7c 4720 if (aContextAIS.IsNull())
4721 {
7c3ef2f7 4722 std::cout << "No active viewer!\n";
59f45b7c 4723 return 1;
4724 }
4725
4726 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
7c3ef2f7 4727 if (theArgNb < 2)
59f45b7c 4728 {
7c3ef2f7 4729 TColStd_SequenceOfInteger aLayers;
4730 aViewer->GetAllZLayers (aLayers);
4731 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4732 {
4733 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4734 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4735 printZLayerInfo (theDI, aSettings);
4736 }
59f45b7c 4737 return 1;
4738 }
4739
7c3ef2f7 4740 Standard_Integer anArgIter = 1;
4741 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4742 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4743 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
59f45b7c 4744 {
7c3ef2f7 4745 ++anArgIter;
4746 }
59f45b7c 4747
7c3ef2f7 4748 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4749 if (aFirstArg.IsIntegerValue())
4750 {
4751 ++anArgIter;
4752 aLayerId = aFirstArg.IntegerValue();
59f45b7c 4753 }
7c3ef2f7 4754 else
59f45b7c 4755 {
7c3ef2f7 4756 aFirstArg.LowerCase();
4757 if (aFirstArg == "default"
4758 || aFirstArg == "def")
59f45b7c 4759 {
7c3ef2f7 4760 aLayerId = Graphic3d_ZLayerId_Default;
4761 ++anArgIter;
59f45b7c 4762 }
7c3ef2f7 4763 else if (aFirstArg == "top")
59f45b7c 4764 {
7c3ef2f7 4765 aLayerId = Graphic3d_ZLayerId_Top;
4766 ++anArgIter;
59f45b7c 4767 }
7c3ef2f7 4768 else if (aFirstArg == "topmost")
a1954302 4769 {
7c3ef2f7 4770 aLayerId = Graphic3d_ZLayerId_Topmost;
4771 ++anArgIter;
a1954302 4772 }
7c3ef2f7 4773 else if (aFirstArg == "overlay"
4774 || aFirstArg == "toposd")
59f45b7c 4775 {
7c3ef2f7 4776 aLayerId = Graphic3d_ZLayerId_TopOSD;
4777 ++anArgIter;
59f45b7c 4778 }
7c3ef2f7 4779 else if (aFirstArg == "underlay"
4780 || aFirstArg == "botosd")
c5751993 4781 {
7c3ef2f7 4782 aLayerId = Graphic3d_ZLayerId_BotOSD;
4783 ++anArgIter;
c5751993 4784 }
7c3ef2f7 4785 else
c5751993 4786 {
7c3ef2f7 4787 TColStd_SequenceOfInteger aLayers;
4788 aViewer->GetAllZLayers (aLayers);
4789 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4790 {
4791 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4792 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False))
4793 {
4794 aLayerId = aLayeriter.Value();
4795 ++anArgIter;
4796 break;
4797 }
4798 }
c5751993 4799 }
7c3ef2f7 4800 }
c5751993 4801
7c3ef2f7 4802 for (; anArgIter < theArgNb; ++anArgIter)
4803 {
4804 // perform operation
4805 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4806 anArg.LowerCase();
4807 if (anUpdateTool.parseRedrawMode (anArg))
c5751993 4808 {
7c3ef2f7 4809 //
c5751993 4810 }
7c3ef2f7 4811 else if (anArg == "-add"
4812 || anArg == "add")
c5751993 4813 {
7c3ef2f7 4814 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4815 if (!aViewer->AddZLayer (aLayerId))
4816 {
4817 std::cout << "Error: can not add a new z layer!\n";
4818 return 0;
4819 }
4820
4821 theDI << aLayerId;
c5751993 4822 }
7c3ef2f7 4823 else if (anArg == "-del"
4824 || anArg == "-delete"
4825 || anArg == "del")
c5751993 4826 {
7c3ef2f7 4827 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4828 {
4829 if (++anArgIter >= theArgNb)
4830 {
4831 std::cout << "Syntax error: id of z layer to remove is missing\n";
4832 return 1;
4833 }
4834
4835 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4836 }
4837
4838 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4839 || aLayerId == Graphic3d_ZLayerId_Default
4840 || aLayerId == Graphic3d_ZLayerId_Top
4841 || aLayerId == Graphic3d_ZLayerId_Topmost
4842 || aLayerId == Graphic3d_ZLayerId_TopOSD
4843 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4844 {
4845 std::cout << "Syntax error: standard Z layer can not be removed\n";
4846 return 1;
4847 }
4848
4849 // move all object displayed in removing layer to default layer
4850 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4851 anObjIter.More(); anObjIter.Next())
4852 {
4853 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4854 if (aPrs.IsNull()
4855 || aPrs->ZLayer() != aLayerId)
4856 {
4857 continue;
4858 }
4859 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4860 }
4861
4862 if (!aViewer->RemoveZLayer (aLayerId))
4863 {
4864 std::cout << "Z layer can not be removed!\n";
4865 }
4866 else
4867 {
4868 theDI << aLayerId << " ";
4869 }
c5751993 4870 }
7c3ef2f7 4871 else if (anArg == "-get"
4872 || anArg == "get")
c5751993 4873 {
7c3ef2f7 4874 TColStd_SequenceOfInteger aLayers;
4875 aViewer->GetAllZLayers (aLayers);
4876 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4877 {
4878 theDI << aLayeriter.Value() << " ";
4879 }
4880
4881 theDI << "\n";
c5751993 4882 }
7c3ef2f7 4883 else if (anArg == "-name")
c5751993 4884 {
7c3ef2f7 4885 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
c5751993 4886 {
7c3ef2f7 4887 std::cout << "Syntax error: id of Z layer is missing\n";
c5751993 4888 return 1;
4889 }
4890
7c3ef2f7 4891 if (++anArgIter >= theArgNb)
4892 {
4893 std::cout << "Syntax error: name is missing\n";
4894 return 1;
4895 }
c5751993 4896
7c3ef2f7 4897 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4898 aSettings.SetName (theArgVec[anArgIter]);
4899 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 4900 }
7c3ef2f7 4901 else if (anArg == "-origin")
c5751993 4902 {
7c3ef2f7 4903 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4904 {
4905 std::cout << "Syntax error: id of Z layer is missing\n";
4906 return 1;
4907 }
4908
4909 if (anArgIter + 2 >= theArgNb)
4910 {
4911 std::cout << "Syntax error: origin coordinates are missing\n";
4912 return 1;
4913 }
4914
4915 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4916 gp_XYZ anOrigin;
4917 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4918 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4919 anOrigin.SetZ (0.0);
4920 if (anArgIter + 3 < theArgNb)
4921 {
4922 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4923 anArgIter += 3;
4924 }
4925 else
4926 {
4927 anArgIter += 2;
4928 }
4929 aSettings.SetOrigin (anOrigin);
4930 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 4931 }
4ecf34cc 4932 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4933 && anArgIter + 1 < theArgNb
4934 && (anArg == "-cullingdistance"
4935 || anArg == "-cullingdist"
4936 || anArg == "-culldistance"
4937 || anArg == "-culldist"
4938 || anArg == "-distcull"
4939 || anArg == "-distculling"
4940 || anArg == "-distanceculling"))
4941 {
4942 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4943 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
4944 aSettings.SetCullingDistance (aDist);
4945 aViewer->SetZLayerSettings (aLayerId, aSettings);
4946 }
4947 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4948 && anArgIter + 1 < theArgNb
4949 && (anArg == "-cullingsize"
4950 || anArg == "-cullsize"
4951 || anArg == "-sizecull"
4952 || anArg == "-sizeculling"))
4953 {
4954 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4955 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
4956 aSettings.SetCullingSize (aSize);
4957 aViewer->SetZLayerSettings (aLayerId, aSettings);
4958 }
7c3ef2f7 4959 else if (anArg == "-settings"
4960 || anArg == "settings")
c5751993 4961 {
7c3ef2f7 4962 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4963 {
4964 if (++anArgIter >= theArgNb)
4965 {
4966 std::cout << "Syntax error: id of Z layer is missing\n";
4967 return 1;
4968 }
4969
4970 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4971 }
4972
4973 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4974 printZLayerInfo (theDI, aSettings);
c5751993 4975 }
7c3ef2f7 4976 else if (anArg == "-enable"
4977 || anArg == "enable"
4978 || anArg == "-disable"
4979 || anArg == "disable")
83da37b1 4980 {
7c3ef2f7 4981 const Standard_Boolean toEnable = anArg == "-enable"
4982 || anArg == "enable";
4983 if (++anArgIter >= theArgNb)
4984 {
4985 std::cout << "Syntax error: option name is missing\n";
4986 return 1;
4987 }
c5751993 4988
7c3ef2f7 4989 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
4990 aSubOp.LowerCase();
4991 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4992 {
4993 if (++anArgIter >= theArgNb)
4994 {
4995 std::cout << "Syntax error: id of Z layer is missing\n";
4996 return 1;
4997 }
c5751993 4998
7c3ef2f7 4999 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5000 }
c5751993 5001
7c3ef2f7 5002 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5003 if (aSubOp == "depthtest"
5004 || aSubOp == "test")
5005 {
5006 aSettings.SetEnableDepthTest (toEnable);
5007 }
5008 else if (aSubOp == "depthwrite"
5009 || aSubOp == "write")
5010 {
5011 aSettings.SetEnableDepthWrite (toEnable);
5012 }
5013 else if (aSubOp == "depthclear"
5014 || aSubOp == "clear")
5015 {
5016 aSettings.SetClearDepth (toEnable);
5017 }
5018 else if (aSubOp == "depthoffset"
5019 || aSubOp == "offset")
5020 {
5021 Graphic3d_PolygonOffset aParams;
5022 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5023 if (toEnable)
5024 {
5025 if (anArgIter + 2 >= theArgNb)
5026 {
5027 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5028 return 1;
5029 }
c5751993 5030
7c3ef2f7 5031 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5032 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5033 }
5034 aSettings.SetPolygonOffset (aParams);
5035 }
5036 else if (aSubOp == "positiveoffset"
5037 || aSubOp == "poffset")
5038 {
5039 if (toEnable)
5040 {
5041 aSettings.SetDepthOffsetPositive();
5042 }
5043 else
5044 {
5045 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5046 }
5047 }
5048 else if (aSubOp == "negativeoffset"
5049 || aSubOp == "noffset")
5050 {
5051 if (toEnable)
5052 {
5053 aSettings.SetDepthOffsetNegative();
5054 }
5055 else
5056 {
5057 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5058 }
5059 }
5060 else if (aSubOp == "textureenv")
5061 {
5062 aSettings.SetEnvironmentTexture (toEnable);
5063 }
5064
5065 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 5066 }
7c3ef2f7 5067 else
83da37b1 5068 {
7c3ef2f7 5069 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5070 return 1;
83da37b1 5071 }
59f45b7c 5072 }
5073
5074 return 0;
5075}
5076
c357e426 5077// The interactive presentation of 2d layer item
5078// for "vlayerline" command it provides a presentation of
5079// line with user-defined linewidth, linetype and transparency.
61b0191c 5080class V3d_LineItem : public AIS_InteractiveObject
20637bd2 5081{
5082public:
5083 // CASCADE RTTI
92efcf78 5084 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
4fe56619 5085
20637bd2 5086 // constructor
5087 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5088 Standard_Real X2, Standard_Real Y2,
20637bd2 5089 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5090 Standard_Real theWidth = 0.5,
5091 Standard_Real theTransp = 1.0);
5092
61b0191c 5093 private:
5094
5095 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5096 const Handle(Prs3d_Presentation)& thePresentation,
79104795 5097 const Standard_Integer theMode) Standard_OVERRIDE;
61b0191c 5098
5099 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
79104795 5100 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5101 {}
20637bd2 5102
5103private:
5104
5105 Standard_Real myX1, myY1, myX2, myY2;
eafb234b 5106 Aspect_TypeOfLine myType;
20637bd2 5107 Standard_Real myWidth;
20637bd2 5108};
5109
20637bd2 5110// default constructor for line item
4fe56619 5111V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
20637bd2 5112 Standard_Real X2, Standard_Real Y2,
20637bd2 5113 Aspect_TypeOfLine theType,
5114 Standard_Real theWidth,
5115 Standard_Real theTransp) :
61b0191c 5116 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5117 myType(theType), myWidth(theWidth)
20637bd2 5118{
61b0191c 5119 SetTransparency (1-theTransp);
20637bd2 5120}
5121
5122// render line
61b0191c 5123void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5124 const Handle(Prs3d_Presentation)& thePresentation,
5125 const Standard_Integer /*theMode*/)
20637bd2 5126{
61b0191c 5127 thePresentation->Clear();
5128 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
5129 Standard_Integer aWidth, aHeight;
5130 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5131 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5132 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5133 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5134 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5135 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5136 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5137 aGroup->AddPrimitiveArray (aPrim);
20637bd2 5138}
5139
5140//=============================================================================
5141//function : VLayerLine
5142//purpose : Draws line in the v3d view layer with given attributes: linetype,
5143// : linewidth, transparency coefficient
5144//============================================================================
5145static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5146{
5147 // get the active view
5148 Handle(V3d_View) aView = ViewerTest::CurrentView();
5149 if (aView.IsNull())
5150 {
5151 di << "Call vinit before!\n";
5152 return 1;
5153 }
5154 else if (argc < 5)
5155 {
5156 di << "Use: " << argv[0];
5157 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5158 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5159 di << " 0 - solid \n";
5160 di << " 1 - dashed \n";
5161 di << " 2 - dot \n";
5162 di << " 3 - dashdot\n";
5163 di << " transparency : { 0.0 - 1.0 } \n";
5164 di << " 0.0 - transparent\n";
5165 di << " 1.0 - visible \n";
5166 return 1;
5167 }
5168
61b0191c 5169 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
20637bd2 5170 // get the input params
91322f44 5171 Standard_Real X1 = Draw::Atof(argv[1]);
5172 Standard_Real Y1 = Draw::Atof(argv[2]);
5173 Standard_Real X2 = Draw::Atof(argv[3]);
5174 Standard_Real Y2 = Draw::Atof(argv[4]);
20637bd2 5175
3a4a3962 5176 Standard_Real aWidth = 0.5;
5177 Standard_Real aTransparency = 1.0;
20637bd2 5178
5179 // has width
5180 if (argc > 5)
91322f44 5181 aWidth = Draw::Atof(argv[5]);
20637bd2 5182
3a4a3962 5183 // select appropriate line type
5184 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5185 if (argc > 6
5186 && !ViewerTest::ParseLineType (argv[6], aLineType))
5187 {
5188 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5189 return 1;
5190 }
20637bd2 5191
5192 // has transparency
5193 if (argc > 7)
5194 {
91322f44 5195 aTransparency = Draw::Atof(argv[7]);
4fe56619 5196 if (aTransparency < 0 || aTransparency > 1.0)
20637bd2 5197 aTransparency = 1.0;
5198 }
5199
61b0191c 5200 static Handle (V3d_LineItem) aLine;
5201 if (!aLine.IsNull())
25289ec1 5202 {
0577ae8c 5203 aContext->Erase (aLine, Standard_False);
25289ec1 5204 }
61b0191c 5205 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5206 aLineType, aWidth,
5207 aTransparency);
25289ec1 5208
778cd667 5209 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
61b0191c 5210 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5211 aLine->SetToUpdate();
5212 aContext->Display (aLine, Standard_True);
25289ec1 5213
5214 return 0;
5215}
5216
61b0191c 5217
2bd4c032 5218//==============================================================================
5219//function : VGrid
5220//purpose :
5221//==============================================================================
5222
35e08fe8 5223static int VGrid (Draw_Interpretor& /*theDI*/,
2bd4c032 5224 Standard_Integer theArgNb,
5225 const char** theArgVec)
5226{
5227 // get the active view
5228 Handle(V3d_View) aView = ViewerTest::CurrentView();
5229 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5230 if (aView.IsNull() || aViewer.IsNull())
5231 {
5232 std::cerr << "No active view. Please call vinit.\n";
5233 return 1;
5234 }
5235
5236 Aspect_GridType aType = aViewer->GridType();
5237 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
224f48fa 5238 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2bd4c032 5239 Standard_Integer anIter = 1;
5240 for (; anIter < theArgNb; ++anIter)
5241 {
5242 const char* aValue = theArgVec[anIter];
224f48fa 5243 if (anUpdateTool.parseRedrawMode (aValue))
5244 {
5245 continue;
5246 }
5247 else if (*aValue == 'r')
2bd4c032 5248 {
5249 aType = Aspect_GT_Rectangular;
5250 }
5251 else if (*aValue == 'c')
5252 {
5253 aType = Aspect_GT_Circular;
5254 }
5255 else if (*aValue == 'l')
5256 {
5257 aMode = Aspect_GDM_Lines;
5258 }
5259 else if (*aValue == 'p')
5260 {
5261 aMode = Aspect_GDM_Points;
5262 }
5263 else if (strcmp (aValue, "off" ) == 0)
5264 {
5265 aViewer->DeactivateGrid();
5266 return 0;
5267 }
5268 else
5269 {
5270 break;
5271 }
5272 }
5273
5274 Standard_Integer aTail = (theArgNb - anIter);
5275 if (aTail == 0)
5276 {
5277 aViewer->ActivateGrid (aType, aMode);
5278 return 0;
5279 }
5280 else if (aTail != 2 && aTail != 5)
5281 {
5282 std::cerr << "Incorrect arguments number! Usage:\n"
5283 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
5284 return 1;
5285 }
5286
ee2be2a8 5287 Standard_Real anOriginX, anOriginY, aRotAngle;
2bd4c032 5288 if (aType == Aspect_GT_Rectangular)
5289 {
ee2be2a8 5290 Standard_Real aRStepX, aRStepY;
2bd4c032 5291 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5292
91322f44 5293 anOriginX = Draw::Atof (theArgVec[anIter++]);
5294 anOriginY = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5295 if (aTail == 5)
5296 {
91322f44 5297 aRStepX = Draw::Atof (theArgVec[anIter++]);
5298 aRStepY = Draw::Atof (theArgVec[anIter++]);
5299 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5300 }
5301 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5302 aViewer->ActivateGrid (aType, aMode);
5303 }
5304 else if (aType == Aspect_GT_Circular)
5305 {
ee2be2a8 5306 Standard_Real aRadiusStep;
2bd4c032 5307 Standard_Integer aDivisionNumber;
5308 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5309
91322f44 5310 anOriginX = Draw::Atof (theArgVec[anIter++]);
5311 anOriginY = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5312 if (aTail == 5)
5313 {
91322f44 5314 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
5315 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
5316 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5317 }
5318
5319 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5320 aViewer->ActivateGrid (aType, aMode);
5321 }
5322
5323 return 0;
5324}
5325
c40b7d58 5326//==============================================================================
5327//function : VPriviledgedPlane
5328//purpose :
5329//==============================================================================
5330
5331static int VPriviledgedPlane (Draw_Interpretor& theDI,
5332 Standard_Integer theArgNb,
5333 const char** theArgVec)
5334{
5335 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5336 {
5337 std::cerr << "Error: wrong number of arguments! See usage:\n";
5338 theDI.PrintHelp (theArgVec[0]);
5339 return 1;
5340 }
5341
5342 // get the active viewer
5343 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5344 if (aViewer.IsNull())
5345 {
5346 std::cerr << "Error: no active viewer. Please call vinit.\n";
5347 return 1;
5348 }
5349
5350 if (theArgNb == 1)
5351 {
5352 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5353 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5354 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5355 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5356 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5357 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5358 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5359 return 0;
5360 }
5361
5362 Standard_Integer anArgIdx = 1;
5363 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5364 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5365 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5366 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5367 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5368 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5369
5370 gp_Ax3 aPriviledgedPlane;
5371 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5372 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5373 if (theArgNb > 7)
5374 {
5375 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5376 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5377 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5378 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5379 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5380 }
5381 else
5382 {
5383 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5384 }
5385
5386 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5387
5388 return 0;
5389}
5390
f25b82d6 5391//==============================================================================
5392//function : VConvert
5393//purpose :
5394//==============================================================================
5395
5396static int VConvert (Draw_Interpretor& theDI,
5397 Standard_Integer theArgNb,
5398 const char** theArgVec)
5399{
5400 // get the active view
5401 Handle(V3d_View) aView = ViewerTest::CurrentView();
5402 if (aView.IsNull())
5403 {
c40b7d58 5404 std::cerr << "Error: no active view. Please call vinit.\n";
f25b82d6 5405 return 1;
5406 }
5407
5408 enum { Model, Ray, View, Window, Grid } aMode = Model;
5409
5410 // access coordinate arguments
5411 TColStd_SequenceOfReal aCoord;
5412 Standard_Integer anArgIdx = 1;
5413 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5414 {
5415 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5416 if (!anArg.IsRealValue())
5417 {
5418 break;
5419 }
5420 aCoord.Append (anArg.RealValue());
5421 }
5422
5423 // non-numeric argument too early
5424 if (aCoord.IsEmpty())
5425 {
5426 std::cerr << "Error: wrong number of arguments! See usage:\n";
5427 theDI.PrintHelp (theArgVec[0]);
5428 return 1;
5429 }
5430
5431 // collect all other arguments and options
5432 for (; anArgIdx < theArgNb; ++anArgIdx)
5433 {
5434 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5435 anArg.LowerCase();
5436 if (anArg == "window") aMode = Window;
5437 else if (anArg == "view") aMode = View;
5438 else if (anArg == "grid") aMode = Grid;
5439 else if (anArg == "ray") aMode = Ray;
5440 else
5441 {
5442 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5443 theDI.PrintHelp (theArgVec[0]);
5444 return 1;
5445 }
5446 }
5447
5448 // complete input checks
5449 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5450 (aCoord.Length() == 2 && theArgNb > 4) ||
5451 (aCoord.Length() == 3 && theArgNb > 5))
5452 {
5453 std::cerr << "Error: wrong number of arguments! See usage:\n";
5454 theDI.PrintHelp (theArgVec[0]);
5455 return 1;
5456 }
5457
5458 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5459 Standard_Integer aXYp[2] = {0, 0};
5460
5461 // convert one-dimensional coordinate
5462 if (aCoord.Length() == 1)
5463 {
5464 switch (aMode)
5465 {
ee2be2a8 5466 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
5467 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
f25b82d6 5468 default:
5469 std::cerr << "Error: wrong arguments! See usage:\n";
5470 theDI.PrintHelp (theArgVec[0]);
5471 return 1;
5472 }
5473 }
5474
5475 // convert 2D coordinates from projection or view reference space
5476 if (aCoord.Length() == 2)
5477 {
5478 switch (aMode)
5479 {
5480 case Model :
5481 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5482 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5483 return 0;
5484
5485 case View :
5486 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5487 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5488 return 0;
5489
5490 case Window :
ee2be2a8 5491 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
f25b82d6 5492 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5493 return 0;
5494
5495 case Grid :
5496 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5497 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5498 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5499 return 0;
5500
5501 case Ray :
5502 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5503 (Standard_Integer) aCoord (2),
5504 aXYZ[0], aXYZ[1], aXYZ[2],
5505 aXYZ[3], aXYZ[4], aXYZ[5]);
5506 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5507 return 0;
5508
5509 default:
5510 std::cerr << "Error: wrong arguments! See usage:\n";
5511 theDI.PrintHelp (theArgVec[0]);
5512 return 1;
5513 }
5514 }
5515
5516 // convert 3D coordinates from view reference space
5517 else if (aCoord.Length() == 3)
5518 {
5519 switch (aMode)
5520 {
5521 case Window :
5522 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5523 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5524 return 0;
5525
5526 case Grid :
5527 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5528 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5529 return 0;
5530
5531 default:
5532 std::cerr << "Error: wrong arguments! See usage:\n";
5533 theDI.PrintHelp (theArgVec[0]);
5534 return 1;
5535 }
5536 }
5537
5538 return 0;
5539}
5540
208e6839 5541//==============================================================================
5542//function : VFps
5543//purpose :
5544//==============================================================================
5545
5546static int VFps (Draw_Interpretor& theDI,
5547 Standard_Integer theArgNb,
5548 const char** theArgVec)
5549{
5550 // get the active view
5551 Handle(V3d_View) aView = ViewerTest::CurrentView();
5552 if (aView.IsNull())
5553 {
5554 std::cerr << "No active view. Please call vinit.\n";
5555 return 1;
5556 }
5557
91322f44 5558 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
208e6839 5559 if (aFramesNb <= 0)
5560 {
5561 std::cerr << "Incorrect arguments!\n";
5562 return 1;
5563 }
5564
5565 // the time is meaningless for first call
5566 // due to async OpenGl rendering
5567 aView->Redraw();
5568
5569 // redraw view in loop to estimate average values
5570 OSD_Timer aTimer;
5571 aTimer.Start();
5572 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5573 {
5574 aView->Redraw();
5575 }
5576 aTimer.Stop();
5577 Standard_Real aCpu;
5578 const Standard_Real aTime = aTimer.ElapsedTime();
5579 aTimer.OSD_Chronometer::Show (aCpu);
5580
5581 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5582 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5583
5584 // return statistics
5585 theDI << "FPS: " << aFpsAver << "\n"
5586 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5587
8c820969 5588 // compute additional statistics in ray-tracing mode
5589 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5590
5591 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5592 {
5593 Standard_Integer aSizeX;
5594 Standard_Integer aSizeY;
5595
5596 aView->Window()->Size (aSizeX, aSizeY);
5597
5598 // 1 shadow ray and 1 secondary ray pew each bounce
5599 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5600
5601 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5602 }
5603
208e6839 5604 return 0;
5605}
5606
58655684 5607//==============================================================================
5608//function : VGlDebug
5609//purpose :
5610//==============================================================================
5611
5612static int VGlDebug (Draw_Interpretor& theDI,
5613 Standard_Integer theArgNb,
5614 const char** theArgVec)
5615{
aaf512f1 5616 Handle(OpenGl_GraphicDriver) aDriver;
5617 Handle(V3d_View) aView = ViewerTest::CurrentView();
5618 if (!aView.IsNull())
5619 {
5620 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5621 }
c87535af 5622 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5623 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5624
58655684 5625 if (theArgNb < 2)
5626 {
c87535af 5627 TCollection_AsciiString aDebActive, aSyncActive;
5628 if (aCaps == NULL)
58655684 5629 {
c87535af 5630 aCaps = aDefCaps;
5631 }
5632 else
5633 {
5634 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5635 "GL_ARB_debug_output");
5636 aDebActive = isActive ? " (active)" : " (inactive)";
5637 if (isActive)
5638 {
5639 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5640 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5641 }
58655684 5642 }
5643
c87535af 5644 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5645 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5646 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5647 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
58655684 5648 return 0;
5649 }
5650
c87535af 5651 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
aaf512f1 5652 {
c87535af 5653 Standard_CString anArg = theArgVec[anArgIter];
5654 TCollection_AsciiString anArgCase (anArg);
5655 anArgCase.LowerCase();
5656 Standard_Boolean toEnableDebug = Standard_True;
5657 if (anArgCase == "-glsl"
5658 || anArgCase == "-glslwarn"
5659 || anArgCase == "-glslwarns"
5660 || anArgCase == "-glslwarnings")
5661 {
5662 Standard_Boolean toShowWarns = Standard_True;
5663 if (++anArgIter < theArgNb
a5565a3c 5664 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
c87535af 5665 {
5666 --anArgIter;
5667 }
5668 aDefCaps->glslWarnings = toShowWarns;
5669 if (aCaps != NULL)
5670 {
5671 aCaps->glslWarnings = toShowWarns;
5672 }
5673 }
5674 else if (anArgCase == "-extra"
5675 || anArgCase == "-extramsg"
5676 || anArgCase == "-extramessages")
5677 {
5678 Standard_Boolean toShow = Standard_True;
5679 if (++anArgIter < theArgNb
a5565a3c 5680 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
c87535af 5681 {
5682 --anArgIter;
5683 }
5684 aDefCaps->suppressExtraMsg = !toShow;
5685 if (aCaps != NULL)
5686 {
5687 aCaps->suppressExtraMsg = !toShow;
5688 }
5689 }
5690 else if (anArgCase == "-noextra"
5691 || anArgCase == "-noextramsg"
5692 || anArgCase == "-noextramessages")
5693 {
5694 Standard_Boolean toSuppress = Standard_True;
5695 if (++anArgIter < theArgNb
a5565a3c 5696 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
c87535af 5697 {
5698 --anArgIter;
5699 }
5700 aDefCaps->suppressExtraMsg = toSuppress;
5701 if (aCaps != NULL)
5702 {
5703 aCaps->suppressExtraMsg = toSuppress;
5704 }
5705 }
5706 else if (anArgCase == "-sync")
5707 {
5708 Standard_Boolean toSync = Standard_True;
5709 if (++anArgIter < theArgNb
a5565a3c 5710 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
c87535af 5711 {
5712 --anArgIter;
5713 }
5714 aDefCaps->contextSyncDebug = toSync;
5715 if (toSync)
5716 {
5717 aDefCaps->contextDebug = Standard_True;
5718 }
5719 }
5720 else if (anArgCase == "-debug")
5721 {
5722 if (++anArgIter < theArgNb
a5565a3c 5723 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
c87535af 5724 {
5725 --anArgIter;
5726 }
5727 aDefCaps->contextDebug = toEnableDebug;
5728 }
a5565a3c 5729 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
c87535af 5730 && (anArgIter + 1 == theArgNb))
5731 {
5732 // simple alias to turn on almost everything
5733 aDefCaps->contextDebug = toEnableDebug;
5734 aDefCaps->contextSyncDebug = toEnableDebug;
5735 aDefCaps->glslWarnings = toEnableDebug;
5736 }
5737 else
5738 {
5739 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5740 return 1;
5741 }
aaf512f1 5742 }
5743
58655684 5744 return 0;
5745}
208e6839 5746
5747//==============================================================================
5748//function : VVbo
5749//purpose :
5750//==============================================================================
5751
58655684 5752static int VVbo (Draw_Interpretor& theDI,
208e6839 5753 Standard_Integer theArgNb,
5754 const char** theArgVec)
5755{
58655684 5756 const Standard_Boolean toSet = (theArgNb > 1);
5757 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5758 if (toSet)
208e6839 5759 {
58655684 5760 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
208e6839 5761 }
5762
58655684 5763 // get the context
5764 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5765 if (aContextAIS.IsNull())
208e6839 5766 {
58655684 5767 if (!toSet)
5768 {
5769 std::cerr << "No active view!\n";
5770 }
208e6839 5771 return 1;
5772 }
58655684 5773 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5774 if (!aDriver.IsNull())
208e6839 5775 {
58655684 5776 if (!toSet)
5777 {
5778 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5779 }
5780 else
5781 {
5782 aDriver->ChangeOptions().vboDisable = toUseVbo;
5783 }
208e6839 5784 }
5785
208e6839 5786 return 0;
5787}
5788
a577aaab 5789//==============================================================================
5790//function : VCaps
5791//purpose :
5792//==============================================================================
5793
5794static int VCaps (Draw_Interpretor& theDI,
5795 Standard_Integer theArgNb,
5796 const char** theArgVec)
5797{
5798 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5799 Handle(OpenGl_GraphicDriver) aDriver;
8625ef7e 5800 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5801 if (!aContext.IsNull())
a577aaab 5802 {
8625ef7e 5803 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
a577aaab 5804 aCaps = &aDriver->ChangeOptions();
5805 }
5806
5807 if (theArgNb < 2)
5808 {
5809 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5810 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
abe46077 5811 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
8625ef7e 5812 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
f978241f 5813 theDI << "VSync: " << aCaps->swapInterval << "\n";
4e1523ef 5814 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
f978241f 5815 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
56689b27 5816 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
a577aaab 5817 return 0;
5818 }
5819
8625ef7e 5820 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
a577aaab 5821 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5822 {
8625ef7e 5823 Standard_CString anArg = theArgVec[anArgIter];
5824 TCollection_AsciiString anArgCase (anArg);
5825 anArgCase.LowerCase();
5826 if (anUpdateTool.parseRedrawMode (anArg))
5827 {
5828 continue;
5829 }
f978241f 5830 else if (anArgCase == "-vsync"
5831 || anArgCase == "-swapinterval")
5832 {
5833 Standard_Boolean toEnable = Standard_True;
5834 if (++anArgIter < theArgNb
a5565a3c 5835 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 5836 {
5837 --anArgIter;
5838 }
5839 aCaps->swapInterval = toEnable;
5840 }
8625ef7e 5841 else if (anArgCase == "-ffp")
5842 {
5843 Standard_Boolean toEnable = Standard_True;
5844 if (++anArgIter < theArgNb
a5565a3c 5845 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5846 {
5847 --anArgIter;
5848 }
5849 aCaps->ffpEnable = toEnable;
5850 }
5851 else if (anArgCase == "-vbo")
a577aaab 5852 {
8625ef7e 5853 Standard_Boolean toEnable = Standard_True;
5854 if (++anArgIter < theArgNb
a5565a3c 5855 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5856 {
5857 --anArgIter;
5858 }
5859 aCaps->vboDisable = !toEnable;
a577aaab 5860 }
8625ef7e 5861 else if (anArgCase == "-sprite"
5862 || anArgCase == "-sprites")
a577aaab 5863 {
8625ef7e 5864 Standard_Boolean toEnable = Standard_True;
5865 if (++anArgIter < theArgNb
a5565a3c 5866 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5867 {
5868 --anArgIter;
5869 }
5870 aCaps->pntSpritesDisable = !toEnable;
a577aaab 5871 }
8625ef7e 5872 else if (anArgCase == "-softmode")
abe46077 5873 {
8625ef7e 5874 Standard_Boolean toEnable = Standard_True;
5875 if (++anArgIter < theArgNb
a5565a3c 5876 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5877 {
5878 --anArgIter;
5879 }
5880 aCaps->contextNoAccel = toEnable;
5881 }
56689b27 5882 else if (anArgCase == "-winbuffer"
5883 || anArgCase == "-windowbuffer"
5884 || anArgCase == "-usewinbuffer"
5885 || anArgCase == "-usewindowbuffer"
5886 || anArgCase == "-usesystembuffer")
5887 {
5888 Standard_Boolean toEnable = Standard_True;
5889 if (++anArgIter < theArgNb
5890 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5891 {
5892 --anArgIter;
5893 }
5894 aCaps->useSystemBuffer = toEnable;
5895 }
8625ef7e 5896 else if (anArgCase == "-accel"
5897 || anArgCase == "-acceleration")
5898 {
5899 Standard_Boolean toEnable = Standard_True;
5900 if (++anArgIter < theArgNb
a5565a3c 5901 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5902 {
5903 --anArgIter;
5904 }
5905 aCaps->contextNoAccel = !toEnable;
abe46077 5906 }
4e1523ef 5907 else if (anArgCase == "-compat"
5908 || anArgCase == "-compatprofile"
5909 || anArgCase == "-compatible"
5910 || anArgCase == "-compatibleprofile")
5911 {
5912 Standard_Boolean toEnable = Standard_True;
5913 if (++anArgIter < theArgNb
a5565a3c 5914 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
4e1523ef 5915 {
5916 --anArgIter;
5917 }
5918 aCaps->contextCompatible = toEnable;
5919 if (!aCaps->contextCompatible)
5920 {
5921 aCaps->ffpEnable = Standard_False;
5922 }
5923 }
5924 else if (anArgCase == "-core"
5925 || anArgCase == "-coreprofile")
5926 {
5927 Standard_Boolean toEnable = Standard_True;
5928 if (++anArgIter < theArgNb
a5565a3c 5929 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
4e1523ef 5930 {
5931 --anArgIter;
5932 }
5933 aCaps->contextCompatible = !toEnable;
5934 if (!aCaps->contextCompatible)
5935 {
5936 aCaps->ffpEnable = Standard_False;
5937 }
5938 }
f978241f 5939 else if (anArgCase == "-stereo"
5940 || anArgCase == "-quadbuffer")
5941 {
5942 Standard_Boolean toEnable = Standard_True;
5943 if (++anArgIter < theArgNb
a5565a3c 5944 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 5945 {
5946 --anArgIter;
5947 }
5948 aCaps->contextStereo = toEnable;
5949 }
a577aaab 5950 else
5951 {
8625ef7e 5952 std::cout << "Error: unknown argument '" << anArg << "'\n";
5953 return 1;
a577aaab 5954 }
5955 }
5956 if (aCaps != &ViewerTest_myDefaultCaps)
5957 {
5958 ViewerTest_myDefaultCaps = *aCaps;
5959 }
5960 return 0;
5961}
5962
f0430952 5963//==============================================================================
5964//function : VMemGpu
5965//purpose :
5966//==============================================================================
5967
5968static int VMemGpu (Draw_Interpretor& theDI,
5969 Standard_Integer theArgNb,
5970 const char** theArgVec)
5971{
5972 // get the context
5973 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5974 if (aContextAIS.IsNull())
5975 {
5976 std::cerr << "No active view. Please call vinit.\n";
5977 return 1;
5978 }
5979
dc3fe572 5980 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
f0430952 5981 if (aDriver.IsNull())
5982 {
5983 std::cerr << "Graphic driver not available.\n";
5984 return 1;
5985 }
5986
5987 Standard_Size aFreeBytes = 0;
5988 TCollection_AsciiString anInfo;
5989 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5990 {
5991 std::cerr << "Information not available.\n";
5992 return 1;
5993 }
5994
5995 if (theArgNb > 1 && *theArgVec[1] == 'f')
5996 {
5997 theDI << Standard_Real (aFreeBytes);
5998 }
5999 else
6000 {
6001 theDI << anInfo;
6002 }
6003
6004 return 0;
6005}
6006
85e096c3 6007// ==============================================================================
6008// function : VReadPixel
6009// purpose :
6010// ==============================================================================
6011static int VReadPixel (Draw_Interpretor& theDI,
6012 Standard_Integer theArgNb,
6013 const char** theArgVec)
6014{
6015 // get the active view
6016 Handle(V3d_View) aView = ViewerTest::CurrentView();
6017 if (aView.IsNull())
6018 {
6019 std::cerr << "No active view. Please call vinit.\n";
6020 return 1;
6021 }
6022 else if (theArgNb < 3)
6023 {
6024 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
6025 return 1;
6026 }
6027
dc858f4c 6028 Image_Format aFormat = Image_Format_RGBA;
6029 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
692613e5 6030
85e096c3 6031 Standard_Integer aWidth, aHeight;
6032 aView->Window()->Size (aWidth, aHeight);
91322f44 6033 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
6034 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
85e096c3 6035 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
6036 {
6037 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
6038 return 1;
6039 }
6040
6041 Standard_Boolean toShowName = Standard_False;
6042 Standard_Boolean toShowHls = Standard_False;
6043 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
6044 {
dc858f4c 6045 TCollection_AsciiString aParam (theArgVec[anIter]);
6046 aParam.LowerCase();
6047 if (aParam == "rgb")
85e096c3 6048 {
dc858f4c 6049 aFormat = Image_Format_RGB;
692613e5 6050 aBufferType = Graphic3d_BT_RGB;
85e096c3 6051 }
dc858f4c 6052 else if (aParam == "hls")
85e096c3 6053 {
dc858f4c 6054 aFormat = Image_Format_RGB;
692613e5 6055 aBufferType = Graphic3d_BT_RGB;
85e096c3 6056 toShowHls = Standard_True;
6057 }
dc858f4c 6058 else if (aParam == "rgbf")
85e096c3 6059 {
dc858f4c 6060 aFormat = Image_Format_RGBF;
692613e5 6061 aBufferType = Graphic3d_BT_RGB;
85e096c3 6062 }
dc858f4c 6063 else if (aParam == "rgba")
85e096c3 6064 {
dc858f4c 6065 aFormat = Image_Format_RGBA;
692613e5 6066 aBufferType = Graphic3d_BT_RGBA;
85e096c3 6067 }
dc858f4c 6068 else if (aParam == "rgbaf")
85e096c3 6069 {
dc858f4c 6070 aFormat = Image_Format_RGBAF;
692613e5 6071 aBufferType = Graphic3d_BT_RGBA;
85e096c3 6072 }
dc858f4c 6073 else if (aParam == "depth")
85e096c3 6074 {
dc858f4c 6075 aFormat = Image_Format_GrayF;
692613e5 6076 aBufferType = Graphic3d_BT_Depth;
85e096c3 6077 }
dc858f4c 6078 else if (aParam == "name")
85e096c3 6079 {
6080 toShowName = Standard_True;
6081 }
6082 }
6083
692613e5 6084 Image_PixMap anImage;
6085 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
6086 {
6087 std::cerr << "Image allocation failed\n";
6088 return 1;
6089 }
6090 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
85e096c3 6091 {
6092 std::cerr << "Image dump failed\n";
6093 return 1;
6094 }
6095
68beaa3c 6096 // redirect possible warning messages that could have been added by ToPixMap
6097 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
6098 // contaminate result of the command
6099 Standard_CString aWarnLog = theDI.Result();
6100 if (aWarnLog != NULL && aWarnLog[0] != '\0')
6101 {
6102 std::cout << aWarnLog << std::endl;
6103 }
6104 theDI.Reset();
6105
e958a649 6106 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
85e096c3 6107 if (toShowName)
6108 {
692613e5 6109 if (aBufferType == Graphic3d_BT_RGBA)
85e096c3 6110 {
e958a649 6111 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
85e096c3 6112 }
6113 else
6114 {
e958a649 6115 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
85e096c3 6116 }
6117 }
6118 else
6119 {
6120 switch (aBufferType)
6121 {
6122 default:
692613e5 6123 case Graphic3d_BT_RGB:
85e096c3 6124 {
6125 if (toShowHls)
6126 {
e958a649 6127 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
85e096c3 6128 }
6129 else
6130 {
e958a649 6131 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
85e096c3 6132 }
6133 break;
6134 }
692613e5 6135 case Graphic3d_BT_RGBA:
85e096c3 6136 {
e958a649 6137 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
85e096c3 6138 break;
6139 }
692613e5 6140 case Graphic3d_BT_Depth:
85e096c3 6141 {
e958a649 6142 theDI << aColor.GetRGB().Red();
85e096c3 6143 break;
6144 }
6145 }
6146 }
6147
6148 return 0;
6149}
6150
fd3f6bd0 6151//! Auxiliary presentation for an image plane.
6152class ViewerTest_ImagePrs : public AIS_InteractiveObject
6153{
6154public:
6155 //! Main constructor.
6156 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
6157 const Standard_Real theWidth,
6158 const Standard_Real theHeight,
6159 const TCollection_AsciiString& theLabel)
6160 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
6161 {
6162 SetDisplayMode (0);
6163 SetHilightMode (1);
6164 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
6165 {
6166 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6167 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
6168 Graphic3d_MaterialAspect aMat;
6169 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
6170 aMat.SetAmbient (1.0);
6171 aMat.SetDiffuse (1.0);
6172 aMat.SetSpecular (1.0);
6173 aMat.SetEmissive (1.0);
6174 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
6175 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
6176 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
6177 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
6178 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6179 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
6180 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6181 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6182 aFillAspect->SetFrontMaterial (aMat);
6183 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
6184 aFillAspect->SetTextureMapOn();
6185 }
6186 {
6187 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
6188 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
6189 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
6190 myDrawer->SetTextAspect (aTextAspect);
6191 }
6192 {
6193 const gp_Dir aNorm (0.0, 0.0, 1.0);
6194 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
6195 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
6196 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
6197 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
6198 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
6199 myTris->AddEdge (1);
6200 myTris->AddEdge (2);
6201 myTris->AddEdge (3);
6202 myTris->AddEdge (3);
6203 myTris->AddEdge (2);
6204 myTris->AddEdge (4);
6205
6206 myRect = new Graphic3d_ArrayOfPolylines (4);
6207 myRect->AddVertex (myTris->Vertice (1));
6208 myRect->AddVertex (myTris->Vertice (3));
6209 myRect->AddVertex (myTris->Vertice (4));
6210 myRect->AddVertex (myTris->Vertice (2));
6211 }
6212 }
6213
6214 //! Returns TRUE for accepted display modes.
6215 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
6216
6217 //! Compute presentation.
6218 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
6219 {
6220 switch (theMode)
6221 {
6222 case 0:
6223 {
6224 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6225 aGroup->AddPrimitiveArray (myTris);
6226 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
6227 aGroup->AddPrimitiveArray (myRect);
6228 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6229 return;
6230 }
6231 case 1:
6232 {
6233 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
6234 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6235 aGroup->AddPrimitiveArray (myRect);
6236 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6237 return;
6238 }
6239 }
6240 }
6241
6242 //! Compute selection.
6243 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
6244 {
6245 if (theMode == 0)
6246 {
6247 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
6248 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
6249 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
6250 theSel->Add (aSensitive);
6251 }
6252 }
6253
6254private:
6255 Handle(Graphic3d_ArrayOfTriangles) myTris;
6256 Handle(Graphic3d_ArrayOfPolylines) myRect;
6257 TCollection_AsciiString myLabel;
6258 Standard_Real myWidth;
6259 Standard_Real myHeight;
6260};
6261
692613e5 6262//==============================================================================
6263//function : VDiffImage
6264//purpose : The draw-command compares two images.
6265//==============================================================================
6266
6267static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
6268{
fd3f6bd0 6269 if (theArgNb < 3)
692613e5 6270 {
fd3f6bd0 6271 std::cout << "Syntax error: not enough arguments.\n";
692613e5 6272 return 1;
6273 }
6274
fd3f6bd0 6275 Standard_Integer anArgIter = 1;
6276 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
6277 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
6278 TCollection_AsciiString aDiffImagePath;
6279 Standard_Real aTolColor = -1.0;
6280 Standard_Integer toBlackWhite = -1;
6281 Standard_Integer isBorderFilterOn = -1;
6282 Standard_Boolean isOldSyntax = Standard_False;
6283 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
6284 for (; anArgIter < theArgNb; ++anArgIter)
6285 {
6286 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6287 anArg.LowerCase();
6288 if (anArgIter + 1 < theArgNb
6289 && (anArg == "-toleranceofcolor"
6290 || anArg == "-tolerancecolor"
6291 || anArg == "-tolerance"
6292 || anArg == "-toler"))
6293 {
6294 aTolColor = Atof (theArgVec[++anArgIter]);
6295 if (aTolColor < 0.0 || aTolColor > 1.0)
6296 {
6297 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6298 return 1;
6299 }
6300 }
6301 else if (anArg == "-blackwhite")
6302 {
6303 Standard_Boolean toEnable = Standard_True;
6304 if (anArgIter + 1 < theArgNb
6305 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6306 {
6307 ++anArgIter;
6308 }
6309 toBlackWhite = toEnable ? 1 : 0;
6310 }
6311 else if (anArg == "-borderfilter")
6312 {
6313 Standard_Boolean toEnable = Standard_True;
6314 if (anArgIter + 1 < theArgNb
6315 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6316 {
6317 ++anArgIter;
6318 }
6319 isBorderFilterOn = toEnable ? 1 : 0;
6320 }
6321 else if (anArg == "-exitonclose")
6322 {
6323 Draw_ToExitOnCloseView = true;
6324 if (anArgIter + 1 < theArgNb
6325 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToExitOnCloseView))
6326 {
6327 ++anArgIter;
6328 }
6329 }
6330 else if (anArg == "-closeonescape"
6331 || anArg == "-closeonesc")
6332 {
6333 Draw_ToCloseViewOnEsc = true;
6334 if (anArgIter + 1 < theArgNb
6335 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToCloseViewOnEsc))
6336 {
6337 ++anArgIter;
6338 }
6339 }
6340 else if (anArgIter + 3 < theArgNb
6341 && anArg == "-display")
6342 {
6343 aViewName = theArgVec[++anArgIter];
6344 aPrsNameRef = theArgVec[++anArgIter];
6345 aPrsNameNew = theArgVec[++anArgIter];
6346 if (anArgIter + 1 < theArgNb
6347 && *theArgVec[anArgIter + 1] != '-')
6348 {
6349 aPrsNameDiff = theArgVec[++anArgIter];
6350 }
6351 }
6352 else if (aTolColor < 0.0
6353 && anArg.IsRealValue())
6354 {
6355 isOldSyntax = Standard_True;
6356 aTolColor = anArg.RealValue();
6357 if (aTolColor < 0.0 || aTolColor > 1.0)
6358 {
6359 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6360 return 1;
6361 }
6362 }
6363 else if (isOldSyntax
6364 && toBlackWhite == -1
6365 && (anArg == "0" || anArg == "1"))
6366 {
6367 toBlackWhite = anArg == "1" ? 1 : 0;
6368 }
6369 else if (isOldSyntax
6370 && isBorderFilterOn == -1
6371 && (anArg == "0" || anArg == "1"))
6372 {
6373 isBorderFilterOn = anArg == "1" ? 1 : 0;
6374 }
6375 else if (aDiffImagePath.IsEmpty())
6376 {
6377 aDiffImagePath = theArgVec[anArgIter];
6378 }
6379 else
6380 {
6381 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6382 return 1;
6383 }
6384 }
692613e5 6385
fd3f6bd0 6386 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
6387 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
6388 if (!anImgRef->Load (anImgPathRef))
6389 {
6390 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
6391 return 1;
6392 }
6393 if (!anImgNew->Load (anImgPathNew))
6394 {
6395 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
6396 return 1;
6397 }
692613e5 6398
6399 // compare the images
6400 Image_Diff aComparer;
fd3f6bd0 6401 Standard_Integer aDiffColorsNb = -1;
6402 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
692613e5 6403 {
fd3f6bd0 6404 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
6405 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
6406 aDiffColorsNb = aComparer.Compare();
6407 theDI << aDiffColorsNb << "\n";
692613e5 6408 }
6409
692613e5 6410 // save image of difference
fd3f6bd0 6411 Handle(Image_AlienPixMap) aDiff;
6412 if (aDiffColorsNb > 0
6413 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
6414 {
6415 aDiff = new Image_AlienPixMap();
6416 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
6417 {
6418 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
6419 return 1;
6420 }
6421 aComparer.SaveDiffImage (*aDiff);
6422 if (!aDiffImagePath.IsEmpty()
6423 && !aDiff->Save (aDiffImagePath))
6424 {
6425 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
6426 return 1;
6427 }
6428 }
6429
6430 if (aViewName.IsEmpty())
6431 {
6432 return 0;
6433 }
6434
6435 ViewerTest_Names aViewNames (aViewName);
6436 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
6437 {
6438 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
6439 theDI.Eval (aCommand.ToCString());
6440 }
6441
6442 Standard_Integer aPxLeft = 0;
6443 Standard_Integer aPxTop = 0;
6444 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
6445 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
6446 ? int(anImgRef->SizeY() * 2)
6447 : int(anImgRef->SizeY());
6448 TCollection_AsciiString aDisplayName;
9e04ccdc 6449 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
6450 aViewName, aDisplayName);
fd3f6bd0 6451
6452 Standard_Real aRatio = anImgRef->Ratio();
6453 Standard_Real aSizeX = 1.0;
6454 Standard_Real aSizeY = aSizeX / aRatio;
692613e5 6455 {
fd3f6bd0 6456 OSD_Path aPath (anImgPathRef);
6457 TCollection_AsciiString aLabelRef;
6458 if (!aPath.Name().IsEmpty())
6459 {
6460 aLabelRef = aPath.Name() + aPath.Extension();
6461 }
6462 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
6463
6464 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
6465 gp_Trsf aTrsfRef;
6466 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
6467 anImgRefPrs->SetLocalTransformation (aTrsfRef);
6468 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
692613e5 6469 }
fd3f6bd0 6470 {
6471 OSD_Path aPath (anImgPathNew);
6472 TCollection_AsciiString aLabelNew;
6473 if (!aPath.Name().IsEmpty())
6474 {
6475 aLabelNew = aPath.Name() + aPath.Extension();
6476 }
6477 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
692613e5 6478
fd3f6bd0 6479 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
6480 gp_Trsf aTrsfRef;
6481 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
6482 anImgNewPrs->SetLocalTransformation (aTrsfRef);
6483 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
6484 }
6485 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
6486 if (!aDiff.IsNull())
6487 {
6488 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
6489 gp_Trsf aTrsfDiff;
6490 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
6491 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
6492 }
6493 if (!aPrsNameDiff.IsEmpty())
6494 {
6495 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
6496 }
6497 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
6498 ViewerTest::CurrentView()->FitAll();
692613e5 6499 return 0;
6500}
6501
4754e164 6502//=======================================================================
6503//function : VSelect
6504//purpose : Emulates different types of selection by mouse:
6505// 1) single click selection
6506// 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
6507// 3) selection with polygon having corners at
dc3fe572 6508// pixel positions (x1,y1),...,(xn,yn)
4754e164 6509// 4) any of these selections with shift button pressed
6510//=======================================================================
6511static Standard_Integer VSelect (Draw_Interpretor& di,
6512 Standard_Integer argc,
6513 const char ** argv)
6514{
dc3fe572 6515 if(argc < 3)
4754e164 6516 {
586db386 6517 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
4754e164 6518 return 1;
6519 }
6520
6521 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
dc3fe572 6522 if(myAIScontext.IsNull())
4754e164 6523 {
6524 di << "use 'vinit' command before " << argv[0] << "\n";
6525 return 1;
6526 }
2157d6ac 6527
6528 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
6529 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
6530 TCollection_AsciiString anArg;
6531 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
6532 anArg.LowerCase();
6533 if (anArg == "-allowoverlap")
6534 {
6535 Standard_Boolean isValidated = isShiftSelection ? argc == 8
6536 : argc == 7;
6537 if (!isValidated)
6538 {
6539 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
6540 return 1;
6541 }
6542
6543 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
dde68833 6544 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
2157d6ac 6545 aCoordsNb -= 2;
6546 }
6547
4754e164 6548 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
6549 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
2157d6ac 6550 if(aCoordsNb == 2)
4754e164 6551 {
6552 if(isShiftSelection)
6553 aCurrentEventManager->ShiftSelect();
6554 else
6555 aCurrentEventManager->Select();
6556 }
2157d6ac 6557 else if(aCoordsNb == 4)
4754e164 6558 {
6559 if(isShiftSelection)
2157d6ac 6560 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
4754e164 6561 else
2157d6ac 6562 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
4754e164 6563 }
6564 else
6565 {
2157d6ac 6566 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
4754e164 6567
2157d6ac 6568 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
4754e164 6569 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
6570
6571 if(isShiftSelection)
6572 aCurrentEventManager->ShiftSelect(aPolyline);
6573 else
6574 aCurrentEventManager->Select(aPolyline);
6575 }
6576 return 0;
6577}
6578
6579//=======================================================================
6580//function : VMoveTo
dc3fe572 6581//purpose : Emulates cursor movement to defined pixel position
4754e164 6582//=======================================================================
8a590580 6583static Standard_Integer VMoveTo (Draw_Interpretor& ,
6584 Standard_Integer theNbArgs,
6585 const char** theArgVec)
4754e164 6586{
8a590580 6587 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
6588 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
6589 if (aContext.IsNull())
4754e164 6590 {
8a590580 6591 std::cout << "Error: no active View\n";
4754e164 6592 return 1;
6593 }
6594
8a590580 6595 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
6596 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4754e164 6597 {
8a590580 6598 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
6599 anArgStr.LowerCase();
6600 if (anArgStr == "-reset"
6601 || anArgStr == "-clear")
6602 {
6603 if (anArgIter + 1 < theNbArgs)
6604 {
6605 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
6606 return 1;
6607 }
6608
6609 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
6610 && aContext->CurrentViewer()->GridEcho();
6611 if (toEchoGrid)
6612 {
6613 aContext->CurrentViewer()->HideGridEcho (aView);
6614 }
6615 if (aContext->ClearDetected() || toEchoGrid)
6616 {
6617 aContext->CurrentViewer()->RedrawImmediate();
6618 }
6619 return 0;
6620 }
6621 else if (aMousePos.x() == IntegerLast()
6622 && anArgStr.IsIntegerValue())
6623 {
6624 aMousePos.x() = anArgStr.IntegerValue();
6625 }
6626 else if (aMousePos.y() == IntegerLast()
6627 && anArgStr.IsIntegerValue())
6628 {
6629 aMousePos.y() = anArgStr.IntegerValue();
6630 }
6631 else
6632 {
6633 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6634 return 1;
6635 }
6636 }
6637
6638 if (aMousePos.x() == IntegerLast()
6639 || aMousePos.y() == IntegerLast())
6640 {
6641 std::cout << "Syntax error: wrong number of arguments\n";
4754e164 6642 return 1;
6643 }
8a590580 6644
6645 ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y());
4754e164 6646 return 0;
6647}
6648
1beb58d7 6649namespace
6650{
6651 //! Global map storing all animations registered in ViewerTest.
6652 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
6653
6654 //! The animation calling the Draw Harness command.
6655 class ViewerTest_AnimationProc : public AIS_Animation
6656 {
6657 public:
6658
6659 //! Main constructor.
6660 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6661 Draw_Interpretor* theDI,
6662 const TCollection_AsciiString& theCommand)
6663 : AIS_Animation (theAnimationName),
6664 myDrawInter(theDI),
6665 myCommand (theCommand)
6666 {
6667 //
6668 }
6669
6670 protected:
6671
6672 //! Evaluate the command.
6673 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6674 {
6675 TCollection_AsciiString aCmd = myCommand;
6676 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6677 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6678 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6679 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6680 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6681 myDrawInter->Eval (aCmd.ToCString());
6682 }
6683
6684 //! Find the keyword in the command and replace it with value.
6685 //! @return the position of the keyword to pass value
6686 void replace (TCollection_AsciiString& theCmd,
6687 const TCollection_AsciiString& theKey,
6688 const TCollection_AsciiString& theVal)
6689 {
6690 TCollection_AsciiString aCmd (theCmd);
6691 aCmd.LowerCase();
6692 const Standard_Integer aPos = aCmd.Search (theKey);
6693 if (aPos == -1)
6694 {
6695 return;
6696 }
6697
6698 TCollection_AsciiString aPart1, aPart2;
6699 Standard_Integer aPart1To = aPos - 1;
6700 if (aPart1To >= 1
6701 && aPart1To <= theCmd.Length())
6702 {
6703 aPart1 = theCmd.SubString (1, aPart1To);
6704 }
6705
6706 Standard_Integer aPart2From = aPos + theKey.Length();
6707 if (aPart2From >= 1
6708 && aPart2From <= theCmd.Length())
6709 {
6710 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
6711 }
6712
6713 theCmd = aPart1 + theVal + aPart2;
6714 }
6715
6716 protected:
6717
6718 Draw_Interpretor* myDrawInter;
6719 TCollection_AsciiString myCommand;
6720
6721 };
6722
6723 //! Replace the animation with the new one.
6724 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
6725 Handle(AIS_Animation)& theAnimation,
6726 const Handle(AIS_Animation)& theAnimationNew)
6727 {
6728 theAnimationNew->CopyFrom (theAnimation);
6729 if (!theParentAnimation.IsNull())
6730 {
6731 theParentAnimation->Replace (theAnimation, theAnimationNew);
6732 }
6733 else
6734 {
6735 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
6736 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
6737 }
6738 theAnimation = theAnimationNew;
6739 }
6740
6741 //! Parse the point.
6742 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
6743 {
6744 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
6745 if (!anXYZ[0].IsRealValue()
6746 || !anXYZ[1].IsRealValue()
6747 || !anXYZ[2].IsRealValue())
6748 {
6749 return Standard_False;
6750 }
6751
6752 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
6753 return Standard_True;
6754 }
6755
6756 //! Parse the quaternion.
6757 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
6758 {
6759 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
6760 if (!anXYZW[0].IsRealValue()
6761 || !anXYZW[1].IsRealValue()
6762 || !anXYZW[2].IsRealValue()
6763 || !anXYZW[3].IsRealValue())
6764 {
6765 return Standard_False;
6766 }
6767
6768 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
6769 return Standard_True;
6770 }
6771
08f8a185 6772 //! Auxiliary class for flipping image upside-down.
6773 class ImageFlipper
6774 {
6775 public:
6776
6777 //! Empty constructor.
6778 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
6779
6780 //! Perform flipping.
6781 Standard_Boolean FlipY (Image_PixMap& theImage)
6782 {
6783 if (theImage.IsEmpty()
6784 || theImage.SizeX() == 0
6785 || theImage.SizeY() == 0)
6786 {
6787 return Standard_False;
6788 }
6789
6790 const Standard_Size aRowSize = theImage.SizeRowBytes();
6791 if (myTmp.Size() < aRowSize
6792 && !myTmp.Allocate (aRowSize))
6793 {
6794 return Standard_False;
6795 }
6796
6797 // for odd height middle row should be left as is
6798 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
6799 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
6800 {
6801 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
6802 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
6803 memcpy (myTmp.ChangeData(), aTop, aRowSize);
6804 memcpy (aTop, aBot, aRowSize);
6805 memcpy (aBot, myTmp.Data(), aRowSize);
6806 }
6807 return Standard_True;
6808 }
6809
6810 private:
6811 NCollection_Buffer myTmp;
6812 };
6813
1beb58d7 6814}
6815
197ac94e 6816//=================================================================================================
4754e164 6817//function : VViewParams
dc3fe572 6818//purpose : Gets or sets AIS View characteristics
197ac94e 6819//=================================================================================================
6820static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4754e164 6821{
1beb58d7 6822 Handle(V3d_View) aView = ViewerTest::CurrentView();
6823 if (aView.IsNull())
4754e164 6824 {
197ac94e 6825 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
4754e164 6826 return 1;
6827 }
197ac94e 6828
1beb58d7 6829 Standard_Boolean toSetProj = Standard_False;
6830 Standard_Boolean toSetUp = Standard_False;
6831 Standard_Boolean toSetAt = Standard_False;
6832 Standard_Boolean toSetEye = Standard_False;
6833 Standard_Boolean toSetScale = Standard_False;
6834 Standard_Boolean toSetSize = Standard_False;
6835 Standard_Boolean toSetCenter2d = Standard_False;
ee2be2a8 6836 Standard_Real aViewScale = aView->Scale();
6837 Standard_Real aViewSize = 1.0;
1beb58d7 6838 Graphic3d_Vec2i aCenter2d;
6839 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
6840 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
6841 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
6842 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
6843 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
197ac94e 6844 if (theArgsNb == 1)
4754e164 6845 {
197ac94e 6846 // print all of the available view parameters
1beb58d7 6847 char aText[4096];
6848 Sprintf (aText,
6849 "Scale: %g\n"
6850 "Proj: %12g %12g %12g\n"
6851 "Up: %12g %12g %12g\n"
6852 "At: %12g %12g %12g\n"
6853 "Eye: %12g %12g %12g\n",
6854 aViewScale,
6855 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6856 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6857 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
6858 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6859 theDi << aText;
197ac94e 6860 return 0;
4754e164 6861 }
197ac94e 6862
1beb58d7 6863 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
6864 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
197ac94e 6865 {
1beb58d7 6866 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6867 anArg.LowerCase();
6868 if (anUpdateTool.parseRedrawMode (anArg))
197ac94e 6869 {
197ac94e 6870 continue;
6871 }
1beb58d7 6872 else if (anArg == "-cmd"
6873 || anArg == "-command"
6874 || anArg == "-args")
6875 {
6876 char aText[4096];
6877 Sprintf (aText,
6878 "-scale %g "
6879 "-proj %g %g %g "
6880 "-up %g %g %g "
6881 "-at %g %g %g\n",
6882 aViewScale,
6883 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6884 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6885 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6886 theDi << aText;
6887 }
6888 else if (anArg == "-scale"
6889 || anArg == "-size")
6890 {
6891 if (anArgIter + 1 < theArgsNb
6892 && *theArgVec[anArgIter + 1] != '-')
6893 {
6894 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
6895 if (aValueArg.IsRealValue())
6896 {
6897 ++anArgIter;
6898 if (anArg == "-scale")
6899 {
6900 toSetScale = Standard_True;
6901 aViewScale = aValueArg.RealValue();
6902 }
6903 else if (anArg == "-size")
6904 {
6905 toSetSize = Standard_True;
6906 aViewSize = aValueArg.RealValue();
6907 }
6908 continue;
6909 }
6910 }
6911 if (anArg == "-scale")
6912 {
6913 theDi << "Scale: " << aView->Scale() << "\n";
6914 }
6915 else if (anArg == "-size")
6916 {
6917 Graphic3d_Vec2d aSizeXY;
6918 aView->Size (aSizeXY.x(), aSizeXY.y());
6919 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
6920 }
6921 }
6922 else if (anArg == "-eye"
6923 || anArg == "-at"
6924 || anArg == "-up"
6925 || anArg == "-proj")
6926 {
6927 if (anArgIter + 3 < theArgsNb)
6928 {
6929 gp_XYZ anXYZ;
6930 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
6931 {
6932 anArgIter += 3;
6933 if (anArg == "-eye")
6934 {
6935 toSetEye = Standard_True;
6936 aViewEye = anXYZ;
6937 }
6938 else if (anArg == "-at")
6939 {
6940 toSetAt = Standard_True;
6941 aViewAt = anXYZ;
6942 }
6943 else if (anArg == "-up")
6944 {
6945 toSetUp = Standard_True;
6946 aViewUp = anXYZ;
6947 }
6948 else if (anArg == "-proj")
6949 {
6950 toSetProj = Standard_True;
6951 aViewProj = anXYZ;
6952 }
6953 continue;
6954 }
6955 }
197ac94e 6956
1beb58d7 6957 if (anArg == "-eye")
6958 {
6959 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
6960 }
6961 else if (anArg == "-at")
6962 {
6963 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
6964 }
6965 else if (anArg == "-up")
6966 {
6967 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
6968 }
6969 else if (anArg == "-proj")
6970 {
6971 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
6972 }
6973 }
6974 else if (anArg == "-center")
3dfe95cd 6975 {
1beb58d7 6976 if (anArgIter + 2 < theArgsNb)
6977 {
6978 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
6979 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
6980 if (anX.IsIntegerValue()
6981 && anY.IsIntegerValue())
6982 {
6983 toSetCenter2d = Standard_True;
6984 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
6985 }
6986 }
6987 }
6988 else
6989 {
6990 std::cout << "Syntax error at '" << anArg << "'\n";
3dfe95cd 6991 return 1;
6992 }
1beb58d7 6993 }
3dfe95cd 6994
1beb58d7 6995 // change view parameters in proper order
6996 if (toSetScale)
6997 {
6998 aView->SetScale (aViewScale);
6999 }
7000 if (toSetSize)
7001 {
7002 aView->SetSize (aViewSize);
7003 }
7004 if (toSetEye)
7005 {
7006 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7007 }
7008 if (toSetAt)
7009 {
7010 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7011 }
7012 if (toSetProj)
7013 {
7014 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
7015 }
7016 if (toSetUp)
7017 {
7018 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
7019 }
7020 if (toSetCenter2d)
7021 {
7022 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
197ac94e 7023 }
7024
1beb58d7 7025 return 0;
7026}
197ac94e 7027
2e93433e 7028//==============================================================================
7029//function : V2DMode
7030//purpose :
7031//==============================================================================
7032static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
7033{
7034 bool is2dMode = true;
7035 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
7036 if (aV3dView.IsNull())
7037 {
7038 std::cout << "Error: no active view.\n";
7039 return 1;
7040 }
7041 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7042 {
7043 const TCollection_AsciiString anArg = theArgVec[anArgIt];
7044 TCollection_AsciiString anArgCase = anArg;
7045 anArgCase.LowerCase();
7046 if (anArgIt + 1 < theArgsNb
7047 && anArgCase == "-name")
7048 {
7049 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
7050 TCollection_AsciiString aViewName = aViewNames.GetViewName();
7051 if (!ViewerTest_myViews.IsBound1 (aViewName))
7052 {
7053 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
7054 return 1;
7055 }
7056 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
7057 }
7058 else if (anArgCase == "-mode")
7059 {
7060 if (anArgIt + 1 < theArgsNb
7061 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
7062 {
7063 ++anArgIt;
7064 }
7065 }
7066 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
7067 {
7068 //
7069 }
7070 else
7071 {
7072 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
7073 return 1;
7074 }
7075 }
7076
7077 aV3dView->SetView2DMode (is2dMode);
7078 return 0;
7079}
7080
1beb58d7 7081//==============================================================================
7082//function : VAnimation
7083//purpose :
7084//==============================================================================
7085static Standard_Integer VAnimation (Draw_Interpretor& theDI,
7086 Standard_Integer theArgNb,
7087 const char** theArgVec)
7088{
7089 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
7090 if (theArgNb < 2)
4754e164 7091 {
1beb58d7 7092 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
7093 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
7094 {
7095 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
197ac94e 7096 }
1beb58d7 7097 return 0;
7098 }
7099 if (aCtx.IsNull())
7100 {
7101 std::cout << "Error: no active view\n";
7102 return 1;
4754e164 7103 }
197ac94e 7104
1beb58d7 7105 Standard_Integer anArgIter = 1;
7106 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
7107 if (aNameArg.IsEmpty())
7108 {
7109 std::cout << "Syntax error: animation name is not defined.\n";
7110 return 1;
7111 }
7112
7113 TCollection_AsciiString aNameArgLower = aNameArg;
7114 aNameArgLower.LowerCase();
7115 if (aNameArgLower == "-reset"
7116 || aNameArgLower == "-clear")
7117 {
7118 ViewerTest_AnimationTimelineMap.Clear();
7119 return 0;
7120 }
7121 else if (aNameArg.Value (1) == '-')
7122 {
7123 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
7124 return 1;
7125 }
197ac94e 7126
1beb58d7 7127 const char* aNameSplitter = "/";
7128 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
7129 if (aSplitPos == -1)
197ac94e 7130 {
1beb58d7 7131 aNameSplitter = ".";
7132 aSplitPos = aNameArg.Search (aNameSplitter);
7133 }
7134
7135 // find existing or create a new animation by specified name within syntax "parent.child".
7136 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
7137 for (; !aNameArg.IsEmpty();)
7138 {
7139 TCollection_AsciiString aNameParent;
7140 if (aSplitPos != -1)
197ac94e 7141 {
1beb58d7 7142 if (aSplitPos == aNameArg.Length())
7143 {
7144 std::cout << "Syntax error: animation name is not defined.\n";
7145 return 1;
7146 }
7147
7148 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
7149 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
7150
7151 aSplitPos = aNameArg.Search (aNameSplitter);
197ac94e 7152 }
7153 else
7154 {
1beb58d7 7155 aNameParent = aNameArg;
7156 aNameArg.Clear();
197ac94e 7157 }
1beb58d7 7158
7159 if (anAnimation.IsNull())
3dfe95cd 7160 {
1beb58d7 7161 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
7162 {
7163 anAnimation = new AIS_Animation (aNameParent);
7164 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
7165 }
7166 aRootAnimation = anAnimation;
3dfe95cd 7167 }
7168 else
7169 {
1beb58d7 7170 aParentAnimation = anAnimation;
7171 anAnimation = aParentAnimation->Find (aNameParent);
7172 if (anAnimation.IsNull())
7173 {
7174 anAnimation = new AIS_Animation (aNameParent);
7175 aParentAnimation->Add (anAnimation);
7176 }
3dfe95cd 7177 }
7178 }
1beb58d7 7179
7180 if (anArgIter >= theArgNb)
197ac94e 7181 {
1beb58d7 7182 // just print the list of children
7183 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
197ac94e 7184 {
1beb58d7 7185 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
197ac94e 7186 }
1beb58d7 7187 return 0;
197ac94e 7188 }
1beb58d7 7189
bf7b2ceb 7190 // animation parameters
1beb58d7 7191 Standard_Boolean toPlay = Standard_False;
7192 Standard_Real aPlaySpeed = 1.0;
7193 Standard_Real aPlayStartTime = anAnimation->StartPts();
7194 Standard_Real aPlayDuration = anAnimation->Duration();
1beb58d7 7195 Standard_Boolean isFreeCamera = Standard_False;
7196 Standard_Boolean isLockLoop = Standard_False;
08f8a185 7197
7198 // video recording parameters
7199 TCollection_AsciiString aRecFile;
7200 Image_VideoParams aRecParams;
7201
1beb58d7 7202 Handle(V3d_View) aView = ViewerTest::CurrentView();
7203 for (; anArgIter < theArgNb; ++anArgIter)
197ac94e 7204 {
1beb58d7 7205 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7206 anArg.LowerCase();
bf7b2ceb 7207 // general options
1beb58d7 7208 if (anArg == "-reset"
7209 || anArg == "-clear")
197ac94e 7210 {
1beb58d7 7211 anAnimation->Clear();
7212 }
7213 else if (anArg == "-remove"
7214 || anArg == "-del"
7215 || anArg == "-delete")
7216 {
7217 if (!aParentAnimation.IsNull())
7218 {
7219 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
7220 }
7221 else
7222 {
7223 aParentAnimation->Remove (anAnimation);
7224 }
7225 }
bf7b2ceb 7226 // playback options
1beb58d7 7227 else if (anArg == "-play")
7228 {
7229 toPlay = Standard_True;
7230 if (++anArgIter < theArgNb)
7231 {
7232 if (*theArgVec[anArgIter] == '-')
7233 {
7234 --anArgIter;
7235 continue;
7236 }
7237 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
7238
7239 if (++anArgIter < theArgNb)
7240 {
7241 if (*theArgVec[anArgIter] == '-')
7242 {
7243 --anArgIter;
7244 continue;
7245 }
7246 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7247 }
7248 }
7249 }
7250 else if (anArg == "-resume")
7251 {
7252 toPlay = Standard_True;
7253 aPlayStartTime = anAnimation->ElapsedTime();
7254 if (++anArgIter < theArgNb)
7255 {
7256 if (*theArgVec[anArgIter] == '-')
7257 {
7258 --anArgIter;
7259 continue;
7260 }
7261
7262 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7263 }
7264 }
7265 else if (anArg == "-playspeed"
7266 || anArg == "-speed")
7267 {
7268 if (++anArgIter >= theArgNb)
7269 {
7270 std::cout << "Syntax error at " << anArg << ".\n";
7271 return 1;
7272 }
7273 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
7274 }
7275 else if (anArg == "-lock"
7276 || anArg == "-lockloop"
7277 || anArg == "-playlockloop")
7278 {
7279 isLockLoop = Standard_True;
7280 }
7281 else if (anArg == "-freecamera"
7282 || anArg == "-playfreecamera"
7283 || anArg == "-freelook")
7284 {
7285 isFreeCamera = Standard_True;
7286 }
08f8a185 7287 // video recodring options
7288 else if (anArg == "-rec"
7289 || anArg == "-record")
7290 {
7291 if (++anArgIter >= theArgNb)
7292 {
7293 std::cout << "Syntax error at " << anArg << ".\n";
7294 return 1;
7295 }
7296
7297 aRecFile = theArgVec[anArgIter];
7298 if (aRecParams.FpsNum <= 0)
7299 {
7300 aRecParams.FpsNum = 24;
7301 }
7302
7303 if (anArgIter + 2 < theArgNb
7304 && *theArgVec[anArgIter + 1] != '-'
7305 && *theArgVec[anArgIter + 2] != '-')
7306 {
7307 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
7308 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
7309 if (aWidthArg .IsIntegerValue()
7310 && aHeightArg.IsIntegerValue())
7311 {
7312 aRecParams.Width = aWidthArg .IntegerValue();
7313 aRecParams.Height = aHeightArg.IntegerValue();
7314 anArgIter += 2;
7315 }
7316 }
7317 }
1beb58d7 7318 else if (anArg == "-fps")
7319 {
7320 if (++anArgIter >= theArgNb)
7321 {
7322 std::cout << "Syntax error at " << anArg << ".\n";
7323 return 1;
7324 }
bf7b2ceb 7325
7326 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
7327 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
7328 if (aSplitIndex == 0)
7329 {
08f8a185 7330 aRecParams.FpsNum = aFpsArg.IntegerValue();
bf7b2ceb 7331 }
7332 else
7333 {
7334 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
7335 aFpsArg.Split (aFpsArg.Length() - 1);
7336 const TCollection_AsciiString aNumStr = aFpsArg;
08f8a185 7337 aRecParams.FpsNum = aNumStr.IntegerValue();
7338 aRecParams.FpsDen = aDenStr.IntegerValue();
7339 if (aRecParams.FpsDen < 1)
bf7b2ceb 7340 {
7341 std::cout << "Syntax error at " << anArg << ".\n";
7342 return 1;
7343 }
7344 }
1beb58d7 7345 }
08f8a185 7346 else if (anArg == "-format")
7347 {
7348 if (++anArgIter >= theArgNb)
7349 {
7350 std::cout << "Syntax error at " << anArg << ".\n";
7351 return 1;
7352 }
7353 aRecParams.Format = theArgVec[anArgIter];
7354 }
7355 else if (anArg == "-pix_fmt"
7356 || anArg == "-pixfmt"
7357 || anArg == "-pixelformat")
7358 {
7359 if (++anArgIter >= theArgNb)
7360 {
7361 std::cout << "Syntax error at " << anArg << ".\n";
7362 return 1;
7363 }
7364 aRecParams.PixelFormat = theArgVec[anArgIter];
7365 }
7366 else if (anArg == "-codec"
7367 || anArg == "-vcodec"
7368 || anArg == "-videocodec")
7369 {
7370 if (++anArgIter >= theArgNb)
7371 {
7372 std::cout << "Syntax error at " << anArg << ".\n";
7373 return 1;
7374 }
7375 aRecParams.VideoCodec = theArgVec[anArgIter];
7376 }
7377 else if (anArg == "-crf"
7378 || anArg == "-preset"
7379 || anArg == "-qp")
7380 {
7381 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
7382 if (++anArgIter >= theArgNb)
7383 {
7384 std::cout << "Syntax error at " << anArg << ".\n";
7385 return 1;
7386 }
7387
7388 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
7389 }
bf7b2ceb 7390 // animation definition options
1beb58d7 7391 else if (anArg == "-start"
7392 || anArg == "-starttime"
7393 || anArg == "-startpts")
7394 {
7395 if (++anArgIter >= theArgNb)
7396 {
7397 std::cout << "Syntax error at " << anArg << ".\n";
7398 return 1;
7399 }
7400
7401 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
7402 aRootAnimation->UpdateTotalDuration();
7403 }
7404 else if (anArg == "-end"
7405 || anArg == "-endtime"
7406 || anArg == "-endpts")
7407 {
7408 if (++anArgIter >= theArgNb)
7409 {
7410 std::cout << "Syntax error at " << anArg << ".\n";
7411 return 1;
7412 }
7413
7414 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
7415 aRootAnimation->UpdateTotalDuration();
7416 }
7417 else if (anArg == "-dur"
7418 || anArg == "-duration")
7419 {
7420 if (++anArgIter >= theArgNb)
7421 {
7422 std::cout << "Syntax error at " << anArg << ".\n";
7423 return 1;
7424 }
7425
7426 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
7427 aRootAnimation->UpdateTotalDuration();
7428 }
7429 else if (anArg == "-command"
7430 || anArg == "-cmd"
7431 || anArg == "-invoke"
7432 || anArg == "-eval"
7433 || anArg == "-proc")
7434 {
7435 if (++anArgIter >= theArgNb)
7436 {
7437 std::cout << "Syntax error at " << anArg << ".\n";
7438 return 1;
7439 }
7440
7441 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
7442 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
7443 }
7444 else if (anArg == "-objecttrsf"
7445 || anArg == "-objectransformation"
7446 || anArg == "-objtransformation"
7447 || anArg == "-objtrsf"
7448 || anArg == "-object"
7449 || anArg == "-obj")
7450 {
7451 if (++anArgIter >= theArgNb)
7452 {
7453 std::cout << "Syntax error at " << anArg << ".\n";
7454 return 1;
7455 }
7456
7457 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
7458 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
7459 if (!aMapOfAIS.IsBound2 (anObjName))
7460 {
7461 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
7462 return 1;
7463 }
7464
7465 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapOfAIS.Find2 (anObjName));
7466 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
7467 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
7468 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
7469 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
7470 Standard_Boolean isTrsfSet = Standard_False;
7471 Standard_Integer aTrsfArgIter = anArgIter + 1;
7472 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
7473 {
7474 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
7475 aTrsfArg.LowerCase();
7476 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
7477 if (aTrsfArg.StartsWith ("-rotation")
7478 || aTrsfArg.StartsWith ("-rot"))
7479 {
7480 isTrsfSet = Standard_True;
7481 if (aTrsfArgIter + 4 >= theArgNb
7482 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
7483 {
7484 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7485 return 1;
7486 }
7487 aTrsfArgIter += 4;
7488 }
7489 else if (aTrsfArg.StartsWith ("-location")
7490 || aTrsfArg.StartsWith ("-loc"))
7491 {
7492 isTrsfSet = Standard_True;
7493 if (aTrsfArgIter + 3 >= theArgNb
7494 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
7495 {
7496 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7497 return 1;
7498 }
7499 aTrsfArgIter += 3;
7500 }
7501 else if (aTrsfArg.StartsWith ("-scale"))
7502 {
7503 isTrsfSet = Standard_True;
7504 if (++aTrsfArgIter >= theArgNb)
7505 {
7506 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7507 return 1;
7508 }
7509
7510 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
7511 if (!aScaleStr.IsRealValue())
7512 {
7513 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7514 return 1;
7515 }
7516 aScales[anIndex] = aScaleStr.RealValue();
7517 }
7518 else
7519 {
7520 anArgIter = aTrsfArgIter - 1;
7521 break;
7522 }
7523 }
7524 if (!isTrsfSet)
7525 {
7526 std::cout << "Syntax error at " << anArg << ".\n";
7527 return 1;
7528 }
7529 else if (aTrsfArgIter >= theArgNb)
7530 {
7531 anArgIter = theArgNb;
7532 }
7533
7534 aTrsfs[0].SetRotation (aRotQuats[0]);
7535 aTrsfs[1].SetRotation (aRotQuats[1]);
7536 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
7537 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
7538 aTrsfs[0].SetScaleFactor (aScales[0]);
7539 aTrsfs[1].SetScaleFactor (aScales[1]);
7540
7541 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
7542 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
7543 }
7544 else if (anArg == "-viewtrsf"
7545 || anArg == "-view")
7546 {
7547 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
7548 if (aCamAnimation.IsNull())
7549 {
7550 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
7551 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
7552 }
7553
7554 Handle(Graphic3d_Camera) aCams[2] =
7555 {
7556 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
7557 new Graphic3d_Camera (aCamAnimation->View()->Camera())
7558 };
7559
7560 Standard_Boolean isTrsfSet = Standard_False;
7561 Standard_Integer aViewArgIter = anArgIter + 1;
7562 for (; aViewArgIter < theArgNb; ++aViewArgIter)
7563 {
7564 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
7565 aViewArg.LowerCase();
7566 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
7567 if (aViewArg.StartsWith ("-scale"))
7568 {
7569 isTrsfSet = Standard_True;
7570 if (++aViewArgIter >= theArgNb)
7571 {
7572 std::cout << "Syntax error at " << anArg << ".\n";
7573 return 1;
7574 }
7575
7576 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
7577 if (!aScaleStr.IsRealValue())
7578 {
7579 std::cout << "Syntax error at " << aViewArg << ".\n";
7580 return 1;
7581 }
7582 Standard_Real aScale = aScaleStr.RealValue();
7583 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
7584 aCams[anIndex]->SetScale (aScale);
7585 }
7586 else if (aViewArg.StartsWith ("-eye")
7587 || aViewArg.StartsWith ("-center")
7588 || aViewArg.StartsWith ("-at")
7589 || aViewArg.StartsWith ("-up"))
7590 {
7591 isTrsfSet = Standard_True;
7592 gp_XYZ anXYZ;
7593 if (aViewArgIter + 3 >= theArgNb
7594 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
7595 {
7596 std::cout << "Syntax error at " << aViewArg << ".\n";
7597 return 1;
7598 }
7599 aViewArgIter += 3;
7600
7601 if (aViewArg.StartsWith ("-eye"))
7602 {
7603 aCams[anIndex]->SetEye (anXYZ);
7604 }
7605 else if (aViewArg.StartsWith ("-center")
7606 || aViewArg.StartsWith ("-at"))
7607 {
7608 aCams[anIndex]->SetCenter (anXYZ);
7609 }
7610 else if (aViewArg.StartsWith ("-up"))
7611 {
7612 aCams[anIndex]->SetUp (anXYZ);
7613 }
7614 }
7615 else
7616 {
7617 anArgIter = aViewArgIter - 1;
7618 break;
7619 }
7620 }
7621 if (!isTrsfSet)
7622 {
7623 std::cout << "Syntax error at " << anArg << ".\n";
7624 return 1;
7625 }
7626 else if (aViewArgIter >= theArgNb)
7627 {
7628 anArgIter = theArgNb;
7629 }
7630
7631 aCamAnimation->SetCameraStart(aCams[0]);
7632 aCamAnimation->SetCameraEnd (aCams[1]);
197ac94e 7633 }
7634 else
7635 {
1beb58d7 7636 std::cout << "Syntax error at " << anArg << ".\n";
7637 return 1;
197ac94e 7638 }
7639 }
1beb58d7 7640
08f8a185 7641 if (!toPlay && aRecFile.IsEmpty())
197ac94e 7642 {
1beb58d7 7643 return 0;
7644 }
7645
7646 // Start animation timeline and process frame updating.
7647 TheIsAnimating = Standard_True;
7648 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
7649 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
bf7b2ceb 7650 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
1beb58d7 7651 if (isFreeCamera)
7652 {
7653 aView->Camera()->Copy (aCameraBack);
7654 }
7655
7656 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
08f8a185 7657 if (aRecParams.FpsNum <= 0)
1beb58d7 7658 {
7659 while (!anAnimation->IsStopped())
197ac94e 7660 {
1beb58d7 7661 aCameraBack->Copy (aView->Camera());
7662 const Standard_Real aPts = anAnimation->UpdateTimer();
7663 if (isFreeCamera)
7664 {
7665 aView->Camera()->Copy (aCameraBack);
7666 }
7667
7668 if (aPts >= anUpperPts)
7669 {
7670 anAnimation->Pause();
7671 break;
7672 }
7673
7674 if (aView->IsInvalidated())
7675 {
7676 aView->Redraw();
7677 }
7678 else
7679 {
7680 aView->RedrawImmediate();
7681 }
7682
7683 if (!isLockLoop)
7684 {
7685 // handle user events
7686 theDI.Eval ("after 1 set waiter 1");
7687 theDI.Eval ("vwait waiter");
7688 }
7689 if (!TheIsAnimating)
7690 {
7691 anAnimation->Pause();
7692 theDI << aPts;
7693 break;
7694 }
7695 }
7696
7697 if (aView->IsInvalidated())
7698 {
7699 aView->Redraw();
197ac94e 7700 }
7701 else
7702 {
1beb58d7 7703 aView->RedrawImmediate();
197ac94e 7704 }
7705 }
1beb58d7 7706 else
197ac94e 7707 {
bf7b2ceb 7708 OSD_Timer aPerfTimer;
7709 aPerfTimer.Start();
1beb58d7 7710
08f8a185 7711 Handle(Image_VideoRecorder) aRecorder;
7712 ImageFlipper aFlipper;
7713 Handle(Draw_ProgressIndicator) aProgress;
7714 if (!aRecFile.IsEmpty())
7715 {
7716 if (aRecParams.Width <= 0
7717 || aRecParams.Height <= 0)
7718 {
7719 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
7720 }
7721
7722 aRecorder = new Image_VideoRecorder();
7723 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
7724 {
7725 std::cout << "Error: failed to open video file for recording\n";
7726 return 0;
7727 }
7728
7729 aProgress = new Draw_ProgressIndicator (theDI, 1);
7730 }
7731
1beb58d7 7732 // Manage frame-rated animation here
7733 Standard_Real aPts = aPlayStartTime;
bf7b2ceb 7734 int64_t aNbFrames = 0;
08f8a185 7735 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
7736 Standard_Integer aSecondsProgress = 0;
7737 for (; aPts <= anUpperPts && aPSentry.More();)
197ac94e 7738 {
08f8a185 7739 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
bf7b2ceb 7740 aPts = aPlayStartTime + aRecPts;
7741 ++aNbFrames;
1beb58d7 7742 if (!anAnimation->Update (aPts))
7743 {
7744 break;
7745 }
7746
08f8a185 7747 if (!aRecorder.IsNull())
7748 {
7749 V3d_ImageDumpOptions aDumpParams;
7750 aDumpParams.Width = aRecParams.Width;
7751 aDumpParams.Height = aRecParams.Height;
7752 aDumpParams.BufferType = Graphic3d_BT_RGBA;
7753 aDumpParams.StereoOptions = V3d_SDO_MONO;
7754 aDumpParams.ToAdjustAspect = Standard_True;
7755 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
7756 {
7757 std::cout << "Error: view dump is failed!\n";
7758 return 0;
7759 }
7760 aFlipper.FlipY (aRecorder->ChangeFrame());
7761 if (!aRecorder->PushFrame())
7762 {
7763 return 0;
7764 }
7765 }
7766 else
7767 {
7768 aView->Redraw();
7769 }
7770
7771 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
7772 {
7773 aPSentry.Next();
7774 ++aSecondsProgress;
7775 }
197ac94e 7776 }
bf7b2ceb 7777
7778 aPerfTimer.Stop();
1beb58d7 7779 anAnimation->Stop();
bf7b2ceb 7780 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
7781 theDI << "Average FPS: " << aRecFps << "\n"
7782 << "Nb. Frames: " << Standard_Real(aNbFrames);
7783
7784 aView->Redraw();
197ac94e 7785 }
7786
1beb58d7 7787 aView->SetImmediateUpdate (wasImmediateUpdate);
7788 TheIsAnimating = Standard_False;
4754e164 7789 return 0;
7790}
7791
1beb58d7 7792
4754e164 7793//=======================================================================
7794//function : VChangeSelected
dc3fe572 7795//purpose : Adds the shape to selection or remove one from it
4754e164 7796//=======================================================================
7797static Standard_Integer VChangeSelected (Draw_Interpretor& di,
7798 Standard_Integer argc,
7799 const char ** argv)
7800{
7801 if(argc != 2)
7802 {
7803 di<<"Usage : " << argv[0] << " shape \n";
7804 return 1;
7805 }
7806 //get AIS_Shape:
7807 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7808 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
7809 TCollection_AsciiString aName(argv[1]);
7810 Handle(AIS_InteractiveObject) anAISObject;
7811
7812 if(!aMap.IsBound2(aName))
7813 {
7814 di<<"Use 'vdisplay' before";
7815 return 1;
7816 }
7817 else
7818 {
7819 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
7820 if(anAISObject.IsNull()){
7821 di<<"No interactive object \n";
7822 return 1;
7823 }
7824
0577ae8c 7825 aContext->AddOrRemoveSelected(anAISObject, Standard_True);
4754e164 7826 }
7827 return 0;
7828}
7829
4754e164 7830//=======================================================================
7831//function : VNbSelected
dc3fe572 7832//purpose : Returns number of selected objects
4754e164 7833//=======================================================================
7834static Standard_Integer VNbSelected (Draw_Interpretor& di,
7835 Standard_Integer argc,
7836 const char ** argv)
7837{
7838 if(argc != 1)
7839 {
7840 di << "Usage : " << argv[0] << "\n";
7841 return 1;
7842 }
7843 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7844 if(aContext.IsNull())
7845 {
7846 di << "use 'vinit' command before " << argv[0] << "\n";
7847 return 1;
7848 }
7849 di << aContext->NbSelected() << "\n";
7850 return 0;
7851}
7852
4754e164 7853//=======================================================================
7854//function : VPurgeDisplay
dc3fe572 7855//purpose : Switches altialiasing on or off
4754e164 7856//=======================================================================
7857static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
7858 Standard_Integer argc,
7859 const char ** argv)
7860{
eb4320f2 7861 if (argc > 1)
4754e164 7862 {
eb4320f2 7863 di << "Usage : " << argv[0] << "\n";
4754e164 7864 return 1;
7865 }
4754e164 7866 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7867 if (aContext.IsNull())
7868 {
7869 di << "use 'vinit' command before " << argv[0] << "\n";
7870 return 1;
7871 }
404c8936 7872
eb4320f2 7873 di << aContext->PurgeDisplay() << "\n";
4754e164 7874 return 0;
7875}
7876
7877//=======================================================================
7878//function : VSetViewSize
7879//purpose :
7880//=======================================================================
7881static Standard_Integer VSetViewSize (Draw_Interpretor& di,
7882 Standard_Integer argc,
7883 const char ** argv)
7884{
7885 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7886 if(aContext.IsNull())
7887 {
7888 di << "use 'vinit' command before " << argv[0] << "\n";
7889 return 1;
7890 }
7891 if(argc != 2)
7892 {
7893 di<<"Usage : " << argv[0] << " Size\n";
7894 return 1;
7895 }
6b62b2da 7896 Standard_Real aSize = Draw::Atof (argv[1]);
4754e164 7897 if (aSize <= 0.)
7898 {
7899 di<<"Bad Size value : " << aSize << "\n";
7900 return 1;
7901 }
7902
7903 Handle(V3d_View) aView = ViewerTest::CurrentView();
7904 aView->SetSize(aSize);
7905 return 0;
7906}
7907
7908//=======================================================================
7909//function : VMoveView
7910//purpose :
7911//=======================================================================
7912static Standard_Integer VMoveView (Draw_Interpretor& di,
7913 Standard_Integer argc,
7914 const char ** argv)
7915{
7916 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7917 if(aContext.IsNull())
7918 {
7919 di << "use 'vinit' command before " << argv[0] << "\n";
7920 return 1;
7921 }
7922 if(argc < 4 || argc > 5)
7923 {
7924 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7925 return 1;
7926 }
6b62b2da 7927 Standard_Real Dx = Draw::Atof (argv[1]);
7928 Standard_Real Dy = Draw::Atof (argv[2]);
7929 Standard_Real Dz = Draw::Atof (argv[3]);
4754e164 7930 Standard_Boolean aStart = Standard_True;
7931 if (argc == 5)
7932 {
6b62b2da 7933 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 7934 }
7935
7936 Handle(V3d_View) aView = ViewerTest::CurrentView();
7937 aView->Move(Dx,Dy,Dz,aStart);
7938 return 0;
7939}
7940
7941//=======================================================================
7942//function : VTranslateView
7943//purpose :
7944//=======================================================================
7945static Standard_Integer VTranslateView (Draw_Interpretor& di,
7946 Standard_Integer argc,
7947 const char ** argv)
7948{
7949 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7950 if(aContext.IsNull())
7951 {
7952 di << "use 'vinit' command before " << argv[0] << "\n";
7953 return 1;
7954 }
7955 if(argc < 4 || argc > 5)
7956 {
7957 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7958 return 1;
7959 }
6b62b2da 7960 Standard_Real Dx = Draw::Atof (argv[1]);
7961 Standard_Real Dy = Draw::Atof (argv[2]);
7962 Standard_Real Dz = Draw::Atof (argv[3]);
4754e164 7963 Standard_Boolean aStart = Standard_True;
dc3fe572 7964 if (argc == 5)
4754e164 7965 {
6b62b2da 7966 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 7967 }
7968
7969 Handle(V3d_View) aView = ViewerTest::CurrentView();
7970 aView->Translate(Dx,Dy,Dz,aStart);
7971 return 0;
7972}
7973
7974//=======================================================================
7975//function : VTurnView
7976//purpose :
7977//=======================================================================
7978static Standard_Integer VTurnView (Draw_Interpretor& di,
7979 Standard_Integer argc,
7980 const char ** argv)
7981{
7982 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7983 if(aContext.IsNull()) {
7984 di << "use 'vinit' command before " << argv[0] << "\n";
7985 return 1;
7986 }
7987 if(argc < 4 || argc > 5){
7988 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
7989 return 1;
7990 }
6b62b2da 7991 Standard_Real Ax = Draw::Atof (argv[1]);
7992 Standard_Real Ay = Draw::Atof (argv[2]);
7993 Standard_Real Az = Draw::Atof (argv[3]);
4754e164 7994 Standard_Boolean aStart = Standard_True;
dc3fe572 7995 if (argc == 5)
4754e164 7996 {
6b62b2da 7997 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 7998 }
7999
8000 Handle(V3d_View) aView = ViewerTest::CurrentView();
8001 aView->Turn(Ax,Ay,Az,aStart);
8002 return 0;
8003}
8004
269294d6 8005//==============================================================================
8006//function : VTextureEnv
8007//purpose : ENables or disables environment mapping
8008//==============================================================================
8009class OCC_TextureEnv : public Graphic3d_TextureEnv
8010{
8011public:
8012 OCC_TextureEnv(const Standard_CString FileName);
8013 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
8014 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
8015 const Standard_Boolean theModulateFlag,
8016 const Graphic3d_TypeOfTextureFilter theFilter,
8017 const Standard_ShortReal theXScale,
8018 const Standard_ShortReal theYScale,
8019 const Standard_ShortReal theXShift,
8020 const Standard_ShortReal theYShift,
8021 const Standard_ShortReal theAngle);
68858c7d 8022 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
269294d6 8023};
a3f6f591 8024DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
ec357c5c 8025
269294d6 8026OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
8027 : Graphic3d_TextureEnv(theFileName)
8028{
8029}
8030
8031OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
8032 : Graphic3d_TextureEnv(theTexId)
8033{
8034}
8035
8036void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
8037 const Standard_Boolean theModulateFlag,
8038 const Graphic3d_TypeOfTextureFilter theFilter,
8039 const Standard_ShortReal theXScale,
8040 const Standard_ShortReal theYScale,
8041 const Standard_ShortReal theXShift,
8042 const Standard_ShortReal theYShift,
8043 const Standard_ShortReal theAngle)
8044{
8045 myParams->SetRepeat (theRepeatFlag);
8046 myParams->SetModulate (theModulateFlag);
8047 myParams->SetFilter (theFilter);
8048 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
8049 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
8050 myParams->SetRotation (theAngle);
8051}
8052
35e08fe8 8053static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
269294d6 8054{
8055 // get the active view
8056 Handle(V3d_View) aView = ViewerTest::CurrentView();
8057 if (aView.IsNull())
8058 {
8059 std::cerr << "No active view. Please call vinit.\n";
8060 return 1;
8061 }
8062
8063 // Checking the input arguments
8064 Standard_Boolean anEnableFlag = Standard_False;
8065 Standard_Boolean isOk = theArgNb >= 2;
8066 if (isOk)
8067 {
8068 TCollection_AsciiString anEnableOpt(theArgVec[1]);
8069 anEnableFlag = anEnableOpt.IsEqual("on");
8070 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
8071 }
8072 if (anEnableFlag)
8073 {
8074 isOk = (theArgNb == 3 || theArgNb == 11);
8075 if (isOk)
8076 {
8077 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8078 isOk = (!aTextureOpt.IsIntegerValue() ||
8079 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
8080
8081 if (isOk && theArgNb == 11)
8082 {
8083 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
8084 aModulateOpt(theArgVec[4]),
8085 aFilterOpt (theArgVec[5]),
8086 aSScaleOpt (theArgVec[6]),
8087 aTScaleOpt (theArgVec[7]),
8088 aSTransOpt (theArgVec[8]),
8089 aTTransOpt (theArgVec[9]),
8090 anAngleOpt (theArgVec[10]);
8091 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
8092 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
8093 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
8094 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
8095 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
8096 anAngleOpt.IsRealValue());
8097 }
8098 }
8099 }
8100
8101 if (!isOk)
8102 {
8103 std::cerr << "Usage :" << std::endl;
8104 std::cerr << theArgVec[0] << " off" << std::endl;
8105 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;
8106 return 1;
8107 }
8108
8109 if (anEnableFlag)
8110 {
8111 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8112 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
8113 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
8114 new OCC_TextureEnv(theArgVec[2]);
8115
8116 if (theArgNb == 11)
8117 {
8118 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
8119 aTexEnv->SetTextureParameters(
8120 aRepeatOpt. IsEqual("repeat"),
8121 aModulateOpt.IsEqual("modulate"),
8122 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
8123 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
8124 Graphic3d_TOTF_TRILINEAR,
8125 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
8126 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
8127 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
8128 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
8129 (Standard_ShortReal)Draw::Atof(theArgVec[10])
8130 );
8131 }
8132 aView->SetTextureEnv(aTexEnv);
269294d6 8133 }
8134 else // Disabling environment mapping
8135 {
269294d6 8136 Handle(Graphic3d_TextureEnv) aTexture;
8137 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
8138 }
8139
8140 aView->Redraw();
8141 return 0;
8142}
8143
3e05329c 8144namespace
8145{
8146 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
8147
8148 //! Remove registered clipping plane from all views and objects.
8149 static void removePlane (MapOfPlanes& theRegPlanes,
8150 const TCollection_AsciiString& theName)
8151 {
8152 Handle(Graphic3d_ClipPlane) aClipPlane;
8153 if (!theRegPlanes.Find (theName, aClipPlane))
8154 {
8155 std::cout << "Warning: no such plane.\n";
8156 return;
8157 }
8158
8159 theRegPlanes.UnBind (theName);
8160 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
8161 anIObjIt.More(); anIObjIt.Next())
8162 {
8163 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
8164 aPrs->RemoveClipPlane (aClipPlane);
8165 }
8166
8167 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
8168 aViewIt.More(); aViewIt.Next())
8169 {
8170 const Handle(V3d_View)& aView = aViewIt.Key2();
8171 aView->RemoveClipPlane(aClipPlane);
8172 }
8173
8174 ViewerTest::RedrawAllViews();
8175 }
8176}
8177
4269bd1b 8178//===============================================================================================
8179//function : VClipPlane
8180//purpose :
8181//===============================================================================================
8182static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8183{
8184 // use short-cut for created clip planes map of created (or "registered by name") clip planes
4269bd1b 8185 static MapOfPlanes aRegPlanes;
8186
8187 if (theArgsNb < 2)
8188 {
3e05329c 8189 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
8190 {
8191 theDi << aPlaneIter.Key() << " ";
8192 }
8193 return 0;
4269bd1b 8194 }
8195
8196 TCollection_AsciiString aCommand (theArgVec[1]);
3e05329c 8197 aCommand.LowerCase();
8198 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
8199 if (anActiveView.IsNull())
8200 {
8201 std::cout << "Error: no active view.\n";
8202 return 1;
8203 }
4269bd1b 8204
8205 // print maximum number of planes for current viewer
3e05329c 8206 if (aCommand == "-maxplanes"
8207 || aCommand == "maxplanes")
4269bd1b 8208 {
3e05329c 8209 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
8210 << " plane slots provided by driver.\n";
4269bd1b 8211 return 0;
8212 }
8213
8214 // create / delete plane instance
3e05329c 8215 if (aCommand == "-create"
8216 || aCommand == "create"
8217 || aCommand == "-delete"
8218 || aCommand == "delete"
8219 || aCommand == "-clone"
8220 || aCommand == "clone")
4269bd1b 8221 {
8222 if (theArgsNb < 3)
8223 {
3e05329c 8224 std::cout << "Syntax error: plane name is required.\n";
4269bd1b 8225 return 1;
8226 }
8227
3e05329c 8228 Standard_Boolean toCreate = aCommand == "-create"
8229 || aCommand == "create";
8230 Standard_Boolean toClone = aCommand == "-clone"
8231 || aCommand == "clone";
8232 Standard_Boolean toDelete = aCommand == "-delete"
8233 || aCommand == "delete";
4269bd1b 8234 TCollection_AsciiString aPlane (theArgVec[2]);
8235
8236 if (toCreate)
8237 {
8238 if (aRegPlanes.IsBound (aPlane))
8239 {
3e05329c 8240 std::cout << "Warning: existing plane has been overridden.\n";
8241 toDelete = true;
8242 }
8243 else
8244 {
8245 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8246 return 0;
4269bd1b 8247 }
4269bd1b 8248 }
8249 else if (toClone) // toClone
8250 {
8251 if (!aRegPlanes.IsBound (aPlane))
8252 {
3e05329c 8253 std::cout << "Error: no such plane.\n";
4269bd1b 8254 return 1;
8255 }
3e05329c 8256 else if (theArgsNb < 4)
4269bd1b 8257 {
3e05329c 8258 std::cout << "Syntax error: enter name for new plane.\n";
4269bd1b 8259 return 1;
8260 }
8261
8262 TCollection_AsciiString aClone (theArgVec[3]);
8263 if (aRegPlanes.IsBound (aClone))
8264 {
3e05329c 8265 std::cout << "Error: plane name is in use.\n";
4269bd1b 8266 return 1;
8267 }
8268
8269 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
8270
8271 aRegPlanes.Bind (aClone, aClipPlane->Clone());
3e05329c 8272 return 0;
4269bd1b 8273 }
4269bd1b 8274
3e05329c 8275 if (toDelete)
8276 {
8277 if (aPlane == "ALL"
8278 || aPlane == "all"
8279 || aPlane == "*")
4269bd1b 8280 {
3e05329c 8281 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
8282 {
8283 aPlane = aPlaneIter.Key();
8284 removePlane (aRegPlanes, aPlane);
8285 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
8286 }
4269bd1b 8287 }
3e05329c 8288 else
4269bd1b 8289 {
3e05329c 8290 removePlane (aRegPlanes, aPlane);
4269bd1b 8291 }
4269bd1b 8292 }
8293
3e05329c 8294 if (toCreate)
8295 {
8296 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8297 }
4269bd1b 8298 return 0;
8299 }
8300
8301 // set / unset plane command
3e05329c 8302 if (aCommand == "set"
8303 || aCommand == "unset")
4269bd1b 8304 {
3e05329c 8305 if (theArgsNb < 5)
4269bd1b 8306 {
3e05329c 8307 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 8308 return 1;
8309 }
8310
3e05329c 8311 // redirect to new syntax
8312 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
8313 anArgVec.SetValue (1, theArgVec[0]);
8314 anArgVec.SetValue (2, theArgVec[2]);
8315 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
8316 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
4269bd1b 8317 {
3e05329c 8318 anArgVec.SetValue (anIt, theArgVec[anIt]);
4269bd1b 8319 }
8320
3e05329c 8321 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
4269bd1b 8322 }
8323
8324 // change plane command
3e05329c 8325 TCollection_AsciiString aPlaneName;
8326 Handle(Graphic3d_ClipPlane) aClipPlane;
8327 Standard_Integer anArgIter = 0;
8328 if (aCommand == "-change"
8329 || aCommand == "change")
4269bd1b 8330 {
3e05329c 8331 // old syntax support
8332 if (theArgsNb < 3)
4269bd1b 8333 {
3e05329c 8334 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 8335 return 1;
8336 }
8337
3e05329c 8338 anArgIter = 3;
8339 aPlaneName = theArgVec[2];
8340 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
4269bd1b 8341 {
3e05329c 8342 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
4269bd1b 8343 return 1;
8344 }
3e05329c 8345 }
8346 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
8347 {
8348 anArgIter = 2;
8349 aPlaneName = theArgVec[1];
8350 }
8351 else
8352 {
8353 anArgIter = 2;
8354 aPlaneName = theArgVec[1];
8355 aClipPlane = new Graphic3d_ClipPlane();
8356 aRegPlanes.Bind (aPlaneName, aClipPlane);
8357 theDi << "Created new plane " << aPlaneName << ".\n";
8358 }
4269bd1b 8359
3e05329c 8360 if (theArgsNb - anArgIter < 1)
8361 {
8362 std::cout << "Syntax error: need more arguments.\n";
8363 return 1;
8364 }
4269bd1b 8365
3e05329c 8366 for (; anArgIter < theArgsNb; ++anArgIter)
8367 {
8368 const char** aChangeArgs = theArgVec + anArgIter;
8369 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
8370 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
8371 aChangeArg.LowerCase();
4269bd1b 8372
3e05329c 8373 Standard_Boolean toEnable = Standard_True;
8374 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
4269bd1b 8375 {
3e05329c 8376 aClipPlane->SetOn (toEnable);
4269bd1b 8377 }
25c35042 8378 else if (aChangeArg.StartsWith ("-equation")
8379 || aChangeArg.StartsWith ("equation"))
4269bd1b 8380 {
3e05329c 8381 if (aNbChangeArgs < 5)
4269bd1b 8382 {
3e05329c 8383 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 8384 return 1;
8385 }
8386
25c35042 8387 Standard_Integer aSubIndex = 1;
8388 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
8389 if (aPrefixLen < aChangeArg.Length())
8390 {
8391 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
8392 if (!aSubStr.IsIntegerValue()
8393 || aSubStr.IntegerValue() <= 0)
8394 {
8395 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8396 return 1;
8397 }
8398 aSubIndex = aSubStr.IntegerValue();
8399 }
8400
8401 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
8402 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
8403 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
8404 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
8405 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8406 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
8407 {
8408 if (aSubPln->ChainNextPlane().IsNull())
8409 {
8410 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8411 }
8412 aSubPln = aSubPln->ChainNextPlane();
8413 }
8414 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8415 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
3e05329c 8416 anArgIter += 4;
4269bd1b 8417 }
25c35042 8418 else if ((aChangeArg == "-boxinterior"
8419 || aChangeArg == "-boxint"
8420 || aChangeArg == "-box")
8421 && aNbChangeArgs >= 7)
8422 {
8423 Graphic3d_BndBox3d aBndBox;
8424 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
8425 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
8426 anArgIter += 6;
8427
8428 Standard_Integer aNbSubPlanes = 6;
8429 const Graphic3d_Vec3d aDirArray[6] =
8430 {
8431 Graphic3d_Vec3d (-1, 0, 0),
8432 Graphic3d_Vec3d ( 1, 0, 0),
8433 Graphic3d_Vec3d ( 0,-1, 0),
8434 Graphic3d_Vec3d ( 0, 1, 0),
8435 Graphic3d_Vec3d ( 0, 0,-1),
8436 Graphic3d_Vec3d ( 0, 0, 1),
8437 };
8438 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8439 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
8440 {
8441 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
8442 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
8443 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
8444 if (aSubPlaneIter + 1 == aNbSubPlanes)
8445 {
8446 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8447 }
8448 else
8449 {
8450 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8451 }
8452 aSubPln = aSubPln->ChainNextPlane();
8453 }
8454 }
3e05329c 8455 else if (aChangeArg == "-capping"
8456 || aChangeArg == "capping")
4269bd1b 8457 {
3e05329c 8458 if (aNbChangeArgs < 2)
4269bd1b 8459 {
3e05329c 8460 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 8461 return 1;
8462 }
8463
3e05329c 8464 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
4269bd1b 8465 {
3e05329c 8466 aClipPlane->SetCapping (toEnable);
8467 anArgIter += 1;
8468 }
8469 else
8470 {
8471 // just skip otherwise (old syntax)
8472 }
8473 }
8474 else if (aChangeArg == "-useobjectmaterial"
8475 || aChangeArg == "-useobjectmat"
8476 || aChangeArg == "-useobjmat"
8477 || aChangeArg == "-useobjmaterial")
8478 {
8479 if (aNbChangeArgs < 2)
8480 {
8481 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 8482 return 1;
8483 }
8484
3e05329c 8485 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
4269bd1b 8486 {
3e05329c 8487 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
8488 anArgIter += 1;
4269bd1b 8489 }
3e05329c 8490 }
8491 else if (aChangeArg == "-useobjecttexture"
8492 || aChangeArg == "-useobjecttex"
8493 || aChangeArg == "-useobjtexture"
8494 || aChangeArg == "-useobjtex")
8495 {
8496 if (aNbChangeArgs < 2)
4269bd1b 8497 {
3e05329c 8498 std::cout << "Syntax error: need more arguments.\n";
8499 return 1;
8500 }
4269bd1b 8501
3e05329c 8502 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8503 {
8504 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
8505 anArgIter += 1;
8506 }
8507 }
8508 else if (aChangeArg == "-useobjectshader"
8509 || aChangeArg == "-useobjshader")
8510 {
8511 if (aNbChangeArgs < 2)
8512 {
8513 std::cout << "Syntax error: need more arguments.\n";
8514 return 1;
8515 }
4269bd1b 8516
3e05329c 8517 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8518 {
8519 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
8520 anArgIter += 1;
4269bd1b 8521 }
3e05329c 8522 }
8523 else if (aChangeArg == "-color"
8524 || aChangeArg == "color")
8525 {
8526 Quantity_Color aColor;
8527 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
8528 aChangeArgs + 1,
8529 aColor);
8530 if (aNbParsed == 0)
4269bd1b 8531 {
3e05329c 8532 std::cout << "Syntax error: need more arguments.\n";
8533 return 1;
8534 }
4269bd1b 8535
3e05329c 8536 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8537 aMat.SetAmbientColor (aColor);
8538 aMat.SetDiffuseColor (aColor);
8539 aClipPlane->SetCappingMaterial (aMat);
8540 anArgIter += aNbParsed;
8541 }
8542 else if (aChangeArg == "-texname"
8543 || aChangeArg == "texname")
8544 {
8545 if (aNbChangeArgs < 2)
8546 {
8547 std::cout << "Syntax error: need more arguments.\n";
8548 return 1;
8549 }
4269bd1b 8550
3e05329c 8551 TCollection_AsciiString aTextureName (aChangeArgs[1]);
8552 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
8553 if (!aTexture->IsDone())
8554 {
8555 aClipPlane->SetCappingTexture (NULL);
4269bd1b 8556 }
3e05329c 8557 else
4269bd1b 8558 {
3e05329c 8559 aTexture->EnableModulate();
8560 aTexture->EnableRepeat();
8561 aClipPlane->SetCappingTexture (aTexture);
8562 }
8563 anArgIter += 1;
8564 }
8565 else if (aChangeArg == "-texscale"
8566 || aChangeArg == "texscale")
8567 {
8568 if (aClipPlane->CappingTexture().IsNull())
8569 {
8570 std::cout << "Error: no texture is set.\n";
8571 return 1;
8572 }
4269bd1b 8573
3e05329c 8574 if (aNbChangeArgs < 3)
8575 {
8576 std::cout << "Syntax error: need more arguments.\n";
8577 return 1;
8578 }
4269bd1b 8579
3e05329c 8580 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8581 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8582 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
8583 anArgIter += 2;
8584 }
8585 else if (aChangeArg == "-texorigin"
8586 || aChangeArg == "texorigin") // texture origin
8587 {
8588 if (aClipPlane->CappingTexture().IsNull())
8589 {
8590 std::cout << "Error: no texture is set.\n";
8591 return 1;
8592 }
4269bd1b 8593
3e05329c 8594 if (aNbChangeArgs < 3)
8595 {
8596 std::cout << "Syntax error: need more arguments.\n";
8597 return 1;
4269bd1b 8598 }
3e05329c 8599
8600 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8601 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8602
8603 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
8604 anArgIter += 2;
8605 }
8606 else if (aChangeArg == "-texrotate"
8607 || aChangeArg == "texrotate") // texture rotation
8608 {
8609 if (aClipPlane->CappingTexture().IsNull())
4269bd1b 8610 {
3e05329c 8611 std::cout << "Error: no texture is set.\n";
8612 return 1;
8613 }
4269bd1b 8614
3e05329c 8615 if (aNbChangeArgs < 2)
8616 {
8617 std::cout << "Syntax error: need more arguments.\n";
8618 return 1;
8619 }
4269bd1b 8620
3e05329c 8621 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8622 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8623 anArgIter += 1;
8624 }
8625 else if (aChangeArg == "-hatch"
8626 || aChangeArg == "hatch")
8627 {
8628 if (aNbChangeArgs < 2)
8629 {
8630 std::cout << "Syntax error: need more arguments.\n";
8631 return 1;
8632 }
4269bd1b 8633
3e05329c 8634 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8635 aHatchStr.LowerCase();
8636 if (aHatchStr == "on")
8637 {
8638 aClipPlane->SetCappingHatchOn();
8639 }
8640 else if (aHatchStr == "off")
8641 {
8642 aClipPlane->SetCappingHatchOff();
4269bd1b 8643 }
3e05329c 8644 else
4269bd1b 8645 {
3e05329c 8646 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8647 }
8648 anArgIter += 1;
8649 }
8650 else if (aChangeArg == "-delete"
8651 || aChangeArg == "delete")
8652 {
8653 removePlane (aRegPlanes, aPlaneName);
8654 return 0;
8655 }
8656 else if (aChangeArg == "-set"
32ca7711 8657 || aChangeArg == "-unset"
8658 || aChangeArg == "-setoverrideglobal")
3e05329c 8659 {
8660 // set / unset plane command
32ca7711 8661 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
8662 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
3e05329c 8663 Standard_Integer anIt = 1;
8664 for (; anIt < aNbChangeArgs; ++anIt)
8665 {
8666 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8667 if (anEntityName.IsEmpty()
8668 || anEntityName.Value (1) == '-')
4269bd1b 8669 {
3e05329c 8670 break;
4269bd1b 8671 }
32ca7711 8672 else if (!toOverrideGlobal
8673 && ViewerTest_myViews.IsBound1 (anEntityName))
4269bd1b 8674 {
3e05329c 8675 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
8676 if (toSet)
8677 {
8678 aView->AddClipPlane (aClipPlane);
8679 }
8680 else
8681 {
8682 aView->RemoveClipPlane (aClipPlane);
8683 }
8684 continue;
4269bd1b 8685 }
3e05329c 8686 else if (GetMapOfAIS().IsBound2 (anEntityName))
4269bd1b 8687 {
3e05329c 8688 Handle(AIS_InteractiveObject) aIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
8689 if (toSet)
8690 {
8691 aIObj->AddClipPlane (aClipPlane);
8692 }
8693 else
8694 {
8695 aIObj->RemoveClipPlane (aClipPlane);
8696 }
32ca7711 8697 if (!aIObj->ClipPlanes().IsNull())
8698 {
8699 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
8700 }
4269bd1b 8701 }
3e05329c 8702 else
4269bd1b 8703 {
3e05329c 8704 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
8705 return 1;
4269bd1b 8706 }
3e05329c 8707 }
8708
8709 if (anIt == 1)
8710 {
8711 // apply to active view
8712 if (toSet)
4269bd1b 8713 {
3e05329c 8714 anActiveView->AddClipPlane (aClipPlane);
4269bd1b 8715 }
8716 else
8717 {
3e05329c 8718 anActiveView->RemoveClipPlane (aClipPlane);
4269bd1b 8719 }
8720 }
3e05329c 8721 else
8722 {
8723 anArgIter = anArgIter + anIt - 1;
8724 }
8725 }
8726 else
8727 {
8728 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8729 return 1;
4269bd1b 8730 }
4269bd1b 8731 }
8732
3e05329c 8733 ViewerTest::RedrawAllViews();
8734 return 0;
4269bd1b 8735}
8736
b5ac8292 8737//===============================================================================================
8738//function : VZRange
8739//purpose :
8740//===============================================================================================
8741static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8742{
197ac94e 8743 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8744
8745 if (aCurrentView.IsNull())
b5ac8292 8746 {
197ac94e 8747 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 8748 return 1;
8749 }
8750
197ac94e 8751 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
b5ac8292 8752
8753 if (theArgsNb < 2)
8754 {
8755 theDi << "ZNear: " << aCamera->ZNear() << "\n";
8756 theDi << "ZFar: " << aCamera->ZFar() << "\n";
8757 return 0;
8758 }
8759
8760 if (theArgsNb == 3)
8761 {
6b62b2da 8762 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
8763 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
197ac94e 8764
8765 if (aNewZNear >= aNewZFar)
8766 {
8767 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
8768 return 1;
8769 }
8770
8771 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
8772 {
8773 std::cout << theArgVec[0] << ": invalid arguments: ";
8774 std::cout << "znear, zfar should be positive for perspective camera.\n";
8775 return 1;
8776 }
8777
8778 aCamera->SetZRange (aNewZNear, aNewZFar);
b5ac8292 8779 }
8780 else
8781 {
197ac94e 8782 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
b5ac8292 8783 return 1;
8784 }
8785
197ac94e 8786 aCurrentView->Redraw();
8787
b5ac8292 8788 return 0;
8789}
8790
8791//===============================================================================================
8792//function : VAutoZFit
8793//purpose :
8794//===============================================================================================
8795static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8796{
197ac94e 8797 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8798
8799 if (aCurrentView.IsNull())
b5ac8292 8800 {
197ac94e 8801 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 8802 return 1;
8803 }
8804
c357e426 8805 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
197ac94e 8806
8807 if (theArgsNb > 3)
b5ac8292 8808 {
197ac94e 8809 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8810 return 1;
b5ac8292 8811 }
8812
197ac94e 8813 if (theArgsNb < 2)
b5ac8292 8814 {
586db386 8815 theDi << "Auto z-fit mode: \n"
c357e426 8816 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
197ac94e 8817 << "Scale: " << aScale << "\n";
8818 return 0;
b5ac8292 8819 }
197ac94e 8820
8821 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
8822
8823 if (theArgsNb >= 3)
b5ac8292 8824 {
197ac94e 8825 aScale = Draw::Atoi (theArgVec[2]);
b5ac8292 8826 }
8827
c357e426 8828 aCurrentView->SetAutoZFitMode (isOn, aScale);
8829 aCurrentView->AutoZFit();
197ac94e 8830 aCurrentView->Redraw();
8831
b5ac8292 8832 return 0;
8833}
8834
6b62b2da 8835//! Auxiliary function to print projection type
8836inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
8837{
8838 switch (theProjType)
8839 {
8840 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
8841 case Graphic3d_Camera::Projection_Perspective: return "perspective";
8842 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
8843 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
8844 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
8845 }
8846 return "UNKNOWN";
8847}
8848
b5ac8292 8849//===============================================================================================
6b62b2da 8850//function : VCamera
b5ac8292 8851//purpose :
8852//===============================================================================================
6b62b2da 8853static int VCamera (Draw_Interpretor& theDI,
8854 Standard_Integer theArgsNb,
8855 const char** theArgVec)
b5ac8292 8856{
6b62b2da 8857 Handle(V3d_View) aView = ViewerTest::CurrentView();
8858 if (aView.IsNull())
b5ac8292 8859 {
6b62b2da 8860 std::cout << "Error: no active view.\n";
b5ac8292 8861 return 1;
8862 }
8863
6b62b2da 8864 Handle(Graphic3d_Camera) aCamera = aView->Camera();
8865 if (theArgsNb < 2)
b5ac8292 8866 {
6b62b2da 8867 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
8868 theDI << "FOVy: " << aCamera->FOVy() << "\n";
8869 theDI << "Distance: " << aCamera->Distance() << "\n";
8870 theDI << "IOD: " << aCamera->IOD() << "\n";
8871 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
8872 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
8873 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
8874 return 0;
b5ac8292 8875 }
8876
6b62b2da 8877 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
b5ac8292 8878 {
6b62b2da 8879 Standard_CString anArg = theArgVec[anArgIter];
8880 TCollection_AsciiString anArgCase (anArg);
8881 anArgCase.LowerCase();
8882 if (anArgCase == "-proj"
8883 || anArgCase == "-projection"
8884 || anArgCase == "-projtype"
8885 || anArgCase == "-projectiontype")
8886 {
8887 theDI << projTypeName (aCamera->ProjectionType()) << " ";
8888 }
8889 else if (anArgCase == "-ortho"
8890 || anArgCase == "-orthographic")
b5ac8292 8891 {
8892 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
6b62b2da 8893 }
8894 else if (anArgCase == "-persp"
8895 || anArgCase == "-perspective"
8896 || anArgCase == "-perspmono"
8897 || anArgCase == "-perspectivemono"
8898 || anArgCase == "-mono")
b5ac8292 8899 {
8900 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
8901 }
6b62b2da 8902 else if (anArgCase == "-stereo"
8903 || anArgCase == "-stereoscopic"
8904 || anArgCase == "-perspstereo"
8905 || anArgCase == "-perspectivestereo")
8906 {
8907 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
8908 }
8909 else if (anArgCase == "-left"
8910 || anArgCase == "-lefteye"
8911 || anArgCase == "-monoleft"
8912 || anArgCase == "-monolefteye"
8913 || anArgCase == "-perpsleft"
8914 || anArgCase == "-perpslefteye")
b5ac8292 8915 {
8916 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
8917 }
6b62b2da 8918 else if (anArgCase == "-right"
8919 || anArgCase == "-righteye"
8920 || anArgCase == "-monoright"
8921 || anArgCase == "-monorighteye"
8922 || anArgCase == "-perpsright")
b5ac8292 8923 {
8924 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
8925 }
6b62b2da 8926 else if (anArgCase == "-dist"
8927 || anArgCase == "-distance")
b5ac8292 8928 {
6b62b2da 8929 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8930 if (anArgValue != NULL
8931 && *anArgValue != '-')
8932 {
8933 ++anArgIter;
8934 aCamera->SetDistance (Draw::Atof (anArgValue));
8935 continue;
8936 }
8937 theDI << aCamera->Distance() << " ";
b5ac8292 8938 }
6b62b2da 8939 else if (anArgCase == "-iod")
b5ac8292 8940 {
6b62b2da 8941 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8942 if (anArgValue != NULL
8943 && *anArgValue != '-')
8944 {
8945 ++anArgIter;
8946 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
8947 continue;
8948 }
8949 theDI << aCamera->IOD() << " ";
b5ac8292 8950 }
6b62b2da 8951 else if (anArgCase == "-iodtype")
b5ac8292 8952 {
6b62b2da 8953 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8954 TCollection_AsciiString anValueCase (anArgValue);
8955 anValueCase.LowerCase();
8956 if (anValueCase == "abs"
8957 || anValueCase == "absolute")
8958 {
8959 ++anArgIter;
8960 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
8961 continue;
8962 }
8963 else if (anValueCase == "rel"
8964 || anValueCase == "relative")
8965 {
8966 ++anArgIter;
8967 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
8968 continue;
8969 }
8970 else if (*anArgValue != '-')
8971 {
8972 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
8973 return 1;
8974 }
8975 switch (aCamera->GetIODType())
8976 {
8977 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
8978 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
8979 }
b5ac8292 8980 }
6b62b2da 8981 else if (anArgCase == "-zfocus")
b5ac8292 8982 {
6b62b2da 8983 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8984 if (anArgValue != NULL
8985 && *anArgValue != '-')
8986 {
8987 ++anArgIter;
8988 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
8989 continue;
8990 }
8991 theDI << aCamera->ZFocus() << " ";
b5ac8292 8992 }
6b62b2da 8993 else if (anArgCase == "-zfocustype")
b5ac8292 8994 {
6b62b2da 8995 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8996 TCollection_AsciiString anValueCase (anArgValue);
8997 anValueCase.LowerCase();
8998 if (anValueCase == "abs"
8999 || anValueCase == "absolute")
9000 {
9001 ++anArgIter;
9002 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
9003 continue;
9004 }
9005 else if (anValueCase == "rel"
9006 || anValueCase == "relative")
9007 {
9008 ++anArgIter;
9009 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
9010 continue;
9011 }
9012 else if (*anArgValue != '-')
9013 {
9014 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
9015 return 1;
9016 }
9017 switch (aCamera->ZFocusType())
9018 {
9019 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
9020 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
9021 }
9022 }
9023 else if (anArgCase == "-fov"
9024 || anArgCase == "-fovy")
b5ac8292 9025 {
6b62b2da 9026 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9027 if (anArgValue != NULL
9028 && *anArgValue != '-')
9029 {
9030 ++anArgIter;
9031 aCamera->SetFOVy (Draw::Atof (anArgValue));
9032 continue;
9033 }
9034 theDI << aCamera->FOVy() << " ";
b5ac8292 9035 }
9036 else
9037 {
6b62b2da 9038 std::cout << "Error: unknown argument '" << anArg << "'\n";
b5ac8292 9039 return 1;
9040 }
9041 }
b5ac8292 9042
c357e426 9043 aView->AutoZFit();
6b62b2da 9044 aView->Redraw();
b5ac8292 9045
9046 return 0;
9047}
9048
f978241f 9049//! Parse stereo output mode
9050inline Standard_Boolean parseStereoMode (Standard_CString theArg,
9051 Graphic3d_StereoMode& theMode)
9052{
9053 TCollection_AsciiString aFlag (theArg);
9054 aFlag.LowerCase();
9055 if (aFlag == "quadbuffer")
9056 {
9057 theMode = Graphic3d_StereoMode_QuadBuffer;
9058 }
9059 else if (aFlag == "anaglyph")
9060 {
9061 theMode = Graphic3d_StereoMode_Anaglyph;
9062 }
9063 else if (aFlag == "row"
9064 || aFlag == "rowinterlaced")
9065 {
9066 theMode = Graphic3d_StereoMode_RowInterlaced;
9067 }
9068 else if (aFlag == "col"
9069 || aFlag == "colinterlaced"
9070 || aFlag == "columninterlaced")
9071 {
9072 theMode = Graphic3d_StereoMode_ColumnInterlaced;
9073 }
9074 else if (aFlag == "chess"
9075 || aFlag == "chessboard")
9076 {
9077 theMode = Graphic3d_StereoMode_ChessBoard;
9078 }
9079 else if (aFlag == "sbs"
9080 || aFlag == "sidebyside")
9081 {
9082 theMode = Graphic3d_StereoMode_SideBySide;
9083 }
9084 else if (aFlag == "ou"
9085 || aFlag == "overunder")
9086 {
9087 theMode = Graphic3d_StereoMode_OverUnder;
9088 }
9089 else if (aFlag == "pageflip"
9090 || aFlag == "softpageflip")
9091 {
9092 theMode = Graphic3d_StereoMode_SoftPageFlip;
9093 }
9094 else
9095 {
9096 return Standard_False;
9097 }
9098 return Standard_True;
9099}
9100
9101//! Parse anaglyph filter
9102inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
9103 Graphic3d_RenderingParams::Anaglyph& theFilter)
9104{
9105 TCollection_AsciiString aFlag (theArg);
9106 aFlag.LowerCase();
9107 if (aFlag == "redcyansimple")
9108 {
9109 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9110 }
9111 else if (aFlag == "redcyan"
9112 || aFlag == "redcyanoptimized")
9113 {
9114 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
9115 }
9116 else if (aFlag == "yellowbluesimple")
9117 {
9118 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
9119 }
9120 else if (aFlag == "yellowblue"
9121 || aFlag == "yellowblueoptimized")
9122 {
9123 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
9124 }
9125 else if (aFlag == "greenmagenta"
9126 || aFlag == "greenmagentasimple")
9127 {
9128 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
9129 }
9130 else
9131 {
9132 return Standard_False;
9133 }
9134 return Standard_True;
9135}
9136
b5ac8292 9137//==============================================================================
9138//function : VStereo
9139//purpose :
9140//==============================================================================
9141
9142static int VStereo (Draw_Interpretor& theDI,
9143 Standard_Integer theArgNb,
9144 const char** theArgVec)
9145{
f978241f 9146 Handle(V3d_View) aView = ViewerTest::CurrentView();
b5ac8292 9147 if (theArgNb < 2)
9148 {
b5ac8292 9149 if (aView.IsNull())
9150 {
f978241f 9151 std::cout << "Error: no active viewer!\n";
b5ac8292 9152 return 0;
9153 }
9154
9155 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
9156 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
bf02aa7d 9157 if (isActive)
9158 {
9159 TCollection_AsciiString aMode;
9160 switch (aView->RenderingParams().StereoMode)
9161 {
9162 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
9163 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
9164 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
9165 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
9166 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
9167 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
9168 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
9169 case Graphic3d_StereoMode_Anaglyph :
9170 aMode = "anaglyph";
9171 switch (aView->RenderingParams().AnaglyphFilter)
9172 {
9173 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
9174 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
9175 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
9176 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
9177 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
9178 default: break;
9179 }
9180 default: break;
9181 }
9182 theDI << "Mode " << aMode << "\n";
9183 }
b5ac8292 9184 return 0;
9185 }
9186
f978241f 9187 Handle(Graphic3d_Camera) aCamera;
9188 Graphic3d_RenderingParams* aParams = NULL;
9189 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
9190 if (!aView.IsNull())
9191 {
9192 aParams = &aView->ChangeRenderingParams();
9193 aMode = aParams->StereoMode;
9194 aCamera = aView->Camera();
9195 }
9196
9197 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9198 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9199 {
9200 Standard_CString anArg = theArgVec[anArgIter];
9201 TCollection_AsciiString aFlag (anArg);
9202 aFlag.LowerCase();
9203 if (anUpdateTool.parseRedrawMode (aFlag))
9204 {
9205 continue;
9206 }
9207 else if (aFlag == "0"
9208 || aFlag == "off")
9209 {
9210 if (++anArgIter < theArgNb)
9211 {
9212 std::cout << "Error: wrong number of arguments!\n";
9213 return 1;
9214 }
9215
9216 if (!aCamera.IsNull()
9217 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
9218 {
9219 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9220 }
9221 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
9222 return 0;
9223 }
9224 else if (aFlag == "1"
9225 || aFlag == "on")
9226 {
9227 if (++anArgIter < theArgNb)
9228 {
9229 std::cout << "Error: wrong number of arguments!\n";
9230 return 1;
9231 }
9232
9233 if (!aCamera.IsNull())
9234 {
9235 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9236 }
9237 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9238 return 0;
9239 }
9240 else if (aFlag == "-reverse"
9241 || aFlag == "-reversed"
9242 || aFlag == "-swap")
9243 {
9244 Standard_Boolean toEnable = Standard_True;
9245 if (++anArgIter < theArgNb
a5565a3c 9246 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 9247 {
9248 --anArgIter;
9249 }
9250 aParams->ToReverseStereo = toEnable;
9251 }
9252 else if (aFlag == "-noreverse"
9253 || aFlag == "-noswap")
9254 {
9255 Standard_Boolean toDisable = Standard_True;
9256 if (++anArgIter < theArgNb
a5565a3c 9257 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
f978241f 9258 {
9259 --anArgIter;
9260 }
9261 aParams->ToReverseStereo = !toDisable;
9262 }
9263 else if (aFlag == "-mode"
9264 || aFlag == "-stereomode")
9265 {
9266 if (++anArgIter >= theArgNb
9267 || !parseStereoMode (theArgVec[anArgIter], aMode))
9268 {
9269 std::cout << "Error: syntax error at '" << anArg << "'\n";
9270 return 1;
9271 }
9272
9273 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9274 {
9275 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9276 }
9277 }
9278 else if (aFlag == "-anaglyph"
9279 || aFlag == "-anaglyphfilter")
9280 {
9281 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9282 if (++anArgIter >= theArgNb
9283 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
9284 {
9285 std::cout << "Error: syntax error at '" << anArg << "'\n";
9286 return 1;
9287 }
9288
9289 aMode = Graphic3d_StereoMode_Anaglyph;
9290 aParams->AnaglyphFilter = aFilter;
9291 }
9292 else if (parseStereoMode (anArg, aMode)) // short syntax
9293 {
9294 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9295 {
9296 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9297 }
9298 }
9299 else
9300 {
9301 std::cout << "Error: syntax error at '" << anArg << "'\n";
9302 return 1;
9303 }
9304 }
9305
9306 if (!aView.IsNull())
9307 {
9308 aParams->StereoMode = aMode;
9309 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9310 }
b5ac8292 9311 return 0;
9312}
9313
392ac980 9314//===============================================================================================
9315//function : VDefaults
9316//purpose :
9317//===============================================================================================
9318static int VDefaults (Draw_Interpretor& theDi,
9319 Standard_Integer theArgsNb,
9320 const char** theArgVec)
9321{
9322 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9323 if (aCtx.IsNull())
9324 {
9325 std::cerr << "No active viewer!\n";
9326 return 1;
9327 }
9328
9329 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
9330 if (theArgsNb < 2)
9331 {
9332 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
9333 {
9334 theDi << "DeflType: relative\n"
9335 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
9336 }
9337 else
9338 {
9339 theDi << "DeflType: absolute\n"
9340 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
9341 }
9342 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
4c513386 9343 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
392ac980 9344 return 0;
9345 }
9346
9347 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9348 {
9349 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4c513386 9350 anArg.UpperCase();
9351 if (anArg == "-ABSDEFL"
9352 || anArg == "-ABSOLUTEDEFLECTION"
9353 || anArg == "-DEFL"
9354 || anArg == "-DEFLECTION")
392ac980 9355 {
4c513386 9356 if (++anArgIter >= theArgsNb)
9357 {
9358 std::cout << "Error: wrong syntax at " << anArg << "\n";
9359 return 1;
9360 }
392ac980 9361 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
4c513386 9362 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
392ac980 9363 }
4c513386 9364 else if (anArg == "-RELDEFL"
9365 || anArg == "-RELATIVEDEFLECTION"
9366 || anArg == "-DEVCOEFF"
9367 || anArg == "-DEVIATIONCOEFF"
9368 || anArg == "-DEVIATIONCOEFFICIENT")
392ac980 9369 {
4c513386 9370 if (++anArgIter >= theArgsNb)
9371 {
9372 std::cout << "Error: wrong syntax at " << anArg << "\n";
9373 return 1;
9374 }
392ac980 9375 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
4c513386 9376 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
392ac980 9377 }
4c513386 9378 else if (anArg == "-ANGDEFL"
9379 || anArg == "-ANGULARDEFL"
9380 || anArg == "-ANGULARDEFLECTION")
392ac980 9381 {
4c513386 9382 if (++anArgIter >= theArgsNb)
9383 {
9384 std::cout << "Error: wrong syntax at " << anArg << "\n";
9385 return 1;
9386 }
392ac980 9387 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
4c513386 9388 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
9389 }
385c43e7 9390 else if (anArg == "-AUTOTR"
9391 || anArg == "-AUTOTRIANG"
9392 || anArg == "-AUTOTRIANGULATION")
4c513386 9393 {
9394 if (++anArgIter >= theArgsNb)
9395 {
9396 std::cout << "Error: wrong syntax at " << anArg << "\n";
9397 return 1;
9398 }
9399 TCollection_AsciiString aValue (theArgVec[anArgIter]);
9400 aValue.LowerCase();
9401 if (aValue == "on"
9402 || aValue == "1")
9403 {
9404 aDefParams->SetAutoTriangulation (Standard_True);
9405 }
9406 else if (aValue == "off"
9407 || aValue == "0")
9408 {
9409 aDefParams->SetAutoTriangulation (Standard_False);
9410 }
392ac980 9411 }
9412 else
9413 {
9414 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
9415 }
9416 }
9417
9418 return 0;
9419}
9420
12381341 9421//! Auxiliary method
9422inline void addLight (const Handle(V3d_Light)& theLightNew,
992ed6b3 9423 const Graphic3d_ZLayerId theLayer,
12381341 9424 const Standard_Boolean theIsGlobal)
9425{
9426 if (theLightNew.IsNull())
9427 {
9428 return;
9429 }
9430
992ed6b3 9431 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9432 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
12381341 9433 {
992ed6b3 9434 aViewer->AddLight (theLightNew);
9435 if (theIsGlobal)
9436 {
9437 aViewer->SetLightOn (theLightNew);
9438 }
9439 else
9440 {
9441 ViewerTest::CurrentView()->SetLightOn (theLightNew);
9442 }
12381341 9443 }
9444 else
9445 {
992ed6b3 9446 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
9447 if (aSettings.Lights().IsNull())
9448 {
9449 aSettings.SetLights (new Graphic3d_LightSet());
9450 }
9451 aSettings.Lights()->Add (theLightNew);
9452 aViewer->SetZLayerSettings (theLayer, aSettings);
12381341 9453 }
9454}
9455
9456//! Auxiliary method
9457inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
9458{
9459 TCollection_AsciiString anArgNextCase (theArgNext);
9460 anArgNextCase.UpperCase();
9461 if (anArgNextCase.Length() > 5
9462 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
9463 {
9464 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
9465 }
9466 else
9467 {
9468 return theArgNext.IntegerValue();
9469 }
9470}
9471
9472//===============================================================================================
9473//function : VLight
9474//purpose :
9475//===============================================================================================
9476static int VLight (Draw_Interpretor& theDi,
9477 Standard_Integer theArgsNb,
9478 const char** theArgVec)
9479{
9480 Handle(V3d_View) aView = ViewerTest::CurrentView();
9481 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9482 if (aView.IsNull()
9483 || aViewer.IsNull())
9484 {
9485 std::cerr << "No active viewer!\n";
9486 return 1;
9487 }
9488
ee2be2a8 9489 Standard_Real anXYZ[3] = {};
9490 Standard_Real anAtten[2] = {};
12381341 9491 if (theArgsNb < 2)
9492 {
9493 // print lights info
9494 Standard_Integer aLightId = 0;
6a24c6de 9495 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
12381341 9496 {
6a24c6de 9497 Handle(V3d_Light) aLight = aLightIter.Value();
12381341 9498 const Quantity_Color aColor = aLight->Color();
992ed6b3 9499 theDi << "Light #" << aLightId
9500 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
9501 << " [" << aLight->GetId() << "]" << "\n";
12381341 9502 switch (aLight->Type())
9503 {
9504 case V3d_AMBIENT:
9505 {
189f85a3 9506 theDi << " Type: Ambient\n";
9507 theDi << " Intensity: " << aLight->Intensity() << "\n";
12381341 9508 break;
9509 }
9510 case V3d_DIRECTIONAL:
9511 {
189f85a3 9512 theDi << " Type: Directional\n";
9513 theDi << " Intensity: " << aLight->Intensity() << "\n";
9514 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9515 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
992ed6b3 9516 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9517 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
12381341 9518 break;
9519 }
9520 case V3d_POSITIONAL:
9521 {
189f85a3 9522 theDi << " Type: Positional\n";
9523 theDi << " Intensity: " << aLight->Intensity() << "\n";
9524 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9525 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
992ed6b3 9526 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9527 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9528 aLight->Attenuation (anAtten[0], anAtten[1]);
9529 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
12381341 9530 break;
9531 }
9532 case V3d_SPOT:
9533 {
189f85a3 9534 theDi << " Type: Spot\n";
9535 theDi << " Intensity: " << aLight->Intensity() << "\n";
9536 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
992ed6b3 9537 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9538 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9539 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9540 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9541 aLight->Attenuation (anAtten[0], anAtten[1]);
9542 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9543 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
9544 theDi << " Exponent: " << aLight->Concentration() << "\n";
12381341 9545 break;
9546 }
9547 default:
9548 {
189f85a3 9549 theDi << " Type: UNKNOWN\n";
12381341 9550 break;
9551 }
9552 }
992ed6b3 9553 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
12381341 9554 }
9555 }
9556
9557 Handle(V3d_Light) aLightNew;
9558 Handle(V3d_Light) aLightOld;
992ed6b3 9559 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
12381341 9560 Standard_Boolean isGlobal = Standard_True;
9561 Standard_Boolean toCreate = Standard_False;
761d8807 9562 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
12381341 9563 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
9564 {
992ed6b3 9565 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
12381341 9566
9567 TCollection_AsciiString aName, aValue;
9568 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
9569 TCollection_AsciiString anArgCase (anArg);
9570 anArgCase.UpperCase();
761d8807 9571 if (anUpdateTool.parseRedrawMode (anArg))
9572 {
9573 continue;
9574 }
9575
12381341 9576 if (anArgCase.IsEqual ("NEW")
9577 || anArgCase.IsEqual ("ADD")
992ed6b3 9578 || anArgCase.IsEqual ("CREATE")
9579 || anArgCase.IsEqual ("-NEW")
9580 || anArgCase.IsEqual ("-ADD")
9581 || anArgCase.IsEqual ("-CREATE"))
12381341 9582 {
9583 toCreate = Standard_True;
9584 }
992ed6b3 9585 else if (anArgCase.IsEqual ("-LAYER")
9586 || anArgCase.IsEqual ("-ZLAYER"))
9587 {
9588 if (++anArgIt >= theArgsNb)
9589 {
9590 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9591 return 1;
9592 }
9593
9594 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
9595 aValStr.LowerCase();
9596 if (aValStr == "default"
9597 || aValStr == "def")
9598 {
9599 aLayer = Graphic3d_ZLayerId_Default;
9600 }
9601 else if (aValStr == "top")
9602 {
9603 aLayer = Graphic3d_ZLayerId_Top;
9604 }
9605 else if (aValStr == "topmost")
9606 {
9607 aLayer = Graphic3d_ZLayerId_Topmost;
9608 }
9609 else if (aValStr == "toposd"
9610 || aValStr == "osd")
9611 {
9612 aLayer = Graphic3d_ZLayerId_TopOSD;
9613 }
9614 else if (aValStr == "botosd"
9615 || aValStr == "bottom")
9616 {
9617 aLayer = Graphic3d_ZLayerId_BotOSD;
9618 }
9619 else if (aValStr.IsIntegerValue())
9620 {
9621 aLayer = Draw::Atoi (theArgVec[anArgIt]);
9622 }
9623 else
9624 {
9625 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
9626 return 1;
9627 }
9628 }
12381341 9629 else if (anArgCase.IsEqual ("GLOB")
992ed6b3 9630 || anArgCase.IsEqual ("GLOBAL")
9631 || anArgCase.IsEqual ("-GLOB")
9632 || anArgCase.IsEqual ("-GLOBAL"))
12381341 9633 {
9634 isGlobal = Standard_True;
9635 }
9636 else if (anArgCase.IsEqual ("LOC")
992ed6b3 9637 || anArgCase.IsEqual ("LOCAL")
9638 || anArgCase.IsEqual ("-LOC")
9639 || anArgCase.IsEqual ("-LOCAL"))
12381341 9640 {
9641 isGlobal = Standard_False;
9642 }
4fe9ad57 9643 else if (anArgCase.IsEqual ("DEF")
992ed6b3 9644 || anArgCase.IsEqual ("DEFAULTS")
9645 || anArgCase.IsEqual ("-DEF")
9646 || anArgCase.IsEqual ("-DEFAULTS"))
4fe9ad57 9647 {
9648 toCreate = Standard_False;
9649 aViewer->SetDefaultLights();
9650 }
9651 else if (anArgCase.IsEqual ("CLR")
992ed6b3 9652 || anArgCase.IsEqual ("CLEAR")
9653 || anArgCase.IsEqual ("-CLR")
9654 || anArgCase.IsEqual ("-CLEAR"))
4fe9ad57 9655 {
9656 toCreate = Standard_False;
992ed6b3 9657
9658 TColStd_SequenceOfInteger aLayers;
9659 aViewer->GetAllZLayers (aLayers);
9660 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4fe9ad57 9661 {
992ed6b3 9662 if (aLayeriter.Value() == aLayer
9663 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9664 {
9665 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9666 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9667 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9668 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9669 {
9670 break;
9671 }
9672 }
9673 }
9674
9675 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
9676 {
9677 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
9678 {
9679 Handle(V3d_Light) aLight = aLightIter.Value();
9680 aViewer->DelLight (aLight);
9681 aLightIter = aView->ActiveLightIterator();
9682 }
4fe9ad57 9683 }
9684 }
12381341 9685 else if (anArgCase.IsEqual ("AMB")
9686 || anArgCase.IsEqual ("AMBIENT")
9687 || anArgCase.IsEqual ("AMBLIGHT"))
9688 {
12381341 9689 if (!toCreate)
9690 {
9691 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9692 return 1;
9693 }
992ed6b3 9694
9695 addLight (aLightNew, aLayer, isGlobal);
12381341 9696 toCreate = Standard_False;
992ed6b3 9697 aLightNew = new V3d_AmbientLight();
12381341 9698 }
9699 else if (anArgCase.IsEqual ("DIRECTIONAL")
9700 || anArgCase.IsEqual ("DIRLIGHT"))
9701 {
12381341 9702 if (!toCreate)
9703 {
9704 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9705 return 1;
9706 }
992ed6b3 9707
9708 addLight (aLightNew, aLayer, isGlobal);
12381341 9709 toCreate = Standard_False;
992ed6b3 9710 aLightNew = new V3d_DirectionalLight();
12381341 9711 }
9712 else if (anArgCase.IsEqual ("SPOT")
9713 || anArgCase.IsEqual ("SPOTLIGHT"))
9714 {
12381341 9715 if (!toCreate)
9716 {
9717 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9718 return 1;
9719 }
992ed6b3 9720
9721 addLight (aLightNew, aLayer, isGlobal);
12381341 9722 toCreate = Standard_False;
992ed6b3 9723 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
12381341 9724 }
9725 else if (anArgCase.IsEqual ("POSLIGHT")
9726 || anArgCase.IsEqual ("POSITIONAL"))
9727 {
12381341 9728 if (!toCreate)
9729 {
9730 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9731 return 1;
9732 }
992ed6b3 9733
9734 addLight (aLightNew, aLayer, isGlobal);
12381341 9735 toCreate = Standard_False;
992ed6b3 9736 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
12381341 9737 }
992ed6b3 9738 else if (anArgCase.IsEqual ("CHANGE")
9739 || anArgCase.IsEqual ("-CHANGE"))
12381341 9740 {
12381341 9741 if (++anArgIt >= theArgsNb)
9742 {
9743 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9744 return 1;
9745 }
9746
992ed6b3 9747 addLight (aLightNew, aLayer, isGlobal);
9748 aLightNew.Nullify();
12381341 9749 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
9750 Standard_Integer aLightIt = 0;
6a24c6de 9751 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
12381341 9752 {
9753 if (aLightIt == aLightId)
9754 {
6a24c6de 9755 aLightOld = aLightIter.Value();
12381341 9756 break;
9757 }
9758 }
9759
9760 if (aLightOld.IsNull())
9761 {
9762 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
9763 return 1;
9764 }
9765 }
9766 else if (anArgCase.IsEqual ("DEL")
992ed6b3 9767 || anArgCase.IsEqual ("DELETE")
9768 || anArgCase.IsEqual ("-DEL")
9769 || anArgCase.IsEqual ("-DELETE"))
12381341 9770 {
9771 Handle(V3d_Light) aLightDel;
9772 if (++anArgIt >= theArgsNb)
9773 {
9774 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9775 return 1;
9776 }
9777
9778 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9779 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
9780 Standard_Integer aLightIt = 0;
6a24c6de 9781 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
12381341 9782 {
6a24c6de 9783 aLightDel = aLightIter.Value();
12381341 9784 if (aLightIt == aLightDelId)
9785 {
9786 break;
9787 }
9788 }
992ed6b3 9789 if (aLightDel.IsNull())
9790 {
9791 continue;
9792 }
9793
9794 TColStd_SequenceOfInteger aLayers;
9795 aViewer->GetAllZLayers (aLayers);
9796 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9797 {
9798 if (aLayeriter.Value() == aLayer
9799 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9800 {
9801 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9802 if (!aSettings.Lights().IsNull())
9803 {
9804 aSettings.Lights()->Remove (aLightDel);
9805 if (aSettings.Lights()->IsEmpty())
9806 {
9807 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9808 }
9809 }
9810 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9811 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9812 {
9813 break;
9814 }
9815 }
9816 }
9817
9818 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
12381341 9819 {
9820 aViewer->DelLight (aLightDel);
9821 }
9822 }
9823 else if (anArgCase.IsEqual ("COLOR")
992ed6b3 9824 || anArgCase.IsEqual ("COLOUR")
9825 || anArgCase.IsEqual ("-COLOR")
9826 || anArgCase.IsEqual ("-COLOUR"))
12381341 9827 {
992ed6b3 9828 if (++anArgIt >= theArgsNb
9829 || aLightCurr.IsNull())
12381341 9830 {
9831 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9832 return 1;
9833 }
9834
9835 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9836 anArgNext.UpperCase();
9837 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
992ed6b3 9838 aLightCurr->SetColor (aColor);
12381341 9839 }
9840 else if (anArgCase.IsEqual ("POS")
992ed6b3 9841 || anArgCase.IsEqual ("POSITION")
9842 || anArgCase.IsEqual ("-POS")
9843 || anArgCase.IsEqual ("-POSITION"))
12381341 9844 {
992ed6b3 9845 if ((anArgIt + 3) >= theArgsNb
9846 || aLightCurr.IsNull()
9847 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
9848 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 9849 {
9850 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9851 return 1;
9852 }
9853
9854 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9855 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9856 anXYZ[2] = Atof (theArgVec[++anArgIt]);
992ed6b3 9857 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
12381341 9858 }
9859 else if (anArgCase.IsEqual ("DIR")
992ed6b3 9860 || anArgCase.IsEqual ("DIRECTION")
9861 || anArgCase.IsEqual ("-DIR")
9862 || anArgCase.IsEqual ("-DIRECTION"))
12381341 9863 {
992ed6b3 9864 if ((anArgIt + 3) >= theArgsNb
9865 || aLightCurr.IsNull()
9866 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
9867 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 9868 {
9869 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9870 return 1;
9871 }
9872
9873 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9874 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9875 anXYZ[2] = Atof (theArgVec[++anArgIt]);
992ed6b3 9876 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
12381341 9877 }
189f85a3 9878 else if (anArgCase.IsEqual ("SM")
992ed6b3 9879 || anArgCase.IsEqual ("SMOOTHNESS")
9880 || anArgCase.IsEqual ("-SM")
9881 || anArgCase.IsEqual ("-SMOOTHNESS"))
189f85a3 9882 {
992ed6b3 9883 if (++anArgIt >= theArgsNb
9884 || aLightCurr.IsNull())
189f85a3 9885 {
9886 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9887 return 1;
9888 }
9889
992ed6b3 9890 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
9891 if (Abs (aSmoothness) <= ShortRealEpsilon())
189f85a3 9892 {
9893 aLightCurr->SetIntensity (1.f);
9894 }
992ed6b3 9895 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
189f85a3 9896 {
9897 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
9898 }
9899 else
9900 {
9901 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
9902 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
9903 }
9904
992ed6b3 9905 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
189f85a3 9906 {
992ed6b3 9907 aLightCurr->SetSmoothRadius (aSmoothness);
189f85a3 9908 }
992ed6b3 9909 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
189f85a3 9910 {
992ed6b3 9911 aLightCurr->SetSmoothAngle (aSmoothness);
189f85a3 9912 }
9913 }
9914 else if (anArgCase.IsEqual ("INT")
992ed6b3 9915 || anArgCase.IsEqual ("INTENSITY")
9916 || anArgCase.IsEqual ("-INT")
9917 || anArgCase.IsEqual ("-INTENSITY"))
189f85a3 9918 {
992ed6b3 9919 if (++anArgIt >= theArgsNb
9920 || aLightCurr.IsNull())
189f85a3 9921 {
9922 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9923 return 1;
9924 }
9925
992ed6b3 9926 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
9927 aLightCurr->SetIntensity (aIntensity);
189f85a3 9928 }
4fe9ad57 9929 else if (anArgCase.IsEqual ("ANG")
992ed6b3 9930 || anArgCase.IsEqual ("ANGLE")
9931 || anArgCase.IsEqual ("-ANG")
9932 || anArgCase.IsEqual ("-ANGLE"))
4fe9ad57 9933 {
992ed6b3 9934 if (++anArgIt >= theArgsNb
9935 || aLightCurr.IsNull()
9936 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
4fe9ad57 9937 {
9938 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9939 return 1;
9940 }
9941
992ed6b3 9942 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
9943 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
4fe9ad57 9944 }
12381341 9945 else if (anArgCase.IsEqual ("CONSTATTEN")
992ed6b3 9946 || anArgCase.IsEqual ("CONSTATTENUATION")
9947 || anArgCase.IsEqual ("-CONSTATTEN")
9948 || anArgCase.IsEqual ("-CONSTATTENUATION"))
12381341 9949 {
992ed6b3 9950 if (++anArgIt >= theArgsNb
9951 || aLightCurr.IsNull()
9952 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
9953 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 9954 {
9955 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9956 return 1;
9957 }
9958
992ed6b3 9959 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
9960 anAtten[0] = Atof (theArgVec[anArgIt]);
9961 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
12381341 9962 }
9963 else if (anArgCase.IsEqual ("LINATTEN")
9964 || anArgCase.IsEqual ("LINEARATTEN")
992ed6b3 9965 || anArgCase.IsEqual ("LINEARATTENUATION")
9966 || anArgCase.IsEqual ("-LINATTEN")
9967 || anArgCase.IsEqual ("-LINEARATTEN")
9968 || anArgCase.IsEqual ("-LINEARATTENUATION"))
12381341 9969 {
992ed6b3 9970 if (++anArgIt >= theArgsNb
9971 || aLightCurr.IsNull()
9972 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
9973 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 9974 {
9975 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9976 return 1;
9977 }
9978
992ed6b3 9979 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
9980 anAtten[1] = Atof (theArgVec[anArgIt]);
9981 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
12381341 9982 }
9983 else if (anArgCase.IsEqual ("EXP")
9984 || anArgCase.IsEqual ("EXPONENT")
9985 || anArgCase.IsEqual ("SPOTEXP")
992ed6b3 9986 || anArgCase.IsEqual ("SPOTEXPONENT")
9987 || anArgCase.IsEqual ("-EXP")
9988 || anArgCase.IsEqual ("-EXPONENT")
9989 || anArgCase.IsEqual ("-SPOTEXP")
9990 || anArgCase.IsEqual ("-SPOTEXPONENT"))
12381341 9991 {
992ed6b3 9992 if (++anArgIt >= theArgsNb
9993 || aLightCurr.IsNull()
9994 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
12381341 9995 {
9996 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9997 return 1;
9998 }
9999
992ed6b3 10000 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
12381341 10001 }
10002 else if (anArgCase.IsEqual ("HEAD")
992ed6b3 10003 || anArgCase.IsEqual ("HEADLIGHT")
10004 || anArgCase.IsEqual ("-HEAD")
10005 || anArgCase.IsEqual ("-HEADLIGHT"))
12381341 10006 {
992ed6b3 10007 if (aLightCurr.IsNull()
10008 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
12381341 10009 {
10010 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10011 return 1;
10012 }
10013
992ed6b3 10014 Standard_Boolean isHeadLight = Standard_True;
10015 if (anArgIt + 1 < theArgsNb
10016 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
12381341 10017 {
992ed6b3 10018 ++anArgIt;
12381341 10019 }
992ed6b3 10020 aLightCurr->SetHeadlight (isHeadLight);
12381341 10021 }
10022 else
10023 {
10024 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
10025 }
10026 }
10027
992ed6b3 10028 addLight (aLightNew, aLayer, isGlobal);
12381341 10029 return 0;
10030}
10031
15669413 10032//! Read Graphic3d_RenderingParams::PerfCounters flag.
10033static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
10034 Standard_Boolean& theToReset,
10035 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
10036 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
10037{
10038 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
10039 TCollection_AsciiString aVal = theValue;
10040 Standard_Boolean toReverse = Standard_False;
10041 if (aVal == "none")
10042 {
10043 theToReset = Standard_True;
10044 return Standard_True;
10045 }
10046 else if (aVal.StartsWith ("-"))
10047 {
10048 toReverse = Standard_True;
10049 aVal = aVal.SubString (2, aVal.Length());
10050 }
10051 else if (aVal.StartsWith ("no"))
10052 {
10053 toReverse = Standard_True;
10054 aVal = aVal.SubString (3, aVal.Length());
10055 }
10056 else if (aVal.StartsWith ("+"))
10057 {
10058 aVal = aVal.SubString (2, aVal.Length());
10059 }
10060 else
10061 {
10062 theToReset = Standard_True;
10063 }
10064
10065 if ( aVal == "fps"
10066 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
10067 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
10068 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
10069 else if (aVal == "structs"
10070 || aVal == "structures"
10071 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
10072 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
10073 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
10074 else if (aVal == "tris"
10075 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
10076 else if (aVal == "pnts"
10077 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
10078 else if (aVal == "mem"
10079 || aVal == "gpumem"
10080 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
10081 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
10082 else if (aVal == "extended"
10083 || aVal == "verbose"
10084 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
10085 else
10086 {
10087 return Standard_False;
10088 }
10089
10090 if (toReverse)
10091 {
10092 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
10093 }
10094 else
10095 {
10096 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
10097 }
10098 return Standard_True;
10099}
10100
10101//! Read Graphic3d_RenderingParams::PerfCounters flags.
10102static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
10103 Graphic3d_RenderingParams::PerfCounters& theFlags)
10104{
10105 TCollection_AsciiString aValue = theValue;
10106 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
10107 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
10108 Standard_Boolean toReset = Standard_False;
10109 for (;;)
10110 {
10111 Standard_Integer aSplitPos = aValue.Search ("|");
10112 if (aSplitPos <= 0)
10113 {
10114 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
10115 {
10116 return Standard_False;
10117 }
10118 if (toReset)
10119 {
10120 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
10121 }
10122 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
10123 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
10124 return Standard_True;
10125 }
10126
10127 if (aSplitPos > 1)
10128 {
10129 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
10130 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
10131 {
10132 return Standard_False;
10133 }
10134 }
10135 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
10136 }
10137}
10138
e276548b 10139//=======================================================================
bc8c79bb 10140//function : VRenderParams
10141//purpose : Enables/disables rendering features
e276548b 10142//=======================================================================
10143
bc8c79bb 10144static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
10145 Standard_Integer theArgNb,
10146 const char** theArgVec)
e276548b 10147{
7ae4a307 10148 Handle(V3d_View) aView = ViewerTest::CurrentView();
10149 if (aView.IsNull())
e276548b 10150 {
bc8c79bb 10151 std::cerr << "Error: no active viewer!\n";
e276548b 10152 return 1;
10153 }
bc8c79bb 10154
10155 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
6b62b2da 10156 TCollection_AsciiString aCmdName (theArgVec[0]);
10157 aCmdName.LowerCase();
10158 if (aCmdName == "vraytrace")
10159 {
10160 if (theArgNb == 1)
10161 {
10162 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
10163 return 0;
10164 }
10165 else if (theArgNb == 2)
10166 {
10167 TCollection_AsciiString aValue (theArgVec[1]);
10168 aValue.LowerCase();
10169 if (aValue == "on"
10170 || aValue == "1")
10171 {
10172 aParams.Method = Graphic3d_RM_RAYTRACING;
10173 aView->Redraw();
10174 return 0;
10175 }
10176 else if (aValue == "off"
10177 || aValue == "0")
10178 {
10179 aParams.Method = Graphic3d_RM_RASTERIZATION;
10180 aView->Redraw();
10181 return 0;
10182 }
10183 else
10184 {
10185 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
10186 return 1;
10187 }
10188 }
10189 else
10190 {
10191 std::cout << "Error: wrong number of arguments\n";
10192 return 1;
10193 }
10194 }
bc8c79bb 10195
10196 if (theArgNb < 2)
e276548b 10197 {
bc8c79bb 10198 theDI << "renderMode: ";
10199 switch (aParams.Method)
10200 {
10201 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10202 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
10203 }
10204 theDI << "\n";
a1073ae2 10205 theDI << "transparency: ";
10206 switch (aParams.TransparencyMethod)
10207 {
10208 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
10209 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
10210 << TCollection_AsciiString (aParams.OitDepthFactor); break;
10211 }
10212 theDI << "\n";
b4327ba8 10213 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
56689b27 10214 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
b4327ba8 10215 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
10216 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
10217 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
10218 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
10219 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
10220 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
10221 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
10222 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
10223 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
10224 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
b09447ed 10225 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
4eaaf9d8 10226 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
8625ef7e 10227 theDI << "shadingModel: ";
10228 switch (aView->ShadingModel())
10229 {
dc89236f 10230 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10231 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
10232 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
10233 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
10234 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
8625ef7e 10235 }
15669413 10236 {
10237 theDI << "perfCounters:";
10238 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
10239 {
10240 theDI << " fps";
10241 }
10242 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
10243 {
10244 theDI << " cpu";
10245 }
10246 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
10247 {
10248 theDI << " structs";
10249 }
10250 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
10251 {
10252 theDI << " groups";
10253 }
10254 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
10255 {
10256 theDI << " arrays";
10257 }
10258 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
10259 {
10260 theDI << " tris";
10261 }
10262 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
10263 {
10264 theDI << " pnts";
10265 }
10266 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
10267 {
10268 theDI << " gpumem";
10269 }
10270 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
10271 {
10272 theDI << " none";
10273 }
10274 theDI << "\n";
10275 }
f88457e6 10276 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
c40eb6b9 10277 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
8625ef7e 10278 theDI << "\n";
bc8c79bb 10279 return 0;
e276548b 10280 }
10281
bc8c79bb 10282 Standard_Boolean toPrint = Standard_False;
8625ef7e 10283 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
e276548b 10284 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10285 {
bc8c79bb 10286 Standard_CString anArg (theArgVec[anArgIter]);
10287 TCollection_AsciiString aFlag (anArg);
10288 aFlag.LowerCase();
8625ef7e 10289 if (anUpdateTool.parseRedrawMode (aFlag))
10290 {
10291 continue;
10292 }
10293 else if (aFlag == "-echo"
10294 || aFlag == "-print")
e276548b 10295 {
bc8c79bb 10296 toPrint = Standard_True;
8625ef7e 10297 anUpdateTool.Invalidate();
e276548b 10298 }
bc8c79bb 10299 else if (aFlag == "-mode"
10300 || aFlag == "-rendermode"
10301 || aFlag == "-render_mode")
e276548b 10302 {
bc8c79bb 10303 if (toPrint)
10304 {
10305 switch (aParams.Method)
10306 {
10307 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10308 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
10309 }
10310 continue;
10311 }
e276548b 10312 else
bc8c79bb 10313 {
10314 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10315 return 1;
10316 }
10317 }
10318 else if (aFlag == "-ray"
10319 || aFlag == "-raytrace")
10320 {
10321 if (toPrint)
10322 {
10323 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
10324 continue;
10325 }
10326
10327 aParams.Method = Graphic3d_RM_RAYTRACING;
e276548b 10328 }
bc8c79bb 10329 else if (aFlag == "-rast"
10330 || aFlag == "-raster"
10331 || aFlag == "-rasterization")
e276548b 10332 {
bc8c79bb 10333 if (toPrint)
10334 {
10335 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
10336 continue;
10337 }
10338
10339 aParams.Method = Graphic3d_RM_RASTERIZATION;
10340 }
3c4b62a4 10341 else if (aFlag == "-msaa")
10342 {
10343 if (toPrint)
10344 {
10345 theDI << aParams.NbMsaaSamples << " ";
10346 continue;
10347 }
10348 else if (++anArgIter >= theArgNb)
10349 {
10350 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10351 return 1;
10352 }
10353
10354 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
10355 if (aNbSamples < 0)
10356 {
10357 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
10358 return 1;
10359 }
10360 else
10361 {
10362 aParams.NbMsaaSamples = aNbSamples;
10363 }
10364 }
a1073ae2 10365 else if (aFlag == "-oit")
10366 {
10367 if (toPrint)
10368 {
10369 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
10370 {
10371 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
10372 }
10373 else
10374 {
10375 theDI << "off" << " ";
10376 }
10377 continue;
10378 }
10379 else if (++anArgIter >= theArgNb)
10380 {
10381 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10382 return 1;
10383 }
10384
10385 TCollection_AsciiString aParam = theArgVec[anArgIter];
10386 aParam.LowerCase();
10387 if (aParam.IsRealValue())
10388 {
10389 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10390 if (aWeight < 0.f || aWeight > 1.f)
10391 {
10392 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
10393 return 1;
10394 }
10395
10396 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
10397 aParams.OitDepthFactor = aWeight;
10398 }
10399 else if (aParam == "off")
10400 {
10401 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
10402 }
10403 else
10404 {
10405 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10406 return 1;
10407 }
10408 }
f88457e6 10409 else if (aFlag == "-depthprepass")
10410 {
10411 if (toPrint)
10412 {
10413 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
10414 continue;
10415 }
10416 aParams.ToEnableDepthPrepass = Standard_True;
10417 if (anArgIter + 1 < theArgNb
10418 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
10419 {
10420 ++anArgIter;
10421 }
10422 }
c40eb6b9 10423 else if (aFlag == "-samplealphatocoverage"
10424 || aFlag == "-alphatocoverage")
10425 {
10426 if (toPrint)
10427 {
10428 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
10429 continue;
10430 }
10431 aParams.ToEnableAlphaToCoverage = Standard_True;
10432 if (anArgIter + 1 < theArgNb
10433 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
10434 {
10435 ++anArgIter;
10436 }
10437 }
56689b27 10438 else if (aFlag == "-rendscale"
10439 || aFlag == "-renderscale"
10440 || aFlag == "-renderresolutionscale")
10441 {
10442 if (toPrint)
10443 {
10444 theDI << aParams.RenderResolutionScale << " ";
10445 continue;
10446 }
10447 else if (++anArgIter >= theArgNb)
10448 {
10449 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10450 return 1;
10451 }
10452
10453 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
10454 if (aScale < 0.01)
10455 {
10456 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
10457 return 1;
10458 }
10459 else
10460 {
10461 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
10462 }
10463 }
bc8c79bb 10464 else if (aFlag == "-raydepth"
10465 || aFlag == "-ray_depth")
10466 {
10467 if (toPrint)
10468 {
10469 theDI << aParams.RaytracingDepth << " ";
10470 continue;
10471 }
10472 else if (++anArgIter >= theArgNb)
10473 {
10474 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10475 return 1;
10476 }
10477
10478 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
189f85a3 10479
10480 // We allow RaytracingDepth be more than 10 in case of GI enabled
10481 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
bc8c79bb 10482 {
10483 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
10484 return 1;
10485 }
e276548b 10486 else
bc8c79bb 10487 {
10488 aParams.RaytracingDepth = aDepth;
10489 }
10490 }
10491 else if (aFlag == "-shad"
10492 || aFlag == "-shadows")
10493 {
10494 if (toPrint)
10495 {
10496 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
10497 continue;
10498 }
10499
10500 Standard_Boolean toEnable = Standard_True;
10501 if (++anArgIter < theArgNb
a5565a3c 10502 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 10503 {
10504 --anArgIter;
10505 }
10506 aParams.IsShadowEnabled = toEnable;
10507 }
10508 else if (aFlag == "-refl"
10509 || aFlag == "-reflections")
10510 {
10511 if (toPrint)
10512 {
10513 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
10514 continue;
10515 }
10516
10517 Standard_Boolean toEnable = Standard_True;
10518 if (++anArgIter < theArgNb
a5565a3c 10519 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 10520 {
10521 --anArgIter;
10522 }
10523 aParams.IsReflectionEnabled = toEnable;
10524 }
10525 else if (aFlag == "-fsaa")
10526 {
10527 if (toPrint)
10528 {
10529 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
10530 continue;
10531 }
10532
10533 Standard_Boolean toEnable = Standard_True;
10534 if (++anArgIter < theArgNb
a5565a3c 10535 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 10536 {
10537 --anArgIter;
10538 }
10539 aParams.IsAntialiasingEnabled = toEnable;
10540 }
10541 else if (aFlag == "-gleam")
10542 {
10543 if (toPrint)
10544 {
10545 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
10546 continue;
10547 }
10548
10549 Standard_Boolean toEnable = Standard_True;
10550 if (++anArgIter < theArgNb
a5565a3c 10551 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 10552 {
10553 --anArgIter;
10554 }
10555 aParams.IsTransparentShadowEnabled = toEnable;
e276548b 10556 }
189f85a3 10557 else if (aFlag == "-gi")
10558 {
10559 if (toPrint)
10560 {
10561 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
10562 continue;
10563 }
10564
10565 Standard_Boolean toEnable = Standard_True;
10566 if (++anArgIter < theArgNb
a5565a3c 10567 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
189f85a3 10568 {
10569 --anArgIter;
10570 }
10571 aParams.IsGlobalIlluminationEnabled = toEnable;
10572 if (!toEnable)
10573 {
10574 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
10575 }
10576 }
8c820969 10577 else if (aFlag == "-blockedrng"
10578 || aFlag == "-brng")
10579 {
10580 if (toPrint)
10581 {
10582 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
10583 continue;
10584 }
10585
10586 Standard_Boolean toEnable = Standard_True;
10587 if (++anArgIter < theArgNb
a5565a3c 10588 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8c820969 10589 {
10590 --anArgIter;
10591 }
10592 aParams.CoherentPathTracingMode = toEnable;
10593 }
b09447ed 10594 else if (aFlag == "-maxrad")
10595 {
10596 if (toPrint)
10597 {
10598 theDI << aParams.RadianceClampingValue << " ";
10599 continue;
10600 }
10601 else if (++anArgIter >= theArgNb)
10602 {
10603 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10604 return 1;
10605 }
10606
10607 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
10608 if (!aMaxRadStr.IsRealValue())
10609 {
10610 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10611 return 1;
10612 }
10613
10614 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
10615 if (aMaxRadiance <= 0.0)
10616 {
10617 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
10618 return 1;
10619 }
10620 else
10621 {
10622 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
10623 }
10624 }
3a9b5dc8 10625 else if (aFlag == "-iss")
10626 {
10627 if (toPrint)
10628 {
10629 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
10630 continue;
10631 }
10632
10633 Standard_Boolean toEnable = Standard_True;
10634 if (++anArgIter < theArgNb
10635 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10636 {
10637 --anArgIter;
10638 }
10639 aParams.AdaptiveScreenSampling = toEnable;
10640 }
10641 else if (aFlag == "-issd")
10642 {
10643 if (toPrint)
10644 {
10645 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
10646 continue;
10647 }
10648
10649 Standard_Boolean toEnable = Standard_True;
10650 if (++anArgIter < theArgNb
10651 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10652 {
10653 --anArgIter;
10654 }
10655 aParams.ShowSamplingTiles = toEnable;
10656 }
4eaaf9d8 10657 else if (aFlag == "-nbtiles")
10658 {
10659 if (toPrint)
10660 {
10661 theDI << aParams.NbRayTracingTiles << " ";
10662 continue;
10663 }
10664 else if (++anArgIter >= theArgNb)
10665 {
10666 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10667 return 1;
10668 }
10669
10670 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
10671
10672 if (aNbTiles < 64)
10673 {
10674 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
10675 std::cerr << "Specify value in range [64, 1024].\n";
10676 return 1;
10677 }
10678 else
10679 {
10680 aParams.NbRayTracingTiles = aNbTiles;
10681 }
10682 }
189f85a3 10683 else if (aFlag == "-env")
10684 {
10685 if (toPrint)
10686 {
10687 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
10688 continue;
10689 }
10690
10691 Standard_Boolean toEnable = Standard_True;
10692 if (++anArgIter < theArgNb
a5565a3c 10693 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
189f85a3 10694 {
10695 --anArgIter;
10696 }
10697 aParams.UseEnvironmentMapBackground = toEnable;
10698 }
b4327ba8 10699 else if (aFlag == "-twoside")
10700 {
10701 if (toPrint)
10702 {
10703 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
10704 continue;
10705 }
10706
10707 Standard_Boolean toEnable = Standard_True;
10708 if (++anArgIter < theArgNb
10709 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10710 {
10711 --anArgIter;
10712 }
10713 aParams.TwoSidedBsdfModels = toEnable;
10714 }
8625ef7e 10715 else if (aFlag == "-shademodel"
10716 || aFlag == "-shadingmodel"
10717 || aFlag == "-shading")
10718 {
10719 if (toPrint)
10720 {
10721 switch (aView->ShadingModel())
10722 {
dc89236f 10723 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10724 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
10725 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
10726 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
10727 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
8625ef7e 10728 }
10729 continue;
10730 }
10731
10732 if (++anArgIter >= theArgNb)
10733 {
10734 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10735 }
10736
dc89236f 10737 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
10738 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
10739 && aModel != Graphic3d_TOSM_DEFAULT)
8625ef7e 10740 {
dc89236f 10741 aView->SetShadingModel (aModel);
8625ef7e 10742 }
10743 else
10744 {
dc89236f 10745 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
8625ef7e 10746 return 1;
10747 }
10748 }
4b1c8733 10749 else if (aFlag == "-resolution")
10750 {
10751 if (++anArgIter >= theArgNb)
10752 {
10753 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10754 return 1;
10755 }
10756
10757 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
10758 if (aResolution.IsIntegerValue())
10759 {
10760 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
10761 }
10762 else
10763 {
10764 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10765 return 1;
10766 }
10767 }
d877e610 10768 else if (aFlag == "-rebuildglsl"
10769 || aFlag == "-rebuild")
10770 {
10771 if (toPrint)
10772 {
10773 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
10774 continue;
10775 }
10776
10777 Standard_Boolean toEnable = Standard_True;
10778 if (++anArgIter < theArgNb
10779 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10780 {
10781 --anArgIter;
10782 }
10783 aParams.RebuildRayTracingShaders = toEnable;
10784 }
b27ab03d 10785 else if (aFlag == "-focal")
10786 {
10787 if (++anArgIter >= theArgNb)
10788 {
10789 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10790 return 1;
10791 }
10792
10793 TCollection_AsciiString aParam (theArgVec[anArgIter]);
10794 if (aParam.IsRealValue())
10795 {
10796 float aFocalDist = static_cast<float> (aParam.RealValue());
10797 if (aFocalDist < 0)
10798 {
10799 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
10800 return 1;
10801 }
10802 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
10803 }
10804 else
10805 {
10806 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10807 return 1;
10808 }
10809 }
10810 else if (aFlag == "-aperture")
10811 {
10812 if (++anArgIter >= theArgNb)
10813 {
10814 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10815 return 1;
10816 }
10817
10818 TCollection_AsciiString aParam(theArgVec[anArgIter]);
10819 if (aParam.IsRealValue())
10820 {
10821 float aApertureSize = static_cast<float> (aParam.RealValue());
10822 if (aApertureSize < 0)
10823 {
10824 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
10825 return 1;
10826 }
10827 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
10828 }
10829 else
10830 {
10831 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10832 return 1;
10833 }
10834 }
eb85ed36 10835 else if (aFlag == "-exposure")
10836 {
10837 if (++anArgIter >= theArgNb)
10838 {
10839 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10840 return 1;
10841 }
10842
10843 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
10844 if (anExposure.IsRealValue())
10845 {
10846 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
10847 }
10848 else
10849 {
10850 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10851 return 1;
10852 }
10853 }
10854 else if (aFlag == "-whitepoint")
10855 {
10856 if (++anArgIter >= theArgNb)
10857 {
10858 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10859 return 1;
10860 }
10861
10862 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
10863 if (aWhitePoint.IsRealValue())
10864 {
10865 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
10866 }
10867 else
10868 {
10869 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10870 return 1;
10871 }
10872 }
10873 else if (aFlag == "-tonemapping")
10874 {
10875 if (++anArgIter >= theArgNb)
10876 {
10877 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10878 return 1;
10879 }
10880
10881 TCollection_AsciiString aMode (theArgVec[anArgIter]);
10882 aMode.LowerCase();
10883
10884 if (aMode == "disabled")
10885 {
10886 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
10887 }
10888 else if (aMode == "filmic")
10889 {
10890 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
10891 }
10892 else
10893 {
10894 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10895 return 1;
10896 }
10897 }
15669413 10898 else if (aFlag == "-performancestats"
10899 || aFlag == "-performancecounters"
10900 || aFlag == "-perfstats"
10901 || aFlag == "-perfcounters"
10902 || aFlag == "-stats")
10903 {
10904 if (++anArgIter >= theArgNb)
10905 {
10906 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10907 return 1;
10908 }
10909
10910 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
10911 aFlagsStr.LowerCase();
10912 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
10913 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
10914 {
10915 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10916 return 1;
10917 }
10918 aView->ChangeRenderingParams().CollectedStats = aFlags;
10919 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
10920 }
10921 else if (aFlag == "-perfupdateinterval"
10922 || aFlag == "-statsupdateinterval")
10923 {
10924 if (++anArgIter >= theArgNb)
10925 {
10926 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10927 return 1;
10928 }
10929 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
10930 }
e276548b 10931 else
10932 {
bc8c79bb 10933 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
10934 return 1;
e276548b 10935 }
10936 }
189f85a3 10937
10938 return 0;
10939}
10940
10941//=======================================================================
10942//function : VProgressiveMode
10943//purpose :
10944//=======================================================================
10945#if defined(_WIN32)
10946static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
10947 Standard_Integer /*theNbArgs*/,
10948 const char** /*theArgs*/)
10949{
10950 Handle(V3d_View) aView = ViewerTest::CurrentView();
10951 if (aView.IsNull())
10952 {
10953 std::cerr << "Error: no active viewer!\n";
10954 return 1;
10955 }
10956
10957 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
10958
10959 for (;;)
10960 {
10961 aView->Redraw();
10962
10963 Standard_Boolean toExit = Standard_False;
10964
10965 MSG aMsg;
ad03c234 10966 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
189f85a3 10967 {
10968 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
10969 {
10970 toExit = Standard_True;
10971 }
10972
10973 TranslateMessage (&aMsg);
ad03c234 10974 DispatchMessageW (&aMsg);
189f85a3 10975 }
10976
10977 if (toExit)
10978 {
10979 break;
10980 }
10981 }
10982
e276548b 10983 return 0;
10984}
189f85a3 10985#endif
e276548b 10986
b7cd4ba7 10987//=======================================================================
10988//function : VFrustumCulling
10989//purpose : enables/disables view volume's culling.
10990//=======================================================================
10991static int VFrustumCulling (Draw_Interpretor& theDI,
10992 Standard_Integer theArgNb,
10993 const char** theArgVec)
10994{
10995 Handle(V3d_View) aView = ViewerTest::CurrentView();
10996 if (aView.IsNull())
10997 {
10998 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
10999 return 1;
11000 }
11001
11002 if (theArgNb < 2)
11003 {
11004 theDI << (aView->IsCullingEnabled() ? "on" : "off");
11005 return 0;
11006 }
11007 else if (theArgNb != 2)
11008 {
11009 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
11010 return 1;
11011 }
11012
11013 TCollection_AsciiString aModeStr (theArgVec[1]);
11014 aModeStr.LowerCase();
11015 Standard_Boolean toEnable = 0;
11016 if (aModeStr == "on")
11017 {
11018 toEnable = 1;
11019 }
11020 else if (aModeStr == "off")
11021 {
11022 toEnable = 0;
11023 }
11024 else
11025 {
11026 toEnable = Draw::Atoi (theArgVec[1]) != 0;
11027 }
11028
11029 aView->SetFrustumCulling (toEnable);
11030 aView->Redraw();
11031 return 0;
11032}
11033
c398b00e 11034//=======================================================================
11035//function : VHighlightSelected
11036//purpose :
11037//=======================================================================
11038static int VHighlightSelected (Draw_Interpretor& theDI,
11039 Standard_Integer theArgNb,
11040 const char** theArgVec)
11041{
11042 if (ViewerTest::GetAISContext().IsNull())
11043 {
11044 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
11045 return 1;
11046 }
11047
11048 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
11049
11050 if (theArgNb < 2)
11051 {
11052 theDI << (aContext->ToHilightSelected() ? "on" : "off");
11053 return 0;
11054 }
11055
11056 if (theArgNb != 2)
11057 {
11058 std::cout << theArgVec[0] << " error : wrong number of parameters."
11059 << "Type 'help" << theArgVec[0] << "' for more information.";
11060 return 1;
11061 }
11062
11063 // Parse parameter
11064 TCollection_AsciiString aMode (theArgVec[1]);
11065 aMode.LowerCase();
11066 Standard_Boolean toEnable = Standard_False;
11067 if (aMode.IsEqual ("on"))
11068 {
11069 toEnable = Standard_True;
11070 }
11071 else if (aMode.IsEqual ("off"))
11072 {
11073 toEnable = Standard_False;
11074 }
11075 else
11076 {
11077 toEnable = Draw::Atoi (theArgVec[1]) != 0;
11078 }
11079
11080 if (toEnable != aContext->ToHilightSelected())
11081 {
11082 aContext->SetToHilightSelected (toEnable);
11083
11084 // Move cursor to null position and back to process updating of detection
11085 // and highlighting of selected object immediatly.
11086 Standard_Integer aPixX = 0;
11087 Standard_Integer aPixY = 0;
11088 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
11089
11090 anEventManager->GetCurrentPosition (aPixX, aPixY);
11091 anEventManager->MoveTo (0, 0);
11092 anEventManager->MoveTo (aPixX, aPixY);
11093 }
11094
11095 return 0;
11096}
11097
0717ddc1 11098//=======================================================================
11099//function : VXRotate
11100//purpose :
11101//=======================================================================
11102static Standard_Integer VXRotate (Draw_Interpretor& di,
11103 Standard_Integer argc,
11104 const char ** argv)
11105{
11106 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
11107 if (aContext.IsNull())
11108 {
586db386 11109 di << argv[0] << "ERROR : use 'vinit' command before \n";
0717ddc1 11110 return 1;
11111 }
11112
11113 if (argc != 3)
11114 {
586db386 11115 di << "ERROR : Usage : " << argv[0] << " name angle\n";
0717ddc1 11116 return 1;
11117 }
11118
11119 TCollection_AsciiString aName (argv[1]);
11120 Standard_Real anAngle = Draw::Atof (argv[2]);
11121
11122 // find object
11123 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
11124 Handle(AIS_InteractiveObject) anIObj;
11125 if (!aMap.IsBound2 (aName) )
11126 {
586db386 11127 di << "Use 'vdisplay' before\n";
0717ddc1 11128 return 1;
11129 }
11130 else
11131 {
11132 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
11133
11134 gp_Trsf aTransform;
11135 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
11136 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
11137
11138 aContext->SetLocation (anIObj, aTransform);
11139 aContext->UpdateCurrentViewer();
11140 }
11141
11142 return 0;
11143}
11144
625e1958 11145//===============================================================================================
11146//class : ViewerTest_AISManipulator
11147//purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
11148//===============================================================================================
11149DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11150
11151class ViewerTest_AISManipulator : public AIS_Manipulator
11152{
11153public:
11154
11155 ViewerTest_AISManipulator() : AIS_Manipulator()
11156 {
11157 GetMapOfAISManipulators().Add (this);
11158 }
11159
11160 virtual ~ViewerTest_AISManipulator()
11161 {
11162 GetMapOfAISManipulators().Remove (this);
11163 }
11164
11165 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11166};
11167
11168IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11169IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11170
11171//===============================================================================================
11172//function : VManipulator
11173//purpose :
11174//===============================================================================================
11175static int VManipulator (Draw_Interpretor& theDi,
11176 Standard_Integer theArgsNb,
11177 const char** theArgVec)
11178{
11179 Handle(V3d_View) aView = ViewerTest::CurrentView();
11180 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
11181 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
11182 if (aView.IsNull()
11183 || aViewer.IsNull())
11184 {
11185 std::cerr << "No active viewer!\n";
11186 return 1;
11187 }
11188
11189 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
11190 Standard_Integer anArgIter = 1;
11191 for (; anArgIter < theArgsNb; ++anArgIter)
11192 {
11193 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
11194 }
11195
11196 ViewerTest_CmdParser aCmd;
11197 aCmd.AddDescription ("Manages manipulator for interactive objects:");
11198 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
11199 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
11200 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
11201 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
11202 aCmd.AddOption ("detach", "... - detach manipulator");
11203
11204 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
11205 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
11206 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
11207
11208 aCmd.AddOption ("move", "... x y z - move object");
11209 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
11210 aCmd.AddOption ("scale", "... factor - scale object");
11211
11212 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
11213 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
11214 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
11215 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
11216 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
11217 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
11218 aCmd.AddOption ("size", "... size - set size of manipulator");
11219 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
11220
11221 aCmd.Parse (theArgsNb, theArgVec);
11222
11223 if (aCmd.HasOption ("help"))
11224 {
11225 theDi.PrintHelp (theArgVec[0]);
11226 return 0;
11227 }
11228
11229 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
11230
11231 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
11232
11233 if (aName.IsEmpty())
11234 {
11235 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
11236 return 1;
11237 }
11238
11239 // ----------------------------------
11240 // detach existing manipulator object
11241 // ----------------------------------
11242
11243 if (aCmd.HasOption ("detach"))
11244 {
11245 if (!aMapAIS.IsBound2 (aName))
11246 {
11247 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
11248 return 1;
11249 }
11250
11251 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11252 if (aManipulator.IsNull())
11253 {
11254 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11255 return 1;
11256 }
11257
11258 aManipulator->Detach();
11259 aMapAIS.UnBind2 (aName);
0577ae8c 11260 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
625e1958 11261
11262 return 0;
11263 }
11264
11265 // -----------------------------------------------
11266 // find or create manipulator if it does not exist
11267 // -----------------------------------------------
11268
11269 Handle(AIS_Manipulator) aManipulator;
11270 if (!aMapAIS.IsBound2 (aName))
11271 {
11272 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
11273
11274 aManipulator = new ViewerTest_AISManipulator();
11275 aMapAIS.Bind (aManipulator, aName);
11276 }
11277 else
11278 {
11279 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11280 if (aManipulator.IsNull())
11281 {
11282 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11283 return 1;
11284 }
11285 }
11286
11287 // -----------------------------------------
11288 // change properties of manipulator instance
11289 // -----------------------------------------
11290
11291 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
11292 {
11293 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
11294 }
11295 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
11296 {
11297 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
11298 }
11299 if (aCmd.HasOption ("followRotation", 1, Standard_True))
11300 {
11301 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
11302 }
11303 if (aCmd.HasOption ("gap", 1, Standard_True))
11304 {
11305 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
11306 }
11307 if (aCmd.HasOption ("part", 3, Standard_True))
11308 {
11309 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
11310 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
11311 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
11312 if (aMode < 1 || aMode > 3)
11313 {
11314 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
11315 return 1;
11316 }
11317
11318 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
11319 }
11320 if (aCmd.HasOption ("pos", 3, Standard_True))
11321 {
11322 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
11323 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
11324 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
11325
11326 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
11327 }
11328 if (aCmd.HasOption ("size", 1, Standard_True))
11329 {
11330 aManipulator->SetSize (aCmd.ArgFloat ("size"));
11331 }
11332 if (aCmd.HasOption ("zoomable", 1, Standard_True))
11333 {
11334 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
11335
11336 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
11337 {
11338 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
11339 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
11340 }
11341 }
11342
11343 // ---------------------------------------------------
11344 // attach, detach or access manipulator from an object
11345 // ---------------------------------------------------
11346
11347 if (aCmd.HasOption ("attach"))
11348 {
11349 // Find an object and attach manipulator to it
11350 if (!aCmd.HasOption ("attach", 1, Standard_True))
11351 {
11352 return 1;
11353 }
11354
11355 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
11356 if (!aMapAIS.IsBound2 (anObjName))
11357 {
11358 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
11359 return 1;
11360 }
11361
11362 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapAIS.Find2 (anObjName));
11363 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
11364 for (; anIt.More(); anIt.Next())
11365 {
11366 if (anIt.Value()->IsAttached()
11367 && anIt.Value()->Object() == anObject)
11368 {
11369 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
11370 return 1;
11371 }
11372 }
11373
11374 AIS_Manipulator::OptionsForAttach anOptions;
11375 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
11376 {
11377 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
11378 }
11379 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
11380 {
11381 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
11382 }
11383 if (aCmd.HasOption ("enableModes", 1, Standard_True))
11384 {
11385 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
11386 }
11387
11388 aManipulator->Attach (anObject, anOptions);
11389 }
11390
11391 // --------------------------------------
11392 // apply transformation using manipulator
11393 // --------------------------------------
11394
11395 if (aCmd.HasOption ("startTransform", 2, Standard_True))
11396 {
11397 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
11398 }
11399 if (aCmd.HasOption ("transform", 2, Standard_True))
11400 {
11401 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
11402 }
11403 if (aCmd.HasOption ("stopTransform"))
11404 {
11405 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
11406
11407 aManipulator->StopTransform (toApply);
11408 }
11409
11410 gp_Trsf aT;
11411 if (aCmd.HasOption ("move", 3, Standard_True))
11412 {
11413 aT.SetTranslationPart (aCmd.ArgVec ("move"));
11414 }
11415 if (aCmd.HasOption ("rotate", 7, Standard_True))
11416 {
11417 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
11418 }
11419 if (aCmd.HasOption ("scale", 1))
11420 {
11421 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
11422 }
11423
11424 if (aT.Form() != gp_Identity)
11425 {
11426 aManipulator->Transform (aT);
11427 }
11428
0577ae8c 11429 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
625e1958 11430
11431 return 0;
11432}
11433
8e5fb5ea 11434//===============================================================================================
11435//function : VSelectionProperties
11436//purpose :
11437//===============================================================================================
11438static int VSelectionProperties (Draw_Interpretor& theDi,
11439 Standard_Integer theArgsNb,
11440 const char** theArgVec)
11441{
11442 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
11443 if (aCtx.IsNull())
11444 {
11445 std::cerr << "No active viewer!\n";
11446 return 1;
11447 }
11448
f838dac4 11449 Standard_Boolean toPrint = theArgsNb == 1;
11450 Standard_Boolean toRedraw = Standard_False;
11451 Standard_Integer anArgIter = 1;
11452 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
11453 if (anArgIter < theArgsNb)
11454 {
11455 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
11456 anArgFirst.LowerCase();
11457 ++anArgIter;
11458 if (anArgFirst == "dynhighlight"
11459 || anArgFirst == "dynhilight"
11460 || anArgFirst == "dynamichighlight"
11461 || anArgFirst == "dynamichilight")
11462 {
11463 aType = Prs3d_TypeOfHighlight_Dynamic;
11464 }
11465 else if (anArgFirst == "localdynhighlight"
11466 || anArgFirst == "localdynhilight"
11467 || anArgFirst == "localdynamichighlight"
11468 || anArgFirst == "localdynamichilight")
11469 {
11470 aType = Prs3d_TypeOfHighlight_LocalDynamic;
11471 }
11472 else if (anArgFirst == "selhighlight"
11473 || anArgFirst == "selhilight"
11474 || anArgFirst == "selectedhighlight"
11475 || anArgFirst == "selectedhilight")
11476 {
11477 aType = Prs3d_TypeOfHighlight_Selected;
11478 }
11479 else if (anArgFirst == "localselhighlight"
11480 || anArgFirst == "localselhilight"
11481 || anArgFirst == "localselectedhighlight"
11482 || anArgFirst == "localselectedhilight")
11483 {
11484 aType = Prs3d_TypeOfHighlight_LocalSelected;
11485 }
11486 else
11487 {
11488 --anArgIter;
11489 }
11490 }
11491 for (; anArgIter < theArgsNb; ++anArgIter)
11492 {
11493 TCollection_AsciiString anArg (theArgVec[anArgIter]);
11494 anArg.LowerCase();
11495 if (anArg == "-help")
11496 {
11497 theDi.PrintHelp (theArgVec[0]);
11498 return 0;
11499 }
11500 else if (anArg == "-print")
11501 {
11502 toPrint = Standard_True;
11503 }
11504 else if (anArg == "-autoactivate")
11505 {
11506 Standard_Boolean toEnable = Standard_True;
11507 if (anArgIter + 1 < theArgsNb
11508 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11509 {
11510 ++anArgIter;
11511 }
11512 aCtx->SetAutoActivateSelection (toEnable);
11513 }
14c4193d 11514 else if (anArg == "-pickstrategy"
11515 || anArg == "-pickingstrategy")
11516 {
11517 if (++anArgIter >= theArgsNb)
11518 {
11519 std::cout << "Syntax error: type of highlighting is undefined\n";
11520 return 1;
11521 }
11522
11523 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11524 TCollection_AsciiString aVal (theArgVec[anArgIter]);
11525 aVal.LowerCase();
11526 if (aVal == "first"
11527 || aVal == "firstaccepted"
11528 || aVal == "firstacceptable")
11529 {
11530 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11531 }
11532 else if (aVal == "topmost"
11533 || aVal == "onlyTopmost")
11534 {
11535 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
11536 }
11537 else
11538 {
11539 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
11540 return 1;
11541 }
11542
11543 aCtx->SetPickingStrategy (aStrategy);
11544 }
f838dac4 11545 else if (anArg == "-pixtol"
11546 && anArgIter + 1 < theArgsNb)
11547 {
11548 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
11549 }
11550 else if ((anArg == "-mode"
11551 || anArg == "-dispmode")
11552 && anArgIter + 1 < theArgsNb)
11553 {
11554 if (aType == Prs3d_TypeOfHighlight_None)
11555 {
11556 std::cout << "Syntax error: type of highlighting is undefined\n";
11557 return 1;
11558 }
8e5fb5ea 11559
f838dac4 11560 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
11561 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11562 aStyle->SetDisplayMode (aDispMode);
11563 toRedraw = Standard_True;
11564 }
11565 else if (anArg == "-layer"
11566 && anArgIter + 1 < theArgsNb)
11567 {
11568 if (aType == Prs3d_TypeOfHighlight_None)
11569 {
11570 std::cout << "Syntax error: type of highlighting is undefined\n";
11571 return 1;
11572 }
8e5fb5ea 11573
f838dac4 11574 const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]);
11575 if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN)
11576 {
11577 TColStd_SequenceOfInteger aLayers;
11578 aCtx->CurrentViewer()->GetAllZLayers (aLayers);
11579 if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end())
11580 {
11581 std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n";
11582 return 1;
11583 }
11584 }
8e5fb5ea 11585
f838dac4 11586 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11587 aStyle->SetZLayer (aNewLayer);
11588 toRedraw = Standard_True;
11589 }
11590 else if (anArg == "-hicolor"
11591 || anArg == "-selcolor"
11592 || anArg == "-color")
11593 {
11594 if (anArg.StartsWith ("-hi"))
11595 {
11596 aType = Prs3d_TypeOfHighlight_Dynamic;
11597 }
11598 else if (anArg.StartsWith ("-sel"))
11599 {
11600 aType = Prs3d_TypeOfHighlight_Selected;
11601 }
11602 else if (aType == Prs3d_TypeOfHighlight_None)
11603 {
11604 std::cout << "Syntax error: type of highlighting is undefined\n";
11605 return 1;
11606 }
8e5fb5ea 11607
f838dac4 11608 Quantity_Color aColor;
11609 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
11610 theArgVec + anArgIter + 1,
11611 aColor);
11612 if (aNbParsed == 0)
11613 {
11614 std::cout << "Syntax error: need more arguments.\n";
11615 return 1;
11616 }
11617 anArgIter += aNbParsed;
8e5fb5ea 11618
f838dac4 11619 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11620 aStyle->SetColor (aColor);
11621 toRedraw = Standard_True;
11622 }
11623 else if ((anArg == "-transp"
11624 || anArg == "-transparency"
11625 || anArg == "-hitransp"
11626 || anArg == "-seltransp"
11627 || anArg == "-hitransplocal"
11628 || anArg == "-seltransplocal")
11629 && anArgIter + 1 < theArgsNb)
11630 {
11631 if (anArg.StartsWith ("-hi"))
11632 {
11633 aType = Prs3d_TypeOfHighlight_Dynamic;
11634 }
11635 else if (anArg.StartsWith ("-sel"))
11636 {
11637 aType = Prs3d_TypeOfHighlight_Selected;
11638 }
11639 else if (aType == Prs3d_TypeOfHighlight_None)
11640 {
11641 std::cout << "Syntax error: type of highlighting is undefined\n";
11642 return 1;
11643 }
8e5fb5ea 11644
f838dac4 11645 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
11646 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11647 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
11648 toRedraw = Standard_True;
11649 }
11650 else if ((anArg == "-mat"
11651 || anArg == "-material")
11652 && anArgIter + 1 < theArgsNb)
11653 {
11654 if (aType == Prs3d_TypeOfHighlight_None)
11655 {
11656 std::cout << "Syntax error: type of highlighting is undefined\n";
11657 return 1;
11658 }
8e5fb5ea 11659
f838dac4 11660 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11661 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
11662 if (aMatName != Graphic3d_NOM_DEFAULT)
11663 {
11664 ++anArgIter;
11665 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
11666 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
11667 Graphic3d_MaterialAspect aMat (aMatName);
11668 aMat.SetColor (aStyle->Color());
11669 aMat.SetTransparency (aStyle->Transparency());
11670 anAspect->SetFrontMaterial (aMat);
11671 anAspect->SetInteriorColor (aStyle->Color());
11672 aStyle->SetBasicFillAreaAspect (anAspect);
11673 }
11674 else
11675 {
11676 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
11677 }
11678 toRedraw = Standard_True;
11679 }
11680 else
11681 {
11682 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
11683 }
8e5fb5ea 11684 }
11685
f838dac4 11686 if (toPrint)
8e5fb5ea 11687 {
f838dac4 11688 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
11689 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
8e5fb5ea 11690 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
11691 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
f838dac4 11692 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
11693 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
11694 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
11695 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
11696 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
11697 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
11698 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
11699 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
8e5fb5ea 11700 }
11701
11702 if (aCtx->NbSelected() != 0 && toRedraw)
11703 {
11704 aCtx->HilightSelected (Standard_True);
11705 }
11706
11707 return 0;
11708}
11709
decdee7d 11710//===============================================================================================
11711//function : VDumpSelectionImage
11712//purpose :
11713//===============================================================================================
11714static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
11715 Standard_Integer theArgsNb,
11716 const char** theArgVec)
11717{
11718 if (theArgsNb < 2)
11719 {
11720 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
11721 return 1;
11722 }
11723
11724 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
11725 if (aContext.IsNull())
11726 {
11727 std::cout << "Error: no active view.\n";
11728 return 1;
11729 }
11730
11731 TCollection_AsciiString aFile;
11732 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
dc858f4c 11733 Image_Format anImgFormat = Image_Format_BGR;
decdee7d 11734 Standard_Integer aPickedIndex = 1;
11735 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
11736 {
11737 TCollection_AsciiString aParam (theArgVec[anArgIter]);
11738 aParam.LowerCase();
11739 if (aParam == "-type")
11740 {
11741 if (++anArgIter >= theArgsNb)
11742 {
11743 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
11744 return 1;
11745 }
11746
11747 TCollection_AsciiString aValue (theArgVec[anArgIter]);
11748 aValue.LowerCase();
11749 if (aValue == "depth"
11750 || aValue == "normdepth"
11751 || aValue == "normalizeddepth")
11752 {
11753 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
dc858f4c 11754 anImgFormat = Image_Format_GrayF;
decdee7d 11755 }
11756 if (aValue == "depthinverted"
11757 || aValue == "normdepthinverted"
11758 || aValue == "normalizeddepthinverted"
11759 || aValue == "inverted")
11760 {
11761 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
dc858f4c 11762 anImgFormat = Image_Format_GrayF;
decdee7d 11763 }
11764 else if (aValue == "unnormdepth"
11765 || aValue == "unnormalizeddepth")
11766 {
11767 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
dc858f4c 11768 anImgFormat = Image_Format_GrayF;
decdee7d 11769 }
11770 else if (aValue == "objectcolor"
11771 || aValue == "object"
11772 || aValue == "color")
11773 {
11774 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
11775 }
11776 else if (aValue == "entitycolor"
11777 || aValue == "entity")
11778 {
11779 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
11780 }
11781 else if (aValue == "ownercolor"
11782 || aValue == "owner")
11783 {
11784 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
11785 }
11786 else if (aValue == "selectionmodecolor"
11787 || aValue == "selectionmode"
11788 || aValue == "selmodecolor"
11789 || aValue == "selmode")
11790 {
11791 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
11792 }
11793 }
11794 else if (aParam == "-picked"
11795 || aParam == "-pickeddepth"
11796 || aParam == "-pickedindex")
11797 {
11798 if (++anArgIter >= theArgsNb)
11799 {
11800 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
11801 return 1;
11802 }
11803
11804 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
11805 }
11806 else if (aFile.IsEmpty())
11807 {
11808 aFile = theArgVec[anArgIter];
11809 }
11810 else
11811 {
11812 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
11813 return 1;
11814 }
11815 }
11816 if (aFile.IsEmpty())
11817 {
11818 std::cout << "Syntax error: image file name is missing.\n";
11819 return 1;
11820 }
11821
11822 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
11823 Standard_Integer aWidth = 0, aHeight = 0;
11824 aView->Window()->Size (aWidth, aHeight);
11825
11826 Image_AlienPixMap aPixMap;
11827 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
11828 {
11829 std::cout << "Error: can't allocate image.\n";
11830 return 1;
11831 }
11832 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
11833 {
11834 std::cout << "Error: can't generate selection image.\n";
11835 return 1;
11836 }
11837 if (!aPixMap.Save (aFile))
11838 {
11839 std::cout << "Error: can't save selection image.\n";
11840 return 0;
11841 }
11842 return 0;
11843}
11844
7fd59977 11845//=======================================================================
11846//function : ViewerCommands
11847//purpose :
11848//=======================================================================
11849
11850void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
11851{
11852
11853 const char *group = "ZeViewer";
18d715bd 11854 theCommands.Add("vinit",
fd3f6bd0 11855 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
2e93433e 11856 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
fd3f6bd0 11857 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
11858 "\n\t\t: [-display displayName]"
11859 #endif
11860 "\n\t\t: Creates new View window with specified name viewName."
11861 "\n\t\t: By default the new view is created in the viewer and in"
11862 "\n\t\t: graphic driver shared with active view."
11863 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
11864 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
11865 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
11866#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
11867 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
11868 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
18d715bd 11869#endif
fd3f6bd0 11870 "\n\t\t: -left, -top pixel position of left top corner of the window."
11871 "\n\t\t: -width, -height width and heigth of window respectively."
9e04ccdc 11872 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
fd3f6bd0 11873 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
11874 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
2e93433e 11875 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
fd3f6bd0 11876 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
7fd59977 11877 __FILE__,VInit,group);
18d715bd 11878 theCommands.Add("vclose" ,
d0cc1cb7 11879 "[view_id [keep_context=0|1]]\n"
18d715bd 11880 "or vclose ALL - to remove all created views\n"
11881 " - removes view(viewer window) defined by its view_id.\n"
11882 " - keep_context: by default 0; if 1 and the last view is deleted"
11883 " the current context is not removed.",
11884 __FILE__,VClose,group);
11885 theCommands.Add("vactivate" ,
11886 "view_id"
11887 " - activates view(viewer window) defined by its view_id",
11888 __FILE__,VActivate,group);
11889 theCommands.Add("vviewlist",
11890 "vviewlist [format={tree, long}]"
11891 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
11892 " - format: format of result output, if tree the output is a tree view;"
11893 "otherwise it's a list of full view names. By default format = tree",
11894 __FILE__,VViewList,group);
7fd59977 11895 theCommands.Add("vhelp" ,
11896 "vhelp : display help on the viewer commands",
11897 __FILE__,VHelp,group);
11898 theCommands.Add("vtop" ,
27af3052 11899 "vtop or <T> : Top view. Orientation +X+Y" ,
7fd59977 11900 __FILE__,VTop,group);
44b8f2d6 11901 theCommands.Add("vbottom" ,
27af3052 11902 "vbottom : Bottom view. Orientation +X-Y" ,
44b8f2d6 11903 __FILE__,VBottom,group);
11904 theCommands.Add("vleft" ,
27af3052 11905 "vleft : Left view. Orientation -Y+Z" ,
44b8f2d6 11906 __FILE__,VLeft,group);
11907 theCommands.Add("vright" ,
27af3052 11908 "vright : Right view. Orientation +Y+Z" ,
44b8f2d6 11909 __FILE__,VRight,group);
7fd59977 11910 theCommands.Add("vaxo" ,
27af3052 11911 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
7fd59977 11912 __FILE__,VAxo,group);
44b8f2d6 11913 theCommands.Add("vfront" ,
27af3052 11914 "vfront : Front view. Orientation +X+Z" ,
44b8f2d6 11915 __FILE__,VFront,group);
11916 theCommands.Add("vback" ,
27af3052 11917 "vback : Back view. Orientation -X+Z" ,
44b8f2d6 11918 __FILE__,VBack,group);
7fd59977 11919 theCommands.Add("vpick" ,
11920 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
11921 VPick,group);
1beb58d7 11922 theCommands.Add("vfit",
11923 "vfit or <F> [-selected] [-noupdate]"
b586500b 11924 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
7fd59977 11925 __FILE__,VFit,group);
6262a303 11926 theCommands.Add ("vfitarea",
11927 "vfitarea x1 y1 x2 y2"
11928 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
11929 "\n\t\t: Fit view to show area located between two points"
11930 "\n\t\t: given in world 2D or 3D corrdinates.",
11931 __FILE__, VFitArea, group);
197ac94e 11932 theCommands.Add ("vzfit", "vzfit [scale]\n"
11933 " Matches Z near, Z far view volume planes to the displayed objects.\n"
11934 " \"scale\" - specifies factor to scale computed z range.\n",
11935 __FILE__, VZFit, group);
7fd59977 11936 theCommands.Add("vrepaint",
56689b27 11937 "vrepaint [-immediate]"
11938 "\n\t\t: force redraw",
7fd59977 11939 __FILE__,VRepaint,group);
11940 theCommands.Add("vclear",
faea8b40 11941 "vclear : vclear"
11942 "\n\t\t: remove all the object from the viewer",
7fd59977 11943 __FILE__,VClear,group);
11944 theCommands.Add("vsetbg",
11945 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
11946 __FILE__,VSetBg,group);
f8b2ed36 11947 theCommands.Add("vsetbgmode",
11948 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
11949 __FILE__,VSetBgMode,group);
7fd59977 11950 theCommands.Add("vsetgradientbg",
f8b2ed36 11951 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
7fd59977 11952 __FILE__,VSetGradientBg,group);
f8b2ed36 11953 theCommands.Add("vsetgrbgmode",
11954 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
11955 __FILE__,VSetGradientBgMode,group);
11956 theCommands.Add("vsetcolorbg",
11957 "vsetcolorbg : vsetcolorbg r g b : Set background color",
11958 __FILE__,VSetColorBg,group);
f42753ed 11959 theCommands.Add("vsetdefaultbg",
11960 "vsetdefaultbg r g b\n"
11961 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
11962 "\n\t\t: Set default viewer background fill color (flat/gradient).",
11963 __FILE__,VSetDefaultBg,group);
7fd59977 11964 theCommands.Add("vscale",
11965 "vscale : vscale X Y Z",
11966 __FILE__,VScale,group);
11967 theCommands.Add("vzbufftrihedron",
536d98e2 11968 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
11969 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
11970 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
11971 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
11972 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
11973 "\n\t\t: Displays a trihedron",
11974 __FILE__,VZBuffTrihedron,group);
7fd59977 11975 theCommands.Add("vrotate",
4af098ba 11976 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
11977 "\n : Option -mouseStart starts rotation according to the mouse position"
11978 "\n : Option -mouseMove continues rotation with angle computed"
11979 "\n : from last and new mouse position."
11980 "\n : vrotate AX AY AZ [X Y Z]",
7fd59977 11981 __FILE__,VRotate,group);
11982 theCommands.Add("vzoom",
11983 "vzoom : vzoom coef",
11984 __FILE__,VZoom,group);
11985 theCommands.Add("vpan",
11986 "vpan : vpan dx dy",
11987 __FILE__,VPan,group);
7fd59977 11988 theCommands.Add("vcolorscale",
4b3d6eb1 11989 "vcolorscale name [-noupdate|-update] [-demo]"
11990 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
11991 "\n\t\t: [-font HeightFont=20]"
11992 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
11993 "\n\t\t: [-smoothTransition {on|off}=off]"
11994 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
11995 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
11996 "\n\t\t: [-textpos {left|right|center|none}=right]"
11997 "\n\t\t: [-labelAtBorder {on|off}=on]"
11998 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
11999 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
12000 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
12001 "\n\t\t: [-xy Left=0 Bottom=0]"
12002 "\n\t\t: -demo - displays a color scale with demonstratio values"
12003 "\n\t\t: -colors - set colors for all intervals"
12004 "\n\t\t: -color - set color for specific interval"
12005 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
12006 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
12007 "\n\t\t: at border means the value inbetween neighbor intervals,"
12008 "\n\t\t: at center means the center value within current interval"
12009 "\n\t\t: -labels - set labels for all intervals"
12010 "\n\t\t: -freeLabels - same as -labels but does not require"
12011 "\n\t\t: matching the number of intervals"
12012 "\n\t\t: -label - set label for specific interval"
12013 "\n\t\t: -title - set title"
12014 "\n\t\t: -reversed - setup smooth color transition between intervals"
12015 "\n\t\t: -smoothTransition - swap colorscale direction"
12016 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
12017 __FILE__, VColorScale, group);
7fd59977 12018 theCommands.Add("vgraduatedtrihedron",
a79f67f8 12019 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
12020 "\t[-namefont Name] [-valuesfont Name]\n"
12021 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
12022 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
12023 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
12024 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
12025 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
12026 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
12027 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
12028 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
12029 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
536d98e2 12030 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
a79f67f8 12031 " - Displays or erases graduated trihedron"
12032 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
12033 " - namefont - font of axes names. Default: Arial\n"
12034 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
12035 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
12036 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
12037 " - valuesfont - font of axes values. Default: Arial\n"
12038 " - xcolor, ycolor, zcolor - color of axis and values\n"
12039 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
12040 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
7fd59977 12041 __FILE__,VGraduatedTrihedron,group);
3bffef55 12042 theCommands.Add("vtile" ,
12043 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
12044 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
12045 "\n\t\t: -totalSize the size of virtual bigger viewport"
12046 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
12047 "\n\t\t: -lowerLeft tile offset as lower left corner"
12048 "\n\t\t: -upperLeft tile offset as upper left corner",
12049 __FILE__, VTile, group);
59f45b7c 12050 theCommands.Add("vzlayer",
7c3ef2f7 12051 "vzlayer [layerId]"
12052 "\n\t\t: [-add|-delete|-get|-settings]"
4ecf34cc 12053 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
7c3ef2f7 12054 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
12055 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
12056 "\n\t\t: ZLayer list management:"
12057 "\n\t\t: -add add new z layer to viewer and print its id"
12058 "\n\t\t: -delete delete z layer"
12059 "\n\t\t: -get print sequence of z layers"
12060 "\n\t\t: -settings print status of z layer settings"
12061 "\n\t\t: -disable disables given setting"
12062 "\n\t\t: -enable enables given setting",
59f45b7c 12063 __FILE__,VZLayer,group);
20637bd2 12064 theCommands.Add("vlayerline",
12065 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
12066 __FILE__,VLayerLine,group);
2bd4c032 12067 theCommands.Add ("vgrid",
12068 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
12069 " : Mode - rectangular or circular"
12070 " : Type - lines or points",
12071 __FILE__, VGrid, group);
c40b7d58 12072 theCommands.Add ("vpriviledgedplane",
12073 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
12074 "\n\t\t: Ox, Oy, Oz - plane origin"
12075 "\n\t\t: Nx, Ny, Nz - plane normal direction"
12076 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
12077 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
12078 __FILE__, VPriviledgedPlane, group);
f25b82d6 12079 theCommands.Add ("vconvert",
12080 "vconvert v [Mode={window|view}]"
12081 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
12082 "\n\t\t: vconvert x y z [Mode={window|grid}]"
12083 "\n\t\t: window - convert to window coordinates, pixels"
12084 "\n\t\t: view - convert to view projection plane"
12085 "\n\t\t: grid - convert to model coordinates, given on grid"
12086 "\n\t\t: ray - convert projection ray to model coordiantes"
12087 "\n\t\t: - vconvert v window : convert view to window;"
12088 "\n\t\t: - vconvert v view : convert window to view;"
12089 "\n\t\t: - vconvert x y window : convert view to window;"
12090 "\n\t\t: - vconvert x y view : convert window to view;"
12091 "\n\t\t: - vconvert x y : convert window to model;"
12092 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
12093 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
12094 "\n\t\t: - vconvert x y z window : convert model to window;"
12095 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
12096 "\n\t\t: Converts the given coordinates to window/view/model space.",
12097 __FILE__, VConvert, group);
208e6839 12098 theCommands.Add ("vfps",
12099 "vfps [framesNb=100] : estimate average frame rate for active view",
12100 __FILE__, VFps, group);
58655684 12101 theCommands.Add ("vgldebug",
c87535af 12102 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
12103 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
12104 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
12105 "\n\t\t: Debug context can be requested only on Windows"
12106 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
12107 "\n\t\t: -sync - request synchronized debug GL context"
12108 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
12109 "\n\t\t: which are suppressed by default,"
12110 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
12111 "\n\t\t: which are suppressed by default",
58655684 12112 __FILE__, VGlDebug, group);
208e6839 12113 theCommands.Add ("vvbo",
58655684 12114 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
208e6839 12115 __FILE__, VVbo, group);
b5ac8292 12116 theCommands.Add ("vstereo",
f978241f 12117 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
12118 "\n\t\t: [-anaglyph Filter]"
12119 "\n\t\t: Control stereo output mode. Available modes for -mode:"
12120 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
12121 "\n\t\t: requires driver support."
12122 "\n\t\t: Should be called BEFORE vinit!"
12123 "\n\t\t: anaglyph - Anaglyph glasses"
12124 "\n\t\t: rowInterlaced - row-interlaced display"
12125 "\n\t\t: columnInterlaced - column-interlaced display"
12126 "\n\t\t: chessBoard - chess-board output"
12127 "\n\t\t: sideBySide - horizontal pair"
12128 "\n\t\t: overUnder - vertical pair"
12129 "\n\t\t: Available Anaglyph filters for -anaglyph:"
12130 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
12131 "\n\t\t: greenMagentaSimple",
b5ac8292 12132 __FILE__, VStereo, group);
a577aaab 12133 theCommands.Add ("vcaps",
8625ef7e 12134 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
1dfe71a6 12135 "\n\t\t: [-compatibleProfile {0|1}]"
56689b27 12136 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
f978241f 12137 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
8625ef7e 12138 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
12139 "\n\t\t: Modify particular graphic driver options:"
12140 "\n\t\t: FFP - use fixed-function pipeline instead of"
12141 "\n\t\t: built-in GLSL programs"
4e1523ef 12142 "\n\t\t: (requires compatible profile)"
8625ef7e 12143 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
12144 "\n\t\t: arrays to GPU memory)"
12145 "\n\t\t: sprite - use textured sprites instead of bitmaps"
f978241f 12146 "\n\t\t: vsync - switch VSync on or off"
56689b27 12147 "\n\t\t: winBuffer - allow using window buffer for rendering"
4e1523ef 12148 "\n\t\t: Context creation options:"
12149 "\n\t\t: softMode - software OpenGL implementation"
12150 "\n\t\t: compatibleProfile - backward-compatible profile"
f978241f 12151 "\n\t\t: quadbuffer - QuadBuffer"
8625ef7e 12152 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
12153 "\n\t\t: rendering paths producing the same visual result when"
12154 "\n\t\t: possible."
12155 "\n\t\t: Command is intended for testing old hardware compatibility.",
a577aaab 12156 __FILE__, VCaps, group);
f0430952 12157 theCommands.Add ("vmemgpu",
12158 "vmemgpu [f]: print system-dependent GPU memory information if available;"
12159 " with f option returns free memory in bytes",
12160 __FILE__, VMemGpu, group);
85e096c3 12161 theCommands.Add ("vreadpixel",
12162 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
12163 " : Read pixel value for active view",
12164 __FILE__, VReadPixel, group);
692613e5 12165 theCommands.Add("diffimage",
fd3f6bd0 12166 "diffimage imageFile1 imageFile2 [diffImageFile]"
12167 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
12168 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
12169 "\n\t\t: Compare two images by content and generate difference image."
12170 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
12171 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
692613e5 12172 __FILE__, VDiffImage, group);
4754e164 12173 theCommands.Add ("vselect",
2157d6ac 12174 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
4754e164 12175 "- emulates different types of selection:\n"
12176 "- 1) single click selection\n"
12177 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
12178 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
faea8b40 12179 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
12180 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
12181 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
2157d6ac 12182 " (partial inclusion - overlap - is not allowed by default)\n"
12183 "- 5) any of these selections with shift button pressed",
4754e164 12184 __FILE__, VSelect, group);
12185 theCommands.Add ("vmoveto",
8a590580 12186 "vmoveto [x y] [-reset]"
12187 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
12188 "\n\t\t: -reset resets current highlighting",
4754e164 12189 __FILE__, VMoveTo, group);
1beb58d7 12190 theCommands.Add ("vviewparams",
12191 "vviewparams [-args] [-scale [s]]"
12192 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
12193 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
12194 "\n\t\t: Manage current view parameters or prints all"
12195 "\n\t\t: current values when called without argument."
12196 "\n\t\t: -scale [s] prints or sets viewport relative scale"
12197 "\n\t\t: -eye [x y z] prints or sets eye location"
12198 "\n\t\t: -at [x y z] prints or sets center of look"
12199 "\n\t\t: -up [x y z] prints or sets direction of up vector"
12200 "\n\t\t: -proj [x y z] prints or sets direction of look"
12201 "\n\t\t: -center x y sets location of center of the screen in pixels"
12202 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
12203 "\n\t\t: or changes the size of its maximum dimension"
12204 "\n\t\t: -args prints vviewparams arguments for restoring current view",
197ac94e 12205 __FILE__, VViewParams, group);
1beb58d7 12206
2e93433e 12207 theCommands.Add("v2dmode",
12208 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
12209 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
12210 "\n\t\t: mode - switches On/Off rotation mode"
12211 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
12212 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
12213 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
12214 "\n\t\t: View camera position might be changed only by commands.",
12215 __FILE__, V2DMode, group);
12216
1beb58d7 12217 theCommands.Add("vanimation", "Alias for vanim",
12218 __FILE__, VAnimation, group);
12219
12220 theCommands.Add("vanim",
12221 "List existing animations:"
12222 "\n\t\t: vanim"
12223 "\n\t\t: Animation playback:"
12224 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
12225 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
12226 "\n\t\t: -speed playback speed (1.0 is normal speed)"
12227 "\n\t\t: -freeLook skip camera animations"
12228 "\n\t\t: -lockLoop disable any interactions"
12229 "\n\t\t:"
12230 "\n\t\t: Animation definition:"
12231 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
12232 "\n\t\t: [start TimeSec] [duration TimeSec]"
12233 "\n\t\t:"
12234 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
12235 "\n\t\t: specifies nested animations."
12236 "\n\t\t: There is no syntax to explicitly add new animation,"
12237 "\n\t\t: and all non-existing animations within the name will be"
12238 "\n\t\t: implicitly created on first use (including parents)."
12239 "\n\t\t:"
12240 "\n\t\t: Each animation might define the SINGLE action (see below),"
12241 "\n\t\t: like camera transition, object transformation or custom callback."
12242 "\n\t\t: Child animations can be used for defining concurrent actions."
12243 "\n\t\t:"
12244 "\n\t\t: Camera animation:"
12245 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
12246 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
12247 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
12248 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12249 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
12250 "\n\t\t: -atX camera Center positions pair"
12251 "\n\t\t: -upX camera Up directions pair"
12252 "\n\t\t: -scaleX camera Scale factors pair"
12253 "\n\t\t: Object animation:"
12254 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
12255 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
12256 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12257 "\n\t\t: -locX object Location points pair (translation)"
12258 "\n\t\t: -rotX object Orientations pair (quaternions)"
12259 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
12260 "\n\t\t: Custom callback:"
12261 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
12262 "\n\t\t: %Pts overall animation presentation timestamp"
12263 "\n\t\t: %LocalPts local animation timestamp"
12264 "\n\t\t: %Normalized local animation normalized value in range 0..1"
08f8a185 12265 "\n\t\t:"
12266 "\n\t\t: Video recording:"
12267 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
12268 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
12269 "\n\t\t: [-crf Value] [-preset Preset]"
12270 "\n\t\t: -fps video framerate"
12271 "\n\t\t: -format file format, container (matroska, etc.)"
12272 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
12273 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
12274 "\n\t\t: -crf constant rate factor (specific to codec)"
12275 "\n\t\t: -preset codec parameters preset (specific to codec)"
1beb58d7 12276 __FILE__, VAnimation, group);
12277
4754e164 12278 theCommands.Add("vchangeselected",
dc3fe572 12279 "vchangeselected shape"
4754e164 12280 "- adds to shape to selection or remove one from it",
12281 __FILE__, VChangeSelected, group);
4754e164 12282 theCommands.Add ("vnbselected",
faea8b40 12283 "vnbselected"
12284 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
6b62b2da 12285 theCommands.Add ("vcamera",
12286 "vcamera [-ortho] [-projtype]"
12287 "\n\t\t: [-persp]"
12288 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
12289 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
12290 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
12291 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
12292 "\n\t\t: Manage camera parameters."
12293 "\n\t\t: Prints current value when option called without argument."
12294 "\n\t\t: Orthographic camera:"
12295 "\n\t\t: -ortho activate orthographic projection"
12296 "\n\t\t: Perspective camera:"
12297 "\n\t\t: -persp activate perspective projection (mono)"
12298 "\n\t\t: -fovy field of view in y axis, in degrees"
12299 "\n\t\t: -distance distance of eye from camera center"
12300 "\n\t\t: Stereoscopic camera:"
12301 "\n\t\t: -stereo perspective projection (stereo)"
12302 "\n\t\t: -leftEye perspective projection (left eye)"
12303 "\n\t\t: -rightEye perspective projection (right eye)"
12304 "\n\t\t: -iod intraocular distance value"
12305 "\n\t\t: -iodType distance type, absolute or relative"
12306 "\n\t\t: -zfocus stereographic focus value"
12307 "\n\t\t: -zfocusType focus type, absolute or relative",
12308 __FILE__, VCamera, group);
b5ac8292 12309 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
197ac94e 12310 "- vautozfit [on={1|0}] [scale]\n"
12311 " Prints or changes parameters of automatic z-fit mode:\n"
12312 " \"on\" - turns automatic z-fit on or off\n"
12313 " \"scale\" - specifies factor to scale computed z range.\n",
12314 __FILE__, VAutoZFit, group);
b5ac8292 12315 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
12316 " vzrange - without parameters shows current values\n"
12317 " vzrange [znear] [zfar] - applies provided values to view",
12318 __FILE__,VZRange, group);
4754e164 12319 theCommands.Add ("vpurgedisplay",
eb4320f2 12320 "vpurgedisplay"
4754e164 12321 "- removes structures which don't belong to objects displayed in neutral point",
12322 __FILE__, VPurgeDisplay, group);
12323 theCommands.Add("vsetviewsize",
12324 "vsetviewsize size",
12325 __FILE__,VSetViewSize,group);
12326 theCommands.Add("vmoveview",
12327 "vmoveview Dx Dy Dz [Start = 1|0]",
12328 __FILE__,VMoveView,group);
12329 theCommands.Add("vtranslateview",
12330 "vtranslateview Dx Dy Dz [Start = 1|0)]",
12331 __FILE__,VTranslateView,group);
12332 theCommands.Add("vturnview",
12333 "vturnview Ax Ay Az [Start = 1|0]",
12334 __FILE__,VTurnView,group);
269294d6 12335 theCommands.Add("vtextureenv",
12336 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
12337 "or user-defined file and optionally applying texture mapping parameters\n"
12338 " Usage:\n"
12339 " vtextureenv off - disables environment mapping\n"
12340 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
12341 " std_texture = (0..7)\n"
12342 " rep = {clamp|repeat}\n"
12343 " mod = {decal|modulate}\n"
12344 " flt = {nearest|bilinear|trilinear}\n"
12345 " ss, st - scale factors for s and t texture coordinates\n"
12346 " ts, tt - translation for s and t texture coordinates\n"
12347 " rot - texture rotation angle in degrees",
12348 __FILE__, VTextureEnv, group);
1eeef710 12349 theCommands.Add("vhlr",
12350 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
12351 "\n\t\t: Hidden Line Removal algorithm."
12352 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
12353 "\n\t\t: -algoType type of HLR algorithm.\n",
0a768f56 12354 __FILE__,VHLR,group);
1eeef710 12355 theCommands.Add("vhlrtype",
12356 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
12357 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
12358 "\n\t\t: 'algo' - exact HLR algorithm is applied"
12359 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
12360 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
0a768f56 12361 __FILE__,VHLRType,group);
3e05329c 12362 theCommands.Add("vclipplane",
12363 "vclipplane planeName [{0|1}]"
25c35042 12364 "\n\t\t: [-equation1 A B C D]"
12365 "\n\t\t: [-equation2 A B C D]"
12366 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
32ca7711 12367 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
3e05329c 12368 "\n\t\t: [-maxPlanes]"
12369 "\n\t\t: [-capping {0|1}]"
12370 "\n\t\t: [-color R G B] [-hatch {on|off|ID}]"
12371 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
12372 "\n\t\t: [-texRotate Angle]"
12373 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
12374 "\n\t\t: [-useObjShader {0|1}]"
12375 "\n\t\t: Clipping planes management:"
12376 "\n\t\t: -maxPlanes print plane limit for view"
12377 "\n\t\t: -delete delete plane with given name"
12378 "\n\t\t: {off|on|0|1} turn clipping on/off"
12379 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
12380 "\n\t\t: applied to active View when list is omitted"
12381 "\n\t\t: -equation A B C D change plane equation"
12382 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
12383 "\n\t\t: Capping options:"
12384 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
12385 "\n\t\t: -color R G B set capping color"
12386 "\n\t\t: -texName Texture set capping texture"
12387 "\n\t\t: -texScale SX SY set capping tex scale"
12388 "\n\t\t: -texOrigin TX TY set capping tex origin"
12389 "\n\t\t: -texRotate Angle set capping tex rotation"
12390 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
12391 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
12392 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
12393 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
12394 __FILE__, VClipPlane, group);
392ac980 12395 theCommands.Add("vdefaults",
4c513386 12396 "vdefaults [-absDefl value]"
12397 "\n\t\t: [-devCoeff value]"
12398 "\n\t\t: [-angDefl value]"
12399 "\n\t\t: [-autoTriang {off/on | 0/1}]"
12400 , __FILE__, VDefaults, group);
12381341 12401 theCommands.Add("vlight",
816d03ee 12402 "tool to manage light sources, without arguments shows list of lights."
12403 "\n Main commands: "
992ed6b3 12404 "\n '-clear' to clear lights"
12405 "\n '-{def}aults' to load deafault lights"
12406 "\n '-add' <type> to add any light source"
816d03ee 12407 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
12408 "\n 'change' <lightId> to edit light source with specified lightId"
12409 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
992ed6b3 12410 "\n -layer Id"
12411 "\n -{pos}ition X Y Z"
12412 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
12413 "\n -color colorName"
12414 "\n -{head}light 0|1"
12415 "\n -{sm}oothness value"
12416 "\n -{int}ensity value"
12417 "\n -{constAtten}uation value"
12418 "\n -{linearAtten}uation value"
12419 "\n -angle angleDeg"
12420 "\n -{spotexp}onent value"
12421 "\n -local|-global"
12422 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
12423 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
12381341 12424 __FILE__, VLight, group);
6b62b2da 12425 theCommands.Add("vraytrace",
12426 "vraytrace [0|1]"
189f85a3 12427 "\n\t\t: Turns on/off ray-tracing renderer."
6b62b2da 12428 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
12429 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
12430 __FILE__, VRenderParams, group);
bc8c79bb 12431 theCommands.Add("vrenderparams",
12432 "\n Manages rendering parameters: "
a1073ae2 12433 "\n '-raster' Disables GPU ray-tracing"
12434 "\n '-msaa 0..4' Specifies number of samples for MSAA"
12435 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
f88457e6 12436 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
c40eb6b9 12437 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
a1073ae2 12438 "\n '-rendScale value Rendering resolution scale factor"
12439 "\n '-rayTrace' Enables GPU ray-tracing"
12440 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
12441 "\n '-shadows on|off' Enables/disables shadows rendering"
12442 "\n '-reflections on|off' Enables/disables specular reflections"
12443 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
12444 "\n '-gleam on|off' Enables/disables transparency shadow effects"
12445 "\n '-gi on|off' Enables/disables global illumination effects"
12446 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
12447 "\n '-env on|off' Enables/disables environment map background"
12448 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
12449 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
12450 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
12451 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
12452 "\n '-nbtiles 64..1024' Specifies number of screen tiles in ISS mode"
12453 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
12454 "\n '-shadingModel model' Controls shading model from enumeration"
12455 "\n color, flat, gouraud, phong"
12456 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
b27ab03d 12457 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
12458 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
eb85ed36 12459 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
12460 "\n '-whitepoint value' White point value for filmic tone mapping"
12461 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
15669413 12462 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points|gpuMem|basic|extended|nofps'"
12463 "\n Show/hide performance counters (flags can be combined)"
12464 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
8625ef7e 12465 "\n Unlike vcaps, these parameters dramatically change visual properties."
12466 "\n Command is intended to control presentation quality depending on"
12467 "\n hardware capabilities and performance.",
bc8c79bb 12468 __FILE__, VRenderParams, group);
b7cd4ba7 12469 theCommands.Add("vfrustumculling",
12470 "vfrustumculling [toEnable]: enables/disables objects clipping",
12471 __FILE__,VFrustumCulling,group);
c398b00e 12472 theCommands.Add("vhighlightselected",
12473 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
12474 "Without arguments it shows if highlighting of selected objects is enabled now.",
12475 __FILE__,VHighlightSelected,group);
49e1a5c7 12476 theCommands.Add ("vplace",
12477 "vplace dx dy"
12478 "\n\t\t: Places the point (in pixels) at the center of the window",
12479 __FILE__, VPlace, group);
0717ddc1 12480 theCommands.Add("vxrotate",
12481 "vxrotate",
12482 __FILE__,VXRotate,group);
12483
625e1958 12484 theCommands.Add("vmanipulator",
12485 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
12486 "\n tool to create and manage AIS manipulators."
12487 "\n Options: "
12488 "\n '-attach AISObject' attach manipulator to AISObject"
12489 "\n '-adjustPosition {0|1}' adjust position when attaching"
12490 "\n '-adjustSize {0|1}' adjust size when attaching"
12491 "\n '-enableModes {0|1}' enable modes when attaching"
12492 "\n '-detach' detach manipulator"
12493 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
12494 "\n '-transform mouse_x mouse_y' - invoke transformation"
12495 "\n '-stopTransform [abort]' - invoke stop of transformation"
12496 "\n '-move x y z' - move attached object"
12497 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
12498 "\n '-scale factor' - scale attached object"
12499 "\n '-autoActivate {0|1}' - set activation on detection"
12500 "\n '-followTranslation {0|1}' - set following translation transform"
12501 "\n '-followRotation {0|1}' - set following rotation transform"
12502 "\n '-gap value' - set gap between sub-parts"
12503 "\n '-part axis mode {0|1}' - set visual part"
12504 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
12505 "\n '-size value' - set size of manipulator"
12506 "\n '-zoomable {0|1}' - set zoom persistence",
12507 __FILE__, VManipulator, group);
12508
8e5fb5ea 12509 theCommands.Add("vselprops",
f838dac4 12510 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
8e5fb5ea 12511 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
12512 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
14c4193d 12513 "\n -pickStrategy {first|topmost} : defines picking strategy"
12514 "\n 'first' to pick first acceptable (default)"
12515 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
8e5fb5ea 12516 "\n -pixTol value : sets up pixel tolerance"
f838dac4 12517 "\n -dispMode dispMode : sets display mode for highlighting"
12518 "\n -layer ZLayer : sets ZLayer for highlighting"
12519 "\n -color {name|r g b} : sets highlight color"
12520 "\n -transp value : sets transparency coefficient for highlight"
12521 "\n -material material : sets highlight material"
8e5fb5ea 12522 "\n -print : prints current state of all mentioned parameters",
12523 __FILE__, VSelectionProperties, group);
12524
decdee7d 12525 theCommands.Add ("vseldump",
12526 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
12527 "\n\t\t: Generate an image based on detection results:"
12528 "\n\t\t: depth normalized depth values"
12529 "\n\t\t: unnormDepth unnormalized depth values"
12530 "\n\t\t: object color of detected object"
12531 "\n\t\t: owner color of detected owner"
12532 "\n\t\t: selMode color of selection mode"
12533 "\n\t\t: entity color of etected entity",
12534 __FILE__, VDumpSelectionImage, group);
12535
189f85a3 12536#if defined(_WIN32)
12537 theCommands.Add("vprogressive",
12538 "vprogressive",
12539 __FILE__, VProgressiveMode, group);
12540#endif
7fd59977 12541}