0029021: Coding Rules - eliminate GCC warnings in Qt sample
[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>
29#include <DBRep.hxx>
08f8a185 30#include <Draw_ProgressIndicator.hxx>
61b0191c 31#include <Graphic3d_ArrayOfPolylines.hxx>
2bd4c032 32#include <Graphic3d_AspectMarker3d.hxx>
7fd59977 33#include <Graphic3d_ExportFormat.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>
7fd59977 81
57c28b61 82#ifdef _WIN32
25289ec1 83#undef DrawText
84#endif
85
692613e5 86#include <cstdlib>
25289ec1 87
58655684 88#if defined(_WIN32)
4fe56619 89 #include <WNT_WClass.hxx>
90 #include <WNT_Window.hxx>
4fe56619 91#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 92 #include <Cocoa_Window.hxx>
7fd59977 93#else
4fe56619 94 #include <Xw_Window.hxx>
95 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
96 #include <X11/Xutil.h>
97 #include <tk.h>
7fd59977 98#endif
99
b514beda 100// Auxiliary definitions
101static const char THE_KEY_DELETE = 127;
7fd59977 102
103//==============================================================================
104// VIEWER GLOBAL VARIABLES
105//==============================================================================
106
107Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
b514beda 108Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
7fd59977 109
110Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
4754e164 111extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
7fd59977 112
b514beda 113extern int VErase (Draw_Interpretor& theDI,
114 Standard_Integer theArgNb,
115 const char** theArgVec);
116
58655684 117#if defined(_WIN32)
7fd59977 118static Handle(WNT_Window)& VT_GetWindow() {
119 static Handle(WNT_Window) WNTWin;
120 return WNTWin;
121}
4fe56619 122#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 123static Handle(Cocoa_Window)& VT_GetWindow()
124{
125 static Handle(Cocoa_Window) aWindow;
126 return aWindow;
127}
128extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
18d715bd 129extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
130extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
131
7fd59977 132#else
7fd59977 133static Handle(Xw_Window)& VT_GetWindow(){
134 static Handle(Xw_Window) XWWin;
135 return XWWin;
136}
7fd59977 137
138static void VProcessEvents(ClientData,int);
139#endif
140
18d715bd 141static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
142{
143 static Handle(Aspect_DisplayConnection) aDisplayConnection;
144 return aDisplayConnection;
145}
146
147static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
148{
149 GetDisplayConnection() = theDisplayConnection;
150}
151
58655684 152#if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 153Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
dc3fe572 154{
0ebaa4db 155 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
58655684 156#if defined(_WIN32)
18d715bd 157 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
158 if (!aWindow.IsNull())
159 return aWindow->HWindow();
160#elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
161 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
162 if (!aWindow.IsNull())
163 return aWindow->XWindow();
164#endif
165 return aWindowHandle;
dc3fe572 166}
18d715bd 167#endif
dc3fe572 168
18d715bd 169NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
58655684 170static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
18d715bd 171static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
58655684 172static OpenGl_Caps ViewerTest_myDefaultCaps;
18d715bd 173
7fd59977 174static void OSWindowSetup();
175
f42753ed 176static struct
177{
178 Quantity_Color FlatColor;
179 Quantity_Color GradientColor1;
180 Quantity_Color GradientColor2;
181 Aspect_GradientFillMethod FillMethod;
182} ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
183
7fd59977 184//==============================================================================
185// EVENT GLOBAL VARIABLES
186//==============================================================================
187
188static int Start_Rot = 0;
1eeef710 189Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
4fe56619 190int X_Motion = 0; // Current cursor position
191int Y_Motion = 0;
192int X_ButtonPress = 0; // Last ButtonPress position
193int Y_ButtonPress = 0;
194Standard_Boolean IsDragged = Standard_False;
8abada55 195Standard_Boolean DragFirst = Standard_False;
1beb58d7 196Standard_Boolean TheIsAnimating = Standard_False;
7fd59977 197
b12e1c7b 198
199Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
200{
201 static Handle(AIS_RubberBand) aBand;
202 if (aBand.IsNull())
203 {
69adb9ce 204 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
205 aBand->SetDisplayMode (0);
b12e1c7b 206 }
207 return aBand;
208}
209
625e1958 210typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
211
212Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
213{
214 static ViewerTest_MapOfAISManipulators aMap;
215 return aMap;
216}
217
218Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
219{
220 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
221 for (; anIt.More(); anIt.Next())
222 {
223 if (anIt.Value()->HasActiveMode())
224 {
225 return anIt.Value();
226 }
227 }
228 return NULL;
229}
230
7fd59977 231//==============================================================================
232
57c28b61 233#ifdef _WIN32
7fd59977 234static LRESULT WINAPI ViewerWindowProc(
235 HWND hwnd,
236 UINT uMsg,
237 WPARAM wParam,
238 LPARAM lParam );
239static LRESULT WINAPI AdvViewerWindowProc(
240 HWND hwnd,
241 UINT uMsg,
242 WPARAM wParam,
243 LPARAM lParam );
244#endif
245
246
247//==============================================================================
248//function : WClass
249//purpose :
250//==============================================================================
251
ad03c234 252const Handle(Standard_Transient)& ViewerTest::WClass()
7fd59977 253{
ad03c234 254 static Handle(Standard_Transient) theWClass;
58655684 255#if defined(_WIN32)
4fe56619 256 if (theWClass.IsNull())
257 {
7c65581d 258 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
ad03c234 259 CS_VREDRAW | CS_HREDRAW, 0, 0,
260 ::LoadCursorW (NULL, IDC_ARROW));
7fd59977 261 }
262#endif
263 return theWClass;
264}
265
18d715bd 266//==============================================================================
267//function : CreateName
268//purpose : Create numerical name for new object in theMap
269//==============================================================================
270template <typename ObjectType>
271TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
272 const TCollection_AsciiString& theDefaultString)
273{
274 if (theObjectMap.IsEmpty())
275 return theDefaultString + TCollection_AsciiString(1);
276
277 Standard_Integer aNextKey = 1;
278 Standard_Boolean isFound = Standard_False;
279 while (!isFound)
280 {
281 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
282 // Look for objects with default names
283 if (theObjectMap.IsBound1(aStringKey))
284 {
285 aNextKey++;
286 }
287 else
288 isFound = Standard_True;
289 }
290
291 return theDefaultString + TCollection_AsciiString(aNextKey);
292}
293
294//==============================================================================
295//structure : ViewerTest_Names
296//purpose : Allow to operate with full view name: driverName/viewerName/viewName
297//==============================================================================
298struct ViewerTest_Names
299{
300private:
301 TCollection_AsciiString myDriverName;
302 TCollection_AsciiString myViewerName;
303 TCollection_AsciiString myViewName;
304
305public:
306
307 const TCollection_AsciiString& GetDriverName () const
308 {
309 return myDriverName;
310 }
311 void SetDriverName (const TCollection_AsciiString& theDriverName)
312 {
313 myDriverName = theDriverName;
314 }
315 const TCollection_AsciiString& GetViewerName () const
316 {
317 return myViewerName;
318 }
319 void SetViewerName (const TCollection_AsciiString& theViewerName)
320 {
321 myViewerName = theViewerName;
322 }
323 const TCollection_AsciiString& GetViewName () const
324 {
325 return myViewName;
326 }
327 void SetViewName (const TCollection_AsciiString& theViewName)
328 {
329 myViewName = theViewName;
330 }
331
332 //===========================================================================
333 //function : Constructor for ViewerTest_Names
334 //purpose : Get view, viewer, driver names from custom string
335 //===========================================================================
336
337 ViewerTest_Names (const TCollection_AsciiString& theInputString)
338 {
339 TCollection_AsciiString aName(theInputString);
340 if (theInputString.IsEmpty())
341 {
342 // Get current configuration
343 if (ViewerTest_myDrivers.IsEmpty())
344 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
345 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
346 else
347 myDriverName = ViewerTest_myDrivers.Find2
348 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
349
350 if(ViewerTest_myContexts.IsEmpty())
351 {
352 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
353 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
354 }
355 else
c48e2889 356 {
18d715bd 357 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
c48e2889 358 }
18d715bd 359
c48e2889 360 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
18d715bd 361 }
362 else
363 {
364 // There is at least view name
365 Standard_Integer aParserNumber = 0;
366 for (Standard_Integer i = 0; i < 3; ++i)
367 {
368 Standard_Integer aParserPos = aName.SearchFromEnd("/");
369 if(aParserPos != -1)
370 {
371 aParserNumber++;
372 aName.Split(aParserPos-1);
373 }
374 else
375 break;
376 }
377 if (aParserNumber == 0)
378 {
379 // Only view name
380 if (!ViewerTest::GetAISContext().IsNull())
381 {
382 myDriverName = ViewerTest_myDrivers.Find2
383 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
384 myViewerName = ViewerTest_myContexts.Find2
385 (ViewerTest::GetAISContext());
386 }
387 else
388 {
389 // There is no opened contexts here, need to create names for viewer and driver
390 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
391 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
392
393 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
394 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
395 }
396 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
397 }
398 else if (aParserNumber == 1)
399 {
400 // Here is viewerName/viewName
401 if (!ViewerTest::GetAISContext().IsNull())
402 myDriverName = ViewerTest_myDrivers.Find2
403 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
404 else
405 {
406 // There is no opened contexts here, need to create name for driver
407 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
408 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
409 }
410 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
411
412 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
413 }
414 else
415 {
416 //Here is driverName/viewerName/viewName
417 myDriverName = TCollection_AsciiString(aName);
418
419 TCollection_AsciiString aViewerName(theInputString);
420 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
421 myViewerName = TCollection_AsciiString(aViewerName);
422
423 myViewName = TCollection_AsciiString(theInputString);
424 }
425 }
426 }
427};
428
429//==============================================================================
430//function : FindContextByView
431//purpose : Find AIS_InteractiveContext by View
432//==============================================================================
433
434Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
435{
436 Handle(AIS_InteractiveContext) anAISContext;
437
438 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
439 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
440 {
441 if (anIter.Value()->CurrentViewer() == theView->Viewer())
442 return anIter.Key2();
443 }
444 return anAISContext;
445}
446
447
448//==============================================================================
449//function : SetWindowTitle
450//purpose : Set window title
451//==============================================================================
452
453void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
454 Standard_CString theTitle)
455{
58655684 456#if defined(_WIN32)
ad03c234 457 const TCollection_ExtendedString theTitleW (theTitle);
458 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
18d715bd 459#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
460 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
461#else
462 if(GetDisplayConnection()->GetDisplay())
463 {
464 Window aWindow =
465 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
466 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
467 }
468#endif
469}
470
471//==============================================================================
472//function : IsWindowOverlapped
473//purpose : Check if theWindow overlapp another view
474//==============================================================================
475
476Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
477 const Standard_Integer thePxTop,
478 const Standard_Integer thePxRight,
479 const Standard_Integer thePxBottom,
480 TCollection_AsciiString& theViewId)
481{
482 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
483 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
484 {
485 Standard_Integer aTop = 0,
486 aLeft = 0,
487 aRight = 0,
488 aBottom = 0;
489 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
490 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
491 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
492 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
493 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
494 {
495 theViewId = anIter.Key1();
496 return Standard_True;
497 }
498 }
499 return Standard_False;
500}
501
502// Workaround: to create and delete non-orthographic views outside ViewerTest
503void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
504{
505 ViewerTest_myViews.UnBind1 (theName);
506}
507
508void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
509 const Handle(V3d_View)& theView)
510{
511 ViewerTest_myViews.Bind (theName, theView);
512}
513
514TCollection_AsciiString ViewerTest::GetCurrentViewName ()
515{
516 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
517}
7fd59977 518//==============================================================================
519//function : ViewerInit
520//purpose : Create the window viewer and initialize all the global variable
521//==============================================================================
522
18d715bd 523TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
524 const Standard_Integer thePxTop,
525 const Standard_Integer thePxWidth,
526 const Standard_Integer thePxHeight,
527 Standard_CString theViewName,
528 Standard_CString theDisplayName)
7fd59977 529{
8c3c9904 530 // Default position and dimension of the viewer window.
4fe56619 531 // Note that left top corner is set to be sufficiently small to have
8c3c9904 532 // window fit in the small screens (actual for remote desktops, see #23003).
4fe56619 533 // The position corresponds to the window's client area, thus some
8c3c9904 534 // gap is added for window frame to be visible.
535 Standard_Integer aPxLeft = 20;
536 Standard_Integer aPxTop = 40;
7fd59977 537 Standard_Integer aPxWidth = 409;
538 Standard_Integer aPxHeight = 409;
18d715bd 539 Standard_Boolean toCreateViewer = Standard_False;
540
58655684 541 Handle(OpenGl_GraphicDriver) aGraphicDriver;
18d715bd 542 ViewerTest_Names aViewNames(theViewName);
543 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
544 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
545
546 if (thePxLeft != 0)
547 aPxLeft = thePxLeft;
548 if (thePxTop != 0)
549 aPxTop = thePxTop;
550 if (thePxWidth != 0)
551 aPxWidth = thePxWidth;
552 if (thePxHeight != 0)
7fd59977 553 aPxHeight = thePxHeight;
4269bd1b 554
18d715bd 555 // Get graphic driver (create it or get from another view)
556 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
557 {
558 // Get connection string
58655684 559 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 560 TCollection_AsciiString aDisplayName(theDisplayName);
498ce76b 561 if (!aDisplayName.IsEmpty())
18d715bd 562 SetDisplayConnection (new Aspect_DisplayConnection ());
563 else
564 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
18d715bd 565 #else
498ce76b 566 (void)theDisplayName; // avoid warning on unused argument
18d715bd 567 SetDisplayConnection (new Aspect_DisplayConnection ());
568 #endif
14cb22a1 569
570 if (Draw_VirtualWindows)
571 {
572 // don't waste the time waiting for VSync when window is not displayed on the screen
573 ViewerTest_myDefaultCaps.swapInterval = 0;
574 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
575 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
576 }
65993a95 577 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
58655684 578 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
14cb22a1 579
18d715bd 580 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
581 toCreateViewer = Standard_True;
582 }
583 else
584 {
58655684 585 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
7fd59977 586 }
587
18d715bd 588 //Dispose the window if input parameters are default
589 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
7fd59977 590 {
18d715bd 591 Standard_Integer aTop = 0,
592 aLeft = 0,
593 aRight = 0,
594 aBottom = 0,
595 aScreenWidth = 0,
596 aScreenHeight = 0;
597
598 // Get screen resolution
599#if defined(_WIN32) || defined(__WIN32__)
600 RECT aWindowSize;
601 GetClientRect(GetDesktopWindow(), &aWindowSize);
602 aScreenHeight = aWindowSize.bottom;
603 aScreenWidth = aWindowSize.right;
604#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
605 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
606#else
607 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
608 aScreenWidth = WidthOfScreen(aScreen);
609 aScreenHeight = HeightOfScreen(aScreen);
610#endif
611
612 TCollection_AsciiString anOverlappedViewId("");
773f53f1 613
614 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
dc3fe572 615 {
18d715bd 616 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
617
618 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
619 && aRight + 2*aPxWidth + 40 > aScreenWidth)
620 {
621 if (aBottom + aPxHeight + 40 > aScreenHeight)
622 {
623 aPxLeft = 20;
624 aPxTop = 40;
625 break;
626 }
627 aPxLeft = 20;
628 aPxTop = aBottom + 40;
629 }
630 else
631 aPxLeft = aRight + 20;
dc3fe572 632 }
18d715bd 633 }
634
635 // Get viewer name
636 TCollection_AsciiString aTitle("3D View - ");
637 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
638
639 // Change name of current active window
640 if (!ViewerTest::CurrentView().IsNull())
641 {
51740958 642 TCollection_AsciiString anActiveWindowTitle("3D View - ");
643 anActiveWindowTitle = anActiveWindowTitle
18d715bd 644 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
51740958 645 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
18d715bd 646 }
647
648 // Create viewer
eb4320f2 649 Handle(V3d_Viewer) a3DViewer;
18d715bd 650 // If it's the single view, we first look for empty context
651 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
652 {
653 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
654 anIter(ViewerTest_myContexts);
655 if (anIter.More())
656 ViewerTest::SetAISContext (anIter.Value());
657 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 658 }
659 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
660 {
661 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
662 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 663 }
eb4320f2 664 else if (a3DViewer.IsNull())
18d715bd 665 {
666 toCreateViewer = Standard_True;
6a24c6de 667 a3DViewer = new V3d_Viewer(aGraphicDriver);
f42753ed 668 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
669 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
670 ViewerTest_DefaultBackground.GradientColor2,
671 ViewerTest_DefaultBackground.FillMethod);
18d715bd 672 }
673
674 // AIS context setup
675 if (ViewerTest::GetAISContext().IsNull() ||
676 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
677 {
e79a94b9 678 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
18d715bd 679 ViewerTest::SetAISContext (aContext);
680 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
681 }
682 else
e79a94b9 683 {
18d715bd 684 ViewerTest::ResetEventManager();
e79a94b9 685 }
18d715bd 686
687 // Create window
e79a94b9 688#if defined(_WIN32)
689 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
690 Handle(WNT_WClass)::DownCast (WClass()),
62e1beed 691 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
e79a94b9 692 aPxLeft, aPxTop,
693 aPxWidth, aPxHeight,
694 Quantity_NOC_BLACK);
4fe56619 695#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
e79a94b9 696 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
697 aPxLeft, aPxTop,
698 aPxWidth, aPxHeight);
699 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
7fd59977 700#else
e79a94b9 701 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
702 aTitle.ToCString(),
703 aPxLeft, aPxTop,
704 aPxWidth, aPxHeight);
7fd59977 705#endif
18d715bd 706 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
7fd59977 707
d09dda09 708 // View setup
709 Handle(V3d_View) aView = a3DViewer->CreateView();
710 aView->SetWindow (VT_GetWindow());
c3282ec1 711 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
4269bd1b 712
18d715bd 713 ViewerTest::CurrentView(aView);
714 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
7fd59977 715
18d715bd 716 // Setup for X11 or NT
717 OSWindowSetup();
7fd59977 718
18d715bd 719 // Set parameters for V3d_View and V3d_Viewer
720 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
721 aV3dView->SetComputedMode(Standard_False);
7fd59977 722
18d715bd 723 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
724 if (toCreateViewer)
725 {
7fd59977 726 a3DViewer->SetDefaultLights();
727 a3DViewer->SetLightOn();
18d715bd 728 }
7fd59977 729
e79a94b9 730 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4fe56619 731 #if TCL_MAJOR_VERSION < 8
18d715bd 732 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 733 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 734 #else
18d715bd 735 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 736 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 737 #endif
738 #endif
7fd59977 739
7fd59977 740 VT_GetWindow()->Map();
4269bd1b 741
18d715bd 742 // Set the handle of created view in the event manager
743 ViewerTest::ResetEventManager();
744
4fe56619 745 ViewerTest::CurrentView()->Redraw();
18d715bd 746
747 aView.Nullify();
748 a3DViewer.Nullify();
18d715bd 749
750 return aViewNames.GetViewName();
751}
752
4269bd1b 753//==============================================================================
754//function : RedrawAllViews
755//purpose : Redraw all created views
756//==============================================================================
757void ViewerTest::RedrawAllViews()
758{
759 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
760 for (; aViewIt.More(); aViewIt.Next())
761 {
762 const Handle(V3d_View)& aView = aViewIt.Key2();
763 aView->Redraw();
764 }
765}
766
7fd59977 767//==============================================================================
768//function : Vinit
769//purpose : Create the window viewer and initialize all the global variable
e79a94b9 770// Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
7fd59977 771//==============================================================================
772
18d715bd 773static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 774{
e79a94b9 775 if (theArgsNb > 9)
18d715bd 776 {
e79a94b9 777 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
778 << "Type help for more information.\n";
18d715bd 779 return 1;
780 }
18d715bd 781
e79a94b9 782 TCollection_AsciiString aViewName, aDisplayName;
783 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
784 TCollection_AsciiString aName, aValue;
785 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
18d715bd 786 {
e79a94b9 787 const TCollection_AsciiString anArg = theArgVec[anArgIt];
788 TCollection_AsciiString anArgCase = anArg;
789 anArgCase.UpperCase();
1d7ca641 790 if (ViewerTest::SplitParameter (anArg, aName, aValue))
18d715bd 791 {
e79a94b9 792 aName.UpperCase();
793 if (aName.IsEqual ("NAME"))
18d715bd 794 {
795 aViewName = aValue;
796 }
e79a94b9 797 else if (aName.IsEqual ("L")
798 || aName.IsEqual ("LEFT"))
799 {
18d715bd 800 aPxLeft = aValue.IntegerValue();
e79a94b9 801 }
802 else if (aName.IsEqual ("T")
803 || aName.IsEqual ("TOP"))
804 {
18d715bd 805 aPxTop = aValue.IntegerValue();
e79a94b9 806 }
807 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
808 else if (aName.IsEqual ("DISP")
809 || aName.IsEqual ("DISPLAY"))
810 {
18d715bd 811 aDisplayName = aValue;
e79a94b9 812 }
813 #endif
814 else if (aName.IsEqual ("W")
815 || aName.IsEqual ("WIDTH"))
816 {
18d715bd 817 aPxWidth = aValue.IntegerValue();
e79a94b9 818 }
819 else if (aName.IsEqual ("H")
820 || aName.IsEqual ("HEIGHT"))
821 {
18d715bd 822 aPxHeight = aValue.IntegerValue();
e79a94b9 823 }
18d715bd 824 else
825 {
e79a94b9 826 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
18d715bd 827 }
828 }
e79a94b9 829 else if (aViewName.IsEmpty())
830 {
831 aViewName = anArg;
832 }
833 else
834 {
835 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
836 }
18d715bd 837 }
838
839 ViewerTest_Names aViewNames (aViewName);
e79a94b9 840 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
18d715bd 841 {
e79a94b9 842 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
843 theDi.Eval (aCommand.ToCString());
18d715bd 844 return 0;
845 }
846
847 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
848 aViewName.ToCString(),
849 aDisplayName.ToCString());
e79a94b9 850 theDi << aViewId;
7fd59977 851 return 0;
852}
853
1eeef710 854//! Parse HLR algo type.
855static Standard_Boolean parseHlrAlgoType (const char* theName,
856 Prs3d_TypeOfHLR& theType)
857{
858 TCollection_AsciiString aName (theName);
859 aName.LowerCase();
860 if (aName == "polyalgo")
861 {
862 theType = Prs3d_TOH_PolyAlgo;
863 }
864 else if (aName == "algo")
865 {
866 theType = Prs3d_TOH_Algo;
867 }
868 else
869 {
870 return Standard_False;
871 }
872 return Standard_True;
873}
874
0a768f56 875//==============================================================================
876//function : VHLR
877//purpose : hidden lines removal algorithm
878//==============================================================================
879
880static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
881{
1eeef710 882 const Handle(V3d_View) aView = ViewerTest::CurrentView();
883 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
884 if (aView.IsNull())
0a768f56 885 {
1eeef710 886 std::cerr << "Error: No opened viewer!\n";
0a768f56 887 return 1;
888 }
889
1eeef710 890 Standard_Boolean hasHlrOnArg = Standard_False;
891 Standard_Boolean hasShowHiddenArg = Standard_False;
892 Standard_Boolean isHLROn = Standard_False;
893 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
894 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
895 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
896 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
0a768f56 897 {
1eeef710 898 TCollection_AsciiString anArg (argv[anArgIter]);
899 anArg.LowerCase();
900 if (anUpdateTool.parseRedrawMode (anArg))
901 {
902 continue;
903 }
904 else if (anArg == "-showhidden"
905 && anArgIter + 1 < argc
906 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
907 {
908 ++anArgIter;
909 hasShowHiddenArg = Standard_True;
910 continue;
911 }
912 else if ((anArg == "-type"
913 || anArg == "-algo"
914 || anArg == "-algotype")
915 && anArgIter + 1 < argc
916 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
917 {
918 ++anArgIter;
919 continue;
920 }
921 else if (!hasHlrOnArg
922 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
923 {
924 hasHlrOnArg = Standard_True;
925 continue;
926 }
927 // old syntax
928 else if (!hasShowHiddenArg
929 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
930 {
931 hasShowHiddenArg = Standard_True;
932 continue;
933 }
934 else
935 {
936 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
937 return 1;
938 }
0a768f56 939 }
1eeef710 940 if (!hasHlrOnArg)
0a768f56 941 {
1eeef710 942 di << "HLR: " << aView->ComputedMode() << "\n";
943 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
944 di << "HlrAlgo: ";
945 switch (aCtx->DefaultDrawer()->TypeOfHLR())
946 {
947 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
948 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
949 case Prs3d_TOH_Algo: di << "Algo\n"; break;
950 }
951 anUpdateTool.Invalidate();
952 return 0;
0a768f56 953 }
954
1eeef710 955 Standard_Boolean toRecompute = Standard_False;
956 if (aTypeOfHLR != Prs3d_TOH_NotSet
957 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
e9224045 958 {
1eeef710 959 toRecompute = Standard_True;
960 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
961 }
962 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
963 {
964 toRecompute = Standard_True;
965 if (toShowHidden)
e9224045 966 {
1eeef710 967 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
e9224045 968 }
969 else
970 {
1eeef710 971 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
e9224045 972 }
1eeef710 973 }
e9224045 974
1eeef710 975 // redisplay shapes
976 if (aView->ComputedMode() && isHLROn && toRecompute)
977 {
978 AIS_ListOfInteractive aListOfShapes;
979 aCtx->DisplayedObjects (aListOfShapes);
980 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
e9224045 981 {
1eeef710 982 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
e9224045 983 {
1eeef710 984 aCtx->Redisplay (aShape, Standard_False);
e9224045 985 }
986 }
987 }
0a768f56 988
1eeef710 989 aView->SetComputedMode (isHLROn);
0a768f56 990 return 0;
991}
992
993//==============================================================================
994//function : VHLRType
995//purpose : change type of using HLR algorithm
996//==============================================================================
997
1eeef710 998static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
0a768f56 999{
1eeef710 1000 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1001 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1002 if (aView.IsNull())
0a768f56 1003 {
1eeef710 1004 std::cerr << "Error: No opened viewer!\n";
0a768f56 1005 return 1;
1006 }
1007
1eeef710 1008 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1009 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1010 AIS_ListOfInteractive aListOfShapes;
1011 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
0a768f56 1012 {
1eeef710 1013 TCollection_AsciiString anArg (argv[anArgIter]);
1014 anArg.LowerCase();
1015 if (anUpdateTool.parseRedrawMode (anArg))
0a768f56 1016 {
1eeef710 1017 continue;
0a768f56 1018 }
1eeef710 1019 else if ((anArg == "-type"
1020 || anArg == "-algo"
1021 || anArg == "-algotype")
1022 && anArgIter + 1 < argc
1023 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1024 {
1025 ++anArgIter;
1026 continue;
1027 }
1028 // old syntax
1029 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1030 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1031 {
1032 continue;
1033 }
1034 else
0a768f56 1035 {
1036 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1eeef710 1037 TCollection_AsciiString aName (argv[anArgIter]);
0a768f56 1038 if (!aMap.IsBound2 (aName))
1039 {
1eeef710 1040 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1041 return 1;
0a768f56 1042 }
1eeef710 1043
1044 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1045 if (aShape.IsNull())
1046 {
1047 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1048 return 1;
1049 }
1050 aListOfShapes.Append (aShape);
1051 continue;
0a768f56 1052 }
1eeef710 1053 }
1054 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1055 {
1056 std::cout << "Syntax error: wrong number of arguments!\n";
1057 return 1;
1058 }
1059
1060 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1061 if (isGlobal)
1062 {
1063 aCtx->DisplayedObjects (aListOfShapes);
1064 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
0a768f56 1065 }
1066
1eeef710 1067 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1068 {
1069 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1070 if (aShape.IsNull())
1071 {
1072 continue;
1073 }
1074
1075 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1076 && aView->ComputedMode();
1077 if (!isGlobal
1078 || aShape->TypeOfHLR() != aTypeOfHLR)
1079 {
1080 aShape->SetTypeOfHLR (aTypeOfHLR);
1081 }
1082 if (toUpdateShape)
1083 {
1084 aCtx->Redisplay (aShape, Standard_False);
1085 }
1086 }
0a768f56 1087 return 0;
1088}
1089
18d715bd 1090//==============================================================================
1091//function : FindViewIdByWindowHandle
1092//purpose : Find theView Id in the map of views by window handle
1093//==============================================================================
1094#if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1095TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1096{
1097 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1098 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1099 {
1100 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1101 if (aWindowHandle == theWindowHandle)
1102 return anIter.Key1();
1103 }
1104 return TCollection_AsciiString("");
1105}
1106#endif
1107
1108//==============================================================================
1109//function : ActivateView
1110//purpose : Make the view active
1111//==============================================================================
1112
1113void ActivateView (const TCollection_AsciiString& theViewName)
1114{
1115 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1116 if (!aView.IsNull())
1117 {
1118 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1119 if (!anAISContext.IsNull())
1120 {
1121 if (!ViewerTest::CurrentView().IsNull())
1122 {
1123 TCollection_AsciiString aTitle("3D View - ");
1124 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1125 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1126 }
1127
1128 ViewerTest::CurrentView (aView);
18d715bd 1129 ViewerTest::SetAISContext (anAISContext);
1eeef710 1130 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
18d715bd 1131 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1eeef710 1132#if defined(_WIN32)
18d715bd 1133 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1134#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1135 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1136#else
1137 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1138#endif
1139 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1140 ViewerTest::CurrentView()->Redraw();
1141 }
1142 }
1143}
1144
0e93d9e5 1145//==============================================================================
1146//function : RemoveView
1147//purpose :
1148//==============================================================================
1149void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1150 const Standard_Boolean theToRemoveContext)
1151{
1152 if (!ViewerTest_myViews.IsBound2 (theView))
1153 {
1154 return;
1155 }
1156
1157 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1158 RemoveView (aViewName, theToRemoveContext);
1159}
1160
18d715bd 1161//==============================================================================
1162//function : RemoveView
1163//purpose : Close and remove view from display, clear maps if neccessary
1164//==============================================================================
1165void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1166{
1167 if (!ViewerTest_myViews.IsBound1(theViewName))
1168 {
1169 cout << "Wrong view name\n";
1170 return;
1171 }
1172
1173 // Activate another view if it's active now
1174 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1175 {
1176 if (ViewerTest_myViews.Extent() > 1)
1177 {
1178 TCollection_AsciiString aNewViewName;
c48e2889 1179 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1180 anIter.More(); anIter.Next())
1181 {
18d715bd 1182 if (anIter.Key1() != theViewName)
1183 {
1184 aNewViewName = anIter.Key1();
1185 break;
1186 }
c48e2889 1187 }
1188 ActivateView (aNewViewName);
18d715bd 1189 }
1190 else
1191 {
1192 Handle(V3d_View) anEmptyView;
1193#if defined(_WIN32) || defined(__WIN32__)
1194 Handle(WNT_Window) anEmptyWindow;
1195#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1196 Handle(Cocoa_Window) anEmptyWindow;
1197#else
1198 Handle(Xw_Window) anEmptyWindow;
1199#endif
1200 VT_GetWindow() = anEmptyWindow;
1201 ViewerTest::CurrentView (anEmptyView);
1202 if (isContextRemoved)
1203 {
1204 Handle(AIS_InteractiveContext) anEmptyContext;
1205 ViewerTest::SetAISContext(anEmptyContext);
1206 }
1207 }
1208 }
1209
1210 // Delete view
1211 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1212 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1213
1214 // Remove view resources
18d715bd 1215 ViewerTest_myViews.UnBind1(theViewName);
851dacdb 1216 aView->Window()->Unmap();
18d715bd 1217 aView->Remove();
1218
1219#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1220 XFlush (GetDisplayConnection()->GetDisplay());
1221#endif
1222
1223 // Keep context opened only if the closed view is last to avoid
1224 // unused empty contexts
1225 if (!aCurrentContext.IsNull())
1226 {
1227 // Check if there are more difined views in the viewer
1228 aCurrentContext->CurrentViewer()->InitDefinedViews();
1229 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1230 {
1231 // Remove driver if there is no viewers that use it
1232 Standard_Boolean isRemoveDriver = Standard_True;
1233 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1234 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1235 {
1236 if (aCurrentContext != anIter.Key2() &&
1237 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1238 {
1239 isRemoveDriver = Standard_False;
1240 break;
1241 }
1242 }
2ec85268 1243
1244 aCurrentContext->RemoveAll (Standard_False);
18d715bd 1245 if(isRemoveDriver)
1246 {
1247 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1248 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1249 #if TCL_MAJOR_VERSION < 8
1250 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1251 #else
1252 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1253 #endif
1254 #endif
1255 }
1256
1257 ViewerTest_myContexts.UnBind2(aCurrentContext);
1258 }
1259 }
1260 cout << "3D View - " << theViewName << " was deleted.\n";
1261
1262}
1263
1264//==============================================================================
1265//function : VClose
1266//purpose : Remove the view defined by its name
1267//==============================================================================
1268
d0cc1cb7 1269static int VClose (Draw_Interpretor& /*theDi*/,
1270 Standard_Integer theArgsNb,
1271 const char** theArgVec)
18d715bd 1272{
18d715bd 1273 NCollection_List<TCollection_AsciiString> aViewList;
d0cc1cb7 1274 if (theArgsNb > 1)
18d715bd 1275 {
d0cc1cb7 1276 TCollection_AsciiString anArg (theArgVec[1]);
1277 anArg.UpperCase();
1278 if (anArg.IsEqual ("ALL")
1279 || anArg.IsEqual ("*"))
1280 {
1281 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1282 anIter.More(); anIter.Next())
1283 {
1284 aViewList.Append (anIter.Key1());
1285 }
1286 if (aViewList.IsEmpty())
1287 {
1288 std::cout << "No view to close\n";
1289 return 0;
1290 }
1291 }
1292 else
18d715bd 1293 {
d0cc1cb7 1294 ViewerTest_Names aViewName (theArgVec[1]);
1295 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1296 {
1297 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1298 return 1;
1299 }
1300 aViewList.Append (aViewName.GetViewName());
18d715bd 1301 }
1302 }
1303 else
1304 {
d0cc1cb7 1305 // close active view
1306 if (ViewerTest::CurrentView().IsNull())
1307 {
1308 std::cerr << "No active view!\n";
1309 return 1;
1310 }
1311 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
18d715bd 1312 }
1313
d0cc1cb7 1314 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
18d715bd 1315 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1316 anIter.More(); anIter.Next())
1317 {
d0cc1cb7 1318 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
18d715bd 1319 }
1320
1321 return 0;
1322}
1323
1324//==============================================================================
1325//function : VActivate
1326//purpose : Activate the view defined by its ID
1327//==============================================================================
1328
1329static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1330{
1331 if (theArgsNb > 2)
1332 {
1333 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1334 << "Usage: " << theArgVec[0] << " ViewID\n";
1335 return 1;
1336 }
1337 if(theArgsNb == 1)
1338 {
1339 theDi.Eval("vviewlist");
1340 return 0;
1341 }
1342
1343 TCollection_AsciiString aNameString(theArgVec[1]);
29cb310a 1344 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
18d715bd 1345 {
1346 TCollection_AsciiString aTitle("3D View - ");
1347 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1348 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1349 Handle(V3d_View) anEmptyView;
1350#if defined(_WIN32) || defined(__WIN32__)
1351 Handle(WNT_Window) anEmptyWindow;
1352#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1353 Handle(Cocoa_Window) anEmptyWindow;
1354#else
1355 Handle(Xw_Window) anEmptyWindow;
1356#endif
1357 VT_GetWindow() = anEmptyWindow;
1358 ViewerTest::CurrentView (anEmptyView);
1359 ViewerTest::ResetEventManager();
1360 theDi << theArgVec[0] << ": all views are inactive\n";
1361 return 0;
1362 }
1363
1364 ViewerTest_Names aViewNames(aNameString);
1365
1366 // Check if this view exists in the viewer with the driver
1367 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1368 {
1369 theDi << "Wrong view name\n";
1370 return 1;
1371 }
1372
1373 // Check if it is active already
1374 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1375 {
1376 theDi << theArgVec[0] << ": the view is active already\n";
1377 return 0;
1378 }
1379
1380 ActivateView (aViewNames.GetViewName());
1381 return 0;
1382}
1383
1384//==============================================================================
1385//function : VViewList
1386//purpose : Print current list of views per viewer and graphic driver ID
1387// shared between viewers
1388//==============================================================================
1389
1390static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1391{
1392 if (theArgsNb > 2)
1393 {
1394 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
29cb310a 1395 << "Usage: " << theArgVec[0] << " name";
18d715bd 1396 return 1;
1397 }
1398 if (ViewerTest_myContexts.Size() < 1)
1399 return 0;
1400
18d715bd 1401 Standard_Boolean isTreeView =
29cb310a 1402 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
18d715bd 1403
1404 if (isTreeView)
c48e2889 1405 {
18d715bd 1406 theDi << theArgVec[0] <<":\n";
c48e2889 1407 }
18d715bd 1408
c48e2889 1409 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1410 aDriverIter.More(); aDriverIter.Next())
1411 {
1412 if (isTreeView)
1413 theDi << aDriverIter.Key1() << ":\n";
18d715bd 1414
c48e2889 1415 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1416 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1417 {
1418 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
18d715bd 1419 {
c48e2889 1420 if (isTreeView)
18d715bd 1421 {
c48e2889 1422 TCollection_AsciiString aContextName(aContextIter.Key1());
1423 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1424 }
18d715bd 1425
c48e2889 1426 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1427 aViewIter.More(); aViewIter.Next())
1428 {
1429 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
18d715bd 1430 {
c48e2889 1431 TCollection_AsciiString aViewName(aViewIter.Key1());
1432 if (isTreeView)
18d715bd 1433 {
c48e2889 1434 if (aViewIter.Value() == ViewerTest::CurrentView())
1435 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
18d715bd 1436 else
c48e2889 1437 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1438 }
1439 else
1440 {
1441 theDi << aViewName << " ";
18d715bd 1442 }
1443 }
1444 }
1445 }
1446 }
c48e2889 1447 }
18d715bd 1448 return 0;
1449}
1450
7fd59977 1451//==============================================================================
4fe56619 1452//function : VT_ProcessKeyPress
7fd59977 1453//purpose : Handle KeyPress event from a CString
1454//==============================================================================
4fe56619 1455void VT_ProcessKeyPress (const char* buf_ret)
7fd59977 1456{
1457 //cout << "KeyPress" << endl;
1458 const Handle(V3d_View) aView = ViewerTest::CurrentView();
7fd59977 1459 // Letter in alphabetic order
1460
b514beda 1461 if (!strcasecmp (buf_ret, "A"))
1462 {
7fd59977 1463 // AXO
1464 aView->SetProj(V3d_XposYnegZpos);
1465 }
b514beda 1466 else if (!strcasecmp (buf_ret, "D"))
1467 {
7fd59977 1468 // Reset
1469 aView->Reset();
1470 }
b514beda 1471 else if (!strcasecmp (buf_ret, "F"))
1472 {
b586500b 1473 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1474 {
1475 ViewerTest::GetAISContext()->FitSelected (aView);
1476 }
1477 else
1478 {
1479 // FitAll
1480 aView->FitAll();
1481 }
7fd59977 1482 }
b514beda 1483 else if (!strcasecmp (buf_ret, "H"))
1484 {
7fd59977 1485 // HLR
1eeef710 1486 std::cout << "HLR" << std::endl;
de75ed09 1487 aView->SetComputedMode (!aView->ComputedMode());
1eeef710 1488 aView->Redraw();
7fd59977 1489 }
b514beda 1490 else if (!strcasecmp (buf_ret, "P"))
1491 {
0a768f56 1492 // Type of HLR
1493 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1494 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1495 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1496 else
1497 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
c3282ec1 1498 if (aContext->NbSelected()==0)
0a768f56 1499 {
1500 AIS_ListOfInteractive aListOfShapes;
1501 aContext->DisplayedObjects(aListOfShapes);
1502 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1503 anIter.More(); anIter.Next())
1504 {
1505 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1506 if (aShape.IsNull())
1507 continue;
1508 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1509 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1510 else
1511 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1512 aContext->Redisplay (aShape, Standard_False);
0a768f56 1513 }
1514 }
1515 else
1516 {
c3282ec1 1517 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
0a768f56 1518 {
c3282ec1 1519 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
0a768f56 1520 if (aShape.IsNull())
1521 continue;
1522 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1523 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1524 else
1525 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1526 aContext->Redisplay (aShape, Standard_False);
0a768f56 1527 }
1528 }
1529
1530 aContext->UpdateCurrentViewer();
4269bd1b 1531
0a768f56 1532 }
b514beda 1533 else if (!strcasecmp (buf_ret, "S"))
1534 {
1535 std::cout << "setup Shaded display mode" << std::endl;
4fe56619 1536
7fd59977 1537 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1538 if(Ctx->NbSelected()==0)
0577ae8c 1539 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
7fd59977 1540 else{
c3282ec1 1541 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1542 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
7fd59977 1543 Ctx->UpdateCurrentViewer();
1544 }
1545 }
b514beda 1546 else if (!strcasecmp (buf_ret, "U"))
1547 {
41811896 1548 // Unset display mode
b514beda 1549 std::cout << "reset display mode to defaults" << std::endl;
4fe56619 1550
7fd59977 1551 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1552 if(Ctx->NbSelected()==0)
0577ae8c 1553 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 1554 else{
c3282ec1 1555 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1556 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
7fd59977 1557 Ctx->UpdateCurrentViewer();
1558 }
1559
1560 }
b514beda 1561 else if (!strcasecmp (buf_ret, "T"))
1562 {
7fd59977 1563 // Top
1564 aView->SetProj(V3d_Zpos);
1565 }
b514beda 1566 else if (!strcasecmp (buf_ret, "B"))
1567 {
41811896 1568 // Bottom
7fd59977 1569 aView->SetProj(V3d_Zneg);
1570 }
b514beda 1571 else if (!strcasecmp (buf_ret, "L"))
1572 {
41811896 1573 // Left
7fd59977 1574 aView->SetProj(V3d_Xneg);
1575 }
b514beda 1576 else if (!strcasecmp (buf_ret, "R"))
1577 {
41811896 1578 // Right
7fd59977 1579 aView->SetProj(V3d_Xpos);
1580 }
b514beda 1581 else if (!strcasecmp (buf_ret, "W"))
1582 {
1583 std::cout << "setup WireFrame display mode" << std::endl;
7fd59977 1584 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1585 if(Ctx->NbSelected()==0)
0577ae8c 1586 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 1587 else{
c3282ec1 1588 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1589 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
7fd59977 1590 Ctx->UpdateCurrentViewer();
1591 }
1592 }
b514beda 1593 else if (!strcasecmp (buf_ret, ","))
1594 {
7fd59977 1595 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
7fd59977 1596 }
b514beda 1597 else if (!strcasecmp (buf_ret, "."))
1598 {
7fd59977 1599 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1600 }
f978241f 1601 else if (!strcasecmp (buf_ret, "/"))
1602 {
1603 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1604 if (aCamera->IsStereo())
1605 {
1606 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1607 aView->Redraw();
1608 }
1609 }
1610 else if (!strcasecmp (buf_ret, "*"))
1611 {
1612 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1613 if (aCamera->IsStereo())
1614 {
1615 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1616 aView->Redraw();
1617 }
1618 }
b514beda 1619 else if (*buf_ret == THE_KEY_DELETE)
1620 {
1621 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1622 if (!aCtx.IsNull()
b514beda 1623 && aCtx->NbSelected() > 0)
1624 {
1625 Draw_Interprete ("verase");
1626 }
1627 }
1628 else
1629 {
1630 // Number
91322f44 1631 Standard_Integer Num = Draw::Atoi(buf_ret);
7fd59977 1632 if(Num>=0 && Num<=7)
1633 ViewerTest::StandardModeActivation(Num);
1634 }
1635}
1636
1637//==============================================================================
4fe56619 1638//function : VT_ProcessExpose
7fd59977 1639//purpose : Redraw the View on an Expose Event
1640//==============================================================================
4fe56619 1641void VT_ProcessExpose()
1642{
1643 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1644 if (!aView3d.IsNull())
1645 {
1646 aView3d->Redraw();
1647 }
7fd59977 1648}
1649
1650//==============================================================================
4fe56619 1651//function : VT_ProcessConfigure
7fd59977 1652//purpose : Resize the View on an Configure Event
1653//==============================================================================
4fe56619 1654void VT_ProcessConfigure()
7fd59977 1655{
4fe56619 1656 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1657 if (aView3d.IsNull())
1658 {
1659 return;
1660 }
1661
1662 aView3d->MustBeResized();
1663 aView3d->Update();
1664 aView3d->Redraw();
7fd59977 1665}
1666
1667//==============================================================================
4fe56619 1668//function : VT_ProcessButton1Press
7fd59977 1669//purpose : Picking
1670//==============================================================================
e79a94b9 1671Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1672 const char** theArgVec,
1673 Standard_Boolean theToPick,
1674 Standard_Boolean theIsShift)
7fd59977 1675{
1beb58d7 1676 if (TheIsAnimating)
1677 {
1678 TheIsAnimating = Standard_False;
1679 return Standard_False;
1680 }
1681
e79a94b9 1682 if (theToPick)
1683 {
7fd59977 1684 Standard_Real X, Y, Z;
e79a94b9 1685 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
7fd59977 1686
e79a94b9 1687 Draw::Set (theArgVec[1], X);
1688 Draw::Set (theArgVec[2], Y);
1689 Draw::Set (theArgVec[3], Z);
1690 }
7fd59977 1691
e79a94b9 1692 if (theIsShift)
1693 {
1694 ViewerTest::CurrentEventManager()->ShiftSelect();
1695 }
7fd59977 1696 else
e79a94b9 1697 {
1698 ViewerTest::CurrentEventManager()->Select();
1699 }
7fd59977 1700
e79a94b9 1701 return Standard_False;
7fd59977 1702}
1703
1704//==============================================================================
4fe56619 1705//function : VT_ProcessButton1Release
1706//purpose : End selecting
7fd59977 1707//==============================================================================
4fe56619 1708void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1709{
1710 if (IsDragged)
1711 {
1712 IsDragged = Standard_False;
1713 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1714 if (theIsShift)
1715 {
2157d6ac 1716 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1717 X_Motion, Y_Motion);
4fe56619 1718 }
1719 else
1720 {
2157d6ac 1721 EM->Select (X_ButtonPress, Y_ButtonPress,
1722 X_Motion, Y_Motion);
4fe56619 1723 }
1724 }
1725}
7fd59977 1726
4fe56619 1727//==============================================================================
1728//function : VT_ProcessButton3Press
1729//purpose : Start Rotation
1730//==============================================================================
1731void VT_ProcessButton3Press()
1732{
7fd59977 1733 Start_Rot = 1;
1eeef710 1734 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1735 if (HasHlrOnBeforeRotation)
de75ed09 1736 {
1737 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1738 }
7fd59977 1739 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
7fd59977 1740}
4fe56619 1741
7fd59977 1742//==============================================================================
4fe56619 1743//function : VT_ProcessButton3Release
1744//purpose : End rotation
7fd59977 1745//==============================================================================
4fe56619 1746void VT_ProcessButton3Release()
1747{
1748 if (Start_Rot)
1749 {
7fd59977 1750 Start_Rot = 0;
1eeef710 1751 if (HasHlrOnBeforeRotation)
de75ed09 1752 {
1eeef710 1753 HasHlrOnBeforeRotation = Standard_False;
de75ed09 1754 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1eeef710 1755 ViewerTest::CurrentView()->Redraw();
de75ed09 1756 }
7fd59977 1757 }
7fd59977 1758}
1759
7fd59977 1760//==============================================================================
1761//function : ProcessControlButton1Motion
1762//purpose : Zoom
1763//==============================================================================
1764
900f7229 1765#if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 1766static void ProcessControlButton1Motion()
1767{
1768 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1769
1770 X_ButtonPress = X_Motion;
1771 Y_ButtonPress = Y_Motion;
1772}
900f7229 1773#endif
7fd59977 1774
1775//==============================================================================
4fe56619 1776//function : VT_ProcessControlButton2Motion
1777//purpose : Panning
7fd59977 1778//==============================================================================
4fe56619 1779void VT_ProcessControlButton2Motion()
7fd59977 1780{
197ac94e 1781 Standard_Integer aDx = X_Motion - X_ButtonPress;
1782 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
7fd59977 1783
197ac94e 1784 aDy = -aDy; // Xwindow Y axis is from top to Bottom
7fd59977 1785
197ac94e 1786 ViewerTest::CurrentView()->Pan (aDx, aDy);
7fd59977 1787
1788 X_ButtonPress = X_Motion;
1789 Y_ButtonPress = Y_Motion;
1790}
1791
1792//==============================================================================
4fe56619 1793//function : VT_ProcessControlButton3Motion
7fd59977 1794//purpose : Rotation
1795//==============================================================================
4fe56619 1796void VT_ProcessControlButton3Motion()
7fd59977 1797{
4fe56619 1798 if (Start_Rot)
1799 {
1800 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1801 }
7fd59977 1802}
1803
1804//==============================================================================
4fe56619 1805//function : VT_ProcessMotion
1806//purpose :
7fd59977 1807//==============================================================================
4fe56619 1808void VT_ProcessMotion()
7fd59977 1809{
1810 //pre-hilights detected objects at mouse position
1811
1812 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1813 EM->MoveTo(X_Motion, Y_Motion);
1814}
1815
1816
1817void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1818{
1819 Xpix = X_Motion;Ypix=Y_Motion;
1820}
1821
44b8f2d6 1822//==============================================================================
1823//function : ViewProject: implements VAxo, VTop, VLeft, ...
1824//purpose : Switches to an axonometric, top, left and other views
1825//==============================================================================
1826
1827static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1828{
4fe56619 1829 if ( ViewerTest::CurrentView().IsNull() )
44b8f2d6 1830 {
586db386 1831 di<<"Call vinit before this command, please\n";
44b8f2d6 1832 return 1;
1833 }
1834
1835 ViewerTest::CurrentView()->SetProj(ori);
1836 return 0;
1837}
1838
7fd59977 1839//==============================================================================
1840//function : VAxo
1841//purpose : Switch to an Axonometric view
1842//Draw arg : No args
1843//==============================================================================
1844
1845static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
44b8f2d6 1846{
1847 return ViewProject(di, V3d_XposYnegZpos);
7fd59977 1848}
1849
1850//==============================================================================
1851//function : VTop
1852//purpose : Switch to a Top View
1853//Draw arg : No args
1854//==============================================================================
1855
1856static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1857{
44b8f2d6 1858 return ViewProject(di, V3d_Zpos);
1859}
7fd59977 1860
44b8f2d6 1861//==============================================================================
1862//function : VBottom
1863//purpose : Switch to a Bottom View
1864//Draw arg : No args
1865//==============================================================================
7fd59977 1866
44b8f2d6 1867static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1868{
1869 return ViewProject(di, V3d_Zneg);
1870}
7fd59977 1871
44b8f2d6 1872//==============================================================================
1873//function : VLeft
1874//purpose : Switch to a Left View
1875//Draw arg : No args
1876//==============================================================================
1877
1878static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1879{
27af3052 1880 return ViewProject(di, V3d_Xneg);
44b8f2d6 1881}
1882
1883//==============================================================================
1884//function : VRight
1885//purpose : Switch to a Right View
1886//Draw arg : No args
1887//==============================================================================
1888
1889static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1890{
27af3052 1891 return ViewProject(di, V3d_Xpos);
44b8f2d6 1892}
7fd59977 1893
44b8f2d6 1894//==============================================================================
1895//function : VFront
1896//purpose : Switch to a Front View
1897//Draw arg : No args
1898//==============================================================================
1899
1900static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1901{
27af3052 1902 return ViewProject(di, V3d_Yneg);
44b8f2d6 1903}
1904
1905//==============================================================================
1906//function : VBack
1907//purpose : Switch to a Back View
1908//Draw arg : No args
1909//==============================================================================
1910
1911static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1912{
27af3052 1913 return ViewProject(di, V3d_Ypos);
7fd59977 1914}
1915
1916//==============================================================================
1917//function : VHelp
1918//purpose : Dsiplay help on viewer Keyboead and mouse commands
1919//Draw arg : No args
1920//==============================================================================
1921
1922static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1923{
1924
586db386 1925 di << "Q : Quit the application\n";
1926
1927 di << "=========================\n";
1928 di << "F : FitAll\n";
1929 di << "T : TopView\n";
1930 di << "B : BottomView\n";
1931 di << "R : RightView\n";
1932 di << "L : LeftView\n";
1933 di << "A : AxonometricView\n";
1934 di << "D : ResetView\n";
1935
1936 di << "=========================\n";
1937 di << "S : Shading\n";
1938 di << "W : Wireframe\n";
1939 di << "H : HidelLineRemoval\n";
1940 di << "U : Unset display mode\n";
1941 di << "Delete : Remove selection from viewer\n";
1942
1943 di << "=========================\n";
1944 di << "Selection mode \n";
1945 di << "0 : Shape\n";
1946 di << "1 : Vertex\n";
1947 di << "2 : Edge\n";
1948 di << "3 : Wire\n";
1949 di << "4 : Face\n";
1950 di << "5 : Shell\n";
1951 di << "6 : Solid\n";
1952 di << "7 : Compound\n";
1953
1954 di << "=========================\n";
1955 di << "Z : Switch Z clipping On/Off\n";
1956 di << ", : Hilight next detected\n";
1957 di << ". : Hilight previous detected\n";
7fd59977 1958
1959 return 0;
1960}
1961
57c28b61 1962#ifdef _WIN32
7fd59977 1963
1964static Standard_Boolean Ppick = 0;
1965static Standard_Integer Pargc = 0;
1966static const char** Pargv = NULL;
1967
1968
1969static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1970 UINT Msg,
1971 WPARAM wParam,
1972 LPARAM lParam )
1973{
18d715bd 1974 if (!ViewerTest_myViews.IsEmpty()) {
7fd59977 1975
1976 WPARAM fwKeys = wParam;
1977
1978 switch( Msg ) {
18d715bd 1979 case WM_CLOSE:
1980 {
1981 // Delete view from map of views
1982 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1983 return 0;
1984 }
1985 break;
1986 case WM_ACTIVATE:
1987 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1988 || ViewerTest::CurrentView().IsNull())
1989 {
1990 // Activate inactive window
1991 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1992 {
1993 ActivateView (FindViewIdByWindowHandle(hwnd));
1994 }
1995 }
1996 break;
625e1958 1997
7fd59977 1998 case WM_LBUTTONUP:
625e1958 1999 if (IsDragged && !DragFirst)
7fd59977 2000 {
625e1958 2001 if (!GetActiveAISManipulator().IsNull())
2002 {
2003 GetActiveAISManipulator()->StopTransform();
0577ae8c 2004 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
625e1958 2005 }
2006
b12e1c7b 2007 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2008 {
2009 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2010 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2011 }
2012
dde68833 2013 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
7fd59977 2014 }
8abada55 2015 IsDragged = Standard_False;
7fd59977 2016 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2017
625e1958 2018 case WM_RBUTTONUP:
2019 if (IsDragged && !DragFirst)
2020 {
2021 if (!GetActiveAISManipulator().IsNull())
2022 {
2023 GetActiveAISManipulator()->StopTransform (Standard_False);
0577ae8c 2024 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
625e1958 2025 }
2026 IsDragged = Standard_False;
2027 }
2028 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2029
7fd59977 2030 case WM_LBUTTONDOWN:
625e1958 2031 if (!GetActiveAISManipulator().IsNull())
2032 {
2033 IsDragged = ( fwKeys == MK_LBUTTON );
2034 }
2035 else
2036 {
2037 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2038 }
2039
2040 if (IsDragged)
7fd59977 2041 {
7fd59977 2042 DragFirst = Standard_True;
4fe56619 2043 X_ButtonPress = LOWORD(lParam);
2044 Y_ButtonPress = HIWORD(lParam);
7fd59977 2045 }
2046 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2047
7fd59977 2048 case WM_MOUSEMOVE:
b12e1c7b 2049 if (IsDragged)
7fd59977 2050 {
b12e1c7b 2051 X_Motion = LOWORD (lParam);
2052 Y_Motion = HIWORD (lParam);
625e1958 2053 if (!GetActiveAISManipulator().IsNull())
b12e1c7b 2054 {
625e1958 2055 if (DragFirst)
2056 {
2057 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2058 }
2059 else
2060 {
2061 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2062 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2063 }
69adb9ce 2064 }
625e1958 2065 else
69adb9ce 2066 {
625e1958 2067 bool toRedraw = false;
2068 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2069 {
2070 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2071 toRedraw = true;
2072 }
2073
2074 RECT aRect;
2075 if (GetClientRect (hwnd, &aRect))
2076 {
2077 int aHeight = aRect.bottom - aRect.top;
2078 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2079 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2080 toRedraw = true;
2081 }
2082 if (toRedraw)
2083 {
2084 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2085 }
b12e1c7b 2086 }
625e1958 2087
2088 DragFirst = Standard_False;
7fd59977 2089 }
2090 else
2091 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2092 break;
2093
2094 default:
2095 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2096 }
2097 return 0;
2098 }
2099 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2100}
2101
2102
2103static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2104 UINT Msg,
2105 WPARAM wParam,
2106 LPARAM lParam )
2107{
7fd59977 2108 static int Up = 1;
f978241f 2109 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2110 if (aView.IsNull())
2111 {
ad03c234 2112 return DefWindowProcW (hwnd, Msg, wParam, lParam);
f978241f 2113 }
7fd59977 2114
7fd59977 2115 PAINTSTRUCT ps;
2116
2117 switch( Msg ) {
7fd59977 2118 case WM_PAINT:
7fd59977 2119 BeginPaint(hwnd, &ps);
2120 EndPaint(hwnd, &ps);
4fe56619 2121 VT_ProcessExpose();
7fd59977 2122 break;
2123
2124 case WM_SIZE:
4fe56619 2125 VT_ProcessConfigure();
7fd59977 2126 break;
f978241f 2127 case WM_MOVE:
2128 case WM_MOVING:
2129 case WM_SIZING:
2130 switch (aView->RenderingParams().StereoMode)
2131 {
2132 case Graphic3d_StereoMode_RowInterlaced:
2133 case Graphic3d_StereoMode_ColumnInterlaced:
2134 case Graphic3d_StereoMode_ChessBoard:
2135 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2136 break;
2137 default:
2138 break;
2139 }
2140 break;
7fd59977 2141
2142 case WM_KEYDOWN:
4fe56619 2143 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2144 {
7fd59977 2145 char c[2];
2146 c[0] = (char) wParam;
2147 c[1] = '\0';
b514beda 2148 if (wParam == VK_DELETE)
2149 {
2150 c[0] = THE_KEY_DELETE;
2151 }
4ca4bbe8 2152 // comma
2153 else if (wParam == VK_OEM_COMMA)
2154 {
2155 c[0] = ',';
2156 }
2157 // dot
2158 else if (wParam == VK_OEM_PERIOD)
2159 {
2160 c[0] = '.';
2161 }
f978241f 2162 else if (wParam == VK_DIVIDE)
2163 {
2164 c[0] = '/';
2165 }
2166 // dot
2167 else if (wParam == VK_MULTIPLY)
2168 {
2169 c[0] = '*';
2170 }
4fe56619 2171 VT_ProcessKeyPress (c);
7fd59977 2172 }
2173 break;
2174
2175 case WM_LBUTTONUP:
2176 case WM_MBUTTONUP:
2177 case WM_RBUTTONUP:
7fd59977 2178 Up = 1;
4fe56619 2179 VT_ProcessButton3Release();
7fd59977 2180 break;
2181
2182 case WM_LBUTTONDOWN:
2183 case WM_MBUTTONDOWN:
2184 case WM_RBUTTONDOWN:
2185 {
7fd59977 2186 WPARAM fwKeys = wParam;
2187
2188 Up = 0;
2189
2190 X_ButtonPress = LOWORD(lParam);
2191 Y_ButtonPress = HIWORD(lParam);
2192
4fe56619 2193 if (Msg == WM_LBUTTONDOWN)
2194 {
dde68833 2195 if ((fwKeys & MK_CONTROL) != 0)
4fe56619 2196 {
dde68833 2197 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
4fe56619 2198 }
2199 else
2200 {
dde68833 2201 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
4fe56619 2202 }
7fd59977 2203 }
4fe56619 2204 else if (Msg == WM_RBUTTONDOWN)
2205 {
7fd59977 2206 // Start rotation
4fe56619 2207 VT_ProcessButton3Press();
7fd59977 2208 }
2209 }
2210 break;
2211
f978241f 2212 case WM_MOUSEWHEEL:
2213 {
2214 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2215 if (wParam & MK_CONTROL)
2216 {
2217 if (aView->Camera()->IsStereo())
2218 {
2219 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2220 if (aFocus > 0.2
2221 && aFocus < 2.0)
2222 {
2223 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2224 aView->Redraw();
2225 }
2226 }
2227 }
2228 else
2229 {
2230 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2231 }
2232 break;
2233 }
2234
7fd59977 2235 case WM_MOUSEMOVE:
2236 {
2237 //cout << "\t WM_MOUSEMOVE" << endl;
2238 WPARAM fwKeys = wParam;
2239 X_Motion = LOWORD(lParam);
2240 Y_Motion = HIWORD(lParam);
2241
2242 if ( Up &&
dde68833 2243 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2244 {
7fd59977 2245 Up = 0;
2246 X_ButtonPress = LOWORD(lParam);
2247 Y_ButtonPress = HIWORD(lParam);
2248
dde68833 2249 if ((fwKeys & MK_RBUTTON) != 0) {
7fd59977 2250 // Start rotation
4fe56619 2251 VT_ProcessButton3Press();
7fd59977 2252 }
2253 }
2254
dde68833 2255 if ((fwKeys & MK_CONTROL) != 0)
2256 {
2257 if ((fwKeys & MK_LBUTTON) != 0)
2258 {
7fd59977 2259 ProcessControlButton1Motion();
2260 }
dde68833 2261 else if ((fwKeys & MK_MBUTTON) != 0
2262 || ((fwKeys & MK_LBUTTON) != 0
2263 && (fwKeys & MK_RBUTTON) != 0))
2264 {
2265 VT_ProcessControlButton2Motion();
2266 }
2267 else if ((fwKeys & MK_RBUTTON) != 0)
2268 {
4fe56619 2269 VT_ProcessControlButton3Motion();
7fd59977 2270 }
2271 }
08398024 2272 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2273 {
89a929ea 2274 VT_ProcessMotion();
08398024 2275 }
7fd59977 2276 }
2277 break;
2278
2279 default:
ad03c234 2280 return DefWindowProcW (hwnd, Msg, wParam, lParam);
7fd59977 2281 }
2282 return 0L;
7fd59977 2283}
2284
7fd59977 2285//==============================================================================
2286//function : ViewerMainLoop
2287//purpose : Get a Event on the view and dispatch it
2288//==============================================================================
2289
2290
8263fcd3 2291int ViewerMainLoop(Standard_Integer argc, const char** argv)
7fd59977 2292{
7fd59977 2293 Ppick = (argc > 0)? 1 : 0;
2294 Pargc = argc;
2295 Pargv = argv;
2296
2297 if ( Ppick ) {
2298 MSG msg;
2299 msg.wParam = 1;
2300
2301 cout << "Start picking" << endl;
2302
7fd59977 2303 while ( Ppick == 1 ) {
4fe56619 2304 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
ad03c234 2305 if (GetMessageW (&msg, NULL, 0, 0))
2306 {
2307 TranslateMessage (&msg);
2308 DispatchMessageW (&msg);
7fd59977 2309 }
2310 }
2311
2312 cout << "Picking done" << endl;
2313 }
2314
2315 return Ppick;
2316}
2317
4fe56619 2318#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 2319
2320int min( int a, int b )
2321{
2322 if( a<b )
2323 return a;
2324 else
2325 return b;
2326}
2327
2328int max( int a, int b )
2329{
2330 if( a>b )
2331 return a;
2332 else
2333 return b;
2334}
2335
2336int ViewerMainLoop(Standard_Integer argc, const char** argv)
2337
4269bd1b 2338{
18d715bd 2339 static XEvent aReport;
2340 Standard_Boolean pick = argc > 0;
2341 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2342 XNextEvent (aDisplay, &aReport);
7fd59977 2343
18d715bd 2344 // Handle event for the chosen display connection
2345 switch (aReport.type) {
2346 case ClientMessage:
2347 {
eb1ebea4 2348 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
18d715bd 2349 {
2350 // Close the window
2351 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2352 }
2353 }
2354 return 0;
2355 case FocusIn:
2356 {
2357 // Activate inactive view
2358 Window aWindow = GetWindowHandle(VT_GetWindow());
2359 if(aWindow != aReport.xfocus.window)
2360 {
2361 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2362 }
2363 }
2364 break;
7fd59977 2365 case Expose:
2366 {
4fe56619 2367 VT_ProcessExpose();
7fd59977 2368 }
2369 break;
2370 case ConfigureNotify:
2371 {
4fe56619 2372 VT_ProcessConfigure();
7fd59977 2373 }
2374 break;
2375 case KeyPress:
2376 {
2377
2378 KeySym ks_ret ;
2379 char buf_ret[11] ;
2380 int ret_len ;
2381 XComposeStatus status_in_out;
2382
18d715bd 2383 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
7fd59977 2384 (char *) buf_ret , 10 ,
2385 &ks_ret , &status_in_out ) ;
2386
2387
2388 buf_ret[ret_len] = '\0' ;
2389
4fe56619 2390 if (ret_len)
2391 {
2392 VT_ProcessKeyPress (buf_ret);
7fd59977 2393 }
2394 }
2395 break;
2396 case ButtonPress:
7fd59977 2397 {
18d715bd 2398 X_ButtonPress = aReport.xbutton.x;
2399 Y_ButtonPress = aReport.xbutton.y;
7fd59977 2400
18d715bd 2401 if (aReport.xbutton.button == Button1)
4fe56619 2402 {
18d715bd 2403 if (aReport.xbutton.state & ControlMask)
4fe56619 2404 {
18d715bd 2405 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
4fe56619 2406 }
7fd59977 2407 else
2408 {
2409 IsDragged = Standard_True;
7fd59977 2410 DragFirst = Standard_True;
2411 }
4fe56619 2412 }
18d715bd 2413 else if (aReport.xbutton.button == Button3)
4fe56619 2414 {
7fd59977 2415 // Start rotation
4fe56619 2416 VT_ProcessButton3Press();
2417 }
7fd59977 2418 }
2419 break;
2420 case ButtonRelease:
2421 {
7fd59977 2422 if( IsDragged )
2423 {
2424 if( !DragFirst )
2425 {
b12e1c7b 2426 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2427 {
2428 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2429 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2430 }
7fd59977 2431 }
2432
2433 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2434 if( aContext.IsNull() )
2435 {
2436 cout << "The context is null. Please use vinit before createmesh" << endl;
2437 return 0;
2438 }
2439
18d715bd 2440 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2441 if( aReport.xbutton.button==1 )
7fd59977 2442 if( DragFirst )
2443 if( ShiftPressed )
2444 {
0577ae8c 2445 aContext->ShiftSelect (Standard_True);
7fd59977 2446 }
2447 else
2448 {
0577ae8c 2449 aContext->Select (Standard_True);
7fd59977 2450 }
2451 else
2452 if( ShiftPressed )
2453 {
0577ae8c 2454 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2455 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2456 ViewerTest::CurrentView(), Standard_True);
7fd59977 2457 }
2458 else
2459 {
0577ae8c 2460 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2461 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2462 ViewerTest::CurrentView(), Standard_True);
7fd59977 2463 }
2464 else
4fe56619 2465 VT_ProcessButton3Release();
7fd59977 2466
2467 IsDragged = Standard_False;
2468 }
2469 else
4fe56619 2470 VT_ProcessButton3Release();
7fd59977 2471 }
2472 break;
2473 case MotionNotify:
2474 {
08398024 2475 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2476 {
2477 break;
2478 }
7fd59977 2479 if( IsDragged )
2480 {
7fd59977 2481 if( !DragFirst )
b12e1c7b 2482 {
2483 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2484 {
2485 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
b12e1c7b 2486 }
2487 }
7fd59977 2488
18d715bd 2489 X_Motion = aReport.xmotion.x;
2490 Y_Motion = aReport.xmotion.y;
7fd59977 2491 DragFirst = Standard_False;
2492
b12e1c7b 2493 Window aWindow = GetWindowHandle(VT_GetWindow());
2494 Window aRoot;
2495 int anX, anY;
2496 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2497 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2498 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
69adb9ce 2499 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
b12e1c7b 2500 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
7fd59977 2501 }
2502 else
2503 {
18d715bd 2504 X_Motion = aReport.xmotion.x;
2505 Y_Motion = aReport.xmotion.y;
7fd59977 2506
18d715bd 2507 // remove all the ButtonMotionMaskr
2508 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
7fd59977 2509
18d715bd 2510 if ( aReport.xmotion.state & ControlMask ) {
2511 if ( aReport.xmotion.state & Button1Mask ) {
7fd59977 2512 ProcessControlButton1Motion();
2513 }
18d715bd 2514 else if ( aReport.xmotion.state & Button2Mask ) {
4fe56619 2515 VT_ProcessControlButton2Motion();
7fd59977 2516 }
18d715bd 2517 else if ( aReport.xmotion.state & Button3Mask ) {
4fe56619 2518 VT_ProcessControlButton3Motion();
7fd59977 2519 }
2520 }
4fe56619 2521 else
2522 {
2523 VT_ProcessMotion();
7fd59977 2524 }
2525 }
2526 }
2527 break;
2528}
7fd59977 2529return pick;
2530}
2531
2532//==============================================================================
2533//function : VProcessEvents
2534//purpose : call by Tk_CreateFileHandler() to be able to manage the
2535// event in the Viewer window
2536//==============================================================================
2537
2538static void VProcessEvents(ClientData,int)
2539{
18d715bd 2540 NCollection_Vector<int> anEventNumbers;
2541 // Get number of messages from every display
2542 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2543 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2544 {
2545 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
4269bd1b 2546 }
18d715bd 2547 // Handle events for every display
2548 int anEventIter = 0;
2549 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2550 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2551 {
4269bd1b 2552 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
18d715bd 2553 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2554 {
2555 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2556 int anEventResult = ViewerMainLoop( 0, NULL);
2557 // If window is closed or context was not found finish current event processing loop
2558 if (!anEventResult)
2559 return;
2560 }
7fd59977 2561 }
4269bd1b 2562
18d715bd 2563 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
4269bd1b 2564
7fd59977 2565}
2566#endif
2567
2568//==============================================================================
2569//function : OSWindowSetup
2570//purpose : Setup for the X11 window to be able to cath the event
2571//==============================================================================
2572
2573
2574static void OSWindowSetup()
2575{
4fe56619 2576#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2577 // X11
2578
2579 Window window = VT_GetWindow()->XWindow();
18d715bd 2580 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2581 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2582 XSynchronize(aDisplay, 1);
7fd59977 2583
2584 // X11 : For keyboard on SUN
2585 XWMHints wmhints;
2586 wmhints.flags = InputHint;
2587 wmhints.input = 1;
2588
18d715bd 2589 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 2590
18d715bd 2591 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
7fd59977 2592 ButtonPressMask | ButtonReleaseMask |
2593 StructureNotifyMask |
2594 PointerMotionMask |
2595 Button1MotionMask | Button2MotionMask |
18d715bd 2596 Button3MotionMask | FocusChangeMask
7fd59977 2597 );
18d715bd 2598 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2599 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 2600
18d715bd 2601 XSynchronize(aDisplay, 0);
7fd59977 2602
2603#else
57c28b61 2604 // _WIN32
7fd59977 2605#endif
2606
2607}
2608
7fd59977 2609//==============================================================================
2610//function : VFit
1beb58d7 2611//purpose :
7fd59977 2612//==============================================================================
2613
1beb58d7 2614static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
7fd59977 2615{
1beb58d7 2616 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2617 if (aView.IsNull())
b586500b 2618 {
1beb58d7 2619 std::cout << "Error: no active viewer!\n";
2620 return 1;
b586500b 2621 }
2622
1beb58d7 2623 Standard_Boolean toFit = Standard_True;
2624 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2625 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
b586500b 2626 {
1beb58d7 2627 TCollection_AsciiString anArg (theArgv[anArgIter]);
b586500b 2628 anArg.LowerCase();
1beb58d7 2629 if (anUpdateTool.parseRedrawMode (anArg))
b586500b 2630 {
1beb58d7 2631 continue;
2632 }
2633 else if (anArg == "-selected")
2634 {
2635 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2636 toFit = Standard_False;
2637 }
2638 else
2639 {
2640 std::cout << "Syntax error at '" << anArg << "'\n";
b586500b 2641 }
2642 }
2643
1beb58d7 2644 if (toFit)
2645 {
2646 aView->FitAll (0.01, Standard_False);
7fd59977 2647 }
2648 return 0;
2649}
2650
6262a303 2651//=======================================================================
2652//function : VFitArea
2653//purpose : Fit view to show area located between two points
2654// : given in world 2D or 3D coordinates.
2655//=======================================================================
2656static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2657{
2658 Handle(V3d_View) aView = ViewerTest::CurrentView();
2659 if (aView.IsNull())
2660 {
2661 std::cerr << theArgVec[0] << "Error: No active view.\n";
2662 return 1;
2663 }
2664
2665 // Parse arguments.
2666 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2667 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2668
2669 if (theArgNb == 5)
2670 {
2671 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2672 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2673 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2674 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2675 }
2676 else if (theArgNb == 7)
2677 {
2678 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2679 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2680 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2681 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2682 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2683 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2684 }
2685 else
2686 {
2687 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2688 theDI.PrintHelp(theArgVec[0]);
2689 return 1;
2690 }
2691
2692 // Convert model coordinates to view space
2693 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2694 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2695 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2696
2697 // Determine fit area
2698 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2699 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2700
2701 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2702
2703 if (aDiagonal < Precision::Confusion())
2704 {
2705 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2706 return 1;
2707 }
2708
2709 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2710 return 0;
2711}
2712
7fd59977 2713//==============================================================================
2714//function : VZFit
2715//purpose : ZFitall, no DRAW arguments
2716//Draw arg : No args
2717//==============================================================================
197ac94e 2718static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 2719{
197ac94e 2720 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2721
2722 if (aCurrentView.IsNull())
2723 {
2724 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2725 return 1;
2726 }
2727
2728 if (theArgsNb == 1)
2729 {
c357e426 2730 aCurrentView->ZFitAll();
197ac94e 2731 aCurrentView->Redraw();
2732 return 0;
2733 }
2734
2735 Standard_Real aScale = 1.0;
2736
2737 if (theArgsNb >= 2)
2738 {
2739 aScale = Draw::Atoi (theArgVec[1]);
2740 }
2741
c357e426 2742 aCurrentView->ZFitAll (aScale);
197ac94e 2743 aCurrentView->Redraw();
7fd59977 2744
197ac94e 2745 return 0;
2746}
7fd59977 2747
197ac94e 2748//==============================================================================
2749//function : VRepaint
2750//purpose :
2751//==============================================================================
56689b27 2752static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
7fd59977 2753{
56689b27 2754 Handle(V3d_View) aView = ViewerTest::CurrentView();
2755 if (aView.IsNull())
2756 {
2757 std::cout << "Error: no active viewer!\n";
2758 return 1;
2759 }
2760
2761 Standard_Boolean isImmediateUpdate = Standard_False;
2762 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2763 {
2764 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2765 anArg.LowerCase();
2766 if (anArg == "-immediate")
2767 {
2768 isImmediateUpdate = Standard_True;
2769 if (anArgIter + 1 < theArgNb
2770 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2771 {
2772 ++anArgIter;
2773 }
2774 }
2775 else
2776 {
2777 std::cout << "Syntax error at '" << anArg << "'\n";
2778 }
2779 }
2780
2781 if (isImmediateUpdate)
2782 {
2783 aView->RedrawImmediate();
2784 }
2785 else
2786 {
2787 aView->Redraw();
2788 }
2789 return 0;
7fd59977 2790}
2791
7fd59977 2792//==============================================================================
2793//function : VClear
2794//purpose : Remove all the object from the viewer
2795//Draw arg : No args
2796//==============================================================================
2797
2798static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2799{
2800 Handle(V3d_View) V = ViewerTest::CurrentView();
2801 if(!V.IsNull())
2802 ViewerTest::Clear();
2803 return 0;
2804}
2805
2806//==============================================================================
2807//function : VPick
2808//purpose :
2809//==============================================================================
2810
2811static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2812{ if (ViewerTest::CurrentView().IsNull() ) return 1;
2813
2814if ( argc < 4 ) {
586db386 2815 di << argv[0] << "Invalid number of arguments\n";
7fd59977 2816 return 1;
2817}
2818
2819while (ViewerMainLoop( argc, argv)) {
2820}
2821
2822return 0;
2823}
2824
7fd59977 2825//==============================================================================
2826//function : VSetBg
2827//purpose : Load image as background
2828//==============================================================================
2829
2830static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2831{
2832 if (argc < 2 || argc > 3)
2833 {
586db386 2834 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
2835 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
7fd59977 2836 return 1;
2837 }
2838
2839 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2840 if(AISContext.IsNull())
2841 {
2842 di << "use 'vinit' command before " << argv[0] << "\n";
2843 return 1;
2844 }
2845
2846 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2847 if (argc == 3)
2848 {
2849 const char* szType = argv[2];
2850 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2851 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2852 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2853 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2854 else
2855 {
2856 di << "Wrong fill type : " << szType << "\n";
586db386 2857 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
7fd59977 2858 return 1;
2859 }
2860 }
2861
2862 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2863 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2864
2865 return 0;
2866}
2867
f8b2ed36 2868//==============================================================================
2869//function : VSetBgMode
2870//purpose : Change background image fill type
2871//==============================================================================
2872
2873static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2874{
2875 if (argc != 2)
2876 {
586db386 2877 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
2878 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
f8b2ed36 2879 return 1;
2880 }
2881
2882 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2883 if(AISContext.IsNull())
2884 {
2885 di << "use 'vinit' command before " << argv[0] << "\n";
2886 return 1;
2887 }
1d47d8d0 2888 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2889 const char* szType = argv[1];
2890 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2891 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2892 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2893 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2894 else
f8b2ed36 2895 {
1d47d8d0 2896 di << "Wrong fill type : " << szType << "\n";
586db386 2897 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
1d47d8d0 2898 return 1;
f8b2ed36 2899 }
f8b2ed36 2900 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2901 V3dView->SetBgImageStyle(aFillType, Standard_True);
f8b2ed36 2902 return 0;
2903}
2904
7fd59977 2905//==============================================================================
2906//function : VSetGradientBg
2907//purpose : Mount gradient background
2908//==============================================================================
2909static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2910{
2911 if (argc != 8 )
2912 {
586db386 2913 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
2914 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
2915 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2916 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
7fd59977 2917 return 1;
2918 }
2919
2920 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2921 if(AISContext.IsNull())
2922 {
2923 di << "use 'vinit' command before " << argv[0] << "\n";
2924 return 1;
2925 }
2926 if (argc == 8)
2927 {
2928
91322f44 2929 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2930 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2931 Standard_Real B1 = Draw::Atof(argv[3])/255.;
7fd59977 2932 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2933
91322f44 2934 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2935 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2936 Standard_Real B2 = Draw::Atof(argv[6])/255.;
7fd59977 2937
2938 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
91322f44 2939 int aType = Draw::Atoi(argv[7]);
7fd59977 2940 if( aType < 0 || aType > 8 )
2941 {
586db386 2942 di << "Wrong fill type \n";
2943 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2944 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
7fd59977 2945 return 1;
2946 }
2947
2948 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2949
2950 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2951 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2952 }
2953
2954 return 0;
2955}
2956
f8b2ed36 2957//==============================================================================
2958//function : VSetGradientBgMode
2959//purpose : Change gradient background fill style
2960//==============================================================================
2961static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2962{
2963 if (argc != 2 )
2964 {
586db386 2965 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
2966 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2967 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
f8b2ed36 2968 return 1;
2969 }
2970
2971 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2972 if(AISContext.IsNull())
2973 {
2974 di << "use 'vinit' command before " << argv[0] << "\n";
2975 return 1;
2976 }
2977 if (argc == 2)
2978 {
91322f44 2979 int aType = Draw::Atoi(argv[1]);
f8b2ed36 2980 if( aType < 0 || aType > 8 )
2981 {
586db386 2982 di << "Wrong fill type \n";
2983 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2984 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
f8b2ed36 2985 return 1;
2986 }
2987
2988 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2989
2990 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2991 V3dView->SetBgGradientStyle( aMethod, 1 );
2992 }
2993
2994 return 0;
2995}
2996
2997//==============================================================================
2998//function : VSetColorBg
2999//purpose : Set color background
3000//==============================================================================
3001static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3002{
3003 if (argc != 4 )
3004 {
586db386 3005 di << "Usage : " << argv[0] << " R G B : Set color background\n";
3006 di << "R,G,B = [0..255]\n";
f8b2ed36 3007 return 1;
3008 }
3009
3010 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3011 if(AISContext.IsNull())
3012 {
3013 di << "use 'vinit' command before " << argv[0] << "\n";
3014 return 1;
3015 }
3016 if (argc == 4)
3017 {
3018
91322f44 3019 Standard_Real R = Draw::Atof(argv[1])/255.;
3020 Standard_Real G = Draw::Atof(argv[2])/255.;
3021 Standard_Real B = Draw::Atof(argv[3])/255.;
f8b2ed36 3022 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
3023
3024 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3025 V3dView->SetBackgroundColor( aColor );
3026 V3dView->Update();
3027 }
3028
3029 return 0;
3030}
3031
f42753ed 3032//==============================================================================
3033//function : VSetDefaultBg
3034//purpose : Set default viewer background fill color
3035//==============================================================================
3036static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3037{
3038 if (theArgNb != 4
3039 && theArgNb != 8)
3040 {
3041 std::cout << "Error: wrong syntax! See usage:\n";
3042 theDI.PrintHelp (theArgVec[0]);
3043 return 1;
3044 }
3045
3046 ViewerTest_DefaultBackground.FillMethod =
3047 theArgNb == 4 ? Aspect_GFM_NONE
3048 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
3049
3050 if (theArgNb == 4)
3051 {
3052 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
3053 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
3054 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
3055 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
3056 }
3057 else
3058 {
3059 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
3060 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
3061 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
3062 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
3063
3064 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
3065 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
3066 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
3067 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
3068 }
3069
3070 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
3071 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
3072 {
3073 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
3074 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
3075 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
3076 ViewerTest_DefaultBackground.GradientColor2,
3077 ViewerTest_DefaultBackground.FillMethod);
3078 }
3079
3080 return 0;
3081}
3082
7fd59977 3083//==============================================================================
3084//function : VScale
3085//purpose : View Scaling
3086//==============================================================================
3087
3088static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3089{
3090 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3091 if ( V3dView.IsNull() ) return 1;
3092
3093 if ( argc != 4 ) {
586db386 3094 di << argv[0] << "Invalid number of arguments\n";
7fd59977 3095 return 1;
3096 }
91322f44 3097 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
7fd59977 3098 return 0;
3099}
3100//==============================================================================
536d98e2 3101//function : VZBuffTrihedron
3102//purpose :
7fd59977 3103//==============================================================================
3104
536d98e2 3105static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3106 Standard_Integer theArgNb,
3107 const char** theArgVec)
7fd59977 3108{
536d98e2 3109 Handle(V3d_View) aView = ViewerTest::CurrentView();
3110 if (aView.IsNull())
3111 {
3112 std::cout << "Error: no active viewer!\n";
3113 return 1;
3114 }
7fd59977 3115
536d98e2 3116 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7c8a8fcc 3117
536d98e2 3118 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3119 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3120 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3121 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3122 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3123 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3124 Standard_Real aScale = 0.1;
3125 Standard_Real aSizeRatio = 0.8;
3126 Standard_Real anArrowDiam = 0.05;
3127 Standard_Integer aNbFacets = 12;
3128 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7c8a8fcc 3129 {
536d98e2 3130 Standard_CString anArg = theArgVec[anArgIter];
3131 TCollection_AsciiString aFlag (anArg);
3132 aFlag.LowerCase();
3133 if (anUpdateTool.parseRedrawMode (aFlag))
7c8a8fcc 3134 {
536d98e2 3135 continue;
3136 }
3137 else if (aFlag == "-on")
7c8a8fcc 3138 {
536d98e2 3139 continue;
3140 }
3141 else if (aFlag == "-off")
7c8a8fcc 3142 {
536d98e2 3143 aView->TriedronErase();
3144 return 0;
3145 }
3146 else if (aFlag == "-pos"
3147 || aFlag == "-position"
3148 || aFlag == "-corner")
7c8a8fcc 3149 {
536d98e2 3150 if (++anArgIter >= theArgNb)
3151 {
3152 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3153 return 1;
3154 }
3155
3156 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3157 aPosName.LowerCase();
3158 if (aPosName == "center")
3159 {
3160 aPosition = Aspect_TOTP_CENTER;
3161 }
3162 else if (aPosName == "left_lower"
3163 || aPosName == "lower_left"
3164 || aPosName == "leftlower"
3165 || aPosName == "lowerleft")
3166 {
3167 aPosition = Aspect_TOTP_LEFT_LOWER;
3168 }
3169 else if (aPosName == "left_upper"
3170 || aPosName == "upper_left"
3171 || aPosName == "leftupper"
3172 || aPosName == "upperleft")
3173 {
3174 aPosition = Aspect_TOTP_LEFT_UPPER;
3175 }
3176 else if (aPosName == "right_lower"
3177 || aPosName == "lower_right"
3178 || aPosName == "rightlower"
3179 || aPosName == "lowerright")
3180 {
3181 aPosition = Aspect_TOTP_RIGHT_LOWER;
3182 }
3183 else if (aPosName == "right_upper"
3184 || aPosName == "upper_right"
3185 || aPosName == "rightupper"
3186 || aPosName == "upperright")
3187 {
3188 aPosition = Aspect_TOTP_RIGHT_UPPER;
3189 }
3190 else
3191 {
3192 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3193 return 1;
3194 }
3195 }
3196 else if (aFlag == "-type")
7c8a8fcc 3197 {
536d98e2 3198 if (++anArgIter >= theArgNb)
3199 {
3200 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3201 return 1;
3202 }
3203
3204 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3205 aTypeName.LowerCase();
3206 if (aTypeName == "wireframe"
3207 || aTypeName == "wire")
3208 {
3209 aVisType = V3d_WIREFRAME;
3210 }
3211 else if (aTypeName == "zbuffer"
3212 || aTypeName == "shaded")
3213 {
3214 aVisType = V3d_ZBUFFER;
3215 }
3216 else
3217 {
3218 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3219 }
3220 }
3221 else if (aFlag == "-scale")
7c8a8fcc 3222 {
536d98e2 3223 if (++anArgIter >= theArgNb)
3224 {
3225 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3226 return 1;
3227 }
3228
3229 aScale = Draw::Atof (theArgVec[anArgIter]);
7c8a8fcc 3230 }
536d98e2 3231 else if (aFlag == "-size"
3232 || aFlag == "-sizeratio")
3233 {
3234 if (++anArgIter >= theArgNb)
3235 {
3236 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3237 return 1;
3238 }
7c8a8fcc 3239
536d98e2 3240 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3241 }
3242 else if (aFlag == "-arrowdiam"
3243 || aFlag == "-arrowdiameter")
3244 {
3245 if (++anArgIter >= theArgNb)
3246 {
3247 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3248 return 1;
3249 }
7c8a8fcc 3250
536d98e2 3251 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3252 }
3253 else if (aFlag == "-nbfacets")
3254 {
3255 if (++anArgIter >= theArgNb)
3256 {
3257 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3258 return 1;
3259 }
7c8a8fcc 3260
536d98e2 3261 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3262 }
3263 else if (aFlag == "-colorlabel"
3264 || aFlag == "-colorlabels")
7c8a8fcc 3265 {
536d98e2 3266 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3267 theArgVec + anArgIter + 1,
3268 aLabelsColor);
3269 if (aNbParsed == 0)
3270 {
3271 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3272 return 1;
3273 }
3274 anArgIter += aNbParsed;
7c8a8fcc 3275 }
536d98e2 3276 else if (aFlag == "-colorarrowx")
7c8a8fcc 3277 {
536d98e2 3278 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3279 theArgVec + anArgIter + 1,
3280 anArrowColorX);
3281 if (aNbParsed == 0)
3282 {
3283 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3284 return 1;
3285 }
3286 anArgIter += aNbParsed;
3287 }
3288 else if (aFlag == "-colorarrowy")
7c8a8fcc 3289 {
536d98e2 3290 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3291 theArgVec + anArgIter + 1,
3292 anArrowColorY);
3293 if (aNbParsed == 0)
3294 {
3295 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3296 return 1;
3297 }
3298 anArgIter += aNbParsed;
3299 }
3300 else if (aFlag == "-colorarrowz")
7c8a8fcc 3301 {
536d98e2 3302 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3303 theArgVec + anArgIter + 1,
3304 anArrowColorZ);
3305 if (aNbParsed == 0)
3306 {
3307 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3308 return 1;
3309 }
3310 anArgIter += aNbParsed;
3311 }
3312 else
3313 {
3314 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
7c8a8fcc 3315 return 1;
3316 }
7c8a8fcc 3317 }
3318
536d98e2 3319 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3320 aSizeRatio, anArrowDiam, aNbFacets);
3321 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
c357e426 3322 aView->ZFitAll();
7fd59977 3323 return 0;
3324}
3325
3326//==============================================================================
3327//function : VRotate
3328//purpose : Camera Rotating
3329//==============================================================================
3330
4af098ba 3331static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3332{
3333 Handle(V3d_View) aView = ViewerTest::CurrentView();
3334 if (aView.IsNull())
3335 {
3336 std::cout << "No active view!\n";
7fd59977 3337 return 1;
3338 }
3339
4af098ba 3340 Standard_Boolean hasFlags = Standard_False;
3341 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3342 {
3343 Standard_CString anArg (theArgVec[anArgIter]);
3344 TCollection_AsciiString aFlag (anArg);
3345 aFlag.LowerCase();
3346 if (aFlag == "-mousestart"
3347 || aFlag == "-mousefrom")
3348 {
3349 hasFlags = Standard_True;
3350 if (anArgIter + 2 >= theArgNb)
3351 {
3352 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3353 return 1;
3354 }
3355
3356 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3357 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3358 aView->StartRotation (anX, anY);
3359 }
3360 else if (aFlag == "-mousemove")
3361 {
3362 hasFlags = Standard_True;
3363 if (anArgIter + 2 >= theArgNb)
3364 {
3365 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3366 return 1;
3367 }
3368
3369 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3370 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3371 aView->Rotation (anX, anY);
3372 }
3373 else if (theArgNb != 4
3374 && theArgNb != 7)
3375 {
3376 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3377 return 1;
3378 }
3379 }
3380
3381 if (hasFlags)
3382 {
7fd59977 3383 return 0;
4af098ba 3384 }
3385 else if (theArgNb == 4)
3386 {
3387 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3388 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3389 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3390 aView->Rotate (anAX, anAY, anAZ);
3391 return 0;
3392 }
3393 else if (theArgNb == 7)
3394 {
3395 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3396 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3397 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3398
3399 Standard_Real anX = Draw::Atof (theArgVec[4]);
3400 Standard_Real anY = Draw::Atof (theArgVec[5]);
3401 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3402
3403 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
7fd59977 3404 return 0;
7fd59977 3405 }
4af098ba 3406
3407 std::cout << "Error: Invalid number of arguments\n";
3408 return 1;
7fd59977 3409}
3410
3411//==============================================================================
3412//function : VZoom
3413//purpose : View zoom in / out (relative to current zoom)
3414//==============================================================================
3415
3416static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3417 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3418 if ( V3dView.IsNull() ) {
3419 return 1;
3420 }
3421
3422 if ( argc == 2 ) {
91322f44 3423 Standard_Real coef = Draw::Atof(argv[1]);
7fd59977 3424 if ( coef <= 0.0 ) {
586db386 3425 di << argv[1] << "Invalid value\n";
7fd59977 3426 return 1;
3427 }
91322f44 3428 V3dView->SetZoom( Draw::Atof(argv[1]) );
7fd59977 3429 return 0;
3430 } else {
586db386 3431 di << argv[0] << " Invalid number of arguments\n";
7fd59977 3432 return 1;
3433 }
3434}
3435
3436//==============================================================================
3437//function : VPan
3438//purpose : View panning (in pixels)
3439//==============================================================================
3440
3441static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3442 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3443 if ( V3dView.IsNull() ) return 1;
3444
3445 if ( argc == 3 ) {
91322f44 3446 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
7fd59977 3447 return 0;
3448 } else {
586db386 3449 di << argv[0] << " Invalid number of arguments\n";
7fd59977 3450 return 1;
3451 }
3452}
3453
49e1a5c7 3454//==============================================================================
3455//function : VPlace
3456//purpose : Place the point (in pixels) at the center of the window
3457//==============================================================================
3458static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3459{
3460 Handle(V3d_View) aView = ViewerTest::CurrentView();
3461 if (aView.IsNull())
3462 {
3463 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3464 return 1;
3465 }
3466
3467 if (theArgNb != 3)
3468 {
3469 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3470 return 1;
3471 }
3472
3473 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3474
3475 return 0;
3476}
7fd59977 3477
3478//==============================================================================
3479//function : VExport
5cedc27f 3480//purpose : Export the view to a vector graphic format (PS, EMF, PDF)
7fd59977 3481//==============================================================================
3482
3483static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3484{
3485 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
5cedc27f
K
3486 if (V3dView.IsNull())
3487 return 1;
7fd59977 3488
5cedc27f
K
3489 if (argc == 1)
3490 {
3491 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
7fd59977 3492 return 1;
3493 }
3494
5cedc27f
K
3495 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3496 TCollection_AsciiString aFormatStr;
3497
3498 TCollection_AsciiString aFileName (argv[1]);
3499 Standard_Integer aLen = aFileName.Length();
3500
3501 if (argc > 2)
3502 {
3503 aFormatStr = TCollection_AsciiString (argv[2]);
3504 }
3505 else if (aLen >= 4)
3506 {
3507 if (aFileName.Value (aLen - 2) == '.')
3508 {
c3282ec1 3509 aFormatStr = aFileName.ToCString() + aLen - 2;
5cedc27f
K
3510 }
3511 else if (aFileName.Value (aLen - 3) == '.')
3512 {
c3282ec1 3513 aFormatStr = aFileName.ToCString() + aLen - 3;
5cedc27f
K
3514 }
3515 else
3516 {
3517 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3518 return 1;
3519 }
3520 }
3521 else
3522 {
3523 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3524 return 1;
3525 }
3526
3527 aFormatStr.UpperCase();
3528 if (aFormatStr == "PS")
3529 anExpFormat = Graphic3d_EF_PostScript;
3530 else if (aFormatStr == "EPS")
3531 anExpFormat = Graphic3d_EF_EnhPostScript;
3532 else if (aFormatStr == "TEX")
3533 anExpFormat = Graphic3d_EF_TEX;
3534 else if (aFormatStr == "PDF")
3535 anExpFormat = Graphic3d_EF_PDF;
3536 else if (aFormatStr == "SVG")
3537 anExpFormat = Graphic3d_EF_SVG;
3538 else if (aFormatStr == "PGF")
3539 anExpFormat = Graphic3d_EF_PGF;
3540 else if (aFormatStr == "EMF")
3541 anExpFormat = Graphic3d_EF_EMF;
3542 else
3543 {
3544 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3545 return 1;
3546 }
3547
404c8936 3548 Standard_DISABLE_DEPRECATION_WARNINGS
c357e426 3549 try
3550 {
3551 if (!V3dView->Export (argv[1], anExpFormat))
9753e6de 3552 {
3553 di << "Error: export of image to " << aFormatStr << " failed!\n";
3554 }
3555 }
9775fa61 3556 catch (Standard_Failure const& anException)
5cedc27f 3557 {
9753e6de 3558 di << "Error: export of image to " << aFormatStr << " failed";
9775fa61 3559 di << " (exception: " << anException.GetMessageString() << ")";
5cedc27f 3560 }
404c8936 3561 Standard_ENABLE_DEPRECATION_WARNINGS
7fd59977 3562 return 0;
3563}
3564
71215351 3565static int VColorScale (Draw_Interpretor& theDI,
3566 Standard_Integer theArgNb,
3567 const char** theArgVec)
3568{
7fd59977 3569 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
71215351 3570 Handle(V3d_View) aView = ViewerTest::CurrentView();
3571 if (aContext.IsNull())
3572 {
3573 std::cout << "Error: no active view!\n";
3574 return 1;
7fd59977 3575 }
24a88697 3576 if (theArgNb <= 1)
3577 {
3578 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3579 return 1;
3580 }
7fd59977 3581
4b3d6eb1 3582 Handle(AIS_ColorScale) aColorScale;
7a324550 3583 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
71215351 3584 {
4b3d6eb1 3585 // find existing object
3586 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3587 if (aColorScale.IsNull())
7a324550 3588 {
3589 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3590 return 1;
3591 }
3592 }
71215351 3593
7a324550 3594 if (theArgNb <= 2)
3595 {
4b3d6eb1 3596 if (aColorScale.IsNull())
3597 {
3598 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
3599 return 1;
3600 }
3601
7a324550 3602 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
4b3d6eb1 3603 << "Min range: " << aColorScale->GetMin() << "\n"
3604 << "Max range: " << aColorScale->GetMax() << "\n"
3605 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
3606 << "Text height: " << aColorScale->GetTextHeight() << "\n"
3607 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
3608 << "Color scale title: " << aColorScale->GetTitle() << "\n"
71215351 3609 << "Label position: ";
4b3d6eb1 3610 switch (aColorScale->GetLabelPosition())
71215351 3611 {
3612 case Aspect_TOCSP_NONE:
3613 theDI << "None\n";
3614 break;
3615 case Aspect_TOCSP_LEFT:
3616 theDI << "Left\n";
3617 break;
3618 case Aspect_TOCSP_RIGHT:
3619 theDI << "Right\n";
3620 break;
3621 case Aspect_TOCSP_CENTER:
3622 theDI << "Center\n";
3623 break;
3624 }
3625 return 0;
3626 }
71215351 3627
4b3d6eb1 3628 if (aColorScale.IsNull())
3629 {
3630 aColorScale = new AIS_ColorScale();
3631 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3632 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3633 }
3634
3635 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
7a324550 3636 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
71215351 3637 {
3638 Standard_CString anArg = theArgVec[anArgIter];
3639 TCollection_AsciiString aFlag (anArg);
3640 aFlag.LowerCase();
3641 if (anUpdateTool.parseRedrawMode (aFlag))
3642 {
3643 continue;
3644 }
3645 else if (aFlag == "-range")
3646 {
3647 if (anArgIter + 3 >= theArgNb)
3648 {
3649 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3650 return 1;
3651 }
3652
4b3d6eb1 3653 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
3654 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
3655 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
3656 if (!aRangeMin.IsRealValue()
3657 || !aRangeMax.IsRealValue())
71215351 3658 {
4b3d6eb1 3659 std::cout << "Error: the range values should be real!\n";
71215351 3660 return 1;
3661 }
4b3d6eb1 3662 else if (!aNbIntervals.IsIntegerValue())
71215351 3663 {
3664 std::cout << "Error: the number of intervals should be integer!\n";
3665 return 1;
3666 }
3667
4b3d6eb1 3668 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
3669 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
71215351 3670 }
3671 else if (aFlag == "-font")
3672 {
3673 if (anArgIter + 1 >= theArgNb)
3674 {
3675 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3676 return 1;
3677 }
51740958 3678 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3679 if (!aFontArg.IsIntegerValue())
71215351 3680 {
3681 std::cout << "Error: HeightFont value should be integer!\n";
3682 return 1;
3683 }
3684
4b3d6eb1 3685 aColorScale->SetTextHeight (aFontArg.IntegerValue());
71215351 3686 anArgIter += 1;
3687 }
3688 else if (aFlag == "-textpos")
3689 {
3690 if (anArgIter + 1 >= theArgNb)
3691 {
3692 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3693 return 1;
3694 }
4b3d6eb1 3695
51740958 3696 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3697 aTextPosArg.LowerCase();
4b3d6eb1 3698 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
51740958 3699 if (aTextPosArg == "none")
71215351 3700 {
3701 aLabPosition = Aspect_TOCSP_NONE;
3702 }
51740958 3703 else if (aTextPosArg == "left")
71215351 3704 {
3705 aLabPosition = Aspect_TOCSP_LEFT;
3706 }
51740958 3707 else if (aTextPosArg == "right")
71215351 3708 {
3709 aLabPosition = Aspect_TOCSP_RIGHT;
3710 }
51740958 3711 else if (aTextPosArg == "center")
71215351 3712 {
3713 aLabPosition = Aspect_TOCSP_CENTER;
3714 }
3715 else
3716 {
51740958 3717 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
71215351 3718 return 1;
3719 }
4b3d6eb1 3720 aColorScale->SetLabelPosition (aLabPosition);
71215351 3721 }
24a88697 3722 else if (aFlag == "-logarithmic"
3723 || aFlag == "-log")
3724 {
3725 if (anArgIter + 1 >= theArgNb)
3726 {
3727 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3728 return 1;
3729 }
4b3d6eb1 3730
24a88697 3731 Standard_Boolean IsLog;
3732 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3733 {
3734 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3735 return 1;
3736 }
4b3d6eb1 3737 aColorScale->SetLogarithmic (IsLog);
3738 }
3739 else if (aFlag == "-huerange"
3740 || aFlag == "-hue")
3741 {
3742 if (anArgIter + 2 >= theArgNb)
3743 {
3744 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3745 return 1;
3746 }
3747
3748 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
3749 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
3750 aColorScale->SetHueRange (aHueMin, aHueMax);
3751 }
3752 else if (aFlag == "-colorrange")
3753 {
3754 Quantity_Color aColorMin, aColorMax;
3755 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3756 theArgVec + (anArgIter + 1),
3757 aColorMin);
3758 anArgIter += aNbParsed1;
3759 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3760 theArgVec + (anArgIter + 1),
3761 aColorMax);
3762 anArgIter += aNbParsed2;
3763 if (aNbParsed1 == 0
3764 || aNbParsed2 == 0)
3765 {
3766 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3767 return 1;
3768 }
3769
3770 aColorScale->SetColorRange (aColorMin, aColorMax);
3771 }
3772 else if (aFlag == "-reversed"
3773 || aFlag == "-inverted"
3774 || aFlag == "-topdown"
3775 || aFlag == "-bottomup")
3776 {
3777 Standard_Boolean toEnable = Standard_True;
3778 if (anArgIter + 1 < theArgNb
3779 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
3780 {
3781 ++anArgIter;
3782 }
3783 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
3784 }
3785 else if (aFlag == "-smooth"
3786 || aFlag == "-smoothtransition")
3787 {
3788 Standard_Boolean toEnable = Standard_True;
3789 if (anArgIter + 1 < theArgNb
3790 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3791 {
3792 ++anArgIter;
3793 }
3794 aColorScale->SetSmoothTransition (toEnable);
24a88697 3795 }
71215351 3796 else if (aFlag == "-xy")
3797 {
3798 if (anArgIter + 2 >= theArgNb)
3799 {
3800 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3801 return 1;
3802 }
3803
4b3d6eb1 3804 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
3805 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
3806 if (!anX.IsIntegerValue()
3807 || !anY.IsIntegerValue())
71215351 3808 {
b4b2ecca 3809 std::cout << "Error: coordinates should be integer values!\n";
71215351 3810 return 1;
3811 }
3812
4b3d6eb1 3813 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
b4b2ecca 3814 }
3815 else if (aFlag == "-width"
4b3d6eb1 3816 || aFlag == "-w"
3817 || aFlag == "-breadth")
b4b2ecca 3818 {
3819 if (anArgIter + 1 >= theArgNb)
3820 {
3821 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3822 return 1;
3823 }
3824
4b3d6eb1 3825 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
3826 if (!aBreadth.IsIntegerValue())
b4b2ecca 3827 {
3828 std::cout << "Error: a width should be an integer value!\n";
3829 return 1;
3830 }
4b3d6eb1 3831 aColorScale->SetBreadth (aBreadth.IntegerValue());
b4b2ecca 3832 }
3833 else if (aFlag == "-height"
3834 || aFlag == "-h")
3835 {
3836 if (anArgIter + 1 >= theArgNb)
3837 {
3838 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3839 return 1;
3840 }
3841
4b3d6eb1 3842 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
3843 if (!aHeight.IsIntegerValue())
b4b2ecca 3844 {
3845 std::cout << "Error: a width should be an integer value!\n";
3846 return 1;
3847 }
4b3d6eb1 3848 aColorScale->SetHeight (aHeight.IntegerValue());
71215351 3849 }
3850 else if (aFlag == "-color")
3851 {
4b3d6eb1 3852 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
71215351 3853 {
3854 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3855 return 1;
3856 }
4b3d6eb1 3857 else if (anArgIter + 2 >= theArgNb)
71215351 3858 {
4b3d6eb1 3859 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3860 return 1;
71215351 3861 }
3862
4b3d6eb1 3863 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
71215351 3864 if (!anInd.IsIntegerValue())
3865 {
3866 std::cout << "Error: Index value should be integer!\n";
3867 return 1;
3868 }
4b3d6eb1 3869 const Standard_Integer anIndex = anInd.IntegerValue();
3870 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
71215351 3871 {
4b3d6eb1 3872 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
71215351 3873 return 1;
3874 }
3875
4b3d6eb1 3876 Quantity_Color aColor;
3877 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3878 theArgVec + (anArgIter + 1),
3879 aColor);
3880 if (aNbParsed == 0)
71215351 3881 {
4b3d6eb1 3882 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
71215351 3883 return 1;
3884 }
4b3d6eb1 3885 aColorScale->SetIntervalColor (aColor, anIndex);
3886 aColorScale->SetColorType (Aspect_TOCSD_USER);
3887 anArgIter += aNbParsed;
71215351 3888 }
3889 else if (aFlag == "-label")
3890 {
4b3d6eb1 3891 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
71215351 3892 {
3893 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3894 return 1;
3895 }
3896 else if (anArgIter + 2 >= theArgNb)
3897 {
3898 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3899 return 1;
3900 }
3901
3902 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4b3d6eb1 3903 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
71215351 3904 {
4b3d6eb1 3905 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
71215351 3906 return 1;
3907 }
3908
3909 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4b3d6eb1 3910 aColorScale->SetLabel (aText, anIndex);
3911 aColorScale->SetLabelType (Aspect_TOCSD_USER);
71215351 3912 anArgIter += 2;
3913 }
4b3d6eb1 3914 else if (aFlag == "-labelat"
3915 || aFlag == "-labat"
3916 || aFlag == "-labelatborder"
3917 || aFlag == "-labatborder"
3918 || aFlag == "-labelatcenter"
3919 || aFlag == "-labatcenter")
71215351 3920 {
4b3d6eb1 3921 Standard_Boolean toEnable = Standard_True;
3922 if (aFlag == "-labelat"
3923 || aFlag == "-labat")
71215351 3924 {
4b3d6eb1 3925 Standard_Integer aLabAtBorder = -1;
3926 if (++anArgIter >= theArgNb)
71215351 3927 {
4b3d6eb1 3928 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
3929 anAtBorder.LowerCase();
3930 if (anAtBorder == "border")
71215351 3931 {
4b3d6eb1 3932 aLabAtBorder = 1;
71215351 3933 }
4b3d6eb1 3934 else if (anAtBorder == "center")
71215351 3935 {
4b3d6eb1 3936 aLabAtBorder = 0;
71215351 3937 }
71215351 3938 }
4b3d6eb1 3939 if (aLabAtBorder == -1)
3940 {
3941 std::cout << "Syntax error at argument '" << anArg << "'!\n";
3942 return 1;
3943 }
3944 toEnable = (aLabAtBorder == 1);
3945 }
3946 else if (anArgIter + 1 < theArgNb
3947 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3948 {
3949 ++anArgIter;
71215351 3950 }
4b3d6eb1 3951 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
3952 || aFlag == "-labatcenter"
3953 ? !toEnable
3954 : toEnable);
3955 }
3956 else if (aFlag == "-colors")
3957 {
3958 Aspect_SequenceOfColor aSeq;
3959 for (;;)
3960 {
3961 Quantity_Color aColor;
3962 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3963 theArgVec + (anArgIter + 1),
3964 aColor);
3965 if (aNbParsed == 0)
3966 {
3967 break;
3968 }
3969 anArgIter += aNbParsed;
3970 aSeq.Append (aColor);
3971 }
3972 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
71215351 3973 {
3974 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4b3d6eb1 3975 << aColorScale->GetNumberOfIntervals() << " intervals\n";
71215351 3976 return 1;
3977 }
3978
4b3d6eb1 3979 aColorScale->SetColors (aSeq);
3980 aColorScale->SetColorType (Aspect_TOCSD_USER);
71215351 3981 }
4b3d6eb1 3982 else if (aFlag == "-labels"
3983 || aFlag == "-freelabels")
71215351 3984 {
4b3d6eb1 3985 if (anArgIter + 1 >= theArgNb)
3986 {
3987 std::cout << "Syntax error at argument '" << anArg << "'!\n";
3988 return 1;
3989 }
3990
3991 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
3992 ? aColorScale->GetNumberOfIntervals() + 1
3993 : aColorScale->GetNumberOfIntervals();
3994 if (aFlag == "-freelabels")
3995 {
3996 ++anArgIter;
3997 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
3998 }
3999 if (anArgIter + aNbLabels >= theArgNb)
71215351 4000 {
4b3d6eb1 4001 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
71215351 4002 return 1;
4003 }
4004
4005 TColStd_SequenceOfExtendedString aSeq;
4b3d6eb1 4006 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
71215351 4007 {
4b3d6eb1 4008 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
71215351 4009 }
4b3d6eb1 4010 aColorScale->SetLabels (aSeq);
4011 aColorScale->SetLabelType (Aspect_TOCSD_USER);
71215351 4012 }
4013 else if (aFlag == "-title")
4014 {
4015 if (anArgIter + 1 >= theArgNb)
4016 {
4017 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4018 return 1;
4019 }
4020
4021 Standard_Boolean isTwoArgs = Standard_False;
4022 if (anArgIter + 2 < theArgNb)
4023 {
4024 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4025 aSecondArg.LowerCase();
4b3d6eb1 4026 Standard_DISABLE_DEPRECATION_WARNINGS
71215351 4027 if (aSecondArg == "none")
4028 {
4b3d6eb1 4029 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
71215351 4030 isTwoArgs = Standard_True;
4031 }
4032 else if (aSecondArg == "left")
4033 {
4b3d6eb1 4034 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
71215351 4035 isTwoArgs = Standard_True;
4036 }
4037 else if (aSecondArg == "right")
4038 {
4b3d6eb1 4039 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
71215351 4040 isTwoArgs = Standard_True;
4041 }
4042 else if (aSecondArg == "center")
4043 {
4b3d6eb1 4044 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
71215351 4045 isTwoArgs = Standard_True;
4046 }
4b3d6eb1 4047 Standard_ENABLE_DEPRECATION_WARNINGS
71215351 4048 }
4049
4b3d6eb1 4050 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
71215351 4051 if (isTwoArgs)
4052 {
4053 anArgIter += 1;
4054 }
4055 anArgIter += 1;
4056 }
4057 else if (aFlag == "-demoversion"
4058 || aFlag == "-demo")
4059 {
4b3d6eb1 4060 aColorScale->SetPosition (0, 0);
4061 aColorScale->SetTextHeight (16);
4062 aColorScale->SetRange (0.0, 100.0);
4063 aColorScale->SetNumberOfIntervals (10);
4064 aColorScale->SetBreadth (0);
4065 aColorScale->SetHeight (0);
4066 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4067 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4068 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
71215351 4069 }
d5514578 4070 else if (aFlag == "-findcolor")
4071 {
4072 if (anArgIter + 1 >= theArgNb)
4073 {
4074 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4075 return 1;
4076 }
4077
4078 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4079
4080 if (!anArg1.IsRealValue())
4081 {
4082 std::cout << "Error: the value should be real!\n";
4083 return 1;
4084 }
4085
4086 Quantity_Color aColor;
4b3d6eb1 4087 aColorScale->FindColor (anArg1.RealValue(), aColor);
d5514578 4088 theDI << Quantity_Color::StringName (aColor.Name());
4089 return 0;
4090 }
71215351 4091 else
4092 {
4093 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4094 return 1;
4095 }
4096 }
4b3d6eb1 4097
4098 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4099 aView->Window()->Size (aWinWidth, aWinHeight);
4100 if (aColorScale->GetBreadth() == 0)
b4b2ecca 4101 {
4b3d6eb1 4102 aColorScale->SetBreadth (aWinWidth);
b4b2ecca 4103 }
4b3d6eb1 4104 if (aColorScale->GetHeight() == 0)
4105 {
4106 aColorScale->SetHeight (aWinHeight);
4107 }
4108 aColorScale->SetToUpdate();
4109 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
7fd59977 4110 return 0;
4111}
4112
4113//==============================================================================
4114//function : VGraduatedTrihedron
a79f67f8 4115//purpose : Displays or hides a graduated trihedron
7fd59977 4116//==============================================================================
a79f67f8 4117static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4118 Quantity_Color& theColor)
13a22457 4119{
a79f67f8 4120 Quantity_NameOfColor aColorName;
4121 TCollection_AsciiString aVal = theValue;
4122 aVal.UpperCase();
4123 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
13a22457 4124 {
a79f67f8 4125 return Standard_False;
13a22457 4126 }
a79f67f8 4127 theColor = Quantity_Color (aColorName);
4128 return Standard_True;
13a22457
S
4129}
4130
a79f67f8 4131static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
7fd59977 4132{
a79f67f8 4133 if (theArgNum < 2)
13a22457 4134 {
a79f67f8 4135 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4136 << theArgs[0] <<"' for more information.\n";
4137 return 1; //TCL_ERROR
13a22457 4138 }
7fd59977 4139
a79f67f8 4140 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4141 TCollection_AsciiString aParseKey;
4142 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4143 {
4144 TCollection_AsciiString anArg (theArgs [anArgIt]);
4145
4146 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4147 {
4148 aParseKey = anArg;
4149 aParseKey.Remove (1);
4150 aParseKey.LowerCase();
4151 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4152 continue;
4153 }
13a22457 4154
a79f67f8 4155 if (aParseKey.IsEmpty())
4156 {
4157 continue;
4158 }
4159
4160 aMapOfArgs(aParseKey)->Append (anArg);
4161 }
4162
4163 // Check parameters
4164 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4165 aMapIt.More(); aMapIt.Next())
7fd59977 4166 {
a79f67f8 4167 const TCollection_AsciiString& aKey = aMapIt.Key();
4168 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4169
4170 // Bool key, without arguments
4171 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4172 && anArgs->IsEmpty())
4173 {
4174 continue;
4175 }
4176
4177 // One argument
4178 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4179 && anArgs->Length() == 1)
4180 {
4181 continue;
4182 }
4183
4184 // On/off arguments
4185 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4186 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
536d98e2 4187 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4188 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
a79f67f8 4189 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4190 {
4191 continue;
4192 }
4193
4194 // One string argument
4195 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4196 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4197 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4198 {
4199 continue;
4200 }
4201
4202 // One integer argument
4203 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4204 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4205 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4206 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4207 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4208 {
4209 continue;
4210 }
4211
4212 // One real argument
4213 if ( aKey.IsEqual ("arrowlength")
4214 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4215 {
4216 continue;
4217 }
4218
4219 // Two string arguments
4220 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4221 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
13a22457 4222 {
a79f67f8 4223 continue;
13a22457 4224 }
a79f67f8 4225
4226 TCollection_AsciiString aLowerKey;
4227 aLowerKey = "-";
4228 aLowerKey += aKey;
4229 aLowerKey.LowerCase();
4230 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4231 std::cout << "Type help for more information.\n";
4232 return 1;
7fd59977 4233 }
4234
a79f67f8 4235 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4236 if (anAISContext.IsNull())
4237 {
586db386 4238 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
a79f67f8 4239 return 1;
4240 }
7fd59977 4241
a79f67f8 4242 Standard_Boolean toDisplay = Standard_True;
4243 Quantity_Color aColor;
4244 Graphic3d_GraduatedTrihedron aTrihedronData;
4245 // Process parameters
4246 Handle(TColStd_HSequenceOfAsciiString) aValues;
4247 if (aMapOfArgs.Find ("off", aValues))
7fd59977 4248 {
a79f67f8 4249 toDisplay = Standard_False;
4250 }
13a22457 4251
a79f67f8 4252 // AXES NAMES
4253 if (aMapOfArgs.Find ("xname", aValues))
4254 {
4255 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4256 }
4257 if (aMapOfArgs.Find ("yname", aValues))
4258 {
4259 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4260 }
4261 if (aMapOfArgs.Find ("zname", aValues))
4262 {
4263 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4264 }
4265 if (aMapOfArgs.Find ("xdrawname", aValues))
4266 {
536d98e2 4267 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4268 }
4269 if (aMapOfArgs.Find ("ydrawname", aValues))
4270 {
536d98e2 4271 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4272 }
4273 if (aMapOfArgs.Find ("zdrawname", aValues))
4274 {
536d98e2 4275 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4276 }
4277 if (aMapOfArgs.Find ("xnameoffset", aValues))
4278 {
4279 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4280 }
4281 if (aMapOfArgs.Find ("ynameoffset", aValues))
4282 {
4283 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4284 }
4285 if (aMapOfArgs.Find ("znameoffset", aValues))
4286 {
4287 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4288 }
13a22457 4289
a79f67f8 4290 // COLORS
4291 if (aMapOfArgs.Find ("xnamecolor", aValues))
4292 {
4293 if (!GetColor (aValues->Value(1), aColor))
13a22457 4294 {
a79f67f8 4295 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4296 return 1;
13a22457 4297 }
a79f67f8 4298 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4299 }
4300 if (aMapOfArgs.Find ("ynamecolor", aValues))
4301 {
4302 if (!GetColor (aValues->Value(1), aColor))
13a22457 4303 {
a79f67f8 4304 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4305 return 1;
4306 }
4307 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4308 }
4309 if (aMapOfArgs.Find ("znamecolor", aValues))
4310 {
4311 if (!GetColor (aValues->Value(1), aColor))
4312 {
4313 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4314 return 1;
4315 }
4316 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4317 }
4318 if (aMapOfArgs.Find ("xcolor", aValues))
4319 {
4320 if (!GetColor (aValues->Value(1), aColor))
4321 {
4322 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4323 return 1;
4324 }
4325 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4326 }
4327 if (aMapOfArgs.Find ("ycolor", aValues))
4328 {
4329 if (!GetColor (aValues->Value(1), aColor))
4330 {
4331 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4332 return 1;
4333 }
4334 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4335 }
4336 if (aMapOfArgs.Find ("zcolor", aValues))
4337 {
4338 if (!GetColor (aValues->Value(1), aColor))
4339 {
4340 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4341 return 1;
4342 }
4343 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4344 }
4345
4346 // TICKMARKS
4347 if (aMapOfArgs.Find ("xticks", aValues))
4348 {
536d98e2 4349 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4350 }
4351 if (aMapOfArgs.Find ("yticks", aValues))
4352 {
536d98e2 4353 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4354 }
4355 if (aMapOfArgs.Find ("zticks", aValues))
4356 {
536d98e2 4357 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4358 }
4359 if (aMapOfArgs.Find ("xticklength", aValues))
4360 {
536d98e2 4361 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4362 }
4363 if (aMapOfArgs.Find ("yticklength", aValues))
4364 {
536d98e2 4365 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4366 }
4367 if (aMapOfArgs.Find ("zticklength", aValues))
4368 {
536d98e2 4369 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4370 }
4371 if (aMapOfArgs.Find ("xdrawticks", aValues))
4372 {
536d98e2 4373 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4374 }
4375 if (aMapOfArgs.Find ("ydrawticks", aValues))
4376 {
536d98e2 4377 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4378 }
4379 if (aMapOfArgs.Find ("zdrawticks", aValues))
4380 {
536d98e2 4381 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4382 }
4383
4384 // VALUES
4385 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4386 {
536d98e2 4387 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4388 }
4389 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4390 {
536d98e2 4391 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4392 }
4393 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4394 {
536d98e2 4395 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4396 }
4397 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4398 {
4399 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4400 }
4401 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4402 {
4403 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4404 }
4405 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4406 {
4407 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4408 }
4409
4410 // ARROWS
4411 if (aMapOfArgs.Find ("arrowlength", aValues))
4412 {
536d98e2 4413 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
a79f67f8 4414 }
4415
4416 // FONTS
4417 if (aMapOfArgs.Find ("namefont", aValues))
4418 {
4419 aTrihedronData.SetNamesFont (aValues->Value(1));
4420 }
4421 if (aMapOfArgs.Find ("valuesfont", aValues))
4422 {
4423 aTrihedronData.SetValuesFont (aValues->Value(1));
4424 }
4425
536d98e2 4426 if (aMapOfArgs.Find ("drawgrid", aValues))
4427 {
4428 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4429 }
4430 if (aMapOfArgs.Find ("drawaxes", aValues))
4431 {
4432 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4433 }
4434
a79f67f8 4435 // The final step: display of erase trihedron
4436 if (toDisplay)
4437 {
4438 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
13a22457 4439 }
7fd59977 4440 else
a79f67f8 4441 {
4442 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4443 }
7fd59977 4444
4445 ViewerTest::GetAISContext()->UpdateCurrentViewer();
a79f67f8 4446 ViewerTest::CurrentView()->Redraw();
13a22457 4447
7fd59977 4448 return 0;
4449}
4450
3bffef55 4451//==============================================================================
4452//function : VTile
4453//purpose :
4454//==============================================================================
4455static int VTile (Draw_Interpretor& theDI,
4456 Standard_Integer theArgNb,
4457 const char** theArgVec)
4458{
4459 Handle(V3d_View) aView = ViewerTest::CurrentView();
4460 if (aView.IsNull())
4461 {
4462 std::cerr << "Error: no active viewer.\n";
4463 return 1;
4464 }
4465
4466 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4467 if (theArgNb < 2)
4468 {
4469 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4470 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4471 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4472 return 0;
4473 }
4474
4475 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4476 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4477 {
4478 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4479 anArg.LowerCase();
4480 if (anArg == "-lowerleft"
4481 || anArg == "-upperleft")
4482 {
4483 if (anArgIter + 3 < theArgNb)
4484 {
4485 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4486 return 1;
4487 }
4488 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4489 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4490 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4491 }
4492 else if (anArg == "-total"
4493 || anArg == "-totalsize"
4494 || anArg == "-viewsize")
4495 {
4496 if (anArgIter + 3 < theArgNb)
4497 {
4498 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4499 return 1;
4500 }
4501 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4502 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4503 if (aTile.TotalSize.x() < 1
4504 || aTile.TotalSize.y() < 1)
4505 {
4506 std::cerr << "Error: total size is incorrect.\n";
4507 return 1;
4508 }
4509 }
4510 else if (anArg == "-tilesize")
4511 {
4512 if (anArgIter + 3 < theArgNb)
4513 {
4514 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4515 return 1;
4516 }
4517
4518 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4519 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4520 if (aTile.TileSize.x() < 1
4521 || aTile.TileSize.y() < 1)
4522 {
4523 std::cerr << "Error: tile size is incorrect.\n";
4524 return 1;
4525 }
4526 }
4527 else if (anArg == "-unset")
4528 {
4529 aView->Camera()->SetTile (Graphic3d_CameraTile());
4530 aView->Redraw();
4531 return 0;
4532 }
4533 }
4534
4535 if (aTile.TileSize.x() < 1
4536 || aTile.TileSize.y() < 1)
4537 {
4538 std::cerr << "Error: tile size is undefined.\n";
4539 return 1;
4540 }
4541 else if (aTile.TotalSize.x() < 1
4542 || aTile.TotalSize.y() < 1)
4543 {
4544 std::cerr << "Error: total size is undefined.\n";
4545 return 1;
4546 }
4547
4548 aView->Camera()->SetTile (aTile);
4549 aView->Redraw();
4550 return 0;
4551}
4552
7c3ef2f7 4553//! Format ZLayer ID.
4554inline const char* formZLayerId (const Standard_Integer theLayerId)
4555{
4556 switch (theLayerId)
4557 {
4558 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4559 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4560 case Graphic3d_ZLayerId_Top: return "[TOP]";
4561 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4562 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4563 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4564 }
4565 return "";
4566}
4567
4568//! Print the ZLayer information.
4569inline void printZLayerInfo (Draw_Interpretor& theDI,
4570 const Graphic3d_ZLayerSettings& theLayer)
4571{
4572 if (!theLayer.Name().IsEmpty())
4573 {
4574 theDI << " Name: " << theLayer.Name() << "\n";
4575 }
4576 if (theLayer.IsImmediate())
4577 {
4578 theDI << " Immediate: TRUE\n";
4579 }
4580 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4581 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4582 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4583 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4584 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4585 {
4586 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4587 }
4588}
4589
59f45b7c 4590//==============================================================================
4591//function : VZLayer
4592//purpose : Test z layer operations for v3d viewer
4593//==============================================================================
7c3ef2f7 4594static int VZLayer (Draw_Interpretor& theDI,
4595 Standard_Integer theArgNb,
4596 const char** theArgVec)
59f45b7c 4597{
7c3ef2f7 4598 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
59f45b7c 4599 if (aContextAIS.IsNull())
4600 {
7c3ef2f7 4601 std::cout << "No active viewer!\n";
59f45b7c 4602 return 1;
4603 }
4604
4605 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
7c3ef2f7 4606 if (theArgNb < 2)
59f45b7c 4607 {
7c3ef2f7 4608 TColStd_SequenceOfInteger aLayers;
4609 aViewer->GetAllZLayers (aLayers);
4610 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4611 {
4612 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4613 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4614 printZLayerInfo (theDI, aSettings);
4615 }
59f45b7c 4616 return 1;
4617 }
4618
7c3ef2f7 4619 Standard_Integer anArgIter = 1;
4620 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4621 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4622 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
59f45b7c 4623 {
7c3ef2f7 4624 ++anArgIter;
4625 }
59f45b7c 4626
7c3ef2f7 4627 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4628 if (aFirstArg.IsIntegerValue())
4629 {
4630 ++anArgIter;
4631 aLayerId = aFirstArg.IntegerValue();
59f45b7c 4632 }
7c3ef2f7 4633 else
59f45b7c 4634 {
7c3ef2f7 4635 aFirstArg.LowerCase();
4636 if (aFirstArg == "default"
4637 || aFirstArg == "def")
59f45b7c 4638 {
7c3ef2f7 4639 aLayerId = Graphic3d_ZLayerId_Default;
4640 ++anArgIter;
59f45b7c 4641 }
7c3ef2f7 4642 else if (aFirstArg == "top")
59f45b7c 4643 {
7c3ef2f7 4644 aLayerId = Graphic3d_ZLayerId_Top;
4645 ++anArgIter;
59f45b7c 4646 }
7c3ef2f7 4647 else if (aFirstArg == "topmost")
a1954302 4648 {
7c3ef2f7 4649 aLayerId = Graphic3d_ZLayerId_Topmost;
4650 ++anArgIter;
a1954302 4651 }
7c3ef2f7 4652 else if (aFirstArg == "overlay"
4653 || aFirstArg == "toposd")
59f45b7c 4654 {
7c3ef2f7 4655 aLayerId = Graphic3d_ZLayerId_TopOSD;
4656 ++anArgIter;
59f45b7c 4657 }
7c3ef2f7 4658 else if (aFirstArg == "underlay"
4659 || aFirstArg == "botosd")
c5751993 4660 {
7c3ef2f7 4661 aLayerId = Graphic3d_ZLayerId_BotOSD;
4662 ++anArgIter;
c5751993 4663 }
7c3ef2f7 4664 else
c5751993 4665 {
7c3ef2f7 4666 TColStd_SequenceOfInteger aLayers;
4667 aViewer->GetAllZLayers (aLayers);
4668 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4669 {
4670 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4671 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False))
4672 {
4673 aLayerId = aLayeriter.Value();
4674 ++anArgIter;
4675 break;
4676 }
4677 }
c5751993 4678 }
7c3ef2f7 4679 }
c5751993 4680
7c3ef2f7 4681 for (; anArgIter < theArgNb; ++anArgIter)
4682 {
4683 // perform operation
4684 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4685 anArg.LowerCase();
4686 if (anUpdateTool.parseRedrawMode (anArg))
c5751993 4687 {
7c3ef2f7 4688 //
c5751993 4689 }
7c3ef2f7 4690 else if (anArg == "-add"
4691 || anArg == "add")
c5751993 4692 {
7c3ef2f7 4693 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4694 if (!aViewer->AddZLayer (aLayerId))
4695 {
4696 std::cout << "Error: can not add a new z layer!\n";
4697 return 0;
4698 }
4699
4700 theDI << aLayerId;
c5751993 4701 }
7c3ef2f7 4702 else if (anArg == "-del"
4703 || anArg == "-delete"
4704 || anArg == "del")
c5751993 4705 {
7c3ef2f7 4706 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4707 {
4708 if (++anArgIter >= theArgNb)
4709 {
4710 std::cout << "Syntax error: id of z layer to remove is missing\n";
4711 return 1;
4712 }
4713
4714 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4715 }
4716
4717 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4718 || aLayerId == Graphic3d_ZLayerId_Default
4719 || aLayerId == Graphic3d_ZLayerId_Top
4720 || aLayerId == Graphic3d_ZLayerId_Topmost
4721 || aLayerId == Graphic3d_ZLayerId_TopOSD
4722 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4723 {
4724 std::cout << "Syntax error: standard Z layer can not be removed\n";
4725 return 1;
4726 }
4727
4728 // move all object displayed in removing layer to default layer
4729 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4730 anObjIter.More(); anObjIter.Next())
4731 {
4732 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4733 if (aPrs.IsNull()
4734 || aPrs->ZLayer() != aLayerId)
4735 {
4736 continue;
4737 }
4738 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4739 }
4740
4741 if (!aViewer->RemoveZLayer (aLayerId))
4742 {
4743 std::cout << "Z layer can not be removed!\n";
4744 }
4745 else
4746 {
4747 theDI << aLayerId << " ";
4748 }
c5751993 4749 }
7c3ef2f7 4750 else if (anArg == "-get"
4751 || anArg == "get")
c5751993 4752 {
7c3ef2f7 4753 TColStd_SequenceOfInteger aLayers;
4754 aViewer->GetAllZLayers (aLayers);
4755 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4756 {
4757 theDI << aLayeriter.Value() << " ";
4758 }
4759
4760 theDI << "\n";
c5751993 4761 }
7c3ef2f7 4762 else if (anArg == "-name")
c5751993 4763 {
7c3ef2f7 4764 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
c5751993 4765 {
7c3ef2f7 4766 std::cout << "Syntax error: id of Z layer is missing\n";
c5751993 4767 return 1;
4768 }
4769
7c3ef2f7 4770 if (++anArgIter >= theArgNb)
4771 {
4772 std::cout << "Syntax error: name is missing\n";
4773 return 1;
4774 }
c5751993 4775
7c3ef2f7 4776 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4777 aSettings.SetName (theArgVec[anArgIter]);
4778 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 4779 }
7c3ef2f7 4780 else if (anArg == "-origin")
c5751993 4781 {
7c3ef2f7 4782 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4783 {
4784 std::cout << "Syntax error: id of Z layer is missing\n";
4785 return 1;
4786 }
4787
4788 if (anArgIter + 2 >= theArgNb)
4789 {
4790 std::cout << "Syntax error: origin coordinates are missing\n";
4791 return 1;
4792 }
4793
4794 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4795 gp_XYZ anOrigin;
4796 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4797 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4798 anOrigin.SetZ (0.0);
4799 if (anArgIter + 3 < theArgNb)
4800 {
4801 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4802 anArgIter += 3;
4803 }
4804 else
4805 {
4806 anArgIter += 2;
4807 }
4808 aSettings.SetOrigin (anOrigin);
4809 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 4810 }
7c3ef2f7 4811 else if (anArg == "-settings"
4812 || anArg == "settings")
c5751993 4813 {
7c3ef2f7 4814 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4815 {
4816 if (++anArgIter >= theArgNb)
4817 {
4818 std::cout << "Syntax error: id of Z layer is missing\n";
4819 return 1;
4820 }
4821
4822 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4823 }
4824
4825 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4826 printZLayerInfo (theDI, aSettings);
c5751993 4827 }
7c3ef2f7 4828 else if (anArg == "-enable"
4829 || anArg == "enable"
4830 || anArg == "-disable"
4831 || anArg == "disable")
83da37b1 4832 {
7c3ef2f7 4833 const Standard_Boolean toEnable = anArg == "-enable"
4834 || anArg == "enable";
4835 if (++anArgIter >= theArgNb)
4836 {
4837 std::cout << "Syntax error: option name is missing\n";
4838 return 1;
4839 }
c5751993 4840
7c3ef2f7 4841 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
4842 aSubOp.LowerCase();
4843 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4844 {
4845 if (++anArgIter >= theArgNb)
4846 {
4847 std::cout << "Syntax error: id of Z layer is missing\n";
4848 return 1;
4849 }
c5751993 4850
7c3ef2f7 4851 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4852 }
c5751993 4853
7c3ef2f7 4854 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4855 if (aSubOp == "depthtest"
4856 || aSubOp == "test")
4857 {
4858 aSettings.SetEnableDepthTest (toEnable);
4859 }
4860 else if (aSubOp == "depthwrite"
4861 || aSubOp == "write")
4862 {
4863 aSettings.SetEnableDepthWrite (toEnable);
4864 }
4865 else if (aSubOp == "depthclear"
4866 || aSubOp == "clear")
4867 {
4868 aSettings.SetClearDepth (toEnable);
4869 }
4870 else if (aSubOp == "depthoffset"
4871 || aSubOp == "offset")
4872 {
4873 Graphic3d_PolygonOffset aParams;
4874 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
4875 if (toEnable)
4876 {
4877 if (anArgIter + 2 >= theArgNb)
4878 {
4879 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
4880 return 1;
4881 }
c5751993 4882
7c3ef2f7 4883 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
4884 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
4885 }
4886 aSettings.SetPolygonOffset (aParams);
4887 }
4888 else if (aSubOp == "positiveoffset"
4889 || aSubOp == "poffset")
4890 {
4891 if (toEnable)
4892 {
4893 aSettings.SetDepthOffsetPositive();
4894 }
4895 else
4896 {
4897 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
4898 }
4899 }
4900 else if (aSubOp == "negativeoffset"
4901 || aSubOp == "noffset")
4902 {
4903 if (toEnable)
4904 {
4905 aSettings.SetDepthOffsetNegative();
4906 }
4907 else
4908 {
4909 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
4910 }
4911 }
4912 else if (aSubOp == "textureenv")
4913 {
4914 aSettings.SetEnvironmentTexture (toEnable);
4915 }
4916
4917 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 4918 }
7c3ef2f7 4919 else
83da37b1 4920 {
7c3ef2f7 4921 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
4922 return 1;
83da37b1 4923 }
59f45b7c 4924 }
4925
4926 return 0;
4927}
4928
c357e426 4929// The interactive presentation of 2d layer item
4930// for "vlayerline" command it provides a presentation of
4931// line with user-defined linewidth, linetype and transparency.
61b0191c 4932class V3d_LineItem : public AIS_InteractiveObject
20637bd2 4933{
4934public:
4935 // CASCADE RTTI
92efcf78 4936 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
4fe56619 4937
20637bd2 4938 // constructor
4939 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4940 Standard_Real X2, Standard_Real Y2,
20637bd2 4941 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4942 Standard_Real theWidth = 0.5,
4943 Standard_Real theTransp = 1.0);
4944
61b0191c 4945 private:
4946
4947 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4948 const Handle(Prs3d_Presentation)& thePresentation,
79104795 4949 const Standard_Integer theMode) Standard_OVERRIDE;
61b0191c 4950
4951 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
79104795 4952 const Standard_Integer /*aMode*/) Standard_OVERRIDE
4953 {}
20637bd2 4954
4955private:
4956
4957 Standard_Real myX1, myY1, myX2, myY2;
eafb234b 4958 Aspect_TypeOfLine myType;
20637bd2 4959 Standard_Real myWidth;
20637bd2 4960};
4961
20637bd2 4962// default constructor for line item
4fe56619 4963V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
20637bd2 4964 Standard_Real X2, Standard_Real Y2,
20637bd2 4965 Aspect_TypeOfLine theType,
4966 Standard_Real theWidth,
4967 Standard_Real theTransp) :
61b0191c 4968 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
4969 myType(theType), myWidth(theWidth)
20637bd2 4970{
61b0191c 4971 SetTransparency (1-theTransp);
20637bd2 4972}
4973
4974// render line
61b0191c 4975void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4976 const Handle(Prs3d_Presentation)& thePresentation,
4977 const Standard_Integer /*theMode*/)
20637bd2 4978{
61b0191c 4979 thePresentation->Clear();
4980 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
4981 Standard_Integer aWidth, aHeight;
4982 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
4983 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
4984 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
4985 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
4986 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
4987 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
4988 aGroup->SetPrimitivesAspect (anAspect->Aspect());
4989 aGroup->AddPrimitiveArray (aPrim);
20637bd2 4990}
4991
4992//=============================================================================
4993//function : VLayerLine
4994//purpose : Draws line in the v3d view layer with given attributes: linetype,
4995// : linewidth, transparency coefficient
4996//============================================================================
4997static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4998{
4999 // get the active view
5000 Handle(V3d_View) aView = ViewerTest::CurrentView();
5001 if (aView.IsNull())
5002 {
5003 di << "Call vinit before!\n";
5004 return 1;
5005 }
5006 else if (argc < 5)
5007 {
5008 di << "Use: " << argv[0];
5009 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5010 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5011 di << " 0 - solid \n";
5012 di << " 1 - dashed \n";
5013 di << " 2 - dot \n";
5014 di << " 3 - dashdot\n";
5015 di << " transparency : { 0.0 - 1.0 } \n";
5016 di << " 0.0 - transparent\n";
5017 di << " 1.0 - visible \n";
5018 return 1;
5019 }
5020
61b0191c 5021 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
20637bd2 5022 // get the input params
91322f44 5023 Standard_Real X1 = Draw::Atof(argv[1]);
5024 Standard_Real Y1 = Draw::Atof(argv[2]);
5025 Standard_Real X2 = Draw::Atof(argv[3]);
5026 Standard_Real Y2 = Draw::Atof(argv[4]);
20637bd2 5027
3a4a3962 5028 Standard_Real aWidth = 0.5;
5029 Standard_Real aTransparency = 1.0;
20637bd2 5030
5031 // has width
5032 if (argc > 5)
91322f44 5033 aWidth = Draw::Atof(argv[5]);
20637bd2 5034
3a4a3962 5035 // select appropriate line type
5036 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5037 if (argc > 6
5038 && !ViewerTest::ParseLineType (argv[6], aLineType))
5039 {
5040 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5041 return 1;
5042 }
20637bd2 5043
5044 // has transparency
5045 if (argc > 7)
5046 {
91322f44 5047 aTransparency = Draw::Atof(argv[7]);
4fe56619 5048 if (aTransparency < 0 || aTransparency > 1.0)
20637bd2 5049 aTransparency = 1.0;
5050 }
5051
61b0191c 5052 static Handle (V3d_LineItem) aLine;
5053 if (!aLine.IsNull())
25289ec1 5054 {
0577ae8c 5055 aContext->Erase (aLine, Standard_False);
25289ec1 5056 }
61b0191c 5057 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5058 aLineType, aWidth,
5059 aTransparency);
25289ec1 5060
778cd667 5061 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
61b0191c 5062 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5063 aLine->SetToUpdate();
5064 aContext->Display (aLine, Standard_True);
25289ec1 5065
5066 return 0;
5067}
5068
61b0191c 5069
2bd4c032 5070//==============================================================================
5071//function : VGrid
5072//purpose :
5073//==============================================================================
5074
35e08fe8 5075static int VGrid (Draw_Interpretor& /*theDI*/,
2bd4c032 5076 Standard_Integer theArgNb,
5077 const char** theArgVec)
5078{
5079 // get the active view
5080 Handle(V3d_View) aView = ViewerTest::CurrentView();
5081 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5082 if (aView.IsNull() || aViewer.IsNull())
5083 {
5084 std::cerr << "No active view. Please call vinit.\n";
5085 return 1;
5086 }
5087
5088 Aspect_GridType aType = aViewer->GridType();
5089 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
224f48fa 5090 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2bd4c032 5091 Standard_Integer anIter = 1;
5092 for (; anIter < theArgNb; ++anIter)
5093 {
5094 const char* aValue = theArgVec[anIter];
224f48fa 5095 if (anUpdateTool.parseRedrawMode (aValue))
5096 {
5097 continue;
5098 }
5099 else if (*aValue == 'r')
2bd4c032 5100 {
5101 aType = Aspect_GT_Rectangular;
5102 }
5103 else if (*aValue == 'c')
5104 {
5105 aType = Aspect_GT_Circular;
5106 }
5107 else if (*aValue == 'l')
5108 {
5109 aMode = Aspect_GDM_Lines;
5110 }
5111 else if (*aValue == 'p')
5112 {
5113 aMode = Aspect_GDM_Points;
5114 }
5115 else if (strcmp (aValue, "off" ) == 0)
5116 {
5117 aViewer->DeactivateGrid();
5118 return 0;
5119 }
5120 else
5121 {
5122 break;
5123 }
5124 }
5125
5126 Standard_Integer aTail = (theArgNb - anIter);
5127 if (aTail == 0)
5128 {
5129 aViewer->ActivateGrid (aType, aMode);
5130 return 0;
5131 }
5132 else if (aTail != 2 && aTail != 5)
5133 {
5134 std::cerr << "Incorrect arguments number! Usage:\n"
5135 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
5136 return 1;
5137 }
5138
ee2be2a8 5139 Standard_Real anOriginX, anOriginY, aRotAngle;
2bd4c032 5140 if (aType == Aspect_GT_Rectangular)
5141 {
ee2be2a8 5142 Standard_Real aRStepX, aRStepY;
2bd4c032 5143 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5144
91322f44 5145 anOriginX = Draw::Atof (theArgVec[anIter++]);
5146 anOriginY = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5147 if (aTail == 5)
5148 {
91322f44 5149 aRStepX = Draw::Atof (theArgVec[anIter++]);
5150 aRStepY = Draw::Atof (theArgVec[anIter++]);
5151 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5152 }
5153 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5154 aViewer->ActivateGrid (aType, aMode);
5155 }
5156 else if (aType == Aspect_GT_Circular)
5157 {
ee2be2a8 5158 Standard_Real aRadiusStep;
2bd4c032 5159 Standard_Integer aDivisionNumber;
5160 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5161
91322f44 5162 anOriginX = Draw::Atof (theArgVec[anIter++]);
5163 anOriginY = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5164 if (aTail == 5)
5165 {
91322f44 5166 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
5167 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
5168 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2bd4c032 5169 }
5170
5171 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5172 aViewer->ActivateGrid (aType, aMode);
5173 }
5174
5175 return 0;
5176}
5177
c40b7d58 5178//==============================================================================
5179//function : VPriviledgedPlane
5180//purpose :
5181//==============================================================================
5182
5183static int VPriviledgedPlane (Draw_Interpretor& theDI,
5184 Standard_Integer theArgNb,
5185 const char** theArgVec)
5186{
5187 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5188 {
5189 std::cerr << "Error: wrong number of arguments! See usage:\n";
5190 theDI.PrintHelp (theArgVec[0]);
5191 return 1;
5192 }
5193
5194 // get the active viewer
5195 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5196 if (aViewer.IsNull())
5197 {
5198 std::cerr << "Error: no active viewer. Please call vinit.\n";
5199 return 1;
5200 }
5201
5202 if (theArgNb == 1)
5203 {
5204 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5205 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5206 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5207 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5208 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5209 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5210 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5211 return 0;
5212 }
5213
5214 Standard_Integer anArgIdx = 1;
5215 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5216 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5217 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5218 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5219 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5220 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5221
5222 gp_Ax3 aPriviledgedPlane;
5223 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5224 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5225 if (theArgNb > 7)
5226 {
5227 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5228 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5229 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5230 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5231 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5232 }
5233 else
5234 {
5235 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5236 }
5237
5238 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5239
5240 return 0;
5241}
5242
f25b82d6 5243//==============================================================================
5244//function : VConvert
5245//purpose :
5246//==============================================================================
5247
5248static int VConvert (Draw_Interpretor& theDI,
5249 Standard_Integer theArgNb,
5250 const char** theArgVec)
5251{
5252 // get the active view
5253 Handle(V3d_View) aView = ViewerTest::CurrentView();
5254 if (aView.IsNull())
5255 {
c40b7d58 5256 std::cerr << "Error: no active view. Please call vinit.\n";
f25b82d6 5257 return 1;
5258 }
5259
5260 enum { Model, Ray, View, Window, Grid } aMode = Model;
5261
5262 // access coordinate arguments
5263 TColStd_SequenceOfReal aCoord;
5264 Standard_Integer anArgIdx = 1;
5265 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5266 {
5267 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5268 if (!anArg.IsRealValue())
5269 {
5270 break;
5271 }
5272 aCoord.Append (anArg.RealValue());
5273 }
5274
5275 // non-numeric argument too early
5276 if (aCoord.IsEmpty())
5277 {
5278 std::cerr << "Error: wrong number of arguments! See usage:\n";
5279 theDI.PrintHelp (theArgVec[0]);
5280 return 1;
5281 }
5282
5283 // collect all other arguments and options
5284 for (; anArgIdx < theArgNb; ++anArgIdx)
5285 {
5286 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5287 anArg.LowerCase();
5288 if (anArg == "window") aMode = Window;
5289 else if (anArg == "view") aMode = View;
5290 else if (anArg == "grid") aMode = Grid;
5291 else if (anArg == "ray") aMode = Ray;
5292 else
5293 {
5294 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5295 theDI.PrintHelp (theArgVec[0]);
5296 return 1;
5297 }
5298 }
5299
5300 // complete input checks
5301 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5302 (aCoord.Length() == 2 && theArgNb > 4) ||
5303 (aCoord.Length() == 3 && theArgNb > 5))
5304 {
5305 std::cerr << "Error: wrong number of arguments! See usage:\n";
5306 theDI.PrintHelp (theArgVec[0]);
5307 return 1;
5308 }
5309
5310 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5311 Standard_Integer aXYp[2] = {0, 0};
5312
5313 // convert one-dimensional coordinate
5314 if (aCoord.Length() == 1)
5315 {
5316 switch (aMode)
5317 {
ee2be2a8 5318 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
5319 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
f25b82d6 5320 default:
5321 std::cerr << "Error: wrong arguments! See usage:\n";
5322 theDI.PrintHelp (theArgVec[0]);
5323 return 1;
5324 }
5325 }
5326
5327 // convert 2D coordinates from projection or view reference space
5328 if (aCoord.Length() == 2)
5329 {
5330 switch (aMode)
5331 {
5332 case Model :
5333 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5334 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5335 return 0;
5336
5337 case View :
5338 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5339 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5340 return 0;
5341
5342 case Window :
ee2be2a8 5343 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
f25b82d6 5344 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5345 return 0;
5346
5347 case Grid :
5348 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5349 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5350 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5351 return 0;
5352
5353 case Ray :
5354 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5355 (Standard_Integer) aCoord (2),
5356 aXYZ[0], aXYZ[1], aXYZ[2],
5357 aXYZ[3], aXYZ[4], aXYZ[5]);
5358 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5359 return 0;
5360
5361 default:
5362 std::cerr << "Error: wrong arguments! See usage:\n";
5363 theDI.PrintHelp (theArgVec[0]);
5364 return 1;
5365 }
5366 }
5367
5368 // convert 3D coordinates from view reference space
5369 else if (aCoord.Length() == 3)
5370 {
5371 switch (aMode)
5372 {
5373 case Window :
5374 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5375 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5376 return 0;
5377
5378 case Grid :
5379 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5380 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5381 return 0;
5382
5383 default:
5384 std::cerr << "Error: wrong arguments! See usage:\n";
5385 theDI.PrintHelp (theArgVec[0]);
5386 return 1;
5387 }
5388 }
5389
5390 return 0;
5391}
5392
208e6839 5393//==============================================================================
5394//function : VFps
5395//purpose :
5396//==============================================================================
5397
5398static int VFps (Draw_Interpretor& theDI,
5399 Standard_Integer theArgNb,
5400 const char** theArgVec)
5401{
5402 // get the active view
5403 Handle(V3d_View) aView = ViewerTest::CurrentView();
5404 if (aView.IsNull())
5405 {
5406 std::cerr << "No active view. Please call vinit.\n";
5407 return 1;
5408 }
5409
91322f44 5410 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
208e6839 5411 if (aFramesNb <= 0)
5412 {
5413 std::cerr << "Incorrect arguments!\n";
5414 return 1;
5415 }
5416
5417 // the time is meaningless for first call
5418 // due to async OpenGl rendering
5419 aView->Redraw();
5420
5421 // redraw view in loop to estimate average values
5422 OSD_Timer aTimer;
5423 aTimer.Start();
5424 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5425 {
5426 aView->Redraw();
5427 }
5428 aTimer.Stop();
5429 Standard_Real aCpu;
5430 const Standard_Real aTime = aTimer.ElapsedTime();
5431 aTimer.OSD_Chronometer::Show (aCpu);
5432
5433 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5434 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5435
5436 // return statistics
5437 theDI << "FPS: " << aFpsAver << "\n"
5438 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5439
8c820969 5440 // compute additional statistics in ray-tracing mode
5441 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5442
5443 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5444 {
5445 Standard_Integer aSizeX;
5446 Standard_Integer aSizeY;
5447
5448 aView->Window()->Size (aSizeX, aSizeY);
5449
5450 // 1 shadow ray and 1 secondary ray pew each bounce
5451 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5452
5453 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5454 }
5455
208e6839 5456 return 0;
5457}
5458
58655684 5459//==============================================================================
5460//function : VGlDebug
5461//purpose :
5462//==============================================================================
5463
5464static int VGlDebug (Draw_Interpretor& theDI,
5465 Standard_Integer theArgNb,
5466 const char** theArgVec)
5467{
aaf512f1 5468 Handle(OpenGl_GraphicDriver) aDriver;
5469 Handle(V3d_View) aView = ViewerTest::CurrentView();
5470 if (!aView.IsNull())
5471 {
5472 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5473 }
c87535af 5474 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5475 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5476
58655684 5477 if (theArgNb < 2)
5478 {
c87535af 5479 TCollection_AsciiString aDebActive, aSyncActive;
5480 if (aCaps == NULL)
58655684 5481 {
c87535af 5482 aCaps = aDefCaps;
5483 }
5484 else
5485 {
5486 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5487 "GL_ARB_debug_output");
5488 aDebActive = isActive ? " (active)" : " (inactive)";
5489 if (isActive)
5490 {
5491 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5492 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5493 }
58655684 5494 }
5495
c87535af 5496 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5497 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5498 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5499 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
58655684 5500 return 0;
5501 }
5502
c87535af 5503 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
aaf512f1 5504 {
c87535af 5505 Standard_CString anArg = theArgVec[anArgIter];
5506 TCollection_AsciiString anArgCase (anArg);
5507 anArgCase.LowerCase();
5508 Standard_Boolean toEnableDebug = Standard_True;
5509 if (anArgCase == "-glsl"
5510 || anArgCase == "-glslwarn"
5511 || anArgCase == "-glslwarns"
5512 || anArgCase == "-glslwarnings")
5513 {
5514 Standard_Boolean toShowWarns = Standard_True;
5515 if (++anArgIter < theArgNb
a5565a3c 5516 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
c87535af 5517 {
5518 --anArgIter;
5519 }
5520 aDefCaps->glslWarnings = toShowWarns;
5521 if (aCaps != NULL)
5522 {
5523 aCaps->glslWarnings = toShowWarns;
5524 }
5525 }
5526 else if (anArgCase == "-extra"
5527 || anArgCase == "-extramsg"
5528 || anArgCase == "-extramessages")
5529 {
5530 Standard_Boolean toShow = Standard_True;
5531 if (++anArgIter < theArgNb
a5565a3c 5532 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
c87535af 5533 {
5534 --anArgIter;
5535 }
5536 aDefCaps->suppressExtraMsg = !toShow;
5537 if (aCaps != NULL)
5538 {
5539 aCaps->suppressExtraMsg = !toShow;
5540 }
5541 }
5542 else if (anArgCase == "-noextra"
5543 || anArgCase == "-noextramsg"
5544 || anArgCase == "-noextramessages")
5545 {
5546 Standard_Boolean toSuppress = Standard_True;
5547 if (++anArgIter < theArgNb
a5565a3c 5548 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
c87535af 5549 {
5550 --anArgIter;
5551 }
5552 aDefCaps->suppressExtraMsg = toSuppress;
5553 if (aCaps != NULL)
5554 {
5555 aCaps->suppressExtraMsg = toSuppress;
5556 }
5557 }
5558 else if (anArgCase == "-sync")
5559 {
5560 Standard_Boolean toSync = Standard_True;
5561 if (++anArgIter < theArgNb
a5565a3c 5562 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
c87535af 5563 {
5564 --anArgIter;
5565 }
5566 aDefCaps->contextSyncDebug = toSync;
5567 if (toSync)
5568 {
5569 aDefCaps->contextDebug = Standard_True;
5570 }
5571 }
5572 else if (anArgCase == "-debug")
5573 {
5574 if (++anArgIter < theArgNb
a5565a3c 5575 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
c87535af 5576 {
5577 --anArgIter;
5578 }
5579 aDefCaps->contextDebug = toEnableDebug;
5580 }
a5565a3c 5581 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
c87535af 5582 && (anArgIter + 1 == theArgNb))
5583 {
5584 // simple alias to turn on almost everything
5585 aDefCaps->contextDebug = toEnableDebug;
5586 aDefCaps->contextSyncDebug = toEnableDebug;
5587 aDefCaps->glslWarnings = toEnableDebug;
5588 }
5589 else
5590 {
5591 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5592 return 1;
5593 }
aaf512f1 5594 }
5595
58655684 5596 return 0;
5597}
208e6839 5598
5599//==============================================================================
5600//function : VVbo
5601//purpose :
5602//==============================================================================
5603
58655684 5604static int VVbo (Draw_Interpretor& theDI,
208e6839 5605 Standard_Integer theArgNb,
5606 const char** theArgVec)
5607{
58655684 5608 const Standard_Boolean toSet = (theArgNb > 1);
5609 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5610 if (toSet)
208e6839 5611 {
58655684 5612 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
208e6839 5613 }
5614
58655684 5615 // get the context
5616 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5617 if (aContextAIS.IsNull())
208e6839 5618 {
58655684 5619 if (!toSet)
5620 {
5621 std::cerr << "No active view!\n";
5622 }
208e6839 5623 return 1;
5624 }
58655684 5625 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5626 if (!aDriver.IsNull())
208e6839 5627 {
58655684 5628 if (!toSet)
5629 {
5630 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5631 }
5632 else
5633 {
5634 aDriver->ChangeOptions().vboDisable = toUseVbo;
5635 }
208e6839 5636 }
5637
208e6839 5638 return 0;
5639}
5640
a577aaab 5641//==============================================================================
5642//function : VCaps
5643//purpose :
5644//==============================================================================
5645
5646static int VCaps (Draw_Interpretor& theDI,
5647 Standard_Integer theArgNb,
5648 const char** theArgVec)
5649{
5650 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5651 Handle(OpenGl_GraphicDriver) aDriver;
8625ef7e 5652 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5653 if (!aContext.IsNull())
a577aaab 5654 {
8625ef7e 5655 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
a577aaab 5656 aCaps = &aDriver->ChangeOptions();
5657 }
5658
5659 if (theArgNb < 2)
5660 {
5661 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5662 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
abe46077 5663 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
8625ef7e 5664 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
f978241f 5665 theDI << "VSync: " << aCaps->swapInterval << "\n";
4e1523ef 5666 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
f978241f 5667 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
56689b27 5668 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
a577aaab 5669 return 0;
5670 }
5671
8625ef7e 5672 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
a577aaab 5673 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5674 {
8625ef7e 5675 Standard_CString anArg = theArgVec[anArgIter];
5676 TCollection_AsciiString anArgCase (anArg);
5677 anArgCase.LowerCase();
5678 if (anUpdateTool.parseRedrawMode (anArg))
5679 {
5680 continue;
5681 }
f978241f 5682 else if (anArgCase == "-vsync"
5683 || anArgCase == "-swapinterval")
5684 {
5685 Standard_Boolean toEnable = Standard_True;
5686 if (++anArgIter < theArgNb
a5565a3c 5687 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 5688 {
5689 --anArgIter;
5690 }
5691 aCaps->swapInterval = toEnable;
5692 }
8625ef7e 5693 else if (anArgCase == "-ffp")
5694 {
5695 Standard_Boolean toEnable = Standard_True;
5696 if (++anArgIter < theArgNb
a5565a3c 5697 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5698 {
5699 --anArgIter;
5700 }
5701 aCaps->ffpEnable = toEnable;
5702 }
5703 else if (anArgCase == "-vbo")
a577aaab 5704 {
8625ef7e 5705 Standard_Boolean toEnable = Standard_True;
5706 if (++anArgIter < theArgNb
a5565a3c 5707 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5708 {
5709 --anArgIter;
5710 }
5711 aCaps->vboDisable = !toEnable;
a577aaab 5712 }
8625ef7e 5713 else if (anArgCase == "-sprite"
5714 || anArgCase == "-sprites")
a577aaab 5715 {
8625ef7e 5716 Standard_Boolean toEnable = Standard_True;
5717 if (++anArgIter < theArgNb
a5565a3c 5718 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5719 {
5720 --anArgIter;
5721 }
5722 aCaps->pntSpritesDisable = !toEnable;
a577aaab 5723 }
8625ef7e 5724 else if (anArgCase == "-softmode")
abe46077 5725 {
8625ef7e 5726 Standard_Boolean toEnable = Standard_True;
5727 if (++anArgIter < theArgNb
a5565a3c 5728 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5729 {
5730 --anArgIter;
5731 }
5732 aCaps->contextNoAccel = toEnable;
5733 }
56689b27 5734 else if (anArgCase == "-winbuffer"
5735 || anArgCase == "-windowbuffer"
5736 || anArgCase == "-usewinbuffer"
5737 || anArgCase == "-usewindowbuffer"
5738 || anArgCase == "-usesystembuffer")
5739 {
5740 Standard_Boolean toEnable = Standard_True;
5741 if (++anArgIter < theArgNb
5742 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5743 {
5744 --anArgIter;
5745 }
5746 aCaps->useSystemBuffer = toEnable;
5747 }
8625ef7e 5748 else if (anArgCase == "-accel"
5749 || anArgCase == "-acceleration")
5750 {
5751 Standard_Boolean toEnable = Standard_True;
5752 if (++anArgIter < theArgNb
a5565a3c 5753 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 5754 {
5755 --anArgIter;
5756 }
5757 aCaps->contextNoAccel = !toEnable;
abe46077 5758 }
4e1523ef 5759 else if (anArgCase == "-compat"
5760 || anArgCase == "-compatprofile"
5761 || anArgCase == "-compatible"
5762 || anArgCase == "-compatibleprofile")
5763 {
5764 Standard_Boolean toEnable = Standard_True;
5765 if (++anArgIter < theArgNb
a5565a3c 5766 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
4e1523ef 5767 {
5768 --anArgIter;
5769 }
5770 aCaps->contextCompatible = toEnable;
5771 if (!aCaps->contextCompatible)
5772 {
5773 aCaps->ffpEnable = Standard_False;
5774 }
5775 }
5776 else if (anArgCase == "-core"
5777 || anArgCase == "-coreprofile")
5778 {
5779 Standard_Boolean toEnable = Standard_True;
5780 if (++anArgIter < theArgNb
a5565a3c 5781 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
4e1523ef 5782 {
5783 --anArgIter;
5784 }
5785 aCaps->contextCompatible = !toEnable;
5786 if (!aCaps->contextCompatible)
5787 {
5788 aCaps->ffpEnable = Standard_False;
5789 }
5790 }
f978241f 5791 else if (anArgCase == "-stereo"
5792 || anArgCase == "-quadbuffer")
5793 {
5794 Standard_Boolean toEnable = Standard_True;
5795 if (++anArgIter < theArgNb
a5565a3c 5796 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 5797 {
5798 --anArgIter;
5799 }
5800 aCaps->contextStereo = toEnable;
5801 }
a577aaab 5802 else
5803 {
8625ef7e 5804 std::cout << "Error: unknown argument '" << anArg << "'\n";
5805 return 1;
a577aaab 5806 }
5807 }
5808 if (aCaps != &ViewerTest_myDefaultCaps)
5809 {
5810 ViewerTest_myDefaultCaps = *aCaps;
5811 }
5812 return 0;
5813}
5814
f0430952 5815//==============================================================================
5816//function : VMemGpu
5817//purpose :
5818//==============================================================================
5819
5820static int VMemGpu (Draw_Interpretor& theDI,
5821 Standard_Integer theArgNb,
5822 const char** theArgVec)
5823{
5824 // get the context
5825 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5826 if (aContextAIS.IsNull())
5827 {
5828 std::cerr << "No active view. Please call vinit.\n";
5829 return 1;
5830 }
5831
dc3fe572 5832 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
f0430952 5833 if (aDriver.IsNull())
5834 {
5835 std::cerr << "Graphic driver not available.\n";
5836 return 1;
5837 }
5838
5839 Standard_Size aFreeBytes = 0;
5840 TCollection_AsciiString anInfo;
5841 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5842 {
5843 std::cerr << "Information not available.\n";
5844 return 1;
5845 }
5846
5847 if (theArgNb > 1 && *theArgVec[1] == 'f')
5848 {
5849 theDI << Standard_Real (aFreeBytes);
5850 }
5851 else
5852 {
5853 theDI << anInfo;
5854 }
5855
5856 return 0;
5857}
5858
85e096c3 5859// ==============================================================================
5860// function : VReadPixel
5861// purpose :
5862// ==============================================================================
5863static int VReadPixel (Draw_Interpretor& theDI,
5864 Standard_Integer theArgNb,
5865 const char** theArgVec)
5866{
5867 // get the active view
5868 Handle(V3d_View) aView = ViewerTest::CurrentView();
5869 if (aView.IsNull())
5870 {
5871 std::cerr << "No active view. Please call vinit.\n";
5872 return 1;
5873 }
5874 else if (theArgNb < 3)
5875 {
5876 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5877 return 1;
5878 }
5879
dc858f4c 5880 Image_Format aFormat = Image_Format_RGBA;
5881 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
692613e5 5882
85e096c3 5883 Standard_Integer aWidth, aHeight;
5884 aView->Window()->Size (aWidth, aHeight);
91322f44 5885 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5886 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
85e096c3 5887 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5888 {
5889 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5890 return 1;
5891 }
5892
5893 Standard_Boolean toShowName = Standard_False;
5894 Standard_Boolean toShowHls = Standard_False;
5895 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5896 {
dc858f4c 5897 TCollection_AsciiString aParam (theArgVec[anIter]);
5898 aParam.LowerCase();
5899 if (aParam == "rgb")
85e096c3 5900 {
dc858f4c 5901 aFormat = Image_Format_RGB;
692613e5 5902 aBufferType = Graphic3d_BT_RGB;
85e096c3 5903 }
dc858f4c 5904 else if (aParam == "hls")
85e096c3 5905 {
dc858f4c 5906 aFormat = Image_Format_RGB;
692613e5 5907 aBufferType = Graphic3d_BT_RGB;
85e096c3 5908 toShowHls = Standard_True;
5909 }
dc858f4c 5910 else if (aParam == "rgbf")
85e096c3 5911 {
dc858f4c 5912 aFormat = Image_Format_RGBF;
692613e5 5913 aBufferType = Graphic3d_BT_RGB;
85e096c3 5914 }
dc858f4c 5915 else if (aParam == "rgba")
85e096c3 5916 {
dc858f4c 5917 aFormat = Image_Format_RGBA;
692613e5 5918 aBufferType = Graphic3d_BT_RGBA;
85e096c3 5919 }
dc858f4c 5920 else if (aParam == "rgbaf")
85e096c3 5921 {
dc858f4c 5922 aFormat = Image_Format_RGBAF;
692613e5 5923 aBufferType = Graphic3d_BT_RGBA;
85e096c3 5924 }
dc858f4c 5925 else if (aParam == "depth")
85e096c3 5926 {
dc858f4c 5927 aFormat = Image_Format_GrayF;
692613e5 5928 aBufferType = Graphic3d_BT_Depth;
85e096c3 5929 }
dc858f4c 5930 else if (aParam == "name")
85e096c3 5931 {
5932 toShowName = Standard_True;
5933 }
5934 }
5935
692613e5 5936 Image_PixMap anImage;
5937 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5938 {
5939 std::cerr << "Image allocation failed\n";
5940 return 1;
5941 }
5942 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
85e096c3 5943 {
5944 std::cerr << "Image dump failed\n";
5945 return 1;
5946 }
5947
e958a649 5948 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
85e096c3 5949 if (toShowName)
5950 {
692613e5 5951 if (aBufferType == Graphic3d_BT_RGBA)
85e096c3 5952 {
e958a649 5953 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
85e096c3 5954 }
5955 else
5956 {
e958a649 5957 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
85e096c3 5958 }
5959 }
5960 else
5961 {
5962 switch (aBufferType)
5963 {
5964 default:
692613e5 5965 case Graphic3d_BT_RGB:
85e096c3 5966 {
5967 if (toShowHls)
5968 {
e958a649 5969 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
85e096c3 5970 }
5971 else
5972 {
e958a649 5973 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
85e096c3 5974 }
5975 break;
5976 }
692613e5 5977 case Graphic3d_BT_RGBA:
85e096c3 5978 {
e958a649 5979 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
85e096c3 5980 break;
5981 }
692613e5 5982 case Graphic3d_BT_Depth:
85e096c3 5983 {
e958a649 5984 theDI << aColor.GetRGB().Red();
85e096c3 5985 break;
5986 }
5987 }
5988 }
5989
5990 return 0;
5991}
5992
692613e5 5993//==============================================================================
5994//function : VDiffImage
5995//purpose : The draw-command compares two images.
5996//==============================================================================
5997
5998static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5999{
6000 if (theArgNb < 6)
6001 {
6002 theDI << "Not enough arguments.\n";
6003 return 1;
6004 }
6005
6006 // image file names
6007 const char* anImgPathRef = theArgVec[1];
6008 const char* anImgPathNew = theArgVec[2];
6009
6010 // get string tolerance and check its validity
91322f44 6011 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
692613e5 6012 if (aTolColor < 0.0)
6013 aTolColor = 0.0;
6014 if (aTolColor > 1.0)
6015 aTolColor = 1.0;
6016
91322f44 6017 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
6018 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
692613e5 6019
6020 // image file of difference
6021 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
6022
6023 // compare the images
6024 Image_Diff aComparer;
6025 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
6026 {
6027 return 1;
6028 }
6029
6030 aComparer.SetColorTolerance (aTolColor);
6031 aComparer.SetBorderFilterOn (isBorderFilterOn);
6032 Standard_Integer aDiffColorsNb = aComparer.Compare();
6033 theDI << aDiffColorsNb << "\n";
6034
6035 // save image of difference
936f43da 6036 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
692613e5 6037 {
6038 aComparer.SaveDiffImage (aDiffImagePath);
6039 }
6040
6041 return 0;
6042}
6043
4754e164 6044//=======================================================================
6045//function : VSelect
6046//purpose : Emulates different types of selection by mouse:
6047// 1) single click selection
6048// 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
6049// 3) selection with polygon having corners at
dc3fe572 6050// pixel positions (x1,y1),...,(xn,yn)
4754e164 6051// 4) any of these selections with shift button pressed
6052//=======================================================================
6053static Standard_Integer VSelect (Draw_Interpretor& di,
6054 Standard_Integer argc,
6055 const char ** argv)
6056{
dc3fe572 6057 if(argc < 3)
4754e164 6058 {
586db386 6059 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
4754e164 6060 return 1;
6061 }
6062
6063 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
dc3fe572 6064 if(myAIScontext.IsNull())
4754e164 6065 {
6066 di << "use 'vinit' command before " << argv[0] << "\n";
6067 return 1;
6068 }
2157d6ac 6069
6070 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
6071 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
6072 TCollection_AsciiString anArg;
6073 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
6074 anArg.LowerCase();
6075 if (anArg == "-allowoverlap")
6076 {
6077 Standard_Boolean isValidated = isShiftSelection ? argc == 8
6078 : argc == 7;
6079 if (!isValidated)
6080 {
6081 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
6082 return 1;
6083 }
6084
6085 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
dde68833 6086 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
2157d6ac 6087 aCoordsNb -= 2;
6088 }
6089
4754e164 6090 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
6091 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
2157d6ac 6092 if(aCoordsNb == 2)
4754e164 6093 {
6094 if(isShiftSelection)
6095 aCurrentEventManager->ShiftSelect();
6096 else
6097 aCurrentEventManager->Select();
6098 }
2157d6ac 6099 else if(aCoordsNb == 4)
4754e164 6100 {
6101 if(isShiftSelection)
2157d6ac 6102 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
4754e164 6103 else
2157d6ac 6104 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
4754e164 6105 }
6106 else
6107 {
2157d6ac 6108 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
4754e164 6109
2157d6ac 6110 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
4754e164 6111 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
6112
6113 if(isShiftSelection)
6114 aCurrentEventManager->ShiftSelect(aPolyline);
6115 else
6116 aCurrentEventManager->Select(aPolyline);
6117 }
6118 return 0;
6119}
6120
6121//=======================================================================
6122//function : VMoveTo
dc3fe572 6123//purpose : Emulates cursor movement to defined pixel position
4754e164 6124//=======================================================================
6125static Standard_Integer VMoveTo (Draw_Interpretor& di,
6126 Standard_Integer argc,
6127 const char ** argv)
6128{
dc3fe572 6129 if(argc != 3)
4754e164 6130 {
586db386 6131 di << "Usage : " << argv[0] << " x y\n";
4754e164 6132 return 1;
6133 }
6134
6135 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
dc3fe572 6136 if(aContext.IsNull())
4754e164 6137 {
6138 di << "use 'vinit' command before " << argv[0] << "\n";
6139 return 1;
6140 }
6141 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
6142 return 0;
6143}
6144
1beb58d7 6145namespace
6146{
6147 //! Global map storing all animations registered in ViewerTest.
6148 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
6149
6150 //! The animation calling the Draw Harness command.
6151 class ViewerTest_AnimationProc : public AIS_Animation
6152 {
6153 public:
6154
6155 //! Main constructor.
6156 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6157 Draw_Interpretor* theDI,
6158 const TCollection_AsciiString& theCommand)
6159 : AIS_Animation (theAnimationName),
6160 myDrawInter(theDI),
6161 myCommand (theCommand)
6162 {
6163 //
6164 }
6165
6166 protected:
6167
6168 //! Evaluate the command.
6169 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6170 {
6171 TCollection_AsciiString aCmd = myCommand;
6172 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6173 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6174 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6175 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6176 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6177 myDrawInter->Eval (aCmd.ToCString());
6178 }
6179
6180 //! Find the keyword in the command and replace it with value.
6181 //! @return the position of the keyword to pass value
6182 void replace (TCollection_AsciiString& theCmd,
6183 const TCollection_AsciiString& theKey,
6184 const TCollection_AsciiString& theVal)
6185 {
6186 TCollection_AsciiString aCmd (theCmd);
6187 aCmd.LowerCase();
6188 const Standard_Integer aPos = aCmd.Search (theKey);
6189 if (aPos == -1)
6190 {
6191 return;
6192 }
6193
6194 TCollection_AsciiString aPart1, aPart2;
6195 Standard_Integer aPart1To = aPos - 1;
6196 if (aPart1To >= 1
6197 && aPart1To <= theCmd.Length())
6198 {
6199 aPart1 = theCmd.SubString (1, aPart1To);
6200 }
6201
6202 Standard_Integer aPart2From = aPos + theKey.Length();
6203 if (aPart2From >= 1
6204 && aPart2From <= theCmd.Length())
6205 {
6206 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
6207 }
6208
6209 theCmd = aPart1 + theVal + aPart2;
6210 }
6211
6212 protected:
6213
6214 Draw_Interpretor* myDrawInter;
6215 TCollection_AsciiString myCommand;
6216
6217 };
6218
6219 //! Replace the animation with the new one.
6220 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
6221 Handle(AIS_Animation)& theAnimation,
6222 const Handle(AIS_Animation)& theAnimationNew)
6223 {
6224 theAnimationNew->CopyFrom (theAnimation);
6225 if (!theParentAnimation.IsNull())
6226 {
6227 theParentAnimation->Replace (theAnimation, theAnimationNew);
6228 }
6229 else
6230 {
6231 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
6232 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
6233 }
6234 theAnimation = theAnimationNew;
6235 }
6236
6237 //! Parse the point.
6238 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
6239 {
6240 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
6241 if (!anXYZ[0].IsRealValue()
6242 || !anXYZ[1].IsRealValue()
6243 || !anXYZ[2].IsRealValue())
6244 {
6245 return Standard_False;
6246 }
6247
6248 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
6249 return Standard_True;
6250 }
6251
6252 //! Parse the quaternion.
6253 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
6254 {
6255 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
6256 if (!anXYZW[0].IsRealValue()
6257 || !anXYZW[1].IsRealValue()
6258 || !anXYZW[2].IsRealValue()
6259 || !anXYZW[3].IsRealValue())
6260 {
6261 return Standard_False;
6262 }
6263
6264 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
6265 return Standard_True;
6266 }
6267
08f8a185 6268 //! Auxiliary class for flipping image upside-down.
6269 class ImageFlipper
6270 {
6271 public:
6272
6273 //! Empty constructor.
6274 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
6275
6276 //! Perform flipping.
6277 Standard_Boolean FlipY (Image_PixMap& theImage)
6278 {
6279 if (theImage.IsEmpty()
6280 || theImage.SizeX() == 0
6281 || theImage.SizeY() == 0)
6282 {
6283 return Standard_False;
6284 }
6285
6286 const Standard_Size aRowSize = theImage.SizeRowBytes();
6287 if (myTmp.Size() < aRowSize
6288 && !myTmp.Allocate (aRowSize))
6289 {
6290 return Standard_False;
6291 }
6292
6293 // for odd height middle row should be left as is
6294 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
6295 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
6296 {
6297 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
6298 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
6299 memcpy (myTmp.ChangeData(), aTop, aRowSize);
6300 memcpy (aTop, aBot, aRowSize);
6301 memcpy (aBot, myTmp.Data(), aRowSize);
6302 }
6303 return Standard_True;
6304 }
6305
6306 private:
6307 NCollection_Buffer myTmp;
6308 };
6309
1beb58d7 6310}
6311
197ac94e 6312//=================================================================================================
4754e164 6313//function : VViewParams
dc3fe572 6314//purpose : Gets or sets AIS View characteristics
197ac94e 6315//=================================================================================================
6316static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4754e164 6317{
1beb58d7 6318 Handle(V3d_View) aView = ViewerTest::CurrentView();
6319 if (aView.IsNull())
4754e164 6320 {
197ac94e 6321 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
4754e164 6322 return 1;
6323 }
197ac94e 6324
1beb58d7 6325 Standard_Boolean toSetProj = Standard_False;
6326 Standard_Boolean toSetUp = Standard_False;
6327 Standard_Boolean toSetAt = Standard_False;
6328 Standard_Boolean toSetEye = Standard_False;
6329 Standard_Boolean toSetScale = Standard_False;
6330 Standard_Boolean toSetSize = Standard_False;
6331 Standard_Boolean toSetCenter2d = Standard_False;
ee2be2a8 6332 Standard_Real aViewScale = aView->Scale();
6333 Standard_Real aViewSize = 1.0;
1beb58d7 6334 Graphic3d_Vec2i aCenter2d;
6335 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
6336 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
6337 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
6338 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
6339 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
197ac94e 6340 if (theArgsNb == 1)
4754e164 6341 {
197ac94e 6342 // print all of the available view parameters
1beb58d7 6343 char aText[4096];
6344 Sprintf (aText,
6345 "Scale: %g\n"
6346 "Proj: %12g %12g %12g\n"
6347 "Up: %12g %12g %12g\n"
6348 "At: %12g %12g %12g\n"
6349 "Eye: %12g %12g %12g\n",
6350 aViewScale,
6351 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6352 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6353 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
6354 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6355 theDi << aText;
197ac94e 6356 return 0;
4754e164 6357 }
197ac94e 6358
1beb58d7 6359 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
6360 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
197ac94e 6361 {
1beb58d7 6362 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6363 anArg.LowerCase();
6364 if (anUpdateTool.parseRedrawMode (anArg))
197ac94e 6365 {
197ac94e 6366 continue;
6367 }
1beb58d7 6368 else if (anArg == "-cmd"
6369 || anArg == "-command"
6370 || anArg == "-args")
6371 {
6372 char aText[4096];
6373 Sprintf (aText,
6374 "-scale %g "
6375 "-proj %g %g %g "
6376 "-up %g %g %g "
6377 "-at %g %g %g\n",
6378 aViewScale,
6379 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6380 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6381 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6382 theDi << aText;
6383 }
6384 else if (anArg == "-scale"
6385 || anArg == "-size")
6386 {
6387 if (anArgIter + 1 < theArgsNb
6388 && *theArgVec[anArgIter + 1] != '-')
6389 {
6390 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
6391 if (aValueArg.IsRealValue())
6392 {
6393 ++anArgIter;
6394 if (anArg == "-scale")
6395 {
6396 toSetScale = Standard_True;
6397 aViewScale = aValueArg.RealValue();
6398 }
6399 else if (anArg == "-size")
6400 {
6401 toSetSize = Standard_True;
6402 aViewSize = aValueArg.RealValue();
6403 }
6404 continue;
6405 }
6406 }
6407 if (anArg == "-scale")
6408 {
6409 theDi << "Scale: " << aView->Scale() << "\n";
6410 }
6411 else if (anArg == "-size")
6412 {
6413 Graphic3d_Vec2d aSizeXY;
6414 aView->Size (aSizeXY.x(), aSizeXY.y());
6415 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
6416 }
6417 }
6418 else if (anArg == "-eye"
6419 || anArg == "-at"
6420 || anArg == "-up"
6421 || anArg == "-proj")
6422 {
6423 if (anArgIter + 3 < theArgsNb)
6424 {
6425 gp_XYZ anXYZ;
6426 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
6427 {
6428 anArgIter += 3;
6429 if (anArg == "-eye")
6430 {
6431 toSetEye = Standard_True;
6432 aViewEye = anXYZ;
6433 }
6434 else if (anArg == "-at")
6435 {
6436 toSetAt = Standard_True;
6437 aViewAt = anXYZ;
6438 }
6439 else if (anArg == "-up")
6440 {
6441 toSetUp = Standard_True;
6442 aViewUp = anXYZ;
6443 }
6444 else if (anArg == "-proj")
6445 {
6446 toSetProj = Standard_True;
6447 aViewProj = anXYZ;
6448 }
6449 continue;
6450 }
6451 }
197ac94e 6452
1beb58d7 6453 if (anArg == "-eye")
6454 {
6455 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
6456 }
6457 else if (anArg == "-at")
6458 {
6459 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
6460 }
6461 else if (anArg == "-up")
6462 {
6463 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
6464 }
6465 else if (anArg == "-proj")
6466 {
6467 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
6468 }
6469 }
6470 else if (anArg == "-center")
3dfe95cd 6471 {
1beb58d7 6472 if (anArgIter + 2 < theArgsNb)
6473 {
6474 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
6475 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
6476 if (anX.IsIntegerValue()
6477 && anY.IsIntegerValue())
6478 {
6479 toSetCenter2d = Standard_True;
6480 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
6481 }
6482 }
6483 }
6484 else
6485 {
6486 std::cout << "Syntax error at '" << anArg << "'\n";
3dfe95cd 6487 return 1;
6488 }
1beb58d7 6489 }
3dfe95cd 6490
1beb58d7 6491 // change view parameters in proper order
6492 if (toSetScale)
6493 {
6494 aView->SetScale (aViewScale);
6495 }
6496 if (toSetSize)
6497 {
6498 aView->SetSize (aViewSize);
6499 }
6500 if (toSetEye)
6501 {
6502 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6503 }
6504 if (toSetAt)
6505 {
6506 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6507 }
6508 if (toSetProj)
6509 {
6510 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
6511 }
6512 if (toSetUp)
6513 {
6514 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
6515 }
6516 if (toSetCenter2d)
6517 {
6518 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
197ac94e 6519 }
6520
1beb58d7 6521 return 0;
6522}
197ac94e 6523
1beb58d7 6524//==============================================================================
6525//function : VAnimation
6526//purpose :
6527//==============================================================================
6528static Standard_Integer VAnimation (Draw_Interpretor& theDI,
6529 Standard_Integer theArgNb,
6530 const char** theArgVec)
6531{
6532 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
6533 if (theArgNb < 2)
4754e164 6534 {
1beb58d7 6535 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
6536 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
6537 {
6538 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
197ac94e 6539 }
1beb58d7 6540 return 0;
6541 }
6542 if (aCtx.IsNull())
6543 {
6544 std::cout << "Error: no active view\n";
6545 return 1;
4754e164 6546 }
197ac94e 6547
1beb58d7 6548 Standard_Integer anArgIter = 1;
6549 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
6550 if (aNameArg.IsEmpty())
6551 {
6552 std::cout << "Syntax error: animation name is not defined.\n";
6553 return 1;
6554 }
6555
6556 TCollection_AsciiString aNameArgLower = aNameArg;
6557 aNameArgLower.LowerCase();
6558 if (aNameArgLower == "-reset"
6559 || aNameArgLower == "-clear")
6560 {
6561 ViewerTest_AnimationTimelineMap.Clear();
6562 return 0;
6563 }
6564 else if (aNameArg.Value (1) == '-')
6565 {
6566 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
6567 return 1;
6568 }
197ac94e 6569
1beb58d7 6570 const char* aNameSplitter = "/";
6571 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
6572 if (aSplitPos == -1)
197ac94e 6573 {
1beb58d7 6574 aNameSplitter = ".";
6575 aSplitPos = aNameArg.Search (aNameSplitter);
6576 }
6577
6578 // find existing or create a new animation by specified name within syntax "parent.child".
6579 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
6580 for (; !aNameArg.IsEmpty();)
6581 {
6582 TCollection_AsciiString aNameParent;
6583 if (aSplitPos != -1)
197ac94e 6584 {
1beb58d7 6585 if (aSplitPos == aNameArg.Length())
6586 {
6587 std::cout << "Syntax error: animation name is not defined.\n";
6588 return 1;
6589 }
6590
6591 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
6592 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
6593
6594 aSplitPos = aNameArg.Search (aNameSplitter);
197ac94e 6595 }
6596 else
6597 {
1beb58d7 6598 aNameParent = aNameArg;
6599 aNameArg.Clear();
197ac94e 6600 }
1beb58d7 6601
6602 if (anAnimation.IsNull())
3dfe95cd 6603 {
1beb58d7 6604 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
6605 {
6606 anAnimation = new AIS_Animation (aNameParent);
6607 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
6608 }
6609 aRootAnimation = anAnimation;
3dfe95cd 6610 }
6611 else
6612 {
1beb58d7 6613 aParentAnimation = anAnimation;
6614 anAnimation = aParentAnimation->Find (aNameParent);
6615 if (anAnimation.IsNull())
6616 {
6617 anAnimation = new AIS_Animation (aNameParent);
6618 aParentAnimation->Add (anAnimation);
6619 }
3dfe95cd 6620 }
6621 }
1beb58d7 6622
6623 if (anArgIter >= theArgNb)
197ac94e 6624 {
1beb58d7 6625 // just print the list of children
6626 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
197ac94e 6627 {
1beb58d7 6628 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
197ac94e 6629 }
1beb58d7 6630 return 0;
197ac94e 6631 }
1beb58d7 6632
bf7b2ceb 6633 // animation parameters
1beb58d7 6634 Standard_Boolean toPlay = Standard_False;
6635 Standard_Real aPlaySpeed = 1.0;
6636 Standard_Real aPlayStartTime = anAnimation->StartPts();
6637 Standard_Real aPlayDuration = anAnimation->Duration();
1beb58d7 6638 Standard_Boolean isFreeCamera = Standard_False;
6639 Standard_Boolean isLockLoop = Standard_False;
08f8a185 6640
6641 // video recording parameters
6642 TCollection_AsciiString aRecFile;
6643 Image_VideoParams aRecParams;
6644
1beb58d7 6645 Handle(V3d_View) aView = ViewerTest::CurrentView();
6646 for (; anArgIter < theArgNb; ++anArgIter)
197ac94e 6647 {
1beb58d7 6648 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6649 anArg.LowerCase();
bf7b2ceb 6650 // general options
1beb58d7 6651 if (anArg == "-reset"
6652 || anArg == "-clear")
197ac94e 6653 {
1beb58d7 6654 anAnimation->Clear();
6655 }
6656 else if (anArg == "-remove"
6657 || anArg == "-del"
6658 || anArg == "-delete")
6659 {
6660 if (!aParentAnimation.IsNull())
6661 {
6662 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
6663 }
6664 else
6665 {
6666 aParentAnimation->Remove (anAnimation);
6667 }
6668 }
bf7b2ceb 6669 // playback options
1beb58d7 6670 else if (anArg == "-play")
6671 {
6672 toPlay = Standard_True;
6673 if (++anArgIter < theArgNb)
6674 {
6675 if (*theArgVec[anArgIter] == '-')
6676 {
6677 --anArgIter;
6678 continue;
6679 }
6680 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
6681
6682 if (++anArgIter < theArgNb)
6683 {
6684 if (*theArgVec[anArgIter] == '-')
6685 {
6686 --anArgIter;
6687 continue;
6688 }
6689 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
6690 }
6691 }
6692 }
6693 else if (anArg == "-resume")
6694 {
6695 toPlay = Standard_True;
6696 aPlayStartTime = anAnimation->ElapsedTime();
6697 if (++anArgIter < theArgNb)
6698 {
6699 if (*theArgVec[anArgIter] == '-')
6700 {
6701 --anArgIter;
6702 continue;
6703 }
6704
6705 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
6706 }
6707 }
6708 else if (anArg == "-playspeed"
6709 || anArg == "-speed")
6710 {
6711 if (++anArgIter >= theArgNb)
6712 {
6713 std::cout << "Syntax error at " << anArg << ".\n";
6714 return 1;
6715 }
6716 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
6717 }
6718 else if (anArg == "-lock"
6719 || anArg == "-lockloop"
6720 || anArg == "-playlockloop")
6721 {
6722 isLockLoop = Standard_True;
6723 }
6724 else if (anArg == "-freecamera"
6725 || anArg == "-playfreecamera"
6726 || anArg == "-freelook")
6727 {
6728 isFreeCamera = Standard_True;
6729 }
08f8a185 6730 // video recodring options
6731 else if (anArg == "-rec"
6732 || anArg == "-record")
6733 {
6734 if (++anArgIter >= theArgNb)
6735 {
6736 std::cout << "Syntax error at " << anArg << ".\n";
6737 return 1;
6738 }
6739
6740 aRecFile = theArgVec[anArgIter];
6741 if (aRecParams.FpsNum <= 0)
6742 {
6743 aRecParams.FpsNum = 24;
6744 }
6745
6746 if (anArgIter + 2 < theArgNb
6747 && *theArgVec[anArgIter + 1] != '-'
6748 && *theArgVec[anArgIter + 2] != '-')
6749 {
6750 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
6751 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
6752 if (aWidthArg .IsIntegerValue()
6753 && aHeightArg.IsIntegerValue())
6754 {
6755 aRecParams.Width = aWidthArg .IntegerValue();
6756 aRecParams.Height = aHeightArg.IntegerValue();
6757 anArgIter += 2;
6758 }
6759 }
6760 }
1beb58d7 6761 else if (anArg == "-fps")
6762 {
6763 if (++anArgIter >= theArgNb)
6764 {
6765 std::cout << "Syntax error at " << anArg << ".\n";
6766 return 1;
6767 }
bf7b2ceb 6768
6769 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
6770 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
6771 if (aSplitIndex == 0)
6772 {
08f8a185 6773 aRecParams.FpsNum = aFpsArg.IntegerValue();
bf7b2ceb 6774 }
6775 else
6776 {
6777 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
6778 aFpsArg.Split (aFpsArg.Length() - 1);
6779 const TCollection_AsciiString aNumStr = aFpsArg;
08f8a185 6780 aRecParams.FpsNum = aNumStr.IntegerValue();
6781 aRecParams.FpsDen = aDenStr.IntegerValue();
6782 if (aRecParams.FpsDen < 1)
bf7b2ceb 6783 {
6784 std::cout << "Syntax error at " << anArg << ".\n";
6785 return 1;
6786 }
6787 }
1beb58d7 6788 }
08f8a185 6789 else if (anArg == "-format")
6790 {
6791 if (++anArgIter >= theArgNb)
6792 {
6793 std::cout << "Syntax error at " << anArg << ".\n";
6794 return 1;
6795 }
6796 aRecParams.Format = theArgVec[anArgIter];
6797 }
6798 else if (anArg == "-pix_fmt"
6799 || anArg == "-pixfmt"
6800 || anArg == "-pixelformat")
6801 {
6802 if (++anArgIter >= theArgNb)
6803 {
6804 std::cout << "Syntax error at " << anArg << ".\n";
6805 return 1;
6806 }
6807 aRecParams.PixelFormat = theArgVec[anArgIter];
6808 }
6809 else if (anArg == "-codec"
6810 || anArg == "-vcodec"
6811 || anArg == "-videocodec")
6812 {
6813 if (++anArgIter >= theArgNb)
6814 {
6815 std::cout << "Syntax error at " << anArg << ".\n";
6816 return 1;
6817 }
6818 aRecParams.VideoCodec = theArgVec[anArgIter];
6819 }
6820 else if (anArg == "-crf"
6821 || anArg == "-preset"
6822 || anArg == "-qp")
6823 {
6824 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
6825 if (++anArgIter >= theArgNb)
6826 {
6827 std::cout << "Syntax error at " << anArg << ".\n";
6828 return 1;
6829 }
6830
6831 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
6832 }
bf7b2ceb 6833 // animation definition options
1beb58d7 6834 else if (anArg == "-start"
6835 || anArg == "-starttime"
6836 || anArg == "-startpts")
6837 {
6838 if (++anArgIter >= theArgNb)
6839 {
6840 std::cout << "Syntax error at " << anArg << ".\n";
6841 return 1;
6842 }
6843
6844 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
6845 aRootAnimation->UpdateTotalDuration();
6846 }
6847 else if (anArg == "-end"
6848 || anArg == "-endtime"
6849 || anArg == "-endpts")
6850 {
6851 if (++anArgIter >= theArgNb)
6852 {
6853 std::cout << "Syntax error at " << anArg << ".\n";
6854 return 1;
6855 }
6856
6857 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
6858 aRootAnimation->UpdateTotalDuration();
6859 }
6860 else if (anArg == "-dur"
6861 || anArg == "-duration")
6862 {
6863 if (++anArgIter >= theArgNb)
6864 {
6865 std::cout << "Syntax error at " << anArg << ".\n";
6866 return 1;
6867 }
6868
6869 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
6870 aRootAnimation->UpdateTotalDuration();
6871 }
6872 else if (anArg == "-command"
6873 || anArg == "-cmd"
6874 || anArg == "-invoke"
6875 || anArg == "-eval"
6876 || anArg == "-proc")
6877 {
6878 if (++anArgIter >= theArgNb)
6879 {
6880 std::cout << "Syntax error at " << anArg << ".\n";
6881 return 1;
6882 }
6883
6884 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
6885 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
6886 }
6887 else if (anArg == "-objecttrsf"
6888 || anArg == "-objectransformation"
6889 || anArg == "-objtransformation"
6890 || anArg == "-objtrsf"
6891 || anArg == "-object"
6892 || anArg == "-obj")
6893 {
6894 if (++anArgIter >= theArgNb)
6895 {
6896 std::cout << "Syntax error at " << anArg << ".\n";
6897 return 1;
6898 }
6899
6900 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
6901 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
6902 if (!aMapOfAIS.IsBound2 (anObjName))
6903 {
6904 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
6905 return 1;
6906 }
6907
6908 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapOfAIS.Find2 (anObjName));
6909 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
6910 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
6911 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
6912 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
6913 Standard_Boolean isTrsfSet = Standard_False;
6914 Standard_Integer aTrsfArgIter = anArgIter + 1;
6915 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
6916 {
6917 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
6918 aTrsfArg.LowerCase();
6919 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
6920 if (aTrsfArg.StartsWith ("-rotation")
6921 || aTrsfArg.StartsWith ("-rot"))
6922 {
6923 isTrsfSet = Standard_True;
6924 if (aTrsfArgIter + 4 >= theArgNb
6925 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
6926 {
6927 std::cout << "Syntax error at " << aTrsfArg << ".\n";
6928 return 1;
6929 }
6930 aTrsfArgIter += 4;
6931 }
6932 else if (aTrsfArg.StartsWith ("-location")
6933 || aTrsfArg.StartsWith ("-loc"))
6934 {
6935 isTrsfSet = Standard_True;
6936 if (aTrsfArgIter + 3 >= theArgNb
6937 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
6938 {
6939 std::cout << "Syntax error at " << aTrsfArg << ".\n";
6940 return 1;
6941 }
6942 aTrsfArgIter += 3;
6943 }
6944 else if (aTrsfArg.StartsWith ("-scale"))
6945 {
6946 isTrsfSet = Standard_True;
6947 if (++aTrsfArgIter >= theArgNb)
6948 {
6949 std::cout << "Syntax error at " << aTrsfArg << ".\n";
6950 return 1;
6951 }
6952
6953 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
6954 if (!aScaleStr.IsRealValue())
6955 {
6956 std::cout << "Syntax error at " << aTrsfArg << ".\n";
6957 return 1;
6958 }
6959 aScales[anIndex] = aScaleStr.RealValue();
6960 }
6961 else
6962 {
6963 anArgIter = aTrsfArgIter - 1;
6964 break;
6965 }
6966 }
6967 if (!isTrsfSet)
6968 {
6969 std::cout << "Syntax error at " << anArg << ".\n";
6970 return 1;
6971 }
6972 else if (aTrsfArgIter >= theArgNb)
6973 {
6974 anArgIter = theArgNb;
6975 }
6976
6977 aTrsfs[0].SetRotation (aRotQuats[0]);
6978 aTrsfs[1].SetRotation (aRotQuats[1]);
6979 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
6980 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
6981 aTrsfs[0].SetScaleFactor (aScales[0]);
6982 aTrsfs[1].SetScaleFactor (aScales[1]);
6983
6984 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
6985 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
6986 }
6987 else if (anArg == "-viewtrsf"
6988 || anArg == "-view")
6989 {
6990 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
6991 if (aCamAnimation.IsNull())
6992 {
6993 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
6994 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
6995 }
6996
6997 Handle(Graphic3d_Camera) aCams[2] =
6998 {
6999 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
7000 new Graphic3d_Camera (aCamAnimation->View()->Camera())
7001 };
7002
7003 Standard_Boolean isTrsfSet = Standard_False;
7004 Standard_Integer aViewArgIter = anArgIter + 1;
7005 for (; aViewArgIter < theArgNb; ++aViewArgIter)
7006 {
7007 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
7008 aViewArg.LowerCase();
7009 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
7010 if (aViewArg.StartsWith ("-scale"))
7011 {
7012 isTrsfSet = Standard_True;
7013 if (++aViewArgIter >= theArgNb)
7014 {
7015 std::cout << "Syntax error at " << anArg << ".\n";
7016 return 1;
7017 }
7018
7019 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
7020 if (!aScaleStr.IsRealValue())
7021 {
7022 std::cout << "Syntax error at " << aViewArg << ".\n";
7023 return 1;
7024 }
7025 Standard_Real aScale = aScaleStr.RealValue();
7026 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
7027 aCams[anIndex]->SetScale (aScale);
7028 }
7029 else if (aViewArg.StartsWith ("-eye")
7030 || aViewArg.StartsWith ("-center")
7031 || aViewArg.StartsWith ("-at")
7032 || aViewArg.StartsWith ("-up"))
7033 {
7034 isTrsfSet = Standard_True;
7035 gp_XYZ anXYZ;
7036 if (aViewArgIter + 3 >= theArgNb
7037 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
7038 {
7039 std::cout << "Syntax error at " << aViewArg << ".\n";
7040 return 1;
7041 }
7042 aViewArgIter += 3;
7043
7044 if (aViewArg.StartsWith ("-eye"))
7045 {
7046 aCams[anIndex]->SetEye (anXYZ);
7047 }
7048 else if (aViewArg.StartsWith ("-center")
7049 || aViewArg.StartsWith ("-at"))
7050 {
7051 aCams[anIndex]->SetCenter (anXYZ);
7052 }
7053 else if (aViewArg.StartsWith ("-up"))
7054 {
7055 aCams[anIndex]->SetUp (anXYZ);
7056 }
7057 }
7058 else
7059 {
7060 anArgIter = aViewArgIter - 1;
7061 break;
7062 }
7063 }
7064 if (!isTrsfSet)
7065 {
7066 std::cout << "Syntax error at " << anArg << ".\n";
7067 return 1;
7068 }
7069 else if (aViewArgIter >= theArgNb)
7070 {
7071 anArgIter = theArgNb;
7072 }
7073
7074 aCamAnimation->SetCameraStart(aCams[0]);
7075 aCamAnimation->SetCameraEnd (aCams[1]);
197ac94e 7076 }
7077 else
7078 {
1beb58d7 7079 std::cout << "Syntax error at " << anArg << ".\n";
7080 return 1;
197ac94e 7081 }
7082 }
1beb58d7 7083
08f8a185 7084 if (!toPlay && aRecFile.IsEmpty())
197ac94e 7085 {
1beb58d7 7086 return 0;
7087 }
7088
7089 // Start animation timeline and process frame updating.
7090 TheIsAnimating = Standard_True;
7091 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
7092 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
bf7b2ceb 7093 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
1beb58d7 7094 if (isFreeCamera)
7095 {
7096 aView->Camera()->Copy (aCameraBack);
7097 }
7098
7099 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
08f8a185 7100 if (aRecParams.FpsNum <= 0)
1beb58d7 7101 {
7102 while (!anAnimation->IsStopped())
197ac94e 7103 {
1beb58d7 7104 aCameraBack->Copy (aView->Camera());
7105 const Standard_Real aPts = anAnimation->UpdateTimer();
7106 if (isFreeCamera)
7107 {
7108 aView->Camera()->Copy (aCameraBack);
7109 }
7110
7111 if (aPts >= anUpperPts)
7112 {
7113 anAnimation->Pause();
7114 break;
7115 }
7116
7117 if (aView->IsInvalidated())
7118 {
7119 aView->Redraw();
7120 }
7121 else
7122 {
7123 aView->RedrawImmediate();
7124 }
7125
7126 if (!isLockLoop)
7127 {
7128 // handle user events
7129 theDI.Eval ("after 1 set waiter 1");
7130 theDI.Eval ("vwait waiter");
7131 }
7132 if (!TheIsAnimating)
7133 {
7134 anAnimation->Pause();
7135 theDI << aPts;
7136 break;
7137 }
7138 }
7139
7140 if (aView->IsInvalidated())
7141 {
7142 aView->Redraw();
197ac94e 7143 }
7144 else
7145 {
1beb58d7 7146 aView->RedrawImmediate();
197ac94e 7147 }
7148 }
1beb58d7 7149 else
197ac94e 7150 {
bf7b2ceb 7151 OSD_Timer aPerfTimer;
7152 aPerfTimer.Start();
1beb58d7 7153
08f8a185 7154 Handle(Image_VideoRecorder) aRecorder;
7155 ImageFlipper aFlipper;
7156 Handle(Draw_ProgressIndicator) aProgress;
7157 if (!aRecFile.IsEmpty())
7158 {
7159 if (aRecParams.Width <= 0
7160 || aRecParams.Height <= 0)
7161 {
7162 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
7163 }
7164
7165 aRecorder = new Image_VideoRecorder();
7166 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
7167 {
7168 std::cout << "Error: failed to open video file for recording\n";
7169 return 0;
7170 }
7171
7172 aProgress = new Draw_ProgressIndicator (theDI, 1);
7173 }
7174
1beb58d7 7175 // Manage frame-rated animation here
7176 Standard_Real aPts = aPlayStartTime;
bf7b2ceb 7177 int64_t aNbFrames = 0;
08f8a185 7178 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
7179 Standard_Integer aSecondsProgress = 0;
7180 for (; aPts <= anUpperPts && aPSentry.More();)
197ac94e 7181 {
08f8a185 7182 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
bf7b2ceb 7183 aPts = aPlayStartTime + aRecPts;
7184 ++aNbFrames;
1beb58d7 7185 if (!anAnimation->Update (aPts))
7186 {
7187 break;
7188 }
7189
08f8a185 7190 if (!aRecorder.IsNull())
7191 {
7192 V3d_ImageDumpOptions aDumpParams;
7193 aDumpParams.Width = aRecParams.Width;
7194 aDumpParams.Height = aRecParams.Height;
7195 aDumpParams.BufferType = Graphic3d_BT_RGBA;
7196 aDumpParams.StereoOptions = V3d_SDO_MONO;
7197 aDumpParams.ToAdjustAspect = Standard_True;
7198 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
7199 {
7200 std::cout << "Error: view dump is failed!\n";
7201 return 0;
7202 }
7203 aFlipper.FlipY (aRecorder->ChangeFrame());
7204 if (!aRecorder->PushFrame())
7205 {
7206 return 0;
7207 }
7208 }
7209 else
7210 {
7211 aView->Redraw();
7212 }
7213
7214 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
7215 {
7216 aPSentry.Next();
7217 ++aSecondsProgress;
7218 }
197ac94e 7219 }
bf7b2ceb 7220
7221 aPerfTimer.Stop();
1beb58d7 7222 anAnimation->Stop();
bf7b2ceb 7223 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
7224 theDI << "Average FPS: " << aRecFps << "\n"
7225 << "Nb. Frames: " << Standard_Real(aNbFrames);
7226
7227 aView->Redraw();
197ac94e 7228 }
7229
1beb58d7 7230 aView->SetImmediateUpdate (wasImmediateUpdate);
7231 TheIsAnimating = Standard_False;
4754e164 7232 return 0;
7233}
7234
1beb58d7 7235
4754e164 7236//=======================================================================
7237//function : VChangeSelected
dc3fe572 7238//purpose : Adds the shape to selection or remove one from it
4754e164 7239//=======================================================================
7240static Standard_Integer VChangeSelected (Draw_Interpretor& di,
7241 Standard_Integer argc,
7242 const char ** argv)
7243{
7244 if(argc != 2)
7245 {
7246 di<<"Usage : " << argv[0] << " shape \n";
7247 return 1;
7248 }
7249 //get AIS_Shape:
7250 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7251 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
7252 TCollection_AsciiString aName(argv[1]);
7253 Handle(AIS_InteractiveObject) anAISObject;
7254
7255 if(!aMap.IsBound2(aName))
7256 {
7257 di<<"Use 'vdisplay' before";
7258 return 1;
7259 }
7260 else
7261 {
7262 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
7263 if(anAISObject.IsNull()){
7264 di<<"No interactive object \n";
7265 return 1;
7266 }
7267
0577ae8c 7268 aContext->AddOrRemoveSelected(anAISObject, Standard_True);
4754e164 7269 }
7270 return 0;
7271}
7272
4754e164 7273//=======================================================================
7274//function : VNbSelected
dc3fe572 7275//purpose : Returns number of selected objects
4754e164 7276//=======================================================================
7277static Standard_Integer VNbSelected (Draw_Interpretor& di,
7278 Standard_Integer argc,
7279 const char ** argv)
7280{
7281 if(argc != 1)
7282 {
7283 di << "Usage : " << argv[0] << "\n";
7284 return 1;
7285 }
7286 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7287 if(aContext.IsNull())
7288 {
7289 di << "use 'vinit' command before " << argv[0] << "\n";
7290 return 1;
7291 }
7292 di << aContext->NbSelected() << "\n";
7293 return 0;
7294}
7295
4754e164 7296//=======================================================================
7297//function : VPurgeDisplay
dc3fe572 7298//purpose : Switches altialiasing on or off
4754e164 7299//=======================================================================
7300static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
7301 Standard_Integer argc,
7302 const char ** argv)
7303{
eb4320f2 7304 if (argc > 1)
4754e164 7305 {
eb4320f2 7306 di << "Usage : " << argv[0] << "\n";
4754e164 7307 return 1;
7308 }
4754e164 7309 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7310 if (aContext.IsNull())
7311 {
7312 di << "use 'vinit' command before " << argv[0] << "\n";
7313 return 1;
7314 }
404c8936 7315
eb4320f2 7316 di << aContext->PurgeDisplay() << "\n";
4754e164 7317 return 0;
7318}
7319
7320//=======================================================================
7321//function : VSetViewSize
7322//purpose :
7323//=======================================================================
7324static Standard_Integer VSetViewSize (Draw_Interpretor& di,
7325 Standard_Integer argc,
7326 const char ** argv)
7327{
7328 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7329 if(aContext.IsNull())
7330 {
7331 di << "use 'vinit' command before " << argv[0] << "\n";
7332 return 1;
7333 }
7334 if(argc != 2)
7335 {
7336 di<<"Usage : " << argv[0] << " Size\n";
7337 return 1;
7338 }
6b62b2da 7339 Standard_Real aSize = Draw::Atof (argv[1]);
4754e164 7340 if (aSize <= 0.)
7341 {
7342 di<<"Bad Size value : " << aSize << "\n";
7343 return 1;
7344 }
7345
7346 Handle(V3d_View) aView = ViewerTest::CurrentView();
7347 aView->SetSize(aSize);
7348 return 0;
7349}
7350
7351//=======================================================================
7352//function : VMoveView
7353//purpose :
7354//=======================================================================
7355static Standard_Integer VMoveView (Draw_Interpretor& di,
7356 Standard_Integer argc,
7357 const char ** argv)
7358{
7359 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7360 if(aContext.IsNull())
7361 {
7362 di << "use 'vinit' command before " << argv[0] << "\n";
7363 return 1;
7364 }
7365 if(argc < 4 || argc > 5)
7366 {
7367 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7368 return 1;
7369 }
6b62b2da 7370 Standard_Real Dx = Draw::Atof (argv[1]);
7371 Standard_Real Dy = Draw::Atof (argv[2]);
7372 Standard_Real Dz = Draw::Atof (argv[3]);
4754e164 7373 Standard_Boolean aStart = Standard_True;
7374 if (argc == 5)
7375 {
6b62b2da 7376 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 7377 }
7378
7379 Handle(V3d_View) aView = ViewerTest::CurrentView();
7380 aView->Move(Dx,Dy,Dz,aStart);
7381 return 0;
7382}
7383
7384//=======================================================================
7385//function : VTranslateView
7386//purpose :
7387//=======================================================================
7388static Standard_Integer VTranslateView (Draw_Interpretor& di,
7389 Standard_Integer argc,
7390 const char ** argv)
7391{
7392 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7393 if(aContext.IsNull())
7394 {
7395 di << "use 'vinit' command before " << argv[0] << "\n";
7396 return 1;
7397 }
7398 if(argc < 4 || argc > 5)
7399 {
7400 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7401 return 1;
7402 }
6b62b2da 7403 Standard_Real Dx = Draw::Atof (argv[1]);
7404 Standard_Real Dy = Draw::Atof (argv[2]);
7405 Standard_Real Dz = Draw::Atof (argv[3]);
4754e164 7406 Standard_Boolean aStart = Standard_True;
dc3fe572 7407 if (argc == 5)
4754e164 7408 {
6b62b2da 7409 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 7410 }
7411
7412 Handle(V3d_View) aView = ViewerTest::CurrentView();
7413 aView->Translate(Dx,Dy,Dz,aStart);
7414 return 0;
7415}
7416
7417//=======================================================================
7418//function : VTurnView
7419//purpose :
7420//=======================================================================
7421static Standard_Integer VTurnView (Draw_Interpretor& di,
7422 Standard_Integer argc,
7423 const char ** argv)
7424{
7425 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7426 if(aContext.IsNull()) {
7427 di << "use 'vinit' command before " << argv[0] << "\n";
7428 return 1;
7429 }
7430 if(argc < 4 || argc > 5){
7431 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
7432 return 1;
7433 }
6b62b2da 7434 Standard_Real Ax = Draw::Atof (argv[1]);
7435 Standard_Real Ay = Draw::Atof (argv[2]);
7436 Standard_Real Az = Draw::Atof (argv[3]);
4754e164 7437 Standard_Boolean aStart = Standard_True;
dc3fe572 7438 if (argc == 5)
4754e164 7439 {
6b62b2da 7440 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 7441 }
7442
7443 Handle(V3d_View) aView = ViewerTest::CurrentView();
7444 aView->Turn(Ax,Ay,Az,aStart);
7445 return 0;
7446}
7447
269294d6 7448//==============================================================================
7449//function : VTextureEnv
7450//purpose : ENables or disables environment mapping
7451//==============================================================================
7452class OCC_TextureEnv : public Graphic3d_TextureEnv
7453{
7454public:
7455 OCC_TextureEnv(const Standard_CString FileName);
7456 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
7457 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
7458 const Standard_Boolean theModulateFlag,
7459 const Graphic3d_TypeOfTextureFilter theFilter,
7460 const Standard_ShortReal theXScale,
7461 const Standard_ShortReal theYScale,
7462 const Standard_ShortReal theXShift,
7463 const Standard_ShortReal theYShift,
7464 const Standard_ShortReal theAngle);
68858c7d 7465 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
269294d6 7466};
a3f6f591 7467DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
ec357c5c 7468
269294d6 7469OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
7470 : Graphic3d_TextureEnv(theFileName)
7471{
7472}
7473
7474OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
7475 : Graphic3d_TextureEnv(theTexId)
7476{
7477}
7478
7479void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
7480 const Standard_Boolean theModulateFlag,
7481 const Graphic3d_TypeOfTextureFilter theFilter,
7482 const Standard_ShortReal theXScale,
7483 const Standard_ShortReal theYScale,
7484 const Standard_ShortReal theXShift,
7485 const Standard_ShortReal theYShift,
7486 const Standard_ShortReal theAngle)
7487{
7488 myParams->SetRepeat (theRepeatFlag);
7489 myParams->SetModulate (theModulateFlag);
7490 myParams->SetFilter (theFilter);
7491 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
7492 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
7493 myParams->SetRotation (theAngle);
7494}
7495
35e08fe8 7496static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
269294d6 7497{
7498 // get the active view
7499 Handle(V3d_View) aView = ViewerTest::CurrentView();
7500 if (aView.IsNull())
7501 {
7502 std::cerr << "No active view. Please call vinit.\n";
7503 return 1;
7504 }
7505
7506 // Checking the input arguments
7507 Standard_Boolean anEnableFlag = Standard_False;
7508 Standard_Boolean isOk = theArgNb >= 2;
7509 if (isOk)
7510 {
7511 TCollection_AsciiString anEnableOpt(theArgVec[1]);
7512 anEnableFlag = anEnableOpt.IsEqual("on");
7513 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
7514 }
7515 if (anEnableFlag)
7516 {
7517 isOk = (theArgNb == 3 || theArgNb == 11);
7518 if (isOk)
7519 {
7520 TCollection_AsciiString aTextureOpt(theArgVec[2]);
7521 isOk = (!aTextureOpt.IsIntegerValue() ||
7522 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
7523
7524 if (isOk && theArgNb == 11)
7525 {
7526 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
7527 aModulateOpt(theArgVec[4]),
7528 aFilterOpt (theArgVec[5]),
7529 aSScaleOpt (theArgVec[6]),
7530 aTScaleOpt (theArgVec[7]),
7531 aSTransOpt (theArgVec[8]),
7532 aTTransOpt (theArgVec[9]),
7533 anAngleOpt (theArgVec[10]);
7534 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
7535 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
7536 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
7537 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
7538 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
7539 anAngleOpt.IsRealValue());
7540 }
7541 }
7542 }
7543
7544 if (!isOk)
7545 {
7546 std::cerr << "Usage :" << std::endl;
7547 std::cerr << theArgVec[0] << " off" << std::endl;
7548 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;
7549 return 1;
7550 }
7551
7552 if (anEnableFlag)
7553 {
7554 TCollection_AsciiString aTextureOpt(theArgVec[2]);
7555 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
7556 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
7557 new OCC_TextureEnv(theArgVec[2]);
7558
7559 if (theArgNb == 11)
7560 {
7561 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
7562 aTexEnv->SetTextureParameters(
7563 aRepeatOpt. IsEqual("repeat"),
7564 aModulateOpt.IsEqual("modulate"),
7565 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
7566 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
7567 Graphic3d_TOTF_TRILINEAR,
7568 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
7569 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
7570 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
7571 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
7572 (Standard_ShortReal)Draw::Atof(theArgVec[10])
7573 );
7574 }
7575 aView->SetTextureEnv(aTexEnv);
269294d6 7576 }
7577 else // Disabling environment mapping
7578 {
269294d6 7579 Handle(Graphic3d_TextureEnv) aTexture;
7580 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
7581 }
7582
7583 aView->Redraw();
7584 return 0;
7585}
7586
3e05329c 7587namespace
7588{
7589 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
7590
7591 //! Remove registered clipping plane from all views and objects.
7592 static void removePlane (MapOfPlanes& theRegPlanes,
7593 const TCollection_AsciiString& theName)
7594 {
7595 Handle(Graphic3d_ClipPlane) aClipPlane;
7596 if (!theRegPlanes.Find (theName, aClipPlane))
7597 {
7598 std::cout << "Warning: no such plane.\n";
7599 return;
7600 }
7601
7602 theRegPlanes.UnBind (theName);
7603 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
7604 anIObjIt.More(); anIObjIt.Next())
7605 {
7606 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
7607 aPrs->RemoveClipPlane (aClipPlane);
7608 }
7609
7610 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
7611 aViewIt.More(); aViewIt.Next())
7612 {
7613 const Handle(V3d_View)& aView = aViewIt.Key2();
7614 aView->RemoveClipPlane(aClipPlane);
7615 }
7616
7617 ViewerTest::RedrawAllViews();
7618 }
7619}
7620
4269bd1b 7621//===============================================================================================
7622//function : VClipPlane
7623//purpose :
7624//===============================================================================================
7625static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7626{
7627 // use short-cut for created clip planes map of created (or "registered by name") clip planes
4269bd1b 7628 static MapOfPlanes aRegPlanes;
7629
7630 if (theArgsNb < 2)
7631 {
3e05329c 7632 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
7633 {
7634 theDi << aPlaneIter.Key() << " ";
7635 }
7636 return 0;
4269bd1b 7637 }
7638
7639 TCollection_AsciiString aCommand (theArgVec[1]);
3e05329c 7640 aCommand.LowerCase();
7641 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
7642 if (anActiveView.IsNull())
7643 {
7644 std::cout << "Error: no active view.\n";
7645 return 1;
7646 }
4269bd1b 7647
7648 // print maximum number of planes for current viewer
3e05329c 7649 if (aCommand == "-maxplanes"
7650 || aCommand == "maxplanes")
4269bd1b 7651 {
3e05329c 7652 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
7653 << " plane slots provided by driver.\n";
4269bd1b 7654 return 0;
7655 }
7656
7657 // create / delete plane instance
3e05329c 7658 if (aCommand == "-create"
7659 || aCommand == "create"
7660 || aCommand == "-delete"
7661 || aCommand == "delete"
7662 || aCommand == "-clone"
7663 || aCommand == "clone")
4269bd1b 7664 {
7665 if (theArgsNb < 3)
7666 {
3e05329c 7667 std::cout << "Syntax error: plane name is required.\n";
4269bd1b 7668 return 1;
7669 }
7670
3e05329c 7671 Standard_Boolean toCreate = aCommand == "-create"
7672 || aCommand == "create";
7673 Standard_Boolean toClone = aCommand == "-clone"
7674 || aCommand == "clone";
7675 Standard_Boolean toDelete = aCommand == "-delete"
7676 || aCommand == "delete";
4269bd1b 7677 TCollection_AsciiString aPlane (theArgVec[2]);
7678
7679 if (toCreate)
7680 {
7681 if (aRegPlanes.IsBound (aPlane))
7682 {
3e05329c 7683 std::cout << "Warning: existing plane has been overridden.\n";
7684 toDelete = true;
7685 }
7686 else
7687 {
7688 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
7689 return 0;
4269bd1b 7690 }
4269bd1b 7691 }
7692 else if (toClone) // toClone
7693 {
7694 if (!aRegPlanes.IsBound (aPlane))
7695 {
3e05329c 7696 std::cout << "Error: no such plane.\n";
4269bd1b 7697 return 1;
7698 }
3e05329c 7699 else if (theArgsNb < 4)
4269bd1b 7700 {
3e05329c 7701 std::cout << "Syntax error: enter name for new plane.\n";
4269bd1b 7702 return 1;
7703 }
7704
7705 TCollection_AsciiString aClone (theArgVec[3]);
7706 if (aRegPlanes.IsBound (aClone))
7707 {
3e05329c 7708 std::cout << "Error: plane name is in use.\n";
4269bd1b 7709 return 1;
7710 }
7711
7712 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
7713
7714 aRegPlanes.Bind (aClone, aClipPlane->Clone());
3e05329c 7715 return 0;
4269bd1b 7716 }
4269bd1b 7717
3e05329c 7718 if (toDelete)
7719 {
7720 if (aPlane == "ALL"
7721 || aPlane == "all"
7722 || aPlane == "*")
4269bd1b 7723 {
3e05329c 7724 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
7725 {
7726 aPlane = aPlaneIter.Key();
7727 removePlane (aRegPlanes, aPlane);
7728 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
7729 }
4269bd1b 7730 }
3e05329c 7731 else
4269bd1b 7732 {
3e05329c 7733 removePlane (aRegPlanes, aPlane);
4269bd1b 7734 }
4269bd1b 7735 }
7736
3e05329c 7737 if (toCreate)
7738 {
7739 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
7740 }
4269bd1b 7741 return 0;
7742 }
7743
7744 // set / unset plane command
3e05329c 7745 if (aCommand == "set"
7746 || aCommand == "unset")
4269bd1b 7747 {
3e05329c 7748 if (theArgsNb < 5)
4269bd1b 7749 {
3e05329c 7750 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 7751 return 1;
7752 }
7753
3e05329c 7754 // redirect to new syntax
7755 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
7756 anArgVec.SetValue (1, theArgVec[0]);
7757 anArgVec.SetValue (2, theArgVec[2]);
7758 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
7759 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
4269bd1b 7760 {
3e05329c 7761 anArgVec.SetValue (anIt, theArgVec[anIt]);
4269bd1b 7762 }
7763
3e05329c 7764 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
4269bd1b 7765 }
7766
7767 // change plane command
3e05329c 7768 TCollection_AsciiString aPlaneName;
7769 Handle(Graphic3d_ClipPlane) aClipPlane;
7770 Standard_Integer anArgIter = 0;
7771 if (aCommand == "-change"
7772 || aCommand == "change")
4269bd1b 7773 {
3e05329c 7774 // old syntax support
7775 if (theArgsNb < 3)
4269bd1b 7776 {
3e05329c 7777 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 7778 return 1;
7779 }
7780
3e05329c 7781 anArgIter = 3;
7782 aPlaneName = theArgVec[2];
7783 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
4269bd1b 7784 {
3e05329c 7785 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
4269bd1b 7786 return 1;
7787 }
3e05329c 7788 }
7789 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
7790 {
7791 anArgIter = 2;
7792 aPlaneName = theArgVec[1];
7793 }
7794 else
7795 {
7796 anArgIter = 2;
7797 aPlaneName = theArgVec[1];
7798 aClipPlane = new Graphic3d_ClipPlane();
7799 aRegPlanes.Bind (aPlaneName, aClipPlane);
7800 theDi << "Created new plane " << aPlaneName << ".\n";
7801 }
4269bd1b 7802
3e05329c 7803 if (theArgsNb - anArgIter < 1)
7804 {
7805 std::cout << "Syntax error: need more arguments.\n";
7806 return 1;
7807 }
4269bd1b 7808
3e05329c 7809 for (; anArgIter < theArgsNb; ++anArgIter)
7810 {
7811 const char** aChangeArgs = theArgVec + anArgIter;
7812 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
7813 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
7814 aChangeArg.LowerCase();
4269bd1b 7815
3e05329c 7816 Standard_Boolean toEnable = Standard_True;
7817 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
4269bd1b 7818 {
3e05329c 7819 aClipPlane->SetOn (toEnable);
4269bd1b 7820 }
3e05329c 7821 else if (aChangeArg == "-equation"
7822 || aChangeArg == "equation")
4269bd1b 7823 {
3e05329c 7824 if (aNbChangeArgs < 5)
4269bd1b 7825 {
3e05329c 7826 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 7827 return 1;
7828 }
7829
3e05329c 7830 Standard_Real aCoeffA = Draw::Atof (aChangeArgs [1]);
7831 Standard_Real aCoeffB = Draw::Atof (aChangeArgs [2]);
7832 Standard_Real aCoeffC = Draw::Atof (aChangeArgs [3]);
7833 Standard_Real aCoeffD = Draw::Atof (aChangeArgs [4]);
4269bd1b 7834 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
3e05329c 7835 anArgIter += 4;
4269bd1b 7836 }
3e05329c 7837 else if (aChangeArg == "-capping"
7838 || aChangeArg == "capping")
4269bd1b 7839 {
3e05329c 7840 if (aNbChangeArgs < 2)
4269bd1b 7841 {
3e05329c 7842 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 7843 return 1;
7844 }
7845
3e05329c 7846 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
4269bd1b 7847 {
3e05329c 7848 aClipPlane->SetCapping (toEnable);
7849 anArgIter += 1;
7850 }
7851 else
7852 {
7853 // just skip otherwise (old syntax)
7854 }
7855 }
7856 else if (aChangeArg == "-useobjectmaterial"
7857 || aChangeArg == "-useobjectmat"
7858 || aChangeArg == "-useobjmat"
7859 || aChangeArg == "-useobjmaterial")
7860 {
7861 if (aNbChangeArgs < 2)
7862 {
7863 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 7864 return 1;
7865 }
7866
3e05329c 7867 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
4269bd1b 7868 {
3e05329c 7869 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
7870 anArgIter += 1;
4269bd1b 7871 }
3e05329c 7872 }
7873 else if (aChangeArg == "-useobjecttexture"
7874 || aChangeArg == "-useobjecttex"
7875 || aChangeArg == "-useobjtexture"
7876 || aChangeArg == "-useobjtex")
7877 {
7878 if (aNbChangeArgs < 2)
4269bd1b 7879 {
3e05329c 7880 std::cout << "Syntax error: need more arguments.\n";
7881 return 1;
7882 }
4269bd1b 7883
3e05329c 7884 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
7885 {
7886 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
7887 anArgIter += 1;
7888 }
7889 }
7890 else if (aChangeArg == "-useobjectshader"
7891 || aChangeArg == "-useobjshader")
7892 {
7893 if (aNbChangeArgs < 2)
7894 {
7895 std::cout << "Syntax error: need more arguments.\n";
7896 return 1;
7897 }
4269bd1b 7898
3e05329c 7899 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
7900 {
7901 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
7902 anArgIter += 1;
4269bd1b 7903 }
3e05329c 7904 }
7905 else if (aChangeArg == "-color"
7906 || aChangeArg == "color")
7907 {
7908 Quantity_Color aColor;
7909 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
7910 aChangeArgs + 1,
7911 aColor);
7912 if (aNbParsed == 0)
4269bd1b 7913 {
3e05329c 7914 std::cout << "Syntax error: need more arguments.\n";
7915 return 1;
7916 }
4269bd1b 7917
3e05329c 7918 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
7919 aMat.SetAmbientColor (aColor);
7920 aMat.SetDiffuseColor (aColor);
7921 aClipPlane->SetCappingMaterial (aMat);
7922 anArgIter += aNbParsed;
7923 }
7924 else if (aChangeArg == "-texname"
7925 || aChangeArg == "texname")
7926 {
7927 if (aNbChangeArgs < 2)
7928 {
7929 std::cout << "Syntax error: need more arguments.\n";
7930 return 1;
7931 }
4269bd1b 7932
3e05329c 7933 TCollection_AsciiString aTextureName (aChangeArgs[1]);
7934 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
7935 if (!aTexture->IsDone())
7936 {
7937 aClipPlane->SetCappingTexture (NULL);
4269bd1b 7938 }
3e05329c 7939 else
4269bd1b 7940 {
3e05329c 7941 aTexture->EnableModulate();
7942 aTexture->EnableRepeat();
7943 aClipPlane->SetCappingTexture (aTexture);
7944 }
7945 anArgIter += 1;
7946 }
7947 else if (aChangeArg == "-texscale"
7948 || aChangeArg == "texscale")
7949 {
7950 if (aClipPlane->CappingTexture().IsNull())
7951 {
7952 std::cout << "Error: no texture is set.\n";
7953 return 1;
7954 }
4269bd1b 7955
3e05329c 7956 if (aNbChangeArgs < 3)
7957 {
7958 std::cout << "Syntax error: need more arguments.\n";
7959 return 1;
7960 }
4269bd1b 7961
3e05329c 7962 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
7963 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
7964 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
7965 anArgIter += 2;
7966 }
7967 else if (aChangeArg == "-texorigin"
7968 || aChangeArg == "texorigin") // texture origin
7969 {
7970 if (aClipPlane->CappingTexture().IsNull())
7971 {
7972 std::cout << "Error: no texture is set.\n";
7973 return 1;
7974 }
4269bd1b 7975
3e05329c 7976 if (aNbChangeArgs < 3)
7977 {
7978 std::cout << "Syntax error: need more arguments.\n";
7979 return 1;
4269bd1b 7980 }
3e05329c 7981
7982 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
7983 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
7984
7985 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
7986 anArgIter += 2;
7987 }
7988 else if (aChangeArg == "-texrotate"
7989 || aChangeArg == "texrotate") // texture rotation
7990 {
7991 if (aClipPlane->CappingTexture().IsNull())
4269bd1b 7992 {
3e05329c 7993 std::cout << "Error: no texture is set.\n";
7994 return 1;
7995 }
4269bd1b 7996
3e05329c 7997 if (aNbChangeArgs < 2)
7998 {
7999 std::cout << "Syntax error: need more arguments.\n";
8000 return 1;
8001 }
4269bd1b 8002
3e05329c 8003 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8004 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8005 anArgIter += 1;
8006 }
8007 else if (aChangeArg == "-hatch"
8008 || aChangeArg == "hatch")
8009 {
8010 if (aNbChangeArgs < 2)
8011 {
8012 std::cout << "Syntax error: need more arguments.\n";
8013 return 1;
8014 }
4269bd1b 8015
3e05329c 8016 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8017 aHatchStr.LowerCase();
8018 if (aHatchStr == "on")
8019 {
8020 aClipPlane->SetCappingHatchOn();
8021 }
8022 else if (aHatchStr == "off")
8023 {
8024 aClipPlane->SetCappingHatchOff();
4269bd1b 8025 }
3e05329c 8026 else
4269bd1b 8027 {
3e05329c 8028 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8029 }
8030 anArgIter += 1;
8031 }
8032 else if (aChangeArg == "-delete"
8033 || aChangeArg == "delete")
8034 {
8035 removePlane (aRegPlanes, aPlaneName);
8036 return 0;
8037 }
8038 else if (aChangeArg == "-set"
8039 || aChangeArg == "-unset")
8040 {
8041 // set / unset plane command
8042 Standard_Boolean toSet = aChangeArg == "-set";
8043 Standard_Integer anIt = 1;
8044 for (; anIt < aNbChangeArgs; ++anIt)
8045 {
8046 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8047 if (anEntityName.IsEmpty()
8048 || anEntityName.Value (1) == '-')
4269bd1b 8049 {
3e05329c 8050 break;
4269bd1b 8051 }
3e05329c 8052 else if (ViewerTest_myViews.IsBound1 (anEntityName))
4269bd1b 8053 {
3e05329c 8054 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
8055 if (toSet)
8056 {
8057 aView->AddClipPlane (aClipPlane);
8058 }
8059 else
8060 {
8061 aView->RemoveClipPlane (aClipPlane);
8062 }
8063 continue;
4269bd1b 8064 }
3e05329c 8065 else if (GetMapOfAIS().IsBound2 (anEntityName))
4269bd1b 8066 {
3e05329c 8067 Handle(AIS_InteractiveObject) aIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
8068 if (toSet)
8069 {
8070 aIObj->AddClipPlane (aClipPlane);
8071 }
8072 else
8073 {
8074 aIObj->RemoveClipPlane (aClipPlane);
8075 }
4269bd1b 8076 }
3e05329c 8077 else
4269bd1b 8078 {
3e05329c 8079 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
8080 return 1;
4269bd1b 8081 }
3e05329c 8082 }
8083
8084 if (anIt == 1)
8085 {
8086 // apply to active view
8087 if (toSet)
4269bd1b 8088 {
3e05329c 8089 anActiveView->AddClipPlane (aClipPlane);
4269bd1b 8090 }
8091 else
8092 {
3e05329c 8093 anActiveView->RemoveClipPlane (aClipPlane);
4269bd1b 8094 }
8095 }
3e05329c 8096 else
8097 {
8098 anArgIter = anArgIter + anIt - 1;
8099 }
8100 }
8101 else
8102 {
8103 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8104 return 1;
4269bd1b 8105 }
4269bd1b 8106 }
8107
3e05329c 8108 ViewerTest::RedrawAllViews();
8109 return 0;
4269bd1b 8110}
8111
b5ac8292 8112//===============================================================================================
8113//function : VZRange
8114//purpose :
8115//===============================================================================================
8116static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8117{
197ac94e 8118 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8119
8120 if (aCurrentView.IsNull())
b5ac8292 8121 {
197ac94e 8122 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 8123 return 1;
8124 }
8125
197ac94e 8126 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
b5ac8292 8127
8128 if (theArgsNb < 2)
8129 {
8130 theDi << "ZNear: " << aCamera->ZNear() << "\n";
8131 theDi << "ZFar: " << aCamera->ZFar() << "\n";
8132 return 0;
8133 }
8134
8135 if (theArgsNb == 3)
8136 {
6b62b2da 8137 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
8138 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
197ac94e 8139
8140 if (aNewZNear >= aNewZFar)
8141 {
8142 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
8143 return 1;
8144 }
8145
8146 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
8147 {
8148 std::cout << theArgVec[0] << ": invalid arguments: ";
8149 std::cout << "znear, zfar should be positive for perspective camera.\n";
8150 return 1;
8151 }
8152
8153 aCamera->SetZRange (aNewZNear, aNewZFar);
b5ac8292 8154 }
8155 else
8156 {
197ac94e 8157 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
b5ac8292 8158 return 1;
8159 }
8160
197ac94e 8161 aCurrentView->Redraw();
8162
b5ac8292 8163 return 0;
8164}
8165
8166//===============================================================================================
8167//function : VAutoZFit
8168//purpose :
8169//===============================================================================================
8170static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8171{
197ac94e 8172 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8173
8174 if (aCurrentView.IsNull())
b5ac8292 8175 {
197ac94e 8176 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 8177 return 1;
8178 }
8179
c357e426 8180 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
197ac94e 8181
8182 if (theArgsNb > 3)
b5ac8292 8183 {
197ac94e 8184 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8185 return 1;
b5ac8292 8186 }
8187
197ac94e 8188 if (theArgsNb < 2)
b5ac8292 8189 {
586db386 8190 theDi << "Auto z-fit mode: \n"
c357e426 8191 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
197ac94e 8192 << "Scale: " << aScale << "\n";
8193 return 0;
b5ac8292 8194 }
197ac94e 8195
8196 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
8197
8198 if (theArgsNb >= 3)
b5ac8292 8199 {
197ac94e 8200 aScale = Draw::Atoi (theArgVec[2]);
b5ac8292 8201 }
8202
c357e426 8203 aCurrentView->SetAutoZFitMode (isOn, aScale);
8204 aCurrentView->AutoZFit();
197ac94e 8205 aCurrentView->Redraw();
8206
b5ac8292 8207 return 0;
8208}
8209
6b62b2da 8210//! Auxiliary function to print projection type
8211inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
8212{
8213 switch (theProjType)
8214 {
8215 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
8216 case Graphic3d_Camera::Projection_Perspective: return "perspective";
8217 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
8218 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
8219 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
8220 }
8221 return "UNKNOWN";
8222}
8223
b5ac8292 8224//===============================================================================================
6b62b2da 8225//function : VCamera
b5ac8292 8226//purpose :
8227//===============================================================================================
6b62b2da 8228static int VCamera (Draw_Interpretor& theDI,
8229 Standard_Integer theArgsNb,
8230 const char** theArgVec)
b5ac8292 8231{
6b62b2da 8232 Handle(V3d_View) aView = ViewerTest::CurrentView();
8233 if (aView.IsNull())
b5ac8292 8234 {
6b62b2da 8235 std::cout << "Error: no active view.\n";
b5ac8292 8236 return 1;
8237 }
8238
6b62b2da 8239 Handle(Graphic3d_Camera) aCamera = aView->Camera();
8240 if (theArgsNb < 2)
b5ac8292 8241 {
6b62b2da 8242 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
8243 theDI << "FOVy: " << aCamera->FOVy() << "\n";
8244 theDI << "Distance: " << aCamera->Distance() << "\n";
8245 theDI << "IOD: " << aCamera->IOD() << "\n";
8246 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
8247 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
8248 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
8249 return 0;
b5ac8292 8250 }
8251
6b62b2da 8252 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
b5ac8292 8253 {
6b62b2da 8254 Standard_CString anArg = theArgVec[anArgIter];
8255 TCollection_AsciiString anArgCase (anArg);
8256 anArgCase.LowerCase();
8257 if (anArgCase == "-proj"
8258 || anArgCase == "-projection"
8259 || anArgCase == "-projtype"
8260 || anArgCase == "-projectiontype")
8261 {
8262 theDI << projTypeName (aCamera->ProjectionType()) << " ";
8263 }
8264 else if (anArgCase == "-ortho"
8265 || anArgCase == "-orthographic")
b5ac8292 8266 {
8267 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
6b62b2da 8268 }
8269 else if (anArgCase == "-persp"
8270 || anArgCase == "-perspective"
8271 || anArgCase == "-perspmono"
8272 || anArgCase == "-perspectivemono"
8273 || anArgCase == "-mono")
b5ac8292 8274 {
8275 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
8276 }
6b62b2da 8277 else if (anArgCase == "-stereo"
8278 || anArgCase == "-stereoscopic"
8279 || anArgCase == "-perspstereo"
8280 || anArgCase == "-perspectivestereo")
8281 {
8282 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
8283 }
8284 else if (anArgCase == "-left"
8285 || anArgCase == "-lefteye"
8286 || anArgCase == "-monoleft"
8287 || anArgCase == "-monolefteye"
8288 || anArgCase == "-perpsleft"
8289 || anArgCase == "-perpslefteye")
b5ac8292 8290 {
8291 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
8292 }
6b62b2da 8293 else if (anArgCase == "-right"
8294 || anArgCase == "-righteye"
8295 || anArgCase == "-monoright"
8296 || anArgCase == "-monorighteye"
8297 || anArgCase == "-perpsright")
b5ac8292 8298 {
8299 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
8300 }
6b62b2da 8301 else if (anArgCase == "-dist"
8302 || anArgCase == "-distance")
b5ac8292 8303 {
6b62b2da 8304 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8305 if (anArgValue != NULL
8306 && *anArgValue != '-')
8307 {
8308 ++anArgIter;
8309 aCamera->SetDistance (Draw::Atof (anArgValue));
8310 continue;
8311 }
8312 theDI << aCamera->Distance() << " ";
b5ac8292 8313 }
6b62b2da 8314 else if (anArgCase == "-iod")
b5ac8292 8315 {
6b62b2da 8316 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8317 if (anArgValue != NULL
8318 && *anArgValue != '-')
8319 {
8320 ++anArgIter;
8321 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
8322 continue;
8323 }
8324 theDI << aCamera->IOD() << " ";
b5ac8292 8325 }
6b62b2da 8326 else if (anArgCase == "-iodtype")
b5ac8292 8327 {
6b62b2da 8328 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8329 TCollection_AsciiString anValueCase (anArgValue);
8330 anValueCase.LowerCase();
8331 if (anValueCase == "abs"
8332 || anValueCase == "absolute")
8333 {
8334 ++anArgIter;
8335 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
8336 continue;
8337 }
8338 else if (anValueCase == "rel"
8339 || anValueCase == "relative")
8340 {
8341 ++anArgIter;
8342 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
8343 continue;
8344 }
8345 else if (*anArgValue != '-')
8346 {
8347 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
8348 return 1;
8349 }
8350 switch (aCamera->GetIODType())
8351 {
8352 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
8353 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
8354 }
b5ac8292 8355 }
6b62b2da 8356 else if (anArgCase == "-zfocus")
b5ac8292 8357 {
6b62b2da 8358 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8359 if (anArgValue != NULL
8360 && *anArgValue != '-')
8361 {
8362 ++anArgIter;
8363 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
8364 continue;
8365 }
8366 theDI << aCamera->ZFocus() << " ";
b5ac8292 8367 }
6b62b2da 8368 else if (anArgCase == "-zfocustype")
b5ac8292 8369 {
6b62b2da 8370 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8371 TCollection_AsciiString anValueCase (anArgValue);
8372 anValueCase.LowerCase();
8373 if (anValueCase == "abs"
8374 || anValueCase == "absolute")
8375 {
8376 ++anArgIter;
8377 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
8378 continue;
8379 }
8380 else if (anValueCase == "rel"
8381 || anValueCase == "relative")
8382 {
8383 ++anArgIter;
8384 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
8385 continue;
8386 }
8387 else if (*anArgValue != '-')
8388 {
8389 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
8390 return 1;
8391 }
8392 switch (aCamera->ZFocusType())
8393 {
8394 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
8395 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
8396 }
8397 }
8398 else if (anArgCase == "-fov"
8399 || anArgCase == "-fovy")
b5ac8292 8400 {
6b62b2da 8401 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8402 if (anArgValue != NULL
8403 && *anArgValue != '-')
8404 {
8405 ++anArgIter;
8406 aCamera->SetFOVy (Draw::Atof (anArgValue));
8407 continue;
8408 }
8409 theDI << aCamera->FOVy() << " ";
b5ac8292 8410 }
8411 else
8412 {
6b62b2da 8413 std::cout << "Error: unknown argument '" << anArg << "'\n";
b5ac8292 8414 return 1;
8415 }
8416 }
b5ac8292 8417
c357e426 8418 aView->AutoZFit();
6b62b2da 8419 aView->Redraw();
b5ac8292 8420
8421 return 0;
8422}
8423
f978241f 8424//! Parse stereo output mode
8425inline Standard_Boolean parseStereoMode (Standard_CString theArg,
8426 Graphic3d_StereoMode& theMode)
8427{
8428 TCollection_AsciiString aFlag (theArg);
8429 aFlag.LowerCase();
8430 if (aFlag == "quadbuffer")
8431 {
8432 theMode = Graphic3d_StereoMode_QuadBuffer;
8433 }
8434 else if (aFlag == "anaglyph")
8435 {
8436 theMode = Graphic3d_StereoMode_Anaglyph;
8437 }
8438 else if (aFlag == "row"
8439 || aFlag == "rowinterlaced")
8440 {
8441 theMode = Graphic3d_StereoMode_RowInterlaced;
8442 }
8443 else if (aFlag == "col"
8444 || aFlag == "colinterlaced"
8445 || aFlag == "columninterlaced")
8446 {
8447 theMode = Graphic3d_StereoMode_ColumnInterlaced;
8448 }
8449 else if (aFlag == "chess"
8450 || aFlag == "chessboard")
8451 {
8452 theMode = Graphic3d_StereoMode_ChessBoard;
8453 }
8454 else if (aFlag == "sbs"
8455 || aFlag == "sidebyside")
8456 {
8457 theMode = Graphic3d_StereoMode_SideBySide;
8458 }
8459 else if (aFlag == "ou"
8460 || aFlag == "overunder")
8461 {
8462 theMode = Graphic3d_StereoMode_OverUnder;
8463 }
8464 else if (aFlag == "pageflip"
8465 || aFlag == "softpageflip")
8466 {
8467 theMode = Graphic3d_StereoMode_SoftPageFlip;
8468 }
8469 else
8470 {
8471 return Standard_False;
8472 }
8473 return Standard_True;
8474}
8475
8476//! Parse anaglyph filter
8477inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
8478 Graphic3d_RenderingParams::Anaglyph& theFilter)
8479{
8480 TCollection_AsciiString aFlag (theArg);
8481 aFlag.LowerCase();
8482 if (aFlag == "redcyansimple")
8483 {
8484 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
8485 }
8486 else if (aFlag == "redcyan"
8487 || aFlag == "redcyanoptimized")
8488 {
8489 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
8490 }
8491 else if (aFlag == "yellowbluesimple")
8492 {
8493 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
8494 }
8495 else if (aFlag == "yellowblue"
8496 || aFlag == "yellowblueoptimized")
8497 {
8498 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
8499 }
8500 else if (aFlag == "greenmagenta"
8501 || aFlag == "greenmagentasimple")
8502 {
8503 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
8504 }
8505 else
8506 {
8507 return Standard_False;
8508 }
8509 return Standard_True;
8510}
8511
b5ac8292 8512//==============================================================================
8513//function : VStereo
8514//purpose :
8515//==============================================================================
8516
8517static int VStereo (Draw_Interpretor& theDI,
8518 Standard_Integer theArgNb,
8519 const char** theArgVec)
8520{
f978241f 8521 Handle(V3d_View) aView = ViewerTest::CurrentView();
b5ac8292 8522 if (theArgNb < 2)
8523 {
b5ac8292 8524 if (aView.IsNull())
8525 {
f978241f 8526 std::cout << "Error: no active viewer!\n";
b5ac8292 8527 return 0;
8528 }
8529
8530 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
8531 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
bf02aa7d 8532 if (isActive)
8533 {
8534 TCollection_AsciiString aMode;
8535 switch (aView->RenderingParams().StereoMode)
8536 {
8537 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
8538 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
8539 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
8540 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
8541 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
8542 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
8543 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
8544 case Graphic3d_StereoMode_Anaglyph :
8545 aMode = "anaglyph";
8546 switch (aView->RenderingParams().AnaglyphFilter)
8547 {
8548 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
8549 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
8550 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
8551 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
8552 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
8553 default: break;
8554 }
8555 default: break;
8556 }
8557 theDI << "Mode " << aMode << "\n";
8558 }
b5ac8292 8559 return 0;
8560 }
8561
f978241f 8562 Handle(Graphic3d_Camera) aCamera;
8563 Graphic3d_RenderingParams* aParams = NULL;
8564 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
8565 if (!aView.IsNull())
8566 {
8567 aParams = &aView->ChangeRenderingParams();
8568 aMode = aParams->StereoMode;
8569 aCamera = aView->Camera();
8570 }
8571
8572 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
8573 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
8574 {
8575 Standard_CString anArg = theArgVec[anArgIter];
8576 TCollection_AsciiString aFlag (anArg);
8577 aFlag.LowerCase();
8578 if (anUpdateTool.parseRedrawMode (aFlag))
8579 {
8580 continue;
8581 }
8582 else if (aFlag == "0"
8583 || aFlag == "off")
8584 {
8585 if (++anArgIter < theArgNb)
8586 {
8587 std::cout << "Error: wrong number of arguments!\n";
8588 return 1;
8589 }
8590
8591 if (!aCamera.IsNull()
8592 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
8593 {
8594 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
8595 }
8596 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
8597 return 0;
8598 }
8599 else if (aFlag == "1"
8600 || aFlag == "on")
8601 {
8602 if (++anArgIter < theArgNb)
8603 {
8604 std::cout << "Error: wrong number of arguments!\n";
8605 return 1;
8606 }
8607
8608 if (!aCamera.IsNull())
8609 {
8610 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
8611 }
8612 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
8613 return 0;
8614 }
8615 else if (aFlag == "-reverse"
8616 || aFlag == "-reversed"
8617 || aFlag == "-swap")
8618 {
8619 Standard_Boolean toEnable = Standard_True;
8620 if (++anArgIter < theArgNb
a5565a3c 8621 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 8622 {
8623 --anArgIter;
8624 }
8625 aParams->ToReverseStereo = toEnable;
8626 }
8627 else if (aFlag == "-noreverse"
8628 || aFlag == "-noswap")
8629 {
8630 Standard_Boolean toDisable = Standard_True;
8631 if (++anArgIter < theArgNb
a5565a3c 8632 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
f978241f 8633 {
8634 --anArgIter;
8635 }
8636 aParams->ToReverseStereo = !toDisable;
8637 }
8638 else if (aFlag == "-mode"
8639 || aFlag == "-stereomode")
8640 {
8641 if (++anArgIter >= theArgNb
8642 || !parseStereoMode (theArgVec[anArgIter], aMode))
8643 {
8644 std::cout << "Error: syntax error at '" << anArg << "'\n";
8645 return 1;
8646 }
8647
8648 if (aMode == Graphic3d_StereoMode_QuadBuffer)
8649 {
8650 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
8651 }
8652 }
8653 else if (aFlag == "-anaglyph"
8654 || aFlag == "-anaglyphfilter")
8655 {
8656 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
8657 if (++anArgIter >= theArgNb
8658 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
8659 {
8660 std::cout << "Error: syntax error at '" << anArg << "'\n";
8661 return 1;
8662 }
8663
8664 aMode = Graphic3d_StereoMode_Anaglyph;
8665 aParams->AnaglyphFilter = aFilter;
8666 }
8667 else if (parseStereoMode (anArg, aMode)) // short syntax
8668 {
8669 if (aMode == Graphic3d_StereoMode_QuadBuffer)
8670 {
8671 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
8672 }
8673 }
8674 else
8675 {
8676 std::cout << "Error: syntax error at '" << anArg << "'\n";
8677 return 1;
8678 }
8679 }
8680
8681 if (!aView.IsNull())
8682 {
8683 aParams->StereoMode = aMode;
8684 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
8685 }
b5ac8292 8686 return 0;
8687}
8688
392ac980 8689//===============================================================================================
8690//function : VDefaults
8691//purpose :
8692//===============================================================================================
8693static int VDefaults (Draw_Interpretor& theDi,
8694 Standard_Integer theArgsNb,
8695 const char** theArgVec)
8696{
8697 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
8698 if (aCtx.IsNull())
8699 {
8700 std::cerr << "No active viewer!\n";
8701 return 1;
8702 }
8703
8704 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
8705 if (theArgsNb < 2)
8706 {
8707 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
8708 {
8709 theDi << "DeflType: relative\n"
8710 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
8711 }
8712 else
8713 {
8714 theDi << "DeflType: absolute\n"
8715 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
8716 }
8717 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
4c513386 8718 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
392ac980 8719 return 0;
8720 }
8721
8722 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
8723 {
8724 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4c513386 8725 anArg.UpperCase();
8726 if (anArg == "-ABSDEFL"
8727 || anArg == "-ABSOLUTEDEFLECTION"
8728 || anArg == "-DEFL"
8729 || anArg == "-DEFLECTION")
392ac980 8730 {
4c513386 8731 if (++anArgIter >= theArgsNb)
8732 {
8733 std::cout << "Error: wrong syntax at " << anArg << "\n";
8734 return 1;
8735 }
392ac980 8736 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
4c513386 8737 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
392ac980 8738 }
4c513386 8739 else if (anArg == "-RELDEFL"
8740 || anArg == "-RELATIVEDEFLECTION"
8741 || anArg == "-DEVCOEFF"
8742 || anArg == "-DEVIATIONCOEFF"
8743 || anArg == "-DEVIATIONCOEFFICIENT")
392ac980 8744 {
4c513386 8745 if (++anArgIter >= theArgsNb)
8746 {
8747 std::cout << "Error: wrong syntax at " << anArg << "\n";
8748 return 1;
8749 }
392ac980 8750 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
4c513386 8751 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
392ac980 8752 }
4c513386 8753 else if (anArg == "-ANGDEFL"
8754 || anArg == "-ANGULARDEFL"
8755 || anArg == "-ANGULARDEFLECTION")
392ac980 8756 {
4c513386 8757 if (++anArgIter >= theArgsNb)
8758 {
8759 std::cout << "Error: wrong syntax at " << anArg << "\n";
8760 return 1;
8761 }
392ac980 8762 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
4c513386 8763 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
8764 }
385c43e7 8765 else if (anArg == "-AUTOTR"
8766 || anArg == "-AUTOTRIANG"
8767 || anArg == "-AUTOTRIANGULATION")
4c513386 8768 {
8769 if (++anArgIter >= theArgsNb)
8770 {
8771 std::cout << "Error: wrong syntax at " << anArg << "\n";
8772 return 1;
8773 }
8774 TCollection_AsciiString aValue (theArgVec[anArgIter]);
8775 aValue.LowerCase();
8776 if (aValue == "on"
8777 || aValue == "1")
8778 {
8779 aDefParams->SetAutoTriangulation (Standard_True);
8780 }
8781 else if (aValue == "off"
8782 || aValue == "0")
8783 {
8784 aDefParams->SetAutoTriangulation (Standard_False);
8785 }
392ac980 8786 }
8787 else
8788 {
8789 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
8790 }
8791 }
8792
8793 return 0;
8794}
8795
12381341 8796//! Auxiliary method
8797inline void addLight (const Handle(V3d_Light)& theLightNew,
8798 const Standard_Boolean theIsGlobal)
8799{
8800 if (theLightNew.IsNull())
8801 {
8802 return;
8803 }
8804
8805 if (theIsGlobal)
8806 {
8807 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
8808 }
8809 else
8810 {
8811 ViewerTest::CurrentView()->SetLightOn (theLightNew);
8812 }
8813}
8814
8815//! Auxiliary method
8816inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
8817{
8818 TCollection_AsciiString anArgNextCase (theArgNext);
8819 anArgNextCase.UpperCase();
8820 if (anArgNextCase.Length() > 5
8821 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
8822 {
8823 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
8824 }
8825 else
8826 {
8827 return theArgNext.IntegerValue();
8828 }
8829}
8830
8831//===============================================================================================
8832//function : VLight
8833//purpose :
8834//===============================================================================================
8835static int VLight (Draw_Interpretor& theDi,
8836 Standard_Integer theArgsNb,
8837 const char** theArgVec)
8838{
8839 Handle(V3d_View) aView = ViewerTest::CurrentView();
8840 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
8841 if (aView.IsNull()
8842 || aViewer.IsNull())
8843 {
8844 std::cerr << "No active viewer!\n";
8845 return 1;
8846 }
8847
ee2be2a8 8848 Standard_Real anXYZ[3] = {};
8849 Standard_Real anAtten[2] = {};
12381341 8850 if (theArgsNb < 2)
8851 {
8852 // print lights info
8853 Standard_Integer aLightId = 0;
6a24c6de 8854 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
12381341 8855 {
6a24c6de 8856 Handle(V3d_Light) aLight = aLightIter.Value();
12381341 8857 const Quantity_Color aColor = aLight->Color();
8858 theDi << "Light" << aLightId << "\n";
8859 switch (aLight->Type())
8860 {
8861 case V3d_AMBIENT:
8862 {
189f85a3 8863 theDi << " Type: Ambient\n";
8864 theDi << " Intensity: " << aLight->Intensity() << "\n";
12381341 8865 break;
8866 }
8867 case V3d_DIRECTIONAL:
8868 {
8869 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
189f85a3 8870 theDi << " Type: Directional\n";
8871 theDi << " Intensity: " << aLight->Intensity() << "\n";
8872 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
8873 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
12381341 8874 if (!aLightDir.IsNull())
8875 {
8876 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
189f85a3 8877 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
12381341 8878 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
189f85a3 8879 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
12381341 8880 }
8881 break;
8882 }
8883 case V3d_POSITIONAL:
8884 {
8885 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
189f85a3 8886 theDi << " Type: Positional\n";
8887 theDi << " Intensity: " << aLight->Intensity() << "\n";
8888 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
8889 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
12381341 8890 if (!aLightPos.IsNull())
8891 {
8892 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
189f85a3 8893 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
12381341 8894 aLightPos->Attenuation (anAtten[0], anAtten[1]);
189f85a3 8895 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
12381341 8896 }
8897 break;
8898 }
8899 case V3d_SPOT:
8900 {
8901 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
189f85a3 8902 theDi << " Type: Spot\n";
8903 theDi << " Intensity: " << aLight->Intensity() << "\n";
8904 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
12381341 8905 if (!aLightSpot.IsNull())
8906 {
8907 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
189f85a3 8908 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
12381341 8909 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
189f85a3 8910 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
12381341 8911 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
189f85a3 8912 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
8913 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
8914 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
12381341 8915 }
8916 break;
8917 }
8918 default:
8919 {
189f85a3 8920 theDi << " Type: UNKNOWN\n";
12381341 8921 break;
8922 }
8923 }
8924 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
8925 }
8926 }
8927
8928 Handle(V3d_Light) aLightNew;
8929 Handle(V3d_Light) aLightOld;
8930 Standard_Boolean isGlobal = Standard_True;
8931 Standard_Boolean toCreate = Standard_False;
8932 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
8933 {
8934 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
8935 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
8936 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
8937 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
8938 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
8939
8940 TCollection_AsciiString aName, aValue;
8941 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
8942 TCollection_AsciiString anArgCase (anArg);
8943 anArgCase.UpperCase();
8944 if (anArgCase.IsEqual ("NEW")
8945 || anArgCase.IsEqual ("ADD")
8946 || anArgCase.IsEqual ("CREATE"))
8947 {
8948 toCreate = Standard_True;
8949 }
8950 else if (anArgCase.IsEqual ("GLOB")
8951 || anArgCase.IsEqual ("GLOBAL"))
8952 {
8953 isGlobal = Standard_True;
8954 }
8955 else if (anArgCase.IsEqual ("LOC")
8956 || anArgCase.IsEqual ("LOCAL"))
8957 {
8958 isGlobal = Standard_False;
8959 }
4fe9ad57 8960 else if (anArgCase.IsEqual ("DEF")
8961 || anArgCase.IsEqual ("DEFAULTS"))
8962 {
8963 toCreate = Standard_False;
8964 aViewer->SetDefaultLights();
8965 }
8966 else if (anArgCase.IsEqual ("CLR")
8967 || anArgCase.IsEqual ("CLEAR"))
8968 {
8969 toCreate = Standard_False;
6a24c6de 8970 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
4fe9ad57 8971 {
6a24c6de 8972 Handle(V3d_Light) aLight = aLightIter.Value();
8973 aViewer->DelLight (aLight);
8974 aLightIter = aView->ActiveLightIterator();
4fe9ad57 8975 }
8976 }
12381341 8977 else if (anArgCase.IsEqual ("AMB")
8978 || anArgCase.IsEqual ("AMBIENT")
8979 || anArgCase.IsEqual ("AMBLIGHT"))
8980 {
8981 addLight (aLightNew, isGlobal);
8982 if (!toCreate)
8983 {
8984 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8985 return 1;
8986 }
8987 toCreate = Standard_False;
8988 aLightNew = new V3d_AmbientLight (aViewer);
8989 }
8990 else if (anArgCase.IsEqual ("DIRECTIONAL")
8991 || anArgCase.IsEqual ("DIRLIGHT"))
8992 {
8993 addLight (aLightNew, isGlobal);
8994 if (!toCreate)
8995 {
8996 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8997 return 1;
8998 }
8999 toCreate = Standard_False;
9000 aLightNew = new V3d_DirectionalLight (aViewer);
9001 }
9002 else if (anArgCase.IsEqual ("SPOT")
9003 || anArgCase.IsEqual ("SPOTLIGHT"))
9004 {
9005 addLight (aLightNew, isGlobal);
9006 if (!toCreate)
9007 {
9008 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9009 return 1;
9010 }
9011 toCreate = Standard_False;
9012 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
9013 }
9014 else if (anArgCase.IsEqual ("POSLIGHT")
9015 || anArgCase.IsEqual ("POSITIONAL"))
9016 {
9017 addLight (aLightNew, isGlobal);
9018 if (!toCreate)
9019 {
9020 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9021 return 1;
9022 }
9023 toCreate = Standard_False;
9024 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
9025 }
9026 else if (anArgCase.IsEqual ("CHANGE"))
9027 {
9028 addLight (aLightNew, isGlobal);
9029 aLightNew.Nullify();
9030 if (++anArgIt >= theArgsNb)
9031 {
9032 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9033 return 1;
9034 }
9035
9036 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
9037 Standard_Integer aLightIt = 0;
6a24c6de 9038 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
12381341 9039 {
9040 if (aLightIt == aLightId)
9041 {
6a24c6de 9042 aLightOld = aLightIter.Value();
12381341 9043 break;
9044 }
9045 }
9046
9047 if (aLightOld.IsNull())
9048 {
9049 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
9050 return 1;
9051 }
9052 }
9053 else if (anArgCase.IsEqual ("DEL")
9054 || anArgCase.IsEqual ("DELETE"))
9055 {
9056 Handle(V3d_Light) aLightDel;
9057 if (++anArgIt >= theArgsNb)
9058 {
9059 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9060 return 1;
9061 }
9062
9063 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9064 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
9065 Standard_Integer aLightIt = 0;
6a24c6de 9066 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
12381341 9067 {
6a24c6de 9068 aLightDel = aLightIter.Value();
12381341 9069 if (aLightIt == aLightDelId)
9070 {
9071 break;
9072 }
9073 }
9074 if (!aLightDel.IsNull())
9075 {
9076 aViewer->DelLight (aLightDel);
9077 }
9078 }
9079 else if (anArgCase.IsEqual ("COLOR")
9080 || anArgCase.IsEqual ("COLOUR"))
9081 {
9082 if (++anArgIt >= theArgsNb)
9083 {
9084 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9085 return 1;
9086 }
9087
9088 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9089 anArgNext.UpperCase();
9090 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
9091 if (!aLightCurr.IsNull())
9092 {
9093 aLightCurr->SetColor (aColor);
9094 }
9095 }
9096 else if (anArgCase.IsEqual ("POS")
9097 || anArgCase.IsEqual ("POSITION"))
9098 {
9099 if ((anArgIt + 3) >= theArgsNb)
9100 {
9101 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9102 return 1;
9103 }
9104
9105 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9106 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9107 anXYZ[2] = Atof (theArgVec[++anArgIt]);
9108 if (!aLightDir.IsNull())
9109 {
9110 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
9111 }
9112 else if (!aLightPos.IsNull())
9113 {
9114 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
9115 }
9116 else if (!aLightSpot.IsNull())
9117 {
9118 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
9119 }
9120 else
9121 {
9122 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9123 return 1;
9124 }
9125 }
9126 else if (anArgCase.IsEqual ("DIR")
9127 || anArgCase.IsEqual ("DIRECTION"))
9128 {
9129 if ((anArgIt + 3) >= theArgsNb)
9130 {
9131 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9132 return 1;
9133 }
9134
9135 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9136 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9137 anXYZ[2] = Atof (theArgVec[++anArgIt]);
9138 if (!aLightDir.IsNull())
9139 {
9140 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
9141 }
9142 else if (!aLightSpot.IsNull())
9143 {
9144 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
9145 }
9146 else
9147 {
9148 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9149 return 1;
9150 }
9151 }
189f85a3 9152 else if (anArgCase.IsEqual ("SM")
9153 || anArgCase.IsEqual ("SMOOTHNESS"))
9154 {
9155 if (++anArgIt >= theArgsNb)
9156 {
9157 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9158 return 1;
9159 }
9160
9161 Standard_Real aSmoothness = Atof (theArgVec[anArgIt]);
9162
9163 if (fabs (aSmoothness) < Precision::Confusion())
9164 {
9165 aLightCurr->SetIntensity (1.f);
9166 }
9167 else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion())
9168 {
9169 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
9170 }
9171 else
9172 {
9173 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
9174 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
9175 }
9176
9177 if (!aLightPos.IsNull())
9178 {
9179 aLightPos->SetSmoothRadius (aSmoothness);
9180 }
9181 else if (!aLightDir.IsNull())
9182 {
9183 aLightDir->SetSmoothAngle (aSmoothness);
9184 }
9185 }
9186 else if (anArgCase.IsEqual ("INT")
9187 || anArgCase.IsEqual ("INTENSITY"))
9188 {
9189 if (++anArgIt >= theArgsNb)
9190 {
9191 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9192 return 1;
9193 }
9194
9195 Standard_Real aIntensity = Atof (theArgVec[anArgIt]);
9196
9197 if (!aLightCurr.IsNull())
9198 {
9199 aLightCurr->SetIntensity (aIntensity);
9200 }
9201 }
4fe9ad57 9202 else if (anArgCase.IsEqual ("ANG")
9203 || anArgCase.IsEqual ("ANGLE"))
9204 {
9205 if (++anArgIt >= theArgsNb)
9206 {
9207 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9208 return 1;
9209 }
9210
9211 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
9212
9213 if (!aLightSpot.IsNull())
9214 {
9215 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
9216 }
9217 }
12381341 9218 else if (anArgCase.IsEqual ("CONSTATTEN")
9219 || anArgCase.IsEqual ("CONSTATTENUATION"))
9220 {
9221 if (++anArgIt >= theArgsNb)
9222 {
9223 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9224 return 1;
9225 }
9226
9227 if (!aLightPos.IsNull())
9228 {
9229 aLightPos->Attenuation (anAtten[0], anAtten[1]);
9230 anAtten[0] = Atof (theArgVec[anArgIt]);
9231 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
9232 }
9233 else if (!aLightSpot.IsNull())
9234 {
9235 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
9236 anAtten[0] = Atof (theArgVec[anArgIt]);
9237 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
9238 }
9239 else
9240 {
9241 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9242 return 1;
9243 }
9244 }
9245 else if (anArgCase.IsEqual ("LINATTEN")
9246 || anArgCase.IsEqual ("LINEARATTEN")
9247 || anArgCase.IsEqual ("LINEARATTENUATION"))
9248 {
9249 if (++anArgIt >= theArgsNb)
9250 {
9251 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9252 return 1;
9253 }
9254
9255 if (!aLightPos.IsNull())
9256 {
9257 aLightPos->Attenuation (anAtten[0], anAtten[1]);
9258 anAtten[1] = Atof (theArgVec[anArgIt]);
9259 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
9260 }
9261 else if (!aLightSpot.IsNull())
9262 {
9263 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
9264 anAtten[1] = Atof (theArgVec[anArgIt]);
9265 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
9266 }
9267 else
9268 {
9269 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9270 return 1;
9271 }
9272 }
9273 else if (anArgCase.IsEqual ("EXP")
9274 || anArgCase.IsEqual ("EXPONENT")
9275 || anArgCase.IsEqual ("SPOTEXP")
9276 || anArgCase.IsEqual ("SPOTEXPONENT"))
9277 {
9278 if (++anArgIt >= theArgsNb)
9279 {
9280 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9281 return 1;
9282 }
9283
9284 if (!aLightSpot.IsNull())
9285 {
9286 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
9287 }
9288 else
9289 {
9290 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9291 return 1;
9292 }
9293 }
9294 else if (anArgCase.IsEqual ("HEAD")
9295 || anArgCase.IsEqual ("HEADLIGHT"))
9296 {
9297 if (++anArgIt >= theArgsNb)
9298 {
9299 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9300 return 1;
9301 }
9302
9303 if (aLightAmb.IsNull()
9304 && !aLightCurr.IsNull())
9305 {
9306 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
9307 }
9308 else
9309 {
9310 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9311 return 1;
9312 }
9313 }
9314 else
9315 {
9316 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
9317 }
9318 }
9319
9320 addLight (aLightNew, isGlobal);
9321 aViewer->UpdateLights();
9322
9323 return 0;
9324}
9325
e276548b 9326//=======================================================================
bc8c79bb 9327//function : VRenderParams
9328//purpose : Enables/disables rendering features
e276548b 9329//=======================================================================
9330
bc8c79bb 9331static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
9332 Standard_Integer theArgNb,
9333 const char** theArgVec)
e276548b 9334{
7ae4a307 9335 Handle(V3d_View) aView = ViewerTest::CurrentView();
9336 if (aView.IsNull())
e276548b 9337 {
bc8c79bb 9338 std::cerr << "Error: no active viewer!\n";
e276548b 9339 return 1;
9340 }
bc8c79bb 9341
9342 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
6b62b2da 9343 TCollection_AsciiString aCmdName (theArgVec[0]);
9344 aCmdName.LowerCase();
9345 if (aCmdName == "vraytrace")
9346 {
9347 if (theArgNb == 1)
9348 {
9349 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
9350 return 0;
9351 }
9352 else if (theArgNb == 2)
9353 {
9354 TCollection_AsciiString aValue (theArgVec[1]);
9355 aValue.LowerCase();
9356 if (aValue == "on"
9357 || aValue == "1")
9358 {
9359 aParams.Method = Graphic3d_RM_RAYTRACING;
9360 aView->Redraw();
9361 return 0;
9362 }
9363 else if (aValue == "off"
9364 || aValue == "0")
9365 {
9366 aParams.Method = Graphic3d_RM_RASTERIZATION;
9367 aView->Redraw();
9368 return 0;
9369 }
9370 else
9371 {
9372 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
9373 return 1;
9374 }
9375 }
9376 else
9377 {
9378 std::cout << "Error: wrong number of arguments\n";
9379 return 1;
9380 }
9381 }
bc8c79bb 9382
9383 if (theArgNb < 2)
e276548b 9384 {
bc8c79bb 9385 theDI << "renderMode: ";
9386 switch (aParams.Method)
9387 {
9388 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
9389 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
9390 }
9391 theDI << "\n";
a1073ae2 9392 theDI << "transparency: ";
9393 switch (aParams.TransparencyMethod)
9394 {
9395 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
9396 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
9397 << TCollection_AsciiString (aParams.OitDepthFactor); break;
9398 }
9399 theDI << "\n";
b4327ba8 9400 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
56689b27 9401 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
b4327ba8 9402 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
9403 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
9404 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
9405 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
9406 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
9407 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
9408 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
9409 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
9410 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
9411 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
b09447ed 9412 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
4eaaf9d8 9413 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
8625ef7e 9414 theDI << "shadingModel: ";
9415 switch (aView->ShadingModel())
9416 {
9417 case V3d_COLOR: theDI << "color"; break;
9418 case V3d_FLAT: theDI << "flat"; break;
9419 case V3d_GOURAUD: theDI << "gouraud"; break;
9420 case V3d_PHONG: theDI << "phong"; break;
9421 }
9422 theDI << "\n";
bc8c79bb 9423 return 0;
e276548b 9424 }
9425
bc8c79bb 9426 Standard_Boolean toPrint = Standard_False;
8625ef7e 9427 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
e276548b 9428 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9429 {
bc8c79bb 9430 Standard_CString anArg (theArgVec[anArgIter]);
9431 TCollection_AsciiString aFlag (anArg);
9432 aFlag.LowerCase();
8625ef7e 9433 if (anUpdateTool.parseRedrawMode (aFlag))
9434 {
9435 continue;
9436 }
9437 else if (aFlag == "-echo"
9438 || aFlag == "-print")
e276548b 9439 {
bc8c79bb 9440 toPrint = Standard_True;
8625ef7e 9441 anUpdateTool.Invalidate();
e276548b 9442 }
bc8c79bb 9443 else if (aFlag == "-mode"
9444 || aFlag == "-rendermode"
9445 || aFlag == "-render_mode")
e276548b 9446 {
bc8c79bb 9447 if (toPrint)
9448 {
9449 switch (aParams.Method)
9450 {
9451 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
9452 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
9453 }
9454 continue;
9455 }
e276548b 9456 else
bc8c79bb 9457 {
9458 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9459 return 1;
9460 }
9461 }
9462 else if (aFlag == "-ray"
9463 || aFlag == "-raytrace")
9464 {
9465 if (toPrint)
9466 {
9467 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
9468 continue;
9469 }
9470
9471 aParams.Method = Graphic3d_RM_RAYTRACING;
e276548b 9472 }
bc8c79bb 9473 else if (aFlag == "-rast"
9474 || aFlag == "-raster"
9475 || aFlag == "-rasterization")
e276548b 9476 {
bc8c79bb 9477 if (toPrint)
9478 {
9479 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
9480 continue;
9481 }
9482
9483 aParams.Method = Graphic3d_RM_RASTERIZATION;
9484 }
3c4b62a4 9485 else if (aFlag == "-msaa")
9486 {
9487 if (toPrint)
9488 {
9489 theDI << aParams.NbMsaaSamples << " ";
9490 continue;
9491 }
9492 else if (++anArgIter >= theArgNb)
9493 {
9494 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9495 return 1;
9496 }
9497
9498 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
9499 if (aNbSamples < 0)
9500 {
9501 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
9502 return 1;
9503 }
9504 else
9505 {
9506 aParams.NbMsaaSamples = aNbSamples;
9507 }
9508 }
a1073ae2 9509 else if (aFlag == "-oit")
9510 {
9511 if (toPrint)
9512 {
9513 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
9514 {
9515 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
9516 }
9517 else
9518 {
9519 theDI << "off" << " ";
9520 }
9521 continue;
9522 }
9523 else if (++anArgIter >= theArgNb)
9524 {
9525 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9526 return 1;
9527 }
9528
9529 TCollection_AsciiString aParam = theArgVec[anArgIter];
9530 aParam.LowerCase();
9531 if (aParam.IsRealValue())
9532 {
9533 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
9534 if (aWeight < 0.f || aWeight > 1.f)
9535 {
9536 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
9537 return 1;
9538 }
9539
9540 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
9541 aParams.OitDepthFactor = aWeight;
9542 }
9543 else if (aParam == "off")
9544 {
9545 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
9546 }
9547 else
9548 {
9549 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9550 return 1;
9551 }
9552 }
56689b27 9553 else if (aFlag == "-rendscale"
9554 || aFlag == "-renderscale"
9555 || aFlag == "-renderresolutionscale")
9556 {
9557 if (toPrint)
9558 {
9559 theDI << aParams.RenderResolutionScale << " ";
9560 continue;
9561 }
9562 else if (++anArgIter >= theArgNb)
9563 {
9564 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9565 return 1;
9566 }
9567
9568 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
9569 if (aScale < 0.01)
9570 {
9571 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
9572 return 1;
9573 }
9574 else
9575 {
9576 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
9577 }
9578 }
bc8c79bb 9579 else if (aFlag == "-raydepth"
9580 || aFlag == "-ray_depth")
9581 {
9582 if (toPrint)
9583 {
9584 theDI << aParams.RaytracingDepth << " ";
9585 continue;
9586 }
9587 else if (++anArgIter >= theArgNb)
9588 {
9589 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9590 return 1;
9591 }
9592
9593 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
189f85a3 9594
9595 // We allow RaytracingDepth be more than 10 in case of GI enabled
9596 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
bc8c79bb 9597 {
9598 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
9599 return 1;
9600 }
e276548b 9601 else
bc8c79bb 9602 {
9603 aParams.RaytracingDepth = aDepth;
9604 }
9605 }
9606 else if (aFlag == "-shad"
9607 || aFlag == "-shadows")
9608 {
9609 if (toPrint)
9610 {
9611 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
9612 continue;
9613 }
9614
9615 Standard_Boolean toEnable = Standard_True;
9616 if (++anArgIter < theArgNb
a5565a3c 9617 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 9618 {
9619 --anArgIter;
9620 }
9621 aParams.IsShadowEnabled = toEnable;
9622 }
9623 else if (aFlag == "-refl"
9624 || aFlag == "-reflections")
9625 {
9626 if (toPrint)
9627 {
9628 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
9629 continue;
9630 }
9631
9632 Standard_Boolean toEnable = Standard_True;
9633 if (++anArgIter < theArgNb
a5565a3c 9634 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 9635 {
9636 --anArgIter;
9637 }
9638 aParams.IsReflectionEnabled = toEnable;
9639 }
9640 else if (aFlag == "-fsaa")
9641 {
9642 if (toPrint)
9643 {
9644 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
9645 continue;
9646 }
9647
9648 Standard_Boolean toEnable = Standard_True;
9649 if (++anArgIter < theArgNb
a5565a3c 9650 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 9651 {
9652 --anArgIter;
9653 }
9654 aParams.IsAntialiasingEnabled = toEnable;
9655 }
9656 else if (aFlag == "-gleam")
9657 {
9658 if (toPrint)
9659 {
9660 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
9661 continue;
9662 }
9663
9664 Standard_Boolean toEnable = Standard_True;
9665 if (++anArgIter < theArgNb
a5565a3c 9666 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 9667 {
9668 --anArgIter;
9669 }
9670 aParams.IsTransparentShadowEnabled = toEnable;
e276548b 9671 }
189f85a3 9672 else if (aFlag == "-gi")
9673 {
9674 if (toPrint)
9675 {
9676 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
9677 continue;
9678 }
9679
9680 Standard_Boolean toEnable = Standard_True;
9681 if (++anArgIter < theArgNb
a5565a3c 9682 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
189f85a3 9683 {
9684 --anArgIter;
9685 }
9686 aParams.IsGlobalIlluminationEnabled = toEnable;
9687 if (!toEnable)
9688 {
9689 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
9690 }
9691 }
8c820969 9692 else if (aFlag == "-blockedrng"
9693 || aFlag == "-brng")
9694 {
9695 if (toPrint)
9696 {
9697 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
9698 continue;
9699 }
9700
9701 Standard_Boolean toEnable = Standard_True;
9702 if (++anArgIter < theArgNb
a5565a3c 9703 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8c820969 9704 {
9705 --anArgIter;
9706 }
9707 aParams.CoherentPathTracingMode = toEnable;
9708 }
b09447ed 9709 else if (aFlag == "-maxrad")
9710 {
9711 if (toPrint)
9712 {
9713 theDI << aParams.RadianceClampingValue << " ";
9714 continue;
9715 }
9716 else if (++anArgIter >= theArgNb)
9717 {
9718 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9719 return 1;
9720 }
9721
9722 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
9723 if (!aMaxRadStr.IsRealValue())
9724 {
9725 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9726 return 1;
9727 }
9728
9729 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
9730 if (aMaxRadiance <= 0.0)
9731 {
9732 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
9733 return 1;
9734 }
9735 else
9736 {
9737 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
9738 }
9739 }
3a9b5dc8 9740 else if (aFlag == "-iss")
9741 {
9742 if (toPrint)
9743 {
9744 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
9745 continue;
9746 }
9747
9748 Standard_Boolean toEnable = Standard_True;
9749 if (++anArgIter < theArgNb
9750 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9751 {
9752 --anArgIter;
9753 }
9754 aParams.AdaptiveScreenSampling = toEnable;
9755 }
9756 else if (aFlag == "-issd")
9757 {
9758 if (toPrint)
9759 {
9760 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
9761 continue;
9762 }
9763
9764 Standard_Boolean toEnable = Standard_True;
9765 if (++anArgIter < theArgNb
9766 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9767 {
9768 --anArgIter;
9769 }
9770 aParams.ShowSamplingTiles = toEnable;
9771 }
4eaaf9d8 9772 else if (aFlag == "-nbtiles")
9773 {
9774 if (toPrint)
9775 {
9776 theDI << aParams.NbRayTracingTiles << " ";
9777 continue;
9778 }
9779 else if (++anArgIter >= theArgNb)
9780 {
9781 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9782 return 1;
9783 }
9784
9785 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
9786
9787 if (aNbTiles < 64)
9788 {
9789 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
9790 std::cerr << "Specify value in range [64, 1024].\n";
9791 return 1;
9792 }
9793 else
9794 {
9795 aParams.NbRayTracingTiles = aNbTiles;
9796 }
9797 }
189f85a3 9798 else if (aFlag == "-env")
9799 {
9800 if (toPrint)
9801 {
9802 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
9803 continue;
9804 }
9805
9806 Standard_Boolean toEnable = Standard_True;
9807 if (++anArgIter < theArgNb
a5565a3c 9808 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
189f85a3 9809 {
9810 --anArgIter;
9811 }
9812 aParams.UseEnvironmentMapBackground = toEnable;
9813 }
b4327ba8 9814 else if (aFlag == "-twoside")
9815 {
9816 if (toPrint)
9817 {
9818 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
9819 continue;
9820 }
9821
9822 Standard_Boolean toEnable = Standard_True;
9823 if (++anArgIter < theArgNb
9824 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9825 {
9826 --anArgIter;
9827 }
9828 aParams.TwoSidedBsdfModels = toEnable;
9829 }
8625ef7e 9830 else if (aFlag == "-shademodel"
9831 || aFlag == "-shadingmodel"
9832 || aFlag == "-shading")
9833 {
9834 if (toPrint)
9835 {
9836 switch (aView->ShadingModel())
9837 {
9838 case V3d_COLOR: theDI << "color "; break;
9839 case V3d_FLAT: theDI << "flat "; break;
9840 case V3d_GOURAUD: theDI << "gouraud "; break;
9841 case V3d_PHONG: theDI << "phong "; break;
9842 }
9843 continue;
9844 }
9845
9846 if (++anArgIter >= theArgNb)
9847 {
9848 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9849 }
9850
9851 TCollection_AsciiString aMode (theArgVec[anArgIter]);
9852 aMode.LowerCase();
9853 if (aMode == "color"
9854 || aMode == "none")
9855 {
9856 aView->SetShadingModel (V3d_COLOR);
9857 }
9858 else if (aMode == "flat"
9859 || aMode == "facet")
9860 {
9861 aView->SetShadingModel (V3d_FLAT);
9862 }
9863 else if (aMode == "gouraud"
9864 || aMode == "vertex"
9865 || aMode == "vert")
9866 {
9867 aView->SetShadingModel (V3d_GOURAUD);
9868 }
9869 else if (aMode == "phong"
9870 || aMode == "fragment"
9871 || aMode == "frag"
9872 || aMode == "pixel")
9873 {
9874 aView->SetShadingModel (V3d_PHONG);
9875 }
9876 else
9877 {
9878 std::cout << "Error: unknown shading model '" << aMode << "'\n";
9879 return 1;
9880 }
9881 }
4b1c8733 9882 else if (aFlag == "-resolution")
9883 {
9884 if (++anArgIter >= theArgNb)
9885 {
9886 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9887 return 1;
9888 }
9889
9890 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
9891 if (aResolution.IsIntegerValue())
9892 {
9893 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
9894 }
9895 else
9896 {
9897 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
9898 return 1;
9899 }
9900 }
d877e610 9901 else if (aFlag == "-rebuildglsl"
9902 || aFlag == "-rebuild")
9903 {
9904 if (toPrint)
9905 {
9906 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
9907 continue;
9908 }
9909
9910 Standard_Boolean toEnable = Standard_True;
9911 if (++anArgIter < theArgNb
9912 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9913 {
9914 --anArgIter;
9915 }
9916 aParams.RebuildRayTracingShaders = toEnable;
9917 }
b27ab03d 9918 else if (aFlag == "-focal")
9919 {
9920 if (++anArgIter >= theArgNb)
9921 {
9922 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
9923 return 1;
9924 }
9925
9926 TCollection_AsciiString aParam (theArgVec[anArgIter]);
9927 if (aParam.IsRealValue())
9928 {
9929 float aFocalDist = static_cast<float> (aParam.RealValue());
9930 if (aFocalDist < 0)
9931 {
9932 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
9933 return 1;
9934 }
9935 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
9936 }
9937 else
9938 {
9939 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
9940 return 1;
9941 }
9942 }
9943 else if (aFlag == "-aperture")
9944 {
9945 if (++anArgIter >= theArgNb)
9946 {
9947 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
9948 return 1;
9949 }
9950
9951 TCollection_AsciiString aParam(theArgVec[anArgIter]);
9952 if (aParam.IsRealValue())
9953 {
9954 float aApertureSize = static_cast<float> (aParam.RealValue());
9955 if (aApertureSize < 0)
9956 {
9957 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
9958 return 1;
9959 }
9960 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
9961 }
9962 else
9963 {
9964 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
9965 return 1;
9966 }
9967 }
eb85ed36 9968 else if (aFlag == "-exposure")
9969 {
9970 if (++anArgIter >= theArgNb)
9971 {
9972 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
9973 return 1;
9974 }
9975
9976 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
9977 if (anExposure.IsRealValue())
9978 {
9979 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
9980 }
9981 else
9982 {
9983 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
9984 return 1;
9985 }
9986 }
9987 else if (aFlag == "-whitepoint")
9988 {
9989 if (++anArgIter >= theArgNb)
9990 {
9991 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
9992 return 1;
9993 }
9994
9995 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
9996 if (aWhitePoint.IsRealValue())
9997 {
9998 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
9999 }
10000 else
10001 {
10002 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10003 return 1;
10004 }
10005 }
10006 else if (aFlag == "-tonemapping")
10007 {
10008 if (++anArgIter >= theArgNb)
10009 {
10010 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10011 return 1;
10012 }
10013
10014 TCollection_AsciiString aMode (theArgVec[anArgIter]);
10015 aMode.LowerCase();
10016
10017 if (aMode == "disabled")
10018 {
10019 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
10020 }
10021 else if (aMode == "filmic")
10022 {
10023 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
10024 }
10025 else
10026 {
10027 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10028 return 1;
10029 }
10030 }
e276548b 10031 else
10032 {
bc8c79bb 10033 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
10034 return 1;
e276548b 10035 }
10036 }
189f85a3 10037
10038 return 0;
10039}
10040
10041//=======================================================================
10042//function : VProgressiveMode
10043//purpose :
10044//=======================================================================
10045#if defined(_WIN32)
10046static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
10047 Standard_Integer /*theNbArgs*/,
10048 const char** /*theArgs*/)
10049{
10050 Handle(V3d_View) aView = ViewerTest::CurrentView();
10051 if (aView.IsNull())
10052 {
10053 std::cerr << "Error: no active viewer!\n";
10054 return 1;
10055 }
10056
10057 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
10058
10059 for (;;)
10060 {
10061 aView->Redraw();
10062
10063 Standard_Boolean toExit = Standard_False;
10064
10065 MSG aMsg;
ad03c234 10066 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
189f85a3 10067 {
10068 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
10069 {
10070 toExit = Standard_True;
10071 }
10072
10073 TranslateMessage (&aMsg);
ad03c234 10074 DispatchMessageW (&aMsg);
189f85a3 10075 }
10076
10077 if (toExit)
10078 {
10079 break;
10080 }
10081 }
10082
e276548b 10083 return 0;
10084}
189f85a3 10085#endif
e276548b 10086
b7cd4ba7 10087//=======================================================================
10088//function : VFrustumCulling
10089//purpose : enables/disables view volume's culling.
10090//=======================================================================
10091static int VFrustumCulling (Draw_Interpretor& theDI,
10092 Standard_Integer theArgNb,
10093 const char** theArgVec)
10094{
10095 Handle(V3d_View) aView = ViewerTest::CurrentView();
10096 if (aView.IsNull())
10097 {
10098 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
10099 return 1;
10100 }
10101
10102 if (theArgNb < 2)
10103 {
10104 theDI << (aView->IsCullingEnabled() ? "on" : "off");
10105 return 0;
10106 }
10107 else if (theArgNb != 2)
10108 {
10109 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
10110 return 1;
10111 }
10112
10113 TCollection_AsciiString aModeStr (theArgVec[1]);
10114 aModeStr.LowerCase();
10115 Standard_Boolean toEnable = 0;
10116 if (aModeStr == "on")
10117 {
10118 toEnable = 1;
10119 }
10120 else if (aModeStr == "off")
10121 {
10122 toEnable = 0;
10123 }
10124 else
10125 {
10126 toEnable = Draw::Atoi (theArgVec[1]) != 0;
10127 }
10128
10129 aView->SetFrustumCulling (toEnable);
10130 aView->Redraw();
10131 return 0;
10132}
10133
c398b00e 10134//=======================================================================
10135//function : VHighlightSelected
10136//purpose :
10137//=======================================================================
10138static int VHighlightSelected (Draw_Interpretor& theDI,
10139 Standard_Integer theArgNb,
10140 const char** theArgVec)
10141{
10142 if (ViewerTest::GetAISContext().IsNull())
10143 {
10144 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
10145 return 1;
10146 }
10147
10148 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
10149
10150 if (theArgNb < 2)
10151 {
10152 theDI << (aContext->ToHilightSelected() ? "on" : "off");
10153 return 0;
10154 }
10155
10156 if (theArgNb != 2)
10157 {
10158 std::cout << theArgVec[0] << " error : wrong number of parameters."
10159 << "Type 'help" << theArgVec[0] << "' for more information.";
10160 return 1;
10161 }
10162
10163 // Parse parameter
10164 TCollection_AsciiString aMode (theArgVec[1]);
10165 aMode.LowerCase();
10166 Standard_Boolean toEnable = Standard_False;
10167 if (aMode.IsEqual ("on"))
10168 {
10169 toEnable = Standard_True;
10170 }
10171 else if (aMode.IsEqual ("off"))
10172 {
10173 toEnable = Standard_False;
10174 }
10175 else
10176 {
10177 toEnable = Draw::Atoi (theArgVec[1]) != 0;
10178 }
10179
10180 if (toEnable != aContext->ToHilightSelected())
10181 {
10182 aContext->SetToHilightSelected (toEnable);
10183
10184 // Move cursor to null position and back to process updating of detection
10185 // and highlighting of selected object immediatly.
10186 Standard_Integer aPixX = 0;
10187 Standard_Integer aPixY = 0;
10188 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
10189
10190 anEventManager->GetCurrentPosition (aPixX, aPixY);
10191 anEventManager->MoveTo (0, 0);
10192 anEventManager->MoveTo (aPixX, aPixY);
10193 }
10194
10195 return 0;
10196}
10197
0717ddc1 10198//=======================================================================
10199//function : VXRotate
10200//purpose :
10201//=======================================================================
10202static Standard_Integer VXRotate (Draw_Interpretor& di,
10203 Standard_Integer argc,
10204 const char ** argv)
10205{
10206 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
10207 if (aContext.IsNull())
10208 {
586db386 10209 di << argv[0] << "ERROR : use 'vinit' command before \n";
0717ddc1 10210 return 1;
10211 }
10212
10213 if (argc != 3)
10214 {
586db386 10215 di << "ERROR : Usage : " << argv[0] << " name angle\n";
0717ddc1 10216 return 1;
10217 }
10218
10219 TCollection_AsciiString aName (argv[1]);
10220 Standard_Real anAngle = Draw::Atof (argv[2]);
10221
10222 // find object
10223 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
10224 Handle(AIS_InteractiveObject) anIObj;
10225 if (!aMap.IsBound2 (aName) )
10226 {
586db386 10227 di << "Use 'vdisplay' before\n";
0717ddc1 10228 return 1;
10229 }
10230 else
10231 {
10232 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
10233
10234 gp_Trsf aTransform;
10235 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
10236 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
10237
10238 aContext->SetLocation (anIObj, aTransform);
10239 aContext->UpdateCurrentViewer();
10240 }
10241
10242 return 0;
10243}
10244
625e1958 10245//===============================================================================================
10246//class : ViewerTest_AISManipulator
10247//purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
10248//===============================================================================================
10249DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
10250
10251class ViewerTest_AISManipulator : public AIS_Manipulator
10252{
10253public:
10254
10255 ViewerTest_AISManipulator() : AIS_Manipulator()
10256 {
10257 GetMapOfAISManipulators().Add (this);
10258 }
10259
10260 virtual ~ViewerTest_AISManipulator()
10261 {
10262 GetMapOfAISManipulators().Remove (this);
10263 }
10264
10265 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
10266};
10267
10268IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
10269IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
10270
10271//===============================================================================================
10272//function : VManipulator
10273//purpose :
10274//===============================================================================================
10275static int VManipulator (Draw_Interpretor& theDi,
10276 Standard_Integer theArgsNb,
10277 const char** theArgVec)
10278{
10279 Handle(V3d_View) aView = ViewerTest::CurrentView();
10280 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10281 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
10282 if (aView.IsNull()
10283 || aViewer.IsNull())
10284 {
10285 std::cerr << "No active viewer!\n";
10286 return 1;
10287 }
10288
10289 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
10290 Standard_Integer anArgIter = 1;
10291 for (; anArgIter < theArgsNb; ++anArgIter)
10292 {
10293 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
10294 }
10295
10296 ViewerTest_CmdParser aCmd;
10297 aCmd.AddDescription ("Manages manipulator for interactive objects:");
10298 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
10299 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
10300 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
10301 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
10302 aCmd.AddOption ("detach", "... - detach manipulator");
10303
10304 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
10305 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
10306 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
10307
10308 aCmd.AddOption ("move", "... x y z - move object");
10309 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
10310 aCmd.AddOption ("scale", "... factor - scale object");
10311
10312 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
10313 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
10314 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
10315 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
10316 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
10317 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
10318 aCmd.AddOption ("size", "... size - set size of manipulator");
10319 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
10320
10321 aCmd.Parse (theArgsNb, theArgVec);
10322
10323 if (aCmd.HasOption ("help"))
10324 {
10325 theDi.PrintHelp (theArgVec[0]);
10326 return 0;
10327 }
10328
10329 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
10330
10331 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
10332
10333 if (aName.IsEmpty())
10334 {
10335 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
10336 return 1;
10337 }
10338
10339 // ----------------------------------
10340 // detach existing manipulator object
10341 // ----------------------------------
10342
10343 if (aCmd.HasOption ("detach"))
10344 {
10345 if (!aMapAIS.IsBound2 (aName))
10346 {
10347 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
10348 return 1;
10349 }
10350
10351 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
10352 if (aManipulator.IsNull())
10353 {
10354 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
10355 return 1;
10356 }
10357
10358 aManipulator->Detach();
10359 aMapAIS.UnBind2 (aName);
0577ae8c 10360 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
625e1958 10361
10362 return 0;
10363 }
10364
10365 // -----------------------------------------------
10366 // find or create manipulator if it does not exist
10367 // -----------------------------------------------
10368
10369 Handle(AIS_Manipulator) aManipulator;
10370 if (!aMapAIS.IsBound2 (aName))
10371 {
10372 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
10373
10374 aManipulator = new ViewerTest_AISManipulator();
10375 aMapAIS.Bind (aManipulator, aName);
10376 }
10377 else
10378 {
10379 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
10380 if (aManipulator.IsNull())
10381 {
10382 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
10383 return 1;
10384 }
10385 }
10386
10387 // -----------------------------------------
10388 // change properties of manipulator instance
10389 // -----------------------------------------
10390
10391 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
10392 {
10393 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
10394 }
10395 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
10396 {
10397 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
10398 }
10399 if (aCmd.HasOption ("followRotation", 1, Standard_True))
10400 {
10401 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
10402 }
10403 if (aCmd.HasOption ("gap", 1, Standard_True))
10404 {
10405 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
10406 }
10407 if (aCmd.HasOption ("part", 3, Standard_True))
10408 {
10409 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
10410 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
10411 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
10412 if (aMode < 1 || aMode > 3)
10413 {
10414 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
10415 return 1;
10416 }
10417
10418 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
10419 }
10420 if (aCmd.HasOption ("pos", 3, Standard_True))
10421 {
10422 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
10423 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
10424 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
10425
10426 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
10427 }
10428 if (aCmd.HasOption ("size", 1, Standard_True))
10429 {
10430 aManipulator->SetSize (aCmd.ArgFloat ("size"));
10431 }
10432 if (aCmd.HasOption ("zoomable", 1, Standard_True))
10433 {
10434 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
10435
10436 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
10437 {
10438 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
10439 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
10440 }
10441 }
10442
10443 // ---------------------------------------------------
10444 // attach, detach or access manipulator from an object
10445 // ---------------------------------------------------
10446
10447 if (aCmd.HasOption ("attach"))
10448 {
10449 // Find an object and attach manipulator to it
10450 if (!aCmd.HasOption ("attach", 1, Standard_True))
10451 {
10452 return 1;
10453 }
10454
10455 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
10456 if (!aMapAIS.IsBound2 (anObjName))
10457 {
10458 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
10459 return 1;
10460 }
10461
10462 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapAIS.Find2 (anObjName));
10463 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
10464 for (; anIt.More(); anIt.Next())
10465 {
10466 if (anIt.Value()->IsAttached()
10467 && anIt.Value()->Object() == anObject)
10468 {
10469 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
10470 return 1;
10471 }
10472 }
10473
10474 AIS_Manipulator::OptionsForAttach anOptions;
10475 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
10476 {
10477 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
10478 }
10479 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
10480 {
10481 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
10482 }
10483 if (aCmd.HasOption ("enableModes", 1, Standard_True))
10484 {
10485 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
10486 }
10487
10488 aManipulator->Attach (anObject, anOptions);
10489 }
10490
10491 // --------------------------------------
10492 // apply transformation using manipulator
10493 // --------------------------------------
10494
10495 if (aCmd.HasOption ("startTransform", 2, Standard_True))
10496 {
10497 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
10498 }
10499 if (aCmd.HasOption ("transform", 2, Standard_True))
10500 {
10501 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
10502 }
10503 if (aCmd.HasOption ("stopTransform"))
10504 {
10505 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
10506
10507 aManipulator->StopTransform (toApply);
10508 }
10509
10510 gp_Trsf aT;
10511 if (aCmd.HasOption ("move", 3, Standard_True))
10512 {
10513 aT.SetTranslationPart (aCmd.ArgVec ("move"));
10514 }
10515 if (aCmd.HasOption ("rotate", 7, Standard_True))
10516 {
10517 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
10518 }
10519 if (aCmd.HasOption ("scale", 1))
10520 {
10521 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
10522 }
10523
10524 if (aT.Form() != gp_Identity)
10525 {
10526 aManipulator->Transform (aT);
10527 }
10528
0577ae8c 10529 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
625e1958 10530
10531 return 0;
10532}
10533
8e5fb5ea 10534//===============================================================================================
10535//function : VSelectionProperties
10536//purpose :
10537//===============================================================================================
10538static int VSelectionProperties (Draw_Interpretor& theDi,
10539 Standard_Integer theArgsNb,
10540 const char** theArgVec)
10541{
10542 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
10543 if (aCtx.IsNull())
10544 {
10545 std::cerr << "No active viewer!\n";
10546 return 1;
10547 }
10548
f838dac4 10549 Standard_Boolean toPrint = theArgsNb == 1;
10550 Standard_Boolean toRedraw = Standard_False;
10551 Standard_Integer anArgIter = 1;
10552 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
10553 if (anArgIter < theArgsNb)
10554 {
10555 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
10556 anArgFirst.LowerCase();
10557 ++anArgIter;
10558 if (anArgFirst == "dynhighlight"
10559 || anArgFirst == "dynhilight"
10560 || anArgFirst == "dynamichighlight"
10561 || anArgFirst == "dynamichilight")
10562 {
10563 aType = Prs3d_TypeOfHighlight_Dynamic;
10564 }
10565 else if (anArgFirst == "localdynhighlight"
10566 || anArgFirst == "localdynhilight"
10567 || anArgFirst == "localdynamichighlight"
10568 || anArgFirst == "localdynamichilight")
10569 {
10570 aType = Prs3d_TypeOfHighlight_LocalDynamic;
10571 }
10572 else if (anArgFirst == "selhighlight"
10573 || anArgFirst == "selhilight"
10574 || anArgFirst == "selectedhighlight"
10575 || anArgFirst == "selectedhilight")
10576 {
10577 aType = Prs3d_TypeOfHighlight_Selected;
10578 }
10579 else if (anArgFirst == "localselhighlight"
10580 || anArgFirst == "localselhilight"
10581 || anArgFirst == "localselectedhighlight"
10582 || anArgFirst == "localselectedhilight")
10583 {
10584 aType = Prs3d_TypeOfHighlight_LocalSelected;
10585 }
10586 else
10587 {
10588 --anArgIter;
10589 }
10590 }
10591 for (; anArgIter < theArgsNb; ++anArgIter)
10592 {
10593 TCollection_AsciiString anArg (theArgVec[anArgIter]);
10594 anArg.LowerCase();
10595 if (anArg == "-help")
10596 {
10597 theDi.PrintHelp (theArgVec[0]);
10598 return 0;
10599 }
10600 else if (anArg == "-print")
10601 {
10602 toPrint = Standard_True;
10603 }
10604 else if (anArg == "-autoactivate")
10605 {
10606 Standard_Boolean toEnable = Standard_True;
10607 if (anArgIter + 1 < theArgsNb
10608 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
10609 {
10610 ++anArgIter;
10611 }
10612 aCtx->SetAutoActivateSelection (toEnable);
10613 }
14c4193d 10614 else if (anArg == "-pickstrategy"
10615 || anArg == "-pickingstrategy")
10616 {
10617 if (++anArgIter >= theArgsNb)
10618 {
10619 std::cout << "Syntax error: type of highlighting is undefined\n";
10620 return 1;
10621 }
10622
10623 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
10624 TCollection_AsciiString aVal (theArgVec[anArgIter]);
10625 aVal.LowerCase();
10626 if (aVal == "first"
10627 || aVal == "firstaccepted"
10628 || aVal == "firstacceptable")
10629 {
10630 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
10631 }
10632 else if (aVal == "topmost"
10633 || aVal == "onlyTopmost")
10634 {
10635 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
10636 }
10637 else
10638 {
10639 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
10640 return 1;
10641 }
10642
10643 aCtx->SetPickingStrategy (aStrategy);
10644 }
f838dac4 10645 else if (anArg == "-pixtol"
10646 && anArgIter + 1 < theArgsNb)
10647 {
10648 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
10649 }
10650 else if ((anArg == "-mode"
10651 || anArg == "-dispmode")
10652 && anArgIter + 1 < theArgsNb)
10653 {
10654 if (aType == Prs3d_TypeOfHighlight_None)
10655 {
10656 std::cout << "Syntax error: type of highlighting is undefined\n";
10657 return 1;
10658 }
8e5fb5ea 10659
f838dac4 10660 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
10661 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
10662 aStyle->SetDisplayMode (aDispMode);
10663 toRedraw = Standard_True;
10664 }
10665 else if (anArg == "-layer"
10666 && anArgIter + 1 < theArgsNb)
10667 {
10668 if (aType == Prs3d_TypeOfHighlight_None)
10669 {
10670 std::cout << "Syntax error: type of highlighting is undefined\n";
10671 return 1;
10672 }
8e5fb5ea 10673
f838dac4 10674 const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]);
10675 if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN)
10676 {
10677 TColStd_SequenceOfInteger aLayers;
10678 aCtx->CurrentViewer()->GetAllZLayers (aLayers);
10679 if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end())
10680 {
10681 std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n";
10682 return 1;
10683 }
10684 }
8e5fb5ea 10685
f838dac4 10686 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
10687 aStyle->SetZLayer (aNewLayer);
10688 toRedraw = Standard_True;
10689 }
10690 else if (anArg == "-hicolor"
10691 || anArg == "-selcolor"
10692 || anArg == "-color")
10693 {
10694 if (anArg.StartsWith ("-hi"))
10695 {
10696 aType = Prs3d_TypeOfHighlight_Dynamic;
10697 }
10698 else if (anArg.StartsWith ("-sel"))
10699 {
10700 aType = Prs3d_TypeOfHighlight_Selected;
10701 }
10702 else if (aType == Prs3d_TypeOfHighlight_None)
10703 {
10704 std::cout << "Syntax error: type of highlighting is undefined\n";
10705 return 1;
10706 }
8e5fb5ea 10707
f838dac4 10708 Quantity_Color aColor;
10709 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
10710 theArgVec + anArgIter + 1,
10711 aColor);
10712 if (aNbParsed == 0)
10713 {
10714 std::cout << "Syntax error: need more arguments.\n";
10715 return 1;
10716 }
10717 anArgIter += aNbParsed;
8e5fb5ea 10718
f838dac4 10719 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
10720 aStyle->SetColor (aColor);
10721 toRedraw = Standard_True;
10722 }
10723 else if ((anArg == "-transp"
10724 || anArg == "-transparency"
10725 || anArg == "-hitransp"
10726 || anArg == "-seltransp"
10727 || anArg == "-hitransplocal"
10728 || anArg == "-seltransplocal")
10729 && anArgIter + 1 < theArgsNb)
10730 {
10731 if (anArg.StartsWith ("-hi"))
10732 {
10733 aType = Prs3d_TypeOfHighlight_Dynamic;
10734 }
10735 else if (anArg.StartsWith ("-sel"))
10736 {
10737 aType = Prs3d_TypeOfHighlight_Selected;
10738 }
10739 else if (aType == Prs3d_TypeOfHighlight_None)
10740 {
10741 std::cout << "Syntax error: type of highlighting is undefined\n";
10742 return 1;
10743 }
8e5fb5ea 10744
f838dac4 10745 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
10746 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
10747 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
10748 toRedraw = Standard_True;
10749 }
10750 else if ((anArg == "-mat"
10751 || anArg == "-material")
10752 && anArgIter + 1 < theArgsNb)
10753 {
10754 if (aType == Prs3d_TypeOfHighlight_None)
10755 {
10756 std::cout << "Syntax error: type of highlighting is undefined\n";
10757 return 1;
10758 }
8e5fb5ea 10759
f838dac4 10760 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
10761 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
10762 if (aMatName != Graphic3d_NOM_DEFAULT)
10763 {
10764 ++anArgIter;
10765 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
10766 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
10767 Graphic3d_MaterialAspect aMat (aMatName);
10768 aMat.SetColor (aStyle->Color());
10769 aMat.SetTransparency (aStyle->Transparency());
10770 anAspect->SetFrontMaterial (aMat);
10771 anAspect->SetInteriorColor (aStyle->Color());
10772 aStyle->SetBasicFillAreaAspect (anAspect);
10773 }
10774 else
10775 {
10776 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
10777 }
10778 toRedraw = Standard_True;
10779 }
10780 else
10781 {
10782 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
10783 }
8e5fb5ea 10784 }
10785
f838dac4 10786 if (toPrint)
8e5fb5ea 10787 {
f838dac4 10788 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
10789 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
8e5fb5ea 10790 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
10791 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
f838dac4 10792 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
10793 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
10794 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
10795 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
10796 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
10797 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
10798 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
10799 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
8e5fb5ea 10800 }
10801
10802 if (aCtx->NbSelected() != 0 && toRedraw)
10803 {
10804 aCtx->HilightSelected (Standard_True);
10805 }
10806
10807 return 0;
10808}
10809
decdee7d 10810//===============================================================================================
10811//function : VDumpSelectionImage
10812//purpose :
10813//===============================================================================================
10814static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
10815 Standard_Integer theArgsNb,
10816 const char** theArgVec)
10817{
10818 if (theArgsNb < 2)
10819 {
10820 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
10821 return 1;
10822 }
10823
10824 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
10825 if (aContext.IsNull())
10826 {
10827 std::cout << "Error: no active view.\n";
10828 return 1;
10829 }
10830
10831 TCollection_AsciiString aFile;
10832 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
dc858f4c 10833 Image_Format anImgFormat = Image_Format_BGR;
decdee7d 10834 Standard_Integer aPickedIndex = 1;
10835 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10836 {
10837 TCollection_AsciiString aParam (theArgVec[anArgIter]);
10838 aParam.LowerCase();
10839 if (aParam == "-type")
10840 {
10841 if (++anArgIter >= theArgsNb)
10842 {
10843 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
10844 return 1;
10845 }
10846
10847 TCollection_AsciiString aValue (theArgVec[anArgIter]);
10848 aValue.LowerCase();
10849 if (aValue == "depth"
10850 || aValue == "normdepth"
10851 || aValue == "normalizeddepth")
10852 {
10853 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
dc858f4c 10854 anImgFormat = Image_Format_GrayF;
decdee7d 10855 }
10856 if (aValue == "depthinverted"
10857 || aValue == "normdepthinverted"
10858 || aValue == "normalizeddepthinverted"
10859 || aValue == "inverted")
10860 {
10861 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
dc858f4c 10862 anImgFormat = Image_Format_GrayF;
decdee7d 10863 }
10864 else if (aValue == "unnormdepth"
10865 || aValue == "unnormalizeddepth")
10866 {
10867 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
dc858f4c 10868 anImgFormat = Image_Format_GrayF;
decdee7d 10869 }
10870 else if (aValue == "objectcolor"
10871 || aValue == "object"
10872 || aValue == "color")
10873 {
10874 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
10875 }
10876 else if (aValue == "entitycolor"
10877 || aValue == "entity")
10878 {
10879 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
10880 }
10881 else if (aValue == "ownercolor"
10882 || aValue == "owner")
10883 {
10884 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
10885 }
10886 else if (aValue == "selectionmodecolor"
10887 || aValue == "selectionmode"
10888 || aValue == "selmodecolor"
10889 || aValue == "selmode")
10890 {
10891 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
10892 }
10893 }
10894 else if (aParam == "-picked"
10895 || aParam == "-pickeddepth"
10896 || aParam == "-pickedindex")
10897 {
10898 if (++anArgIter >= theArgsNb)
10899 {
10900 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
10901 return 1;
10902 }
10903
10904 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
10905 }
10906 else if (aFile.IsEmpty())
10907 {
10908 aFile = theArgVec[anArgIter];
10909 }
10910 else
10911 {
10912 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
10913 return 1;
10914 }
10915 }
10916 if (aFile.IsEmpty())
10917 {
10918 std::cout << "Syntax error: image file name is missing.\n";
10919 return 1;
10920 }
10921
10922 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
10923 Standard_Integer aWidth = 0, aHeight = 0;
10924 aView->Window()->Size (aWidth, aHeight);
10925
10926 Image_AlienPixMap aPixMap;
10927 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
10928 {
10929 std::cout << "Error: can't allocate image.\n";
10930 return 1;
10931 }
10932 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
10933 {
10934 std::cout << "Error: can't generate selection image.\n";
10935 return 1;
10936 }
10937 if (!aPixMap.Save (aFile))
10938 {
10939 std::cout << "Error: can't save selection image.\n";
10940 return 0;
10941 }
10942 return 0;
10943}
10944
7fd59977 10945//=======================================================================
10946//function : ViewerCommands
10947//purpose :
10948//=======================================================================
10949
10950void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
10951{
10952
10953 const char *group = "ZeViewer";
18d715bd 10954 theCommands.Add("vinit",
10955#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
10956 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
10957#else
10958 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
10959#endif
10960 " - Creates new View window with specified name view_name.\n"
10961 "By default the new view is created in the viewer and in"
10962 " graphic driver shared with active view.\n"
10963 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
10964 "If driverName isn't specified the driver will be shared with active view.\n"
10965 "If viewerName isn't specified the viewer will be shared with active view.\n"
10966#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
10967 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
10968 "is used in creation of graphic driver\n"
10969#endif
10970 " - l, t: pixel position of left top corner of the window\n"
10971 " - w,h: width and heigth of window respectively.\n"
10972 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
7fd59977 10973 __FILE__,VInit,group);
18d715bd 10974 theCommands.Add("vclose" ,
d0cc1cb7 10975 "[view_id [keep_context=0|1]]\n"
18d715bd 10976 "or vclose ALL - to remove all created views\n"
10977 " - removes view(viewer window) defined by its view_id.\n"
10978 " - keep_context: by default 0; if 1 and the last view is deleted"
10979 " the current context is not removed.",
10980 __FILE__,VClose,group);
10981 theCommands.Add("vactivate" ,
10982 "view_id"
10983 " - activates view(viewer window) defined by its view_id",
10984 __FILE__,VActivate,group);
10985 theCommands.Add("vviewlist",
10986 "vviewlist [format={tree, long}]"
10987 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
10988 " - format: format of result output, if tree the output is a tree view;"
10989 "otherwise it's a list of full view names. By default format = tree",
10990 __FILE__,VViewList,group);
7fd59977 10991 theCommands.Add("vhelp" ,
10992 "vhelp : display help on the viewer commands",
10993 __FILE__,VHelp,group);
10994 theCommands.Add("vtop" ,
27af3052 10995 "vtop or <T> : Top view. Orientation +X+Y" ,
7fd59977 10996 __FILE__,VTop,group);
44b8f2d6 10997 theCommands.Add("vbottom" ,
27af3052 10998 "vbottom : Bottom view. Orientation +X-Y" ,
44b8f2d6 10999 __FILE__,VBottom,group);
11000 theCommands.Add("vleft" ,
27af3052 11001 "vleft : Left view. Orientation -Y+Z" ,
44b8f2d6 11002 __FILE__,VLeft,group);
11003 theCommands.Add("vright" ,
27af3052 11004 "vright : Right view. Orientation +Y+Z" ,
44b8f2d6 11005 __FILE__,VRight,group);
7fd59977 11006 theCommands.Add("vaxo" ,
27af3052 11007 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
7fd59977 11008 __FILE__,VAxo,group);
44b8f2d6 11009 theCommands.Add("vfront" ,
27af3052 11010 "vfront : Front view. Orientation +X+Z" ,
44b8f2d6 11011 __FILE__,VFront,group);
11012 theCommands.Add("vback" ,
27af3052 11013 "vback : Back view. Orientation -X+Z" ,
44b8f2d6 11014 __FILE__,VBack,group);
7fd59977 11015 theCommands.Add("vpick" ,
11016 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
11017 VPick,group);
1beb58d7 11018 theCommands.Add("vfit",
11019 "vfit or <F> [-selected] [-noupdate]"
b586500b 11020 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
7fd59977 11021 __FILE__,VFit,group);
6262a303 11022 theCommands.Add ("vfitarea",
11023 "vfitarea x1 y1 x2 y2"
11024 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
11025 "\n\t\t: Fit view to show area located between two points"
11026 "\n\t\t: given in world 2D or 3D corrdinates.",
11027 __FILE__, VFitArea, group);
197ac94e 11028 theCommands.Add ("vzfit", "vzfit [scale]\n"
11029 " Matches Z near, Z far view volume planes to the displayed objects.\n"
11030 " \"scale\" - specifies factor to scale computed z range.\n",
11031 __FILE__, VZFit, group);
7fd59977 11032 theCommands.Add("vrepaint",
56689b27 11033 "vrepaint [-immediate]"
11034 "\n\t\t: force redraw",
7fd59977 11035 __FILE__,VRepaint,group);
11036 theCommands.Add("vclear",
faea8b40 11037 "vclear : vclear"
11038 "\n\t\t: remove all the object from the viewer",
7fd59977 11039 __FILE__,VClear,group);
11040 theCommands.Add("vsetbg",
11041 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
11042 __FILE__,VSetBg,group);
f8b2ed36 11043 theCommands.Add("vsetbgmode",
11044 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
11045 __FILE__,VSetBgMode,group);
7fd59977 11046 theCommands.Add("vsetgradientbg",
f8b2ed36 11047 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
7fd59977 11048 __FILE__,VSetGradientBg,group);
f8b2ed36 11049 theCommands.Add("vsetgrbgmode",
11050 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
11051 __FILE__,VSetGradientBgMode,group);
11052 theCommands.Add("vsetcolorbg",
11053 "vsetcolorbg : vsetcolorbg r g b : Set background color",
11054 __FILE__,VSetColorBg,group);
f42753ed 11055 theCommands.Add("vsetdefaultbg",
11056 "vsetdefaultbg r g b\n"
11057 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
11058 "\n\t\t: Set default viewer background fill color (flat/gradient).",
11059 __FILE__,VSetDefaultBg,group);
7fd59977 11060 theCommands.Add("vscale",
11061 "vscale : vscale X Y Z",
11062 __FILE__,VScale,group);
11063 theCommands.Add("vzbufftrihedron",
536d98e2 11064 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
11065 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
11066 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
11067 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
11068 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
11069 "\n\t\t: Displays a trihedron",
11070 __FILE__,VZBuffTrihedron,group);
7fd59977 11071 theCommands.Add("vrotate",
4af098ba 11072 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
11073 "\n : Option -mouseStart starts rotation according to the mouse position"
11074 "\n : Option -mouseMove continues rotation with angle computed"
11075 "\n : from last and new mouse position."
11076 "\n : vrotate AX AY AZ [X Y Z]",
7fd59977 11077 __FILE__,VRotate,group);
11078 theCommands.Add("vzoom",
11079 "vzoom : vzoom coef",
11080 __FILE__,VZoom,group);
11081 theCommands.Add("vpan",
11082 "vpan : vpan dx dy",
11083 __FILE__,VPan,group);
11084 theCommands.Add("vexport",
5cedc27f
K
11085 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
11086 " : exports the view to a vector file of a given format"
11087 " : notice that EMF format requires patched gl2ps",
7fd59977 11088 __FILE__,VExport,group);
11089 theCommands.Add("vcolorscale",
4b3d6eb1 11090 "vcolorscale name [-noupdate|-update] [-demo]"
11091 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
11092 "\n\t\t: [-font HeightFont=20]"
11093 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
11094 "\n\t\t: [-smoothTransition {on|off}=off]"
11095 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
11096 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
11097 "\n\t\t: [-textpos {left|right|center|none}=right]"
11098 "\n\t\t: [-labelAtBorder {on|off}=on]"
11099 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
11100 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
11101 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
11102 "\n\t\t: [-xy Left=0 Bottom=0]"
11103 "\n\t\t: -demo - displays a color scale with demonstratio values"
11104 "\n\t\t: -colors - set colors for all intervals"
11105 "\n\t\t: -color - set color for specific interval"
11106 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
11107 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
11108 "\n\t\t: at border means the value inbetween neighbor intervals,"
11109 "\n\t\t: at center means the center value within current interval"
11110 "\n\t\t: -labels - set labels for all intervals"
11111 "\n\t\t: -freeLabels - same as -labels but does not require"
11112 "\n\t\t: matching the number of intervals"
11113 "\n\t\t: -label - set label for specific interval"
11114 "\n\t\t: -title - set title"
11115 "\n\t\t: -reversed - setup smooth color transition between intervals"
11116 "\n\t\t: -smoothTransition - swap colorscale direction"
11117 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
11118 __FILE__, VColorScale, group);
7fd59977 11119 theCommands.Add("vgraduatedtrihedron",
a79f67f8 11120 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
11121 "\t[-namefont Name] [-valuesfont Name]\n"
11122 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
11123 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
11124 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
11125 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
11126 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
11127 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
11128 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
11129 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
11130 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
536d98e2 11131 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
a79f67f8 11132 " - Displays or erases graduated trihedron"
11133 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
11134 " - namefont - font of axes names. Default: Arial\n"
11135 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
11136 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
11137 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
11138 " - valuesfont - font of axes values. Default: Arial\n"
11139 " - xcolor, ycolor, zcolor - color of axis and values\n"
11140 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
11141 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
7fd59977 11142 __FILE__,VGraduatedTrihedron,group);
3bffef55 11143 theCommands.Add("vtile" ,
11144 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
11145 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
11146 "\n\t\t: -totalSize the size of virtual bigger viewport"
11147 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
11148 "\n\t\t: -lowerLeft tile offset as lower left corner"
11149 "\n\t\t: -upperLeft tile offset as upper left corner",
11150 __FILE__, VTile, group);
59f45b7c 11151 theCommands.Add("vzlayer",
7c3ef2f7 11152 "vzlayer [layerId]"
11153 "\n\t\t: [-add|-delete|-get|-settings]"
11154 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
11155 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
11156 "\n\t\t: ZLayer list management:"
11157 "\n\t\t: -add add new z layer to viewer and print its id"
11158 "\n\t\t: -delete delete z layer"
11159 "\n\t\t: -get print sequence of z layers"
11160 "\n\t\t: -settings print status of z layer settings"
11161 "\n\t\t: -disable disables given setting"
11162 "\n\t\t: -enable enables given setting",
59f45b7c 11163 __FILE__,VZLayer,group);
20637bd2 11164 theCommands.Add("vlayerline",
11165 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
11166 __FILE__,VLayerLine,group);
2bd4c032 11167 theCommands.Add ("vgrid",
11168 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
11169 " : Mode - rectangular or circular"
11170 " : Type - lines or points",
11171 __FILE__, VGrid, group);
c40b7d58 11172 theCommands.Add ("vpriviledgedplane",
11173 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
11174 "\n\t\t: Ox, Oy, Oz - plane origin"
11175 "\n\t\t: Nx, Ny, Nz - plane normal direction"
11176 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
11177 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
11178 __FILE__, VPriviledgedPlane, group);
f25b82d6 11179 theCommands.Add ("vconvert",
11180 "vconvert v [Mode={window|view}]"
11181 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
11182 "\n\t\t: vconvert x y z [Mode={window|grid}]"
11183 "\n\t\t: window - convert to window coordinates, pixels"
11184 "\n\t\t: view - convert to view projection plane"
11185 "\n\t\t: grid - convert to model coordinates, given on grid"
11186 "\n\t\t: ray - convert projection ray to model coordiantes"
11187 "\n\t\t: - vconvert v window : convert view to window;"
11188 "\n\t\t: - vconvert v view : convert window to view;"
11189 "\n\t\t: - vconvert x y window : convert view to window;"
11190 "\n\t\t: - vconvert x y view : convert window to view;"
11191 "\n\t\t: - vconvert x y : convert window to model;"
11192 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
11193 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
11194 "\n\t\t: - vconvert x y z window : convert model to window;"
11195 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
11196 "\n\t\t: Converts the given coordinates to window/view/model space.",
11197 __FILE__, VConvert, group);
208e6839 11198 theCommands.Add ("vfps",
11199 "vfps [framesNb=100] : estimate average frame rate for active view",
11200 __FILE__, VFps, group);
58655684 11201 theCommands.Add ("vgldebug",
c87535af 11202 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
11203 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
11204 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
11205 "\n\t\t: Debug context can be requested only on Windows"
11206 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
11207 "\n\t\t: -sync - request synchronized debug GL context"
11208 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
11209 "\n\t\t: which are suppressed by default,"
11210 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
11211 "\n\t\t: which are suppressed by default",
58655684 11212 __FILE__, VGlDebug, group);
208e6839 11213 theCommands.Add ("vvbo",
58655684 11214 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
208e6839 11215 __FILE__, VVbo, group);
b5ac8292 11216 theCommands.Add ("vstereo",
f978241f 11217 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
11218 "\n\t\t: [-anaglyph Filter]"
11219 "\n\t\t: Control stereo output mode. Available modes for -mode:"
11220 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
11221 "\n\t\t: requires driver support."
11222 "\n\t\t: Should be called BEFORE vinit!"
11223 "\n\t\t: anaglyph - Anaglyph glasses"
11224 "\n\t\t: rowInterlaced - row-interlaced display"
11225 "\n\t\t: columnInterlaced - column-interlaced display"
11226 "\n\t\t: chessBoard - chess-board output"
11227 "\n\t\t: sideBySide - horizontal pair"
11228 "\n\t\t: overUnder - vertical pair"
11229 "\n\t\t: Available Anaglyph filters for -anaglyph:"
11230 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
11231 "\n\t\t: greenMagentaSimple",
b5ac8292 11232 __FILE__, VStereo, group);
a577aaab 11233 theCommands.Add ("vcaps",
8625ef7e 11234 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
1dfe71a6 11235 "\n\t\t: [-compatibleProfile {0|1}]"
56689b27 11236 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
f978241f 11237 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
8625ef7e 11238 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
11239 "\n\t\t: Modify particular graphic driver options:"
11240 "\n\t\t: FFP - use fixed-function pipeline instead of"
11241 "\n\t\t: built-in GLSL programs"
4e1523ef 11242 "\n\t\t: (requires compatible profile)"
8625ef7e 11243 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
11244 "\n\t\t: arrays to GPU memory)"
11245 "\n\t\t: sprite - use textured sprites instead of bitmaps"
f978241f 11246 "\n\t\t: vsync - switch VSync on or off"
56689b27 11247 "\n\t\t: winBuffer - allow using window buffer for rendering"
4e1523ef 11248 "\n\t\t: Context creation options:"
11249 "\n\t\t: softMode - software OpenGL implementation"
11250 "\n\t\t: compatibleProfile - backward-compatible profile"
f978241f 11251 "\n\t\t: quadbuffer - QuadBuffer"
8625ef7e 11252 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
11253 "\n\t\t: rendering paths producing the same visual result when"
11254 "\n\t\t: possible."
11255 "\n\t\t: Command is intended for testing old hardware compatibility.",
a577aaab 11256 __FILE__, VCaps, group);
f0430952 11257 theCommands.Add ("vmemgpu",
11258 "vmemgpu [f]: print system-dependent GPU memory information if available;"
11259 " with f option returns free memory in bytes",
11260 __FILE__, VMemGpu, group);
85e096c3 11261 theCommands.Add ("vreadpixel",
11262 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
11263 " : Read pixel value for active view",
11264 __FILE__, VReadPixel, group);
692613e5 11265 theCommands.Add("diffimage",
11266 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
11267 __FILE__, VDiffImage, group);
4754e164 11268 theCommands.Add ("vselect",
2157d6ac 11269 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
4754e164 11270 "- emulates different types of selection:\n"
11271 "- 1) single click selection\n"
11272 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
11273 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
faea8b40 11274 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
11275 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
11276 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
2157d6ac 11277 " (partial inclusion - overlap - is not allowed by default)\n"
11278 "- 5) any of these selections with shift button pressed",
4754e164 11279 __FILE__, VSelect, group);
11280 theCommands.Add ("vmoveto",
11281 "vmoveto x y"
11282 "- emulates cursor movement to pixel postion (x,y)",
11283 __FILE__, VMoveTo, group);
1beb58d7 11284 theCommands.Add ("vviewparams",
11285 "vviewparams [-args] [-scale [s]]"
11286 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
11287 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
11288 "\n\t\t: Manage current view parameters or prints all"
11289 "\n\t\t: current values when called without argument."
11290 "\n\t\t: -scale [s] prints or sets viewport relative scale"
11291 "\n\t\t: -eye [x y z] prints or sets eye location"
11292 "\n\t\t: -at [x y z] prints or sets center of look"
11293 "\n\t\t: -up [x y z] prints or sets direction of up vector"
11294 "\n\t\t: -proj [x y z] prints or sets direction of look"
11295 "\n\t\t: -center x y sets location of center of the screen in pixels"
11296 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
11297 "\n\t\t: or changes the size of its maximum dimension"
11298 "\n\t\t: -args prints vviewparams arguments for restoring current view",
197ac94e 11299 __FILE__, VViewParams, group);
1beb58d7 11300
11301 theCommands.Add("vanimation", "Alias for vanim",
11302 __FILE__, VAnimation, group);
11303
11304 theCommands.Add("vanim",
11305 "List existing animations:"
11306 "\n\t\t: vanim"
11307 "\n\t\t: Animation playback:"
11308 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
11309 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
11310 "\n\t\t: -speed playback speed (1.0 is normal speed)"
11311 "\n\t\t: -freeLook skip camera animations"
11312 "\n\t\t: -lockLoop disable any interactions"
11313 "\n\t\t:"
11314 "\n\t\t: Animation definition:"
11315 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
11316 "\n\t\t: [start TimeSec] [duration TimeSec]"
11317 "\n\t\t:"
11318 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
11319 "\n\t\t: specifies nested animations."
11320 "\n\t\t: There is no syntax to explicitly add new animation,"
11321 "\n\t\t: and all non-existing animations within the name will be"
11322 "\n\t\t: implicitly created on first use (including parents)."
11323 "\n\t\t:"
11324 "\n\t\t: Each animation might define the SINGLE action (see below),"
11325 "\n\t\t: like camera transition, object transformation or custom callback."
11326 "\n\t\t: Child animations can be used for defining concurrent actions."
11327 "\n\t\t:"
11328 "\n\t\t: Camera animation:"
11329 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
11330 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
11331 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
11332 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
11333 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
11334 "\n\t\t: -atX camera Center positions pair"
11335 "\n\t\t: -upX camera Up directions pair"
11336 "\n\t\t: -scaleX camera Scale factors pair"
11337 "\n\t\t: Object animation:"
11338 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
11339 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
11340 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
11341 "\n\t\t: -locX object Location points pair (translation)"
11342 "\n\t\t: -rotX object Orientations pair (quaternions)"
11343 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
11344 "\n\t\t: Custom callback:"
11345 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
11346 "\n\t\t: %Pts overall animation presentation timestamp"
11347 "\n\t\t: %LocalPts local animation timestamp"
11348 "\n\t\t: %Normalized local animation normalized value in range 0..1"
08f8a185 11349 "\n\t\t:"
11350 "\n\t\t: Video recording:"
11351 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
11352 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
11353 "\n\t\t: [-crf Value] [-preset Preset]"
11354 "\n\t\t: -fps video framerate"
11355 "\n\t\t: -format file format, container (matroska, etc.)"
11356 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
11357 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
11358 "\n\t\t: -crf constant rate factor (specific to codec)"
11359 "\n\t\t: -preset codec parameters preset (specific to codec)"
1beb58d7 11360 __FILE__, VAnimation, group);
11361
4754e164 11362 theCommands.Add("vchangeselected",
dc3fe572 11363 "vchangeselected shape"
4754e164 11364 "- adds to shape to selection or remove one from it",
11365 __FILE__, VChangeSelected, group);
4754e164 11366 theCommands.Add ("vnbselected",
faea8b40 11367 "vnbselected"
11368 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
6b62b2da 11369 theCommands.Add ("vcamera",
11370 "vcamera [-ortho] [-projtype]"
11371 "\n\t\t: [-persp]"
11372 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
11373 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
11374 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
11375 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
11376 "\n\t\t: Manage camera parameters."
11377 "\n\t\t: Prints current value when option called without argument."
11378 "\n\t\t: Orthographic camera:"
11379 "\n\t\t: -ortho activate orthographic projection"
11380 "\n\t\t: Perspective camera:"
11381 "\n\t\t: -persp activate perspective projection (mono)"
11382 "\n\t\t: -fovy field of view in y axis, in degrees"
11383 "\n\t\t: -distance distance of eye from camera center"
11384 "\n\t\t: Stereoscopic camera:"
11385 "\n\t\t: -stereo perspective projection (stereo)"
11386 "\n\t\t: -leftEye perspective projection (left eye)"
11387 "\n\t\t: -rightEye perspective projection (right eye)"
11388 "\n\t\t: -iod intraocular distance value"
11389 "\n\t\t: -iodType distance type, absolute or relative"
11390 "\n\t\t: -zfocus stereographic focus value"
11391 "\n\t\t: -zfocusType focus type, absolute or relative",
11392 __FILE__, VCamera, group);
b5ac8292 11393 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
197ac94e 11394 "- vautozfit [on={1|0}] [scale]\n"
11395 " Prints or changes parameters of automatic z-fit mode:\n"
11396 " \"on\" - turns automatic z-fit on or off\n"
11397 " \"scale\" - specifies factor to scale computed z range.\n",
11398 __FILE__, VAutoZFit, group);
b5ac8292 11399 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
11400 " vzrange - without parameters shows current values\n"
11401 " vzrange [znear] [zfar] - applies provided values to view",
11402 __FILE__,VZRange, group);
4754e164 11403 theCommands.Add ("vpurgedisplay",
eb4320f2 11404 "vpurgedisplay"
4754e164 11405 "- removes structures which don't belong to objects displayed in neutral point",
11406 __FILE__, VPurgeDisplay, group);
11407 theCommands.Add("vsetviewsize",
11408 "vsetviewsize size",
11409 __FILE__,VSetViewSize,group);
11410 theCommands.Add("vmoveview",
11411 "vmoveview Dx Dy Dz [Start = 1|0]",
11412 __FILE__,VMoveView,group);
11413 theCommands.Add("vtranslateview",
11414 "vtranslateview Dx Dy Dz [Start = 1|0)]",
11415 __FILE__,VTranslateView,group);
11416 theCommands.Add("vturnview",
11417 "vturnview Ax Ay Az [Start = 1|0]",
11418 __FILE__,VTurnView,group);
269294d6 11419 theCommands.Add("vtextureenv",
11420 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
11421 "or user-defined file and optionally applying texture mapping parameters\n"
11422 " Usage:\n"
11423 " vtextureenv off - disables environment mapping\n"
11424 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
11425 " std_texture = (0..7)\n"
11426 " rep = {clamp|repeat}\n"
11427 " mod = {decal|modulate}\n"
11428 " flt = {nearest|bilinear|trilinear}\n"
11429 " ss, st - scale factors for s and t texture coordinates\n"
11430 " ts, tt - translation for s and t texture coordinates\n"
11431 " rot - texture rotation angle in degrees",
11432 __FILE__, VTextureEnv, group);
1eeef710 11433 theCommands.Add("vhlr",
11434 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
11435 "\n\t\t: Hidden Line Removal algorithm."
11436 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
11437 "\n\t\t: -algoType type of HLR algorithm.\n",
0a768f56 11438 __FILE__,VHLR,group);
1eeef710 11439 theCommands.Add("vhlrtype",
11440 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
11441 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
11442 "\n\t\t: 'algo' - exact HLR algorithm is applied"
11443 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
11444 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
0a768f56 11445 __FILE__,VHLRType,group);
3e05329c 11446 theCommands.Add("vclipplane",
11447 "vclipplane planeName [{0|1}]"
11448 "\n\t\t: [-equation A B C D]"
11449 "\n\t\t: [-set|-unset [objects|views]]"
11450 "\n\t\t: [-maxPlanes]"
11451 "\n\t\t: [-capping {0|1}]"
11452 "\n\t\t: [-color R G B] [-hatch {on|off|ID}]"
11453 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
11454 "\n\t\t: [-texRotate Angle]"
11455 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
11456 "\n\t\t: [-useObjShader {0|1}]"
11457 "\n\t\t: Clipping planes management:"
11458 "\n\t\t: -maxPlanes print plane limit for view"
11459 "\n\t\t: -delete delete plane with given name"
11460 "\n\t\t: {off|on|0|1} turn clipping on/off"
11461 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
11462 "\n\t\t: applied to active View when list is omitted"
11463 "\n\t\t: -equation A B C D change plane equation"
11464 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
11465 "\n\t\t: Capping options:"
11466 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
11467 "\n\t\t: -color R G B set capping color"
11468 "\n\t\t: -texName Texture set capping texture"
11469 "\n\t\t: -texScale SX SY set capping tex scale"
11470 "\n\t\t: -texOrigin TX TY set capping tex origin"
11471 "\n\t\t: -texRotate Angle set capping tex rotation"
11472 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
11473 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
11474 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
11475 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
11476 __FILE__, VClipPlane, group);
392ac980 11477 theCommands.Add("vdefaults",
4c513386 11478 "vdefaults [-absDefl value]"
11479 "\n\t\t: [-devCoeff value]"
11480 "\n\t\t: [-angDefl value]"
11481 "\n\t\t: [-autoTriang {off/on | 0/1}]"
11482 , __FILE__, VDefaults, group);
12381341 11483 theCommands.Add("vlight",
816d03ee 11484 "tool to manage light sources, without arguments shows list of lights."
11485 "\n Main commands: "
11486 "\n 'clear' to clear lights"
11487 "\n '{def}aults' to load deafault lights"
11488 "\n 'add' (or 'new') <type> to add any light source"
11489 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
11490 "\n 'change' <lightId> to edit light source with specified lightId"
11491 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
11492 "\n {pos}ition X Y Z"
11493 "\n {dir}ection X Y Z (for directional light or for spotlight)"
11494 "\n color colorName"
11495 "\n {head}light 0|1"
189f85a3 11496 "\n {sm}oothness value"
11497 "\n {int}ensity value"
816d03ee 11498 "\n {constAtten}uation value"
11499 "\n {linearAtten}uation value"
11500 "\n angle angleDeg"
11501 "\n {spotexp}onent value"
11502 "\n local|global"
11503 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
11504 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
12381341 11505 __FILE__, VLight, group);
6b62b2da 11506 theCommands.Add("vraytrace",
11507 "vraytrace [0|1]"
189f85a3 11508 "\n\t\t: Turns on/off ray-tracing renderer."
6b62b2da 11509 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
11510 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
11511 __FILE__, VRenderParams, group);
bc8c79bb 11512 theCommands.Add("vrenderparams",
11513 "\n Manages rendering parameters: "
a1073ae2 11514 "\n '-raster' Disables GPU ray-tracing"
11515 "\n '-msaa 0..4' Specifies number of samples for MSAA"
11516 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
11517 "\n '-rendScale value Rendering resolution scale factor"
11518 "\n '-rayTrace' Enables GPU ray-tracing"
11519 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
11520 "\n '-shadows on|off' Enables/disables shadows rendering"
11521 "\n '-reflections on|off' Enables/disables specular reflections"
11522 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
11523 "\n '-gleam on|off' Enables/disables transparency shadow effects"
11524 "\n '-gi on|off' Enables/disables global illumination effects"
11525 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
11526 "\n '-env on|off' Enables/disables environment map background"
11527 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
11528 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
11529 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
11530 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
11531 "\n '-nbtiles 64..1024' Specifies number of screen tiles in ISS mode"
11532 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
11533 "\n '-shadingModel model' Controls shading model from enumeration"
11534 "\n color, flat, gouraud, phong"
11535 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
b27ab03d 11536 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
11537 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
eb85ed36 11538 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
11539 "\n '-whitepoint value' White point value for filmic tone mapping"
11540 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
8625ef7e 11541 "\n Unlike vcaps, these parameters dramatically change visual properties."
11542 "\n Command is intended to control presentation quality depending on"
11543 "\n hardware capabilities and performance.",
bc8c79bb 11544 __FILE__, VRenderParams, group);
b7cd4ba7 11545 theCommands.Add("vfrustumculling",
11546 "vfrustumculling [toEnable]: enables/disables objects clipping",
11547 __FILE__,VFrustumCulling,group);
c398b00e 11548 theCommands.Add("vhighlightselected",
11549 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
11550 "Without arguments it shows if highlighting of selected objects is enabled now.",
11551 __FILE__,VHighlightSelected,group);
49e1a5c7 11552 theCommands.Add ("vplace",
11553 "vplace dx dy"
11554 "\n\t\t: Places the point (in pixels) at the center of the window",
11555 __FILE__, VPlace, group);
0717ddc1 11556 theCommands.Add("vxrotate",
11557 "vxrotate",
11558 __FILE__,VXRotate,group);
11559
625e1958 11560 theCommands.Add("vmanipulator",
11561 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
11562 "\n tool to create and manage AIS manipulators."
11563 "\n Options: "
11564 "\n '-attach AISObject' attach manipulator to AISObject"
11565 "\n '-adjustPosition {0|1}' adjust position when attaching"
11566 "\n '-adjustSize {0|1}' adjust size when attaching"
11567 "\n '-enableModes {0|1}' enable modes when attaching"
11568 "\n '-detach' detach manipulator"
11569 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
11570 "\n '-transform mouse_x mouse_y' - invoke transformation"
11571 "\n '-stopTransform [abort]' - invoke stop of transformation"
11572 "\n '-move x y z' - move attached object"
11573 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
11574 "\n '-scale factor' - scale attached object"
11575 "\n '-autoActivate {0|1}' - set activation on detection"
11576 "\n '-followTranslation {0|1}' - set following translation transform"
11577 "\n '-followRotation {0|1}' - set following rotation transform"
11578 "\n '-gap value' - set gap between sub-parts"
11579 "\n '-part axis mode {0|1}' - set visual part"
11580 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
11581 "\n '-size value' - set size of manipulator"
11582 "\n '-zoomable {0|1}' - set zoom persistence",
11583 __FILE__, VManipulator, group);
11584
8e5fb5ea 11585 theCommands.Add("vselprops",
f838dac4 11586 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
8e5fb5ea 11587 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
11588 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
14c4193d 11589 "\n -pickStrategy {first|topmost} : defines picking strategy"
11590 "\n 'first' to pick first acceptable (default)"
11591 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
8e5fb5ea 11592 "\n -pixTol value : sets up pixel tolerance"
f838dac4 11593 "\n -dispMode dispMode : sets display mode for highlighting"
11594 "\n -layer ZLayer : sets ZLayer for highlighting"
11595 "\n -color {name|r g b} : sets highlight color"
11596 "\n -transp value : sets transparency coefficient for highlight"
11597 "\n -material material : sets highlight material"
8e5fb5ea 11598 "\n -print : prints current state of all mentioned parameters",
11599 __FILE__, VSelectionProperties, group);
11600
decdee7d 11601 theCommands.Add ("vseldump",
11602 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
11603 "\n\t\t: Generate an image based on detection results:"
11604 "\n\t\t: depth normalized depth values"
11605 "\n\t\t: unnormDepth unnormalized depth values"
11606 "\n\t\t: object color of detected object"
11607 "\n\t\t: owner color of detected owner"
11608 "\n\t\t: selMode color of selection mode"
11609 "\n\t\t: entity color of etected entity",
11610 __FILE__, VDumpSelectionImage, group);
11611
189f85a3 11612#if defined(_WIN32)
11613 theCommands.Add("vprogressive",
11614 "vprogressive",
11615 __FILE__, VProgressiveMode, group);
11616#endif
7fd59977 11617}