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(WNT_WClass)& ViewerTest::WClass()
1402 static Handle(WNT_WClass) 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(), WClass(),
1943 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
1945 aPxWidth, aPxHeight,
1946 Quantity_NOC_BLACK);
1947 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1948 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
1950 aPxWidth, aPxHeight);
1951 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
1953 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
1956 aPxWidth, aPxHeight);
1958 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
1961 Handle(V3d_View) aView;
1962 if (!theViewToClone.IsNull())
1964 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
1968 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
1971 aView->SetWindow (VT_GetWindow());
1972 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
1974 ViewerTest::CurrentView(aView);
1975 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
1977 // Setup for X11 or NT
1980 // Set parameters for V3d_View and V3d_Viewer
1981 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
1982 aV3dView->SetComputedMode(Standard_False);
1984 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
1987 a3DViewer->SetDefaultLights();
1988 a3DViewer->SetLightOn();
1991 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1994 ::Display* aDispX = GetDisplayConnection()->GetDisplay();
1995 Tcl_CreateFileHandler (XConnectionNumber (aDispX), TCL_READABLE, VProcessEvents, (ClientData )aDispX);
1999 VT_GetWindow()->Map();
2001 // Set the handle of created view in the event manager
2002 ViewerTest::ResetEventManager();
2004 ViewerTest::CurrentView()->Redraw();
2007 a3DViewer.Nullify();
2009 return aViewNames.GetViewName();
2012 //==============================================================================
2013 //function : RedrawAllViews
2014 //purpose : Redraw all created views
2015 //==============================================================================
2016 void ViewerTest::RedrawAllViews()
2018 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
2019 for (; aViewIt.More(); aViewIt.Next())
2021 const Handle(V3d_View)& aView = aViewIt.Key2();
2026 //==============================================================================
2028 //purpose : Create the window viewer and initialize all the global variable
2029 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
2030 //==============================================================================
2032 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2034 TCollection_AsciiString aViewName, aDisplayName;
2035 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
2036 Handle(V3d_View) aCopyFrom;
2037 TCollection_AsciiString aName, aValue;
2039 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2041 const TCollection_AsciiString anArg = theArgVec[anArgIt];
2042 TCollection_AsciiString anArgCase = anArg;
2043 anArgCase.LowerCase();
2044 if (anArgIt + 1 < theArgsNb
2045 && anArgCase == "-name")
2047 aViewName = theArgVec[++anArgIt];
2049 else if (anArgIt + 1 < theArgsNb
2050 && (anArgCase == "-left"
2051 || anArgCase == "-l"))
2053 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
2055 else if (anArgIt + 1 < theArgsNb
2056 && (anArgCase == "-top"
2057 || anArgCase == "-t"))
2059 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
2061 else if (anArgIt + 1 < theArgsNb
2062 && (anArgCase == "-width"
2063 || anArgCase == "-w"))
2065 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
2067 else if (anArgIt + 1 < theArgsNb
2068 && (anArgCase == "-height"
2069 || anArgCase == "-h"))
2071 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
2073 else if (anArgCase == "-exitonclose")
2075 ViewerTest_EventManager::ToExitOnCloseView() = true;
2076 if (anArgIt + 1 < theArgsNb
2077 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToExitOnCloseView()))
2082 else if (anArgCase == "-closeonescape"
2083 || anArgCase == "-closeonesc")
2085 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
2086 if (anArgIt + 1 < theArgsNb
2087 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
2092 else if (anArgCase == "-2d_mode"
2093 || anArgCase == "-2dmode"
2094 || anArgCase == "-2d")
2096 bool toEnable = true;
2097 if (anArgIt + 1 < theArgsNb
2098 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
2102 is2dMode = toEnable ? 1 : 0;
2104 else if (anArgIt + 1 < theArgsNb
2105 && (anArgCase == "-disp"
2106 || anArgCase == "-display"))
2108 aDisplayName = theArgVec[++anArgIt];
2110 else if (!ViewerTest::CurrentView().IsNull()
2111 && aCopyFrom.IsNull()
2112 && (anArgCase == "-copy"
2113 || anArgCase == "-clone"
2114 || anArgCase == "-cloneactive"
2115 || anArgCase == "-cloneactiveview"))
2117 aCopyFrom = ViewerTest::CurrentView();
2120 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
2123 if (aName == "name")
2127 else if (aName == "l"
2130 aPxLeft = aValue.IntegerValue();
2132 else if (aName == "t"
2135 aPxTop = aValue.IntegerValue();
2137 else if (aName == "disp"
2138 || aName == "display")
2140 aDisplayName = aValue;
2142 else if (aName == "w"
2143 || aName == "width")
2145 aPxWidth = aValue.IntegerValue();
2147 else if (aName == "h"
2148 || aName == "height")
2150 aPxHeight = aValue.IntegerValue();
2154 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
2158 else if (aViewName.IsEmpty())
2164 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
2169 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
2170 if (!aDisplayName.IsEmpty())
2172 aDisplayName.Clear();
2173 std::cout << "Warning: display parameter will be ignored.\n";
2177 ViewerTest_Names aViewNames (aViewName);
2178 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
2180 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
2181 theDi.Eval (aCommand.ToCString());
2184 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
2189 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
2190 aViewName, aDisplayName, aCopyFrom);
2193 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
2199 //! Parse HLR algo type.
2200 static Standard_Boolean parseHlrAlgoType (const char* theName,
2201 Prs3d_TypeOfHLR& theType)
2203 TCollection_AsciiString aName (theName);
2205 if (aName == "polyalgo")
2207 theType = Prs3d_TOH_PolyAlgo;
2209 else if (aName == "algo")
2211 theType = Prs3d_TOH_Algo;
2215 return Standard_False;
2217 return Standard_True;
2220 //==============================================================================
2222 //purpose : hidden lines removal algorithm
2223 //==============================================================================
2225 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2227 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2228 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2231 std::cerr << "Error: No opened viewer!\n";
2235 Standard_Boolean hasHlrOnArg = Standard_False;
2236 Standard_Boolean hasShowHiddenArg = Standard_False;
2237 Standard_Boolean isHLROn = Standard_False;
2238 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
2239 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
2240 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2241 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
2243 TCollection_AsciiString anArg (argv[anArgIter]);
2245 if (anUpdateTool.parseRedrawMode (anArg))
2249 else if (anArg == "-showhidden"
2250 && anArgIter + 1 < argc
2251 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
2254 hasShowHiddenArg = Standard_True;
2257 else if ((anArg == "-type"
2259 || anArg == "-algotype")
2260 && anArgIter + 1 < argc
2261 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
2266 else if (!hasHlrOnArg
2267 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
2269 hasHlrOnArg = Standard_True;
2273 else if (!hasShowHiddenArg
2274 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
2276 hasShowHiddenArg = Standard_True;
2281 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
2287 di << "HLR: " << aView->ComputedMode() << "\n";
2288 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
2290 switch (aCtx->DefaultDrawer()->TypeOfHLR())
2292 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
2293 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
2294 case Prs3d_TOH_Algo: di << "Algo\n"; break;
2296 anUpdateTool.Invalidate();
2300 Standard_Boolean toRecompute = Standard_False;
2301 if (aTypeOfHLR != Prs3d_TOH_NotSet
2302 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
2304 toRecompute = Standard_True;
2305 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
2307 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
2309 toRecompute = Standard_True;
2312 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
2316 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
2321 if (aView->ComputedMode() && isHLROn && toRecompute)
2323 AIS_ListOfInteractive aListOfShapes;
2324 aCtx->DisplayedObjects (aListOfShapes);
2325 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
2327 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
2329 aCtx->Redisplay (aShape, Standard_False);
2334 aView->SetComputedMode (isHLROn);
2338 //==============================================================================
2339 //function : VHLRType
2340 //purpose : change type of using HLR algorithm
2341 //==============================================================================
2343 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
2345 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2346 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2349 std::cerr << "Error: No opened viewer!\n";
2353 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
2354 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2355 AIS_ListOfInteractive aListOfShapes;
2356 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
2358 TCollection_AsciiString anArg (argv[anArgIter]);
2360 if (anUpdateTool.parseRedrawMode (anArg))
2364 else if ((anArg == "-type"
2366 || anArg == "-algotype")
2367 && anArgIter + 1 < argc
2368 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
2374 else if (aTypeOfHLR == Prs3d_TOH_NotSet
2375 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
2381 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
2382 TCollection_AsciiString aName (argv[anArgIter]);
2383 if (!aMap.IsBound2 (aName))
2385 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
2389 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
2390 if (aShape.IsNull())
2392 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
2395 aListOfShapes.Append (aShape);
2399 if (aTypeOfHLR == Prs3d_TOH_NotSet)
2401 std::cout << "Syntax error: wrong number of arguments!\n";
2405 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
2408 aCtx->DisplayedObjects (aListOfShapes);
2409 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
2412 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
2414 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
2415 if (aShape.IsNull())
2420 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
2421 && aView->ComputedMode();
2423 || aShape->TypeOfHLR() != aTypeOfHLR)
2425 aShape->SetTypeOfHLR (aTypeOfHLR);
2429 aCtx->Redisplay (aShape, Standard_False);
2435 //==============================================================================
2436 //function : FindViewIdByWindowHandle
2437 //purpose : Find theView Id in the map of views by window handle
2438 //==============================================================================
2439 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2440 TCollection_AsciiString FindViewIdByWindowHandle (Aspect_Drawable theWindowHandle)
2442 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
2443 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
2445 Aspect_Drawable aWindowHandle = anIter.Value()->Window()->NativeHandle();
2446 if (aWindowHandle == theWindowHandle)
2447 return anIter.Key1();
2449 return TCollection_AsciiString("");
2453 //! Make the view active
2454 void ActivateView (const TCollection_AsciiString& theViewName,
2455 Standard_Boolean theToUpdate = Standard_True)
2457 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
2463 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
2464 if (!anAISContext.IsNull())
2466 if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView())
2468 aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView));
2471 ViewerTest::CurrentView (aView);
2472 ViewerTest::SetAISContext (anAISContext);
2473 aView->Window()->SetTitle (TCollection_AsciiString("3D View - ") + theViewName + "(*)");
2475 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
2476 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
2477 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
2479 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
2481 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2484 ViewerTest::CurrentView()->Redraw();
2489 //==============================================================================
2490 //function : RemoveView
2492 //==============================================================================
2493 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
2494 const Standard_Boolean theToRemoveContext)
2496 if (!ViewerTest_myViews.IsBound2 (theView))
2501 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
2502 RemoveView (aViewName, theToRemoveContext);
2505 //==============================================================================
2506 //function : RemoveView
2507 //purpose : Close and remove view from display, clear maps if neccessary
2508 //==============================================================================
2509 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
2511 if (!ViewerTest_myViews.IsBound1(theViewName))
2513 std::cout << "Wrong view name\n";
2517 // Activate another view if it's active now
2518 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
2520 if (ViewerTest_myViews.Extent() > 1)
2522 TCollection_AsciiString aNewViewName;
2523 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
2524 anIter.More(); anIter.Next())
2526 if (anIter.Key1() != theViewName)
2528 aNewViewName = anIter.Key1();
2532 ActivateView (aNewViewName);
2536 VT_GetWindow().Nullify();
2537 ViewerTest::CurrentView (Handle(V3d_View)());
2538 if (isContextRemoved)
2540 Handle(AIS_InteractiveContext) anEmptyContext;
2541 ViewerTest::SetAISContext(anEmptyContext);
2547 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
2548 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
2549 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
2550 aRedrawer.Stop (aView->Window());
2552 // Remove view resources
2553 ViewerTest_myViews.UnBind1(theViewName);
2554 aView->Window()->Unmap();
2557 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2558 XFlush (GetDisplayConnection()->GetDisplay());
2561 // Keep context opened only if the closed view is last to avoid
2562 // unused empty contexts
2563 if (!aCurrentContext.IsNull())
2565 // Check if there are more difined views in the viewer
2566 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1)
2567 && aCurrentContext->CurrentViewer()->DefinedViews().IsEmpty())
2569 // Remove driver if there is no viewers that use it
2570 Standard_Boolean isRemoveDriver = Standard_True;
2571 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2572 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
2574 if (aCurrentContext != anIter.Key2() &&
2575 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
2577 isRemoveDriver = Standard_False;
2582 aCurrentContext->RemoveAll (Standard_False);
2585 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
2586 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2587 Tcl_DeleteFileHandler (XConnectionNumber (aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
2591 ViewerTest_myContexts.UnBind2(aCurrentContext);
2594 std::cout << "3D View - " << theViewName << " was deleted.\n";
2595 if (ViewerTest_EventManager::ToExitOnCloseView())
2597 Draw_Interprete ("exit");
2601 //==============================================================================
2603 //purpose : Remove the view defined by its name
2604 //==============================================================================
2606 static int VClose (Draw_Interpretor& /*theDi*/,
2607 Standard_Integer theArgsNb,
2608 const char** theArgVec)
2610 NCollection_List<TCollection_AsciiString> aViewList;
2613 TCollection_AsciiString anArg (theArgVec[1]);
2615 if (anArg.IsEqual ("ALL")
2616 || anArg.IsEqual ("*"))
2618 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
2619 anIter.More(); anIter.Next())
2621 aViewList.Append (anIter.Key1());
2623 if (aViewList.IsEmpty())
2625 std::cout << "No view to close\n";
2631 ViewerTest_Names aViewName (theArgVec[1]);
2632 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
2634 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
2637 aViewList.Append (aViewName.GetViewName());
2642 // close active view
2643 if (ViewerTest::CurrentView().IsNull())
2645 std::cerr << "No active view!\n";
2648 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
2651 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
2652 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
2653 anIter.More(); anIter.Next())
2655 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
2661 //==============================================================================
2662 //function : VActivate
2663 //purpose : Activate the view defined by its ID
2664 //==============================================================================
2666 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2670 theDi.Eval("vviewlist");
2674 TCollection_AsciiString aNameString;
2675 Standard_Boolean toUpdate = Standard_True;
2676 Standard_Boolean toActivate = Standard_True;
2677 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
2679 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2682 && anArg == "-noupdate")
2684 toUpdate = Standard_False;
2687 && aNameString.IsEmpty()
2690 ViewerTest::CurrentView()->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
2691 VT_GetWindow().Nullify();
2692 ViewerTest::CurrentView (Handle(V3d_View)());
2693 ViewerTest::ResetEventManager();
2694 theDi << theArgVec[0] << ": all views are inactive\n";
2695 toActivate = Standard_False;
2698 && aNameString.IsEmpty())
2700 aNameString = theArgVec[anArgIter];
2704 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
2713 else if (aNameString.IsEmpty())
2715 std::cout << "Syntax error: wrong number of arguments\n";
2719 // Check if this view exists in the viewer with the driver
2720 ViewerTest_Names aViewNames (aNameString);
2721 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
2723 theDi << "Syntax error: wrong view name '" << aNameString << "'\n";
2727 // Check if it is active already
2728 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
2730 theDi << theArgVec[0] << ": the view is active already\n";
2734 ActivateView (aViewNames.GetViewName(), toUpdate);
2738 //==============================================================================
2739 //function : VViewList
2740 //purpose : Print current list of views per viewer and graphic driver ID
2741 // shared between viewers
2742 //==============================================================================
2744 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2748 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
2749 << "Usage: " << theArgVec[0] << " name";
2752 if (ViewerTest_myContexts.Size() < 1)
2755 Standard_Boolean isTreeView =
2756 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
2760 theDi << theArgVec[0] <<":\n";
2763 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
2764 aDriverIter.More(); aDriverIter.Next())
2767 theDi << aDriverIter.Key1() << ":\n";
2769 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2770 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
2772 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
2776 TCollection_AsciiString aContextName(aContextIter.Key1());
2777 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
2780 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
2781 aViewIter.More(); aViewIter.Next())
2783 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
2785 TCollection_AsciiString aViewName(aViewIter.Key1());
2788 if (aViewIter.Value() == ViewerTest::CurrentView())
2789 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
2791 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
2795 theDi << aViewName << " ";
2805 //==============================================================================
2806 //function : GetMousePosition
2808 //==============================================================================
2809 void ViewerTest::GetMousePosition (Standard_Integer& theX,
2810 Standard_Integer& theY)
2812 if (Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager())
2814 theX = aViewCtrl->LastMousePosition().x();
2815 theY = aViewCtrl->LastMousePosition().y();
2819 //==============================================================================
2820 //function : VViewProj
2821 //purpose : Switch view projection
2822 //==============================================================================
2823 static int VViewProj (Draw_Interpretor& ,
2824 Standard_Integer theNbArgs,
2825 const char** theArgVec)
2827 static Standard_Boolean isYup = Standard_False;
2828 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2831 std::cout << "Error: no active view\n";
2835 TCollection_AsciiString aCmdName (theArgVec[0]);
2836 Standard_Boolean isGeneralCmd = Standard_False;
2837 if (aCmdName == "vfront")
2839 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup);
2841 else if (aCmdName == "vback")
2843 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup);
2845 else if (aCmdName == "vtop")
2847 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup);
2849 else if (aCmdName == "vbottom")
2851 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup);
2853 else if (aCmdName == "vleft")
2855 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup);
2857 else if (aCmdName == "vright")
2859 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup);
2861 else if (aCmdName == "vaxo")
2863 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup);
2867 isGeneralCmd = Standard_True;
2868 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
2870 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2871 anArgCase.LowerCase();
2872 if (anArgCase == "-zup")
2874 isYup = Standard_False;
2876 else if (anArgCase == "-yup")
2878 isYup = Standard_True;
2880 else if (anArgCase == "-front"
2881 || anArgCase == "front"
2882 || anArgCase == "-f"
2883 || anArgCase == "f")
2885 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup);
2887 else if (anArgCase == "-back"
2888 || anArgCase == "back"
2889 || anArgCase == "-b"
2890 || anArgCase == "b")
2892 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup);
2894 else if (anArgCase == "-top"
2895 || anArgCase == "top"
2896 || anArgCase == "-t"
2897 || anArgCase == "t")
2899 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup);
2901 else if (anArgCase == "-bottom"
2902 || anArgCase == "bottom"
2903 || anArgCase == "-bot"
2904 || anArgCase == "bot"
2905 || anArgCase == "-b"
2906 || anArgCase == "b")
2908 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup);
2910 else if (anArgCase == "-left"
2911 || anArgCase == "left"
2912 || anArgCase == "-l"
2913 || anArgCase == "l")
2915 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup);
2917 else if (anArgCase == "-right"
2918 || anArgCase == "right"
2919 || anArgCase == "-r"
2920 || anArgCase == "r")
2922 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup);
2924 else if (anArgCase == "-axoleft"
2925 || anArgCase == "-leftaxo"
2926 || anArgCase == "axoleft"
2927 || anArgCase == "leftaxo")
2929 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoLeft : V3d_TypeOfOrientation_Zup_AxoLeft, isYup);
2931 else if (anArgCase == "-axo"
2932 || anArgCase == "axo"
2933 || anArgCase == "-a"
2935 || anArgCase == "-axoright"
2936 || anArgCase == "-rightaxo"
2937 || anArgCase == "axoright"
2938 || anArgCase == "rightaxo")
2940 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup);
2942 else if (anArgCase == "+x")
2944 aView->SetProj (V3d_Xpos, isYup);
2946 else if (anArgCase == "-x")
2948 aView->SetProj (V3d_Xneg, isYup);
2950 else if (anArgCase == "+y")
2952 aView->SetProj (V3d_Ypos, isYup);
2954 else if (anArgCase == "-y")
2956 aView->SetProj (V3d_Yneg, isYup);
2958 else if (anArgCase == "+z")
2960 aView->SetProj (V3d_Zpos, isYup);
2962 else if (anArgCase == "-z")
2964 aView->SetProj (V3d_Zneg, isYup);
2966 else if (anArgCase == "+x+y+z")
2968 aView->SetProj (V3d_XposYposZpos, isYup);
2970 else if (anArgCase == "+x+y-z")
2972 aView->SetProj (V3d_XposYposZneg, isYup);
2974 else if (anArgCase == "+x-y+z")
2976 aView->SetProj (V3d_XposYnegZpos, isYup);
2978 else if (anArgCase == "+x-y-z")
2980 aView->SetProj (V3d_XposYnegZneg, isYup);
2982 else if (anArgCase == "-x+y+z")
2984 aView->SetProj (V3d_XnegYposZpos, isYup);
2986 else if (anArgCase == "-x+y-z")
2988 aView->SetProj (V3d_XnegYposZneg, isYup);
2990 else if (anArgCase == "-x-y+z")
2992 aView->SetProj (V3d_XnegYnegZpos, isYup);
2994 else if (anArgCase == "-x-y-z")
2996 aView->SetProj (V3d_XnegYnegZneg, isYup);
2998 else if (anArgCase == "+x+y")
3000 aView->SetProj (V3d_XposYpos, isYup);
3002 else if (anArgCase == "+x-y")
3004 aView->SetProj (V3d_XposYneg, isYup);
3006 else if (anArgCase == "-x+y")
3008 aView->SetProj (V3d_XnegYpos, isYup);
3010 else if (anArgCase == "-x-y")
3012 aView->SetProj (V3d_XnegYneg, isYup);
3014 else if (anArgCase == "+x+z")
3016 aView->SetProj (V3d_XposZpos, isYup);
3018 else if (anArgCase == "+x-z")
3020 aView->SetProj (V3d_XposZneg, isYup);
3022 else if (anArgCase == "-x+z")
3024 aView->SetProj (V3d_XnegZpos, isYup);
3026 else if (anArgCase == "-x-z")
3028 aView->SetProj (V3d_XnegZneg, isYup);
3030 else if (anArgCase == "+y+z")
3032 aView->SetProj (V3d_YposZpos, isYup);
3034 else if (anArgCase == "+y-z")
3036 aView->SetProj (V3d_YposZneg, isYup);
3038 else if (anArgCase == "-y+z")
3040 aView->SetProj (V3d_YnegZpos, isYup);
3042 else if (anArgCase == "-y-z")
3044 aView->SetProj (V3d_YnegZneg, isYup);
3046 else if (anArgIter + 1 < theNbArgs
3047 && anArgCase == "-frame"
3048 && TCollection_AsciiString (theArgVec[anArgIter + 1]).Length() == 4)
3050 TCollection_AsciiString aFrameDef (theArgVec[++anArgIter]);
3051 aFrameDef.LowerCase();
3052 gp_Dir aRight, anUp;
3053 if (aFrameDef.Value (2) == aFrameDef.Value (4))
3055 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3059 if (aFrameDef.Value (2) == 'x')
3061 aRight = aFrameDef.Value (1) == '+' ? gp::DX() : -gp::DX();
3063 else if (aFrameDef.Value (2) == 'y')
3065 aRight = aFrameDef.Value (1) == '+' ? gp::DY() : -gp::DY();
3067 else if (aFrameDef.Value (2) == 'z')
3069 aRight = aFrameDef.Value (1) == '+' ? gp::DZ() : -gp::DZ();
3073 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3077 if (aFrameDef.Value (4) == 'x')
3079 anUp = aFrameDef.Value (3) == '+' ? gp::DX() : -gp::DX();
3081 else if (aFrameDef.Value (4) == 'y')
3083 anUp = aFrameDef.Value (3) == '+' ? gp::DY() : -gp::DY();
3085 else if (aFrameDef.Value (4) == 'z')
3087 anUp = aFrameDef.Value (3) == '+' ? gp::DZ() : -gp::DZ();
3091 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3095 const Handle(Graphic3d_Camera)& aCamera = aView->Camera();
3096 const gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin());
3097 const gp_Dir aDir = anUp.Crossed (aRight);
3098 aCamera->SetCenter (gp_Pnt (0, 0, 0));
3099 aCamera->SetDirection (aDir);
3100 aCamera->SetUp (anUp);
3101 aCamera->OrthogonalizeUp();
3103 aView->Panning (anOriginVCS.X(), anOriginVCS.Y());
3108 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3117 std::cout << "Syntax error: wrong number of arguments\n";
3123 //==============================================================================
3125 //purpose : Dsiplay help on viewer Keyboead and mouse commands
3126 //Draw arg : No args
3127 //==============================================================================
3129 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
3131 di << "=========================\n";
3132 di << "F : FitAll\n";
3133 di << "T : TopView\n";
3134 di << "B : BottomView\n";
3135 di << "R : RightView\n";
3136 di << "L : LeftView\n";
3137 di << "A : AxonometricView\n";
3138 di << "D : ResetView\n";
3140 di << "=========================\n";
3141 di << "S : Shading\n";
3142 di << "W : Wireframe\n";
3143 di << "H : HiddenLineRemoval\n";
3144 di << "U : Unset display mode\n";
3145 di << "Delete : Remove selection from viewer\n";
3147 di << "=========================\n";
3148 di << "Selection mode \n";
3149 di << "0 : Shape\n";
3150 di << "1 : Vertex\n";
3154 di << "5 : Shell\n";
3155 di << "6 : Solid\n";
3156 di << "7 : Compound\n";
3158 di << "=========================\n";
3159 di << "< : Hilight next detected\n";
3160 di << "> : Hilight previous detected\n";
3167 static LRESULT WINAPI AdvViewerWindowProc (HWND theWinHandle,
3172 if (ViewerTest_myViews.IsEmpty())
3174 return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam);
3181 // Delete view from map of views
3182 ViewerTest::RemoveView (FindViewIdByWindowHandle (theWinHandle));
3187 if (LOWORD(wParam) == WA_CLICKACTIVE
3188 || LOWORD(wParam) == WA_ACTIVE
3189 || ViewerTest::CurrentView().IsNull())
3191 // Activate inactive window
3192 if (VT_GetWindow().IsNull()
3193 || (HWND )VT_GetWindow()->HWindow() != theWinHandle)
3195 ActivateView (FindViewIdByWindowHandle (theWinHandle));
3202 return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam);
3208 static LRESULT WINAPI ViewerWindowProc (HWND theWinHandle,
3213 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3216 return DefWindowProcW (theWinHandle, theMsg, wParam, lParam);
3224 BeginPaint(theWinHandle, &aPaint);
3225 EndPaint (theWinHandle, &aPaint);
3226 ViewerTest::CurrentEventManager()->ProcessExpose();
3231 ViewerTest::CurrentEventManager()->ProcessConfigure();
3238 switch (aView->RenderingParams().StereoMode)
3240 case Graphic3d_StereoMode_RowInterlaced:
3241 case Graphic3d_StereoMode_ColumnInterlaced:
3242 case Graphic3d_StereoMode_ChessBoard:
3244 // track window moves to reverse stereo pair
3245 aView->MustBeResized();
3257 const Aspect_VKey aVKey = WNT_Window::VirtualKeyFromNative ((Standard_Integer )wParam);
3258 if (aVKey != Aspect_VKey_UNKNOWN)
3260 const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime();
3261 if (theMsg == WM_KEYDOWN)
3263 ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp);
3267 ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp);
3269 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3276 case WM_LBUTTONDOWN:
3277 case WM_MBUTTONDOWN:
3278 case WM_RBUTTONDOWN:
3280 const Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam));
3281 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam);
3282 Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE;
3286 case WM_LBUTTONDOWN:
3287 aButton = Aspect_VKeyMouse_LeftButton;
3290 case WM_MBUTTONDOWN:
3291 aButton = Aspect_VKeyMouse_MiddleButton;
3294 case WM_RBUTTONDOWN:
3295 aButton = Aspect_VKeyMouse_RightButton;
3298 if (theMsg == WM_LBUTTONDOWN
3299 || theMsg == WM_MBUTTONDOWN
3300 || theMsg == WM_RBUTTONDOWN)
3302 if (aButton == Aspect_VKeyMouse_LeftButton)
3304 TheIsAnimating = Standard_False;
3307 SetFocus (theWinHandle);
3308 SetCapture(theWinHandle);
3309 ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false);
3314 ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false);
3316 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3321 const int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
3322 const Standard_Real aDeltaF = Standard_Real(aDelta) / Standard_Real(WHEEL_DELTA);
3323 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam);
3324 Graphic3d_Vec2i aPos (int(short(LOWORD(lParam))), int(short(HIWORD(lParam))));
3325 POINT aCursorPnt = { aPos.x(), aPos.y() };
3326 if (ScreenToClient (theWinHandle, &aCursorPnt))
3328 aPos.SetValues (aCursorPnt.x, aCursorPnt.y);
3331 ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags));
3332 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3337 Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam));
3338 Aspect_VKeyMouse aButtons = WNT_Window::MouseButtonsFromEvent (wParam);
3339 Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent(wParam);
3341 // don't make a slide-show from input events - fetch the actual mouse cursor position
3343 aCursor.cbSize = sizeof(aCursor);
3344 if (::GetCursorInfo (&aCursor) != FALSE)
3346 POINT aCursorPnt = { aCursor.ptScreenPos.x, aCursor.ptScreenPos.y };
3347 if (ScreenToClient (theWinHandle, &aCursorPnt))
3349 // as we override mouse position, we need overriding also mouse state
3350 aPos.SetValues (aCursorPnt.x, aCursorPnt.y);
3351 aButtons = WNT_Window::MouseButtonsAsync();
3352 aFlags = WNT_Window::MouseKeyFlagsAsync();
3356 if (VT_GetWindow().IsNull()
3357 || (HWND )VT_GetWindow()->HWindow() != theWinHandle)
3359 // mouse move events come also for inactive windows
3363 ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
3364 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
3369 return DefWindowProcW (theWinHandle, theMsg, wParam, lParam);
3375 //==============================================================================
3376 //function : ViewerMainLoop
3377 //purpose : Get a Event on the view and dispatch it
3378 //==============================================================================
3380 int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec)
3382 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
3383 if (aViewCtrl.IsNull()
3389 aViewCtrl->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]);
3391 std::cout << "Start picking\n";
3395 while (aViewCtrl->ToPickPoint())
3397 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
3398 if (GetMessageW (&aMsg, NULL, 0, 0))
3400 TranslateMessage (&aMsg);
3401 DispatchMessageW (&aMsg);
3405 std::cout << "Picking done\n";
3409 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
3411 int min( int a, int b )
3419 int max( int a, int b )
3427 int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec)
3429 static XEvent aReport;
3430 const Standard_Boolean toPick = theNbArgs > 0;
3433 if (ViewerTest::CurrentEventManager().IsNull())
3437 ViewerTest::CurrentEventManager()->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]);
3440 Display* aDisplay = GetDisplayConnection()->GetDisplay();
3441 XNextEvent (aDisplay, &aReport);
3443 // Handle event for the chosen display connection
3444 switch (aReport.type)
3448 if ((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
3451 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
3452 return toPick ? 0 : 1;
3458 // Activate inactive view
3459 Window aWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3460 if (aWindow != aReport.xfocus.window)
3462 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
3468 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3469 if (anXWindow == aReport.xexpose.window)
3471 ViewerTest::CurrentEventManager()->ProcessExpose();
3474 // remove all the ExposureMask and process them at once
3475 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3477 if (!XCheckWindowEvent (aDisplay, anXWindow, ExposureMask, &aReport))
3485 case ConfigureNotify:
3487 // remove all the StructureNotifyMask and process them at once
3488 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3489 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3491 if (!XCheckWindowEvent (aDisplay, anXWindow, StructureNotifyMask, &aReport))
3497 if (anXWindow == aReport.xconfigure.window)
3499 ViewerTest::CurrentEventManager()->ProcessConfigure();
3506 XKeyEvent* aKeyEvent = (XKeyEvent* )&aReport;
3507 const KeySym aKeySym = XLookupKeysym (aKeyEvent, 0);
3508 const Aspect_VKey aVKey = Xw_Window::VirtualKeyFromNative (aKeySym);
3509 if (aVKey != Aspect_VKey_UNKNOWN)
3511 const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime();
3512 if (aReport.type == KeyPress)
3514 ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp);
3518 ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp);
3520 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3527 const Graphic3d_Vec2i aPos (aReport.xbutton.x, aReport.xbutton.y);
3528 Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
3529 Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE;
3530 if (aReport.xbutton.button == Button1)
3532 aButton = Aspect_VKeyMouse_LeftButton;
3534 if (aReport.xbutton.button == Button2)
3536 aButton = Aspect_VKeyMouse_MiddleButton;
3538 if (aReport.xbutton.button == Button3)
3540 aButton = Aspect_VKeyMouse_RightButton;
3543 if (aReport.xbutton.state & ControlMask)
3545 aFlags |= Aspect_VKeyFlags_CTRL;
3547 if (aReport.xbutton.state & ShiftMask)
3549 aFlags |= Aspect_VKeyFlags_SHIFT;
3551 if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt))
3553 aFlags |= Aspect_VKeyFlags_ALT;
3556 if (aReport.xbutton.button == Button4
3557 || aReport.xbutton.button == Button5)
3559 if (aReport.type != ButtonPress)
3564 const double aDeltaF = (aReport.xbutton.button == Button4 ? 1.0 : -1.0);
3565 ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags));
3567 else if (aReport.type == ButtonPress)
3569 if (aButton == Aspect_VKeyMouse_LeftButton)
3571 TheIsAnimating = Standard_False;
3573 ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false);
3577 ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false);
3579 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3584 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3585 if (anXWindow != aReport.xmotion.window)
3590 // remove all the ButtonMotionMask and process them at once
3591 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3593 if (!XCheckWindowEvent (aDisplay, anXWindow, ButtonMotionMask | PointerMotionMask, &aReport))
3599 Graphic3d_Vec2i aPos (aReport.xmotion.x, aReport.xmotion.y);
3600 Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
3601 Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
3602 if ((aReport.xmotion.state & Button1Mask) != 0)
3604 aButtons |= Aspect_VKeyMouse_LeftButton;
3606 else if ((aReport.xmotion.state & Button2Mask) != 0)
3608 aButtons |= Aspect_VKeyMouse_MiddleButton;
3610 else if ((aReport.xmotion.state & Button3Mask) != 0)
3612 aButtons |= Aspect_VKeyMouse_RightButton;
3615 if (aReport.xmotion.state & ControlMask)
3617 aFlags |= Aspect_VKeyFlags_CTRL;
3619 if (aReport.xmotion.state & ShiftMask)
3621 aFlags |= Aspect_VKeyFlags_SHIFT;
3623 if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt))
3625 aFlags |= Aspect_VKeyFlags_ALT;
3628 ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
3629 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3633 return (!toPick || ViewerTest::CurrentEventManager()->ToPickPoint()) ? 1 : 0;
3636 //==============================================================================
3637 //function : VProcessEvents
3638 //purpose : manage the event in the Viewer window (see Tcl_CreateFileHandler())
3639 //==============================================================================
3640 static void VProcessEvents (ClientData theDispX, int)
3642 Display* aDispX = (Display* )theDispX;
3643 Handle(Aspect_DisplayConnection) aDispConn;
3644 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
3645 aDriverIter (ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
3647 const Handle(Aspect_DisplayConnection)& aDispConnTmp = aDriverIter.Key2()->GetDisplayConnection();
3648 if (aDispConnTmp->GetDisplay() == aDispX)
3650 aDispConn = aDispConnTmp;
3654 if (aDispConn.IsNull())
3656 std::cerr << "Error: ViewerTest is unable processing messages for unknown X Display\n";
3660 // process new events in queue
3661 SetDisplayConnection (aDispConn);
3663 for (int aNbEventsMax = XPending (aDispX), anEventIter (0);;)
3665 const int anEventResult = ViewerMainLoop (0, NULL);
3666 if (anEventResult == 0)
3671 aNbRemain = XPending (aDispX);
3672 if (++anEventIter >= aNbEventsMax
3679 // Listening X events through Tcl_CreateFileHandler() callback is fragile,
3680 // it is possible that new events will arrive to queue before the end of this callback
3681 // so that either this callback should go into an infinite loop (blocking processing of other events)
3682 // or to keep unprocessed events till the next queue update (which can arrive not soon).
3683 // Sending a dummy event in this case is a simple workaround (still, it is possible that new event will be queued in-between).
3687 memset (&aDummyEvent, 0, sizeof(aDummyEvent));
3688 aDummyEvent.type = ClientMessage;
3689 aDummyEvent.xclient.format = 32;
3690 XSendEvent (aDispX, InputFocus, False, 0, &aDummyEvent);
3694 if (const Handle(AIS_InteractiveContext)& anActiveCtx = ViewerTest::GetAISContext())
3696 SetDisplayConnection (anActiveCtx->CurrentViewer()->Driver()->GetDisplayConnection());
3701 //==============================================================================
3702 //function : OSWindowSetup
3703 //purpose : Setup for the X11 window to be able to cath the event
3704 //==============================================================================
3707 static void OSWindowSetup()
3709 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
3712 Window window = VT_GetWindow()->XWindow();
3713 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
3714 Display *aDisplay = GetDisplayConnection()->GetDisplay();
3715 XSynchronize(aDisplay, 1);
3717 // X11 : For keyboard on SUN
3719 wmhints.flags = InputHint;
3722 XSetWMHints( aDisplay, window, &wmhints);
3724 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | KeyReleaseMask |
3725 ButtonPressMask | ButtonReleaseMask |
3726 StructureNotifyMask |
3728 Button1MotionMask | Button2MotionMask |
3729 Button3MotionMask | FocusChangeMask
3731 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
3732 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
3734 XSynchronize(aDisplay, 0);
3742 //==============================================================================
3745 //==============================================================================
3747 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
3749 const Handle(V3d_View) aView = ViewerTest::CurrentView();
3752 std::cout << "Error: no active viewer!\n";
3756 Standard_Boolean toFit = Standard_True;
3757 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
3758 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3760 TCollection_AsciiString anArg (theArgv[anArgIter]);
3762 if (anUpdateTool.parseRedrawMode (anArg))
3766 else if (anArg == "-selected")
3768 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
3769 toFit = Standard_False;
3773 std::cout << "Syntax error at '" << anArg << "'\n";
3779 aView->FitAll (0.01, Standard_False);
3784 //=======================================================================
3785 //function : VFitArea
3786 //purpose : Fit view to show area located between two points
3787 // : given in world 2D or 3D coordinates.
3788 //=======================================================================
3789 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3791 Handle(V3d_View) aView = ViewerTest::CurrentView();
3794 std::cerr << theArgVec[0] << "Error: No active view.\n";
3799 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
3800 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
3804 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
3805 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
3806 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
3807 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
3809 else if (theArgNb == 7)
3811 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
3812 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
3813 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
3814 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
3815 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
3816 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
3820 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
3821 theDI.PrintHelp(theArgVec[0]);
3825 // Convert model coordinates to view space
3826 Handle(Graphic3d_Camera) aCamera = aView->Camera();
3827 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
3828 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
3830 // Determine fit area
3831 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
3832 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
3834 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
3836 if (aDiagonal < Precision::Confusion())
3838 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
3842 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
3846 //==============================================================================
3848 //purpose : ZFitall, no DRAW arguments
3849 //Draw arg : No args
3850 //==============================================================================
3851 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3853 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
3855 if (aCurrentView.IsNull())
3857 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
3863 aCurrentView->ZFitAll();
3864 aCurrentView->Redraw();
3868 Standard_Real aScale = 1.0;
3872 aScale = Draw::Atoi (theArgVec[1]);
3875 aCurrentView->ZFitAll (aScale);
3876 aCurrentView->Redraw();
3881 //==============================================================================
3882 //function : VRepaint
3884 //==============================================================================
3885 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
3887 Handle(V3d_View) aView = ViewerTest::CurrentView();
3890 std::cout << "Error: no active viewer!\n";
3894 Standard_Boolean isImmediateUpdate = Standard_False;
3895 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3897 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3899 if (anArg == "-immediate"
3902 isImmediateUpdate = Standard_True;
3903 if (anArgIter + 1 < theArgNb
3904 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
3909 else if (anArg == "-continuous"
3912 || anArg == "-framerate")
3914 Standard_Real aFps = -1.0;
3915 if (anArgIter + 1 < theArgNb
3916 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue())
3918 aFps = Draw::Atof (theArgVec[++anArgIter]);
3921 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
3922 if (Abs (aFps) >= 1.0)
3924 aRedrawer.Start (aView->Window(), aFps);
3933 std::cout << "Syntax error at '" << anArg << "'\n";
3938 if (isImmediateUpdate)
3940 aView->RedrawImmediate();
3949 //==============================================================================
3951 //purpose : Remove all the object from the viewer
3952 //Draw arg : No args
3953 //==============================================================================
3955 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3957 Handle(V3d_View) V = ViewerTest::CurrentView();
3959 ViewerTest::Clear();
3963 //==============================================================================
3966 //==============================================================================
3968 static int VPick (Draw_Interpretor& ,
3969 Standard_Integer theNbArgs,
3970 const char** theArgVec)
3972 if (ViewerTest::CurrentView().IsNull())
3979 std::cout << "Syntax error: Invalid number of arguments\n";
3983 while (ViewerMainLoop (theNbArgs, theArgVec))
3994 //! Changes the background
3995 //! @param theDrawInterpretor the interpreter of the Draw Harness application
3996 //! @param theNumberOfCommandLineArguments the number of passed command line arguments
3997 //! @param theCommandLineArguments the array of command line arguments
3998 //! @return TCL_OK if changing was successful, or TCL_ERROR otherwise
3999 static int vbackground (Draw_Interpretor& theDrawInterpretor,
4000 const Standard_Integer theNumberOfCommandLineArguments,
4001 const char** const theCommandLineArguments)
4003 if (theNumberOfCommandLineArguments < 1)
4007 BackgroundChanger aBackgroundChanger;
4008 if (!aBackgroundChanger.ProcessCommandLine (theDrawInterpretor,
4009 theNumberOfCommandLineArguments,
4010 theCommandLineArguments))
4012 theDrawInterpretor << "Wrong command arguments.\n"
4014 << theCommandLineArguments[0] << "' for information about command options and its arguments.\n";
4022 //==============================================================================
4024 //purpose : View Scaling
4025 //==============================================================================
4027 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4029 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4030 if ( V3dView.IsNull() ) return 1;
4033 di << argv[0] << "Invalid number of arguments\n";
4036 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
4039 //==============================================================================
4040 //function : VZBuffTrihedron
4042 //==============================================================================
4044 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
4045 Standard_Integer theArgNb,
4046 const char** theArgVec)
4048 Handle(V3d_View) aView = ViewerTest::CurrentView();
4051 std::cout << "Error: no active viewer!\n";
4055 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
4057 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
4058 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
4059 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
4060 Quantity_Color anArrowColorX = Quantity_NOC_RED;
4061 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
4062 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
4063 Standard_Real aScale = 0.1;
4064 Standard_Real aSizeRatio = 0.8;
4065 Standard_Real anArrowDiam = 0.05;
4066 Standard_Integer aNbFacets = 12;
4067 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4069 Standard_CString anArg = theArgVec[anArgIter];
4070 TCollection_AsciiString aFlag (anArg);
4072 if (anUpdateTool.parseRedrawMode (aFlag))
4076 else if (aFlag == "-on")
4080 else if (aFlag == "-off")
4082 aView->TriedronErase();
4085 else if (aFlag == "-pos"
4086 || aFlag == "-position"
4087 || aFlag == "-corner")
4089 if (++anArgIter >= theArgNb)
4091 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4095 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
4096 aPosName.LowerCase();
4097 if (aPosName == "center")
4099 aPosition = Aspect_TOTP_CENTER;
4101 else if (aPosName == "left_lower"
4102 || aPosName == "lower_left"
4103 || aPosName == "leftlower"
4104 || aPosName == "lowerleft")
4106 aPosition = Aspect_TOTP_LEFT_LOWER;
4108 else if (aPosName == "left_upper"
4109 || aPosName == "upper_left"
4110 || aPosName == "leftupper"
4111 || aPosName == "upperleft")
4113 aPosition = Aspect_TOTP_LEFT_UPPER;
4115 else if (aPosName == "right_lower"
4116 || aPosName == "lower_right"
4117 || aPosName == "rightlower"
4118 || aPosName == "lowerright")
4120 aPosition = Aspect_TOTP_RIGHT_LOWER;
4122 else if (aPosName == "right_upper"
4123 || aPosName == "upper_right"
4124 || aPosName == "rightupper"
4125 || aPosName == "upperright")
4127 aPosition = Aspect_TOTP_RIGHT_UPPER;
4131 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
4135 else if (aFlag == "-type")
4137 if (++anArgIter >= theArgNb)
4139 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4143 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
4144 aTypeName.LowerCase();
4145 if (aTypeName == "wireframe"
4146 || aTypeName == "wire")
4148 aVisType = V3d_WIREFRAME;
4150 else if (aTypeName == "zbuffer"
4151 || aTypeName == "shaded")
4153 aVisType = V3d_ZBUFFER;
4157 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
4160 else if (aFlag == "-scale")
4162 if (++anArgIter >= theArgNb)
4164 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4168 aScale = Draw::Atof (theArgVec[anArgIter]);
4170 else if (aFlag == "-size"
4171 || aFlag == "-sizeratio")
4173 if (++anArgIter >= theArgNb)
4175 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4179 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
4181 else if (aFlag == "-arrowdiam"
4182 || aFlag == "-arrowdiameter")
4184 if (++anArgIter >= theArgNb)
4186 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4190 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
4192 else if (aFlag == "-nbfacets")
4194 if (++anArgIter >= theArgNb)
4196 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4200 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
4202 else if (aFlag == "-colorlabel"
4203 || aFlag == "-colorlabels")
4205 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4206 theArgVec + anArgIter + 1,
4210 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4213 anArgIter += aNbParsed;
4215 else if (aFlag == "-colorarrowx")
4217 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4218 theArgVec + anArgIter + 1,
4222 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4225 anArgIter += aNbParsed;
4227 else if (aFlag == "-colorarrowy")
4229 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4230 theArgVec + anArgIter + 1,
4234 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4237 anArgIter += aNbParsed;
4239 else if (aFlag == "-colorarrowz")
4241 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4242 theArgVec + anArgIter + 1,
4246 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4249 anArgIter += aNbParsed;
4253 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4258 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
4259 aSizeRatio, anArrowDiam, aNbFacets);
4260 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
4265 //==============================================================================
4266 //function : VRotate
4267 //purpose : Camera Rotating
4268 //==============================================================================
4270 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
4272 Handle(V3d_View) aView = ViewerTest::CurrentView();
4275 std::cout << "No active view!\n";
4279 Standard_Boolean hasFlags = Standard_False;
4280 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4282 Standard_CString anArg (theArgVec[anArgIter]);
4283 TCollection_AsciiString aFlag (anArg);
4285 if (aFlag == "-mousestart"
4286 || aFlag == "-mousefrom")
4288 hasFlags = Standard_True;
4289 if (anArgIter + 2 >= theArgNb)
4291 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4295 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
4296 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
4297 aView->StartRotation (anX, anY);
4299 else if (aFlag == "-mousemove")
4301 hasFlags = Standard_True;
4302 if (anArgIter + 2 >= theArgNb)
4304 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4308 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
4309 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
4310 aView->Rotation (anX, anY);
4312 else if (theArgNb != 4
4315 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4324 else if (theArgNb == 4)
4326 Standard_Real anAX = Draw::Atof (theArgVec[1]);
4327 Standard_Real anAY = Draw::Atof (theArgVec[2]);
4328 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
4329 aView->Rotate (anAX, anAY, anAZ);
4332 else if (theArgNb == 7)
4334 Standard_Real anAX = Draw::Atof (theArgVec[1]);
4335 Standard_Real anAY = Draw::Atof (theArgVec[2]);
4336 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
4338 Standard_Real anX = Draw::Atof (theArgVec[4]);
4339 Standard_Real anY = Draw::Atof (theArgVec[5]);
4340 Standard_Real anZ = Draw::Atof (theArgVec[6]);
4342 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
4346 std::cout << "Error: Invalid number of arguments\n";
4350 //==============================================================================
4352 //purpose : View zoom in / out (relative to current zoom)
4353 //==============================================================================
4355 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4356 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4357 if ( V3dView.IsNull() ) {
4362 Standard_Real coef = Draw::Atof(argv[1]);
4363 if ( coef <= 0.0 ) {
4364 di << argv[1] << "Invalid value\n";
4367 V3dView->SetZoom( Draw::Atof(argv[1]) );
4370 di << argv[0] << " Invalid number of arguments\n";
4375 //==============================================================================
4377 //purpose : View panning (in pixels)
4378 //==============================================================================
4380 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4381 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4382 if ( V3dView.IsNull() ) return 1;
4385 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
4388 di << argv[0] << " Invalid number of arguments\n";
4393 //==============================================================================
4395 //purpose : Place the point (in pixels) at the center of the window
4396 //==============================================================================
4397 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
4399 Handle(V3d_View) aView = ViewerTest::CurrentView();
4402 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
4408 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
4412 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
4417 static int VColorScale (Draw_Interpretor& theDI,
4418 Standard_Integer theArgNb,
4419 const char** theArgVec)
4421 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4422 Handle(V3d_View) aView = ViewerTest::CurrentView();
4423 if (aContext.IsNull())
4425 std::cout << "Error: no active view!\n";
4430 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
4434 Handle(AIS_ColorScale) aColorScale;
4435 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
4437 // find existing object
4438 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
4439 if (aColorScale.IsNull())
4441 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
4448 if (aColorScale.IsNull())
4450 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
4454 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
4455 << "Min range: " << aColorScale->GetMin() << "\n"
4456 << "Max range: " << aColorScale->GetMax() << "\n"
4457 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
4458 << "Text height: " << aColorScale->GetTextHeight() << "\n"
4459 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
4460 << "Color scale title: " << aColorScale->GetTitle() << "\n"
4461 << "Label position: ";
4462 switch (aColorScale->GetLabelPosition())
4464 case Aspect_TOCSP_NONE:
4467 case Aspect_TOCSP_LEFT:
4470 case Aspect_TOCSP_RIGHT:
4473 case Aspect_TOCSP_CENTER:
4474 theDI << "Center\n";
4480 if (aColorScale.IsNull())
4482 aColorScale = new AIS_ColorScale();
4483 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4484 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
4487 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
4488 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
4490 Standard_CString anArg = theArgVec[anArgIter];
4491 TCollection_AsciiString aFlag (anArg);
4493 if (anUpdateTool.parseRedrawMode (aFlag))
4497 else if (aFlag == "-range")
4499 if (anArgIter + 3 >= theArgNb)
4501 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4505 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
4506 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
4507 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
4508 if (!aRangeMin.IsRealValue()
4509 || !aRangeMax.IsRealValue())
4511 std::cout << "Error: the range values should be real!\n";
4514 else if (!aNbIntervals.IsIntegerValue())
4516 std::cout << "Error: the number of intervals should be integer!\n";
4520 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
4521 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
4523 else if (aFlag == "-font")
4525 if (anArgIter + 1 >= theArgNb)
4527 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4530 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
4531 if (!aFontArg.IsIntegerValue())
4533 std::cout << "Error: HeightFont value should be integer!\n";
4537 aColorScale->SetTextHeight (aFontArg.IntegerValue());
4540 else if (aFlag == "-textpos")
4542 if (anArgIter + 1 >= theArgNb)
4544 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4548 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
4549 aTextPosArg.LowerCase();
4550 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
4551 if (aTextPosArg == "none")
4553 aLabPosition = Aspect_TOCSP_NONE;
4555 else if (aTextPosArg == "left")
4557 aLabPosition = Aspect_TOCSP_LEFT;
4559 else if (aTextPosArg == "right")
4561 aLabPosition = Aspect_TOCSP_RIGHT;
4563 else if (aTextPosArg == "center")
4565 aLabPosition = Aspect_TOCSP_CENTER;
4569 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
4572 aColorScale->SetLabelPosition (aLabPosition);
4574 else if (aFlag == "-logarithmic"
4577 if (anArgIter + 1 >= theArgNb)
4579 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4583 Standard_Boolean IsLog;
4584 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
4586 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4589 aColorScale->SetLogarithmic (IsLog);
4591 else if (aFlag == "-huerange"
4594 if (anArgIter + 2 >= theArgNb)
4596 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4600 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
4601 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
4602 aColorScale->SetHueRange (aHueMin, aHueMax);
4604 else if (aFlag == "-colorrange")
4606 Quantity_Color aColorMin, aColorMax;
4607 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4608 theArgVec + (anArgIter + 1),
4610 anArgIter += aNbParsed1;
4611 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4612 theArgVec + (anArgIter + 1),
4614 anArgIter += aNbParsed2;
4618 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4622 aColorScale->SetColorRange (aColorMin, aColorMax);
4624 else if (aFlag == "-reversed"
4625 || aFlag == "-inverted"
4626 || aFlag == "-topdown"
4627 || aFlag == "-bottomup")
4629 Standard_Boolean toEnable = Standard_True;
4630 if (anArgIter + 1 < theArgNb
4631 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
4635 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
4637 else if (aFlag == "-smooth"
4638 || aFlag == "-smoothtransition")
4640 Standard_Boolean toEnable = Standard_True;
4641 if (anArgIter + 1 < theArgNb
4642 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4646 aColorScale->SetSmoothTransition (toEnable);
4648 else if (aFlag == "-xy")
4650 if (anArgIter + 2 >= theArgNb)
4652 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4656 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
4657 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
4658 if (!anX.IsIntegerValue()
4659 || !anY.IsIntegerValue())
4661 std::cout << "Error: coordinates should be integer values!\n";
4665 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
4667 else if (aFlag == "-width"
4669 || aFlag == "-breadth")
4671 if (anArgIter + 1 >= theArgNb)
4673 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4677 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
4678 if (!aBreadth.IsIntegerValue())
4680 std::cout << "Error: a width should be an integer value!\n";
4683 aColorScale->SetBreadth (aBreadth.IntegerValue());
4685 else if (aFlag == "-height"
4688 if (anArgIter + 1 >= theArgNb)
4690 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4694 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
4695 if (!aHeight.IsIntegerValue())
4697 std::cout << "Error: a width should be an integer value!\n";
4700 aColorScale->SetHeight (aHeight.IntegerValue());
4702 else if (aFlag == "-color")
4704 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4706 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
4709 else if (anArgIter + 2 >= theArgNb)
4711 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4715 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
4716 if (!anInd.IsIntegerValue())
4718 std::cout << "Error: Index value should be integer!\n";
4721 const Standard_Integer anIndex = anInd.IntegerValue();
4722 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
4724 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
4728 Quantity_Color aColor;
4729 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4730 theArgVec + (anArgIter + 1),
4734 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4737 aColorScale->SetIntervalColor (aColor, anIndex);
4738 aColorScale->SetColorType (Aspect_TOCSD_USER);
4739 anArgIter += aNbParsed;
4741 else if (aFlag == "-label")
4743 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4745 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
4748 else if (anArgIter + 2 >= theArgNb)
4750 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4754 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4755 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
4757 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
4761 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4762 aColorScale->SetLabel (aText, anIndex);
4763 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4766 else if (aFlag == "-labelat"
4767 || aFlag == "-labat"
4768 || aFlag == "-labelatborder"
4769 || aFlag == "-labatborder"
4770 || aFlag == "-labelatcenter"
4771 || aFlag == "-labatcenter")
4773 Standard_Boolean toEnable = Standard_True;
4774 if (aFlag == "-labelat"
4775 || aFlag == "-labat")
4777 Standard_Integer aLabAtBorder = -1;
4778 if (++anArgIter >= theArgNb)
4780 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4781 anAtBorder.LowerCase();
4782 if (anAtBorder == "border")
4786 else if (anAtBorder == "center")
4791 if (aLabAtBorder == -1)
4793 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4796 toEnable = (aLabAtBorder == 1);
4798 else if (anArgIter + 1 < theArgNb
4799 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4803 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4804 || aFlag == "-labatcenter"
4808 else if (aFlag == "-colors")
4810 Aspect_SequenceOfColor aSeq;
4813 Quantity_Color aColor;
4814 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4815 theArgVec + (anArgIter + 1),
4821 anArgIter += aNbParsed;
4822 aSeq.Append (aColor);
4824 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
4826 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4827 << aColorScale->GetNumberOfIntervals() << " intervals\n";
4831 aColorScale->SetColors (aSeq);
4832 aColorScale->SetColorType (Aspect_TOCSD_USER);
4834 else if (aFlag == "-uniform")
4836 const Standard_Real aLightness = Draw::Atof (theArgVec[++anArgIter]);
4837 const Standard_Real aHueStart = Draw::Atof (theArgVec[++anArgIter]);
4838 const Standard_Real aHueEnd = Draw::Atof (theArgVec[++anArgIter]);
4839 aColorScale->SetUniformColors (aLightness, aHueStart, aHueEnd);
4840 aColorScale->SetColorType (Aspect_TOCSD_USER);
4842 else if (aFlag == "-labels"
4843 || aFlag == "-freelabels")
4845 if (anArgIter + 1 >= theArgNb)
4847 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4851 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4852 ? aColorScale->GetNumberOfIntervals() + 1
4853 : aColorScale->GetNumberOfIntervals();
4854 if (aFlag == "-freelabels")
4857 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4859 if (anArgIter + aNbLabels >= theArgNb)
4861 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
4865 TColStd_SequenceOfExtendedString aSeq;
4866 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
4868 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
4870 aColorScale->SetLabels (aSeq);
4871 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4873 else if (aFlag == "-title")
4875 if (anArgIter + 1 >= theArgNb)
4877 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4881 Standard_Boolean isTwoArgs = Standard_False;
4882 if (anArgIter + 2 < theArgNb)
4884 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4885 aSecondArg.LowerCase();
4886 Standard_DISABLE_DEPRECATION_WARNINGS
4887 if (aSecondArg == "none")
4889 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
4890 isTwoArgs = Standard_True;
4892 else if (aSecondArg == "left")
4894 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
4895 isTwoArgs = Standard_True;
4897 else if (aSecondArg == "right")
4899 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
4900 isTwoArgs = Standard_True;
4902 else if (aSecondArg == "center")
4904 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
4905 isTwoArgs = Standard_True;
4907 Standard_ENABLE_DEPRECATION_WARNINGS
4910 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
4917 else if (aFlag == "-demoversion"
4918 || aFlag == "-demo")
4920 aColorScale->SetPosition (0, 0);
4921 aColorScale->SetTextHeight (16);
4922 aColorScale->SetRange (0.0, 100.0);
4923 aColorScale->SetNumberOfIntervals (10);
4924 aColorScale->SetBreadth (0);
4925 aColorScale->SetHeight (0);
4926 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4927 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4928 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
4930 else if (aFlag == "-findcolor")
4932 if (anArgIter + 1 >= theArgNb)
4934 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4938 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4940 if (!anArg1.IsRealValue())
4942 std::cout << "Error: the value should be real!\n";
4946 Quantity_Color aColor;
4947 aColorScale->FindColor (anArg1.RealValue(), aColor);
4948 theDI << Quantity_Color::StringName (aColor.Name());
4953 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4958 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4959 aView->Window()->Size (aWinWidth, aWinHeight);
4960 if (aColorScale->GetBreadth() == 0)
4962 aColorScale->SetBreadth (aWinWidth);
4964 if (aColorScale->GetHeight() == 0)
4966 aColorScale->SetHeight (aWinHeight);
4968 aColorScale->SetToUpdate();
4969 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
4973 //==============================================================================
4974 //function : VGraduatedTrihedron
4975 //purpose : Displays or hides a graduated trihedron
4976 //==============================================================================
4977 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4978 Quantity_Color& theColor)
4980 Quantity_NameOfColor aColorName;
4981 TCollection_AsciiString aVal = theValue;
4983 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
4985 return Standard_False;
4987 theColor = Quantity_Color (aColorName);
4988 return Standard_True;
4991 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
4995 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4996 << theArgs[0] <<"' for more information.\n";
4997 return 1; //TCL_ERROR
5000 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
5001 TCollection_AsciiString aParseKey;
5002 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
5004 TCollection_AsciiString anArg (theArgs [anArgIt]);
5006 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5009 aParseKey.Remove (1);
5010 aParseKey.LowerCase();
5011 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5015 if (aParseKey.IsEmpty())
5020 aMapOfArgs(aParseKey)->Append (anArg);
5024 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
5025 aMapIt.More(); aMapIt.Next())
5027 const TCollection_AsciiString& aKey = aMapIt.Key();
5028 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
5030 // Bool key, without arguments
5031 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
5032 && anArgs->IsEmpty())
5038 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
5039 && anArgs->Length() == 1)
5045 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
5046 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
5047 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
5048 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
5049 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
5054 // One string argument
5055 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
5056 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
5057 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
5062 // One integer argument
5063 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
5064 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
5065 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
5066 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
5067 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
5072 // One real argument
5073 if ( aKey.IsEqual ("arrowlength")
5074 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
5079 // Two string arguments
5080 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
5081 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
5086 TCollection_AsciiString aLowerKey;
5089 aLowerKey.LowerCase();
5090 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
5091 std::cout << "Type help for more information.\n";
5095 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5096 if (anAISContext.IsNull())
5098 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
5102 Standard_Boolean toDisplay = Standard_True;
5103 Quantity_Color aColor;
5104 Graphic3d_GraduatedTrihedron aTrihedronData;
5105 // Process parameters
5106 Handle(TColStd_HSequenceOfAsciiString) aValues;
5107 if (aMapOfArgs.Find ("off", aValues))
5109 toDisplay = Standard_False;
5113 if (aMapOfArgs.Find ("xname", aValues))
5115 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
5117 if (aMapOfArgs.Find ("yname", aValues))
5119 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
5121 if (aMapOfArgs.Find ("zname", aValues))
5123 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
5125 if (aMapOfArgs.Find ("xdrawname", aValues))
5127 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5129 if (aMapOfArgs.Find ("ydrawname", aValues))
5131 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5133 if (aMapOfArgs.Find ("zdrawname", aValues))
5135 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5137 if (aMapOfArgs.Find ("xnameoffset", aValues))
5139 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5141 if (aMapOfArgs.Find ("ynameoffset", aValues))
5143 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5145 if (aMapOfArgs.Find ("znameoffset", aValues))
5147 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5151 if (aMapOfArgs.Find ("xnamecolor", aValues))
5153 if (!GetColor (aValues->Value(1), aColor))
5155 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
5158 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
5160 if (aMapOfArgs.Find ("ynamecolor", aValues))
5162 if (!GetColor (aValues->Value(1), aColor))
5164 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
5167 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
5169 if (aMapOfArgs.Find ("znamecolor", aValues))
5171 if (!GetColor (aValues->Value(1), aColor))
5173 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
5176 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
5178 if (aMapOfArgs.Find ("xcolor", aValues))
5180 if (!GetColor (aValues->Value(1), aColor))
5182 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
5185 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
5187 if (aMapOfArgs.Find ("ycolor", aValues))
5189 if (!GetColor (aValues->Value(1), aColor))
5191 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
5194 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
5196 if (aMapOfArgs.Find ("zcolor", aValues))
5198 if (!GetColor (aValues->Value(1), aColor))
5200 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
5203 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
5207 if (aMapOfArgs.Find ("xticks", aValues))
5209 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5211 if (aMapOfArgs.Find ("yticks", aValues))
5213 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5215 if (aMapOfArgs.Find ("zticks", aValues))
5217 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5219 if (aMapOfArgs.Find ("xticklength", aValues))
5221 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5223 if (aMapOfArgs.Find ("yticklength", aValues))
5225 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5227 if (aMapOfArgs.Find ("zticklength", aValues))
5229 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5231 if (aMapOfArgs.Find ("xdrawticks", aValues))
5233 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5235 if (aMapOfArgs.Find ("ydrawticks", aValues))
5237 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5239 if (aMapOfArgs.Find ("zdrawticks", aValues))
5241 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5245 if (aMapOfArgs.Find ("xdrawvalues", aValues))
5247 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5249 if (aMapOfArgs.Find ("ydrawvalues", aValues))
5251 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5253 if (aMapOfArgs.Find ("zdrawvalues", aValues))
5255 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5257 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
5259 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5261 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
5263 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5265 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
5267 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5271 if (aMapOfArgs.Find ("arrowlength", aValues))
5273 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
5277 if (aMapOfArgs.Find ("namefont", aValues))
5279 aTrihedronData.SetNamesFont (aValues->Value(1));
5281 if (aMapOfArgs.Find ("valuesfont", aValues))
5283 aTrihedronData.SetValuesFont (aValues->Value(1));
5286 if (aMapOfArgs.Find ("drawgrid", aValues))
5288 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
5290 if (aMapOfArgs.Find ("drawaxes", aValues))
5292 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
5295 // The final step: display of erase trihedron
5298 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
5302 ViewerTest::CurrentView()->GraduatedTrihedronErase();
5305 ViewerTest::GetAISContext()->UpdateCurrentViewer();
5306 ViewerTest::CurrentView()->Redraw();
5311 //==============================================================================
5314 //==============================================================================
5315 static int VTile (Draw_Interpretor& theDI,
5316 Standard_Integer theArgNb,
5317 const char** theArgVec)
5319 Handle(V3d_View) aView = ViewerTest::CurrentView();
5322 std::cerr << "Error: no active viewer.\n";
5326 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
5329 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
5330 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
5331 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
5335 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
5336 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5338 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5340 if (anArg == "-lowerleft"
5341 || anArg == "-upperleft")
5343 if (anArgIter + 3 < theArgNb)
5345 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5348 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
5349 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5350 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5352 else if (anArg == "-total"
5353 || anArg == "-totalsize"
5354 || anArg == "-viewsize")
5356 if (anArgIter + 3 < theArgNb)
5358 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5361 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5362 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5363 if (aTile.TotalSize.x() < 1
5364 || aTile.TotalSize.y() < 1)
5366 std::cerr << "Error: total size is incorrect.\n";
5370 else if (anArg == "-tilesize")
5372 if (anArgIter + 3 < theArgNb)
5374 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5378 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5379 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5380 if (aTile.TileSize.x() < 1
5381 || aTile.TileSize.y() < 1)
5383 std::cerr << "Error: tile size is incorrect.\n";
5387 else if (anArg == "-unset")
5389 aView->Camera()->SetTile (Graphic3d_CameraTile());
5395 if (aTile.TileSize.x() < 1
5396 || aTile.TileSize.y() < 1)
5398 std::cerr << "Error: tile size is undefined.\n";
5401 else if (aTile.TotalSize.x() < 1
5402 || aTile.TotalSize.y() < 1)
5404 std::cerr << "Error: total size is undefined.\n";
5408 aView->Camera()->SetTile (aTile);
5413 //! Format ZLayer ID.
5414 inline const char* formZLayerId (const Standard_Integer theLayerId)
5418 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
5419 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
5420 case Graphic3d_ZLayerId_Top: return "[TOP]";
5421 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
5422 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
5423 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
5428 //! Print the ZLayer information.
5429 inline void printZLayerInfo (Draw_Interpretor& theDI,
5430 const Graphic3d_ZLayerSettings& theLayer)
5432 if (!theLayer.Name().IsEmpty())
5434 theDI << " Name: " << theLayer.Name() << "\n";
5436 if (theLayer.IsImmediate())
5438 theDI << " Immediate: TRUE\n";
5440 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
5441 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
5442 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
5443 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
5444 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
5445 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
5446 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
5448 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
5452 //==============================================================================
5453 //function : VZLayer
5454 //purpose : Test z layer operations for v3d viewer
5455 //==============================================================================
5456 static int VZLayer (Draw_Interpretor& theDI,
5457 Standard_Integer theArgNb,
5458 const char** theArgVec)
5460 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5461 if (aContextAIS.IsNull())
5463 std::cout << "No active viewer!\n";
5467 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
5470 TColStd_SequenceOfInteger aLayers;
5471 aViewer->GetAllZLayers (aLayers);
5472 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5474 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
5475 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
5476 printZLayerInfo (theDI, aSettings);
5481 Standard_Integer anArgIter = 1;
5482 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5483 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
5484 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5490 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
5491 if (aFirstArg.IsIntegerValue())
5494 aLayerId = aFirstArg.IntegerValue();
5498 if (ViewerTest::ParseZLayerName (aFirstArg.ToCString(), aLayerId))
5505 Graphic3d_ZLayerId anOtherLayerId = Graphic3d_ZLayerId_UNKNOWN;
5506 for (; anArgIter < theArgNb; ++anArgIter)
5508 // perform operation
5509 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5511 if (anUpdateTool.parseRedrawMode (anArg))
5515 else if (anArg == "-add"
5518 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5519 if (!aViewer->AddZLayer (aLayerId))
5521 std::cout << "Error: can not add a new z layer!\n";
5527 else if (anArg == "-insertbefore"
5528 && anArgIter + 1 < theArgNb
5529 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
5532 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5533 if (!aViewer->InsertLayerBefore (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
5535 std::cout << "Error: can not add a new z layer!\n";
5541 else if (anArg == "-insertafter"
5542 && anArgIter + 1 < theArgNb
5543 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
5546 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5547 if (!aViewer->InsertLayerAfter (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
5549 std::cout << "Error: can not add a new z layer!\n";
5555 else if (anArg == "-del"
5556 || anArg == "-delete"
5559 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5561 if (++anArgIter >= theArgNb)
5563 std::cout << "Syntax error: id of z layer to remove is missing\n";
5567 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5570 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
5571 || aLayerId == Graphic3d_ZLayerId_Default
5572 || aLayerId == Graphic3d_ZLayerId_Top
5573 || aLayerId == Graphic3d_ZLayerId_Topmost
5574 || aLayerId == Graphic3d_ZLayerId_TopOSD
5575 || aLayerId == Graphic3d_ZLayerId_BotOSD)
5577 std::cout << "Syntax error: standard Z layer can not be removed\n";
5581 // move all object displayed in removing layer to default layer
5582 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5583 anObjIter.More(); anObjIter.Next())
5585 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
5587 || aPrs->ZLayer() != aLayerId)
5591 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
5594 if (!aViewer->RemoveZLayer (aLayerId))
5596 std::cout << "Z layer can not be removed!\n";
5600 theDI << aLayerId << " ";
5603 else if (anArg == "-get"
5606 TColStd_SequenceOfInteger aLayers;
5607 aViewer->GetAllZLayers (aLayers);
5608 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5610 theDI << aLayeriter.Value() << " ";
5615 else if (anArg == "-name")
5617 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5619 std::cout << "Syntax error: id of Z layer is missing\n";
5623 if (++anArgIter >= theArgNb)
5625 std::cout << "Syntax error: name is missing\n";
5629 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5630 aSettings.SetName (theArgVec[anArgIter]);
5631 aViewer->SetZLayerSettings (aLayerId, aSettings);
5633 else if (anArg == "-origin")
5635 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5637 std::cout << "Syntax error: id of Z layer is missing\n";
5641 if (anArgIter + 2 >= theArgNb)
5643 std::cout << "Syntax error: origin coordinates are missing\n";
5647 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5649 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
5650 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
5651 anOrigin.SetZ (0.0);
5652 if (anArgIter + 3 < theArgNb)
5654 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
5661 aSettings.SetOrigin (anOrigin);
5662 aViewer->SetZLayerSettings (aLayerId, aSettings);
5664 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5665 && anArgIter + 1 < theArgNb
5666 && (anArg == "-cullingdistance"
5667 || anArg == "-cullingdist"
5668 || anArg == "-culldistance"
5669 || anArg == "-culldist"
5670 || anArg == "-distcull"
5671 || anArg == "-distculling"
5672 || anArg == "-distanceculling"))
5674 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5675 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
5676 aSettings.SetCullingDistance (aDist);
5677 aViewer->SetZLayerSettings (aLayerId, aSettings);
5679 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5680 && anArgIter + 1 < theArgNb
5681 && (anArg == "-cullingsize"
5682 || anArg == "-cullsize"
5683 || anArg == "-sizecull"
5684 || anArg == "-sizeculling"))
5686 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5687 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
5688 aSettings.SetCullingSize (aSize);
5689 aViewer->SetZLayerSettings (aLayerId, aSettings);
5691 else if (anArg == "-settings"
5692 || anArg == "settings")
5694 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5696 if (++anArgIter >= theArgNb)
5698 std::cout << "Syntax error: id of Z layer is missing\n";
5702 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5705 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5706 printZLayerInfo (theDI, aSettings);
5708 else if (anArg == "-enable"
5709 || anArg == "enable"
5710 || anArg == "-disable"
5711 || anArg == "disable")
5713 const Standard_Boolean toEnable = anArg == "-enable"
5714 || anArg == "enable";
5715 if (++anArgIter >= theArgNb)
5717 std::cout << "Syntax error: option name is missing\n";
5721 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
5723 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5725 if (++anArgIter >= theArgNb)
5727 std::cout << "Syntax error: id of Z layer is missing\n";
5731 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5734 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5735 if (aSubOp == "depthtest"
5736 || aSubOp == "test")
5738 aSettings.SetEnableDepthTest (toEnable);
5740 else if (aSubOp == "depthwrite"
5741 || aSubOp == "write")
5743 aSettings.SetEnableDepthWrite (toEnable);
5745 else if (aSubOp == "depthclear"
5746 || aSubOp == "clear")
5748 aSettings.SetClearDepth (toEnable);
5750 else if (aSubOp == "depthoffset"
5751 || aSubOp == "offset")
5753 Graphic3d_PolygonOffset aParams;
5754 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5757 if (anArgIter + 2 >= theArgNb)
5759 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5763 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5764 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5766 aSettings.SetPolygonOffset (aParams);
5768 else if (aSubOp == "positiveoffset"
5769 || aSubOp == "poffset")
5773 aSettings.SetDepthOffsetPositive();
5777 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5780 else if (aSubOp == "negativeoffset"
5781 || aSubOp == "noffset")
5785 aSettings.SetDepthOffsetNegative();
5789 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5792 else if (aSubOp == "textureenv")
5794 aSettings.SetEnvironmentTexture (toEnable);
5796 else if (aSubOp == "raytracing")
5798 aSettings.SetRaytracable (toEnable);
5801 aViewer->SetZLayerSettings (aLayerId, aSettings);
5805 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5813 // The interactive presentation of 2d layer item
5814 // for "vlayerline" command it provides a presentation of
5815 // line with user-defined linewidth, linetype and transparency.
5816 class V3d_LineItem : public AIS_InteractiveObject
5820 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
5823 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5824 Standard_Real X2, Standard_Real Y2,
5825 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5826 Standard_Real theWidth = 0.5,
5827 Standard_Real theTransp = 1.0);
5831 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5832 const Handle(Prs3d_Presentation)& thePresentation,
5833 const Standard_Integer theMode) Standard_OVERRIDE;
5835 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
5836 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5841 Standard_Real myX1, myY1, myX2, myY2;
5842 Aspect_TypeOfLine myType;
5843 Standard_Real myWidth;
5846 // default constructor for line item
5847 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5848 Standard_Real X2, Standard_Real Y2,
5849 Aspect_TypeOfLine theType,
5850 Standard_Real theWidth,
5851 Standard_Real theTransp) :
5852 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5853 myType(theType), myWidth(theWidth)
5855 SetTransparency (1-theTransp);
5859 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5860 const Handle(Prs3d_Presentation)& thePresentation,
5861 const Standard_Integer /*theMode*/)
5863 thePresentation->Clear();
5864 Quantity_Color aColor (Quantity_NOC_RED);
5865 Standard_Integer aWidth, aHeight;
5866 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5867 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5868 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5869 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5870 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5871 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5872 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5873 aGroup->AddPrimitiveArray (aPrim);
5876 //=============================================================================
5877 //function : VLayerLine
5878 //purpose : Draws line in the v3d view layer with given attributes: linetype,
5879 // : linewidth, transparency coefficient
5880 //============================================================================
5881 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5883 // get the active view
5884 Handle(V3d_View) aView = ViewerTest::CurrentView();
5887 di << "Call vinit before!\n";
5892 di << "Use: " << argv[0];
5893 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5894 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5895 di << " 0 - solid \n";
5896 di << " 1 - dashed \n";
5897 di << " 2 - dot \n";
5898 di << " 3 - dashdot\n";
5899 di << " transparency : { 0.0 - 1.0 } \n";
5900 di << " 0.0 - transparent\n";
5901 di << " 1.0 - visible \n";
5905 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5906 // get the input params
5907 Standard_Real X1 = Draw::Atof(argv[1]);
5908 Standard_Real Y1 = Draw::Atof(argv[2]);
5909 Standard_Real X2 = Draw::Atof(argv[3]);
5910 Standard_Real Y2 = Draw::Atof(argv[4]);
5912 Standard_Real aWidth = 0.5;
5913 Standard_Real aTransparency = 1.0;
5917 aWidth = Draw::Atof(argv[5]);
5919 // select appropriate line type
5920 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5922 && !ViewerTest::ParseLineType (argv[6], aLineType))
5924 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5931 aTransparency = Draw::Atof(argv[7]);
5932 if (aTransparency < 0 || aTransparency > 1.0)
5933 aTransparency = 1.0;
5936 static Handle (V3d_LineItem) aLine;
5937 if (!aLine.IsNull())
5939 aContext->Erase (aLine, Standard_False);
5941 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5945 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5946 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5947 aLine->SetToUpdate();
5948 aContext->Display (aLine, Standard_True);
5954 //==============================================================================
5957 //==============================================================================
5959 static int VGrid (Draw_Interpretor& /*theDI*/,
5960 Standard_Integer theArgNb,
5961 const char** theArgVec)
5963 Handle(V3d_View) aView = ViewerTest::CurrentView();
5964 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5965 if (aView.IsNull() || aViewer.IsNull())
5967 std::cerr << "Error: no active view\n";
5971 Aspect_GridType aType = aViewer->GridType();
5972 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5973 Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY;
5974 Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0;
5975 bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false;
5976 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5977 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5979 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5981 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5985 else if (anArgIter + 1 < theArgNb
5986 && anArg == "-type")
5988 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5989 anArgNext.LowerCase();
5990 if (anArgNext == "r"
5991 || anArgNext == "rect"
5992 || anArgNext == "rectangular")
5994 aType = Aspect_GT_Rectangular;
5996 else if (anArgNext == "c"
5997 || anArgNext == "circ"
5998 || anArgNext == "circular")
6000 aType = Aspect_GT_Circular;
6004 std::cout << "Syntax error at '" << anArgNext << "'\n";
6008 else if (anArgIter + 1 < theArgNb
6009 && anArg == "-mode")
6011 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
6012 anArgNext.LowerCase();
6013 if (anArgNext == "l"
6014 || anArgNext == "line"
6015 || anArgNext == "lines")
6017 aMode = Aspect_GDM_Lines;
6019 else if (anArgNext == "p"
6020 || anArgNext == "point"
6021 || anArgNext == "points")
6023 aMode = Aspect_GDM_Points;
6027 std::cout << "Syntax error at '" << anArgNext << "'\n";
6031 else if (anArgIter + 2 < theArgNb
6032 && (anArg == "-origin"
6033 || anArg == "-orig"))
6036 aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6037 Draw::Atof (theArgVec[anArgIter + 2]));
6040 else if (anArgIter + 2 < theArgNb
6041 && anArg == "-step")
6044 aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6045 Draw::Atof (theArgVec[anArgIter + 2]));
6046 if (aNewStepXY.x() <= 0.0
6047 || aNewStepXY.y() <= 0.0)
6049 std::cout << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
6054 else if (anArgIter + 1 < theArgNb
6055 && (anArg == "-angle"
6056 || anArg == "-rotangle"
6057 || anArg == "-rotationangle"))
6060 aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]);
6062 else if (anArgIter + 1 < theArgNb
6063 && (anArg == "-zoffset"
6067 aNewZOffset = Draw::Atof (theArgVec[++anArgIter]);
6069 else if (anArgIter + 1 < theArgNb
6070 && anArg == "-radius")
6074 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0);
6075 if (aNewStepXY.x() <= 0.0)
6077 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'\n";
6081 else if (anArgIter + 2 < theArgNb
6082 && anArg == "-size")
6085 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6086 Draw::Atof (theArgVec[anArgIter + 2]));
6087 if (aNewStepXY.x() <= 0.0
6088 || aNewStepXY.y() <= 0.0)
6090 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
6095 else if (anArg == "r"
6097 || anArg == "rectangular")
6099 aType = Aspect_GT_Rectangular;
6101 else if (anArg == "c"
6103 || anArg == "circular")
6105 aType = Aspect_GT_Circular;
6107 else if (anArg == "l"
6109 || anArg == "lines")
6111 aMode = Aspect_GDM_Lines;
6113 else if (anArg == "p"
6115 || anArg == "points")
6117 aMode = Aspect_GDM_Points;
6119 else if (anArgIter + 1 >= theArgNb
6122 aViewer->DeactivateGrid();
6127 std::cout << "Syntax error at '" << anArg << "'\n";
6132 if (aType == Aspect_GT_Rectangular)
6134 Graphic3d_Vec2d anOrigXY, aStepXY;
6135 Standard_Real aRotAngle = 0.0;
6136 aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
6139 anOrigXY = aNewOriginXY;
6143 aStepXY = aNewStepXY;
6147 aRotAngle = aNewRotAngle;
6149 aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
6150 if (hasSize || hasZOffset)
6152 Graphic3d_Vec3d aSize;
6153 aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
6156 aSize.x() = aNewSizeXY.x();
6157 aSize.y() = aNewSizeXY.y();
6161 aSize.z() = aNewZOffset;
6163 aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
6166 else if (aType == Aspect_GT_Circular)
6168 Graphic3d_Vec2d anOrigXY;
6169 Standard_Real aRadiusStep;
6170 Standard_Integer aDivisionNumber;
6171 Standard_Real aRotAngle = 0.0;
6172 aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6175 anOrigXY = aNewOriginXY;
6179 aRadiusStep = aNewStepXY[0];
6180 aDivisionNumber = (int )aNewStepXY[1];
6181 if (aDivisionNumber < 1)
6183 std::cout << "Syntax error: invalid division number '" << aNewStepXY[1] << "'\n";
6189 aRotAngle = aNewRotAngle;
6192 aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6193 if (hasSize || hasZOffset)
6195 Standard_Real aRadius = 0.0, aZOffset = 0.0;
6196 aViewer->CircularGridGraphicValues (aRadius, aZOffset);
6199 aRadius = aNewSizeXY.x();
6200 if (aNewSizeXY.y() != 0.0)
6202 std::cout << "Syntax error: circular size should be specified as radius\n";
6208 aZOffset = aNewZOffset;
6210 aViewer->SetCircularGridGraphicValues (aRadius, aZOffset);
6213 aViewer->ActivateGrid (aType, aMode);
6217 //==============================================================================
6218 //function : VPriviledgedPlane
6220 //==============================================================================
6222 static int VPriviledgedPlane (Draw_Interpretor& theDI,
6223 Standard_Integer theArgNb,
6224 const char** theArgVec)
6226 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
6228 std::cerr << "Error: wrong number of arguments! See usage:\n";
6229 theDI.PrintHelp (theArgVec[0]);
6233 // get the active viewer
6234 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6235 if (aViewer.IsNull())
6237 std::cerr << "Error: no active viewer. Please call vinit.\n";
6243 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
6244 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
6245 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
6246 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
6247 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
6248 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
6249 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
6253 Standard_Integer anArgIdx = 1;
6254 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
6255 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
6256 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
6257 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
6258 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
6259 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
6261 gp_Ax3 aPriviledgedPlane;
6262 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
6263 gp_Dir aNorm (aNormX, aNormY, aNormZ);
6266 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
6267 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
6268 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
6269 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
6270 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
6274 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
6277 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
6282 //==============================================================================
6283 //function : VConvert
6285 //==============================================================================
6287 static int VConvert (Draw_Interpretor& theDI,
6288 Standard_Integer theArgNb,
6289 const char** theArgVec)
6291 // get the active view
6292 Handle(V3d_View) aView = ViewerTest::CurrentView();
6295 std::cerr << "Error: no active view. Please call vinit.\n";
6299 enum { Model, Ray, View, Window, Grid } aMode = Model;
6301 // access coordinate arguments
6302 TColStd_SequenceOfReal aCoord;
6303 Standard_Integer anArgIdx = 1;
6304 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
6306 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6307 if (!anArg.IsRealValue())
6311 aCoord.Append (anArg.RealValue());
6314 // non-numeric argument too early
6315 if (aCoord.IsEmpty())
6317 std::cerr << "Error: wrong number of arguments! See usage:\n";
6318 theDI.PrintHelp (theArgVec[0]);
6322 // collect all other arguments and options
6323 for (; anArgIdx < theArgNb; ++anArgIdx)
6325 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6327 if (anArg == "window") aMode = Window;
6328 else if (anArg == "view") aMode = View;
6329 else if (anArg == "grid") aMode = Grid;
6330 else if (anArg == "ray") aMode = Ray;
6333 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
6334 theDI.PrintHelp (theArgVec[0]);
6339 // complete input checks
6340 if ((aCoord.Length() == 1 && theArgNb > 3) ||
6341 (aCoord.Length() == 2 && theArgNb > 4) ||
6342 (aCoord.Length() == 3 && theArgNb > 5))
6344 std::cerr << "Error: wrong number of arguments! See usage:\n";
6345 theDI.PrintHelp (theArgVec[0]);
6349 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
6350 Standard_Integer aXYp[2] = {0, 0};
6352 // convert one-dimensional coordinate
6353 if (aCoord.Length() == 1)
6357 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
6358 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
6360 std::cerr << "Error: wrong arguments! See usage:\n";
6361 theDI.PrintHelp (theArgVec[0]);
6366 // convert 2D coordinates from projection or view reference space
6367 if (aCoord.Length() == 2)
6372 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6373 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6377 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
6378 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
6382 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
6383 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6387 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6388 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
6389 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6393 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
6394 (Standard_Integer) aCoord (2),
6395 aXYZ[0], aXYZ[1], aXYZ[2],
6396 aXYZ[3], aXYZ[4], aXYZ[5]);
6397 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6401 std::cerr << "Error: wrong arguments! See usage:\n";
6402 theDI.PrintHelp (theArgVec[0]);
6407 // convert 3D coordinates from view reference space
6408 else if (aCoord.Length() == 3)
6413 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
6414 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6418 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
6419 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6423 std::cerr << "Error: wrong arguments! See usage:\n";
6424 theDI.PrintHelp (theArgVec[0]);
6432 //==============================================================================
6435 //==============================================================================
6437 static int VFps (Draw_Interpretor& theDI,
6438 Standard_Integer theArgNb,
6439 const char** theArgVec)
6441 // get the active view
6442 Handle(V3d_View) aView = ViewerTest::CurrentView();
6445 std::cerr << "No active view. Please call vinit.\n";
6449 Standard_Integer aFramesNb = -1;
6450 Standard_Real aDuration = -1.0;
6451 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6453 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6456 && anArgIter + 1 < theArgNb
6457 && (anArg == "-duration"
6459 || anArg == "-time"))
6461 aDuration = Draw::Atof (theArgVec[++anArgIter]);
6463 else if (aFramesNb < 0
6464 && anArg.IsIntegerValue())
6466 aFramesNb = anArg.IntegerValue();
6469 std::cerr << "Syntax error at '" << anArg << "'\n";
6475 std::cerr << "Syntax error at '" << anArg << "'\n";
6479 if (aFramesNb < 0 && aDuration < 0.0)
6484 // the time is meaningless for first call
6485 // due to async OpenGl rendering
6488 // redraw view in loop to estimate average values
6491 Standard_Integer aFrameIter = 1;
6492 for (;; ++aFrameIter)
6496 && aFrameIter >= aFramesNb)
6498 && aTimer.ElapsedTime() >= aDuration))
6505 const Standard_Real aTime = aTimer.ElapsedTime();
6506 aTimer.OSD_Chronometer::Show (aCpu);
6508 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
6509 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
6511 // return statistics
6512 theDI << "FPS: " << aFpsAver << "\n"
6513 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
6515 // compute additional statistics in ray-tracing mode
6516 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
6517 if (aParams.Method == Graphic3d_RM_RAYTRACING)
6519 Graphic3d_Vec2i aWinSize (0, 0);
6520 aView->Window()->Size (aWinSize.x(), aWinSize.y());
6522 // 1 shadow ray and 1 secondary ray pew each bounce
6523 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
6524 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
6530 //! Auxiliary function for parsing glsl dump level argument.
6531 static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
6532 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
6534 TCollection_AsciiString aTypeStr (theArg);
6535 aTypeStr.LowerCase();
6536 if (aTypeStr == "off"
6539 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6541 else if (aTypeStr == "short")
6543 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
6545 else if (aTypeStr == "full"
6548 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6552 return Standard_False;
6554 return Standard_True;
6557 //==============================================================================
6558 //function : VGlDebug
6560 //==============================================================================
6562 static int VGlDebug (Draw_Interpretor& theDI,
6563 Standard_Integer theArgNb,
6564 const char** theArgVec)
6566 Handle(OpenGl_GraphicDriver) aDriver;
6567 Handle(V3d_View) aView = ViewerTest::CurrentView();
6568 if (!aView.IsNull())
6570 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
6572 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
6573 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
6577 TCollection_AsciiString aDebActive, aSyncActive;
6584 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
6585 "GL_ARB_debug_output");
6586 aDebActive = isActive ? " (active)" : " (inactive)";
6589 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
6590 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
6594 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
6595 + "glslSourceCode: "
6596 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
6598 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
6602 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
6603 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
6604 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
6605 << aGlslCodeDebugStatus
6606 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
6610 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6612 Standard_CString anArg = theArgVec[anArgIter];
6613 TCollection_AsciiString anArgCase (anArg);
6614 anArgCase.LowerCase();
6615 Standard_Boolean toEnableDebug = Standard_True;
6616 if (anArgCase == "-glsl"
6617 || anArgCase == "-glslwarn"
6618 || anArgCase == "-glslwarns"
6619 || anArgCase == "-glslwarnings")
6621 Standard_Boolean toShowWarns = Standard_True;
6622 if (++anArgIter < theArgNb
6623 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
6627 aDefCaps->glslWarnings = toShowWarns;
6630 aCaps->glslWarnings = toShowWarns;
6633 else if (anArgCase == "-extra"
6634 || anArgCase == "-extramsg"
6635 || anArgCase == "-extramessages")
6637 Standard_Boolean toShow = Standard_True;
6638 if (++anArgIter < theArgNb
6639 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
6643 aDefCaps->suppressExtraMsg = !toShow;
6646 aCaps->suppressExtraMsg = !toShow;
6649 else if (anArgCase == "-noextra"
6650 || anArgCase == "-noextramsg"
6651 || anArgCase == "-noextramessages")
6653 Standard_Boolean toSuppress = Standard_True;
6654 if (++anArgIter < theArgNb
6655 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
6659 aDefCaps->suppressExtraMsg = toSuppress;
6662 aCaps->suppressExtraMsg = toSuppress;
6665 else if (anArgCase == "-sync")
6667 Standard_Boolean toSync = Standard_True;
6668 if (++anArgIter < theArgNb
6669 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
6673 aDefCaps->contextSyncDebug = toSync;
6676 aDefCaps->contextDebug = Standard_True;
6679 else if (anArgCase == "-glslsourcecode"
6680 || anArgCase == "-glslcode")
6682 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6683 if (++anArgIter < theArgNb
6684 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
6688 aDefCaps->glslDumpLevel = aGslsDumpLevel;
6691 aCaps->glslDumpLevel = aGslsDumpLevel;
6694 else if (anArgCase == "-debug")
6696 if (++anArgIter < theArgNb
6697 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
6701 aDefCaps->contextDebug = toEnableDebug;
6703 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
6704 && (anArgIter + 1 == theArgNb))
6706 // simple alias to turn on almost everything
6707 aDefCaps->contextDebug = toEnableDebug;
6708 aDefCaps->contextSyncDebug = toEnableDebug;
6709 aDefCaps->glslWarnings = toEnableDebug;
6712 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6714 aDefCaps->suppressExtraMsg = !toEnableDebug;
6717 aCaps->contextDebug = toEnableDebug;
6718 aCaps->contextSyncDebug = toEnableDebug;
6719 aCaps->glslWarnings = toEnableDebug;
6722 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6724 aCaps->suppressExtraMsg = !toEnableDebug;
6729 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
6737 //==============================================================================
6740 //==============================================================================
6742 static int VVbo (Draw_Interpretor& theDI,
6743 Standard_Integer theArgNb,
6744 const char** theArgVec)
6746 const Standard_Boolean toSet = (theArgNb > 1);
6747 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
6750 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
6754 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6755 if (aContextAIS.IsNull())
6759 std::cerr << "No active view!\n";
6763 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
6764 if (!aDriver.IsNull())
6768 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
6772 aDriver->ChangeOptions().vboDisable = toUseVbo;
6779 //==============================================================================
6782 //==============================================================================
6784 static int VCaps (Draw_Interpretor& theDI,
6785 Standard_Integer theArgNb,
6786 const char** theArgVec)
6788 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
6789 Handle(OpenGl_GraphicDriver) aDriver;
6790 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6791 if (!aContext.IsNull())
6793 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
6794 aCaps = &aDriver->ChangeOptions();
6799 theDI << "sRGB: " << (aCaps->sRGBDisable ? "0" : "1") << "\n";
6800 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
6801 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
6802 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
6803 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
6804 theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n";
6805 theDI << "VSync: " << aCaps->swapInterval << "\n";
6806 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
6807 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
6808 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
6809 theDI << "NoExt:" << (aCaps->contextNoExtensions ? "1" : "0") << "\n";
6810 theDI << "MaxVersion:" << aCaps->contextMajorVersionUpper << "." << aCaps->contextMinorVersionUpper << "\n";
6814 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6815 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6817 Standard_CString anArg = theArgVec[anArgIter];
6818 TCollection_AsciiString anArgCase (anArg);
6819 anArgCase.LowerCase();
6820 if (anUpdateTool.parseRedrawMode (anArg))
6824 else if (anArgCase == "-vsync"
6825 || anArgCase == "-swapinterval")
6827 Standard_Boolean toEnable = Standard_True;
6828 if (++anArgIter < theArgNb
6829 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6833 aCaps->swapInterval = toEnable;
6835 else if (anArgCase == "-ffp")
6837 Standard_Boolean toEnable = Standard_True;
6838 if (++anArgIter < theArgNb
6839 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6843 aCaps->ffpEnable = toEnable;
6845 else if (anArgCase == "-polygonmode")
6847 Standard_Boolean toEnable = Standard_True;
6848 if (++anArgIter < theArgNb
6849 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6853 aCaps->usePolygonMode = toEnable;
6855 else if (anArgCase == "-srgb")
6857 Standard_Boolean toEnable = Standard_True;
6858 if (++anArgIter < theArgNb
6859 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6863 aCaps->sRGBDisable = !toEnable;
6865 else if (anArgCase == "-vbo")
6867 Standard_Boolean toEnable = Standard_True;
6868 if (++anArgIter < theArgNb
6869 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6873 aCaps->vboDisable = !toEnable;
6875 else if (anArgCase == "-sprite"
6876 || anArgCase == "-sprites")
6878 Standard_Boolean toEnable = Standard_True;
6879 if (++anArgIter < theArgNb
6880 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6884 aCaps->pntSpritesDisable = !toEnable;
6886 else if (anArgCase == "-softmode")
6888 Standard_Boolean toEnable = Standard_True;
6889 if (++anArgIter < theArgNb
6890 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6894 aCaps->contextNoAccel = toEnable;
6896 else if (anArgCase == "-winbuffer"
6897 || anArgCase == "-windowbuffer"
6898 || anArgCase == "-usewinbuffer"
6899 || anArgCase == "-usewindowbuffer"
6900 || anArgCase == "-usesystembuffer")
6902 Standard_Boolean toEnable = Standard_True;
6903 if (++anArgIter < theArgNb
6904 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6908 aCaps->useSystemBuffer = toEnable;
6910 else if (anArgCase == "-accel"
6911 || anArgCase == "-acceleration")
6913 Standard_Boolean toEnable = Standard_True;
6914 if (++anArgIter < theArgNb
6915 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6919 aCaps->contextNoAccel = !toEnable;
6921 else if (anArgCase == "-compat"
6922 || anArgCase == "-compatprofile"
6923 || anArgCase == "-compatible"
6924 || anArgCase == "-compatibleprofile")
6926 Standard_Boolean toEnable = Standard_True;
6927 if (++anArgIter < theArgNb
6928 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6932 aCaps->contextCompatible = toEnable;
6933 if (!aCaps->contextCompatible)
6935 aCaps->ffpEnable = Standard_False;
6938 else if (anArgCase == "-core"
6939 || anArgCase == "-coreprofile")
6941 Standard_Boolean toEnable = Standard_True;
6942 if (++anArgIter < theArgNb
6943 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6947 aCaps->contextCompatible = !toEnable;
6948 if (!aCaps->contextCompatible)
6950 aCaps->ffpEnable = Standard_False;
6953 else if (anArgCase == "-stereo"
6954 || anArgCase == "-quadbuffer")
6956 Standard_Boolean toEnable = Standard_True;
6957 if (++anArgIter < theArgNb
6958 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6962 aCaps->contextStereo = toEnable;
6964 else if (anArgCase == "-noext"
6965 || anArgCase == "-noextensions"
6966 || anArgCase == "-noextension")
6968 Standard_Boolean toDisable = Standard_True;
6969 if (++anArgIter < theArgNb
6970 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
6974 aCaps->contextNoExtensions = toDisable;
6976 else if (anArgCase == "-maxversion"
6977 || anArgCase == "-upperversion"
6978 || anArgCase == "-limitversion")
6980 Standard_Integer aVer[2] = { -2, -1 };
6981 for (Standard_Integer aValIter = 0; aValIter < 2; ++aValIter)
6983 if (anArgIter + 1 < theArgNb)
6985 const TCollection_AsciiString aStr (theArgVec[anArgIter + 1]);
6986 if (aStr.IsIntegerValue())
6988 aVer[aValIter] = aStr.IntegerValue();
6996 std::cout << "Syntax error at '" << anArgCase << "'\n";
6999 aCaps->contextMajorVersionUpper = aVer[0];
7000 aCaps->contextMinorVersionUpper = aVer[1];
7004 std::cout << "Error: unknown argument '" << anArg << "'\n";
7008 if (aCaps != &ViewerTest_myDefaultCaps)
7010 ViewerTest_myDefaultCaps = *aCaps;
7015 //==============================================================================
7016 //function : VMemGpu
7018 //==============================================================================
7020 static int VMemGpu (Draw_Interpretor& theDI,
7021 Standard_Integer theArgNb,
7022 const char** theArgVec)
7025 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
7026 if (aContextAIS.IsNull())
7028 std::cerr << "No active view. Please call vinit.\n";
7032 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
7033 if (aDriver.IsNull())
7035 std::cerr << "Graphic driver not available.\n";
7039 Standard_Size aFreeBytes = 0;
7040 TCollection_AsciiString anInfo;
7041 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
7043 std::cerr << "Information not available.\n";
7047 if (theArgNb > 1 && *theArgVec[1] == 'f')
7049 theDI << Standard_Real (aFreeBytes);
7059 // ==============================================================================
7060 // function : VReadPixel
7062 // ==============================================================================
7063 static int VReadPixel (Draw_Interpretor& theDI,
7064 Standard_Integer theArgNb,
7065 const char** theArgVec)
7067 // get the active view
7068 Handle(V3d_View) aView = ViewerTest::CurrentView();
7071 std::cerr << "No active view. Please call vinit.\n";
7074 else if (theArgNb < 3)
7076 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
7080 Image_Format aFormat = Image_Format_RGBA;
7081 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
7083 Standard_Integer aWidth, aHeight;
7084 aView->Window()->Size (aWidth, aHeight);
7085 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
7086 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
7087 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
7089 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
7093 bool toShowName = false, toShowHls = false, toShowHex = false, toShow_sRGB = false;
7094 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
7096 TCollection_AsciiString aParam (theArgVec[anIter]);
7098 if (aParam == "-rgb"
7100 || aParam == "-srgb"
7101 || aParam == "srgb")
7103 aFormat = Image_Format_RGB;
7104 aBufferType = Graphic3d_BT_RGB;
7105 toShow_sRGB = aParam == "-srgb" || aParam == "srgb";
7107 else if (aParam == "-hls"
7110 aFormat = Image_Format_RGB;
7111 aBufferType = Graphic3d_BT_RGB;
7112 toShowHls = Standard_True;
7114 else if (aParam == "-rgbf"
7115 || aParam == "rgbf")
7117 aFormat = Image_Format_RGBF;
7118 aBufferType = Graphic3d_BT_RGB;
7120 else if (aParam == "-rgba"
7122 || aParam == "-srgba"
7123 || aParam == "srgba")
7125 aFormat = Image_Format_RGBA;
7126 aBufferType = Graphic3d_BT_RGBA;
7127 toShow_sRGB = aParam == "-srgba" || aParam == "srgba";
7129 else if (aParam == "-rgbaf"
7130 || aParam == "rgbaf")
7132 aFormat = Image_Format_RGBAF;
7133 aBufferType = Graphic3d_BT_RGBA;
7135 else if (aParam == "-depth"
7136 || aParam == "depth")
7138 aFormat = Image_Format_GrayF;
7139 aBufferType = Graphic3d_BT_Depth;
7141 else if (aParam == "-name"
7142 || aParam == "name")
7144 toShowName = Standard_True;
7146 else if (aParam == "-hex"
7149 toShowHex = Standard_True;
7153 std::cout << "Syntax error at '" << aParam << "'\n";
7158 Image_PixMap anImage;
7159 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
7161 std::cerr << "Image allocation failed\n";
7164 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
7166 std::cerr << "Image dump failed\n";
7170 // redirect possible warning messages that could have been added by ToPixMap
7171 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
7172 // contaminate result of the command
7173 Standard_CString aWarnLog = theDI.Result();
7174 if (aWarnLog != NULL && aWarnLog[0] != '\0')
7176 std::cout << aWarnLog << std::endl;
7180 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY, true);
7183 if (aBufferType == Graphic3d_BT_RGBA)
7185 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
7189 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
7194 if (aBufferType == Graphic3d_BT_RGBA)
7196 theDI << Quantity_ColorRGBA::ColorToHex (aColor);
7200 theDI << Quantity_Color::ColorToHex (aColor.GetRGB());
7205 switch (aBufferType)
7208 case Graphic3d_BT_RGB:
7212 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
7214 else if (toShow_sRGB)
7216 const Graphic3d_Vec4 aColor_sRGB = Quantity_ColorRGBA::Convert_LinearRGB_To_sRGB ((Graphic3d_Vec4 )aColor);
7217 theDI << aColor_sRGB.r() << " " << aColor_sRGB.g() << " " << aColor_sRGB.b();
7221 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
7225 case Graphic3d_BT_RGBA:
7227 const Graphic3d_Vec4 aVec4 = toShow_sRGB ? Quantity_ColorRGBA::Convert_LinearRGB_To_sRGB ((Graphic3d_Vec4 )aColor) : (Graphic3d_Vec4 )aColor;
7228 theDI << aVec4.r() << " " << aVec4.g() << " " << aVec4.b() << " " << aVec4.a();
7231 case Graphic3d_BT_Depth:
7233 theDI << aColor.GetRGB().Red();
7242 //! Auxiliary presentation for an image plane.
7243 class ViewerTest_ImagePrs : public AIS_InteractiveObject
7246 //! Main constructor.
7247 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
7248 const Standard_Real theWidth,
7249 const Standard_Real theHeight,
7250 const TCollection_AsciiString& theLabel)
7251 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
7255 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
7257 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
7258 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
7259 Graphic3d_MaterialAspect aMat;
7260 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
7261 aMat.SetAmbientColor (Quantity_NOC_BLACK);
7262 aMat.SetDiffuseColor (Quantity_NOC_WHITE);
7263 aMat.SetSpecularColor (Quantity_NOC_BLACK);
7264 aMat.SetEmissiveColor (Quantity_NOC_BLACK);
7265 aFillAspect->SetFrontMaterial (aMat);
7266 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
7267 aFillAspect->SetTextureMapOn();
7270 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
7271 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
7272 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
7273 myDrawer->SetTextAspect (aTextAspect);
7276 const gp_Dir aNorm (0.0, 0.0, 1.0);
7277 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
7278 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
7279 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
7280 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
7281 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
7282 myTris->AddEdge (1);
7283 myTris->AddEdge (2);
7284 myTris->AddEdge (3);
7285 myTris->AddEdge (3);
7286 myTris->AddEdge (2);
7287 myTris->AddEdge (4);
7289 myRect = new Graphic3d_ArrayOfPolylines (4);
7290 myRect->AddVertex (myTris->Vertice (1));
7291 myRect->AddVertex (myTris->Vertice (3));
7292 myRect->AddVertex (myTris->Vertice (4));
7293 myRect->AddVertex (myTris->Vertice (2));
7297 //! Returns TRUE for accepted display modes.
7298 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
7300 //! Compute presentation.
7301 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
7307 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7308 aGroup->AddPrimitiveArray (myTris);
7309 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
7310 aGroup->AddPrimitiveArray (myRect);
7311 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7316 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
7317 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7318 aGroup->AddPrimitiveArray (myRect);
7319 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7325 //! Compute selection.
7326 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
7330 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
7331 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
7332 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
7333 theSel->Add (aSensitive);
7338 Handle(Graphic3d_ArrayOfTriangles) myTris;
7339 Handle(Graphic3d_ArrayOfPolylines) myRect;
7340 TCollection_AsciiString myLabel;
7341 Standard_Real myWidth;
7342 Standard_Real myHeight;
7345 //==============================================================================
7346 //function : VDiffImage
7347 //purpose : The draw-command compares two images.
7348 //==============================================================================
7350 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
7354 std::cout << "Syntax error: not enough arguments.\n";
7358 Standard_Integer anArgIter = 1;
7359 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
7360 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
7361 TCollection_AsciiString aDiffImagePath;
7362 Standard_Real aTolColor = -1.0;
7363 Standard_Integer toBlackWhite = -1;
7364 Standard_Integer isBorderFilterOn = -1;
7365 Standard_Boolean isOldSyntax = Standard_False;
7366 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
7367 for (; anArgIter < theArgNb; ++anArgIter)
7369 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7371 if (anArgIter + 1 < theArgNb
7372 && (anArg == "-toleranceofcolor"
7373 || anArg == "-tolerancecolor"
7374 || anArg == "-tolerance"
7375 || anArg == "-toler"))
7377 aTolColor = Atof (theArgVec[++anArgIter]);
7378 if (aTolColor < 0.0 || aTolColor > 1.0)
7380 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7384 else if (anArg == "-blackwhite")
7386 Standard_Boolean toEnable = Standard_True;
7387 if (anArgIter + 1 < theArgNb
7388 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7392 toBlackWhite = toEnable ? 1 : 0;
7394 else if (anArg == "-borderfilter")
7396 Standard_Boolean toEnable = Standard_True;
7397 if (anArgIter + 1 < theArgNb
7398 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7402 isBorderFilterOn = toEnable ? 1 : 0;
7404 else if (anArg == "-exitonclose")
7406 ViewerTest_EventManager::ToExitOnCloseView() = true;
7407 if (anArgIter + 1 < theArgNb
7408 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToExitOnCloseView()))
7413 else if (anArg == "-closeonescape"
7414 || anArg == "-closeonesc")
7416 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
7417 if (anArgIter + 1 < theArgNb
7418 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
7423 else if (anArgIter + 3 < theArgNb
7424 && anArg == "-display")
7426 aViewName = theArgVec[++anArgIter];
7427 aPrsNameRef = theArgVec[++anArgIter];
7428 aPrsNameNew = theArgVec[++anArgIter];
7429 if (anArgIter + 1 < theArgNb
7430 && *theArgVec[anArgIter + 1] != '-')
7432 aPrsNameDiff = theArgVec[++anArgIter];
7435 else if (aTolColor < 0.0
7436 && anArg.IsRealValue())
7438 isOldSyntax = Standard_True;
7439 aTolColor = anArg.RealValue();
7440 if (aTolColor < 0.0 || aTolColor > 1.0)
7442 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7446 else if (isOldSyntax
7447 && toBlackWhite == -1
7448 && (anArg == "0" || anArg == "1"))
7450 toBlackWhite = anArg == "1" ? 1 : 0;
7452 else if (isOldSyntax
7453 && isBorderFilterOn == -1
7454 && (anArg == "0" || anArg == "1"))
7456 isBorderFilterOn = anArg == "1" ? 1 : 0;
7458 else if (aDiffImagePath.IsEmpty())
7460 aDiffImagePath = theArgVec[anArgIter];
7464 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7469 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
7470 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
7471 if (!anImgRef->Load (anImgPathRef))
7473 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
7476 if (!anImgNew->Load (anImgPathNew))
7478 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
7482 // compare the images
7483 Image_Diff aComparer;
7484 Standard_Integer aDiffColorsNb = -1;
7485 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
7487 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
7488 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
7489 aDiffColorsNb = aComparer.Compare();
7490 theDI << aDiffColorsNb << "\n";
7493 // save image of difference
7494 Handle(Image_AlienPixMap) aDiff;
7495 if (aDiffColorsNb > 0
7496 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
7498 aDiff = new Image_AlienPixMap();
7499 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
7501 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
7504 aComparer.SaveDiffImage (*aDiff);
7505 if (!aDiffImagePath.IsEmpty()
7506 && !aDiff->Save (aDiffImagePath))
7508 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
7513 if (aViewName.IsEmpty())
7518 ViewerTest_Names aViewNames (aViewName);
7519 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
7521 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
7522 theDI.Eval (aCommand.ToCString());
7525 Standard_Integer aPxLeft = 0;
7526 Standard_Integer aPxTop = 0;
7527 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
7528 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
7529 ? int(anImgRef->SizeY() * 2)
7530 : int(anImgRef->SizeY());
7531 TCollection_AsciiString aDisplayName;
7532 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
7533 aViewName, aDisplayName);
7535 Standard_Real aRatio = anImgRef->Ratio();
7536 Standard_Real aSizeX = 1.0;
7537 Standard_Real aSizeY = aSizeX / aRatio;
7539 OSD_Path aPath (anImgPathRef);
7540 TCollection_AsciiString aLabelRef;
7541 if (!aPath.Name().IsEmpty())
7543 aLabelRef = aPath.Name() + aPath.Extension();
7545 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
7547 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
7549 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
7550 anImgRefPrs->SetLocalTransformation (aTrsfRef);
7551 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
7554 OSD_Path aPath (anImgPathNew);
7555 TCollection_AsciiString aLabelNew;
7556 if (!aPath.Name().IsEmpty())
7558 aLabelNew = aPath.Name() + aPath.Extension();
7560 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
7562 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
7564 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
7565 anImgNewPrs->SetLocalTransformation (aTrsfRef);
7566 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
7568 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
7569 if (!aDiff.IsNull())
7571 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
7573 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
7574 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
7576 if (!aPrsNameDiff.IsEmpty())
7578 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
7580 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
7581 ViewerTest::CurrentView()->FitAll();
7585 //=======================================================================
7586 //function : VSelect
7587 //purpose : Emulates different types of selection by mouse:
7588 // 1) single click selection
7589 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
7590 // 3) selection with polygon having corners at
7591 // pixel positions (x1,y1),...,(xn,yn)
7592 // 4) any of these selections with shift button pressed
7593 //=======================================================================
7594 static Standard_Integer VSelect (Draw_Interpretor& ,
7595 Standard_Integer theNbArgs,
7596 const char** theArgVec)
7598 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7601 std::cout << "Error: no active View\n";
7605 NCollection_Sequence<Graphic3d_Vec2i> aPnts;
7606 bool isShiftSelection = false, toAllowOverlap = false;
7607 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7609 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7611 if (anArg == "-allowoverlap")
7613 toAllowOverlap = true;
7614 if (anArgIter + 1 < theNbArgs
7615 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toAllowOverlap))
7620 else if (anArgIter + 1 < theNbArgs
7621 && anArg.IsIntegerValue()
7622 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
7624 const TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
7625 aPnts.Append (Graphic3d_Vec2i (anArg.IntegerValue(), anArgNext.IntegerValue()));
7627 else if (anArgIter + 1 == theNbArgs
7628 && anArg.IsIntegerValue())
7630 isShiftSelection = anArg.IntegerValue() == 1;
7634 std::cout << "Syntax error at '" << anArg << "'\n";
7639 && aPnts.Length() != 2)
7641 std::cout << "Syntax error: -allowoverlap key is applied only for rectangle selection\n";
7646 aCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
7649 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
7650 if (aPnts.IsEmpty())
7652 if (isShiftSelection)
7654 aCtx->ShiftSelect (false);
7658 aCtx->Select (false);
7660 aCtx->CurrentViewer()->Invalidate();
7662 else if (aPnts.Length() == 2)
7665 && aPnts.First().y() < aPnts.Last().y())
7667 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7669 else if (!toAllowOverlap
7670 && aPnts.First().y() > aPnts.Last().y())
7672 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7674 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
7678 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
7680 aCurrentEventManager->FlushViewEvents (aCtx, ViewerTest::CurrentView(), true);
7684 //=======================================================================
7685 //function : VMoveTo
7686 //purpose : Emulates cursor movement to defined pixel position
7687 //=======================================================================
7688 static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
7689 Standard_Integer theNbArgs,
7690 const char** theArgVec)
7692 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
7693 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
7694 if (aContext.IsNull())
7696 std::cout << "Error: no active View\n";
7700 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
7701 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7703 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
7704 anArgStr.LowerCase();
7705 if (anArgStr == "-reset"
7706 || anArgStr == "-clear")
7708 if (anArgIter + 1 < theNbArgs)
7710 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
7714 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
7715 && aContext->CurrentViewer()->GridEcho();
7718 aContext->CurrentViewer()->HideGridEcho (aView);
7720 if (aContext->ClearDetected() || toEchoGrid)
7722 aContext->CurrentViewer()->RedrawImmediate();
7726 else if (aMousePos.x() == IntegerLast()
7727 && anArgStr.IsIntegerValue())
7729 aMousePos.x() = anArgStr.IntegerValue();
7731 else if (aMousePos.y() == IntegerLast()
7732 && anArgStr.IsIntegerValue())
7734 aMousePos.y() = anArgStr.IntegerValue();
7738 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7743 if (aMousePos.x() == IntegerLast()
7744 || aMousePos.y() == IntegerLast())
7746 std::cout << "Syntax error: wrong number of arguments\n";
7750 ViewerTest::CurrentEventManager()->ResetPreviousMoveTo();
7751 ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false);
7752 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
7754 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
7755 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
7756 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
7758 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
7760 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
7764 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
7770 //! Global map storing all animations registered in ViewerTest.
7771 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
7773 //! The animation calling the Draw Harness command.
7774 class ViewerTest_AnimationProc : public AIS_Animation
7778 //! Main constructor.
7779 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
7780 Draw_Interpretor* theDI,
7781 const TCollection_AsciiString& theCommand)
7782 : AIS_Animation (theAnimationName),
7784 myCommand (theCommand)
7791 //! Evaluate the command.
7792 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
7794 TCollection_AsciiString aCmd = myCommand;
7795 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
7796 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
7797 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
7798 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
7799 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
7800 myDrawInter->Eval (aCmd.ToCString());
7803 //! Find the keyword in the command and replace it with value.
7804 //! @return the position of the keyword to pass value
7805 void replace (TCollection_AsciiString& theCmd,
7806 const TCollection_AsciiString& theKey,
7807 const TCollection_AsciiString& theVal)
7809 TCollection_AsciiString aCmd (theCmd);
7811 const Standard_Integer aPos = aCmd.Search (theKey);
7817 TCollection_AsciiString aPart1, aPart2;
7818 Standard_Integer aPart1To = aPos - 1;
7820 && aPart1To <= theCmd.Length())
7822 aPart1 = theCmd.SubString (1, aPart1To);
7825 Standard_Integer aPart2From = aPos + theKey.Length();
7827 && aPart2From <= theCmd.Length())
7829 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
7832 theCmd = aPart1 + theVal + aPart2;
7837 Draw_Interpretor* myDrawInter;
7838 TCollection_AsciiString myCommand;
7842 //! Replace the animation with the new one.
7843 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
7844 Handle(AIS_Animation)& theAnimation,
7845 const Handle(AIS_Animation)& theAnimationNew)
7847 theAnimationNew->CopyFrom (theAnimation);
7848 if (!theParentAnimation.IsNull())
7850 theParentAnimation->Replace (theAnimation, theAnimationNew);
7854 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
7855 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
7857 theAnimation = theAnimationNew;
7860 //! Parse the point.
7861 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
7863 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
7864 if (!anXYZ[0].IsRealValue()
7865 || !anXYZ[1].IsRealValue()
7866 || !anXYZ[2].IsRealValue())
7868 return Standard_False;
7871 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
7872 return Standard_True;
7875 //! Parse the quaternion.
7876 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
7878 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
7879 if (!anXYZW[0].IsRealValue()
7880 || !anXYZW[1].IsRealValue()
7881 || !anXYZW[2].IsRealValue()
7882 || !anXYZW[3].IsRealValue())
7884 return Standard_False;
7887 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
7888 return Standard_True;
7891 //! Auxiliary class for flipping image upside-down.
7896 //! Empty constructor.
7897 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
7899 //! Perform flipping.
7900 Standard_Boolean FlipY (Image_PixMap& theImage)
7902 if (theImage.IsEmpty()
7903 || theImage.SizeX() == 0
7904 || theImage.SizeY() == 0)
7906 return Standard_False;
7909 const Standard_Size aRowSize = theImage.SizeRowBytes();
7910 if (myTmp.Size() < aRowSize
7911 && !myTmp.Allocate (aRowSize))
7913 return Standard_False;
7916 // for odd height middle row should be left as is
7917 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
7918 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
7920 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
7921 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
7922 memcpy (myTmp.ChangeData(), aTop, aRowSize);
7923 memcpy (aTop, aBot, aRowSize);
7924 memcpy (aBot, myTmp.Data(), aRowSize);
7926 return Standard_True;
7930 NCollection_Buffer myTmp;
7935 //=================================================================================================
7936 //function : VViewParams
7937 //purpose : Gets or sets AIS View characteristics
7938 //=================================================================================================
7939 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7941 Handle(V3d_View) aView = ViewerTest::CurrentView();
7944 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
7948 Standard_Boolean toSetProj = Standard_False;
7949 Standard_Boolean toSetUp = Standard_False;
7950 Standard_Boolean toSetAt = Standard_False;
7951 Standard_Boolean toSetEye = Standard_False;
7952 Standard_Boolean toSetScale = Standard_False;
7953 Standard_Boolean toSetSize = Standard_False;
7954 Standard_Boolean toSetCenter2d = Standard_False;
7955 Standard_Real aViewScale = aView->Scale();
7956 Standard_Real aViewSize = 1.0;
7957 Graphic3d_Vec2i aCenter2d;
7958 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
7959 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
7960 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
7961 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
7962 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
7965 // print all of the available view parameters
7969 "Proj: %12g %12g %12g\n"
7970 "Up: %12g %12g %12g\n"
7971 "At: %12g %12g %12g\n"
7972 "Eye: %12g %12g %12g\n",
7974 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7975 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7976 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
7977 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7982 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7983 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7985 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7987 if (anUpdateTool.parseRedrawMode (anArg))
7991 else if (anArg == "-cmd"
7992 || anArg == "-command"
7993 || anArg == "-args")
8002 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
8003 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
8004 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
8007 else if (anArg == "-scale"
8008 || anArg == "-size")
8010 if (anArgIter + 1 < theArgsNb
8011 && *theArgVec[anArgIter + 1] != '-')
8013 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
8014 if (aValueArg.IsRealValue())
8017 if (anArg == "-scale")
8019 toSetScale = Standard_True;
8020 aViewScale = aValueArg.RealValue();
8022 else if (anArg == "-size")
8024 toSetSize = Standard_True;
8025 aViewSize = aValueArg.RealValue();
8030 if (anArg == "-scale")
8032 theDi << "Scale: " << aView->Scale() << "\n";
8034 else if (anArg == "-size")
8036 Graphic3d_Vec2d aSizeXY;
8037 aView->Size (aSizeXY.x(), aSizeXY.y());
8038 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
8041 else if (anArg == "-eye"
8044 || anArg == "-proj")
8046 if (anArgIter + 3 < theArgsNb)
8049 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
8052 if (anArg == "-eye")
8054 toSetEye = Standard_True;
8057 else if (anArg == "-at")
8059 toSetAt = Standard_True;
8062 else if (anArg == "-up")
8064 toSetUp = Standard_True;
8067 else if (anArg == "-proj")
8069 toSetProj = Standard_True;
8076 if (anArg == "-eye")
8078 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
8080 else if (anArg == "-at")
8082 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
8084 else if (anArg == "-up")
8086 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
8088 else if (anArg == "-proj")
8090 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
8093 else if (anArg == "-center")
8095 if (anArgIter + 2 < theArgsNb)
8097 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
8098 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
8099 if (anX.IsIntegerValue()
8100 && anY.IsIntegerValue())
8102 toSetCenter2d = Standard_True;
8103 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
8109 std::cout << "Syntax error at '" << anArg << "'\n";
8114 // change view parameters in proper order
8117 aView->SetScale (aViewScale);
8121 aView->SetSize (aViewSize);
8125 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
8129 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
8133 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
8137 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
8141 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
8147 //==============================================================================
8148 //function : V2DMode
8150 //==============================================================================
8151 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
8153 bool is2dMode = true;
8154 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
8155 if (aV3dView.IsNull())
8157 std::cout << "Error: no active view.\n";
8160 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
8162 const TCollection_AsciiString anArg = theArgVec[anArgIt];
8163 TCollection_AsciiString anArgCase = anArg;
8164 anArgCase.LowerCase();
8165 if (anArgIt + 1 < theArgsNb
8166 && anArgCase == "-name")
8168 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
8169 TCollection_AsciiString aViewName = aViewNames.GetViewName();
8170 if (!ViewerTest_myViews.IsBound1 (aViewName))
8172 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
8175 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
8177 else if (anArgCase == "-mode")
8179 if (anArgIt + 1 < theArgsNb
8180 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
8185 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
8191 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
8196 aV3dView->SetView2DMode (is2dMode);
8200 //==============================================================================
8201 //function : VAnimation
8203 //==============================================================================
8204 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
8205 Standard_Integer theArgNb,
8206 const char** theArgVec)
8208 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
8211 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
8212 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
8214 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
8220 std::cout << "Error: no active view\n";
8224 Standard_Integer anArgIter = 1;
8225 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
8226 if (aNameArg.IsEmpty())
8228 std::cout << "Syntax error: animation name is not defined.\n";
8232 TCollection_AsciiString aNameArgLower = aNameArg;
8233 aNameArgLower.LowerCase();
8234 if (aNameArgLower == "-reset"
8235 || aNameArgLower == "-clear")
8237 ViewerTest_AnimationTimelineMap.Clear();
8240 else if (aNameArg.Value (1) == '-')
8242 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
8246 const char* aNameSplitter = "/";
8247 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
8248 if (aSplitPos == -1)
8250 aNameSplitter = ".";
8251 aSplitPos = aNameArg.Search (aNameSplitter);
8254 // find existing or create a new animation by specified name within syntax "parent.child".
8255 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
8256 for (; !aNameArg.IsEmpty();)
8258 TCollection_AsciiString aNameParent;
8259 if (aSplitPos != -1)
8261 if (aSplitPos == aNameArg.Length())
8263 std::cout << "Syntax error: animation name is not defined.\n";
8267 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
8268 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
8270 aSplitPos = aNameArg.Search (aNameSplitter);
8274 aNameParent = aNameArg;
8278 if (anAnimation.IsNull())
8280 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
8282 anAnimation = new AIS_Animation (aNameParent);
8283 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
8285 aRootAnimation = anAnimation;
8289 aParentAnimation = anAnimation;
8290 anAnimation = aParentAnimation->Find (aNameParent);
8291 if (anAnimation.IsNull())
8293 anAnimation = new AIS_Animation (aNameParent);
8294 aParentAnimation->Add (anAnimation);
8299 if (anArgIter >= theArgNb)
8301 // just print the list of children
8302 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
8304 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
8309 // animation parameters
8310 Standard_Boolean toPlay = Standard_False;
8311 Standard_Real aPlaySpeed = 1.0;
8312 Standard_Real aPlayStartTime = anAnimation->StartPts();
8313 Standard_Real aPlayDuration = anAnimation->Duration();
8314 Standard_Boolean isFreeCamera = Standard_False;
8315 Standard_Boolean isLockLoop = Standard_False;
8317 // video recording parameters
8318 TCollection_AsciiString aRecFile;
8319 Image_VideoParams aRecParams;
8321 Handle(V3d_View) aView = ViewerTest::CurrentView();
8322 for (; anArgIter < theArgNb; ++anArgIter)
8324 TCollection_AsciiString anArg (theArgVec[anArgIter]);
8327 if (anArg == "-reset"
8328 || anArg == "-clear")
8330 anAnimation->Clear();
8332 else if (anArg == "-remove"
8334 || anArg == "-delete")
8336 if (!aParentAnimation.IsNull())
8338 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
8342 aParentAnimation->Remove (anAnimation);
8346 else if (anArg == "-play")
8348 toPlay = Standard_True;
8349 if (++anArgIter < theArgNb)
8351 if (*theArgVec[anArgIter] == '-')
8356 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
8358 if (++anArgIter < theArgNb)
8360 if (*theArgVec[anArgIter] == '-')
8365 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8369 else if (anArg == "-resume")
8371 toPlay = Standard_True;
8372 aPlayStartTime = anAnimation->ElapsedTime();
8373 if (++anArgIter < theArgNb)
8375 if (*theArgVec[anArgIter] == '-')
8381 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8384 else if (anArg == "-playspeed"
8385 || anArg == "-speed")
8387 if (++anArgIter >= theArgNb)
8389 std::cout << "Syntax error at " << anArg << ".\n";
8392 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
8394 else if (anArg == "-lock"
8395 || anArg == "-lockloop"
8396 || anArg == "-playlockloop")
8398 isLockLoop = Standard_True;
8400 else if (anArg == "-freecamera"
8401 || anArg == "-playfreecamera"
8402 || anArg == "-freelook")
8404 isFreeCamera = Standard_True;
8406 // video recodring options
8407 else if (anArg == "-rec"
8408 || anArg == "-record")
8410 if (++anArgIter >= theArgNb)
8412 std::cout << "Syntax error at " << anArg << ".\n";
8416 aRecFile = theArgVec[anArgIter];
8417 if (aRecParams.FpsNum <= 0)
8419 aRecParams.FpsNum = 24;
8422 if (anArgIter + 2 < theArgNb
8423 && *theArgVec[anArgIter + 1] != '-'
8424 && *theArgVec[anArgIter + 2] != '-')
8426 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
8427 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
8428 if (aWidthArg .IsIntegerValue()
8429 && aHeightArg.IsIntegerValue())
8431 aRecParams.Width = aWidthArg .IntegerValue();
8432 aRecParams.Height = aHeightArg.IntegerValue();
8437 else if (anArg == "-fps")
8439 if (++anArgIter >= theArgNb)
8441 std::cout << "Syntax error at " << anArg << ".\n";
8445 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
8446 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
8447 if (aSplitIndex == 0)
8449 aRecParams.FpsNum = aFpsArg.IntegerValue();
8453 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
8454 aFpsArg.Split (aFpsArg.Length() - 1);
8455 const TCollection_AsciiString aNumStr = aFpsArg;
8456 aRecParams.FpsNum = aNumStr.IntegerValue();
8457 aRecParams.FpsDen = aDenStr.IntegerValue();
8458 if (aRecParams.FpsDen < 1)
8460 std::cout << "Syntax error at " << anArg << ".\n";
8465 else if (anArg == "-format")
8467 if (++anArgIter >= theArgNb)
8469 std::cout << "Syntax error at " << anArg << ".\n";
8472 aRecParams.Format = theArgVec[anArgIter];
8474 else if (anArg == "-pix_fmt"
8475 || anArg == "-pixfmt"
8476 || anArg == "-pixelformat")
8478 if (++anArgIter >= theArgNb)
8480 std::cout << "Syntax error at " << anArg << ".\n";
8483 aRecParams.PixelFormat = theArgVec[anArgIter];
8485 else if (anArg == "-codec"
8486 || anArg == "-vcodec"
8487 || anArg == "-videocodec")
8489 if (++anArgIter >= theArgNb)
8491 std::cout << "Syntax error at " << anArg << ".\n";
8494 aRecParams.VideoCodec = theArgVec[anArgIter];
8496 else if (anArg == "-crf"
8497 || anArg == "-preset"
8500 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
8501 if (++anArgIter >= theArgNb)
8503 std::cout << "Syntax error at " << anArg << ".\n";
8507 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
8509 // animation definition options
8510 else if (anArg == "-start"
8511 || anArg == "-starttime"
8512 || anArg == "-startpts")
8514 if (++anArgIter >= theArgNb)
8516 std::cout << "Syntax error at " << anArg << ".\n";
8520 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
8521 aRootAnimation->UpdateTotalDuration();
8523 else if (anArg == "-end"
8524 || anArg == "-endtime"
8525 || anArg == "-endpts")
8527 if (++anArgIter >= theArgNb)
8529 std::cout << "Syntax error at " << anArg << ".\n";
8533 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
8534 aRootAnimation->UpdateTotalDuration();
8536 else if (anArg == "-dur"
8537 || anArg == "-duration")
8539 if (++anArgIter >= theArgNb)
8541 std::cout << "Syntax error at " << anArg << ".\n";
8545 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
8546 aRootAnimation->UpdateTotalDuration();
8548 else if (anArg == "-command"
8550 || anArg == "-invoke"
8552 || anArg == "-proc")
8554 if (++anArgIter >= theArgNb)
8556 std::cout << "Syntax error at " << anArg << ".\n";
8560 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
8561 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
8563 else if (anArg == "-objecttrsf"
8564 || anArg == "-objectransformation"
8565 || anArg == "-objtransformation"
8566 || anArg == "-objtrsf"
8567 || anArg == "-object"
8570 if (++anArgIter >= theArgNb)
8572 std::cout << "Syntax error at " << anArg << ".\n";
8576 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
8577 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
8578 Handle(AIS_InteractiveObject) anObject;
8579 if (!aMapOfAIS.Find2 (anObjName, anObject))
8581 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
8585 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
8586 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
8587 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
8588 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
8589 Standard_Boolean isTrsfSet = Standard_False;
8590 Standard_Integer aTrsfArgIter = anArgIter + 1;
8591 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
8593 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
8594 aTrsfArg.LowerCase();
8595 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
8596 if (aTrsfArg.StartsWith ("-rotation")
8597 || aTrsfArg.StartsWith ("-rot"))
8599 isTrsfSet = Standard_True;
8600 if (aTrsfArgIter + 4 >= theArgNb
8601 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
8603 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8608 else if (aTrsfArg.StartsWith ("-location")
8609 || aTrsfArg.StartsWith ("-loc"))
8611 isTrsfSet = Standard_True;
8612 if (aTrsfArgIter + 3 >= theArgNb
8613 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
8615 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8620 else if (aTrsfArg.StartsWith ("-scale"))
8622 isTrsfSet = Standard_True;
8623 if (++aTrsfArgIter >= theArgNb)
8625 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8629 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
8630 if (!aScaleStr.IsRealValue())
8632 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8635 aScales[anIndex] = aScaleStr.RealValue();
8639 anArgIter = aTrsfArgIter - 1;
8645 std::cout << "Syntax error at " << anArg << ".\n";
8648 else if (aTrsfArgIter >= theArgNb)
8650 anArgIter = theArgNb;
8653 aTrsfs[0].SetRotation (aRotQuats[0]);
8654 aTrsfs[1].SetRotation (aRotQuats[1]);
8655 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
8656 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
8657 aTrsfs[0].SetScaleFactor (aScales[0]);
8658 aTrsfs[1].SetScaleFactor (aScales[1]);
8660 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
8661 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
8663 else if (anArg == "-viewtrsf"
8664 || anArg == "-view")
8666 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
8667 if (aCamAnimation.IsNull())
8669 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
8670 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
8673 Handle(Graphic3d_Camera) aCams[2] =
8675 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
8676 new Graphic3d_Camera (aCamAnimation->View()->Camera())
8679 Standard_Boolean isTrsfSet = Standard_False;
8680 Standard_Integer aViewArgIter = anArgIter + 1;
8681 for (; aViewArgIter < theArgNb; ++aViewArgIter)
8683 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
8684 aViewArg.LowerCase();
8685 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
8686 if (aViewArg.StartsWith ("-scale"))
8688 isTrsfSet = Standard_True;
8689 if (++aViewArgIter >= theArgNb)
8691 std::cout << "Syntax error at " << anArg << ".\n";
8695 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
8696 if (!aScaleStr.IsRealValue())
8698 std::cout << "Syntax error at " << aViewArg << ".\n";
8701 Standard_Real aScale = aScaleStr.RealValue();
8702 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
8703 aCams[anIndex]->SetScale (aScale);
8705 else if (aViewArg.StartsWith ("-eye")
8706 || aViewArg.StartsWith ("-center")
8707 || aViewArg.StartsWith ("-at")
8708 || aViewArg.StartsWith ("-up"))
8710 isTrsfSet = Standard_True;
8712 if (aViewArgIter + 3 >= theArgNb
8713 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
8715 std::cout << "Syntax error at " << aViewArg << ".\n";
8720 if (aViewArg.StartsWith ("-eye"))
8722 aCams[anIndex]->SetEye (anXYZ);
8724 else if (aViewArg.StartsWith ("-center")
8725 || aViewArg.StartsWith ("-at"))
8727 aCams[anIndex]->SetCenter (anXYZ);
8729 else if (aViewArg.StartsWith ("-up"))
8731 aCams[anIndex]->SetUp (anXYZ);
8736 anArgIter = aViewArgIter - 1;
8742 std::cout << "Syntax error at " << anArg << ".\n";
8745 else if (aViewArgIter >= theArgNb)
8747 anArgIter = theArgNb;
8750 aCamAnimation->SetCameraStart(aCams[0]);
8751 aCamAnimation->SetCameraEnd (aCams[1]);
8755 std::cout << "Syntax error at " << anArg << ".\n";
8760 if (!toPlay && aRecFile.IsEmpty())
8765 // Start animation timeline and process frame updating.
8766 TheIsAnimating = Standard_True;
8767 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
8768 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
8769 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
8772 aView->Camera()->Copy (aCameraBack);
8775 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
8776 if (aRecParams.FpsNum <= 0)
8778 while (!anAnimation->IsStopped())
8780 aCameraBack->Copy (aView->Camera());
8781 const Standard_Real aPts = anAnimation->UpdateTimer();
8784 aView->Camera()->Copy (aCameraBack);
8787 if (aPts >= anUpperPts)
8789 anAnimation->Pause();
8793 if (aView->IsInvalidated())
8799 aView->RedrawImmediate();
8804 // handle user events
8805 theDI.Eval ("after 1 set waiter 1");
8806 theDI.Eval ("vwait waiter");
8808 if (!TheIsAnimating)
8810 anAnimation->Pause();
8816 if (aView->IsInvalidated())
8822 aView->RedrawImmediate();
8827 OSD_Timer aPerfTimer;
8830 Handle(Image_VideoRecorder) aRecorder;
8831 ImageFlipper aFlipper;
8832 Handle(Draw_ProgressIndicator) aProgress;
8833 if (!aRecFile.IsEmpty())
8835 if (aRecParams.Width <= 0
8836 || aRecParams.Height <= 0)
8838 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
8841 aRecorder = new Image_VideoRecorder();
8842 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
8844 std::cout << "Error: failed to open video file for recording\n";
8848 aProgress = new Draw_ProgressIndicator (theDI, 1);
8851 // Manage frame-rated animation here
8852 Standard_Real aPts = aPlayStartTime;
8853 int64_t aNbFrames = 0;
8854 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
8855 Standard_Integer aSecondsProgress = 0;
8856 for (; aPts <= anUpperPts && aPSentry.More();)
8858 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
8859 aPts = aPlayStartTime + aRecPts;
8861 if (!anAnimation->Update (aPts))
8866 if (!aRecorder.IsNull())
8868 V3d_ImageDumpOptions aDumpParams;
8869 aDumpParams.Width = aRecParams.Width;
8870 aDumpParams.Height = aRecParams.Height;
8871 aDumpParams.BufferType = Graphic3d_BT_RGBA;
8872 aDumpParams.StereoOptions = V3d_SDO_MONO;
8873 aDumpParams.ToAdjustAspect = Standard_True;
8874 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
8876 std::cout << "Error: view dump is failed!\n";
8879 aFlipper.FlipY (aRecorder->ChangeFrame());
8880 if (!aRecorder->PushFrame())
8890 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
8898 anAnimation->Stop();
8899 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
8900 theDI << "Average FPS: " << aRecFps << "\n"
8901 << "Nb. Frames: " << Standard_Real(aNbFrames);
8906 aView->SetImmediateUpdate (wasImmediateUpdate);
8907 TheIsAnimating = Standard_False;
8912 //=======================================================================
8913 //function : VChangeSelected
8914 //purpose : Adds the shape to selection or remove one from it
8915 //=======================================================================
8916 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
8917 Standard_Integer argc,
8922 di<<"Usage : " << argv[0] << " shape \n";
8926 TCollection_AsciiString aName(argv[1]);
8927 Handle(AIS_InteractiveObject) anAISObject;
8928 if (!GetMapOfAIS().Find2 (aName, anAISObject)
8929 || anAISObject.IsNull())
8931 di<<"Use 'vdisplay' before";
8935 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
8939 //=======================================================================
8940 //function : VNbSelected
8941 //purpose : Returns number of selected objects
8942 //=======================================================================
8943 static Standard_Integer VNbSelected (Draw_Interpretor& di,
8944 Standard_Integer argc,
8949 di << "Usage : " << argv[0] << "\n";
8952 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8953 if(aContext.IsNull())
8955 di << "use 'vinit' command before " << argv[0] << "\n";
8958 di << aContext->NbSelected() << "\n";
8962 //=======================================================================
8963 //function : VPurgeDisplay
8964 //purpose : Switches altialiasing on or off
8965 //=======================================================================
8966 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
8967 Standard_Integer argc,
8972 di << "Usage : " << argv[0] << "\n";
8975 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8976 if (aContext.IsNull())
8978 di << "use 'vinit' command before " << argv[0] << "\n";
8982 di << aContext->PurgeDisplay() << "\n";
8986 //=======================================================================
8987 //function : VSetViewSize
8989 //=======================================================================
8990 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
8991 Standard_Integer argc,
8994 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8995 if(aContext.IsNull())
8997 di << "use 'vinit' command before " << argv[0] << "\n";
9002 di<<"Usage : " << argv[0] << " Size\n";
9005 Standard_Real aSize = Draw::Atof (argv[1]);
9008 di<<"Bad Size value : " << aSize << "\n";
9012 Handle(V3d_View) aView = ViewerTest::CurrentView();
9013 aView->SetSize(aSize);
9017 //=======================================================================
9018 //function : VMoveView
9020 //=======================================================================
9021 static Standard_Integer VMoveView (Draw_Interpretor& di,
9022 Standard_Integer argc,
9025 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9026 if(aContext.IsNull())
9028 di << "use 'vinit' command before " << argv[0] << "\n";
9031 if(argc < 4 || argc > 5)
9033 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
9036 Standard_Real Dx = Draw::Atof (argv[1]);
9037 Standard_Real Dy = Draw::Atof (argv[2]);
9038 Standard_Real Dz = Draw::Atof (argv[3]);
9039 Standard_Boolean aStart = Standard_True;
9042 aStart = (Draw::Atoi (argv[4]) > 0);
9045 Handle(V3d_View) aView = ViewerTest::CurrentView();
9046 aView->Move(Dx,Dy,Dz,aStart);
9050 //=======================================================================
9051 //function : VTranslateView
9053 //=======================================================================
9054 static Standard_Integer VTranslateView (Draw_Interpretor& di,
9055 Standard_Integer argc,
9058 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9059 if(aContext.IsNull())
9061 di << "use 'vinit' command before " << argv[0] << "\n";
9064 if(argc < 4 || argc > 5)
9066 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
9069 Standard_Real Dx = Draw::Atof (argv[1]);
9070 Standard_Real Dy = Draw::Atof (argv[2]);
9071 Standard_Real Dz = Draw::Atof (argv[3]);
9072 Standard_Boolean aStart = Standard_True;
9075 aStart = (Draw::Atoi (argv[4]) > 0);
9078 Handle(V3d_View) aView = ViewerTest::CurrentView();
9079 aView->Translate(Dx,Dy,Dz,aStart);
9083 //=======================================================================
9084 //function : VTurnView
9086 //=======================================================================
9087 static Standard_Integer VTurnView (Draw_Interpretor& di,
9088 Standard_Integer argc,
9091 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9092 if(aContext.IsNull()) {
9093 di << "use 'vinit' command before " << argv[0] << "\n";
9096 if(argc < 4 || argc > 5){
9097 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
9100 Standard_Real Ax = Draw::Atof (argv[1]);
9101 Standard_Real Ay = Draw::Atof (argv[2]);
9102 Standard_Real Az = Draw::Atof (argv[3]);
9103 Standard_Boolean aStart = Standard_True;
9106 aStart = (Draw::Atoi (argv[4]) > 0);
9109 Handle(V3d_View) aView = ViewerTest::CurrentView();
9110 aView->Turn(Ax,Ay,Az,aStart);
9114 //==============================================================================
9115 //function : VTextureEnv
9116 //purpose : ENables or disables environment mapping
9117 //==============================================================================
9118 class OCC_TextureEnv : public Graphic3d_TextureEnv
9121 OCC_TextureEnv(const Standard_CString FileName);
9122 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
9123 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
9124 const Standard_Boolean theModulateFlag,
9125 const Graphic3d_TypeOfTextureFilter theFilter,
9126 const Standard_ShortReal theXScale,
9127 const Standard_ShortReal theYScale,
9128 const Standard_ShortReal theXShift,
9129 const Standard_ShortReal theYShift,
9130 const Standard_ShortReal theAngle);
9131 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
9133 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
9135 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
9136 : Graphic3d_TextureEnv(theFileName)
9140 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
9141 : Graphic3d_TextureEnv(theTexId)
9145 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
9146 const Standard_Boolean theModulateFlag,
9147 const Graphic3d_TypeOfTextureFilter theFilter,
9148 const Standard_ShortReal theXScale,
9149 const Standard_ShortReal theYScale,
9150 const Standard_ShortReal theXShift,
9151 const Standard_ShortReal theYShift,
9152 const Standard_ShortReal theAngle)
9154 myParams->SetRepeat (theRepeatFlag);
9155 myParams->SetModulate (theModulateFlag);
9156 myParams->SetFilter (theFilter);
9157 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
9158 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
9159 myParams->SetRotation (theAngle);
9162 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
9164 // get the active view
9165 Handle(V3d_View) aView = ViewerTest::CurrentView();
9168 std::cerr << "No active view. Please call vinit.\n";
9172 // Checking the input arguments
9173 Standard_Boolean anEnableFlag = Standard_False;
9174 Standard_Boolean isOk = theArgNb >= 2;
9177 TCollection_AsciiString anEnableOpt(theArgVec[1]);
9178 anEnableFlag = anEnableOpt.IsEqual("on");
9179 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
9183 isOk = (theArgNb == 3 || theArgNb == 11);
9186 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9187 isOk = (!aTextureOpt.IsIntegerValue() ||
9188 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
9190 if (isOk && theArgNb == 11)
9192 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
9193 aModulateOpt(theArgVec[4]),
9194 aFilterOpt (theArgVec[5]),
9195 aSScaleOpt (theArgVec[6]),
9196 aTScaleOpt (theArgVec[7]),
9197 aSTransOpt (theArgVec[8]),
9198 aTTransOpt (theArgVec[9]),
9199 anAngleOpt (theArgVec[10]);
9200 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
9201 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
9202 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
9203 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
9204 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
9205 anAngleOpt.IsRealValue());
9212 std::cerr << "Usage :" << std::endl;
9213 std::cerr << theArgVec[0] << " off" << std::endl;
9214 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;
9220 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9221 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
9222 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
9223 new OCC_TextureEnv(theArgVec[2]);
9227 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
9228 aTexEnv->SetTextureParameters(
9229 aRepeatOpt. IsEqual("repeat"),
9230 aModulateOpt.IsEqual("modulate"),
9231 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
9232 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
9233 Graphic3d_TOTF_TRILINEAR,
9234 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
9235 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
9236 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
9237 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
9238 (Standard_ShortReal)Draw::Atof(theArgVec[10])
9241 aView->SetTextureEnv(aTexEnv);
9243 else // Disabling environment mapping
9245 Handle(Graphic3d_TextureEnv) aTexture;
9246 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
9255 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
9257 //! Remove registered clipping plane from all views and objects.
9258 static void removePlane (MapOfPlanes& theRegPlanes,
9259 const TCollection_AsciiString& theName)
9261 Handle(Graphic3d_ClipPlane) aClipPlane;
9262 if (!theRegPlanes.Find (theName, aClipPlane))
9264 std::cout << "Warning: no such plane.\n";
9268 theRegPlanes.UnBind (theName);
9269 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
9270 anIObjIt.More(); anIObjIt.Next())
9272 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
9273 aPrs->RemoveClipPlane (aClipPlane);
9276 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
9277 aViewIt.More(); aViewIt.Next())
9279 const Handle(V3d_View)& aView = aViewIt.Key2();
9280 aView->RemoveClipPlane(aClipPlane);
9283 ViewerTest::RedrawAllViews();
9287 //===============================================================================================
9288 //function : VClipPlane
9290 //===============================================================================================
9291 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9293 // use short-cut for created clip planes map of created (or "registered by name") clip planes
9294 static MapOfPlanes aRegPlanes;
9298 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
9300 theDi << aPlaneIter.Key() << " ";
9305 TCollection_AsciiString aCommand (theArgVec[1]);
9306 aCommand.LowerCase();
9307 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
9308 if (anActiveView.IsNull())
9310 std::cout << "Error: no active view.\n";
9314 // print maximum number of planes for current viewer
9315 if (aCommand == "-maxplanes"
9316 || aCommand == "maxplanes")
9318 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
9319 << " plane slots provided by driver.\n";
9323 // create / delete plane instance
9324 if (aCommand == "-create"
9325 || aCommand == "create"
9326 || aCommand == "-delete"
9327 || aCommand == "delete"
9328 || aCommand == "-clone"
9329 || aCommand == "clone")
9333 std::cout << "Syntax error: plane name is required.\n";
9337 Standard_Boolean toCreate = aCommand == "-create"
9338 || aCommand == "create";
9339 Standard_Boolean toClone = aCommand == "-clone"
9340 || aCommand == "clone";
9341 Standard_Boolean toDelete = aCommand == "-delete"
9342 || aCommand == "delete";
9343 TCollection_AsciiString aPlane (theArgVec[2]);
9347 if (aRegPlanes.IsBound (aPlane))
9349 std::cout << "Warning: existing plane has been overridden.\n";
9354 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9358 else if (toClone) // toClone
9360 if (!aRegPlanes.IsBound (aPlane))
9362 std::cout << "Error: no such plane.\n";
9365 else if (theArgsNb < 4)
9367 std::cout << "Syntax error: enter name for new plane.\n";
9371 TCollection_AsciiString aClone (theArgVec[3]);
9372 if (aRegPlanes.IsBound (aClone))
9374 std::cout << "Error: plane name is in use.\n";
9378 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
9380 aRegPlanes.Bind (aClone, aClipPlane->Clone());
9390 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
9392 aPlane = aPlaneIter.Key();
9393 removePlane (aRegPlanes, aPlane);
9394 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
9399 removePlane (aRegPlanes, aPlane);
9405 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9410 // set / unset plane command
9411 if (aCommand == "set"
9412 || aCommand == "unset")
9416 std::cout << "Syntax error: need more arguments.\n";
9420 // redirect to new syntax
9421 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
9422 anArgVec.SetValue (1, theArgVec[0]);
9423 anArgVec.SetValue (2, theArgVec[2]);
9424 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
9425 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
9427 anArgVec.SetValue (anIt, theArgVec[anIt]);
9430 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
9433 // change plane command
9434 TCollection_AsciiString aPlaneName;
9435 Handle(Graphic3d_ClipPlane) aClipPlane;
9436 Standard_Integer anArgIter = 0;
9437 if (aCommand == "-change"
9438 || aCommand == "change")
9440 // old syntax support
9443 std::cout << "Syntax error: need more arguments.\n";
9448 aPlaneName = theArgVec[2];
9449 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
9451 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
9455 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
9458 aPlaneName = theArgVec[1];
9463 aPlaneName = theArgVec[1];
9464 aClipPlane = new Graphic3d_ClipPlane();
9465 aRegPlanes.Bind (aPlaneName, aClipPlane);
9466 theDi << "Created new plane " << aPlaneName << ".\n";
9469 if (theArgsNb - anArgIter < 1)
9471 std::cout << "Syntax error: need more arguments.\n";
9475 for (; anArgIter < theArgsNb; ++anArgIter)
9477 const char** aChangeArgs = theArgVec + anArgIter;
9478 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
9479 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
9480 aChangeArg.LowerCase();
9482 Standard_Boolean toEnable = Standard_True;
9483 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
9485 aClipPlane->SetOn (toEnable);
9487 else if (aChangeArg.StartsWith ("-equation")
9488 || aChangeArg.StartsWith ("equation"))
9490 if (aNbChangeArgs < 5)
9492 std::cout << "Syntax error: need more arguments.\n";
9496 Standard_Integer aSubIndex = 1;
9497 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
9498 if (aPrefixLen < aChangeArg.Length())
9500 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
9501 if (!aSubStr.IsIntegerValue()
9502 || aSubStr.IntegerValue() <= 0)
9504 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9507 aSubIndex = aSubStr.IntegerValue();
9510 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
9511 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
9512 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
9513 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
9514 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9515 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
9517 if (aSubPln->ChainNextPlane().IsNull())
9519 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9521 aSubPln = aSubPln->ChainNextPlane();
9523 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9524 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
9527 else if ((aChangeArg == "-boxinterior"
9528 || aChangeArg == "-boxint"
9529 || aChangeArg == "-box")
9530 && aNbChangeArgs >= 7)
9532 Graphic3d_BndBox3d aBndBox;
9533 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
9534 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
9537 Standard_Integer aNbSubPlanes = 6;
9538 const Graphic3d_Vec3d aDirArray[6] =
9540 Graphic3d_Vec3d (-1, 0, 0),
9541 Graphic3d_Vec3d ( 1, 0, 0),
9542 Graphic3d_Vec3d ( 0,-1, 0),
9543 Graphic3d_Vec3d ( 0, 1, 0),
9544 Graphic3d_Vec3d ( 0, 0,-1),
9545 Graphic3d_Vec3d ( 0, 0, 1),
9547 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9548 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
9550 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
9551 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
9552 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
9553 if (aSubPlaneIter + 1 == aNbSubPlanes)
9555 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9559 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9561 aSubPln = aSubPln->ChainNextPlane();
9564 else if (aChangeArg == "-capping"
9565 || aChangeArg == "capping")
9567 if (aNbChangeArgs < 2)
9569 std::cout << "Syntax error: need more arguments.\n";
9573 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9575 aClipPlane->SetCapping (toEnable);
9580 // just skip otherwise (old syntax)
9583 else if (aChangeArg == "-useobjectmaterial"
9584 || aChangeArg == "-useobjectmat"
9585 || aChangeArg == "-useobjmat"
9586 || aChangeArg == "-useobjmaterial")
9588 if (aNbChangeArgs < 2)
9590 std::cout << "Syntax error: need more arguments.\n";
9594 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9596 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
9600 else if (aChangeArg == "-useobjecttexture"
9601 || aChangeArg == "-useobjecttex"
9602 || aChangeArg == "-useobjtexture"
9603 || aChangeArg == "-useobjtex")
9605 if (aNbChangeArgs < 2)
9607 std::cout << "Syntax error: need more arguments.\n";
9611 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9613 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
9617 else if (aChangeArg == "-useobjectshader"
9618 || aChangeArg == "-useobjshader")
9620 if (aNbChangeArgs < 2)
9622 std::cout << "Syntax error: need more arguments.\n";
9626 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9628 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
9632 else if (aChangeArg == "-color"
9633 || aChangeArg == "color")
9635 Quantity_Color aColor;
9636 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
9641 std::cout << "Syntax error: need more arguments.\n";
9644 aClipPlane->SetCappingColor (aColor);
9645 anArgIter += aNbParsed;
9647 else if (aNbChangeArgs >= 1
9648 && (aChangeArg == "-material"
9649 || aChangeArg == "material"))
9652 Graphic3d_NameOfMaterial aMatName;
9653 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeArgs[1], aMatName))
9655 std::cout << "Syntax error: unknown material '" << aChangeArgs[1] << "'.\n";
9658 aClipPlane->SetCappingMaterial (aMatName);
9660 else if ((aChangeArg == "-transparency"
9661 || aChangeArg == "-transp")
9662 && aNbChangeArgs >= 2)
9664 TCollection_AsciiString aValStr (aChangeArgs[1]);
9665 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
9666 if (aValStr.IsRealValue())
9668 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
9669 aMat.SetTransparency ((float )aValStr.RealValue());
9670 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
9671 aClipPlane->SetCappingMaterial (aMat);
9675 aValStr.LowerCase();
9676 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
9677 if (aValStr == "opaque")
9679 aMode = Graphic3d_AlphaMode_Opaque;
9681 else if (aValStr == "mask")
9683 aMode = Graphic3d_AlphaMode_Mask;
9685 else if (aValStr == "blend")
9687 aMode = Graphic3d_AlphaMode_Blend;
9689 else if (aValStr == "blendauto")
9691 aMode = Graphic3d_AlphaMode_BlendAuto;
9695 std::cout << "Syntax error at '" << aValStr << "'\n";
9698 anAspect->SetAlphaMode (aMode);
9699 aClipPlane->SetCappingAspect (anAspect);
9703 else if (aChangeArg == "-texname"
9704 || aChangeArg == "texname")
9706 if (aNbChangeArgs < 2)
9708 std::cout << "Syntax error: need more arguments.\n";
9712 TCollection_AsciiString aTextureName (aChangeArgs[1]);
9713 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
9714 if (!aTexture->IsDone())
9716 aClipPlane->SetCappingTexture (NULL);
9720 aTexture->EnableModulate();
9721 aTexture->EnableRepeat();
9722 aClipPlane->SetCappingTexture (aTexture);
9726 else if (aChangeArg == "-texscale"
9727 || aChangeArg == "texscale")
9729 if (aClipPlane->CappingTexture().IsNull())
9731 std::cout << "Error: no texture is set.\n";
9735 if (aNbChangeArgs < 3)
9737 std::cout << "Syntax error: need more arguments.\n";
9741 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9742 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9743 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
9746 else if (aChangeArg == "-texorigin"
9747 || aChangeArg == "texorigin") // texture origin
9749 if (aClipPlane->CappingTexture().IsNull())
9751 std::cout << "Error: no texture is set.\n";
9755 if (aNbChangeArgs < 3)
9757 std::cout << "Syntax error: need more arguments.\n";
9761 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9762 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9764 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
9767 else if (aChangeArg == "-texrotate"
9768 || aChangeArg == "texrotate") // texture rotation
9770 if (aClipPlane->CappingTexture().IsNull())
9772 std::cout << "Error: no texture is set.\n";
9776 if (aNbChangeArgs < 2)
9778 std::cout << "Syntax error: need more arguments.\n";
9782 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9783 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
9786 else if (aChangeArg == "-hatch"
9787 || aChangeArg == "hatch")
9789 if (aNbChangeArgs < 2)
9791 std::cout << "Syntax error: need more arguments.\n";
9795 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
9796 aHatchStr.LowerCase();
9797 if (aHatchStr == "on")
9799 aClipPlane->SetCappingHatchOn();
9801 else if (aHatchStr == "off")
9803 aClipPlane->SetCappingHatchOff();
9807 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
9811 else if (aChangeArg == "-delete"
9812 || aChangeArg == "delete")
9814 removePlane (aRegPlanes, aPlaneName);
9817 else if (aChangeArg == "-set"
9818 || aChangeArg == "-unset"
9819 || aChangeArg == "-setoverrideglobal")
9821 // set / unset plane command
9822 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
9823 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
9824 Standard_Integer anIt = 1;
9825 for (; anIt < aNbChangeArgs; ++anIt)
9827 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
9828 if (anEntityName.IsEmpty()
9829 || anEntityName.Value (1) == '-')
9833 else if (!toOverrideGlobal
9834 && ViewerTest_myViews.IsBound1 (anEntityName))
9836 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
9839 aView->AddClipPlane (aClipPlane);
9843 aView->RemoveClipPlane (aClipPlane);
9847 else if (GetMapOfAIS().IsBound2 (anEntityName))
9849 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
9852 aIObj->AddClipPlane (aClipPlane);
9856 aIObj->RemoveClipPlane (aClipPlane);
9858 if (!aIObj->ClipPlanes().IsNull())
9860 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
9865 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
9872 // apply to active view
9875 anActiveView->AddClipPlane (aClipPlane);
9879 anActiveView->RemoveClipPlane (aClipPlane);
9884 anArgIter = anArgIter + anIt - 1;
9889 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9894 ViewerTest::RedrawAllViews();
9898 //===============================================================================================
9899 //function : VZRange
9901 //===============================================================================================
9902 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9904 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9906 if (aCurrentView.IsNull())
9908 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9912 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
9916 theDi << "ZNear: " << aCamera->ZNear() << "\n";
9917 theDi << "ZFar: " << aCamera->ZFar() << "\n";
9923 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
9924 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
9926 if (aNewZNear >= aNewZFar)
9928 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
9932 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
9934 std::cout << theArgVec[0] << ": invalid arguments: ";
9935 std::cout << "znear, zfar should be positive for perspective camera.\n";
9939 aCamera->SetZRange (aNewZNear, aNewZFar);
9943 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9947 aCurrentView->Redraw();
9952 //===============================================================================================
9953 //function : VAutoZFit
9955 //===============================================================================================
9956 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9958 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9960 if (aCurrentView.IsNull())
9962 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9966 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
9970 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9976 theDi << "Auto z-fit mode: \n"
9977 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
9978 << "Scale: " << aScale << "\n";
9982 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
9986 aScale = Draw::Atoi (theArgVec[2]);
9989 aCurrentView->SetAutoZFitMode (isOn, aScale);
9990 aCurrentView->AutoZFit();
9991 aCurrentView->Redraw();
9996 //! Auxiliary function to print projection type
9997 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
9999 switch (theProjType)
10001 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
10002 case Graphic3d_Camera::Projection_Perspective: return "perspective";
10003 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
10004 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
10005 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
10010 //===============================================================================================
10011 //function : VCamera
10013 //===============================================================================================
10014 static int VCamera (Draw_Interpretor& theDI,
10015 Standard_Integer theArgsNb,
10016 const char** theArgVec)
10018 Handle(V3d_View) aView = ViewerTest::CurrentView();
10019 if (aView.IsNull())
10021 std::cout << "Error: no active view.\n";
10025 Handle(Graphic3d_Camera) aCamera = aView->Camera();
10028 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
10029 theDI << "FOVy: " << aCamera->FOVy() << "\n";
10030 theDI << "Distance: " << aCamera->Distance() << "\n";
10031 theDI << "IOD: " << aCamera->IOD() << "\n";
10032 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
10033 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
10034 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
10038 TCollection_AsciiString aPrsName;
10039 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10041 Standard_CString anArg = theArgVec[anArgIter];
10042 TCollection_AsciiString anArgCase (anArg);
10043 anArgCase.LowerCase();
10044 if (anArgCase == "-proj"
10045 || anArgCase == "-projection"
10046 || anArgCase == "-projtype"
10047 || anArgCase == "-projectiontype")
10049 theDI << projTypeName (aCamera->ProjectionType()) << " ";
10051 else if (anArgCase == "-ortho"
10052 || anArgCase == "-orthographic")
10054 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
10056 else if (anArgCase == "-persp"
10057 || anArgCase == "-perspective"
10058 || anArgCase == "-perspmono"
10059 || anArgCase == "-perspectivemono"
10060 || anArgCase == "-mono")
10062 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10064 else if (anArgCase == "-stereo"
10065 || anArgCase == "-stereoscopic"
10066 || anArgCase == "-perspstereo"
10067 || anArgCase == "-perspectivestereo")
10069 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10071 else if (anArgCase == "-left"
10072 || anArgCase == "-lefteye"
10073 || anArgCase == "-monoleft"
10074 || anArgCase == "-monolefteye"
10075 || anArgCase == "-perpsleft"
10076 || anArgCase == "-perpslefteye")
10078 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
10080 else if (anArgCase == "-right"
10081 || anArgCase == "-righteye"
10082 || anArgCase == "-monoright"
10083 || anArgCase == "-monorighteye"
10084 || anArgCase == "-perpsright")
10086 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
10088 else if (anArgCase == "-dist"
10089 || anArgCase == "-distance")
10091 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10092 if (anArgValue != NULL
10093 && *anArgValue != '-')
10096 aCamera->SetDistance (Draw::Atof (anArgValue));
10099 theDI << aCamera->Distance() << " ";
10101 else if (anArgCase == "-iod")
10103 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10104 if (anArgValue != NULL
10105 && *anArgValue != '-')
10108 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
10111 theDI << aCamera->IOD() << " ";
10113 else if (anArgCase == "-iodtype")
10115 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10116 TCollection_AsciiString anValueCase (anArgValue);
10117 anValueCase.LowerCase();
10118 if (anValueCase == "abs"
10119 || anValueCase == "absolute")
10122 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
10125 else if (anValueCase == "rel"
10126 || anValueCase == "relative")
10129 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
10132 else if (*anArgValue != '-')
10134 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
10137 switch (aCamera->GetIODType())
10139 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
10140 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
10143 else if (anArgCase == "-zfocus")
10145 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10146 if (anArgValue != NULL
10147 && *anArgValue != '-')
10150 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
10153 theDI << aCamera->ZFocus() << " ";
10155 else if (anArgCase == "-zfocustype")
10157 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10158 TCollection_AsciiString anValueCase (anArgValue);
10159 anValueCase.LowerCase();
10160 if (anValueCase == "abs"
10161 || anValueCase == "absolute")
10164 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
10167 else if (anValueCase == "rel"
10168 || anValueCase == "relative")
10171 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
10174 else if (*anArgValue != '-')
10176 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
10179 switch (aCamera->ZFocusType())
10181 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
10182 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
10185 else if (anArgCase == "-fov"
10186 || anArgCase == "-fovy")
10188 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10189 if (anArgValue != NULL
10190 && *anArgValue != '-')
10193 aCamera->SetFOVy (Draw::Atof (anArgValue));
10196 theDI << aCamera->FOVy() << " ";
10198 else if (aPrsName.IsEmpty()
10199 && !anArgCase.StartsWith ("-"))
10205 std::cout << "Error: unknown argument '" << anArg << "'\n";
10210 if (aPrsName.IsEmpty()
10217 if (!aPrsName.IsEmpty())
10219 Handle(AIS_CameraFrustum) aCameraFrustum;
10220 if (GetMapOfAIS().IsBound2 (aPrsName))
10222 // find existing object
10223 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
10224 if (aCameraFrustum.IsNull())
10226 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
10231 if (aCameraFrustum.IsNull())
10233 aCameraFrustum = new AIS_CameraFrustum();
10237 // not include displayed object of old camera frustum in the new one.
10238 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
10241 aCameraFrustum->SetCameraFrustum (aView->Camera());
10243 ViewerTest::Display (aPrsName, aCameraFrustum);
10249 //! Parse stereo output mode
10250 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
10251 Graphic3d_StereoMode& theMode)
10253 TCollection_AsciiString aFlag (theArg);
10255 if (aFlag == "quadbuffer")
10257 theMode = Graphic3d_StereoMode_QuadBuffer;
10259 else if (aFlag == "anaglyph")
10261 theMode = Graphic3d_StereoMode_Anaglyph;
10263 else if (aFlag == "row"
10264 || aFlag == "rowinterlaced")
10266 theMode = Graphic3d_StereoMode_RowInterlaced;
10268 else if (aFlag == "col"
10269 || aFlag == "colinterlaced"
10270 || aFlag == "columninterlaced")
10272 theMode = Graphic3d_StereoMode_ColumnInterlaced;
10274 else if (aFlag == "chess"
10275 || aFlag == "chessboard")
10277 theMode = Graphic3d_StereoMode_ChessBoard;
10279 else if (aFlag == "sbs"
10280 || aFlag == "sidebyside")
10282 theMode = Graphic3d_StereoMode_SideBySide;
10284 else if (aFlag == "ou"
10285 || aFlag == "overunder")
10287 theMode = Graphic3d_StereoMode_OverUnder;
10289 else if (aFlag == "pageflip"
10290 || aFlag == "softpageflip")
10292 theMode = Graphic3d_StereoMode_SoftPageFlip;
10296 return Standard_False;
10298 return Standard_True;
10301 //! Parse anaglyph filter
10302 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
10303 Graphic3d_RenderingParams::Anaglyph& theFilter)
10305 TCollection_AsciiString aFlag (theArg);
10307 if (aFlag == "redcyansimple")
10309 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10311 else if (aFlag == "redcyan"
10312 || aFlag == "redcyanoptimized")
10314 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
10316 else if (aFlag == "yellowbluesimple")
10318 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
10320 else if (aFlag == "yellowblue"
10321 || aFlag == "yellowblueoptimized")
10323 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
10325 else if (aFlag == "greenmagenta"
10326 || aFlag == "greenmagentasimple")
10328 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
10332 return Standard_False;
10334 return Standard_True;
10337 //==============================================================================
10338 //function : VStereo
10340 //==============================================================================
10342 static int VStereo (Draw_Interpretor& theDI,
10343 Standard_Integer theArgNb,
10344 const char** theArgVec)
10346 Handle(V3d_View) aView = ViewerTest::CurrentView();
10349 if (aView.IsNull())
10351 std::cout << "Error: no active viewer!\n";
10355 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
10356 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
10359 TCollection_AsciiString aMode;
10360 switch (aView->RenderingParams().StereoMode)
10362 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
10363 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
10364 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
10365 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
10366 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
10367 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
10368 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
10369 case Graphic3d_StereoMode_Anaglyph :
10370 aMode = "anaglyph";
10371 switch (aView->RenderingParams().AnaglyphFilter)
10373 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
10374 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
10375 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
10376 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
10377 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
10382 theDI << "Mode " << aMode << "\n";
10387 Handle(Graphic3d_Camera) aCamera;
10388 Graphic3d_RenderingParams* aParams = NULL;
10389 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
10390 if (!aView.IsNull())
10392 aParams = &aView->ChangeRenderingParams();
10393 aMode = aParams->StereoMode;
10394 aCamera = aView->Camera();
10397 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10398 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10400 Standard_CString anArg = theArgVec[anArgIter];
10401 TCollection_AsciiString aFlag (anArg);
10403 if (anUpdateTool.parseRedrawMode (aFlag))
10407 else if (aFlag == "0"
10410 if (++anArgIter < theArgNb)
10412 std::cout << "Error: wrong number of arguments!\n";
10416 if (!aCamera.IsNull()
10417 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
10419 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10421 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
10424 else if (aFlag == "1"
10427 if (++anArgIter < theArgNb)
10429 std::cout << "Error: wrong number of arguments!\n";
10433 if (!aCamera.IsNull())
10435 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10437 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10440 else if (aFlag == "-reverse"
10441 || aFlag == "-reversed"
10442 || aFlag == "-swap")
10444 Standard_Boolean toEnable = Standard_True;
10445 if (++anArgIter < theArgNb
10446 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10450 aParams->ToReverseStereo = toEnable;
10452 else if (aFlag == "-noreverse"
10453 || aFlag == "-noswap")
10455 Standard_Boolean toDisable = Standard_True;
10456 if (++anArgIter < theArgNb
10457 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
10461 aParams->ToReverseStereo = !toDisable;
10463 else if (aFlag == "-mode"
10464 || aFlag == "-stereomode")
10466 if (++anArgIter >= theArgNb
10467 || !parseStereoMode (theArgVec[anArgIter], aMode))
10469 std::cout << "Error: syntax error at '" << anArg << "'\n";
10473 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10475 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10478 else if (aFlag == "-anaglyph"
10479 || aFlag == "-anaglyphfilter")
10481 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10482 if (++anArgIter >= theArgNb
10483 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
10485 std::cout << "Error: syntax error at '" << anArg << "'\n";
10489 aMode = Graphic3d_StereoMode_Anaglyph;
10490 aParams->AnaglyphFilter = aFilter;
10492 else if (parseStereoMode (anArg, aMode)) // short syntax
10494 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10496 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10501 std::cout << "Error: syntax error at '" << anArg << "'\n";
10506 if (!aView.IsNull())
10508 aParams->StereoMode = aMode;
10509 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10514 //===============================================================================================
10515 //function : VDefaults
10517 //===============================================================================================
10518 static int VDefaults (Draw_Interpretor& theDi,
10519 Standard_Integer theArgsNb,
10520 const char** theArgVec)
10522 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
10525 std::cout << "Error: no active viewer\n";
10529 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
10532 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
10534 theDi << "DeflType: relative\n"
10535 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
10539 theDi << "DeflType: absolute\n"
10540 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
10542 theDi << "AngularDeflection: " << (180.0 * aDefParams->DeviationAngle() / M_PI) << "\n";
10543 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
10547 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10549 TCollection_AsciiString anArg (theArgVec[anArgIter]);
10551 if (anArg == "-ABSDEFL"
10552 || anArg == "-ABSOLUTEDEFLECTION"
10553 || anArg == "-DEFL"
10554 || anArg == "-DEFLECTION")
10556 if (++anArgIter >= theArgsNb)
10558 std::cout << "Error: wrong syntax at " << anArg << "\n";
10561 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
10562 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
10564 else if (anArg == "-RELDEFL"
10565 || anArg == "-RELATIVEDEFLECTION"
10566 || anArg == "-DEVCOEFF"
10567 || anArg == "-DEVIATIONCOEFF"
10568 || anArg == "-DEVIATIONCOEFFICIENT")
10570 if (++anArgIter >= theArgsNb)
10572 std::cout << "Error: wrong syntax at " << anArg << "\n";
10575 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
10576 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
10578 else if (anArg == "-ANGDEFL"
10579 || anArg == "-ANGULARDEFL"
10580 || anArg == "-ANGULARDEFLECTION")
10582 if (++anArgIter >= theArgsNb)
10584 std::cout << "Error: wrong syntax at " << anArg << "\n";
10587 aDefParams->SetDeviationAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
10589 else if (anArg == "-AUTOTR"
10590 || anArg == "-AUTOTRIANG"
10591 || anArg == "-AUTOTRIANGULATION")
10594 bool toTurnOn = true;
10595 if (anArgIter >= theArgsNb
10596 || !ViewerTest::ParseOnOff (theArgVec[anArgIter], toTurnOn))
10598 std::cout << "Syntax error at '" << anArg << "'\n";
10601 aDefParams->SetAutoTriangulation (toTurnOn);
10605 std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
10613 //! Auxiliary method
10614 inline void addLight (const Handle(V3d_Light)& theLightNew,
10615 const Graphic3d_ZLayerId theLayer,
10616 const Standard_Boolean theIsGlobal)
10618 if (theLightNew.IsNull())
10623 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10624 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
10626 aViewer->AddLight (theLightNew);
10629 aViewer->SetLightOn (theLightNew);
10633 ViewerTest::CurrentView()->SetLightOn (theLightNew);
10638 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
10639 if (aSettings.Lights().IsNull())
10641 aSettings.SetLights (new Graphic3d_LightSet());
10643 aSettings.Lights()->Add (theLightNew);
10644 aViewer->SetZLayerSettings (theLayer, aSettings);
10648 //! Auxiliary method
10649 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
10651 TCollection_AsciiString anArgNextCase (theArgNext);
10652 anArgNextCase.UpperCase();
10653 if (anArgNextCase.Length() > 5
10654 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
10656 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
10660 return theArgNext.IntegerValue();
10664 //===============================================================================================
10665 //function : VLight
10667 //===============================================================================================
10668 static int VLight (Draw_Interpretor& theDi,
10669 Standard_Integer theArgsNb,
10670 const char** theArgVec)
10672 Handle(V3d_View) aView = ViewerTest::CurrentView();
10673 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10675 || aViewer.IsNull())
10677 std::cerr << "No active viewer!\n";
10681 Standard_Real anXYZ[3] = {};
10682 Standard_Real anAtten[2] = {};
10685 // print lights info
10686 Standard_Integer aLightId = 0;
10687 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
10689 Handle(V3d_Light) aLight = aLightIter.Value();
10690 const Quantity_Color aColor = aLight->Color();
10691 theDi << "Light #" << aLightId
10692 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
10693 << " [" << aLight->GetId() << "]" << "\n";
10694 switch (aLight->Type())
10698 theDi << " Type: Ambient\n";
10699 theDi << " Intensity: " << aLight->Intensity() << "\n";
10702 case V3d_DIRECTIONAL:
10704 theDi << " Type: Directional\n";
10705 theDi << " Intensity: " << aLight->Intensity() << "\n";
10706 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10707 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10708 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10709 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10712 case V3d_POSITIONAL:
10714 theDi << " Type: Positional\n";
10715 theDi << " Intensity: " << aLight->Intensity() << "\n";
10716 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10717 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10718 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10719 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10720 aLight->Attenuation (anAtten[0], anAtten[1]);
10721 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10722 theDi << " Range: " << aLight->Range() << "\n";
10727 theDi << " Type: Spot\n";
10728 theDi << " Intensity: " << aLight->Intensity() << "\n";
10729 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10730 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10731 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10732 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10733 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10734 aLight->Attenuation (anAtten[0], anAtten[1]);
10735 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10736 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
10737 theDi << " Exponent: " << aLight->Concentration() << "\n";
10738 theDi << " Range: " << aLight->Range() << "\n";
10743 theDi << " Type: UNKNOWN\n";
10747 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
10751 Handle(V3d_Light) aLightNew;
10752 Handle(V3d_Light) aLightOld;
10753 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
10754 Standard_Boolean isGlobal = Standard_True;
10755 Standard_Boolean toCreate = Standard_False;
10756 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10757 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
10759 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
10761 TCollection_AsciiString aName, aValue;
10762 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
10763 TCollection_AsciiString anArgCase (anArg);
10764 anArgCase.UpperCase();
10765 if (anUpdateTool.parseRedrawMode (anArg))
10770 if (anArgCase.IsEqual ("NEW")
10771 || anArgCase.IsEqual ("ADD")
10772 || anArgCase.IsEqual ("CREATE")
10773 || anArgCase.IsEqual ("-NEW")
10774 || anArgCase.IsEqual ("-ADD")
10775 || anArgCase.IsEqual ("-CREATE"))
10777 toCreate = Standard_True;
10779 else if (anArgCase.IsEqual ("-LAYER")
10780 || anArgCase.IsEqual ("-ZLAYER"))
10782 if (++anArgIt >= theArgsNb)
10784 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10788 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
10789 aValStr.LowerCase();
10790 if (aValStr == "default"
10791 || aValStr == "def")
10793 aLayer = Graphic3d_ZLayerId_Default;
10795 else if (aValStr == "top")
10797 aLayer = Graphic3d_ZLayerId_Top;
10799 else if (aValStr == "topmost")
10801 aLayer = Graphic3d_ZLayerId_Topmost;
10803 else if (aValStr == "toposd"
10804 || aValStr == "osd")
10806 aLayer = Graphic3d_ZLayerId_TopOSD;
10808 else if (aValStr == "botosd"
10809 || aValStr == "bottom")
10811 aLayer = Graphic3d_ZLayerId_BotOSD;
10813 else if (aValStr.IsIntegerValue())
10815 aLayer = Draw::Atoi (theArgVec[anArgIt]);
10819 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
10823 else if (anArgCase.IsEqual ("GLOB")
10824 || anArgCase.IsEqual ("GLOBAL")
10825 || anArgCase.IsEqual ("-GLOB")
10826 || anArgCase.IsEqual ("-GLOBAL"))
10828 isGlobal = Standard_True;
10830 else if (anArgCase.IsEqual ("LOC")
10831 || anArgCase.IsEqual ("LOCAL")
10832 || anArgCase.IsEqual ("-LOC")
10833 || anArgCase.IsEqual ("-LOCAL"))
10835 isGlobal = Standard_False;
10837 else if (anArgCase.IsEqual ("DEF")
10838 || anArgCase.IsEqual ("DEFAULTS")
10839 || anArgCase.IsEqual ("-DEF")
10840 || anArgCase.IsEqual ("-DEFAULTS"))
10842 toCreate = Standard_False;
10843 aViewer->SetDefaultLights();
10845 else if (anArgCase.IsEqual ("CLR")
10846 || anArgCase.IsEqual ("CLEAR")
10847 || anArgCase.IsEqual ("-CLR")
10848 || anArgCase.IsEqual ("-CLEAR"))
10850 toCreate = Standard_False;
10852 TColStd_SequenceOfInteger aLayers;
10853 aViewer->GetAllZLayers (aLayers);
10854 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10856 if (aLayeriter.Value() == aLayer
10857 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10859 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10860 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10861 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10862 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10869 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10871 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
10873 Handle(V3d_Light) aLight = aLightIter.Value();
10874 aViewer->DelLight (aLight);
10875 aLightIter = aView->ActiveLightIterator();
10879 else if (anArgCase.IsEqual ("AMB")
10880 || anArgCase.IsEqual ("AMBIENT")
10881 || anArgCase.IsEqual ("AMBLIGHT"))
10885 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10889 addLight (aLightNew, aLayer, isGlobal);
10890 toCreate = Standard_False;
10891 aLightNew = new V3d_AmbientLight();
10893 else if (anArgCase.IsEqual ("DIRECTIONAL")
10894 || anArgCase.IsEqual ("DIRLIGHT"))
10898 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10902 addLight (aLightNew, aLayer, isGlobal);
10903 toCreate = Standard_False;
10904 aLightNew = new V3d_DirectionalLight();
10906 else if (anArgCase.IsEqual ("SPOT")
10907 || anArgCase.IsEqual ("SPOTLIGHT"))
10911 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10915 addLight (aLightNew, aLayer, isGlobal);
10916 toCreate = Standard_False;
10917 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
10919 else if (anArgCase.IsEqual ("POSLIGHT")
10920 || anArgCase.IsEqual ("POSITIONAL"))
10924 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10928 addLight (aLightNew, aLayer, isGlobal);
10929 toCreate = Standard_False;
10930 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
10932 else if (anArgCase.IsEqual ("CHANGE")
10933 || anArgCase.IsEqual ("-CHANGE"))
10935 if (++anArgIt >= theArgsNb)
10937 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10941 addLight (aLightNew, aLayer, isGlobal);
10942 aLightNew.Nullify();
10943 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
10944 Standard_Integer aLightIt = 0;
10945 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10947 if (aLightIt == aLightId)
10949 aLightOld = aLightIter.Value();
10954 if (aLightOld.IsNull())
10956 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
10960 else if (anArgCase.IsEqual ("DEL")
10961 || anArgCase.IsEqual ("DELETE")
10962 || anArgCase.IsEqual ("-DEL")
10963 || anArgCase.IsEqual ("-DELETE"))
10965 Handle(V3d_Light) aLightDel;
10966 if (++anArgIt >= theArgsNb)
10968 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10972 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10973 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
10974 Standard_Integer aLightIt = 0;
10975 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10977 aLightDel = aLightIter.Value();
10978 if (aLightIt == aLightDelId)
10983 if (aLightDel.IsNull())
10988 TColStd_SequenceOfInteger aLayers;
10989 aViewer->GetAllZLayers (aLayers);
10990 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10992 if (aLayeriter.Value() == aLayer
10993 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10995 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10996 if (!aSettings.Lights().IsNull())
10998 aSettings.Lights()->Remove (aLightDel);
10999 if (aSettings.Lights()->IsEmpty())
11001 aSettings.SetLights (Handle(Graphic3d_LightSet)());
11004 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
11005 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
11012 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
11014 aViewer->DelLight (aLightDel);
11017 else if (anArgCase.IsEqual ("COLOR")
11018 || anArgCase.IsEqual ("COLOUR")
11019 || anArgCase.IsEqual ("-COLOR")
11020 || anArgCase.IsEqual ("-COLOUR"))
11022 if (++anArgIt >= theArgsNb
11023 || aLightCurr.IsNull())
11025 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11029 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
11030 anArgNext.UpperCase();
11031 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
11032 aLightCurr->SetColor (aColor);
11034 else if (anArgCase.IsEqual ("POS")
11035 || anArgCase.IsEqual ("POSITION")
11036 || anArgCase.IsEqual ("-POS")
11037 || anArgCase.IsEqual ("-POSITION"))
11039 if ((anArgIt + 3) >= theArgsNb
11040 || aLightCurr.IsNull()
11041 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11042 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11044 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11048 anXYZ[0] = Atof (theArgVec[++anArgIt]);
11049 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11050 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11051 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
11053 else if (anArgCase.IsEqual ("DIR")
11054 || anArgCase.IsEqual ("DIRECTION")
11055 || anArgCase.IsEqual ("-DIR")
11056 || anArgCase.IsEqual ("-DIRECTION"))
11058 if ((anArgIt + 3) >= theArgsNb
11059 || aLightCurr.IsNull()
11060 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
11061 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11063 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11067 anXYZ[0] = Atof (theArgVec[++anArgIt]);
11068 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11069 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11070 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
11072 else if (anArgCase.IsEqual ("SM")
11073 || anArgCase.IsEqual ("SMOOTHNESS")
11074 || anArgCase.IsEqual ("-SM")
11075 || anArgCase.IsEqual ("-SMOOTHNESS"))
11077 if (++anArgIt >= theArgsNb
11078 || aLightCurr.IsNull())
11080 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11084 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11085 if (Abs (aSmoothness) <= ShortRealEpsilon())
11087 aLightCurr->SetIntensity (1.f);
11089 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
11091 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
11095 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
11096 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
11099 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
11101 aLightCurr->SetSmoothRadius (aSmoothness);
11103 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
11105 aLightCurr->SetSmoothAngle (aSmoothness);
11108 else if (anArgCase.IsEqual ("INT")
11109 || anArgCase.IsEqual ("INTENSITY")
11110 || anArgCase.IsEqual ("-INT")
11111 || anArgCase.IsEqual ("-INTENSITY"))
11113 if (++anArgIt >= theArgsNb
11114 || aLightCurr.IsNull())
11116 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11120 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11121 aLightCurr->SetIntensity (aIntensity);
11123 else if (anArgCase.IsEqual ("ANG")
11124 || anArgCase.IsEqual ("ANGLE")
11125 || anArgCase.IsEqual ("-ANG")
11126 || anArgCase.IsEqual ("-ANGLE"))
11128 if (++anArgIt >= theArgsNb
11129 || aLightCurr.IsNull()
11130 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11132 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11136 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11137 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
11139 else if (anArgCase.IsEqual ("CONSTATTEN")
11140 || anArgCase.IsEqual ("CONSTATTENUATION")
11141 || anArgCase.IsEqual ("-CONSTATTEN")
11142 || anArgCase.IsEqual ("-CONSTATTENUATION"))
11144 if (++anArgIt >= theArgsNb
11145 || aLightCurr.IsNull()
11146 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11147 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11149 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11153 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11154 anAtten[0] = Atof (theArgVec[anArgIt]);
11155 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11157 else if (anArgCase.IsEqual ("LINATTEN")
11158 || anArgCase.IsEqual ("LINEARATTEN")
11159 || anArgCase.IsEqual ("LINEARATTENUATION")
11160 || anArgCase.IsEqual ("-LINATTEN")
11161 || anArgCase.IsEqual ("-LINEARATTEN")
11162 || anArgCase.IsEqual ("-LINEARATTENUATION"))
11164 if (++anArgIt >= theArgsNb
11165 || aLightCurr.IsNull()
11166 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11167 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11169 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11173 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11174 anAtten[1] = Atof (theArgVec[anArgIt]);
11175 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11177 else if (anArgCase.IsEqual ("EXP")
11178 || anArgCase.IsEqual ("EXPONENT")
11179 || anArgCase.IsEqual ("SPOTEXP")
11180 || anArgCase.IsEqual ("SPOTEXPONENT")
11181 || anArgCase.IsEqual ("-EXP")
11182 || anArgCase.IsEqual ("-EXPONENT")
11183 || anArgCase.IsEqual ("-SPOTEXP")
11184 || anArgCase.IsEqual ("-SPOTEXPONENT"))
11186 if (++anArgIt >= theArgsNb
11187 || aLightCurr.IsNull()
11188 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11190 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11194 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
11196 else if (anArgCase.IsEqual("RANGE")
11197 || anArgCase.IsEqual("-RANGE"))
11199 if (++anArgIt >= theArgsNb
11200 || aLightCurr.IsNull()
11201 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT
11202 || aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
11204 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11208 aLightCurr->SetRange ((Standard_ShortReal)Atof (theArgVec[anArgIt]));
11210 else if (anArgCase.IsEqual ("HEAD")
11211 || anArgCase.IsEqual ("HEADLIGHT")
11212 || anArgCase.IsEqual ("-HEAD")
11213 || anArgCase.IsEqual ("-HEADLIGHT"))
11215 if (aLightCurr.IsNull()
11216 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
11218 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11222 Standard_Boolean isHeadLight = Standard_True;
11223 if (anArgIt + 1 < theArgsNb
11224 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
11228 aLightCurr->SetHeadlight (isHeadLight);
11232 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
11236 addLight (aLightNew, aLayer, isGlobal);
11240 //===============================================================================================
11241 //function : VPBREnvironment
11243 //===============================================================================================
11244 static int VPBREnvironment (Draw_Interpretor&,
11245 Standard_Integer theArgsNb,
11246 const char** theArgVec)
11250 std::cerr << "Error: 'vpbrenv' command has only one argument\n";
11254 Handle(V3d_View) aView = ViewerTest::CurrentView();
11255 if (aView.IsNull())
11257 std::cerr << "Error: no active viewer!\n";
11261 TCollection_AsciiString anArg = TCollection_AsciiString (theArgVec[1]);
11264 if (anArg == "-generate"
11265 || anArg == "-gen")
11267 aView->GeneratePBREnvironment (Standard_True);
11269 else if (anArg == "-clear")
11271 aView->ClearPBREnvironment (Standard_True);
11275 std::cerr << "Error: unknown argument [" << theArgVec[1] << "] for 'vpbrenv' command\n";
11282 //! Read Graphic3d_RenderingParams::PerfCounters flag.
11283 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
11284 Standard_Boolean& theToReset,
11285 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
11286 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
11288 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
11289 TCollection_AsciiString aVal = theValue;
11290 Standard_Boolean toReverse = Standard_False;
11291 if (aVal == "none")
11293 theToReset = Standard_True;
11294 return Standard_True;
11296 else if (aVal.StartsWith ("-"))
11298 toReverse = Standard_True;
11299 aVal = aVal.SubString (2, aVal.Length());
11301 else if (aVal.StartsWith ("no"))
11303 toReverse = Standard_True;
11304 aVal = aVal.SubString (3, aVal.Length());
11306 else if (aVal.StartsWith ("+"))
11308 aVal = aVal.SubString (2, aVal.Length());
11312 theToReset = Standard_True;
11316 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11317 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
11318 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
11319 else if (aVal == "structs"
11320 || aVal == "structures"
11321 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
11322 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
11323 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11324 else if (aVal == "tris"
11325 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
11326 else if (aVal == "pnts"
11327 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
11328 else if (aVal == "mem"
11329 || aVal == "gpumem"
11330 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11331 else if (aVal == "skipimmediate"
11332 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
11333 else if (aVal == "frametime"
11334 || aVal == "frametimers"
11335 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11336 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
11337 else if (aVal == "extended"
11338 || aVal == "verbose"
11339 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
11340 else if (aVal == "full"
11341 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
11344 return Standard_False;
11349 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
11353 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
11355 return Standard_True;
11358 //! Read Graphic3d_RenderingParams::PerfCounters flags.
11359 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
11360 Graphic3d_RenderingParams::PerfCounters& theFlags)
11362 TCollection_AsciiString aValue = theValue;
11363 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
11364 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
11365 Standard_Boolean toReset = Standard_False;
11368 Standard_Integer aSplitPos = aValue.Search ("|");
11369 if (aSplitPos <= 0)
11371 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
11373 return Standard_False;
11377 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
11379 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
11380 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
11381 return Standard_True;
11386 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
11387 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
11389 return Standard_False;
11392 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
11396 //=======================================================================
11397 //function : VRenderParams
11398 //purpose : Enables/disables rendering features
11399 //=======================================================================
11401 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
11402 Standard_Integer theArgNb,
11403 const char** theArgVec)
11405 Handle(V3d_View) aView = ViewerTest::CurrentView();
11406 if (aView.IsNull())
11408 std::cerr << "Error: no active viewer!\n";
11412 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
11413 TCollection_AsciiString aCmdName (theArgVec[0]);
11414 aCmdName.LowerCase();
11415 if (aCmdName == "vraytrace")
11419 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
11422 else if (theArgNb == 2)
11424 TCollection_AsciiString aValue (theArgVec[1]);
11425 aValue.LowerCase();
11429 aParams.Method = Graphic3d_RM_RAYTRACING;
11433 else if (aValue == "off"
11436 aParams.Method = Graphic3d_RM_RASTERIZATION;
11442 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
11448 std::cout << "Error: wrong number of arguments\n";
11455 theDI << "renderMode: ";
11456 switch (aParams.Method)
11458 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11459 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
11462 theDI << "transparency: ";
11463 switch (aParams.TransparencyMethod)
11465 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
11466 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
11467 << TCollection_AsciiString (aParams.OitDepthFactor); break;
11470 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
11471 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
11472 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
11473 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
11474 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
11475 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
11476 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
11477 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
11478 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
11479 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
11480 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
11481 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
11482 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
11483 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
11484 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
11485 theDI << "shadingModel: ";
11486 switch (aView->ShadingModel())
11488 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11489 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
11490 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
11491 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
11492 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
11493 case Graphic3d_TOSM_PBR: theDI << "pbr"; break;
11494 case Graphic3d_TOSM_PBR_FACET: theDI << "pbr_facet"; break;
11497 theDI << "perfCounters:";
11498 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
11502 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
11506 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
11508 theDI << " structs";
11510 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
11512 theDI << " groups";
11514 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
11516 theDI << " arrays";
11518 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
11522 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
11526 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
11528 theDI << " gpumem";
11530 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
11532 theDI << " frameTime";
11534 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
11536 theDI << " skipimmediate";
11538 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
11544 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
11545 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
11546 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
11547 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
11548 "noUpdate") << "\n";
11553 Standard_Boolean toPrint = Standard_False;
11554 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
11555 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11557 Standard_CString anArg (theArgVec[anArgIter]);
11558 TCollection_AsciiString aFlag (anArg);
11560 if (anUpdateTool.parseRedrawMode (aFlag))
11564 else if (aFlag == "-echo"
11565 || aFlag == "-print")
11567 toPrint = Standard_True;
11568 anUpdateTool.Invalidate();
11570 else if (aFlag == "-mode"
11571 || aFlag == "-rendermode"
11572 || aFlag == "-render_mode")
11576 switch (aParams.Method)
11578 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11579 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
11585 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11589 else if (aFlag == "-ray"
11590 || aFlag == "-raytrace")
11594 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
11598 aParams.Method = Graphic3d_RM_RAYTRACING;
11600 else if (aFlag == "-rast"
11601 || aFlag == "-raster"
11602 || aFlag == "-rasterization")
11606 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
11610 aParams.Method = Graphic3d_RM_RASTERIZATION;
11612 else if (aFlag == "-msaa")
11616 theDI << aParams.NbMsaaSamples << " ";
11619 else if (++anArgIter >= theArgNb)
11621 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11625 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
11626 if (aNbSamples < 0)
11628 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
11633 aParams.NbMsaaSamples = aNbSamples;
11636 else if (aFlag == "-linefeather"
11637 || aFlag == "-edgefeather"
11638 || aFlag == "-feather")
11642 theDI << " " << aParams.LineFeather << " ";
11645 else if (++anArgIter >= theArgNb)
11647 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11651 TCollection_AsciiString aParam = theArgVec[anArgIter];
11652 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11653 if (aFeather <= 0.0f)
11655 std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n";
11658 aParams.LineFeather = aFeather;
11660 else if (aFlag == "-oit")
11664 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
11666 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
11670 theDI << "off" << " ";
11674 else if (++anArgIter >= theArgNb)
11676 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11680 TCollection_AsciiString aParam = theArgVec[anArgIter];
11681 aParam.LowerCase();
11682 if (aParam.IsRealValue())
11684 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11685 if (aWeight < 0.f || aWeight > 1.f)
11687 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
11691 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
11692 aParams.OitDepthFactor = aWeight;
11694 else if (aParam == "off")
11696 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
11700 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11704 else if (aFlag == "-depthprepass")
11708 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
11711 aParams.ToEnableDepthPrepass = Standard_True;
11712 if (anArgIter + 1 < theArgNb
11713 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
11718 else if (aFlag == "-samplealphatocoverage"
11719 || aFlag == "-alphatocoverage")
11723 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
11726 aParams.ToEnableAlphaToCoverage = Standard_True;
11727 if (anArgIter + 1 < theArgNb
11728 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
11733 else if (aFlag == "-rendscale"
11734 || aFlag == "-renderscale"
11735 || aFlag == "-renderresolutionscale")
11739 theDI << aParams.RenderResolutionScale << " ";
11742 else if (++anArgIter >= theArgNb)
11744 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11748 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
11751 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
11756 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
11759 else if (aFlag == "-raydepth"
11760 || aFlag == "-ray_depth")
11764 theDI << aParams.RaytracingDepth << " ";
11767 else if (++anArgIter >= theArgNb)
11769 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11773 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
11775 // We allow RaytracingDepth be more than 10 in case of GI enabled
11776 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
11778 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
11783 aParams.RaytracingDepth = aDepth;
11786 else if (aFlag == "-shad"
11787 || aFlag == "-shadows")
11791 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
11795 Standard_Boolean toEnable = Standard_True;
11796 if (++anArgIter < theArgNb
11797 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11801 aParams.IsShadowEnabled = toEnable;
11803 else if (aFlag == "-refl"
11804 || aFlag == "-reflections")
11808 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
11812 Standard_Boolean toEnable = Standard_True;
11813 if (++anArgIter < theArgNb
11814 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11818 aParams.IsReflectionEnabled = toEnable;
11820 else if (aFlag == "-fsaa")
11824 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
11828 Standard_Boolean toEnable = Standard_True;
11829 if (++anArgIter < theArgNb
11830 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11834 aParams.IsAntialiasingEnabled = toEnable;
11836 else if (aFlag == "-gleam")
11840 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
11844 Standard_Boolean toEnable = Standard_True;
11845 if (++anArgIter < theArgNb
11846 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11850 aParams.IsTransparentShadowEnabled = toEnable;
11852 else if (aFlag == "-gi")
11856 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
11860 Standard_Boolean toEnable = Standard_True;
11861 if (++anArgIter < theArgNb
11862 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11866 aParams.IsGlobalIlluminationEnabled = toEnable;
11869 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
11872 else if (aFlag == "-blockedrng"
11873 || aFlag == "-brng")
11877 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
11881 Standard_Boolean toEnable = Standard_True;
11882 if (++anArgIter < theArgNb
11883 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11887 aParams.CoherentPathTracingMode = toEnable;
11889 else if (aFlag == "-maxrad")
11893 theDI << aParams.RadianceClampingValue << " ";
11896 else if (++anArgIter >= theArgNb)
11898 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11902 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
11903 if (!aMaxRadStr.IsRealValue())
11905 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11909 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
11910 if (aMaxRadiance <= 0.0)
11912 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
11917 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
11920 else if (aFlag == "-iss")
11924 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
11928 Standard_Boolean toEnable = Standard_True;
11929 if (++anArgIter < theArgNb
11930 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11934 aParams.AdaptiveScreenSampling = toEnable;
11936 else if (aFlag == "-issatomic")
11940 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
11944 Standard_Boolean toEnable = Standard_True;
11945 if (++anArgIter < theArgNb
11946 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11950 aParams.AdaptiveScreenSamplingAtomic = toEnable;
11952 else if (aFlag == "-issd")
11956 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
11960 Standard_Boolean toEnable = Standard_True;
11961 if (++anArgIter < theArgNb
11962 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11966 aParams.ShowSamplingTiles = toEnable;
11968 else if (aFlag == "-tilesize")
11972 theDI << aParams.RayTracingTileSize << " ";
11975 else if (++anArgIter >= theArgNb)
11977 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11981 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
11984 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
11987 aParams.RayTracingTileSize = aTileSize;
11989 else if (aFlag == "-nbtiles")
11993 theDI << aParams.NbRayTracingTiles << " ";
11996 else if (++anArgIter >= theArgNb)
11998 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12002 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
12005 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
12008 else if (aNbTiles > 0
12010 || aNbTiles > 1024))
12012 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
12014 aParams.NbRayTracingTiles = aNbTiles;
12016 else if (aFlag == "-env")
12020 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
12024 Standard_Boolean toEnable = Standard_True;
12025 if (++anArgIter < theArgNb
12026 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12030 aParams.UseEnvironmentMapBackground = toEnable;
12032 else if (aFlag == "-ignorenormalmap")
12036 theDI << (aParams.ToIgnoreNormalMapInRayTracing ? "on" : "off") << " ";
12040 Standard_Boolean toEnable = Standard_True;
12041 if (++anArgIter < theArgNb
12042 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12046 aParams.ToIgnoreNormalMapInRayTracing = toEnable;
12048 else if (aFlag == "-twoside")
12052 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
12056 Standard_Boolean toEnable = Standard_True;
12057 if (++anArgIter < theArgNb
12058 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12062 aParams.TwoSidedBsdfModels = toEnable;
12064 else if (aFlag == "-shademodel"
12065 || aFlag == "-shadingmodel"
12066 || aFlag == "-shading")
12070 switch (aView->ShadingModel())
12072 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
12073 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
12074 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
12075 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
12076 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
12077 case Graphic3d_TOSM_PBR: theDI << "pbr"; break;
12078 case Graphic3d_TOSM_PBR_FACET: theDI << "pbr_facet"; break;
12083 if (++anArgIter >= theArgNb)
12085 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12088 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
12089 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
12090 && aModel != Graphic3d_TOSM_DEFAULT)
12092 aView->SetShadingModel (aModel);
12096 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
12100 else if (aFlag == "-pbrenvpow2size"
12101 || aFlag == "-pbrenvp2s"
12102 || aFlag == "-pep2s")
12104 if (++anArgIter >= theArgNb)
12106 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12110 const Standard_Integer aPbrEnvPow2Size = Draw::Atoi (theArgVec[anArgIter]);
12111 if (aPbrEnvPow2Size < 1)
12113 std::cout << "Error: 'Pow2Size' of PBR Environment has to be greater or equal 1\n";
12116 aParams.PbrEnvPow2Size = aPbrEnvPow2Size;
12118 else if (aFlag == "-pbrenvspecmaplevelsnumber"
12119 || aFlag == "-pbrenvspecmapnblevels"
12120 || aFlag == "-pbrenvspecmaplevels"
12121 || aFlag == "-pbrenvsmln"
12122 || aFlag == "-pesmln")
12124 if (++anArgIter >= theArgNb)
12126 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12130 const Standard_Integer aPbrEnvSpecMapNbLevels = Draw::Atoi (theArgVec[anArgIter]);
12131 if (aPbrEnvSpecMapNbLevels < 2)
12133 std::cout << "Error: 'SpecMapLevelsNumber' of PBR Environment has to be greater or equal 2\n";
12136 aParams.PbrEnvSpecMapNbLevels = aPbrEnvSpecMapNbLevels;
12138 else if (aFlag == "-pbrenvbakngdiffsamplesnumber"
12139 || aFlag == "-pbrenvbakingdiffsamples"
12140 || aFlag == "-pbrenvbdsn")
12142 if (++anArgIter >= theArgNb)
12144 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12148 const Standard_Integer aPbrEnvBakingDiffNbSamples = Draw::Atoi (theArgVec[anArgIter]);
12149 if (aPbrEnvBakingDiffNbSamples < 1)
12151 std::cout << "Error: 'BakingDiffSamplesNumber' of PBR Environtment has to be greater or equal 1\n";
12154 aParams.PbrEnvBakingDiffNbSamples = aPbrEnvBakingDiffNbSamples;
12156 else if (aFlag == "-pbrenvbakngspecsamplesnumber"
12157 || aFlag == "-pbrenvbakingspecsamples"
12158 || aFlag == "-pbrenvbssn")
12160 if (++anArgIter >= theArgNb)
12162 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12166 const Standard_Integer aPbrEnvBakingSpecNbSamples = Draw::Atoi(theArgVec[anArgIter]);
12167 if (aPbrEnvBakingSpecNbSamples < 1)
12169 std::cout << "Error: 'BakingSpecSamplesNumber' of PBR Environtment has to be greater or equal 1\n";
12172 aParams.PbrEnvBakingSpecNbSamples = aPbrEnvBakingSpecNbSamples;
12174 else if (aFlag == "-pbrenvbakingprobability"
12175 || aFlag == "-pbrenvbp")
12177 if (++anArgIter >= theArgNb)
12179 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12182 const Standard_ShortReal aPbrEnvBakingProbability = static_cast<Standard_ShortReal>(Draw::Atof (theArgVec[anArgIter]));
12183 if (aPbrEnvBakingProbability < 0.f
12184 || aPbrEnvBakingProbability > 1.f)
12186 std::cout << "Error: 'BakingProbability' of PBR Environtment has to be in range of [0, 1]\n";
12189 aParams.PbrEnvBakingProbability = aPbrEnvBakingProbability;
12191 else if (aFlag == "-resolution")
12193 if (++anArgIter >= theArgNb)
12195 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12199 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
12200 if (aResolution.IsIntegerValue())
12202 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
12206 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12210 else if (aFlag == "-rebuildglsl"
12211 || aFlag == "-rebuild")
12215 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
12219 Standard_Boolean toEnable = Standard_True;
12220 if (++anArgIter < theArgNb
12221 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12225 aParams.RebuildRayTracingShaders = toEnable;
12227 else if (aFlag == "-focal")
12229 if (++anArgIter >= theArgNb)
12231 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12235 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12236 if (aParam.IsRealValue())
12238 float aFocalDist = static_cast<float> (aParam.RealValue());
12239 if (aFocalDist < 0)
12241 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12244 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
12248 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12252 else if (aFlag == "-aperture")
12254 if (++anArgIter >= theArgNb)
12256 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12260 TCollection_AsciiString aParam(theArgVec[anArgIter]);
12261 if (aParam.IsRealValue())
12263 float aApertureSize = static_cast<float> (aParam.RealValue());
12264 if (aApertureSize < 0)
12266 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12269 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
12273 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12277 else if (aFlag == "-exposure")
12279 if (++anArgIter >= theArgNb)
12281 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12285 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
12286 if (anExposure.IsRealValue())
12288 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
12292 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12296 else if (aFlag == "-whitepoint")
12298 if (++anArgIter >= theArgNb)
12300 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12304 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
12305 if (aWhitePoint.IsRealValue())
12307 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
12311 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12315 else if (aFlag == "-tonemapping")
12317 if (++anArgIter >= theArgNb)
12319 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12323 TCollection_AsciiString aMode (theArgVec[anArgIter]);
12326 if (aMode == "disabled")
12328 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
12330 else if (aMode == "filmic")
12332 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
12336 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12340 else if (aFlag == "-performancestats"
12341 || aFlag == "-performancecounters"
12342 || aFlag == "-perfstats"
12343 || aFlag == "-perfcounters"
12344 || aFlag == "-stats")
12346 if (++anArgIter >= theArgNb)
12348 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12352 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
12353 aFlagsStr.LowerCase();
12354 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
12355 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
12357 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12360 aView->ChangeRenderingParams().CollectedStats = aFlags;
12361 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
12363 else if (aFlag == "-perfupdateinterval"
12364 || aFlag == "-statsupdateinterval")
12366 if (++anArgIter >= theArgNb)
12368 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12371 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12373 else if (aFlag == "-perfchart"
12374 || aFlag == "-statschart")
12376 if (++anArgIter >= theArgNb)
12378 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12381 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
12383 else if (aFlag == "-perfchartmax"
12384 || aFlag == "-statschartmax")
12386 if (++anArgIter >= theArgNb)
12388 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12391 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12393 else if (aFlag == "-frustumculling"
12394 || aFlag == "-culling")
12398 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
12399 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
12400 "noUpdate") << " ";
12404 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
12405 if (++anArgIter < theArgNb)
12407 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
12408 aStateStr.LowerCase();
12409 bool toEnable = true;
12410 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
12412 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
12414 else if (aStateStr == "noupdate"
12415 || aStateStr == "freeze")
12417 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
12424 aParams.FrustumCullingState = aState;
12428 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
12436 //=======================================================================
12437 //function : searchInfo
12439 //=======================================================================
12440 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
12441 const TCollection_AsciiString& theKey)
12443 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
12445 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
12447 return anIter.Value();
12450 return TCollection_AsciiString();
12453 //=======================================================================
12454 //function : VStatProfiler
12456 //=======================================================================
12457 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
12458 Standard_Integer theArgNb,
12459 const char** theArgVec)
12461 Handle(V3d_View) aView = ViewerTest::CurrentView();
12462 if (aView.IsNull())
12464 std::cerr << "Error: no active viewer!\n";
12468 Standard_Boolean toRedraw = Standard_True;
12469 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
12470 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
12471 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
12472 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12474 Standard_CString anArg (theArgVec[anArgIter]);
12475 TCollection_AsciiString aFlag (anArg);
12477 if (aFlag == "-noredraw")
12479 toRedraw = Standard_False;
12483 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
12484 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
12485 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
12486 else if (aFlag == "alllayers"
12487 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
12488 else if (aFlag == "allstructs"
12489 || aFlag == "allstructures"
12490 || aFlag == "structs"
12491 || aFlag == "structures") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
12492 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
12493 else if (aFlag == "allarrays"
12494 || aFlag == "fillarrays"
12495 || aFlag == "linearrays"
12496 || aFlag == "pointarrays"
12497 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
12498 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
12499 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
12500 else if (aFlag == "geommem"
12501 || aFlag == "texturemem"
12502 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
12503 else if (aFlag == "elapsedframe"
12504 || aFlag == "cpuframeaverage"
12505 || aFlag == "cpupickingaverage"
12506 || aFlag == "cpucullingaverage"
12507 || aFlag == "cpudynaverage"
12508 || aFlag == "cpuframemax"
12509 || aFlag == "cpupickingmax"
12510 || aFlag == "cpucullingmax"
12511 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
12514 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
12518 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
12522 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
12524 aView->ChangeRenderingParams().CollectedStats =
12525 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
12529 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12531 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12534 TColStd_IndexedDataMapOfStringString aDict;
12535 aView->StatisticInformation (aDict);
12537 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
12539 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12541 Standard_CString anArg(theArgVec[anArgIter]);
12542 TCollection_AsciiString aFlag(anArg);
12544 if (aFlag == "fps")
12546 theDI << searchInfo (aDict, "FPS") << " ";
12548 else if (aFlag == "cpu")
12550 theDI << searchInfo (aDict, "CPU FPS") << " ";
12552 else if (aFlag == "alllayers")
12554 theDI << searchInfo (aDict, "Layers") << " ";
12556 else if (aFlag == "layers")
12558 theDI << searchInfo (aDict, "Rendered layers") << " ";
12560 else if (aFlag == "allstructs"
12561 || aFlag == "allstructures")
12563 theDI << searchInfo (aDict, "Structs") << " ";
12565 else if (aFlag == "structs"
12566 || aFlag == "structures")
12568 TCollection_AsciiString aRend = searchInfo (aDict, "Rendered structs");
12569 if (aRend.IsEmpty()) // all structures rendered
12571 aRend = searchInfo (aDict, "Structs");
12573 theDI << aRend << " ";
12575 else if (aFlag == "groups")
12577 theDI << searchInfo (aDict, "Rendered groups") << " ";
12579 else if (aFlag == "allarrays")
12581 theDI << searchInfo (aDict, "Rendered arrays") << " ";
12583 else if (aFlag == "fillarrays")
12585 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
12587 else if (aFlag == "linearrays")
12589 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
12591 else if (aFlag == "pointarrays")
12593 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
12595 else if (aFlag == "textarrays")
12597 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
12599 else if (aFlag == "triangles")
12601 theDI << searchInfo (aDict, "Rendered triangles") << " ";
12603 else if (aFlag == "points")
12605 theDI << searchInfo (aDict, "Rendered points") << " ";
12607 else if (aFlag == "geommem")
12609 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
12611 else if (aFlag == "texturemem")
12613 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
12615 else if (aFlag == "framemem")
12617 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
12619 else if (aFlag == "elapsedframe")
12621 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
12623 else if (aFlag == "cpuframe_average")
12625 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
12627 else if (aFlag == "cpupicking_average")
12629 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
12631 else if (aFlag == "cpuculling_average")
12633 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
12635 else if (aFlag == "cpudyn_average")
12637 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
12639 else if (aFlag == "cpuframe_max")
12641 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
12643 else if (aFlag == "cpupicking_max")
12645 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
12647 else if (aFlag == "cpuculling_max")
12649 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
12651 else if (aFlag == "cpudyn_max")
12653 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
12661 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12663 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12665 theDI << "Statistic info:\n" << aView->StatisticInformation();
12670 //=======================================================================
12671 //function : VXRotate
12673 //=======================================================================
12674 static Standard_Integer VXRotate (Draw_Interpretor& di,
12675 Standard_Integer argc,
12676 const char ** argv)
12678 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
12679 if (aContext.IsNull())
12681 di << argv[0] << "ERROR : use 'vinit' command before \n";
12687 di << "ERROR : Usage : " << argv[0] << " name angle\n";
12691 TCollection_AsciiString aName (argv[1]);
12692 Standard_Real anAngle = Draw::Atof (argv[2]);
12695 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
12696 Handle(AIS_InteractiveObject) anIObj;
12697 if (!aMap.Find2 (aName, anIObj))
12699 di << "Use 'vdisplay' before\n";
12703 gp_Trsf aTransform;
12704 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
12705 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
12707 aContext->SetLocation (anIObj, aTransform);
12708 aContext->UpdateCurrentViewer();
12712 //===============================================================================================
12713 //function : VManipulator
12715 //===============================================================================================
12716 static int VManipulator (Draw_Interpretor& theDi,
12717 Standard_Integer theArgsNb,
12718 const char** theArgVec)
12720 Handle(V3d_View) aCurrentView = ViewerTest::CurrentView();
12721 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
12722 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
12723 if (aCurrentView.IsNull()
12724 || aViewer.IsNull())
12726 std::cerr << "No active viewer!\n";
12730 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
12731 Standard_Integer anArgIter = 1;
12732 for (; anArgIter < theArgsNb; ++anArgIter)
12734 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
12737 ViewerTest_CmdParser aCmd;
12738 aCmd.SetDescription ("Manages manipulator for interactive objects:");
12739 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
12740 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
12741 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
12742 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
12743 aCmd.AddOption ("view", "... {active | [view name]} - define view in which manipulator will be displayed, 'all' by default");
12744 aCmd.AddOption ("detach", "... - detach manipulator");
12746 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
12747 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
12748 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
12750 aCmd.AddOption ("move", "... x y z - move object");
12751 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
12752 aCmd.AddOption ("scale", "... factor - scale object");
12754 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
12755 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
12756 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
12757 aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform");
12758 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
12759 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
12760 aCmd.AddOption ("parts", "... all axes mode {0|1} - set visual part");
12761 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
12762 aCmd.AddOption ("size", "... size - set size of manipulator");
12763 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
12765 aCmd.Parse (theArgsNb, theArgVec);
12767 if (aCmd.HasOption ("help"))
12769 theDi.PrintHelp (theArgVec[0]);
12773 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
12775 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
12777 if (aName.IsEmpty())
12779 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
12783 // ----------------------------------
12784 // detach existing manipulator object
12785 // ----------------------------------
12787 if (aCmd.HasOption ("detach"))
12789 if (!aMapAIS.IsBound2 (aName))
12791 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
12795 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12796 if (aManipulator.IsNull())
12798 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12802 aManipulator->Detach();
12803 aMapAIS.UnBind2 (aName);
12804 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
12809 // -----------------------------------------------
12810 // find or create manipulator if it does not exist
12811 // -----------------------------------------------
12813 Handle(AIS_Manipulator) aManipulator;
12814 if (!aMapAIS.IsBound2 (aName))
12816 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
12818 aManipulator = new AIS_Manipulator();
12819 aManipulator->SetModeActivationOnDetection (true);
12820 aMapAIS.Bind (aManipulator, aName);
12824 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12825 if (aManipulator.IsNull())
12827 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12832 // -----------------------------------------
12833 // change properties of manipulator instance
12834 // -----------------------------------------
12836 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
12838 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
12840 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
12842 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
12844 if (aCmd.HasOption ("followRotation", 1, Standard_True))
12846 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
12848 if (aCmd.HasOption("followDragging", 1, Standard_True))
12850 aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging"));
12852 if (aCmd.HasOption ("gap", 1, Standard_True))
12854 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
12856 if (aCmd.HasOption ("part", 3, Standard_True))
12858 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
12859 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
12860 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
12861 if (aMode < 1 || aMode > 4)
12863 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12867 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
12869 if (aCmd.HasOption("parts", 2, Standard_True))
12871 Standard_Integer aMode = aCmd.ArgInt("parts", 0);
12872 Standard_Boolean aOnOff = aCmd.ArgBool("parts", 1);
12873 if (aMode < 1 || aMode > 4)
12875 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12879 aManipulator->SetPart(static_cast<AIS_ManipulatorMode>(aMode), aOnOff);
12881 if (aCmd.HasOption ("pos", 3, Standard_True))
12883 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
12884 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
12885 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
12887 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
12889 if (aCmd.HasOption ("size", 1, Standard_True))
12891 aManipulator->SetSize (aCmd.ArgFloat ("size"));
12893 if (aCmd.HasOption ("zoomable", 1, Standard_True))
12895 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
12897 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
12899 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
12900 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
12904 // ---------------------------------------------------
12905 // attach, detach or access manipulator from an object
12906 // ---------------------------------------------------
12908 if (aCmd.HasOption ("attach"))
12910 // Find an object and attach manipulator to it
12911 if (!aCmd.HasOption ("attach", 1, Standard_True))
12916 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
12917 Handle(AIS_InteractiveObject) anObject;
12918 if (!aMapAIS.Find2 (anObjName, anObject))
12920 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
12924 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (aMapAIS);
12925 anIter.More(); anIter.Next())
12927 Handle(AIS_Manipulator) aManip = Handle(AIS_Manipulator)::DownCast (anIter.Key1());
12928 if (!aManip.IsNull()
12929 && aManip->IsAttached()
12930 && aManip->Object() == anObject)
12932 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
12937 AIS_Manipulator::OptionsForAttach anOptions;
12938 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
12940 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
12942 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
12944 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
12946 if (aCmd.HasOption ("enableModes", 1, Standard_True))
12948 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
12951 aManipulator->Attach (anObject, anOptions);
12953 // Check view option
12954 if (aCmd.HasOption ("view"))
12956 if (!aCmd.HasOption ("view", 1, Standard_True))
12960 TCollection_AsciiString aViewString (aCmd.Arg ("view", 0).c_str());
12961 Handle(V3d_View) aView;
12962 if (aViewString.IsEqual ("active"))
12964 aView = ViewerTest::CurrentView();
12966 else // Check view name
12968 ViewerTest_Names aViewNames (aViewString);
12969 if (!ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
12971 std::cerr << theArgVec[0] << " error: wrong view name '" << aViewString << "'\n";
12974 aView = ViewerTest_myViews.Find1 (aViewNames.GetViewName());
12975 if (aView.IsNull())
12977 std::cerr << theArgVec[0] << " error: cannot find view with name '" << aViewString << "'\n";
12981 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
12982 anIter (ViewerTest_myViews); anIter.More(); anIter.Next())
12984 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, anIter.Value(), Standard_False);
12986 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, aView, Standard_True);
12990 // --------------------------------------
12991 // apply transformation using manipulator
12992 // --------------------------------------
12994 if (aCmd.HasOption ("startTransform", 2, Standard_True))
12996 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
12998 if (aCmd.HasOption ("transform", 2, Standard_True))
13000 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
13002 if (aCmd.HasOption ("stopTransform"))
13004 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
13006 aManipulator->StopTransform (toApply);
13010 if (aCmd.HasOption ("move", 3, Standard_True))
13012 aT.SetTranslationPart (aCmd.ArgVec ("move"));
13014 if (aCmd.HasOption ("rotate", 7, Standard_True))
13016 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
13018 if (aCmd.HasOption ("scale", 1))
13020 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
13023 if (aT.Form() != gp_Identity)
13025 aManipulator->Transform (aT);
13028 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
13033 //===============================================================================================
13034 //function : VSelectionProperties
13036 //===============================================================================================
13037 static int VSelectionProperties (Draw_Interpretor& theDi,
13038 Standard_Integer theArgsNb,
13039 const char** theArgVec)
13041 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
13044 std::cerr << "No active viewer!\n";
13048 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
13050 // handle obsolete alias
13051 bool toEnable = true;
13054 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
13057 else if (theArgsNb != 2
13058 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
13060 std::cout << "Syntax error: wrong number of parameters.";
13063 if (toEnable != aCtx->ToHilightSelected())
13065 aCtx->ClearDetected();
13066 aCtx->SetToHilightSelected (toEnable);
13071 Standard_Boolean toPrint = theArgsNb == 1;
13072 Standard_Boolean toRedraw = Standard_False;
13073 Standard_Integer anArgIter = 1;
13074 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
13075 if (anArgIter < theArgsNb)
13077 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
13078 anArgFirst.LowerCase();
13080 if (anArgFirst == "dynhighlight"
13081 || anArgFirst == "dynhilight"
13082 || anArgFirst == "dynamichighlight"
13083 || anArgFirst == "dynamichilight")
13085 aType = Prs3d_TypeOfHighlight_Dynamic;
13087 else if (anArgFirst == "localdynhighlight"
13088 || anArgFirst == "localdynhilight"
13089 || anArgFirst == "localdynamichighlight"
13090 || anArgFirst == "localdynamichilight")
13092 aType = Prs3d_TypeOfHighlight_LocalDynamic;
13094 else if (anArgFirst == "selhighlight"
13095 || anArgFirst == "selhilight"
13096 || anArgFirst == "selectedhighlight"
13097 || anArgFirst == "selectedhilight")
13099 aType = Prs3d_TypeOfHighlight_Selected;
13101 else if (anArgFirst == "localselhighlight"
13102 || anArgFirst == "localselhilight"
13103 || anArgFirst == "localselectedhighlight"
13104 || anArgFirst == "localselectedhilight")
13106 aType = Prs3d_TypeOfHighlight_LocalSelected;
13113 for (; anArgIter < theArgsNb; ++anArgIter)
13115 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13117 if (anArg == "-help")
13119 theDi.PrintHelp (theArgVec[0]);
13122 else if (anArg == "-print")
13124 toPrint = Standard_True;
13126 else if (anArg == "-autoactivate")
13128 Standard_Boolean toEnable = Standard_True;
13129 if (anArgIter + 1 < theArgsNb
13130 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13134 aCtx->SetAutoActivateSelection (toEnable);
13136 else if (anArg == "-automatichighlight"
13137 || anArg == "-automatichilight"
13138 || anArg == "-autohighlight"
13139 || anArg == "-autohilight")
13141 Standard_Boolean toEnable = Standard_True;
13142 if (anArgIter + 1 < theArgsNb
13143 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13147 aCtx->ClearSelected (false);
13148 aCtx->ClearDetected();
13149 aCtx->SetAutomaticHilight (toEnable);
13152 else if (anArg == "-highlightselected"
13153 || anArg == "-hilightselected")
13155 Standard_Boolean toEnable = Standard_True;
13156 if (anArgIter + 1 < theArgsNb
13157 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13161 aCtx->ClearDetected();
13162 aCtx->SetToHilightSelected (toEnable);
13165 else if (anArg == "-pickstrategy"
13166 || anArg == "-pickingstrategy")
13168 if (++anArgIter >= theArgsNb)
13170 std::cout << "Syntax error: type of highlighting is undefined\n";
13174 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
13175 TCollection_AsciiString aVal (theArgVec[anArgIter]);
13177 if (aVal == "first"
13178 || aVal == "firstaccepted"
13179 || aVal == "firstacceptable")
13181 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
13183 else if (aVal == "topmost"
13184 || aVal == "onlyTopmost")
13186 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
13190 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
13194 aCtx->SetPickingStrategy (aStrategy);
13196 else if (anArg == "-pixtol"
13197 && anArgIter + 1 < theArgsNb)
13199 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
13201 else if ((anArg == "-mode"
13202 || anArg == "-dispmode")
13203 && anArgIter + 1 < theArgsNb)
13205 if (aType == Prs3d_TypeOfHighlight_None)
13207 std::cout << "Syntax error: type of highlighting is undefined\n";
13211 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
13212 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13213 aStyle->SetDisplayMode (aDispMode);
13214 toRedraw = Standard_True;
13216 else if (anArg == "-layer"
13217 && anArgIter + 1 < theArgsNb)
13219 if (aType == Prs3d_TypeOfHighlight_None)
13221 std::cout << "Syntax error: type of highlighting is undefined\n";
13226 Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN;
13227 if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer))
13229 std::cerr << "Error: wrong syntax at " << theArgVec[anArgIter] << ".\n";
13233 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13234 aStyle->SetZLayer (aNewLayer);
13235 toRedraw = Standard_True;
13237 else if (anArg == "-hicolor"
13238 || anArg == "-selcolor"
13239 || anArg == "-color")
13241 if (anArg.StartsWith ("-hi"))
13243 aType = Prs3d_TypeOfHighlight_Dynamic;
13245 else if (anArg.StartsWith ("-sel"))
13247 aType = Prs3d_TypeOfHighlight_Selected;
13249 else if (aType == Prs3d_TypeOfHighlight_None)
13251 std::cout << "Syntax error: type of highlighting is undefined\n";
13255 Quantity_Color aColor;
13256 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
13257 theArgVec + anArgIter + 1,
13259 if (aNbParsed == 0)
13261 std::cout << "Syntax error: need more arguments.\n";
13264 anArgIter += aNbParsed;
13266 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13267 aStyle->SetColor (aColor);
13268 toRedraw = Standard_True;
13270 else if ((anArg == "-transp"
13271 || anArg == "-transparency"
13272 || anArg == "-hitransp"
13273 || anArg == "-seltransp"
13274 || anArg == "-hitransplocal"
13275 || anArg == "-seltransplocal")
13276 && anArgIter + 1 < theArgsNb)
13278 if (anArg.StartsWith ("-hi"))
13280 aType = Prs3d_TypeOfHighlight_Dynamic;
13282 else if (anArg.StartsWith ("-sel"))
13284 aType = Prs3d_TypeOfHighlight_Selected;
13286 else if (aType == Prs3d_TypeOfHighlight_None)
13288 std::cout << "Syntax error: type of highlighting is undefined\n";
13292 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
13293 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13294 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
13295 toRedraw = Standard_True;
13297 else if ((anArg == "-mat"
13298 || anArg == "-material")
13299 && anArgIter + 1 < theArgsNb)
13301 if (aType == Prs3d_TypeOfHighlight_None)
13303 std::cout << "Syntax error: type of highlighting is undefined\n";
13307 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13308 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
13309 if (aMatName != Graphic3d_NOM_DEFAULT)
13312 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
13313 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
13314 Graphic3d_MaterialAspect aMat (aMatName);
13315 aMat.SetColor (aStyle->Color());
13316 aMat.SetTransparency (aStyle->Transparency());
13317 anAspect->SetFrontMaterial (aMat);
13318 anAspect->SetInteriorColor (aStyle->Color());
13319 aStyle->SetBasicFillAreaAspect (anAspect);
13323 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
13325 toRedraw = Standard_True;
13329 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
13335 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
13336 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
13337 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
13338 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
13339 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
13340 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
13341 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
13342 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
13343 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
13344 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
13345 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
13346 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
13347 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
13348 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
13351 if (aCtx->NbSelected() != 0 && toRedraw)
13353 aCtx->HilightSelected (Standard_True);
13359 //===============================================================================================
13360 //function : VDumpSelectionImage
13362 //===============================================================================================
13363 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
13364 Standard_Integer theArgsNb,
13365 const char** theArgVec)
13369 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
13373 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13374 if (aContext.IsNull())
13376 std::cout << "Error: no active view.\n";
13380 TCollection_AsciiString aFile;
13381 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13382 Image_Format anImgFormat = Image_Format_BGR;
13383 Standard_Integer aPickedIndex = 1;
13384 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
13386 TCollection_AsciiString aParam (theArgVec[anArgIter]);
13387 aParam.LowerCase();
13388 if (aParam == "-type")
13390 if (++anArgIter >= theArgsNb)
13392 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
13396 TCollection_AsciiString aValue (theArgVec[anArgIter]);
13397 aValue.LowerCase();
13398 if (aValue == "depth"
13399 || aValue == "normdepth"
13400 || aValue == "normalizeddepth")
13402 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13403 anImgFormat = Image_Format_GrayF;
13405 if (aValue == "depthinverted"
13406 || aValue == "normdepthinverted"
13407 || aValue == "normalizeddepthinverted"
13408 || aValue == "inverted")
13410 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
13411 anImgFormat = Image_Format_GrayF;
13413 else if (aValue == "unnormdepth"
13414 || aValue == "unnormalizeddepth")
13416 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
13417 anImgFormat = Image_Format_GrayF;
13419 else if (aValue == "objectcolor"
13420 || aValue == "object"
13421 || aValue == "color")
13423 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
13425 else if (aValue == "entitycolor"
13426 || aValue == "entity")
13428 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
13430 else if (aValue == "ownercolor"
13431 || aValue == "owner")
13433 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
13435 else if (aValue == "selectionmodecolor"
13436 || aValue == "selectionmode"
13437 || aValue == "selmodecolor"
13438 || aValue == "selmode")
13440 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
13443 else if (aParam == "-picked"
13444 || aParam == "-pickeddepth"
13445 || aParam == "-pickedindex")
13447 if (++anArgIter >= theArgsNb)
13449 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
13453 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
13455 else if (aFile.IsEmpty())
13457 aFile = theArgVec[anArgIter];
13461 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
13465 if (aFile.IsEmpty())
13467 std::cout << "Syntax error: image file name is missing.\n";
13471 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13472 Standard_Integer aWidth = 0, aHeight = 0;
13473 aView->Window()->Size (aWidth, aHeight);
13475 Image_AlienPixMap aPixMap;
13476 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
13478 std::cout << "Error: can't allocate image.\n";
13481 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
13483 std::cout << "Error: can't generate selection image.\n";
13486 if (!aPixMap.Save (aFile))
13488 std::cout << "Error: can't save selection image.\n";
13494 //===============================================================================================
13495 //function : VViewCube
13497 //===============================================================================================
13498 static int VViewCube (Draw_Interpretor& ,
13499 Standard_Integer theNbArgs,
13500 const char** theArgVec)
13502 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13503 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13504 if (aContext.IsNull() || aView.IsNull())
13506 std::cout << "Error: no active view.\n";
13509 else if (theNbArgs < 2)
13511 std::cout << "Syntax error: wrong number arguments\n";
13515 Handle(AIS_ViewCube) aViewCube;
13516 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
13517 Quantity_Color aColorRgb;
13518 TCollection_AsciiString aName;
13519 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
13521 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13523 if (anUpdateTool.parseRedrawMode (anArg))
13527 else if (aViewCube.IsNull())
13529 aName = theArgVec[anArgIter];
13530 if (aName.StartsWith ("-"))
13532 std::cout << "Syntax error: object name should be specified.\n";
13535 Handle(AIS_InteractiveObject) aPrs;
13536 GetMapOfAIS().Find2 (aName, aPrs);
13537 aViewCube = Handle(AIS_ViewCube)::DownCast (aPrs);
13538 if (aViewCube.IsNull())
13540 aViewCube = new AIS_ViewCube();
13541 aViewCube->SetBoxColor (Quantity_NOC_GRAY50);
13542 aViewCube->SetViewAnimation (ViewerTest::CurrentEventManager()->ViewAnimation());
13543 aViewCube->SetFixedAnimationLoop (false);
13546 else if (anArg == "-reset")
13548 aViewCube->ResetStyles();
13550 else if (anArg == "-color"
13551 || anArg == "-boxcolor"
13552 || anArg == "-boxsidecolor"
13553 || anArg == "-sidecolor"
13554 || anArg == "-boxedgecolor"
13555 || anArg == "-edgecolor"
13556 || anArg == "-boxcornercolor"
13557 || anArg == "-cornercolor"
13558 || anArg == "-innercolor"
13559 || anArg == "-textcolor")
13561 Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - anArgIter - 1,
13562 theArgVec + anArgIter + 1,
13564 if (aNbParsed == 0)
13566 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
13569 anArgIter += aNbParsed;
13570 if (anArg == "-boxcolor")
13572 aViewCube->SetBoxColor (aColorRgb);
13574 else if (anArg == "-boxsidecolor"
13575 || anArg == "-sidecolor")
13577 aViewCube->BoxSideStyle()->SetColor (aColorRgb);
13578 aViewCube->SynchronizeAspects();
13580 else if (anArg == "-boxedgecolor"
13581 || anArg == "-edgecolor")
13583 aViewCube->BoxEdgeStyle()->SetColor (aColorRgb);
13584 aViewCube->SynchronizeAspects();
13586 else if (anArg == "-boxcornercolor"
13587 || anArg == "-cornercolor")
13589 aViewCube->BoxCornerStyle()->SetColor (aColorRgb);
13590 aViewCube->SynchronizeAspects();
13592 else if (anArg == "-innercolor")
13594 aViewCube->SetInnerColor (aColorRgb);
13596 else if (anArg == "-textcolor")
13598 aViewCube->SetTextColor (aColorRgb);
13602 aViewCube->SetColor (aColorRgb);
13605 else if (anArgIter + 1 < theNbArgs
13606 && (anArg == "-transparency"
13607 || anArg == "-boxtransparency"))
13609 const Standard_Real aValue = Draw::Atof (theArgVec[++anArgIter]);
13610 if (aValue < 0.0 || aValue > 1.0)
13612 std::cout << "Syntax error: invalid transparency value " << theArgVec[anArgIter] << "\n";
13616 if (anArg == "-boxtransparency")
13618 aViewCube->SetBoxTransparency (aValue);
13622 aViewCube->SetTransparency (aValue);
13625 else if (anArg == "-axes"
13626 || anArg == "-edges"
13627 || anArg == "-vertices"
13628 || anArg == "-vertexes"
13629 || anArg == "-fixedanimation")
13631 bool toShow = true;
13632 if (anArgIter + 1 < theNbArgs
13633 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShow))
13637 if (anArg == "-fixedanimation")
13639 aViewCube->SetFixedAnimationLoop (toShow);
13641 else if (anArg == "-axes")
13643 aViewCube->SetDrawAxes (toShow);
13645 else if (anArg == "-edges")
13647 aViewCube->SetDrawEdges (toShow);
13651 aViewCube->SetDrawVertices (toShow);
13654 else if (anArg == "-yup"
13655 || anArg == "-zup")
13658 if (anArgIter + 1 < theNbArgs
13659 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isOn))
13663 if (anArg == "-yup")
13665 aViewCube->SetYup (isOn);
13669 aViewCube->SetYup (!isOn);
13672 else if (anArgIter + 1 < theNbArgs
13673 && anArg == "-font")
13675 aViewCube->SetFont (theArgVec[++anArgIter]);
13677 else if (anArgIter + 1 < theNbArgs
13678 && anArg == "-fontheight")
13680 aViewCube->SetFontHeight (Draw::Atof (theArgVec[++anArgIter]));
13682 else if (anArgIter + 1 < theNbArgs
13683 && (anArg == "-size"
13684 || anArg == "-boxsize"))
13686 aViewCube->SetSize (Draw::Atof (theArgVec[++anArgIter]),
13687 anArg != "-boxsize");
13689 else if (anArgIter + 1 < theNbArgs
13690 && (anArg == "-boxfacet"
13691 || anArg == "-boxfacetextension"
13692 || anArg == "-facetextension"
13693 || anArg == "-extension"))
13695 aViewCube->SetBoxFacetExtension (Draw::Atof (theArgVec[++anArgIter]));
13697 else if (anArgIter + 1 < theNbArgs
13698 && (anArg == "-boxedgegap"
13699 || anArg == "-edgegap"))
13701 aViewCube->SetBoxEdgeGap (Draw::Atof (theArgVec[++anArgIter]));
13703 else if (anArgIter + 1 < theNbArgs
13704 && (anArg == "-boxedgeminsize"
13705 || anArg == "-edgeminsize"))
13707 aViewCube->SetBoxEdgeMinSize (Draw::Atof (theArgVec[++anArgIter]));
13709 else if (anArgIter + 1 < theNbArgs
13710 && (anArg == "-boxcornerminsize"
13711 || anArg == "-cornerminsize"))
13713 aViewCube->SetBoxCornerMinSize (Draw::Atof (theArgVec[++anArgIter]));
13715 else if (anArgIter + 1 < theNbArgs
13716 && anArg == "-axespadding")
13718 aViewCube->SetAxesPadding (Draw::Atof (theArgVec[++anArgIter]));
13720 else if (anArgIter + 1 < theNbArgs
13721 && anArg == "-roundradius")
13723 aViewCube->SetRoundRadius (Draw::Atof (theArgVec[++anArgIter]));
13725 else if (anArgIter + 1 < theNbArgs
13726 && anArg == "-duration")
13728 aViewCube->SetDuration (Draw::Atof (theArgVec[++anArgIter]));
13730 else if (anArgIter + 1 < theNbArgs
13731 && anArg == "-axesradius")
13733 aViewCube->SetAxesRadius (Draw::Atof (theArgVec[++anArgIter]));
13735 else if (anArgIter + 1 < theNbArgs
13736 && anArg == "-axesconeradius")
13738 aViewCube->SetAxesConeRadius (Draw::Atof (theArgVec[++anArgIter]));
13740 else if (anArgIter + 1 < theNbArgs
13741 && anArg == "-axessphereradius")
13743 aViewCube->SetAxesSphereRadius (Draw::Atof (theArgVec[++anArgIter]));
13747 std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
13751 if (aViewCube.IsNull())
13753 std::cout << "Syntax error: wrong number of arguments\n";
13757 ViewerTest::Display (aName, aViewCube, false);
13761 //===============================================================================================
13762 //function : VColorConvert
13764 //===============================================================================================
13765 static int VColorConvert (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec)
13767 if (theNbArgs != 6)
13769 std::cerr << "Error: command syntax is incorrect, see help" << std::endl;
13773 Standard_Boolean convertFrom = (! strcasecmp (theArgVec[1], "from"));
13774 if (! convertFrom && strcasecmp (theArgVec[1], "to"))
13776 std::cerr << "Error: first argument must be either \"to\" or \"from\"" << std::endl;
13780 const char* aTypeStr = theArgVec[2];
13781 Quantity_TypeOfColor aType = Quantity_TOC_RGB;
13782 if (! strcasecmp (aTypeStr, "srgb"))
13784 aType = Quantity_TOC_sRGB;
13786 else if (! strcasecmp (aTypeStr, "hls"))
13788 aType = Quantity_TOC_HLS;
13790 else if (! strcasecmp (aTypeStr, "lab"))
13792 aType = Quantity_TOC_CIELab;
13794 else if (! strcasecmp (aTypeStr, "lch"))
13796 aType = Quantity_TOC_CIELch;
13800 std::cerr << "Error: unknown colorspace type: " << aTypeStr << std::endl;
13804 double aC1 = Draw::Atof (theArgVec[3]);
13805 double aC2 = Draw::Atof (theArgVec[4]);
13806 double aC3 = Draw::Atof (theArgVec[5]);
13808 Quantity_Color aColor (aC1, aC2, aC3, convertFrom ? aType : Quantity_TOC_RGB);
13809 aColor.Values (aC1, aC2, aC3, convertFrom ? Quantity_TOC_RGB : aType);
13811 // print values with 6 decimal digits
13813 Sprintf (buffer, "%.6f %.6f %.6f", aC1, aC2, aC3);
13819 //===============================================================================================
13820 //function : VColorDiff
13822 //===============================================================================================
13823 static int VColorDiff (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec)
13825 if (theNbArgs != 7)
13827 std::cerr << "Error: command syntax is incorrect, see help" << std::endl;
13831 double aR1 = Draw::Atof (theArgVec[1]);
13832 double aG1 = Draw::Atof (theArgVec[2]);
13833 double aB1 = Draw::Atof (theArgVec[3]);
13834 double aR2 = Draw::Atof (theArgVec[4]);
13835 double aG2 = Draw::Atof (theArgVec[5]);
13836 double aB2 = Draw::Atof (theArgVec[6]);
13838 Quantity_Color aColor1 (aR1, aG1, aB1, Quantity_TOC_RGB);
13839 Quantity_Color aColor2 (aR2, aG2, aB2, Quantity_TOC_RGB);
13841 theDI << aColor1.DeltaE2000 (aColor2);
13846 //=======================================================================
13847 //function : ViewerCommands
13849 //=======================================================================
13851 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
13854 const char *group = "ZeViewer";
13855 theCommands.Add("vinit",
13856 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
13857 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
13858 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13859 "\n\t\t: [-display displayName]"
13861 "\n\t\t: Creates new View window with specified name viewName."
13862 "\n\t\t: By default the new view is created in the viewer and in"
13863 "\n\t\t: graphic driver shared with active view."
13864 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
13865 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
13866 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
13867 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13868 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
13869 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
13871 "\n\t\t: -left, -top pixel position of left top corner of the window."
13872 "\n\t\t: -width, -height width and heigth of window respectively."
13873 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
13874 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
13875 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
13876 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
13877 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
13878 __FILE__,VInit,group);
13879 theCommands.Add("vclose" ,
13880 "[view_id [keep_context=0|1]]\n"
13881 "or vclose ALL - to remove all created views\n"
13882 " - removes view(viewer window) defined by its view_id.\n"
13883 " - keep_context: by default 0; if 1 and the last view is deleted"
13884 " the current context is not removed.",
13885 __FILE__,VClose,group);
13886 theCommands.Add("vactivate" ,
13887 "vactivate view_id [-noUpdate]"
13888 " - activates view(viewer window) defined by its view_id",
13889 __FILE__,VActivate,group);
13890 theCommands.Add("vviewlist",
13891 "vviewlist [format={tree, long}]"
13892 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
13893 " - format: format of result output, if tree the output is a tree view;"
13894 "otherwise it's a list of full view names. By default format = tree",
13895 __FILE__,VViewList,group);
13896 theCommands.Add("vhelp" ,
13897 "vhelp : display help on the viewer commands",
13898 __FILE__,VHelp,group);
13899 theCommands.Add("vviewproj",
13900 "vviewproj [top|bottom|left|right|front|back|axoLeft|axoRight]"
13901 "\n\t\t: [+-X+-Y+-Z] [-Zup|-Yup] [-frame +-X+-Y]"
13902 "\n\t\t: Setup view direction"
13903 "\n\t\t: -Yup use Y-up convention instead of Zup (which is default)."
13904 "\n\t\t: +-X+-Y+-Z define direction as combination of DX, DY and DZ;"
13905 "\n\t\t: for example '+Z' will show front of the model,"
13906 "\n\t\t: '-X-Y+Z' will define left axonometrical view."
13907 "\n\t\t: -frame define camera Up and Right directions (regardless Up convention);"
13908 "\n\t\t: for example '+X+Z' will show front of the model with Z-up."
13909 __FILE__,VViewProj,group);
13910 theCommands.Add("vtop" ,
13911 "vtop or <T> : Top view. Orientation +X+Y" ,
13912 __FILE__,VViewProj,group);
13913 theCommands.Add("vbottom" ,
13914 "vbottom : Bottom view. Orientation +X-Y" ,
13915 __FILE__,VViewProj,group);
13916 theCommands.Add("vleft" ,
13917 "vleft : Left view. Orientation -Y+Z" ,
13918 __FILE__,VViewProj,group);
13919 theCommands.Add("vright" ,
13920 "vright : Right view. Orientation +Y+Z" ,
13921 __FILE__,VViewProj,group);
13922 theCommands.Add("vaxo" ,
13923 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
13924 __FILE__,VViewProj,group);
13925 theCommands.Add("vfront" ,
13926 "vfront : Front view. Orientation +X+Z" ,
13927 __FILE__,VViewProj,group);
13928 theCommands.Add("vback" ,
13929 "vback : Back view. Orientation -X+Z" ,
13930 __FILE__,VViewProj,group);
13931 theCommands.Add("vpick" ,
13932 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
13934 theCommands.Add("vfit",
13935 "vfit or <F> [-selected] [-noupdate]"
13936 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
13937 __FILE__,VFit,group);
13938 theCommands.Add ("vfitarea",
13939 "vfitarea x1 y1 x2 y2"
13940 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
13941 "\n\t\t: Fit view to show area located between two points"
13942 "\n\t\t: given in world 2D or 3D corrdinates.",
13943 __FILE__, VFitArea, group);
13944 theCommands.Add ("vzfit", "vzfit [scale]\n"
13945 " Matches Z near, Z far view volume planes to the displayed objects.\n"
13946 " \"scale\" - specifies factor to scale computed z range.\n",
13947 __FILE__, VZFit, group);
13948 theCommands.Add("vrepaint",
13949 "vrepaint [-immediate] [-continuous FPS]"
13950 "\n\t\t: force redraw of active View"
13951 "\n\t\t: -immediate flag performs redraw of immediate layers only;"
13952 "\n\t\t: -continuous activates/deactivates continuous redraw of active View,"
13953 "\n\t\t: 0 means no continuous rendering,"
13954 "\n\t\t: -1 means non-stop redraws,"
13955 "\n\t\t: >0 specifies target framerate,",
13956 __FILE__,VRepaint,group);
13957 theCommands.Add("vclear",
13959 "\n\t\t: remove all the object from the viewer",
13960 __FILE__,VClear,group);
13963 "Changes background or some background settings.\n"
13966 " vbackground -imageFile ImageFile [-imageMode FillType]\n"
13967 " vbackground -imageMode FillType\n"
13968 " vbackground -gradient Color1 Color2 [-gradientMode FillMethod]\n"
13969 " vbackground -gradientMode FillMethod\n"
13970 " vbackground -cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]\n"
13971 " vbackground -color Color\n"
13972 " vbackground -default -gradient Color1 Color2 [-gradientMode FillType]\n"
13973 " vbackground -default -color Color\n"
13974 " vbackground -help\n"
13977 " -imageFile (-imgFile, -image, -img): sets filename of image used as background\n"
13978 " -imageMode (-imgMode, -imageMd, -imgMd): sets image fill type\n"
13979 " -gradient (-grad, -gr): sets background gradient starting and ending colors\n"
13980 " -gradientMode (-gradMode, -gradMd, -grMode, -grMd): sets gradient fill method\n"
13981 " -cubemap (-cmap, -cm): sets environmet cubemap as background\n"
13982 " -invertedz (-invz, -iz): sets inversion of Z axis for background cubemap rendering\n"
13983 " -order (-o): defines order of tiles in one image cubemap\n"
13984 " (has no effect in case of multi image cubemaps)\n"
13985 " -color (-col): sets background color\n"
13986 " -default (-def): sets background default gradient or color\n"
13987 " -help (-h): outputs short help message\n"
13990 " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n"
13991 " or reals within the range [0.0, 1.0]\n"
13992 " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n"
13993 " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n"
13994 " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, "
13996 " FillType: one of CENTERED, TILED, STRETCH, NONE\n"
13997 " ImageFile: a name of the file with the image used as a background\n"
13998 " CubemapFilei: a name of the file with one image packed cubemap or names of separate files with every cubemap side\n"
13999 " TileIndexi: a cubemap side index in range [0, 5] for i tile of one image packed cubemap\n",
14003 theCommands.Add ("vsetbg",
14004 "Loads image as background."
14005 "\n\t\t: vsetbg ImageFile [FillType]"
14006 "\n\t\t: vsetbg -imageFile ImageFile [-imageMode FillType]"
14007 "\n\t\t: Alias for 'vbackground -imageFile ImageFile [-imageMode FillType]'.",
14011 theCommands.Add ("vsetbgmode",
14012 "Changes background image fill type."
14013 "\n\t\t: vsetbgmode [-imageMode] FillType"
14014 "\n\t\t: Alias for 'vbackground -imageMode FillType'.",
14018 theCommands.Add ("vsetgradientbg",
14019 "Mounts gradient background."
14020 "\n\t\t: vsetgradientbg Color1 Color2 [FillMethod]"
14021 "\n\t\t: vsetgradientbg -gradient Color1 Color2 [-gradientMode FillMethod]"
14022 "\n\t\t: Alias for 'vbackground -gradient Color1 Color2 -gradientMode FillMethod'.",
14026 theCommands.Add ("vsetgrbgmode",
14027 "Changes gradient background fill method."
14028 "\n\t\t: vsetgrbgmode [-gradientMode] FillMethod"
14029 "\n\t\t: Alias for 'vbackground -gradientMode FillMethod'.",
14033 theCommands.Add ("vsetcolorbg",
14034 "Sets background color."
14035 "\n\t\t: vsetcolorbg [-color] Color."
14036 "\n\t\t: Alias for 'vbackground -color Color'.",
14040 theCommands.Add ("vsetdefaultbg",
14041 "Sets default viewer background fill color (flat/gradient)."
14042 "\n\t\t: vsetdefaultbg Color1 Color2 [FillMethod]"
14043 "\n\t\t: vsetdefaultbg -gradient Color1 Color2 [-gradientMode FillMethod]"
14044 "\n\t\t: Alias for 'vbackground -default -gradient Color1 Color2 [-gradientMode FillMethod]'."
14045 "\n\t\t: vsetdefaultbg [-color] Color"
14046 "\n\t\t: Alias for 'vbackground -default -color Color'.",
14050 theCommands.Add("vscale",
14051 "vscale : vscale X Y Z",
14052 __FILE__,VScale,group);
14053 theCommands.Add("vzbufftrihedron",
14054 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
14055 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
14056 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
14057 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
14058 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
14059 "\n\t\t: Displays a trihedron",
14060 __FILE__,VZBuffTrihedron,group);
14061 theCommands.Add("vrotate",
14062 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
14063 "\n : Option -mouseStart starts rotation according to the mouse position"
14064 "\n : Option -mouseMove continues rotation with angle computed"
14065 "\n : from last and new mouse position."
14066 "\n : vrotate AX AY AZ [X Y Z]",
14067 __FILE__,VRotate,group);
14068 theCommands.Add("vzoom",
14069 "vzoom : vzoom coef",
14070 __FILE__,VZoom,group);
14071 theCommands.Add("vpan",
14072 "vpan : vpan dx dy",
14073 __FILE__,VPan,group);
14074 theCommands.Add("vcolorscale",
14075 "vcolorscale name [-noupdate|-update] [-demo]"
14076 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
14077 "\n\t\t: [-font HeightFont=20]"
14078 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
14079 "\n\t\t: [-smoothTransition {on|off}=off]"
14080 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
14081 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
14082 "\n\t\t: [-textpos {left|right|center|none}=right]"
14083 "\n\t\t: [-labelAtBorder {on|off}=on]"
14084 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
14085 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
14086 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
14087 "\n\t\t: [-xy Left=0 Bottom=0]"
14088 "\n\t\t: [-uniform lightness hue_from hue_to]"
14089 "\n\t\t: -demo - displays a color scale with demonstratio values"
14090 "\n\t\t: -colors - set colors for all intervals"
14091 "\n\t\t: -color - set color for specific interval"
14092 "\n\t\t: -uniform - generate colors with the same lightness"
14093 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
14094 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
14095 "\n\t\t: at border means the value inbetween neighbor intervals,"
14096 "\n\t\t: at center means the center value within current interval"
14097 "\n\t\t: -labels - set labels for all intervals"
14098 "\n\t\t: -freeLabels - same as -labels but does not require"
14099 "\n\t\t: matching the number of intervals"
14100 "\n\t\t: -label - set label for specific interval"
14101 "\n\t\t: -title - set title"
14102 "\n\t\t: -reversed - setup smooth color transition between intervals"
14103 "\n\t\t: -smoothTransition - swap colorscale direction"
14104 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values",
14105 __FILE__, VColorScale, group);
14106 theCommands.Add("vgraduatedtrihedron",
14107 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
14108 "\t[-namefont Name] [-valuesfont Name]\n"
14109 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
14110 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
14111 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
14112 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
14113 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
14114 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
14115 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
14116 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
14117 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
14118 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
14119 " - Displays or erases graduated trihedron"
14120 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
14121 " - namefont - font of axes names. Default: Arial\n"
14122 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
14123 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
14124 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
14125 " - valuesfont - font of axes values. Default: Arial\n"
14126 " - xcolor, ycolor, zcolor - color of axis and values\n"
14127 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
14128 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
14129 __FILE__,VGraduatedTrihedron,group);
14130 theCommands.Add("vtile" ,
14131 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
14132 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
14133 "\n\t\t: -totalSize the size of virtual bigger viewport"
14134 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
14135 "\n\t\t: -lowerLeft tile offset as lower left corner"
14136 "\n\t\t: -upperLeft tile offset as upper left corner",
14137 __FILE__, VTile, group);
14138 theCommands.Add("vzlayer",
14139 "vzlayer [layerId]"
14140 "\n\t\t: [-add|-delete|-get|-settings] [-insertBefore AnotherLayer] [-insertAfter AnotherLayer]"
14141 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
14142 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
14143 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv|rayTracing}]"
14144 "\n\t\t: ZLayer list management:"
14145 "\n\t\t: -add add new z layer to viewer and print its id"
14146 "\n\t\t: -insertBefore add new z layer and insert it before existing one"
14147 "\n\t\t: -insertAfter add new z layer and insert it after existing one"
14148 "\n\t\t: -delete delete z layer"
14149 "\n\t\t: -get print sequence of z layers"
14150 "\n\t\t: -settings print status of z layer settings"
14151 "\n\t\t: -disable disables given setting"
14152 "\n\t\t: -enable enables given setting",
14153 __FILE__,VZLayer,group);
14154 theCommands.Add("vlayerline",
14155 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
14156 __FILE__,VLayerLine,group);
14157 theCommands.Add("vgrid",
14158 "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]"
14159 "\n\t\t: [-step X Y] [-size DX DY]"
14160 "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]",
14161 __FILE__, VGrid, group);
14162 theCommands.Add ("vpriviledgedplane",
14163 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
14164 "\n\t\t: Ox, Oy, Oz - plane origin"
14165 "\n\t\t: Nx, Ny, Nz - plane normal direction"
14166 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
14167 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
14168 __FILE__, VPriviledgedPlane, group);
14169 theCommands.Add ("vconvert",
14170 "vconvert v [Mode={window|view}]"
14171 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
14172 "\n\t\t: vconvert x y z [Mode={window|grid}]"
14173 "\n\t\t: window - convert to window coordinates, pixels"
14174 "\n\t\t: view - convert to view projection plane"
14175 "\n\t\t: grid - convert to model coordinates, given on grid"
14176 "\n\t\t: ray - convert projection ray to model coordiantes"
14177 "\n\t\t: - vconvert v window : convert view to window;"
14178 "\n\t\t: - vconvert v view : convert window to view;"
14179 "\n\t\t: - vconvert x y window : convert view to window;"
14180 "\n\t\t: - vconvert x y view : convert window to view;"
14181 "\n\t\t: - vconvert x y : convert window to model;"
14182 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
14183 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
14184 "\n\t\t: - vconvert x y z window : convert model to window;"
14185 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
14186 "\n\t\t: Converts the given coordinates to window/view/model space.",
14187 __FILE__, VConvert, group);
14188 theCommands.Add ("vfps",
14189 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
14190 __FILE__, VFps, group);
14191 theCommands.Add ("vgldebug",
14192 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
14193 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
14194 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
14195 "\n\t\t: Debug context can be requested only on Windows"
14196 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
14197 "\n\t\t: -sync - request synchronized debug GL context"
14198 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
14199 "\n\t\t: which are suppressed by default,"
14200 "\n\t\t: -glslCode - log GLSL program source code,"
14201 "\n\t\t: which are suppressed by default,"
14202 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
14203 "\n\t\t: which are suppressed by default",
14204 __FILE__, VGlDebug, group);
14205 theCommands.Add ("vvbo",
14206 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
14207 __FILE__, VVbo, group);
14208 theCommands.Add ("vstereo",
14209 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
14210 "\n\t\t: [-anaglyph Filter]"
14211 "\n\t\t: Control stereo output mode. Available modes for -mode:"
14212 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
14213 "\n\t\t: requires driver support."
14214 "\n\t\t: Should be called BEFORE vinit!"
14215 "\n\t\t: anaglyph - Anaglyph glasses"
14216 "\n\t\t: rowInterlaced - row-interlaced display"
14217 "\n\t\t: columnInterlaced - column-interlaced display"
14218 "\n\t\t: chessBoard - chess-board output"
14219 "\n\t\t: sideBySide - horizontal pair"
14220 "\n\t\t: overUnder - vertical pair"
14221 "\n\t\t: Available Anaglyph filters for -anaglyph:"
14222 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
14223 "\n\t\t: greenMagentaSimple",
14224 __FILE__, VStereo, group);
14225 theCommands.Add ("vcaps",
14226 "vcaps [-sRGB {0|1}] [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
14227 "\n\t\t: [-compatibleProfile {0|1}]"
14228 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
14229 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
14230 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
14231 "\n\t\t: [-noExtensions {0|1}] [-maxVersion Major Minor]"
14232 "\n\t\t: Modify particular graphic driver options:"
14233 "\n\t\t: sRGB - enable/disable sRGB rendering"
14234 "\n\t\t: FFP - use fixed-function pipeline instead of"
14235 "\n\t\t: built-in GLSL programs"
14236 "\n\t\t: (requires compatible profile)"
14237 "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs"
14238 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
14239 "\n\t\t: arrays to GPU memory)"
14240 "\n\t\t: sprite - use textured sprites instead of bitmaps"
14241 "\n\t\t: vsync - switch VSync on or off"
14242 "\n\t\t: winBuffer - allow using window buffer for rendering"
14243 "\n\t\t: Context creation options:"
14244 "\n\t\t: softMode - software OpenGL implementation"
14245 "\n\t\t: compatibleProfile - backward-compatible profile"
14246 "\n\t\t: quadbuffer - QuadBuffer"
14247 "\n\t\t: noExtensions - disallow usage of extensions"
14248 "\n\t\t: maxVersion - force upper OpenGL version to be used"
14249 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
14250 "\n\t\t: rendering paths producing the same visual result when"
14251 "\n\t\t: possible."
14252 "\n\t\t: Command is intended for testing old hardware compatibility.",
14253 __FILE__, VCaps, group);
14254 theCommands.Add ("vmemgpu",
14255 "vmemgpu [f]: print system-dependent GPU memory information if available;"
14256 " with f option returns free memory in bytes",
14257 __FILE__, VMemGpu, group);
14258 theCommands.Add ("vreadpixel",
14259 "vreadpixel xPixel yPixel [{rgb|rgba|sRGB|sRGBa|depth|hls|rgbf|rgbaf}=rgba] [-name|-hex]"
14260 " : Read pixel value for active view",
14261 __FILE__, VReadPixel, group);
14262 theCommands.Add("diffimage",
14263 "diffimage imageFile1 imageFile2 [diffImageFile]"
14264 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
14265 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
14266 "\n\t\t: Compare two images by content and generate difference image."
14267 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
14268 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
14269 __FILE__, VDiffImage, group);
14270 theCommands.Add ("vselect",
14271 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
14272 "- emulates different types of selection:\n"
14273 "- 1) single click selection\n"
14274 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
14275 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
14276 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
14277 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
14278 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
14279 " (partial inclusion - overlap - is not allowed by default)\n"
14280 "- 5) any of these selections with shift button pressed",
14281 __FILE__, VSelect, group);
14282 theCommands.Add ("vmoveto",
14283 "vmoveto [x y] [-reset]"
14284 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
14285 "\n\t\t: -reset resets current highlighting",
14286 __FILE__, VMoveTo, group);
14287 theCommands.Add ("vviewparams",
14288 "vviewparams [-args] [-scale [s]]"
14289 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
14290 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
14291 "\n\t\t: Manage current view parameters or prints all"
14292 "\n\t\t: current values when called without argument."
14293 "\n\t\t: -scale [s] prints or sets viewport relative scale"
14294 "\n\t\t: -eye [x y z] prints or sets eye location"
14295 "\n\t\t: -at [x y z] prints or sets center of look"
14296 "\n\t\t: -up [x y z] prints or sets direction of up vector"
14297 "\n\t\t: -proj [x y z] prints or sets direction of look"
14298 "\n\t\t: -center x y sets location of center of the screen in pixels"
14299 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
14300 "\n\t\t: or changes the size of its maximum dimension"
14301 "\n\t\t: -args prints vviewparams arguments for restoring current view",
14302 __FILE__, VViewParams, group);
14304 theCommands.Add("v2dmode",
14305 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
14306 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
14307 "\n\t\t: mode - switches On/Off rotation mode"
14308 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
14309 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
14310 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
14311 "\n\t\t: View camera position might be changed only by commands.",
14312 __FILE__, V2DMode, group);
14314 theCommands.Add("vanimation", "Alias for vanim",
14315 __FILE__, VAnimation, group);
14317 theCommands.Add("vanim",
14318 "List existing animations:"
14320 "\n\t\t: Animation playback:"
14321 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
14322 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
14323 "\n\t\t: -speed playback speed (1.0 is normal speed)"
14324 "\n\t\t: -freeLook skip camera animations"
14325 "\n\t\t: -lockLoop disable any interactions"
14327 "\n\t\t: Animation definition:"
14328 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
14329 "\n\t\t: [start TimeSec] [duration TimeSec]"
14331 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
14332 "\n\t\t: specifies nested animations."
14333 "\n\t\t: There is no syntax to explicitly add new animation,"
14334 "\n\t\t: and all non-existing animations within the name will be"
14335 "\n\t\t: implicitly created on first use (including parents)."
14337 "\n\t\t: Each animation might define the SINGLE action (see below),"
14338 "\n\t\t: like camera transition, object transformation or custom callback."
14339 "\n\t\t: Child animations can be used for defining concurrent actions."
14341 "\n\t\t: Camera animation:"
14342 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
14343 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
14344 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
14345 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
14346 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
14347 "\n\t\t: -atX camera Center positions pair"
14348 "\n\t\t: -upX camera Up directions pair"
14349 "\n\t\t: -scaleX camera Scale factors pair"
14350 "\n\t\t: Object animation:"
14351 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
14352 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
14353 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
14354 "\n\t\t: -locX object Location points pair (translation)"
14355 "\n\t\t: -rotX object Orientations pair (quaternions)"
14356 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
14357 "\n\t\t: Custom callback:"
14358 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
14359 "\n\t\t: %Pts overall animation presentation timestamp"
14360 "\n\t\t: %LocalPts local animation timestamp"
14361 "\n\t\t: %Normalized local animation normalized value in range 0..1"
14363 "\n\t\t: Video recording:"
14364 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
14365 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
14366 "\n\t\t: [-crf Value] [-preset Preset]"
14367 "\n\t\t: -fps video framerate"
14368 "\n\t\t: -format file format, container (matroska, etc.)"
14369 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
14370 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
14371 "\n\t\t: -crf constant rate factor (specific to codec)"
14372 "\n\t\t: -preset codec parameters preset (specific to codec)"
14373 __FILE__, VAnimation, group);
14375 theCommands.Add("vchangeselected",
14376 "vchangeselected shape"
14377 "- adds to shape to selection or remove one from it",
14378 __FILE__, VChangeSelected, group);
14379 theCommands.Add ("vnbselected",
14381 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
14382 theCommands.Add ("vcamera",
14383 "vcamera [PrsName] [-ortho] [-projtype]"
14385 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
14386 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
14387 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
14388 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
14389 "\n\t\t: Manages camera parameters."
14390 "\n\t\t: Displays frustum when presntation name PrsName is specified."
14391 "\n\t\t: Prints current value when option called without argument."
14392 "\n\t\t: Orthographic camera:"
14393 "\n\t\t: -ortho activate orthographic projection"
14394 "\n\t\t: Perspective camera:"
14395 "\n\t\t: -persp activate perspective projection (mono)"
14396 "\n\t\t: -fovy field of view in y axis, in degrees"
14397 "\n\t\t: -distance distance of eye from camera center"
14398 "\n\t\t: Stereoscopic camera:"
14399 "\n\t\t: -stereo perspective projection (stereo)"
14400 "\n\t\t: -leftEye perspective projection (left eye)"
14401 "\n\t\t: -rightEye perspective projection (right eye)"
14402 "\n\t\t: -iod intraocular distance value"
14403 "\n\t\t: -iodType distance type, absolute or relative"
14404 "\n\t\t: -zfocus stereographic focus value"
14405 "\n\t\t: -zfocusType focus type, absolute or relative",
14406 __FILE__, VCamera, group);
14407 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
14408 "- vautozfit [on={1|0}] [scale]\n"
14409 " Prints or changes parameters of automatic z-fit mode:\n"
14410 " \"on\" - turns automatic z-fit on or off\n"
14411 " \"scale\" - specifies factor to scale computed z range.\n",
14412 __FILE__, VAutoZFit, group);
14413 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
14414 " vzrange - without parameters shows current values\n"
14415 " vzrange [znear] [zfar] - applies provided values to view",
14416 __FILE__,VZRange, group);
14417 theCommands.Add ("vpurgedisplay",
14419 "- removes structures which don't belong to objects displayed in neutral point",
14420 __FILE__, VPurgeDisplay, group);
14421 theCommands.Add("vsetviewsize",
14422 "vsetviewsize size",
14423 __FILE__,VSetViewSize,group);
14424 theCommands.Add("vmoveview",
14425 "vmoveview Dx Dy Dz [Start = 1|0]",
14426 __FILE__,VMoveView,group);
14427 theCommands.Add("vtranslateview",
14428 "vtranslateview Dx Dy Dz [Start = 1|0)]",
14429 __FILE__,VTranslateView,group);
14430 theCommands.Add("vturnview",
14431 "vturnview Ax Ay Az [Start = 1|0]",
14432 __FILE__,VTurnView,group);
14433 theCommands.Add("vtextureenv",
14434 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
14435 "or user-defined file and optionally applying texture mapping parameters\n"
14437 " vtextureenv off - disables environment mapping\n"
14438 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
14439 " std_texture = (0..7)\n"
14440 " rep = {clamp|repeat}\n"
14441 " mod = {decal|modulate}\n"
14442 " flt = {nearest|bilinear|trilinear}\n"
14443 " ss, st - scale factors for s and t texture coordinates\n"
14444 " ts, tt - translation for s and t texture coordinates\n"
14445 " rot - texture rotation angle in degrees",
14446 __FILE__, VTextureEnv, group);
14447 theCommands.Add("vhlr",
14448 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
14449 "\n\t\t: Hidden Line Removal algorithm."
14450 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
14451 "\n\t\t: -algoType type of HLR algorithm.\n",
14452 __FILE__,VHLR,group);
14453 theCommands.Add("vhlrtype",
14454 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
14455 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
14456 "\n\t\t: 'algo' - exact HLR algorithm is applied"
14457 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
14458 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
14459 __FILE__,VHLRType,group);
14460 theCommands.Add("vclipplane",
14461 "vclipplane planeName [{0|1}]"
14462 "\n\t\t: [-equation1 A B C D]"
14463 "\n\t\t: [-equation2 A B C D]"
14464 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
14465 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
14466 "\n\t\t: [-maxPlanes]"
14467 "\n\t\t: [-capping {0|1}]"
14468 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
14469 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
14470 "\n\t\t: [-texRotate Angle]"
14471 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
14472 "\n\t\t: [-useObjShader {0|1}]"
14473 "\n\t\t: Clipping planes management:"
14474 "\n\t\t: -maxPlanes print plane limit for view"
14475 "\n\t\t: -delete delete plane with given name"
14476 "\n\t\t: {off|on|0|1} turn clipping on/off"
14477 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
14478 "\n\t\t: applied to active View when list is omitted"
14479 "\n\t\t: -equation A B C D change plane equation"
14480 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
14481 "\n\t\t: Capping options:"
14482 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
14483 "\n\t\t: -color R G B set capping color"
14484 "\n\t\t: -transparency Value set capping transparency 0..1"
14485 "\n\t\t: -texName Texture set capping texture"
14486 "\n\t\t: -texScale SX SY set capping tex scale"
14487 "\n\t\t: -texOrigin TX TY set capping tex origin"
14488 "\n\t\t: -texRotate Angle set capping tex rotation"
14489 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
14490 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
14491 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
14492 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
14493 __FILE__, VClipPlane, group);
14494 theCommands.Add("vdefaults",
14495 "vdefaults [-absDefl value]"
14496 "\n\t\t: [-devCoeff value]"
14497 "\n\t\t: [-angDefl value]"
14498 "\n\t\t: [-autoTriang {off/on | 0/1}]"
14499 , __FILE__, VDefaults, group);
14500 theCommands.Add("vlight",
14501 "tool to manage light sources, without arguments shows list of lights."
14502 "\n Main commands: "
14503 "\n '-clear' to clear lights"
14504 "\n '-{def}aults' to load deafault lights"
14505 "\n '-add' <type> to add any light source"
14506 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
14507 "\n 'change' <lightId> to edit light source with specified lightId"
14508 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
14510 "\n -{pos}ition X Y Z"
14511 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
14512 "\n -color colorName"
14513 "\n -{head}light 0|1"
14514 "\n -{sm}oothness value"
14515 "\n -{int}ensity value"
14516 "\n -{constAtten}uation value"
14517 "\n -{linearAtten}uation value"
14518 "\n -angle angleDeg"
14519 "\n -{spotexp}onent value"
14521 "\n -local|-global"
14522 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
14523 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
14524 __FILE__, VLight, group);
14525 theCommands.Add("vpbrenv",
14526 "vpbrenv -clear|-generate"
14527 "\n\t\t: Clears or generates PBR environment map of active view."
14528 "\n\t\t: -clear clears PBR environment (fills by white color)"
14529 "\n\t\t: -generate generates PBR environment from current background cubemap",
14530 __FILE__, VPBREnvironment, group);
14531 theCommands.Add("vraytrace",
14533 "\n\t\t: Turns on/off ray-tracing renderer."
14534 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
14535 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
14536 __FILE__, VRenderParams, group);
14537 theCommands.Add("vrenderparams",
14538 "\n Manages rendering parameters: "
14539 "\n '-raster' Disables GPU ray-tracing"
14540 "\n '-msaa 0..4' Specifies number of samples for MSAA"
14541 "\n '-lineFeather > 0' Sets line feather factor"
14542 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
14543 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
14544 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
14545 "\n '-rendScale value Rendering resolution scale factor"
14546 "\n '-rayTrace' Enables GPU ray-tracing"
14547 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
14548 "\n '-shadows on|off' Enables/disables shadows rendering"
14549 "\n '-reflections on|off' Enables/disables specular reflections"
14550 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
14551 "\n '-gleam on|off' Enables/disables transparency shadow effects"
14552 "\n '-gi on|off' Enables/disables global illumination effects"
14553 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
14554 "\n '-env on|off' Enables/disables environment map background"
14555 "\n '-ignoreNormalMap on|off' Enables/disables normal map ignoring during path tracing"
14556 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
14557 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
14558 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
14559 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
14560 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
14561 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
14562 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
14563 "\n '-shadingModel model' Controls shading model from enumeration"
14564 "\n unlit, flat, gouraud, phong"
14565 "\n '-pbrEnvPow2size > 0' Controls size of IBL maps (real size can be calculates as 2^pbrenvpow2size)"
14566 "\n '-pbrEnvSMLN > 1' Controls number of mipmap levels used in specular IBL map"
14567 "\n '-pbrEnvBDSN > 0' Controls number of samples in Monte-Carlo integration during diffuse IBL map's sherical harmonics calculation"
14568 "\n '-pbrEnvBSSN > 0' Controls maximum number of samples per mipmap level in Monte-Carlo integration during specular IBL maps generation"
14569 "\n '-pbrEnvBP [0, 1]' Controls strength of samples number reducing during specular IBL maps generation (1 disables reducing)"
14570 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
14571 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
14572 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
14573 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
14574 "\n '-whitepoint value' White point value for filmic tone mapping"
14575 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
14576 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triangles|points"
14577 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
14578 "\n Show/hide performance counters (flags can be combined)"
14579 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
14580 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
14581 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
14582 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
14583 "\n set state to check structures culled previously."
14584 "\n Unlike vcaps, these parameters dramatically change visual properties."
14585 "\n Command is intended to control presentation quality depending on"
14586 "\n hardware capabilities and performance.",
14587 __FILE__, VRenderParams, group);
14588 theCommands.Add("vstatprofiler",
14589 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
14590 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
14591 "\n |triangles|points|geomMem|textureMem|frameMem"
14592 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
14593 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
14595 "\n\t\t: Prints rendering statistics."
14596 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
14597 "\n\t\t: else - print all performance counters set previously."
14598 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
14599 __FILE__, VStatProfiler, group);
14600 theCommands.Add ("vplace",
14602 "\n\t\t: Places the point (in pixels) at the center of the window",
14603 __FILE__, VPlace, group);
14604 theCommands.Add("vxrotate",
14606 __FILE__,VXRotate,group);
14608 theCommands.Add("vmanipulator",
14609 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
14610 "\n tool to create and manage AIS manipulators."
14612 "\n '-attach AISObject' attach manipulator to AISObject"
14613 "\n '-adjustPosition {0|1}' adjust position when attaching"
14614 "\n '-adjustSize {0|1}' adjust size when attaching"
14615 "\n '-enableModes {0|1}' enable modes when attaching"
14616 "\n '-view {active | [name of view]}' display manipulator only in defined view,"
14617 "\n by default it is displayed in all views of the current viewer"
14618 "\n '-detach' detach manipulator"
14619 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
14620 "\n '-transform mouse_x mouse_y' - invoke transformation"
14621 "\n '-stopTransform [abort]' - invoke stop of transformation"
14622 "\n '-move x y z' - move attached object"
14623 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
14624 "\n '-scale factor' - scale attached object"
14625 "\n '-autoActivate {0|1}' - set activation on detection"
14626 "\n '-followTranslation {0|1}' - set following translation transform"
14627 "\n '-followRotation {0|1}' - set following rotation transform"
14628 "\n '-followDragging {0|1}' - set following dragging transform"
14629 "\n '-gap value' - set gap between sub-parts"
14630 "\n '-part axis mode {0|1}' - set visual part"
14631 "\n '-parts axis mode {0|1}' - set visual part"
14632 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
14633 "\n '-size value' - set size of manipulator"
14634 "\n '-zoomable {0|1}' - set zoom persistence",
14635 __FILE__, VManipulator, group);
14637 theCommands.Add("vselprops",
14638 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
14639 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
14640 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
14641 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
14642 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
14643 "\n -pickStrategy {first|topmost} : defines picking strategy"
14644 "\n 'first' to pick first acceptable (default)"
14645 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
14646 "\n -pixTol value : sets up pixel tolerance"
14647 "\n -dispMode dispMode : sets display mode for highlighting"
14648 "\n -layer ZLayer : sets ZLayer for highlighting"
14649 "\n -color {name|r g b} : sets highlight color"
14650 "\n -transp value : sets transparency coefficient for highlight"
14651 "\n -material material : sets highlight material"
14652 "\n -print : prints current state of all mentioned parameters",
14653 __FILE__, VSelectionProperties, group);
14654 theCommands.Add ("vhighlightselected",
14655 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
14656 __FILE__, VSelectionProperties, group);
14658 theCommands.Add ("vseldump",
14659 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
14660 "\n\t\t: Generate an image based on detection results:"
14661 "\n\t\t: depth normalized depth values"
14662 "\n\t\t: unnormDepth unnormalized depth values"
14663 "\n\t\t: object color of detected object"
14664 "\n\t\t: owner color of detected owner"
14665 "\n\t\t: selMode color of selection mode"
14666 "\n\t\t: entity color of etected entity",
14667 __FILE__, VDumpSelectionImage, group);
14669 theCommands.Add ("vviewcube",
14671 "\n\t\t: Displays interactive view manipualtion object."
14672 "\n\t\t: Options: "
14673 "\n\t\t: -reset reset geomertical and visual attributes'"
14674 "\n\t\t: -size Size adapted size of View Cube"
14675 "\n\t\t: -boxSize Size box size"
14676 "\n\t\t: -axes {0|1 } show/hide axes (trihedron)"
14677 "\n\t\t: -edges {0|1} show/hide edges of View Cube"
14678 "\n\t\t: -vertices {0|1} show/hide vertices of View Cube"
14679 "\n\t\t: -Yup {0|1} -Zup {0|1} set Y-up or Z-up view orientation"
14680 "\n\t\t: -color Color color of View Cube"
14681 "\n\t\t: -boxColor Color box color"
14682 "\n\t\t: -boxSideColor Color box sides color"
14683 "\n\t\t: -boxEdgeColor Color box edges color"
14684 "\n\t\t: -boxCornerColor Color box corner color"
14685 "\n\t\t: -textColor Color color of side text of view cube"
14686 "\n\t\t: -innerColor Color inner box color"
14687 "\n\t\t: -transparency Value transparency of object within [0, 1] range"
14688 "\n\t\t: -boxTransparency Value transparency of box within [0, 1] range"
14689 "\n\t\t: -font Name font name"
14690 "\n\t\t: -fontHeight Value font height"
14691 "\n\t\t: -boxFacetExtension Value box facet extension"
14692 "\n\t\t: -boxEdgeGap Value gap between box edges and box sides"
14693 "\n\t\t: -boxEdgeMinSize Value minimal box edge size"
14694 "\n\t\t: -boxCornerMinSize Value minimal box corner size"
14695 "\n\t\t: -axesPadding Value padding between box and arrows"
14696 "\n\t\t: -roundRadius Value relative radius of corners of sides within [0.0, 0.5] range"
14697 "\n\t\t: -axesRadius Value radius of axes of the trihedron"
14698 "\n\t\t: -axesConeRadius Value radius of the cone (arrow) of the trihedron"
14699 "\n\t\t: -axesSphereRadius Value radius of the sphere (central point) of trihedron"
14700 "\n\t\t: -fixedanimation {0|1} uninterruptible animation loop"
14701 "\n\t\t: -duration Seconds animation duration in seconds",
14702 __FILE__, VViewCube, group);
14704 theCommands.Add("vcolorconvert" ,
14705 "vcolorconvert {from|to} type C1 C2 C2"
14706 "\n\t\t: vcolorconvert from type C1 C2 C2: Converts color from specified color space to linear RGB"
14707 "\n\t\t: vcolorconvert to type R G B: Converts linear RGB color to specified color space"
14708 "\n\t\t: type can be sRGB, HLS, Lab, or Lch",
14709 __FILE__,VColorConvert,group);
14710 theCommands.Add("vcolordiff" ,
14711 "vcolordiff R1 G1 B1 R2 G2 B2: returns CIEDE2000 color difference between two RGB colors",
14712 __FILE__,VColorDiff,group);