1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <OpenGl_GlCore20.hxx>
18 #include <ViewerTest.hxx>
20 #include <AIS_AnimationCamera.hxx>
21 #include <AIS_AnimationObject.hxx>
22 #include <AIS_CameraFrustum.hxx>
23 #include <AIS_ColorScale.hxx>
24 #include <AIS_InteractiveContext.hxx>
25 #include <AIS_ListOfInteractive.hxx>
26 #include <AIS_ListIteratorOfListOfInteractive.hxx>
27 #include <AIS_Manipulator.hxx>
28 #include <AIS_ViewCube.hxx>
29 #include <AIS_Shape.hxx>
30 #include <Aspect_DisplayConnection.hxx>
31 #include <Aspect_Grid.hxx>
32 #include <Aspect_TypeOfLine.hxx>
34 #include <Draw_Appli.hxx>
35 #include <Draw_Interpretor.hxx>
36 #include <Draw_ProgressIndicator.hxx>
40 #include <Graphic3d_ArrayOfPolylines.hxx>
41 #include <Graphic3d_AspectFillArea3d.hxx>
42 #include <Graphic3d_AspectMarker3d.hxx>
43 #include <Graphic3d_ClipPlane.hxx>
44 #include <Graphic3d_CubeMapPacked.hxx>
45 #include <Graphic3d_CubeMapSeparate.hxx>
46 #include <Graphic3d_GraduatedTrihedron.hxx>
47 #include <Graphic3d_NameOfTextureEnv.hxx>
48 #include <Graphic3d_Texture2Dmanual.hxx>
49 #include <Graphic3d_TextureEnv.hxx>
50 #include <Graphic3d_TextureParams.hxx>
51 #include <Graphic3d_TypeOfTextureFilter.hxx>
52 #include <Image_AlienPixMap.hxx>
53 #include <Image_Diff.hxx>
54 #include <Image_VideoRecorder.hxx>
55 #include <Message_ProgressSentry.hxx>
56 #include <NCollection_DataMap.hxx>
57 #include <NCollection_List.hxx>
58 #include <NCollection_Vector.hxx>
60 #include <OSD_Timer.hxx>
61 #include <OpenGl_GraphicDriver.hxx>
62 #include <Prs3d_ShadingAspect.hxx>
63 #include <Prs3d_Drawer.hxx>
64 #include <Prs3d_LineAspect.hxx>
65 #include <Prs3d_Root.hxx>
66 #include <Prs3d_Text.hxx>
67 #include <Select3D_SensitivePrimitiveArray.hxx>
68 #include <TColStd_HSequenceOfAsciiString.hxx>
69 #include <TColStd_SequenceOfInteger.hxx>
70 #include <TColStd_HSequenceOfReal.hxx>
71 #include <TColgp_Array1OfPnt2d.hxx>
72 #include <TColStd_MapOfAsciiString.hxx>
73 #include <ViewerTest_AutoUpdater.hxx>
74 #include <ViewerTest_EventManager.hxx>
75 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
76 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
77 #include <ViewerTest_CmdParser.hxx>
78 #include <ViewerTest_V3dView.hxx>
79 #include <V3d_AmbientLight.hxx>
80 #include <V3d_DirectionalLight.hxx>
81 #include <V3d_PositionalLight.hxx>
82 #include <V3d_SpotLight.hxx>
89 #include <WNT_WClass.hxx>
90 #include <WNT_Window.hxx>
91 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
92 #include <Cocoa_Window.hxx>
94 #include <Xw_Window.hxx>
95 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
96 #include <X11/Xutil.h>
100 //==============================================================================
101 // VIEWER GLOBAL VARIABLES
102 //==============================================================================
104 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
105 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
107 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
108 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
111 static Handle(WNT_Window)& VT_GetWindow() {
112 static Handle(WNT_Window) WNTWin;
115 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
116 static Handle(Cocoa_Window)& VT_GetWindow()
118 static Handle(Cocoa_Window) aWindow;
121 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
122 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
125 static Handle(Xw_Window)& VT_GetWindow(){
126 static Handle(Xw_Window) XWWin;
130 static void VProcessEvents(ClientData,int);
133 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
135 static Handle(Aspect_DisplayConnection) aDisplayConnection;
136 return aDisplayConnection;
139 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
141 GetDisplayConnection() = theDisplayConnection;
144 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
145 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
146 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
147 static OpenGl_Caps ViewerTest_myDefaultCaps;
149 static void OSWindowSetup();
153 Quantity_Color FlatColor;
154 Quantity_Color GradientColor1;
155 Quantity_Color GradientColor2;
156 Aspect_GradientFillMethod FillMethod;
157 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
159 //==============================================================================
160 // EVENT GLOBAL VARIABLES
161 //==============================================================================
163 Standard_Boolean TheIsAnimating = Standard_False;
168 //! Checks if some set is a subset of other set
169 //! @tparam TheSuperSet the type of the superset
170 //! @tparam TheSubSet the type of the subset
171 //! @param theSuperSet the superset
172 //! @param theSubSet the subset to be checked
173 //! @return true if the superset includes subset, or false otherwise
174 template <typename TheSuperSet, typename TheSubSet>
175 static bool includes (const TheSuperSet& theSuperSet, const TheSubSet& theSubSet)
177 return std::includes (theSuperSet.begin(), theSuperSet.end(), theSubSet.begin(), theSubSet.end());
180 //! A variable set of keys for command-line options.
181 //! It includes a set of mandatory keys and a set of all possible keys.
182 class CommandOptionKeyVariableSet
185 //! Default constructor
186 CommandOptionKeyVariableSet()
191 //! @param theMandatoryKeySet the set of the mandatory option keys
192 //! @param theAdditionalKeySet the set of additional options that could be omitted
193 CommandOptionKeyVariableSet (
194 const ViewerTest_CommandOptionKeySet& theMandatoryKeySet,
195 const ViewerTest_CommandOptionKeySet& theAdditionalKeySet = ViewerTest_CommandOptionKeySet())
196 : myMandatoryKeySet (theMandatoryKeySet)
198 std::set_union (theMandatoryKeySet.begin(),
199 theMandatoryKeySet.end(),
200 theAdditionalKeySet.begin(),
201 theAdditionalKeySet.end(),
202 std::inserter (myFullKeySet, myFullKeySet.begin()));
205 //! Checks if the set of option keys fits to the current variable set (it must contain all mandatory keys
206 //! and be contained in the full key set)
207 //! @param theCheckedKeySet the set of option keys to be checked
208 bool IsInSet (const ViewerTest_CommandOptionKeySet& theCheckedKeySet) const
210 return includes (theCheckedKeySet, myMandatoryKeySet) && includes (myFullKeySet, theCheckedKeySet);
214 //! A set of mandatory command-line option keys
215 ViewerTest_CommandOptionKeySet myMandatoryKeySet;
217 //! A full set of command-line option keys (includes mandatory and additional option keys)
218 ViewerTest_CommandOptionKeySet myFullKeySet;
221 //! Gets some code by its name
222 //! @tparam TheCode the type of a code to be found
223 //! @param theCodeNameMap the map from code names to codes
224 //! @param theCodeName the name of a code to be found
225 //! @param theCode the code to be found
226 //! @return true if a code is found, or false otherwise
227 template <typename TheCode>
228 static bool getSomeCodeByName (const std::map<TCollection_AsciiString, TheCode>& theCodeNameMap,
229 TCollection_AsciiString theCodeName,
232 theCodeName.LowerCase();
233 const typename std::map<TCollection_AsciiString, TheCode>::const_iterator aCodeIterator = theCodeNameMap.find (
235 if (aCodeIterator == theCodeNameMap.end())
239 theCode = aCodeIterator->second;
243 // Defines possible commands related to background changing
244 enum BackgroundCommand
246 BackgroundCommand_Main, //!< The main command that manages other commands through options
247 BackgroundCommand_Image, //!< Sets an image as a background
248 BackgroundCommand_ImageMode, //!< Changes a background image mode
249 BackgroundCommand_Gradient, //!< Sets a gradient as a background
250 BackgroundCommand_GradientMode, //!< Changes a background gradient mode
251 BackgroundCommand_Color, //!< Fills background with a specified color
252 BackgroundCommand_Default //!< Sets the background default color or gradient
255 //! Map from background command names to its codes
256 typedef std::map<TCollection_AsciiString, BackgroundCommand> BackgroundCommandNameMap;
258 //! Creates a map from background command names to its codes
259 //! @return a map from background command names to its codes
260 static BackgroundCommandNameMap createBackgroundCommandNameMap()
262 BackgroundCommandNameMap aBackgroundCommandNameMap;
263 aBackgroundCommandNameMap["vbackground"] = BackgroundCommand_Main;
264 aBackgroundCommandNameMap["vsetbg"] = BackgroundCommand_Image;
265 aBackgroundCommandNameMap["vsetbgmode"] = BackgroundCommand_ImageMode;
266 aBackgroundCommandNameMap["vsetgradientbg"] = BackgroundCommand_Gradient;
267 aBackgroundCommandNameMap["vsetgrbgmode"] = BackgroundCommand_GradientMode;
268 aBackgroundCommandNameMap["vsetcolorbg"] = BackgroundCommand_Color;
269 aBackgroundCommandNameMap["vsetdefaultbg"] = BackgroundCommand_Default;
270 return aBackgroundCommandNameMap;
273 //! Gets a background command by its name
274 //! @param theBackgroundCommandName the name of the background command
275 //! @param theBackgroundCommand the background command to be found
276 //! @return true if a background command is found, or false otherwise
277 static bool getBackgroundCommandByName (const TCollection_AsciiString& theBackgroundCommandName,
278 BackgroundCommand& theBackgroundCommand)
280 static const BackgroundCommandNameMap THE_BACKGROUND_COMMAND_NAME_MAP = createBackgroundCommandNameMap();
281 return getSomeCodeByName (THE_BACKGROUND_COMMAND_NAME_MAP, theBackgroundCommandName, theBackgroundCommand);
284 //! Map from background image fill method names to its codes
285 typedef std::map<TCollection_AsciiString, Aspect_FillMethod> BackgroundImageFillMethodNameMap;
287 //! Creates a map from background image fill method names to its codes
288 //! @return a map from background image fill method names to its codes
289 static BackgroundImageFillMethodNameMap createBackgroundImageFillMethodNameMap()
291 BackgroundImageFillMethodNameMap aBackgroundImageFillMethodNameMap;
292 aBackgroundImageFillMethodNameMap["none"] = Aspect_FM_NONE;
293 aBackgroundImageFillMethodNameMap["centered"] = Aspect_FM_CENTERED;
294 aBackgroundImageFillMethodNameMap["tiled"] = Aspect_FM_TILED;
295 aBackgroundImageFillMethodNameMap["stretch"] = Aspect_FM_STRETCH;
296 return aBackgroundImageFillMethodNameMap;
299 //! Gets a background image fill method by its name
300 //! @param theBackgroundImageFillMethodName the name of the background image fill method
301 //! @param theBackgroundImageFillMethod the background image fill method to be found
302 //! @return true if a background image fill method is found, or false otherwise
303 static bool getBackgroundImageFillMethodByName (const TCollection_AsciiString& theBackgroundImageFillMethodName,
304 Aspect_FillMethod& theBackgroundImageFillMethod)
306 static const BackgroundImageFillMethodNameMap THE_BACKGROUND_IMAGE_FILL_METHOD_NAME_MAP =
307 createBackgroundImageFillMethodNameMap();
308 return getSomeCodeByName (THE_BACKGROUND_IMAGE_FILL_METHOD_NAME_MAP,
309 theBackgroundImageFillMethodName,
310 theBackgroundImageFillMethod);
313 //! Map from background gradient fill method names to its codes
314 typedef std::map<TCollection_AsciiString, Aspect_GradientFillMethod> BackgroundGradientFillMethodNameMap;
316 //! Creates a map from background gradient fill method names to its codes
317 //! @return a map from background gradient fill method names to its codes
318 static BackgroundGradientFillMethodNameMap createBackgroundGradientFillMethodNameMap()
320 BackgroundGradientFillMethodNameMap aBackgroundGradientFillMethodNameMap;
321 aBackgroundGradientFillMethodNameMap["none"] = Aspect_GFM_NONE;
322 aBackgroundGradientFillMethodNameMap["hor"] = Aspect_GFM_HOR;
323 aBackgroundGradientFillMethodNameMap["horizontal"] = Aspect_GFM_HOR;
324 aBackgroundGradientFillMethodNameMap["ver"] = Aspect_GFM_VER;
325 aBackgroundGradientFillMethodNameMap["vertical"] = Aspect_GFM_VER;
326 aBackgroundGradientFillMethodNameMap["diag1"] = Aspect_GFM_DIAG1;
327 aBackgroundGradientFillMethodNameMap["diagonal1"] = Aspect_GFM_DIAG1;
328 aBackgroundGradientFillMethodNameMap["diag2"] = Aspect_GFM_DIAG2;
329 aBackgroundGradientFillMethodNameMap["diagonal2"] = Aspect_GFM_DIAG2;
330 aBackgroundGradientFillMethodNameMap["corner1"] = Aspect_GFM_CORNER1;
331 aBackgroundGradientFillMethodNameMap["corner2"] = Aspect_GFM_CORNER2;
332 aBackgroundGradientFillMethodNameMap["corner3"] = Aspect_GFM_CORNER3;
333 aBackgroundGradientFillMethodNameMap["corner4"] = Aspect_GFM_CORNER4;
334 return aBackgroundGradientFillMethodNameMap;
337 //! Gets a gradient fill method by its name
338 //! @param theBackgroundGradientFillMethodName the name of the gradient fill method
339 //! @param theBackgroundGradientFillMethod the gradient fill method to be found
340 //! @return true if a gradient fill method is found, or false otherwise
341 static bool getBackgroundGradientFillMethodByName (const TCollection_AsciiString& theBackgroundGradientFillMethodName,
342 Aspect_GradientFillMethod& theBackgroundGradientFillMethod)
344 static const BackgroundGradientFillMethodNameMap THE_BACKGROUND_GRADIENT_FILL_METHOD_NAME_MAP =
345 createBackgroundGradientFillMethodNameMap();
346 return getSomeCodeByName (THE_BACKGROUND_GRADIENT_FILL_METHOD_NAME_MAP,
347 theBackgroundGradientFillMethodName,
348 theBackgroundGradientFillMethod);
351 //! Changes the background in accordance with passed command line options
352 class BackgroundChanger
355 //! Constructor. Prepares the command parser
358 prepareCommandParser();
361 //! Processes the command line and changes the background
362 //! @param theDrawInterpretor the interpreter of the Draw Harness application
363 //! @param theNumberOfCommandLineArguments the number of passed command line arguments
364 //! @param theCommandLineArguments the array of command line arguments
365 bool ProcessCommandLine (Draw_Interpretor& theDrawInterpretor,
366 const Standard_Integer theNumberOfCommandLineArguments,
367 const char* const* const theCommandLineArguments)
369 const char* const aBackgroundCommandName = theCommandLineArguments[0];
370 BackgroundCommand aBackgroundCommand = BackgroundCommand_Main;
371 if (!getBackgroundCommandByName (aBackgroundCommandName, aBackgroundCommand))
375 addCommandDescription (aBackgroundCommand);
376 myCommandParser.Parse (theNumberOfCommandLineArguments, theCommandLineArguments);
377 return processCommandOptions (aBackgroundCommandName, aBackgroundCommand, theDrawInterpretor);
381 //! The type of functions that are able to set gradient background filling
382 typedef void SetGradientFunction (const Quantity_Color& /* theColor1 */,
383 const Quantity_Color& /* theColor2 */,
384 const Aspect_GradientFillMethod /* theGradientMode */);
386 //! The type of functions that are able to fill a background with a specific color
387 typedef void SetColorFunction (const Quantity_Color& /* theColor */);
389 //! the command parser used to parse command line options and its arguments
390 ViewerTest_CmdParser myCommandParser;
392 //! the option key for the command that sets an image as a background
393 ViewerTest_CommandOptionKey myImageOptionKey;
395 //! the option key for the command that sets a background image fill type
396 ViewerTest_CommandOptionKey myImageModeOptionKey;
398 //! the option key for the command that sets a gradient filling for the background
399 ViewerTest_CommandOptionKey myGradientOptionKey;
401 //! the option key for the command that sets a background gradient filling method
402 ViewerTest_CommandOptionKey myGradientModeOptionKey;
404 //! the option key for the command that fills background with a specific color
405 ViewerTest_CommandOptionKey myColorOptionKey;
407 //! the option key for the command that sets default background gradient or color
408 ViewerTest_CommandOptionKey myDefaultOptionKey;
410 //! the option key for the command that sets an environment cubemap as a background
411 ViewerTest_CommandOptionKey myCubeMapOptionKey;
413 //! the option key for the command that defines order of tiles in one image packed cubemap
414 ViewerTest_CommandOptionKey myCubeMapOrderOptionKey;
416 //! the option key for the command that sets inversion of Z axis for background cubemap
417 ViewerTest_CommandOptionKey myCubeMapInvertedZOptionKey;
419 //! the option key for the command that allows skip IBL map generation
420 ViewerTest_CommandOptionKey myCubeMapDoNotGenPBREnvOptionKey;
422 //! the variable set of options that are allowed for the old scenario (without any option passed)
423 CommandOptionKeyVariableSet myUnnamedOptionVariableSet;
425 //! the variable set of options that are allowed for setting an environment cubemap as background
426 CommandOptionKeyVariableSet myCubeMapOptionVariableSet;
428 //! the variable set of options that are allowed for setting an image as a background
429 CommandOptionKeyVariableSet myImageOptionVariableSet;
431 //! the variable set of options that are allowed for setting a background image fill type
432 CommandOptionKeyVariableSet myImageModeOptionVariableSet;
434 //! the variable set of options that are allowed for setting a gradient filling for the background
435 CommandOptionKeyVariableSet myGradientOptionVariableSet;
437 //! the variable set of options that are allowed for setting a background gradient filling method
438 CommandOptionKeyVariableSet myGradientModeOptionVariableSet;
440 //! the variable set of options that are allowed for filling a background with a specific color
441 CommandOptionKeyVariableSet myColorOptionVariableSet;
443 //! the variable set of options that are allowed for setting a default background gradient
444 CommandOptionKeyVariableSet myDefaultGradientOptionVariableSet;
446 //! the variable set of options that are allowed for setting a default background color
447 CommandOptionKeyVariableSet myDefaultColorOptionVariableSet;
449 //! the variable set of options that are allowed for printing help
450 CommandOptionKeyVariableSet myHelpOptionVariableSet;
452 //! Adds options to command parser
453 void addOptionsToCommandParser()
455 myImageOptionKey = myCommandParser.AddOption ("imageFile|image|imgFile|img",
456 "filename of image used as background");
457 myImageModeOptionKey = myCommandParser.AddOption (
458 "imageMode|imgMode", "image fill type, should be one of CENTERED, TILED, STRETCH, NONE");
459 myGradientOptionKey = myCommandParser.AddOption ("gradient|grad|gr",
460 "sets background gradient starting and ending colors");
461 myGradientModeOptionKey =
462 myCommandParser.AddOption ("gradientMode|gradMode|gradMd|grMode|grMd",
463 "gradient fill method, should be one of NONE, HOR[IZONTAL], VER[TICAL], "
464 "DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, CORNER4");
465 myColorOptionKey = myCommandParser.AddOption ("color|col", "background color");
466 myDefaultOptionKey = myCommandParser.AddOption ("default|def", "sets background default gradient or color");
468 myCubeMapOptionKey = myCommandParser.AddOption ("cubemap|cmap|cm", "background cubemap");
469 myCubeMapOrderOptionKey = myCommandParser.AddOption ("order|o", "order of sides in one image packed cubemap");
470 myCubeMapInvertedZOptionKey = myCommandParser.AddOption (
471 "invertedz|invz|iz", "whether Z axis is inverted or not during background cubemap rendering");
472 myCubeMapDoNotGenPBREnvOptionKey = myCommandParser.AddOption ("nopbrenv", "whether IBL map generation should be skipped");
475 //! Creates option sets used to determine if a passed option set is valid or not
476 void createOptionSets()
478 ViewerTest_CommandOptionKeySet anUnnamedOptionSet;
479 anUnnamedOptionSet.insert (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
480 myUnnamedOptionVariableSet = CommandOptionKeyVariableSet (anUnnamedOptionSet);
482 ViewerTest_CommandOptionKeySet aCubeMapOptionSet;
483 aCubeMapOptionSet.insert (myCubeMapOptionKey);
484 ViewerTest_CommandOptionKeySet aCubeMapAdditionalOptionKeySet;
485 aCubeMapAdditionalOptionKeySet.insert (myCubeMapInvertedZOptionKey);
486 aCubeMapAdditionalOptionKeySet.insert (myCubeMapDoNotGenPBREnvOptionKey);
487 aCubeMapAdditionalOptionKeySet.insert (myCubeMapOrderOptionKey);
488 myCubeMapOptionVariableSet = CommandOptionKeyVariableSet (aCubeMapOptionSet, aCubeMapAdditionalOptionKeySet);
490 ViewerTest_CommandOptionKeySet anImageOptionSet;
491 anImageOptionSet.insert (myImageOptionKey);
492 ViewerTest_CommandOptionKeySet anImageModeOptionSet;
493 anImageModeOptionSet.insert (myImageModeOptionKey);
494 myImageOptionVariableSet = CommandOptionKeyVariableSet (anImageOptionSet, anImageModeOptionSet);
495 myImageModeOptionVariableSet = CommandOptionKeyVariableSet (anImageModeOptionSet);
497 ViewerTest_CommandOptionKeySet aGradientOptionSet;
498 aGradientOptionSet.insert (myGradientOptionKey);
499 ViewerTest_CommandOptionKeySet aGradientModeOptionSet;
500 aGradientModeOptionSet.insert (myGradientModeOptionKey);
501 myGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet);
502 myGradientModeOptionVariableSet = CommandOptionKeyVariableSet (aGradientModeOptionSet);
504 ViewerTest_CommandOptionKeySet aColorOptionSet;
505 aColorOptionSet.insert (myColorOptionKey);
506 myColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet);
508 aGradientOptionSet.insert (myDefaultOptionKey);
509 myDefaultGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet);
510 aColorOptionSet.insert (myDefaultOptionKey);
511 myDefaultColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet);
513 ViewerTest_CommandOptionKeySet aHelpOptionSet;
514 aHelpOptionSet.insert (ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY);
515 myHelpOptionVariableSet = CommandOptionKeyVariableSet (aHelpOptionSet);
518 //! Prepares the command parser. Adds options and creates option sets used to determine
519 //! if a passed option set is valid or not
520 void prepareCommandParser()
522 addOptionsToCommandParser();
526 //! Adds a command description to the command parser
527 //! @param theBackgroundCommand the key of the command which description is added to the command parser
528 void addCommandDescription (const BackgroundCommand theBackgroundCommand)
530 std::string aDescription;
531 bool isMainCommand = false;
532 switch (theBackgroundCommand)
534 case BackgroundCommand_Main:
535 aDescription = "Command: vbackground (changes background or some background settings)";
536 isMainCommand = true;
538 case BackgroundCommand_Image:
539 aDescription = "Command: vsetbg (loads image as a background)";
541 case BackgroundCommand_ImageMode:
542 aDescription = "Command: vsetbgmode (changes background fill type)";
544 case BackgroundCommand_Gradient:
545 aDescription = "Command: vsetgradientbg (mounts gradient background)";
547 case BackgroundCommand_GradientMode:
548 aDescription = "Command: vsetgradientbgmode (changes gradient background fill method)";
550 case BackgroundCommand_Color:
551 aDescription = "Command: vsetcolorbg (sets color background)";
553 case BackgroundCommand_Default:
554 aDescription = "Command: vsetdefaultbg (sets default viewer background gradient or fill color)";
561 aDescription += "\nThis command is obsolete. Use vbackground instead.";
563 myCommandParser.SetDescription (aDescription);
566 //! Check if a viewer is needed to be initialized
567 //! @param theBackgroundCommand the key of the command that changes the background
568 //! @return true if processing was successful, or false otherwise
569 bool checkViewerIsNeeded (const BackgroundCommand theBackgroundCommand) const
571 const bool isMain = (theBackgroundCommand == BackgroundCommand_Main);
572 const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions();
573 const bool aViewerIsNotNeeded =
574 (theBackgroundCommand == BackgroundCommand_Default)
575 || (myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain)
576 || (myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain)
577 || myHelpOptionVariableSet.IsInSet (aUsedOptions);
578 return !aViewerIsNotNeeded;
581 //! Check if a viewer is initialized
582 //! @param theBackgroundCommandName the name of the command that changes the background
583 //! @param theDrawInterpretor the interpreter of the Draw Harness application
584 //! @return true if a viewer is initialized, or false otherwise
585 static bool checkViewerIsInitialized (const char* const theBackgroundCommandName,
586 Draw_Interpretor& theDrawInterpretor)
588 const Handle (AIS_InteractiveContext)& anAISContext = ViewerTest::GetAISContext();
589 if (anAISContext.IsNull())
591 theDrawInterpretor << "Use 'vinit' command before executing '" << theBackgroundCommandName << "' command.\n";
597 //! Processes command options
598 //! @param theBackgroundCommandName the name of the command that changes the background
599 //! @param theBackgroundCommand the key of the command that changes the background
600 //! @param theDrawInterpretor the interpreter of the Draw Harness application
601 //! @return true if processing was successful, or false otherwise
602 bool processCommandOptions (const char* const theBackgroundCommandName,
603 const BackgroundCommand theBackgroundCommand,
604 Draw_Interpretor& theDrawInterpretor) const
606 if (myCommandParser.HasNoOption())
608 return printHelp (theBackgroundCommandName, theDrawInterpretor);
610 if (checkViewerIsNeeded (theBackgroundCommand)
611 && !checkViewerIsInitialized (theBackgroundCommandName, theDrawInterpretor))
615 if (myCommandParser.HasOnlyUnnamedOption())
617 return processUnnamedOption (theBackgroundCommand);
619 return processNamedOptions (theBackgroundCommandName, theBackgroundCommand, theDrawInterpretor);
622 //! Processes the unnamed option
623 //! @param theBackgroundCommand the key of the command that changes the background
624 //! @return true if processing was successful, or false otherwise
625 bool processUnnamedOption (const BackgroundCommand theBackgroundCommand) const
627 switch (theBackgroundCommand)
629 case BackgroundCommand_Main:
631 case BackgroundCommand_Image:
632 return processImageUnnamedOption();
633 case BackgroundCommand_ImageMode:
634 return processImageModeUnnamedOption();
635 case BackgroundCommand_Gradient:
636 return processGradientUnnamedOption();
637 case BackgroundCommand_GradientMode:
638 return processGradientModeUnnamedOption();
639 case BackgroundCommand_Color:
640 return processColorUnnamedOption();
641 case BackgroundCommand_Default:
642 return processDefaultUnnamedOption();
648 //! Processes the image unnamed option
649 //! @return true if processing was successful, or false otherwise
650 bool processImageUnnamedOption() const
652 const std::size_t aNumberOfImageUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments (
653 ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
654 if ((aNumberOfImageUnnamedOptionArguments != 1) && (aNumberOfImageUnnamedOptionArguments != 2))
658 std::string anImageFileName;
659 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0, anImageFileName))
663 Aspect_FillMethod anImageMode = Aspect_FM_CENTERED;
664 if (aNumberOfImageUnnamedOptionArguments == 2)
666 std::string anImageModeString;
667 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 1, anImageModeString))
671 if (!getBackgroundImageFillMethodByName (anImageModeString.c_str(), anImageMode))
676 setImage (anImageFileName.c_str(), anImageMode);
680 //! Processes the image mode unnamed option
681 //! @return true if processing was successful, or false otherwise
682 bool processImageModeUnnamedOption() const
684 return processImageModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
687 //! Processes the gradient unnamed option
688 //! @param theSetGradient the function used to set a background gradient filling
689 //! @return true if processing was successful, or false otherwise
690 bool processGradientUnnamedOption (SetGradientFunction* const theSetGradient = setGradient) const
692 const Standard_Integer aNumberOfGradientUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments (
693 ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
694 if (aNumberOfGradientUnnamedOptionArguments < 2)
699 Standard_Integer anArgumentIndex = 0;
700 Quantity_Color aColor1;
701 if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor1))
705 if (anArgumentIndex >= aNumberOfGradientUnnamedOptionArguments)
710 Quantity_Color aColor2;
711 if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor2))
715 if (anArgumentIndex > aNumberOfGradientUnnamedOptionArguments)
720 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR;
721 if (anArgumentIndex == aNumberOfGradientUnnamedOptionArguments - 1)
723 std::string anGradientModeString;
725 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY,
727 anGradientModeString))
731 if (!getBackgroundGradientFillMethodByName (anGradientModeString.c_str(), aGradientMode))
737 if (anArgumentIndex != aNumberOfGradientUnnamedOptionArguments)
741 theSetGradient (aColor1, aColor2, aGradientMode);
745 //! Processes the gradient mode unnamed option
746 //! @return true if processing was successful, or false otherwise
747 bool processGradientModeUnnamedOption() const
749 return processGradientModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
752 //! Processes the color unnamed option
753 //! @param theSetColor the function used to set a background color
754 //! @return true if processing was successful, or false otherwise
755 bool processColorUnnamedOption (SetColorFunction* const theSetColor = setColor) const
757 return processColorOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, theSetColor);
760 //! Processes the default back unnamed option
761 //! @return true if processing was successful, or false otherwise
762 bool processDefaultUnnamedOption() const
764 if (processGradientUnnamedOption (setDefaultGradient))
768 return processColorUnnamedOption (setDefaultColor);
771 //! Processes named options
772 //! @param theBackgroundCommandName the name of the command that changes the background
773 //! @param theBackgroundCommand the key of the command that changes the background
774 //! @param theDrawInterpretor the interpreter of the Draw Harness application
775 //! @return true if processing was successful, or false otherwise
776 bool processNamedOptions (const char* const theBackgroundCommandName,
777 const BackgroundCommand theBackgroundCommand,
778 Draw_Interpretor& theDrawInterpretor) const
780 const bool isMain = (theBackgroundCommand == BackgroundCommand_Main);
781 const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions();
782 if (myCubeMapOptionVariableSet.IsInSet (aUsedOptions) && isMain)
784 return processCubeMapOptionSet();
786 if (myImageOptionVariableSet.IsInSet (aUsedOptions)
787 && (isMain || (theBackgroundCommand == BackgroundCommand_Image)))
789 return processImageOptionSet();
791 if (myImageModeOptionVariableSet.IsInSet (aUsedOptions)
792 && (isMain || (theBackgroundCommand == BackgroundCommand_ImageMode)))
794 return processImageModeOptionSet();
796 if (myGradientOptionVariableSet.IsInSet (aUsedOptions)
797 && (isMain || (theBackgroundCommand == BackgroundCommand_Gradient)))
799 return processGradientOptionSet();
801 if (myGradientModeOptionVariableSet.IsInSet (aUsedOptions)
802 && (isMain || (theBackgroundCommand == BackgroundCommand_GradientMode)))
804 return processGradientModeOptionSet();
806 if (myColorOptionVariableSet.IsInSet (aUsedOptions)
807 && (isMain || (theBackgroundCommand == BackgroundCommand_Color)))
809 return processColorOptionSet();
811 if ((myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain)
812 || (myGradientOptionVariableSet.IsInSet (aUsedOptions)
813 && (theBackgroundCommand == BackgroundCommand_Default)))
815 return processDefaultGradientOptionSet();
817 if ((myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain)
818 || (myColorOptionVariableSet.IsInSet (aUsedOptions) && (theBackgroundCommand == BackgroundCommand_Default)))
820 return processDefaultColorOptionSet();
822 if (myHelpOptionVariableSet.IsInSet (aUsedOptions))
824 return processHelpOptionSet (theBackgroundCommandName, theDrawInterpretor);
829 //! Process the cubemap option set in named and unnamed case.
830 //! @return true if processing was successful, or false otherwise
831 bool processCubeMapOptionSet() const
833 NCollection_Array1<TCollection_AsciiString> aFilePaths;
835 if (!processCubeMapOptions (aFilePaths))
840 Graphic3d_CubeMapOrder anOrder = Graphic3d_CubeMapOrder::Default();
842 if (myCommandParser.HasOption (myCubeMapOrderOptionKey))
844 if (!processCubeMapOrderOptions (anOrder))
850 bool aZIsInverted = false;
851 if (myCommandParser.HasOption (myCubeMapInvertedZOptionKey))
853 if (!processCubeMapInvertedZOptionSet())
860 bool aToGenPBREnv = true;
861 if (myCommandParser.HasOption (myCubeMapDoNotGenPBREnvOptionKey))
863 if (!processCubeMapDoNotGenPBREnvOptionSet())
867 aToGenPBREnv = false;
870 setCubeMap (aFilePaths, anOrder.Validated(), aZIsInverted, aToGenPBREnv);
874 //! Processes the image option set
875 //! @return true if processing was successful, or false otherwise
876 bool processImageOptionSet() const
878 std::string anImageFileName;
879 if (!processImageOption (anImageFileName))
883 Aspect_FillMethod anImageMode = Aspect_FM_CENTERED;
884 if (myCommandParser.HasOption (myImageModeOptionKey) && !processImageModeOption (anImageMode))
888 setImage (anImageFileName.c_str(), anImageMode);
892 //! Processes the image mode option set
893 //! @return true if processing was successful, or false otherwise
894 bool processImageModeOptionSet() const
896 return processImageModeOptionSet (myImageModeOptionKey);
899 //! Processes the image mode option set
900 //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option
901 //! @return true if processing was successful, or false otherwise
902 bool processImageModeOptionSet (const ViewerTest_CommandOptionKey theImageModeOptionKey) const
904 Aspect_FillMethod anImageMode = Aspect_FM_NONE;
905 if (!processImageModeOption (theImageModeOptionKey, anImageMode))
909 setImageMode (anImageMode);
913 //! Processes the gradient option set
914 //! @param theSetGradient the function used to set a background gradient filling
915 //! @return true if processing was successful, or false otherwise
916 bool processGradientOptionSet (SetGradientFunction* const theSetGradient = setGradient) const
918 Quantity_Color aColor1;
919 Quantity_Color aColor2;
920 if (!processGradientOption (aColor1, aColor2))
924 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR;
925 if (myCommandParser.HasOption (myGradientModeOptionKey) && !processGradientModeOption (aGradientMode))
929 theSetGradient (aColor1, aColor2, aGradientMode);
933 //! Processes the gradient mode option set
934 //! @return true if processing was successful, or false otherwise
935 bool processGradientModeOptionSet() const
937 return processGradientModeOptionSet (myGradientModeOptionKey);
940 //! Processes the gradient mode option set
941 //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option
942 //! @return true if processing was successful, or false otherwise
943 bool processGradientModeOptionSet (const ViewerTest_CommandOptionKey theGradientModeOptionKey) const
945 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_NONE;
946 if (!processGradientModeOption (theGradientModeOptionKey, aGradientMode))
950 setGradientMode (aGradientMode);
954 //! Processes the color option set
955 //! @param theSetColor the function used to set a background color
956 //! @return true if processing was successful, or false otherwise
957 bool processColorOptionSet (SetColorFunction* const theSetColor = setColor) const
959 return processColorOptionSet (myColorOptionKey, theSetColor);
962 //! Processes the default color option set
963 //! @return true if processing was successful, or false otherwise
964 bool processDefaultGradientOptionSet() const
966 return processGradientOptionSet (setDefaultGradient);
969 //! Processes the default gradient option set
970 //! @return true if processing was successful, or false otherwise
971 bool processDefaultColorOptionSet() const
973 return processColorOptionSet (setDefaultColor);
976 //! Processes the color option set
977 //! @param theColorOptionKey the key of the option that is interpreted as a color option
978 //! @param theSetColor the function used to set a background color
979 //! @return true if processing was successful, or false otherwise
980 bool processColorOptionSet (const ViewerTest_CommandOptionKey theColorOptionKey,
981 SetColorFunction* const theSetColor = setColor) const
983 Quantity_Color aColor;
984 if (!processColorOption (theColorOptionKey, aColor))
988 theSetColor (aColor);
992 //! Processes the help option set
993 //! @param theBackgroundCommandName the name of the command that changes the background
994 //! @param theDrawInterpretor the interpreter of the Draw Harness application
995 //! @return true if processing was successful, or false otherwise
996 bool processHelpOptionSet (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor) const
998 const Standard_Integer aNumberOfHelpOptionArguments = myCommandParser.GetNumberOfOptionArguments (
999 ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY);
1000 if (aNumberOfHelpOptionArguments != 0)
1004 return printHelp (theBackgroundCommandName, theDrawInterpretor);
1007 //! Processes the cubemap option
1008 //! @param theFilePaths the array of filenames of cubemap sides
1009 //! @return true if processing was successful, or false otherwise
1010 bool processCubeMapOptions (NCollection_Array1<TCollection_AsciiString> &theFilePaths) const
1012 const Standard_Integer aNumberOfCubeMapOptionArguments = myCommandParser.GetNumberOfOptionArguments (myCubeMapOptionKey);
1014 if (aNumberOfCubeMapOptionArguments != 1
1015 && aNumberOfCubeMapOptionArguments != 6)
1020 theFilePaths.Resize(0, aNumberOfCubeMapOptionArguments - 1, Standard_False);
1022 for (int i = 0; i < aNumberOfCubeMapOptionArguments; ++i)
1024 std::string aCubeMapFileName;
1025 if (!myCommandParser.Arg (myCubeMapOptionKey, i, aCubeMapFileName))
1029 theFilePaths[i] = aCubeMapFileName.c_str();
1035 //! Processes the inverted z cubemap option
1036 //! @return true if processing was successful, or false otherwise
1037 bool processCubeMapInvertedZOptionSet () const
1039 const Standard_Integer aNumberOfCubeMapZInversionOptionArguments =
1040 myCommandParser.GetNumberOfOptionArguments (myCubeMapInvertedZOptionKey);
1042 if (aNumberOfCubeMapZInversionOptionArguments != 0)
1050 //! Processes the option allowing to skip IBM maps generation
1051 //! @return true if processing was successful, or false otherwise
1052 bool processCubeMapDoNotGenPBREnvOptionSet() const
1054 const Standard_Integer aNumberOfCubeMapDoNotGenPBREnvOptionArguments =
1055 myCommandParser.GetNumberOfOptionArguments(myCubeMapDoNotGenPBREnvOptionKey);
1057 if (aNumberOfCubeMapDoNotGenPBREnvOptionArguments != 0)
1065 //! Processes the tiles order option
1066 //! @param theOrder the array of indexes if cubemap sides in tile grid
1067 //! @return true if processing was successful, or false otherwise
1068 bool processCubeMapOrderOptions (Graphic3d_CubeMapOrder& theOrder) const
1070 const Standard_Integer aNumberOfCubeMapOrderOptionArguments = myCommandParser.GetNumberOfOptionArguments(
1071 myCubeMapOrderOptionKey);
1073 if (aNumberOfCubeMapOrderOptionArguments != 6)
1079 for (unsigned int i = 0; i < 6; ++i)
1081 std::string anOrderItem;
1082 if (!myCommandParser.Arg (myCubeMapOrderOptionKey, i, anOrderItem))
1087 theOrder.Set (Graphic3d_CubeMapSide (i),
1088 static_cast<unsigned char> (Draw::Atoi (anOrderItem.c_str())));
1091 return theOrder.IsValid();
1094 //! Processes the image option
1095 //! @param theImageFileName the filename of the image to be used as a background
1096 //! @return true if processing was successful, or false otherwise
1097 bool processImageOption (std::string& theImageFileName) const
1099 const Standard_Integer aNumberOfImageOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1101 if (aNumberOfImageOptionArguments != 1)
1105 std::string anImageFileName;
1106 if (!myCommandParser.Arg (myImageOptionKey, 0, anImageFileName))
1110 theImageFileName = anImageFileName;
1114 //! Processes the image mode option
1115 //! @param theImageMode the fill type used for a background image
1116 //! @return true if processing was successful, or false otherwise
1117 bool processImageModeOption (Aspect_FillMethod& theImageMode) const
1119 return processImageModeOption (myImageModeOptionKey, theImageMode);
1122 //! Processes the image mode option
1123 //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option
1124 //! @param theImageMode the fill type used for a background image
1125 //! @return true if processing was successful, or false otherwise
1126 bool processImageModeOption (const ViewerTest_CommandOptionKey theImageModeOptionKey,
1127 Aspect_FillMethod& theImageMode) const
1129 return processModeOption (theImageModeOptionKey, getBackgroundImageFillMethodByName, theImageMode);
1132 //! Processes the gradient option
1133 //! @param theColor1 the gradient starting color
1134 //! @param theColor2 the gradient ending color
1135 //! @return true if processing was successful, or false otherwise
1136 bool processGradientOption (Quantity_Color& theColor1, Quantity_Color& theColor2) const
1138 Standard_Integer anArgumentIndex = 0;
1139 Quantity_Color aColor1;
1140 if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor1))
1144 Quantity_Color aColor2;
1145 if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor2))
1149 const Standard_Integer aNumberOfGradientOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1150 myGradientOptionKey);
1151 if (anArgumentIndex != aNumberOfGradientOptionArguments)
1155 theColor1 = aColor1;
1156 theColor2 = aColor2;
1160 //! Processes the gradient mode option
1161 //! @param theGradientMode the fill method used for a background gradient filling
1162 //! @return true if processing was successful, or false otherwise
1163 bool processGradientModeOption (Aspect_GradientFillMethod& theGradientMode) const
1165 return processGradientModeOption (myGradientModeOptionKey, theGradientMode);
1168 //! Processes the gradient mode option
1169 //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option
1170 //! @param theGradientMode the fill method used for a background gradient filling
1171 //! @return true if processing was successful, or false otherwise
1172 bool processGradientModeOption (const ViewerTest_CommandOptionKey theGradientModeOptionKey,
1173 Aspect_GradientFillMethod& theGradientMode) const
1175 return processModeOption (theGradientModeOptionKey, getBackgroundGradientFillMethodByName, theGradientMode);
1178 //! Processes some mode option
1179 //! @tparam TheMode the type of a mode to be processed
1180 //! @param theModeOptionKey the key of the option that is interpreted as a mode option
1181 //! @param theMode a mode to be processed
1182 //! @return true if processing was successful, or false otherwise
1183 template <typename TheMode>
1184 bool processModeOption (const ViewerTest_CommandOptionKey theModeOptionKey,
1185 bool (*const theGetModeByName) (const TCollection_AsciiString& /* theModeName */,
1186 TheMode& /* theMode */),
1187 TheMode& theMode) const
1189 const Standard_Integer aNumberOfModeOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1191 if (aNumberOfModeOptionArguments != 1)
1195 std::string aModeString;
1196 if (!myCommandParser.Arg (theModeOptionKey, 0, aModeString))
1200 TheMode aMode = TheMode();
1201 if (!theGetModeByName (aModeString.c_str(), aMode))
1209 //! Processes the color option
1210 //! @param theColor a color used for filling a background
1211 //! @return true if processing was successful, or false otherwise
1212 bool processColorOption (Quantity_Color& theColor) const
1214 return processColorOption (myColorOptionKey, theColor);
1217 //! Processes the color option
1218 //! @param theColorOptionKey the key of the option that is interpreted as a color option
1219 //! @param theColor a color used for filling a background
1220 //! @return true if processing was successful, or false otherwise
1221 bool processColorOption (const ViewerTest_CommandOptionKey theColorOptionKey, Quantity_Color& theColor) const
1223 Standard_Integer anArgumentIndex = 0;
1224 Quantity_Color aColor;
1225 if (!myCommandParser.ArgColor (theColorOptionKey, anArgumentIndex, aColor))
1229 const Standard_Integer aNumberOfColorOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1231 if (anArgumentIndex != aNumberOfColorOptionArguments)
1239 //! Prints helping message
1240 //! @param theBackgroundCommandName the name of the command that changes the background
1241 //! @param theDrawInterpretor the interpreter of the Draw Harness application
1242 //! @return true if printing was successful, or false otherwise
1243 static bool printHelp (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor)
1245 return theDrawInterpretor.PrintHelp (theBackgroundCommandName) == TCL_OK;
1248 //! Sets the cubemap as a background
1249 //! @param theFileNames the array of filenames of packed or multifile cubemap
1250 //! @param theOrder array of cubemap sides indexes mapping them from tiles in packed cubemap
1251 static void setCubeMap (const NCollection_Array1<TCollection_AsciiString>& theFileNames,
1252 const Graphic3d_ValidatedCubeMapOrder theOrder = Graphic3d_CubeMapOrder::Default(),
1253 bool theZIsInverted = false,
1254 bool theToGenPBREnv = true)
1256 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
1257 Handle(Graphic3d_CubeMap) aCubeMap;
1259 if (theFileNames.Size() == 1)
1260 aCubeMap = new Graphic3d_CubeMapPacked(theFileNames[0], theOrder);
1262 aCubeMap = new Graphic3d_CubeMapSeparate(theFileNames);
1264 aCubeMap->SetZInversion (theZIsInverted);
1266 aCubeMap->GetParams()->SetFilter(Graphic3d_TOTF_BILINEAR);
1267 aCubeMap->GetParams()->SetRepeat(Standard_False);
1268 aCubeMap->GetParams()->SetTextureUnit(Graphic3d_TextureUnit_EnvMap);
1270 aCurrentView->SetBackgroundCubeMap (aCubeMap, theToGenPBREnv, Standard_True);
1273 //! Sets the image as a background
1274 //! @param theImageFileName the filename of the image to be used as a background
1275 //! @param theImageMode the fill type used for a background image
1276 static void setImage (const Standard_CString theImageFileName, const Aspect_FillMethod theImageMode)
1278 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1279 aCurrentView->SetBackgroundImage (theImageFileName, theImageMode, Standard_True);
1282 //! Sets the fill type used for a background image
1283 //! @param theImageMode the fill type used for a background image
1284 static void setImageMode (const Aspect_FillMethod theImageMode)
1286 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1287 aCurrentView->SetBgImageStyle (theImageMode, Standard_True);
1290 //! Sets the gradient filling for a background
1291 //! @param theColor1 the gradient starting color
1292 //! @param theColor2 the gradient ending color
1293 //! @param theGradientMode the fill method used for a background gradient filling
1294 static void setGradient (const Quantity_Color& theColor1,
1295 const Quantity_Color& theColor2,
1296 const Aspect_GradientFillMethod theGradientMode)
1298 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1299 aCurrentView->SetBgGradientColors (theColor1, theColor2, theGradientMode, Standard_True);
1302 //! Sets the fill method used for a background gradient filling
1303 //! @param theGradientMode the fill method used for a background gradient filling
1304 static void setGradientMode (const Aspect_GradientFillMethod theGradientMode)
1306 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1307 aCurrentView->SetBgGradientStyle (theGradientMode, Standard_True);
1310 //! Sets the color used for filling a background
1311 //! @param theColor the color used for filling a background
1312 static void setColor (const Quantity_Color& theColor)
1314 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1315 aCurrentView->SetBgGradientStyle (Aspect_GFM_NONE);
1316 aCurrentView->SetBackgroundColor (theColor);
1317 aCurrentView->Update();
1320 //! Sets the gradient filling for a background in a default viewer
1321 //! @param theColor1 the gradient starting color
1322 //! @param theColor2 the gradient ending color
1323 //! @param theGradientMode the fill method used for a background gradient filling
1324 static void setDefaultGradient (const Quantity_Color& theColor1,
1325 const Quantity_Color& theColor2,
1326 const Aspect_GradientFillMethod theGradientMode)
1328 ViewerTest_DefaultBackground.GradientColor1 = theColor1;
1329 ViewerTest_DefaultBackground.GradientColor2 = theColor2;
1330 ViewerTest_DefaultBackground.FillMethod = theGradientMode;
1331 setDefaultGradient();
1334 //! Sets the color used for filling a background in a default viewer
1335 //! @param theColor the color used for filling a background
1336 static void setDefaultColor (const Quantity_Color& theColor)
1338 ViewerTest_DefaultBackground.GradientColor1 = Quantity_Color();
1339 ViewerTest_DefaultBackground.GradientColor2 = Quantity_Color();
1340 ViewerTest_DefaultBackground.FillMethod = Aspect_GFM_NONE;
1341 ViewerTest_DefaultBackground.FlatColor = theColor;
1342 setDefaultGradient();
1346 //! Sets the gradient filling for a background in a default viewer.
1347 //! Gradient settings are taken from ViewerTest_DefaultBackground structure
1348 static void setDefaultGradient()
1350 for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator
1351 anInteractiveContextIterator (ViewerTest_myContexts);
1352 anInteractiveContextIterator.More();
1353 anInteractiveContextIterator.Next())
1355 const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer();
1356 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
1357 ViewerTest_DefaultBackground.GradientColor2,
1358 ViewerTest_DefaultBackground.FillMethod);
1362 //! Sets the color used for filling a background in a default viewer.
1363 //! The color value is taken from ViewerTest_DefaultBackground structure
1364 static void setDefaultColor()
1366 for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator
1367 anInteractiveContextIterator (ViewerTest_myContexts);
1368 anInteractiveContextIterator.More();
1369 anInteractiveContextIterator.Next())
1371 const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer();
1372 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
1379 //==============================================================================
1382 static LRESULT WINAPI ViewerWindowProc(
1387 static LRESULT WINAPI AdvViewerWindowProc(
1395 //==============================================================================
1398 //==============================================================================
1400 const Handle(Standard_Transient)& ViewerTest::WClass()
1402 static Handle(Standard_Transient) theWClass;
1404 if (theWClass.IsNull())
1406 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
1407 CS_VREDRAW | CS_HREDRAW, 0, 0,
1408 ::LoadCursor (NULL, IDC_ARROW));
1414 //==============================================================================
1415 //function : CreateName
1416 //purpose : Create numerical name for new object in theMap
1417 //==============================================================================
1418 template <typename ObjectType>
1419 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
1420 const TCollection_AsciiString& theDefaultString)
1422 if (theObjectMap.IsEmpty())
1423 return theDefaultString + TCollection_AsciiString(1);
1425 Standard_Integer aNextKey = 1;
1426 Standard_Boolean isFound = Standard_False;
1429 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
1430 // Look for objects with default names
1431 if (theObjectMap.IsBound1(aStringKey))
1436 isFound = Standard_True;
1439 return theDefaultString + TCollection_AsciiString(aNextKey);
1442 //==============================================================================
1443 //structure : ViewerTest_Names
1444 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
1445 //==============================================================================
1446 struct ViewerTest_Names
1449 TCollection_AsciiString myDriverName;
1450 TCollection_AsciiString myViewerName;
1451 TCollection_AsciiString myViewName;
1455 const TCollection_AsciiString& GetDriverName () const
1457 return myDriverName;
1459 void SetDriverName (const TCollection_AsciiString& theDriverName)
1461 myDriverName = theDriverName;
1463 const TCollection_AsciiString& GetViewerName () const
1465 return myViewerName;
1467 void SetViewerName (const TCollection_AsciiString& theViewerName)
1469 myViewerName = theViewerName;
1471 const TCollection_AsciiString& GetViewName () const
1475 void SetViewName (const TCollection_AsciiString& theViewName)
1477 myViewName = theViewName;
1480 //===========================================================================
1481 //function : Constructor for ViewerTest_Names
1482 //purpose : Get view, viewer, driver names from custom string
1483 //===========================================================================
1485 ViewerTest_Names (const TCollection_AsciiString& theInputString)
1487 TCollection_AsciiString aName(theInputString);
1488 if (theInputString.IsEmpty())
1490 // Get current configuration
1491 if (ViewerTest_myDrivers.IsEmpty())
1492 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1493 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1495 myDriverName = ViewerTest_myDrivers.Find2
1496 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1498 if(ViewerTest_myContexts.IsEmpty())
1500 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
1501 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
1505 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
1508 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
1512 // There is at least view name
1513 Standard_Integer aParserNumber = 0;
1514 for (Standard_Integer i = 0; i < 3; ++i)
1516 Standard_Integer aParserPos = aName.SearchFromEnd("/");
1517 if(aParserPos != -1)
1520 aName.Split(aParserPos-1);
1525 if (aParserNumber == 0)
1528 if (!ViewerTest::GetAISContext().IsNull())
1530 myDriverName = ViewerTest_myDrivers.Find2
1531 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1532 myViewerName = ViewerTest_myContexts.Find2
1533 (ViewerTest::GetAISContext());
1537 // There is no opened contexts here, need to create names for viewer and driver
1538 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1539 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1541 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
1542 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
1544 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
1546 else if (aParserNumber == 1)
1548 // Here is viewerName/viewName
1549 if (!ViewerTest::GetAISContext().IsNull())
1550 myDriverName = ViewerTest_myDrivers.Find2
1551 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1554 // There is no opened contexts here, need to create name for driver
1555 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1556 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1558 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
1560 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
1564 //Here is driverName/viewerName/viewName
1565 myDriverName = TCollection_AsciiString(aName);
1567 TCollection_AsciiString aViewerName(theInputString);
1568 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
1569 myViewerName = TCollection_AsciiString(aViewerName);
1571 myViewName = TCollection_AsciiString(theInputString);
1577 //==============================================================================
1578 //function : FindContextByView
1579 //purpose : Find AIS_InteractiveContext by View
1580 //==============================================================================
1582 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
1584 Handle(AIS_InteractiveContext) anAISContext;
1586 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1587 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
1589 if (anIter.Value()->CurrentViewer() == theView->Viewer())
1590 return anIter.Key2();
1592 return anAISContext;
1595 //==============================================================================
1596 //function : IsWindowOverlapped
1597 //purpose : Check if theWindow overlapp another view
1598 //==============================================================================
1600 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
1601 const Standard_Integer thePxTop,
1602 const Standard_Integer thePxRight,
1603 const Standard_Integer thePxBottom,
1604 TCollection_AsciiString& theViewId)
1606 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1607 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1609 Standard_Integer aTop = 0,
1613 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
1614 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
1615 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
1616 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
1617 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
1619 theViewId = anIter.Key1();
1620 return Standard_True;
1623 return Standard_False;
1626 // Workaround: to create and delete non-orthographic views outside ViewerTest
1627 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
1629 ViewerTest_myViews.UnBind1 (theName);
1632 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
1633 const Handle(V3d_View)& theView)
1635 ViewerTest_myViews.Bind (theName, theView);
1638 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
1640 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
1643 //! Auxiliary tool performing continuous redraws of specified window.
1644 class ViewerTest_ContinuousRedrawer
1647 //! Return global instance.
1648 static ViewerTest_ContinuousRedrawer& Instance()
1650 static ViewerTest_ContinuousRedrawer aRedrawer;
1656 ~ViewerTest_ContinuousRedrawer()
1662 void Start (const Handle(Aspect_Window)& theWindow,
1663 Standard_Real theTargetFps)
1665 if (myWindow != theWindow
1666 || myTargetFps != theTargetFps)
1669 myWindow = theWindow;
1670 myTargetFps = theTargetFps;
1672 if (myThread.GetId() == 0)
1675 myThread.Run (this);
1680 void Stop (const Handle(Aspect_Window)& theWindow = NULL)
1682 if (!theWindow.IsNull()
1683 && myWindow != theWindow)
1689 Standard_Mutex::Sentry aLock (myMutex);
1702 Handle(Aspect_DisplayConnection) aDisp = new Aspect_DisplayConnection();
1705 Standard_Real aTimeOld = 0.0;
1706 const Standard_Real aTargetDur = myTargetFps > 0.0 ? 1.0 / myTargetFps : -1.0;
1710 Standard_Mutex::Sentry aLock (myMutex);
1716 if (myTargetFps > 0.0)
1718 const Standard_Real aTimeNew = aTimer.ElapsedTime();
1719 const Standard_Real aDuration = aTimeNew - aTimeOld;
1720 if (aDuration >= aTargetDur)
1722 myWindow->InvalidateContent (aDisp);
1723 aTimeOld = aTimeNew;
1728 myWindow->InvalidateContent (aDisp);
1731 OSD::MilliSecSleep (1);
1735 //! Thread creation callback.
1736 static Standard_Address doThreadWrapper (Standard_Address theData)
1738 ViewerTest_ContinuousRedrawer* aThis = (ViewerTest_ContinuousRedrawer* )theData;
1739 aThis->doThreadLoop();
1743 //! Empty constructor.
1744 ViewerTest_ContinuousRedrawer()
1745 : myThread (doThreadWrapper),
1750 Handle(Aspect_Window) myWindow;
1751 OSD_Thread myThread;
1752 Standard_Mutex myMutex;
1753 Standard_Real myTargetFps;
1754 volatile bool myToStop;
1757 //==============================================================================
1758 //function : ViewerInit
1759 //purpose : Create the window viewer and initialize all the global variable
1760 //==============================================================================
1762 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
1763 const Standard_Integer thePxTop,
1764 const Standard_Integer thePxWidth,
1765 const Standard_Integer thePxHeight,
1766 const TCollection_AsciiString& theViewName,
1767 const TCollection_AsciiString& theDisplayName,
1768 const Handle(V3d_View)& theViewToClone)
1770 // Default position and dimension of the viewer window.
1771 // Note that left top corner is set to be sufficiently small to have
1772 // window fit in the small screens (actual for remote desktops, see #23003).
1773 // The position corresponds to the window's client area, thus some
1774 // gap is added for window frame to be visible.
1775 Standard_Integer aPxLeft = 20;
1776 Standard_Integer aPxTop = 40;
1777 Standard_Integer aPxWidth = 409;
1778 Standard_Integer aPxHeight = 409;
1779 Standard_Boolean toCreateViewer = Standard_False;
1780 if (!theViewToClone.IsNull())
1782 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
1785 Handle(OpenGl_GraphicDriver) aGraphicDriver;
1786 ViewerTest_Names aViewNames(theViewName);
1787 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
1788 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
1791 aPxLeft = thePxLeft;
1794 if (thePxWidth != 0)
1795 aPxWidth = thePxWidth;
1796 if (thePxHeight != 0)
1797 aPxHeight = thePxHeight;
1799 // Get graphic driver (create it or get from another view)
1800 const bool isNewDriver = !ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName());
1803 // Get connection string
1804 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1805 if (!theDisplayName.IsEmpty())
1807 SetDisplayConnection (new Aspect_DisplayConnection (theDisplayName));
1811 ::Display* aDispX = NULL;
1812 // create dedicated display connection instead of reusing Tk connection
1813 // so that to procede events independently through VProcessEvents()/ViewerMainLoop() callbacks
1814 /*Draw_Interpretor& aCommands = Draw::GetInterpretor();
1815 Tcl_Interp* aTclInterp = aCommands.Interp();
1816 Tk_Window aMainWindow = Tk_MainWindow (aTclInterp);
1817 aDispX = aMainWindow != NULL ? Tk_Display (aMainWindow) : NULL;*/
1818 SetDisplayConnection (new Aspect_DisplayConnection (aDispX));
1821 (void)theDisplayName; // avoid warning on unused argument
1822 SetDisplayConnection (new Aspect_DisplayConnection ());
1825 if (Draw_VirtualWindows)
1827 // don't waste the time waiting for VSync when window is not displayed on the screen
1828 ViewerTest_myDefaultCaps.swapInterval = 0;
1829 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
1830 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
1832 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection(), false);
1833 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
1834 aGraphicDriver->InitContext();
1836 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
1837 toCreateViewer = Standard_True;
1841 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
1844 //Dispose the window if input parameters are default
1845 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
1847 Standard_Integer aTop = 0,
1854 // Get screen resolution
1855 #if defined(_WIN32) || defined(__WIN32__)
1857 GetClientRect(GetDesktopWindow(), &aWindowSize);
1858 aScreenHeight = aWindowSize.bottom;
1859 aScreenWidth = aWindowSize.right;
1860 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1861 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
1863 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
1864 aScreenWidth = WidthOfScreen(aScreen);
1865 aScreenHeight = HeightOfScreen(aScreen);
1868 TCollection_AsciiString anOverlappedViewId("");
1870 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
1872 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
1874 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
1875 && aRight + 2*aPxWidth + 40 > aScreenWidth)
1877 if (aBottom + aPxHeight + 40 > aScreenHeight)
1884 aPxTop = aBottom + 40;
1887 aPxLeft = aRight + 20;
1892 TCollection_AsciiString aTitle("3D View - ");
1893 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
1895 // Change name of current active window
1896 if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView())
1898 aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView));
1902 Handle(V3d_Viewer) a3DViewer;
1903 // If it's the single view, we first look for empty context
1904 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
1906 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1907 anIter(ViewerTest_myContexts);
1909 ViewerTest::SetAISContext (anIter.Value());
1910 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
1912 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
1914 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
1915 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
1917 else if (a3DViewer.IsNull())
1919 toCreateViewer = Standard_True;
1920 a3DViewer = new V3d_Viewer(aGraphicDriver);
1921 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
1922 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
1923 ViewerTest_DefaultBackground.GradientColor2,
1924 ViewerTest_DefaultBackground.FillMethod);
1927 // AIS context setup
1928 if (ViewerTest::GetAISContext().IsNull() ||
1929 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
1931 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
1932 ViewerTest::SetAISContext (aContext);
1933 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
1937 ViewerTest::ResetEventManager();
1942 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
1943 Handle(WNT_WClass)::DownCast (WClass()),
1944 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
1946 aPxWidth, aPxHeight,
1947 Quantity_NOC_BLACK);
1948 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1949 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
1951 aPxWidth, aPxHeight);
1952 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
1954 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
1957 aPxWidth, aPxHeight);
1959 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
1962 Handle(V3d_View) aView;
1963 if (!theViewToClone.IsNull())
1965 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
1969 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
1972 aView->SetWindow (VT_GetWindow());
1973 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
1975 ViewerTest::CurrentView(aView);
1976 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
1978 // Setup for X11 or NT
1981 // Set parameters for V3d_View and V3d_Viewer
1982 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
1983 aV3dView->SetComputedMode(Standard_False);
1985 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
1988 a3DViewer->SetDefaultLights();
1989 a3DViewer->SetLightOn();
1992 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1995 ::Display* aDispX = GetDisplayConnection()->GetDisplay();
1996 Tcl_CreateFileHandler (XConnectionNumber (aDispX), TCL_READABLE, VProcessEvents, (ClientData )aDispX);
2000 VT_GetWindow()->Map();
2002 // Set the handle of created view in the event manager
2003 ViewerTest::ResetEventManager();
2005 ViewerTest::CurrentView()->Redraw();
2008 a3DViewer.Nullify();
2010 return aViewNames.GetViewName();
2013 //==============================================================================
2014 //function : RedrawAllViews
2015 //purpose : Redraw all created views
2016 //==============================================================================
2017 void ViewerTest::RedrawAllViews()
2019 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
2020 for (; aViewIt.More(); aViewIt.Next())
2022 const Handle(V3d_View)& aView = aViewIt.Key2();
2027 //==============================================================================
2029 //purpose : Create the window viewer and initialize all the global variable
2030 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
2031 //==============================================================================
2033 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2035 TCollection_AsciiString aViewName, aDisplayName;
2036 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
2037 Handle(V3d_View) aCopyFrom;
2038 TCollection_AsciiString aName, aValue;
2040 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2042 const TCollection_AsciiString anArg = theArgVec[anArgIt];
2043 TCollection_AsciiString anArgCase = anArg;
2044 anArgCase.LowerCase();
2045 if (anArgIt + 1 < theArgsNb
2046 && anArgCase == "-name")
2048 aViewName = theArgVec[++anArgIt];
2050 else if (anArgIt + 1 < theArgsNb
2051 && (anArgCase == "-left"
2052 || anArgCase == "-l"))
2054 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
2056 else if (anArgIt + 1 < theArgsNb
2057 && (anArgCase == "-top"
2058 || anArgCase == "-t"))
2060 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
2062 else if (anArgIt + 1 < theArgsNb
2063 && (anArgCase == "-width"
2064 || anArgCase == "-w"))
2066 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
2068 else if (anArgIt + 1 < theArgsNb
2069 && (anArgCase == "-height"
2070 || anArgCase == "-h"))
2072 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
2074 else if (anArgCase == "-exitonclose")
2076 ViewerTest_EventManager::ToExitOnCloseView() = true;
2077 if (anArgIt + 1 < theArgsNb
2078 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToExitOnCloseView()))
2083 else if (anArgCase == "-closeonescape"
2084 || anArgCase == "-closeonesc")
2086 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
2087 if (anArgIt + 1 < theArgsNb
2088 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
2093 else if (anArgCase == "-2d_mode"
2094 || anArgCase == "-2dmode"
2095 || anArgCase == "-2d")
2097 bool toEnable = true;
2098 if (anArgIt + 1 < theArgsNb
2099 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
2103 is2dMode = toEnable ? 1 : 0;
2105 else if (anArgIt + 1 < theArgsNb
2106 && (anArgCase == "-disp"
2107 || anArgCase == "-display"))
2109 aDisplayName = theArgVec[++anArgIt];
2111 else if (!ViewerTest::CurrentView().IsNull()
2112 && aCopyFrom.IsNull()
2113 && (anArgCase == "-copy"
2114 || anArgCase == "-clone"
2115 || anArgCase == "-cloneactive"
2116 || anArgCase == "-cloneactiveview"))
2118 aCopyFrom = ViewerTest::CurrentView();
2121 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
2124 if (aName == "name")
2128 else if (aName == "l"
2131 aPxLeft = aValue.IntegerValue();
2133 else if (aName == "t"
2136 aPxTop = aValue.IntegerValue();
2138 else if (aName == "disp"
2139 || aName == "display")
2141 aDisplayName = aValue;
2143 else if (aName == "w"
2144 || aName == "width")
2146 aPxWidth = aValue.IntegerValue();
2148 else if (aName == "h"
2149 || aName == "height")
2151 aPxHeight = aValue.IntegerValue();
2155 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
2159 else if (aViewName.IsEmpty())
2165 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
2170 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
2171 if (!aDisplayName.IsEmpty())
2173 aDisplayName.Clear();
2174 std::cout << "Warning: display parameter will be ignored.\n";
2178 ViewerTest_Names aViewNames (aViewName);
2179 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
2181 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
2182 theDi.Eval (aCommand.ToCString());
2185 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
2190 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
2191 aViewName, aDisplayName, aCopyFrom);
2194 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
2200 //! Parse HLR algo type.
2201 static Standard_Boolean parseHlrAlgoType (const char* theName,
2202 Prs3d_TypeOfHLR& theType)
2204 TCollection_AsciiString aName (theName);
2206 if (aName == "polyalgo")
2208 theType = Prs3d_TOH_PolyAlgo;
2210 else if (aName == "algo")
2212 theType = Prs3d_TOH_Algo;
2216 return Standard_False;
2218 return Standard_True;
2221 //==============================================================================
2223 //purpose : hidden lines removal algorithm
2224 //==============================================================================
2226 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2228 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2229 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2232 std::cerr << "Error: No opened viewer!\n";
2236 Standard_Boolean hasHlrOnArg = Standard_False;
2237 Standard_Boolean hasShowHiddenArg = Standard_False;
2238 Standard_Boolean isHLROn = Standard_False;
2239 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
2240 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
2241 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2242 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
2244 TCollection_AsciiString anArg (argv[anArgIter]);
2246 if (anUpdateTool.parseRedrawMode (anArg))
2250 else if (anArg == "-showhidden"
2251 && anArgIter + 1 < argc
2252 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
2255 hasShowHiddenArg = Standard_True;
2258 else if ((anArg == "-type"
2260 || anArg == "-algotype")
2261 && anArgIter + 1 < argc
2262 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
2267 else if (!hasHlrOnArg
2268 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
2270 hasHlrOnArg = Standard_True;
2274 else if (!hasShowHiddenArg
2275 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
2277 hasShowHiddenArg = Standard_True;
2282 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
2288 di << "HLR: " << aView->ComputedMode() << "\n";
2289 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
2291 switch (aCtx->DefaultDrawer()->TypeOfHLR())
2293 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
2294 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
2295 case Prs3d_TOH_Algo: di << "Algo\n"; break;
2297 anUpdateTool.Invalidate();
2301 Standard_Boolean toRecompute = Standard_False;
2302 if (aTypeOfHLR != Prs3d_TOH_NotSet
2303 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
2305 toRecompute = Standard_True;
2306 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
2308 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
2310 toRecompute = Standard_True;
2313 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
2317 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
2322 if (aView->ComputedMode() && isHLROn && toRecompute)
2324 AIS_ListOfInteractive aListOfShapes;
2325 aCtx->DisplayedObjects (aListOfShapes);
2326 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
2328 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
2330 aCtx->Redisplay (aShape, Standard_False);
2335 aView->SetComputedMode (isHLROn);
2339 //==============================================================================
2340 //function : VHLRType
2341 //purpose : change type of using HLR algorithm
2342 //==============================================================================
2344 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
2346 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2347 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2350 std::cerr << "Error: No opened viewer!\n";
2354 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
2355 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2356 AIS_ListOfInteractive aListOfShapes;
2357 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
2359 TCollection_AsciiString anArg (argv[anArgIter]);
2361 if (anUpdateTool.parseRedrawMode (anArg))
2365 else if ((anArg == "-type"
2367 || anArg == "-algotype")
2368 && anArgIter + 1 < argc
2369 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
2375 else if (aTypeOfHLR == Prs3d_TOH_NotSet
2376 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
2382 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
2383 TCollection_AsciiString aName (argv[anArgIter]);
2384 if (!aMap.IsBound2 (aName))
2386 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
2390 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
2391 if (aShape.IsNull())
2393 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
2396 aListOfShapes.Append (aShape);
2400 if (aTypeOfHLR == Prs3d_TOH_NotSet)
2402 std::cout << "Syntax error: wrong number of arguments!\n";
2406 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
2409 aCtx->DisplayedObjects (aListOfShapes);
2410 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
2413 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
2415 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
2416 if (aShape.IsNull())
2421 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
2422 && aView->ComputedMode();
2424 || aShape->TypeOfHLR() != aTypeOfHLR)
2426 aShape->SetTypeOfHLR (aTypeOfHLR);
2430 aCtx->Redisplay (aShape, Standard_False);
2436 //==============================================================================
2437 //function : FindViewIdByWindowHandle
2438 //purpose : Find theView Id in the map of views by window handle
2439 //==============================================================================
2440 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2441 TCollection_AsciiString FindViewIdByWindowHandle (Aspect_Drawable theWindowHandle)
2443 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
2444 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
2446 Aspect_Drawable aWindowHandle = anIter.Value()->Window()->NativeHandle();
2447 if (aWindowHandle == theWindowHandle)
2448 return anIter.Key1();
2450 return TCollection_AsciiString("");
2454 //! Make the view active
2455 void ActivateView (const TCollection_AsciiString& theViewName,
2456 Standard_Boolean theToUpdate = Standard_True)
2458 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
2464 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
2465 if (!anAISContext.IsNull())
2467 if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView())
2469 aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView));
2472 ViewerTest::CurrentView (aView);
2473 ViewerTest::SetAISContext (anAISContext);
2474 aView->Window()->SetTitle (TCollection_AsciiString("3D View - ") + theViewName + "(*)");
2476 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
2477 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
2478 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
2480 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
2482 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2485 ViewerTest::CurrentView()->Redraw();
2490 //==============================================================================
2491 //function : RemoveView
2493 //==============================================================================
2494 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
2495 const Standard_Boolean theToRemoveContext)
2497 if (!ViewerTest_myViews.IsBound2 (theView))
2502 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
2503 RemoveView (aViewName, theToRemoveContext);
2506 //==============================================================================
2507 //function : RemoveView
2508 //purpose : Close and remove view from display, clear maps if neccessary
2509 //==============================================================================
2510 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
2512 if (!ViewerTest_myViews.IsBound1(theViewName))
2514 std::cout << "Wrong view name\n";
2518 // Activate another view if it's active now
2519 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
2521 if (ViewerTest_myViews.Extent() > 1)
2523 TCollection_AsciiString aNewViewName;
2524 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
2525 anIter.More(); anIter.Next())
2527 if (anIter.Key1() != theViewName)
2529 aNewViewName = anIter.Key1();
2533 ActivateView (aNewViewName);
2537 VT_GetWindow().Nullify();
2538 ViewerTest::CurrentView (Handle(V3d_View)());
2539 if (isContextRemoved)
2541 Handle(AIS_InteractiveContext) anEmptyContext;
2542 ViewerTest::SetAISContext(anEmptyContext);
2548 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
2549 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
2550 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
2551 aRedrawer.Stop (aView->Window());
2553 // Remove view resources
2554 ViewerTest_myViews.UnBind1(theViewName);
2555 aView->Window()->Unmap();
2558 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2559 XFlush (GetDisplayConnection()->GetDisplay());
2562 // Keep context opened only if the closed view is last to avoid
2563 // unused empty contexts
2564 if (!aCurrentContext.IsNull())
2566 // Check if there are more difined views in the viewer
2567 aCurrentContext->CurrentViewer()->InitDefinedViews();
2568 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
2570 // Remove driver if there is no viewers that use it
2571 Standard_Boolean isRemoveDriver = Standard_True;
2572 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2573 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
2575 if (aCurrentContext != anIter.Key2() &&
2576 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
2578 isRemoveDriver = Standard_False;
2583 aCurrentContext->RemoveAll (Standard_False);
2586 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
2587 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2588 Tcl_DeleteFileHandler (XConnectionNumber (aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
2592 ViewerTest_myContexts.UnBind2(aCurrentContext);
2595 std::cout << "3D View - " << theViewName << " was deleted.\n";
2596 if (ViewerTest_EventManager::ToExitOnCloseView())
2598 Draw_Interprete ("exit");
2602 //==============================================================================
2604 //purpose : Remove the view defined by its name
2605 //==============================================================================
2607 static int VClose (Draw_Interpretor& /*theDi*/,
2608 Standard_Integer theArgsNb,
2609 const char** theArgVec)
2611 NCollection_List<TCollection_AsciiString> aViewList;
2614 TCollection_AsciiString anArg (theArgVec[1]);
2616 if (anArg.IsEqual ("ALL")
2617 || anArg.IsEqual ("*"))
2619 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
2620 anIter.More(); anIter.Next())
2622 aViewList.Append (anIter.Key1());
2624 if (aViewList.IsEmpty())
2626 std::cout << "No view to close\n";
2632 ViewerTest_Names aViewName (theArgVec[1]);
2633 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
2635 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
2638 aViewList.Append (aViewName.GetViewName());
2643 // close active view
2644 if (ViewerTest::CurrentView().IsNull())
2646 std::cerr << "No active view!\n";
2649 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
2652 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
2653 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
2654 anIter.More(); anIter.Next())
2656 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
2662 //==============================================================================
2663 //function : VActivate
2664 //purpose : Activate the view defined by its ID
2665 //==============================================================================
2667 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2671 theDi.Eval("vviewlist");
2675 TCollection_AsciiString aNameString;
2676 Standard_Boolean toUpdate = Standard_True;
2677 Standard_Boolean toActivate = Standard_True;
2678 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
2680 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2683 && anArg == "-noupdate")
2685 toUpdate = Standard_False;
2688 && aNameString.IsEmpty()
2691 ViewerTest::CurrentView()->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
2692 VT_GetWindow().Nullify();
2693 ViewerTest::CurrentView (Handle(V3d_View)());
2694 ViewerTest::ResetEventManager();
2695 theDi << theArgVec[0] << ": all views are inactive\n";
2696 toActivate = Standard_False;
2699 && aNameString.IsEmpty())
2701 aNameString = theArgVec[anArgIter];
2705 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
2714 else if (aNameString.IsEmpty())
2716 std::cout << "Syntax error: wrong number of arguments\n";
2720 // Check if this view exists in the viewer with the driver
2721 ViewerTest_Names aViewNames (aNameString);
2722 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
2724 theDi << "Syntax error: wrong view name '" << aNameString << "'\n";
2728 // Check if it is active already
2729 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
2731 theDi << theArgVec[0] << ": the view is active already\n";
2735 ActivateView (aViewNames.GetViewName(), toUpdate);
2739 //==============================================================================
2740 //function : VViewList
2741 //purpose : Print current list of views per viewer and graphic driver ID
2742 // shared between viewers
2743 //==============================================================================
2745 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2749 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
2750 << "Usage: " << theArgVec[0] << " name";
2753 if (ViewerTest_myContexts.Size() < 1)
2756 Standard_Boolean isTreeView =
2757 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
2761 theDi << theArgVec[0] <<":\n";
2764 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
2765 aDriverIter.More(); aDriverIter.Next())
2768 theDi << aDriverIter.Key1() << ":\n";
2770 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2771 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
2773 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
2777 TCollection_AsciiString aContextName(aContextIter.Key1());
2778 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
2781 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
2782 aViewIter.More(); aViewIter.Next())
2784 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
2786 TCollection_AsciiString aViewName(aViewIter.Key1());
2789 if (aViewIter.Value() == ViewerTest::CurrentView())
2790 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
2792 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
2796 theDi << aViewName << " ";
2806 //==============================================================================
2807 //function : GetMousePosition
2809 //==============================================================================
2810 void ViewerTest::GetMousePosition (Standard_Integer& theX,
2811 Standard_Integer& theY)
2813 if (Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager())
2815 theX = aViewCtrl->LastMousePosition().x();
2816 theY = aViewCtrl->LastMousePosition().y();
2820 //==============================================================================
2821 //function : VViewProj
2822 //purpose : Switch view projection
2823 //==============================================================================
2824 static int VViewProj (Draw_Interpretor& ,
2825 Standard_Integer theNbArgs,
2826 const char** theArgVec)
2828 static Standard_Boolean isYup = Standard_False;
2829 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2832 std::cout << "Error: no active view\n";
2836 TCollection_AsciiString aCmdName (theArgVec[0]);
2837 Standard_Boolean isGeneralCmd = Standard_False;
2838 if (aCmdName == "vfront")
2840 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup);
2842 else if (aCmdName == "vback")
2844 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup);
2846 else if (aCmdName == "vtop")
2848 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup);
2850 else if (aCmdName == "vbottom")
2852 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup);
2854 else if (aCmdName == "vleft")
2856 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup);
2858 else if (aCmdName == "vright")
2860 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup);
2862 else if (aCmdName == "vaxo")
2864 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup);
2868 isGeneralCmd = Standard_True;
2869 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
2871 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2872 anArgCase.LowerCase();
2873 if (anArgCase == "-zup")
2875 isYup = Standard_False;
2877 else if (anArgCase == "-yup")
2879 isYup = Standard_True;
2881 else if (anArgCase == "-front"
2882 || anArgCase == "front"
2883 || anArgCase == "-f"
2884 || anArgCase == "f")
2886 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup);
2888 else if (anArgCase == "-back"
2889 || anArgCase == "back"
2890 || anArgCase == "-b"
2891 || anArgCase == "b")
2893 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup);
2895 else if (anArgCase == "-top"
2896 || anArgCase == "top"
2897 || anArgCase == "-t"
2898 || anArgCase == "t")
2900 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup);
2902 else if (anArgCase == "-bottom"
2903 || anArgCase == "bottom"
2904 || anArgCase == "-bot"
2905 || anArgCase == "bot"
2906 || anArgCase == "-b"
2907 || anArgCase == "b")
2909 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup);
2911 else if (anArgCase == "-left"
2912 || anArgCase == "left"
2913 || anArgCase == "-l"
2914 || anArgCase == "l")
2916 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup);
2918 else if (anArgCase == "-right"
2919 || anArgCase == "right"
2920 || anArgCase == "-r"
2921 || anArgCase == "r")
2923 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup);
2925 else if (anArgCase == "-axoleft"
2926 || anArgCase == "-leftaxo"
2927 || anArgCase == "axoleft"
2928 || anArgCase == "leftaxo")
2930 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoLeft : V3d_TypeOfOrientation_Zup_AxoLeft, isYup);
2932 else if (anArgCase == "-axo"
2933 || anArgCase == "axo"
2934 || anArgCase == "-a"
2936 || anArgCase == "-axoright"
2937 || anArgCase == "-rightaxo"
2938 || anArgCase == "axoright"
2939 || anArgCase == "rightaxo")
2941 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup);
2943 else if (anArgCase == "+x")
2945 aView->SetProj (V3d_Xpos, isYup);
2947 else if (anArgCase == "-x")
2949 aView->SetProj (V3d_Xneg, isYup);
2951 else if (anArgCase == "+y")
2953 aView->SetProj (V3d_Ypos, isYup);
2955 else if (anArgCase == "-y")
2957 aView->SetProj (V3d_Yneg, isYup);
2959 else if (anArgCase == "+z")
2961 aView->SetProj (V3d_Zpos, isYup);
2963 else if (anArgCase == "-z")
2965 aView->SetProj (V3d_Zneg, isYup);
2967 else if (anArgCase == "+x+y+z")
2969 aView->SetProj (V3d_XposYposZpos, isYup);
2971 else if (anArgCase == "+x+y-z")
2973 aView->SetProj (V3d_XposYposZneg, isYup);
2975 else if (anArgCase == "+x-y+z")
2977 aView->SetProj (V3d_XposYnegZpos, isYup);
2979 else if (anArgCase == "+x-y-z")
2981 aView->SetProj (V3d_XposYnegZneg, isYup);
2983 else if (anArgCase == "-x+y+z")
2985 aView->SetProj (V3d_XnegYposZpos, isYup);
2987 else if (anArgCase == "-x+y-z")
2989 aView->SetProj (V3d_XnegYposZneg, isYup);
2991 else if (anArgCase == "-x-y+z")
2993 aView->SetProj (V3d_XnegYnegZpos, isYup);
2995 else if (anArgCase == "-x-y-z")
2997 aView->SetProj (V3d_XnegYnegZneg, isYup);
2999 else if (anArgCase == "+x+y")
3001 aView->SetProj (V3d_XposYpos, isYup);
3003 else if (anArgCase == "+x-y")
3005 aView->SetProj (V3d_XposYneg, isYup);
3007 else if (anArgCase == "-x+y")
3009 aView->SetProj (V3d_XnegYpos, isYup);
3011 else if (anArgCase == "-x-y")
3013 aView->SetProj (V3d_XnegYneg, isYup);
3015 else if (anArgCase == "+x+z")
3017 aView->SetProj (V3d_XposZpos, isYup);
3019 else if (anArgCase == "+x-z")
3021 aView->SetProj (V3d_XposZneg, isYup);
3023 else if (anArgCase == "-x+z")
3025 aView->SetProj (V3d_XnegZpos, isYup);
3027 else if (anArgCase == "-x-z")
3029 aView->SetProj (V3d_XnegZneg, isYup);
3031 else if (anArgCase == "+y+z")
3033 aView->SetProj (V3d_YposZpos, isYup);
3035 else if (anArgCase == "+y-z")
3037 aView->SetProj (V3d_YposZneg, isYup);
3039 else if (anArgCase == "-y+z")
3041 aView->SetProj (V3d_YnegZpos, isYup);
3043 else if (anArgCase == "-y-z")
3045 aView->SetProj (V3d_YnegZneg, isYup);
3047 else if (anArgIter + 1 < theNbArgs
3048 && anArgCase == "-frame"
3049 && TCollection_AsciiString (theArgVec[anArgIter + 1]).Length() == 4)
3051 TCollection_AsciiString aFrameDef (theArgVec[++anArgIter]);
3052 aFrameDef.LowerCase();
3053 gp_Dir aRight, anUp;
3054 if (aFrameDef.Value (2) == aFrameDef.Value (4))
3056 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3060 if (aFrameDef.Value (2) == 'x')
3062 aRight = aFrameDef.Value (1) == '+' ? gp::DX() : -gp::DX();
3064 else if (aFrameDef.Value (2) == 'y')
3066 aRight = aFrameDef.Value (1) == '+' ? gp::DY() : -gp::DY();
3068 else if (aFrameDef.Value (2) == 'z')
3070 aRight = aFrameDef.Value (1) == '+' ? gp::DZ() : -gp::DZ();
3074 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3078 if (aFrameDef.Value (4) == 'x')
3080 anUp = aFrameDef.Value (3) == '+' ? gp::DX() : -gp::DX();
3082 else if (aFrameDef.Value (4) == 'y')
3084 anUp = aFrameDef.Value (3) == '+' ? gp::DY() : -gp::DY();
3086 else if (aFrameDef.Value (4) == 'z')
3088 anUp = aFrameDef.Value (3) == '+' ? gp::DZ() : -gp::DZ();
3092 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3096 const Handle(Graphic3d_Camera)& aCamera = aView->Camera();
3097 const gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin());
3098 const gp_Dir aDir = anUp.Crossed (aRight);
3099 aCamera->SetCenter (gp_Pnt (0, 0, 0));
3100 aCamera->SetDirection (aDir);
3101 aCamera->SetUp (anUp);
3102 aCamera->OrthogonalizeUp();
3104 aView->Panning (anOriginVCS.X(), anOriginVCS.Y());
3109 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3118 std::cout << "Syntax error: wrong number of arguments\n";
3124 //==============================================================================
3126 //purpose : Dsiplay help on viewer Keyboead and mouse commands
3127 //Draw arg : No args
3128 //==============================================================================
3130 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
3132 di << "=========================\n";
3133 di << "F : FitAll\n";
3134 di << "T : TopView\n";
3135 di << "B : BottomView\n";
3136 di << "R : RightView\n";
3137 di << "L : LeftView\n";
3138 di << "A : AxonometricView\n";
3139 di << "D : ResetView\n";
3141 di << "=========================\n";
3142 di << "S : Shading\n";
3143 di << "W : Wireframe\n";
3144 di << "H : HiddenLineRemoval\n";
3145 di << "U : Unset display mode\n";
3146 di << "Delete : Remove selection from viewer\n";
3148 di << "=========================\n";
3149 di << "Selection mode \n";
3150 di << "0 : Shape\n";
3151 di << "1 : Vertex\n";
3155 di << "5 : Shell\n";
3156 di << "6 : Solid\n";
3157 di << "7 : Compound\n";
3159 di << "=========================\n";
3160 di << "< : Hilight next detected\n";
3161 di << "> : Hilight previous detected\n";
3168 static LRESULT WINAPI AdvViewerWindowProc (HWND theWinHandle,
3173 if (ViewerTest_myViews.IsEmpty())
3175 return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam);
3182 // Delete view from map of views
3183 ViewerTest::RemoveView (FindViewIdByWindowHandle (theWinHandle));
3188 if (LOWORD(wParam) == WA_CLICKACTIVE
3189 || LOWORD(wParam) == WA_ACTIVE
3190 || ViewerTest::CurrentView().IsNull())
3192 // Activate inactive window
3193 if (VT_GetWindow().IsNull()
3194 || (HWND )VT_GetWindow()->HWindow() != theWinHandle)
3196 ActivateView (FindViewIdByWindowHandle (theWinHandle));
3203 return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam);
3209 static LRESULT WINAPI ViewerWindowProc (HWND theWinHandle,
3214 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3217 return DefWindowProcW (theWinHandle, theMsg, wParam, lParam);
3225 BeginPaint(theWinHandle, &aPaint);
3226 EndPaint (theWinHandle, &aPaint);
3227 ViewerTest::CurrentEventManager()->ProcessExpose();
3232 ViewerTest::CurrentEventManager()->ProcessConfigure();
3239 switch (aView->RenderingParams().StereoMode)
3241 case Graphic3d_StereoMode_RowInterlaced:
3242 case Graphic3d_StereoMode_ColumnInterlaced:
3243 case Graphic3d_StereoMode_ChessBoard:
3245 // track window moves to reverse stereo pair
3246 aView->MustBeResized();
3258 const Aspect_VKey aVKey = WNT_Window::VirtualKeyFromNative ((Standard_Integer )wParam);
3259 if (aVKey != Aspect_VKey_UNKNOWN)
3261 const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime();
3262 if (theMsg == WM_KEYDOWN)
3264 ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp);
3268 ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp);
3270 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3277 case WM_LBUTTONDOWN:
3278 case WM_MBUTTONDOWN:
3279 case WM_RBUTTONDOWN:
3281 const Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam));
3282 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam);
3283 Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE;
3287 case WM_LBUTTONDOWN:
3288 aButton = Aspect_VKeyMouse_LeftButton;
3291 case WM_MBUTTONDOWN:
3292 aButton = Aspect_VKeyMouse_MiddleButton;
3295 case WM_RBUTTONDOWN:
3296 aButton = Aspect_VKeyMouse_RightButton;
3299 if (theMsg == WM_LBUTTONDOWN
3300 || theMsg == WM_MBUTTONDOWN
3301 || theMsg == WM_RBUTTONDOWN)
3303 if (aButton == Aspect_VKeyMouse_LeftButton)
3305 TheIsAnimating = Standard_False;
3308 SetFocus (theWinHandle);
3309 SetCapture(theWinHandle);
3310 ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false);
3315 ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false);
3317 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3322 const int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
3323 const Standard_Real aDeltaF = Standard_Real(aDelta) / Standard_Real(WHEEL_DELTA);
3324 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam);
3325 Graphic3d_Vec2i aPos (int(short(LOWORD(lParam))), int(short(HIWORD(lParam))));
3326 POINT aCursorPnt = { aPos.x(), aPos.y() };
3327 if (ScreenToClient (theWinHandle, &aCursorPnt))
3329 aPos.SetValues (aCursorPnt.x, aCursorPnt.y);
3332 ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags));
3333 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3338 Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam));
3339 Aspect_VKeyMouse aButtons = WNT_Window::MouseButtonsFromEvent (wParam);
3340 Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent(wParam);
3342 // don't make a slide-show from input events - fetch the actual mouse cursor position
3344 aCursor.cbSize = sizeof(aCursor);
3345 if (::GetCursorInfo (&aCursor) != FALSE)
3347 POINT aCursorPnt = { aCursor.ptScreenPos.x, aCursor.ptScreenPos.y };
3348 if (ScreenToClient (theWinHandle, &aCursorPnt))
3350 // as we override mouse position, we need overriding also mouse state
3351 aPos.SetValues (aCursorPnt.x, aCursorPnt.y);
3352 aButtons = WNT_Window::MouseButtonsAsync();
3353 aFlags = WNT_Window::MouseKeyFlagsAsync();
3357 if (VT_GetWindow().IsNull()
3358 || (HWND )VT_GetWindow()->HWindow() != theWinHandle)
3360 // mouse move events come also for inactive windows
3364 ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
3365 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
3370 return DefWindowProcW (theWinHandle, theMsg, wParam, lParam);
3376 //==============================================================================
3377 //function : ViewerMainLoop
3378 //purpose : Get a Event on the view and dispatch it
3379 //==============================================================================
3381 int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec)
3383 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
3384 if (aViewCtrl.IsNull()
3390 aViewCtrl->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]);
3392 std::cout << "Start picking\n";
3396 while (aViewCtrl->ToPickPoint())
3398 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
3399 if (GetMessageW (&aMsg, NULL, 0, 0))
3401 TranslateMessage (&aMsg);
3402 DispatchMessageW (&aMsg);
3406 std::cout << "Picking done\n";
3410 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
3412 int min( int a, int b )
3420 int max( int a, int b )
3428 int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec)
3430 static XEvent aReport;
3431 const Standard_Boolean toPick = theNbArgs > 0;
3434 if (ViewerTest::CurrentEventManager().IsNull())
3438 ViewerTest::CurrentEventManager()->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]);
3441 Display* aDisplay = GetDisplayConnection()->GetDisplay();
3442 XNextEvent (aDisplay, &aReport);
3444 // Handle event for the chosen display connection
3445 switch (aReport.type)
3449 if ((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
3452 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
3453 return toPick ? 0 : 1;
3459 // Activate inactive view
3460 Window aWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3461 if (aWindow != aReport.xfocus.window)
3463 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
3469 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3470 if (anXWindow == aReport.xexpose.window)
3472 ViewerTest::CurrentEventManager()->ProcessExpose();
3475 // remove all the ExposureMask and process them at once
3476 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3478 if (!XCheckWindowEvent (aDisplay, anXWindow, ExposureMask, &aReport))
3486 case ConfigureNotify:
3488 // remove all the StructureNotifyMask and process them at once
3489 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3490 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3492 if (!XCheckWindowEvent (aDisplay, anXWindow, StructureNotifyMask, &aReport))
3498 if (anXWindow == aReport.xconfigure.window)
3500 ViewerTest::CurrentEventManager()->ProcessConfigure();
3507 XKeyEvent* aKeyEvent = (XKeyEvent* )&aReport;
3508 const KeySym aKeySym = XLookupKeysym (aKeyEvent, 0);
3509 const Aspect_VKey aVKey = Xw_Window::VirtualKeyFromNative (aKeySym);
3510 if (aVKey != Aspect_VKey_UNKNOWN)
3512 const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime();
3513 if (aReport.type == KeyPress)
3515 ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp);
3519 ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp);
3521 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3528 const Graphic3d_Vec2i aPos (aReport.xbutton.x, aReport.xbutton.y);
3529 Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
3530 Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE;
3531 if (aReport.xbutton.button == Button1)
3533 aButton = Aspect_VKeyMouse_LeftButton;
3535 if (aReport.xbutton.button == Button2)
3537 aButton = Aspect_VKeyMouse_MiddleButton;
3539 if (aReport.xbutton.button == Button3)
3541 aButton = Aspect_VKeyMouse_RightButton;
3544 if (aReport.xbutton.state & ControlMask)
3546 aFlags |= Aspect_VKeyFlags_CTRL;
3548 if (aReport.xbutton.state & ShiftMask)
3550 aFlags |= Aspect_VKeyFlags_SHIFT;
3552 if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt))
3554 aFlags |= Aspect_VKeyFlags_ALT;
3557 if (aReport.xbutton.button == Button4
3558 || aReport.xbutton.button == Button5)
3560 if (aReport.type != ButtonPress)
3565 const double aDeltaF = (aReport.xbutton.button == Button4 ? 1.0 : -1.0);
3566 ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags));
3568 else if (aReport.type == ButtonPress)
3570 if (aButton == Aspect_VKeyMouse_LeftButton)
3572 TheIsAnimating = Standard_False;
3574 ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false);
3578 ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false);
3580 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3585 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3586 if (anXWindow != aReport.xmotion.window)
3591 // remove all the ButtonMotionMask and process them at once
3592 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3594 if (!XCheckWindowEvent (aDisplay, anXWindow, ButtonMotionMask | PointerMotionMask, &aReport))
3600 Graphic3d_Vec2i aPos (aReport.xmotion.x, aReport.xmotion.y);
3601 Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
3602 Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
3603 if ((aReport.xmotion.state & Button1Mask) != 0)
3605 aButtons |= Aspect_VKeyMouse_LeftButton;
3607 else if ((aReport.xmotion.state & Button2Mask) != 0)
3609 aButtons |= Aspect_VKeyMouse_MiddleButton;
3611 else if ((aReport.xmotion.state & Button3Mask) != 0)
3613 aButtons |= Aspect_VKeyMouse_RightButton;
3616 if (aReport.xmotion.state & ControlMask)
3618 aFlags |= Aspect_VKeyFlags_CTRL;
3620 if (aReport.xmotion.state & ShiftMask)
3622 aFlags |= Aspect_VKeyFlags_SHIFT;
3624 if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt))
3626 aFlags |= Aspect_VKeyFlags_ALT;
3629 ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
3630 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3634 return (!toPick || ViewerTest::CurrentEventManager()->ToPickPoint()) ? 1 : 0;
3637 //==============================================================================
3638 //function : VProcessEvents
3639 //purpose : manage the event in the Viewer window (see Tcl_CreateFileHandler())
3640 //==============================================================================
3641 static void VProcessEvents (ClientData theDispX, int)
3643 Display* aDispX = (Display* )theDispX;
3644 Handle(Aspect_DisplayConnection) aDispConn;
3645 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
3646 aDriverIter (ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
3648 const Handle(Aspect_DisplayConnection)& aDispConnTmp = aDriverIter.Key2()->GetDisplayConnection();
3649 if (aDispConnTmp->GetDisplay() == aDispX)
3651 aDispConn = aDispConnTmp;
3655 if (aDispConn.IsNull())
3657 std::cerr << "Error: ViewerTest is unable processing messages for unknown X Display\n";
3661 // process new events in queue
3662 SetDisplayConnection (aDispConn);
3664 for (int aNbEventsMax = XPending (aDispX), anEventIter (0);;)
3666 const int anEventResult = ViewerMainLoop (0, NULL);
3667 if (anEventResult == 0)
3672 aNbRemain = XPending (aDispX);
3673 if (++anEventIter >= aNbEventsMax
3680 // Listening X events through Tcl_CreateFileHandler() callback is fragile,
3681 // it is possible that new events will arrive to queue before the end of this callback
3682 // so that either this callback should go into an infinite loop (blocking processing of other events)
3683 // or to keep unprocessed events till the next queue update (which can arrive not soon).
3684 // Sending a dummy event in this case is a simple workaround (still, it is possible that new event will be queued in-between).
3688 memset (&aDummyEvent, 0, sizeof(aDummyEvent));
3689 aDummyEvent.type = ClientMessage;
3690 aDummyEvent.xclient.format = 32;
3691 XSendEvent (aDispX, InputFocus, False, 0, &aDummyEvent);
3695 if (const Handle(AIS_InteractiveContext)& anActiveCtx = ViewerTest::GetAISContext())
3697 SetDisplayConnection (anActiveCtx->CurrentViewer()->Driver()->GetDisplayConnection());
3702 //==============================================================================
3703 //function : OSWindowSetup
3704 //purpose : Setup for the X11 window to be able to cath the event
3705 //==============================================================================
3708 static void OSWindowSetup()
3710 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
3713 Window window = VT_GetWindow()->XWindow();
3714 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
3715 Display *aDisplay = GetDisplayConnection()->GetDisplay();
3716 XSynchronize(aDisplay, 1);
3718 // X11 : For keyboard on SUN
3720 wmhints.flags = InputHint;
3723 XSetWMHints( aDisplay, window, &wmhints);
3725 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | KeyReleaseMask |
3726 ButtonPressMask | ButtonReleaseMask |
3727 StructureNotifyMask |
3729 Button1MotionMask | Button2MotionMask |
3730 Button3MotionMask | FocusChangeMask
3732 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
3733 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
3735 XSynchronize(aDisplay, 0);
3743 //==============================================================================
3746 //==============================================================================
3748 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
3750 const Handle(V3d_View) aView = ViewerTest::CurrentView();
3753 std::cout << "Error: no active viewer!\n";
3757 Standard_Boolean toFit = Standard_True;
3758 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
3759 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3761 TCollection_AsciiString anArg (theArgv[anArgIter]);
3763 if (anUpdateTool.parseRedrawMode (anArg))
3767 else if (anArg == "-selected")
3769 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
3770 toFit = Standard_False;
3774 std::cout << "Syntax error at '" << anArg << "'\n";
3780 aView->FitAll (0.01, Standard_False);
3785 //=======================================================================
3786 //function : VFitArea
3787 //purpose : Fit view to show area located between two points
3788 // : given in world 2D or 3D coordinates.
3789 //=======================================================================
3790 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3792 Handle(V3d_View) aView = ViewerTest::CurrentView();
3795 std::cerr << theArgVec[0] << "Error: No active view.\n";
3800 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
3801 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
3805 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
3806 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
3807 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
3808 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
3810 else if (theArgNb == 7)
3812 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
3813 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
3814 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
3815 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
3816 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
3817 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
3821 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
3822 theDI.PrintHelp(theArgVec[0]);
3826 // Convert model coordinates to view space
3827 Handle(Graphic3d_Camera) aCamera = aView->Camera();
3828 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
3829 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
3831 // Determine fit area
3832 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
3833 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
3835 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
3837 if (aDiagonal < Precision::Confusion())
3839 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
3843 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
3847 //==============================================================================
3849 //purpose : ZFitall, no DRAW arguments
3850 //Draw arg : No args
3851 //==============================================================================
3852 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3854 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
3856 if (aCurrentView.IsNull())
3858 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
3864 aCurrentView->ZFitAll();
3865 aCurrentView->Redraw();
3869 Standard_Real aScale = 1.0;
3873 aScale = Draw::Atoi (theArgVec[1]);
3876 aCurrentView->ZFitAll (aScale);
3877 aCurrentView->Redraw();
3882 //==============================================================================
3883 //function : VRepaint
3885 //==============================================================================
3886 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
3888 Handle(V3d_View) aView = ViewerTest::CurrentView();
3891 std::cout << "Error: no active viewer!\n";
3895 Standard_Boolean isImmediateUpdate = Standard_False;
3896 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3898 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3900 if (anArg == "-immediate"
3903 isImmediateUpdate = Standard_True;
3904 if (anArgIter + 1 < theArgNb
3905 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
3910 else if (anArg == "-continuous"
3913 || anArg == "-framerate")
3915 Standard_Real aFps = -1.0;
3916 if (anArgIter + 1 < theArgNb
3917 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue())
3919 aFps = Draw::Atof (theArgVec[++anArgIter]);
3922 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
3923 if (Abs (aFps) >= 1.0)
3925 aRedrawer.Start (aView->Window(), aFps);
3934 std::cout << "Syntax error at '" << anArg << "'\n";
3939 if (isImmediateUpdate)
3941 aView->RedrawImmediate();
3950 //==============================================================================
3952 //purpose : Remove all the object from the viewer
3953 //Draw arg : No args
3954 //==============================================================================
3956 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3958 Handle(V3d_View) V = ViewerTest::CurrentView();
3960 ViewerTest::Clear();
3964 //==============================================================================
3967 //==============================================================================
3969 static int VPick (Draw_Interpretor& ,
3970 Standard_Integer theNbArgs,
3971 const char** theArgVec)
3973 if (ViewerTest::CurrentView().IsNull())
3980 std::cout << "Syntax error: Invalid number of arguments\n";
3984 while (ViewerMainLoop (theNbArgs, theArgVec))
3995 //! Changes the background
3996 //! @param theDrawInterpretor the interpreter of the Draw Harness application
3997 //! @param theNumberOfCommandLineArguments the number of passed command line arguments
3998 //! @param theCommandLineArguments the array of command line arguments
3999 //! @return TCL_OK if changing was successful, or TCL_ERROR otherwise
4000 static int vbackground (Draw_Interpretor& theDrawInterpretor,
4001 const Standard_Integer theNumberOfCommandLineArguments,
4002 const char** const theCommandLineArguments)
4004 if (theNumberOfCommandLineArguments < 1)
4008 BackgroundChanger aBackgroundChanger;
4009 if (!aBackgroundChanger.ProcessCommandLine (theDrawInterpretor,
4010 theNumberOfCommandLineArguments,
4011 theCommandLineArguments))
4013 theDrawInterpretor << "Wrong command arguments.\n"
4015 << theCommandLineArguments[0] << "' for information about command options and its arguments.\n";
4023 //==============================================================================
4025 //purpose : View Scaling
4026 //==============================================================================
4028 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4030 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4031 if ( V3dView.IsNull() ) return 1;
4034 di << argv[0] << "Invalid number of arguments\n";
4037 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
4040 //==============================================================================
4041 //function : VZBuffTrihedron
4043 //==============================================================================
4045 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
4046 Standard_Integer theArgNb,
4047 const char** theArgVec)
4049 Handle(V3d_View) aView = ViewerTest::CurrentView();
4052 std::cout << "Error: no active viewer!\n";
4056 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
4058 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
4059 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
4060 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
4061 Quantity_Color anArrowColorX = Quantity_NOC_RED;
4062 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
4063 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
4064 Standard_Real aScale = 0.1;
4065 Standard_Real aSizeRatio = 0.8;
4066 Standard_Real anArrowDiam = 0.05;
4067 Standard_Integer aNbFacets = 12;
4068 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4070 Standard_CString anArg = theArgVec[anArgIter];
4071 TCollection_AsciiString aFlag (anArg);
4073 if (anUpdateTool.parseRedrawMode (aFlag))
4077 else if (aFlag == "-on")
4081 else if (aFlag == "-off")
4083 aView->TriedronErase();
4086 else if (aFlag == "-pos"
4087 || aFlag == "-position"
4088 || aFlag == "-corner")
4090 if (++anArgIter >= theArgNb)
4092 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4096 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
4097 aPosName.LowerCase();
4098 if (aPosName == "center")
4100 aPosition = Aspect_TOTP_CENTER;
4102 else if (aPosName == "left_lower"
4103 || aPosName == "lower_left"
4104 || aPosName == "leftlower"
4105 || aPosName == "lowerleft")
4107 aPosition = Aspect_TOTP_LEFT_LOWER;
4109 else if (aPosName == "left_upper"
4110 || aPosName == "upper_left"
4111 || aPosName == "leftupper"
4112 || aPosName == "upperleft")
4114 aPosition = Aspect_TOTP_LEFT_UPPER;
4116 else if (aPosName == "right_lower"
4117 || aPosName == "lower_right"
4118 || aPosName == "rightlower"
4119 || aPosName == "lowerright")
4121 aPosition = Aspect_TOTP_RIGHT_LOWER;
4123 else if (aPosName == "right_upper"
4124 || aPosName == "upper_right"
4125 || aPosName == "rightupper"
4126 || aPosName == "upperright")
4128 aPosition = Aspect_TOTP_RIGHT_UPPER;
4132 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
4136 else if (aFlag == "-type")
4138 if (++anArgIter >= theArgNb)
4140 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4144 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
4145 aTypeName.LowerCase();
4146 if (aTypeName == "wireframe"
4147 || aTypeName == "wire")
4149 aVisType = V3d_WIREFRAME;
4151 else if (aTypeName == "zbuffer"
4152 || aTypeName == "shaded")
4154 aVisType = V3d_ZBUFFER;
4158 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
4161 else if (aFlag == "-scale")
4163 if (++anArgIter >= theArgNb)
4165 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4169 aScale = Draw::Atof (theArgVec[anArgIter]);
4171 else if (aFlag == "-size"
4172 || aFlag == "-sizeratio")
4174 if (++anArgIter >= theArgNb)
4176 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4180 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
4182 else if (aFlag == "-arrowdiam"
4183 || aFlag == "-arrowdiameter")
4185 if (++anArgIter >= theArgNb)
4187 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4191 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
4193 else if (aFlag == "-nbfacets")
4195 if (++anArgIter >= theArgNb)
4197 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4201 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
4203 else if (aFlag == "-colorlabel"
4204 || aFlag == "-colorlabels")
4206 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4207 theArgVec + anArgIter + 1,
4211 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4214 anArgIter += aNbParsed;
4216 else if (aFlag == "-colorarrowx")
4218 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4219 theArgVec + anArgIter + 1,
4223 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4226 anArgIter += aNbParsed;
4228 else if (aFlag == "-colorarrowy")
4230 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4231 theArgVec + anArgIter + 1,
4235 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4238 anArgIter += aNbParsed;
4240 else if (aFlag == "-colorarrowz")
4242 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4243 theArgVec + anArgIter + 1,
4247 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4250 anArgIter += aNbParsed;
4254 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4259 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
4260 aSizeRatio, anArrowDiam, aNbFacets);
4261 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
4266 //==============================================================================
4267 //function : VRotate
4268 //purpose : Camera Rotating
4269 //==============================================================================
4271 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
4273 Handle(V3d_View) aView = ViewerTest::CurrentView();
4276 std::cout << "No active view!\n";
4280 Standard_Boolean hasFlags = Standard_False;
4281 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4283 Standard_CString anArg (theArgVec[anArgIter]);
4284 TCollection_AsciiString aFlag (anArg);
4286 if (aFlag == "-mousestart"
4287 || aFlag == "-mousefrom")
4289 hasFlags = Standard_True;
4290 if (anArgIter + 2 >= theArgNb)
4292 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4296 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
4297 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
4298 aView->StartRotation (anX, anY);
4300 else if (aFlag == "-mousemove")
4302 hasFlags = Standard_True;
4303 if (anArgIter + 2 >= theArgNb)
4305 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4309 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
4310 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
4311 aView->Rotation (anX, anY);
4313 else if (theArgNb != 4
4316 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4325 else if (theArgNb == 4)
4327 Standard_Real anAX = Draw::Atof (theArgVec[1]);
4328 Standard_Real anAY = Draw::Atof (theArgVec[2]);
4329 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
4330 aView->Rotate (anAX, anAY, anAZ);
4333 else if (theArgNb == 7)
4335 Standard_Real anAX = Draw::Atof (theArgVec[1]);
4336 Standard_Real anAY = Draw::Atof (theArgVec[2]);
4337 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
4339 Standard_Real anX = Draw::Atof (theArgVec[4]);
4340 Standard_Real anY = Draw::Atof (theArgVec[5]);
4341 Standard_Real anZ = Draw::Atof (theArgVec[6]);
4343 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
4347 std::cout << "Error: Invalid number of arguments\n";
4351 //==============================================================================
4353 //purpose : View zoom in / out (relative to current zoom)
4354 //==============================================================================
4356 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4357 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4358 if ( V3dView.IsNull() ) {
4363 Standard_Real coef = Draw::Atof(argv[1]);
4364 if ( coef <= 0.0 ) {
4365 di << argv[1] << "Invalid value\n";
4368 V3dView->SetZoom( Draw::Atof(argv[1]) );
4371 di << argv[0] << " Invalid number of arguments\n";
4376 //==============================================================================
4378 //purpose : View panning (in pixels)
4379 //==============================================================================
4381 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4382 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4383 if ( V3dView.IsNull() ) return 1;
4386 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
4389 di << argv[0] << " Invalid number of arguments\n";
4394 //==============================================================================
4396 //purpose : Place the point (in pixels) at the center of the window
4397 //==============================================================================
4398 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
4400 Handle(V3d_View) aView = ViewerTest::CurrentView();
4403 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
4409 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
4413 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
4418 static int VColorScale (Draw_Interpretor& theDI,
4419 Standard_Integer theArgNb,
4420 const char** theArgVec)
4422 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4423 Handle(V3d_View) aView = ViewerTest::CurrentView();
4424 if (aContext.IsNull())
4426 std::cout << "Error: no active view!\n";
4431 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
4435 Handle(AIS_ColorScale) aColorScale;
4436 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
4438 // find existing object
4439 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
4440 if (aColorScale.IsNull())
4442 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
4449 if (aColorScale.IsNull())
4451 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
4455 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
4456 << "Min range: " << aColorScale->GetMin() << "\n"
4457 << "Max range: " << aColorScale->GetMax() << "\n"
4458 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
4459 << "Text height: " << aColorScale->GetTextHeight() << "\n"
4460 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
4461 << "Color scale title: " << aColorScale->GetTitle() << "\n"
4462 << "Label position: ";
4463 switch (aColorScale->GetLabelPosition())
4465 case Aspect_TOCSP_NONE:
4468 case Aspect_TOCSP_LEFT:
4471 case Aspect_TOCSP_RIGHT:
4474 case Aspect_TOCSP_CENTER:
4475 theDI << "Center\n";
4481 if (aColorScale.IsNull())
4483 aColorScale = new AIS_ColorScale();
4484 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4485 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
4488 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
4489 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
4491 Standard_CString anArg = theArgVec[anArgIter];
4492 TCollection_AsciiString aFlag (anArg);
4494 if (anUpdateTool.parseRedrawMode (aFlag))
4498 else if (aFlag == "-range")
4500 if (anArgIter + 3 >= theArgNb)
4502 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4506 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
4507 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
4508 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
4509 if (!aRangeMin.IsRealValue()
4510 || !aRangeMax.IsRealValue())
4512 std::cout << "Error: the range values should be real!\n";
4515 else if (!aNbIntervals.IsIntegerValue())
4517 std::cout << "Error: the number of intervals should be integer!\n";
4521 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
4522 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
4524 else if (aFlag == "-font")
4526 if (anArgIter + 1 >= theArgNb)
4528 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4531 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
4532 if (!aFontArg.IsIntegerValue())
4534 std::cout << "Error: HeightFont value should be integer!\n";
4538 aColorScale->SetTextHeight (aFontArg.IntegerValue());
4541 else if (aFlag == "-textpos")
4543 if (anArgIter + 1 >= theArgNb)
4545 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4549 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
4550 aTextPosArg.LowerCase();
4551 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
4552 if (aTextPosArg == "none")
4554 aLabPosition = Aspect_TOCSP_NONE;
4556 else if (aTextPosArg == "left")
4558 aLabPosition = Aspect_TOCSP_LEFT;
4560 else if (aTextPosArg == "right")
4562 aLabPosition = Aspect_TOCSP_RIGHT;
4564 else if (aTextPosArg == "center")
4566 aLabPosition = Aspect_TOCSP_CENTER;
4570 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
4573 aColorScale->SetLabelPosition (aLabPosition);
4575 else if (aFlag == "-logarithmic"
4578 if (anArgIter + 1 >= theArgNb)
4580 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4584 Standard_Boolean IsLog;
4585 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
4587 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4590 aColorScale->SetLogarithmic (IsLog);
4592 else if (aFlag == "-huerange"
4595 if (anArgIter + 2 >= theArgNb)
4597 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4601 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
4602 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
4603 aColorScale->SetHueRange (aHueMin, aHueMax);
4605 else if (aFlag == "-colorrange")
4607 Quantity_Color aColorMin, aColorMax;
4608 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4609 theArgVec + (anArgIter + 1),
4611 anArgIter += aNbParsed1;
4612 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4613 theArgVec + (anArgIter + 1),
4615 anArgIter += aNbParsed2;
4619 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4623 aColorScale->SetColorRange (aColorMin, aColorMax);
4625 else if (aFlag == "-reversed"
4626 || aFlag == "-inverted"
4627 || aFlag == "-topdown"
4628 || aFlag == "-bottomup")
4630 Standard_Boolean toEnable = Standard_True;
4631 if (anArgIter + 1 < theArgNb
4632 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
4636 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
4638 else if (aFlag == "-smooth"
4639 || aFlag == "-smoothtransition")
4641 Standard_Boolean toEnable = Standard_True;
4642 if (anArgIter + 1 < theArgNb
4643 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4647 aColorScale->SetSmoothTransition (toEnable);
4649 else if (aFlag == "-xy")
4651 if (anArgIter + 2 >= theArgNb)
4653 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4657 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
4658 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
4659 if (!anX.IsIntegerValue()
4660 || !anY.IsIntegerValue())
4662 std::cout << "Error: coordinates should be integer values!\n";
4666 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
4668 else if (aFlag == "-width"
4670 || aFlag == "-breadth")
4672 if (anArgIter + 1 >= theArgNb)
4674 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4678 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
4679 if (!aBreadth.IsIntegerValue())
4681 std::cout << "Error: a width should be an integer value!\n";
4684 aColorScale->SetBreadth (aBreadth.IntegerValue());
4686 else if (aFlag == "-height"
4689 if (anArgIter + 1 >= theArgNb)
4691 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4695 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
4696 if (!aHeight.IsIntegerValue())
4698 std::cout << "Error: a width should be an integer value!\n";
4701 aColorScale->SetHeight (aHeight.IntegerValue());
4703 else if (aFlag == "-color")
4705 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4707 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
4710 else if (anArgIter + 2 >= theArgNb)
4712 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4716 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
4717 if (!anInd.IsIntegerValue())
4719 std::cout << "Error: Index value should be integer!\n";
4722 const Standard_Integer anIndex = anInd.IntegerValue();
4723 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
4725 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
4729 Quantity_Color aColor;
4730 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4731 theArgVec + (anArgIter + 1),
4735 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4738 aColorScale->SetIntervalColor (aColor, anIndex);
4739 aColorScale->SetColorType (Aspect_TOCSD_USER);
4740 anArgIter += aNbParsed;
4742 else if (aFlag == "-label")
4744 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4746 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
4749 else if (anArgIter + 2 >= theArgNb)
4751 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4755 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4756 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
4758 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
4762 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4763 aColorScale->SetLabel (aText, anIndex);
4764 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4767 else if (aFlag == "-labelat"
4768 || aFlag == "-labat"
4769 || aFlag == "-labelatborder"
4770 || aFlag == "-labatborder"
4771 || aFlag == "-labelatcenter"
4772 || aFlag == "-labatcenter")
4774 Standard_Boolean toEnable = Standard_True;
4775 if (aFlag == "-labelat"
4776 || aFlag == "-labat")
4778 Standard_Integer aLabAtBorder = -1;
4779 if (++anArgIter >= theArgNb)
4781 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4782 anAtBorder.LowerCase();
4783 if (anAtBorder == "border")
4787 else if (anAtBorder == "center")
4792 if (aLabAtBorder == -1)
4794 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4797 toEnable = (aLabAtBorder == 1);
4799 else if (anArgIter + 1 < theArgNb
4800 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4804 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4805 || aFlag == "-labatcenter"
4809 else if (aFlag == "-colors")
4811 Aspect_SequenceOfColor aSeq;
4814 Quantity_Color aColor;
4815 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4816 theArgVec + (anArgIter + 1),
4822 anArgIter += aNbParsed;
4823 aSeq.Append (aColor);
4825 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
4827 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4828 << aColorScale->GetNumberOfIntervals() << " intervals\n";
4832 aColorScale->SetColors (aSeq);
4833 aColorScale->SetColorType (Aspect_TOCSD_USER);
4835 else if (aFlag == "-labels"
4836 || aFlag == "-freelabels")
4838 if (anArgIter + 1 >= theArgNb)
4840 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4844 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4845 ? aColorScale->GetNumberOfIntervals() + 1
4846 : aColorScale->GetNumberOfIntervals();
4847 if (aFlag == "-freelabels")
4850 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4852 if (anArgIter + aNbLabels >= theArgNb)
4854 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
4858 TColStd_SequenceOfExtendedString aSeq;
4859 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
4861 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
4863 aColorScale->SetLabels (aSeq);
4864 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4866 else if (aFlag == "-title")
4868 if (anArgIter + 1 >= theArgNb)
4870 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4874 Standard_Boolean isTwoArgs = Standard_False;
4875 if (anArgIter + 2 < theArgNb)
4877 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4878 aSecondArg.LowerCase();
4879 Standard_DISABLE_DEPRECATION_WARNINGS
4880 if (aSecondArg == "none")
4882 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
4883 isTwoArgs = Standard_True;
4885 else if (aSecondArg == "left")
4887 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
4888 isTwoArgs = Standard_True;
4890 else if (aSecondArg == "right")
4892 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
4893 isTwoArgs = Standard_True;
4895 else if (aSecondArg == "center")
4897 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
4898 isTwoArgs = Standard_True;
4900 Standard_ENABLE_DEPRECATION_WARNINGS
4903 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
4910 else if (aFlag == "-demoversion"
4911 || aFlag == "-demo")
4913 aColorScale->SetPosition (0, 0);
4914 aColorScale->SetTextHeight (16);
4915 aColorScale->SetRange (0.0, 100.0);
4916 aColorScale->SetNumberOfIntervals (10);
4917 aColorScale->SetBreadth (0);
4918 aColorScale->SetHeight (0);
4919 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4920 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4921 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
4923 else if (aFlag == "-findcolor")
4925 if (anArgIter + 1 >= theArgNb)
4927 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4931 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4933 if (!anArg1.IsRealValue())
4935 std::cout << "Error: the value should be real!\n";
4939 Quantity_Color aColor;
4940 aColorScale->FindColor (anArg1.RealValue(), aColor);
4941 theDI << Quantity_Color::StringName (aColor.Name());
4946 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4951 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4952 aView->Window()->Size (aWinWidth, aWinHeight);
4953 if (aColorScale->GetBreadth() == 0)
4955 aColorScale->SetBreadth (aWinWidth);
4957 if (aColorScale->GetHeight() == 0)
4959 aColorScale->SetHeight (aWinHeight);
4961 aColorScale->SetToUpdate();
4962 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
4966 //==============================================================================
4967 //function : VGraduatedTrihedron
4968 //purpose : Displays or hides a graduated trihedron
4969 //==============================================================================
4970 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4971 Quantity_Color& theColor)
4973 Quantity_NameOfColor aColorName;
4974 TCollection_AsciiString aVal = theValue;
4976 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
4978 return Standard_False;
4980 theColor = Quantity_Color (aColorName);
4981 return Standard_True;
4984 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
4988 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4989 << theArgs[0] <<"' for more information.\n";
4990 return 1; //TCL_ERROR
4993 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4994 TCollection_AsciiString aParseKey;
4995 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4997 TCollection_AsciiString anArg (theArgs [anArgIt]);
4999 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5002 aParseKey.Remove (1);
5003 aParseKey.LowerCase();
5004 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5008 if (aParseKey.IsEmpty())
5013 aMapOfArgs(aParseKey)->Append (anArg);
5017 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
5018 aMapIt.More(); aMapIt.Next())
5020 const TCollection_AsciiString& aKey = aMapIt.Key();
5021 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
5023 // Bool key, without arguments
5024 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
5025 && anArgs->IsEmpty())
5031 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
5032 && anArgs->Length() == 1)
5038 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
5039 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
5040 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
5041 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
5042 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
5047 // One string argument
5048 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
5049 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
5050 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
5055 // One integer argument
5056 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
5057 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
5058 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
5059 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
5060 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
5065 // One real argument
5066 if ( aKey.IsEqual ("arrowlength")
5067 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
5072 // Two string arguments
5073 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
5074 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
5079 TCollection_AsciiString aLowerKey;
5082 aLowerKey.LowerCase();
5083 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
5084 std::cout << "Type help for more information.\n";
5088 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5089 if (anAISContext.IsNull())
5091 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
5095 Standard_Boolean toDisplay = Standard_True;
5096 Quantity_Color aColor;
5097 Graphic3d_GraduatedTrihedron aTrihedronData;
5098 // Process parameters
5099 Handle(TColStd_HSequenceOfAsciiString) aValues;
5100 if (aMapOfArgs.Find ("off", aValues))
5102 toDisplay = Standard_False;
5106 if (aMapOfArgs.Find ("xname", aValues))
5108 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
5110 if (aMapOfArgs.Find ("yname", aValues))
5112 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
5114 if (aMapOfArgs.Find ("zname", aValues))
5116 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
5118 if (aMapOfArgs.Find ("xdrawname", aValues))
5120 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5122 if (aMapOfArgs.Find ("ydrawname", aValues))
5124 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5126 if (aMapOfArgs.Find ("zdrawname", aValues))
5128 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5130 if (aMapOfArgs.Find ("xnameoffset", aValues))
5132 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5134 if (aMapOfArgs.Find ("ynameoffset", aValues))
5136 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5138 if (aMapOfArgs.Find ("znameoffset", aValues))
5140 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5144 if (aMapOfArgs.Find ("xnamecolor", aValues))
5146 if (!GetColor (aValues->Value(1), aColor))
5148 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
5151 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
5153 if (aMapOfArgs.Find ("ynamecolor", aValues))
5155 if (!GetColor (aValues->Value(1), aColor))
5157 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
5160 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
5162 if (aMapOfArgs.Find ("znamecolor", aValues))
5164 if (!GetColor (aValues->Value(1), aColor))
5166 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
5169 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
5171 if (aMapOfArgs.Find ("xcolor", aValues))
5173 if (!GetColor (aValues->Value(1), aColor))
5175 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
5178 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
5180 if (aMapOfArgs.Find ("ycolor", aValues))
5182 if (!GetColor (aValues->Value(1), aColor))
5184 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
5187 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
5189 if (aMapOfArgs.Find ("zcolor", aValues))
5191 if (!GetColor (aValues->Value(1), aColor))
5193 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
5196 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
5200 if (aMapOfArgs.Find ("xticks", aValues))
5202 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5204 if (aMapOfArgs.Find ("yticks", aValues))
5206 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5208 if (aMapOfArgs.Find ("zticks", aValues))
5210 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5212 if (aMapOfArgs.Find ("xticklength", aValues))
5214 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5216 if (aMapOfArgs.Find ("yticklength", aValues))
5218 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5220 if (aMapOfArgs.Find ("zticklength", aValues))
5222 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5224 if (aMapOfArgs.Find ("xdrawticks", aValues))
5226 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5228 if (aMapOfArgs.Find ("ydrawticks", aValues))
5230 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5232 if (aMapOfArgs.Find ("zdrawticks", aValues))
5234 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5238 if (aMapOfArgs.Find ("xdrawvalues", aValues))
5240 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5242 if (aMapOfArgs.Find ("ydrawvalues", aValues))
5244 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5246 if (aMapOfArgs.Find ("zdrawvalues", aValues))
5248 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5250 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
5252 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5254 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
5256 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5258 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
5260 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5264 if (aMapOfArgs.Find ("arrowlength", aValues))
5266 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
5270 if (aMapOfArgs.Find ("namefont", aValues))
5272 aTrihedronData.SetNamesFont (aValues->Value(1));
5274 if (aMapOfArgs.Find ("valuesfont", aValues))
5276 aTrihedronData.SetValuesFont (aValues->Value(1));
5279 if (aMapOfArgs.Find ("drawgrid", aValues))
5281 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
5283 if (aMapOfArgs.Find ("drawaxes", aValues))
5285 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
5288 // The final step: display of erase trihedron
5291 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
5295 ViewerTest::CurrentView()->GraduatedTrihedronErase();
5298 ViewerTest::GetAISContext()->UpdateCurrentViewer();
5299 ViewerTest::CurrentView()->Redraw();
5304 //==============================================================================
5307 //==============================================================================
5308 static int VTile (Draw_Interpretor& theDI,
5309 Standard_Integer theArgNb,
5310 const char** theArgVec)
5312 Handle(V3d_View) aView = ViewerTest::CurrentView();
5315 std::cerr << "Error: no active viewer.\n";
5319 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
5322 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
5323 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
5324 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
5328 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
5329 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5331 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5333 if (anArg == "-lowerleft"
5334 || anArg == "-upperleft")
5336 if (anArgIter + 3 < theArgNb)
5338 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5341 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
5342 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5343 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5345 else if (anArg == "-total"
5346 || anArg == "-totalsize"
5347 || anArg == "-viewsize")
5349 if (anArgIter + 3 < theArgNb)
5351 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5354 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5355 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5356 if (aTile.TotalSize.x() < 1
5357 || aTile.TotalSize.y() < 1)
5359 std::cerr << "Error: total size is incorrect.\n";
5363 else if (anArg == "-tilesize")
5365 if (anArgIter + 3 < theArgNb)
5367 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5371 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5372 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5373 if (aTile.TileSize.x() < 1
5374 || aTile.TileSize.y() < 1)
5376 std::cerr << "Error: tile size is incorrect.\n";
5380 else if (anArg == "-unset")
5382 aView->Camera()->SetTile (Graphic3d_CameraTile());
5388 if (aTile.TileSize.x() < 1
5389 || aTile.TileSize.y() < 1)
5391 std::cerr << "Error: tile size is undefined.\n";
5394 else if (aTile.TotalSize.x() < 1
5395 || aTile.TotalSize.y() < 1)
5397 std::cerr << "Error: total size is undefined.\n";
5401 aView->Camera()->SetTile (aTile);
5406 //! Format ZLayer ID.
5407 inline const char* formZLayerId (const Standard_Integer theLayerId)
5411 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
5412 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
5413 case Graphic3d_ZLayerId_Top: return "[TOP]";
5414 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
5415 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
5416 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
5421 //! Print the ZLayer information.
5422 inline void printZLayerInfo (Draw_Interpretor& theDI,
5423 const Graphic3d_ZLayerSettings& theLayer)
5425 if (!theLayer.Name().IsEmpty())
5427 theDI << " Name: " << theLayer.Name() << "\n";
5429 if (theLayer.IsImmediate())
5431 theDI << " Immediate: TRUE\n";
5433 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
5434 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
5435 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
5436 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
5437 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
5438 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
5439 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
5441 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
5445 //==============================================================================
5446 //function : VZLayer
5447 //purpose : Test z layer operations for v3d viewer
5448 //==============================================================================
5449 static int VZLayer (Draw_Interpretor& theDI,
5450 Standard_Integer theArgNb,
5451 const char** theArgVec)
5453 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5454 if (aContextAIS.IsNull())
5456 std::cout << "No active viewer!\n";
5460 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
5463 TColStd_SequenceOfInteger aLayers;
5464 aViewer->GetAllZLayers (aLayers);
5465 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5467 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
5468 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
5469 printZLayerInfo (theDI, aSettings);
5474 Standard_Integer anArgIter = 1;
5475 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5476 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
5477 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5483 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
5484 if (aFirstArg.IsIntegerValue())
5487 aLayerId = aFirstArg.IntegerValue();
5491 if (ViewerTest::ParseZLayerName (aFirstArg.ToCString(), aLayerId))
5498 Graphic3d_ZLayerId anOtherLayerId = Graphic3d_ZLayerId_UNKNOWN;
5499 for (; anArgIter < theArgNb; ++anArgIter)
5501 // perform operation
5502 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5504 if (anUpdateTool.parseRedrawMode (anArg))
5508 else if (anArg == "-add"
5511 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5512 if (!aViewer->AddZLayer (aLayerId))
5514 std::cout << "Error: can not add a new z layer!\n";
5520 else if (anArg == "-insertbefore"
5521 && anArgIter + 1 < theArgNb
5522 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
5525 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5526 if (!aViewer->InsertLayerBefore (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
5528 std::cout << "Error: can not add a new z layer!\n";
5534 else if (anArg == "-insertafter"
5535 && anArgIter + 1 < theArgNb
5536 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
5539 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5540 if (!aViewer->InsertLayerAfter (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
5542 std::cout << "Error: can not add a new z layer!\n";
5548 else if (anArg == "-del"
5549 || anArg == "-delete"
5552 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5554 if (++anArgIter >= theArgNb)
5556 std::cout << "Syntax error: id of z layer to remove is missing\n";
5560 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5563 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
5564 || aLayerId == Graphic3d_ZLayerId_Default
5565 || aLayerId == Graphic3d_ZLayerId_Top
5566 || aLayerId == Graphic3d_ZLayerId_Topmost
5567 || aLayerId == Graphic3d_ZLayerId_TopOSD
5568 || aLayerId == Graphic3d_ZLayerId_BotOSD)
5570 std::cout << "Syntax error: standard Z layer can not be removed\n";
5574 // move all object displayed in removing layer to default layer
5575 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5576 anObjIter.More(); anObjIter.Next())
5578 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
5580 || aPrs->ZLayer() != aLayerId)
5584 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
5587 if (!aViewer->RemoveZLayer (aLayerId))
5589 std::cout << "Z layer can not be removed!\n";
5593 theDI << aLayerId << " ";
5596 else if (anArg == "-get"
5599 TColStd_SequenceOfInteger aLayers;
5600 aViewer->GetAllZLayers (aLayers);
5601 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5603 theDI << aLayeriter.Value() << " ";
5608 else if (anArg == "-name")
5610 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5612 std::cout << "Syntax error: id of Z layer is missing\n";
5616 if (++anArgIter >= theArgNb)
5618 std::cout << "Syntax error: name is missing\n";
5622 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5623 aSettings.SetName (theArgVec[anArgIter]);
5624 aViewer->SetZLayerSettings (aLayerId, aSettings);
5626 else if (anArg == "-origin")
5628 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5630 std::cout << "Syntax error: id of Z layer is missing\n";
5634 if (anArgIter + 2 >= theArgNb)
5636 std::cout << "Syntax error: origin coordinates are missing\n";
5640 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5642 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
5643 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
5644 anOrigin.SetZ (0.0);
5645 if (anArgIter + 3 < theArgNb)
5647 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
5654 aSettings.SetOrigin (anOrigin);
5655 aViewer->SetZLayerSettings (aLayerId, aSettings);
5657 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5658 && anArgIter + 1 < theArgNb
5659 && (anArg == "-cullingdistance"
5660 || anArg == "-cullingdist"
5661 || anArg == "-culldistance"
5662 || anArg == "-culldist"
5663 || anArg == "-distcull"
5664 || anArg == "-distculling"
5665 || anArg == "-distanceculling"))
5667 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5668 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
5669 aSettings.SetCullingDistance (aDist);
5670 aViewer->SetZLayerSettings (aLayerId, aSettings);
5672 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5673 && anArgIter + 1 < theArgNb
5674 && (anArg == "-cullingsize"
5675 || anArg == "-cullsize"
5676 || anArg == "-sizecull"
5677 || anArg == "-sizeculling"))
5679 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5680 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
5681 aSettings.SetCullingSize (aSize);
5682 aViewer->SetZLayerSettings (aLayerId, aSettings);
5684 else if (anArg == "-settings"
5685 || anArg == "settings")
5687 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5689 if (++anArgIter >= theArgNb)
5691 std::cout << "Syntax error: id of Z layer is missing\n";
5695 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5698 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5699 printZLayerInfo (theDI, aSettings);
5701 else if (anArg == "-enable"
5702 || anArg == "enable"
5703 || anArg == "-disable"
5704 || anArg == "disable")
5706 const Standard_Boolean toEnable = anArg == "-enable"
5707 || anArg == "enable";
5708 if (++anArgIter >= theArgNb)
5710 std::cout << "Syntax error: option name is missing\n";
5714 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
5716 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5718 if (++anArgIter >= theArgNb)
5720 std::cout << "Syntax error: id of Z layer is missing\n";
5724 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5727 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5728 if (aSubOp == "depthtest"
5729 || aSubOp == "test")
5731 aSettings.SetEnableDepthTest (toEnable);
5733 else if (aSubOp == "depthwrite"
5734 || aSubOp == "write")
5736 aSettings.SetEnableDepthWrite (toEnable);
5738 else if (aSubOp == "depthclear"
5739 || aSubOp == "clear")
5741 aSettings.SetClearDepth (toEnable);
5743 else if (aSubOp == "depthoffset"
5744 || aSubOp == "offset")
5746 Graphic3d_PolygonOffset aParams;
5747 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5750 if (anArgIter + 2 >= theArgNb)
5752 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5756 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5757 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5759 aSettings.SetPolygonOffset (aParams);
5761 else if (aSubOp == "positiveoffset"
5762 || aSubOp == "poffset")
5766 aSettings.SetDepthOffsetPositive();
5770 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5773 else if (aSubOp == "negativeoffset"
5774 || aSubOp == "noffset")
5778 aSettings.SetDepthOffsetNegative();
5782 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5785 else if (aSubOp == "textureenv")
5787 aSettings.SetEnvironmentTexture (toEnable);
5789 else if (aSubOp == "raytracing")
5791 aSettings.SetRaytracable (toEnable);
5794 aViewer->SetZLayerSettings (aLayerId, aSettings);
5798 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5806 // The interactive presentation of 2d layer item
5807 // for "vlayerline" command it provides a presentation of
5808 // line with user-defined linewidth, linetype and transparency.
5809 class V3d_LineItem : public AIS_InteractiveObject
5813 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
5816 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5817 Standard_Real X2, Standard_Real Y2,
5818 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5819 Standard_Real theWidth = 0.5,
5820 Standard_Real theTransp = 1.0);
5824 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5825 const Handle(Prs3d_Presentation)& thePresentation,
5826 const Standard_Integer theMode) Standard_OVERRIDE;
5828 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
5829 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5834 Standard_Real myX1, myY1, myX2, myY2;
5835 Aspect_TypeOfLine myType;
5836 Standard_Real myWidth;
5839 // default constructor for line item
5840 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5841 Standard_Real X2, Standard_Real Y2,
5842 Aspect_TypeOfLine theType,
5843 Standard_Real theWidth,
5844 Standard_Real theTransp) :
5845 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5846 myType(theType), myWidth(theWidth)
5848 SetTransparency (1-theTransp);
5852 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5853 const Handle(Prs3d_Presentation)& thePresentation,
5854 const Standard_Integer /*theMode*/)
5856 thePresentation->Clear();
5857 Quantity_Color aColor (Quantity_NOC_RED);
5858 Standard_Integer aWidth, aHeight;
5859 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5860 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5861 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5862 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5863 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5864 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5865 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5866 aGroup->AddPrimitiveArray (aPrim);
5869 //=============================================================================
5870 //function : VLayerLine
5871 //purpose : Draws line in the v3d view layer with given attributes: linetype,
5872 // : linewidth, transparency coefficient
5873 //============================================================================
5874 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5876 // get the active view
5877 Handle(V3d_View) aView = ViewerTest::CurrentView();
5880 di << "Call vinit before!\n";
5885 di << "Use: " << argv[0];
5886 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5887 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5888 di << " 0 - solid \n";
5889 di << " 1 - dashed \n";
5890 di << " 2 - dot \n";
5891 di << " 3 - dashdot\n";
5892 di << " transparency : { 0.0 - 1.0 } \n";
5893 di << " 0.0 - transparent\n";
5894 di << " 1.0 - visible \n";
5898 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5899 // get the input params
5900 Standard_Real X1 = Draw::Atof(argv[1]);
5901 Standard_Real Y1 = Draw::Atof(argv[2]);
5902 Standard_Real X2 = Draw::Atof(argv[3]);
5903 Standard_Real Y2 = Draw::Atof(argv[4]);
5905 Standard_Real aWidth = 0.5;
5906 Standard_Real aTransparency = 1.0;
5910 aWidth = Draw::Atof(argv[5]);
5912 // select appropriate line type
5913 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5915 && !ViewerTest::ParseLineType (argv[6], aLineType))
5917 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5924 aTransparency = Draw::Atof(argv[7]);
5925 if (aTransparency < 0 || aTransparency > 1.0)
5926 aTransparency = 1.0;
5929 static Handle (V3d_LineItem) aLine;
5930 if (!aLine.IsNull())
5932 aContext->Erase (aLine, Standard_False);
5934 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5938 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5939 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5940 aLine->SetToUpdate();
5941 aContext->Display (aLine, Standard_True);
5947 //==============================================================================
5950 //==============================================================================
5952 static int VGrid (Draw_Interpretor& /*theDI*/,
5953 Standard_Integer theArgNb,
5954 const char** theArgVec)
5956 Handle(V3d_View) aView = ViewerTest::CurrentView();
5957 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5958 if (aView.IsNull() || aViewer.IsNull())
5960 std::cerr << "Error: no active view\n";
5964 Aspect_GridType aType = aViewer->GridType();
5965 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5966 Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY;
5967 Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0;
5968 bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false;
5969 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5970 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5972 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5974 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5978 else if (anArgIter + 1 < theArgNb
5979 && anArg == "-type")
5981 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5982 anArgNext.LowerCase();
5983 if (anArgNext == "r"
5984 || anArgNext == "rect"
5985 || anArgNext == "rectangular")
5987 aType = Aspect_GT_Rectangular;
5989 else if (anArgNext == "c"
5990 || anArgNext == "circ"
5991 || anArgNext == "circular")
5993 aType = Aspect_GT_Circular;
5997 std::cout << "Syntax error at '" << anArgNext << "'\n";
6001 else if (anArgIter + 1 < theArgNb
6002 && anArg == "-mode")
6004 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
6005 anArgNext.LowerCase();
6006 if (anArgNext == "l"
6007 || anArgNext == "line"
6008 || anArgNext == "lines")
6010 aMode = Aspect_GDM_Lines;
6012 else if (anArgNext == "p"
6013 || anArgNext == "point"
6014 || anArgNext == "points")
6016 aMode = Aspect_GDM_Points;
6020 std::cout << "Syntax error at '" << anArgNext << "'\n";
6024 else if (anArgIter + 2 < theArgNb
6025 && (anArg == "-origin"
6026 || anArg == "-orig"))
6029 aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6030 Draw::Atof (theArgVec[anArgIter + 2]));
6033 else if (anArgIter + 2 < theArgNb
6034 && anArg == "-step")
6037 aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6038 Draw::Atof (theArgVec[anArgIter + 2]));
6039 if (aNewStepXY.x() <= 0.0
6040 || aNewStepXY.y() <= 0.0)
6042 std::cout << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
6047 else if (anArgIter + 1 < theArgNb
6048 && (anArg == "-angle"
6049 || anArg == "-rotangle"
6050 || anArg == "-rotationangle"))
6053 aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]);
6055 else if (anArgIter + 1 < theArgNb
6056 && (anArg == "-zoffset"
6060 aNewZOffset = Draw::Atof (theArgVec[++anArgIter]);
6062 else if (anArgIter + 1 < theArgNb
6063 && anArg == "-radius")
6067 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0);
6068 if (aNewStepXY.x() <= 0.0)
6070 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'\n";
6074 else if (anArgIter + 2 < theArgNb
6075 && anArg == "-size")
6078 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6079 Draw::Atof (theArgVec[anArgIter + 2]));
6080 if (aNewStepXY.x() <= 0.0
6081 || aNewStepXY.y() <= 0.0)
6083 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
6088 else if (anArg == "r"
6090 || anArg == "rectangular")
6092 aType = Aspect_GT_Rectangular;
6094 else if (anArg == "c"
6096 || anArg == "circular")
6098 aType = Aspect_GT_Circular;
6100 else if (anArg == "l"
6102 || anArg == "lines")
6104 aMode = Aspect_GDM_Lines;
6106 else if (anArg == "p"
6108 || anArg == "points")
6110 aMode = Aspect_GDM_Points;
6112 else if (anArgIter + 1 >= theArgNb
6115 aViewer->DeactivateGrid();
6120 std::cout << "Syntax error at '" << anArg << "'\n";
6125 if (aType == Aspect_GT_Rectangular)
6127 Graphic3d_Vec2d anOrigXY, aStepXY;
6128 Standard_Real aRotAngle = 0.0;
6129 aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
6132 anOrigXY = aNewOriginXY;
6136 aStepXY = aNewStepXY;
6140 aRotAngle = aNewRotAngle;
6142 aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
6143 if (hasSize || hasZOffset)
6145 Graphic3d_Vec3d aSize;
6146 aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
6149 aSize.x() = aNewSizeXY.x();
6150 aSize.y() = aNewSizeXY.y();
6154 aSize.z() = aNewZOffset;
6156 aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
6159 else if (aType == Aspect_GT_Circular)
6161 Graphic3d_Vec2d anOrigXY;
6162 Standard_Real aRadiusStep;
6163 Standard_Integer aDivisionNumber;
6164 Standard_Real aRotAngle = 0.0;
6165 aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6168 anOrigXY = aNewOriginXY;
6172 aRadiusStep = aNewStepXY[0];
6173 aDivisionNumber = (int )aNewStepXY[1];
6174 if (aDivisionNumber < 1)
6176 std::cout << "Syntax error: invalid division number '" << aNewStepXY[1] << "'\n";
6182 aRotAngle = aNewRotAngle;
6185 aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6186 if (hasSize || hasZOffset)
6188 Standard_Real aRadius = 0.0, aZOffset = 0.0;
6189 aViewer->CircularGridGraphicValues (aRadius, aZOffset);
6192 aRadius = aNewSizeXY.x();
6193 if (aNewSizeXY.y() != 0.0)
6195 std::cout << "Syntax error: circular size should be specified as radius\n";
6201 aZOffset = aNewZOffset;
6203 aViewer->SetCircularGridGraphicValues (aRadius, aZOffset);
6206 aViewer->ActivateGrid (aType, aMode);
6210 //==============================================================================
6211 //function : VPriviledgedPlane
6213 //==============================================================================
6215 static int VPriviledgedPlane (Draw_Interpretor& theDI,
6216 Standard_Integer theArgNb,
6217 const char** theArgVec)
6219 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
6221 std::cerr << "Error: wrong number of arguments! See usage:\n";
6222 theDI.PrintHelp (theArgVec[0]);
6226 // get the active viewer
6227 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6228 if (aViewer.IsNull())
6230 std::cerr << "Error: no active viewer. Please call vinit.\n";
6236 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
6237 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
6238 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
6239 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
6240 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
6241 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
6242 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
6246 Standard_Integer anArgIdx = 1;
6247 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
6248 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
6249 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
6250 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
6251 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
6252 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
6254 gp_Ax3 aPriviledgedPlane;
6255 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
6256 gp_Dir aNorm (aNormX, aNormY, aNormZ);
6259 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
6260 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
6261 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
6262 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
6263 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
6267 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
6270 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
6275 //==============================================================================
6276 //function : VConvert
6278 //==============================================================================
6280 static int VConvert (Draw_Interpretor& theDI,
6281 Standard_Integer theArgNb,
6282 const char** theArgVec)
6284 // get the active view
6285 Handle(V3d_View) aView = ViewerTest::CurrentView();
6288 std::cerr << "Error: no active view. Please call vinit.\n";
6292 enum { Model, Ray, View, Window, Grid } aMode = Model;
6294 // access coordinate arguments
6295 TColStd_SequenceOfReal aCoord;
6296 Standard_Integer anArgIdx = 1;
6297 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
6299 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6300 if (!anArg.IsRealValue())
6304 aCoord.Append (anArg.RealValue());
6307 // non-numeric argument too early
6308 if (aCoord.IsEmpty())
6310 std::cerr << "Error: wrong number of arguments! See usage:\n";
6311 theDI.PrintHelp (theArgVec[0]);
6315 // collect all other arguments and options
6316 for (; anArgIdx < theArgNb; ++anArgIdx)
6318 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6320 if (anArg == "window") aMode = Window;
6321 else if (anArg == "view") aMode = View;
6322 else if (anArg == "grid") aMode = Grid;
6323 else if (anArg == "ray") aMode = Ray;
6326 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
6327 theDI.PrintHelp (theArgVec[0]);
6332 // complete input checks
6333 if ((aCoord.Length() == 1 && theArgNb > 3) ||
6334 (aCoord.Length() == 2 && theArgNb > 4) ||
6335 (aCoord.Length() == 3 && theArgNb > 5))
6337 std::cerr << "Error: wrong number of arguments! See usage:\n";
6338 theDI.PrintHelp (theArgVec[0]);
6342 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
6343 Standard_Integer aXYp[2] = {0, 0};
6345 // convert one-dimensional coordinate
6346 if (aCoord.Length() == 1)
6350 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
6351 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
6353 std::cerr << "Error: wrong arguments! See usage:\n";
6354 theDI.PrintHelp (theArgVec[0]);
6359 // convert 2D coordinates from projection or view reference space
6360 if (aCoord.Length() == 2)
6365 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6366 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6370 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
6371 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
6375 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
6376 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6380 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6381 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
6382 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6386 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
6387 (Standard_Integer) aCoord (2),
6388 aXYZ[0], aXYZ[1], aXYZ[2],
6389 aXYZ[3], aXYZ[4], aXYZ[5]);
6390 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6394 std::cerr << "Error: wrong arguments! See usage:\n";
6395 theDI.PrintHelp (theArgVec[0]);
6400 // convert 3D coordinates from view reference space
6401 else if (aCoord.Length() == 3)
6406 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
6407 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6411 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
6412 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6416 std::cerr << "Error: wrong arguments! See usage:\n";
6417 theDI.PrintHelp (theArgVec[0]);
6425 //==============================================================================
6428 //==============================================================================
6430 static int VFps (Draw_Interpretor& theDI,
6431 Standard_Integer theArgNb,
6432 const char** theArgVec)
6434 // get the active view
6435 Handle(V3d_View) aView = ViewerTest::CurrentView();
6438 std::cerr << "No active view. Please call vinit.\n";
6442 Standard_Integer aFramesNb = -1;
6443 Standard_Real aDuration = -1.0;
6444 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6446 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6449 && anArgIter + 1 < theArgNb
6450 && (anArg == "-duration"
6452 || anArg == "-time"))
6454 aDuration = Draw::Atof (theArgVec[++anArgIter]);
6456 else if (aFramesNb < 0
6457 && anArg.IsIntegerValue())
6459 aFramesNb = anArg.IntegerValue();
6462 std::cerr << "Syntax error at '" << anArg << "'\n";
6468 std::cerr << "Syntax error at '" << anArg << "'\n";
6472 if (aFramesNb < 0 && aDuration < 0.0)
6477 // the time is meaningless for first call
6478 // due to async OpenGl rendering
6481 // redraw view in loop to estimate average values
6484 Standard_Integer aFrameIter = 1;
6485 for (;; ++aFrameIter)
6489 && aFrameIter >= aFramesNb)
6491 && aTimer.ElapsedTime() >= aDuration))
6498 const Standard_Real aTime = aTimer.ElapsedTime();
6499 aTimer.OSD_Chronometer::Show (aCpu);
6501 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
6502 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
6504 // return statistics
6505 theDI << "FPS: " << aFpsAver << "\n"
6506 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
6508 // compute additional statistics in ray-tracing mode
6509 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
6510 if (aParams.Method == Graphic3d_RM_RAYTRACING)
6512 Graphic3d_Vec2i aWinSize (0, 0);
6513 aView->Window()->Size (aWinSize.x(), aWinSize.y());
6515 // 1 shadow ray and 1 secondary ray pew each bounce
6516 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
6517 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
6523 //! Auxiliary function for parsing glsl dump level argument.
6524 static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
6525 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
6527 TCollection_AsciiString aTypeStr (theArg);
6528 aTypeStr.LowerCase();
6529 if (aTypeStr == "off"
6532 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6534 else if (aTypeStr == "short")
6536 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
6538 else if (aTypeStr == "full"
6541 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6545 return Standard_False;
6547 return Standard_True;
6550 //==============================================================================
6551 //function : VGlDebug
6553 //==============================================================================
6555 static int VGlDebug (Draw_Interpretor& theDI,
6556 Standard_Integer theArgNb,
6557 const char** theArgVec)
6559 Handle(OpenGl_GraphicDriver) aDriver;
6560 Handle(V3d_View) aView = ViewerTest::CurrentView();
6561 if (!aView.IsNull())
6563 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
6565 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
6566 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
6570 TCollection_AsciiString aDebActive, aSyncActive;
6577 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
6578 "GL_ARB_debug_output");
6579 aDebActive = isActive ? " (active)" : " (inactive)";
6582 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
6583 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
6587 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
6588 + "glslSourceCode: "
6589 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
6591 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
6595 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
6596 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
6597 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
6598 << aGlslCodeDebugStatus
6599 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
6603 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6605 Standard_CString anArg = theArgVec[anArgIter];
6606 TCollection_AsciiString anArgCase (anArg);
6607 anArgCase.LowerCase();
6608 Standard_Boolean toEnableDebug = Standard_True;
6609 if (anArgCase == "-glsl"
6610 || anArgCase == "-glslwarn"
6611 || anArgCase == "-glslwarns"
6612 || anArgCase == "-glslwarnings")
6614 Standard_Boolean toShowWarns = Standard_True;
6615 if (++anArgIter < theArgNb
6616 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
6620 aDefCaps->glslWarnings = toShowWarns;
6623 aCaps->glslWarnings = toShowWarns;
6626 else if (anArgCase == "-extra"
6627 || anArgCase == "-extramsg"
6628 || anArgCase == "-extramessages")
6630 Standard_Boolean toShow = Standard_True;
6631 if (++anArgIter < theArgNb
6632 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
6636 aDefCaps->suppressExtraMsg = !toShow;
6639 aCaps->suppressExtraMsg = !toShow;
6642 else if (anArgCase == "-noextra"
6643 || anArgCase == "-noextramsg"
6644 || anArgCase == "-noextramessages")
6646 Standard_Boolean toSuppress = Standard_True;
6647 if (++anArgIter < theArgNb
6648 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
6652 aDefCaps->suppressExtraMsg = toSuppress;
6655 aCaps->suppressExtraMsg = toSuppress;
6658 else if (anArgCase == "-sync")
6660 Standard_Boolean toSync = Standard_True;
6661 if (++anArgIter < theArgNb
6662 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
6666 aDefCaps->contextSyncDebug = toSync;
6669 aDefCaps->contextDebug = Standard_True;
6672 else if (anArgCase == "-glslsourcecode"
6673 || anArgCase == "-glslcode")
6675 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6676 if (++anArgIter < theArgNb
6677 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
6681 aDefCaps->glslDumpLevel = aGslsDumpLevel;
6684 aCaps->glslDumpLevel = aGslsDumpLevel;
6687 else if (anArgCase == "-debug")
6689 if (++anArgIter < theArgNb
6690 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
6694 aDefCaps->contextDebug = toEnableDebug;
6696 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
6697 && (anArgIter + 1 == theArgNb))
6699 // simple alias to turn on almost everything
6700 aDefCaps->contextDebug = toEnableDebug;
6701 aDefCaps->contextSyncDebug = toEnableDebug;
6702 aDefCaps->glslWarnings = toEnableDebug;
6705 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6707 aDefCaps->suppressExtraMsg = !toEnableDebug;
6710 aCaps->contextDebug = toEnableDebug;
6711 aCaps->contextSyncDebug = toEnableDebug;
6712 aCaps->glslWarnings = toEnableDebug;
6715 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6717 aCaps->suppressExtraMsg = !toEnableDebug;
6722 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
6730 //==============================================================================
6733 //==============================================================================
6735 static int VVbo (Draw_Interpretor& theDI,
6736 Standard_Integer theArgNb,
6737 const char** theArgVec)
6739 const Standard_Boolean toSet = (theArgNb > 1);
6740 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
6743 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
6747 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6748 if (aContextAIS.IsNull())
6752 std::cerr << "No active view!\n";
6756 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
6757 if (!aDriver.IsNull())
6761 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
6765 aDriver->ChangeOptions().vboDisable = toUseVbo;
6772 //==============================================================================
6775 //==============================================================================
6777 static int VCaps (Draw_Interpretor& theDI,
6778 Standard_Integer theArgNb,
6779 const char** theArgVec)
6781 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
6782 Handle(OpenGl_GraphicDriver) aDriver;
6783 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6784 if (!aContext.IsNull())
6786 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
6787 aCaps = &aDriver->ChangeOptions();
6792 theDI << "sRGB: " << (aCaps->sRGBDisable ? "0" : "1") << "\n";
6793 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
6794 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
6795 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
6796 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
6797 theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n";
6798 theDI << "VSync: " << aCaps->swapInterval << "\n";
6799 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
6800 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
6801 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
6802 theDI << "NoExt:" << (aCaps->contextNoExtensions ? "1" : "0") << "\n";
6803 theDI << "MaxVersion:" << aCaps->contextMajorVersionUpper << "." << aCaps->contextMinorVersionUpper << "\n";
6807 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6808 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6810 Standard_CString anArg = theArgVec[anArgIter];
6811 TCollection_AsciiString anArgCase (anArg);
6812 anArgCase.LowerCase();
6813 if (anUpdateTool.parseRedrawMode (anArg))
6817 else if (anArgCase == "-vsync"
6818 || anArgCase == "-swapinterval")
6820 Standard_Boolean toEnable = Standard_True;
6821 if (++anArgIter < theArgNb
6822 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6826 aCaps->swapInterval = toEnable;
6828 else if (anArgCase == "-ffp")
6830 Standard_Boolean toEnable = Standard_True;
6831 if (++anArgIter < theArgNb
6832 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6836 aCaps->ffpEnable = toEnable;
6838 else if (anArgCase == "-polygonmode")
6840 Standard_Boolean toEnable = Standard_True;
6841 if (++anArgIter < theArgNb
6842 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6846 aCaps->usePolygonMode = toEnable;
6848 else if (anArgCase == "-srgb")
6850 Standard_Boolean toEnable = Standard_True;
6851 if (++anArgIter < theArgNb
6852 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6856 aCaps->sRGBDisable = !toEnable;
6858 else if (anArgCase == "-vbo")
6860 Standard_Boolean toEnable = Standard_True;
6861 if (++anArgIter < theArgNb
6862 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6866 aCaps->vboDisable = !toEnable;
6868 else if (anArgCase == "-sprite"
6869 || anArgCase == "-sprites")
6871 Standard_Boolean toEnable = Standard_True;
6872 if (++anArgIter < theArgNb
6873 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6877 aCaps->pntSpritesDisable = !toEnable;
6879 else if (anArgCase == "-softmode")
6881 Standard_Boolean toEnable = Standard_True;
6882 if (++anArgIter < theArgNb
6883 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6887 aCaps->contextNoAccel = toEnable;
6889 else if (anArgCase == "-winbuffer"
6890 || anArgCase == "-windowbuffer"
6891 || anArgCase == "-usewinbuffer"
6892 || anArgCase == "-usewindowbuffer"
6893 || anArgCase == "-usesystembuffer")
6895 Standard_Boolean toEnable = Standard_True;
6896 if (++anArgIter < theArgNb
6897 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6901 aCaps->useSystemBuffer = toEnable;
6903 else if (anArgCase == "-accel"
6904 || anArgCase == "-acceleration")
6906 Standard_Boolean toEnable = Standard_True;
6907 if (++anArgIter < theArgNb
6908 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6912 aCaps->contextNoAccel = !toEnable;
6914 else if (anArgCase == "-compat"
6915 || anArgCase == "-compatprofile"
6916 || anArgCase == "-compatible"
6917 || anArgCase == "-compatibleprofile")
6919 Standard_Boolean toEnable = Standard_True;
6920 if (++anArgIter < theArgNb
6921 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6925 aCaps->contextCompatible = toEnable;
6926 if (!aCaps->contextCompatible)
6928 aCaps->ffpEnable = Standard_False;
6931 else if (anArgCase == "-core"
6932 || anArgCase == "-coreprofile")
6934 Standard_Boolean toEnable = Standard_True;
6935 if (++anArgIter < theArgNb
6936 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6940 aCaps->contextCompatible = !toEnable;
6941 if (!aCaps->contextCompatible)
6943 aCaps->ffpEnable = Standard_False;
6946 else if (anArgCase == "-stereo"
6947 || anArgCase == "-quadbuffer")
6949 Standard_Boolean toEnable = Standard_True;
6950 if (++anArgIter < theArgNb
6951 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6955 aCaps->contextStereo = toEnable;
6957 else if (anArgCase == "-noext"
6958 || anArgCase == "-noextensions"
6959 || anArgCase == "-noextension")
6961 Standard_Boolean toDisable = Standard_True;
6962 if (++anArgIter < theArgNb
6963 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
6967 aCaps->contextNoExtensions = toDisable;
6969 else if (anArgCase == "-maxversion"
6970 || anArgCase == "-upperversion"
6971 || anArgCase == "-limitversion")
6973 Standard_Integer aVer[2] = { -2, -1 };
6974 for (Standard_Integer aValIter = 0; aValIter < 2; ++aValIter)
6976 if (anArgIter + 1 < theArgNb)
6978 const TCollection_AsciiString aStr (theArgVec[anArgIter + 1]);
6979 if (aStr.IsIntegerValue())
6981 aVer[aValIter] = aStr.IntegerValue();
6989 std::cout << "Syntax error at '" << anArgCase << "'\n";
6992 aCaps->contextMajorVersionUpper = aVer[0];
6993 aCaps->contextMinorVersionUpper = aVer[1];
6997 std::cout << "Error: unknown argument '" << anArg << "'\n";
7001 if (aCaps != &ViewerTest_myDefaultCaps)
7003 ViewerTest_myDefaultCaps = *aCaps;
7008 //==============================================================================
7009 //function : VMemGpu
7011 //==============================================================================
7013 static int VMemGpu (Draw_Interpretor& theDI,
7014 Standard_Integer theArgNb,
7015 const char** theArgVec)
7018 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
7019 if (aContextAIS.IsNull())
7021 std::cerr << "No active view. Please call vinit.\n";
7025 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
7026 if (aDriver.IsNull())
7028 std::cerr << "Graphic driver not available.\n";
7032 Standard_Size aFreeBytes = 0;
7033 TCollection_AsciiString anInfo;
7034 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
7036 std::cerr << "Information not available.\n";
7040 if (theArgNb > 1 && *theArgVec[1] == 'f')
7042 theDI << Standard_Real (aFreeBytes);
7052 // ==============================================================================
7053 // function : VReadPixel
7055 // ==============================================================================
7056 static int VReadPixel (Draw_Interpretor& theDI,
7057 Standard_Integer theArgNb,
7058 const char** theArgVec)
7060 // get the active view
7061 Handle(V3d_View) aView = ViewerTest::CurrentView();
7064 std::cerr << "No active view. Please call vinit.\n";
7067 else if (theArgNb < 3)
7069 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
7073 Image_Format aFormat = Image_Format_RGBA;
7074 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
7076 Standard_Integer aWidth, aHeight;
7077 aView->Window()->Size (aWidth, aHeight);
7078 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
7079 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
7080 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
7082 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
7086 bool toShowName = false, toShowHls = false, toShowHex = false, toShow_sRGB = false;
7087 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
7089 TCollection_AsciiString aParam (theArgVec[anIter]);
7091 if (aParam == "-rgb"
7093 || aParam == "-srgb"
7094 || aParam == "srgb")
7096 aFormat = Image_Format_RGB;
7097 aBufferType = Graphic3d_BT_RGB;
7098 toShow_sRGB = aParam == "-srgb" || aParam == "srgb";
7100 else if (aParam == "-hls"
7103 aFormat = Image_Format_RGB;
7104 aBufferType = Graphic3d_BT_RGB;
7105 toShowHls = Standard_True;
7107 else if (aParam == "-rgbf"
7108 || aParam == "rgbf")
7110 aFormat = Image_Format_RGBF;
7111 aBufferType = Graphic3d_BT_RGB;
7113 else if (aParam == "-rgba"
7115 || aParam == "-srgba"
7116 || aParam == "srgba")
7118 aFormat = Image_Format_RGBA;
7119 aBufferType = Graphic3d_BT_RGBA;
7120 toShow_sRGB = aParam == "-srgba" || aParam == "srgba";
7122 else if (aParam == "-rgbaf"
7123 || aParam == "rgbaf")
7125 aFormat = Image_Format_RGBAF;
7126 aBufferType = Graphic3d_BT_RGBA;
7128 else if (aParam == "-depth"
7129 || aParam == "depth")
7131 aFormat = Image_Format_GrayF;
7132 aBufferType = Graphic3d_BT_Depth;
7134 else if (aParam == "-name"
7135 || aParam == "name")
7137 toShowName = Standard_True;
7139 else if (aParam == "-hex"
7142 toShowHex = Standard_True;
7146 std::cout << "Syntax error at '" << aParam << "'\n";
7151 Image_PixMap anImage;
7152 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
7154 std::cerr << "Image allocation failed\n";
7157 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
7159 std::cerr << "Image dump failed\n";
7163 // redirect possible warning messages that could have been added by ToPixMap
7164 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
7165 // contaminate result of the command
7166 Standard_CString aWarnLog = theDI.Result();
7167 if (aWarnLog != NULL && aWarnLog[0] != '\0')
7169 std::cout << aWarnLog << std::endl;
7173 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY, true);
7176 if (aBufferType == Graphic3d_BT_RGBA)
7178 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
7182 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
7187 if (aBufferType == Graphic3d_BT_RGBA)
7189 theDI << Quantity_ColorRGBA::ColorToHex (aColor);
7193 theDI << Quantity_Color::ColorToHex (aColor.GetRGB());
7198 switch (aBufferType)
7201 case Graphic3d_BT_RGB:
7205 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
7207 else if (toShow_sRGB)
7209 const Graphic3d_Vec4 aColor_sRGB = Quantity_ColorRGBA::Convert_LinearRGB_To_sRGB ((Graphic3d_Vec4 )aColor);
7210 theDI << aColor_sRGB.r() << " " << aColor_sRGB.g() << " " << aColor_sRGB.b();
7214 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
7218 case Graphic3d_BT_RGBA:
7220 const Graphic3d_Vec4 aVec4 = toShow_sRGB ? Quantity_ColorRGBA::Convert_LinearRGB_To_sRGB ((Graphic3d_Vec4 )aColor) : (Graphic3d_Vec4 )aColor;
7221 theDI << aVec4.r() << " " << aVec4.g() << " " << aVec4.b() << " " << aVec4.a();
7224 case Graphic3d_BT_Depth:
7226 theDI << aColor.GetRGB().Red();
7235 //! Auxiliary presentation for an image plane.
7236 class ViewerTest_ImagePrs : public AIS_InteractiveObject
7239 //! Main constructor.
7240 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
7241 const Standard_Real theWidth,
7242 const Standard_Real theHeight,
7243 const TCollection_AsciiString& theLabel)
7244 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
7248 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
7250 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
7251 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
7252 Graphic3d_MaterialAspect aMat;
7253 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
7254 aMat.SetAmbientColor (Quantity_NOC_BLACK);
7255 aMat.SetDiffuseColor (Quantity_NOC_WHITE);
7256 aMat.SetSpecularColor (Quantity_NOC_BLACK);
7257 aMat.SetEmissiveColor (Quantity_NOC_BLACK);
7258 aFillAspect->SetFrontMaterial (aMat);
7259 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
7260 aFillAspect->SetTextureMapOn();
7263 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
7264 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
7265 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
7266 myDrawer->SetTextAspect (aTextAspect);
7269 const gp_Dir aNorm (0.0, 0.0, 1.0);
7270 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
7271 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
7272 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
7273 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
7274 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
7275 myTris->AddEdge (1);
7276 myTris->AddEdge (2);
7277 myTris->AddEdge (3);
7278 myTris->AddEdge (3);
7279 myTris->AddEdge (2);
7280 myTris->AddEdge (4);
7282 myRect = new Graphic3d_ArrayOfPolylines (4);
7283 myRect->AddVertex (myTris->Vertice (1));
7284 myRect->AddVertex (myTris->Vertice (3));
7285 myRect->AddVertex (myTris->Vertice (4));
7286 myRect->AddVertex (myTris->Vertice (2));
7290 //! Returns TRUE for accepted display modes.
7291 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
7293 //! Compute presentation.
7294 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
7300 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7301 aGroup->AddPrimitiveArray (myTris);
7302 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
7303 aGroup->AddPrimitiveArray (myRect);
7304 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7309 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
7310 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7311 aGroup->AddPrimitiveArray (myRect);
7312 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7318 //! Compute selection.
7319 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
7323 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
7324 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
7325 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
7326 theSel->Add (aSensitive);
7331 Handle(Graphic3d_ArrayOfTriangles) myTris;
7332 Handle(Graphic3d_ArrayOfPolylines) myRect;
7333 TCollection_AsciiString myLabel;
7334 Standard_Real myWidth;
7335 Standard_Real myHeight;
7338 //==============================================================================
7339 //function : VDiffImage
7340 //purpose : The draw-command compares two images.
7341 //==============================================================================
7343 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
7347 std::cout << "Syntax error: not enough arguments.\n";
7351 Standard_Integer anArgIter = 1;
7352 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
7353 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
7354 TCollection_AsciiString aDiffImagePath;
7355 Standard_Real aTolColor = -1.0;
7356 Standard_Integer toBlackWhite = -1;
7357 Standard_Integer isBorderFilterOn = -1;
7358 Standard_Boolean isOldSyntax = Standard_False;
7359 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
7360 for (; anArgIter < theArgNb; ++anArgIter)
7362 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7364 if (anArgIter + 1 < theArgNb
7365 && (anArg == "-toleranceofcolor"
7366 || anArg == "-tolerancecolor"
7367 || anArg == "-tolerance"
7368 || anArg == "-toler"))
7370 aTolColor = Atof (theArgVec[++anArgIter]);
7371 if (aTolColor < 0.0 || aTolColor > 1.0)
7373 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7377 else if (anArg == "-blackwhite")
7379 Standard_Boolean toEnable = Standard_True;
7380 if (anArgIter + 1 < theArgNb
7381 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7385 toBlackWhite = toEnable ? 1 : 0;
7387 else if (anArg == "-borderfilter")
7389 Standard_Boolean toEnable = Standard_True;
7390 if (anArgIter + 1 < theArgNb
7391 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7395 isBorderFilterOn = toEnable ? 1 : 0;
7397 else if (anArg == "-exitonclose")
7399 ViewerTest_EventManager::ToExitOnCloseView() = true;
7400 if (anArgIter + 1 < theArgNb
7401 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToExitOnCloseView()))
7406 else if (anArg == "-closeonescape"
7407 || anArg == "-closeonesc")
7409 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
7410 if (anArgIter + 1 < theArgNb
7411 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
7416 else if (anArgIter + 3 < theArgNb
7417 && anArg == "-display")
7419 aViewName = theArgVec[++anArgIter];
7420 aPrsNameRef = theArgVec[++anArgIter];
7421 aPrsNameNew = theArgVec[++anArgIter];
7422 if (anArgIter + 1 < theArgNb
7423 && *theArgVec[anArgIter + 1] != '-')
7425 aPrsNameDiff = theArgVec[++anArgIter];
7428 else if (aTolColor < 0.0
7429 && anArg.IsRealValue())
7431 isOldSyntax = Standard_True;
7432 aTolColor = anArg.RealValue();
7433 if (aTolColor < 0.0 || aTolColor > 1.0)
7435 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7439 else if (isOldSyntax
7440 && toBlackWhite == -1
7441 && (anArg == "0" || anArg == "1"))
7443 toBlackWhite = anArg == "1" ? 1 : 0;
7445 else if (isOldSyntax
7446 && isBorderFilterOn == -1
7447 && (anArg == "0" || anArg == "1"))
7449 isBorderFilterOn = anArg == "1" ? 1 : 0;
7451 else if (aDiffImagePath.IsEmpty())
7453 aDiffImagePath = theArgVec[anArgIter];
7457 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7462 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
7463 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
7464 if (!anImgRef->Load (anImgPathRef))
7466 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
7469 if (!anImgNew->Load (anImgPathNew))
7471 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
7475 // compare the images
7476 Image_Diff aComparer;
7477 Standard_Integer aDiffColorsNb = -1;
7478 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
7480 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
7481 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
7482 aDiffColorsNb = aComparer.Compare();
7483 theDI << aDiffColorsNb << "\n";
7486 // save image of difference
7487 Handle(Image_AlienPixMap) aDiff;
7488 if (aDiffColorsNb > 0
7489 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
7491 aDiff = new Image_AlienPixMap();
7492 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
7494 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
7497 aComparer.SaveDiffImage (*aDiff);
7498 if (!aDiffImagePath.IsEmpty()
7499 && !aDiff->Save (aDiffImagePath))
7501 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
7506 if (aViewName.IsEmpty())
7511 ViewerTest_Names aViewNames (aViewName);
7512 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
7514 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
7515 theDI.Eval (aCommand.ToCString());
7518 Standard_Integer aPxLeft = 0;
7519 Standard_Integer aPxTop = 0;
7520 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
7521 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
7522 ? int(anImgRef->SizeY() * 2)
7523 : int(anImgRef->SizeY());
7524 TCollection_AsciiString aDisplayName;
7525 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
7526 aViewName, aDisplayName);
7528 Standard_Real aRatio = anImgRef->Ratio();
7529 Standard_Real aSizeX = 1.0;
7530 Standard_Real aSizeY = aSizeX / aRatio;
7532 OSD_Path aPath (anImgPathRef);
7533 TCollection_AsciiString aLabelRef;
7534 if (!aPath.Name().IsEmpty())
7536 aLabelRef = aPath.Name() + aPath.Extension();
7538 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
7540 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
7542 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
7543 anImgRefPrs->SetLocalTransformation (aTrsfRef);
7544 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
7547 OSD_Path aPath (anImgPathNew);
7548 TCollection_AsciiString aLabelNew;
7549 if (!aPath.Name().IsEmpty())
7551 aLabelNew = aPath.Name() + aPath.Extension();
7553 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
7555 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
7557 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
7558 anImgNewPrs->SetLocalTransformation (aTrsfRef);
7559 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
7561 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
7562 if (!aDiff.IsNull())
7564 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
7566 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
7567 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
7569 if (!aPrsNameDiff.IsEmpty())
7571 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
7573 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
7574 ViewerTest::CurrentView()->FitAll();
7578 //=======================================================================
7579 //function : VSelect
7580 //purpose : Emulates different types of selection by mouse:
7581 // 1) single click selection
7582 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
7583 // 3) selection with polygon having corners at
7584 // pixel positions (x1,y1),...,(xn,yn)
7585 // 4) any of these selections with shift button pressed
7586 //=======================================================================
7587 static Standard_Integer VSelect (Draw_Interpretor& ,
7588 Standard_Integer theNbArgs,
7589 const char** theArgVec)
7591 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7594 std::cout << "Error: no active View\n";
7598 NCollection_Sequence<Graphic3d_Vec2i> aPnts;
7599 bool isShiftSelection = false, toAllowOverlap = false;
7600 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7602 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7604 if (anArg == "-allowoverlap")
7606 toAllowOverlap = true;
7607 if (anArgIter + 1 < theNbArgs
7608 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toAllowOverlap))
7613 else if (anArgIter + 1 < theNbArgs
7614 && anArg.IsIntegerValue()
7615 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
7617 const TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
7618 aPnts.Append (Graphic3d_Vec2i (anArg.IntegerValue(), anArgNext.IntegerValue()));
7620 else if (anArgIter + 1 == theNbArgs
7621 && anArg.IsIntegerValue())
7623 isShiftSelection = anArg.IntegerValue() == 1;
7627 std::cout << "Syntax error at '" << anArg << "'\n";
7632 && aPnts.Length() != 2)
7634 std::cout << "Syntax error: -allowoverlap key is applied only for rectangle selection\n";
7639 aCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
7642 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
7643 if (aPnts.IsEmpty())
7645 if (isShiftSelection)
7647 aCtx->ShiftSelect (false);
7651 aCtx->Select (false);
7653 aCtx->CurrentViewer()->Invalidate();
7655 else if (aPnts.Length() == 2)
7658 && aPnts.First().y() < aPnts.Last().y())
7660 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7662 else if (!toAllowOverlap
7663 && aPnts.First().y() > aPnts.Last().y())
7665 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7667 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
7671 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
7673 aCurrentEventManager->FlushViewEvents (aCtx, ViewerTest::CurrentView(), true);
7677 //=======================================================================
7678 //function : VMoveTo
7679 //purpose : Emulates cursor movement to defined pixel position
7680 //=======================================================================
7681 static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
7682 Standard_Integer theNbArgs,
7683 const char** theArgVec)
7685 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
7686 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
7687 if (aContext.IsNull())
7689 std::cout << "Error: no active View\n";
7693 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
7694 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7696 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
7697 anArgStr.LowerCase();
7698 if (anArgStr == "-reset"
7699 || anArgStr == "-clear")
7701 if (anArgIter + 1 < theNbArgs)
7703 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
7707 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
7708 && aContext->CurrentViewer()->GridEcho();
7711 aContext->CurrentViewer()->HideGridEcho (aView);
7713 if (aContext->ClearDetected() || toEchoGrid)
7715 aContext->CurrentViewer()->RedrawImmediate();
7719 else if (aMousePos.x() == IntegerLast()
7720 && anArgStr.IsIntegerValue())
7722 aMousePos.x() = anArgStr.IntegerValue();
7724 else if (aMousePos.y() == IntegerLast()
7725 && anArgStr.IsIntegerValue())
7727 aMousePos.y() = anArgStr.IntegerValue();
7731 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7736 if (aMousePos.x() == IntegerLast()
7737 || aMousePos.y() == IntegerLast())
7739 std::cout << "Syntax error: wrong number of arguments\n";
7743 ViewerTest::CurrentEventManager()->ResetPreviousMoveTo();
7744 ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false);
7745 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
7747 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
7748 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
7749 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
7751 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
7753 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
7757 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
7763 //! Global map storing all animations registered in ViewerTest.
7764 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
7766 //! The animation calling the Draw Harness command.
7767 class ViewerTest_AnimationProc : public AIS_Animation
7771 //! Main constructor.
7772 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
7773 Draw_Interpretor* theDI,
7774 const TCollection_AsciiString& theCommand)
7775 : AIS_Animation (theAnimationName),
7777 myCommand (theCommand)
7784 //! Evaluate the command.
7785 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
7787 TCollection_AsciiString aCmd = myCommand;
7788 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
7789 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
7790 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
7791 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
7792 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
7793 myDrawInter->Eval (aCmd.ToCString());
7796 //! Find the keyword in the command and replace it with value.
7797 //! @return the position of the keyword to pass value
7798 void replace (TCollection_AsciiString& theCmd,
7799 const TCollection_AsciiString& theKey,
7800 const TCollection_AsciiString& theVal)
7802 TCollection_AsciiString aCmd (theCmd);
7804 const Standard_Integer aPos = aCmd.Search (theKey);
7810 TCollection_AsciiString aPart1, aPart2;
7811 Standard_Integer aPart1To = aPos - 1;
7813 && aPart1To <= theCmd.Length())
7815 aPart1 = theCmd.SubString (1, aPart1To);
7818 Standard_Integer aPart2From = aPos + theKey.Length();
7820 && aPart2From <= theCmd.Length())
7822 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
7825 theCmd = aPart1 + theVal + aPart2;
7830 Draw_Interpretor* myDrawInter;
7831 TCollection_AsciiString myCommand;
7835 //! Replace the animation with the new one.
7836 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
7837 Handle(AIS_Animation)& theAnimation,
7838 const Handle(AIS_Animation)& theAnimationNew)
7840 theAnimationNew->CopyFrom (theAnimation);
7841 if (!theParentAnimation.IsNull())
7843 theParentAnimation->Replace (theAnimation, theAnimationNew);
7847 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
7848 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
7850 theAnimation = theAnimationNew;
7853 //! Parse the point.
7854 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
7856 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
7857 if (!anXYZ[0].IsRealValue()
7858 || !anXYZ[1].IsRealValue()
7859 || !anXYZ[2].IsRealValue())
7861 return Standard_False;
7864 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
7865 return Standard_True;
7868 //! Parse the quaternion.
7869 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
7871 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
7872 if (!anXYZW[0].IsRealValue()
7873 || !anXYZW[1].IsRealValue()
7874 || !anXYZW[2].IsRealValue()
7875 || !anXYZW[3].IsRealValue())
7877 return Standard_False;
7880 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
7881 return Standard_True;
7884 //! Auxiliary class for flipping image upside-down.
7889 //! Empty constructor.
7890 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
7892 //! Perform flipping.
7893 Standard_Boolean FlipY (Image_PixMap& theImage)
7895 if (theImage.IsEmpty()
7896 || theImage.SizeX() == 0
7897 || theImage.SizeY() == 0)
7899 return Standard_False;
7902 const Standard_Size aRowSize = theImage.SizeRowBytes();
7903 if (myTmp.Size() < aRowSize
7904 && !myTmp.Allocate (aRowSize))
7906 return Standard_False;
7909 // for odd height middle row should be left as is
7910 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
7911 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
7913 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
7914 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
7915 memcpy (myTmp.ChangeData(), aTop, aRowSize);
7916 memcpy (aTop, aBot, aRowSize);
7917 memcpy (aBot, myTmp.Data(), aRowSize);
7919 return Standard_True;
7923 NCollection_Buffer myTmp;
7928 //=================================================================================================
7929 //function : VViewParams
7930 //purpose : Gets or sets AIS View characteristics
7931 //=================================================================================================
7932 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7934 Handle(V3d_View) aView = ViewerTest::CurrentView();
7937 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
7941 Standard_Boolean toSetProj = Standard_False;
7942 Standard_Boolean toSetUp = Standard_False;
7943 Standard_Boolean toSetAt = Standard_False;
7944 Standard_Boolean toSetEye = Standard_False;
7945 Standard_Boolean toSetScale = Standard_False;
7946 Standard_Boolean toSetSize = Standard_False;
7947 Standard_Boolean toSetCenter2d = Standard_False;
7948 Standard_Real aViewScale = aView->Scale();
7949 Standard_Real aViewSize = 1.0;
7950 Graphic3d_Vec2i aCenter2d;
7951 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
7952 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
7953 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
7954 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
7955 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
7958 // print all of the available view parameters
7962 "Proj: %12g %12g %12g\n"
7963 "Up: %12g %12g %12g\n"
7964 "At: %12g %12g %12g\n"
7965 "Eye: %12g %12g %12g\n",
7967 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7968 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7969 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
7970 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7975 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7976 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7978 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7980 if (anUpdateTool.parseRedrawMode (anArg))
7984 else if (anArg == "-cmd"
7985 || anArg == "-command"
7986 || anArg == "-args")
7995 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7996 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7997 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
8000 else if (anArg == "-scale"
8001 || anArg == "-size")
8003 if (anArgIter + 1 < theArgsNb
8004 && *theArgVec[anArgIter + 1] != '-')
8006 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
8007 if (aValueArg.IsRealValue())
8010 if (anArg == "-scale")
8012 toSetScale = Standard_True;
8013 aViewScale = aValueArg.RealValue();
8015 else if (anArg == "-size")
8017 toSetSize = Standard_True;
8018 aViewSize = aValueArg.RealValue();
8023 if (anArg == "-scale")
8025 theDi << "Scale: " << aView->Scale() << "\n";
8027 else if (anArg == "-size")
8029 Graphic3d_Vec2d aSizeXY;
8030 aView->Size (aSizeXY.x(), aSizeXY.y());
8031 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
8034 else if (anArg == "-eye"
8037 || anArg == "-proj")
8039 if (anArgIter + 3 < theArgsNb)
8042 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
8045 if (anArg == "-eye")
8047 toSetEye = Standard_True;
8050 else if (anArg == "-at")
8052 toSetAt = Standard_True;
8055 else if (anArg == "-up")
8057 toSetUp = Standard_True;
8060 else if (anArg == "-proj")
8062 toSetProj = Standard_True;
8069 if (anArg == "-eye")
8071 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
8073 else if (anArg == "-at")
8075 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
8077 else if (anArg == "-up")
8079 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
8081 else if (anArg == "-proj")
8083 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
8086 else if (anArg == "-center")
8088 if (anArgIter + 2 < theArgsNb)
8090 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
8091 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
8092 if (anX.IsIntegerValue()
8093 && anY.IsIntegerValue())
8095 toSetCenter2d = Standard_True;
8096 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
8102 std::cout << "Syntax error at '" << anArg << "'\n";
8107 // change view parameters in proper order
8110 aView->SetScale (aViewScale);
8114 aView->SetSize (aViewSize);
8118 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
8122 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
8126 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
8130 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
8134 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
8140 //==============================================================================
8141 //function : V2DMode
8143 //==============================================================================
8144 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
8146 bool is2dMode = true;
8147 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
8148 if (aV3dView.IsNull())
8150 std::cout << "Error: no active view.\n";
8153 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
8155 const TCollection_AsciiString anArg = theArgVec[anArgIt];
8156 TCollection_AsciiString anArgCase = anArg;
8157 anArgCase.LowerCase();
8158 if (anArgIt + 1 < theArgsNb
8159 && anArgCase == "-name")
8161 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
8162 TCollection_AsciiString aViewName = aViewNames.GetViewName();
8163 if (!ViewerTest_myViews.IsBound1 (aViewName))
8165 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
8168 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
8170 else if (anArgCase == "-mode")
8172 if (anArgIt + 1 < theArgsNb
8173 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
8178 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
8184 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
8189 aV3dView->SetView2DMode (is2dMode);
8193 //==============================================================================
8194 //function : VAnimation
8196 //==============================================================================
8197 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
8198 Standard_Integer theArgNb,
8199 const char** theArgVec)
8201 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
8204 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
8205 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
8207 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
8213 std::cout << "Error: no active view\n";
8217 Standard_Integer anArgIter = 1;
8218 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
8219 if (aNameArg.IsEmpty())
8221 std::cout << "Syntax error: animation name is not defined.\n";
8225 TCollection_AsciiString aNameArgLower = aNameArg;
8226 aNameArgLower.LowerCase();
8227 if (aNameArgLower == "-reset"
8228 || aNameArgLower == "-clear")
8230 ViewerTest_AnimationTimelineMap.Clear();
8233 else if (aNameArg.Value (1) == '-')
8235 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
8239 const char* aNameSplitter = "/";
8240 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
8241 if (aSplitPos == -1)
8243 aNameSplitter = ".";
8244 aSplitPos = aNameArg.Search (aNameSplitter);
8247 // find existing or create a new animation by specified name within syntax "parent.child".
8248 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
8249 for (; !aNameArg.IsEmpty();)
8251 TCollection_AsciiString aNameParent;
8252 if (aSplitPos != -1)
8254 if (aSplitPos == aNameArg.Length())
8256 std::cout << "Syntax error: animation name is not defined.\n";
8260 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
8261 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
8263 aSplitPos = aNameArg.Search (aNameSplitter);
8267 aNameParent = aNameArg;
8271 if (anAnimation.IsNull())
8273 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
8275 anAnimation = new AIS_Animation (aNameParent);
8276 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
8278 aRootAnimation = anAnimation;
8282 aParentAnimation = anAnimation;
8283 anAnimation = aParentAnimation->Find (aNameParent);
8284 if (anAnimation.IsNull())
8286 anAnimation = new AIS_Animation (aNameParent);
8287 aParentAnimation->Add (anAnimation);
8292 if (anArgIter >= theArgNb)
8294 // just print the list of children
8295 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
8297 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
8302 // animation parameters
8303 Standard_Boolean toPlay = Standard_False;
8304 Standard_Real aPlaySpeed = 1.0;
8305 Standard_Real aPlayStartTime = anAnimation->StartPts();
8306 Standard_Real aPlayDuration = anAnimation->Duration();
8307 Standard_Boolean isFreeCamera = Standard_False;
8308 Standard_Boolean isLockLoop = Standard_False;
8310 // video recording parameters
8311 TCollection_AsciiString aRecFile;
8312 Image_VideoParams aRecParams;
8314 Handle(V3d_View) aView = ViewerTest::CurrentView();
8315 for (; anArgIter < theArgNb; ++anArgIter)
8317 TCollection_AsciiString anArg (theArgVec[anArgIter]);
8320 if (anArg == "-reset"
8321 || anArg == "-clear")
8323 anAnimation->Clear();
8325 else if (anArg == "-remove"
8327 || anArg == "-delete")
8329 if (!aParentAnimation.IsNull())
8331 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
8335 aParentAnimation->Remove (anAnimation);
8339 else if (anArg == "-play")
8341 toPlay = Standard_True;
8342 if (++anArgIter < theArgNb)
8344 if (*theArgVec[anArgIter] == '-')
8349 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
8351 if (++anArgIter < theArgNb)
8353 if (*theArgVec[anArgIter] == '-')
8358 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8362 else if (anArg == "-resume")
8364 toPlay = Standard_True;
8365 aPlayStartTime = anAnimation->ElapsedTime();
8366 if (++anArgIter < theArgNb)
8368 if (*theArgVec[anArgIter] == '-')
8374 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8377 else if (anArg == "-playspeed"
8378 || anArg == "-speed")
8380 if (++anArgIter >= theArgNb)
8382 std::cout << "Syntax error at " << anArg << ".\n";
8385 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
8387 else if (anArg == "-lock"
8388 || anArg == "-lockloop"
8389 || anArg == "-playlockloop")
8391 isLockLoop = Standard_True;
8393 else if (anArg == "-freecamera"
8394 || anArg == "-playfreecamera"
8395 || anArg == "-freelook")
8397 isFreeCamera = Standard_True;
8399 // video recodring options
8400 else if (anArg == "-rec"
8401 || anArg == "-record")
8403 if (++anArgIter >= theArgNb)
8405 std::cout << "Syntax error at " << anArg << ".\n";
8409 aRecFile = theArgVec[anArgIter];
8410 if (aRecParams.FpsNum <= 0)
8412 aRecParams.FpsNum = 24;
8415 if (anArgIter + 2 < theArgNb
8416 && *theArgVec[anArgIter + 1] != '-'
8417 && *theArgVec[anArgIter + 2] != '-')
8419 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
8420 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
8421 if (aWidthArg .IsIntegerValue()
8422 && aHeightArg.IsIntegerValue())
8424 aRecParams.Width = aWidthArg .IntegerValue();
8425 aRecParams.Height = aHeightArg.IntegerValue();
8430 else if (anArg == "-fps")
8432 if (++anArgIter >= theArgNb)
8434 std::cout << "Syntax error at " << anArg << ".\n";
8438 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
8439 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
8440 if (aSplitIndex == 0)
8442 aRecParams.FpsNum = aFpsArg.IntegerValue();
8446 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
8447 aFpsArg.Split (aFpsArg.Length() - 1);
8448 const TCollection_AsciiString aNumStr = aFpsArg;
8449 aRecParams.FpsNum = aNumStr.IntegerValue();
8450 aRecParams.FpsDen = aDenStr.IntegerValue();
8451 if (aRecParams.FpsDen < 1)
8453 std::cout << "Syntax error at " << anArg << ".\n";
8458 else if (anArg == "-format")
8460 if (++anArgIter >= theArgNb)
8462 std::cout << "Syntax error at " << anArg << ".\n";
8465 aRecParams.Format = theArgVec[anArgIter];
8467 else if (anArg == "-pix_fmt"
8468 || anArg == "-pixfmt"
8469 || anArg == "-pixelformat")
8471 if (++anArgIter >= theArgNb)
8473 std::cout << "Syntax error at " << anArg << ".\n";
8476 aRecParams.PixelFormat = theArgVec[anArgIter];
8478 else if (anArg == "-codec"
8479 || anArg == "-vcodec"
8480 || anArg == "-videocodec")
8482 if (++anArgIter >= theArgNb)
8484 std::cout << "Syntax error at " << anArg << ".\n";
8487 aRecParams.VideoCodec = theArgVec[anArgIter];
8489 else if (anArg == "-crf"
8490 || anArg == "-preset"
8493 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
8494 if (++anArgIter >= theArgNb)
8496 std::cout << "Syntax error at " << anArg << ".\n";
8500 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
8502 // animation definition options
8503 else if (anArg == "-start"
8504 || anArg == "-starttime"
8505 || anArg == "-startpts")
8507 if (++anArgIter >= theArgNb)
8509 std::cout << "Syntax error at " << anArg << ".\n";
8513 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
8514 aRootAnimation->UpdateTotalDuration();
8516 else if (anArg == "-end"
8517 || anArg == "-endtime"
8518 || anArg == "-endpts")
8520 if (++anArgIter >= theArgNb)
8522 std::cout << "Syntax error at " << anArg << ".\n";
8526 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
8527 aRootAnimation->UpdateTotalDuration();
8529 else if (anArg == "-dur"
8530 || anArg == "-duration")
8532 if (++anArgIter >= theArgNb)
8534 std::cout << "Syntax error at " << anArg << ".\n";
8538 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
8539 aRootAnimation->UpdateTotalDuration();
8541 else if (anArg == "-command"
8543 || anArg == "-invoke"
8545 || anArg == "-proc")
8547 if (++anArgIter >= theArgNb)
8549 std::cout << "Syntax error at " << anArg << ".\n";
8553 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
8554 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
8556 else if (anArg == "-objecttrsf"
8557 || anArg == "-objectransformation"
8558 || anArg == "-objtransformation"
8559 || anArg == "-objtrsf"
8560 || anArg == "-object"
8563 if (++anArgIter >= theArgNb)
8565 std::cout << "Syntax error at " << anArg << ".\n";
8569 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
8570 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
8571 Handle(AIS_InteractiveObject) anObject;
8572 if (!aMapOfAIS.Find2 (anObjName, anObject))
8574 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
8578 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
8579 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
8580 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
8581 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
8582 Standard_Boolean isTrsfSet = Standard_False;
8583 Standard_Integer aTrsfArgIter = anArgIter + 1;
8584 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
8586 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
8587 aTrsfArg.LowerCase();
8588 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
8589 if (aTrsfArg.StartsWith ("-rotation")
8590 || aTrsfArg.StartsWith ("-rot"))
8592 isTrsfSet = Standard_True;
8593 if (aTrsfArgIter + 4 >= theArgNb
8594 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
8596 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8601 else if (aTrsfArg.StartsWith ("-location")
8602 || aTrsfArg.StartsWith ("-loc"))
8604 isTrsfSet = Standard_True;
8605 if (aTrsfArgIter + 3 >= theArgNb
8606 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
8608 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8613 else if (aTrsfArg.StartsWith ("-scale"))
8615 isTrsfSet = Standard_True;
8616 if (++aTrsfArgIter >= theArgNb)
8618 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8622 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
8623 if (!aScaleStr.IsRealValue())
8625 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8628 aScales[anIndex] = aScaleStr.RealValue();
8632 anArgIter = aTrsfArgIter - 1;
8638 std::cout << "Syntax error at " << anArg << ".\n";
8641 else if (aTrsfArgIter >= theArgNb)
8643 anArgIter = theArgNb;
8646 aTrsfs[0].SetRotation (aRotQuats[0]);
8647 aTrsfs[1].SetRotation (aRotQuats[1]);
8648 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
8649 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
8650 aTrsfs[0].SetScaleFactor (aScales[0]);
8651 aTrsfs[1].SetScaleFactor (aScales[1]);
8653 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
8654 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
8656 else if (anArg == "-viewtrsf"
8657 || anArg == "-view")
8659 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
8660 if (aCamAnimation.IsNull())
8662 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
8663 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
8666 Handle(Graphic3d_Camera) aCams[2] =
8668 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
8669 new Graphic3d_Camera (aCamAnimation->View()->Camera())
8672 Standard_Boolean isTrsfSet = Standard_False;
8673 Standard_Integer aViewArgIter = anArgIter + 1;
8674 for (; aViewArgIter < theArgNb; ++aViewArgIter)
8676 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
8677 aViewArg.LowerCase();
8678 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
8679 if (aViewArg.StartsWith ("-scale"))
8681 isTrsfSet = Standard_True;
8682 if (++aViewArgIter >= theArgNb)
8684 std::cout << "Syntax error at " << anArg << ".\n";
8688 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
8689 if (!aScaleStr.IsRealValue())
8691 std::cout << "Syntax error at " << aViewArg << ".\n";
8694 Standard_Real aScale = aScaleStr.RealValue();
8695 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
8696 aCams[anIndex]->SetScale (aScale);
8698 else if (aViewArg.StartsWith ("-eye")
8699 || aViewArg.StartsWith ("-center")
8700 || aViewArg.StartsWith ("-at")
8701 || aViewArg.StartsWith ("-up"))
8703 isTrsfSet = Standard_True;
8705 if (aViewArgIter + 3 >= theArgNb
8706 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
8708 std::cout << "Syntax error at " << aViewArg << ".\n";
8713 if (aViewArg.StartsWith ("-eye"))
8715 aCams[anIndex]->SetEye (anXYZ);
8717 else if (aViewArg.StartsWith ("-center")
8718 || aViewArg.StartsWith ("-at"))
8720 aCams[anIndex]->SetCenter (anXYZ);
8722 else if (aViewArg.StartsWith ("-up"))
8724 aCams[anIndex]->SetUp (anXYZ);
8729 anArgIter = aViewArgIter - 1;
8735 std::cout << "Syntax error at " << anArg << ".\n";
8738 else if (aViewArgIter >= theArgNb)
8740 anArgIter = theArgNb;
8743 aCamAnimation->SetCameraStart(aCams[0]);
8744 aCamAnimation->SetCameraEnd (aCams[1]);
8748 std::cout << "Syntax error at " << anArg << ".\n";
8753 if (!toPlay && aRecFile.IsEmpty())
8758 // Start animation timeline and process frame updating.
8759 TheIsAnimating = Standard_True;
8760 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
8761 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
8762 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
8765 aView->Camera()->Copy (aCameraBack);
8768 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
8769 if (aRecParams.FpsNum <= 0)
8771 while (!anAnimation->IsStopped())
8773 aCameraBack->Copy (aView->Camera());
8774 const Standard_Real aPts = anAnimation->UpdateTimer();
8777 aView->Camera()->Copy (aCameraBack);
8780 if (aPts >= anUpperPts)
8782 anAnimation->Pause();
8786 if (aView->IsInvalidated())
8792 aView->RedrawImmediate();
8797 // handle user events
8798 theDI.Eval ("after 1 set waiter 1");
8799 theDI.Eval ("vwait waiter");
8801 if (!TheIsAnimating)
8803 anAnimation->Pause();
8809 if (aView->IsInvalidated())
8815 aView->RedrawImmediate();
8820 OSD_Timer aPerfTimer;
8823 Handle(Image_VideoRecorder) aRecorder;
8824 ImageFlipper aFlipper;
8825 Handle(Draw_ProgressIndicator) aProgress;
8826 if (!aRecFile.IsEmpty())
8828 if (aRecParams.Width <= 0
8829 || aRecParams.Height <= 0)
8831 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
8834 aRecorder = new Image_VideoRecorder();
8835 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
8837 std::cout << "Error: failed to open video file for recording\n";
8841 aProgress = new Draw_ProgressIndicator (theDI, 1);
8844 // Manage frame-rated animation here
8845 Standard_Real aPts = aPlayStartTime;
8846 int64_t aNbFrames = 0;
8847 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
8848 Standard_Integer aSecondsProgress = 0;
8849 for (; aPts <= anUpperPts && aPSentry.More();)
8851 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
8852 aPts = aPlayStartTime + aRecPts;
8854 if (!anAnimation->Update (aPts))
8859 if (!aRecorder.IsNull())
8861 V3d_ImageDumpOptions aDumpParams;
8862 aDumpParams.Width = aRecParams.Width;
8863 aDumpParams.Height = aRecParams.Height;
8864 aDumpParams.BufferType = Graphic3d_BT_RGBA;
8865 aDumpParams.StereoOptions = V3d_SDO_MONO;
8866 aDumpParams.ToAdjustAspect = Standard_True;
8867 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
8869 std::cout << "Error: view dump is failed!\n";
8872 aFlipper.FlipY (aRecorder->ChangeFrame());
8873 if (!aRecorder->PushFrame())
8883 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
8891 anAnimation->Stop();
8892 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
8893 theDI << "Average FPS: " << aRecFps << "\n"
8894 << "Nb. Frames: " << Standard_Real(aNbFrames);
8899 aView->SetImmediateUpdate (wasImmediateUpdate);
8900 TheIsAnimating = Standard_False;
8905 //=======================================================================
8906 //function : VChangeSelected
8907 //purpose : Adds the shape to selection or remove one from it
8908 //=======================================================================
8909 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
8910 Standard_Integer argc,
8915 di<<"Usage : " << argv[0] << " shape \n";
8919 TCollection_AsciiString aName(argv[1]);
8920 Handle(AIS_InteractiveObject) anAISObject;
8921 if (!GetMapOfAIS().Find2 (aName, anAISObject)
8922 || anAISObject.IsNull())
8924 di<<"Use 'vdisplay' before";
8928 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
8932 //=======================================================================
8933 //function : VNbSelected
8934 //purpose : Returns number of selected objects
8935 //=======================================================================
8936 static Standard_Integer VNbSelected (Draw_Interpretor& di,
8937 Standard_Integer argc,
8942 di << "Usage : " << argv[0] << "\n";
8945 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8946 if(aContext.IsNull())
8948 di << "use 'vinit' command before " << argv[0] << "\n";
8951 di << aContext->NbSelected() << "\n";
8955 //=======================================================================
8956 //function : VPurgeDisplay
8957 //purpose : Switches altialiasing on or off
8958 //=======================================================================
8959 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
8960 Standard_Integer argc,
8965 di << "Usage : " << argv[0] << "\n";
8968 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8969 if (aContext.IsNull())
8971 di << "use 'vinit' command before " << argv[0] << "\n";
8975 di << aContext->PurgeDisplay() << "\n";
8979 //=======================================================================
8980 //function : VSetViewSize
8982 //=======================================================================
8983 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
8984 Standard_Integer argc,
8987 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8988 if(aContext.IsNull())
8990 di << "use 'vinit' command before " << argv[0] << "\n";
8995 di<<"Usage : " << argv[0] << " Size\n";
8998 Standard_Real aSize = Draw::Atof (argv[1]);
9001 di<<"Bad Size value : " << aSize << "\n";
9005 Handle(V3d_View) aView = ViewerTest::CurrentView();
9006 aView->SetSize(aSize);
9010 //=======================================================================
9011 //function : VMoveView
9013 //=======================================================================
9014 static Standard_Integer VMoveView (Draw_Interpretor& di,
9015 Standard_Integer argc,
9018 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9019 if(aContext.IsNull())
9021 di << "use 'vinit' command before " << argv[0] << "\n";
9024 if(argc < 4 || argc > 5)
9026 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
9029 Standard_Real Dx = Draw::Atof (argv[1]);
9030 Standard_Real Dy = Draw::Atof (argv[2]);
9031 Standard_Real Dz = Draw::Atof (argv[3]);
9032 Standard_Boolean aStart = Standard_True;
9035 aStart = (Draw::Atoi (argv[4]) > 0);
9038 Handle(V3d_View) aView = ViewerTest::CurrentView();
9039 aView->Move(Dx,Dy,Dz,aStart);
9043 //=======================================================================
9044 //function : VTranslateView
9046 //=======================================================================
9047 static Standard_Integer VTranslateView (Draw_Interpretor& di,
9048 Standard_Integer argc,
9051 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9052 if(aContext.IsNull())
9054 di << "use 'vinit' command before " << argv[0] << "\n";
9057 if(argc < 4 || argc > 5)
9059 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
9062 Standard_Real Dx = Draw::Atof (argv[1]);
9063 Standard_Real Dy = Draw::Atof (argv[2]);
9064 Standard_Real Dz = Draw::Atof (argv[3]);
9065 Standard_Boolean aStart = Standard_True;
9068 aStart = (Draw::Atoi (argv[4]) > 0);
9071 Handle(V3d_View) aView = ViewerTest::CurrentView();
9072 aView->Translate(Dx,Dy,Dz,aStart);
9076 //=======================================================================
9077 //function : VTurnView
9079 //=======================================================================
9080 static Standard_Integer VTurnView (Draw_Interpretor& di,
9081 Standard_Integer argc,
9084 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9085 if(aContext.IsNull()) {
9086 di << "use 'vinit' command before " << argv[0] << "\n";
9089 if(argc < 4 || argc > 5){
9090 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
9093 Standard_Real Ax = Draw::Atof (argv[1]);
9094 Standard_Real Ay = Draw::Atof (argv[2]);
9095 Standard_Real Az = Draw::Atof (argv[3]);
9096 Standard_Boolean aStart = Standard_True;
9099 aStart = (Draw::Atoi (argv[4]) > 0);
9102 Handle(V3d_View) aView = ViewerTest::CurrentView();
9103 aView->Turn(Ax,Ay,Az,aStart);
9107 //==============================================================================
9108 //function : VTextureEnv
9109 //purpose : ENables or disables environment mapping
9110 //==============================================================================
9111 class OCC_TextureEnv : public Graphic3d_TextureEnv
9114 OCC_TextureEnv(const Standard_CString FileName);
9115 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
9116 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
9117 const Standard_Boolean theModulateFlag,
9118 const Graphic3d_TypeOfTextureFilter theFilter,
9119 const Standard_ShortReal theXScale,
9120 const Standard_ShortReal theYScale,
9121 const Standard_ShortReal theXShift,
9122 const Standard_ShortReal theYShift,
9123 const Standard_ShortReal theAngle);
9124 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
9126 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
9128 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
9129 : Graphic3d_TextureEnv(theFileName)
9133 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
9134 : Graphic3d_TextureEnv(theTexId)
9138 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
9139 const Standard_Boolean theModulateFlag,
9140 const Graphic3d_TypeOfTextureFilter theFilter,
9141 const Standard_ShortReal theXScale,
9142 const Standard_ShortReal theYScale,
9143 const Standard_ShortReal theXShift,
9144 const Standard_ShortReal theYShift,
9145 const Standard_ShortReal theAngle)
9147 myParams->SetRepeat (theRepeatFlag);
9148 myParams->SetModulate (theModulateFlag);
9149 myParams->SetFilter (theFilter);
9150 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
9151 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
9152 myParams->SetRotation (theAngle);
9155 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
9157 // get the active view
9158 Handle(V3d_View) aView = ViewerTest::CurrentView();
9161 std::cerr << "No active view. Please call vinit.\n";
9165 // Checking the input arguments
9166 Standard_Boolean anEnableFlag = Standard_False;
9167 Standard_Boolean isOk = theArgNb >= 2;
9170 TCollection_AsciiString anEnableOpt(theArgVec[1]);
9171 anEnableFlag = anEnableOpt.IsEqual("on");
9172 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
9176 isOk = (theArgNb == 3 || theArgNb == 11);
9179 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9180 isOk = (!aTextureOpt.IsIntegerValue() ||
9181 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
9183 if (isOk && theArgNb == 11)
9185 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
9186 aModulateOpt(theArgVec[4]),
9187 aFilterOpt (theArgVec[5]),
9188 aSScaleOpt (theArgVec[6]),
9189 aTScaleOpt (theArgVec[7]),
9190 aSTransOpt (theArgVec[8]),
9191 aTTransOpt (theArgVec[9]),
9192 anAngleOpt (theArgVec[10]);
9193 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
9194 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
9195 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
9196 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
9197 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
9198 anAngleOpt.IsRealValue());
9205 std::cerr << "Usage :" << std::endl;
9206 std::cerr << theArgVec[0] << " off" << std::endl;
9207 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;
9213 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9214 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
9215 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
9216 new OCC_TextureEnv(theArgVec[2]);
9220 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
9221 aTexEnv->SetTextureParameters(
9222 aRepeatOpt. IsEqual("repeat"),
9223 aModulateOpt.IsEqual("modulate"),
9224 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
9225 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
9226 Graphic3d_TOTF_TRILINEAR,
9227 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
9228 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
9229 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
9230 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
9231 (Standard_ShortReal)Draw::Atof(theArgVec[10])
9234 aView->SetTextureEnv(aTexEnv);
9236 else // Disabling environment mapping
9238 Handle(Graphic3d_TextureEnv) aTexture;
9239 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
9248 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
9250 //! Remove registered clipping plane from all views and objects.
9251 static void removePlane (MapOfPlanes& theRegPlanes,
9252 const TCollection_AsciiString& theName)
9254 Handle(Graphic3d_ClipPlane) aClipPlane;
9255 if (!theRegPlanes.Find (theName, aClipPlane))
9257 std::cout << "Warning: no such plane.\n";
9261 theRegPlanes.UnBind (theName);
9262 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
9263 anIObjIt.More(); anIObjIt.Next())
9265 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
9266 aPrs->RemoveClipPlane (aClipPlane);
9269 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
9270 aViewIt.More(); aViewIt.Next())
9272 const Handle(V3d_View)& aView = aViewIt.Key2();
9273 aView->RemoveClipPlane(aClipPlane);
9276 ViewerTest::RedrawAllViews();
9280 //===============================================================================================
9281 //function : VClipPlane
9283 //===============================================================================================
9284 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9286 // use short-cut for created clip planes map of created (or "registered by name") clip planes
9287 static MapOfPlanes aRegPlanes;
9291 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
9293 theDi << aPlaneIter.Key() << " ";
9298 TCollection_AsciiString aCommand (theArgVec[1]);
9299 aCommand.LowerCase();
9300 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
9301 if (anActiveView.IsNull())
9303 std::cout << "Error: no active view.\n";
9307 // print maximum number of planes for current viewer
9308 if (aCommand == "-maxplanes"
9309 || aCommand == "maxplanes")
9311 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
9312 << " plane slots provided by driver.\n";
9316 // create / delete plane instance
9317 if (aCommand == "-create"
9318 || aCommand == "create"
9319 || aCommand == "-delete"
9320 || aCommand == "delete"
9321 || aCommand == "-clone"
9322 || aCommand == "clone")
9326 std::cout << "Syntax error: plane name is required.\n";
9330 Standard_Boolean toCreate = aCommand == "-create"
9331 || aCommand == "create";
9332 Standard_Boolean toClone = aCommand == "-clone"
9333 || aCommand == "clone";
9334 Standard_Boolean toDelete = aCommand == "-delete"
9335 || aCommand == "delete";
9336 TCollection_AsciiString aPlane (theArgVec[2]);
9340 if (aRegPlanes.IsBound (aPlane))
9342 std::cout << "Warning: existing plane has been overridden.\n";
9347 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9351 else if (toClone) // toClone
9353 if (!aRegPlanes.IsBound (aPlane))
9355 std::cout << "Error: no such plane.\n";
9358 else if (theArgsNb < 4)
9360 std::cout << "Syntax error: enter name for new plane.\n";
9364 TCollection_AsciiString aClone (theArgVec[3]);
9365 if (aRegPlanes.IsBound (aClone))
9367 std::cout << "Error: plane name is in use.\n";
9371 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
9373 aRegPlanes.Bind (aClone, aClipPlane->Clone());
9383 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
9385 aPlane = aPlaneIter.Key();
9386 removePlane (aRegPlanes, aPlane);
9387 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
9392 removePlane (aRegPlanes, aPlane);
9398 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9403 // set / unset plane command
9404 if (aCommand == "set"
9405 || aCommand == "unset")
9409 std::cout << "Syntax error: need more arguments.\n";
9413 // redirect to new syntax
9414 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
9415 anArgVec.SetValue (1, theArgVec[0]);
9416 anArgVec.SetValue (2, theArgVec[2]);
9417 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
9418 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
9420 anArgVec.SetValue (anIt, theArgVec[anIt]);
9423 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
9426 // change plane command
9427 TCollection_AsciiString aPlaneName;
9428 Handle(Graphic3d_ClipPlane) aClipPlane;
9429 Standard_Integer anArgIter = 0;
9430 if (aCommand == "-change"
9431 || aCommand == "change")
9433 // old syntax support
9436 std::cout << "Syntax error: need more arguments.\n";
9441 aPlaneName = theArgVec[2];
9442 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
9444 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
9448 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
9451 aPlaneName = theArgVec[1];
9456 aPlaneName = theArgVec[1];
9457 aClipPlane = new Graphic3d_ClipPlane();
9458 aRegPlanes.Bind (aPlaneName, aClipPlane);
9459 theDi << "Created new plane " << aPlaneName << ".\n";
9462 if (theArgsNb - anArgIter < 1)
9464 std::cout << "Syntax error: need more arguments.\n";
9468 for (; anArgIter < theArgsNb; ++anArgIter)
9470 const char** aChangeArgs = theArgVec + anArgIter;
9471 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
9472 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
9473 aChangeArg.LowerCase();
9475 Standard_Boolean toEnable = Standard_True;
9476 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
9478 aClipPlane->SetOn (toEnable);
9480 else if (aChangeArg.StartsWith ("-equation")
9481 || aChangeArg.StartsWith ("equation"))
9483 if (aNbChangeArgs < 5)
9485 std::cout << "Syntax error: need more arguments.\n";
9489 Standard_Integer aSubIndex = 1;
9490 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
9491 if (aPrefixLen < aChangeArg.Length())
9493 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
9494 if (!aSubStr.IsIntegerValue()
9495 || aSubStr.IntegerValue() <= 0)
9497 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9500 aSubIndex = aSubStr.IntegerValue();
9503 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
9504 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
9505 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
9506 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
9507 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9508 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
9510 if (aSubPln->ChainNextPlane().IsNull())
9512 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9514 aSubPln = aSubPln->ChainNextPlane();
9516 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9517 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
9520 else if ((aChangeArg == "-boxinterior"
9521 || aChangeArg == "-boxint"
9522 || aChangeArg == "-box")
9523 && aNbChangeArgs >= 7)
9525 Graphic3d_BndBox3d aBndBox;
9526 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
9527 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
9530 Standard_Integer aNbSubPlanes = 6;
9531 const Graphic3d_Vec3d aDirArray[6] =
9533 Graphic3d_Vec3d (-1, 0, 0),
9534 Graphic3d_Vec3d ( 1, 0, 0),
9535 Graphic3d_Vec3d ( 0,-1, 0),
9536 Graphic3d_Vec3d ( 0, 1, 0),
9537 Graphic3d_Vec3d ( 0, 0,-1),
9538 Graphic3d_Vec3d ( 0, 0, 1),
9540 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9541 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
9543 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
9544 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
9545 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
9546 if (aSubPlaneIter + 1 == aNbSubPlanes)
9548 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9552 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9554 aSubPln = aSubPln->ChainNextPlane();
9557 else if (aChangeArg == "-capping"
9558 || aChangeArg == "capping")
9560 if (aNbChangeArgs < 2)
9562 std::cout << "Syntax error: need more arguments.\n";
9566 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9568 aClipPlane->SetCapping (toEnable);
9573 // just skip otherwise (old syntax)
9576 else if (aChangeArg == "-useobjectmaterial"
9577 || aChangeArg == "-useobjectmat"
9578 || aChangeArg == "-useobjmat"
9579 || aChangeArg == "-useobjmaterial")
9581 if (aNbChangeArgs < 2)
9583 std::cout << "Syntax error: need more arguments.\n";
9587 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9589 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
9593 else if (aChangeArg == "-useobjecttexture"
9594 || aChangeArg == "-useobjecttex"
9595 || aChangeArg == "-useobjtexture"
9596 || aChangeArg == "-useobjtex")
9598 if (aNbChangeArgs < 2)
9600 std::cout << "Syntax error: need more arguments.\n";
9604 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9606 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
9610 else if (aChangeArg == "-useobjectshader"
9611 || aChangeArg == "-useobjshader")
9613 if (aNbChangeArgs < 2)
9615 std::cout << "Syntax error: need more arguments.\n";
9619 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9621 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
9625 else if (aChangeArg == "-color"
9626 || aChangeArg == "color")
9628 Quantity_Color aColor;
9629 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
9634 std::cout << "Syntax error: need more arguments.\n";
9637 aClipPlane->SetCappingColor (aColor);
9638 anArgIter += aNbParsed;
9640 else if (aNbChangeArgs >= 1
9641 && (aChangeArg == "-material"
9642 || aChangeArg == "material"))
9645 Graphic3d_NameOfMaterial aMatName;
9646 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeArgs[1], aMatName))
9648 std::cout << "Syntax error: unknown material '" << aChangeArgs[1] << "'.\n";
9651 aClipPlane->SetCappingMaterial (aMatName);
9653 else if ((aChangeArg == "-transparency"
9654 || aChangeArg == "-transp")
9655 && aNbChangeArgs >= 2)
9657 TCollection_AsciiString aValStr (aChangeArgs[1]);
9658 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
9659 if (aValStr.IsRealValue())
9661 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
9662 aMat.SetTransparency ((float )aValStr.RealValue());
9663 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
9664 aClipPlane->SetCappingMaterial (aMat);
9668 aValStr.LowerCase();
9669 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
9670 if (aValStr == "opaque")
9672 aMode = Graphic3d_AlphaMode_Opaque;
9674 else if (aValStr == "mask")
9676 aMode = Graphic3d_AlphaMode_Mask;
9678 else if (aValStr == "blend")
9680 aMode = Graphic3d_AlphaMode_Blend;
9682 else if (aValStr == "blendauto")
9684 aMode = Graphic3d_AlphaMode_BlendAuto;
9688 std::cout << "Syntax error at '" << aValStr << "'\n";
9691 anAspect->SetAlphaMode (aMode);
9692 aClipPlane->SetCappingAspect (anAspect);
9696 else if (aChangeArg == "-texname"
9697 || aChangeArg == "texname")
9699 if (aNbChangeArgs < 2)
9701 std::cout << "Syntax error: need more arguments.\n";
9705 TCollection_AsciiString aTextureName (aChangeArgs[1]);
9706 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
9707 if (!aTexture->IsDone())
9709 aClipPlane->SetCappingTexture (NULL);
9713 aTexture->EnableModulate();
9714 aTexture->EnableRepeat();
9715 aClipPlane->SetCappingTexture (aTexture);
9719 else if (aChangeArg == "-texscale"
9720 || aChangeArg == "texscale")
9722 if (aClipPlane->CappingTexture().IsNull())
9724 std::cout << "Error: no texture is set.\n";
9728 if (aNbChangeArgs < 3)
9730 std::cout << "Syntax error: need more arguments.\n";
9734 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9735 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9736 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
9739 else if (aChangeArg == "-texorigin"
9740 || aChangeArg == "texorigin") // texture origin
9742 if (aClipPlane->CappingTexture().IsNull())
9744 std::cout << "Error: no texture is set.\n";
9748 if (aNbChangeArgs < 3)
9750 std::cout << "Syntax error: need more arguments.\n";
9754 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9755 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9757 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
9760 else if (aChangeArg == "-texrotate"
9761 || aChangeArg == "texrotate") // texture rotation
9763 if (aClipPlane->CappingTexture().IsNull())
9765 std::cout << "Error: no texture is set.\n";
9769 if (aNbChangeArgs < 2)
9771 std::cout << "Syntax error: need more arguments.\n";
9775 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9776 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
9779 else if (aChangeArg == "-hatch"
9780 || aChangeArg == "hatch")
9782 if (aNbChangeArgs < 2)
9784 std::cout << "Syntax error: need more arguments.\n";
9788 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
9789 aHatchStr.LowerCase();
9790 if (aHatchStr == "on")
9792 aClipPlane->SetCappingHatchOn();
9794 else if (aHatchStr == "off")
9796 aClipPlane->SetCappingHatchOff();
9800 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
9804 else if (aChangeArg == "-delete"
9805 || aChangeArg == "delete")
9807 removePlane (aRegPlanes, aPlaneName);
9810 else if (aChangeArg == "-set"
9811 || aChangeArg == "-unset"
9812 || aChangeArg == "-setoverrideglobal")
9814 // set / unset plane command
9815 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
9816 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
9817 Standard_Integer anIt = 1;
9818 for (; anIt < aNbChangeArgs; ++anIt)
9820 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
9821 if (anEntityName.IsEmpty()
9822 || anEntityName.Value (1) == '-')
9826 else if (!toOverrideGlobal
9827 && ViewerTest_myViews.IsBound1 (anEntityName))
9829 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
9832 aView->AddClipPlane (aClipPlane);
9836 aView->RemoveClipPlane (aClipPlane);
9840 else if (GetMapOfAIS().IsBound2 (anEntityName))
9842 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
9845 aIObj->AddClipPlane (aClipPlane);
9849 aIObj->RemoveClipPlane (aClipPlane);
9851 if (!aIObj->ClipPlanes().IsNull())
9853 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
9858 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
9865 // apply to active view
9868 anActiveView->AddClipPlane (aClipPlane);
9872 anActiveView->RemoveClipPlane (aClipPlane);
9877 anArgIter = anArgIter + anIt - 1;
9882 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9887 ViewerTest::RedrawAllViews();
9891 //===============================================================================================
9892 //function : VZRange
9894 //===============================================================================================
9895 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9897 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9899 if (aCurrentView.IsNull())
9901 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9905 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
9909 theDi << "ZNear: " << aCamera->ZNear() << "\n";
9910 theDi << "ZFar: " << aCamera->ZFar() << "\n";
9916 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
9917 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
9919 if (aNewZNear >= aNewZFar)
9921 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
9925 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
9927 std::cout << theArgVec[0] << ": invalid arguments: ";
9928 std::cout << "znear, zfar should be positive for perspective camera.\n";
9932 aCamera->SetZRange (aNewZNear, aNewZFar);
9936 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9940 aCurrentView->Redraw();
9945 //===============================================================================================
9946 //function : VAutoZFit
9948 //===============================================================================================
9949 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9951 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9953 if (aCurrentView.IsNull())
9955 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9959 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
9963 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9969 theDi << "Auto z-fit mode: \n"
9970 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
9971 << "Scale: " << aScale << "\n";
9975 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
9979 aScale = Draw::Atoi (theArgVec[2]);
9982 aCurrentView->SetAutoZFitMode (isOn, aScale);
9983 aCurrentView->AutoZFit();
9984 aCurrentView->Redraw();
9989 //! Auxiliary function to print projection type
9990 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
9992 switch (theProjType)
9994 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
9995 case Graphic3d_Camera::Projection_Perspective: return "perspective";
9996 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
9997 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
9998 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
10003 //===============================================================================================
10004 //function : VCamera
10006 //===============================================================================================
10007 static int VCamera (Draw_Interpretor& theDI,
10008 Standard_Integer theArgsNb,
10009 const char** theArgVec)
10011 Handle(V3d_View) aView = ViewerTest::CurrentView();
10012 if (aView.IsNull())
10014 std::cout << "Error: no active view.\n";
10018 Handle(Graphic3d_Camera) aCamera = aView->Camera();
10021 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
10022 theDI << "FOVy: " << aCamera->FOVy() << "\n";
10023 theDI << "Distance: " << aCamera->Distance() << "\n";
10024 theDI << "IOD: " << aCamera->IOD() << "\n";
10025 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
10026 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
10027 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
10031 TCollection_AsciiString aPrsName;
10032 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10034 Standard_CString anArg = theArgVec[anArgIter];
10035 TCollection_AsciiString anArgCase (anArg);
10036 anArgCase.LowerCase();
10037 if (anArgCase == "-proj"
10038 || anArgCase == "-projection"
10039 || anArgCase == "-projtype"
10040 || anArgCase == "-projectiontype")
10042 theDI << projTypeName (aCamera->ProjectionType()) << " ";
10044 else if (anArgCase == "-ortho"
10045 || anArgCase == "-orthographic")
10047 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
10049 else if (anArgCase == "-persp"
10050 || anArgCase == "-perspective"
10051 || anArgCase == "-perspmono"
10052 || anArgCase == "-perspectivemono"
10053 || anArgCase == "-mono")
10055 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10057 else if (anArgCase == "-stereo"
10058 || anArgCase == "-stereoscopic"
10059 || anArgCase == "-perspstereo"
10060 || anArgCase == "-perspectivestereo")
10062 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10064 else if (anArgCase == "-left"
10065 || anArgCase == "-lefteye"
10066 || anArgCase == "-monoleft"
10067 || anArgCase == "-monolefteye"
10068 || anArgCase == "-perpsleft"
10069 || anArgCase == "-perpslefteye")
10071 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
10073 else if (anArgCase == "-right"
10074 || anArgCase == "-righteye"
10075 || anArgCase == "-monoright"
10076 || anArgCase == "-monorighteye"
10077 || anArgCase == "-perpsright")
10079 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
10081 else if (anArgCase == "-dist"
10082 || anArgCase == "-distance")
10084 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10085 if (anArgValue != NULL
10086 && *anArgValue != '-')
10089 aCamera->SetDistance (Draw::Atof (anArgValue));
10092 theDI << aCamera->Distance() << " ";
10094 else if (anArgCase == "-iod")
10096 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10097 if (anArgValue != NULL
10098 && *anArgValue != '-')
10101 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
10104 theDI << aCamera->IOD() << " ";
10106 else if (anArgCase == "-iodtype")
10108 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10109 TCollection_AsciiString anValueCase (anArgValue);
10110 anValueCase.LowerCase();
10111 if (anValueCase == "abs"
10112 || anValueCase == "absolute")
10115 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
10118 else if (anValueCase == "rel"
10119 || anValueCase == "relative")
10122 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
10125 else if (*anArgValue != '-')
10127 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
10130 switch (aCamera->GetIODType())
10132 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
10133 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
10136 else if (anArgCase == "-zfocus")
10138 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10139 if (anArgValue != NULL
10140 && *anArgValue != '-')
10143 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
10146 theDI << aCamera->ZFocus() << " ";
10148 else if (anArgCase == "-zfocustype")
10150 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10151 TCollection_AsciiString anValueCase (anArgValue);
10152 anValueCase.LowerCase();
10153 if (anValueCase == "abs"
10154 || anValueCase == "absolute")
10157 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
10160 else if (anValueCase == "rel"
10161 || anValueCase == "relative")
10164 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
10167 else if (*anArgValue != '-')
10169 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
10172 switch (aCamera->ZFocusType())
10174 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
10175 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
10178 else if (anArgCase == "-fov"
10179 || anArgCase == "-fovy")
10181 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10182 if (anArgValue != NULL
10183 && *anArgValue != '-')
10186 aCamera->SetFOVy (Draw::Atof (anArgValue));
10189 theDI << aCamera->FOVy() << " ";
10191 else if (aPrsName.IsEmpty()
10192 && !anArgCase.StartsWith ("-"))
10198 std::cout << "Error: unknown argument '" << anArg << "'\n";
10203 if (aPrsName.IsEmpty()
10210 if (!aPrsName.IsEmpty())
10212 Handle(AIS_CameraFrustum) aCameraFrustum;
10213 if (GetMapOfAIS().IsBound2 (aPrsName))
10215 // find existing object
10216 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
10217 if (aCameraFrustum.IsNull())
10219 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
10224 if (aCameraFrustum.IsNull())
10226 aCameraFrustum = new AIS_CameraFrustum();
10230 // not include displayed object of old camera frustum in the new one.
10231 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
10234 aCameraFrustum->SetCameraFrustum (aView->Camera());
10236 ViewerTest::Display (aPrsName, aCameraFrustum);
10242 //! Parse stereo output mode
10243 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
10244 Graphic3d_StereoMode& theMode)
10246 TCollection_AsciiString aFlag (theArg);
10248 if (aFlag == "quadbuffer")
10250 theMode = Graphic3d_StereoMode_QuadBuffer;
10252 else if (aFlag == "anaglyph")
10254 theMode = Graphic3d_StereoMode_Anaglyph;
10256 else if (aFlag == "row"
10257 || aFlag == "rowinterlaced")
10259 theMode = Graphic3d_StereoMode_RowInterlaced;
10261 else if (aFlag == "col"
10262 || aFlag == "colinterlaced"
10263 || aFlag == "columninterlaced")
10265 theMode = Graphic3d_StereoMode_ColumnInterlaced;
10267 else if (aFlag == "chess"
10268 || aFlag == "chessboard")
10270 theMode = Graphic3d_StereoMode_ChessBoard;
10272 else if (aFlag == "sbs"
10273 || aFlag == "sidebyside")
10275 theMode = Graphic3d_StereoMode_SideBySide;
10277 else if (aFlag == "ou"
10278 || aFlag == "overunder")
10280 theMode = Graphic3d_StereoMode_OverUnder;
10282 else if (aFlag == "pageflip"
10283 || aFlag == "softpageflip")
10285 theMode = Graphic3d_StereoMode_SoftPageFlip;
10289 return Standard_False;
10291 return Standard_True;
10294 //! Parse anaglyph filter
10295 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
10296 Graphic3d_RenderingParams::Anaglyph& theFilter)
10298 TCollection_AsciiString aFlag (theArg);
10300 if (aFlag == "redcyansimple")
10302 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10304 else if (aFlag == "redcyan"
10305 || aFlag == "redcyanoptimized")
10307 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
10309 else if (aFlag == "yellowbluesimple")
10311 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
10313 else if (aFlag == "yellowblue"
10314 || aFlag == "yellowblueoptimized")
10316 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
10318 else if (aFlag == "greenmagenta"
10319 || aFlag == "greenmagentasimple")
10321 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
10325 return Standard_False;
10327 return Standard_True;
10330 //==============================================================================
10331 //function : VStereo
10333 //==============================================================================
10335 static int VStereo (Draw_Interpretor& theDI,
10336 Standard_Integer theArgNb,
10337 const char** theArgVec)
10339 Handle(V3d_View) aView = ViewerTest::CurrentView();
10342 if (aView.IsNull())
10344 std::cout << "Error: no active viewer!\n";
10348 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
10349 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
10352 TCollection_AsciiString aMode;
10353 switch (aView->RenderingParams().StereoMode)
10355 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
10356 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
10357 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
10358 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
10359 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
10360 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
10361 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
10362 case Graphic3d_StereoMode_Anaglyph :
10363 aMode = "anaglyph";
10364 switch (aView->RenderingParams().AnaglyphFilter)
10366 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
10367 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
10368 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
10369 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
10370 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
10375 theDI << "Mode " << aMode << "\n";
10380 Handle(Graphic3d_Camera) aCamera;
10381 Graphic3d_RenderingParams* aParams = NULL;
10382 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
10383 if (!aView.IsNull())
10385 aParams = &aView->ChangeRenderingParams();
10386 aMode = aParams->StereoMode;
10387 aCamera = aView->Camera();
10390 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10391 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10393 Standard_CString anArg = theArgVec[anArgIter];
10394 TCollection_AsciiString aFlag (anArg);
10396 if (anUpdateTool.parseRedrawMode (aFlag))
10400 else if (aFlag == "0"
10403 if (++anArgIter < theArgNb)
10405 std::cout << "Error: wrong number of arguments!\n";
10409 if (!aCamera.IsNull()
10410 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
10412 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10414 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
10417 else if (aFlag == "1"
10420 if (++anArgIter < theArgNb)
10422 std::cout << "Error: wrong number of arguments!\n";
10426 if (!aCamera.IsNull())
10428 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10430 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10433 else if (aFlag == "-reverse"
10434 || aFlag == "-reversed"
10435 || aFlag == "-swap")
10437 Standard_Boolean toEnable = Standard_True;
10438 if (++anArgIter < theArgNb
10439 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10443 aParams->ToReverseStereo = toEnable;
10445 else if (aFlag == "-noreverse"
10446 || aFlag == "-noswap")
10448 Standard_Boolean toDisable = Standard_True;
10449 if (++anArgIter < theArgNb
10450 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
10454 aParams->ToReverseStereo = !toDisable;
10456 else if (aFlag == "-mode"
10457 || aFlag == "-stereomode")
10459 if (++anArgIter >= theArgNb
10460 || !parseStereoMode (theArgVec[anArgIter], aMode))
10462 std::cout << "Error: syntax error at '" << anArg << "'\n";
10466 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10468 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10471 else if (aFlag == "-anaglyph"
10472 || aFlag == "-anaglyphfilter")
10474 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10475 if (++anArgIter >= theArgNb
10476 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
10478 std::cout << "Error: syntax error at '" << anArg << "'\n";
10482 aMode = Graphic3d_StereoMode_Anaglyph;
10483 aParams->AnaglyphFilter = aFilter;
10485 else if (parseStereoMode (anArg, aMode)) // short syntax
10487 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10489 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10494 std::cout << "Error: syntax error at '" << anArg << "'\n";
10499 if (!aView.IsNull())
10501 aParams->StereoMode = aMode;
10502 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10507 //===============================================================================================
10508 //function : VDefaults
10510 //===============================================================================================
10511 static int VDefaults (Draw_Interpretor& theDi,
10512 Standard_Integer theArgsNb,
10513 const char** theArgVec)
10515 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
10518 std::cout << "Error: no active viewer\n";
10522 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
10525 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
10527 theDi << "DeflType: relative\n"
10528 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
10532 theDi << "DeflType: absolute\n"
10533 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
10535 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
10536 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
10540 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10542 TCollection_AsciiString anArg (theArgVec[anArgIter]);
10544 if (anArg == "-ABSDEFL"
10545 || anArg == "-ABSOLUTEDEFLECTION"
10546 || anArg == "-DEFL"
10547 || anArg == "-DEFLECTION")
10549 if (++anArgIter >= theArgsNb)
10551 std::cout << "Error: wrong syntax at " << anArg << "\n";
10554 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
10555 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
10557 else if (anArg == "-RELDEFL"
10558 || anArg == "-RELATIVEDEFLECTION"
10559 || anArg == "-DEVCOEFF"
10560 || anArg == "-DEVIATIONCOEFF"
10561 || anArg == "-DEVIATIONCOEFFICIENT")
10563 if (++anArgIter >= theArgsNb)
10565 std::cout << "Error: wrong syntax at " << anArg << "\n";
10568 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
10569 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
10571 else if (anArg == "-ANGDEFL"
10572 || anArg == "-ANGULARDEFL"
10573 || anArg == "-ANGULARDEFLECTION")
10575 if (++anArgIter >= theArgsNb)
10577 std::cout << "Error: wrong syntax at " << anArg << "\n";
10580 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
10581 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
10583 else if (anArg == "-AUTOTR"
10584 || anArg == "-AUTOTRIANG"
10585 || anArg == "-AUTOTRIANGULATION")
10588 bool toTurnOn = true;
10589 if (anArgIter >= theArgsNb
10590 || !ViewerTest::ParseOnOff (theArgVec[anArgIter], toTurnOn))
10592 std::cout << "Syntax error at '" << anArg << "'\n";
10595 aDefParams->SetAutoTriangulation (toTurnOn);
10599 std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
10607 //! Auxiliary method
10608 inline void addLight (const Handle(V3d_Light)& theLightNew,
10609 const Graphic3d_ZLayerId theLayer,
10610 const Standard_Boolean theIsGlobal)
10612 if (theLightNew.IsNull())
10617 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10618 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
10620 aViewer->AddLight (theLightNew);
10623 aViewer->SetLightOn (theLightNew);
10627 ViewerTest::CurrentView()->SetLightOn (theLightNew);
10632 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
10633 if (aSettings.Lights().IsNull())
10635 aSettings.SetLights (new Graphic3d_LightSet());
10637 aSettings.Lights()->Add (theLightNew);
10638 aViewer->SetZLayerSettings (theLayer, aSettings);
10642 //! Auxiliary method
10643 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
10645 TCollection_AsciiString anArgNextCase (theArgNext);
10646 anArgNextCase.UpperCase();
10647 if (anArgNextCase.Length() > 5
10648 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
10650 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
10654 return theArgNext.IntegerValue();
10658 //===============================================================================================
10659 //function : VLight
10661 //===============================================================================================
10662 static int VLight (Draw_Interpretor& theDi,
10663 Standard_Integer theArgsNb,
10664 const char** theArgVec)
10666 Handle(V3d_View) aView = ViewerTest::CurrentView();
10667 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10669 || aViewer.IsNull())
10671 std::cerr << "No active viewer!\n";
10675 Standard_Real anXYZ[3] = {};
10676 Standard_Real anAtten[2] = {};
10679 // print lights info
10680 Standard_Integer aLightId = 0;
10681 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
10683 Handle(V3d_Light) aLight = aLightIter.Value();
10684 const Quantity_Color aColor = aLight->Color();
10685 theDi << "Light #" << aLightId
10686 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
10687 << " [" << aLight->GetId() << "]" << "\n";
10688 switch (aLight->Type())
10692 theDi << " Type: Ambient\n";
10693 theDi << " Intensity: " << aLight->Intensity() << "\n";
10696 case V3d_DIRECTIONAL:
10698 theDi << " Type: Directional\n";
10699 theDi << " Intensity: " << aLight->Intensity() << "\n";
10700 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10701 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10702 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10703 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10706 case V3d_POSITIONAL:
10708 theDi << " Type: Positional\n";
10709 theDi << " Intensity: " << aLight->Intensity() << "\n";
10710 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10711 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10712 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10713 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10714 aLight->Attenuation (anAtten[0], anAtten[1]);
10715 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10720 theDi << " Type: Spot\n";
10721 theDi << " Intensity: " << aLight->Intensity() << "\n";
10722 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10723 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10724 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10725 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10726 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10727 aLight->Attenuation (anAtten[0], anAtten[1]);
10728 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10729 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
10730 theDi << " Exponent: " << aLight->Concentration() << "\n";
10735 theDi << " Type: UNKNOWN\n";
10739 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
10743 Handle(V3d_Light) aLightNew;
10744 Handle(V3d_Light) aLightOld;
10745 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
10746 Standard_Boolean isGlobal = Standard_True;
10747 Standard_Boolean toCreate = Standard_False;
10748 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10749 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
10751 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
10753 TCollection_AsciiString aName, aValue;
10754 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
10755 TCollection_AsciiString anArgCase (anArg);
10756 anArgCase.UpperCase();
10757 if (anUpdateTool.parseRedrawMode (anArg))
10762 if (anArgCase.IsEqual ("NEW")
10763 || anArgCase.IsEqual ("ADD")
10764 || anArgCase.IsEqual ("CREATE")
10765 || anArgCase.IsEqual ("-NEW")
10766 || anArgCase.IsEqual ("-ADD")
10767 || anArgCase.IsEqual ("-CREATE"))
10769 toCreate = Standard_True;
10771 else if (anArgCase.IsEqual ("-LAYER")
10772 || anArgCase.IsEqual ("-ZLAYER"))
10774 if (++anArgIt >= theArgsNb)
10776 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10780 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
10781 aValStr.LowerCase();
10782 if (aValStr == "default"
10783 || aValStr == "def")
10785 aLayer = Graphic3d_ZLayerId_Default;
10787 else if (aValStr == "top")
10789 aLayer = Graphic3d_ZLayerId_Top;
10791 else if (aValStr == "topmost")
10793 aLayer = Graphic3d_ZLayerId_Topmost;
10795 else if (aValStr == "toposd"
10796 || aValStr == "osd")
10798 aLayer = Graphic3d_ZLayerId_TopOSD;
10800 else if (aValStr == "botosd"
10801 || aValStr == "bottom")
10803 aLayer = Graphic3d_ZLayerId_BotOSD;
10805 else if (aValStr.IsIntegerValue())
10807 aLayer = Draw::Atoi (theArgVec[anArgIt]);
10811 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
10815 else if (anArgCase.IsEqual ("GLOB")
10816 || anArgCase.IsEqual ("GLOBAL")
10817 || anArgCase.IsEqual ("-GLOB")
10818 || anArgCase.IsEqual ("-GLOBAL"))
10820 isGlobal = Standard_True;
10822 else if (anArgCase.IsEqual ("LOC")
10823 || anArgCase.IsEqual ("LOCAL")
10824 || anArgCase.IsEqual ("-LOC")
10825 || anArgCase.IsEqual ("-LOCAL"))
10827 isGlobal = Standard_False;
10829 else if (anArgCase.IsEqual ("DEF")
10830 || anArgCase.IsEqual ("DEFAULTS")
10831 || anArgCase.IsEqual ("-DEF")
10832 || anArgCase.IsEqual ("-DEFAULTS"))
10834 toCreate = Standard_False;
10835 aViewer->SetDefaultLights();
10837 else if (anArgCase.IsEqual ("CLR")
10838 || anArgCase.IsEqual ("CLEAR")
10839 || anArgCase.IsEqual ("-CLR")
10840 || anArgCase.IsEqual ("-CLEAR"))
10842 toCreate = Standard_False;
10844 TColStd_SequenceOfInteger aLayers;
10845 aViewer->GetAllZLayers (aLayers);
10846 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10848 if (aLayeriter.Value() == aLayer
10849 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10851 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10852 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10853 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10854 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10861 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10863 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
10865 Handle(V3d_Light) aLight = aLightIter.Value();
10866 aViewer->DelLight (aLight);
10867 aLightIter = aView->ActiveLightIterator();
10871 else if (anArgCase.IsEqual ("AMB")
10872 || anArgCase.IsEqual ("AMBIENT")
10873 || anArgCase.IsEqual ("AMBLIGHT"))
10877 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10881 addLight (aLightNew, aLayer, isGlobal);
10882 toCreate = Standard_False;
10883 aLightNew = new V3d_AmbientLight();
10885 else if (anArgCase.IsEqual ("DIRECTIONAL")
10886 || anArgCase.IsEqual ("DIRLIGHT"))
10890 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10894 addLight (aLightNew, aLayer, isGlobal);
10895 toCreate = Standard_False;
10896 aLightNew = new V3d_DirectionalLight();
10898 else if (anArgCase.IsEqual ("SPOT")
10899 || anArgCase.IsEqual ("SPOTLIGHT"))
10903 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10907 addLight (aLightNew, aLayer, isGlobal);
10908 toCreate = Standard_False;
10909 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
10911 else if (anArgCase.IsEqual ("POSLIGHT")
10912 || anArgCase.IsEqual ("POSITIONAL"))
10916 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10920 addLight (aLightNew, aLayer, isGlobal);
10921 toCreate = Standard_False;
10922 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
10924 else if (anArgCase.IsEqual ("CHANGE")
10925 || anArgCase.IsEqual ("-CHANGE"))
10927 if (++anArgIt >= theArgsNb)
10929 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10933 addLight (aLightNew, aLayer, isGlobal);
10934 aLightNew.Nullify();
10935 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
10936 Standard_Integer aLightIt = 0;
10937 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10939 if (aLightIt == aLightId)
10941 aLightOld = aLightIter.Value();
10946 if (aLightOld.IsNull())
10948 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
10952 else if (anArgCase.IsEqual ("DEL")
10953 || anArgCase.IsEqual ("DELETE")
10954 || anArgCase.IsEqual ("-DEL")
10955 || anArgCase.IsEqual ("-DELETE"))
10957 Handle(V3d_Light) aLightDel;
10958 if (++anArgIt >= theArgsNb)
10960 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10964 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10965 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
10966 Standard_Integer aLightIt = 0;
10967 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10969 aLightDel = aLightIter.Value();
10970 if (aLightIt == aLightDelId)
10975 if (aLightDel.IsNull())
10980 TColStd_SequenceOfInteger aLayers;
10981 aViewer->GetAllZLayers (aLayers);
10982 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10984 if (aLayeriter.Value() == aLayer
10985 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10987 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10988 if (!aSettings.Lights().IsNull())
10990 aSettings.Lights()->Remove (aLightDel);
10991 if (aSettings.Lights()->IsEmpty())
10993 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10996 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10997 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
11004 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
11006 aViewer->DelLight (aLightDel);
11009 else if (anArgCase.IsEqual ("COLOR")
11010 || anArgCase.IsEqual ("COLOUR")
11011 || anArgCase.IsEqual ("-COLOR")
11012 || anArgCase.IsEqual ("-COLOUR"))
11014 if (++anArgIt >= theArgsNb
11015 || aLightCurr.IsNull())
11017 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11021 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
11022 anArgNext.UpperCase();
11023 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
11024 aLightCurr->SetColor (aColor);
11026 else if (anArgCase.IsEqual ("POS")
11027 || anArgCase.IsEqual ("POSITION")
11028 || anArgCase.IsEqual ("-POS")
11029 || anArgCase.IsEqual ("-POSITION"))
11031 if ((anArgIt + 3) >= theArgsNb
11032 || aLightCurr.IsNull()
11033 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11034 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11036 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11040 anXYZ[0] = Atof (theArgVec[++anArgIt]);
11041 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11042 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11043 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
11045 else if (anArgCase.IsEqual ("DIR")
11046 || anArgCase.IsEqual ("DIRECTION")
11047 || anArgCase.IsEqual ("-DIR")
11048 || anArgCase.IsEqual ("-DIRECTION"))
11050 if ((anArgIt + 3) >= theArgsNb
11051 || aLightCurr.IsNull()
11052 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
11053 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11055 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11059 anXYZ[0] = Atof (theArgVec[++anArgIt]);
11060 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11061 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11062 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
11064 else if (anArgCase.IsEqual ("SM")
11065 || anArgCase.IsEqual ("SMOOTHNESS")
11066 || anArgCase.IsEqual ("-SM")
11067 || anArgCase.IsEqual ("-SMOOTHNESS"))
11069 if (++anArgIt >= theArgsNb
11070 || aLightCurr.IsNull())
11072 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11076 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11077 if (Abs (aSmoothness) <= ShortRealEpsilon())
11079 aLightCurr->SetIntensity (1.f);
11081 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
11083 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
11087 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
11088 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
11091 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
11093 aLightCurr->SetSmoothRadius (aSmoothness);
11095 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
11097 aLightCurr->SetSmoothAngle (aSmoothness);
11100 else if (anArgCase.IsEqual ("INT")
11101 || anArgCase.IsEqual ("INTENSITY")
11102 || anArgCase.IsEqual ("-INT")
11103 || anArgCase.IsEqual ("-INTENSITY"))
11105 if (++anArgIt >= theArgsNb
11106 || aLightCurr.IsNull())
11108 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11112 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11113 aLightCurr->SetIntensity (aIntensity);
11115 else if (anArgCase.IsEqual ("ANG")
11116 || anArgCase.IsEqual ("ANGLE")
11117 || anArgCase.IsEqual ("-ANG")
11118 || anArgCase.IsEqual ("-ANGLE"))
11120 if (++anArgIt >= theArgsNb
11121 || aLightCurr.IsNull()
11122 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11124 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11128 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11129 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
11131 else if (anArgCase.IsEqual ("CONSTATTEN")
11132 || anArgCase.IsEqual ("CONSTATTENUATION")
11133 || anArgCase.IsEqual ("-CONSTATTEN")
11134 || anArgCase.IsEqual ("-CONSTATTENUATION"))
11136 if (++anArgIt >= theArgsNb
11137 || aLightCurr.IsNull()
11138 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11139 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11141 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11145 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11146 anAtten[0] = Atof (theArgVec[anArgIt]);
11147 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11149 else if (anArgCase.IsEqual ("LINATTEN")
11150 || anArgCase.IsEqual ("LINEARATTEN")
11151 || anArgCase.IsEqual ("LINEARATTENUATION")
11152 || anArgCase.IsEqual ("-LINATTEN")
11153 || anArgCase.IsEqual ("-LINEARATTEN")
11154 || anArgCase.IsEqual ("-LINEARATTENUATION"))
11156 if (++anArgIt >= theArgsNb
11157 || aLightCurr.IsNull()
11158 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11159 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11161 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11165 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11166 anAtten[1] = Atof (theArgVec[anArgIt]);
11167 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11169 else if (anArgCase.IsEqual ("EXP")
11170 || anArgCase.IsEqual ("EXPONENT")
11171 || anArgCase.IsEqual ("SPOTEXP")
11172 || anArgCase.IsEqual ("SPOTEXPONENT")
11173 || anArgCase.IsEqual ("-EXP")
11174 || anArgCase.IsEqual ("-EXPONENT")
11175 || anArgCase.IsEqual ("-SPOTEXP")
11176 || anArgCase.IsEqual ("-SPOTEXPONENT"))
11178 if (++anArgIt >= theArgsNb
11179 || aLightCurr.IsNull()
11180 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11182 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11186 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
11188 else if (anArgCase.IsEqual ("HEAD")
11189 || anArgCase.IsEqual ("HEADLIGHT")
11190 || anArgCase.IsEqual ("-HEAD")
11191 || anArgCase.IsEqual ("-HEADLIGHT"))
11193 if (aLightCurr.IsNull()
11194 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
11196 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11200 Standard_Boolean isHeadLight = Standard_True;
11201 if (anArgIt + 1 < theArgsNb
11202 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
11206 aLightCurr->SetHeadlight (isHeadLight);
11210 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
11214 addLight (aLightNew, aLayer, isGlobal);
11218 //===============================================================================================
11219 //function : VPBREnvironment
11221 //===============================================================================================
11222 static int VPBREnvironment (Draw_Interpretor&,
11223 Standard_Integer theArgsNb,
11224 const char** theArgVec)
11228 std::cerr << "Error: 'vpbrenv' command has only one argument\n";
11232 Handle(V3d_View) aView = ViewerTest::CurrentView();
11233 if (aView.IsNull())
11235 std::cerr << "Error: no active viewer!\n";
11239 TCollection_AsciiString anArg = TCollection_AsciiString (theArgVec[1]);
11242 if (anArg == "-generate"
11243 || anArg == "-gen")
11245 aView->GeneratePBREnvironment (Standard_True);
11247 else if (anArg == "-clear")
11249 aView->ClearPBREnvironment (Standard_True);
11253 std::cerr << "Error: unknown argument [" << theArgVec[1] << "] for 'vpbrenv' command\n";
11260 //! Read Graphic3d_RenderingParams::PerfCounters flag.
11261 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
11262 Standard_Boolean& theToReset,
11263 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
11264 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
11266 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
11267 TCollection_AsciiString aVal = theValue;
11268 Standard_Boolean toReverse = Standard_False;
11269 if (aVal == "none")
11271 theToReset = Standard_True;
11272 return Standard_True;
11274 else if (aVal.StartsWith ("-"))
11276 toReverse = Standard_True;
11277 aVal = aVal.SubString (2, aVal.Length());
11279 else if (aVal.StartsWith ("no"))
11281 toReverse = Standard_True;
11282 aVal = aVal.SubString (3, aVal.Length());
11284 else if (aVal.StartsWith ("+"))
11286 aVal = aVal.SubString (2, aVal.Length());
11290 theToReset = Standard_True;
11294 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11295 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
11296 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
11297 else if (aVal == "structs"
11298 || aVal == "structures"
11299 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
11300 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
11301 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11302 else if (aVal == "tris"
11303 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
11304 else if (aVal == "pnts"
11305 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
11306 else if (aVal == "mem"
11307 || aVal == "gpumem"
11308 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11309 else if (aVal == "skipimmediate"
11310 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
11311 else if (aVal == "frametime"
11312 || aVal == "frametimers"
11313 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11314 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
11315 else if (aVal == "extended"
11316 || aVal == "verbose"
11317 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
11318 else if (aVal == "full"
11319 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
11322 return Standard_False;
11327 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
11331 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
11333 return Standard_True;
11336 //! Read Graphic3d_RenderingParams::PerfCounters flags.
11337 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
11338 Graphic3d_RenderingParams::PerfCounters& theFlags)
11340 TCollection_AsciiString aValue = theValue;
11341 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
11342 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
11343 Standard_Boolean toReset = Standard_False;
11346 Standard_Integer aSplitPos = aValue.Search ("|");
11347 if (aSplitPos <= 0)
11349 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
11351 return Standard_False;
11355 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
11357 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
11358 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
11359 return Standard_True;
11364 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
11365 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
11367 return Standard_False;
11370 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
11374 //=======================================================================
11375 //function : VRenderParams
11376 //purpose : Enables/disables rendering features
11377 //=======================================================================
11379 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
11380 Standard_Integer theArgNb,
11381 const char** theArgVec)
11383 Handle(V3d_View) aView = ViewerTest::CurrentView();
11384 if (aView.IsNull())
11386 std::cerr << "Error: no active viewer!\n";
11390 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
11391 TCollection_AsciiString aCmdName (theArgVec[0]);
11392 aCmdName.LowerCase();
11393 if (aCmdName == "vraytrace")
11397 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
11400 else if (theArgNb == 2)
11402 TCollection_AsciiString aValue (theArgVec[1]);
11403 aValue.LowerCase();
11407 aParams.Method = Graphic3d_RM_RAYTRACING;
11411 else if (aValue == "off"
11414 aParams.Method = Graphic3d_RM_RASTERIZATION;
11420 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
11426 std::cout << "Error: wrong number of arguments\n";
11433 theDI << "renderMode: ";
11434 switch (aParams.Method)
11436 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11437 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
11440 theDI << "transparency: ";
11441 switch (aParams.TransparencyMethod)
11443 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
11444 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
11445 << TCollection_AsciiString (aParams.OitDepthFactor); break;
11448 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
11449 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
11450 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
11451 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
11452 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
11453 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
11454 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
11455 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
11456 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
11457 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
11458 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
11459 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
11460 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
11461 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
11462 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
11463 theDI << "shadingModel: ";
11464 switch (aView->ShadingModel())
11466 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11467 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
11468 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
11469 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
11470 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
11471 case Graphic3d_TOSM_PBR: theDI << "pbr"; break;
11472 case Graphic3d_TOSM_PBR_FACET: theDI << "pbr_facet"; break;
11475 theDI << "perfCounters:";
11476 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
11480 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
11484 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
11486 theDI << " structs";
11488 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
11490 theDI << " groups";
11492 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
11494 theDI << " arrays";
11496 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
11500 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
11504 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
11506 theDI << " gpumem";
11508 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
11510 theDI << " frameTime";
11512 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
11514 theDI << " skipimmediate";
11516 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
11522 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
11523 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
11524 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
11525 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
11526 "noUpdate") << "\n";
11531 Standard_Boolean toPrint = Standard_False;
11532 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
11533 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11535 Standard_CString anArg (theArgVec[anArgIter]);
11536 TCollection_AsciiString aFlag (anArg);
11538 if (anUpdateTool.parseRedrawMode (aFlag))
11542 else if (aFlag == "-echo"
11543 || aFlag == "-print")
11545 toPrint = Standard_True;
11546 anUpdateTool.Invalidate();
11548 else if (aFlag == "-mode"
11549 || aFlag == "-rendermode"
11550 || aFlag == "-render_mode")
11554 switch (aParams.Method)
11556 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11557 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
11563 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11567 else if (aFlag == "-ray"
11568 || aFlag == "-raytrace")
11572 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
11576 aParams.Method = Graphic3d_RM_RAYTRACING;
11578 else if (aFlag == "-rast"
11579 || aFlag == "-raster"
11580 || aFlag == "-rasterization")
11584 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
11588 aParams.Method = Graphic3d_RM_RASTERIZATION;
11590 else if (aFlag == "-msaa")
11594 theDI << aParams.NbMsaaSamples << " ";
11597 else if (++anArgIter >= theArgNb)
11599 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11603 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
11604 if (aNbSamples < 0)
11606 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
11611 aParams.NbMsaaSamples = aNbSamples;
11614 else if (aFlag == "-linefeather"
11615 || aFlag == "-edgefeather"
11616 || aFlag == "-feather")
11620 theDI << " " << aParams.LineFeather << " ";
11623 else if (++anArgIter >= theArgNb)
11625 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11629 TCollection_AsciiString aParam = theArgVec[anArgIter];
11630 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11631 if (aFeather <= 0.0f)
11633 std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n";
11636 aParams.LineFeather = aFeather;
11638 else if (aFlag == "-oit")
11642 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
11644 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
11648 theDI << "off" << " ";
11652 else if (++anArgIter >= theArgNb)
11654 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11658 TCollection_AsciiString aParam = theArgVec[anArgIter];
11659 aParam.LowerCase();
11660 if (aParam.IsRealValue())
11662 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11663 if (aWeight < 0.f || aWeight > 1.f)
11665 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
11669 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
11670 aParams.OitDepthFactor = aWeight;
11672 else if (aParam == "off")
11674 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
11678 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11682 else if (aFlag == "-depthprepass")
11686 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
11689 aParams.ToEnableDepthPrepass = Standard_True;
11690 if (anArgIter + 1 < theArgNb
11691 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
11696 else if (aFlag == "-samplealphatocoverage"
11697 || aFlag == "-alphatocoverage")
11701 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
11704 aParams.ToEnableAlphaToCoverage = Standard_True;
11705 if (anArgIter + 1 < theArgNb
11706 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
11711 else if (aFlag == "-rendscale"
11712 || aFlag == "-renderscale"
11713 || aFlag == "-renderresolutionscale")
11717 theDI << aParams.RenderResolutionScale << " ";
11720 else if (++anArgIter >= theArgNb)
11722 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11726 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
11729 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
11734 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
11737 else if (aFlag == "-raydepth"
11738 || aFlag == "-ray_depth")
11742 theDI << aParams.RaytracingDepth << " ";
11745 else if (++anArgIter >= theArgNb)
11747 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11751 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
11753 // We allow RaytracingDepth be more than 10 in case of GI enabled
11754 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
11756 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
11761 aParams.RaytracingDepth = aDepth;
11764 else if (aFlag == "-shad"
11765 || aFlag == "-shadows")
11769 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
11773 Standard_Boolean toEnable = Standard_True;
11774 if (++anArgIter < theArgNb
11775 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11779 aParams.IsShadowEnabled = toEnable;
11781 else if (aFlag == "-refl"
11782 || aFlag == "-reflections")
11786 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
11790 Standard_Boolean toEnable = Standard_True;
11791 if (++anArgIter < theArgNb
11792 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11796 aParams.IsReflectionEnabled = toEnable;
11798 else if (aFlag == "-fsaa")
11802 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
11806 Standard_Boolean toEnable = Standard_True;
11807 if (++anArgIter < theArgNb
11808 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11812 aParams.IsAntialiasingEnabled = toEnable;
11814 else if (aFlag == "-gleam")
11818 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
11822 Standard_Boolean toEnable = Standard_True;
11823 if (++anArgIter < theArgNb
11824 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11828 aParams.IsTransparentShadowEnabled = toEnable;
11830 else if (aFlag == "-gi")
11834 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
11838 Standard_Boolean toEnable = Standard_True;
11839 if (++anArgIter < theArgNb
11840 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11844 aParams.IsGlobalIlluminationEnabled = toEnable;
11847 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
11850 else if (aFlag == "-blockedrng"
11851 || aFlag == "-brng")
11855 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
11859 Standard_Boolean toEnable = Standard_True;
11860 if (++anArgIter < theArgNb
11861 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11865 aParams.CoherentPathTracingMode = toEnable;
11867 else if (aFlag == "-maxrad")
11871 theDI << aParams.RadianceClampingValue << " ";
11874 else if (++anArgIter >= theArgNb)
11876 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11880 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
11881 if (!aMaxRadStr.IsRealValue())
11883 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11887 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
11888 if (aMaxRadiance <= 0.0)
11890 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
11895 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
11898 else if (aFlag == "-iss")
11902 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
11906 Standard_Boolean toEnable = Standard_True;
11907 if (++anArgIter < theArgNb
11908 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11912 aParams.AdaptiveScreenSampling = toEnable;
11914 else if (aFlag == "-issatomic")
11918 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
11922 Standard_Boolean toEnable = Standard_True;
11923 if (++anArgIter < theArgNb
11924 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11928 aParams.AdaptiveScreenSamplingAtomic = toEnable;
11930 else if (aFlag == "-issd")
11934 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
11938 Standard_Boolean toEnable = Standard_True;
11939 if (++anArgIter < theArgNb
11940 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11944 aParams.ShowSamplingTiles = toEnable;
11946 else if (aFlag == "-tilesize")
11950 theDI << aParams.RayTracingTileSize << " ";
11953 else if (++anArgIter >= theArgNb)
11955 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11959 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
11962 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
11965 aParams.RayTracingTileSize = aTileSize;
11967 else if (aFlag == "-nbtiles")
11971 theDI << aParams.NbRayTracingTiles << " ";
11974 else if (++anArgIter >= theArgNb)
11976 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11980 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
11983 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
11986 else if (aNbTiles > 0
11988 || aNbTiles > 1024))
11990 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
11992 aParams.NbRayTracingTiles = aNbTiles;
11994 else if (aFlag == "-env")
11998 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
12002 Standard_Boolean toEnable = Standard_True;
12003 if (++anArgIter < theArgNb
12004 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12008 aParams.UseEnvironmentMapBackground = toEnable;
12010 else if (aFlag == "-twoside")
12014 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
12018 Standard_Boolean toEnable = Standard_True;
12019 if (++anArgIter < theArgNb
12020 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12024 aParams.TwoSidedBsdfModels = toEnable;
12026 else if (aFlag == "-shademodel"
12027 || aFlag == "-shadingmodel"
12028 || aFlag == "-shading")
12032 switch (aView->ShadingModel())
12034 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
12035 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
12036 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
12037 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
12038 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
12039 case Graphic3d_TOSM_PBR: theDI << "pbr"; break;
12040 case Graphic3d_TOSM_PBR_FACET: theDI << "pbr_facet"; break;
12045 if (++anArgIter >= theArgNb)
12047 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12050 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
12051 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
12052 && aModel != Graphic3d_TOSM_DEFAULT)
12054 aView->SetShadingModel (aModel);
12058 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
12062 else if (aFlag == "-pbrenvpow2size"
12063 || aFlag == "-pbrenvp2s"
12064 || aFlag == "-pep2s")
12066 if (++anArgIter >= theArgNb)
12068 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12072 const Standard_Integer aPbrEnvPow2Size = Draw::Atoi (theArgVec[anArgIter]);
12073 if (aPbrEnvPow2Size < 1)
12075 std::cout << "Error: 'Pow2Size' of PBR Environment has to be greater or equal 1\n";
12078 aParams.PbrEnvPow2Size = aPbrEnvPow2Size;
12080 else if (aFlag == "-pbrenvspecmaplevelsnumber"
12081 || aFlag == "-pbrenvspecmapnblevels"
12082 || aFlag == "-pbrenvspecmaplevels"
12083 || aFlag == "-pbrenvsmln"
12084 || aFlag == "-pesmln")
12086 if (++anArgIter >= theArgNb)
12088 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12092 const Standard_Integer aPbrEnvSpecMapNbLevels = Draw::Atoi (theArgVec[anArgIter]);
12093 if (aPbrEnvSpecMapNbLevels < 2)
12095 std::cout << "Error: 'SpecMapLevelsNumber' of PBR Environment has to be greater or equal 2\n";
12098 aParams.PbrEnvSpecMapNbLevels = aPbrEnvSpecMapNbLevels;
12100 else if (aFlag == "-pbrenvbakngdiffsamplesnumber"
12101 || aFlag == "-pbrenvbakingdiffsamples"
12102 || aFlag == "-pbrenvbdsn")
12104 if (++anArgIter >= theArgNb)
12106 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12110 const Standard_Integer aPbrEnvBakingDiffNbSamples = Draw::Atoi (theArgVec[anArgIter]);
12111 if (aPbrEnvBakingDiffNbSamples < 1)
12113 std::cout << "Error: 'BakingDiffSamplesNumber' of PBR Environtment has to be greater or equal 1\n";
12116 aParams.PbrEnvBakingDiffNbSamples = aPbrEnvBakingDiffNbSamples;
12118 else if (aFlag == "-pbrenvbakngspecsamplesnumber"
12119 || aFlag == "-pbrenvbakingspecsamples"
12120 || aFlag == "-pbrenvbssn")
12122 if (++anArgIter >= theArgNb)
12124 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12128 const Standard_Integer aPbrEnvBakingSpecNbSamples = Draw::Atoi(theArgVec[anArgIter]);
12129 if (aPbrEnvBakingSpecNbSamples < 1)
12131 std::cout << "Error: 'BakingSpecSamplesNumber' of PBR Environtment has to be greater or equal 1\n";
12134 aParams.PbrEnvBakingSpecNbSamples = aPbrEnvBakingSpecNbSamples;
12136 else if (aFlag == "-pbrenvbakingprobability"
12137 || aFlag == "-pbrenvbp")
12139 if (++anArgIter >= theArgNb)
12141 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12144 const Standard_ShortReal aPbrEnvBakingProbability = static_cast<Standard_ShortReal>(Draw::Atof (theArgVec[anArgIter]));
12145 if (aPbrEnvBakingProbability < 0.f
12146 || aPbrEnvBakingProbability > 1.f)
12148 std::cout << "Error: 'BakingProbability' of PBR Environtment has to be in range of [0, 1]\n";
12151 aParams.PbrEnvBakingProbability = aPbrEnvBakingProbability;
12153 else if (aFlag == "-resolution")
12155 if (++anArgIter >= theArgNb)
12157 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12161 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
12162 if (aResolution.IsIntegerValue())
12164 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
12168 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12172 else if (aFlag == "-rebuildglsl"
12173 || aFlag == "-rebuild")
12177 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
12181 Standard_Boolean toEnable = Standard_True;
12182 if (++anArgIter < theArgNb
12183 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12187 aParams.RebuildRayTracingShaders = toEnable;
12189 else if (aFlag == "-focal")
12191 if (++anArgIter >= theArgNb)
12193 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12197 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12198 if (aParam.IsRealValue())
12200 float aFocalDist = static_cast<float> (aParam.RealValue());
12201 if (aFocalDist < 0)
12203 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12206 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
12210 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12214 else if (aFlag == "-aperture")
12216 if (++anArgIter >= theArgNb)
12218 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12222 TCollection_AsciiString aParam(theArgVec[anArgIter]);
12223 if (aParam.IsRealValue())
12225 float aApertureSize = static_cast<float> (aParam.RealValue());
12226 if (aApertureSize < 0)
12228 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12231 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
12235 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12239 else if (aFlag == "-exposure")
12241 if (++anArgIter >= theArgNb)
12243 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12247 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
12248 if (anExposure.IsRealValue())
12250 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
12254 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12258 else if (aFlag == "-whitepoint")
12260 if (++anArgIter >= theArgNb)
12262 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12266 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
12267 if (aWhitePoint.IsRealValue())
12269 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
12273 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12277 else if (aFlag == "-tonemapping")
12279 if (++anArgIter >= theArgNb)
12281 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12285 TCollection_AsciiString aMode (theArgVec[anArgIter]);
12288 if (aMode == "disabled")
12290 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
12292 else if (aMode == "filmic")
12294 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
12298 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12302 else if (aFlag == "-performancestats"
12303 || aFlag == "-performancecounters"
12304 || aFlag == "-perfstats"
12305 || aFlag == "-perfcounters"
12306 || aFlag == "-stats")
12308 if (++anArgIter >= theArgNb)
12310 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12314 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
12315 aFlagsStr.LowerCase();
12316 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
12317 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
12319 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12322 aView->ChangeRenderingParams().CollectedStats = aFlags;
12323 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
12325 else if (aFlag == "-perfupdateinterval"
12326 || aFlag == "-statsupdateinterval")
12328 if (++anArgIter >= theArgNb)
12330 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12333 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12335 else if (aFlag == "-perfchart"
12336 || aFlag == "-statschart")
12338 if (++anArgIter >= theArgNb)
12340 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12343 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
12345 else if (aFlag == "-perfchartmax"
12346 || aFlag == "-statschartmax")
12348 if (++anArgIter >= theArgNb)
12350 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12353 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12355 else if (aFlag == "-frustumculling"
12356 || aFlag == "-culling")
12360 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
12361 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
12362 "noUpdate") << " ";
12366 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
12367 if (++anArgIter < theArgNb)
12369 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
12370 aStateStr.LowerCase();
12371 bool toEnable = true;
12372 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
12374 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
12376 else if (aStateStr == "noupdate"
12377 || aStateStr == "freeze")
12379 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
12386 aParams.FrustumCullingState = aState;
12390 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
12398 //=======================================================================
12399 //function : searchInfo
12401 //=======================================================================
12402 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
12403 const TCollection_AsciiString& theKey)
12405 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
12407 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
12409 return anIter.Value();
12412 return TCollection_AsciiString();
12415 //=======================================================================
12416 //function : VStatProfiler
12418 //=======================================================================
12419 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
12420 Standard_Integer theArgNb,
12421 const char** theArgVec)
12423 Handle(V3d_View) aView = ViewerTest::CurrentView();
12424 if (aView.IsNull())
12426 std::cerr << "Error: no active viewer!\n";
12430 Standard_Boolean toRedraw = Standard_True;
12431 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
12432 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
12433 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
12434 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12436 Standard_CString anArg (theArgVec[anArgIter]);
12437 TCollection_AsciiString aFlag (anArg);
12439 if (aFlag == "-noredraw")
12441 toRedraw = Standard_False;
12445 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
12446 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
12447 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
12448 else if (aFlag == "alllayers"
12449 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
12450 else if (aFlag == "allstructs"
12451 || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
12452 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
12453 else if (aFlag == "allarrays"
12454 || aFlag == "fillarrays"
12455 || aFlag == "linearrays"
12456 || aFlag == "pointarrays"
12457 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
12458 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
12459 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
12460 else if (aFlag == "geommem"
12461 || aFlag == "texturemem"
12462 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
12463 else if (aFlag == "elapsedframe"
12464 || aFlag == "cpuframeaverage"
12465 || aFlag == "cpupickingaverage"
12466 || aFlag == "cpucullingaverage"
12467 || aFlag == "cpudynaverage"
12468 || aFlag == "cpuframemax"
12469 || aFlag == "cpupickingmax"
12470 || aFlag == "cpucullingmax"
12471 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
12474 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
12478 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
12482 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
12484 aView->ChangeRenderingParams().CollectedStats =
12485 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
12489 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12491 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12494 TColStd_IndexedDataMapOfStringString aDict;
12495 aView->StatisticInformation (aDict);
12497 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
12499 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12501 Standard_CString anArg(theArgVec[anArgIter]);
12502 TCollection_AsciiString aFlag(anArg);
12504 if (aFlag == "fps")
12506 theDI << searchInfo (aDict, "FPS") << " ";
12508 else if (aFlag == "cpu")
12510 theDI << searchInfo (aDict, "CPU FPS") << " ";
12512 else if (aFlag == "alllayers")
12514 theDI << searchInfo (aDict, "Layers") << " ";
12516 else if (aFlag == "layers")
12518 theDI << searchInfo (aDict, "Rendered layers") << " ";
12520 else if (aFlag == "allstructs")
12522 theDI << searchInfo (aDict, "Structs") << " ";
12524 else if (aFlag == "structs")
12526 theDI << searchInfo (aDict, "Rendered structs") << " ";
12528 else if (aFlag == "groups")
12530 theDI << searchInfo (aDict, "Rendered groups") << " ";
12532 else if (aFlag == "allarrays")
12534 theDI << searchInfo (aDict, "Rendered arrays") << " ";
12536 else if (aFlag == "fillarrays")
12538 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
12540 else if (aFlag == "linearrays")
12542 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
12544 else if (aFlag == "pointarrays")
12546 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
12548 else if (aFlag == "textarrays")
12550 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
12552 else if (aFlag == "triangles")
12554 theDI << searchInfo (aDict, "Rendered triangles") << " ";
12556 else if (aFlag == "points")
12558 theDI << searchInfo (aDict, "Rendered points") << " ";
12560 else if (aFlag == "geommem")
12562 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
12564 else if (aFlag == "texturemem")
12566 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
12568 else if (aFlag == "framemem")
12570 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
12572 else if (aFlag == "elapsedframe")
12574 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
12576 else if (aFlag == "cpuframe_average")
12578 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
12580 else if (aFlag == "cpupicking_average")
12582 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
12584 else if (aFlag == "cpuculling_average")
12586 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
12588 else if (aFlag == "cpudyn_average")
12590 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
12592 else if (aFlag == "cpuframe_max")
12594 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
12596 else if (aFlag == "cpupicking_max")
12598 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
12600 else if (aFlag == "cpuculling_max")
12602 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
12604 else if (aFlag == "cpudyn_max")
12606 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
12614 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12616 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12618 theDI << "Statistic info:\n" << aView->StatisticInformation();
12623 //=======================================================================
12624 //function : VXRotate
12626 //=======================================================================
12627 static Standard_Integer VXRotate (Draw_Interpretor& di,
12628 Standard_Integer argc,
12629 const char ** argv)
12631 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
12632 if (aContext.IsNull())
12634 di << argv[0] << "ERROR : use 'vinit' command before \n";
12640 di << "ERROR : Usage : " << argv[0] << " name angle\n";
12644 TCollection_AsciiString aName (argv[1]);
12645 Standard_Real anAngle = Draw::Atof (argv[2]);
12648 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
12649 Handle(AIS_InteractiveObject) anIObj;
12650 if (!aMap.Find2 (aName, anIObj))
12652 di << "Use 'vdisplay' before\n";
12656 gp_Trsf aTransform;
12657 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
12658 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
12660 aContext->SetLocation (anIObj, aTransform);
12661 aContext->UpdateCurrentViewer();
12665 //===============================================================================================
12666 //function : VManipulator
12668 //===============================================================================================
12669 static int VManipulator (Draw_Interpretor& theDi,
12670 Standard_Integer theArgsNb,
12671 const char** theArgVec)
12673 Handle(V3d_View) aCurrentView = ViewerTest::CurrentView();
12674 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
12675 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
12676 if (aCurrentView.IsNull()
12677 || aViewer.IsNull())
12679 std::cerr << "No active viewer!\n";
12683 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
12684 Standard_Integer anArgIter = 1;
12685 for (; anArgIter < theArgsNb; ++anArgIter)
12687 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
12690 ViewerTest_CmdParser aCmd;
12691 aCmd.SetDescription ("Manages manipulator for interactive objects:");
12692 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
12693 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
12694 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
12695 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
12696 aCmd.AddOption ("view", "... {active | [view name]} - define view in which manipulator will be displayed, 'all' by default");
12697 aCmd.AddOption ("detach", "... - detach manipulator");
12699 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
12700 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
12701 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
12703 aCmd.AddOption ("move", "... x y z - move object");
12704 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
12705 aCmd.AddOption ("scale", "... factor - scale object");
12707 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
12708 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
12709 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
12710 aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform");
12711 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
12712 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
12713 aCmd.AddOption ("parts", "... all axes mode {0|1} - set visual part");
12714 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
12715 aCmd.AddOption ("size", "... size - set size of manipulator");
12716 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
12718 aCmd.Parse (theArgsNb, theArgVec);
12720 if (aCmd.HasOption ("help"))
12722 theDi.PrintHelp (theArgVec[0]);
12726 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
12728 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
12730 if (aName.IsEmpty())
12732 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
12736 // ----------------------------------
12737 // detach existing manipulator object
12738 // ----------------------------------
12740 if (aCmd.HasOption ("detach"))
12742 if (!aMapAIS.IsBound2 (aName))
12744 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
12748 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12749 if (aManipulator.IsNull())
12751 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12755 aManipulator->Detach();
12756 aMapAIS.UnBind2 (aName);
12757 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
12762 // -----------------------------------------------
12763 // find or create manipulator if it does not exist
12764 // -----------------------------------------------
12766 Handle(AIS_Manipulator) aManipulator;
12767 if (!aMapAIS.IsBound2 (aName))
12769 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
12771 aManipulator = new AIS_Manipulator();
12772 aManipulator->SetModeActivationOnDetection (true);
12773 aMapAIS.Bind (aManipulator, aName);
12777 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12778 if (aManipulator.IsNull())
12780 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12785 // -----------------------------------------
12786 // change properties of manipulator instance
12787 // -----------------------------------------
12789 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
12791 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
12793 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
12795 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
12797 if (aCmd.HasOption ("followRotation", 1, Standard_True))
12799 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
12801 if (aCmd.HasOption("followDragging", 1, Standard_True))
12803 aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging"));
12805 if (aCmd.HasOption ("gap", 1, Standard_True))
12807 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
12809 if (aCmd.HasOption ("part", 3, Standard_True))
12811 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
12812 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
12813 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
12814 if (aMode < 1 || aMode > 4)
12816 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12820 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
12822 if (aCmd.HasOption("parts", 2, Standard_True))
12824 Standard_Integer aMode = aCmd.ArgInt("parts", 0);
12825 Standard_Boolean aOnOff = aCmd.ArgBool("parts", 1);
12826 if (aMode < 1 || aMode > 4)
12828 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12832 aManipulator->SetPart(static_cast<AIS_ManipulatorMode>(aMode), aOnOff);
12834 if (aCmd.HasOption ("pos", 3, Standard_True))
12836 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
12837 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
12838 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
12840 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
12842 if (aCmd.HasOption ("size", 1, Standard_True))
12844 aManipulator->SetSize (aCmd.ArgFloat ("size"));
12846 if (aCmd.HasOption ("zoomable", 1, Standard_True))
12848 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
12850 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
12852 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
12853 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
12857 // ---------------------------------------------------
12858 // attach, detach or access manipulator from an object
12859 // ---------------------------------------------------
12861 if (aCmd.HasOption ("attach"))
12863 // Find an object and attach manipulator to it
12864 if (!aCmd.HasOption ("attach", 1, Standard_True))
12869 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
12870 Handle(AIS_InteractiveObject) anObject;
12871 if (!aMapAIS.Find2 (anObjName, anObject))
12873 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
12877 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (aMapAIS);
12878 anIter.More(); anIter.Next())
12880 Handle(AIS_Manipulator) aManip = Handle(AIS_Manipulator)::DownCast (anIter.Key1());
12881 if (!aManip.IsNull()
12882 && aManip->IsAttached()
12883 && aManip->Object() == anObject)
12885 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
12890 AIS_Manipulator::OptionsForAttach anOptions;
12891 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
12893 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
12895 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
12897 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
12899 if (aCmd.HasOption ("enableModes", 1, Standard_True))
12901 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
12904 aManipulator->Attach (anObject, anOptions);
12906 // Check view option
12907 if (aCmd.HasOption ("view"))
12909 if (!aCmd.HasOption ("view", 1, Standard_True))
12913 TCollection_AsciiString aViewString (aCmd.Arg ("view", 0).c_str());
12914 Handle(V3d_View) aView;
12915 if (aViewString.IsEqual ("active"))
12917 aView = ViewerTest::CurrentView();
12919 else // Check view name
12921 ViewerTest_Names aViewNames (aViewString);
12922 if (!ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
12924 std::cerr << theArgVec[0] << " error: wrong view name '" << aViewString << "'\n";
12927 aView = ViewerTest_myViews.Find1 (aViewNames.GetViewName());
12928 if (aView.IsNull())
12930 std::cerr << theArgVec[0] << " error: cannot find view with name '" << aViewString << "'\n";
12934 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
12935 anIter (ViewerTest_myViews); anIter.More(); anIter.Next())
12937 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, anIter.Value(), Standard_False);
12939 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, aView, Standard_True);
12943 // --------------------------------------
12944 // apply transformation using manipulator
12945 // --------------------------------------
12947 if (aCmd.HasOption ("startTransform", 2, Standard_True))
12949 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
12951 if (aCmd.HasOption ("transform", 2, Standard_True))
12953 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
12955 if (aCmd.HasOption ("stopTransform"))
12957 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
12959 aManipulator->StopTransform (toApply);
12963 if (aCmd.HasOption ("move", 3, Standard_True))
12965 aT.SetTranslationPart (aCmd.ArgVec ("move"));
12967 if (aCmd.HasOption ("rotate", 7, Standard_True))
12969 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
12971 if (aCmd.HasOption ("scale", 1))
12973 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
12976 if (aT.Form() != gp_Identity)
12978 aManipulator->Transform (aT);
12981 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
12986 //===============================================================================================
12987 //function : VSelectionProperties
12989 //===============================================================================================
12990 static int VSelectionProperties (Draw_Interpretor& theDi,
12991 Standard_Integer theArgsNb,
12992 const char** theArgVec)
12994 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
12997 std::cerr << "No active viewer!\n";
13001 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
13003 // handle obsolete alias
13004 bool toEnable = true;
13007 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
13010 else if (theArgsNb != 2
13011 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
13013 std::cout << "Syntax error: wrong number of parameters.";
13016 if (toEnable != aCtx->ToHilightSelected())
13018 aCtx->ClearDetected();
13019 aCtx->SetToHilightSelected (toEnable);
13024 Standard_Boolean toPrint = theArgsNb == 1;
13025 Standard_Boolean toRedraw = Standard_False;
13026 Standard_Integer anArgIter = 1;
13027 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
13028 if (anArgIter < theArgsNb)
13030 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
13031 anArgFirst.LowerCase();
13033 if (anArgFirst == "dynhighlight"
13034 || anArgFirst == "dynhilight"
13035 || anArgFirst == "dynamichighlight"
13036 || anArgFirst == "dynamichilight")
13038 aType = Prs3d_TypeOfHighlight_Dynamic;
13040 else if (anArgFirst == "localdynhighlight"
13041 || anArgFirst == "localdynhilight"
13042 || anArgFirst == "localdynamichighlight"
13043 || anArgFirst == "localdynamichilight")
13045 aType = Prs3d_TypeOfHighlight_LocalDynamic;
13047 else if (anArgFirst == "selhighlight"
13048 || anArgFirst == "selhilight"
13049 || anArgFirst == "selectedhighlight"
13050 || anArgFirst == "selectedhilight")
13052 aType = Prs3d_TypeOfHighlight_Selected;
13054 else if (anArgFirst == "localselhighlight"
13055 || anArgFirst == "localselhilight"
13056 || anArgFirst == "localselectedhighlight"
13057 || anArgFirst == "localselectedhilight")
13059 aType = Prs3d_TypeOfHighlight_LocalSelected;
13066 for (; anArgIter < theArgsNb; ++anArgIter)
13068 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13070 if (anArg == "-help")
13072 theDi.PrintHelp (theArgVec[0]);
13075 else if (anArg == "-print")
13077 toPrint = Standard_True;
13079 else if (anArg == "-autoactivate")
13081 Standard_Boolean toEnable = Standard_True;
13082 if (anArgIter + 1 < theArgsNb
13083 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13087 aCtx->SetAutoActivateSelection (toEnable);
13089 else if (anArg == "-automatichighlight"
13090 || anArg == "-automatichilight"
13091 || anArg == "-autohighlight"
13092 || anArg == "-autohilight")
13094 Standard_Boolean toEnable = Standard_True;
13095 if (anArgIter + 1 < theArgsNb
13096 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13100 aCtx->ClearSelected (false);
13101 aCtx->ClearDetected();
13102 aCtx->SetAutomaticHilight (toEnable);
13105 else if (anArg == "-highlightselected"
13106 || anArg == "-hilightselected")
13108 Standard_Boolean toEnable = Standard_True;
13109 if (anArgIter + 1 < theArgsNb
13110 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13114 aCtx->ClearDetected();
13115 aCtx->SetToHilightSelected (toEnable);
13118 else if (anArg == "-pickstrategy"
13119 || anArg == "-pickingstrategy")
13121 if (++anArgIter >= theArgsNb)
13123 std::cout << "Syntax error: type of highlighting is undefined\n";
13127 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
13128 TCollection_AsciiString aVal (theArgVec[anArgIter]);
13130 if (aVal == "first"
13131 || aVal == "firstaccepted"
13132 || aVal == "firstacceptable")
13134 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
13136 else if (aVal == "topmost"
13137 || aVal == "onlyTopmost")
13139 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
13143 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
13147 aCtx->SetPickingStrategy (aStrategy);
13149 else if (anArg == "-pixtol"
13150 && anArgIter + 1 < theArgsNb)
13152 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
13154 else if ((anArg == "-mode"
13155 || anArg == "-dispmode")
13156 && anArgIter + 1 < theArgsNb)
13158 if (aType == Prs3d_TypeOfHighlight_None)
13160 std::cout << "Syntax error: type of highlighting is undefined\n";
13164 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
13165 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13166 aStyle->SetDisplayMode (aDispMode);
13167 toRedraw = Standard_True;
13169 else if (anArg == "-layer"
13170 && anArgIter + 1 < theArgsNb)
13172 if (aType == Prs3d_TypeOfHighlight_None)
13174 std::cout << "Syntax error: type of highlighting is undefined\n";
13179 Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN;
13180 if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer))
13182 std::cerr << "Error: wrong syntax at " << theArgVec[anArgIter] << ".\n";
13186 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13187 aStyle->SetZLayer (aNewLayer);
13188 toRedraw = Standard_True;
13190 else if (anArg == "-hicolor"
13191 || anArg == "-selcolor"
13192 || anArg == "-color")
13194 if (anArg.StartsWith ("-hi"))
13196 aType = Prs3d_TypeOfHighlight_Dynamic;
13198 else if (anArg.StartsWith ("-sel"))
13200 aType = Prs3d_TypeOfHighlight_Selected;
13202 else if (aType == Prs3d_TypeOfHighlight_None)
13204 std::cout << "Syntax error: type of highlighting is undefined\n";
13208 Quantity_Color aColor;
13209 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
13210 theArgVec + anArgIter + 1,
13212 if (aNbParsed == 0)
13214 std::cout << "Syntax error: need more arguments.\n";
13217 anArgIter += aNbParsed;
13219 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13220 aStyle->SetColor (aColor);
13221 toRedraw = Standard_True;
13223 else if ((anArg == "-transp"
13224 || anArg == "-transparency"
13225 || anArg == "-hitransp"
13226 || anArg == "-seltransp"
13227 || anArg == "-hitransplocal"
13228 || anArg == "-seltransplocal")
13229 && anArgIter + 1 < theArgsNb)
13231 if (anArg.StartsWith ("-hi"))
13233 aType = Prs3d_TypeOfHighlight_Dynamic;
13235 else if (anArg.StartsWith ("-sel"))
13237 aType = Prs3d_TypeOfHighlight_Selected;
13239 else if (aType == Prs3d_TypeOfHighlight_None)
13241 std::cout << "Syntax error: type of highlighting is undefined\n";
13245 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
13246 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13247 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
13248 toRedraw = Standard_True;
13250 else if ((anArg == "-mat"
13251 || anArg == "-material")
13252 && anArgIter + 1 < theArgsNb)
13254 if (aType == Prs3d_TypeOfHighlight_None)
13256 std::cout << "Syntax error: type of highlighting is undefined\n";
13260 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13261 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
13262 if (aMatName != Graphic3d_NOM_DEFAULT)
13265 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
13266 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
13267 Graphic3d_MaterialAspect aMat (aMatName);
13268 aMat.SetColor (aStyle->Color());
13269 aMat.SetTransparency (aStyle->Transparency());
13270 anAspect->SetFrontMaterial (aMat);
13271 anAspect->SetInteriorColor (aStyle->Color());
13272 aStyle->SetBasicFillAreaAspect (anAspect);
13276 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
13278 toRedraw = Standard_True;
13282 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
13288 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
13289 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
13290 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
13291 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
13292 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
13293 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
13294 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
13295 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
13296 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
13297 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
13298 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
13299 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
13300 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
13301 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
13304 if (aCtx->NbSelected() != 0 && toRedraw)
13306 aCtx->HilightSelected (Standard_True);
13312 //===============================================================================================
13313 //function : VDumpSelectionImage
13315 //===============================================================================================
13316 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
13317 Standard_Integer theArgsNb,
13318 const char** theArgVec)
13322 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
13326 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13327 if (aContext.IsNull())
13329 std::cout << "Error: no active view.\n";
13333 TCollection_AsciiString aFile;
13334 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13335 Image_Format anImgFormat = Image_Format_BGR;
13336 Standard_Integer aPickedIndex = 1;
13337 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
13339 TCollection_AsciiString aParam (theArgVec[anArgIter]);
13340 aParam.LowerCase();
13341 if (aParam == "-type")
13343 if (++anArgIter >= theArgsNb)
13345 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
13349 TCollection_AsciiString aValue (theArgVec[anArgIter]);
13350 aValue.LowerCase();
13351 if (aValue == "depth"
13352 || aValue == "normdepth"
13353 || aValue == "normalizeddepth")
13355 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13356 anImgFormat = Image_Format_GrayF;
13358 if (aValue == "depthinverted"
13359 || aValue == "normdepthinverted"
13360 || aValue == "normalizeddepthinverted"
13361 || aValue == "inverted")
13363 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
13364 anImgFormat = Image_Format_GrayF;
13366 else if (aValue == "unnormdepth"
13367 || aValue == "unnormalizeddepth")
13369 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
13370 anImgFormat = Image_Format_GrayF;
13372 else if (aValue == "objectcolor"
13373 || aValue == "object"
13374 || aValue == "color")
13376 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
13378 else if (aValue == "entitycolor"
13379 || aValue == "entity")
13381 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
13383 else if (aValue == "ownercolor"
13384 || aValue == "owner")
13386 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
13388 else if (aValue == "selectionmodecolor"
13389 || aValue == "selectionmode"
13390 || aValue == "selmodecolor"
13391 || aValue == "selmode")
13393 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
13396 else if (aParam == "-picked"
13397 || aParam == "-pickeddepth"
13398 || aParam == "-pickedindex")
13400 if (++anArgIter >= theArgsNb)
13402 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
13406 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
13408 else if (aFile.IsEmpty())
13410 aFile = theArgVec[anArgIter];
13414 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
13418 if (aFile.IsEmpty())
13420 std::cout << "Syntax error: image file name is missing.\n";
13424 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13425 Standard_Integer aWidth = 0, aHeight = 0;
13426 aView->Window()->Size (aWidth, aHeight);
13428 Image_AlienPixMap aPixMap;
13429 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
13431 std::cout << "Error: can't allocate image.\n";
13434 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
13436 std::cout << "Error: can't generate selection image.\n";
13439 if (!aPixMap.Save (aFile))
13441 std::cout << "Error: can't save selection image.\n";
13447 //===============================================================================================
13448 //function : VViewCube
13450 //===============================================================================================
13451 static int VViewCube (Draw_Interpretor& ,
13452 Standard_Integer theNbArgs,
13453 const char** theArgVec)
13455 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13456 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13457 if (aContext.IsNull() || aView.IsNull())
13459 std::cout << "Error: no active view.\n";
13462 else if (theNbArgs < 2)
13464 std::cout << "Syntax error: wrong number arguments\n";
13468 Handle(AIS_ViewCube) aViewCube;
13469 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
13470 Quantity_Color aColorRgb;
13471 TCollection_AsciiString aName;
13472 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
13474 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13476 if (anUpdateTool.parseRedrawMode (anArg))
13480 else if (aViewCube.IsNull())
13482 aName = theArgVec[anArgIter];
13483 if (aName.StartsWith ("-"))
13485 std::cout << "Syntax error: object name should be specified.\n";
13488 Handle(AIS_InteractiveObject) aPrs;
13489 GetMapOfAIS().Find2 (aName, aPrs);
13490 aViewCube = Handle(AIS_ViewCube)::DownCast (aPrs);
13491 if (aViewCube.IsNull())
13493 aViewCube = new AIS_ViewCube();
13494 aViewCube->SetBoxColor (Quantity_NOC_GRAY50);
13495 aViewCube->SetViewAnimation (ViewerTest::CurrentEventManager()->ViewAnimation());
13496 aViewCube->SetFixedAnimationLoop (false);
13499 else if (anArg == "-reset")
13501 aViewCube->ResetStyles();
13503 else if (anArg == "-color"
13504 || anArg == "-boxcolor"
13505 || anArg == "-boxsidecolor"
13506 || anArg == "-sidecolor"
13507 || anArg == "-boxedgecolor"
13508 || anArg == "-edgecolor"
13509 || anArg == "-boxcornercolor"
13510 || anArg == "-cornercolor"
13511 || anArg == "-innercolor"
13512 || anArg == "-textcolor")
13514 Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - anArgIter - 1,
13515 theArgVec + anArgIter + 1,
13517 if (aNbParsed == 0)
13519 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
13522 anArgIter += aNbParsed;
13523 if (anArg == "-boxcolor")
13525 aViewCube->SetBoxColor (aColorRgb);
13527 else if (anArg == "-boxsidecolor"
13528 || anArg == "-sidecolor")
13530 aViewCube->BoxSideStyle()->SetColor (aColorRgb);
13531 aViewCube->SynchronizeAspects();
13533 else if (anArg == "-boxedgecolor"
13534 || anArg == "-edgecolor")
13536 aViewCube->BoxEdgeStyle()->SetColor (aColorRgb);
13537 aViewCube->SynchronizeAspects();
13539 else if (anArg == "-boxcornercolor"
13540 || anArg == "-cornercolor")
13542 aViewCube->BoxCornerStyle()->SetColor (aColorRgb);
13543 aViewCube->SynchronizeAspects();
13545 else if (anArg == "-innercolor")
13547 aViewCube->SetInnerColor (aColorRgb);
13549 else if (anArg == "-textcolor")
13551 aViewCube->SetTextColor (aColorRgb);
13555 aViewCube->SetColor (aColorRgb);
13558 else if (anArgIter + 1 < theNbArgs
13559 && (anArg == "-transparency"
13560 || anArg == "-boxtransparency"))
13562 const Standard_Real aValue = Draw::Atof (theArgVec[++anArgIter]);
13563 if (aValue < 0.0 || aValue > 1.0)
13565 std::cout << "Syntax error: invalid transparency value " << theArgVec[anArgIter] << "\n";
13569 if (anArg == "-boxtransparency")
13571 aViewCube->SetBoxTransparency (aValue);
13575 aViewCube->SetTransparency (aValue);
13578 else if (anArg == "-axes"
13579 || anArg == "-edges"
13580 || anArg == "-vertices"
13581 || anArg == "-vertexes"
13582 || anArg == "-fixedanimation")
13584 bool toShow = true;
13585 if (anArgIter + 1 < theNbArgs
13586 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShow))
13590 if (anArg == "-fixedanimation")
13592 aViewCube->SetFixedAnimationLoop (toShow);
13594 else if (anArg == "-axes")
13596 aViewCube->SetDrawAxes (toShow);
13598 else if (anArg == "-edges")
13600 aViewCube->SetDrawEdges (toShow);
13604 aViewCube->SetDrawVertices (toShow);
13607 else if (anArg == "-yup"
13608 || anArg == "-zup")
13611 if (anArgIter + 1 < theNbArgs
13612 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isOn))
13616 if (anArg == "-yup")
13618 aViewCube->SetYup (isOn);
13622 aViewCube->SetYup (!isOn);
13625 else if (anArgIter + 1 < theNbArgs
13626 && anArg == "-font")
13628 aViewCube->SetFont (theArgVec[++anArgIter]);
13630 else if (anArgIter + 1 < theNbArgs
13631 && anArg == "-fontheight")
13633 aViewCube->SetFontHeight (Draw::Atof (theArgVec[++anArgIter]));
13635 else if (anArgIter + 1 < theNbArgs
13636 && (anArg == "-size"
13637 || anArg == "-boxsize"))
13639 aViewCube->SetSize (Draw::Atof (theArgVec[++anArgIter]),
13640 anArg != "-boxsize");
13642 else if (anArgIter + 1 < theNbArgs
13643 && (anArg == "-boxfacet"
13644 || anArg == "-boxfacetextension"
13645 || anArg == "-facetextension"
13646 || anArg == "-extension"))
13648 aViewCube->SetBoxFacetExtension (Draw::Atof (theArgVec[++anArgIter]));
13650 else if (anArgIter + 1 < theNbArgs
13651 && (anArg == "-boxedgegap"
13652 || anArg == "-edgegap"))
13654 aViewCube->SetBoxEdgeGap (Draw::Atof (theArgVec[++anArgIter]));
13656 else if (anArgIter + 1 < theNbArgs
13657 && (anArg == "-boxedgeminsize"
13658 || anArg == "-edgeminsize"))
13660 aViewCube->SetBoxEdgeMinSize (Draw::Atof (theArgVec[++anArgIter]));
13662 else if (anArgIter + 1 < theNbArgs
13663 && (anArg == "-boxcornerminsize"
13664 || anArg == "-cornerminsize"))
13666 aViewCube->SetBoxCornerMinSize (Draw::Atof (theArgVec[++anArgIter]));
13668 else if (anArgIter + 1 < theNbArgs
13669 && anArg == "-axespadding")
13671 aViewCube->SetAxesPadding (Draw::Atof (theArgVec[++anArgIter]));
13673 else if (anArgIter + 1 < theNbArgs
13674 && anArg == "-roundradius")
13676 aViewCube->SetRoundRadius (Draw::Atof (theArgVec[++anArgIter]));
13678 else if (anArgIter + 1 < theNbArgs
13679 && anArg == "-duration")
13681 aViewCube->SetDuration (Draw::Atof (theArgVec[++anArgIter]));
13685 std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
13689 if (aViewCube.IsNull())
13691 std::cout << "Syntax error: wrong number of arguments\n";
13695 ViewerTest::Display (aName, aViewCube, false);
13699 //=======================================================================
13700 //function : ViewerCommands
13702 //=======================================================================
13704 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
13707 const char *group = "ZeViewer";
13708 theCommands.Add("vinit",
13709 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
13710 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
13711 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13712 "\n\t\t: [-display displayName]"
13714 "\n\t\t: Creates new View window with specified name viewName."
13715 "\n\t\t: By default the new view is created in the viewer and in"
13716 "\n\t\t: graphic driver shared with active view."
13717 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
13718 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
13719 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
13720 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13721 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
13722 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
13724 "\n\t\t: -left, -top pixel position of left top corner of the window."
13725 "\n\t\t: -width, -height width and heigth of window respectively."
13726 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
13727 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
13728 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
13729 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
13730 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
13731 __FILE__,VInit,group);
13732 theCommands.Add("vclose" ,
13733 "[view_id [keep_context=0|1]]\n"
13734 "or vclose ALL - to remove all created views\n"
13735 " - removes view(viewer window) defined by its view_id.\n"
13736 " - keep_context: by default 0; if 1 and the last view is deleted"
13737 " the current context is not removed.",
13738 __FILE__,VClose,group);
13739 theCommands.Add("vactivate" ,
13740 "vactivate view_id [-noUpdate]"
13741 " - activates view(viewer window) defined by its view_id",
13742 __FILE__,VActivate,group);
13743 theCommands.Add("vviewlist",
13744 "vviewlist [format={tree, long}]"
13745 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
13746 " - format: format of result output, if tree the output is a tree view;"
13747 "otherwise it's a list of full view names. By default format = tree",
13748 __FILE__,VViewList,group);
13749 theCommands.Add("vhelp" ,
13750 "vhelp : display help on the viewer commands",
13751 __FILE__,VHelp,group);
13752 theCommands.Add("vviewproj",
13753 "vviewproj [top|bottom|left|right|front|back|axoLeft|axoRight]"
13754 "\n\t\t: [+-X+-Y+-Z] [-Zup|-Yup] [-frame +-X+-Y]"
13755 "\n\t\t: Setup view direction"
13756 "\n\t\t: -Yup use Y-up convention instead of Zup (which is default)."
13757 "\n\t\t: +-X+-Y+-Z define direction as combination of DX, DY and DZ;"
13758 "\n\t\t: for example '+Z' will show front of the model,"
13759 "\n\t\t: '-X-Y+Z' will define left axonometrical view."
13760 "\n\t\t: -frame define camera Up and Right directions (regardless Up convention);"
13761 "\n\t\t: for example '+X+Z' will show front of the model with Z-up."
13762 __FILE__,VViewProj,group);
13763 theCommands.Add("vtop" ,
13764 "vtop or <T> : Top view. Orientation +X+Y" ,
13765 __FILE__,VViewProj,group);
13766 theCommands.Add("vbottom" ,
13767 "vbottom : Bottom view. Orientation +X-Y" ,
13768 __FILE__,VViewProj,group);
13769 theCommands.Add("vleft" ,
13770 "vleft : Left view. Orientation -Y+Z" ,
13771 __FILE__,VViewProj,group);
13772 theCommands.Add("vright" ,
13773 "vright : Right view. Orientation +Y+Z" ,
13774 __FILE__,VViewProj,group);
13775 theCommands.Add("vaxo" ,
13776 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
13777 __FILE__,VViewProj,group);
13778 theCommands.Add("vfront" ,
13779 "vfront : Front view. Orientation +X+Z" ,
13780 __FILE__,VViewProj,group);
13781 theCommands.Add("vback" ,
13782 "vback : Back view. Orientation -X+Z" ,
13783 __FILE__,VViewProj,group);
13784 theCommands.Add("vpick" ,
13785 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
13787 theCommands.Add("vfit",
13788 "vfit or <F> [-selected] [-noupdate]"
13789 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
13790 __FILE__,VFit,group);
13791 theCommands.Add ("vfitarea",
13792 "vfitarea x1 y1 x2 y2"
13793 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
13794 "\n\t\t: Fit view to show area located between two points"
13795 "\n\t\t: given in world 2D or 3D corrdinates.",
13796 __FILE__, VFitArea, group);
13797 theCommands.Add ("vzfit", "vzfit [scale]\n"
13798 " Matches Z near, Z far view volume planes to the displayed objects.\n"
13799 " \"scale\" - specifies factor to scale computed z range.\n",
13800 __FILE__, VZFit, group);
13801 theCommands.Add("vrepaint",
13802 "vrepaint [-immediate] [-continuous FPS]"
13803 "\n\t\t: force redraw of active View"
13804 "\n\t\t: -immediate flag performs redraw of immediate layers only;"
13805 "\n\t\t: -continuous activates/deactivates continuous redraw of active View,"
13806 "\n\t\t: 0 means no continuous rendering,"
13807 "\n\t\t: -1 means non-stop redraws,"
13808 "\n\t\t: >0 specifies target framerate,",
13809 __FILE__,VRepaint,group);
13810 theCommands.Add("vclear",
13812 "\n\t\t: remove all the object from the viewer",
13813 __FILE__,VClear,group);
13816 "Changes background or some background settings.\n"
13819 " vbackground -imageFile ImageFile [-imageMode FillType]\n"
13820 " vbackground -imageMode FillType\n"
13821 " vbackground -gradient Color1 Color2 [-gradientMode FillMethod]\n"
13822 " vbackground -gradientMode FillMethod\n"
13823 " vbackground -cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]\n"
13824 " vbackground -color Color\n"
13825 " vbackground -default -gradient Color1 Color2 [-gradientMode FillType]\n"
13826 " vbackground -default -color Color\n"
13827 " vbackground -help\n"
13830 " -imageFile (-imgFile, -image, -img): sets filename of image used as background\n"
13831 " -imageMode (-imgMode, -imageMd, -imgMd): sets image fill type\n"
13832 " -gradient (-grad, -gr): sets background gradient starting and ending colors\n"
13833 " -gradientMode (-gradMode, -gradMd, -grMode, -grMd): sets gradient fill method\n"
13834 " -cubemap (-cmap, -cm): sets environmet cubemap as background\n"
13835 " -invertedz (-invz, -iz): sets inversion of Z axis for background cubemap rendering\n"
13836 " -order (-o): defines order of tiles in one image cubemap\n"
13837 " (has no effect in case of multi image cubemaps)\n"
13838 " -color (-col): sets background color\n"
13839 " -default (-def): sets background default gradient or color\n"
13840 " -help (-h): outputs short help message\n"
13843 " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n"
13844 " or reals within the range [0.0, 1.0]\n"
13845 " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n"
13846 " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n"
13847 " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, "
13849 " FillType: one of CENTERED, TILED, STRETCH, NONE\n"
13850 " ImageFile: a name of the file with the image used as a background\n"
13851 " CubemapFilei: a name of the file with one image packed cubemap or names of separate files with every cubemap side\n"
13852 " TileIndexi: a cubemap side index in range [0, 5] for i tile of one image packed cubemap\n",
13856 theCommands.Add ("vsetbg",
13857 "Loads image as background."
13858 "\n\t\t: vsetbg ImageFile [FillType]"
13859 "\n\t\t: vsetbg -imageFile ImageFile [-imageMode FillType]"
13860 "\n\t\t: Alias for 'vbackground -imageFile ImageFile [-imageMode FillType]'.",
13864 theCommands.Add ("vsetbgmode",
13865 "Changes background image fill type."
13866 "\n\t\t: vsetbgmode [-imageMode] FillType"
13867 "\n\t\t: Alias for 'vbackground -imageMode FillType'.",
13871 theCommands.Add ("vsetgradientbg",
13872 "Mounts gradient background."
13873 "\n\t\t: vsetgradientbg Color1 Color2 [FillMethod]"
13874 "\n\t\t: vsetgradientbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13875 "\n\t\t: Alias for 'vbackground -gradient Color1 Color2 -gradientMode FillMethod'.",
13879 theCommands.Add ("vsetgrbgmode",
13880 "Changes gradient background fill method."
13881 "\n\t\t: vsetgrbgmode [-gradientMode] FillMethod"
13882 "\n\t\t: Alias for 'vbackground -gradientMode FillMethod'.",
13886 theCommands.Add ("vsetcolorbg",
13887 "Sets background color."
13888 "\n\t\t: vsetcolorbg [-color] Color."
13889 "\n\t\t: Alias for 'vbackground -color Color'.",
13893 theCommands.Add ("vsetdefaultbg",
13894 "Sets default viewer background fill color (flat/gradient)."
13895 "\n\t\t: vsetdefaultbg Color1 Color2 [FillMethod]"
13896 "\n\t\t: vsetdefaultbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13897 "\n\t\t: Alias for 'vbackground -default -gradient Color1 Color2 [-gradientMode FillMethod]'."
13898 "\n\t\t: vsetdefaultbg [-color] Color"
13899 "\n\t\t: Alias for 'vbackground -default -color Color'.",
13903 theCommands.Add("vscale",
13904 "vscale : vscale X Y Z",
13905 __FILE__,VScale,group);
13906 theCommands.Add("vzbufftrihedron",
13907 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
13908 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
13909 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
13910 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
13911 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
13912 "\n\t\t: Displays a trihedron",
13913 __FILE__,VZBuffTrihedron,group);
13914 theCommands.Add("vrotate",
13915 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
13916 "\n : Option -mouseStart starts rotation according to the mouse position"
13917 "\n : Option -mouseMove continues rotation with angle computed"
13918 "\n : from last and new mouse position."
13919 "\n : vrotate AX AY AZ [X Y Z]",
13920 __FILE__,VRotate,group);
13921 theCommands.Add("vzoom",
13922 "vzoom : vzoom coef",
13923 __FILE__,VZoom,group);
13924 theCommands.Add("vpan",
13925 "vpan : vpan dx dy",
13926 __FILE__,VPan,group);
13927 theCommands.Add("vcolorscale",
13928 "vcolorscale name [-noupdate|-update] [-demo]"
13929 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
13930 "\n\t\t: [-font HeightFont=20]"
13931 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
13932 "\n\t\t: [-smoothTransition {on|off}=off]"
13933 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
13934 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
13935 "\n\t\t: [-textpos {left|right|center|none}=right]"
13936 "\n\t\t: [-labelAtBorder {on|off}=on]"
13937 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
13938 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
13939 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
13940 "\n\t\t: [-xy Left=0 Bottom=0]"
13941 "\n\t\t: -demo - displays a color scale with demonstratio values"
13942 "\n\t\t: -colors - set colors for all intervals"
13943 "\n\t\t: -color - set color for specific interval"
13944 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
13945 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
13946 "\n\t\t: at border means the value inbetween neighbor intervals,"
13947 "\n\t\t: at center means the center value within current interval"
13948 "\n\t\t: -labels - set labels for all intervals"
13949 "\n\t\t: -freeLabels - same as -labels but does not require"
13950 "\n\t\t: matching the number of intervals"
13951 "\n\t\t: -label - set label for specific interval"
13952 "\n\t\t: -title - set title"
13953 "\n\t\t: -reversed - setup smooth color transition between intervals"
13954 "\n\t\t: -smoothTransition - swap colorscale direction"
13955 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
13956 __FILE__, VColorScale, group);
13957 theCommands.Add("vgraduatedtrihedron",
13958 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
13959 "\t[-namefont Name] [-valuesfont Name]\n"
13960 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
13961 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
13962 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
13963 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
13964 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
13965 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
13966 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
13967 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
13968 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
13969 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
13970 " - Displays or erases graduated trihedron"
13971 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
13972 " - namefont - font of axes names. Default: Arial\n"
13973 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
13974 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
13975 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
13976 " - valuesfont - font of axes values. Default: Arial\n"
13977 " - xcolor, ycolor, zcolor - color of axis and values\n"
13978 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
13979 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
13980 __FILE__,VGraduatedTrihedron,group);
13981 theCommands.Add("vtile" ,
13982 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
13983 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
13984 "\n\t\t: -totalSize the size of virtual bigger viewport"
13985 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
13986 "\n\t\t: -lowerLeft tile offset as lower left corner"
13987 "\n\t\t: -upperLeft tile offset as upper left corner",
13988 __FILE__, VTile, group);
13989 theCommands.Add("vzlayer",
13990 "vzlayer [layerId]"
13991 "\n\t\t: [-add|-delete|-get|-settings] [-insertBefore AnotherLayer] [-insertAfter AnotherLayer]"
13992 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
13993 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
13994 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv|rayTracing}]"
13995 "\n\t\t: ZLayer list management:"
13996 "\n\t\t: -add add new z layer to viewer and print its id"
13997 "\n\t\t: -insertBefore add new z layer and insert it before existing one"
13998 "\n\t\t: -insertAfter add new z layer and insert it after existing one"
13999 "\n\t\t: -delete delete z layer"
14000 "\n\t\t: -get print sequence of z layers"
14001 "\n\t\t: -settings print status of z layer settings"
14002 "\n\t\t: -disable disables given setting"
14003 "\n\t\t: -enable enables given setting",
14004 __FILE__,VZLayer,group);
14005 theCommands.Add("vlayerline",
14006 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
14007 __FILE__,VLayerLine,group);
14008 theCommands.Add("vgrid",
14009 "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]"
14010 "\n\t\t: [-step X Y] [-size DX DY]"
14011 "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]",
14012 __FILE__, VGrid, group);
14013 theCommands.Add ("vpriviledgedplane",
14014 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
14015 "\n\t\t: Ox, Oy, Oz - plane origin"
14016 "\n\t\t: Nx, Ny, Nz - plane normal direction"
14017 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
14018 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
14019 __FILE__, VPriviledgedPlane, group);
14020 theCommands.Add ("vconvert",
14021 "vconvert v [Mode={window|view}]"
14022 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
14023 "\n\t\t: vconvert x y z [Mode={window|grid}]"
14024 "\n\t\t: window - convert to window coordinates, pixels"
14025 "\n\t\t: view - convert to view projection plane"
14026 "\n\t\t: grid - convert to model coordinates, given on grid"
14027 "\n\t\t: ray - convert projection ray to model coordiantes"
14028 "\n\t\t: - vconvert v window : convert view to window;"
14029 "\n\t\t: - vconvert v view : convert window to view;"
14030 "\n\t\t: - vconvert x y window : convert view to window;"
14031 "\n\t\t: - vconvert x y view : convert window to view;"
14032 "\n\t\t: - vconvert x y : convert window to model;"
14033 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
14034 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
14035 "\n\t\t: - vconvert x y z window : convert model to window;"
14036 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
14037 "\n\t\t: Converts the given coordinates to window/view/model space.",
14038 __FILE__, VConvert, group);
14039 theCommands.Add ("vfps",
14040 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
14041 __FILE__, VFps, group);
14042 theCommands.Add ("vgldebug",
14043 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
14044 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
14045 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
14046 "\n\t\t: Debug context can be requested only on Windows"
14047 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
14048 "\n\t\t: -sync - request synchronized debug GL context"
14049 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
14050 "\n\t\t: which are suppressed by default,"
14051 "\n\t\t: -glslCode - log GLSL program source code,"
14052 "\n\t\t: which are suppressed by default,"
14053 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
14054 "\n\t\t: which are suppressed by default",
14055 __FILE__, VGlDebug, group);
14056 theCommands.Add ("vvbo",
14057 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
14058 __FILE__, VVbo, group);
14059 theCommands.Add ("vstereo",
14060 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
14061 "\n\t\t: [-anaglyph Filter]"
14062 "\n\t\t: Control stereo output mode. Available modes for -mode:"
14063 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
14064 "\n\t\t: requires driver support."
14065 "\n\t\t: Should be called BEFORE vinit!"
14066 "\n\t\t: anaglyph - Anaglyph glasses"
14067 "\n\t\t: rowInterlaced - row-interlaced display"
14068 "\n\t\t: columnInterlaced - column-interlaced display"
14069 "\n\t\t: chessBoard - chess-board output"
14070 "\n\t\t: sideBySide - horizontal pair"
14071 "\n\t\t: overUnder - vertical pair"
14072 "\n\t\t: Available Anaglyph filters for -anaglyph:"
14073 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
14074 "\n\t\t: greenMagentaSimple",
14075 __FILE__, VStereo, group);
14076 theCommands.Add ("vcaps",
14077 "vcaps [-sRGB {0|1}] [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
14078 "\n\t\t: [-compatibleProfile {0|1}]"
14079 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
14080 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
14081 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
14082 "\n\t\t: [-noExtensions {0|1}] [-maxVersion Major Minor]"
14083 "\n\t\t: Modify particular graphic driver options:"
14084 "\n\t\t: sRGB - enable/disable sRGB rendering"
14085 "\n\t\t: FFP - use fixed-function pipeline instead of"
14086 "\n\t\t: built-in GLSL programs"
14087 "\n\t\t: (requires compatible profile)"
14088 "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs"
14089 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
14090 "\n\t\t: arrays to GPU memory)"
14091 "\n\t\t: sprite - use textured sprites instead of bitmaps"
14092 "\n\t\t: vsync - switch VSync on or off"
14093 "\n\t\t: winBuffer - allow using window buffer for rendering"
14094 "\n\t\t: Context creation options:"
14095 "\n\t\t: softMode - software OpenGL implementation"
14096 "\n\t\t: compatibleProfile - backward-compatible profile"
14097 "\n\t\t: quadbuffer - QuadBuffer"
14098 "\n\t\t: noExtensions - disallow usage of extensions"
14099 "\n\t\t: maxVersion - force upper OpenGL version to be used"
14100 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
14101 "\n\t\t: rendering paths producing the same visual result when"
14102 "\n\t\t: possible."
14103 "\n\t\t: Command is intended for testing old hardware compatibility.",
14104 __FILE__, VCaps, group);
14105 theCommands.Add ("vmemgpu",
14106 "vmemgpu [f]: print system-dependent GPU memory information if available;"
14107 " with f option returns free memory in bytes",
14108 __FILE__, VMemGpu, group);
14109 theCommands.Add ("vreadpixel",
14110 "vreadpixel xPixel yPixel [{rgb|rgba|sRGB|sRGBa|depth|hls|rgbf|rgbaf}=rgba] [-name|-hex]"
14111 " : Read pixel value for active view",
14112 __FILE__, VReadPixel, group);
14113 theCommands.Add("diffimage",
14114 "diffimage imageFile1 imageFile2 [diffImageFile]"
14115 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
14116 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
14117 "\n\t\t: Compare two images by content and generate difference image."
14118 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
14119 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
14120 __FILE__, VDiffImage, group);
14121 theCommands.Add ("vselect",
14122 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
14123 "- emulates different types of selection:\n"
14124 "- 1) single click selection\n"
14125 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
14126 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
14127 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
14128 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
14129 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
14130 " (partial inclusion - overlap - is not allowed by default)\n"
14131 "- 5) any of these selections with shift button pressed",
14132 __FILE__, VSelect, group);
14133 theCommands.Add ("vmoveto",
14134 "vmoveto [x y] [-reset]"
14135 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
14136 "\n\t\t: -reset resets current highlighting",
14137 __FILE__, VMoveTo, group);
14138 theCommands.Add ("vviewparams",
14139 "vviewparams [-args] [-scale [s]]"
14140 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
14141 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
14142 "\n\t\t: Manage current view parameters or prints all"
14143 "\n\t\t: current values when called without argument."
14144 "\n\t\t: -scale [s] prints or sets viewport relative scale"
14145 "\n\t\t: -eye [x y z] prints or sets eye location"
14146 "\n\t\t: -at [x y z] prints or sets center of look"
14147 "\n\t\t: -up [x y z] prints or sets direction of up vector"
14148 "\n\t\t: -proj [x y z] prints or sets direction of look"
14149 "\n\t\t: -center x y sets location of center of the screen in pixels"
14150 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
14151 "\n\t\t: or changes the size of its maximum dimension"
14152 "\n\t\t: -args prints vviewparams arguments for restoring current view",
14153 __FILE__, VViewParams, group);
14155 theCommands.Add("v2dmode",
14156 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
14157 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
14158 "\n\t\t: mode - switches On/Off rotation mode"
14159 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
14160 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
14161 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
14162 "\n\t\t: View camera position might be changed only by commands.",
14163 __FILE__, V2DMode, group);
14165 theCommands.Add("vanimation", "Alias for vanim",
14166 __FILE__, VAnimation, group);
14168 theCommands.Add("vanim",
14169 "List existing animations:"
14171 "\n\t\t: Animation playback:"
14172 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
14173 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
14174 "\n\t\t: -speed playback speed (1.0 is normal speed)"
14175 "\n\t\t: -freeLook skip camera animations"
14176 "\n\t\t: -lockLoop disable any interactions"
14178 "\n\t\t: Animation definition:"
14179 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
14180 "\n\t\t: [start TimeSec] [duration TimeSec]"
14182 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
14183 "\n\t\t: specifies nested animations."
14184 "\n\t\t: There is no syntax to explicitly add new animation,"
14185 "\n\t\t: and all non-existing animations within the name will be"
14186 "\n\t\t: implicitly created on first use (including parents)."
14188 "\n\t\t: Each animation might define the SINGLE action (see below),"
14189 "\n\t\t: like camera transition, object transformation or custom callback."
14190 "\n\t\t: Child animations can be used for defining concurrent actions."
14192 "\n\t\t: Camera animation:"
14193 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
14194 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
14195 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
14196 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
14197 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
14198 "\n\t\t: -atX camera Center positions pair"
14199 "\n\t\t: -upX camera Up directions pair"
14200 "\n\t\t: -scaleX camera Scale factors pair"
14201 "\n\t\t: Object animation:"
14202 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
14203 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
14204 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
14205 "\n\t\t: -locX object Location points pair (translation)"
14206 "\n\t\t: -rotX object Orientations pair (quaternions)"
14207 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
14208 "\n\t\t: Custom callback:"
14209 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
14210 "\n\t\t: %Pts overall animation presentation timestamp"
14211 "\n\t\t: %LocalPts local animation timestamp"
14212 "\n\t\t: %Normalized local animation normalized value in range 0..1"
14214 "\n\t\t: Video recording:"
14215 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
14216 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
14217 "\n\t\t: [-crf Value] [-preset Preset]"
14218 "\n\t\t: -fps video framerate"
14219 "\n\t\t: -format file format, container (matroska, etc.)"
14220 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
14221 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
14222 "\n\t\t: -crf constant rate factor (specific to codec)"
14223 "\n\t\t: -preset codec parameters preset (specific to codec)"
14224 __FILE__, VAnimation, group);
14226 theCommands.Add("vchangeselected",
14227 "vchangeselected shape"
14228 "- adds to shape to selection or remove one from it",
14229 __FILE__, VChangeSelected, group);
14230 theCommands.Add ("vnbselected",
14232 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
14233 theCommands.Add ("vcamera",
14234 "vcamera [PrsName] [-ortho] [-projtype]"
14236 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
14237 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
14238 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
14239 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
14240 "\n\t\t: Manages camera parameters."
14241 "\n\t\t: Displays frustum when presntation name PrsName is specified."
14242 "\n\t\t: Prints current value when option called without argument."
14243 "\n\t\t: Orthographic camera:"
14244 "\n\t\t: -ortho activate orthographic projection"
14245 "\n\t\t: Perspective camera:"
14246 "\n\t\t: -persp activate perspective projection (mono)"
14247 "\n\t\t: -fovy field of view in y axis, in degrees"
14248 "\n\t\t: -distance distance of eye from camera center"
14249 "\n\t\t: Stereoscopic camera:"
14250 "\n\t\t: -stereo perspective projection (stereo)"
14251 "\n\t\t: -leftEye perspective projection (left eye)"
14252 "\n\t\t: -rightEye perspective projection (right eye)"
14253 "\n\t\t: -iod intraocular distance value"
14254 "\n\t\t: -iodType distance type, absolute or relative"
14255 "\n\t\t: -zfocus stereographic focus value"
14256 "\n\t\t: -zfocusType focus type, absolute or relative",
14257 __FILE__, VCamera, group);
14258 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
14259 "- vautozfit [on={1|0}] [scale]\n"
14260 " Prints or changes parameters of automatic z-fit mode:\n"
14261 " \"on\" - turns automatic z-fit on or off\n"
14262 " \"scale\" - specifies factor to scale computed z range.\n",
14263 __FILE__, VAutoZFit, group);
14264 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
14265 " vzrange - without parameters shows current values\n"
14266 " vzrange [znear] [zfar] - applies provided values to view",
14267 __FILE__,VZRange, group);
14268 theCommands.Add ("vpurgedisplay",
14270 "- removes structures which don't belong to objects displayed in neutral point",
14271 __FILE__, VPurgeDisplay, group);
14272 theCommands.Add("vsetviewsize",
14273 "vsetviewsize size",
14274 __FILE__,VSetViewSize,group);
14275 theCommands.Add("vmoveview",
14276 "vmoveview Dx Dy Dz [Start = 1|0]",
14277 __FILE__,VMoveView,group);
14278 theCommands.Add("vtranslateview",
14279 "vtranslateview Dx Dy Dz [Start = 1|0)]",
14280 __FILE__,VTranslateView,group);
14281 theCommands.Add("vturnview",
14282 "vturnview Ax Ay Az [Start = 1|0]",
14283 __FILE__,VTurnView,group);
14284 theCommands.Add("vtextureenv",
14285 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
14286 "or user-defined file and optionally applying texture mapping parameters\n"
14288 " vtextureenv off - disables environment mapping\n"
14289 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
14290 " std_texture = (0..7)\n"
14291 " rep = {clamp|repeat}\n"
14292 " mod = {decal|modulate}\n"
14293 " flt = {nearest|bilinear|trilinear}\n"
14294 " ss, st - scale factors for s and t texture coordinates\n"
14295 " ts, tt - translation for s and t texture coordinates\n"
14296 " rot - texture rotation angle in degrees",
14297 __FILE__, VTextureEnv, group);
14298 theCommands.Add("vhlr",
14299 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
14300 "\n\t\t: Hidden Line Removal algorithm."
14301 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
14302 "\n\t\t: -algoType type of HLR algorithm.\n",
14303 __FILE__,VHLR,group);
14304 theCommands.Add("vhlrtype",
14305 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
14306 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
14307 "\n\t\t: 'algo' - exact HLR algorithm is applied"
14308 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
14309 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
14310 __FILE__,VHLRType,group);
14311 theCommands.Add("vclipplane",
14312 "vclipplane planeName [{0|1}]"
14313 "\n\t\t: [-equation1 A B C D]"
14314 "\n\t\t: [-equation2 A B C D]"
14315 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
14316 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
14317 "\n\t\t: [-maxPlanes]"
14318 "\n\t\t: [-capping {0|1}]"
14319 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
14320 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
14321 "\n\t\t: [-texRotate Angle]"
14322 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
14323 "\n\t\t: [-useObjShader {0|1}]"
14324 "\n\t\t: Clipping planes management:"
14325 "\n\t\t: -maxPlanes print plane limit for view"
14326 "\n\t\t: -delete delete plane with given name"
14327 "\n\t\t: {off|on|0|1} turn clipping on/off"
14328 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
14329 "\n\t\t: applied to active View when list is omitted"
14330 "\n\t\t: -equation A B C D change plane equation"
14331 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
14332 "\n\t\t: Capping options:"
14333 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
14334 "\n\t\t: -color R G B set capping color"
14335 "\n\t\t: -transparency Value set capping transparency 0..1"
14336 "\n\t\t: -texName Texture set capping texture"
14337 "\n\t\t: -texScale SX SY set capping tex scale"
14338 "\n\t\t: -texOrigin TX TY set capping tex origin"
14339 "\n\t\t: -texRotate Angle set capping tex rotation"
14340 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
14341 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
14342 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
14343 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
14344 __FILE__, VClipPlane, group);
14345 theCommands.Add("vdefaults",
14346 "vdefaults [-absDefl value]"
14347 "\n\t\t: [-devCoeff value]"
14348 "\n\t\t: [-angDefl value]"
14349 "\n\t\t: [-autoTriang {off/on | 0/1}]"
14350 , __FILE__, VDefaults, group);
14351 theCommands.Add("vlight",
14352 "tool to manage light sources, without arguments shows list of lights."
14353 "\n Main commands: "
14354 "\n '-clear' to clear lights"
14355 "\n '-{def}aults' to load deafault lights"
14356 "\n '-add' <type> to add any light source"
14357 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
14358 "\n 'change' <lightId> to edit light source with specified lightId"
14359 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
14361 "\n -{pos}ition X Y Z"
14362 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
14363 "\n -color colorName"
14364 "\n -{head}light 0|1"
14365 "\n -{sm}oothness value"
14366 "\n -{int}ensity value"
14367 "\n -{constAtten}uation value"
14368 "\n -{linearAtten}uation value"
14369 "\n -angle angleDeg"
14370 "\n -{spotexp}onent value"
14371 "\n -local|-global"
14372 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
14373 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
14374 __FILE__, VLight, group);
14375 theCommands.Add("vpbrenv",
14376 "vpbrenv -clear|-generate"
14377 "\n\t\t: Clears or generates PBR environment map of active view."
14378 "\n\t\t: -clear clears PBR environment (fills by white color)"
14379 "\n\t\t: -generate generates PBR environment from current background cubemap",
14380 __FILE__, VPBREnvironment, group);
14381 theCommands.Add("vraytrace",
14383 "\n\t\t: Turns on/off ray-tracing renderer."
14384 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
14385 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
14386 __FILE__, VRenderParams, group);
14387 theCommands.Add("vrenderparams",
14388 "\n Manages rendering parameters: "
14389 "\n '-raster' Disables GPU ray-tracing"
14390 "\n '-msaa 0..4' Specifies number of samples for MSAA"
14391 "\n '-lineFeather > 0' Sets line feather factor"
14392 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
14393 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
14394 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
14395 "\n '-rendScale value Rendering resolution scale factor"
14396 "\n '-rayTrace' Enables GPU ray-tracing"
14397 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
14398 "\n '-shadows on|off' Enables/disables shadows rendering"
14399 "\n '-reflections on|off' Enables/disables specular reflections"
14400 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
14401 "\n '-gleam on|off' Enables/disables transparency shadow effects"
14402 "\n '-gi on|off' Enables/disables global illumination effects"
14403 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
14404 "\n '-env on|off' Enables/disables environment map background"
14405 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
14406 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
14407 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
14408 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
14409 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
14410 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
14411 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
14412 "\n '-shadingModel model' Controls shading model from enumeration"
14413 "\n unlit, flat, gouraud, phong"
14414 "\n '-pbrEnvPow2size > 0' Controls size of IBL maps (real size can be calculates as 2^pbrenvpow2size)"
14415 "\n '-pbrEnvSMLN > 1' Controls number of mipmap levels used in specular IBL map"
14416 "\n '-pbrEnvBDSN > 0' Controls number of samples in Monte-Carlo integration during diffuse IBL map's sherical harmonics calculation"
14417 "\n '-pbrEnvBSSN > 0' Controls maximum number of samples per mipmap level in Monte-Carlo integration during specular IBL maps generation"
14418 "\n '-pbrEnvBP [0, 1]' Controls strength of samples number reducing during specular IBL maps generation (1 disables reducing)"
14419 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
14420 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
14421 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
14422 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
14423 "\n '-whitepoint value' White point value for filmic tone mapping"
14424 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
14425 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points"
14426 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
14427 "\n Show/hide performance counters (flags can be combined)"
14428 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
14429 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
14430 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
14431 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
14432 "\n set state to check structures culled previously."
14433 "\n Unlike vcaps, these parameters dramatically change visual properties."
14434 "\n Command is intended to control presentation quality depending on"
14435 "\n hardware capabilities and performance.",
14436 __FILE__, VRenderParams, group);
14437 theCommands.Add("vstatprofiler",
14438 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
14439 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
14440 "\n |triagles|points|geomMem|textureMem|frameMem"
14441 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
14442 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
14444 "\n\t\t: Prints rendering statistics."
14445 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
14446 "\n\t\t: else - print all performance counters set previously."
14447 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
14448 __FILE__, VStatProfiler, group);
14449 theCommands.Add ("vplace",
14451 "\n\t\t: Places the point (in pixels) at the center of the window",
14452 __FILE__, VPlace, group);
14453 theCommands.Add("vxrotate",
14455 __FILE__,VXRotate,group);
14457 theCommands.Add("vmanipulator",
14458 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
14459 "\n tool to create and manage AIS manipulators."
14461 "\n '-attach AISObject' attach manipulator to AISObject"
14462 "\n '-adjustPosition {0|1}' adjust position when attaching"
14463 "\n '-adjustSize {0|1}' adjust size when attaching"
14464 "\n '-enableModes {0|1}' enable modes when attaching"
14465 "\n '-view {active | [name of view]}' display manipulator only in defined view,"
14466 "\n by default it is displayed in all views of the current viewer"
14467 "\n '-detach' detach manipulator"
14468 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
14469 "\n '-transform mouse_x mouse_y' - invoke transformation"
14470 "\n '-stopTransform [abort]' - invoke stop of transformation"
14471 "\n '-move x y z' - move attached object"
14472 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
14473 "\n '-scale factor' - scale attached object"
14474 "\n '-autoActivate {0|1}' - set activation on detection"
14475 "\n '-followTranslation {0|1}' - set following translation transform"
14476 "\n '-followRotation {0|1}' - set following rotation transform"
14477 "\n '-followDragging {0|1}' - set following dragging transform"
14478 "\n '-gap value' - set gap between sub-parts"
14479 "\n '-part axis mode {0|1}' - set visual part"
14480 "\n '-parts axis mode {0|1}' - set visual part"
14481 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
14482 "\n '-size value' - set size of manipulator"
14483 "\n '-zoomable {0|1}' - set zoom persistence",
14484 __FILE__, VManipulator, group);
14486 theCommands.Add("vselprops",
14487 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
14488 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
14489 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
14490 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
14491 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
14492 "\n -pickStrategy {first|topmost} : defines picking strategy"
14493 "\n 'first' to pick first acceptable (default)"
14494 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
14495 "\n -pixTol value : sets up pixel tolerance"
14496 "\n -dispMode dispMode : sets display mode for highlighting"
14497 "\n -layer ZLayer : sets ZLayer for highlighting"
14498 "\n -color {name|r g b} : sets highlight color"
14499 "\n -transp value : sets transparency coefficient for highlight"
14500 "\n -material material : sets highlight material"
14501 "\n -print : prints current state of all mentioned parameters",
14502 __FILE__, VSelectionProperties, group);
14503 theCommands.Add ("vhighlightselected",
14504 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
14505 __FILE__, VSelectionProperties, group);
14507 theCommands.Add ("vseldump",
14508 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
14509 "\n\t\t: Generate an image based on detection results:"
14510 "\n\t\t: depth normalized depth values"
14511 "\n\t\t: unnormDepth unnormalized depth values"
14512 "\n\t\t: object color of detected object"
14513 "\n\t\t: owner color of detected owner"
14514 "\n\t\t: selMode color of selection mode"
14515 "\n\t\t: entity color of etected entity",
14516 __FILE__, VDumpSelectionImage, group);
14518 theCommands.Add ("vviewcube",
14520 "\n\t\t: Displays interactive view manipualtion object."
14521 "\n\t\t: Options: "
14522 "\n\t\t: -reset reset geomertical and visual attributes'"
14523 "\n\t\t: -size Size adapted size of View Cube"
14524 "\n\t\t: -boxSize Size box size"
14525 "\n\t\t: -axes {0|1 } show/hide axes (trihedron)"
14526 "\n\t\t: -edges {0|1} show/hide edges of View Cube"
14527 "\n\t\t: -vertices {0|1} show/hide vertices of View Cube"
14528 "\n\t\t: -Yup {0|1} -Zup {0|1} set Y-up or Z-up view orientation"
14529 "\n\t\t: -color Color color of View Cube"
14530 "\n\t\t: -boxColor Color box color"
14531 "\n\t\t: -boxSideColor Color box sides color"
14532 "\n\t\t: -boxEdgeColor Color box edges color"
14533 "\n\t\t: -boxCornerColor Color box corner color"
14534 "\n\t\t: -textColor Color color of side text of view cube"
14535 "\n\t\t: -innerColor Color inner box color"
14536 "\n\t\t: -transparency Value transparency of object within [0, 1] range"
14537 "\n\t\t: -boxTransparency Value transparency of box within [0, 1] range"
14538 "\n\t\t: -font Name font name"
14539 "\n\t\t: -fontHeight Value font height"
14540 "\n\t\t: -boxFacetExtension Value box facet extension"
14541 "\n\t\t: -boxEdgeGap Value gap between box edges and box sides"
14542 "\n\t\t: -boxEdgeMinSize Value minimal box edge size"
14543 "\n\t\t: -boxCornerMinSize Value minimal box corner size"
14544 "\n\t\t: -axesPadding Value padding between box and arrows"
14545 "\n\t\t: -roundRadius Value relative radius of corners of sides within [0.0, 0.5] range"
14546 "\n\t\t: -fixedanimation {0|1} uninterruptible animation loop"
14547 "\n\t\t: -duration Seconds animation duration in seconds",
14548 __FILE__, VViewCube, group);