1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <OpenGl_GlCore20.hxx>
19 #include <AIS_Animation.hxx>
20 #include <AIS_AnimationCamera.hxx>
21 #include <AIS_AnimationObject.hxx>
22 #include <AIS_CameraFrustum.hxx>
23 #include <AIS_ColorScale.hxx>
24 #include <AIS_Manipulator.hxx>
25 #include <AIS_RubberBand.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_InteractiveObject.hxx>
28 #include <AIS_ListOfInteractive.hxx>
29 #include <AIS_ListIteratorOfListOfInteractive.hxx>
30 #include <Aspect_Grid.hxx>
32 #include <Draw_ProgressIndicator.hxx>
33 #include <Graphic3d_ArrayOfPolylines.hxx>
34 #include <Graphic3d_AspectMarker3d.hxx>
35 #include <Graphic3d_NameOfTextureEnv.hxx>
36 #include <Graphic3d_GraduatedTrihedron.hxx>
37 #include <Graphic3d_TextureEnv.hxx>
38 #include <Graphic3d_TextureParams.hxx>
39 #include <Graphic3d_TypeOfTextureFilter.hxx>
40 #include <Graphic3d_AspectFillArea3d.hxx>
41 #include <ViewerTest.hxx>
42 #include <ViewerTest_AutoUpdater.hxx>
43 #include <ViewerTest_EventManager.hxx>
44 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
46 #include <ViewerTest_CmdParser.hxx>
47 #include <V3d_AmbientLight.hxx>
48 #include <V3d_DirectionalLight.hxx>
49 #include <V3d_PositionalLight.hxx>
50 #include <V3d_SpotLight.hxx>
51 #include <Message_ProgressSentry.hxx>
52 #include <NCollection_DoubleMap.hxx>
53 #include <NCollection_List.hxx>
54 #include <NCollection_Vector.hxx>
55 #include <AIS_InteractiveContext.hxx>
56 #include <Draw_Interpretor.hxx>
58 #include <Draw_Appli.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <Image_VideoRecorder.hxx>
61 #include <OpenGl_GraphicDriver.hxx>
63 #include <OSD_Timer.hxx>
64 #include <TColStd_HSequenceOfAsciiString.hxx>
65 #include <TColStd_SequenceOfInteger.hxx>
66 #include <TColStd_HSequenceOfReal.hxx>
67 #include <TColgp_Array1OfPnt2d.hxx>
68 #include <TColStd_MapOfAsciiString.hxx>
69 #include <Aspect_TypeOfLine.hxx>
70 #include <Image_Diff.hxx>
71 #include <Aspect_DisplayConnection.hxx>
75 #include <PrsMgr_PresentableObject.hxx>
76 #include <Graphic3d_ClipPlane.hxx>
77 #include <NCollection_DataMap.hxx>
78 #include <Graphic3d_Texture2Dmanual.hxx>
79 #include <Prs3d_ShadingAspect.hxx>
80 #include <Prs3d_Drawer.hxx>
81 #include <Prs3d_LineAspect.hxx>
82 #include <Prs3d_Root.hxx>
83 #include <Prs3d_Text.hxx>
84 #include <Select3D_SensitivePrimitiveArray.hxx>
95 #include <WNT_WClass.hxx>
96 #include <WNT_Window.hxx>
97 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
98 #include <Cocoa_Window.hxx>
100 #include <Xw_Window.hxx>
101 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
102 #include <X11/Xutil.h>
106 // Auxiliary definitions
107 static const char THE_KEY_DELETE = 127;
108 static const char THE_KEY_ESCAPE = 27;
110 //==============================================================================
111 // VIEWER GLOBAL VARIABLES
112 //==============================================================================
114 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
115 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
117 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
118 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
120 extern int VErase (Draw_Interpretor& theDI,
121 Standard_Integer theArgNb,
122 const char** theArgVec);
125 static Handle(WNT_Window)& VT_GetWindow() {
126 static Handle(WNT_Window) WNTWin;
129 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
130 static Handle(Cocoa_Window)& VT_GetWindow()
132 static Handle(Cocoa_Window) aWindow;
135 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
136 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
137 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
140 static Handle(Xw_Window)& VT_GetWindow(){
141 static Handle(Xw_Window) XWWin;
145 static void VProcessEvents(ClientData,int);
148 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
150 static Handle(Aspect_DisplayConnection) aDisplayConnection;
151 return aDisplayConnection;
154 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
156 GetDisplayConnection() = theDisplayConnection;
159 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
160 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
162 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
164 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
165 if (!aWindow.IsNull())
166 return aWindow->HWindow();
167 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
168 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
169 if (!aWindow.IsNull())
170 return aWindow->XWindow();
172 return aWindowHandle;
176 //! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events
177 class ViewerTest_V3dView : public V3d_View
179 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_V3dView, V3d_View)
181 //! Initializes the view.
182 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC,
183 bool theIs2dMode = false)
184 : V3d_View (theViewer, theType), myIs2dMode (theIs2dMode) {}
186 //! Initializes the view by copying.
187 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
188 : V3d_View (theViewer, theView), myIs2dMode (false)
190 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView))
192 myIs2dMode = aV3dView->IsViewIn2DMode();
196 //! Returns true if 2D mode is set for the view
197 bool IsViewIn2DMode() const { return myIs2dMode; }
199 //! Sets 2D mode for the view
200 void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; }
204 //! Returns true if active view in 2D mode.
205 static bool IsCurrentViewIn2DMode()
207 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
209 return aV3dView->IsViewIn2DMode();
214 //! Set if active view in 2D mode.
215 static void SetCurrentView2DMode (bool theIs2d)
217 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
219 aV3dView->SetView2DMode (theIs2d);
225 Standard_Boolean myIs2dMode; //!< 2D mode flag
229 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
230 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
231 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
232 static OpenGl_Caps ViewerTest_myDefaultCaps;
234 static void OSWindowSetup();
238 Quantity_Color FlatColor;
239 Quantity_Color GradientColor1;
240 Quantity_Color GradientColor2;
241 Aspect_GradientFillMethod FillMethod;
242 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
244 //==============================================================================
245 // EVENT GLOBAL VARIABLES
246 //==============================================================================
248 static int Start_Rot = 0;
249 Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
250 int X_Motion = 0; // Current cursor position
252 int X_ButtonPress = 0; // Last ButtonPress position
253 int Y_ButtonPress = 0;
254 Standard_Boolean IsDragged = Standard_False;
255 Standard_Boolean DragFirst = Standard_False;
256 Standard_Boolean TheIsAnimating = Standard_False;
257 Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
258 Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
263 //! Checks if some set is a subset of other set
264 //! @tparam TheSuperSet the type of the superset
265 //! @tparam TheSubSet the type of the subset
266 //! @param theSuperSet the superset
267 //! @param theSubSet the subset to be checked
268 //! @return true if the superset includes subset, or false otherwise
269 template <typename TheSuperSet, typename TheSubSet>
270 static bool includes (const TheSuperSet& theSuperSet, const TheSubSet& theSubSet)
272 return std::includes (theSuperSet.begin(), theSuperSet.end(), theSubSet.begin(), theSubSet.end());
275 //! A variable set of keys for command-line options.
276 //! It includes a set of mandatory keys and a set of all possible keys.
277 class CommandOptionKeyVariableSet
280 //! Default constructor
281 CommandOptionKeyVariableSet()
286 //! @param theMandatoryKeySet the set of the mandatory option keys
287 //! @param theAdditionalKeySet the set of additional options that could be omitted
288 CommandOptionKeyVariableSet (
289 const ViewerTest_CommandOptionKeySet& theMandatoryKeySet,
290 const ViewerTest_CommandOptionKeySet& theAdditionalKeySet = ViewerTest_CommandOptionKeySet())
291 : myMandatoryKeySet (theMandatoryKeySet)
293 std::set_union (theMandatoryKeySet.begin(),
294 theMandatoryKeySet.end(),
295 theAdditionalKeySet.begin(),
296 theAdditionalKeySet.end(),
297 std::inserter (myFullKeySet, myFullKeySet.begin()));
300 //! Checks if the set of option keys fits to the current variable set (it must contain all mandatory keys
301 //! and be contained in the full key set)
302 //! @param theCheckedKeySet the set of option keys to be checked
303 bool IsInSet (const ViewerTest_CommandOptionKeySet& theCheckedKeySet) const
305 return includes (theCheckedKeySet, myMandatoryKeySet) && includes (myFullKeySet, theCheckedKeySet);
309 //! A set of mandatory command-line option keys
310 ViewerTest_CommandOptionKeySet myMandatoryKeySet;
312 //! A full set of command-line option keys (includes mandatory and additional option keys)
313 ViewerTest_CommandOptionKeySet myFullKeySet;
316 //! Gets some code by its name
317 //! @tparam TheCode the type of a code to be found
318 //! @param theCodeNameMap the map from code names to codes
319 //! @param theCodeName the name of a code to be found
320 //! @param theCode the code to be found
321 //! @return true if a code is found, or false otherwise
322 template <typename TheCode>
323 static bool getSomeCodeByName (const std::map<TCollection_AsciiString, TheCode>& theCodeNameMap,
324 TCollection_AsciiString theCodeName,
327 theCodeName.LowerCase();
328 const typename std::map<TCollection_AsciiString, TheCode>::const_iterator aCodeIterator = theCodeNameMap.find (
330 if (aCodeIterator == theCodeNameMap.end())
334 theCode = aCodeIterator->second;
338 // Defines possible commands related to background changing
339 enum BackgroundCommand
341 BackgroundCommand_Main, //!< The main command that manages other commands through options
342 BackgroundCommand_Image, //!< Sets an image as a background
343 BackgroundCommand_ImageMode, //!< Changes a background image mode
344 BackgroundCommand_Gradient, //!< Sets a gradient as a background
345 BackgroundCommand_GradientMode, //!< Changes a background gradient mode
346 BackgroundCommand_Color, //!< Fills background with a specified color
347 BackgroundCommand_Default //!< Sets the background default color or gradient
350 //! Map from background command names to its codes
351 typedef std::map<TCollection_AsciiString, BackgroundCommand> BackgroundCommandNameMap;
353 //! Creates a map from background command names to its codes
354 //! @return a map from background command names to its codes
355 static BackgroundCommandNameMap createBackgroundCommandNameMap()
357 BackgroundCommandNameMap aBackgroundCommandNameMap;
358 aBackgroundCommandNameMap["vbackground"] = BackgroundCommand_Main;
359 aBackgroundCommandNameMap["vsetbg"] = BackgroundCommand_Image;
360 aBackgroundCommandNameMap["vsetbgmode"] = BackgroundCommand_ImageMode;
361 aBackgroundCommandNameMap["vsetgradientbg"] = BackgroundCommand_Gradient;
362 aBackgroundCommandNameMap["vsetgrbgmode"] = BackgroundCommand_GradientMode;
363 aBackgroundCommandNameMap["vsetcolorbg"] = BackgroundCommand_Color;
364 aBackgroundCommandNameMap["vsetdefaultbg"] = BackgroundCommand_Default;
365 return aBackgroundCommandNameMap;
368 //! Gets a background command by its name
369 //! @param theBackgroundCommandName the name of the background command
370 //! @param theBackgroundCommand the background command to be found
371 //! @return true if a background command is found, or false otherwise
372 static bool getBackgroundCommandByName (const TCollection_AsciiString& theBackgroundCommandName,
373 BackgroundCommand& theBackgroundCommand)
375 static const BackgroundCommandNameMap THE_BACKGROUND_COMMAND_NAME_MAP = createBackgroundCommandNameMap();
376 return getSomeCodeByName (THE_BACKGROUND_COMMAND_NAME_MAP, theBackgroundCommandName, theBackgroundCommand);
379 //! Map from background image fill method names to its codes
380 typedef std::map<TCollection_AsciiString, Aspect_FillMethod> BackgroundImageFillMethodNameMap;
382 //! Creates a map from background image fill method names to its codes
383 //! @return a map from background image fill method names to its codes
384 static BackgroundImageFillMethodNameMap createBackgroundImageFillMethodNameMap()
386 BackgroundImageFillMethodNameMap aBackgroundImageFillMethodNameMap;
387 aBackgroundImageFillMethodNameMap["none"] = Aspect_FM_NONE;
388 aBackgroundImageFillMethodNameMap["centered"] = Aspect_FM_CENTERED;
389 aBackgroundImageFillMethodNameMap["tiled"] = Aspect_FM_TILED;
390 aBackgroundImageFillMethodNameMap["stretch"] = Aspect_FM_STRETCH;
391 return aBackgroundImageFillMethodNameMap;
394 //! Gets a background image fill method by its name
395 //! @param theBackgroundImageFillMethodName the name of the background image fill method
396 //! @param theBackgroundImageFillMethod the background image fill method to be found
397 //! @return true if a background image fill method is found, or false otherwise
398 static bool getBackgroundImageFillMethodByName (const TCollection_AsciiString& theBackgroundImageFillMethodName,
399 Aspect_FillMethod& theBackgroundImageFillMethod)
401 static const BackgroundImageFillMethodNameMap THE_BACKGROUND_IMAGE_FILL_METHOD_NAME_MAP =
402 createBackgroundImageFillMethodNameMap();
403 return getSomeCodeByName (THE_BACKGROUND_IMAGE_FILL_METHOD_NAME_MAP,
404 theBackgroundImageFillMethodName,
405 theBackgroundImageFillMethod);
408 //! Map from background gradient fill method names to its codes
409 typedef std::map<TCollection_AsciiString, Aspect_GradientFillMethod> BackgroundGradientFillMethodNameMap;
411 //! Creates a map from background gradient fill method names to its codes
412 //! @return a map from background gradient fill method names to its codes
413 static BackgroundGradientFillMethodNameMap createBackgroundGradientFillMethodNameMap()
415 BackgroundGradientFillMethodNameMap aBackgroundGradientFillMethodNameMap;
416 aBackgroundGradientFillMethodNameMap["none"] = Aspect_GFM_NONE;
417 aBackgroundGradientFillMethodNameMap["hor"] = Aspect_GFM_HOR;
418 aBackgroundGradientFillMethodNameMap["horizontal"] = Aspect_GFM_HOR;
419 aBackgroundGradientFillMethodNameMap["ver"] = Aspect_GFM_VER;
420 aBackgroundGradientFillMethodNameMap["vertical"] = Aspect_GFM_VER;
421 aBackgroundGradientFillMethodNameMap["diag1"] = Aspect_GFM_DIAG1;
422 aBackgroundGradientFillMethodNameMap["diagonal1"] = Aspect_GFM_DIAG1;
423 aBackgroundGradientFillMethodNameMap["diag2"] = Aspect_GFM_DIAG2;
424 aBackgroundGradientFillMethodNameMap["diagonal2"] = Aspect_GFM_DIAG2;
425 aBackgroundGradientFillMethodNameMap["corner1"] = Aspect_GFM_CORNER1;
426 aBackgroundGradientFillMethodNameMap["corner2"] = Aspect_GFM_CORNER2;
427 aBackgroundGradientFillMethodNameMap["corner3"] = Aspect_GFM_CORNER3;
428 aBackgroundGradientFillMethodNameMap["corner4"] = Aspect_GFM_CORNER4;
429 return aBackgroundGradientFillMethodNameMap;
432 //! Gets a gradient fill method by its name
433 //! @param theBackgroundGradientFillMethodName the name of the gradient fill method
434 //! @param theBackgroundGradientFillMethod the gradient fill method to be found
435 //! @return true if a gradient fill method is found, or false otherwise
436 static bool getBackgroundGradientFillMethodByName (const TCollection_AsciiString& theBackgroundGradientFillMethodName,
437 Aspect_GradientFillMethod& theBackgroundGradientFillMethod)
439 static const BackgroundGradientFillMethodNameMap THE_BACKGROUND_GRADIENT_FILL_METHOD_NAME_MAP =
440 createBackgroundGradientFillMethodNameMap();
441 return getSomeCodeByName (THE_BACKGROUND_GRADIENT_FILL_METHOD_NAME_MAP,
442 theBackgroundGradientFillMethodName,
443 theBackgroundGradientFillMethod);
446 //! Changes the background in accordance with passed command line options
447 class BackgroundChanger
450 //! Constructor. Prepares the command parser
453 prepareCommandParser();
456 //! Processes the command line and changes the background
457 //! @param theDrawInterpretor the interpreter of the Draw Harness application
458 //! @param theNumberOfCommandLineArguments the number of passed command line arguments
459 //! @param theCommandLineArguments the array of command line arguments
460 bool ProcessCommandLine (Draw_Interpretor& theDrawInterpretor,
461 const Standard_Integer theNumberOfCommandLineArguments,
462 const char* const* const theCommandLineArguments)
464 const char* const aBackgroundCommandName = theCommandLineArguments[0];
465 BackgroundCommand aBackgroundCommand = BackgroundCommand_Main;
466 if (!getBackgroundCommandByName (aBackgroundCommandName, aBackgroundCommand))
470 addCommandDescription (aBackgroundCommand);
471 myCommandParser.Parse (theNumberOfCommandLineArguments, theCommandLineArguments);
472 return processCommandOptions (aBackgroundCommandName, aBackgroundCommand, theDrawInterpretor);
476 //! The type of functions that are able to set gradient background filling
477 typedef void SetGradientFunction (const Quantity_Color& /* theColor1 */,
478 const Quantity_Color& /* theColor2 */,
479 const Aspect_GradientFillMethod /* theGradientMode */);
481 //! The type of functions that are able to fill a background with a specific color
482 typedef void SetColorFunction (const Quantity_Color& /* theColor */);
484 //! the command parser used to parse command line options and its arguments
485 ViewerTest_CmdParser myCommandParser;
487 //! the option key for the command that sets an image as a background
488 ViewerTest_CommandOptionKey myImageOptionKey;
490 //! the option key for the command that sets a background image fill type
491 ViewerTest_CommandOptionKey myImageModeOptionKey;
493 //! the option key for the command that sets a gradient filling for the background
494 ViewerTest_CommandOptionKey myGradientOptionKey;
496 //! the option key for the command that sets a background gradient filling method
497 ViewerTest_CommandOptionKey myGradientModeOptionKey;
499 //! the option key for the command that fills background with a specific color
500 ViewerTest_CommandOptionKey myColorOptionKey;
502 //! the option key for the command that sets default background gradient or color
503 ViewerTest_CommandOptionKey myDefaultOptionKey;
505 //! the variable set of options that are allowed for the old scenario (without any option passed)
506 CommandOptionKeyVariableSet myUnnamedOptionVariableSet;
508 //! the variable set of options that are allowed for setting an image as a background
509 CommandOptionKeyVariableSet myImageOptionVariableSet;
511 //! the variable set of options that are allowed for setting a background image fill type
512 CommandOptionKeyVariableSet myImageModeOptionVariableSet;
514 //! the variable set of options that are allowed for setting a gradient filling for the background
515 CommandOptionKeyVariableSet myGradientOptionVariableSet;
517 //! the variable set of options that are allowed for setting a background gradient filling method
518 CommandOptionKeyVariableSet myGradientModeOptionVariableSet;
520 //! the variable set of options that are allowed for filling a background with a specific color
521 CommandOptionKeyVariableSet myColorOptionVariableSet;
523 //! the variable set of options that are allowed for setting a default background gradient
524 CommandOptionKeyVariableSet myDefaultGradientOptionVariableSet;
526 //! the variable set of options that are allowed for setting a default background color
527 CommandOptionKeyVariableSet myDefaultColorOptionVariableSet;
529 //! the variable set of options that are allowed for printing help
530 CommandOptionKeyVariableSet myHelpOptionVariableSet;
532 //! Adds options to command parser
533 void addOptionsToCommandParser()
535 myImageOptionKey = myCommandParser.AddOption ("imageFile|image|imgFile|img",
536 "filename of image used as background");
537 myImageModeOptionKey = myCommandParser.AddOption (
538 "imageMode|imgMode", "image fill type, should be one of CENTERED, TILED, STRETCH, NONE");
539 myGradientOptionKey = myCommandParser.AddOption ("gradient|grad|gr",
540 "sets background gradient starting and ending colors");
541 myGradientModeOptionKey =
542 myCommandParser.AddOption ("gradientMode|gradMode|gradMd|grMode|grMd",
543 "gradient fill method, should be one of NONE, HOR[IZONTAL], VER[TICAL], "
544 "DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, CORNER4");
545 myColorOptionKey = myCommandParser.AddOption ("color|col", "background color");
546 myDefaultOptionKey = myCommandParser.AddOption ("default|def", "sets background default gradient or color");
549 //! Creates option sets used to determine if a passed option set is valid or not
550 void createOptionSets()
552 ViewerTest_CommandOptionKeySet anUnnamedOptionSet;
553 anUnnamedOptionSet.insert (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
554 myUnnamedOptionVariableSet = CommandOptionKeyVariableSet (anUnnamedOptionSet);
556 ViewerTest_CommandOptionKeySet anImageOptionSet;
557 anImageOptionSet.insert (myImageOptionKey);
558 ViewerTest_CommandOptionKeySet anImageModeOptionSet;
559 anImageModeOptionSet.insert (myImageModeOptionKey);
560 myImageOptionVariableSet = CommandOptionKeyVariableSet (anImageOptionSet, anImageModeOptionSet);
561 myImageModeOptionVariableSet = CommandOptionKeyVariableSet (anImageModeOptionSet);
563 ViewerTest_CommandOptionKeySet aGradientOptionSet;
564 aGradientOptionSet.insert (myGradientOptionKey);
565 ViewerTest_CommandOptionKeySet aGradientModeOptionSet;
566 aGradientModeOptionSet.insert (myGradientModeOptionKey);
567 myGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet);
568 myGradientModeOptionVariableSet = CommandOptionKeyVariableSet (aGradientModeOptionSet);
570 ViewerTest_CommandOptionKeySet aColorOptionSet;
571 aColorOptionSet.insert (myColorOptionKey);
572 myColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet);
574 aGradientOptionSet.insert (myDefaultOptionKey);
575 myDefaultGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet);
576 aColorOptionSet.insert (myDefaultOptionKey);
577 myDefaultColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet);
579 ViewerTest_CommandOptionKeySet aHelpOptionSet;
580 aHelpOptionSet.insert (ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY);
581 myHelpOptionVariableSet = CommandOptionKeyVariableSet (aHelpOptionSet);
584 //! Prepares the command parser. Adds options and creates option sets used to determine
585 //! if a passed option set is valid or not
586 void prepareCommandParser()
588 addOptionsToCommandParser();
592 //! Adds a command description to the command parser
593 //! @param theBackgroundCommand the key of the command which description is added to the command parser
594 void addCommandDescription (const BackgroundCommand theBackgroundCommand)
596 std::string aDescription;
597 bool isMainCommand = false;
598 switch (theBackgroundCommand)
600 case BackgroundCommand_Main:
601 aDescription = "Command: vbackground (changes background or some background settings)";
602 isMainCommand = true;
604 case BackgroundCommand_Image:
605 aDescription = "Command: vsetbg (loads image as a background)";
607 case BackgroundCommand_ImageMode:
608 aDescription = "Command: vsetbgmode (changes background fill type)";
610 case BackgroundCommand_Gradient:
611 aDescription = "Command: vsetgradientbg (mounts gradient background)";
613 case BackgroundCommand_GradientMode:
614 aDescription = "Command: vsetgradientbgmode (changes gradient background fill method)";
616 case BackgroundCommand_Color:
617 aDescription = "Command: vsetcolorbg (sets color background)";
619 case BackgroundCommand_Default:
620 aDescription = "Command: vsetdefaultbg (sets default viewer background gradient or fill color)";
627 aDescription += "\nThis command is obsolete. Use vbackground instead.";
629 myCommandParser.SetDescription (aDescription);
632 //! Check if a viewer is needed to be initialized
633 //! @param theBackgroundCommand the key of the command that changes the background
634 //! @return true if processing was successful, or false otherwise
635 bool checkViewerIsNeeded (const BackgroundCommand theBackgroundCommand) const
637 const bool isMain = (theBackgroundCommand == BackgroundCommand_Main);
638 const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions();
639 const bool aViewerIsNotNeeded =
640 (theBackgroundCommand == BackgroundCommand_Default)
641 || (myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain)
642 || (myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain)
643 || myHelpOptionVariableSet.IsInSet (aUsedOptions);
644 return !aViewerIsNotNeeded;
647 //! Check if a viewer is initialized
648 //! @param theBackgroundCommandName the name of the command that changes the background
649 //! @param theDrawInterpretor the interpreter of the Draw Harness application
650 //! @return true if a viewer is initialized, or false otherwise
651 static bool checkViewerIsInitialized (const char* const theBackgroundCommandName,
652 Draw_Interpretor& theDrawInterpretor)
654 const Handle (AIS_InteractiveContext)& anAISContext = ViewerTest::GetAISContext();
655 if (anAISContext.IsNull())
657 theDrawInterpretor << "Use 'vinit' command before executing '" << theBackgroundCommandName << "' command.\n";
663 //! Processes command options
664 //! @param theBackgroundCommandName the name of the command that changes the background
665 //! @param theBackgroundCommand the key of the command that changes the background
666 //! @param theDrawInterpretor the interpreter of the Draw Harness application
667 //! @return true if processing was successful, or false otherwise
668 bool processCommandOptions (const char* const theBackgroundCommandName,
669 const BackgroundCommand theBackgroundCommand,
670 Draw_Interpretor& theDrawInterpretor) const
672 if (myCommandParser.HasNoOption())
674 return printHelp (theBackgroundCommandName, theDrawInterpretor);
676 if (checkViewerIsNeeded (theBackgroundCommand)
677 && !checkViewerIsInitialized (theBackgroundCommandName, theDrawInterpretor))
681 if (myCommandParser.HasOnlyUnnamedOption())
683 return processUnnamedOption (theBackgroundCommand);
685 return processNamedOptions (theBackgroundCommandName, theBackgroundCommand, theDrawInterpretor);
688 //! Processes the unnamed option
689 //! @param theBackgroundCommand the key of the command that changes the background
690 //! @return true if processing was successful, or false otherwise
691 bool processUnnamedOption (const BackgroundCommand theBackgroundCommand) const
693 switch (theBackgroundCommand)
695 case BackgroundCommand_Main:
697 case BackgroundCommand_Image:
698 return processImageUnnamedOption();
699 case BackgroundCommand_ImageMode:
700 return processImageModeUnnamedOption();
701 case BackgroundCommand_Gradient:
702 return processGradientUnnamedOption();
703 case BackgroundCommand_GradientMode:
704 return processGradientModeUnnamedOption();
705 case BackgroundCommand_Color:
706 return processColorUnnamedOption();
707 case BackgroundCommand_Default:
708 return processDefaultUnnamedOption();
714 //! Processes the image unnamed option
715 //! @return true if processing was successful, or false otherwise
716 bool processImageUnnamedOption() const
718 const std::size_t aNumberOfImageUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments (
719 ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
720 if ((aNumberOfImageUnnamedOptionArguments != 1) && (aNumberOfImageUnnamedOptionArguments != 2))
724 std::string anImageFileName;
725 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0, anImageFileName))
729 Aspect_FillMethod anImageMode = Aspect_FM_CENTERED;
730 if (aNumberOfImageUnnamedOptionArguments == 2)
732 std::string anImageModeString;
733 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 1, anImageModeString))
737 if (!getBackgroundImageFillMethodByName (anImageModeString.c_str(), anImageMode))
742 setImage (anImageFileName.c_str(), anImageMode);
746 //! Processes the image mode unnamed option
747 //! @return true if processing was successful, or false otherwise
748 bool processImageModeUnnamedOption() const
750 return processImageModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
753 //! Processes the gradient unnamed option
754 //! @param theSetGradient the function used to set a background gradient filling
755 //! @return true if processing was successful, or false otherwise
756 bool processGradientUnnamedOption (SetGradientFunction* const theSetGradient = setGradient) const
758 const Standard_Integer aNumberOfGradientUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments (
759 ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
760 if (aNumberOfGradientUnnamedOptionArguments < 2)
765 Standard_Integer anArgumentIndex = 0;
766 Quantity_Color aColor1;
767 if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor1))
771 if (anArgumentIndex >= aNumberOfGradientUnnamedOptionArguments)
776 Quantity_Color aColor2;
777 if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor2))
781 if (anArgumentIndex > aNumberOfGradientUnnamedOptionArguments)
786 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR;
787 if (anArgumentIndex == aNumberOfGradientUnnamedOptionArguments - 1)
789 std::string anGradientModeString;
791 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY,
793 anGradientModeString))
797 if (!getBackgroundGradientFillMethodByName (anGradientModeString.c_str(), aGradientMode))
803 if (anArgumentIndex != aNumberOfGradientUnnamedOptionArguments)
807 theSetGradient (aColor1, aColor2, aGradientMode);
811 //! Processes the gradient mode unnamed option
812 //! @return true if processing was successful, or false otherwise
813 bool processGradientModeUnnamedOption() const
815 return processGradientModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
818 //! Processes the color unnamed option
819 //! @param theSetColor the function used to set a background color
820 //! @return true if processing was successful, or false otherwise
821 bool processColorUnnamedOption (SetColorFunction* const theSetColor = setColor) const
823 return processColorOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, theSetColor);
826 //! Processes the default back unnamed option
827 //! @return true if processing was successful, or false otherwise
828 bool processDefaultUnnamedOption() const
830 if (processGradientUnnamedOption (setDefaultGradient))
834 return processColorUnnamedOption (setDefaultColor);
837 //! Processes named options
838 //! @param theBackgroundCommandName the name of the command that changes the background
839 //! @param theBackgroundCommand the key of the command that changes the background
840 //! @param theDrawInterpretor the interpreter of the Draw Harness application
841 //! @return true if processing was successful, or false otherwise
842 bool processNamedOptions (const char* const theBackgroundCommandName,
843 const BackgroundCommand theBackgroundCommand,
844 Draw_Interpretor& theDrawInterpretor) const
846 const bool isMain = (theBackgroundCommand == BackgroundCommand_Main);
847 const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions();
848 if (myImageOptionVariableSet.IsInSet (aUsedOptions)
849 && (isMain || (theBackgroundCommand == BackgroundCommand_Image)))
851 return processImageOptionSet();
853 if (myImageModeOptionVariableSet.IsInSet (aUsedOptions)
854 && (isMain || (theBackgroundCommand == BackgroundCommand_ImageMode)))
856 return processImageModeOptionSet();
858 if (myGradientOptionVariableSet.IsInSet (aUsedOptions)
859 && (isMain || (theBackgroundCommand == BackgroundCommand_Gradient)))
861 return processGradientOptionSet();
863 if (myGradientModeOptionVariableSet.IsInSet (aUsedOptions)
864 && (isMain || (theBackgroundCommand == BackgroundCommand_GradientMode)))
866 return processGradientModeOptionSet();
868 if (myColorOptionVariableSet.IsInSet (aUsedOptions)
869 && (isMain || (theBackgroundCommand == BackgroundCommand_Color)))
871 return processColorOptionSet();
873 if ((myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain)
874 || (myGradientOptionVariableSet.IsInSet (aUsedOptions)
875 && (theBackgroundCommand == BackgroundCommand_Default)))
877 return processDefaultGradientOptionSet();
879 if ((myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain)
880 || (myColorOptionVariableSet.IsInSet (aUsedOptions) && (theBackgroundCommand == BackgroundCommand_Default)))
882 return processDefaultColorOptionSet();
884 if (myHelpOptionVariableSet.IsInSet (aUsedOptions))
886 return processHelpOptionSet (theBackgroundCommandName, theDrawInterpretor);
891 //! Processes the image option set
892 //! @return true if processing was successful, or false otherwise
893 bool processImageOptionSet() const
895 std::string anImageFileName;
896 if (!processImageOption (anImageFileName))
900 Aspect_FillMethod anImageMode = Aspect_FM_CENTERED;
901 if (myCommandParser.HasOption (myImageModeOptionKey) && !processImageModeOption (anImageMode))
905 setImage (anImageFileName.c_str(), anImageMode);
909 //! Processes the image mode option set
910 //! @return true if processing was successful, or false otherwise
911 bool processImageModeOptionSet() const
913 return processImageModeOptionSet (myImageModeOptionKey);
916 //! Processes the image mode option set
917 //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option
918 //! @return true if processing was successful, or false otherwise
919 bool processImageModeOptionSet (const ViewerTest_CommandOptionKey theImageModeOptionKey) const
921 Aspect_FillMethod anImageMode = Aspect_FM_NONE;
922 if (!processImageModeOption (theImageModeOptionKey, anImageMode))
926 setImageMode (anImageMode);
930 //! Processes the gradient option set
931 //! @param theSetGradient the function used to set a background gradient filling
932 //! @return true if processing was successful, or false otherwise
933 bool processGradientOptionSet (SetGradientFunction* const theSetGradient = setGradient) const
935 Quantity_Color aColor1;
936 Quantity_Color aColor2;
937 if (!processGradientOption (aColor1, aColor2))
941 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR;
942 if (myCommandParser.HasOption (myGradientModeOptionKey) && !processGradientModeOption (aGradientMode))
946 theSetGradient (aColor1, aColor2, aGradientMode);
950 //! Processes the gradient mode option set
951 //! @return true if processing was successful, or false otherwise
952 bool processGradientModeOptionSet() const
954 return processGradientModeOptionSet (myGradientModeOptionKey);
957 //! Processes the gradient mode option set
958 //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option
959 //! @return true if processing was successful, or false otherwise
960 bool processGradientModeOptionSet (const ViewerTest_CommandOptionKey theGradientModeOptionKey) const
962 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_NONE;
963 if (!processGradientModeOption (theGradientModeOptionKey, aGradientMode))
967 setGradientMode (aGradientMode);
971 //! Processes the color option set
972 //! @param theSetColor the function used to set a background color
973 //! @return true if processing was successful, or false otherwise
974 bool processColorOptionSet (SetColorFunction* const theSetColor = setColor) const
976 return processColorOptionSet (myColorOptionKey, theSetColor);
979 //! Processes the default color option set
980 //! @return true if processing was successful, or false otherwise
981 bool processDefaultGradientOptionSet() const
983 return processGradientOptionSet (setDefaultGradient);
986 //! Processes the default gradient option set
987 //! @return true if processing was successful, or false otherwise
988 bool processDefaultColorOptionSet() const
990 return processColorOptionSet (setDefaultColor);
993 //! Processes the color option set
994 //! @param theColorOptionKey the key of the option that is interpreted as a color option
995 //! @param theSetColor the function used to set a background color
996 //! @return true if processing was successful, or false otherwise
997 bool processColorOptionSet (const ViewerTest_CommandOptionKey theColorOptionKey,
998 SetColorFunction* const theSetColor = setColor) const
1000 Quantity_Color aColor;
1001 if (!processColorOption (theColorOptionKey, aColor))
1005 theSetColor (aColor);
1009 //! Processes the help option set
1010 //! @param theBackgroundCommandName the name of the command that changes the background
1011 //! @param theDrawInterpretor the interpreter of the Draw Harness application
1012 //! @return true if processing was successful, or false otherwise
1013 bool processHelpOptionSet (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor) const
1015 const Standard_Integer aNumberOfHelpOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1016 ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY);
1017 if (aNumberOfHelpOptionArguments != 0)
1021 return printHelp (theBackgroundCommandName, theDrawInterpretor);
1024 //! Processes the image option
1025 //! @param theImageFileName the filename of the image to be used as a background
1026 //! @return true if processing was successful, or false otherwise
1027 bool processImageOption (std::string& theImageFileName) const
1029 const Standard_Integer aNumberOfImageOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1031 if (aNumberOfImageOptionArguments != 1)
1035 std::string anImageFileName;
1036 if (!myCommandParser.Arg (myImageOptionKey, 0, anImageFileName))
1040 theImageFileName = anImageFileName;
1044 //! Processes the image mode option
1045 //! @param theImageMode the fill type used for a background image
1046 //! @return true if processing was successful, or false otherwise
1047 bool processImageModeOption (Aspect_FillMethod& theImageMode) const
1049 return processImageModeOption (myImageModeOptionKey, theImageMode);
1052 //! Processes the image mode option
1053 //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option
1054 //! @param theImageMode the fill type used for a background image
1055 //! @return true if processing was successful, or false otherwise
1056 bool processImageModeOption (const ViewerTest_CommandOptionKey theImageModeOptionKey,
1057 Aspect_FillMethod& theImageMode) const
1059 return processModeOption (theImageModeOptionKey, getBackgroundImageFillMethodByName, theImageMode);
1062 //! Processes the gradient option
1063 //! @param theColor1 the gradient starting color
1064 //! @param theColor2 the gradient ending color
1065 //! @return true if processing was successful, or false otherwise
1066 bool processGradientOption (Quantity_Color& theColor1, Quantity_Color& theColor2) const
1068 Standard_Integer anArgumentIndex = 0;
1069 Quantity_Color aColor1;
1070 if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor1))
1074 Quantity_Color aColor2;
1075 if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor2))
1079 const Standard_Integer aNumberOfGradientOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1080 myGradientOptionKey);
1081 if (anArgumentIndex != aNumberOfGradientOptionArguments)
1085 theColor1 = aColor1;
1086 theColor2 = aColor2;
1090 //! Processes the gradient mode option
1091 //! @param theGradientMode the fill method used for a background gradient filling
1092 //! @return true if processing was successful, or false otherwise
1093 bool processGradientModeOption (Aspect_GradientFillMethod& theGradientMode) const
1095 return processGradientModeOption (myGradientModeOptionKey, theGradientMode);
1098 //! Processes the gradient mode option
1099 //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option
1100 //! @param theGradientMode the fill method used for a background gradient filling
1101 //! @return true if processing was successful, or false otherwise
1102 bool processGradientModeOption (const ViewerTest_CommandOptionKey theGradientModeOptionKey,
1103 Aspect_GradientFillMethod& theGradientMode) const
1105 return processModeOption (theGradientModeOptionKey, getBackgroundGradientFillMethodByName, theGradientMode);
1108 //! Processes some mode option
1109 //! @tparam TheMode the type of a mode to be processed
1110 //! @param theModeOptionKey the key of the option that is interpreted as a mode option
1111 //! @param theMode a mode to be processed
1112 //! @return true if processing was successful, or false otherwise
1113 template <typename TheMode>
1114 bool processModeOption (const ViewerTest_CommandOptionKey theModeOptionKey,
1115 bool (*const theGetModeByName) (const TCollection_AsciiString& /* theModeName */,
1116 TheMode& /* theMode */),
1117 TheMode& theMode) const
1119 const Standard_Integer aNumberOfModeOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1121 if (aNumberOfModeOptionArguments != 1)
1125 std::string aModeString;
1126 if (!myCommandParser.Arg (theModeOptionKey, 0, aModeString))
1130 TheMode aMode = TheMode();
1131 if (!theGetModeByName (aModeString.c_str(), aMode))
1139 //! Processes the color option
1140 //! @param theColor a color used for filling a background
1141 //! @return true if processing was successful, or false otherwise
1142 bool processColorOption (Quantity_Color& theColor) const
1144 return processColorOption (myColorOptionKey, theColor);
1147 //! Processes the color option
1148 //! @param theColorOptionKey the key of the option that is interpreted as a color option
1149 //! @param theColor a color used for filling a background
1150 //! @return true if processing was successful, or false otherwise
1151 bool processColorOption (const ViewerTest_CommandOptionKey theColorOptionKey, Quantity_Color& theColor) const
1153 Standard_Integer anArgumentIndex = 0;
1154 Quantity_Color aColor;
1155 if (!myCommandParser.ArgColor (theColorOptionKey, anArgumentIndex, aColor))
1159 const Standard_Integer aNumberOfColorOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1161 if (anArgumentIndex != aNumberOfColorOptionArguments)
1169 //! Prints helping message
1170 //! @param theBackgroundCommandName the name of the command that changes the background
1171 //! @param theDrawInterpretor the interpreter of the Draw Harness application
1172 //! @return true if printing was successful, or false otherwise
1173 static bool printHelp (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor)
1175 return theDrawInterpretor.PrintHelp (theBackgroundCommandName) == TCL_OK;
1178 //! Sets the image as a background
1179 //! @param theImageFileName the filename of the image to be used as a background
1180 //! @param theImageMode the fill type used for a background image
1181 static void setImage (const Standard_CString theImageFileName, const Aspect_FillMethod theImageMode)
1183 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1184 aCurrentView->SetBackgroundImage (theImageFileName, theImageMode, Standard_True);
1187 //! Sets the fill type used for a background image
1188 //! @param theImageMode the fill type used for a background image
1189 static void setImageMode (const Aspect_FillMethod theImageMode)
1191 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1192 aCurrentView->SetBgImageStyle (theImageMode, Standard_True);
1195 //! Sets the gradient filling for a background
1196 //! @param theColor1 the gradient starting color
1197 //! @param theColor2 the gradient ending color
1198 //! @param theGradientMode the fill method used for a background gradient filling
1199 static void setGradient (const Quantity_Color& theColor1,
1200 const Quantity_Color& theColor2,
1201 const Aspect_GradientFillMethod theGradientMode)
1203 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1204 aCurrentView->SetBgGradientColors (theColor1, theColor2, theGradientMode, Standard_True);
1207 //! Sets the fill method used for a background gradient filling
1208 //! @param theGradientMode the fill method used for a background gradient filling
1209 static void setGradientMode (const Aspect_GradientFillMethod theGradientMode)
1211 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1212 aCurrentView->SetBgGradientStyle (theGradientMode, Standard_True);
1215 //! Sets the color used for filling a background
1216 //! @param theColor the color used for filling a background
1217 static void setColor (const Quantity_Color& theColor)
1219 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1220 aCurrentView->SetBgGradientStyle (Aspect_GFM_NONE);
1221 aCurrentView->SetBackgroundColor (theColor);
1222 aCurrentView->Update();
1225 //! Sets the gradient filling for a background in a default viewer
1226 //! @param theColor1 the gradient starting color
1227 //! @param theColor2 the gradient ending color
1228 //! @param theGradientMode the fill method used for a background gradient filling
1229 static void setDefaultGradient (const Quantity_Color& theColor1,
1230 const Quantity_Color& theColor2,
1231 const Aspect_GradientFillMethod theGradientMode)
1233 ViewerTest_DefaultBackground.GradientColor1 = theColor1;
1234 ViewerTest_DefaultBackground.GradientColor2 = theColor2;
1235 ViewerTest_DefaultBackground.FillMethod = theGradientMode;
1236 setDefaultGradient();
1239 //! Sets the color used for filling a background in a default viewer
1240 //! @param theColor the color used for filling a background
1241 static void setDefaultColor (const Quantity_Color& theColor)
1243 ViewerTest_DefaultBackground.GradientColor1 = Quantity_Color();
1244 ViewerTest_DefaultBackground.GradientColor2 = Quantity_Color();
1245 ViewerTest_DefaultBackground.FillMethod = Aspect_GFM_NONE;
1246 ViewerTest_DefaultBackground.FlatColor = theColor;
1247 setDefaultGradient();
1251 //! Sets the gradient filling for a background in a default viewer.
1252 //! Gradient settings are taken from ViewerTest_DefaultBackground structure
1253 static void setDefaultGradient()
1255 for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator
1256 anInteractiveContextIterator (ViewerTest_myContexts);
1257 anInteractiveContextIterator.More();
1258 anInteractiveContextIterator.Next())
1260 const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer();
1261 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
1262 ViewerTest_DefaultBackground.GradientColor2,
1263 ViewerTest_DefaultBackground.FillMethod);
1267 //! Sets the color used for filling a background in a default viewer.
1268 //! The color value is taken from ViewerTest_DefaultBackground structure
1269 static void setDefaultColor()
1271 for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator
1272 anInteractiveContextIterator (ViewerTest_myContexts);
1273 anInteractiveContextIterator.More();
1274 anInteractiveContextIterator.Next())
1276 const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer();
1277 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
1284 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
1286 static Handle(AIS_RubberBand) aBand;
1289 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
1290 aBand->SetDisplayMode (0);
1295 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
1297 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
1299 static ViewerTest_MapOfAISManipulators aMap;
1303 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
1305 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
1306 for (; anIt.More(); anIt.Next())
1308 if (anIt.Value()->HasActiveMode())
1310 return anIt.Value();
1316 //==============================================================================
1319 static LRESULT WINAPI ViewerWindowProc(
1324 static LRESULT WINAPI AdvViewerWindowProc(
1332 //==============================================================================
1335 //==============================================================================
1337 const Handle(Standard_Transient)& ViewerTest::WClass()
1339 static Handle(Standard_Transient) theWClass;
1341 if (theWClass.IsNull())
1343 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
1344 CS_VREDRAW | CS_HREDRAW, 0, 0,
1345 ::LoadCursor (NULL, IDC_ARROW));
1351 //==============================================================================
1352 //function : CreateName
1353 //purpose : Create numerical name for new object in theMap
1354 //==============================================================================
1355 template <typename ObjectType>
1356 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
1357 const TCollection_AsciiString& theDefaultString)
1359 if (theObjectMap.IsEmpty())
1360 return theDefaultString + TCollection_AsciiString(1);
1362 Standard_Integer aNextKey = 1;
1363 Standard_Boolean isFound = Standard_False;
1366 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
1367 // Look for objects with default names
1368 if (theObjectMap.IsBound1(aStringKey))
1373 isFound = Standard_True;
1376 return theDefaultString + TCollection_AsciiString(aNextKey);
1379 //==============================================================================
1380 //structure : ViewerTest_Names
1381 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
1382 //==============================================================================
1383 struct ViewerTest_Names
1386 TCollection_AsciiString myDriverName;
1387 TCollection_AsciiString myViewerName;
1388 TCollection_AsciiString myViewName;
1392 const TCollection_AsciiString& GetDriverName () const
1394 return myDriverName;
1396 void SetDriverName (const TCollection_AsciiString& theDriverName)
1398 myDriverName = theDriverName;
1400 const TCollection_AsciiString& GetViewerName () const
1402 return myViewerName;
1404 void SetViewerName (const TCollection_AsciiString& theViewerName)
1406 myViewerName = theViewerName;
1408 const TCollection_AsciiString& GetViewName () const
1412 void SetViewName (const TCollection_AsciiString& theViewName)
1414 myViewName = theViewName;
1417 //===========================================================================
1418 //function : Constructor for ViewerTest_Names
1419 //purpose : Get view, viewer, driver names from custom string
1420 //===========================================================================
1422 ViewerTest_Names (const TCollection_AsciiString& theInputString)
1424 TCollection_AsciiString aName(theInputString);
1425 if (theInputString.IsEmpty())
1427 // Get current configuration
1428 if (ViewerTest_myDrivers.IsEmpty())
1429 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1430 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1432 myDriverName = ViewerTest_myDrivers.Find2
1433 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1435 if(ViewerTest_myContexts.IsEmpty())
1437 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
1438 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
1442 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
1445 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
1449 // There is at least view name
1450 Standard_Integer aParserNumber = 0;
1451 for (Standard_Integer i = 0; i < 3; ++i)
1453 Standard_Integer aParserPos = aName.SearchFromEnd("/");
1454 if(aParserPos != -1)
1457 aName.Split(aParserPos-1);
1462 if (aParserNumber == 0)
1465 if (!ViewerTest::GetAISContext().IsNull())
1467 myDriverName = ViewerTest_myDrivers.Find2
1468 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1469 myViewerName = ViewerTest_myContexts.Find2
1470 (ViewerTest::GetAISContext());
1474 // There is no opened contexts here, need to create names for viewer and driver
1475 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1476 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1478 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
1479 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
1481 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
1483 else if (aParserNumber == 1)
1485 // Here is viewerName/viewName
1486 if (!ViewerTest::GetAISContext().IsNull())
1487 myDriverName = ViewerTest_myDrivers.Find2
1488 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1491 // There is no opened contexts here, need to create name for driver
1492 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1493 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1495 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
1497 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
1501 //Here is driverName/viewerName/viewName
1502 myDriverName = TCollection_AsciiString(aName);
1504 TCollection_AsciiString aViewerName(theInputString);
1505 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
1506 myViewerName = TCollection_AsciiString(aViewerName);
1508 myViewName = TCollection_AsciiString(theInputString);
1514 //==============================================================================
1515 //function : FindContextByView
1516 //purpose : Find AIS_InteractiveContext by View
1517 //==============================================================================
1519 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
1521 Handle(AIS_InteractiveContext) anAISContext;
1523 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1524 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
1526 if (anIter.Value()->CurrentViewer() == theView->Viewer())
1527 return anIter.Key2();
1529 return anAISContext;
1533 //==============================================================================
1534 //function : SetWindowTitle
1535 //purpose : Set window title
1536 //==============================================================================
1538 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
1539 Standard_CString theTitle)
1542 const TCollection_ExtendedString theTitleW (theTitle);
1543 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
1544 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1545 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
1547 if(GetDisplayConnection()->GetDisplay())
1550 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
1551 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
1556 //==============================================================================
1557 //function : IsWindowOverlapped
1558 //purpose : Check if theWindow overlapp another view
1559 //==============================================================================
1561 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
1562 const Standard_Integer thePxTop,
1563 const Standard_Integer thePxRight,
1564 const Standard_Integer thePxBottom,
1565 TCollection_AsciiString& theViewId)
1567 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1568 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1570 Standard_Integer aTop = 0,
1574 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
1575 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
1576 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
1577 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
1578 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
1580 theViewId = anIter.Key1();
1581 return Standard_True;
1584 return Standard_False;
1587 // Workaround: to create and delete non-orthographic views outside ViewerTest
1588 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
1590 ViewerTest_myViews.UnBind1 (theName);
1593 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
1594 const Handle(V3d_View)& theView)
1596 ViewerTest_myViews.Bind (theName, theView);
1599 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
1601 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
1604 //! Auxiliary tool performing continuous redraws of specified window.
1605 class ViewerTest_ContinuousRedrawer
1608 //! Return global instance.
1609 static ViewerTest_ContinuousRedrawer& Instance()
1611 static ViewerTest_ContinuousRedrawer aRedrawer;
1617 ~ViewerTest_ContinuousRedrawer()
1623 void Start (const Handle(Aspect_Window)& theWindow,
1624 Standard_Real theTargetFps)
1626 if (myWindow != theWindow
1627 || myTargetFps != theTargetFps)
1630 myWindow = theWindow;
1631 myTargetFps = theTargetFps;
1633 if (myThread.GetId() == 0)
1636 myThread.Run (this);
1641 void Stop (const Handle(Aspect_Window)& theWindow = NULL)
1643 if (!theWindow.IsNull()
1644 && myWindow != theWindow)
1650 Standard_Mutex::Sentry aLock (myMutex);
1663 Handle(Aspect_DisplayConnection) aDisp = new Aspect_DisplayConnection();
1666 Standard_Real aTimeOld = 0.0;
1667 const Standard_Real aTargetDur = myTargetFps > 0.0 ? 1.0 / myTargetFps : -1.0;
1671 Standard_Mutex::Sentry aLock (myMutex);
1677 if (myTargetFps > 0.0)
1679 const Standard_Real aTimeNew = aTimer.ElapsedTime();
1680 const Standard_Real aDuration = aTimeNew - aTimeOld;
1681 if (aDuration >= aTargetDur)
1683 myWindow->InvalidateContent (aDisp);
1684 aTimeOld = aTimeNew;
1689 myWindow->InvalidateContent (aDisp);
1692 OSD::MilliSecSleep (1);
1696 //! Thread creation callback.
1697 static Standard_Address doThreadWrapper (Standard_Address theData)
1699 ViewerTest_ContinuousRedrawer* aThis = (ViewerTest_ContinuousRedrawer* )theData;
1700 aThis->doThreadLoop();
1704 //! Empty constructor.
1705 ViewerTest_ContinuousRedrawer()
1706 : myThread (doThreadWrapper),
1711 Handle(Aspect_Window) myWindow;
1712 OSD_Thread myThread;
1713 Standard_Mutex myMutex;
1714 Standard_Real myTargetFps;
1715 volatile bool myToStop;
1718 //==============================================================================
1719 //function : ViewerInit
1720 //purpose : Create the window viewer and initialize all the global variable
1721 //==============================================================================
1723 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
1724 const Standard_Integer thePxTop,
1725 const Standard_Integer thePxWidth,
1726 const Standard_Integer thePxHeight,
1727 const TCollection_AsciiString& theViewName,
1728 const TCollection_AsciiString& theDisplayName,
1729 const Handle(V3d_View)& theViewToClone)
1731 // Default position and dimension of the viewer window.
1732 // Note that left top corner is set to be sufficiently small to have
1733 // window fit in the small screens (actual for remote desktops, see #23003).
1734 // The position corresponds to the window's client area, thus some
1735 // gap is added for window frame to be visible.
1736 Standard_Integer aPxLeft = 20;
1737 Standard_Integer aPxTop = 40;
1738 Standard_Integer aPxWidth = 409;
1739 Standard_Integer aPxHeight = 409;
1740 Standard_Boolean toCreateViewer = Standard_False;
1741 if (!theViewToClone.IsNull())
1743 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
1746 Handle(OpenGl_GraphicDriver) aGraphicDriver;
1747 ViewerTest_Names aViewNames(theViewName);
1748 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
1749 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
1752 aPxLeft = thePxLeft;
1755 if (thePxWidth != 0)
1756 aPxWidth = thePxWidth;
1757 if (thePxHeight != 0)
1758 aPxHeight = thePxHeight;
1760 // Get graphic driver (create it or get from another view)
1761 const bool isNewDriver = !ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName());
1764 // Get connection string
1765 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1766 if (!theDisplayName.IsEmpty())
1768 SetDisplayConnection (new Aspect_DisplayConnection (theDisplayName));
1772 ::Display* aDispX = NULL;
1773 // create dedicated display connection instead of reusing Tk connection
1774 // so that to procede events independently through VProcessEvents()/ViewerMainLoop() callbacks
1775 /*Draw_Interpretor& aCommands = Draw::GetInterpretor();
1776 Tcl_Interp* aTclInterp = aCommands.Interp();
1777 Tk_Window aMainWindow = Tk_MainWindow (aTclInterp);
1778 aDispX = aMainWindow != NULL ? Tk_Display (aMainWindow) : NULL;*/
1779 SetDisplayConnection (new Aspect_DisplayConnection (aDispX));
1782 (void)theDisplayName; // avoid warning on unused argument
1783 SetDisplayConnection (new Aspect_DisplayConnection ());
1786 if (Draw_VirtualWindows)
1788 // don't waste the time waiting for VSync when window is not displayed on the screen
1789 ViewerTest_myDefaultCaps.swapInterval = 0;
1790 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
1791 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
1793 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
1794 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
1796 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
1797 toCreateViewer = Standard_True;
1801 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
1804 //Dispose the window if input parameters are default
1805 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
1807 Standard_Integer aTop = 0,
1814 // Get screen resolution
1815 #if defined(_WIN32) || defined(__WIN32__)
1817 GetClientRect(GetDesktopWindow(), &aWindowSize);
1818 aScreenHeight = aWindowSize.bottom;
1819 aScreenWidth = aWindowSize.right;
1820 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1821 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
1823 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
1824 aScreenWidth = WidthOfScreen(aScreen);
1825 aScreenHeight = HeightOfScreen(aScreen);
1828 TCollection_AsciiString anOverlappedViewId("");
1830 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
1832 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
1834 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
1835 && aRight + 2*aPxWidth + 40 > aScreenWidth)
1837 if (aBottom + aPxHeight + 40 > aScreenHeight)
1844 aPxTop = aBottom + 40;
1847 aPxLeft = aRight + 20;
1852 TCollection_AsciiString aTitle("3D View - ");
1853 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
1855 // Change name of current active window
1856 if (!ViewerTest::CurrentView().IsNull())
1858 TCollection_AsciiString anActiveWindowTitle("3D View - ");
1859 anActiveWindowTitle = anActiveWindowTitle
1860 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1861 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
1865 Handle(V3d_Viewer) a3DViewer;
1866 // If it's the single view, we first look for empty context
1867 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
1869 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1870 anIter(ViewerTest_myContexts);
1872 ViewerTest::SetAISContext (anIter.Value());
1873 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
1875 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
1877 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
1878 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
1880 else if (a3DViewer.IsNull())
1882 toCreateViewer = Standard_True;
1883 a3DViewer = new V3d_Viewer(aGraphicDriver);
1884 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
1885 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
1886 ViewerTest_DefaultBackground.GradientColor2,
1887 ViewerTest_DefaultBackground.FillMethod);
1890 // AIS context setup
1891 if (ViewerTest::GetAISContext().IsNull() ||
1892 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
1894 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
1895 ViewerTest::SetAISContext (aContext);
1896 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
1900 ViewerTest::ResetEventManager();
1905 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
1906 Handle(WNT_WClass)::DownCast (WClass()),
1907 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
1909 aPxWidth, aPxHeight,
1910 Quantity_NOC_BLACK);
1911 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1912 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
1914 aPxWidth, aPxHeight);
1915 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
1917 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
1920 aPxWidth, aPxHeight);
1922 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
1925 Handle(V3d_View) aView;
1926 if (!theViewToClone.IsNull())
1928 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
1932 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
1935 aView->SetWindow (VT_GetWindow());
1936 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
1938 ViewerTest::CurrentView(aView);
1939 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
1941 // Setup for X11 or NT
1944 // Set parameters for V3d_View and V3d_Viewer
1945 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
1946 aV3dView->SetComputedMode(Standard_False);
1948 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
1951 a3DViewer->SetDefaultLights();
1952 a3DViewer->SetLightOn();
1955 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1958 ::Display* aDispX = GetDisplayConnection()->GetDisplay();
1959 Tcl_CreateFileHandler (XConnectionNumber (aDispX), TCL_READABLE, VProcessEvents, (ClientData )aDispX);
1963 VT_GetWindow()->Map();
1965 // Set the handle of created view in the event manager
1966 ViewerTest::ResetEventManager();
1968 ViewerTest::CurrentView()->Redraw();
1971 a3DViewer.Nullify();
1973 return aViewNames.GetViewName();
1976 //==============================================================================
1977 //function : RedrawAllViews
1978 //purpose : Redraw all created views
1979 //==============================================================================
1980 void ViewerTest::RedrawAllViews()
1982 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
1983 for (; aViewIt.More(); aViewIt.Next())
1985 const Handle(V3d_View)& aView = aViewIt.Key2();
1990 //==============================================================================
1992 //purpose : Create the window viewer and initialize all the global variable
1993 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
1994 //==============================================================================
1996 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1998 TCollection_AsciiString aViewName, aDisplayName;
1999 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
2000 Handle(V3d_View) aCopyFrom;
2001 TCollection_AsciiString aName, aValue;
2003 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2005 const TCollection_AsciiString anArg = theArgVec[anArgIt];
2006 TCollection_AsciiString anArgCase = anArg;
2007 anArgCase.LowerCase();
2008 if (anArgIt + 1 < theArgsNb
2009 && anArgCase == "-name")
2011 aViewName = theArgVec[++anArgIt];
2013 else if (anArgIt + 1 < theArgsNb
2014 && (anArgCase == "-left"
2015 || anArgCase == "-l"))
2017 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
2019 else if (anArgIt + 1 < theArgsNb
2020 && (anArgCase == "-top"
2021 || anArgCase == "-t"))
2023 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
2025 else if (anArgIt + 1 < theArgsNb
2026 && (anArgCase == "-width"
2027 || anArgCase == "-w"))
2029 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
2031 else if (anArgIt + 1 < theArgsNb
2032 && (anArgCase == "-height"
2033 || anArgCase == "-h"))
2035 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
2037 else if (anArgCase == "-exitonclose")
2039 Draw_ToExitOnCloseView = true;
2040 if (anArgIt + 1 < theArgsNb
2041 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
2046 else if (anArgCase == "-closeonescape"
2047 || anArgCase == "-closeonesc")
2049 Draw_ToCloseViewOnEsc = true;
2050 if (anArgIt + 1 < theArgsNb
2051 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
2056 else if (anArgCase == "-2d_mode"
2057 || anArgCase == "-2dmode"
2058 || anArgCase == "-2d")
2060 bool toEnable = true;
2061 if (anArgIt + 1 < theArgsNb
2062 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
2066 is2dMode = toEnable ? 1 : 0;
2068 else if (anArgIt + 1 < theArgsNb
2069 && (anArgCase == "-disp"
2070 || anArgCase == "-display"))
2072 aDisplayName = theArgVec[++anArgIt];
2074 else if (!ViewerTest::CurrentView().IsNull()
2075 && aCopyFrom.IsNull()
2076 && (anArgCase == "-copy"
2077 || anArgCase == "-clone"
2078 || anArgCase == "-cloneactive"
2079 || anArgCase == "-cloneactiveview"))
2081 aCopyFrom = ViewerTest::CurrentView();
2084 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
2087 if (aName == "name")
2091 else if (aName == "l"
2094 aPxLeft = aValue.IntegerValue();
2096 else if (aName == "t"
2099 aPxTop = aValue.IntegerValue();
2101 else if (aName == "disp"
2102 || aName == "display")
2104 aDisplayName = aValue;
2106 else if (aName == "w"
2107 || aName == "width")
2109 aPxWidth = aValue.IntegerValue();
2111 else if (aName == "h"
2112 || aName == "height")
2114 aPxHeight = aValue.IntegerValue();
2118 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
2122 else if (aViewName.IsEmpty())
2128 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
2133 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
2134 if (!aDisplayName.IsEmpty())
2136 aDisplayName.Clear();
2137 std::cout << "Warning: display parameter will be ignored.\n";
2141 ViewerTest_Names aViewNames (aViewName);
2142 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
2144 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
2145 theDi.Eval (aCommand.ToCString());
2148 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
2153 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
2154 aViewName, aDisplayName, aCopyFrom);
2157 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
2163 //! Parse HLR algo type.
2164 static Standard_Boolean parseHlrAlgoType (const char* theName,
2165 Prs3d_TypeOfHLR& theType)
2167 TCollection_AsciiString aName (theName);
2169 if (aName == "polyalgo")
2171 theType = Prs3d_TOH_PolyAlgo;
2173 else if (aName == "algo")
2175 theType = Prs3d_TOH_Algo;
2179 return Standard_False;
2181 return Standard_True;
2184 //==============================================================================
2186 //purpose : hidden lines removal algorithm
2187 //==============================================================================
2189 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2191 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2192 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2195 std::cerr << "Error: No opened viewer!\n";
2199 Standard_Boolean hasHlrOnArg = Standard_False;
2200 Standard_Boolean hasShowHiddenArg = Standard_False;
2201 Standard_Boolean isHLROn = Standard_False;
2202 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
2203 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
2204 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2205 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
2207 TCollection_AsciiString anArg (argv[anArgIter]);
2209 if (anUpdateTool.parseRedrawMode (anArg))
2213 else if (anArg == "-showhidden"
2214 && anArgIter + 1 < argc
2215 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
2218 hasShowHiddenArg = Standard_True;
2221 else if ((anArg == "-type"
2223 || anArg == "-algotype")
2224 && anArgIter + 1 < argc
2225 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
2230 else if (!hasHlrOnArg
2231 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
2233 hasHlrOnArg = Standard_True;
2237 else if (!hasShowHiddenArg
2238 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
2240 hasShowHiddenArg = Standard_True;
2245 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
2251 di << "HLR: " << aView->ComputedMode() << "\n";
2252 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
2254 switch (aCtx->DefaultDrawer()->TypeOfHLR())
2256 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
2257 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
2258 case Prs3d_TOH_Algo: di << "Algo\n"; break;
2260 anUpdateTool.Invalidate();
2264 Standard_Boolean toRecompute = Standard_False;
2265 if (aTypeOfHLR != Prs3d_TOH_NotSet
2266 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
2268 toRecompute = Standard_True;
2269 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
2271 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
2273 toRecompute = Standard_True;
2276 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
2280 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
2285 if (aView->ComputedMode() && isHLROn && toRecompute)
2287 AIS_ListOfInteractive aListOfShapes;
2288 aCtx->DisplayedObjects (aListOfShapes);
2289 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
2291 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
2293 aCtx->Redisplay (aShape, Standard_False);
2298 aView->SetComputedMode (isHLROn);
2302 //==============================================================================
2303 //function : VHLRType
2304 //purpose : change type of using HLR algorithm
2305 //==============================================================================
2307 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
2309 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2310 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2313 std::cerr << "Error: No opened viewer!\n";
2317 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
2318 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2319 AIS_ListOfInteractive aListOfShapes;
2320 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
2322 TCollection_AsciiString anArg (argv[anArgIter]);
2324 if (anUpdateTool.parseRedrawMode (anArg))
2328 else if ((anArg == "-type"
2330 || anArg == "-algotype")
2331 && anArgIter + 1 < argc
2332 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
2338 else if (aTypeOfHLR == Prs3d_TOH_NotSet
2339 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
2345 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
2346 TCollection_AsciiString aName (argv[anArgIter]);
2347 if (!aMap.IsBound2 (aName))
2349 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
2353 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
2354 if (aShape.IsNull())
2356 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
2359 aListOfShapes.Append (aShape);
2363 if (aTypeOfHLR == Prs3d_TOH_NotSet)
2365 std::cout << "Syntax error: wrong number of arguments!\n";
2369 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
2372 aCtx->DisplayedObjects (aListOfShapes);
2373 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
2376 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
2378 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
2379 if (aShape.IsNull())
2384 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
2385 && aView->ComputedMode();
2387 || aShape->TypeOfHLR() != aTypeOfHLR)
2389 aShape->SetTypeOfHLR (aTypeOfHLR);
2393 aCtx->Redisplay (aShape, Standard_False);
2399 //==============================================================================
2400 //function : FindViewIdByWindowHandle
2401 //purpose : Find theView Id in the map of views by window handle
2402 //==============================================================================
2403 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2404 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
2406 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
2407 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
2409 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
2410 if (aWindowHandle == theWindowHandle)
2411 return anIter.Key1();
2413 return TCollection_AsciiString("");
2417 //! Make the view active
2418 void ActivateView (const TCollection_AsciiString& theViewName,
2419 Standard_Boolean theToUpdate = Standard_True)
2421 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
2427 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
2428 if (!anAISContext.IsNull())
2430 if (!ViewerTest::CurrentView().IsNull())
2432 TCollection_AsciiString aTitle("3D View - ");
2433 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
2434 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
2437 ViewerTest::CurrentView (aView);
2438 ViewerTest::SetAISContext (anAISContext);
2439 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
2440 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
2442 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
2443 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
2444 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
2446 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
2448 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2451 ViewerTest::CurrentView()->Redraw();
2456 //==============================================================================
2457 //function : RemoveView
2459 //==============================================================================
2460 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
2461 const Standard_Boolean theToRemoveContext)
2463 if (!ViewerTest_myViews.IsBound2 (theView))
2468 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
2469 RemoveView (aViewName, theToRemoveContext);
2472 //==============================================================================
2473 //function : RemoveView
2474 //purpose : Close and remove view from display, clear maps if neccessary
2475 //==============================================================================
2476 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
2478 if (!ViewerTest_myViews.IsBound1(theViewName))
2480 cout << "Wrong view name\n";
2484 // Activate another view if it's active now
2485 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
2487 if (ViewerTest_myViews.Extent() > 1)
2489 TCollection_AsciiString aNewViewName;
2490 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
2491 anIter.More(); anIter.Next())
2493 if (anIter.Key1() != theViewName)
2495 aNewViewName = anIter.Key1();
2499 ActivateView (aNewViewName);
2503 VT_GetWindow().Nullify();
2504 ViewerTest::CurrentView (Handle(V3d_View)());
2505 if (isContextRemoved)
2507 Handle(AIS_InteractiveContext) anEmptyContext;
2508 ViewerTest::SetAISContext(anEmptyContext);
2514 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
2515 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
2516 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
2517 aRedrawer.Stop (aView->Window());
2519 // Remove view resources
2520 ViewerTest_myViews.UnBind1(theViewName);
2521 aView->Window()->Unmap();
2524 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2525 XFlush (GetDisplayConnection()->GetDisplay());
2528 // Keep context opened only if the closed view is last to avoid
2529 // unused empty contexts
2530 if (!aCurrentContext.IsNull())
2532 // Check if there are more difined views in the viewer
2533 aCurrentContext->CurrentViewer()->InitDefinedViews();
2534 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
2536 // Remove driver if there is no viewers that use it
2537 Standard_Boolean isRemoveDriver = Standard_True;
2538 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2539 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
2541 if (aCurrentContext != anIter.Key2() &&
2542 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
2544 isRemoveDriver = Standard_False;
2549 aCurrentContext->RemoveAll (Standard_False);
2552 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
2553 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2554 Tcl_DeleteFileHandler (XConnectionNumber (aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
2558 ViewerTest_myContexts.UnBind2(aCurrentContext);
2561 cout << "3D View - " << theViewName << " was deleted.\n";
2562 if (Draw_ToExitOnCloseView)
2564 Draw_Interprete ("exit");
2568 //==============================================================================
2570 //purpose : Remove the view defined by its name
2571 //==============================================================================
2573 static int VClose (Draw_Interpretor& /*theDi*/,
2574 Standard_Integer theArgsNb,
2575 const char** theArgVec)
2577 NCollection_List<TCollection_AsciiString> aViewList;
2580 TCollection_AsciiString anArg (theArgVec[1]);
2582 if (anArg.IsEqual ("ALL")
2583 || anArg.IsEqual ("*"))
2585 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
2586 anIter.More(); anIter.Next())
2588 aViewList.Append (anIter.Key1());
2590 if (aViewList.IsEmpty())
2592 std::cout << "No view to close\n";
2598 ViewerTest_Names aViewName (theArgVec[1]);
2599 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
2601 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
2604 aViewList.Append (aViewName.GetViewName());
2609 // close active view
2610 if (ViewerTest::CurrentView().IsNull())
2612 std::cerr << "No active view!\n";
2615 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
2618 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
2619 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
2620 anIter.More(); anIter.Next())
2622 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
2628 //==============================================================================
2629 //function : VActivate
2630 //purpose : Activate the view defined by its ID
2631 //==============================================================================
2633 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2637 theDi.Eval("vviewlist");
2641 TCollection_AsciiString aNameString;
2642 Standard_Boolean toUpdate = Standard_True;
2643 Standard_Boolean toActivate = Standard_True;
2644 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
2646 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2649 && anArg == "-noupdate")
2651 toUpdate = Standard_False;
2654 && aNameString.IsEmpty()
2657 TCollection_AsciiString aTitle("3D View - ");
2658 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
2659 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
2660 VT_GetWindow().Nullify();
2661 ViewerTest::CurrentView (Handle(V3d_View)());
2662 ViewerTest::ResetEventManager();
2663 theDi << theArgVec[0] << ": all views are inactive\n";
2664 toActivate = Standard_False;
2667 && aNameString.IsEmpty())
2669 aNameString = theArgVec[anArgIter];
2673 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
2682 else if (aNameString.IsEmpty())
2684 std::cout << "Syntax error: wrong number of arguments\n";
2688 // Check if this view exists in the viewer with the driver
2689 ViewerTest_Names aViewNames (aNameString);
2690 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
2692 theDi << "Syntax error: wrong view name '" << aNameString << "'\n";
2696 // Check if it is active already
2697 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
2699 theDi << theArgVec[0] << ": the view is active already\n";
2703 ActivateView (aViewNames.GetViewName(), toUpdate);
2707 //==============================================================================
2708 //function : VViewList
2709 //purpose : Print current list of views per viewer and graphic driver ID
2710 // shared between viewers
2711 //==============================================================================
2713 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2717 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
2718 << "Usage: " << theArgVec[0] << " name";
2721 if (ViewerTest_myContexts.Size() < 1)
2724 Standard_Boolean isTreeView =
2725 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
2729 theDi << theArgVec[0] <<":\n";
2732 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
2733 aDriverIter.More(); aDriverIter.Next())
2736 theDi << aDriverIter.Key1() << ":\n";
2738 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2739 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
2741 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
2745 TCollection_AsciiString aContextName(aContextIter.Key1());
2746 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
2749 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
2750 aViewIter.More(); aViewIter.Next())
2752 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
2754 TCollection_AsciiString aViewName(aViewIter.Key1());
2757 if (aViewIter.Value() == ViewerTest::CurrentView())
2758 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
2760 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
2764 theDi << aViewName << " ";
2774 //==============================================================================
2775 //function : VT_ProcessKeyPress
2776 //purpose : Handle KeyPress event from a CString
2777 //==============================================================================
2778 void VT_ProcessKeyPress (const char* buf_ret)
2780 //cout << "KeyPress" << endl;
2781 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2782 // Letter in alphabetic order
2784 if (!strcasecmp (buf_ret, "A")
2785 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
2788 aView->SetProj(V3d_XposYnegZpos);
2790 else if (!strcasecmp (buf_ret, "D")
2791 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
2796 else if (!strcasecmp (buf_ret, "F"))
2798 if (ViewerTest::GetAISContext()->NbSelected() > 0)
2800 ViewerTest::GetAISContext()->FitSelected (aView);
2808 else if (!strcasecmp (buf_ret, "H"))
2811 std::cout << "HLR" << std::endl;
2812 aView->SetComputedMode (!aView->ComputedMode());
2815 else if (!strcasecmp (buf_ret, "P"))
2818 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2819 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
2820 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
2822 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
2823 if (aContext->NbSelected()==0)
2825 AIS_ListOfInteractive aListOfShapes;
2826 aContext->DisplayedObjects(aListOfShapes);
2827 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
2828 anIter.More(); anIter.Next())
2830 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
2831 if (aShape.IsNull())
2833 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
2834 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
2836 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
2837 aContext->Redisplay (aShape, Standard_False);
2842 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
2844 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
2845 if (aShape.IsNull())
2847 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
2848 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
2850 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
2851 aContext->Redisplay (aShape, Standard_False);
2855 aContext->UpdateCurrentViewer();
2858 else if (!strcasecmp (buf_ret, "S"))
2860 std::cout << "setup Shaded display mode" << std::endl;
2862 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
2863 if(Ctx->NbSelected()==0)
2864 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
2866 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
2867 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
2868 Ctx->UpdateCurrentViewer();
2871 else if (!strcasecmp (buf_ret, "U"))
2873 // Unset display mode
2874 std::cout << "reset display mode to defaults" << std::endl;
2876 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
2877 if(Ctx->NbSelected()==0)
2878 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
2880 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
2881 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
2882 Ctx->UpdateCurrentViewer();
2886 else if (!strcasecmp (buf_ret, "T")
2887 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
2890 aView->SetProj(V3d_Zpos);
2892 else if (!strcasecmp (buf_ret, "B")
2893 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
2896 aView->SetProj(V3d_Zneg);
2898 else if (!strcasecmp (buf_ret, "L")
2899 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
2902 aView->SetProj(V3d_Xneg);
2904 else if (!strcasecmp (buf_ret, "R")
2905 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
2908 aView->SetProj(V3d_Xpos);
2910 else if (!strcasecmp (buf_ret, "W"))
2912 std::cout << "setup WireFrame display mode" << std::endl;
2913 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
2914 if(Ctx->NbSelected()==0)
2915 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
2917 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
2918 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
2919 Ctx->UpdateCurrentViewer();
2922 else if (!strcasecmp (buf_ret, ","))
2924 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
2926 else if (!strcasecmp (buf_ret, "."))
2928 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
2930 else if (!strcasecmp (buf_ret, "/"))
2932 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2933 if (aCamera->IsStereo())
2935 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
2939 else if (!strcasecmp (buf_ret, "*"))
2941 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2942 if (aCamera->IsStereo())
2944 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
2948 else if (*buf_ret == THE_KEY_DELETE)
2950 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2952 && aCtx->NbSelected() > 0)
2954 Draw_Interprete ("verase");
2957 else if (*buf_ret == THE_KEY_ESCAPE)
2959 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2961 && Draw_ToCloseViewOnEsc)
2963 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
2966 else if (*buf_ret >= '0' && *buf_ret <= '7') // Number
2968 const Standard_Integer aSelMode = Draw::Atoi (buf_ret);
2969 bool toEnable = true;
2970 if (const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext())
2972 AIS_ListOfInteractive aPrsList;
2973 aCtx->DisplayedObjects (aPrsList);
2974 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
2976 TColStd_ListOfInteger aModes;
2977 aCtx->ActivatedModes (aPrsIter.Value(), aModes);
2978 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
2980 if (aModeIter.Value() == aSelMode)
2987 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
2988 Draw_Interprete (aCmd.ToCString());
2992 //==============================================================================
2993 //function : VT_ProcessExpose
2994 //purpose : Redraw the View on an Expose Event
2995 //==============================================================================
2996 void VT_ProcessExpose()
2998 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
2999 if (!aView3d.IsNull())
3005 //==============================================================================
3006 //function : VT_ProcessConfigure
3007 //purpose : Resize the View on an Configure Event
3008 //==============================================================================
3009 void VT_ProcessConfigure()
3011 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
3012 if (aView3d.IsNull())
3017 aView3d->MustBeResized();
3022 //==============================================================================
3023 //function : VT_ProcessButton1Press
3025 //==============================================================================
3026 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
3027 const char** theArgVec,
3028 Standard_Boolean theToPick,
3029 Standard_Boolean theIsShift)
3033 TheIsAnimating = Standard_False;
3034 return Standard_False;
3039 Standard_Real X, Y, Z;
3040 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
3042 Draw::Set (theArgVec[1], X);
3043 Draw::Set (theArgVec[2], Y);
3044 Draw::Set (theArgVec[3], Z);
3049 ViewerTest::CurrentEventManager()->ShiftSelect();
3053 ViewerTest::CurrentEventManager()->Select();
3056 return Standard_False;
3059 //==============================================================================
3060 //function : VT_ProcessButton1Release
3061 //purpose : End selecting
3062 //==============================================================================
3063 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
3067 IsDragged = Standard_False;
3068 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
3071 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
3072 X_Motion, Y_Motion);
3076 EM->Select (X_ButtonPress, Y_ButtonPress,
3077 X_Motion, Y_Motion);
3082 //==============================================================================
3083 //function : VT_ProcessButton3Press
3084 //purpose : Start Rotation
3085 //==============================================================================
3086 void VT_ProcessButton3Press()
3088 if (ViewerTest_V3dView::IsCurrentViewIn2DMode())
3094 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
3095 if (HasHlrOnBeforeRotation)
3097 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
3099 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
3102 //==============================================================================
3103 //function : VT_ProcessButton3Release
3104 //purpose : End rotation
3105 //==============================================================================
3106 void VT_ProcessButton3Release()
3111 if (HasHlrOnBeforeRotation)
3113 HasHlrOnBeforeRotation = Standard_False;
3114 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
3115 ViewerTest::CurrentView()->Redraw();
3120 //==============================================================================
3121 //function : ProcessControlButton1Motion
3123 //==============================================================================
3125 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
3126 static void ProcessControlButton1Motion()
3128 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
3130 X_ButtonPress = X_Motion;
3131 Y_ButtonPress = Y_Motion;
3135 //==============================================================================
3136 //function : VT_ProcessControlButton2Motion
3138 //==============================================================================
3139 void VT_ProcessControlButton2Motion()
3141 Standard_Integer aDx = X_Motion - X_ButtonPress;
3142 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
3144 aDy = -aDy; // Xwindow Y axis is from top to Bottom
3146 ViewerTest::CurrentView()->Pan (aDx, aDy);
3148 X_ButtonPress = X_Motion;
3149 Y_ButtonPress = Y_Motion;
3152 //==============================================================================
3153 //function : VT_ProcessControlButton3Motion
3154 //purpose : Rotation
3155 //==============================================================================
3156 void VT_ProcessControlButton3Motion()
3160 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
3164 //==============================================================================
3165 //function : VT_ProcessMotion
3167 //==============================================================================
3168 void VT_ProcessMotion()
3170 //pre-hilights detected objects at mouse position
3172 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
3173 EM->MoveTo(X_Motion, Y_Motion);
3177 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
3179 Xpix = X_Motion;Ypix=Y_Motion;
3182 //==============================================================================
3183 //function : ViewProject: implements VAxo, VTop, VLeft, ...
3184 //purpose : Switches to an axonometric, top, left and other views
3185 //==============================================================================
3187 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
3189 if ( ViewerTest::CurrentView().IsNull() )
3191 di<<"Call vinit before this command, please\n";
3195 ViewerTest::CurrentView()->SetProj(ori);
3199 //==============================================================================
3201 //purpose : Switch to an Axonometric view
3202 //Draw arg : No args
3203 //==============================================================================
3205 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
3207 return ViewProject(di, V3d_XposYnegZpos);
3210 //==============================================================================
3212 //purpose : Switch to a Top View
3213 //Draw arg : No args
3214 //==============================================================================
3216 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
3218 return ViewProject(di, V3d_Zpos);
3221 //==============================================================================
3222 //function : VBottom
3223 //purpose : Switch to a Bottom View
3224 //Draw arg : No args
3225 //==============================================================================
3227 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
3229 return ViewProject(di, V3d_Zneg);
3232 //==============================================================================
3234 //purpose : Switch to a Left View
3235 //Draw arg : No args
3236 //==============================================================================
3238 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
3240 return ViewProject(di, V3d_Xneg);
3243 //==============================================================================
3245 //purpose : Switch to a Right View
3246 //Draw arg : No args
3247 //==============================================================================
3249 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
3251 return ViewProject(di, V3d_Xpos);
3254 //==============================================================================
3256 //purpose : Switch to a Front View
3257 //Draw arg : No args
3258 //==============================================================================
3260 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
3262 return ViewProject(di, V3d_Yneg);
3265 //==============================================================================
3267 //purpose : Switch to a Back View
3268 //Draw arg : No args
3269 //==============================================================================
3271 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
3273 return ViewProject(di, V3d_Ypos);
3276 //==============================================================================
3278 //purpose : Dsiplay help on viewer Keyboead and mouse commands
3279 //Draw arg : No args
3280 //==============================================================================
3282 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
3285 di << "Q : Quit the application\n";
3287 di << "=========================\n";
3288 di << "F : FitAll\n";
3289 di << "T : TopView\n";
3290 di << "B : BottomView\n";
3291 di << "R : RightView\n";
3292 di << "L : LeftView\n";
3293 di << "A : AxonometricView\n";
3294 di << "D : ResetView\n";
3296 di << "=========================\n";
3297 di << "S : Shading\n";
3298 di << "W : Wireframe\n";
3299 di << "H : HidelLineRemoval\n";
3300 di << "U : Unset display mode\n";
3301 di << "Delete : Remove selection from viewer\n";
3303 di << "=========================\n";
3304 di << "Selection mode \n";
3305 di << "0 : Shape\n";
3306 di << "1 : Vertex\n";
3310 di << "5 : Shell\n";
3311 di << "6 : Solid\n";
3312 di << "7 : Compound\n";
3314 di << "=========================\n";
3315 di << "Z : Switch Z clipping On/Off\n";
3316 di << ", : Hilight next detected\n";
3317 di << ". : Hilight previous detected\n";
3324 static Standard_Boolean Ppick = 0;
3325 static Standard_Integer Pargc = 0;
3326 static const char** Pargv = NULL;
3329 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
3334 if (!ViewerTest_myViews.IsEmpty()) {
3336 WPARAM fwKeys = wParam;
3341 // Delete view from map of views
3342 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
3347 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
3348 || ViewerTest::CurrentView().IsNull())
3350 // Activate inactive window
3351 if(GetWindowHandle(VT_GetWindow()) != hwnd)
3353 ActivateView (FindViewIdByWindowHandle(hwnd));
3359 if (IsDragged && !DragFirst)
3361 if (!GetActiveAISManipulator().IsNull())
3363 GetActiveAISManipulator()->StopTransform();
3364 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
3367 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
3369 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
3370 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
3373 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
3375 IsDragged = Standard_False;
3376 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
3379 if (IsDragged && !DragFirst)
3381 if (!GetActiveAISManipulator().IsNull())
3383 GetActiveAISManipulator()->StopTransform (Standard_False);
3384 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
3386 IsDragged = Standard_False;
3388 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
3390 case WM_LBUTTONDOWN:
3391 if (!GetActiveAISManipulator().IsNull())
3393 IsDragged = ( fwKeys == MK_LBUTTON );
3397 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
3402 DragFirst = Standard_True;
3403 X_ButtonPress = LOWORD(lParam);
3404 Y_ButtonPress = HIWORD(lParam);
3406 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
3411 X_Motion = LOWORD (lParam);
3412 Y_Motion = HIWORD (lParam);
3413 if (!GetActiveAISManipulator().IsNull())
3417 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
3421 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
3422 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
3427 bool toRedraw = false;
3428 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
3430 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
3435 if (GetClientRect (hwnd, &aRect))
3437 int aHeight = aRect.bottom - aRect.top;
3438 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
3439 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
3444 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
3448 DragFirst = Standard_False;
3451 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
3455 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
3459 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
3463 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
3469 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3472 return DefWindowProcW (hwnd, Msg, wParam, lParam);
3479 BeginPaint(hwnd, &ps);
3480 EndPaint(hwnd, &ps);
3485 VT_ProcessConfigure();
3490 switch (aView->RenderingParams().StereoMode)
3492 case Graphic3d_StereoMode_RowInterlaced:
3493 case Graphic3d_StereoMode_ColumnInterlaced:
3494 case Graphic3d_StereoMode_ChessBoard:
3495 VT_ProcessConfigure(); // track window moves to reverse stereo pair
3503 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
3506 c[0] = (char) wParam;
3508 if (wParam == VK_DELETE)
3510 c[0] = THE_KEY_DELETE;
3512 else if (wParam == VK_ESCAPE)
3514 c[0] = THE_KEY_ESCAPE;
3517 else if (wParam == VK_OEM_COMMA)
3522 else if (wParam == VK_OEM_PERIOD)
3526 else if (wParam == VK_DIVIDE)
3531 else if (wParam == VK_MULTIPLY)
3535 VT_ProcessKeyPress (c);
3543 VT_ProcessButton3Release();
3546 case WM_LBUTTONDOWN:
3547 case WM_MBUTTONDOWN:
3548 case WM_RBUTTONDOWN:
3550 WPARAM fwKeys = wParam;
3554 X_ButtonPress = LOWORD(lParam);
3555 Y_ButtonPress = HIWORD(lParam);
3557 if (Msg == WM_LBUTTONDOWN)
3559 if ((fwKeys & MK_CONTROL) != 0)
3561 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
3565 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
3568 else if (Msg == WM_RBUTTONDOWN)
3571 VT_ProcessButton3Press();
3578 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
3579 if (wParam & MK_CONTROL)
3581 if (aView->Camera()->IsStereo())
3583 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
3587 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
3594 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
3601 //cout << "\t WM_MOUSEMOVE" << endl;
3602 WPARAM fwKeys = wParam;
3603 X_Motion = LOWORD(lParam);
3604 Y_Motion = HIWORD(lParam);
3607 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
3610 X_ButtonPress = LOWORD(lParam);
3611 Y_ButtonPress = HIWORD(lParam);
3613 if ((fwKeys & MK_RBUTTON) != 0) {
3615 VT_ProcessButton3Press();
3619 if ((fwKeys & MK_CONTROL) != 0)
3621 if ((fwKeys & MK_LBUTTON) != 0)
3623 ProcessControlButton1Motion();
3625 else if ((fwKeys & MK_MBUTTON) != 0
3626 || ((fwKeys & MK_LBUTTON) != 0
3627 && (fwKeys & MK_RBUTTON) != 0))
3629 VT_ProcessControlButton2Motion();
3631 else if ((fwKeys & MK_RBUTTON) != 0)
3633 VT_ProcessControlButton3Motion();
3636 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
3644 return DefWindowProcW (hwnd, Msg, wParam, lParam);
3649 //==============================================================================
3650 //function : ViewerMainLoop
3651 //purpose : Get a Event on the view and dispatch it
3652 //==============================================================================
3655 int ViewerMainLoop(Standard_Integer argc, const char** argv)
3657 Ppick = (argc > 0)? 1 : 0;
3665 cout << "Start picking" << endl;
3667 while ( Ppick == 1 ) {
3668 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
3669 if (GetMessageW (&msg, NULL, 0, 0))
3671 TranslateMessage (&msg);
3672 DispatchMessageW (&msg);
3676 cout << "Picking done" << endl;
3682 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
3684 int min( int a, int b )
3692 int max( int a, int b )
3700 int ViewerMainLoop (Standard_Integer argc, const char** argv)
3702 static XEvent aReport;
3703 const Standard_Boolean toPick = argc > 0;
3704 Standard_Boolean toPickMore = toPick;
3705 Display* aDisplay = GetDisplayConnection()->GetDisplay();
3706 XNextEvent (aDisplay, &aReport);
3708 // Handle event for the chosen display connection
3709 switch (aReport.type)
3713 if ((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
3716 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
3717 return toPick ? 0 : 1;
3723 // Activate inactive view
3724 Window aWindow = GetWindowHandle(VT_GetWindow());
3725 if (aWindow != aReport.xfocus.window)
3727 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
3733 Window anXWindow = GetWindowHandle (VT_GetWindow());
3734 if (anXWindow == aReport.xexpose.window)
3739 // remove all the ExposureMask and process them at once
3740 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3742 if (!XCheckWindowEvent (aDisplay, anXWindow, ExposureMask, &aReport))
3750 case ConfigureNotify:
3752 // remove all the StructureNotifyMask and process them at once
3753 Window anXWindow = GetWindowHandle (VT_GetWindow());
3754 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3756 if (!XCheckWindowEvent (aDisplay, anXWindow, StructureNotifyMask, &aReport))
3762 if (anXWindow == aReport.xconfigure.window)
3764 VT_ProcessConfigure();
3772 XComposeStatus status_in_out;
3773 int aKeyLen = XLookupString ((XKeyEvent* )&aReport, (char* )aKeyBuf, 10, &aKeySym, &status_in_out);
3774 aKeyBuf[aKeyLen] = '\0';
3777 VT_ProcessKeyPress (aKeyBuf);
3783 X_ButtonPress = aReport.xbutton.x;
3784 Y_ButtonPress = aReport.xbutton.y;
3785 if (aReport.xbutton.button == Button1)
3787 if (aReport.xbutton.state & ControlMask)
3789 toPickMore = VT_ProcessButton1Press (argc, argv, toPick, (aReport.xbutton.state & ShiftMask) != 0);
3793 IsDragged = Standard_True;
3794 DragFirst = Standard_True;
3797 else if (aReport.xbutton.button == Button3)
3800 VT_ProcessButton3Press();
3808 VT_ProcessButton3Release();
3812 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3813 if (aContext.IsNull())
3815 std::cout << "Error: No active view.\n";
3820 && aContext->IsDisplayed (GetRubberBand()))
3822 aContext->Remove (GetRubberBand(), Standard_False);
3823 aContext->CurrentViewer()->RedrawImmediate();
3826 if (aReport.xbutton.button != Button1)
3831 const Standard_Boolean isShiftPressed = (aReport.xbutton.state & ShiftMask) != 0;
3836 aContext->ShiftSelect (Standard_True);
3840 aContext->Select (Standard_True);
3847 aContext->ShiftSelect (Min (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion),
3848 Max (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
3849 ViewerTest::CurrentView(), Standard_True);
3853 aContext->Select (Min (X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
3854 Max (X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
3855 ViewerTest::CurrentView(), Standard_True);
3858 IsDragged = Standard_False;
3863 Window anXWindow = GetWindowHandle (VT_GetWindow());
3864 if (anXWindow != aReport.xmotion.window)
3869 // remove all the ButtonMotionMask and process them at once
3870 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3872 if (!XCheckWindowEvent (aDisplay, anXWindow, ButtonMotionMask | PointerMotionMask, &aReport))
3881 && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
3883 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
3886 X_Motion = aReport.xmotion.x;
3887 Y_Motion = aReport.xmotion.y;
3888 DragFirst = Standard_False;
3890 Window aWindow = GetWindowHandle(VT_GetWindow());
3893 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
3894 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
3895 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
3896 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
3897 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
3901 X_Motion = aReport.xmotion.x;
3902 Y_Motion = aReport.xmotion.y;
3903 if ((aReport.xmotion.state & ControlMask) != 0)
3905 if ((aReport.xmotion.state & Button1Mask) != 0)
3907 ProcessControlButton1Motion();
3909 else if ((aReport.xmotion.state & Button2Mask) != 0)
3911 VT_ProcessControlButton2Motion();
3913 else if ((aReport.xmotion.state & Button3Mask) != 0)
3915 VT_ProcessControlButton3Motion();
3926 return (!toPick || toPickMore) ? 1 : 0;
3929 //==============================================================================
3930 //function : VProcessEvents
3931 //purpose : manage the event in the Viewer window (see Tcl_CreateFileHandler())
3932 //==============================================================================
3933 static void VProcessEvents (ClientData theDispX, int)
3935 Display* aDispX = (Display* )theDispX;
3936 Handle(Aspect_DisplayConnection) aDispConn;
3937 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
3938 aDriverIter (ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
3940 const Handle(Aspect_DisplayConnection)& aDispConnTmp = aDriverIter.Key2()->GetDisplayConnection();
3941 if (aDispConnTmp->GetDisplay() == aDispX)
3943 aDispConn = aDispConnTmp;
3947 if (aDispConn.IsNull())
3949 std::cerr << "Error: ViewerTest is unable processing messages for unknown X Display\n";
3953 // process new events in queue
3954 SetDisplayConnection (aDispConn);
3956 for (int aNbEventsMax = XPending (aDispX), anEventIter (0);;)
3958 const int anEventResult = ViewerMainLoop (0, NULL);
3959 if (anEventResult == 0)
3964 aNbRemain = XPending (aDispX);
3965 if (++anEventIter >= aNbEventsMax
3972 // Listening X events through Tcl_CreateFileHandler() callback is fragile,
3973 // it is possible that new events will arrive to queue before the end of this callback
3974 // so that either this callback should go into an infinite loop (blocking processing of other events)
3975 // or to keep unprocessed events till the next queue update (which can arrive not soon).
3976 // Sending a dummy event in this case is a simple workaround (still, it is possible that new event will be queued in-between).
3980 memset (&aDummyEvent, 0, sizeof(aDummyEvent));
3981 aDummyEvent.type = ClientMessage;
3982 aDummyEvent.xclient.format = 32;
3983 XSendEvent (aDispX, InputFocus, False, 0, &aDummyEvent);
3987 if (const Handle(AIS_InteractiveContext)& anActiveCtx = ViewerTest::GetAISContext())
3989 SetDisplayConnection (anActiveCtx->CurrentViewer()->Driver()->GetDisplayConnection());
3994 //==============================================================================
3995 //function : OSWindowSetup
3996 //purpose : Setup for the X11 window to be able to cath the event
3997 //==============================================================================
4000 static void OSWindowSetup()
4002 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4005 Window window = VT_GetWindow()->XWindow();
4006 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
4007 Display *aDisplay = GetDisplayConnection()->GetDisplay();
4008 XSynchronize(aDisplay, 1);
4010 // X11 : For keyboard on SUN
4012 wmhints.flags = InputHint;
4015 XSetWMHints( aDisplay, window, &wmhints);
4017 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
4018 ButtonPressMask | ButtonReleaseMask |
4019 StructureNotifyMask |
4021 Button1MotionMask | Button2MotionMask |
4022 Button3MotionMask | FocusChangeMask
4024 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
4025 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
4027 XSynchronize(aDisplay, 0);
4035 //==============================================================================
4038 //==============================================================================
4040 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
4042 const Handle(V3d_View) aView = ViewerTest::CurrentView();
4045 std::cout << "Error: no active viewer!\n";
4049 Standard_Boolean toFit = Standard_True;
4050 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
4051 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4053 TCollection_AsciiString anArg (theArgv[anArgIter]);
4055 if (anUpdateTool.parseRedrawMode (anArg))
4059 else if (anArg == "-selected")
4061 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
4062 toFit = Standard_False;
4066 std::cout << "Syntax error at '" << anArg << "'\n";
4072 aView->FitAll (0.01, Standard_False);
4077 //=======================================================================
4078 //function : VFitArea
4079 //purpose : Fit view to show area located between two points
4080 // : given in world 2D or 3D coordinates.
4081 //=======================================================================
4082 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4084 Handle(V3d_View) aView = ViewerTest::CurrentView();
4087 std::cerr << theArgVec[0] << "Error: No active view.\n";
4092 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
4093 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
4097 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
4098 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
4099 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
4100 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
4102 else if (theArgNb == 7)
4104 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
4105 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
4106 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
4107 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
4108 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
4109 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
4113 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
4114 theDI.PrintHelp(theArgVec[0]);
4118 // Convert model coordinates to view space
4119 Handle(Graphic3d_Camera) aCamera = aView->Camera();
4120 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
4121 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
4123 // Determine fit area
4124 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
4125 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
4127 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
4129 if (aDiagonal < Precision::Confusion())
4131 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
4135 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
4139 //==============================================================================
4141 //purpose : ZFitall, no DRAW arguments
4142 //Draw arg : No args
4143 //==============================================================================
4144 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
4146 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
4148 if (aCurrentView.IsNull())
4150 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
4156 aCurrentView->ZFitAll();
4157 aCurrentView->Redraw();
4161 Standard_Real aScale = 1.0;
4165 aScale = Draw::Atoi (theArgVec[1]);
4168 aCurrentView->ZFitAll (aScale);
4169 aCurrentView->Redraw();
4174 //==============================================================================
4175 //function : VRepaint
4177 //==============================================================================
4178 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
4180 Handle(V3d_View) aView = ViewerTest::CurrentView();
4183 std::cout << "Error: no active viewer!\n";
4187 Standard_Boolean isImmediateUpdate = Standard_False;
4188 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4190 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4192 if (anArg == "-immediate"
4195 isImmediateUpdate = Standard_True;
4196 if (anArgIter + 1 < theArgNb
4197 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
4202 else if (anArg == "-continuous"
4205 || anArg == "-framerate")
4207 Standard_Real aFps = -1.0;
4208 if (anArgIter + 1 < theArgNb
4209 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue())
4211 aFps = Draw::Atof (theArgVec[++anArgIter]);
4214 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
4215 if (Abs (aFps) >= 1.0)
4217 aRedrawer.Start (aView->Window(), aFps);
4226 std::cout << "Syntax error at '" << anArg << "'\n";
4231 if (isImmediateUpdate)
4233 aView->RedrawImmediate();
4242 //==============================================================================
4244 //purpose : Remove all the object from the viewer
4245 //Draw arg : No args
4246 //==============================================================================
4248 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
4250 Handle(V3d_View) V = ViewerTest::CurrentView();
4252 ViewerTest::Clear();
4256 //==============================================================================
4259 //==============================================================================
4261 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4262 { if (ViewerTest::CurrentView().IsNull() ) return 1;
4265 di << argv[0] << "Invalid number of arguments\n";
4269 while (ViewerMainLoop( argc, argv)) {
4278 //! Changes the background
4279 //! @param theDrawInterpretor the interpreter of the Draw Harness application
4280 //! @param theNumberOfCommandLineArguments the number of passed command line arguments
4281 //! @param theCommandLineArguments the array of command line arguments
4282 //! @return TCL_OK if changing was successful, or TCL_ERROR otherwise
4283 static int vbackground (Draw_Interpretor& theDrawInterpretor,
4284 const Standard_Integer theNumberOfCommandLineArguments,
4285 const char** const theCommandLineArguments)
4287 if (theNumberOfCommandLineArguments < 1)
4291 BackgroundChanger aBackgroundChanger;
4292 if (!aBackgroundChanger.ProcessCommandLine (theDrawInterpretor,
4293 theNumberOfCommandLineArguments,
4294 theCommandLineArguments))
4296 theDrawInterpretor << "Wrong command arguments.\n"
4298 << theCommandLineArguments[0] << "' for information about command options and its arguments.\n";
4306 //==============================================================================
4308 //purpose : View Scaling
4309 //==============================================================================
4311 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4313 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4314 if ( V3dView.IsNull() ) return 1;
4317 di << argv[0] << "Invalid number of arguments\n";
4320 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
4323 //==============================================================================
4324 //function : VZBuffTrihedron
4326 //==============================================================================
4328 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
4329 Standard_Integer theArgNb,
4330 const char** theArgVec)
4332 Handle(V3d_View) aView = ViewerTest::CurrentView();
4335 std::cout << "Error: no active viewer!\n";
4339 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
4341 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
4342 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
4343 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
4344 Quantity_Color anArrowColorX = Quantity_NOC_RED;
4345 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
4346 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
4347 Standard_Real aScale = 0.1;
4348 Standard_Real aSizeRatio = 0.8;
4349 Standard_Real anArrowDiam = 0.05;
4350 Standard_Integer aNbFacets = 12;
4351 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4353 Standard_CString anArg = theArgVec[anArgIter];
4354 TCollection_AsciiString aFlag (anArg);
4356 if (anUpdateTool.parseRedrawMode (aFlag))
4360 else if (aFlag == "-on")
4364 else if (aFlag == "-off")
4366 aView->TriedronErase();
4369 else if (aFlag == "-pos"
4370 || aFlag == "-position"
4371 || aFlag == "-corner")
4373 if (++anArgIter >= theArgNb)
4375 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4379 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
4380 aPosName.LowerCase();
4381 if (aPosName == "center")
4383 aPosition = Aspect_TOTP_CENTER;
4385 else if (aPosName == "left_lower"
4386 || aPosName == "lower_left"
4387 || aPosName == "leftlower"
4388 || aPosName == "lowerleft")
4390 aPosition = Aspect_TOTP_LEFT_LOWER;
4392 else if (aPosName == "left_upper"
4393 || aPosName == "upper_left"
4394 || aPosName == "leftupper"
4395 || aPosName == "upperleft")
4397 aPosition = Aspect_TOTP_LEFT_UPPER;
4399 else if (aPosName == "right_lower"
4400 || aPosName == "lower_right"
4401 || aPosName == "rightlower"
4402 || aPosName == "lowerright")
4404 aPosition = Aspect_TOTP_RIGHT_LOWER;
4406 else if (aPosName == "right_upper"
4407 || aPosName == "upper_right"
4408 || aPosName == "rightupper"
4409 || aPosName == "upperright")
4411 aPosition = Aspect_TOTP_RIGHT_UPPER;
4415 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
4419 else if (aFlag == "-type")
4421 if (++anArgIter >= theArgNb)
4423 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4427 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
4428 aTypeName.LowerCase();
4429 if (aTypeName == "wireframe"
4430 || aTypeName == "wire")
4432 aVisType = V3d_WIREFRAME;
4434 else if (aTypeName == "zbuffer"
4435 || aTypeName == "shaded")
4437 aVisType = V3d_ZBUFFER;
4441 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
4444 else if (aFlag == "-scale")
4446 if (++anArgIter >= theArgNb)
4448 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4452 aScale = Draw::Atof (theArgVec[anArgIter]);
4454 else if (aFlag == "-size"
4455 || aFlag == "-sizeratio")
4457 if (++anArgIter >= theArgNb)
4459 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4463 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
4465 else if (aFlag == "-arrowdiam"
4466 || aFlag == "-arrowdiameter")
4468 if (++anArgIter >= theArgNb)
4470 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4474 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
4476 else if (aFlag == "-nbfacets")
4478 if (++anArgIter >= theArgNb)
4480 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4484 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
4486 else if (aFlag == "-colorlabel"
4487 || aFlag == "-colorlabels")
4489 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4490 theArgVec + anArgIter + 1,
4494 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4497 anArgIter += aNbParsed;
4499 else if (aFlag == "-colorarrowx")
4501 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4502 theArgVec + anArgIter + 1,
4506 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4509 anArgIter += aNbParsed;
4511 else if (aFlag == "-colorarrowy")
4513 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4514 theArgVec + anArgIter + 1,
4518 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4521 anArgIter += aNbParsed;
4523 else if (aFlag == "-colorarrowz")
4525 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4526 theArgVec + anArgIter + 1,
4530 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4533 anArgIter += aNbParsed;
4537 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4542 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
4543 aSizeRatio, anArrowDiam, aNbFacets);
4544 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
4549 //==============================================================================
4550 //function : VRotate
4551 //purpose : Camera Rotating
4552 //==============================================================================
4554 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
4556 Handle(V3d_View) aView = ViewerTest::CurrentView();
4559 std::cout << "No active view!\n";
4563 Standard_Boolean hasFlags = Standard_False;
4564 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4566 Standard_CString anArg (theArgVec[anArgIter]);
4567 TCollection_AsciiString aFlag (anArg);
4569 if (aFlag == "-mousestart"
4570 || aFlag == "-mousefrom")
4572 hasFlags = Standard_True;
4573 if (anArgIter + 2 >= theArgNb)
4575 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4579 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
4580 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
4581 aView->StartRotation (anX, anY);
4583 else if (aFlag == "-mousemove")
4585 hasFlags = Standard_True;
4586 if (anArgIter + 2 >= theArgNb)
4588 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4592 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
4593 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
4594 aView->Rotation (anX, anY);
4596 else if (theArgNb != 4
4599 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4608 else if (theArgNb == 4)
4610 Standard_Real anAX = Draw::Atof (theArgVec[1]);
4611 Standard_Real anAY = Draw::Atof (theArgVec[2]);
4612 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
4613 aView->Rotate (anAX, anAY, anAZ);
4616 else if (theArgNb == 7)
4618 Standard_Real anAX = Draw::Atof (theArgVec[1]);
4619 Standard_Real anAY = Draw::Atof (theArgVec[2]);
4620 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
4622 Standard_Real anX = Draw::Atof (theArgVec[4]);
4623 Standard_Real anY = Draw::Atof (theArgVec[5]);
4624 Standard_Real anZ = Draw::Atof (theArgVec[6]);
4626 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
4630 std::cout << "Error: Invalid number of arguments\n";
4634 //==============================================================================
4636 //purpose : View zoom in / out (relative to current zoom)
4637 //==============================================================================
4639 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4640 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4641 if ( V3dView.IsNull() ) {
4646 Standard_Real coef = Draw::Atof(argv[1]);
4647 if ( coef <= 0.0 ) {
4648 di << argv[1] << "Invalid value\n";
4651 V3dView->SetZoom( Draw::Atof(argv[1]) );
4654 di << argv[0] << " Invalid number of arguments\n";
4659 //==============================================================================
4661 //purpose : View panning (in pixels)
4662 //==============================================================================
4664 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4665 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4666 if ( V3dView.IsNull() ) return 1;
4669 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
4672 di << argv[0] << " Invalid number of arguments\n";
4677 //==============================================================================
4679 //purpose : Place the point (in pixels) at the center of the window
4680 //==============================================================================
4681 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
4683 Handle(V3d_View) aView = ViewerTest::CurrentView();
4686 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
4692 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
4696 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
4701 static int VColorScale (Draw_Interpretor& theDI,
4702 Standard_Integer theArgNb,
4703 const char** theArgVec)
4705 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4706 Handle(V3d_View) aView = ViewerTest::CurrentView();
4707 if (aContext.IsNull())
4709 std::cout << "Error: no active view!\n";
4714 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
4718 Handle(AIS_ColorScale) aColorScale;
4719 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
4721 // find existing object
4722 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
4723 if (aColorScale.IsNull())
4725 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
4732 if (aColorScale.IsNull())
4734 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
4738 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
4739 << "Min range: " << aColorScale->GetMin() << "\n"
4740 << "Max range: " << aColorScale->GetMax() << "\n"
4741 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
4742 << "Text height: " << aColorScale->GetTextHeight() << "\n"
4743 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
4744 << "Color scale title: " << aColorScale->GetTitle() << "\n"
4745 << "Label position: ";
4746 switch (aColorScale->GetLabelPosition())
4748 case Aspect_TOCSP_NONE:
4751 case Aspect_TOCSP_LEFT:
4754 case Aspect_TOCSP_RIGHT:
4757 case Aspect_TOCSP_CENTER:
4758 theDI << "Center\n";
4764 if (aColorScale.IsNull())
4766 aColorScale = new AIS_ColorScale();
4767 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4768 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
4771 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
4772 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
4774 Standard_CString anArg = theArgVec[anArgIter];
4775 TCollection_AsciiString aFlag (anArg);
4777 if (anUpdateTool.parseRedrawMode (aFlag))
4781 else if (aFlag == "-range")
4783 if (anArgIter + 3 >= theArgNb)
4785 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4789 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
4790 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
4791 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
4792 if (!aRangeMin.IsRealValue()
4793 || !aRangeMax.IsRealValue())
4795 std::cout << "Error: the range values should be real!\n";
4798 else if (!aNbIntervals.IsIntegerValue())
4800 std::cout << "Error: the number of intervals should be integer!\n";
4804 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
4805 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
4807 else if (aFlag == "-font")
4809 if (anArgIter + 1 >= theArgNb)
4811 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4814 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
4815 if (!aFontArg.IsIntegerValue())
4817 std::cout << "Error: HeightFont value should be integer!\n";
4821 aColorScale->SetTextHeight (aFontArg.IntegerValue());
4824 else if (aFlag == "-textpos")
4826 if (anArgIter + 1 >= theArgNb)
4828 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4832 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
4833 aTextPosArg.LowerCase();
4834 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
4835 if (aTextPosArg == "none")
4837 aLabPosition = Aspect_TOCSP_NONE;
4839 else if (aTextPosArg == "left")
4841 aLabPosition = Aspect_TOCSP_LEFT;
4843 else if (aTextPosArg == "right")
4845 aLabPosition = Aspect_TOCSP_RIGHT;
4847 else if (aTextPosArg == "center")
4849 aLabPosition = Aspect_TOCSP_CENTER;
4853 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
4856 aColorScale->SetLabelPosition (aLabPosition);
4858 else if (aFlag == "-logarithmic"
4861 if (anArgIter + 1 >= theArgNb)
4863 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4867 Standard_Boolean IsLog;
4868 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
4870 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4873 aColorScale->SetLogarithmic (IsLog);
4875 else if (aFlag == "-huerange"
4878 if (anArgIter + 2 >= theArgNb)
4880 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4884 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
4885 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
4886 aColorScale->SetHueRange (aHueMin, aHueMax);
4888 else if (aFlag == "-colorrange")
4890 Quantity_Color aColorMin, aColorMax;
4891 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4892 theArgVec + (anArgIter + 1),
4894 anArgIter += aNbParsed1;
4895 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4896 theArgVec + (anArgIter + 1),
4898 anArgIter += aNbParsed2;
4902 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4906 aColorScale->SetColorRange (aColorMin, aColorMax);
4908 else if (aFlag == "-reversed"
4909 || aFlag == "-inverted"
4910 || aFlag == "-topdown"
4911 || aFlag == "-bottomup")
4913 Standard_Boolean toEnable = Standard_True;
4914 if (anArgIter + 1 < theArgNb
4915 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
4919 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
4921 else if (aFlag == "-smooth"
4922 || aFlag == "-smoothtransition")
4924 Standard_Boolean toEnable = Standard_True;
4925 if (anArgIter + 1 < theArgNb
4926 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4930 aColorScale->SetSmoothTransition (toEnable);
4932 else if (aFlag == "-xy")
4934 if (anArgIter + 2 >= theArgNb)
4936 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4940 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
4941 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
4942 if (!anX.IsIntegerValue()
4943 || !anY.IsIntegerValue())
4945 std::cout << "Error: coordinates should be integer values!\n";
4949 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
4951 else if (aFlag == "-width"
4953 || aFlag == "-breadth")
4955 if (anArgIter + 1 >= theArgNb)
4957 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4961 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
4962 if (!aBreadth.IsIntegerValue())
4964 std::cout << "Error: a width should be an integer value!\n";
4967 aColorScale->SetBreadth (aBreadth.IntegerValue());
4969 else if (aFlag == "-height"
4972 if (anArgIter + 1 >= theArgNb)
4974 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4978 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
4979 if (!aHeight.IsIntegerValue())
4981 std::cout << "Error: a width should be an integer value!\n";
4984 aColorScale->SetHeight (aHeight.IntegerValue());
4986 else if (aFlag == "-color")
4988 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4990 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
4993 else if (anArgIter + 2 >= theArgNb)
4995 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4999 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
5000 if (!anInd.IsIntegerValue())
5002 std::cout << "Error: Index value should be integer!\n";
5005 const Standard_Integer anIndex = anInd.IntegerValue();
5006 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
5008 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
5012 Quantity_Color aColor;
5013 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
5014 theArgVec + (anArgIter + 1),
5018 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
5021 aColorScale->SetIntervalColor (aColor, anIndex);
5022 aColorScale->SetColorType (Aspect_TOCSD_USER);
5023 anArgIter += aNbParsed;
5025 else if (aFlag == "-label")
5027 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
5029 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
5032 else if (anArgIter + 2 >= theArgNb)
5034 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
5038 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
5039 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
5041 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
5045 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
5046 aColorScale->SetLabel (aText, anIndex);
5047 aColorScale->SetLabelType (Aspect_TOCSD_USER);
5050 else if (aFlag == "-labelat"
5051 || aFlag == "-labat"
5052 || aFlag == "-labelatborder"
5053 || aFlag == "-labatborder"
5054 || aFlag == "-labelatcenter"
5055 || aFlag == "-labatcenter")
5057 Standard_Boolean toEnable = Standard_True;
5058 if (aFlag == "-labelat"
5059 || aFlag == "-labat")
5061 Standard_Integer aLabAtBorder = -1;
5062 if (++anArgIter >= theArgNb)
5064 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
5065 anAtBorder.LowerCase();
5066 if (anAtBorder == "border")
5070 else if (anAtBorder == "center")
5075 if (aLabAtBorder == -1)
5077 std::cout << "Syntax error at argument '" << anArg << "'!\n";
5080 toEnable = (aLabAtBorder == 1);
5082 else if (anArgIter + 1 < theArgNb
5083 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
5087 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
5088 || aFlag == "-labatcenter"
5092 else if (aFlag == "-colors")
5094 Aspect_SequenceOfColor aSeq;
5097 Quantity_Color aColor;
5098 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
5099 theArgVec + (anArgIter + 1),
5105 anArgIter += aNbParsed;
5106 aSeq.Append (aColor);
5108 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
5110 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
5111 << aColorScale->GetNumberOfIntervals() << " intervals\n";
5115 aColorScale->SetColors (aSeq);
5116 aColorScale->SetColorType (Aspect_TOCSD_USER);
5118 else if (aFlag == "-labels"
5119 || aFlag == "-freelabels")
5121 if (anArgIter + 1 >= theArgNb)
5123 std::cout << "Syntax error at argument '" << anArg << "'!\n";
5127 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
5128 ? aColorScale->GetNumberOfIntervals() + 1
5129 : aColorScale->GetNumberOfIntervals();
5130 if (aFlag == "-freelabels")
5133 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
5135 if (anArgIter + aNbLabels >= theArgNb)
5137 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
5141 TColStd_SequenceOfExtendedString aSeq;
5142 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
5144 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
5146 aColorScale->SetLabels (aSeq);
5147 aColorScale->SetLabelType (Aspect_TOCSD_USER);
5149 else if (aFlag == "-title")
5151 if (anArgIter + 1 >= theArgNb)
5153 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
5157 Standard_Boolean isTwoArgs = Standard_False;
5158 if (anArgIter + 2 < theArgNb)
5160 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
5161 aSecondArg.LowerCase();
5162 Standard_DISABLE_DEPRECATION_WARNINGS
5163 if (aSecondArg == "none")
5165 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
5166 isTwoArgs = Standard_True;
5168 else if (aSecondArg == "left")
5170 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
5171 isTwoArgs = Standard_True;
5173 else if (aSecondArg == "right")
5175 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
5176 isTwoArgs = Standard_True;
5178 else if (aSecondArg == "center")
5180 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
5181 isTwoArgs = Standard_True;
5183 Standard_ENABLE_DEPRECATION_WARNINGS
5186 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
5193 else if (aFlag == "-demoversion"
5194 || aFlag == "-demo")
5196 aColorScale->SetPosition (0, 0);
5197 aColorScale->SetTextHeight (16);
5198 aColorScale->SetRange (0.0, 100.0);
5199 aColorScale->SetNumberOfIntervals (10);
5200 aColorScale->SetBreadth (0);
5201 aColorScale->SetHeight (0);
5202 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
5203 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
5204 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
5206 else if (aFlag == "-findcolor")
5208 if (anArgIter + 1 >= theArgNb)
5210 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
5214 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
5216 if (!anArg1.IsRealValue())
5218 std::cout << "Error: the value should be real!\n";
5222 Quantity_Color aColor;
5223 aColorScale->FindColor (anArg1.RealValue(), aColor);
5224 theDI << Quantity_Color::StringName (aColor.Name());
5229 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
5234 Standard_Integer aWinWidth = 0, aWinHeight = 0;
5235 aView->Window()->Size (aWinWidth, aWinHeight);
5236 if (aColorScale->GetBreadth() == 0)
5238 aColorScale->SetBreadth (aWinWidth);
5240 if (aColorScale->GetHeight() == 0)
5242 aColorScale->SetHeight (aWinHeight);
5244 aColorScale->SetToUpdate();
5245 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
5249 //==============================================================================
5250 //function : VGraduatedTrihedron
5251 //purpose : Displays or hides a graduated trihedron
5252 //==============================================================================
5253 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
5254 Quantity_Color& theColor)
5256 Quantity_NameOfColor aColorName;
5257 TCollection_AsciiString aVal = theValue;
5259 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
5261 return Standard_False;
5263 theColor = Quantity_Color (aColorName);
5264 return Standard_True;
5267 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
5271 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
5272 << theArgs[0] <<"' for more information.\n";
5273 return 1; //TCL_ERROR
5276 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
5277 TCollection_AsciiString aParseKey;
5278 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
5280 TCollection_AsciiString anArg (theArgs [anArgIt]);
5282 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5285 aParseKey.Remove (1);
5286 aParseKey.LowerCase();
5287 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5291 if (aParseKey.IsEmpty())
5296 aMapOfArgs(aParseKey)->Append (anArg);
5300 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
5301 aMapIt.More(); aMapIt.Next())
5303 const TCollection_AsciiString& aKey = aMapIt.Key();
5304 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
5306 // Bool key, without arguments
5307 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
5308 && anArgs->IsEmpty())
5314 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
5315 && anArgs->Length() == 1)
5321 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
5322 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
5323 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
5324 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
5325 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
5330 // One string argument
5331 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
5332 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
5333 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
5338 // One integer argument
5339 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
5340 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
5341 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
5342 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
5343 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
5348 // One real argument
5349 if ( aKey.IsEqual ("arrowlength")
5350 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
5355 // Two string arguments
5356 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
5357 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
5362 TCollection_AsciiString aLowerKey;
5365 aLowerKey.LowerCase();
5366 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
5367 std::cout << "Type help for more information.\n";
5371 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5372 if (anAISContext.IsNull())
5374 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
5378 Standard_Boolean toDisplay = Standard_True;
5379 Quantity_Color aColor;
5380 Graphic3d_GraduatedTrihedron aTrihedronData;
5381 // Process parameters
5382 Handle(TColStd_HSequenceOfAsciiString) aValues;
5383 if (aMapOfArgs.Find ("off", aValues))
5385 toDisplay = Standard_False;
5389 if (aMapOfArgs.Find ("xname", aValues))
5391 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
5393 if (aMapOfArgs.Find ("yname", aValues))
5395 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
5397 if (aMapOfArgs.Find ("zname", aValues))
5399 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
5401 if (aMapOfArgs.Find ("xdrawname", aValues))
5403 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5405 if (aMapOfArgs.Find ("ydrawname", aValues))
5407 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5409 if (aMapOfArgs.Find ("zdrawname", aValues))
5411 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5413 if (aMapOfArgs.Find ("xnameoffset", aValues))
5415 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5417 if (aMapOfArgs.Find ("ynameoffset", aValues))
5419 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5421 if (aMapOfArgs.Find ("znameoffset", aValues))
5423 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5427 if (aMapOfArgs.Find ("xnamecolor", aValues))
5429 if (!GetColor (aValues->Value(1), aColor))
5431 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
5434 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
5436 if (aMapOfArgs.Find ("ynamecolor", aValues))
5438 if (!GetColor (aValues->Value(1), aColor))
5440 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
5443 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
5445 if (aMapOfArgs.Find ("znamecolor", aValues))
5447 if (!GetColor (aValues->Value(1), aColor))
5449 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
5452 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
5454 if (aMapOfArgs.Find ("xcolor", aValues))
5456 if (!GetColor (aValues->Value(1), aColor))
5458 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
5461 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
5463 if (aMapOfArgs.Find ("ycolor", aValues))
5465 if (!GetColor (aValues->Value(1), aColor))
5467 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
5470 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
5472 if (aMapOfArgs.Find ("zcolor", aValues))
5474 if (!GetColor (aValues->Value(1), aColor))
5476 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
5479 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
5483 if (aMapOfArgs.Find ("xticks", aValues))
5485 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5487 if (aMapOfArgs.Find ("yticks", aValues))
5489 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5491 if (aMapOfArgs.Find ("zticks", aValues))
5493 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5495 if (aMapOfArgs.Find ("xticklength", aValues))
5497 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5499 if (aMapOfArgs.Find ("yticklength", aValues))
5501 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5503 if (aMapOfArgs.Find ("zticklength", aValues))
5505 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5507 if (aMapOfArgs.Find ("xdrawticks", aValues))
5509 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5511 if (aMapOfArgs.Find ("ydrawticks", aValues))
5513 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5515 if (aMapOfArgs.Find ("zdrawticks", aValues))
5517 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5521 if (aMapOfArgs.Find ("xdrawvalues", aValues))
5523 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5525 if (aMapOfArgs.Find ("ydrawvalues", aValues))
5527 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5529 if (aMapOfArgs.Find ("zdrawvalues", aValues))
5531 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5533 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
5535 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5537 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
5539 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5541 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
5543 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5547 if (aMapOfArgs.Find ("arrowlength", aValues))
5549 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
5553 if (aMapOfArgs.Find ("namefont", aValues))
5555 aTrihedronData.SetNamesFont (aValues->Value(1));
5557 if (aMapOfArgs.Find ("valuesfont", aValues))
5559 aTrihedronData.SetValuesFont (aValues->Value(1));
5562 if (aMapOfArgs.Find ("drawgrid", aValues))
5564 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
5566 if (aMapOfArgs.Find ("drawaxes", aValues))
5568 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
5571 // The final step: display of erase trihedron
5574 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
5578 ViewerTest::CurrentView()->GraduatedTrihedronErase();
5581 ViewerTest::GetAISContext()->UpdateCurrentViewer();
5582 ViewerTest::CurrentView()->Redraw();
5587 //==============================================================================
5590 //==============================================================================
5591 static int VTile (Draw_Interpretor& theDI,
5592 Standard_Integer theArgNb,
5593 const char** theArgVec)
5595 Handle(V3d_View) aView = ViewerTest::CurrentView();
5598 std::cerr << "Error: no active viewer.\n";
5602 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
5605 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
5606 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
5607 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
5611 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
5612 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5614 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5616 if (anArg == "-lowerleft"
5617 || anArg == "-upperleft")
5619 if (anArgIter + 3 < theArgNb)
5621 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5624 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
5625 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5626 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5628 else if (anArg == "-total"
5629 || anArg == "-totalsize"
5630 || anArg == "-viewsize")
5632 if (anArgIter + 3 < theArgNb)
5634 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5637 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5638 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5639 if (aTile.TotalSize.x() < 1
5640 || aTile.TotalSize.y() < 1)
5642 std::cerr << "Error: total size is incorrect.\n";
5646 else if (anArg == "-tilesize")
5648 if (anArgIter + 3 < theArgNb)
5650 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5654 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5655 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5656 if (aTile.TileSize.x() < 1
5657 || aTile.TileSize.y() < 1)
5659 std::cerr << "Error: tile size is incorrect.\n";
5663 else if (anArg == "-unset")
5665 aView->Camera()->SetTile (Graphic3d_CameraTile());
5671 if (aTile.TileSize.x() < 1
5672 || aTile.TileSize.y() < 1)
5674 std::cerr << "Error: tile size is undefined.\n";
5677 else if (aTile.TotalSize.x() < 1
5678 || aTile.TotalSize.y() < 1)
5680 std::cerr << "Error: total size is undefined.\n";
5684 aView->Camera()->SetTile (aTile);
5689 //! Format ZLayer ID.
5690 inline const char* formZLayerId (const Standard_Integer theLayerId)
5694 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
5695 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
5696 case Graphic3d_ZLayerId_Top: return "[TOP]";
5697 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
5698 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
5699 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
5704 //! Print the ZLayer information.
5705 inline void printZLayerInfo (Draw_Interpretor& theDI,
5706 const Graphic3d_ZLayerSettings& theLayer)
5708 if (!theLayer.Name().IsEmpty())
5710 theDI << " Name: " << theLayer.Name() << "\n";
5712 if (theLayer.IsImmediate())
5714 theDI << " Immediate: TRUE\n";
5716 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
5717 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
5718 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
5719 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
5720 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
5721 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
5722 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
5724 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
5728 //==============================================================================
5729 //function : VZLayer
5730 //purpose : Test z layer operations for v3d viewer
5731 //==============================================================================
5732 static int VZLayer (Draw_Interpretor& theDI,
5733 Standard_Integer theArgNb,
5734 const char** theArgVec)
5736 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5737 if (aContextAIS.IsNull())
5739 std::cout << "No active viewer!\n";
5743 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
5746 TColStd_SequenceOfInteger aLayers;
5747 aViewer->GetAllZLayers (aLayers);
5748 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5750 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
5751 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
5752 printZLayerInfo (theDI, aSettings);
5757 Standard_Integer anArgIter = 1;
5758 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5759 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
5760 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5766 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
5767 if (aFirstArg.IsIntegerValue())
5770 aLayerId = aFirstArg.IntegerValue();
5774 if (ViewerTest::ParseZLayerName (aFirstArg.ToCString(), aLayerId))
5781 for (; anArgIter < theArgNb; ++anArgIter)
5783 // perform operation
5784 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5786 if (anUpdateTool.parseRedrawMode (anArg))
5790 else if (anArg == "-add"
5793 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5794 if (!aViewer->AddZLayer (aLayerId))
5796 std::cout << "Error: can not add a new z layer!\n";
5802 else if (anArg == "-del"
5803 || anArg == "-delete"
5806 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5808 if (++anArgIter >= theArgNb)
5810 std::cout << "Syntax error: id of z layer to remove is missing\n";
5814 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5817 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
5818 || aLayerId == Graphic3d_ZLayerId_Default
5819 || aLayerId == Graphic3d_ZLayerId_Top
5820 || aLayerId == Graphic3d_ZLayerId_Topmost
5821 || aLayerId == Graphic3d_ZLayerId_TopOSD
5822 || aLayerId == Graphic3d_ZLayerId_BotOSD)
5824 std::cout << "Syntax error: standard Z layer can not be removed\n";
5828 // move all object displayed in removing layer to default layer
5829 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5830 anObjIter.More(); anObjIter.Next())
5832 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
5834 || aPrs->ZLayer() != aLayerId)
5838 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
5841 if (!aViewer->RemoveZLayer (aLayerId))
5843 std::cout << "Z layer can not be removed!\n";
5847 theDI << aLayerId << " ";
5850 else if (anArg == "-get"
5853 TColStd_SequenceOfInteger aLayers;
5854 aViewer->GetAllZLayers (aLayers);
5855 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5857 theDI << aLayeriter.Value() << " ";
5862 else if (anArg == "-name")
5864 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5866 std::cout << "Syntax error: id of Z layer is missing\n";
5870 if (++anArgIter >= theArgNb)
5872 std::cout << "Syntax error: name is missing\n";
5876 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5877 aSettings.SetName (theArgVec[anArgIter]);
5878 aViewer->SetZLayerSettings (aLayerId, aSettings);
5880 else if (anArg == "-origin")
5882 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5884 std::cout << "Syntax error: id of Z layer is missing\n";
5888 if (anArgIter + 2 >= theArgNb)
5890 std::cout << "Syntax error: origin coordinates are missing\n";
5894 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5896 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
5897 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
5898 anOrigin.SetZ (0.0);
5899 if (anArgIter + 3 < theArgNb)
5901 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
5908 aSettings.SetOrigin (anOrigin);
5909 aViewer->SetZLayerSettings (aLayerId, aSettings);
5911 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5912 && anArgIter + 1 < theArgNb
5913 && (anArg == "-cullingdistance"
5914 || anArg == "-cullingdist"
5915 || anArg == "-culldistance"
5916 || anArg == "-culldist"
5917 || anArg == "-distcull"
5918 || anArg == "-distculling"
5919 || anArg == "-distanceculling"))
5921 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5922 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
5923 aSettings.SetCullingDistance (aDist);
5924 aViewer->SetZLayerSettings (aLayerId, aSettings);
5926 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5927 && anArgIter + 1 < theArgNb
5928 && (anArg == "-cullingsize"
5929 || anArg == "-cullsize"
5930 || anArg == "-sizecull"
5931 || anArg == "-sizeculling"))
5933 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5934 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
5935 aSettings.SetCullingSize (aSize);
5936 aViewer->SetZLayerSettings (aLayerId, aSettings);
5938 else if (anArg == "-settings"
5939 || anArg == "settings")
5941 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5943 if (++anArgIter >= theArgNb)
5945 std::cout << "Syntax error: id of Z layer is missing\n";
5949 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5952 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5953 printZLayerInfo (theDI, aSettings);
5955 else if (anArg == "-enable"
5956 || anArg == "enable"
5957 || anArg == "-disable"
5958 || anArg == "disable")
5960 const Standard_Boolean toEnable = anArg == "-enable"
5961 || anArg == "enable";
5962 if (++anArgIter >= theArgNb)
5964 std::cout << "Syntax error: option name is missing\n";
5968 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
5970 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5972 if (++anArgIter >= theArgNb)
5974 std::cout << "Syntax error: id of Z layer is missing\n";
5978 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5981 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5982 if (aSubOp == "depthtest"
5983 || aSubOp == "test")
5985 aSettings.SetEnableDepthTest (toEnable);
5987 else if (aSubOp == "depthwrite"
5988 || aSubOp == "write")
5990 aSettings.SetEnableDepthWrite (toEnable);
5992 else if (aSubOp == "depthclear"
5993 || aSubOp == "clear")
5995 aSettings.SetClearDepth (toEnable);
5997 else if (aSubOp == "depthoffset"
5998 || aSubOp == "offset")
6000 Graphic3d_PolygonOffset aParams;
6001 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
6004 if (anArgIter + 2 >= theArgNb)
6006 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
6010 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
6011 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
6013 aSettings.SetPolygonOffset (aParams);
6015 else if (aSubOp == "positiveoffset"
6016 || aSubOp == "poffset")
6020 aSettings.SetDepthOffsetPositive();
6024 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
6027 else if (aSubOp == "negativeoffset"
6028 || aSubOp == "noffset")
6032 aSettings.SetDepthOffsetNegative();
6036 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
6039 else if (aSubOp == "textureenv")
6041 aSettings.SetEnvironmentTexture (toEnable);
6044 aViewer->SetZLayerSettings (aLayerId, aSettings);
6048 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
6056 // The interactive presentation of 2d layer item
6057 // for "vlayerline" command it provides a presentation of
6058 // line with user-defined linewidth, linetype and transparency.
6059 class V3d_LineItem : public AIS_InteractiveObject
6063 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
6066 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
6067 Standard_Real X2, Standard_Real Y2,
6068 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
6069 Standard_Real theWidth = 0.5,
6070 Standard_Real theTransp = 1.0);
6074 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
6075 const Handle(Prs3d_Presentation)& thePresentation,
6076 const Standard_Integer theMode) Standard_OVERRIDE;
6078 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
6079 const Standard_Integer /*aMode*/) Standard_OVERRIDE
6084 Standard_Real myX1, myY1, myX2, myY2;
6085 Aspect_TypeOfLine myType;
6086 Standard_Real myWidth;
6089 // default constructor for line item
6090 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
6091 Standard_Real X2, Standard_Real Y2,
6092 Aspect_TypeOfLine theType,
6093 Standard_Real theWidth,
6094 Standard_Real theTransp) :
6095 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
6096 myType(theType), myWidth(theWidth)
6098 SetTransparency (1-theTransp);
6102 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
6103 const Handle(Prs3d_Presentation)& thePresentation,
6104 const Standard_Integer /*theMode*/)
6106 thePresentation->Clear();
6107 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
6108 Standard_Integer aWidth, aHeight;
6109 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
6110 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
6111 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
6112 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
6113 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
6114 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
6115 aGroup->SetPrimitivesAspect (anAspect->Aspect());
6116 aGroup->AddPrimitiveArray (aPrim);
6119 //=============================================================================
6120 //function : VLayerLine
6121 //purpose : Draws line in the v3d view layer with given attributes: linetype,
6122 // : linewidth, transparency coefficient
6123 //============================================================================
6124 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6126 // get the active view
6127 Handle(V3d_View) aView = ViewerTest::CurrentView();
6130 di << "Call vinit before!\n";
6135 di << "Use: " << argv[0];
6136 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
6137 di << " linetype : { 0 | 1 | 2 | 3 } \n";
6138 di << " 0 - solid \n";
6139 di << " 1 - dashed \n";
6140 di << " 2 - dot \n";
6141 di << " 3 - dashdot\n";
6142 di << " transparency : { 0.0 - 1.0 } \n";
6143 di << " 0.0 - transparent\n";
6144 di << " 1.0 - visible \n";
6148 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6149 // get the input params
6150 Standard_Real X1 = Draw::Atof(argv[1]);
6151 Standard_Real Y1 = Draw::Atof(argv[2]);
6152 Standard_Real X2 = Draw::Atof(argv[3]);
6153 Standard_Real Y2 = Draw::Atof(argv[4]);
6155 Standard_Real aWidth = 0.5;
6156 Standard_Real aTransparency = 1.0;
6160 aWidth = Draw::Atof(argv[5]);
6162 // select appropriate line type
6163 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
6165 && !ViewerTest::ParseLineType (argv[6], aLineType))
6167 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
6174 aTransparency = Draw::Atof(argv[7]);
6175 if (aTransparency < 0 || aTransparency > 1.0)
6176 aTransparency = 1.0;
6179 static Handle (V3d_LineItem) aLine;
6180 if (!aLine.IsNull())
6182 aContext->Erase (aLine, Standard_False);
6184 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
6188 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
6189 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
6190 aLine->SetToUpdate();
6191 aContext->Display (aLine, Standard_True);
6197 //==============================================================================
6200 //==============================================================================
6202 static int VGrid (Draw_Interpretor& /*theDI*/,
6203 Standard_Integer theArgNb,
6204 const char** theArgVec)
6206 Handle(V3d_View) aView = ViewerTest::CurrentView();
6207 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6208 if (aView.IsNull() || aViewer.IsNull())
6210 std::cerr << "Error: no active view\n";
6214 Aspect_GridType aType = aViewer->GridType();
6215 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
6216 Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY;
6217 Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0;
6218 bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false;
6219 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
6220 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6222 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6224 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
6228 else if (anArgIter + 1 < theArgNb
6229 && anArg == "-type")
6231 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
6232 anArgNext.LowerCase();
6233 if (anArgNext == "r"
6234 || anArgNext == "rect"
6235 || anArgNext == "rectangular")
6237 aType = Aspect_GT_Rectangular;
6239 else if (anArgNext == "c"
6240 || anArgNext == "circ"
6241 || anArgNext == "circular")
6243 aType = Aspect_GT_Circular;
6247 std::cout << "Syntax error at '" << anArgNext << "'\n";
6251 else if (anArgIter + 1 < theArgNb
6252 && anArg == "-mode")
6254 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
6255 anArgNext.LowerCase();
6256 if (anArgNext == "l"
6257 || anArgNext == "line"
6258 || anArgNext == "lines")
6260 aMode = Aspect_GDM_Lines;
6262 else if (anArgNext == "p"
6263 || anArgNext == "point"
6264 || anArgNext == "points")
6266 aMode = Aspect_GDM_Points;
6270 std::cout << "Syntax error at '" << anArgNext << "'\n";
6274 else if (anArgIter + 2 < theArgNb
6275 && (anArg == "-origin"
6276 || anArg == "-orig"))
6279 aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6280 Draw::Atof (theArgVec[anArgIter + 2]));
6283 else if (anArgIter + 2 < theArgNb
6284 && anArg == "-step")
6287 aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6288 Draw::Atof (theArgVec[anArgIter + 2]));
6289 if (aNewStepXY.x() <= 0.0
6290 || aNewStepXY.y() <= 0.0)
6292 std::cout << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
6297 else if (anArgIter + 1 < theArgNb
6298 && (anArg == "-angle"
6299 || anArg == "-rotangle"
6300 || anArg == "-rotationangle"))
6303 aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]);
6305 else if (anArgIter + 1 < theArgNb
6306 && (anArg == "-zoffset"
6310 aNewZOffset = Draw::Atof (theArgVec[++anArgIter]);
6312 else if (anArgIter + 1 < theArgNb
6313 && anArg == "-radius")
6317 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0);
6318 if (aNewStepXY.x() <= 0.0)
6320 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'\n";
6324 else if (anArgIter + 2 < theArgNb
6325 && anArg == "-size")
6328 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6329 Draw::Atof (theArgVec[anArgIter + 2]));
6330 if (aNewStepXY.x() <= 0.0
6331 || aNewStepXY.y() <= 0.0)
6333 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
6338 else if (anArg == "r"
6340 || anArg == "rectangular")
6342 aType = Aspect_GT_Rectangular;
6344 else if (anArg == "c"
6346 || anArg == "circular")
6348 aType = Aspect_GT_Circular;
6350 else if (anArg == "l"
6352 || anArg == "lines")
6354 aMode = Aspect_GDM_Lines;
6356 else if (anArg == "p"
6358 || anArg == "points")
6360 aMode = Aspect_GDM_Points;
6362 else if (anArgIter + 1 >= theArgNb
6365 aViewer->DeactivateGrid();
6370 std::cout << "Syntax error at '" << anArg << "'\n";
6375 if (aType == Aspect_GT_Rectangular)
6377 Graphic3d_Vec2d anOrigXY, aStepXY;
6378 Standard_Real aRotAngle = 0.0;
6379 aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
6382 anOrigXY = aNewOriginXY;
6386 aStepXY = aNewStepXY;
6390 aRotAngle = aNewRotAngle;
6392 aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
6393 if (hasSize || hasZOffset)
6395 Graphic3d_Vec3d aSize;
6396 aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
6399 aSize.x() = aNewSizeXY.x();
6400 aSize.y() = aNewSizeXY.y();
6404 aSize.z() = aNewZOffset;
6406 aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
6409 else if (aType == Aspect_GT_Circular)
6411 Graphic3d_Vec2d anOrigXY;
6412 Standard_Real aRadiusStep;
6413 Standard_Integer aDivisionNumber;
6414 Standard_Real aRotAngle = 0.0;
6415 aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6418 anOrigXY = aNewOriginXY;
6422 aRadiusStep = aNewStepXY[0];
6423 aDivisionNumber = (int )aNewStepXY[1];
6424 if (aDivisionNumber < 1)
6426 std::cout << "Syntax error: invalid division number '" << aNewStepXY[1] << "'\n";
6432 aRotAngle = aNewRotAngle;
6435 aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6436 if (hasSize || hasZOffset)
6438 Standard_Real aRadius = 0.0, aZOffset = 0.0;
6439 aViewer->CircularGridGraphicValues (aRadius, aZOffset);
6442 aRadius = aNewSizeXY.x();
6443 if (aNewSizeXY.y() != 0.0)
6445 std::cout << "Syntax error: circular size should be specified as radius\n";
6451 aZOffset = aNewZOffset;
6453 aViewer->SetCircularGridGraphicValues (aRadius, aZOffset);
6456 aViewer->ActivateGrid (aType, aMode);
6460 //==============================================================================
6461 //function : VPriviledgedPlane
6463 //==============================================================================
6465 static int VPriviledgedPlane (Draw_Interpretor& theDI,
6466 Standard_Integer theArgNb,
6467 const char** theArgVec)
6469 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
6471 std::cerr << "Error: wrong number of arguments! See usage:\n";
6472 theDI.PrintHelp (theArgVec[0]);
6476 // get the active viewer
6477 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6478 if (aViewer.IsNull())
6480 std::cerr << "Error: no active viewer. Please call vinit.\n";
6486 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
6487 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
6488 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
6489 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
6490 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
6491 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
6492 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
6496 Standard_Integer anArgIdx = 1;
6497 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
6498 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
6499 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
6500 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
6501 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
6502 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
6504 gp_Ax3 aPriviledgedPlane;
6505 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
6506 gp_Dir aNorm (aNormX, aNormY, aNormZ);
6509 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
6510 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
6511 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
6512 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
6513 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
6517 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
6520 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
6525 //==============================================================================
6526 //function : VConvert
6528 //==============================================================================
6530 static int VConvert (Draw_Interpretor& theDI,
6531 Standard_Integer theArgNb,
6532 const char** theArgVec)
6534 // get the active view
6535 Handle(V3d_View) aView = ViewerTest::CurrentView();
6538 std::cerr << "Error: no active view. Please call vinit.\n";
6542 enum { Model, Ray, View, Window, Grid } aMode = Model;
6544 // access coordinate arguments
6545 TColStd_SequenceOfReal aCoord;
6546 Standard_Integer anArgIdx = 1;
6547 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
6549 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6550 if (!anArg.IsRealValue())
6554 aCoord.Append (anArg.RealValue());
6557 // non-numeric argument too early
6558 if (aCoord.IsEmpty())
6560 std::cerr << "Error: wrong number of arguments! See usage:\n";
6561 theDI.PrintHelp (theArgVec[0]);
6565 // collect all other arguments and options
6566 for (; anArgIdx < theArgNb; ++anArgIdx)
6568 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6570 if (anArg == "window") aMode = Window;
6571 else if (anArg == "view") aMode = View;
6572 else if (anArg == "grid") aMode = Grid;
6573 else if (anArg == "ray") aMode = Ray;
6576 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
6577 theDI.PrintHelp (theArgVec[0]);
6582 // complete input checks
6583 if ((aCoord.Length() == 1 && theArgNb > 3) ||
6584 (aCoord.Length() == 2 && theArgNb > 4) ||
6585 (aCoord.Length() == 3 && theArgNb > 5))
6587 std::cerr << "Error: wrong number of arguments! See usage:\n";
6588 theDI.PrintHelp (theArgVec[0]);
6592 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
6593 Standard_Integer aXYp[2] = {0, 0};
6595 // convert one-dimensional coordinate
6596 if (aCoord.Length() == 1)
6600 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
6601 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
6603 std::cerr << "Error: wrong arguments! See usage:\n";
6604 theDI.PrintHelp (theArgVec[0]);
6609 // convert 2D coordinates from projection or view reference space
6610 if (aCoord.Length() == 2)
6615 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6616 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6620 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
6621 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
6625 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
6626 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6630 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6631 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
6632 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6636 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
6637 (Standard_Integer) aCoord (2),
6638 aXYZ[0], aXYZ[1], aXYZ[2],
6639 aXYZ[3], aXYZ[4], aXYZ[5]);
6640 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6644 std::cerr << "Error: wrong arguments! See usage:\n";
6645 theDI.PrintHelp (theArgVec[0]);
6650 // convert 3D coordinates from view reference space
6651 else if (aCoord.Length() == 3)
6656 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
6657 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6661 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
6662 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6666 std::cerr << "Error: wrong arguments! See usage:\n";
6667 theDI.PrintHelp (theArgVec[0]);
6675 //==============================================================================
6678 //==============================================================================
6680 static int VFps (Draw_Interpretor& theDI,
6681 Standard_Integer theArgNb,
6682 const char** theArgVec)
6684 // get the active view
6685 Handle(V3d_View) aView = ViewerTest::CurrentView();
6688 std::cerr << "No active view. Please call vinit.\n";
6692 Standard_Integer aFramesNb = -1;
6693 Standard_Real aDuration = -1.0;
6694 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6696 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6699 && anArgIter + 1 < theArgNb
6700 && (anArg == "-duration"
6702 || anArg == "-time"))
6704 aDuration = Draw::Atof (theArgVec[++anArgIter]);
6706 else if (aFramesNb < 0
6707 && anArg.IsIntegerValue())
6709 aFramesNb = anArg.IntegerValue();
6712 std::cerr << "Syntax error at '" << anArg << "'\n";
6718 std::cerr << "Syntax error at '" << anArg << "'\n";
6722 if (aFramesNb < 0 && aDuration < 0.0)
6727 // the time is meaningless for first call
6728 // due to async OpenGl rendering
6731 // redraw view in loop to estimate average values
6734 Standard_Integer aFrameIter = 1;
6735 for (;; ++aFrameIter)
6739 && aFrameIter >= aFramesNb)
6741 && aTimer.ElapsedTime() >= aDuration))
6748 const Standard_Real aTime = aTimer.ElapsedTime();
6749 aTimer.OSD_Chronometer::Show (aCpu);
6751 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
6752 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
6754 // return statistics
6755 theDI << "FPS: " << aFpsAver << "\n"
6756 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
6758 // compute additional statistics in ray-tracing mode
6759 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
6760 if (aParams.Method == Graphic3d_RM_RAYTRACING)
6762 Graphic3d_Vec2i aWinSize (0, 0);
6763 aView->Window()->Size (aWinSize.x(), aWinSize.y());
6765 // 1 shadow ray and 1 secondary ray pew each bounce
6766 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
6767 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
6773 //! Auxiliary function for parsing glsl dump level argument.
6774 static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
6775 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
6777 TCollection_AsciiString aTypeStr (theArg);
6778 aTypeStr.LowerCase();
6779 if (aTypeStr == "off"
6782 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6784 else if (aTypeStr == "short")
6786 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
6788 else if (aTypeStr == "full"
6791 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6795 return Standard_False;
6797 return Standard_True;
6800 //==============================================================================
6801 //function : VGlDebug
6803 //==============================================================================
6805 static int VGlDebug (Draw_Interpretor& theDI,
6806 Standard_Integer theArgNb,
6807 const char** theArgVec)
6809 Handle(OpenGl_GraphicDriver) aDriver;
6810 Handle(V3d_View) aView = ViewerTest::CurrentView();
6811 if (!aView.IsNull())
6813 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
6815 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
6816 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
6820 TCollection_AsciiString aDebActive, aSyncActive;
6827 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
6828 "GL_ARB_debug_output");
6829 aDebActive = isActive ? " (active)" : " (inactive)";
6832 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
6833 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
6837 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
6838 + "glslSourceCode: "
6839 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
6841 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
6845 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
6846 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
6847 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
6848 << aGlslCodeDebugStatus
6849 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
6853 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6855 Standard_CString anArg = theArgVec[anArgIter];
6856 TCollection_AsciiString anArgCase (anArg);
6857 anArgCase.LowerCase();
6858 Standard_Boolean toEnableDebug = Standard_True;
6859 if (anArgCase == "-glsl"
6860 || anArgCase == "-glslwarn"
6861 || anArgCase == "-glslwarns"
6862 || anArgCase == "-glslwarnings")
6864 Standard_Boolean toShowWarns = Standard_True;
6865 if (++anArgIter < theArgNb
6866 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
6870 aDefCaps->glslWarnings = toShowWarns;
6873 aCaps->glslWarnings = toShowWarns;
6876 else if (anArgCase == "-extra"
6877 || anArgCase == "-extramsg"
6878 || anArgCase == "-extramessages")
6880 Standard_Boolean toShow = Standard_True;
6881 if (++anArgIter < theArgNb
6882 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
6886 aDefCaps->suppressExtraMsg = !toShow;
6889 aCaps->suppressExtraMsg = !toShow;
6892 else if (anArgCase == "-noextra"
6893 || anArgCase == "-noextramsg"
6894 || anArgCase == "-noextramessages")
6896 Standard_Boolean toSuppress = Standard_True;
6897 if (++anArgIter < theArgNb
6898 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
6902 aDefCaps->suppressExtraMsg = toSuppress;
6905 aCaps->suppressExtraMsg = toSuppress;
6908 else if (anArgCase == "-sync")
6910 Standard_Boolean toSync = Standard_True;
6911 if (++anArgIter < theArgNb
6912 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
6916 aDefCaps->contextSyncDebug = toSync;
6919 aDefCaps->contextDebug = Standard_True;
6922 else if (anArgCase == "-glslsourcecode"
6923 || anArgCase == "-glslcode")
6925 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6926 if (++anArgIter < theArgNb
6927 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
6931 aDefCaps->glslDumpLevel = aGslsDumpLevel;
6934 aCaps->glslDumpLevel = aGslsDumpLevel;
6937 else if (anArgCase == "-debug")
6939 if (++anArgIter < theArgNb
6940 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
6944 aDefCaps->contextDebug = toEnableDebug;
6946 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
6947 && (anArgIter + 1 == theArgNb))
6949 // simple alias to turn on almost everything
6950 aDefCaps->contextDebug = toEnableDebug;
6951 aDefCaps->contextSyncDebug = toEnableDebug;
6952 aDefCaps->glslWarnings = toEnableDebug;
6955 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6957 aDefCaps->suppressExtraMsg = !toEnableDebug;
6960 aCaps->contextDebug = toEnableDebug;
6961 aCaps->contextSyncDebug = toEnableDebug;
6962 aCaps->glslWarnings = toEnableDebug;
6965 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6967 aCaps->suppressExtraMsg = !toEnableDebug;
6972 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
6980 //==============================================================================
6983 //==============================================================================
6985 static int VVbo (Draw_Interpretor& theDI,
6986 Standard_Integer theArgNb,
6987 const char** theArgVec)
6989 const Standard_Boolean toSet = (theArgNb > 1);
6990 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
6993 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
6997 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6998 if (aContextAIS.IsNull())
7002 std::cerr << "No active view!\n";
7006 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
7007 if (!aDriver.IsNull())
7011 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
7015 aDriver->ChangeOptions().vboDisable = toUseVbo;
7022 //==============================================================================
7025 //==============================================================================
7027 static int VCaps (Draw_Interpretor& theDI,
7028 Standard_Integer theArgNb,
7029 const char** theArgVec)
7031 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
7032 Handle(OpenGl_GraphicDriver) aDriver;
7033 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7034 if (!aContext.IsNull())
7036 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
7037 aCaps = &aDriver->ChangeOptions();
7042 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
7043 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
7044 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
7045 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
7046 theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n";
7047 theDI << "VSync: " << aCaps->swapInterval << "\n";
7048 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
7049 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
7050 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
7054 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
7055 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7057 Standard_CString anArg = theArgVec[anArgIter];
7058 TCollection_AsciiString anArgCase (anArg);
7059 anArgCase.LowerCase();
7060 if (anUpdateTool.parseRedrawMode (anArg))
7064 else if (anArgCase == "-vsync"
7065 || anArgCase == "-swapinterval")
7067 Standard_Boolean toEnable = Standard_True;
7068 if (++anArgIter < theArgNb
7069 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7073 aCaps->swapInterval = toEnable;
7075 else if (anArgCase == "-ffp")
7077 Standard_Boolean toEnable = Standard_True;
7078 if (++anArgIter < theArgNb
7079 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7083 aCaps->ffpEnable = toEnable;
7085 else if (anArgCase == "-polygonmode")
7087 Standard_Boolean toEnable = Standard_True;
7088 if (++anArgIter < theArgNb
7089 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7093 aCaps->usePolygonMode = toEnable;
7095 else if (anArgCase == "-vbo")
7097 Standard_Boolean toEnable = Standard_True;
7098 if (++anArgIter < theArgNb
7099 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7103 aCaps->vboDisable = !toEnable;
7105 else if (anArgCase == "-sprite"
7106 || anArgCase == "-sprites")
7108 Standard_Boolean toEnable = Standard_True;
7109 if (++anArgIter < theArgNb
7110 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7114 aCaps->pntSpritesDisable = !toEnable;
7116 else if (anArgCase == "-softmode")
7118 Standard_Boolean toEnable = Standard_True;
7119 if (++anArgIter < theArgNb
7120 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7124 aCaps->contextNoAccel = toEnable;
7126 else if (anArgCase == "-winbuffer"
7127 || anArgCase == "-windowbuffer"
7128 || anArgCase == "-usewinbuffer"
7129 || anArgCase == "-usewindowbuffer"
7130 || anArgCase == "-usesystembuffer")
7132 Standard_Boolean toEnable = Standard_True;
7133 if (++anArgIter < theArgNb
7134 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7138 aCaps->useSystemBuffer = toEnable;
7140 else if (anArgCase == "-accel"
7141 || anArgCase == "-acceleration")
7143 Standard_Boolean toEnable = Standard_True;
7144 if (++anArgIter < theArgNb
7145 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7149 aCaps->contextNoAccel = !toEnable;
7151 else if (anArgCase == "-compat"
7152 || anArgCase == "-compatprofile"
7153 || anArgCase == "-compatible"
7154 || anArgCase == "-compatibleprofile")
7156 Standard_Boolean toEnable = Standard_True;
7157 if (++anArgIter < theArgNb
7158 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7162 aCaps->contextCompatible = toEnable;
7163 if (!aCaps->contextCompatible)
7165 aCaps->ffpEnable = Standard_False;
7168 else if (anArgCase == "-core"
7169 || anArgCase == "-coreprofile")
7171 Standard_Boolean toEnable = Standard_True;
7172 if (++anArgIter < theArgNb
7173 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7177 aCaps->contextCompatible = !toEnable;
7178 if (!aCaps->contextCompatible)
7180 aCaps->ffpEnable = Standard_False;
7183 else if (anArgCase == "-stereo"
7184 || anArgCase == "-quadbuffer")
7186 Standard_Boolean toEnable = Standard_True;
7187 if (++anArgIter < theArgNb
7188 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7192 aCaps->contextStereo = toEnable;
7196 std::cout << "Error: unknown argument '" << anArg << "'\n";
7200 if (aCaps != &ViewerTest_myDefaultCaps)
7202 ViewerTest_myDefaultCaps = *aCaps;
7207 //==============================================================================
7208 //function : VMemGpu
7210 //==============================================================================
7212 static int VMemGpu (Draw_Interpretor& theDI,
7213 Standard_Integer theArgNb,
7214 const char** theArgVec)
7217 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
7218 if (aContextAIS.IsNull())
7220 std::cerr << "No active view. Please call vinit.\n";
7224 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
7225 if (aDriver.IsNull())
7227 std::cerr << "Graphic driver not available.\n";
7231 Standard_Size aFreeBytes = 0;
7232 TCollection_AsciiString anInfo;
7233 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
7235 std::cerr << "Information not available.\n";
7239 if (theArgNb > 1 && *theArgVec[1] == 'f')
7241 theDI << Standard_Real (aFreeBytes);
7251 // ==============================================================================
7252 // function : VReadPixel
7254 // ==============================================================================
7255 static int VReadPixel (Draw_Interpretor& theDI,
7256 Standard_Integer theArgNb,
7257 const char** theArgVec)
7259 // get the active view
7260 Handle(V3d_View) aView = ViewerTest::CurrentView();
7263 std::cerr << "No active view. Please call vinit.\n";
7266 else if (theArgNb < 3)
7268 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
7272 Image_Format aFormat = Image_Format_RGBA;
7273 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
7275 Standard_Integer aWidth, aHeight;
7276 aView->Window()->Size (aWidth, aHeight);
7277 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
7278 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
7279 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
7281 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
7285 Standard_Boolean toShowName = Standard_False;
7286 Standard_Boolean toShowHls = Standard_False;
7287 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
7289 TCollection_AsciiString aParam (theArgVec[anIter]);
7291 if (aParam == "-rgb"
7294 aFormat = Image_Format_RGB;
7295 aBufferType = Graphic3d_BT_RGB;
7297 else if (aParam == "-hls"
7300 aFormat = Image_Format_RGB;
7301 aBufferType = Graphic3d_BT_RGB;
7302 toShowHls = Standard_True;
7304 else if (aParam == "-rgbf"
7305 || aParam == "rgbf")
7307 aFormat = Image_Format_RGBF;
7308 aBufferType = Graphic3d_BT_RGB;
7310 else if (aParam == "-rgba"
7311 || aParam == "rgba")
7313 aFormat = Image_Format_RGBA;
7314 aBufferType = Graphic3d_BT_RGBA;
7316 else if (aParam == "-rgbaf"
7317 || aParam == "rgbaf")
7319 aFormat = Image_Format_RGBAF;
7320 aBufferType = Graphic3d_BT_RGBA;
7322 else if (aParam == "-depth"
7323 || aParam == "depth")
7325 aFormat = Image_Format_GrayF;
7326 aBufferType = Graphic3d_BT_Depth;
7328 else if (aParam == "-name"
7329 || aParam == "name")
7331 toShowName = Standard_True;
7335 std::cout << "Syntax error at '" << aParam << "'\n";
7339 Image_PixMap anImage;
7340 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
7342 std::cerr << "Image allocation failed\n";
7345 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
7347 std::cerr << "Image dump failed\n";
7351 // redirect possible warning messages that could have been added by ToPixMap
7352 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
7353 // contaminate result of the command
7354 Standard_CString aWarnLog = theDI.Result();
7355 if (aWarnLog != NULL && aWarnLog[0] != '\0')
7357 std::cout << aWarnLog << std::endl;
7361 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
7364 if (aBufferType == Graphic3d_BT_RGBA)
7366 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
7370 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
7375 switch (aBufferType)
7378 case Graphic3d_BT_RGB:
7382 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
7386 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
7390 case Graphic3d_BT_RGBA:
7392 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
7395 case Graphic3d_BT_Depth:
7397 theDI << aColor.GetRGB().Red();
7406 //! Auxiliary presentation for an image plane.
7407 class ViewerTest_ImagePrs : public AIS_InteractiveObject
7410 //! Main constructor.
7411 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
7412 const Standard_Real theWidth,
7413 const Standard_Real theHeight,
7414 const TCollection_AsciiString& theLabel)
7415 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
7419 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
7421 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
7422 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
7423 Graphic3d_MaterialAspect aMat;
7424 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
7425 aMat.SetAmbient (1.0);
7426 aMat.SetDiffuse (1.0);
7427 aMat.SetSpecular (1.0);
7428 aMat.SetEmissive (1.0);
7429 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
7430 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
7431 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
7432 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
7433 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
7434 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
7435 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
7436 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
7437 aFillAspect->SetFrontMaterial (aMat);
7438 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
7439 aFillAspect->SetTextureMapOn();
7442 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
7443 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
7444 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
7445 myDrawer->SetTextAspect (aTextAspect);
7448 const gp_Dir aNorm (0.0, 0.0, 1.0);
7449 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
7450 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
7451 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
7452 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
7453 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
7454 myTris->AddEdge (1);
7455 myTris->AddEdge (2);
7456 myTris->AddEdge (3);
7457 myTris->AddEdge (3);
7458 myTris->AddEdge (2);
7459 myTris->AddEdge (4);
7461 myRect = new Graphic3d_ArrayOfPolylines (4);
7462 myRect->AddVertex (myTris->Vertice (1));
7463 myRect->AddVertex (myTris->Vertice (3));
7464 myRect->AddVertex (myTris->Vertice (4));
7465 myRect->AddVertex (myTris->Vertice (2));
7469 //! Returns TRUE for accepted display modes.
7470 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
7472 //! Compute presentation.
7473 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
7479 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7480 aGroup->AddPrimitiveArray (myTris);
7481 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
7482 aGroup->AddPrimitiveArray (myRect);
7483 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7488 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
7489 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7490 aGroup->AddPrimitiveArray (myRect);
7491 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7497 //! Compute selection.
7498 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
7502 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
7503 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
7504 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
7505 theSel->Add (aSensitive);
7510 Handle(Graphic3d_ArrayOfTriangles) myTris;
7511 Handle(Graphic3d_ArrayOfPolylines) myRect;
7512 TCollection_AsciiString myLabel;
7513 Standard_Real myWidth;
7514 Standard_Real myHeight;
7517 //==============================================================================
7518 //function : VDiffImage
7519 //purpose : The draw-command compares two images.
7520 //==============================================================================
7522 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
7526 std::cout << "Syntax error: not enough arguments.\n";
7530 Standard_Integer anArgIter = 1;
7531 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
7532 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
7533 TCollection_AsciiString aDiffImagePath;
7534 Standard_Real aTolColor = -1.0;
7535 Standard_Integer toBlackWhite = -1;
7536 Standard_Integer isBorderFilterOn = -1;
7537 Standard_Boolean isOldSyntax = Standard_False;
7538 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
7539 for (; anArgIter < theArgNb; ++anArgIter)
7541 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7543 if (anArgIter + 1 < theArgNb
7544 && (anArg == "-toleranceofcolor"
7545 || anArg == "-tolerancecolor"
7546 || anArg == "-tolerance"
7547 || anArg == "-toler"))
7549 aTolColor = Atof (theArgVec[++anArgIter]);
7550 if (aTolColor < 0.0 || aTolColor > 1.0)
7552 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7556 else if (anArg == "-blackwhite")
7558 Standard_Boolean toEnable = Standard_True;
7559 if (anArgIter + 1 < theArgNb
7560 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7564 toBlackWhite = toEnable ? 1 : 0;
7566 else if (anArg == "-borderfilter")
7568 Standard_Boolean toEnable = Standard_True;
7569 if (anArgIter + 1 < theArgNb
7570 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7574 isBorderFilterOn = toEnable ? 1 : 0;
7576 else if (anArg == "-exitonclose")
7578 Draw_ToExitOnCloseView = true;
7579 if (anArgIter + 1 < theArgNb
7580 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToExitOnCloseView))
7585 else if (anArg == "-closeonescape"
7586 || anArg == "-closeonesc")
7588 Draw_ToCloseViewOnEsc = true;
7589 if (anArgIter + 1 < theArgNb
7590 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToCloseViewOnEsc))
7595 else if (anArgIter + 3 < theArgNb
7596 && anArg == "-display")
7598 aViewName = theArgVec[++anArgIter];
7599 aPrsNameRef = theArgVec[++anArgIter];
7600 aPrsNameNew = theArgVec[++anArgIter];
7601 if (anArgIter + 1 < theArgNb
7602 && *theArgVec[anArgIter + 1] != '-')
7604 aPrsNameDiff = theArgVec[++anArgIter];
7607 else if (aTolColor < 0.0
7608 && anArg.IsRealValue())
7610 isOldSyntax = Standard_True;
7611 aTolColor = anArg.RealValue();
7612 if (aTolColor < 0.0 || aTolColor > 1.0)
7614 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7618 else if (isOldSyntax
7619 && toBlackWhite == -1
7620 && (anArg == "0" || anArg == "1"))
7622 toBlackWhite = anArg == "1" ? 1 : 0;
7624 else if (isOldSyntax
7625 && isBorderFilterOn == -1
7626 && (anArg == "0" || anArg == "1"))
7628 isBorderFilterOn = anArg == "1" ? 1 : 0;
7630 else if (aDiffImagePath.IsEmpty())
7632 aDiffImagePath = theArgVec[anArgIter];
7636 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7641 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
7642 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
7643 if (!anImgRef->Load (anImgPathRef))
7645 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
7648 if (!anImgNew->Load (anImgPathNew))
7650 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
7654 // compare the images
7655 Image_Diff aComparer;
7656 Standard_Integer aDiffColorsNb = -1;
7657 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
7659 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
7660 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
7661 aDiffColorsNb = aComparer.Compare();
7662 theDI << aDiffColorsNb << "\n";
7665 // save image of difference
7666 Handle(Image_AlienPixMap) aDiff;
7667 if (aDiffColorsNb > 0
7668 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
7670 aDiff = new Image_AlienPixMap();
7671 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
7673 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
7676 aComparer.SaveDiffImage (*aDiff);
7677 if (!aDiffImagePath.IsEmpty()
7678 && !aDiff->Save (aDiffImagePath))
7680 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
7685 if (aViewName.IsEmpty())
7690 ViewerTest_Names aViewNames (aViewName);
7691 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
7693 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
7694 theDI.Eval (aCommand.ToCString());
7697 Standard_Integer aPxLeft = 0;
7698 Standard_Integer aPxTop = 0;
7699 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
7700 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
7701 ? int(anImgRef->SizeY() * 2)
7702 : int(anImgRef->SizeY());
7703 TCollection_AsciiString aDisplayName;
7704 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
7705 aViewName, aDisplayName);
7707 Standard_Real aRatio = anImgRef->Ratio();
7708 Standard_Real aSizeX = 1.0;
7709 Standard_Real aSizeY = aSizeX / aRatio;
7711 OSD_Path aPath (anImgPathRef);
7712 TCollection_AsciiString aLabelRef;
7713 if (!aPath.Name().IsEmpty())
7715 aLabelRef = aPath.Name() + aPath.Extension();
7717 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
7719 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
7721 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
7722 anImgRefPrs->SetLocalTransformation (aTrsfRef);
7723 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
7726 OSD_Path aPath (anImgPathNew);
7727 TCollection_AsciiString aLabelNew;
7728 if (!aPath.Name().IsEmpty())
7730 aLabelNew = aPath.Name() + aPath.Extension();
7732 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
7734 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
7736 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
7737 anImgNewPrs->SetLocalTransformation (aTrsfRef);
7738 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
7740 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
7741 if (!aDiff.IsNull())
7743 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
7745 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
7746 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
7748 if (!aPrsNameDiff.IsEmpty())
7750 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
7752 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
7753 ViewerTest::CurrentView()->FitAll();
7757 //=======================================================================
7758 //function : VSelect
7759 //purpose : Emulates different types of selection by mouse:
7760 // 1) single click selection
7761 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
7762 // 3) selection with polygon having corners at
7763 // pixel positions (x1,y1),...,(xn,yn)
7764 // 4) any of these selections with shift button pressed
7765 //=======================================================================
7766 static Standard_Integer VSelect (Draw_Interpretor& di,
7767 Standard_Integer argc,
7772 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
7776 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
7777 if(myAIScontext.IsNull())
7779 di << "use 'vinit' command before " << argv[0] << "\n";
7783 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
7784 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
7785 TCollection_AsciiString anArg;
7786 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
7788 if (anArg == "-allowoverlap")
7790 Standard_Boolean isValidated = isShiftSelection ? argc == 8
7794 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
7798 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
7799 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
7803 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
7804 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
7807 if(isShiftSelection)
7808 aCurrentEventManager->ShiftSelect();
7810 aCurrentEventManager->Select();
7812 else if(aCoordsNb == 4)
7814 if(isShiftSelection)
7815 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
7817 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
7821 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
7823 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
7824 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
7826 if(isShiftSelection)
7827 aCurrentEventManager->ShiftSelect(aPolyline);
7829 aCurrentEventManager->Select(aPolyline);
7834 //=======================================================================
7835 //function : VMoveTo
7836 //purpose : Emulates cursor movement to defined pixel position
7837 //=======================================================================
7838 static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
7839 Standard_Integer theNbArgs,
7840 const char** theArgVec)
7842 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
7843 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
7844 if (aContext.IsNull())
7846 std::cout << "Error: no active View\n";
7850 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
7851 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7853 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
7854 anArgStr.LowerCase();
7855 if (anArgStr == "-reset"
7856 || anArgStr == "-clear")
7858 if (anArgIter + 1 < theNbArgs)
7860 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
7864 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
7865 && aContext->CurrentViewer()->GridEcho();
7868 aContext->CurrentViewer()->HideGridEcho (aView);
7870 if (aContext->ClearDetected() || toEchoGrid)
7872 aContext->CurrentViewer()->RedrawImmediate();
7876 else if (aMousePos.x() == IntegerLast()
7877 && anArgStr.IsIntegerValue())
7879 aMousePos.x() = anArgStr.IntegerValue();
7881 else if (aMousePos.y() == IntegerLast()
7882 && anArgStr.IsIntegerValue())
7884 aMousePos.y() = anArgStr.IntegerValue();
7888 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7893 if (aMousePos.x() == IntegerLast()
7894 || aMousePos.y() == IntegerLast())
7896 std::cout << "Syntax error: wrong number of arguments\n";
7900 ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y());
7901 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
7902 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
7903 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
7905 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
7907 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
7911 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
7917 //! Global map storing all animations registered in ViewerTest.
7918 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
7920 //! The animation calling the Draw Harness command.
7921 class ViewerTest_AnimationProc : public AIS_Animation
7925 //! Main constructor.
7926 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
7927 Draw_Interpretor* theDI,
7928 const TCollection_AsciiString& theCommand)
7929 : AIS_Animation (theAnimationName),
7931 myCommand (theCommand)
7938 //! Evaluate the command.
7939 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
7941 TCollection_AsciiString aCmd = myCommand;
7942 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
7943 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
7944 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
7945 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
7946 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
7947 myDrawInter->Eval (aCmd.ToCString());
7950 //! Find the keyword in the command and replace it with value.
7951 //! @return the position of the keyword to pass value
7952 void replace (TCollection_AsciiString& theCmd,
7953 const TCollection_AsciiString& theKey,
7954 const TCollection_AsciiString& theVal)
7956 TCollection_AsciiString aCmd (theCmd);
7958 const Standard_Integer aPos = aCmd.Search (theKey);
7964 TCollection_AsciiString aPart1, aPart2;
7965 Standard_Integer aPart1To = aPos - 1;
7967 && aPart1To <= theCmd.Length())
7969 aPart1 = theCmd.SubString (1, aPart1To);
7972 Standard_Integer aPart2From = aPos + theKey.Length();
7974 && aPart2From <= theCmd.Length())
7976 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
7979 theCmd = aPart1 + theVal + aPart2;
7984 Draw_Interpretor* myDrawInter;
7985 TCollection_AsciiString myCommand;
7989 //! Replace the animation with the new one.
7990 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
7991 Handle(AIS_Animation)& theAnimation,
7992 const Handle(AIS_Animation)& theAnimationNew)
7994 theAnimationNew->CopyFrom (theAnimation);
7995 if (!theParentAnimation.IsNull())
7997 theParentAnimation->Replace (theAnimation, theAnimationNew);
8001 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
8002 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
8004 theAnimation = theAnimationNew;
8007 //! Parse the point.
8008 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
8010 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
8011 if (!anXYZ[0].IsRealValue()
8012 || !anXYZ[1].IsRealValue()
8013 || !anXYZ[2].IsRealValue())
8015 return Standard_False;
8018 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
8019 return Standard_True;
8022 //! Parse the quaternion.
8023 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
8025 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
8026 if (!anXYZW[0].IsRealValue()
8027 || !anXYZW[1].IsRealValue()
8028 || !anXYZW[2].IsRealValue()
8029 || !anXYZW[3].IsRealValue())
8031 return Standard_False;
8034 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
8035 return Standard_True;
8038 //! Auxiliary class for flipping image upside-down.
8043 //! Empty constructor.
8044 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
8046 //! Perform flipping.
8047 Standard_Boolean FlipY (Image_PixMap& theImage)
8049 if (theImage.IsEmpty()
8050 || theImage.SizeX() == 0
8051 || theImage.SizeY() == 0)
8053 return Standard_False;
8056 const Standard_Size aRowSize = theImage.SizeRowBytes();
8057 if (myTmp.Size() < aRowSize
8058 && !myTmp.Allocate (aRowSize))
8060 return Standard_False;
8063 // for odd height middle row should be left as is
8064 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
8065 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
8067 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
8068 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
8069 memcpy (myTmp.ChangeData(), aTop, aRowSize);
8070 memcpy (aTop, aBot, aRowSize);
8071 memcpy (aBot, myTmp.Data(), aRowSize);
8073 return Standard_True;
8077 NCollection_Buffer myTmp;
8082 //=================================================================================================
8083 //function : VViewParams
8084 //purpose : Gets or sets AIS View characteristics
8085 //=================================================================================================
8086 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8088 Handle(V3d_View) aView = ViewerTest::CurrentView();
8091 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
8095 Standard_Boolean toSetProj = Standard_False;
8096 Standard_Boolean toSetUp = Standard_False;
8097 Standard_Boolean toSetAt = Standard_False;
8098 Standard_Boolean toSetEye = Standard_False;
8099 Standard_Boolean toSetScale = Standard_False;
8100 Standard_Boolean toSetSize = Standard_False;
8101 Standard_Boolean toSetCenter2d = Standard_False;
8102 Standard_Real aViewScale = aView->Scale();
8103 Standard_Real aViewSize = 1.0;
8104 Graphic3d_Vec2i aCenter2d;
8105 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
8106 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
8107 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
8108 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
8109 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
8112 // print all of the available view parameters
8116 "Proj: %12g %12g %12g\n"
8117 "Up: %12g %12g %12g\n"
8118 "At: %12g %12g %12g\n"
8119 "Eye: %12g %12g %12g\n",
8121 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
8122 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
8123 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
8124 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
8129 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
8130 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
8132 TCollection_AsciiString anArg (theArgVec[anArgIter]);
8134 if (anUpdateTool.parseRedrawMode (anArg))
8138 else if (anArg == "-cmd"
8139 || anArg == "-command"
8140 || anArg == "-args")
8149 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
8150 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
8151 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
8154 else if (anArg == "-scale"
8155 || anArg == "-size")
8157 if (anArgIter + 1 < theArgsNb
8158 && *theArgVec[anArgIter + 1] != '-')
8160 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
8161 if (aValueArg.IsRealValue())
8164 if (anArg == "-scale")
8166 toSetScale = Standard_True;
8167 aViewScale = aValueArg.RealValue();
8169 else if (anArg == "-size")
8171 toSetSize = Standard_True;
8172 aViewSize = aValueArg.RealValue();
8177 if (anArg == "-scale")
8179 theDi << "Scale: " << aView->Scale() << "\n";
8181 else if (anArg == "-size")
8183 Graphic3d_Vec2d aSizeXY;
8184 aView->Size (aSizeXY.x(), aSizeXY.y());
8185 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
8188 else if (anArg == "-eye"
8191 || anArg == "-proj")
8193 if (anArgIter + 3 < theArgsNb)
8196 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
8199 if (anArg == "-eye")
8201 toSetEye = Standard_True;
8204 else if (anArg == "-at")
8206 toSetAt = Standard_True;
8209 else if (anArg == "-up")
8211 toSetUp = Standard_True;
8214 else if (anArg == "-proj")
8216 toSetProj = Standard_True;
8223 if (anArg == "-eye")
8225 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
8227 else if (anArg == "-at")
8229 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
8231 else if (anArg == "-up")
8233 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
8235 else if (anArg == "-proj")
8237 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
8240 else if (anArg == "-center")
8242 if (anArgIter + 2 < theArgsNb)
8244 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
8245 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
8246 if (anX.IsIntegerValue()
8247 && anY.IsIntegerValue())
8249 toSetCenter2d = Standard_True;
8250 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
8256 std::cout << "Syntax error at '" << anArg << "'\n";
8261 // change view parameters in proper order
8264 aView->SetScale (aViewScale);
8268 aView->SetSize (aViewSize);
8272 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
8276 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
8280 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
8284 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
8288 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
8294 //==============================================================================
8295 //function : V2DMode
8297 //==============================================================================
8298 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
8300 bool is2dMode = true;
8301 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
8302 if (aV3dView.IsNull())
8304 std::cout << "Error: no active view.\n";
8307 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
8309 const TCollection_AsciiString anArg = theArgVec[anArgIt];
8310 TCollection_AsciiString anArgCase = anArg;
8311 anArgCase.LowerCase();
8312 if (anArgIt + 1 < theArgsNb
8313 && anArgCase == "-name")
8315 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
8316 TCollection_AsciiString aViewName = aViewNames.GetViewName();
8317 if (!ViewerTest_myViews.IsBound1 (aViewName))
8319 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
8322 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
8324 else if (anArgCase == "-mode")
8326 if (anArgIt + 1 < theArgsNb
8327 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
8332 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
8338 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
8343 aV3dView->SetView2DMode (is2dMode);
8347 //==============================================================================
8348 //function : VAnimation
8350 //==============================================================================
8351 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
8352 Standard_Integer theArgNb,
8353 const char** theArgVec)
8355 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
8358 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
8359 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
8361 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
8367 std::cout << "Error: no active view\n";
8371 Standard_Integer anArgIter = 1;
8372 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
8373 if (aNameArg.IsEmpty())
8375 std::cout << "Syntax error: animation name is not defined.\n";
8379 TCollection_AsciiString aNameArgLower = aNameArg;
8380 aNameArgLower.LowerCase();
8381 if (aNameArgLower == "-reset"
8382 || aNameArgLower == "-clear")
8384 ViewerTest_AnimationTimelineMap.Clear();
8387 else if (aNameArg.Value (1) == '-')
8389 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
8393 const char* aNameSplitter = "/";
8394 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
8395 if (aSplitPos == -1)
8397 aNameSplitter = ".";
8398 aSplitPos = aNameArg.Search (aNameSplitter);
8401 // find existing or create a new animation by specified name within syntax "parent.child".
8402 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
8403 for (; !aNameArg.IsEmpty();)
8405 TCollection_AsciiString aNameParent;
8406 if (aSplitPos != -1)
8408 if (aSplitPos == aNameArg.Length())
8410 std::cout << "Syntax error: animation name is not defined.\n";
8414 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
8415 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
8417 aSplitPos = aNameArg.Search (aNameSplitter);
8421 aNameParent = aNameArg;
8425 if (anAnimation.IsNull())
8427 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
8429 anAnimation = new AIS_Animation (aNameParent);
8430 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
8432 aRootAnimation = anAnimation;
8436 aParentAnimation = anAnimation;
8437 anAnimation = aParentAnimation->Find (aNameParent);
8438 if (anAnimation.IsNull())
8440 anAnimation = new AIS_Animation (aNameParent);
8441 aParentAnimation->Add (anAnimation);
8446 if (anArgIter >= theArgNb)
8448 // just print the list of children
8449 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
8451 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
8456 // animation parameters
8457 Standard_Boolean toPlay = Standard_False;
8458 Standard_Real aPlaySpeed = 1.0;
8459 Standard_Real aPlayStartTime = anAnimation->StartPts();
8460 Standard_Real aPlayDuration = anAnimation->Duration();
8461 Standard_Boolean isFreeCamera = Standard_False;
8462 Standard_Boolean isLockLoop = Standard_False;
8464 // video recording parameters
8465 TCollection_AsciiString aRecFile;
8466 Image_VideoParams aRecParams;
8468 Handle(V3d_View) aView = ViewerTest::CurrentView();
8469 for (; anArgIter < theArgNb; ++anArgIter)
8471 TCollection_AsciiString anArg (theArgVec[anArgIter]);
8474 if (anArg == "-reset"
8475 || anArg == "-clear")
8477 anAnimation->Clear();
8479 else if (anArg == "-remove"
8481 || anArg == "-delete")
8483 if (!aParentAnimation.IsNull())
8485 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
8489 aParentAnimation->Remove (anAnimation);
8493 else if (anArg == "-play")
8495 toPlay = Standard_True;
8496 if (++anArgIter < theArgNb)
8498 if (*theArgVec[anArgIter] == '-')
8503 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
8505 if (++anArgIter < theArgNb)
8507 if (*theArgVec[anArgIter] == '-')
8512 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8516 else if (anArg == "-resume")
8518 toPlay = Standard_True;
8519 aPlayStartTime = anAnimation->ElapsedTime();
8520 if (++anArgIter < theArgNb)
8522 if (*theArgVec[anArgIter] == '-')
8528 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8531 else if (anArg == "-playspeed"
8532 || anArg == "-speed")
8534 if (++anArgIter >= theArgNb)
8536 std::cout << "Syntax error at " << anArg << ".\n";
8539 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
8541 else if (anArg == "-lock"
8542 || anArg == "-lockloop"
8543 || anArg == "-playlockloop")
8545 isLockLoop = Standard_True;
8547 else if (anArg == "-freecamera"
8548 || anArg == "-playfreecamera"
8549 || anArg == "-freelook")
8551 isFreeCamera = Standard_True;
8553 // video recodring options
8554 else if (anArg == "-rec"
8555 || anArg == "-record")
8557 if (++anArgIter >= theArgNb)
8559 std::cout << "Syntax error at " << anArg << ".\n";
8563 aRecFile = theArgVec[anArgIter];
8564 if (aRecParams.FpsNum <= 0)
8566 aRecParams.FpsNum = 24;
8569 if (anArgIter + 2 < theArgNb
8570 && *theArgVec[anArgIter + 1] != '-'
8571 && *theArgVec[anArgIter + 2] != '-')
8573 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
8574 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
8575 if (aWidthArg .IsIntegerValue()
8576 && aHeightArg.IsIntegerValue())
8578 aRecParams.Width = aWidthArg .IntegerValue();
8579 aRecParams.Height = aHeightArg.IntegerValue();
8584 else if (anArg == "-fps")
8586 if (++anArgIter >= theArgNb)
8588 std::cout << "Syntax error at " << anArg << ".\n";
8592 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
8593 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
8594 if (aSplitIndex == 0)
8596 aRecParams.FpsNum = aFpsArg.IntegerValue();
8600 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
8601 aFpsArg.Split (aFpsArg.Length() - 1);
8602 const TCollection_AsciiString aNumStr = aFpsArg;
8603 aRecParams.FpsNum = aNumStr.IntegerValue();
8604 aRecParams.FpsDen = aDenStr.IntegerValue();
8605 if (aRecParams.FpsDen < 1)
8607 std::cout << "Syntax error at " << anArg << ".\n";
8612 else if (anArg == "-format")
8614 if (++anArgIter >= theArgNb)
8616 std::cout << "Syntax error at " << anArg << ".\n";
8619 aRecParams.Format = theArgVec[anArgIter];
8621 else if (anArg == "-pix_fmt"
8622 || anArg == "-pixfmt"
8623 || anArg == "-pixelformat")
8625 if (++anArgIter >= theArgNb)
8627 std::cout << "Syntax error at " << anArg << ".\n";
8630 aRecParams.PixelFormat = theArgVec[anArgIter];
8632 else if (anArg == "-codec"
8633 || anArg == "-vcodec"
8634 || anArg == "-videocodec")
8636 if (++anArgIter >= theArgNb)
8638 std::cout << "Syntax error at " << anArg << ".\n";
8641 aRecParams.VideoCodec = theArgVec[anArgIter];
8643 else if (anArg == "-crf"
8644 || anArg == "-preset"
8647 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
8648 if (++anArgIter >= theArgNb)
8650 std::cout << "Syntax error at " << anArg << ".\n";
8654 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
8656 // animation definition options
8657 else if (anArg == "-start"
8658 || anArg == "-starttime"
8659 || anArg == "-startpts")
8661 if (++anArgIter >= theArgNb)
8663 std::cout << "Syntax error at " << anArg << ".\n";
8667 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
8668 aRootAnimation->UpdateTotalDuration();
8670 else if (anArg == "-end"
8671 || anArg == "-endtime"
8672 || anArg == "-endpts")
8674 if (++anArgIter >= theArgNb)
8676 std::cout << "Syntax error at " << anArg << ".\n";
8680 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
8681 aRootAnimation->UpdateTotalDuration();
8683 else if (anArg == "-dur"
8684 || anArg == "-duration")
8686 if (++anArgIter >= theArgNb)
8688 std::cout << "Syntax error at " << anArg << ".\n";
8692 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
8693 aRootAnimation->UpdateTotalDuration();
8695 else if (anArg == "-command"
8697 || anArg == "-invoke"
8699 || anArg == "-proc")
8701 if (++anArgIter >= theArgNb)
8703 std::cout << "Syntax error at " << anArg << ".\n";
8707 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
8708 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
8710 else if (anArg == "-objecttrsf"
8711 || anArg == "-objectransformation"
8712 || anArg == "-objtransformation"
8713 || anArg == "-objtrsf"
8714 || anArg == "-object"
8717 if (++anArgIter >= theArgNb)
8719 std::cout << "Syntax error at " << anArg << ".\n";
8723 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
8724 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
8725 Handle(AIS_InteractiveObject) anObject;
8726 if (!aMapOfAIS.Find2 (anObjName, anObject))
8728 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
8732 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
8733 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
8734 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
8735 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
8736 Standard_Boolean isTrsfSet = Standard_False;
8737 Standard_Integer aTrsfArgIter = anArgIter + 1;
8738 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
8740 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
8741 aTrsfArg.LowerCase();
8742 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
8743 if (aTrsfArg.StartsWith ("-rotation")
8744 || aTrsfArg.StartsWith ("-rot"))
8746 isTrsfSet = Standard_True;
8747 if (aTrsfArgIter + 4 >= theArgNb
8748 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
8750 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8755 else if (aTrsfArg.StartsWith ("-location")
8756 || aTrsfArg.StartsWith ("-loc"))
8758 isTrsfSet = Standard_True;
8759 if (aTrsfArgIter + 3 >= theArgNb
8760 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
8762 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8767 else if (aTrsfArg.StartsWith ("-scale"))
8769 isTrsfSet = Standard_True;
8770 if (++aTrsfArgIter >= theArgNb)
8772 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8776 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
8777 if (!aScaleStr.IsRealValue())
8779 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8782 aScales[anIndex] = aScaleStr.RealValue();
8786 anArgIter = aTrsfArgIter - 1;
8792 std::cout << "Syntax error at " << anArg << ".\n";
8795 else if (aTrsfArgIter >= theArgNb)
8797 anArgIter = theArgNb;
8800 aTrsfs[0].SetRotation (aRotQuats[0]);
8801 aTrsfs[1].SetRotation (aRotQuats[1]);
8802 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
8803 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
8804 aTrsfs[0].SetScaleFactor (aScales[0]);
8805 aTrsfs[1].SetScaleFactor (aScales[1]);
8807 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
8808 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
8810 else if (anArg == "-viewtrsf"
8811 || anArg == "-view")
8813 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
8814 if (aCamAnimation.IsNull())
8816 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
8817 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
8820 Handle(Graphic3d_Camera) aCams[2] =
8822 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
8823 new Graphic3d_Camera (aCamAnimation->View()->Camera())
8826 Standard_Boolean isTrsfSet = Standard_False;
8827 Standard_Integer aViewArgIter = anArgIter + 1;
8828 for (; aViewArgIter < theArgNb; ++aViewArgIter)
8830 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
8831 aViewArg.LowerCase();
8832 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
8833 if (aViewArg.StartsWith ("-scale"))
8835 isTrsfSet = Standard_True;
8836 if (++aViewArgIter >= theArgNb)
8838 std::cout << "Syntax error at " << anArg << ".\n";
8842 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
8843 if (!aScaleStr.IsRealValue())
8845 std::cout << "Syntax error at " << aViewArg << ".\n";
8848 Standard_Real aScale = aScaleStr.RealValue();
8849 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
8850 aCams[anIndex]->SetScale (aScale);
8852 else if (aViewArg.StartsWith ("-eye")
8853 || aViewArg.StartsWith ("-center")
8854 || aViewArg.StartsWith ("-at")
8855 || aViewArg.StartsWith ("-up"))
8857 isTrsfSet = Standard_True;
8859 if (aViewArgIter + 3 >= theArgNb
8860 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
8862 std::cout << "Syntax error at " << aViewArg << ".\n";
8867 if (aViewArg.StartsWith ("-eye"))
8869 aCams[anIndex]->SetEye (anXYZ);
8871 else if (aViewArg.StartsWith ("-center")
8872 || aViewArg.StartsWith ("-at"))
8874 aCams[anIndex]->SetCenter (anXYZ);
8876 else if (aViewArg.StartsWith ("-up"))
8878 aCams[anIndex]->SetUp (anXYZ);
8883 anArgIter = aViewArgIter - 1;
8889 std::cout << "Syntax error at " << anArg << ".\n";
8892 else if (aViewArgIter >= theArgNb)
8894 anArgIter = theArgNb;
8897 aCamAnimation->SetCameraStart(aCams[0]);
8898 aCamAnimation->SetCameraEnd (aCams[1]);
8902 std::cout << "Syntax error at " << anArg << ".\n";
8907 if (!toPlay && aRecFile.IsEmpty())
8912 // Start animation timeline and process frame updating.
8913 TheIsAnimating = Standard_True;
8914 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
8915 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
8916 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
8919 aView->Camera()->Copy (aCameraBack);
8922 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
8923 if (aRecParams.FpsNum <= 0)
8925 while (!anAnimation->IsStopped())
8927 aCameraBack->Copy (aView->Camera());
8928 const Standard_Real aPts = anAnimation->UpdateTimer();
8931 aView->Camera()->Copy (aCameraBack);
8934 if (aPts >= anUpperPts)
8936 anAnimation->Pause();
8940 if (aView->IsInvalidated())
8946 aView->RedrawImmediate();
8951 // handle user events
8952 theDI.Eval ("after 1 set waiter 1");
8953 theDI.Eval ("vwait waiter");
8955 if (!TheIsAnimating)
8957 anAnimation->Pause();
8963 if (aView->IsInvalidated())
8969 aView->RedrawImmediate();
8974 OSD_Timer aPerfTimer;
8977 Handle(Image_VideoRecorder) aRecorder;
8978 ImageFlipper aFlipper;
8979 Handle(Draw_ProgressIndicator) aProgress;
8980 if (!aRecFile.IsEmpty())
8982 if (aRecParams.Width <= 0
8983 || aRecParams.Height <= 0)
8985 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
8988 aRecorder = new Image_VideoRecorder();
8989 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
8991 std::cout << "Error: failed to open video file for recording\n";
8995 aProgress = new Draw_ProgressIndicator (theDI, 1);
8998 // Manage frame-rated animation here
8999 Standard_Real aPts = aPlayStartTime;
9000 int64_t aNbFrames = 0;
9001 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
9002 Standard_Integer aSecondsProgress = 0;
9003 for (; aPts <= anUpperPts && aPSentry.More();)
9005 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
9006 aPts = aPlayStartTime + aRecPts;
9008 if (!anAnimation->Update (aPts))
9013 if (!aRecorder.IsNull())
9015 V3d_ImageDumpOptions aDumpParams;
9016 aDumpParams.Width = aRecParams.Width;
9017 aDumpParams.Height = aRecParams.Height;
9018 aDumpParams.BufferType = Graphic3d_BT_RGBA;
9019 aDumpParams.StereoOptions = V3d_SDO_MONO;
9020 aDumpParams.ToAdjustAspect = Standard_True;
9021 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
9023 std::cout << "Error: view dump is failed!\n";
9026 aFlipper.FlipY (aRecorder->ChangeFrame());
9027 if (!aRecorder->PushFrame())
9037 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
9045 anAnimation->Stop();
9046 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
9047 theDI << "Average FPS: " << aRecFps << "\n"
9048 << "Nb. Frames: " << Standard_Real(aNbFrames);
9053 aView->SetImmediateUpdate (wasImmediateUpdate);
9054 TheIsAnimating = Standard_False;
9059 //=======================================================================
9060 //function : VChangeSelected
9061 //purpose : Adds the shape to selection or remove one from it
9062 //=======================================================================
9063 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
9064 Standard_Integer argc,
9069 di<<"Usage : " << argv[0] << " shape \n";
9073 TCollection_AsciiString aName(argv[1]);
9074 Handle(AIS_InteractiveObject) anAISObject;
9075 if (!GetMapOfAIS().Find2 (aName, anAISObject)
9076 || anAISObject.IsNull())
9078 di<<"Use 'vdisplay' before";
9082 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
9086 //=======================================================================
9087 //function : VNbSelected
9088 //purpose : Returns number of selected objects
9089 //=======================================================================
9090 static Standard_Integer VNbSelected (Draw_Interpretor& di,
9091 Standard_Integer argc,
9096 di << "Usage : " << argv[0] << "\n";
9099 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9100 if(aContext.IsNull())
9102 di << "use 'vinit' command before " << argv[0] << "\n";
9105 di << aContext->NbSelected() << "\n";
9109 //=======================================================================
9110 //function : VPurgeDisplay
9111 //purpose : Switches altialiasing on or off
9112 //=======================================================================
9113 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
9114 Standard_Integer argc,
9119 di << "Usage : " << argv[0] << "\n";
9122 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9123 if (aContext.IsNull())
9125 di << "use 'vinit' command before " << argv[0] << "\n";
9129 di << aContext->PurgeDisplay() << "\n";
9133 //=======================================================================
9134 //function : VSetViewSize
9136 //=======================================================================
9137 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
9138 Standard_Integer argc,
9141 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9142 if(aContext.IsNull())
9144 di << "use 'vinit' command before " << argv[0] << "\n";
9149 di<<"Usage : " << argv[0] << " Size\n";
9152 Standard_Real aSize = Draw::Atof (argv[1]);
9155 di<<"Bad Size value : " << aSize << "\n";
9159 Handle(V3d_View) aView = ViewerTest::CurrentView();
9160 aView->SetSize(aSize);
9164 //=======================================================================
9165 //function : VMoveView
9167 //=======================================================================
9168 static Standard_Integer VMoveView (Draw_Interpretor& di,
9169 Standard_Integer argc,
9172 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9173 if(aContext.IsNull())
9175 di << "use 'vinit' command before " << argv[0] << "\n";
9178 if(argc < 4 || argc > 5)
9180 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
9183 Standard_Real Dx = Draw::Atof (argv[1]);
9184 Standard_Real Dy = Draw::Atof (argv[2]);
9185 Standard_Real Dz = Draw::Atof (argv[3]);
9186 Standard_Boolean aStart = Standard_True;
9189 aStart = (Draw::Atoi (argv[4]) > 0);
9192 Handle(V3d_View) aView = ViewerTest::CurrentView();
9193 aView->Move(Dx,Dy,Dz,aStart);
9197 //=======================================================================
9198 //function : VTranslateView
9200 //=======================================================================
9201 static Standard_Integer VTranslateView (Draw_Interpretor& di,
9202 Standard_Integer argc,
9205 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9206 if(aContext.IsNull())
9208 di << "use 'vinit' command before " << argv[0] << "\n";
9211 if(argc < 4 || argc > 5)
9213 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
9216 Standard_Real Dx = Draw::Atof (argv[1]);
9217 Standard_Real Dy = Draw::Atof (argv[2]);
9218 Standard_Real Dz = Draw::Atof (argv[3]);
9219 Standard_Boolean aStart = Standard_True;
9222 aStart = (Draw::Atoi (argv[4]) > 0);
9225 Handle(V3d_View) aView = ViewerTest::CurrentView();
9226 aView->Translate(Dx,Dy,Dz,aStart);
9230 //=======================================================================
9231 //function : VTurnView
9233 //=======================================================================
9234 static Standard_Integer VTurnView (Draw_Interpretor& di,
9235 Standard_Integer argc,
9238 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9239 if(aContext.IsNull()) {
9240 di << "use 'vinit' command before " << argv[0] << "\n";
9243 if(argc < 4 || argc > 5){
9244 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
9247 Standard_Real Ax = Draw::Atof (argv[1]);
9248 Standard_Real Ay = Draw::Atof (argv[2]);
9249 Standard_Real Az = Draw::Atof (argv[3]);
9250 Standard_Boolean aStart = Standard_True;
9253 aStart = (Draw::Atoi (argv[4]) > 0);
9256 Handle(V3d_View) aView = ViewerTest::CurrentView();
9257 aView->Turn(Ax,Ay,Az,aStart);
9261 //==============================================================================
9262 //function : VTextureEnv
9263 //purpose : ENables or disables environment mapping
9264 //==============================================================================
9265 class OCC_TextureEnv : public Graphic3d_TextureEnv
9268 OCC_TextureEnv(const Standard_CString FileName);
9269 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
9270 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
9271 const Standard_Boolean theModulateFlag,
9272 const Graphic3d_TypeOfTextureFilter theFilter,
9273 const Standard_ShortReal theXScale,
9274 const Standard_ShortReal theYScale,
9275 const Standard_ShortReal theXShift,
9276 const Standard_ShortReal theYShift,
9277 const Standard_ShortReal theAngle);
9278 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
9280 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
9282 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
9283 : Graphic3d_TextureEnv(theFileName)
9287 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
9288 : Graphic3d_TextureEnv(theTexId)
9292 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
9293 const Standard_Boolean theModulateFlag,
9294 const Graphic3d_TypeOfTextureFilter theFilter,
9295 const Standard_ShortReal theXScale,
9296 const Standard_ShortReal theYScale,
9297 const Standard_ShortReal theXShift,
9298 const Standard_ShortReal theYShift,
9299 const Standard_ShortReal theAngle)
9301 myParams->SetRepeat (theRepeatFlag);
9302 myParams->SetModulate (theModulateFlag);
9303 myParams->SetFilter (theFilter);
9304 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
9305 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
9306 myParams->SetRotation (theAngle);
9309 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
9311 // get the active view
9312 Handle(V3d_View) aView = ViewerTest::CurrentView();
9315 std::cerr << "No active view. Please call vinit.\n";
9319 // Checking the input arguments
9320 Standard_Boolean anEnableFlag = Standard_False;
9321 Standard_Boolean isOk = theArgNb >= 2;
9324 TCollection_AsciiString anEnableOpt(theArgVec[1]);
9325 anEnableFlag = anEnableOpt.IsEqual("on");
9326 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
9330 isOk = (theArgNb == 3 || theArgNb == 11);
9333 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9334 isOk = (!aTextureOpt.IsIntegerValue() ||
9335 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
9337 if (isOk && theArgNb == 11)
9339 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
9340 aModulateOpt(theArgVec[4]),
9341 aFilterOpt (theArgVec[5]),
9342 aSScaleOpt (theArgVec[6]),
9343 aTScaleOpt (theArgVec[7]),
9344 aSTransOpt (theArgVec[8]),
9345 aTTransOpt (theArgVec[9]),
9346 anAngleOpt (theArgVec[10]);
9347 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
9348 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
9349 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
9350 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
9351 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
9352 anAngleOpt.IsRealValue());
9359 std::cerr << "Usage :" << std::endl;
9360 std::cerr << theArgVec[0] << " off" << std::endl;
9361 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;
9367 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9368 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
9369 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
9370 new OCC_TextureEnv(theArgVec[2]);
9374 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
9375 aTexEnv->SetTextureParameters(
9376 aRepeatOpt. IsEqual("repeat"),
9377 aModulateOpt.IsEqual("modulate"),
9378 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
9379 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
9380 Graphic3d_TOTF_TRILINEAR,
9381 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
9382 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
9383 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
9384 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
9385 (Standard_ShortReal)Draw::Atof(theArgVec[10])
9388 aView->SetTextureEnv(aTexEnv);
9390 else // Disabling environment mapping
9392 Handle(Graphic3d_TextureEnv) aTexture;
9393 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
9402 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
9404 //! Remove registered clipping plane from all views and objects.
9405 static void removePlane (MapOfPlanes& theRegPlanes,
9406 const TCollection_AsciiString& theName)
9408 Handle(Graphic3d_ClipPlane) aClipPlane;
9409 if (!theRegPlanes.Find (theName, aClipPlane))
9411 std::cout << "Warning: no such plane.\n";
9415 theRegPlanes.UnBind (theName);
9416 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
9417 anIObjIt.More(); anIObjIt.Next())
9419 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
9420 aPrs->RemoveClipPlane (aClipPlane);
9423 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
9424 aViewIt.More(); aViewIt.Next())
9426 const Handle(V3d_View)& aView = aViewIt.Key2();
9427 aView->RemoveClipPlane(aClipPlane);
9430 ViewerTest::RedrawAllViews();
9434 //===============================================================================================
9435 //function : VClipPlane
9437 //===============================================================================================
9438 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9440 // use short-cut for created clip planes map of created (or "registered by name") clip planes
9441 static MapOfPlanes aRegPlanes;
9445 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
9447 theDi << aPlaneIter.Key() << " ";
9452 TCollection_AsciiString aCommand (theArgVec[1]);
9453 aCommand.LowerCase();
9454 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
9455 if (anActiveView.IsNull())
9457 std::cout << "Error: no active view.\n";
9461 // print maximum number of planes for current viewer
9462 if (aCommand == "-maxplanes"
9463 || aCommand == "maxplanes")
9465 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
9466 << " plane slots provided by driver.\n";
9470 // create / delete plane instance
9471 if (aCommand == "-create"
9472 || aCommand == "create"
9473 || aCommand == "-delete"
9474 || aCommand == "delete"
9475 || aCommand == "-clone"
9476 || aCommand == "clone")
9480 std::cout << "Syntax error: plane name is required.\n";
9484 Standard_Boolean toCreate = aCommand == "-create"
9485 || aCommand == "create";
9486 Standard_Boolean toClone = aCommand == "-clone"
9487 || aCommand == "clone";
9488 Standard_Boolean toDelete = aCommand == "-delete"
9489 || aCommand == "delete";
9490 TCollection_AsciiString aPlane (theArgVec[2]);
9494 if (aRegPlanes.IsBound (aPlane))
9496 std::cout << "Warning: existing plane has been overridden.\n";
9501 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9505 else if (toClone) // toClone
9507 if (!aRegPlanes.IsBound (aPlane))
9509 std::cout << "Error: no such plane.\n";
9512 else if (theArgsNb < 4)
9514 std::cout << "Syntax error: enter name for new plane.\n";
9518 TCollection_AsciiString aClone (theArgVec[3]);
9519 if (aRegPlanes.IsBound (aClone))
9521 std::cout << "Error: plane name is in use.\n";
9525 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
9527 aRegPlanes.Bind (aClone, aClipPlane->Clone());
9537 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
9539 aPlane = aPlaneIter.Key();
9540 removePlane (aRegPlanes, aPlane);
9541 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
9546 removePlane (aRegPlanes, aPlane);
9552 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9557 // set / unset plane command
9558 if (aCommand == "set"
9559 || aCommand == "unset")
9563 std::cout << "Syntax error: need more arguments.\n";
9567 // redirect to new syntax
9568 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
9569 anArgVec.SetValue (1, theArgVec[0]);
9570 anArgVec.SetValue (2, theArgVec[2]);
9571 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
9572 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
9574 anArgVec.SetValue (anIt, theArgVec[anIt]);
9577 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
9580 // change plane command
9581 TCollection_AsciiString aPlaneName;
9582 Handle(Graphic3d_ClipPlane) aClipPlane;
9583 Standard_Integer anArgIter = 0;
9584 if (aCommand == "-change"
9585 || aCommand == "change")
9587 // old syntax support
9590 std::cout << "Syntax error: need more arguments.\n";
9595 aPlaneName = theArgVec[2];
9596 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
9598 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
9602 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
9605 aPlaneName = theArgVec[1];
9610 aPlaneName = theArgVec[1];
9611 aClipPlane = new Graphic3d_ClipPlane();
9612 aRegPlanes.Bind (aPlaneName, aClipPlane);
9613 theDi << "Created new plane " << aPlaneName << ".\n";
9616 if (theArgsNb - anArgIter < 1)
9618 std::cout << "Syntax error: need more arguments.\n";
9622 for (; anArgIter < theArgsNb; ++anArgIter)
9624 const char** aChangeArgs = theArgVec + anArgIter;
9625 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
9626 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
9627 aChangeArg.LowerCase();
9629 Standard_Boolean toEnable = Standard_True;
9630 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
9632 aClipPlane->SetOn (toEnable);
9634 else if (aChangeArg.StartsWith ("-equation")
9635 || aChangeArg.StartsWith ("equation"))
9637 if (aNbChangeArgs < 5)
9639 std::cout << "Syntax error: need more arguments.\n";
9643 Standard_Integer aSubIndex = 1;
9644 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
9645 if (aPrefixLen < aChangeArg.Length())
9647 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
9648 if (!aSubStr.IsIntegerValue()
9649 || aSubStr.IntegerValue() <= 0)
9651 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9654 aSubIndex = aSubStr.IntegerValue();
9657 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
9658 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
9659 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
9660 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
9661 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9662 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
9664 if (aSubPln->ChainNextPlane().IsNull())
9666 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9668 aSubPln = aSubPln->ChainNextPlane();
9670 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9671 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
9674 else if ((aChangeArg == "-boxinterior"
9675 || aChangeArg == "-boxint"
9676 || aChangeArg == "-box")
9677 && aNbChangeArgs >= 7)
9679 Graphic3d_BndBox3d aBndBox;
9680 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
9681 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
9684 Standard_Integer aNbSubPlanes = 6;
9685 const Graphic3d_Vec3d aDirArray[6] =
9687 Graphic3d_Vec3d (-1, 0, 0),
9688 Graphic3d_Vec3d ( 1, 0, 0),
9689 Graphic3d_Vec3d ( 0,-1, 0),
9690 Graphic3d_Vec3d ( 0, 1, 0),
9691 Graphic3d_Vec3d ( 0, 0,-1),
9692 Graphic3d_Vec3d ( 0, 0, 1),
9694 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9695 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
9697 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
9698 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
9699 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
9700 if (aSubPlaneIter + 1 == aNbSubPlanes)
9702 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9706 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9708 aSubPln = aSubPln->ChainNextPlane();
9711 else if (aChangeArg == "-capping"
9712 || aChangeArg == "capping")
9714 if (aNbChangeArgs < 2)
9716 std::cout << "Syntax error: need more arguments.\n";
9720 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9722 aClipPlane->SetCapping (toEnable);
9727 // just skip otherwise (old syntax)
9730 else if (aChangeArg == "-useobjectmaterial"
9731 || aChangeArg == "-useobjectmat"
9732 || aChangeArg == "-useobjmat"
9733 || aChangeArg == "-useobjmaterial")
9735 if (aNbChangeArgs < 2)
9737 std::cout << "Syntax error: need more arguments.\n";
9741 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9743 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
9747 else if (aChangeArg == "-useobjecttexture"
9748 || aChangeArg == "-useobjecttex"
9749 || aChangeArg == "-useobjtexture"
9750 || aChangeArg == "-useobjtex")
9752 if (aNbChangeArgs < 2)
9754 std::cout << "Syntax error: need more arguments.\n";
9758 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9760 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
9764 else if (aChangeArg == "-useobjectshader"
9765 || aChangeArg == "-useobjshader")
9767 if (aNbChangeArgs < 2)
9769 std::cout << "Syntax error: need more arguments.\n";
9773 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9775 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
9779 else if (aChangeArg == "-color"
9780 || aChangeArg == "color")
9782 Quantity_Color aColor;
9783 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
9788 std::cout << "Syntax error: need more arguments.\n";
9792 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
9793 aMat.SetAmbientColor (aColor);
9794 aMat.SetDiffuseColor (aColor);
9795 aClipPlane->SetCappingMaterial (aMat);
9796 anArgIter += aNbParsed;
9798 else if ((aChangeArg == "-transparency"
9799 || aChangeArg == "-transp")
9800 && aNbChangeArgs >= 2)
9802 TCollection_AsciiString aValStr (aChangeArgs[1]);
9803 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
9804 if (aValStr.IsRealValue())
9806 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
9807 aMat.SetTransparency ((float )aValStr.RealValue());
9808 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
9809 aClipPlane->SetCappingMaterial (aMat);
9813 aValStr.LowerCase();
9814 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
9815 if (aValStr == "opaque")
9817 aMode = Graphic3d_AlphaMode_Opaque;
9819 else if (aValStr == "mask")
9821 aMode = Graphic3d_AlphaMode_Mask;
9823 else if (aValStr == "blend")
9825 aMode = Graphic3d_AlphaMode_Blend;
9827 else if (aValStr == "blendauto")
9829 aMode = Graphic3d_AlphaMode_BlendAuto;
9833 std::cout << "Syntax error at '" << aValStr << "'\n";
9836 anAspect->SetAlphaMode (aMode);
9837 aClipPlane->SetCappingAspect (anAspect);
9841 else if (aChangeArg == "-texname"
9842 || aChangeArg == "texname")
9844 if (aNbChangeArgs < 2)
9846 std::cout << "Syntax error: need more arguments.\n";
9850 TCollection_AsciiString aTextureName (aChangeArgs[1]);
9851 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
9852 if (!aTexture->IsDone())
9854 aClipPlane->SetCappingTexture (NULL);
9858 aTexture->EnableModulate();
9859 aTexture->EnableRepeat();
9860 aClipPlane->SetCappingTexture (aTexture);
9864 else if (aChangeArg == "-texscale"
9865 || aChangeArg == "texscale")
9867 if (aClipPlane->CappingTexture().IsNull())
9869 std::cout << "Error: no texture is set.\n";
9873 if (aNbChangeArgs < 3)
9875 std::cout << "Syntax error: need more arguments.\n";
9879 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9880 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9881 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
9884 else if (aChangeArg == "-texorigin"
9885 || aChangeArg == "texorigin") // texture origin
9887 if (aClipPlane->CappingTexture().IsNull())
9889 std::cout << "Error: no texture is set.\n";
9893 if (aNbChangeArgs < 3)
9895 std::cout << "Syntax error: need more arguments.\n";
9899 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9900 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9902 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
9905 else if (aChangeArg == "-texrotate"
9906 || aChangeArg == "texrotate") // texture rotation
9908 if (aClipPlane->CappingTexture().IsNull())
9910 std::cout << "Error: no texture is set.\n";
9914 if (aNbChangeArgs < 2)
9916 std::cout << "Syntax error: need more arguments.\n";
9920 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9921 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
9924 else if (aChangeArg == "-hatch"
9925 || aChangeArg == "hatch")
9927 if (aNbChangeArgs < 2)
9929 std::cout << "Syntax error: need more arguments.\n";
9933 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
9934 aHatchStr.LowerCase();
9935 if (aHatchStr == "on")
9937 aClipPlane->SetCappingHatchOn();
9939 else if (aHatchStr == "off")
9941 aClipPlane->SetCappingHatchOff();
9945 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
9949 else if (aChangeArg == "-delete"
9950 || aChangeArg == "delete")
9952 removePlane (aRegPlanes, aPlaneName);
9955 else if (aChangeArg == "-set"
9956 || aChangeArg == "-unset"
9957 || aChangeArg == "-setoverrideglobal")
9959 // set / unset plane command
9960 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
9961 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
9962 Standard_Integer anIt = 1;
9963 for (; anIt < aNbChangeArgs; ++anIt)
9965 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
9966 if (anEntityName.IsEmpty()
9967 || anEntityName.Value (1) == '-')
9971 else if (!toOverrideGlobal
9972 && ViewerTest_myViews.IsBound1 (anEntityName))
9974 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
9977 aView->AddClipPlane (aClipPlane);
9981 aView->RemoveClipPlane (aClipPlane);
9985 else if (GetMapOfAIS().IsBound2 (anEntityName))
9987 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
9990 aIObj->AddClipPlane (aClipPlane);
9994 aIObj->RemoveClipPlane (aClipPlane);
9996 if (!aIObj->ClipPlanes().IsNull())
9998 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
10003 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
10010 // apply to active view
10013 anActiveView->AddClipPlane (aClipPlane);
10017 anActiveView->RemoveClipPlane (aClipPlane);
10022 anArgIter = anArgIter + anIt - 1;
10027 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
10032 ViewerTest::RedrawAllViews();
10036 //===============================================================================================
10037 //function : VZRange
10039 //===============================================================================================
10040 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
10042 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
10044 if (aCurrentView.IsNull())
10046 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
10050 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
10054 theDi << "ZNear: " << aCamera->ZNear() << "\n";
10055 theDi << "ZFar: " << aCamera->ZFar() << "\n";
10059 if (theArgsNb == 3)
10061 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
10062 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
10064 if (aNewZNear >= aNewZFar)
10066 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
10070 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
10072 std::cout << theArgVec[0] << ": invalid arguments: ";
10073 std::cout << "znear, zfar should be positive for perspective camera.\n";
10077 aCamera->SetZRange (aNewZNear, aNewZFar);
10081 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
10085 aCurrentView->Redraw();
10090 //===============================================================================================
10091 //function : VAutoZFit
10093 //===============================================================================================
10094 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
10096 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
10098 if (aCurrentView.IsNull())
10100 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
10104 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
10108 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
10114 theDi << "Auto z-fit mode: \n"
10115 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
10116 << "Scale: " << aScale << "\n";
10120 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
10122 if (theArgsNb >= 3)
10124 aScale = Draw::Atoi (theArgVec[2]);
10127 aCurrentView->SetAutoZFitMode (isOn, aScale);
10128 aCurrentView->AutoZFit();
10129 aCurrentView->Redraw();
10134 //! Auxiliary function to print projection type
10135 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
10137 switch (theProjType)
10139 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
10140 case Graphic3d_Camera::Projection_Perspective: return "perspective";
10141 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
10142 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
10143 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
10148 //===============================================================================================
10149 //function : VCamera
10151 //===============================================================================================
10152 static int VCamera (Draw_Interpretor& theDI,
10153 Standard_Integer theArgsNb,
10154 const char** theArgVec)
10156 Handle(V3d_View) aView = ViewerTest::CurrentView();
10157 if (aView.IsNull())
10159 std::cout << "Error: no active view.\n";
10163 Handle(Graphic3d_Camera) aCamera = aView->Camera();
10166 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
10167 theDI << "FOVy: " << aCamera->FOVy() << "\n";
10168 theDI << "Distance: " << aCamera->Distance() << "\n";
10169 theDI << "IOD: " << aCamera->IOD() << "\n";
10170 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
10171 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
10172 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
10176 TCollection_AsciiString aPrsName;
10177 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10179 Standard_CString anArg = theArgVec[anArgIter];
10180 TCollection_AsciiString anArgCase (anArg);
10181 anArgCase.LowerCase();
10182 if (anArgCase == "-proj"
10183 || anArgCase == "-projection"
10184 || anArgCase == "-projtype"
10185 || anArgCase == "-projectiontype")
10187 theDI << projTypeName (aCamera->ProjectionType()) << " ";
10189 else if (anArgCase == "-ortho"
10190 || anArgCase == "-orthographic")
10192 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
10194 else if (anArgCase == "-persp"
10195 || anArgCase == "-perspective"
10196 || anArgCase == "-perspmono"
10197 || anArgCase == "-perspectivemono"
10198 || anArgCase == "-mono")
10200 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10202 else if (anArgCase == "-stereo"
10203 || anArgCase == "-stereoscopic"
10204 || anArgCase == "-perspstereo"
10205 || anArgCase == "-perspectivestereo")
10207 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10209 else if (anArgCase == "-left"
10210 || anArgCase == "-lefteye"
10211 || anArgCase == "-monoleft"
10212 || anArgCase == "-monolefteye"
10213 || anArgCase == "-perpsleft"
10214 || anArgCase == "-perpslefteye")
10216 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
10218 else if (anArgCase == "-right"
10219 || anArgCase == "-righteye"
10220 || anArgCase == "-monoright"
10221 || anArgCase == "-monorighteye"
10222 || anArgCase == "-perpsright")
10224 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
10226 else if (anArgCase == "-dist"
10227 || anArgCase == "-distance")
10229 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10230 if (anArgValue != NULL
10231 && *anArgValue != '-')
10234 aCamera->SetDistance (Draw::Atof (anArgValue));
10237 theDI << aCamera->Distance() << " ";
10239 else if (anArgCase == "-iod")
10241 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10242 if (anArgValue != NULL
10243 && *anArgValue != '-')
10246 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
10249 theDI << aCamera->IOD() << " ";
10251 else if (anArgCase == "-iodtype")
10253 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10254 TCollection_AsciiString anValueCase (anArgValue);
10255 anValueCase.LowerCase();
10256 if (anValueCase == "abs"
10257 || anValueCase == "absolute")
10260 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
10263 else if (anValueCase == "rel"
10264 || anValueCase == "relative")
10267 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
10270 else if (*anArgValue != '-')
10272 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
10275 switch (aCamera->GetIODType())
10277 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
10278 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
10281 else if (anArgCase == "-zfocus")
10283 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10284 if (anArgValue != NULL
10285 && *anArgValue != '-')
10288 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
10291 theDI << aCamera->ZFocus() << " ";
10293 else if (anArgCase == "-zfocustype")
10295 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10296 TCollection_AsciiString anValueCase (anArgValue);
10297 anValueCase.LowerCase();
10298 if (anValueCase == "abs"
10299 || anValueCase == "absolute")
10302 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
10305 else if (anValueCase == "rel"
10306 || anValueCase == "relative")
10309 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
10312 else if (*anArgValue != '-')
10314 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
10317 switch (aCamera->ZFocusType())
10319 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
10320 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
10323 else if (anArgCase == "-fov"
10324 || anArgCase == "-fovy")
10326 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10327 if (anArgValue != NULL
10328 && *anArgValue != '-')
10331 aCamera->SetFOVy (Draw::Atof (anArgValue));
10334 theDI << aCamera->FOVy() << " ";
10336 else if (aPrsName.IsEmpty()
10337 && !anArgCase.StartsWith ("-"))
10343 std::cout << "Error: unknown argument '" << anArg << "'\n";
10348 if (aPrsName.IsEmpty()
10355 if (!aPrsName.IsEmpty())
10357 Handle(AIS_CameraFrustum) aCameraFrustum;
10358 if (GetMapOfAIS().IsBound2 (aPrsName))
10360 // find existing object
10361 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
10362 if (aCameraFrustum.IsNull())
10364 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
10369 if (aCameraFrustum.IsNull())
10371 aCameraFrustum = new AIS_CameraFrustum();
10375 // not include displayed object of old camera frustum in the new one.
10376 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
10379 aCameraFrustum->SetCameraFrustum (aView->Camera());
10381 ViewerTest::Display (aPrsName, aCameraFrustum);
10387 //! Parse stereo output mode
10388 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
10389 Graphic3d_StereoMode& theMode)
10391 TCollection_AsciiString aFlag (theArg);
10393 if (aFlag == "quadbuffer")
10395 theMode = Graphic3d_StereoMode_QuadBuffer;
10397 else if (aFlag == "anaglyph")
10399 theMode = Graphic3d_StereoMode_Anaglyph;
10401 else if (aFlag == "row"
10402 || aFlag == "rowinterlaced")
10404 theMode = Graphic3d_StereoMode_RowInterlaced;
10406 else if (aFlag == "col"
10407 || aFlag == "colinterlaced"
10408 || aFlag == "columninterlaced")
10410 theMode = Graphic3d_StereoMode_ColumnInterlaced;
10412 else if (aFlag == "chess"
10413 || aFlag == "chessboard")
10415 theMode = Graphic3d_StereoMode_ChessBoard;
10417 else if (aFlag == "sbs"
10418 || aFlag == "sidebyside")
10420 theMode = Graphic3d_StereoMode_SideBySide;
10422 else if (aFlag == "ou"
10423 || aFlag == "overunder")
10425 theMode = Graphic3d_StereoMode_OverUnder;
10427 else if (aFlag == "pageflip"
10428 || aFlag == "softpageflip")
10430 theMode = Graphic3d_StereoMode_SoftPageFlip;
10434 return Standard_False;
10436 return Standard_True;
10439 //! Parse anaglyph filter
10440 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
10441 Graphic3d_RenderingParams::Anaglyph& theFilter)
10443 TCollection_AsciiString aFlag (theArg);
10445 if (aFlag == "redcyansimple")
10447 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10449 else if (aFlag == "redcyan"
10450 || aFlag == "redcyanoptimized")
10452 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
10454 else if (aFlag == "yellowbluesimple")
10456 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
10458 else if (aFlag == "yellowblue"
10459 || aFlag == "yellowblueoptimized")
10461 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
10463 else if (aFlag == "greenmagenta"
10464 || aFlag == "greenmagentasimple")
10466 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
10470 return Standard_False;
10472 return Standard_True;
10475 //==============================================================================
10476 //function : VStereo
10478 //==============================================================================
10480 static int VStereo (Draw_Interpretor& theDI,
10481 Standard_Integer theArgNb,
10482 const char** theArgVec)
10484 Handle(V3d_View) aView = ViewerTest::CurrentView();
10487 if (aView.IsNull())
10489 std::cout << "Error: no active viewer!\n";
10493 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
10494 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
10497 TCollection_AsciiString aMode;
10498 switch (aView->RenderingParams().StereoMode)
10500 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
10501 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
10502 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
10503 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
10504 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
10505 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
10506 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
10507 case Graphic3d_StereoMode_Anaglyph :
10508 aMode = "anaglyph";
10509 switch (aView->RenderingParams().AnaglyphFilter)
10511 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
10512 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
10513 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
10514 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
10515 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
10520 theDI << "Mode " << aMode << "\n";
10525 Handle(Graphic3d_Camera) aCamera;
10526 Graphic3d_RenderingParams* aParams = NULL;
10527 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
10528 if (!aView.IsNull())
10530 aParams = &aView->ChangeRenderingParams();
10531 aMode = aParams->StereoMode;
10532 aCamera = aView->Camera();
10535 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10536 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10538 Standard_CString anArg = theArgVec[anArgIter];
10539 TCollection_AsciiString aFlag (anArg);
10541 if (anUpdateTool.parseRedrawMode (aFlag))
10545 else if (aFlag == "0"
10548 if (++anArgIter < theArgNb)
10550 std::cout << "Error: wrong number of arguments!\n";
10554 if (!aCamera.IsNull()
10555 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
10557 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10559 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
10562 else if (aFlag == "1"
10565 if (++anArgIter < theArgNb)
10567 std::cout << "Error: wrong number of arguments!\n";
10571 if (!aCamera.IsNull())
10573 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10575 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10578 else if (aFlag == "-reverse"
10579 || aFlag == "-reversed"
10580 || aFlag == "-swap")
10582 Standard_Boolean toEnable = Standard_True;
10583 if (++anArgIter < theArgNb
10584 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10588 aParams->ToReverseStereo = toEnable;
10590 else if (aFlag == "-noreverse"
10591 || aFlag == "-noswap")
10593 Standard_Boolean toDisable = Standard_True;
10594 if (++anArgIter < theArgNb
10595 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
10599 aParams->ToReverseStereo = !toDisable;
10601 else if (aFlag == "-mode"
10602 || aFlag == "-stereomode")
10604 if (++anArgIter >= theArgNb
10605 || !parseStereoMode (theArgVec[anArgIter], aMode))
10607 std::cout << "Error: syntax error at '" << anArg << "'\n";
10611 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10613 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10616 else if (aFlag == "-anaglyph"
10617 || aFlag == "-anaglyphfilter")
10619 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10620 if (++anArgIter >= theArgNb
10621 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
10623 std::cout << "Error: syntax error at '" << anArg << "'\n";
10627 aMode = Graphic3d_StereoMode_Anaglyph;
10628 aParams->AnaglyphFilter = aFilter;
10630 else if (parseStereoMode (anArg, aMode)) // short syntax
10632 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10634 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10639 std::cout << "Error: syntax error at '" << anArg << "'\n";
10644 if (!aView.IsNull())
10646 aParams->StereoMode = aMode;
10647 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10652 //===============================================================================================
10653 //function : VDefaults
10655 //===============================================================================================
10656 static int VDefaults (Draw_Interpretor& theDi,
10657 Standard_Integer theArgsNb,
10658 const char** theArgVec)
10660 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
10663 std::cerr << "No active viewer!\n";
10667 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
10670 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
10672 theDi << "DeflType: relative\n"
10673 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
10677 theDi << "DeflType: absolute\n"
10678 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
10680 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
10681 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
10685 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10687 TCollection_AsciiString anArg (theArgVec[anArgIter]);
10689 if (anArg == "-ABSDEFL"
10690 || anArg == "-ABSOLUTEDEFLECTION"
10691 || anArg == "-DEFL"
10692 || anArg == "-DEFLECTION")
10694 if (++anArgIter >= theArgsNb)
10696 std::cout << "Error: wrong syntax at " << anArg << "\n";
10699 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
10700 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
10702 else if (anArg == "-RELDEFL"
10703 || anArg == "-RELATIVEDEFLECTION"
10704 || anArg == "-DEVCOEFF"
10705 || anArg == "-DEVIATIONCOEFF"
10706 || anArg == "-DEVIATIONCOEFFICIENT")
10708 if (++anArgIter >= theArgsNb)
10710 std::cout << "Error: wrong syntax at " << anArg << "\n";
10713 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
10714 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
10716 else if (anArg == "-ANGDEFL"
10717 || anArg == "-ANGULARDEFL"
10718 || anArg == "-ANGULARDEFLECTION")
10720 if (++anArgIter >= theArgsNb)
10722 std::cout << "Error: wrong syntax at " << anArg << "\n";
10725 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
10726 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
10728 else if (anArg == "-AUTOTR"
10729 || anArg == "-AUTOTRIANG"
10730 || anArg == "-AUTOTRIANGULATION")
10732 if (++anArgIter >= theArgsNb)
10734 std::cout << "Error: wrong syntax at " << anArg << "\n";
10737 TCollection_AsciiString aValue (theArgVec[anArgIter]);
10738 aValue.LowerCase();
10742 aDefParams->SetAutoTriangulation (Standard_True);
10744 else if (aValue == "off"
10747 aDefParams->SetAutoTriangulation (Standard_False);
10752 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
10759 //! Auxiliary method
10760 inline void addLight (const Handle(V3d_Light)& theLightNew,
10761 const Graphic3d_ZLayerId theLayer,
10762 const Standard_Boolean theIsGlobal)
10764 if (theLightNew.IsNull())
10769 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10770 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
10772 aViewer->AddLight (theLightNew);
10775 aViewer->SetLightOn (theLightNew);
10779 ViewerTest::CurrentView()->SetLightOn (theLightNew);
10784 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
10785 if (aSettings.Lights().IsNull())
10787 aSettings.SetLights (new Graphic3d_LightSet());
10789 aSettings.Lights()->Add (theLightNew);
10790 aViewer->SetZLayerSettings (theLayer, aSettings);
10794 //! Auxiliary method
10795 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
10797 TCollection_AsciiString anArgNextCase (theArgNext);
10798 anArgNextCase.UpperCase();
10799 if (anArgNextCase.Length() > 5
10800 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
10802 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
10806 return theArgNext.IntegerValue();
10810 //===============================================================================================
10811 //function : VLight
10813 //===============================================================================================
10814 static int VLight (Draw_Interpretor& theDi,
10815 Standard_Integer theArgsNb,
10816 const char** theArgVec)
10818 Handle(V3d_View) aView = ViewerTest::CurrentView();
10819 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10821 || aViewer.IsNull())
10823 std::cerr << "No active viewer!\n";
10827 Standard_Real anXYZ[3] = {};
10828 Standard_Real anAtten[2] = {};
10831 // print lights info
10832 Standard_Integer aLightId = 0;
10833 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
10835 Handle(V3d_Light) aLight = aLightIter.Value();
10836 const Quantity_Color aColor = aLight->Color();
10837 theDi << "Light #" << aLightId
10838 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
10839 << " [" << aLight->GetId() << "]" << "\n";
10840 switch (aLight->Type())
10844 theDi << " Type: Ambient\n";
10845 theDi << " Intensity: " << aLight->Intensity() << "\n";
10848 case V3d_DIRECTIONAL:
10850 theDi << " Type: Directional\n";
10851 theDi << " Intensity: " << aLight->Intensity() << "\n";
10852 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10853 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10854 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10855 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10858 case V3d_POSITIONAL:
10860 theDi << " Type: Positional\n";
10861 theDi << " Intensity: " << aLight->Intensity() << "\n";
10862 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10863 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10864 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10865 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10866 aLight->Attenuation (anAtten[0], anAtten[1]);
10867 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10872 theDi << " Type: Spot\n";
10873 theDi << " Intensity: " << aLight->Intensity() << "\n";
10874 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10875 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10876 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10877 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10878 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10879 aLight->Attenuation (anAtten[0], anAtten[1]);
10880 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10881 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
10882 theDi << " Exponent: " << aLight->Concentration() << "\n";
10887 theDi << " Type: UNKNOWN\n";
10891 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
10895 Handle(V3d_Light) aLightNew;
10896 Handle(V3d_Light) aLightOld;
10897 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
10898 Standard_Boolean isGlobal = Standard_True;
10899 Standard_Boolean toCreate = Standard_False;
10900 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10901 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
10903 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
10905 TCollection_AsciiString aName, aValue;
10906 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
10907 TCollection_AsciiString anArgCase (anArg);
10908 anArgCase.UpperCase();
10909 if (anUpdateTool.parseRedrawMode (anArg))
10914 if (anArgCase.IsEqual ("NEW")
10915 || anArgCase.IsEqual ("ADD")
10916 || anArgCase.IsEqual ("CREATE")
10917 || anArgCase.IsEqual ("-NEW")
10918 || anArgCase.IsEqual ("-ADD")
10919 || anArgCase.IsEqual ("-CREATE"))
10921 toCreate = Standard_True;
10923 else if (anArgCase.IsEqual ("-LAYER")
10924 || anArgCase.IsEqual ("-ZLAYER"))
10926 if (++anArgIt >= theArgsNb)
10928 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10932 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
10933 aValStr.LowerCase();
10934 if (aValStr == "default"
10935 || aValStr == "def")
10937 aLayer = Graphic3d_ZLayerId_Default;
10939 else if (aValStr == "top")
10941 aLayer = Graphic3d_ZLayerId_Top;
10943 else if (aValStr == "topmost")
10945 aLayer = Graphic3d_ZLayerId_Topmost;
10947 else if (aValStr == "toposd"
10948 || aValStr == "osd")
10950 aLayer = Graphic3d_ZLayerId_TopOSD;
10952 else if (aValStr == "botosd"
10953 || aValStr == "bottom")
10955 aLayer = Graphic3d_ZLayerId_BotOSD;
10957 else if (aValStr.IsIntegerValue())
10959 aLayer = Draw::Atoi (theArgVec[anArgIt]);
10963 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
10967 else if (anArgCase.IsEqual ("GLOB")
10968 || anArgCase.IsEqual ("GLOBAL")
10969 || anArgCase.IsEqual ("-GLOB")
10970 || anArgCase.IsEqual ("-GLOBAL"))
10972 isGlobal = Standard_True;
10974 else if (anArgCase.IsEqual ("LOC")
10975 || anArgCase.IsEqual ("LOCAL")
10976 || anArgCase.IsEqual ("-LOC")
10977 || anArgCase.IsEqual ("-LOCAL"))
10979 isGlobal = Standard_False;
10981 else if (anArgCase.IsEqual ("DEF")
10982 || anArgCase.IsEqual ("DEFAULTS")
10983 || anArgCase.IsEqual ("-DEF")
10984 || anArgCase.IsEqual ("-DEFAULTS"))
10986 toCreate = Standard_False;
10987 aViewer->SetDefaultLights();
10989 else if (anArgCase.IsEqual ("CLR")
10990 || anArgCase.IsEqual ("CLEAR")
10991 || anArgCase.IsEqual ("-CLR")
10992 || anArgCase.IsEqual ("-CLEAR"))
10994 toCreate = Standard_False;
10996 TColStd_SequenceOfInteger aLayers;
10997 aViewer->GetAllZLayers (aLayers);
10998 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
11000 if (aLayeriter.Value() == aLayer
11001 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
11003 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
11004 aSettings.SetLights (Handle(Graphic3d_LightSet)());
11005 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
11006 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
11013 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
11015 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
11017 Handle(V3d_Light) aLight = aLightIter.Value();
11018 aViewer->DelLight (aLight);
11019 aLightIter = aView->ActiveLightIterator();
11023 else if (anArgCase.IsEqual ("AMB")
11024 || anArgCase.IsEqual ("AMBIENT")
11025 || anArgCase.IsEqual ("AMBLIGHT"))
11029 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11033 addLight (aLightNew, aLayer, isGlobal);
11034 toCreate = Standard_False;
11035 aLightNew = new V3d_AmbientLight();
11037 else if (anArgCase.IsEqual ("DIRECTIONAL")
11038 || anArgCase.IsEqual ("DIRLIGHT"))
11042 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11046 addLight (aLightNew, aLayer, isGlobal);
11047 toCreate = Standard_False;
11048 aLightNew = new V3d_DirectionalLight();
11050 else if (anArgCase.IsEqual ("SPOT")
11051 || anArgCase.IsEqual ("SPOTLIGHT"))
11055 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11059 addLight (aLightNew, aLayer, isGlobal);
11060 toCreate = Standard_False;
11061 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
11063 else if (anArgCase.IsEqual ("POSLIGHT")
11064 || anArgCase.IsEqual ("POSITIONAL"))
11068 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11072 addLight (aLightNew, aLayer, isGlobal);
11073 toCreate = Standard_False;
11074 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
11076 else if (anArgCase.IsEqual ("CHANGE")
11077 || anArgCase.IsEqual ("-CHANGE"))
11079 if (++anArgIt >= theArgsNb)
11081 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11085 addLight (aLightNew, aLayer, isGlobal);
11086 aLightNew.Nullify();
11087 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
11088 Standard_Integer aLightIt = 0;
11089 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
11091 if (aLightIt == aLightId)
11093 aLightOld = aLightIter.Value();
11098 if (aLightOld.IsNull())
11100 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
11104 else if (anArgCase.IsEqual ("DEL")
11105 || anArgCase.IsEqual ("DELETE")
11106 || anArgCase.IsEqual ("-DEL")
11107 || anArgCase.IsEqual ("-DELETE"))
11109 Handle(V3d_Light) aLightDel;
11110 if (++anArgIt >= theArgsNb)
11112 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11116 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
11117 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
11118 Standard_Integer aLightIt = 0;
11119 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
11121 aLightDel = aLightIter.Value();
11122 if (aLightIt == aLightDelId)
11127 if (aLightDel.IsNull())
11132 TColStd_SequenceOfInteger aLayers;
11133 aViewer->GetAllZLayers (aLayers);
11134 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
11136 if (aLayeriter.Value() == aLayer
11137 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
11139 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
11140 if (!aSettings.Lights().IsNull())
11142 aSettings.Lights()->Remove (aLightDel);
11143 if (aSettings.Lights()->IsEmpty())
11145 aSettings.SetLights (Handle(Graphic3d_LightSet)());
11148 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
11149 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
11156 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
11158 aViewer->DelLight (aLightDel);
11161 else if (anArgCase.IsEqual ("COLOR")
11162 || anArgCase.IsEqual ("COLOUR")
11163 || anArgCase.IsEqual ("-COLOR")
11164 || anArgCase.IsEqual ("-COLOUR"))
11166 if (++anArgIt >= theArgsNb
11167 || aLightCurr.IsNull())
11169 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11173 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
11174 anArgNext.UpperCase();
11175 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
11176 aLightCurr->SetColor (aColor);
11178 else if (anArgCase.IsEqual ("POS")
11179 || anArgCase.IsEqual ("POSITION")
11180 || anArgCase.IsEqual ("-POS")
11181 || anArgCase.IsEqual ("-POSITION"))
11183 if ((anArgIt + 3) >= theArgsNb
11184 || aLightCurr.IsNull()
11185 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11186 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11188 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11192 anXYZ[0] = Atof (theArgVec[++anArgIt]);
11193 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11194 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11195 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
11197 else if (anArgCase.IsEqual ("DIR")
11198 || anArgCase.IsEqual ("DIRECTION")
11199 || anArgCase.IsEqual ("-DIR")
11200 || anArgCase.IsEqual ("-DIRECTION"))
11202 if ((anArgIt + 3) >= theArgsNb
11203 || aLightCurr.IsNull()
11204 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
11205 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11207 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11211 anXYZ[0] = Atof (theArgVec[++anArgIt]);
11212 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11213 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11214 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
11216 else if (anArgCase.IsEqual ("SM")
11217 || anArgCase.IsEqual ("SMOOTHNESS")
11218 || anArgCase.IsEqual ("-SM")
11219 || anArgCase.IsEqual ("-SMOOTHNESS"))
11221 if (++anArgIt >= theArgsNb
11222 || aLightCurr.IsNull())
11224 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11228 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11229 if (Abs (aSmoothness) <= ShortRealEpsilon())
11231 aLightCurr->SetIntensity (1.f);
11233 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
11235 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
11239 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
11240 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
11243 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
11245 aLightCurr->SetSmoothRadius (aSmoothness);
11247 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
11249 aLightCurr->SetSmoothAngle (aSmoothness);
11252 else if (anArgCase.IsEqual ("INT")
11253 || anArgCase.IsEqual ("INTENSITY")
11254 || anArgCase.IsEqual ("-INT")
11255 || anArgCase.IsEqual ("-INTENSITY"))
11257 if (++anArgIt >= theArgsNb
11258 || aLightCurr.IsNull())
11260 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11264 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11265 aLightCurr->SetIntensity (aIntensity);
11267 else if (anArgCase.IsEqual ("ANG")
11268 || anArgCase.IsEqual ("ANGLE")
11269 || anArgCase.IsEqual ("-ANG")
11270 || anArgCase.IsEqual ("-ANGLE"))
11272 if (++anArgIt >= theArgsNb
11273 || aLightCurr.IsNull()
11274 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11276 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11280 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11281 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
11283 else if (anArgCase.IsEqual ("CONSTATTEN")
11284 || anArgCase.IsEqual ("CONSTATTENUATION")
11285 || anArgCase.IsEqual ("-CONSTATTEN")
11286 || anArgCase.IsEqual ("-CONSTATTENUATION"))
11288 if (++anArgIt >= theArgsNb
11289 || aLightCurr.IsNull()
11290 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11291 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11293 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11297 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11298 anAtten[0] = Atof (theArgVec[anArgIt]);
11299 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11301 else if (anArgCase.IsEqual ("LINATTEN")
11302 || anArgCase.IsEqual ("LINEARATTEN")
11303 || anArgCase.IsEqual ("LINEARATTENUATION")
11304 || anArgCase.IsEqual ("-LINATTEN")
11305 || anArgCase.IsEqual ("-LINEARATTEN")
11306 || anArgCase.IsEqual ("-LINEARATTENUATION"))
11308 if (++anArgIt >= theArgsNb
11309 || aLightCurr.IsNull()
11310 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11311 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11313 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11317 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11318 anAtten[1] = Atof (theArgVec[anArgIt]);
11319 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11321 else if (anArgCase.IsEqual ("EXP")
11322 || anArgCase.IsEqual ("EXPONENT")
11323 || anArgCase.IsEqual ("SPOTEXP")
11324 || anArgCase.IsEqual ("SPOTEXPONENT")
11325 || anArgCase.IsEqual ("-EXP")
11326 || anArgCase.IsEqual ("-EXPONENT")
11327 || anArgCase.IsEqual ("-SPOTEXP")
11328 || anArgCase.IsEqual ("-SPOTEXPONENT"))
11330 if (++anArgIt >= theArgsNb
11331 || aLightCurr.IsNull()
11332 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11334 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11338 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
11340 else if (anArgCase.IsEqual ("HEAD")
11341 || anArgCase.IsEqual ("HEADLIGHT")
11342 || anArgCase.IsEqual ("-HEAD")
11343 || anArgCase.IsEqual ("-HEADLIGHT"))
11345 if (aLightCurr.IsNull()
11346 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
11348 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11352 Standard_Boolean isHeadLight = Standard_True;
11353 if (anArgIt + 1 < theArgsNb
11354 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
11358 aLightCurr->SetHeadlight (isHeadLight);
11362 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
11366 addLight (aLightNew, aLayer, isGlobal);
11370 //! Read Graphic3d_RenderingParams::PerfCounters flag.
11371 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
11372 Standard_Boolean& theToReset,
11373 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
11374 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
11376 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
11377 TCollection_AsciiString aVal = theValue;
11378 Standard_Boolean toReverse = Standard_False;
11379 if (aVal == "none")
11381 theToReset = Standard_True;
11382 return Standard_True;
11384 else if (aVal.StartsWith ("-"))
11386 toReverse = Standard_True;
11387 aVal = aVal.SubString (2, aVal.Length());
11389 else if (aVal.StartsWith ("no"))
11391 toReverse = Standard_True;
11392 aVal = aVal.SubString (3, aVal.Length());
11394 else if (aVal.StartsWith ("+"))
11396 aVal = aVal.SubString (2, aVal.Length());
11400 theToReset = Standard_True;
11404 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11405 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
11406 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
11407 else if (aVal == "structs"
11408 || aVal == "structures"
11409 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
11410 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
11411 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11412 else if (aVal == "tris"
11413 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
11414 else if (aVal == "pnts"
11415 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
11416 else if (aVal == "mem"
11417 || aVal == "gpumem"
11418 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11419 else if (aVal == "skipimmediate"
11420 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
11421 else if (aVal == "frametime"
11422 || aVal == "frametimers"
11423 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11424 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
11425 else if (aVal == "extended"
11426 || aVal == "verbose"
11427 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
11428 else if (aVal == "full"
11429 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
11432 return Standard_False;
11437 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
11441 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
11443 return Standard_True;
11446 //! Read Graphic3d_RenderingParams::PerfCounters flags.
11447 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
11448 Graphic3d_RenderingParams::PerfCounters& theFlags)
11450 TCollection_AsciiString aValue = theValue;
11451 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
11452 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
11453 Standard_Boolean toReset = Standard_False;
11456 Standard_Integer aSplitPos = aValue.Search ("|");
11457 if (aSplitPos <= 0)
11459 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
11461 return Standard_False;
11465 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
11467 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
11468 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
11469 return Standard_True;
11474 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
11475 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
11477 return Standard_False;
11480 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
11484 //=======================================================================
11485 //function : VRenderParams
11486 //purpose : Enables/disables rendering features
11487 //=======================================================================
11489 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
11490 Standard_Integer theArgNb,
11491 const char** theArgVec)
11493 Handle(V3d_View) aView = ViewerTest::CurrentView();
11494 if (aView.IsNull())
11496 std::cerr << "Error: no active viewer!\n";
11500 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
11501 TCollection_AsciiString aCmdName (theArgVec[0]);
11502 aCmdName.LowerCase();
11503 if (aCmdName == "vraytrace")
11507 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
11510 else if (theArgNb == 2)
11512 TCollection_AsciiString aValue (theArgVec[1]);
11513 aValue.LowerCase();
11517 aParams.Method = Graphic3d_RM_RAYTRACING;
11521 else if (aValue == "off"
11524 aParams.Method = Graphic3d_RM_RASTERIZATION;
11530 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
11536 std::cout << "Error: wrong number of arguments\n";
11543 theDI << "renderMode: ";
11544 switch (aParams.Method)
11546 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11547 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
11550 theDI << "transparency: ";
11551 switch (aParams.TransparencyMethod)
11553 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
11554 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
11555 << TCollection_AsciiString (aParams.OitDepthFactor); break;
11558 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
11559 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
11560 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
11561 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
11562 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
11563 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
11564 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
11565 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
11566 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
11567 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
11568 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
11569 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
11570 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
11571 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
11572 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
11573 theDI << "shadingModel: ";
11574 switch (aView->ShadingModel())
11576 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11577 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
11578 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
11579 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
11580 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
11583 theDI << "perfCounters:";
11584 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
11588 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
11592 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
11594 theDI << " structs";
11596 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
11598 theDI << " groups";
11600 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
11602 theDI << " arrays";
11604 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
11608 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
11612 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
11614 theDI << " gpumem";
11616 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
11618 theDI << " frameTime";
11620 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
11622 theDI << " skipimmediate";
11624 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
11630 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
11631 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
11632 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
11633 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
11634 "noUpdate") << "\n";
11639 Standard_Boolean toPrint = Standard_False;
11640 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
11641 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11643 Standard_CString anArg (theArgVec[anArgIter]);
11644 TCollection_AsciiString aFlag (anArg);
11646 if (anUpdateTool.parseRedrawMode (aFlag))
11650 else if (aFlag == "-echo"
11651 || aFlag == "-print")
11653 toPrint = Standard_True;
11654 anUpdateTool.Invalidate();
11656 else if (aFlag == "-mode"
11657 || aFlag == "-rendermode"
11658 || aFlag == "-render_mode")
11662 switch (aParams.Method)
11664 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11665 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
11671 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11675 else if (aFlag == "-ray"
11676 || aFlag == "-raytrace")
11680 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
11684 aParams.Method = Graphic3d_RM_RAYTRACING;
11686 else if (aFlag == "-rast"
11687 || aFlag == "-raster"
11688 || aFlag == "-rasterization")
11692 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
11696 aParams.Method = Graphic3d_RM_RASTERIZATION;
11698 else if (aFlag == "-msaa")
11702 theDI << aParams.NbMsaaSamples << " ";
11705 else if (++anArgIter >= theArgNb)
11707 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11711 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
11712 if (aNbSamples < 0)
11714 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
11719 aParams.NbMsaaSamples = aNbSamples;
11722 else if (aFlag == "-linefeather"
11723 || aFlag == "-edgefeather"
11724 || aFlag == "-feather")
11728 theDI << " " << aParams.LineFeather << " ";
11731 else if (++anArgIter >= theArgNb)
11733 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11737 TCollection_AsciiString aParam = theArgVec[anArgIter];
11738 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11739 if (aFeather <= 0.0f)
11741 std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n";
11744 aParams.LineFeather = aFeather;
11746 else if (aFlag == "-oit")
11750 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
11752 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
11756 theDI << "off" << " ";
11760 else if (++anArgIter >= theArgNb)
11762 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11766 TCollection_AsciiString aParam = theArgVec[anArgIter];
11767 aParam.LowerCase();
11768 if (aParam.IsRealValue())
11770 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11771 if (aWeight < 0.f || aWeight > 1.f)
11773 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
11777 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
11778 aParams.OitDepthFactor = aWeight;
11780 else if (aParam == "off")
11782 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
11786 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11790 else if (aFlag == "-depthprepass")
11794 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
11797 aParams.ToEnableDepthPrepass = Standard_True;
11798 if (anArgIter + 1 < theArgNb
11799 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
11804 else if (aFlag == "-samplealphatocoverage"
11805 || aFlag == "-alphatocoverage")
11809 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
11812 aParams.ToEnableAlphaToCoverage = Standard_True;
11813 if (anArgIter + 1 < theArgNb
11814 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
11819 else if (aFlag == "-rendscale"
11820 || aFlag == "-renderscale"
11821 || aFlag == "-renderresolutionscale")
11825 theDI << aParams.RenderResolutionScale << " ";
11828 else if (++anArgIter >= theArgNb)
11830 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11834 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
11837 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
11842 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
11845 else if (aFlag == "-raydepth"
11846 || aFlag == "-ray_depth")
11850 theDI << aParams.RaytracingDepth << " ";
11853 else if (++anArgIter >= theArgNb)
11855 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11859 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
11861 // We allow RaytracingDepth be more than 10 in case of GI enabled
11862 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
11864 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
11869 aParams.RaytracingDepth = aDepth;
11872 else if (aFlag == "-shad"
11873 || aFlag == "-shadows")
11877 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
11881 Standard_Boolean toEnable = Standard_True;
11882 if (++anArgIter < theArgNb
11883 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11887 aParams.IsShadowEnabled = toEnable;
11889 else if (aFlag == "-refl"
11890 || aFlag == "-reflections")
11894 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
11898 Standard_Boolean toEnable = Standard_True;
11899 if (++anArgIter < theArgNb
11900 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11904 aParams.IsReflectionEnabled = toEnable;
11906 else if (aFlag == "-fsaa")
11910 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
11914 Standard_Boolean toEnable = Standard_True;
11915 if (++anArgIter < theArgNb
11916 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11920 aParams.IsAntialiasingEnabled = toEnable;
11922 else if (aFlag == "-gleam")
11926 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
11930 Standard_Boolean toEnable = Standard_True;
11931 if (++anArgIter < theArgNb
11932 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11936 aParams.IsTransparentShadowEnabled = toEnable;
11938 else if (aFlag == "-gi")
11942 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
11946 Standard_Boolean toEnable = Standard_True;
11947 if (++anArgIter < theArgNb
11948 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11952 aParams.IsGlobalIlluminationEnabled = toEnable;
11955 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
11958 else if (aFlag == "-blockedrng"
11959 || aFlag == "-brng")
11963 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
11967 Standard_Boolean toEnable = Standard_True;
11968 if (++anArgIter < theArgNb
11969 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11973 aParams.CoherentPathTracingMode = toEnable;
11975 else if (aFlag == "-maxrad")
11979 theDI << aParams.RadianceClampingValue << " ";
11982 else if (++anArgIter >= theArgNb)
11984 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11988 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
11989 if (!aMaxRadStr.IsRealValue())
11991 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11995 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
11996 if (aMaxRadiance <= 0.0)
11998 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
12003 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
12006 else if (aFlag == "-iss")
12010 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
12014 Standard_Boolean toEnable = Standard_True;
12015 if (++anArgIter < theArgNb
12016 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12020 aParams.AdaptiveScreenSampling = toEnable;
12022 else if (aFlag == "-issatomic")
12026 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
12030 Standard_Boolean toEnable = Standard_True;
12031 if (++anArgIter < theArgNb
12032 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12036 aParams.AdaptiveScreenSamplingAtomic = toEnable;
12038 else if (aFlag == "-issd")
12042 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
12046 Standard_Boolean toEnable = Standard_True;
12047 if (++anArgIter < theArgNb
12048 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12052 aParams.ShowSamplingTiles = toEnable;
12054 else if (aFlag == "-tilesize")
12058 theDI << aParams.RayTracingTileSize << " ";
12061 else if (++anArgIter >= theArgNb)
12063 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12067 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
12070 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
12073 aParams.RayTracingTileSize = aTileSize;
12075 else if (aFlag == "-nbtiles")
12079 theDI << aParams.NbRayTracingTiles << " ";
12082 else if (++anArgIter >= theArgNb)
12084 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12088 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
12091 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
12094 else if (aNbTiles > 0
12096 || aNbTiles > 1024))
12098 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
12100 aParams.NbRayTracingTiles = aNbTiles;
12102 else if (aFlag == "-env")
12106 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
12110 Standard_Boolean toEnable = Standard_True;
12111 if (++anArgIter < theArgNb
12112 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12116 aParams.UseEnvironmentMapBackground = toEnable;
12118 else if (aFlag == "-twoside")
12122 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
12126 Standard_Boolean toEnable = Standard_True;
12127 if (++anArgIter < theArgNb
12128 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12132 aParams.TwoSidedBsdfModels = toEnable;
12134 else if (aFlag == "-shademodel"
12135 || aFlag == "-shadingmodel"
12136 || aFlag == "-shading")
12140 switch (aView->ShadingModel())
12142 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
12143 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
12144 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
12145 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
12146 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
12151 if (++anArgIter >= theArgNb)
12153 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12156 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
12157 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
12158 && aModel != Graphic3d_TOSM_DEFAULT)
12160 aView->SetShadingModel (aModel);
12164 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
12168 else if (aFlag == "-resolution")
12170 if (++anArgIter >= theArgNb)
12172 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12176 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
12177 if (aResolution.IsIntegerValue())
12179 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
12183 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12187 else if (aFlag == "-rebuildglsl"
12188 || aFlag == "-rebuild")
12192 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
12196 Standard_Boolean toEnable = Standard_True;
12197 if (++anArgIter < theArgNb
12198 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12202 aParams.RebuildRayTracingShaders = toEnable;
12204 else if (aFlag == "-focal")
12206 if (++anArgIter >= theArgNb)
12208 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12212 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12213 if (aParam.IsRealValue())
12215 float aFocalDist = static_cast<float> (aParam.RealValue());
12216 if (aFocalDist < 0)
12218 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12221 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
12225 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12229 else if (aFlag == "-aperture")
12231 if (++anArgIter >= theArgNb)
12233 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12237 TCollection_AsciiString aParam(theArgVec[anArgIter]);
12238 if (aParam.IsRealValue())
12240 float aApertureSize = static_cast<float> (aParam.RealValue());
12241 if (aApertureSize < 0)
12243 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12246 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
12250 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12254 else if (aFlag == "-exposure")
12256 if (++anArgIter >= theArgNb)
12258 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12262 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
12263 if (anExposure.IsRealValue())
12265 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
12269 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12273 else if (aFlag == "-whitepoint")
12275 if (++anArgIter >= theArgNb)
12277 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12281 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
12282 if (aWhitePoint.IsRealValue())
12284 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
12288 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12292 else if (aFlag == "-tonemapping")
12294 if (++anArgIter >= theArgNb)
12296 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12300 TCollection_AsciiString aMode (theArgVec[anArgIter]);
12303 if (aMode == "disabled")
12305 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
12307 else if (aMode == "filmic")
12309 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
12313 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12317 else if (aFlag == "-performancestats"
12318 || aFlag == "-performancecounters"
12319 || aFlag == "-perfstats"
12320 || aFlag == "-perfcounters"
12321 || aFlag == "-stats")
12323 if (++anArgIter >= theArgNb)
12325 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12329 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
12330 aFlagsStr.LowerCase();
12331 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
12332 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
12334 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12337 aView->ChangeRenderingParams().CollectedStats = aFlags;
12338 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
12340 else if (aFlag == "-perfupdateinterval"
12341 || aFlag == "-statsupdateinterval")
12343 if (++anArgIter >= theArgNb)
12345 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12348 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12350 else if (aFlag == "-perfchart"
12351 || aFlag == "-statschart")
12353 if (++anArgIter >= theArgNb)
12355 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12358 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
12360 else if (aFlag == "-perfchartmax"
12361 || aFlag == "-statschartmax")
12363 if (++anArgIter >= theArgNb)
12365 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12368 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12370 else if (aFlag == "-frustumculling"
12371 || aFlag == "-culling")
12375 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
12376 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
12377 "noUpdate") << " ";
12381 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
12382 if (++anArgIter < theArgNb)
12384 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
12385 aStateStr.LowerCase();
12386 bool toEnable = true;
12387 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
12389 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
12391 else if (aStateStr == "noupdate"
12392 || aStateStr == "freeze")
12394 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
12401 aParams.FrustumCullingState = aState;
12405 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
12413 //=======================================================================
12414 //function : searchInfo
12416 //=======================================================================
12417 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
12418 const TCollection_AsciiString& theKey)
12420 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
12422 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
12424 return anIter.Value();
12427 return TCollection_AsciiString();
12430 //=======================================================================
12431 //function : VStatProfiler
12433 //=======================================================================
12434 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
12435 Standard_Integer theArgNb,
12436 const char** theArgVec)
12438 Handle(V3d_View) aView = ViewerTest::CurrentView();
12439 if (aView.IsNull())
12441 std::cerr << "Error: no active viewer!\n";
12445 Standard_Boolean toRedraw = Standard_True;
12446 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
12447 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
12448 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
12449 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12451 Standard_CString anArg (theArgVec[anArgIter]);
12452 TCollection_AsciiString aFlag (anArg);
12454 if (aFlag == "-noredraw")
12456 toRedraw = Standard_False;
12460 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
12461 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
12462 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
12463 else if (aFlag == "alllayers"
12464 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
12465 else if (aFlag == "allstructs"
12466 || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
12467 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
12468 else if (aFlag == "allarrays"
12469 || aFlag == "fillarrays"
12470 || aFlag == "linearrays"
12471 || aFlag == "pointarrays"
12472 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
12473 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
12474 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
12475 else if (aFlag == "geommem"
12476 || aFlag == "texturemem"
12477 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
12478 else if (aFlag == "elapsedframe"
12479 || aFlag == "cpuframeaverage"
12480 || aFlag == "cpupickingaverage"
12481 || aFlag == "cpucullingaverage"
12482 || aFlag == "cpudynaverage"
12483 || aFlag == "cpuframemax"
12484 || aFlag == "cpupickingmax"
12485 || aFlag == "cpucullingmax"
12486 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
12489 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
12493 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
12497 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
12499 aView->ChangeRenderingParams().CollectedStats =
12500 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
12504 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12506 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12509 TColStd_IndexedDataMapOfStringString aDict;
12510 aView->StatisticInformation (aDict);
12512 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
12514 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12516 Standard_CString anArg(theArgVec[anArgIter]);
12517 TCollection_AsciiString aFlag(anArg);
12519 if (aFlag == "fps")
12521 theDI << searchInfo (aDict, "FPS") << " ";
12523 else if (aFlag == "cpu")
12525 theDI << searchInfo (aDict, "CPU FPS") << " ";
12527 else if (aFlag == "alllayers")
12529 theDI << searchInfo (aDict, "Layers") << " ";
12531 else if (aFlag == "layers")
12533 theDI << searchInfo (aDict, "Rendered layers") << " ";
12535 else if (aFlag == "allstructs")
12537 theDI << searchInfo (aDict, "Structs") << " ";
12539 else if (aFlag == "structs")
12541 theDI << searchInfo (aDict, "Rendered structs") << " ";
12543 else if (aFlag == "groups")
12545 theDI << searchInfo (aDict, "Rendered groups") << " ";
12547 else if (aFlag == "allarrays")
12549 theDI << searchInfo (aDict, "Rendered arrays") << " ";
12551 else if (aFlag == "fillarrays")
12553 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
12555 else if (aFlag == "linearrays")
12557 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
12559 else if (aFlag == "pointarrays")
12561 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
12563 else if (aFlag == "textarrays")
12565 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
12567 else if (aFlag == "triangles")
12569 theDI << searchInfo (aDict, "Rendered triangles") << " ";
12571 else if (aFlag == "points")
12573 theDI << searchInfo (aDict, "Rendered points") << " ";
12575 else if (aFlag == "geommem")
12577 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
12579 else if (aFlag == "texturemem")
12581 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
12583 else if (aFlag == "framemem")
12585 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
12587 else if (aFlag == "elapsedframe")
12589 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
12591 else if (aFlag == "cpuframe_average")
12593 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
12595 else if (aFlag == "cpupicking_average")
12597 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
12599 else if (aFlag == "cpuculling_average")
12601 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
12603 else if (aFlag == "cpudyn_average")
12605 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
12607 else if (aFlag == "cpuframe_max")
12609 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
12611 else if (aFlag == "cpupicking_max")
12613 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
12615 else if (aFlag == "cpuculling_max")
12617 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
12619 else if (aFlag == "cpudyn_max")
12621 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
12629 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12631 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12633 theDI << "Statistic info:\n" << aView->StatisticInformation();
12638 //=======================================================================
12639 //function : VProgressiveMode
12641 //=======================================================================
12642 #if defined(_WIN32)
12643 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
12644 Standard_Integer /*theNbArgs*/,
12645 const char** /*theArgs*/)
12647 Handle(V3d_View) aView = ViewerTest::CurrentView();
12648 if (aView.IsNull())
12650 std::cerr << "Error: no active viewer!\n";
12654 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
12660 Standard_Boolean toExit = Standard_False;
12663 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
12665 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
12667 toExit = Standard_True;
12670 TranslateMessage (&aMsg);
12671 DispatchMessageW (&aMsg);
12684 //=======================================================================
12685 //function : VXRotate
12687 //=======================================================================
12688 static Standard_Integer VXRotate (Draw_Interpretor& di,
12689 Standard_Integer argc,
12690 const char ** argv)
12692 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
12693 if (aContext.IsNull())
12695 di << argv[0] << "ERROR : use 'vinit' command before \n";
12701 di << "ERROR : Usage : " << argv[0] << " name angle\n";
12705 TCollection_AsciiString aName (argv[1]);
12706 Standard_Real anAngle = Draw::Atof (argv[2]);
12709 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
12710 Handle(AIS_InteractiveObject) anIObj;
12711 if (!aMap.Find2 (aName, anIObj))
12713 di << "Use 'vdisplay' before\n";
12717 gp_Trsf aTransform;
12718 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
12719 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
12721 aContext->SetLocation (anIObj, aTransform);
12722 aContext->UpdateCurrentViewer();
12726 //===============================================================================================
12727 //class : ViewerTest_AISManipulator
12728 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
12729 //===============================================================================================
12730 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
12732 class ViewerTest_AISManipulator : public AIS_Manipulator
12736 ViewerTest_AISManipulator() : AIS_Manipulator()
12738 GetMapOfAISManipulators().Add (this);
12741 virtual ~ViewerTest_AISManipulator()
12743 GetMapOfAISManipulators().Remove (this);
12746 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
12749 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
12750 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
12752 //===============================================================================================
12753 //function : VManipulator
12755 //===============================================================================================
12756 static int VManipulator (Draw_Interpretor& theDi,
12757 Standard_Integer theArgsNb,
12758 const char** theArgVec)
12760 Handle(V3d_View) aView = ViewerTest::CurrentView();
12761 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
12762 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
12764 || aViewer.IsNull())
12766 std::cerr << "No active viewer!\n";
12770 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
12771 Standard_Integer anArgIter = 1;
12772 for (; anArgIter < theArgsNb; ++anArgIter)
12774 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
12777 ViewerTest_CmdParser aCmd;
12778 aCmd.SetDescription ("Manages manipulator for interactive objects:");
12779 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
12780 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
12781 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
12782 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
12783 aCmd.AddOption ("detach", "... - detach manipulator");
12785 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
12786 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
12787 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
12789 aCmd.AddOption ("move", "... x y z - move object");
12790 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
12791 aCmd.AddOption ("scale", "... factor - scale object");
12793 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
12794 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
12795 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
12796 aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform");
12797 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
12798 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
12799 aCmd.AddOption ("parts", "... all axes mode {0|1} - set visual part");
12800 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
12801 aCmd.AddOption ("size", "... size - set size of manipulator");
12802 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
12804 aCmd.Parse (theArgsNb, theArgVec);
12806 if (aCmd.HasOption ("help"))
12808 theDi.PrintHelp (theArgVec[0]);
12812 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
12814 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
12816 if (aName.IsEmpty())
12818 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
12822 // ----------------------------------
12823 // detach existing manipulator object
12824 // ----------------------------------
12826 if (aCmd.HasOption ("detach"))
12828 if (!aMapAIS.IsBound2 (aName))
12830 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
12834 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12835 if (aManipulator.IsNull())
12837 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12841 aManipulator->Detach();
12842 aMapAIS.UnBind2 (aName);
12843 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
12848 // -----------------------------------------------
12849 // find or create manipulator if it does not exist
12850 // -----------------------------------------------
12852 Handle(AIS_Manipulator) aManipulator;
12853 if (!aMapAIS.IsBound2 (aName))
12855 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
12857 aManipulator = new ViewerTest_AISManipulator();
12858 aMapAIS.Bind (aManipulator, aName);
12862 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12863 if (aManipulator.IsNull())
12865 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12870 // -----------------------------------------
12871 // change properties of manipulator instance
12872 // -----------------------------------------
12874 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
12876 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
12878 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
12880 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
12882 if (aCmd.HasOption ("followRotation", 1, Standard_True))
12884 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
12886 if (aCmd.HasOption("followDragging", 1, Standard_True))
12888 aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging"));
12890 if (aCmd.HasOption ("gap", 1, Standard_True))
12892 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
12894 if (aCmd.HasOption ("part", 3, Standard_True))
12896 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
12897 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
12898 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
12899 if (aMode < 1 || aMode > 4)
12901 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12905 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
12907 if (aCmd.HasOption("parts", 2, Standard_True))
12909 Standard_Integer aMode = aCmd.ArgInt("parts", 0);
12910 Standard_Boolean aOnOff = aCmd.ArgBool("parts", 1);
12911 if (aMode < 1 || aMode > 4)
12913 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12917 aManipulator->SetPart(static_cast<AIS_ManipulatorMode>(aMode), aOnOff);
12919 if (aCmd.HasOption ("pos", 3, Standard_True))
12921 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
12922 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
12923 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
12925 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
12927 if (aCmd.HasOption ("size", 1, Standard_True))
12929 aManipulator->SetSize (aCmd.ArgFloat ("size"));
12931 if (aCmd.HasOption ("zoomable", 1, Standard_True))
12933 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
12935 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
12937 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
12938 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
12942 // ---------------------------------------------------
12943 // attach, detach or access manipulator from an object
12944 // ---------------------------------------------------
12946 if (aCmd.HasOption ("attach"))
12948 // Find an object and attach manipulator to it
12949 if (!aCmd.HasOption ("attach", 1, Standard_True))
12954 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
12955 Handle(AIS_InteractiveObject) anObject;
12956 if (!aMapAIS.Find2 (anObjName, anObject))
12958 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
12962 for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next())
12964 if (anIt.Value()->IsAttached()
12965 && anIt.Value()->Object() == anObject)
12967 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
12972 AIS_Manipulator::OptionsForAttach anOptions;
12973 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
12975 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
12977 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
12979 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
12981 if (aCmd.HasOption ("enableModes", 1, Standard_True))
12983 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
12986 aManipulator->Attach (anObject, anOptions);
12989 // --------------------------------------
12990 // apply transformation using manipulator
12991 // --------------------------------------
12993 if (aCmd.HasOption ("startTransform", 2, Standard_True))
12995 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
12997 if (aCmd.HasOption ("transform", 2, Standard_True))
12999 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
13001 if (aCmd.HasOption ("stopTransform"))
13003 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
13005 aManipulator->StopTransform (toApply);
13009 if (aCmd.HasOption ("move", 3, Standard_True))
13011 aT.SetTranslationPart (aCmd.ArgVec ("move"));
13013 if (aCmd.HasOption ("rotate", 7, Standard_True))
13015 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
13017 if (aCmd.HasOption ("scale", 1))
13019 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
13022 if (aT.Form() != gp_Identity)
13024 aManipulator->Transform (aT);
13027 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
13032 //===============================================================================================
13033 //function : VSelectionProperties
13035 //===============================================================================================
13036 static int VSelectionProperties (Draw_Interpretor& theDi,
13037 Standard_Integer theArgsNb,
13038 const char** theArgVec)
13040 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
13043 std::cerr << "No active viewer!\n";
13047 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
13049 // handle obsolete alias
13050 bool toEnable = true;
13053 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
13056 else if (theArgsNb != 2
13057 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
13059 std::cout << "Syntax error: wrong number of parameters.";
13062 if (toEnable != aCtx->ToHilightSelected())
13064 aCtx->ClearDetected();
13065 aCtx->SetToHilightSelected (toEnable);
13070 Standard_Boolean toPrint = theArgsNb == 1;
13071 Standard_Boolean toRedraw = Standard_False;
13072 Standard_Integer anArgIter = 1;
13073 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
13074 if (anArgIter < theArgsNb)
13076 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
13077 anArgFirst.LowerCase();
13079 if (anArgFirst == "dynhighlight"
13080 || anArgFirst == "dynhilight"
13081 || anArgFirst == "dynamichighlight"
13082 || anArgFirst == "dynamichilight")
13084 aType = Prs3d_TypeOfHighlight_Dynamic;
13086 else if (anArgFirst == "localdynhighlight"
13087 || anArgFirst == "localdynhilight"
13088 || anArgFirst == "localdynamichighlight"
13089 || anArgFirst == "localdynamichilight")
13091 aType = Prs3d_TypeOfHighlight_LocalDynamic;
13093 else if (anArgFirst == "selhighlight"
13094 || anArgFirst == "selhilight"
13095 || anArgFirst == "selectedhighlight"
13096 || anArgFirst == "selectedhilight")
13098 aType = Prs3d_TypeOfHighlight_Selected;
13100 else if (anArgFirst == "localselhighlight"
13101 || anArgFirst == "localselhilight"
13102 || anArgFirst == "localselectedhighlight"
13103 || anArgFirst == "localselectedhilight")
13105 aType = Prs3d_TypeOfHighlight_LocalSelected;
13112 for (; anArgIter < theArgsNb; ++anArgIter)
13114 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13116 if (anArg == "-help")
13118 theDi.PrintHelp (theArgVec[0]);
13121 else if (anArg == "-print")
13123 toPrint = Standard_True;
13125 else if (anArg == "-autoactivate")
13127 Standard_Boolean toEnable = Standard_True;
13128 if (anArgIter + 1 < theArgsNb
13129 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13133 aCtx->SetAutoActivateSelection (toEnable);
13135 else if (anArg == "-automatichighlight"
13136 || anArg == "-automatichilight"
13137 || anArg == "-autohighlight"
13138 || anArg == "-autohilight")
13140 Standard_Boolean toEnable = Standard_True;
13141 if (anArgIter + 1 < theArgsNb
13142 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13146 aCtx->ClearSelected (false);
13147 aCtx->ClearDetected();
13148 aCtx->SetAutomaticHilight (toEnable);
13151 else if (anArg == "-highlightselected"
13152 || anArg == "-hilightselected")
13154 Standard_Boolean toEnable = Standard_True;
13155 if (anArgIter + 1 < theArgsNb
13156 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13160 aCtx->ClearDetected();
13161 aCtx->SetToHilightSelected (toEnable);
13164 else if (anArg == "-pickstrategy"
13165 || anArg == "-pickingstrategy")
13167 if (++anArgIter >= theArgsNb)
13169 std::cout << "Syntax error: type of highlighting is undefined\n";
13173 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
13174 TCollection_AsciiString aVal (theArgVec[anArgIter]);
13176 if (aVal == "first"
13177 || aVal == "firstaccepted"
13178 || aVal == "firstacceptable")
13180 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
13182 else if (aVal == "topmost"
13183 || aVal == "onlyTopmost")
13185 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
13189 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
13193 aCtx->SetPickingStrategy (aStrategy);
13195 else if (anArg == "-pixtol"
13196 && anArgIter + 1 < theArgsNb)
13198 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
13200 else if ((anArg == "-mode"
13201 || anArg == "-dispmode")
13202 && anArgIter + 1 < theArgsNb)
13204 if (aType == Prs3d_TypeOfHighlight_None)
13206 std::cout << "Syntax error: type of highlighting is undefined\n";
13210 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
13211 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13212 aStyle->SetDisplayMode (aDispMode);
13213 toRedraw = Standard_True;
13215 else if (anArg == "-layer"
13216 && anArgIter + 1 < theArgsNb)
13218 if (aType == Prs3d_TypeOfHighlight_None)
13220 std::cout << "Syntax error: type of highlighting is undefined\n";
13225 Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN;
13226 if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer))
13228 std::cerr << "Error: wrong syntax at " << theArgVec[anArgIter] << ".\n";
13232 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13233 aStyle->SetZLayer (aNewLayer);
13234 toRedraw = Standard_True;
13236 else if (anArg == "-hicolor"
13237 || anArg == "-selcolor"
13238 || anArg == "-color")
13240 if (anArg.StartsWith ("-hi"))
13242 aType = Prs3d_TypeOfHighlight_Dynamic;
13244 else if (anArg.StartsWith ("-sel"))
13246 aType = Prs3d_TypeOfHighlight_Selected;
13248 else if (aType == Prs3d_TypeOfHighlight_None)
13250 std::cout << "Syntax error: type of highlighting is undefined\n";
13254 Quantity_Color aColor;
13255 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
13256 theArgVec + anArgIter + 1,
13258 if (aNbParsed == 0)
13260 std::cout << "Syntax error: need more arguments.\n";
13263 anArgIter += aNbParsed;
13265 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13266 aStyle->SetColor (aColor);
13267 toRedraw = Standard_True;
13269 else if ((anArg == "-transp"
13270 || anArg == "-transparency"
13271 || anArg == "-hitransp"
13272 || anArg == "-seltransp"
13273 || anArg == "-hitransplocal"
13274 || anArg == "-seltransplocal")
13275 && anArgIter + 1 < theArgsNb)
13277 if (anArg.StartsWith ("-hi"))
13279 aType = Prs3d_TypeOfHighlight_Dynamic;
13281 else if (anArg.StartsWith ("-sel"))
13283 aType = Prs3d_TypeOfHighlight_Selected;
13285 else if (aType == Prs3d_TypeOfHighlight_None)
13287 std::cout << "Syntax error: type of highlighting is undefined\n";
13291 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
13292 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13293 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
13294 toRedraw = Standard_True;
13296 else if ((anArg == "-mat"
13297 || anArg == "-material")
13298 && anArgIter + 1 < theArgsNb)
13300 if (aType == Prs3d_TypeOfHighlight_None)
13302 std::cout << "Syntax error: type of highlighting is undefined\n";
13306 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13307 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
13308 if (aMatName != Graphic3d_NOM_DEFAULT)
13311 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
13312 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
13313 Graphic3d_MaterialAspect aMat (aMatName);
13314 aMat.SetColor (aStyle->Color());
13315 aMat.SetTransparency (aStyle->Transparency());
13316 anAspect->SetFrontMaterial (aMat);
13317 anAspect->SetInteriorColor (aStyle->Color());
13318 aStyle->SetBasicFillAreaAspect (anAspect);
13322 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
13324 toRedraw = Standard_True;
13328 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
13334 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
13335 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
13336 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
13337 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
13338 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
13339 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
13340 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
13341 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
13342 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
13343 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
13344 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
13345 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
13346 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
13347 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
13350 if (aCtx->NbSelected() != 0 && toRedraw)
13352 aCtx->HilightSelected (Standard_True);
13358 //===============================================================================================
13359 //function : VDumpSelectionImage
13361 //===============================================================================================
13362 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
13363 Standard_Integer theArgsNb,
13364 const char** theArgVec)
13368 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
13372 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13373 if (aContext.IsNull())
13375 std::cout << "Error: no active view.\n";
13379 TCollection_AsciiString aFile;
13380 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13381 Image_Format anImgFormat = Image_Format_BGR;
13382 Standard_Integer aPickedIndex = 1;
13383 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
13385 TCollection_AsciiString aParam (theArgVec[anArgIter]);
13386 aParam.LowerCase();
13387 if (aParam == "-type")
13389 if (++anArgIter >= theArgsNb)
13391 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
13395 TCollection_AsciiString aValue (theArgVec[anArgIter]);
13396 aValue.LowerCase();
13397 if (aValue == "depth"
13398 || aValue == "normdepth"
13399 || aValue == "normalizeddepth")
13401 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13402 anImgFormat = Image_Format_GrayF;
13404 if (aValue == "depthinverted"
13405 || aValue == "normdepthinverted"
13406 || aValue == "normalizeddepthinverted"
13407 || aValue == "inverted")
13409 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
13410 anImgFormat = Image_Format_GrayF;
13412 else if (aValue == "unnormdepth"
13413 || aValue == "unnormalizeddepth")
13415 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
13416 anImgFormat = Image_Format_GrayF;
13418 else if (aValue == "objectcolor"
13419 || aValue == "object"
13420 || aValue == "color")
13422 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
13424 else if (aValue == "entitycolor"
13425 || aValue == "entity")
13427 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
13429 else if (aValue == "ownercolor"
13430 || aValue == "owner")
13432 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
13434 else if (aValue == "selectionmodecolor"
13435 || aValue == "selectionmode"
13436 || aValue == "selmodecolor"
13437 || aValue == "selmode")
13439 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
13442 else if (aParam == "-picked"
13443 || aParam == "-pickeddepth"
13444 || aParam == "-pickedindex")
13446 if (++anArgIter >= theArgsNb)
13448 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
13452 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
13454 else if (aFile.IsEmpty())
13456 aFile = theArgVec[anArgIter];
13460 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
13464 if (aFile.IsEmpty())
13466 std::cout << "Syntax error: image file name is missing.\n";
13470 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13471 Standard_Integer aWidth = 0, aHeight = 0;
13472 aView->Window()->Size (aWidth, aHeight);
13474 Image_AlienPixMap aPixMap;
13475 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
13477 std::cout << "Error: can't allocate image.\n";
13480 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
13482 std::cout << "Error: can't generate selection image.\n";
13485 if (!aPixMap.Save (aFile))
13487 std::cout << "Error: can't save selection image.\n";
13493 //=======================================================================
13494 //function : ViewerCommands
13496 //=======================================================================
13498 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
13501 const char *group = "ZeViewer";
13502 theCommands.Add("vinit",
13503 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
13504 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
13505 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13506 "\n\t\t: [-display displayName]"
13508 "\n\t\t: Creates new View window with specified name viewName."
13509 "\n\t\t: By default the new view is created in the viewer and in"
13510 "\n\t\t: graphic driver shared with active view."
13511 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
13512 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
13513 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
13514 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13515 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
13516 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
13518 "\n\t\t: -left, -top pixel position of left top corner of the window."
13519 "\n\t\t: -width, -height width and heigth of window respectively."
13520 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
13521 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
13522 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
13523 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
13524 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
13525 __FILE__,VInit,group);
13526 theCommands.Add("vclose" ,
13527 "[view_id [keep_context=0|1]]\n"
13528 "or vclose ALL - to remove all created views\n"
13529 " - removes view(viewer window) defined by its view_id.\n"
13530 " - keep_context: by default 0; if 1 and the last view is deleted"
13531 " the current context is not removed.",
13532 __FILE__,VClose,group);
13533 theCommands.Add("vactivate" ,
13534 "vactivate view_id [-noUpdate]"
13535 " - activates view(viewer window) defined by its view_id",
13536 __FILE__,VActivate,group);
13537 theCommands.Add("vviewlist",
13538 "vviewlist [format={tree, long}]"
13539 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
13540 " - format: format of result output, if tree the output is a tree view;"
13541 "otherwise it's a list of full view names. By default format = tree",
13542 __FILE__,VViewList,group);
13543 theCommands.Add("vhelp" ,
13544 "vhelp : display help on the viewer commands",
13545 __FILE__,VHelp,group);
13546 theCommands.Add("vtop" ,
13547 "vtop or <T> : Top view. Orientation +X+Y" ,
13548 __FILE__,VTop,group);
13549 theCommands.Add("vbottom" ,
13550 "vbottom : Bottom view. Orientation +X-Y" ,
13551 __FILE__,VBottom,group);
13552 theCommands.Add("vleft" ,
13553 "vleft : Left view. Orientation -Y+Z" ,
13554 __FILE__,VLeft,group);
13555 theCommands.Add("vright" ,
13556 "vright : Right view. Orientation +Y+Z" ,
13557 __FILE__,VRight,group);
13558 theCommands.Add("vaxo" ,
13559 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
13560 __FILE__,VAxo,group);
13561 theCommands.Add("vfront" ,
13562 "vfront : Front view. Orientation +X+Z" ,
13563 __FILE__,VFront,group);
13564 theCommands.Add("vback" ,
13565 "vback : Back view. Orientation -X+Z" ,
13566 __FILE__,VBack,group);
13567 theCommands.Add("vpick" ,
13568 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
13570 theCommands.Add("vfit",
13571 "vfit or <F> [-selected] [-noupdate]"
13572 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
13573 __FILE__,VFit,group);
13574 theCommands.Add ("vfitarea",
13575 "vfitarea x1 y1 x2 y2"
13576 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
13577 "\n\t\t: Fit view to show area located between two points"
13578 "\n\t\t: given in world 2D or 3D corrdinates.",
13579 __FILE__, VFitArea, group);
13580 theCommands.Add ("vzfit", "vzfit [scale]\n"
13581 " Matches Z near, Z far view volume planes to the displayed objects.\n"
13582 " \"scale\" - specifies factor to scale computed z range.\n",
13583 __FILE__, VZFit, group);
13584 theCommands.Add("vrepaint",
13585 "vrepaint [-immediate] [-continuous FPS]"
13586 "\n\t\t: force redraw of active View"
13587 "\n\t\t: -immediate flag performs redraw of immediate layers only;"
13588 "\n\t\t: -continuous activates/deactivates continuous redraw of active View,"
13589 "\n\t\t: 0 means no continuous rendering,"
13590 "\n\t\t: -1 means non-stop redraws,"
13591 "\n\t\t: >0 specifies target framerate,",
13592 __FILE__,VRepaint,group);
13593 theCommands.Add("vclear",
13595 "\n\t\t: remove all the object from the viewer",
13596 __FILE__,VClear,group);
13599 "Changes background or some background settings.\n"
13602 " vbackground -imageFile ImageFile [-imageMode FillType]\n"
13603 " vbackground -imageMode FillType\n"
13604 " vbackground -gradient Color1 Color2 [-gradientMode FillMethod]\n"
13605 " vbackground -gradientMode FillMethod\n"
13606 " vbackground -color Color\n"
13607 " vbackground -default -gradient Color1 Color2 [-gradientMode FillType]\n"
13608 " vbackground -default -color Color\n"
13609 " vbackground -help\n"
13612 " -imageFile (-imgFile, -image, -img): sets filename of image used as background\n"
13613 " -imageMode (-imgMode, -imageMd, -imgMd): sets image fill type\n"
13614 " -gradient (-grad, -gr): sets background gradient starting and ending colors\n"
13615 " -gradientMode (-gradMode, -gradMd, -grMode, -grMd): sets gradient fill method\n"
13616 " -color (-col): sets background color\n"
13617 " -default (-def): sets background default gradient or color\n"
13618 " -help (-h): outputs short help message\n"
13621 " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n"
13622 " or reals within the range [0.0, 1.0]\n"
13623 " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n"
13624 " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n"
13625 " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, "
13627 " FillType: one of CENTERED, TILED, STRETCH, NONE\n"
13628 " ImageFile: a name of the file with the image used as a background\n",
13632 theCommands.Add ("vsetbg",
13633 "Loads image as background."
13634 "\n\t\t: vsetbg ImageFile [FillType]"
13635 "\n\t\t: vsetbg -imageFile ImageFile [-imageMode FillType]"
13636 "\n\t\t: Alias for 'vbackground -imageFile ImageFile [-imageMode FillType]'.",
13640 theCommands.Add ("vsetbgmode",
13641 "Changes background image fill type."
13642 "\n\t\t: vsetbgmode [-imageMode] FillType"
13643 "\n\t\t: Alias for 'vbackground -imageMode FillType'.",
13647 theCommands.Add ("vsetgradientbg",
13648 "Mounts gradient background."
13649 "\n\t\t: vsetgradientbg Color1 Color2 [FillMethod]"
13650 "\n\t\t: vsetgradientbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13651 "\n\t\t: Alias for 'vbackground -gradient Color1 Color2 -gradientMode FillMethod'.",
13655 theCommands.Add ("vsetgrbgmode",
13656 "Changes gradient background fill method."
13657 "\n\t\t: vsetgrbgmode [-gradientMode] FillMethod"
13658 "\n\t\t: Alias for 'vbackground -gradientMode FillMethod'.",
13662 theCommands.Add ("vsetcolorbg",
13663 "Sets background color."
13664 "\n\t\t: vsetcolorbg [-color] Color."
13665 "\n\t\t: Alias for 'vbackground -color Color'.",
13669 theCommands.Add ("vsetdefaultbg",
13670 "Sets default viewer background fill color (flat/gradient)."
13671 "\n\t\t: vsetdefaultbg Color1 Color2 [FillMethod]"
13672 "\n\t\t: vsetdefaultbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13673 "\n\t\t: Alias for 'vbackground -default -gradient Color1 Color2 [-gradientMode FillMethod]'."
13674 "\n\t\t: vsetdefaultbg [-color] Color"
13675 "\n\t\t: Alias for 'vbackground -default -color Color'.",
13679 theCommands.Add("vscale",
13680 "vscale : vscale X Y Z",
13681 __FILE__,VScale,group);
13682 theCommands.Add("vzbufftrihedron",
13683 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
13684 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
13685 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
13686 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
13687 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
13688 "\n\t\t: Displays a trihedron",
13689 __FILE__,VZBuffTrihedron,group);
13690 theCommands.Add("vrotate",
13691 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
13692 "\n : Option -mouseStart starts rotation according to the mouse position"
13693 "\n : Option -mouseMove continues rotation with angle computed"
13694 "\n : from last and new mouse position."
13695 "\n : vrotate AX AY AZ [X Y Z]",
13696 __FILE__,VRotate,group);
13697 theCommands.Add("vzoom",
13698 "vzoom : vzoom coef",
13699 __FILE__,VZoom,group);
13700 theCommands.Add("vpan",
13701 "vpan : vpan dx dy",
13702 __FILE__,VPan,group);
13703 theCommands.Add("vcolorscale",
13704 "vcolorscale name [-noupdate|-update] [-demo]"
13705 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
13706 "\n\t\t: [-font HeightFont=20]"
13707 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
13708 "\n\t\t: [-smoothTransition {on|off}=off]"
13709 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
13710 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
13711 "\n\t\t: [-textpos {left|right|center|none}=right]"
13712 "\n\t\t: [-labelAtBorder {on|off}=on]"
13713 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
13714 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
13715 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
13716 "\n\t\t: [-xy Left=0 Bottom=0]"
13717 "\n\t\t: -demo - displays a color scale with demonstratio values"
13718 "\n\t\t: -colors - set colors for all intervals"
13719 "\n\t\t: -color - set color for specific interval"
13720 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
13721 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
13722 "\n\t\t: at border means the value inbetween neighbor intervals,"
13723 "\n\t\t: at center means the center value within current interval"
13724 "\n\t\t: -labels - set labels for all intervals"
13725 "\n\t\t: -freeLabels - same as -labels but does not require"
13726 "\n\t\t: matching the number of intervals"
13727 "\n\t\t: -label - set label for specific interval"
13728 "\n\t\t: -title - set title"
13729 "\n\t\t: -reversed - setup smooth color transition between intervals"
13730 "\n\t\t: -smoothTransition - swap colorscale direction"
13731 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
13732 __FILE__, VColorScale, group);
13733 theCommands.Add("vgraduatedtrihedron",
13734 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
13735 "\t[-namefont Name] [-valuesfont Name]\n"
13736 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
13737 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
13738 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
13739 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
13740 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
13741 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
13742 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
13743 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
13744 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
13745 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
13746 " - Displays or erases graduated trihedron"
13747 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
13748 " - namefont - font of axes names. Default: Arial\n"
13749 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
13750 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
13751 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
13752 " - valuesfont - font of axes values. Default: Arial\n"
13753 " - xcolor, ycolor, zcolor - color of axis and values\n"
13754 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
13755 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
13756 __FILE__,VGraduatedTrihedron,group);
13757 theCommands.Add("vtile" ,
13758 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
13759 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
13760 "\n\t\t: -totalSize the size of virtual bigger viewport"
13761 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
13762 "\n\t\t: -lowerLeft tile offset as lower left corner"
13763 "\n\t\t: -upperLeft tile offset as upper left corner",
13764 __FILE__, VTile, group);
13765 theCommands.Add("vzlayer",
13766 "vzlayer [layerId]"
13767 "\n\t\t: [-add|-delete|-get|-settings]"
13768 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
13769 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
13770 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
13771 "\n\t\t: ZLayer list management:"
13772 "\n\t\t: -add add new z layer to viewer and print its id"
13773 "\n\t\t: -delete delete z layer"
13774 "\n\t\t: -get print sequence of z layers"
13775 "\n\t\t: -settings print status of z layer settings"
13776 "\n\t\t: -disable disables given setting"
13777 "\n\t\t: -enable enables given setting",
13778 __FILE__,VZLayer,group);
13779 theCommands.Add("vlayerline",
13780 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
13781 __FILE__,VLayerLine,group);
13782 theCommands.Add("vgrid",
13783 "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]"
13784 "\n\t\t: [-step X Y] [-size DX DY]"
13785 "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]",
13786 __FILE__, VGrid, group);
13787 theCommands.Add ("vpriviledgedplane",
13788 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
13789 "\n\t\t: Ox, Oy, Oz - plane origin"
13790 "\n\t\t: Nx, Ny, Nz - plane normal direction"
13791 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
13792 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
13793 __FILE__, VPriviledgedPlane, group);
13794 theCommands.Add ("vconvert",
13795 "vconvert v [Mode={window|view}]"
13796 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
13797 "\n\t\t: vconvert x y z [Mode={window|grid}]"
13798 "\n\t\t: window - convert to window coordinates, pixels"
13799 "\n\t\t: view - convert to view projection plane"
13800 "\n\t\t: grid - convert to model coordinates, given on grid"
13801 "\n\t\t: ray - convert projection ray to model coordiantes"
13802 "\n\t\t: - vconvert v window : convert view to window;"
13803 "\n\t\t: - vconvert v view : convert window to view;"
13804 "\n\t\t: - vconvert x y window : convert view to window;"
13805 "\n\t\t: - vconvert x y view : convert window to view;"
13806 "\n\t\t: - vconvert x y : convert window to model;"
13807 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
13808 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
13809 "\n\t\t: - vconvert x y z window : convert model to window;"
13810 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
13811 "\n\t\t: Converts the given coordinates to window/view/model space.",
13812 __FILE__, VConvert, group);
13813 theCommands.Add ("vfps",
13814 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
13815 __FILE__, VFps, group);
13816 theCommands.Add ("vgldebug",
13817 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
13818 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
13819 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
13820 "\n\t\t: Debug context can be requested only on Windows"
13821 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
13822 "\n\t\t: -sync - request synchronized debug GL context"
13823 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
13824 "\n\t\t: which are suppressed by default,"
13825 "\n\t\t: -glslCode - log GLSL program source code,"
13826 "\n\t\t: which are suppressed by default,"
13827 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
13828 "\n\t\t: which are suppressed by default",
13829 __FILE__, VGlDebug, group);
13830 theCommands.Add ("vvbo",
13831 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
13832 __FILE__, VVbo, group);
13833 theCommands.Add ("vstereo",
13834 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
13835 "\n\t\t: [-anaglyph Filter]"
13836 "\n\t\t: Control stereo output mode. Available modes for -mode:"
13837 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
13838 "\n\t\t: requires driver support."
13839 "\n\t\t: Should be called BEFORE vinit!"
13840 "\n\t\t: anaglyph - Anaglyph glasses"
13841 "\n\t\t: rowInterlaced - row-interlaced display"
13842 "\n\t\t: columnInterlaced - column-interlaced display"
13843 "\n\t\t: chessBoard - chess-board output"
13844 "\n\t\t: sideBySide - horizontal pair"
13845 "\n\t\t: overUnder - vertical pair"
13846 "\n\t\t: Available Anaglyph filters for -anaglyph:"
13847 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
13848 "\n\t\t: greenMagentaSimple",
13849 __FILE__, VStereo, group);
13850 theCommands.Add ("vcaps",
13851 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
13852 "\n\t\t: [-compatibleProfile {0|1}]"
13853 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
13854 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
13855 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
13856 "\n\t\t: Modify particular graphic driver options:"
13857 "\n\t\t: FFP - use fixed-function pipeline instead of"
13858 "\n\t\t: built-in GLSL programs"
13859 "\n\t\t: (requires compatible profile)"
13860 "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs"
13861 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
13862 "\n\t\t: arrays to GPU memory)"
13863 "\n\t\t: sprite - use textured sprites instead of bitmaps"
13864 "\n\t\t: vsync - switch VSync on or off"
13865 "\n\t\t: winBuffer - allow using window buffer for rendering"
13866 "\n\t\t: Context creation options:"
13867 "\n\t\t: softMode - software OpenGL implementation"
13868 "\n\t\t: compatibleProfile - backward-compatible profile"
13869 "\n\t\t: quadbuffer - QuadBuffer"
13870 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
13871 "\n\t\t: rendering paths producing the same visual result when"
13872 "\n\t\t: possible."
13873 "\n\t\t: Command is intended for testing old hardware compatibility.",
13874 __FILE__, VCaps, group);
13875 theCommands.Add ("vmemgpu",
13876 "vmemgpu [f]: print system-dependent GPU memory information if available;"
13877 " with f option returns free memory in bytes",
13878 __FILE__, VMemGpu, group);
13879 theCommands.Add ("vreadpixel",
13880 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [-name]"
13881 " : Read pixel value for active view",
13882 __FILE__, VReadPixel, group);
13883 theCommands.Add("diffimage",
13884 "diffimage imageFile1 imageFile2 [diffImageFile]"
13885 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
13886 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
13887 "\n\t\t: Compare two images by content and generate difference image."
13888 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
13889 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
13890 __FILE__, VDiffImage, group);
13891 theCommands.Add ("vselect",
13892 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
13893 "- emulates different types of selection:\n"
13894 "- 1) single click selection\n"
13895 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
13896 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
13897 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
13898 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
13899 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
13900 " (partial inclusion - overlap - is not allowed by default)\n"
13901 "- 5) any of these selections with shift button pressed",
13902 __FILE__, VSelect, group);
13903 theCommands.Add ("vmoveto",
13904 "vmoveto [x y] [-reset]"
13905 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
13906 "\n\t\t: -reset resets current highlighting",
13907 __FILE__, VMoveTo, group);
13908 theCommands.Add ("vviewparams",
13909 "vviewparams [-args] [-scale [s]]"
13910 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
13911 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
13912 "\n\t\t: Manage current view parameters or prints all"
13913 "\n\t\t: current values when called without argument."
13914 "\n\t\t: -scale [s] prints or sets viewport relative scale"
13915 "\n\t\t: -eye [x y z] prints or sets eye location"
13916 "\n\t\t: -at [x y z] prints or sets center of look"
13917 "\n\t\t: -up [x y z] prints or sets direction of up vector"
13918 "\n\t\t: -proj [x y z] prints or sets direction of look"
13919 "\n\t\t: -center x y sets location of center of the screen in pixels"
13920 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
13921 "\n\t\t: or changes the size of its maximum dimension"
13922 "\n\t\t: -args prints vviewparams arguments for restoring current view",
13923 __FILE__, VViewParams, group);
13925 theCommands.Add("v2dmode",
13926 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
13927 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
13928 "\n\t\t: mode - switches On/Off rotation mode"
13929 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
13930 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
13931 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
13932 "\n\t\t: View camera position might be changed only by commands.",
13933 __FILE__, V2DMode, group);
13935 theCommands.Add("vanimation", "Alias for vanim",
13936 __FILE__, VAnimation, group);
13938 theCommands.Add("vanim",
13939 "List existing animations:"
13941 "\n\t\t: Animation playback:"
13942 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
13943 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
13944 "\n\t\t: -speed playback speed (1.0 is normal speed)"
13945 "\n\t\t: -freeLook skip camera animations"
13946 "\n\t\t: -lockLoop disable any interactions"
13948 "\n\t\t: Animation definition:"
13949 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
13950 "\n\t\t: [start TimeSec] [duration TimeSec]"
13952 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
13953 "\n\t\t: specifies nested animations."
13954 "\n\t\t: There is no syntax to explicitly add new animation,"
13955 "\n\t\t: and all non-existing animations within the name will be"
13956 "\n\t\t: implicitly created on first use (including parents)."
13958 "\n\t\t: Each animation might define the SINGLE action (see below),"
13959 "\n\t\t: like camera transition, object transformation or custom callback."
13960 "\n\t\t: Child animations can be used for defining concurrent actions."
13962 "\n\t\t: Camera animation:"
13963 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
13964 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
13965 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
13966 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
13967 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
13968 "\n\t\t: -atX camera Center positions pair"
13969 "\n\t\t: -upX camera Up directions pair"
13970 "\n\t\t: -scaleX camera Scale factors pair"
13971 "\n\t\t: Object animation:"
13972 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
13973 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
13974 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
13975 "\n\t\t: -locX object Location points pair (translation)"
13976 "\n\t\t: -rotX object Orientations pair (quaternions)"
13977 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
13978 "\n\t\t: Custom callback:"
13979 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
13980 "\n\t\t: %Pts overall animation presentation timestamp"
13981 "\n\t\t: %LocalPts local animation timestamp"
13982 "\n\t\t: %Normalized local animation normalized value in range 0..1"
13984 "\n\t\t: Video recording:"
13985 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
13986 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
13987 "\n\t\t: [-crf Value] [-preset Preset]"
13988 "\n\t\t: -fps video framerate"
13989 "\n\t\t: -format file format, container (matroska, etc.)"
13990 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
13991 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
13992 "\n\t\t: -crf constant rate factor (specific to codec)"
13993 "\n\t\t: -preset codec parameters preset (specific to codec)"
13994 __FILE__, VAnimation, group);
13996 theCommands.Add("vchangeselected",
13997 "vchangeselected shape"
13998 "- adds to shape to selection or remove one from it",
13999 __FILE__, VChangeSelected, group);
14000 theCommands.Add ("vnbselected",
14002 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
14003 theCommands.Add ("vcamera",
14004 "vcamera [PrsName] [-ortho] [-projtype]"
14006 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
14007 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
14008 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
14009 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
14010 "\n\t\t: Manages camera parameters."
14011 "\n\t\t: Displays frustum when presntation name PrsName is specified."
14012 "\n\t\t: Prints current value when option called without argument."
14013 "\n\t\t: Orthographic camera:"
14014 "\n\t\t: -ortho activate orthographic projection"
14015 "\n\t\t: Perspective camera:"
14016 "\n\t\t: -persp activate perspective projection (mono)"
14017 "\n\t\t: -fovy field of view in y axis, in degrees"
14018 "\n\t\t: -distance distance of eye from camera center"
14019 "\n\t\t: Stereoscopic camera:"
14020 "\n\t\t: -stereo perspective projection (stereo)"
14021 "\n\t\t: -leftEye perspective projection (left eye)"
14022 "\n\t\t: -rightEye perspective projection (right eye)"
14023 "\n\t\t: -iod intraocular distance value"
14024 "\n\t\t: -iodType distance type, absolute or relative"
14025 "\n\t\t: -zfocus stereographic focus value"
14026 "\n\t\t: -zfocusType focus type, absolute or relative",
14027 __FILE__, VCamera, group);
14028 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
14029 "- vautozfit [on={1|0}] [scale]\n"
14030 " Prints or changes parameters of automatic z-fit mode:\n"
14031 " \"on\" - turns automatic z-fit on or off\n"
14032 " \"scale\" - specifies factor to scale computed z range.\n",
14033 __FILE__, VAutoZFit, group);
14034 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
14035 " vzrange - without parameters shows current values\n"
14036 " vzrange [znear] [zfar] - applies provided values to view",
14037 __FILE__,VZRange, group);
14038 theCommands.Add ("vpurgedisplay",
14040 "- removes structures which don't belong to objects displayed in neutral point",
14041 __FILE__, VPurgeDisplay, group);
14042 theCommands.Add("vsetviewsize",
14043 "vsetviewsize size",
14044 __FILE__,VSetViewSize,group);
14045 theCommands.Add("vmoveview",
14046 "vmoveview Dx Dy Dz [Start = 1|0]",
14047 __FILE__,VMoveView,group);
14048 theCommands.Add("vtranslateview",
14049 "vtranslateview Dx Dy Dz [Start = 1|0)]",
14050 __FILE__,VTranslateView,group);
14051 theCommands.Add("vturnview",
14052 "vturnview Ax Ay Az [Start = 1|0]",
14053 __FILE__,VTurnView,group);
14054 theCommands.Add("vtextureenv",
14055 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
14056 "or user-defined file and optionally applying texture mapping parameters\n"
14058 " vtextureenv off - disables environment mapping\n"
14059 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
14060 " std_texture = (0..7)\n"
14061 " rep = {clamp|repeat}\n"
14062 " mod = {decal|modulate}\n"
14063 " flt = {nearest|bilinear|trilinear}\n"
14064 " ss, st - scale factors for s and t texture coordinates\n"
14065 " ts, tt - translation for s and t texture coordinates\n"
14066 " rot - texture rotation angle in degrees",
14067 __FILE__, VTextureEnv, group);
14068 theCommands.Add("vhlr",
14069 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
14070 "\n\t\t: Hidden Line Removal algorithm."
14071 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
14072 "\n\t\t: -algoType type of HLR algorithm.\n",
14073 __FILE__,VHLR,group);
14074 theCommands.Add("vhlrtype",
14075 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
14076 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
14077 "\n\t\t: 'algo' - exact HLR algorithm is applied"
14078 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
14079 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
14080 __FILE__,VHLRType,group);
14081 theCommands.Add("vclipplane",
14082 "vclipplane planeName [{0|1}]"
14083 "\n\t\t: [-equation1 A B C D]"
14084 "\n\t\t: [-equation2 A B C D]"
14085 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
14086 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
14087 "\n\t\t: [-maxPlanes]"
14088 "\n\t\t: [-capping {0|1}]"
14089 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
14090 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
14091 "\n\t\t: [-texRotate Angle]"
14092 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
14093 "\n\t\t: [-useObjShader {0|1}]"
14094 "\n\t\t: Clipping planes management:"
14095 "\n\t\t: -maxPlanes print plane limit for view"
14096 "\n\t\t: -delete delete plane with given name"
14097 "\n\t\t: {off|on|0|1} turn clipping on/off"
14098 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
14099 "\n\t\t: applied to active View when list is omitted"
14100 "\n\t\t: -equation A B C D change plane equation"
14101 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
14102 "\n\t\t: Capping options:"
14103 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
14104 "\n\t\t: -color R G B set capping color"
14105 "\n\t\t: -transparency Value set capping transparency 0..1"
14106 "\n\t\t: -texName Texture set capping texture"
14107 "\n\t\t: -texScale SX SY set capping tex scale"
14108 "\n\t\t: -texOrigin TX TY set capping tex origin"
14109 "\n\t\t: -texRotate Angle set capping tex rotation"
14110 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
14111 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
14112 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
14113 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
14114 __FILE__, VClipPlane, group);
14115 theCommands.Add("vdefaults",
14116 "vdefaults [-absDefl value]"
14117 "\n\t\t: [-devCoeff value]"
14118 "\n\t\t: [-angDefl value]"
14119 "\n\t\t: [-autoTriang {off/on | 0/1}]"
14120 , __FILE__, VDefaults, group);
14121 theCommands.Add("vlight",
14122 "tool to manage light sources, without arguments shows list of lights."
14123 "\n Main commands: "
14124 "\n '-clear' to clear lights"
14125 "\n '-{def}aults' to load deafault lights"
14126 "\n '-add' <type> to add any light source"
14127 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
14128 "\n 'change' <lightId> to edit light source with specified lightId"
14129 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
14131 "\n -{pos}ition X Y Z"
14132 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
14133 "\n -color colorName"
14134 "\n -{head}light 0|1"
14135 "\n -{sm}oothness value"
14136 "\n -{int}ensity value"
14137 "\n -{constAtten}uation value"
14138 "\n -{linearAtten}uation value"
14139 "\n -angle angleDeg"
14140 "\n -{spotexp}onent value"
14141 "\n -local|-global"
14142 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
14143 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
14144 __FILE__, VLight, group);
14145 theCommands.Add("vraytrace",
14147 "\n\t\t: Turns on/off ray-tracing renderer."
14148 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
14149 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
14150 __FILE__, VRenderParams, group);
14151 theCommands.Add("vrenderparams",
14152 "\n Manages rendering parameters: "
14153 "\n '-raster' Disables GPU ray-tracing"
14154 "\n '-msaa 0..4' Specifies number of samples for MSAA"
14155 "\n '-lineFeather > 0' Sets line feather factor"
14156 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
14157 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
14158 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
14159 "\n '-rendScale value Rendering resolution scale factor"
14160 "\n '-rayTrace' Enables GPU ray-tracing"
14161 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
14162 "\n '-shadows on|off' Enables/disables shadows rendering"
14163 "\n '-reflections on|off' Enables/disables specular reflections"
14164 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
14165 "\n '-gleam on|off' Enables/disables transparency shadow effects"
14166 "\n '-gi on|off' Enables/disables global illumination effects"
14167 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
14168 "\n '-env on|off' Enables/disables environment map background"
14169 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
14170 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
14171 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
14172 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
14173 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
14174 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
14175 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
14176 "\n '-shadingModel model' Controls shading model from enumeration"
14177 "\n color, flat, gouraud, phong"
14178 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
14179 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
14180 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
14181 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
14182 "\n '-whitepoint value' White point value for filmic tone mapping"
14183 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
14184 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points"
14185 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
14186 "\n Show/hide performance counters (flags can be combined)"
14187 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
14188 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
14189 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
14190 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
14191 "\n set state to check structures culled previously."
14192 "\n Unlike vcaps, these parameters dramatically change visual properties."
14193 "\n Command is intended to control presentation quality depending on"
14194 "\n hardware capabilities and performance.",
14195 __FILE__, VRenderParams, group);
14196 theCommands.Add("vstatprofiler",
14197 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
14198 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
14199 "\n |triagles|points|geomMem|textureMem|frameMem"
14200 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
14201 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
14203 "\n\t\t: Prints rendering statistics."
14204 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
14205 "\n\t\t: else - print all performance counters set previously."
14206 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
14207 __FILE__, VStatProfiler, group);
14208 theCommands.Add ("vplace",
14210 "\n\t\t: Places the point (in pixels) at the center of the window",
14211 __FILE__, VPlace, group);
14212 theCommands.Add("vxrotate",
14214 __FILE__,VXRotate,group);
14216 theCommands.Add("vmanipulator",
14217 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
14218 "\n tool to create and manage AIS manipulators."
14220 "\n '-attach AISObject' attach manipulator to AISObject"
14221 "\n '-adjustPosition {0|1}' adjust position when attaching"
14222 "\n '-adjustSize {0|1}' adjust size when attaching"
14223 "\n '-enableModes {0|1}' enable modes when attaching"
14224 "\n '-detach' detach manipulator"
14225 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
14226 "\n '-transform mouse_x mouse_y' - invoke transformation"
14227 "\n '-stopTransform [abort]' - invoke stop of transformation"
14228 "\n '-move x y z' - move attached object"
14229 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
14230 "\n '-scale factor' - scale attached object"
14231 "\n '-autoActivate {0|1}' - set activation on detection"
14232 "\n '-followTranslation {0|1}' - set following translation transform"
14233 "\n '-followRotation {0|1}' - set following rotation transform"
14234 "\n '-followDragging {0|1}' - set following dragging transform"
14235 "\n '-gap value' - set gap between sub-parts"
14236 "\n '-part axis mode {0|1}' - set visual part"
14237 "\n '-parts axis mode {0|1}' - set visual part"
14238 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
14239 "\n '-size value' - set size of manipulator"
14240 "\n '-zoomable {0|1}' - set zoom persistence",
14241 __FILE__, VManipulator, group);
14243 theCommands.Add("vselprops",
14244 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
14245 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
14246 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
14247 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
14248 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
14249 "\n -pickStrategy {first|topmost} : defines picking strategy"
14250 "\n 'first' to pick first acceptable (default)"
14251 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
14252 "\n -pixTol value : sets up pixel tolerance"
14253 "\n -dispMode dispMode : sets display mode for highlighting"
14254 "\n -layer ZLayer : sets ZLayer for highlighting"
14255 "\n -color {name|r g b} : sets highlight color"
14256 "\n -transp value : sets transparency coefficient for highlight"
14257 "\n -material material : sets highlight material"
14258 "\n -print : prints current state of all mentioned parameters",
14259 __FILE__, VSelectionProperties, group);
14260 theCommands.Add ("vhighlightselected",
14261 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
14262 __FILE__, VSelectionProperties, group);
14264 theCommands.Add ("vseldump",
14265 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
14266 "\n\t\t: Generate an image based on detection results:"
14267 "\n\t\t: depth normalized depth values"
14268 "\n\t\t: unnormDepth unnormalized depth values"
14269 "\n\t\t: object color of detected object"
14270 "\n\t\t: owner color of detected owner"
14271 "\n\t\t: selMode color of selection mode"
14272 "\n\t\t: entity color of etected entity",
14273 __FILE__, VDumpSelectionImage, group);
14275 #if defined(_WIN32)
14276 theCommands.Add("vprogressive",
14278 __FILE__, VProgressiveMode, group);