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 == "-labels"
4835 || aFlag == "-freelabels")
4837 if (anArgIter + 1 >= theArgNb)
4839 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4843 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4844 ? aColorScale->GetNumberOfIntervals() + 1
4845 : aColorScale->GetNumberOfIntervals();
4846 if (aFlag == "-freelabels")
4849 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4851 if (anArgIter + aNbLabels >= theArgNb)
4853 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
4857 TColStd_SequenceOfExtendedString aSeq;
4858 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
4860 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
4862 aColorScale->SetLabels (aSeq);
4863 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4865 else if (aFlag == "-title")
4867 if (anArgIter + 1 >= theArgNb)
4869 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4873 Standard_Boolean isTwoArgs = Standard_False;
4874 if (anArgIter + 2 < theArgNb)
4876 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4877 aSecondArg.LowerCase();
4878 Standard_DISABLE_DEPRECATION_WARNINGS
4879 if (aSecondArg == "none")
4881 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
4882 isTwoArgs = Standard_True;
4884 else if (aSecondArg == "left")
4886 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
4887 isTwoArgs = Standard_True;
4889 else if (aSecondArg == "right")
4891 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
4892 isTwoArgs = Standard_True;
4894 else if (aSecondArg == "center")
4896 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
4897 isTwoArgs = Standard_True;
4899 Standard_ENABLE_DEPRECATION_WARNINGS
4902 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
4909 else if (aFlag == "-demoversion"
4910 || aFlag == "-demo")
4912 aColorScale->SetPosition (0, 0);
4913 aColorScale->SetTextHeight (16);
4914 aColorScale->SetRange (0.0, 100.0);
4915 aColorScale->SetNumberOfIntervals (10);
4916 aColorScale->SetBreadth (0);
4917 aColorScale->SetHeight (0);
4918 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4919 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4920 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
4922 else if (aFlag == "-findcolor")
4924 if (anArgIter + 1 >= theArgNb)
4926 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4930 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4932 if (!anArg1.IsRealValue())
4934 std::cout << "Error: the value should be real!\n";
4938 Quantity_Color aColor;
4939 aColorScale->FindColor (anArg1.RealValue(), aColor);
4940 theDI << Quantity_Color::StringName (aColor.Name());
4945 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4950 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4951 aView->Window()->Size (aWinWidth, aWinHeight);
4952 if (aColorScale->GetBreadth() == 0)
4954 aColorScale->SetBreadth (aWinWidth);
4956 if (aColorScale->GetHeight() == 0)
4958 aColorScale->SetHeight (aWinHeight);
4960 aColorScale->SetToUpdate();
4961 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
4965 //==============================================================================
4966 //function : VGraduatedTrihedron
4967 //purpose : Displays or hides a graduated trihedron
4968 //==============================================================================
4969 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4970 Quantity_Color& theColor)
4972 Quantity_NameOfColor aColorName;
4973 TCollection_AsciiString aVal = theValue;
4975 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
4977 return Standard_False;
4979 theColor = Quantity_Color (aColorName);
4980 return Standard_True;
4983 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
4987 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4988 << theArgs[0] <<"' for more information.\n";
4989 return 1; //TCL_ERROR
4992 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4993 TCollection_AsciiString aParseKey;
4994 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4996 TCollection_AsciiString anArg (theArgs [anArgIt]);
4998 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5001 aParseKey.Remove (1);
5002 aParseKey.LowerCase();
5003 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5007 if (aParseKey.IsEmpty())
5012 aMapOfArgs(aParseKey)->Append (anArg);
5016 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
5017 aMapIt.More(); aMapIt.Next())
5019 const TCollection_AsciiString& aKey = aMapIt.Key();
5020 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
5022 // Bool key, without arguments
5023 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
5024 && anArgs->IsEmpty())
5030 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
5031 && anArgs->Length() == 1)
5037 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
5038 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
5039 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
5040 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
5041 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
5046 // One string argument
5047 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
5048 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
5049 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
5054 // One integer argument
5055 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
5056 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
5057 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
5058 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
5059 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
5064 // One real argument
5065 if ( aKey.IsEqual ("arrowlength")
5066 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
5071 // Two string arguments
5072 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
5073 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
5078 TCollection_AsciiString aLowerKey;
5081 aLowerKey.LowerCase();
5082 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
5083 std::cout << "Type help for more information.\n";
5087 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5088 if (anAISContext.IsNull())
5090 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
5094 Standard_Boolean toDisplay = Standard_True;
5095 Quantity_Color aColor;
5096 Graphic3d_GraduatedTrihedron aTrihedronData;
5097 // Process parameters
5098 Handle(TColStd_HSequenceOfAsciiString) aValues;
5099 if (aMapOfArgs.Find ("off", aValues))
5101 toDisplay = Standard_False;
5105 if (aMapOfArgs.Find ("xname", aValues))
5107 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
5109 if (aMapOfArgs.Find ("yname", aValues))
5111 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
5113 if (aMapOfArgs.Find ("zname", aValues))
5115 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
5117 if (aMapOfArgs.Find ("xdrawname", aValues))
5119 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5121 if (aMapOfArgs.Find ("ydrawname", aValues))
5123 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5125 if (aMapOfArgs.Find ("zdrawname", aValues))
5127 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5129 if (aMapOfArgs.Find ("xnameoffset", aValues))
5131 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5133 if (aMapOfArgs.Find ("ynameoffset", aValues))
5135 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5137 if (aMapOfArgs.Find ("znameoffset", aValues))
5139 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5143 if (aMapOfArgs.Find ("xnamecolor", aValues))
5145 if (!GetColor (aValues->Value(1), aColor))
5147 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
5150 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
5152 if (aMapOfArgs.Find ("ynamecolor", aValues))
5154 if (!GetColor (aValues->Value(1), aColor))
5156 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
5159 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
5161 if (aMapOfArgs.Find ("znamecolor", aValues))
5163 if (!GetColor (aValues->Value(1), aColor))
5165 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
5168 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
5170 if (aMapOfArgs.Find ("xcolor", aValues))
5172 if (!GetColor (aValues->Value(1), aColor))
5174 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
5177 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
5179 if (aMapOfArgs.Find ("ycolor", aValues))
5181 if (!GetColor (aValues->Value(1), aColor))
5183 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
5186 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
5188 if (aMapOfArgs.Find ("zcolor", aValues))
5190 if (!GetColor (aValues->Value(1), aColor))
5192 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
5195 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
5199 if (aMapOfArgs.Find ("xticks", aValues))
5201 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5203 if (aMapOfArgs.Find ("yticks", aValues))
5205 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5207 if (aMapOfArgs.Find ("zticks", aValues))
5209 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5211 if (aMapOfArgs.Find ("xticklength", aValues))
5213 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5215 if (aMapOfArgs.Find ("yticklength", aValues))
5217 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5219 if (aMapOfArgs.Find ("zticklength", aValues))
5221 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5223 if (aMapOfArgs.Find ("xdrawticks", aValues))
5225 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5227 if (aMapOfArgs.Find ("ydrawticks", aValues))
5229 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5231 if (aMapOfArgs.Find ("zdrawticks", aValues))
5233 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5237 if (aMapOfArgs.Find ("xdrawvalues", aValues))
5239 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5241 if (aMapOfArgs.Find ("ydrawvalues", aValues))
5243 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5245 if (aMapOfArgs.Find ("zdrawvalues", aValues))
5247 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5249 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
5251 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5253 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
5255 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5257 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
5259 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5263 if (aMapOfArgs.Find ("arrowlength", aValues))
5265 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
5269 if (aMapOfArgs.Find ("namefont", aValues))
5271 aTrihedronData.SetNamesFont (aValues->Value(1));
5273 if (aMapOfArgs.Find ("valuesfont", aValues))
5275 aTrihedronData.SetValuesFont (aValues->Value(1));
5278 if (aMapOfArgs.Find ("drawgrid", aValues))
5280 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
5282 if (aMapOfArgs.Find ("drawaxes", aValues))
5284 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
5287 // The final step: display of erase trihedron
5290 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
5294 ViewerTest::CurrentView()->GraduatedTrihedronErase();
5297 ViewerTest::GetAISContext()->UpdateCurrentViewer();
5298 ViewerTest::CurrentView()->Redraw();
5303 //==============================================================================
5306 //==============================================================================
5307 static int VTile (Draw_Interpretor& theDI,
5308 Standard_Integer theArgNb,
5309 const char** theArgVec)
5311 Handle(V3d_View) aView = ViewerTest::CurrentView();
5314 std::cerr << "Error: no active viewer.\n";
5318 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
5321 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
5322 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
5323 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
5327 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
5328 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5330 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5332 if (anArg == "-lowerleft"
5333 || anArg == "-upperleft")
5335 if (anArgIter + 3 < theArgNb)
5337 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5340 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
5341 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5342 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5344 else if (anArg == "-total"
5345 || anArg == "-totalsize"
5346 || anArg == "-viewsize")
5348 if (anArgIter + 3 < theArgNb)
5350 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5353 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5354 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5355 if (aTile.TotalSize.x() < 1
5356 || aTile.TotalSize.y() < 1)
5358 std::cerr << "Error: total size is incorrect.\n";
5362 else if (anArg == "-tilesize")
5364 if (anArgIter + 3 < theArgNb)
5366 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5370 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5371 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5372 if (aTile.TileSize.x() < 1
5373 || aTile.TileSize.y() < 1)
5375 std::cerr << "Error: tile size is incorrect.\n";
5379 else if (anArg == "-unset")
5381 aView->Camera()->SetTile (Graphic3d_CameraTile());
5387 if (aTile.TileSize.x() < 1
5388 || aTile.TileSize.y() < 1)
5390 std::cerr << "Error: tile size is undefined.\n";
5393 else if (aTile.TotalSize.x() < 1
5394 || aTile.TotalSize.y() < 1)
5396 std::cerr << "Error: total size is undefined.\n";
5400 aView->Camera()->SetTile (aTile);
5405 //! Format ZLayer ID.
5406 inline const char* formZLayerId (const Standard_Integer theLayerId)
5410 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
5411 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
5412 case Graphic3d_ZLayerId_Top: return "[TOP]";
5413 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
5414 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
5415 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
5420 //! Print the ZLayer information.
5421 inline void printZLayerInfo (Draw_Interpretor& theDI,
5422 const Graphic3d_ZLayerSettings& theLayer)
5424 if (!theLayer.Name().IsEmpty())
5426 theDI << " Name: " << theLayer.Name() << "\n";
5428 if (theLayer.IsImmediate())
5430 theDI << " Immediate: TRUE\n";
5432 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
5433 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
5434 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
5435 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
5436 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
5437 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
5438 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
5440 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
5444 //==============================================================================
5445 //function : VZLayer
5446 //purpose : Test z layer operations for v3d viewer
5447 //==============================================================================
5448 static int VZLayer (Draw_Interpretor& theDI,
5449 Standard_Integer theArgNb,
5450 const char** theArgVec)
5452 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5453 if (aContextAIS.IsNull())
5455 std::cout << "No active viewer!\n";
5459 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
5462 TColStd_SequenceOfInteger aLayers;
5463 aViewer->GetAllZLayers (aLayers);
5464 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5466 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
5467 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
5468 printZLayerInfo (theDI, aSettings);
5473 Standard_Integer anArgIter = 1;
5474 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5475 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
5476 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5482 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
5483 if (aFirstArg.IsIntegerValue())
5486 aLayerId = aFirstArg.IntegerValue();
5490 if (ViewerTest::ParseZLayerName (aFirstArg.ToCString(), aLayerId))
5497 Graphic3d_ZLayerId anOtherLayerId = Graphic3d_ZLayerId_UNKNOWN;
5498 for (; anArgIter < theArgNb; ++anArgIter)
5500 // perform operation
5501 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5503 if (anUpdateTool.parseRedrawMode (anArg))
5507 else if (anArg == "-add"
5510 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5511 if (!aViewer->AddZLayer (aLayerId))
5513 std::cout << "Error: can not add a new z layer!\n";
5519 else if (anArg == "-insertbefore"
5520 && anArgIter + 1 < theArgNb
5521 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
5524 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5525 if (!aViewer->InsertLayerBefore (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
5527 std::cout << "Error: can not add a new z layer!\n";
5533 else if (anArg == "-insertafter"
5534 && anArgIter + 1 < theArgNb
5535 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
5538 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5539 if (!aViewer->InsertLayerAfter (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
5541 std::cout << "Error: can not add a new z layer!\n";
5547 else if (anArg == "-del"
5548 || anArg == "-delete"
5551 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5553 if (++anArgIter >= theArgNb)
5555 std::cout << "Syntax error: id of z layer to remove is missing\n";
5559 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5562 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
5563 || aLayerId == Graphic3d_ZLayerId_Default
5564 || aLayerId == Graphic3d_ZLayerId_Top
5565 || aLayerId == Graphic3d_ZLayerId_Topmost
5566 || aLayerId == Graphic3d_ZLayerId_TopOSD
5567 || aLayerId == Graphic3d_ZLayerId_BotOSD)
5569 std::cout << "Syntax error: standard Z layer can not be removed\n";
5573 // move all object displayed in removing layer to default layer
5574 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5575 anObjIter.More(); anObjIter.Next())
5577 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
5579 || aPrs->ZLayer() != aLayerId)
5583 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
5586 if (!aViewer->RemoveZLayer (aLayerId))
5588 std::cout << "Z layer can not be removed!\n";
5592 theDI << aLayerId << " ";
5595 else if (anArg == "-get"
5598 TColStd_SequenceOfInteger aLayers;
5599 aViewer->GetAllZLayers (aLayers);
5600 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5602 theDI << aLayeriter.Value() << " ";
5607 else if (anArg == "-name")
5609 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5611 std::cout << "Syntax error: id of Z layer is missing\n";
5615 if (++anArgIter >= theArgNb)
5617 std::cout << "Syntax error: name is missing\n";
5621 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5622 aSettings.SetName (theArgVec[anArgIter]);
5623 aViewer->SetZLayerSettings (aLayerId, aSettings);
5625 else if (anArg == "-origin")
5627 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5629 std::cout << "Syntax error: id of Z layer is missing\n";
5633 if (anArgIter + 2 >= theArgNb)
5635 std::cout << "Syntax error: origin coordinates are missing\n";
5639 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5641 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
5642 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
5643 anOrigin.SetZ (0.0);
5644 if (anArgIter + 3 < theArgNb)
5646 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
5653 aSettings.SetOrigin (anOrigin);
5654 aViewer->SetZLayerSettings (aLayerId, aSettings);
5656 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5657 && anArgIter + 1 < theArgNb
5658 && (anArg == "-cullingdistance"
5659 || anArg == "-cullingdist"
5660 || anArg == "-culldistance"
5661 || anArg == "-culldist"
5662 || anArg == "-distcull"
5663 || anArg == "-distculling"
5664 || anArg == "-distanceculling"))
5666 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5667 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
5668 aSettings.SetCullingDistance (aDist);
5669 aViewer->SetZLayerSettings (aLayerId, aSettings);
5671 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5672 && anArgIter + 1 < theArgNb
5673 && (anArg == "-cullingsize"
5674 || anArg == "-cullsize"
5675 || anArg == "-sizecull"
5676 || anArg == "-sizeculling"))
5678 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5679 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
5680 aSettings.SetCullingSize (aSize);
5681 aViewer->SetZLayerSettings (aLayerId, aSettings);
5683 else if (anArg == "-settings"
5684 || anArg == "settings")
5686 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5688 if (++anArgIter >= theArgNb)
5690 std::cout << "Syntax error: id of Z layer is missing\n";
5694 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5697 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5698 printZLayerInfo (theDI, aSettings);
5700 else if (anArg == "-enable"
5701 || anArg == "enable"
5702 || anArg == "-disable"
5703 || anArg == "disable")
5705 const Standard_Boolean toEnable = anArg == "-enable"
5706 || anArg == "enable";
5707 if (++anArgIter >= theArgNb)
5709 std::cout << "Syntax error: option name is missing\n";
5713 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
5715 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5717 if (++anArgIter >= theArgNb)
5719 std::cout << "Syntax error: id of Z layer is missing\n";
5723 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5726 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5727 if (aSubOp == "depthtest"
5728 || aSubOp == "test")
5730 aSettings.SetEnableDepthTest (toEnable);
5732 else if (aSubOp == "depthwrite"
5733 || aSubOp == "write")
5735 aSettings.SetEnableDepthWrite (toEnable);
5737 else if (aSubOp == "depthclear"
5738 || aSubOp == "clear")
5740 aSettings.SetClearDepth (toEnable);
5742 else if (aSubOp == "depthoffset"
5743 || aSubOp == "offset")
5745 Graphic3d_PolygonOffset aParams;
5746 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5749 if (anArgIter + 2 >= theArgNb)
5751 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5755 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5756 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5758 aSettings.SetPolygonOffset (aParams);
5760 else if (aSubOp == "positiveoffset"
5761 || aSubOp == "poffset")
5765 aSettings.SetDepthOffsetPositive();
5769 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5772 else if (aSubOp == "negativeoffset"
5773 || aSubOp == "noffset")
5777 aSettings.SetDepthOffsetNegative();
5781 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5784 else if (aSubOp == "textureenv")
5786 aSettings.SetEnvironmentTexture (toEnable);
5788 else if (aSubOp == "raytracing")
5790 aSettings.SetRaytracable (toEnable);
5793 aViewer->SetZLayerSettings (aLayerId, aSettings);
5797 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5805 // The interactive presentation of 2d layer item
5806 // for "vlayerline" command it provides a presentation of
5807 // line with user-defined linewidth, linetype and transparency.
5808 class V3d_LineItem : public AIS_InteractiveObject
5812 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
5815 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5816 Standard_Real X2, Standard_Real Y2,
5817 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5818 Standard_Real theWidth = 0.5,
5819 Standard_Real theTransp = 1.0);
5823 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5824 const Handle(Prs3d_Presentation)& thePresentation,
5825 const Standard_Integer theMode) Standard_OVERRIDE;
5827 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
5828 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5833 Standard_Real myX1, myY1, myX2, myY2;
5834 Aspect_TypeOfLine myType;
5835 Standard_Real myWidth;
5838 // default constructor for line item
5839 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5840 Standard_Real X2, Standard_Real Y2,
5841 Aspect_TypeOfLine theType,
5842 Standard_Real theWidth,
5843 Standard_Real theTransp) :
5844 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5845 myType(theType), myWidth(theWidth)
5847 SetTransparency (1-theTransp);
5851 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5852 const Handle(Prs3d_Presentation)& thePresentation,
5853 const Standard_Integer /*theMode*/)
5855 thePresentation->Clear();
5856 Quantity_Color aColor (Quantity_NOC_RED);
5857 Standard_Integer aWidth, aHeight;
5858 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5859 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5860 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5861 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5862 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5863 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5864 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5865 aGroup->AddPrimitiveArray (aPrim);
5868 //=============================================================================
5869 //function : VLayerLine
5870 //purpose : Draws line in the v3d view layer with given attributes: linetype,
5871 // : linewidth, transparency coefficient
5872 //============================================================================
5873 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5875 // get the active view
5876 Handle(V3d_View) aView = ViewerTest::CurrentView();
5879 di << "Call vinit before!\n";
5884 di << "Use: " << argv[0];
5885 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5886 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5887 di << " 0 - solid \n";
5888 di << " 1 - dashed \n";
5889 di << " 2 - dot \n";
5890 di << " 3 - dashdot\n";
5891 di << " transparency : { 0.0 - 1.0 } \n";
5892 di << " 0.0 - transparent\n";
5893 di << " 1.0 - visible \n";
5897 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5898 // get the input params
5899 Standard_Real X1 = Draw::Atof(argv[1]);
5900 Standard_Real Y1 = Draw::Atof(argv[2]);
5901 Standard_Real X2 = Draw::Atof(argv[3]);
5902 Standard_Real Y2 = Draw::Atof(argv[4]);
5904 Standard_Real aWidth = 0.5;
5905 Standard_Real aTransparency = 1.0;
5909 aWidth = Draw::Atof(argv[5]);
5911 // select appropriate line type
5912 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5914 && !ViewerTest::ParseLineType (argv[6], aLineType))
5916 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5923 aTransparency = Draw::Atof(argv[7]);
5924 if (aTransparency < 0 || aTransparency > 1.0)
5925 aTransparency = 1.0;
5928 static Handle (V3d_LineItem) aLine;
5929 if (!aLine.IsNull())
5931 aContext->Erase (aLine, Standard_False);
5933 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5937 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5938 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5939 aLine->SetToUpdate();
5940 aContext->Display (aLine, Standard_True);
5946 //==============================================================================
5949 //==============================================================================
5951 static int VGrid (Draw_Interpretor& /*theDI*/,
5952 Standard_Integer theArgNb,
5953 const char** theArgVec)
5955 Handle(V3d_View) aView = ViewerTest::CurrentView();
5956 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5957 if (aView.IsNull() || aViewer.IsNull())
5959 std::cerr << "Error: no active view\n";
5963 Aspect_GridType aType = aViewer->GridType();
5964 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5965 Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY;
5966 Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0;
5967 bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false;
5968 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5969 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5971 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5973 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5977 else if (anArgIter + 1 < theArgNb
5978 && anArg == "-type")
5980 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5981 anArgNext.LowerCase();
5982 if (anArgNext == "r"
5983 || anArgNext == "rect"
5984 || anArgNext == "rectangular")
5986 aType = Aspect_GT_Rectangular;
5988 else if (anArgNext == "c"
5989 || anArgNext == "circ"
5990 || anArgNext == "circular")
5992 aType = Aspect_GT_Circular;
5996 std::cout << "Syntax error at '" << anArgNext << "'\n";
6000 else if (anArgIter + 1 < theArgNb
6001 && anArg == "-mode")
6003 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
6004 anArgNext.LowerCase();
6005 if (anArgNext == "l"
6006 || anArgNext == "line"
6007 || anArgNext == "lines")
6009 aMode = Aspect_GDM_Lines;
6011 else if (anArgNext == "p"
6012 || anArgNext == "point"
6013 || anArgNext == "points")
6015 aMode = Aspect_GDM_Points;
6019 std::cout << "Syntax error at '" << anArgNext << "'\n";
6023 else if (anArgIter + 2 < theArgNb
6024 && (anArg == "-origin"
6025 || anArg == "-orig"))
6028 aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6029 Draw::Atof (theArgVec[anArgIter + 2]));
6032 else if (anArgIter + 2 < theArgNb
6033 && anArg == "-step")
6036 aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6037 Draw::Atof (theArgVec[anArgIter + 2]));
6038 if (aNewStepXY.x() <= 0.0
6039 || aNewStepXY.y() <= 0.0)
6041 std::cout << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
6046 else if (anArgIter + 1 < theArgNb
6047 && (anArg == "-angle"
6048 || anArg == "-rotangle"
6049 || anArg == "-rotationangle"))
6052 aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]);
6054 else if (anArgIter + 1 < theArgNb
6055 && (anArg == "-zoffset"
6059 aNewZOffset = Draw::Atof (theArgVec[++anArgIter]);
6061 else if (anArgIter + 1 < theArgNb
6062 && anArg == "-radius")
6066 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0);
6067 if (aNewStepXY.x() <= 0.0)
6069 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'\n";
6073 else if (anArgIter + 2 < theArgNb
6074 && anArg == "-size")
6077 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6078 Draw::Atof (theArgVec[anArgIter + 2]));
6079 if (aNewStepXY.x() <= 0.0
6080 || aNewStepXY.y() <= 0.0)
6082 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
6087 else if (anArg == "r"
6089 || anArg == "rectangular")
6091 aType = Aspect_GT_Rectangular;
6093 else if (anArg == "c"
6095 || anArg == "circular")
6097 aType = Aspect_GT_Circular;
6099 else if (anArg == "l"
6101 || anArg == "lines")
6103 aMode = Aspect_GDM_Lines;
6105 else if (anArg == "p"
6107 || anArg == "points")
6109 aMode = Aspect_GDM_Points;
6111 else if (anArgIter + 1 >= theArgNb
6114 aViewer->DeactivateGrid();
6119 std::cout << "Syntax error at '" << anArg << "'\n";
6124 if (aType == Aspect_GT_Rectangular)
6126 Graphic3d_Vec2d anOrigXY, aStepXY;
6127 Standard_Real aRotAngle = 0.0;
6128 aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
6131 anOrigXY = aNewOriginXY;
6135 aStepXY = aNewStepXY;
6139 aRotAngle = aNewRotAngle;
6141 aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
6142 if (hasSize || hasZOffset)
6144 Graphic3d_Vec3d aSize;
6145 aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
6148 aSize.x() = aNewSizeXY.x();
6149 aSize.y() = aNewSizeXY.y();
6153 aSize.z() = aNewZOffset;
6155 aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
6158 else if (aType == Aspect_GT_Circular)
6160 Graphic3d_Vec2d anOrigXY;
6161 Standard_Real aRadiusStep;
6162 Standard_Integer aDivisionNumber;
6163 Standard_Real aRotAngle = 0.0;
6164 aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6167 anOrigXY = aNewOriginXY;
6171 aRadiusStep = aNewStepXY[0];
6172 aDivisionNumber = (int )aNewStepXY[1];
6173 if (aDivisionNumber < 1)
6175 std::cout << "Syntax error: invalid division number '" << aNewStepXY[1] << "'\n";
6181 aRotAngle = aNewRotAngle;
6184 aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6185 if (hasSize || hasZOffset)
6187 Standard_Real aRadius = 0.0, aZOffset = 0.0;
6188 aViewer->CircularGridGraphicValues (aRadius, aZOffset);
6191 aRadius = aNewSizeXY.x();
6192 if (aNewSizeXY.y() != 0.0)
6194 std::cout << "Syntax error: circular size should be specified as radius\n";
6200 aZOffset = aNewZOffset;
6202 aViewer->SetCircularGridGraphicValues (aRadius, aZOffset);
6205 aViewer->ActivateGrid (aType, aMode);
6209 //==============================================================================
6210 //function : VPriviledgedPlane
6212 //==============================================================================
6214 static int VPriviledgedPlane (Draw_Interpretor& theDI,
6215 Standard_Integer theArgNb,
6216 const char** theArgVec)
6218 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
6220 std::cerr << "Error: wrong number of arguments! See usage:\n";
6221 theDI.PrintHelp (theArgVec[0]);
6225 // get the active viewer
6226 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6227 if (aViewer.IsNull())
6229 std::cerr << "Error: no active viewer. Please call vinit.\n";
6235 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
6236 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
6237 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
6238 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
6239 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
6240 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
6241 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
6245 Standard_Integer anArgIdx = 1;
6246 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
6247 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
6248 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
6249 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
6250 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
6251 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
6253 gp_Ax3 aPriviledgedPlane;
6254 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
6255 gp_Dir aNorm (aNormX, aNormY, aNormZ);
6258 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
6259 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
6260 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
6261 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
6262 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
6266 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
6269 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
6274 //==============================================================================
6275 //function : VConvert
6277 //==============================================================================
6279 static int VConvert (Draw_Interpretor& theDI,
6280 Standard_Integer theArgNb,
6281 const char** theArgVec)
6283 // get the active view
6284 Handle(V3d_View) aView = ViewerTest::CurrentView();
6287 std::cerr << "Error: no active view. Please call vinit.\n";
6291 enum { Model, Ray, View, Window, Grid } aMode = Model;
6293 // access coordinate arguments
6294 TColStd_SequenceOfReal aCoord;
6295 Standard_Integer anArgIdx = 1;
6296 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
6298 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6299 if (!anArg.IsRealValue())
6303 aCoord.Append (anArg.RealValue());
6306 // non-numeric argument too early
6307 if (aCoord.IsEmpty())
6309 std::cerr << "Error: wrong number of arguments! See usage:\n";
6310 theDI.PrintHelp (theArgVec[0]);
6314 // collect all other arguments and options
6315 for (; anArgIdx < theArgNb; ++anArgIdx)
6317 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6319 if (anArg == "window") aMode = Window;
6320 else if (anArg == "view") aMode = View;
6321 else if (anArg == "grid") aMode = Grid;
6322 else if (anArg == "ray") aMode = Ray;
6325 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
6326 theDI.PrintHelp (theArgVec[0]);
6331 // complete input checks
6332 if ((aCoord.Length() == 1 && theArgNb > 3) ||
6333 (aCoord.Length() == 2 && theArgNb > 4) ||
6334 (aCoord.Length() == 3 && theArgNb > 5))
6336 std::cerr << "Error: wrong number of arguments! See usage:\n";
6337 theDI.PrintHelp (theArgVec[0]);
6341 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
6342 Standard_Integer aXYp[2] = {0, 0};
6344 // convert one-dimensional coordinate
6345 if (aCoord.Length() == 1)
6349 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
6350 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
6352 std::cerr << "Error: wrong arguments! See usage:\n";
6353 theDI.PrintHelp (theArgVec[0]);
6358 // convert 2D coordinates from projection or view reference space
6359 if (aCoord.Length() == 2)
6364 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6365 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6369 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
6370 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
6374 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
6375 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6379 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6380 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
6381 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6385 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
6386 (Standard_Integer) aCoord (2),
6387 aXYZ[0], aXYZ[1], aXYZ[2],
6388 aXYZ[3], aXYZ[4], aXYZ[5]);
6389 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6393 std::cerr << "Error: wrong arguments! See usage:\n";
6394 theDI.PrintHelp (theArgVec[0]);
6399 // convert 3D coordinates from view reference space
6400 else if (aCoord.Length() == 3)
6405 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
6406 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6410 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
6411 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6415 std::cerr << "Error: wrong arguments! See usage:\n";
6416 theDI.PrintHelp (theArgVec[0]);
6424 //==============================================================================
6427 //==============================================================================
6429 static int VFps (Draw_Interpretor& theDI,
6430 Standard_Integer theArgNb,
6431 const char** theArgVec)
6433 // get the active view
6434 Handle(V3d_View) aView = ViewerTest::CurrentView();
6437 std::cerr << "No active view. Please call vinit.\n";
6441 Standard_Integer aFramesNb = -1;
6442 Standard_Real aDuration = -1.0;
6443 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6445 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6448 && anArgIter + 1 < theArgNb
6449 && (anArg == "-duration"
6451 || anArg == "-time"))
6453 aDuration = Draw::Atof (theArgVec[++anArgIter]);
6455 else if (aFramesNb < 0
6456 && anArg.IsIntegerValue())
6458 aFramesNb = anArg.IntegerValue();
6461 std::cerr << "Syntax error at '" << anArg << "'\n";
6467 std::cerr << "Syntax error at '" << anArg << "'\n";
6471 if (aFramesNb < 0 && aDuration < 0.0)
6476 // the time is meaningless for first call
6477 // due to async OpenGl rendering
6480 // redraw view in loop to estimate average values
6483 Standard_Integer aFrameIter = 1;
6484 for (;; ++aFrameIter)
6488 && aFrameIter >= aFramesNb)
6490 && aTimer.ElapsedTime() >= aDuration))
6497 const Standard_Real aTime = aTimer.ElapsedTime();
6498 aTimer.OSD_Chronometer::Show (aCpu);
6500 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
6501 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
6503 // return statistics
6504 theDI << "FPS: " << aFpsAver << "\n"
6505 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
6507 // compute additional statistics in ray-tracing mode
6508 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
6509 if (aParams.Method == Graphic3d_RM_RAYTRACING)
6511 Graphic3d_Vec2i aWinSize (0, 0);
6512 aView->Window()->Size (aWinSize.x(), aWinSize.y());
6514 // 1 shadow ray and 1 secondary ray pew each bounce
6515 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
6516 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
6522 //! Auxiliary function for parsing glsl dump level argument.
6523 static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
6524 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
6526 TCollection_AsciiString aTypeStr (theArg);
6527 aTypeStr.LowerCase();
6528 if (aTypeStr == "off"
6531 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6533 else if (aTypeStr == "short")
6535 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
6537 else if (aTypeStr == "full"
6540 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6544 return Standard_False;
6546 return Standard_True;
6549 //==============================================================================
6550 //function : VGlDebug
6552 //==============================================================================
6554 static int VGlDebug (Draw_Interpretor& theDI,
6555 Standard_Integer theArgNb,
6556 const char** theArgVec)
6558 Handle(OpenGl_GraphicDriver) aDriver;
6559 Handle(V3d_View) aView = ViewerTest::CurrentView();
6560 if (!aView.IsNull())
6562 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
6564 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
6565 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
6569 TCollection_AsciiString aDebActive, aSyncActive;
6576 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
6577 "GL_ARB_debug_output");
6578 aDebActive = isActive ? " (active)" : " (inactive)";
6581 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
6582 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
6586 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
6587 + "glslSourceCode: "
6588 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
6590 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
6594 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
6595 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
6596 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
6597 << aGlslCodeDebugStatus
6598 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
6602 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6604 Standard_CString anArg = theArgVec[anArgIter];
6605 TCollection_AsciiString anArgCase (anArg);
6606 anArgCase.LowerCase();
6607 Standard_Boolean toEnableDebug = Standard_True;
6608 if (anArgCase == "-glsl"
6609 || anArgCase == "-glslwarn"
6610 || anArgCase == "-glslwarns"
6611 || anArgCase == "-glslwarnings")
6613 Standard_Boolean toShowWarns = Standard_True;
6614 if (++anArgIter < theArgNb
6615 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
6619 aDefCaps->glslWarnings = toShowWarns;
6622 aCaps->glslWarnings = toShowWarns;
6625 else if (anArgCase == "-extra"
6626 || anArgCase == "-extramsg"
6627 || anArgCase == "-extramessages")
6629 Standard_Boolean toShow = Standard_True;
6630 if (++anArgIter < theArgNb
6631 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
6635 aDefCaps->suppressExtraMsg = !toShow;
6638 aCaps->suppressExtraMsg = !toShow;
6641 else if (anArgCase == "-noextra"
6642 || anArgCase == "-noextramsg"
6643 || anArgCase == "-noextramessages")
6645 Standard_Boolean toSuppress = Standard_True;
6646 if (++anArgIter < theArgNb
6647 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
6651 aDefCaps->suppressExtraMsg = toSuppress;
6654 aCaps->suppressExtraMsg = toSuppress;
6657 else if (anArgCase == "-sync")
6659 Standard_Boolean toSync = Standard_True;
6660 if (++anArgIter < theArgNb
6661 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
6665 aDefCaps->contextSyncDebug = toSync;
6668 aDefCaps->contextDebug = Standard_True;
6671 else if (anArgCase == "-glslsourcecode"
6672 || anArgCase == "-glslcode")
6674 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6675 if (++anArgIter < theArgNb
6676 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
6680 aDefCaps->glslDumpLevel = aGslsDumpLevel;
6683 aCaps->glslDumpLevel = aGslsDumpLevel;
6686 else if (anArgCase == "-debug")
6688 if (++anArgIter < theArgNb
6689 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
6693 aDefCaps->contextDebug = toEnableDebug;
6695 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
6696 && (anArgIter + 1 == theArgNb))
6698 // simple alias to turn on almost everything
6699 aDefCaps->contextDebug = toEnableDebug;
6700 aDefCaps->contextSyncDebug = toEnableDebug;
6701 aDefCaps->glslWarnings = toEnableDebug;
6704 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6706 aDefCaps->suppressExtraMsg = !toEnableDebug;
6709 aCaps->contextDebug = toEnableDebug;
6710 aCaps->contextSyncDebug = toEnableDebug;
6711 aCaps->glslWarnings = toEnableDebug;
6714 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6716 aCaps->suppressExtraMsg = !toEnableDebug;
6721 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
6729 //==============================================================================
6732 //==============================================================================
6734 static int VVbo (Draw_Interpretor& theDI,
6735 Standard_Integer theArgNb,
6736 const char** theArgVec)
6738 const Standard_Boolean toSet = (theArgNb > 1);
6739 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
6742 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
6746 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6747 if (aContextAIS.IsNull())
6751 std::cerr << "No active view!\n";
6755 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
6756 if (!aDriver.IsNull())
6760 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
6764 aDriver->ChangeOptions().vboDisable = toUseVbo;
6771 //==============================================================================
6774 //==============================================================================
6776 static int VCaps (Draw_Interpretor& theDI,
6777 Standard_Integer theArgNb,
6778 const char** theArgVec)
6780 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
6781 Handle(OpenGl_GraphicDriver) aDriver;
6782 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6783 if (!aContext.IsNull())
6785 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
6786 aCaps = &aDriver->ChangeOptions();
6791 theDI << "sRGB: " << (aCaps->sRGBDisable ? "0" : "1") << "\n";
6792 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
6793 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
6794 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
6795 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
6796 theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n";
6797 theDI << "VSync: " << aCaps->swapInterval << "\n";
6798 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
6799 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
6800 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
6801 theDI << "NoExt:" << (aCaps->contextNoExtensions ? "1" : "0") << "\n";
6802 theDI << "MaxVersion:" << aCaps->contextMajorVersionUpper << "." << aCaps->contextMinorVersionUpper << "\n";
6806 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6807 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6809 Standard_CString anArg = theArgVec[anArgIter];
6810 TCollection_AsciiString anArgCase (anArg);
6811 anArgCase.LowerCase();
6812 if (anUpdateTool.parseRedrawMode (anArg))
6816 else if (anArgCase == "-vsync"
6817 || anArgCase == "-swapinterval")
6819 Standard_Boolean toEnable = Standard_True;
6820 if (++anArgIter < theArgNb
6821 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6825 aCaps->swapInterval = toEnable;
6827 else if (anArgCase == "-ffp")
6829 Standard_Boolean toEnable = Standard_True;
6830 if (++anArgIter < theArgNb
6831 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6835 aCaps->ffpEnable = toEnable;
6837 else if (anArgCase == "-polygonmode")
6839 Standard_Boolean toEnable = Standard_True;
6840 if (++anArgIter < theArgNb
6841 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6845 aCaps->usePolygonMode = toEnable;
6847 else if (anArgCase == "-srgb")
6849 Standard_Boolean toEnable = Standard_True;
6850 if (++anArgIter < theArgNb
6851 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6855 aCaps->sRGBDisable = !toEnable;
6857 else if (anArgCase == "-vbo")
6859 Standard_Boolean toEnable = Standard_True;
6860 if (++anArgIter < theArgNb
6861 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6865 aCaps->vboDisable = !toEnable;
6867 else if (anArgCase == "-sprite"
6868 || anArgCase == "-sprites")
6870 Standard_Boolean toEnable = Standard_True;
6871 if (++anArgIter < theArgNb
6872 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6876 aCaps->pntSpritesDisable = !toEnable;
6878 else if (anArgCase == "-softmode")
6880 Standard_Boolean toEnable = Standard_True;
6881 if (++anArgIter < theArgNb
6882 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6886 aCaps->contextNoAccel = toEnable;
6888 else if (anArgCase == "-winbuffer"
6889 || anArgCase == "-windowbuffer"
6890 || anArgCase == "-usewinbuffer"
6891 || anArgCase == "-usewindowbuffer"
6892 || anArgCase == "-usesystembuffer")
6894 Standard_Boolean toEnable = Standard_True;
6895 if (++anArgIter < theArgNb
6896 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6900 aCaps->useSystemBuffer = toEnable;
6902 else if (anArgCase == "-accel"
6903 || anArgCase == "-acceleration")
6905 Standard_Boolean toEnable = Standard_True;
6906 if (++anArgIter < theArgNb
6907 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6911 aCaps->contextNoAccel = !toEnable;
6913 else if (anArgCase == "-compat"
6914 || anArgCase == "-compatprofile"
6915 || anArgCase == "-compatible"
6916 || anArgCase == "-compatibleprofile")
6918 Standard_Boolean toEnable = Standard_True;
6919 if (++anArgIter < theArgNb
6920 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6924 aCaps->contextCompatible = toEnable;
6925 if (!aCaps->contextCompatible)
6927 aCaps->ffpEnable = Standard_False;
6930 else if (anArgCase == "-core"
6931 || anArgCase == "-coreprofile")
6933 Standard_Boolean toEnable = Standard_True;
6934 if (++anArgIter < theArgNb
6935 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6939 aCaps->contextCompatible = !toEnable;
6940 if (!aCaps->contextCompatible)
6942 aCaps->ffpEnable = Standard_False;
6945 else if (anArgCase == "-stereo"
6946 || anArgCase == "-quadbuffer")
6948 Standard_Boolean toEnable = Standard_True;
6949 if (++anArgIter < theArgNb
6950 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6954 aCaps->contextStereo = toEnable;
6956 else if (anArgCase == "-noext"
6957 || anArgCase == "-noextensions"
6958 || anArgCase == "-noextension")
6960 Standard_Boolean toDisable = Standard_True;
6961 if (++anArgIter < theArgNb
6962 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
6966 aCaps->contextNoExtensions = toDisable;
6968 else if (anArgCase == "-maxversion"
6969 || anArgCase == "-upperversion"
6970 || anArgCase == "-limitversion")
6972 Standard_Integer aVer[2] = { -2, -1 };
6973 for (Standard_Integer aValIter = 0; aValIter < 2; ++aValIter)
6975 if (anArgIter + 1 < theArgNb)
6977 const TCollection_AsciiString aStr (theArgVec[anArgIter + 1]);
6978 if (aStr.IsIntegerValue())
6980 aVer[aValIter] = aStr.IntegerValue();
6988 std::cout << "Syntax error at '" << anArgCase << "'\n";
6991 aCaps->contextMajorVersionUpper = aVer[0];
6992 aCaps->contextMinorVersionUpper = aVer[1];
6996 std::cout << "Error: unknown argument '" << anArg << "'\n";
7000 if (aCaps != &ViewerTest_myDefaultCaps)
7002 ViewerTest_myDefaultCaps = *aCaps;
7007 //==============================================================================
7008 //function : VMemGpu
7010 //==============================================================================
7012 static int VMemGpu (Draw_Interpretor& theDI,
7013 Standard_Integer theArgNb,
7014 const char** theArgVec)
7017 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
7018 if (aContextAIS.IsNull())
7020 std::cerr << "No active view. Please call vinit.\n";
7024 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
7025 if (aDriver.IsNull())
7027 std::cerr << "Graphic driver not available.\n";
7031 Standard_Size aFreeBytes = 0;
7032 TCollection_AsciiString anInfo;
7033 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
7035 std::cerr << "Information not available.\n";
7039 if (theArgNb > 1 && *theArgVec[1] == 'f')
7041 theDI << Standard_Real (aFreeBytes);
7051 // ==============================================================================
7052 // function : VReadPixel
7054 // ==============================================================================
7055 static int VReadPixel (Draw_Interpretor& theDI,
7056 Standard_Integer theArgNb,
7057 const char** theArgVec)
7059 // get the active view
7060 Handle(V3d_View) aView = ViewerTest::CurrentView();
7063 std::cerr << "No active view. Please call vinit.\n";
7066 else if (theArgNb < 3)
7068 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
7072 Image_Format aFormat = Image_Format_RGBA;
7073 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
7075 Standard_Integer aWidth, aHeight;
7076 aView->Window()->Size (aWidth, aHeight);
7077 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
7078 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
7079 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
7081 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
7085 bool toShowName = false, toShowHls = false, toShowHex = false, toShow_sRGB = false;
7086 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
7088 TCollection_AsciiString aParam (theArgVec[anIter]);
7090 if (aParam == "-rgb"
7092 || aParam == "-srgb"
7093 || aParam == "srgb")
7095 aFormat = Image_Format_RGB;
7096 aBufferType = Graphic3d_BT_RGB;
7097 toShow_sRGB = aParam == "-srgb" || aParam == "srgb";
7099 else if (aParam == "-hls"
7102 aFormat = Image_Format_RGB;
7103 aBufferType = Graphic3d_BT_RGB;
7104 toShowHls = Standard_True;
7106 else if (aParam == "-rgbf"
7107 || aParam == "rgbf")
7109 aFormat = Image_Format_RGBF;
7110 aBufferType = Graphic3d_BT_RGB;
7112 else if (aParam == "-rgba"
7114 || aParam == "-srgba"
7115 || aParam == "srgba")
7117 aFormat = Image_Format_RGBA;
7118 aBufferType = Graphic3d_BT_RGBA;
7119 toShow_sRGB = aParam == "-srgba" || aParam == "srgba";
7121 else if (aParam == "-rgbaf"
7122 || aParam == "rgbaf")
7124 aFormat = Image_Format_RGBAF;
7125 aBufferType = Graphic3d_BT_RGBA;
7127 else if (aParam == "-depth"
7128 || aParam == "depth")
7130 aFormat = Image_Format_GrayF;
7131 aBufferType = Graphic3d_BT_Depth;
7133 else if (aParam == "-name"
7134 || aParam == "name")
7136 toShowName = Standard_True;
7138 else if (aParam == "-hex"
7141 toShowHex = Standard_True;
7145 std::cout << "Syntax error at '" << aParam << "'\n";
7150 Image_PixMap anImage;
7151 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
7153 std::cerr << "Image allocation failed\n";
7156 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
7158 std::cerr << "Image dump failed\n";
7162 // redirect possible warning messages that could have been added by ToPixMap
7163 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
7164 // contaminate result of the command
7165 Standard_CString aWarnLog = theDI.Result();
7166 if (aWarnLog != NULL && aWarnLog[0] != '\0')
7168 std::cout << aWarnLog << std::endl;
7172 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY, true);
7175 if (aBufferType == Graphic3d_BT_RGBA)
7177 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
7181 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
7186 if (aBufferType == Graphic3d_BT_RGBA)
7188 theDI << Quantity_ColorRGBA::ColorToHex (aColor);
7192 theDI << Quantity_Color::ColorToHex (aColor.GetRGB());
7197 switch (aBufferType)
7200 case Graphic3d_BT_RGB:
7204 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
7206 else if (toShow_sRGB)
7208 const Graphic3d_Vec4 aColor_sRGB = Quantity_ColorRGBA::Convert_LinearRGB_To_sRGB ((Graphic3d_Vec4 )aColor);
7209 theDI << aColor_sRGB.r() << " " << aColor_sRGB.g() << " " << aColor_sRGB.b();
7213 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
7217 case Graphic3d_BT_RGBA:
7219 const Graphic3d_Vec4 aVec4 = toShow_sRGB ? Quantity_ColorRGBA::Convert_LinearRGB_To_sRGB ((Graphic3d_Vec4 )aColor) : (Graphic3d_Vec4 )aColor;
7220 theDI << aVec4.r() << " " << aVec4.g() << " " << aVec4.b() << " " << aVec4.a();
7223 case Graphic3d_BT_Depth:
7225 theDI << aColor.GetRGB().Red();
7234 //! Auxiliary presentation for an image plane.
7235 class ViewerTest_ImagePrs : public AIS_InteractiveObject
7238 //! Main constructor.
7239 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
7240 const Standard_Real theWidth,
7241 const Standard_Real theHeight,
7242 const TCollection_AsciiString& theLabel)
7243 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
7247 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
7249 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
7250 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
7251 Graphic3d_MaterialAspect aMat;
7252 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
7253 aMat.SetAmbientColor (Quantity_NOC_BLACK);
7254 aMat.SetDiffuseColor (Quantity_NOC_WHITE);
7255 aMat.SetSpecularColor (Quantity_NOC_BLACK);
7256 aMat.SetEmissiveColor (Quantity_NOC_BLACK);
7257 aFillAspect->SetFrontMaterial (aMat);
7258 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
7259 aFillAspect->SetTextureMapOn();
7262 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
7263 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
7264 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
7265 myDrawer->SetTextAspect (aTextAspect);
7268 const gp_Dir aNorm (0.0, 0.0, 1.0);
7269 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
7270 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
7271 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
7272 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
7273 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
7274 myTris->AddEdge (1);
7275 myTris->AddEdge (2);
7276 myTris->AddEdge (3);
7277 myTris->AddEdge (3);
7278 myTris->AddEdge (2);
7279 myTris->AddEdge (4);
7281 myRect = new Graphic3d_ArrayOfPolylines (4);
7282 myRect->AddVertex (myTris->Vertice (1));
7283 myRect->AddVertex (myTris->Vertice (3));
7284 myRect->AddVertex (myTris->Vertice (4));
7285 myRect->AddVertex (myTris->Vertice (2));
7289 //! Returns TRUE for accepted display modes.
7290 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
7292 //! Compute presentation.
7293 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
7299 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7300 aGroup->AddPrimitiveArray (myTris);
7301 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
7302 aGroup->AddPrimitiveArray (myRect);
7303 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7308 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
7309 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7310 aGroup->AddPrimitiveArray (myRect);
7311 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7317 //! Compute selection.
7318 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
7322 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
7323 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
7324 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
7325 theSel->Add (aSensitive);
7330 Handle(Graphic3d_ArrayOfTriangles) myTris;
7331 Handle(Graphic3d_ArrayOfPolylines) myRect;
7332 TCollection_AsciiString myLabel;
7333 Standard_Real myWidth;
7334 Standard_Real myHeight;
7337 //==============================================================================
7338 //function : VDiffImage
7339 //purpose : The draw-command compares two images.
7340 //==============================================================================
7342 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
7346 std::cout << "Syntax error: not enough arguments.\n";
7350 Standard_Integer anArgIter = 1;
7351 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
7352 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
7353 TCollection_AsciiString aDiffImagePath;
7354 Standard_Real aTolColor = -1.0;
7355 Standard_Integer toBlackWhite = -1;
7356 Standard_Integer isBorderFilterOn = -1;
7357 Standard_Boolean isOldSyntax = Standard_False;
7358 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
7359 for (; anArgIter < theArgNb; ++anArgIter)
7361 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7363 if (anArgIter + 1 < theArgNb
7364 && (anArg == "-toleranceofcolor"
7365 || anArg == "-tolerancecolor"
7366 || anArg == "-tolerance"
7367 || anArg == "-toler"))
7369 aTolColor = Atof (theArgVec[++anArgIter]);
7370 if (aTolColor < 0.0 || aTolColor > 1.0)
7372 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7376 else if (anArg == "-blackwhite")
7378 Standard_Boolean toEnable = Standard_True;
7379 if (anArgIter + 1 < theArgNb
7380 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7384 toBlackWhite = toEnable ? 1 : 0;
7386 else if (anArg == "-borderfilter")
7388 Standard_Boolean toEnable = Standard_True;
7389 if (anArgIter + 1 < theArgNb
7390 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7394 isBorderFilterOn = toEnable ? 1 : 0;
7396 else if (anArg == "-exitonclose")
7398 ViewerTest_EventManager::ToExitOnCloseView() = true;
7399 if (anArgIter + 1 < theArgNb
7400 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToExitOnCloseView()))
7405 else if (anArg == "-closeonescape"
7406 || anArg == "-closeonesc")
7408 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
7409 if (anArgIter + 1 < theArgNb
7410 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
7415 else if (anArgIter + 3 < theArgNb
7416 && anArg == "-display")
7418 aViewName = theArgVec[++anArgIter];
7419 aPrsNameRef = theArgVec[++anArgIter];
7420 aPrsNameNew = theArgVec[++anArgIter];
7421 if (anArgIter + 1 < theArgNb
7422 && *theArgVec[anArgIter + 1] != '-')
7424 aPrsNameDiff = theArgVec[++anArgIter];
7427 else if (aTolColor < 0.0
7428 && anArg.IsRealValue())
7430 isOldSyntax = Standard_True;
7431 aTolColor = anArg.RealValue();
7432 if (aTolColor < 0.0 || aTolColor > 1.0)
7434 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7438 else if (isOldSyntax
7439 && toBlackWhite == -1
7440 && (anArg == "0" || anArg == "1"))
7442 toBlackWhite = anArg == "1" ? 1 : 0;
7444 else if (isOldSyntax
7445 && isBorderFilterOn == -1
7446 && (anArg == "0" || anArg == "1"))
7448 isBorderFilterOn = anArg == "1" ? 1 : 0;
7450 else if (aDiffImagePath.IsEmpty())
7452 aDiffImagePath = theArgVec[anArgIter];
7456 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7461 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
7462 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
7463 if (!anImgRef->Load (anImgPathRef))
7465 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
7468 if (!anImgNew->Load (anImgPathNew))
7470 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
7474 // compare the images
7475 Image_Diff aComparer;
7476 Standard_Integer aDiffColorsNb = -1;
7477 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
7479 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
7480 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
7481 aDiffColorsNb = aComparer.Compare();
7482 theDI << aDiffColorsNb << "\n";
7485 // save image of difference
7486 Handle(Image_AlienPixMap) aDiff;
7487 if (aDiffColorsNb > 0
7488 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
7490 aDiff = new Image_AlienPixMap();
7491 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
7493 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
7496 aComparer.SaveDiffImage (*aDiff);
7497 if (!aDiffImagePath.IsEmpty()
7498 && !aDiff->Save (aDiffImagePath))
7500 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
7505 if (aViewName.IsEmpty())
7510 ViewerTest_Names aViewNames (aViewName);
7511 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
7513 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
7514 theDI.Eval (aCommand.ToCString());
7517 Standard_Integer aPxLeft = 0;
7518 Standard_Integer aPxTop = 0;
7519 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
7520 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
7521 ? int(anImgRef->SizeY() * 2)
7522 : int(anImgRef->SizeY());
7523 TCollection_AsciiString aDisplayName;
7524 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
7525 aViewName, aDisplayName);
7527 Standard_Real aRatio = anImgRef->Ratio();
7528 Standard_Real aSizeX = 1.0;
7529 Standard_Real aSizeY = aSizeX / aRatio;
7531 OSD_Path aPath (anImgPathRef);
7532 TCollection_AsciiString aLabelRef;
7533 if (!aPath.Name().IsEmpty())
7535 aLabelRef = aPath.Name() + aPath.Extension();
7537 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
7539 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
7541 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
7542 anImgRefPrs->SetLocalTransformation (aTrsfRef);
7543 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
7546 OSD_Path aPath (anImgPathNew);
7547 TCollection_AsciiString aLabelNew;
7548 if (!aPath.Name().IsEmpty())
7550 aLabelNew = aPath.Name() + aPath.Extension();
7552 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
7554 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
7556 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
7557 anImgNewPrs->SetLocalTransformation (aTrsfRef);
7558 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
7560 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
7561 if (!aDiff.IsNull())
7563 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
7565 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
7566 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
7568 if (!aPrsNameDiff.IsEmpty())
7570 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
7572 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
7573 ViewerTest::CurrentView()->FitAll();
7577 //=======================================================================
7578 //function : VSelect
7579 //purpose : Emulates different types of selection by mouse:
7580 // 1) single click selection
7581 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
7582 // 3) selection with polygon having corners at
7583 // pixel positions (x1,y1),...,(xn,yn)
7584 // 4) any of these selections with shift button pressed
7585 //=======================================================================
7586 static Standard_Integer VSelect (Draw_Interpretor& ,
7587 Standard_Integer theNbArgs,
7588 const char** theArgVec)
7590 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7593 std::cout << "Error: no active View\n";
7597 NCollection_Sequence<Graphic3d_Vec2i> aPnts;
7598 bool isShiftSelection = false, toAllowOverlap = false;
7599 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7601 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7603 if (anArg == "-allowoverlap")
7605 toAllowOverlap = true;
7606 if (anArgIter + 1 < theNbArgs
7607 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toAllowOverlap))
7612 else if (anArgIter + 1 < theNbArgs
7613 && anArg.IsIntegerValue()
7614 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
7616 const TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
7617 aPnts.Append (Graphic3d_Vec2i (anArg.IntegerValue(), anArgNext.IntegerValue()));
7619 else if (anArgIter + 1 == theNbArgs
7620 && anArg.IsIntegerValue())
7622 isShiftSelection = anArg.IntegerValue() == 1;
7626 std::cout << "Syntax error at '" << anArg << "'\n";
7631 && aPnts.Length() != 2)
7633 std::cout << "Syntax error: -allowoverlap key is applied only for rectangle selection\n";
7638 aCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
7641 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
7642 if (aPnts.IsEmpty())
7644 if (isShiftSelection)
7646 aCtx->ShiftSelect (false);
7650 aCtx->Select (false);
7652 aCtx->CurrentViewer()->Invalidate();
7654 else if (aPnts.Length() == 2)
7657 && aPnts.First().y() < aPnts.Last().y())
7659 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7661 else if (!toAllowOverlap
7662 && aPnts.First().y() > aPnts.Last().y())
7664 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7666 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
7670 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
7672 aCurrentEventManager->FlushViewEvents (aCtx, ViewerTest::CurrentView(), true);
7676 //=======================================================================
7677 //function : VMoveTo
7678 //purpose : Emulates cursor movement to defined pixel position
7679 //=======================================================================
7680 static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
7681 Standard_Integer theNbArgs,
7682 const char** theArgVec)
7684 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
7685 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
7686 if (aContext.IsNull())
7688 std::cout << "Error: no active View\n";
7692 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
7693 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7695 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
7696 anArgStr.LowerCase();
7697 if (anArgStr == "-reset"
7698 || anArgStr == "-clear")
7700 if (anArgIter + 1 < theNbArgs)
7702 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
7706 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
7707 && aContext->CurrentViewer()->GridEcho();
7710 aContext->CurrentViewer()->HideGridEcho (aView);
7712 if (aContext->ClearDetected() || toEchoGrid)
7714 aContext->CurrentViewer()->RedrawImmediate();
7718 else if (aMousePos.x() == IntegerLast()
7719 && anArgStr.IsIntegerValue())
7721 aMousePos.x() = anArgStr.IntegerValue();
7723 else if (aMousePos.y() == IntegerLast()
7724 && anArgStr.IsIntegerValue())
7726 aMousePos.y() = anArgStr.IntegerValue();
7730 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7735 if (aMousePos.x() == IntegerLast()
7736 || aMousePos.y() == IntegerLast())
7738 std::cout << "Syntax error: wrong number of arguments\n";
7742 ViewerTest::CurrentEventManager()->ResetPreviousMoveTo();
7743 ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false);
7744 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
7746 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
7747 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
7748 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
7750 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
7752 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
7756 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
7762 //! Global map storing all animations registered in ViewerTest.
7763 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
7765 //! The animation calling the Draw Harness command.
7766 class ViewerTest_AnimationProc : public AIS_Animation
7770 //! Main constructor.
7771 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
7772 Draw_Interpretor* theDI,
7773 const TCollection_AsciiString& theCommand)
7774 : AIS_Animation (theAnimationName),
7776 myCommand (theCommand)
7783 //! Evaluate the command.
7784 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
7786 TCollection_AsciiString aCmd = myCommand;
7787 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
7788 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
7789 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
7790 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
7791 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
7792 myDrawInter->Eval (aCmd.ToCString());
7795 //! Find the keyword in the command and replace it with value.
7796 //! @return the position of the keyword to pass value
7797 void replace (TCollection_AsciiString& theCmd,
7798 const TCollection_AsciiString& theKey,
7799 const TCollection_AsciiString& theVal)
7801 TCollection_AsciiString aCmd (theCmd);
7803 const Standard_Integer aPos = aCmd.Search (theKey);
7809 TCollection_AsciiString aPart1, aPart2;
7810 Standard_Integer aPart1To = aPos - 1;
7812 && aPart1To <= theCmd.Length())
7814 aPart1 = theCmd.SubString (1, aPart1To);
7817 Standard_Integer aPart2From = aPos + theKey.Length();
7819 && aPart2From <= theCmd.Length())
7821 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
7824 theCmd = aPart1 + theVal + aPart2;
7829 Draw_Interpretor* myDrawInter;
7830 TCollection_AsciiString myCommand;
7834 //! Replace the animation with the new one.
7835 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
7836 Handle(AIS_Animation)& theAnimation,
7837 const Handle(AIS_Animation)& theAnimationNew)
7839 theAnimationNew->CopyFrom (theAnimation);
7840 if (!theParentAnimation.IsNull())
7842 theParentAnimation->Replace (theAnimation, theAnimationNew);
7846 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
7847 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
7849 theAnimation = theAnimationNew;
7852 //! Parse the point.
7853 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
7855 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
7856 if (!anXYZ[0].IsRealValue()
7857 || !anXYZ[1].IsRealValue()
7858 || !anXYZ[2].IsRealValue())
7860 return Standard_False;
7863 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
7864 return Standard_True;
7867 //! Parse the quaternion.
7868 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
7870 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
7871 if (!anXYZW[0].IsRealValue()
7872 || !anXYZW[1].IsRealValue()
7873 || !anXYZW[2].IsRealValue()
7874 || !anXYZW[3].IsRealValue())
7876 return Standard_False;
7879 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
7880 return Standard_True;
7883 //! Auxiliary class for flipping image upside-down.
7888 //! Empty constructor.
7889 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
7891 //! Perform flipping.
7892 Standard_Boolean FlipY (Image_PixMap& theImage)
7894 if (theImage.IsEmpty()
7895 || theImage.SizeX() == 0
7896 || theImage.SizeY() == 0)
7898 return Standard_False;
7901 const Standard_Size aRowSize = theImage.SizeRowBytes();
7902 if (myTmp.Size() < aRowSize
7903 && !myTmp.Allocate (aRowSize))
7905 return Standard_False;
7908 // for odd height middle row should be left as is
7909 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
7910 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
7912 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
7913 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
7914 memcpy (myTmp.ChangeData(), aTop, aRowSize);
7915 memcpy (aTop, aBot, aRowSize);
7916 memcpy (aBot, myTmp.Data(), aRowSize);
7918 return Standard_True;
7922 NCollection_Buffer myTmp;
7927 //=================================================================================================
7928 //function : VViewParams
7929 //purpose : Gets or sets AIS View characteristics
7930 //=================================================================================================
7931 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7933 Handle(V3d_View) aView = ViewerTest::CurrentView();
7936 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
7940 Standard_Boolean toSetProj = Standard_False;
7941 Standard_Boolean toSetUp = Standard_False;
7942 Standard_Boolean toSetAt = Standard_False;
7943 Standard_Boolean toSetEye = Standard_False;
7944 Standard_Boolean toSetScale = Standard_False;
7945 Standard_Boolean toSetSize = Standard_False;
7946 Standard_Boolean toSetCenter2d = Standard_False;
7947 Standard_Real aViewScale = aView->Scale();
7948 Standard_Real aViewSize = 1.0;
7949 Graphic3d_Vec2i aCenter2d;
7950 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
7951 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
7952 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
7953 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
7954 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
7957 // print all of the available view parameters
7961 "Proj: %12g %12g %12g\n"
7962 "Up: %12g %12g %12g\n"
7963 "At: %12g %12g %12g\n"
7964 "Eye: %12g %12g %12g\n",
7966 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7967 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7968 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
7969 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7974 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7975 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7977 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7979 if (anUpdateTool.parseRedrawMode (anArg))
7983 else if (anArg == "-cmd"
7984 || anArg == "-command"
7985 || anArg == "-args")
7994 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7995 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7996 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7999 else if (anArg == "-scale"
8000 || anArg == "-size")
8002 if (anArgIter + 1 < theArgsNb
8003 && *theArgVec[anArgIter + 1] != '-')
8005 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
8006 if (aValueArg.IsRealValue())
8009 if (anArg == "-scale")
8011 toSetScale = Standard_True;
8012 aViewScale = aValueArg.RealValue();
8014 else if (anArg == "-size")
8016 toSetSize = Standard_True;
8017 aViewSize = aValueArg.RealValue();
8022 if (anArg == "-scale")
8024 theDi << "Scale: " << aView->Scale() << "\n";
8026 else if (anArg == "-size")
8028 Graphic3d_Vec2d aSizeXY;
8029 aView->Size (aSizeXY.x(), aSizeXY.y());
8030 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
8033 else if (anArg == "-eye"
8036 || anArg == "-proj")
8038 if (anArgIter + 3 < theArgsNb)
8041 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
8044 if (anArg == "-eye")
8046 toSetEye = Standard_True;
8049 else if (anArg == "-at")
8051 toSetAt = Standard_True;
8054 else if (anArg == "-up")
8056 toSetUp = Standard_True;
8059 else if (anArg == "-proj")
8061 toSetProj = Standard_True;
8068 if (anArg == "-eye")
8070 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
8072 else if (anArg == "-at")
8074 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
8076 else if (anArg == "-up")
8078 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
8080 else if (anArg == "-proj")
8082 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
8085 else if (anArg == "-center")
8087 if (anArgIter + 2 < theArgsNb)
8089 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
8090 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
8091 if (anX.IsIntegerValue()
8092 && anY.IsIntegerValue())
8094 toSetCenter2d = Standard_True;
8095 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
8101 std::cout << "Syntax error at '" << anArg << "'\n";
8106 // change view parameters in proper order
8109 aView->SetScale (aViewScale);
8113 aView->SetSize (aViewSize);
8117 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
8121 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
8125 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
8129 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
8133 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
8139 //==============================================================================
8140 //function : V2DMode
8142 //==============================================================================
8143 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
8145 bool is2dMode = true;
8146 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
8147 if (aV3dView.IsNull())
8149 std::cout << "Error: no active view.\n";
8152 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
8154 const TCollection_AsciiString anArg = theArgVec[anArgIt];
8155 TCollection_AsciiString anArgCase = anArg;
8156 anArgCase.LowerCase();
8157 if (anArgIt + 1 < theArgsNb
8158 && anArgCase == "-name")
8160 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
8161 TCollection_AsciiString aViewName = aViewNames.GetViewName();
8162 if (!ViewerTest_myViews.IsBound1 (aViewName))
8164 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
8167 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
8169 else if (anArgCase == "-mode")
8171 if (anArgIt + 1 < theArgsNb
8172 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
8177 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
8183 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
8188 aV3dView->SetView2DMode (is2dMode);
8192 //==============================================================================
8193 //function : VAnimation
8195 //==============================================================================
8196 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
8197 Standard_Integer theArgNb,
8198 const char** theArgVec)
8200 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
8203 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
8204 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
8206 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
8212 std::cout << "Error: no active view\n";
8216 Standard_Integer anArgIter = 1;
8217 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
8218 if (aNameArg.IsEmpty())
8220 std::cout << "Syntax error: animation name is not defined.\n";
8224 TCollection_AsciiString aNameArgLower = aNameArg;
8225 aNameArgLower.LowerCase();
8226 if (aNameArgLower == "-reset"
8227 || aNameArgLower == "-clear")
8229 ViewerTest_AnimationTimelineMap.Clear();
8232 else if (aNameArg.Value (1) == '-')
8234 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
8238 const char* aNameSplitter = "/";
8239 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
8240 if (aSplitPos == -1)
8242 aNameSplitter = ".";
8243 aSplitPos = aNameArg.Search (aNameSplitter);
8246 // find existing or create a new animation by specified name within syntax "parent.child".
8247 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
8248 for (; !aNameArg.IsEmpty();)
8250 TCollection_AsciiString aNameParent;
8251 if (aSplitPos != -1)
8253 if (aSplitPos == aNameArg.Length())
8255 std::cout << "Syntax error: animation name is not defined.\n";
8259 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
8260 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
8262 aSplitPos = aNameArg.Search (aNameSplitter);
8266 aNameParent = aNameArg;
8270 if (anAnimation.IsNull())
8272 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
8274 anAnimation = new AIS_Animation (aNameParent);
8275 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
8277 aRootAnimation = anAnimation;
8281 aParentAnimation = anAnimation;
8282 anAnimation = aParentAnimation->Find (aNameParent);
8283 if (anAnimation.IsNull())
8285 anAnimation = new AIS_Animation (aNameParent);
8286 aParentAnimation->Add (anAnimation);
8291 if (anArgIter >= theArgNb)
8293 // just print the list of children
8294 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
8296 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
8301 // animation parameters
8302 Standard_Boolean toPlay = Standard_False;
8303 Standard_Real aPlaySpeed = 1.0;
8304 Standard_Real aPlayStartTime = anAnimation->StartPts();
8305 Standard_Real aPlayDuration = anAnimation->Duration();
8306 Standard_Boolean isFreeCamera = Standard_False;
8307 Standard_Boolean isLockLoop = Standard_False;
8309 // video recording parameters
8310 TCollection_AsciiString aRecFile;
8311 Image_VideoParams aRecParams;
8313 Handle(V3d_View) aView = ViewerTest::CurrentView();
8314 for (; anArgIter < theArgNb; ++anArgIter)
8316 TCollection_AsciiString anArg (theArgVec[anArgIter]);
8319 if (anArg == "-reset"
8320 || anArg == "-clear")
8322 anAnimation->Clear();
8324 else if (anArg == "-remove"
8326 || anArg == "-delete")
8328 if (!aParentAnimation.IsNull())
8330 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
8334 aParentAnimation->Remove (anAnimation);
8338 else if (anArg == "-play")
8340 toPlay = Standard_True;
8341 if (++anArgIter < theArgNb)
8343 if (*theArgVec[anArgIter] == '-')
8348 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
8350 if (++anArgIter < theArgNb)
8352 if (*theArgVec[anArgIter] == '-')
8357 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8361 else if (anArg == "-resume")
8363 toPlay = Standard_True;
8364 aPlayStartTime = anAnimation->ElapsedTime();
8365 if (++anArgIter < theArgNb)
8367 if (*theArgVec[anArgIter] == '-')
8373 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8376 else if (anArg == "-playspeed"
8377 || anArg == "-speed")
8379 if (++anArgIter >= theArgNb)
8381 std::cout << "Syntax error at " << anArg << ".\n";
8384 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
8386 else if (anArg == "-lock"
8387 || anArg == "-lockloop"
8388 || anArg == "-playlockloop")
8390 isLockLoop = Standard_True;
8392 else if (anArg == "-freecamera"
8393 || anArg == "-playfreecamera"
8394 || anArg == "-freelook")
8396 isFreeCamera = Standard_True;
8398 // video recodring options
8399 else if (anArg == "-rec"
8400 || anArg == "-record")
8402 if (++anArgIter >= theArgNb)
8404 std::cout << "Syntax error at " << anArg << ".\n";
8408 aRecFile = theArgVec[anArgIter];
8409 if (aRecParams.FpsNum <= 0)
8411 aRecParams.FpsNum = 24;
8414 if (anArgIter + 2 < theArgNb
8415 && *theArgVec[anArgIter + 1] != '-'
8416 && *theArgVec[anArgIter + 2] != '-')
8418 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
8419 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
8420 if (aWidthArg .IsIntegerValue()
8421 && aHeightArg.IsIntegerValue())
8423 aRecParams.Width = aWidthArg .IntegerValue();
8424 aRecParams.Height = aHeightArg.IntegerValue();
8429 else if (anArg == "-fps")
8431 if (++anArgIter >= theArgNb)
8433 std::cout << "Syntax error at " << anArg << ".\n";
8437 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
8438 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
8439 if (aSplitIndex == 0)
8441 aRecParams.FpsNum = aFpsArg.IntegerValue();
8445 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
8446 aFpsArg.Split (aFpsArg.Length() - 1);
8447 const TCollection_AsciiString aNumStr = aFpsArg;
8448 aRecParams.FpsNum = aNumStr.IntegerValue();
8449 aRecParams.FpsDen = aDenStr.IntegerValue();
8450 if (aRecParams.FpsDen < 1)
8452 std::cout << "Syntax error at " << anArg << ".\n";
8457 else if (anArg == "-format")
8459 if (++anArgIter >= theArgNb)
8461 std::cout << "Syntax error at " << anArg << ".\n";
8464 aRecParams.Format = theArgVec[anArgIter];
8466 else if (anArg == "-pix_fmt"
8467 || anArg == "-pixfmt"
8468 || anArg == "-pixelformat")
8470 if (++anArgIter >= theArgNb)
8472 std::cout << "Syntax error at " << anArg << ".\n";
8475 aRecParams.PixelFormat = theArgVec[anArgIter];
8477 else if (anArg == "-codec"
8478 || anArg == "-vcodec"
8479 || anArg == "-videocodec")
8481 if (++anArgIter >= theArgNb)
8483 std::cout << "Syntax error at " << anArg << ".\n";
8486 aRecParams.VideoCodec = theArgVec[anArgIter];
8488 else if (anArg == "-crf"
8489 || anArg == "-preset"
8492 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
8493 if (++anArgIter >= theArgNb)
8495 std::cout << "Syntax error at " << anArg << ".\n";
8499 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
8501 // animation definition options
8502 else if (anArg == "-start"
8503 || anArg == "-starttime"
8504 || anArg == "-startpts")
8506 if (++anArgIter >= theArgNb)
8508 std::cout << "Syntax error at " << anArg << ".\n";
8512 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
8513 aRootAnimation->UpdateTotalDuration();
8515 else if (anArg == "-end"
8516 || anArg == "-endtime"
8517 || anArg == "-endpts")
8519 if (++anArgIter >= theArgNb)
8521 std::cout << "Syntax error at " << anArg << ".\n";
8525 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
8526 aRootAnimation->UpdateTotalDuration();
8528 else if (anArg == "-dur"
8529 || anArg == "-duration")
8531 if (++anArgIter >= theArgNb)
8533 std::cout << "Syntax error at " << anArg << ".\n";
8537 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
8538 aRootAnimation->UpdateTotalDuration();
8540 else if (anArg == "-command"
8542 || anArg == "-invoke"
8544 || anArg == "-proc")
8546 if (++anArgIter >= theArgNb)
8548 std::cout << "Syntax error at " << anArg << ".\n";
8552 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
8553 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
8555 else if (anArg == "-objecttrsf"
8556 || anArg == "-objectransformation"
8557 || anArg == "-objtransformation"
8558 || anArg == "-objtrsf"
8559 || anArg == "-object"
8562 if (++anArgIter >= theArgNb)
8564 std::cout << "Syntax error at " << anArg << ".\n";
8568 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
8569 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
8570 Handle(AIS_InteractiveObject) anObject;
8571 if (!aMapOfAIS.Find2 (anObjName, anObject))
8573 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
8577 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
8578 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
8579 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
8580 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
8581 Standard_Boolean isTrsfSet = Standard_False;
8582 Standard_Integer aTrsfArgIter = anArgIter + 1;
8583 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
8585 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
8586 aTrsfArg.LowerCase();
8587 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
8588 if (aTrsfArg.StartsWith ("-rotation")
8589 || aTrsfArg.StartsWith ("-rot"))
8591 isTrsfSet = Standard_True;
8592 if (aTrsfArgIter + 4 >= theArgNb
8593 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
8595 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8600 else if (aTrsfArg.StartsWith ("-location")
8601 || aTrsfArg.StartsWith ("-loc"))
8603 isTrsfSet = Standard_True;
8604 if (aTrsfArgIter + 3 >= theArgNb
8605 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
8607 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8612 else if (aTrsfArg.StartsWith ("-scale"))
8614 isTrsfSet = Standard_True;
8615 if (++aTrsfArgIter >= theArgNb)
8617 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8621 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
8622 if (!aScaleStr.IsRealValue())
8624 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8627 aScales[anIndex] = aScaleStr.RealValue();
8631 anArgIter = aTrsfArgIter - 1;
8637 std::cout << "Syntax error at " << anArg << ".\n";
8640 else if (aTrsfArgIter >= theArgNb)
8642 anArgIter = theArgNb;
8645 aTrsfs[0].SetRotation (aRotQuats[0]);
8646 aTrsfs[1].SetRotation (aRotQuats[1]);
8647 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
8648 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
8649 aTrsfs[0].SetScaleFactor (aScales[0]);
8650 aTrsfs[1].SetScaleFactor (aScales[1]);
8652 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
8653 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
8655 else if (anArg == "-viewtrsf"
8656 || anArg == "-view")
8658 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
8659 if (aCamAnimation.IsNull())
8661 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
8662 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
8665 Handle(Graphic3d_Camera) aCams[2] =
8667 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
8668 new Graphic3d_Camera (aCamAnimation->View()->Camera())
8671 Standard_Boolean isTrsfSet = Standard_False;
8672 Standard_Integer aViewArgIter = anArgIter + 1;
8673 for (; aViewArgIter < theArgNb; ++aViewArgIter)
8675 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
8676 aViewArg.LowerCase();
8677 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
8678 if (aViewArg.StartsWith ("-scale"))
8680 isTrsfSet = Standard_True;
8681 if (++aViewArgIter >= theArgNb)
8683 std::cout << "Syntax error at " << anArg << ".\n";
8687 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
8688 if (!aScaleStr.IsRealValue())
8690 std::cout << "Syntax error at " << aViewArg << ".\n";
8693 Standard_Real aScale = aScaleStr.RealValue();
8694 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
8695 aCams[anIndex]->SetScale (aScale);
8697 else if (aViewArg.StartsWith ("-eye")
8698 || aViewArg.StartsWith ("-center")
8699 || aViewArg.StartsWith ("-at")
8700 || aViewArg.StartsWith ("-up"))
8702 isTrsfSet = Standard_True;
8704 if (aViewArgIter + 3 >= theArgNb
8705 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
8707 std::cout << "Syntax error at " << aViewArg << ".\n";
8712 if (aViewArg.StartsWith ("-eye"))
8714 aCams[anIndex]->SetEye (anXYZ);
8716 else if (aViewArg.StartsWith ("-center")
8717 || aViewArg.StartsWith ("-at"))
8719 aCams[anIndex]->SetCenter (anXYZ);
8721 else if (aViewArg.StartsWith ("-up"))
8723 aCams[anIndex]->SetUp (anXYZ);
8728 anArgIter = aViewArgIter - 1;
8734 std::cout << "Syntax error at " << anArg << ".\n";
8737 else if (aViewArgIter >= theArgNb)
8739 anArgIter = theArgNb;
8742 aCamAnimation->SetCameraStart(aCams[0]);
8743 aCamAnimation->SetCameraEnd (aCams[1]);
8747 std::cout << "Syntax error at " << anArg << ".\n";
8752 if (!toPlay && aRecFile.IsEmpty())
8757 // Start animation timeline and process frame updating.
8758 TheIsAnimating = Standard_True;
8759 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
8760 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
8761 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
8764 aView->Camera()->Copy (aCameraBack);
8767 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
8768 if (aRecParams.FpsNum <= 0)
8770 while (!anAnimation->IsStopped())
8772 aCameraBack->Copy (aView->Camera());
8773 const Standard_Real aPts = anAnimation->UpdateTimer();
8776 aView->Camera()->Copy (aCameraBack);
8779 if (aPts >= anUpperPts)
8781 anAnimation->Pause();
8785 if (aView->IsInvalidated())
8791 aView->RedrawImmediate();
8796 // handle user events
8797 theDI.Eval ("after 1 set waiter 1");
8798 theDI.Eval ("vwait waiter");
8800 if (!TheIsAnimating)
8802 anAnimation->Pause();
8808 if (aView->IsInvalidated())
8814 aView->RedrawImmediate();
8819 OSD_Timer aPerfTimer;
8822 Handle(Image_VideoRecorder) aRecorder;
8823 ImageFlipper aFlipper;
8824 Handle(Draw_ProgressIndicator) aProgress;
8825 if (!aRecFile.IsEmpty())
8827 if (aRecParams.Width <= 0
8828 || aRecParams.Height <= 0)
8830 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
8833 aRecorder = new Image_VideoRecorder();
8834 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
8836 std::cout << "Error: failed to open video file for recording\n";
8840 aProgress = new Draw_ProgressIndicator (theDI, 1);
8843 // Manage frame-rated animation here
8844 Standard_Real aPts = aPlayStartTime;
8845 int64_t aNbFrames = 0;
8846 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
8847 Standard_Integer aSecondsProgress = 0;
8848 for (; aPts <= anUpperPts && aPSentry.More();)
8850 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
8851 aPts = aPlayStartTime + aRecPts;
8853 if (!anAnimation->Update (aPts))
8858 if (!aRecorder.IsNull())
8860 V3d_ImageDumpOptions aDumpParams;
8861 aDumpParams.Width = aRecParams.Width;
8862 aDumpParams.Height = aRecParams.Height;
8863 aDumpParams.BufferType = Graphic3d_BT_RGBA;
8864 aDumpParams.StereoOptions = V3d_SDO_MONO;
8865 aDumpParams.ToAdjustAspect = Standard_True;
8866 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
8868 std::cout << "Error: view dump is failed!\n";
8871 aFlipper.FlipY (aRecorder->ChangeFrame());
8872 if (!aRecorder->PushFrame())
8882 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
8890 anAnimation->Stop();
8891 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
8892 theDI << "Average FPS: " << aRecFps << "\n"
8893 << "Nb. Frames: " << Standard_Real(aNbFrames);
8898 aView->SetImmediateUpdate (wasImmediateUpdate);
8899 TheIsAnimating = Standard_False;
8904 //=======================================================================
8905 //function : VChangeSelected
8906 //purpose : Adds the shape to selection or remove one from it
8907 //=======================================================================
8908 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
8909 Standard_Integer argc,
8914 di<<"Usage : " << argv[0] << " shape \n";
8918 TCollection_AsciiString aName(argv[1]);
8919 Handle(AIS_InteractiveObject) anAISObject;
8920 if (!GetMapOfAIS().Find2 (aName, anAISObject)
8921 || anAISObject.IsNull())
8923 di<<"Use 'vdisplay' before";
8927 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
8931 //=======================================================================
8932 //function : VNbSelected
8933 //purpose : Returns number of selected objects
8934 //=======================================================================
8935 static Standard_Integer VNbSelected (Draw_Interpretor& di,
8936 Standard_Integer argc,
8941 di << "Usage : " << argv[0] << "\n";
8944 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8945 if(aContext.IsNull())
8947 di << "use 'vinit' command before " << argv[0] << "\n";
8950 di << aContext->NbSelected() << "\n";
8954 //=======================================================================
8955 //function : VPurgeDisplay
8956 //purpose : Switches altialiasing on or off
8957 //=======================================================================
8958 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
8959 Standard_Integer argc,
8964 di << "Usage : " << argv[0] << "\n";
8967 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8968 if (aContext.IsNull())
8970 di << "use 'vinit' command before " << argv[0] << "\n";
8974 di << aContext->PurgeDisplay() << "\n";
8978 //=======================================================================
8979 //function : VSetViewSize
8981 //=======================================================================
8982 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
8983 Standard_Integer argc,
8986 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8987 if(aContext.IsNull())
8989 di << "use 'vinit' command before " << argv[0] << "\n";
8994 di<<"Usage : " << argv[0] << " Size\n";
8997 Standard_Real aSize = Draw::Atof (argv[1]);
9000 di<<"Bad Size value : " << aSize << "\n";
9004 Handle(V3d_View) aView = ViewerTest::CurrentView();
9005 aView->SetSize(aSize);
9009 //=======================================================================
9010 //function : VMoveView
9012 //=======================================================================
9013 static Standard_Integer VMoveView (Draw_Interpretor& di,
9014 Standard_Integer argc,
9017 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9018 if(aContext.IsNull())
9020 di << "use 'vinit' command before " << argv[0] << "\n";
9023 if(argc < 4 || argc > 5)
9025 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
9028 Standard_Real Dx = Draw::Atof (argv[1]);
9029 Standard_Real Dy = Draw::Atof (argv[2]);
9030 Standard_Real Dz = Draw::Atof (argv[3]);
9031 Standard_Boolean aStart = Standard_True;
9034 aStart = (Draw::Atoi (argv[4]) > 0);
9037 Handle(V3d_View) aView = ViewerTest::CurrentView();
9038 aView->Move(Dx,Dy,Dz,aStart);
9042 //=======================================================================
9043 //function : VTranslateView
9045 //=======================================================================
9046 static Standard_Integer VTranslateView (Draw_Interpretor& di,
9047 Standard_Integer argc,
9050 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9051 if(aContext.IsNull())
9053 di << "use 'vinit' command before " << argv[0] << "\n";
9056 if(argc < 4 || argc > 5)
9058 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
9061 Standard_Real Dx = Draw::Atof (argv[1]);
9062 Standard_Real Dy = Draw::Atof (argv[2]);
9063 Standard_Real Dz = Draw::Atof (argv[3]);
9064 Standard_Boolean aStart = Standard_True;
9067 aStart = (Draw::Atoi (argv[4]) > 0);
9070 Handle(V3d_View) aView = ViewerTest::CurrentView();
9071 aView->Translate(Dx,Dy,Dz,aStart);
9075 //=======================================================================
9076 //function : VTurnView
9078 //=======================================================================
9079 static Standard_Integer VTurnView (Draw_Interpretor& di,
9080 Standard_Integer argc,
9083 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9084 if(aContext.IsNull()) {
9085 di << "use 'vinit' command before " << argv[0] << "\n";
9088 if(argc < 4 || argc > 5){
9089 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
9092 Standard_Real Ax = Draw::Atof (argv[1]);
9093 Standard_Real Ay = Draw::Atof (argv[2]);
9094 Standard_Real Az = Draw::Atof (argv[3]);
9095 Standard_Boolean aStart = Standard_True;
9098 aStart = (Draw::Atoi (argv[4]) > 0);
9101 Handle(V3d_View) aView = ViewerTest::CurrentView();
9102 aView->Turn(Ax,Ay,Az,aStart);
9106 //==============================================================================
9107 //function : VTextureEnv
9108 //purpose : ENables or disables environment mapping
9109 //==============================================================================
9110 class OCC_TextureEnv : public Graphic3d_TextureEnv
9113 OCC_TextureEnv(const Standard_CString FileName);
9114 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
9115 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
9116 const Standard_Boolean theModulateFlag,
9117 const Graphic3d_TypeOfTextureFilter theFilter,
9118 const Standard_ShortReal theXScale,
9119 const Standard_ShortReal theYScale,
9120 const Standard_ShortReal theXShift,
9121 const Standard_ShortReal theYShift,
9122 const Standard_ShortReal theAngle);
9123 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
9125 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
9127 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
9128 : Graphic3d_TextureEnv(theFileName)
9132 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
9133 : Graphic3d_TextureEnv(theTexId)
9137 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
9138 const Standard_Boolean theModulateFlag,
9139 const Graphic3d_TypeOfTextureFilter theFilter,
9140 const Standard_ShortReal theXScale,
9141 const Standard_ShortReal theYScale,
9142 const Standard_ShortReal theXShift,
9143 const Standard_ShortReal theYShift,
9144 const Standard_ShortReal theAngle)
9146 myParams->SetRepeat (theRepeatFlag);
9147 myParams->SetModulate (theModulateFlag);
9148 myParams->SetFilter (theFilter);
9149 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
9150 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
9151 myParams->SetRotation (theAngle);
9154 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
9156 // get the active view
9157 Handle(V3d_View) aView = ViewerTest::CurrentView();
9160 std::cerr << "No active view. Please call vinit.\n";
9164 // Checking the input arguments
9165 Standard_Boolean anEnableFlag = Standard_False;
9166 Standard_Boolean isOk = theArgNb >= 2;
9169 TCollection_AsciiString anEnableOpt(theArgVec[1]);
9170 anEnableFlag = anEnableOpt.IsEqual("on");
9171 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
9175 isOk = (theArgNb == 3 || theArgNb == 11);
9178 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9179 isOk = (!aTextureOpt.IsIntegerValue() ||
9180 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
9182 if (isOk && theArgNb == 11)
9184 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
9185 aModulateOpt(theArgVec[4]),
9186 aFilterOpt (theArgVec[5]),
9187 aSScaleOpt (theArgVec[6]),
9188 aTScaleOpt (theArgVec[7]),
9189 aSTransOpt (theArgVec[8]),
9190 aTTransOpt (theArgVec[9]),
9191 anAngleOpt (theArgVec[10]);
9192 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
9193 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
9194 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
9195 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
9196 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
9197 anAngleOpt.IsRealValue());
9204 std::cerr << "Usage :" << std::endl;
9205 std::cerr << theArgVec[0] << " off" << std::endl;
9206 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;
9212 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9213 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
9214 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
9215 new OCC_TextureEnv(theArgVec[2]);
9219 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
9220 aTexEnv->SetTextureParameters(
9221 aRepeatOpt. IsEqual("repeat"),
9222 aModulateOpt.IsEqual("modulate"),
9223 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
9224 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
9225 Graphic3d_TOTF_TRILINEAR,
9226 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
9227 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
9228 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
9229 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
9230 (Standard_ShortReal)Draw::Atof(theArgVec[10])
9233 aView->SetTextureEnv(aTexEnv);
9235 else // Disabling environment mapping
9237 Handle(Graphic3d_TextureEnv) aTexture;
9238 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
9247 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
9249 //! Remove registered clipping plane from all views and objects.
9250 static void removePlane (MapOfPlanes& theRegPlanes,
9251 const TCollection_AsciiString& theName)
9253 Handle(Graphic3d_ClipPlane) aClipPlane;
9254 if (!theRegPlanes.Find (theName, aClipPlane))
9256 std::cout << "Warning: no such plane.\n";
9260 theRegPlanes.UnBind (theName);
9261 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
9262 anIObjIt.More(); anIObjIt.Next())
9264 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
9265 aPrs->RemoveClipPlane (aClipPlane);
9268 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
9269 aViewIt.More(); aViewIt.Next())
9271 const Handle(V3d_View)& aView = aViewIt.Key2();
9272 aView->RemoveClipPlane(aClipPlane);
9275 ViewerTest::RedrawAllViews();
9279 //===============================================================================================
9280 //function : VClipPlane
9282 //===============================================================================================
9283 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9285 // use short-cut for created clip planes map of created (or "registered by name") clip planes
9286 static MapOfPlanes aRegPlanes;
9290 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
9292 theDi << aPlaneIter.Key() << " ";
9297 TCollection_AsciiString aCommand (theArgVec[1]);
9298 aCommand.LowerCase();
9299 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
9300 if (anActiveView.IsNull())
9302 std::cout << "Error: no active view.\n";
9306 // print maximum number of planes for current viewer
9307 if (aCommand == "-maxplanes"
9308 || aCommand == "maxplanes")
9310 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
9311 << " plane slots provided by driver.\n";
9315 // create / delete plane instance
9316 if (aCommand == "-create"
9317 || aCommand == "create"
9318 || aCommand == "-delete"
9319 || aCommand == "delete"
9320 || aCommand == "-clone"
9321 || aCommand == "clone")
9325 std::cout << "Syntax error: plane name is required.\n";
9329 Standard_Boolean toCreate = aCommand == "-create"
9330 || aCommand == "create";
9331 Standard_Boolean toClone = aCommand == "-clone"
9332 || aCommand == "clone";
9333 Standard_Boolean toDelete = aCommand == "-delete"
9334 || aCommand == "delete";
9335 TCollection_AsciiString aPlane (theArgVec[2]);
9339 if (aRegPlanes.IsBound (aPlane))
9341 std::cout << "Warning: existing plane has been overridden.\n";
9346 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9350 else if (toClone) // toClone
9352 if (!aRegPlanes.IsBound (aPlane))
9354 std::cout << "Error: no such plane.\n";
9357 else if (theArgsNb < 4)
9359 std::cout << "Syntax error: enter name for new plane.\n";
9363 TCollection_AsciiString aClone (theArgVec[3]);
9364 if (aRegPlanes.IsBound (aClone))
9366 std::cout << "Error: plane name is in use.\n";
9370 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
9372 aRegPlanes.Bind (aClone, aClipPlane->Clone());
9382 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
9384 aPlane = aPlaneIter.Key();
9385 removePlane (aRegPlanes, aPlane);
9386 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
9391 removePlane (aRegPlanes, aPlane);
9397 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9402 // set / unset plane command
9403 if (aCommand == "set"
9404 || aCommand == "unset")
9408 std::cout << "Syntax error: need more arguments.\n";
9412 // redirect to new syntax
9413 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
9414 anArgVec.SetValue (1, theArgVec[0]);
9415 anArgVec.SetValue (2, theArgVec[2]);
9416 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
9417 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
9419 anArgVec.SetValue (anIt, theArgVec[anIt]);
9422 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
9425 // change plane command
9426 TCollection_AsciiString aPlaneName;
9427 Handle(Graphic3d_ClipPlane) aClipPlane;
9428 Standard_Integer anArgIter = 0;
9429 if (aCommand == "-change"
9430 || aCommand == "change")
9432 // old syntax support
9435 std::cout << "Syntax error: need more arguments.\n";
9440 aPlaneName = theArgVec[2];
9441 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
9443 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
9447 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
9450 aPlaneName = theArgVec[1];
9455 aPlaneName = theArgVec[1];
9456 aClipPlane = new Graphic3d_ClipPlane();
9457 aRegPlanes.Bind (aPlaneName, aClipPlane);
9458 theDi << "Created new plane " << aPlaneName << ".\n";
9461 if (theArgsNb - anArgIter < 1)
9463 std::cout << "Syntax error: need more arguments.\n";
9467 for (; anArgIter < theArgsNb; ++anArgIter)
9469 const char** aChangeArgs = theArgVec + anArgIter;
9470 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
9471 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
9472 aChangeArg.LowerCase();
9474 Standard_Boolean toEnable = Standard_True;
9475 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
9477 aClipPlane->SetOn (toEnable);
9479 else if (aChangeArg.StartsWith ("-equation")
9480 || aChangeArg.StartsWith ("equation"))
9482 if (aNbChangeArgs < 5)
9484 std::cout << "Syntax error: need more arguments.\n";
9488 Standard_Integer aSubIndex = 1;
9489 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
9490 if (aPrefixLen < aChangeArg.Length())
9492 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
9493 if (!aSubStr.IsIntegerValue()
9494 || aSubStr.IntegerValue() <= 0)
9496 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9499 aSubIndex = aSubStr.IntegerValue();
9502 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
9503 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
9504 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
9505 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
9506 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9507 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
9509 if (aSubPln->ChainNextPlane().IsNull())
9511 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9513 aSubPln = aSubPln->ChainNextPlane();
9515 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9516 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
9519 else if ((aChangeArg == "-boxinterior"
9520 || aChangeArg == "-boxint"
9521 || aChangeArg == "-box")
9522 && aNbChangeArgs >= 7)
9524 Graphic3d_BndBox3d aBndBox;
9525 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
9526 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
9529 Standard_Integer aNbSubPlanes = 6;
9530 const Graphic3d_Vec3d aDirArray[6] =
9532 Graphic3d_Vec3d (-1, 0, 0),
9533 Graphic3d_Vec3d ( 1, 0, 0),
9534 Graphic3d_Vec3d ( 0,-1, 0),
9535 Graphic3d_Vec3d ( 0, 1, 0),
9536 Graphic3d_Vec3d ( 0, 0,-1),
9537 Graphic3d_Vec3d ( 0, 0, 1),
9539 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9540 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
9542 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
9543 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
9544 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
9545 if (aSubPlaneIter + 1 == aNbSubPlanes)
9547 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9551 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9553 aSubPln = aSubPln->ChainNextPlane();
9556 else if (aChangeArg == "-capping"
9557 || aChangeArg == "capping")
9559 if (aNbChangeArgs < 2)
9561 std::cout << "Syntax error: need more arguments.\n";
9565 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9567 aClipPlane->SetCapping (toEnable);
9572 // just skip otherwise (old syntax)
9575 else if (aChangeArg == "-useobjectmaterial"
9576 || aChangeArg == "-useobjectmat"
9577 || aChangeArg == "-useobjmat"
9578 || aChangeArg == "-useobjmaterial")
9580 if (aNbChangeArgs < 2)
9582 std::cout << "Syntax error: need more arguments.\n";
9586 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9588 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
9592 else if (aChangeArg == "-useobjecttexture"
9593 || aChangeArg == "-useobjecttex"
9594 || aChangeArg == "-useobjtexture"
9595 || aChangeArg == "-useobjtex")
9597 if (aNbChangeArgs < 2)
9599 std::cout << "Syntax error: need more arguments.\n";
9603 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9605 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
9609 else if (aChangeArg == "-useobjectshader"
9610 || aChangeArg == "-useobjshader")
9612 if (aNbChangeArgs < 2)
9614 std::cout << "Syntax error: need more arguments.\n";
9618 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9620 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
9624 else if (aChangeArg == "-color"
9625 || aChangeArg == "color")
9627 Quantity_Color aColor;
9628 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
9633 std::cout << "Syntax error: need more arguments.\n";
9636 aClipPlane->SetCappingColor (aColor);
9637 anArgIter += aNbParsed;
9639 else if (aNbChangeArgs >= 1
9640 && (aChangeArg == "-material"
9641 || aChangeArg == "material"))
9644 Graphic3d_NameOfMaterial aMatName;
9645 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeArgs[1], aMatName))
9647 std::cout << "Syntax error: unknown material '" << aChangeArgs[1] << "'.\n";
9650 aClipPlane->SetCappingMaterial (aMatName);
9652 else if ((aChangeArg == "-transparency"
9653 || aChangeArg == "-transp")
9654 && aNbChangeArgs >= 2)
9656 TCollection_AsciiString aValStr (aChangeArgs[1]);
9657 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
9658 if (aValStr.IsRealValue())
9660 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
9661 aMat.SetTransparency ((float )aValStr.RealValue());
9662 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
9663 aClipPlane->SetCappingMaterial (aMat);
9667 aValStr.LowerCase();
9668 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
9669 if (aValStr == "opaque")
9671 aMode = Graphic3d_AlphaMode_Opaque;
9673 else if (aValStr == "mask")
9675 aMode = Graphic3d_AlphaMode_Mask;
9677 else if (aValStr == "blend")
9679 aMode = Graphic3d_AlphaMode_Blend;
9681 else if (aValStr == "blendauto")
9683 aMode = Graphic3d_AlphaMode_BlendAuto;
9687 std::cout << "Syntax error at '" << aValStr << "'\n";
9690 anAspect->SetAlphaMode (aMode);
9691 aClipPlane->SetCappingAspect (anAspect);
9695 else if (aChangeArg == "-texname"
9696 || aChangeArg == "texname")
9698 if (aNbChangeArgs < 2)
9700 std::cout << "Syntax error: need more arguments.\n";
9704 TCollection_AsciiString aTextureName (aChangeArgs[1]);
9705 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
9706 if (!aTexture->IsDone())
9708 aClipPlane->SetCappingTexture (NULL);
9712 aTexture->EnableModulate();
9713 aTexture->EnableRepeat();
9714 aClipPlane->SetCappingTexture (aTexture);
9718 else if (aChangeArg == "-texscale"
9719 || aChangeArg == "texscale")
9721 if (aClipPlane->CappingTexture().IsNull())
9723 std::cout << "Error: no texture is set.\n";
9727 if (aNbChangeArgs < 3)
9729 std::cout << "Syntax error: need more arguments.\n";
9733 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9734 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9735 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
9738 else if (aChangeArg == "-texorigin"
9739 || aChangeArg == "texorigin") // texture origin
9741 if (aClipPlane->CappingTexture().IsNull())
9743 std::cout << "Error: no texture is set.\n";
9747 if (aNbChangeArgs < 3)
9749 std::cout << "Syntax error: need more arguments.\n";
9753 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9754 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9756 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
9759 else if (aChangeArg == "-texrotate"
9760 || aChangeArg == "texrotate") // texture rotation
9762 if (aClipPlane->CappingTexture().IsNull())
9764 std::cout << "Error: no texture is set.\n";
9768 if (aNbChangeArgs < 2)
9770 std::cout << "Syntax error: need more arguments.\n";
9774 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9775 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
9778 else if (aChangeArg == "-hatch"
9779 || aChangeArg == "hatch")
9781 if (aNbChangeArgs < 2)
9783 std::cout << "Syntax error: need more arguments.\n";
9787 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
9788 aHatchStr.LowerCase();
9789 if (aHatchStr == "on")
9791 aClipPlane->SetCappingHatchOn();
9793 else if (aHatchStr == "off")
9795 aClipPlane->SetCappingHatchOff();
9799 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
9803 else if (aChangeArg == "-delete"
9804 || aChangeArg == "delete")
9806 removePlane (aRegPlanes, aPlaneName);
9809 else if (aChangeArg == "-set"
9810 || aChangeArg == "-unset"
9811 || aChangeArg == "-setoverrideglobal")
9813 // set / unset plane command
9814 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
9815 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
9816 Standard_Integer anIt = 1;
9817 for (; anIt < aNbChangeArgs; ++anIt)
9819 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
9820 if (anEntityName.IsEmpty()
9821 || anEntityName.Value (1) == '-')
9825 else if (!toOverrideGlobal
9826 && ViewerTest_myViews.IsBound1 (anEntityName))
9828 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
9831 aView->AddClipPlane (aClipPlane);
9835 aView->RemoveClipPlane (aClipPlane);
9839 else if (GetMapOfAIS().IsBound2 (anEntityName))
9841 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
9844 aIObj->AddClipPlane (aClipPlane);
9848 aIObj->RemoveClipPlane (aClipPlane);
9850 if (!aIObj->ClipPlanes().IsNull())
9852 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
9857 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
9864 // apply to active view
9867 anActiveView->AddClipPlane (aClipPlane);
9871 anActiveView->RemoveClipPlane (aClipPlane);
9876 anArgIter = anArgIter + anIt - 1;
9881 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9886 ViewerTest::RedrawAllViews();
9890 //===============================================================================================
9891 //function : VZRange
9893 //===============================================================================================
9894 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9896 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9898 if (aCurrentView.IsNull())
9900 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9904 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
9908 theDi << "ZNear: " << aCamera->ZNear() << "\n";
9909 theDi << "ZFar: " << aCamera->ZFar() << "\n";
9915 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
9916 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
9918 if (aNewZNear >= aNewZFar)
9920 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
9924 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
9926 std::cout << theArgVec[0] << ": invalid arguments: ";
9927 std::cout << "znear, zfar should be positive for perspective camera.\n";
9931 aCamera->SetZRange (aNewZNear, aNewZFar);
9935 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9939 aCurrentView->Redraw();
9944 //===============================================================================================
9945 //function : VAutoZFit
9947 //===============================================================================================
9948 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9950 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9952 if (aCurrentView.IsNull())
9954 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9958 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
9962 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9968 theDi << "Auto z-fit mode: \n"
9969 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
9970 << "Scale: " << aScale << "\n";
9974 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
9978 aScale = Draw::Atoi (theArgVec[2]);
9981 aCurrentView->SetAutoZFitMode (isOn, aScale);
9982 aCurrentView->AutoZFit();
9983 aCurrentView->Redraw();
9988 //! Auxiliary function to print projection type
9989 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
9991 switch (theProjType)
9993 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
9994 case Graphic3d_Camera::Projection_Perspective: return "perspective";
9995 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
9996 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
9997 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
10002 //===============================================================================================
10003 //function : VCamera
10005 //===============================================================================================
10006 static int VCamera (Draw_Interpretor& theDI,
10007 Standard_Integer theArgsNb,
10008 const char** theArgVec)
10010 Handle(V3d_View) aView = ViewerTest::CurrentView();
10011 if (aView.IsNull())
10013 std::cout << "Error: no active view.\n";
10017 Handle(Graphic3d_Camera) aCamera = aView->Camera();
10020 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
10021 theDI << "FOVy: " << aCamera->FOVy() << "\n";
10022 theDI << "Distance: " << aCamera->Distance() << "\n";
10023 theDI << "IOD: " << aCamera->IOD() << "\n";
10024 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
10025 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
10026 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
10030 TCollection_AsciiString aPrsName;
10031 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10033 Standard_CString anArg = theArgVec[anArgIter];
10034 TCollection_AsciiString anArgCase (anArg);
10035 anArgCase.LowerCase();
10036 if (anArgCase == "-proj"
10037 || anArgCase == "-projection"
10038 || anArgCase == "-projtype"
10039 || anArgCase == "-projectiontype")
10041 theDI << projTypeName (aCamera->ProjectionType()) << " ";
10043 else if (anArgCase == "-ortho"
10044 || anArgCase == "-orthographic")
10046 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
10048 else if (anArgCase == "-persp"
10049 || anArgCase == "-perspective"
10050 || anArgCase == "-perspmono"
10051 || anArgCase == "-perspectivemono"
10052 || anArgCase == "-mono")
10054 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10056 else if (anArgCase == "-stereo"
10057 || anArgCase == "-stereoscopic"
10058 || anArgCase == "-perspstereo"
10059 || anArgCase == "-perspectivestereo")
10061 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10063 else if (anArgCase == "-left"
10064 || anArgCase == "-lefteye"
10065 || anArgCase == "-monoleft"
10066 || anArgCase == "-monolefteye"
10067 || anArgCase == "-perpsleft"
10068 || anArgCase == "-perpslefteye")
10070 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
10072 else if (anArgCase == "-right"
10073 || anArgCase == "-righteye"
10074 || anArgCase == "-monoright"
10075 || anArgCase == "-monorighteye"
10076 || anArgCase == "-perpsright")
10078 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
10080 else if (anArgCase == "-dist"
10081 || anArgCase == "-distance")
10083 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10084 if (anArgValue != NULL
10085 && *anArgValue != '-')
10088 aCamera->SetDistance (Draw::Atof (anArgValue));
10091 theDI << aCamera->Distance() << " ";
10093 else if (anArgCase == "-iod")
10095 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10096 if (anArgValue != NULL
10097 && *anArgValue != '-')
10100 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
10103 theDI << aCamera->IOD() << " ";
10105 else if (anArgCase == "-iodtype")
10107 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10108 TCollection_AsciiString anValueCase (anArgValue);
10109 anValueCase.LowerCase();
10110 if (anValueCase == "abs"
10111 || anValueCase == "absolute")
10114 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
10117 else if (anValueCase == "rel"
10118 || anValueCase == "relative")
10121 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
10124 else if (*anArgValue != '-')
10126 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
10129 switch (aCamera->GetIODType())
10131 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
10132 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
10135 else if (anArgCase == "-zfocus")
10137 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10138 if (anArgValue != NULL
10139 && *anArgValue != '-')
10142 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
10145 theDI << aCamera->ZFocus() << " ";
10147 else if (anArgCase == "-zfocustype")
10149 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10150 TCollection_AsciiString anValueCase (anArgValue);
10151 anValueCase.LowerCase();
10152 if (anValueCase == "abs"
10153 || anValueCase == "absolute")
10156 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
10159 else if (anValueCase == "rel"
10160 || anValueCase == "relative")
10163 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
10166 else if (*anArgValue != '-')
10168 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
10171 switch (aCamera->ZFocusType())
10173 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
10174 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
10177 else if (anArgCase == "-fov"
10178 || anArgCase == "-fovy")
10180 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10181 if (anArgValue != NULL
10182 && *anArgValue != '-')
10185 aCamera->SetFOVy (Draw::Atof (anArgValue));
10188 theDI << aCamera->FOVy() << " ";
10190 else if (aPrsName.IsEmpty()
10191 && !anArgCase.StartsWith ("-"))
10197 std::cout << "Error: unknown argument '" << anArg << "'\n";
10202 if (aPrsName.IsEmpty()
10209 if (!aPrsName.IsEmpty())
10211 Handle(AIS_CameraFrustum) aCameraFrustum;
10212 if (GetMapOfAIS().IsBound2 (aPrsName))
10214 // find existing object
10215 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
10216 if (aCameraFrustum.IsNull())
10218 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
10223 if (aCameraFrustum.IsNull())
10225 aCameraFrustum = new AIS_CameraFrustum();
10229 // not include displayed object of old camera frustum in the new one.
10230 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
10233 aCameraFrustum->SetCameraFrustum (aView->Camera());
10235 ViewerTest::Display (aPrsName, aCameraFrustum);
10241 //! Parse stereo output mode
10242 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
10243 Graphic3d_StereoMode& theMode)
10245 TCollection_AsciiString aFlag (theArg);
10247 if (aFlag == "quadbuffer")
10249 theMode = Graphic3d_StereoMode_QuadBuffer;
10251 else if (aFlag == "anaglyph")
10253 theMode = Graphic3d_StereoMode_Anaglyph;
10255 else if (aFlag == "row"
10256 || aFlag == "rowinterlaced")
10258 theMode = Graphic3d_StereoMode_RowInterlaced;
10260 else if (aFlag == "col"
10261 || aFlag == "colinterlaced"
10262 || aFlag == "columninterlaced")
10264 theMode = Graphic3d_StereoMode_ColumnInterlaced;
10266 else if (aFlag == "chess"
10267 || aFlag == "chessboard")
10269 theMode = Graphic3d_StereoMode_ChessBoard;
10271 else if (aFlag == "sbs"
10272 || aFlag == "sidebyside")
10274 theMode = Graphic3d_StereoMode_SideBySide;
10276 else if (aFlag == "ou"
10277 || aFlag == "overunder")
10279 theMode = Graphic3d_StereoMode_OverUnder;
10281 else if (aFlag == "pageflip"
10282 || aFlag == "softpageflip")
10284 theMode = Graphic3d_StereoMode_SoftPageFlip;
10288 return Standard_False;
10290 return Standard_True;
10293 //! Parse anaglyph filter
10294 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
10295 Graphic3d_RenderingParams::Anaglyph& theFilter)
10297 TCollection_AsciiString aFlag (theArg);
10299 if (aFlag == "redcyansimple")
10301 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10303 else if (aFlag == "redcyan"
10304 || aFlag == "redcyanoptimized")
10306 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
10308 else if (aFlag == "yellowbluesimple")
10310 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
10312 else if (aFlag == "yellowblue"
10313 || aFlag == "yellowblueoptimized")
10315 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
10317 else if (aFlag == "greenmagenta"
10318 || aFlag == "greenmagentasimple")
10320 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
10324 return Standard_False;
10326 return Standard_True;
10329 //==============================================================================
10330 //function : VStereo
10332 //==============================================================================
10334 static int VStereo (Draw_Interpretor& theDI,
10335 Standard_Integer theArgNb,
10336 const char** theArgVec)
10338 Handle(V3d_View) aView = ViewerTest::CurrentView();
10341 if (aView.IsNull())
10343 std::cout << "Error: no active viewer!\n";
10347 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
10348 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
10351 TCollection_AsciiString aMode;
10352 switch (aView->RenderingParams().StereoMode)
10354 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
10355 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
10356 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
10357 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
10358 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
10359 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
10360 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
10361 case Graphic3d_StereoMode_Anaglyph :
10362 aMode = "anaglyph";
10363 switch (aView->RenderingParams().AnaglyphFilter)
10365 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
10366 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
10367 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
10368 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
10369 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
10374 theDI << "Mode " << aMode << "\n";
10379 Handle(Graphic3d_Camera) aCamera;
10380 Graphic3d_RenderingParams* aParams = NULL;
10381 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
10382 if (!aView.IsNull())
10384 aParams = &aView->ChangeRenderingParams();
10385 aMode = aParams->StereoMode;
10386 aCamera = aView->Camera();
10389 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10390 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10392 Standard_CString anArg = theArgVec[anArgIter];
10393 TCollection_AsciiString aFlag (anArg);
10395 if (anUpdateTool.parseRedrawMode (aFlag))
10399 else if (aFlag == "0"
10402 if (++anArgIter < theArgNb)
10404 std::cout << "Error: wrong number of arguments!\n";
10408 if (!aCamera.IsNull()
10409 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
10411 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10413 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
10416 else if (aFlag == "1"
10419 if (++anArgIter < theArgNb)
10421 std::cout << "Error: wrong number of arguments!\n";
10425 if (!aCamera.IsNull())
10427 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10429 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10432 else if (aFlag == "-reverse"
10433 || aFlag == "-reversed"
10434 || aFlag == "-swap")
10436 Standard_Boolean toEnable = Standard_True;
10437 if (++anArgIter < theArgNb
10438 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10442 aParams->ToReverseStereo = toEnable;
10444 else if (aFlag == "-noreverse"
10445 || aFlag == "-noswap")
10447 Standard_Boolean toDisable = Standard_True;
10448 if (++anArgIter < theArgNb
10449 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
10453 aParams->ToReverseStereo = !toDisable;
10455 else if (aFlag == "-mode"
10456 || aFlag == "-stereomode")
10458 if (++anArgIter >= theArgNb
10459 || !parseStereoMode (theArgVec[anArgIter], aMode))
10461 std::cout << "Error: syntax error at '" << anArg << "'\n";
10465 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10467 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10470 else if (aFlag == "-anaglyph"
10471 || aFlag == "-anaglyphfilter")
10473 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10474 if (++anArgIter >= theArgNb
10475 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
10477 std::cout << "Error: syntax error at '" << anArg << "'\n";
10481 aMode = Graphic3d_StereoMode_Anaglyph;
10482 aParams->AnaglyphFilter = aFilter;
10484 else if (parseStereoMode (anArg, aMode)) // short syntax
10486 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10488 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10493 std::cout << "Error: syntax error at '" << anArg << "'\n";
10498 if (!aView.IsNull())
10500 aParams->StereoMode = aMode;
10501 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10506 //===============================================================================================
10507 //function : VDefaults
10509 //===============================================================================================
10510 static int VDefaults (Draw_Interpretor& theDi,
10511 Standard_Integer theArgsNb,
10512 const char** theArgVec)
10514 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
10517 std::cout << "Error: no active viewer\n";
10521 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
10524 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
10526 theDi << "DeflType: relative\n"
10527 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
10531 theDi << "DeflType: absolute\n"
10532 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
10534 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
10535 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
10539 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10541 TCollection_AsciiString anArg (theArgVec[anArgIter]);
10543 if (anArg == "-ABSDEFL"
10544 || anArg == "-ABSOLUTEDEFLECTION"
10545 || anArg == "-DEFL"
10546 || anArg == "-DEFLECTION")
10548 if (++anArgIter >= theArgsNb)
10550 std::cout << "Error: wrong syntax at " << anArg << "\n";
10553 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
10554 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
10556 else if (anArg == "-RELDEFL"
10557 || anArg == "-RELATIVEDEFLECTION"
10558 || anArg == "-DEVCOEFF"
10559 || anArg == "-DEVIATIONCOEFF"
10560 || anArg == "-DEVIATIONCOEFFICIENT")
10562 if (++anArgIter >= theArgsNb)
10564 std::cout << "Error: wrong syntax at " << anArg << "\n";
10567 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
10568 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
10570 else if (anArg == "-ANGDEFL"
10571 || anArg == "-ANGULARDEFL"
10572 || anArg == "-ANGULARDEFLECTION")
10574 if (++anArgIter >= theArgsNb)
10576 std::cout << "Error: wrong syntax at " << anArg << "\n";
10579 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
10580 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
10582 else if (anArg == "-AUTOTR"
10583 || anArg == "-AUTOTRIANG"
10584 || anArg == "-AUTOTRIANGULATION")
10587 bool toTurnOn = true;
10588 if (anArgIter >= theArgsNb
10589 || !ViewerTest::ParseOnOff (theArgVec[anArgIter], toTurnOn))
10591 std::cout << "Syntax error at '" << anArg << "'\n";
10594 aDefParams->SetAutoTriangulation (toTurnOn);
10598 std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
10606 //! Auxiliary method
10607 inline void addLight (const Handle(V3d_Light)& theLightNew,
10608 const Graphic3d_ZLayerId theLayer,
10609 const Standard_Boolean theIsGlobal)
10611 if (theLightNew.IsNull())
10616 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10617 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
10619 aViewer->AddLight (theLightNew);
10622 aViewer->SetLightOn (theLightNew);
10626 ViewerTest::CurrentView()->SetLightOn (theLightNew);
10631 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
10632 if (aSettings.Lights().IsNull())
10634 aSettings.SetLights (new Graphic3d_LightSet());
10636 aSettings.Lights()->Add (theLightNew);
10637 aViewer->SetZLayerSettings (theLayer, aSettings);
10641 //! Auxiliary method
10642 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
10644 TCollection_AsciiString anArgNextCase (theArgNext);
10645 anArgNextCase.UpperCase();
10646 if (anArgNextCase.Length() > 5
10647 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
10649 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
10653 return theArgNext.IntegerValue();
10657 //===============================================================================================
10658 //function : VLight
10660 //===============================================================================================
10661 static int VLight (Draw_Interpretor& theDi,
10662 Standard_Integer theArgsNb,
10663 const char** theArgVec)
10665 Handle(V3d_View) aView = ViewerTest::CurrentView();
10666 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10668 || aViewer.IsNull())
10670 std::cerr << "No active viewer!\n";
10674 Standard_Real anXYZ[3] = {};
10675 Standard_Real anAtten[2] = {};
10678 // print lights info
10679 Standard_Integer aLightId = 0;
10680 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
10682 Handle(V3d_Light) aLight = aLightIter.Value();
10683 const Quantity_Color aColor = aLight->Color();
10684 theDi << "Light #" << aLightId
10685 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
10686 << " [" << aLight->GetId() << "]" << "\n";
10687 switch (aLight->Type())
10691 theDi << " Type: Ambient\n";
10692 theDi << " Intensity: " << aLight->Intensity() << "\n";
10695 case V3d_DIRECTIONAL:
10697 theDi << " Type: Directional\n";
10698 theDi << " Intensity: " << aLight->Intensity() << "\n";
10699 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10700 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10701 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10702 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10705 case V3d_POSITIONAL:
10707 theDi << " Type: Positional\n";
10708 theDi << " Intensity: " << aLight->Intensity() << "\n";
10709 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10710 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10711 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10712 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10713 aLight->Attenuation (anAtten[0], anAtten[1]);
10714 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10715 theDi << " Range: " << aLight->Range() << "\n";
10720 theDi << " Type: Spot\n";
10721 theDi << " Intensity: " << aLight->Intensity() << "\n";
10722 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10723 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10724 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10725 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10726 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10727 aLight->Attenuation (anAtten[0], anAtten[1]);
10728 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10729 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
10730 theDi << " Exponent: " << aLight->Concentration() << "\n";
10731 theDi << " Range: " << aLight->Range() << "\n";
10736 theDi << " Type: UNKNOWN\n";
10740 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
10744 Handle(V3d_Light) aLightNew;
10745 Handle(V3d_Light) aLightOld;
10746 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
10747 Standard_Boolean isGlobal = Standard_True;
10748 Standard_Boolean toCreate = Standard_False;
10749 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10750 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
10752 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
10754 TCollection_AsciiString aName, aValue;
10755 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
10756 TCollection_AsciiString anArgCase (anArg);
10757 anArgCase.UpperCase();
10758 if (anUpdateTool.parseRedrawMode (anArg))
10763 if (anArgCase.IsEqual ("NEW")
10764 || anArgCase.IsEqual ("ADD")
10765 || anArgCase.IsEqual ("CREATE")
10766 || anArgCase.IsEqual ("-NEW")
10767 || anArgCase.IsEqual ("-ADD")
10768 || anArgCase.IsEqual ("-CREATE"))
10770 toCreate = Standard_True;
10772 else if (anArgCase.IsEqual ("-LAYER")
10773 || anArgCase.IsEqual ("-ZLAYER"))
10775 if (++anArgIt >= theArgsNb)
10777 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10781 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
10782 aValStr.LowerCase();
10783 if (aValStr == "default"
10784 || aValStr == "def")
10786 aLayer = Graphic3d_ZLayerId_Default;
10788 else if (aValStr == "top")
10790 aLayer = Graphic3d_ZLayerId_Top;
10792 else if (aValStr == "topmost")
10794 aLayer = Graphic3d_ZLayerId_Topmost;
10796 else if (aValStr == "toposd"
10797 || aValStr == "osd")
10799 aLayer = Graphic3d_ZLayerId_TopOSD;
10801 else if (aValStr == "botosd"
10802 || aValStr == "bottom")
10804 aLayer = Graphic3d_ZLayerId_BotOSD;
10806 else if (aValStr.IsIntegerValue())
10808 aLayer = Draw::Atoi (theArgVec[anArgIt]);
10812 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
10816 else if (anArgCase.IsEqual ("GLOB")
10817 || anArgCase.IsEqual ("GLOBAL")
10818 || anArgCase.IsEqual ("-GLOB")
10819 || anArgCase.IsEqual ("-GLOBAL"))
10821 isGlobal = Standard_True;
10823 else if (anArgCase.IsEqual ("LOC")
10824 || anArgCase.IsEqual ("LOCAL")
10825 || anArgCase.IsEqual ("-LOC")
10826 || anArgCase.IsEqual ("-LOCAL"))
10828 isGlobal = Standard_False;
10830 else if (anArgCase.IsEqual ("DEF")
10831 || anArgCase.IsEqual ("DEFAULTS")
10832 || anArgCase.IsEqual ("-DEF")
10833 || anArgCase.IsEqual ("-DEFAULTS"))
10835 toCreate = Standard_False;
10836 aViewer->SetDefaultLights();
10838 else if (anArgCase.IsEqual ("CLR")
10839 || anArgCase.IsEqual ("CLEAR")
10840 || anArgCase.IsEqual ("-CLR")
10841 || anArgCase.IsEqual ("-CLEAR"))
10843 toCreate = Standard_False;
10845 TColStd_SequenceOfInteger aLayers;
10846 aViewer->GetAllZLayers (aLayers);
10847 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10849 if (aLayeriter.Value() == aLayer
10850 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10852 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10853 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10854 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10855 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10862 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10864 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
10866 Handle(V3d_Light) aLight = aLightIter.Value();
10867 aViewer->DelLight (aLight);
10868 aLightIter = aView->ActiveLightIterator();
10872 else if (anArgCase.IsEqual ("AMB")
10873 || anArgCase.IsEqual ("AMBIENT")
10874 || anArgCase.IsEqual ("AMBLIGHT"))
10878 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10882 addLight (aLightNew, aLayer, isGlobal);
10883 toCreate = Standard_False;
10884 aLightNew = new V3d_AmbientLight();
10886 else if (anArgCase.IsEqual ("DIRECTIONAL")
10887 || anArgCase.IsEqual ("DIRLIGHT"))
10891 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10895 addLight (aLightNew, aLayer, isGlobal);
10896 toCreate = Standard_False;
10897 aLightNew = new V3d_DirectionalLight();
10899 else if (anArgCase.IsEqual ("SPOT")
10900 || anArgCase.IsEqual ("SPOTLIGHT"))
10904 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10908 addLight (aLightNew, aLayer, isGlobal);
10909 toCreate = Standard_False;
10910 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
10912 else if (anArgCase.IsEqual ("POSLIGHT")
10913 || anArgCase.IsEqual ("POSITIONAL"))
10917 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10921 addLight (aLightNew, aLayer, isGlobal);
10922 toCreate = Standard_False;
10923 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
10925 else if (anArgCase.IsEqual ("CHANGE")
10926 || anArgCase.IsEqual ("-CHANGE"))
10928 if (++anArgIt >= theArgsNb)
10930 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10934 addLight (aLightNew, aLayer, isGlobal);
10935 aLightNew.Nullify();
10936 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
10937 Standard_Integer aLightIt = 0;
10938 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10940 if (aLightIt == aLightId)
10942 aLightOld = aLightIter.Value();
10947 if (aLightOld.IsNull())
10949 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
10953 else if (anArgCase.IsEqual ("DEL")
10954 || anArgCase.IsEqual ("DELETE")
10955 || anArgCase.IsEqual ("-DEL")
10956 || anArgCase.IsEqual ("-DELETE"))
10958 Handle(V3d_Light) aLightDel;
10959 if (++anArgIt >= theArgsNb)
10961 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10965 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10966 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
10967 Standard_Integer aLightIt = 0;
10968 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10970 aLightDel = aLightIter.Value();
10971 if (aLightIt == aLightDelId)
10976 if (aLightDel.IsNull())
10981 TColStd_SequenceOfInteger aLayers;
10982 aViewer->GetAllZLayers (aLayers);
10983 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10985 if (aLayeriter.Value() == aLayer
10986 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10988 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10989 if (!aSettings.Lights().IsNull())
10991 aSettings.Lights()->Remove (aLightDel);
10992 if (aSettings.Lights()->IsEmpty())
10994 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10997 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10998 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
11005 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
11007 aViewer->DelLight (aLightDel);
11010 else if (anArgCase.IsEqual ("COLOR")
11011 || anArgCase.IsEqual ("COLOUR")
11012 || anArgCase.IsEqual ("-COLOR")
11013 || anArgCase.IsEqual ("-COLOUR"))
11015 if (++anArgIt >= theArgsNb
11016 || aLightCurr.IsNull())
11018 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11022 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
11023 anArgNext.UpperCase();
11024 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
11025 aLightCurr->SetColor (aColor);
11027 else if (anArgCase.IsEqual ("POS")
11028 || anArgCase.IsEqual ("POSITION")
11029 || anArgCase.IsEqual ("-POS")
11030 || anArgCase.IsEqual ("-POSITION"))
11032 if ((anArgIt + 3) >= theArgsNb
11033 || aLightCurr.IsNull()
11034 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11035 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11037 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11041 anXYZ[0] = Atof (theArgVec[++anArgIt]);
11042 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11043 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11044 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
11046 else if (anArgCase.IsEqual ("DIR")
11047 || anArgCase.IsEqual ("DIRECTION")
11048 || anArgCase.IsEqual ("-DIR")
11049 || anArgCase.IsEqual ("-DIRECTION"))
11051 if ((anArgIt + 3) >= theArgsNb
11052 || aLightCurr.IsNull()
11053 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
11054 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11056 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11060 anXYZ[0] = Atof (theArgVec[++anArgIt]);
11061 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11062 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11063 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
11065 else if (anArgCase.IsEqual ("SM")
11066 || anArgCase.IsEqual ("SMOOTHNESS")
11067 || anArgCase.IsEqual ("-SM")
11068 || anArgCase.IsEqual ("-SMOOTHNESS"))
11070 if (++anArgIt >= theArgsNb
11071 || aLightCurr.IsNull())
11073 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11077 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11078 if (Abs (aSmoothness) <= ShortRealEpsilon())
11080 aLightCurr->SetIntensity (1.f);
11082 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
11084 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
11088 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
11089 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
11092 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
11094 aLightCurr->SetSmoothRadius (aSmoothness);
11096 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
11098 aLightCurr->SetSmoothAngle (aSmoothness);
11101 else if (anArgCase.IsEqual ("INT")
11102 || anArgCase.IsEqual ("INTENSITY")
11103 || anArgCase.IsEqual ("-INT")
11104 || anArgCase.IsEqual ("-INTENSITY"))
11106 if (++anArgIt >= theArgsNb
11107 || aLightCurr.IsNull())
11109 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11113 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11114 aLightCurr->SetIntensity (aIntensity);
11116 else if (anArgCase.IsEqual ("ANG")
11117 || anArgCase.IsEqual ("ANGLE")
11118 || anArgCase.IsEqual ("-ANG")
11119 || anArgCase.IsEqual ("-ANGLE"))
11121 if (++anArgIt >= theArgsNb
11122 || aLightCurr.IsNull()
11123 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11125 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11129 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11130 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
11132 else if (anArgCase.IsEqual ("CONSTATTEN")
11133 || anArgCase.IsEqual ("CONSTATTENUATION")
11134 || anArgCase.IsEqual ("-CONSTATTEN")
11135 || anArgCase.IsEqual ("-CONSTATTENUATION"))
11137 if (++anArgIt >= theArgsNb
11138 || aLightCurr.IsNull()
11139 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11140 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11142 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11146 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11147 anAtten[0] = Atof (theArgVec[anArgIt]);
11148 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11150 else if (anArgCase.IsEqual ("LINATTEN")
11151 || anArgCase.IsEqual ("LINEARATTEN")
11152 || anArgCase.IsEqual ("LINEARATTENUATION")
11153 || anArgCase.IsEqual ("-LINATTEN")
11154 || anArgCase.IsEqual ("-LINEARATTEN")
11155 || anArgCase.IsEqual ("-LINEARATTENUATION"))
11157 if (++anArgIt >= theArgsNb
11158 || aLightCurr.IsNull()
11159 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11160 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11162 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11166 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11167 anAtten[1] = Atof (theArgVec[anArgIt]);
11168 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11170 else if (anArgCase.IsEqual ("EXP")
11171 || anArgCase.IsEqual ("EXPONENT")
11172 || anArgCase.IsEqual ("SPOTEXP")
11173 || anArgCase.IsEqual ("SPOTEXPONENT")
11174 || anArgCase.IsEqual ("-EXP")
11175 || anArgCase.IsEqual ("-EXPONENT")
11176 || anArgCase.IsEqual ("-SPOTEXP")
11177 || anArgCase.IsEqual ("-SPOTEXPONENT"))
11179 if (++anArgIt >= theArgsNb
11180 || aLightCurr.IsNull()
11181 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11183 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11187 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
11189 else if (anArgCase.IsEqual("RANGE")
11190 || anArgCase.IsEqual("-RANGE"))
11192 if (++anArgIt >= theArgsNb
11193 || aLightCurr.IsNull()
11194 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT
11195 || aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
11197 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11201 aLightCurr->SetRange ((Standard_ShortReal)Atof (theArgVec[anArgIt]));
11203 else if (anArgCase.IsEqual ("HEAD")
11204 || anArgCase.IsEqual ("HEADLIGHT")
11205 || anArgCase.IsEqual ("-HEAD")
11206 || anArgCase.IsEqual ("-HEADLIGHT"))
11208 if (aLightCurr.IsNull()
11209 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
11211 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11215 Standard_Boolean isHeadLight = Standard_True;
11216 if (anArgIt + 1 < theArgsNb
11217 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
11221 aLightCurr->SetHeadlight (isHeadLight);
11225 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
11229 addLight (aLightNew, aLayer, isGlobal);
11233 //===============================================================================================
11234 //function : VPBREnvironment
11236 //===============================================================================================
11237 static int VPBREnvironment (Draw_Interpretor&,
11238 Standard_Integer theArgsNb,
11239 const char** theArgVec)
11243 std::cerr << "Error: 'vpbrenv' command has only one argument\n";
11247 Handle(V3d_View) aView = ViewerTest::CurrentView();
11248 if (aView.IsNull())
11250 std::cerr << "Error: no active viewer!\n";
11254 TCollection_AsciiString anArg = TCollection_AsciiString (theArgVec[1]);
11257 if (anArg == "-generate"
11258 || anArg == "-gen")
11260 aView->GeneratePBREnvironment (Standard_True);
11262 else if (anArg == "-clear")
11264 aView->ClearPBREnvironment (Standard_True);
11268 std::cerr << "Error: unknown argument [" << theArgVec[1] << "] for 'vpbrenv' command\n";
11275 //! Read Graphic3d_RenderingParams::PerfCounters flag.
11276 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
11277 Standard_Boolean& theToReset,
11278 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
11279 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
11281 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
11282 TCollection_AsciiString aVal = theValue;
11283 Standard_Boolean toReverse = Standard_False;
11284 if (aVal == "none")
11286 theToReset = Standard_True;
11287 return Standard_True;
11289 else if (aVal.StartsWith ("-"))
11291 toReverse = Standard_True;
11292 aVal = aVal.SubString (2, aVal.Length());
11294 else if (aVal.StartsWith ("no"))
11296 toReverse = Standard_True;
11297 aVal = aVal.SubString (3, aVal.Length());
11299 else if (aVal.StartsWith ("+"))
11301 aVal = aVal.SubString (2, aVal.Length());
11305 theToReset = Standard_True;
11309 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11310 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
11311 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
11312 else if (aVal == "structs"
11313 || aVal == "structures"
11314 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
11315 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
11316 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11317 else if (aVal == "tris"
11318 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
11319 else if (aVal == "pnts"
11320 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
11321 else if (aVal == "mem"
11322 || aVal == "gpumem"
11323 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11324 else if (aVal == "skipimmediate"
11325 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
11326 else if (aVal == "frametime"
11327 || aVal == "frametimers"
11328 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11329 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
11330 else if (aVal == "extended"
11331 || aVal == "verbose"
11332 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
11333 else if (aVal == "full"
11334 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
11337 return Standard_False;
11342 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
11346 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
11348 return Standard_True;
11351 //! Read Graphic3d_RenderingParams::PerfCounters flags.
11352 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
11353 Graphic3d_RenderingParams::PerfCounters& theFlags)
11355 TCollection_AsciiString aValue = theValue;
11356 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
11357 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
11358 Standard_Boolean toReset = Standard_False;
11361 Standard_Integer aSplitPos = aValue.Search ("|");
11362 if (aSplitPos <= 0)
11364 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
11366 return Standard_False;
11370 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
11372 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
11373 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
11374 return Standard_True;
11379 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
11380 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
11382 return Standard_False;
11385 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
11389 //=======================================================================
11390 //function : VRenderParams
11391 //purpose : Enables/disables rendering features
11392 //=======================================================================
11394 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
11395 Standard_Integer theArgNb,
11396 const char** theArgVec)
11398 Handle(V3d_View) aView = ViewerTest::CurrentView();
11399 if (aView.IsNull())
11401 std::cerr << "Error: no active viewer!\n";
11405 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
11406 TCollection_AsciiString aCmdName (theArgVec[0]);
11407 aCmdName.LowerCase();
11408 if (aCmdName == "vraytrace")
11412 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
11415 else if (theArgNb == 2)
11417 TCollection_AsciiString aValue (theArgVec[1]);
11418 aValue.LowerCase();
11422 aParams.Method = Graphic3d_RM_RAYTRACING;
11426 else if (aValue == "off"
11429 aParams.Method = Graphic3d_RM_RASTERIZATION;
11435 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
11441 std::cout << "Error: wrong number of arguments\n";
11448 theDI << "renderMode: ";
11449 switch (aParams.Method)
11451 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11452 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
11455 theDI << "transparency: ";
11456 switch (aParams.TransparencyMethod)
11458 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
11459 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
11460 << TCollection_AsciiString (aParams.OitDepthFactor); break;
11463 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
11464 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
11465 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
11466 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
11467 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
11468 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
11469 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
11470 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
11471 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
11472 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
11473 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
11474 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
11475 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
11476 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
11477 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
11478 theDI << "shadingModel: ";
11479 switch (aView->ShadingModel())
11481 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11482 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
11483 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
11484 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
11485 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
11486 case Graphic3d_TOSM_PBR: theDI << "pbr"; break;
11487 case Graphic3d_TOSM_PBR_FACET: theDI << "pbr_facet"; break;
11490 theDI << "perfCounters:";
11491 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
11495 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
11499 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
11501 theDI << " structs";
11503 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
11505 theDI << " groups";
11507 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
11509 theDI << " arrays";
11511 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
11515 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
11519 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
11521 theDI << " gpumem";
11523 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
11525 theDI << " frameTime";
11527 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
11529 theDI << " skipimmediate";
11531 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
11537 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
11538 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
11539 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
11540 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
11541 "noUpdate") << "\n";
11546 Standard_Boolean toPrint = Standard_False;
11547 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
11548 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11550 Standard_CString anArg (theArgVec[anArgIter]);
11551 TCollection_AsciiString aFlag (anArg);
11553 if (anUpdateTool.parseRedrawMode (aFlag))
11557 else if (aFlag == "-echo"
11558 || aFlag == "-print")
11560 toPrint = Standard_True;
11561 anUpdateTool.Invalidate();
11563 else if (aFlag == "-mode"
11564 || aFlag == "-rendermode"
11565 || aFlag == "-render_mode")
11569 switch (aParams.Method)
11571 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11572 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
11578 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11582 else if (aFlag == "-ray"
11583 || aFlag == "-raytrace")
11587 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
11591 aParams.Method = Graphic3d_RM_RAYTRACING;
11593 else if (aFlag == "-rast"
11594 || aFlag == "-raster"
11595 || aFlag == "-rasterization")
11599 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
11603 aParams.Method = Graphic3d_RM_RASTERIZATION;
11605 else if (aFlag == "-msaa")
11609 theDI << aParams.NbMsaaSamples << " ";
11612 else if (++anArgIter >= theArgNb)
11614 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11618 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
11619 if (aNbSamples < 0)
11621 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
11626 aParams.NbMsaaSamples = aNbSamples;
11629 else if (aFlag == "-linefeather"
11630 || aFlag == "-edgefeather"
11631 || aFlag == "-feather")
11635 theDI << " " << aParams.LineFeather << " ";
11638 else if (++anArgIter >= theArgNb)
11640 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11644 TCollection_AsciiString aParam = theArgVec[anArgIter];
11645 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11646 if (aFeather <= 0.0f)
11648 std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n";
11651 aParams.LineFeather = aFeather;
11653 else if (aFlag == "-oit")
11657 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
11659 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
11663 theDI << "off" << " ";
11667 else if (++anArgIter >= theArgNb)
11669 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11673 TCollection_AsciiString aParam = theArgVec[anArgIter];
11674 aParam.LowerCase();
11675 if (aParam.IsRealValue())
11677 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11678 if (aWeight < 0.f || aWeight > 1.f)
11680 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
11684 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
11685 aParams.OitDepthFactor = aWeight;
11687 else if (aParam == "off")
11689 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
11693 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11697 else if (aFlag == "-depthprepass")
11701 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
11704 aParams.ToEnableDepthPrepass = Standard_True;
11705 if (anArgIter + 1 < theArgNb
11706 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
11711 else if (aFlag == "-samplealphatocoverage"
11712 || aFlag == "-alphatocoverage")
11716 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
11719 aParams.ToEnableAlphaToCoverage = Standard_True;
11720 if (anArgIter + 1 < theArgNb
11721 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
11726 else if (aFlag == "-rendscale"
11727 || aFlag == "-renderscale"
11728 || aFlag == "-renderresolutionscale")
11732 theDI << aParams.RenderResolutionScale << " ";
11735 else if (++anArgIter >= theArgNb)
11737 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11741 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
11744 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
11749 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
11752 else if (aFlag == "-raydepth"
11753 || aFlag == "-ray_depth")
11757 theDI << aParams.RaytracingDepth << " ";
11760 else if (++anArgIter >= theArgNb)
11762 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11766 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
11768 // We allow RaytracingDepth be more than 10 in case of GI enabled
11769 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
11771 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
11776 aParams.RaytracingDepth = aDepth;
11779 else if (aFlag == "-shad"
11780 || aFlag == "-shadows")
11784 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
11788 Standard_Boolean toEnable = Standard_True;
11789 if (++anArgIter < theArgNb
11790 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11794 aParams.IsShadowEnabled = toEnable;
11796 else if (aFlag == "-refl"
11797 || aFlag == "-reflections")
11801 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
11805 Standard_Boolean toEnable = Standard_True;
11806 if (++anArgIter < theArgNb
11807 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11811 aParams.IsReflectionEnabled = toEnable;
11813 else if (aFlag == "-fsaa")
11817 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
11821 Standard_Boolean toEnable = Standard_True;
11822 if (++anArgIter < theArgNb
11823 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11827 aParams.IsAntialiasingEnabled = toEnable;
11829 else if (aFlag == "-gleam")
11833 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
11837 Standard_Boolean toEnable = Standard_True;
11838 if (++anArgIter < theArgNb
11839 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11843 aParams.IsTransparentShadowEnabled = toEnable;
11845 else if (aFlag == "-gi")
11849 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
11853 Standard_Boolean toEnable = Standard_True;
11854 if (++anArgIter < theArgNb
11855 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11859 aParams.IsGlobalIlluminationEnabled = toEnable;
11862 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
11865 else if (aFlag == "-blockedrng"
11866 || aFlag == "-brng")
11870 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
11874 Standard_Boolean toEnable = Standard_True;
11875 if (++anArgIter < theArgNb
11876 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11880 aParams.CoherentPathTracingMode = toEnable;
11882 else if (aFlag == "-maxrad")
11886 theDI << aParams.RadianceClampingValue << " ";
11889 else if (++anArgIter >= theArgNb)
11891 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11895 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
11896 if (!aMaxRadStr.IsRealValue())
11898 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11902 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
11903 if (aMaxRadiance <= 0.0)
11905 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
11910 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
11913 else if (aFlag == "-iss")
11917 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
11921 Standard_Boolean toEnable = Standard_True;
11922 if (++anArgIter < theArgNb
11923 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11927 aParams.AdaptiveScreenSampling = toEnable;
11929 else if (aFlag == "-issatomic")
11933 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
11937 Standard_Boolean toEnable = Standard_True;
11938 if (++anArgIter < theArgNb
11939 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11943 aParams.AdaptiveScreenSamplingAtomic = toEnable;
11945 else if (aFlag == "-issd")
11949 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
11953 Standard_Boolean toEnable = Standard_True;
11954 if (++anArgIter < theArgNb
11955 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11959 aParams.ShowSamplingTiles = toEnable;
11961 else if (aFlag == "-tilesize")
11965 theDI << aParams.RayTracingTileSize << " ";
11968 else if (++anArgIter >= theArgNb)
11970 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11974 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
11977 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
11980 aParams.RayTracingTileSize = aTileSize;
11982 else if (aFlag == "-nbtiles")
11986 theDI << aParams.NbRayTracingTiles << " ";
11989 else if (++anArgIter >= theArgNb)
11991 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11995 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
11998 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
12001 else if (aNbTiles > 0
12003 || aNbTiles > 1024))
12005 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
12007 aParams.NbRayTracingTiles = aNbTiles;
12009 else if (aFlag == "-env")
12013 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
12017 Standard_Boolean toEnable = Standard_True;
12018 if (++anArgIter < theArgNb
12019 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12023 aParams.UseEnvironmentMapBackground = toEnable;
12025 else if (aFlag == "-ignorenormalmap")
12029 theDI << (aParams.ToIgnoreNormalMapInRayTracing ? "on" : "off") << " ";
12033 Standard_Boolean toEnable = Standard_True;
12034 if (++anArgIter < theArgNb
12035 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12039 aParams.ToIgnoreNormalMapInRayTracing = toEnable;
12041 else if (aFlag == "-twoside")
12045 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
12049 Standard_Boolean toEnable = Standard_True;
12050 if (++anArgIter < theArgNb
12051 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12055 aParams.TwoSidedBsdfModels = toEnable;
12057 else if (aFlag == "-shademodel"
12058 || aFlag == "-shadingmodel"
12059 || aFlag == "-shading")
12063 switch (aView->ShadingModel())
12065 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
12066 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
12067 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
12068 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
12069 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
12070 case Graphic3d_TOSM_PBR: theDI << "pbr"; break;
12071 case Graphic3d_TOSM_PBR_FACET: theDI << "pbr_facet"; break;
12076 if (++anArgIter >= theArgNb)
12078 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12081 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
12082 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
12083 && aModel != Graphic3d_TOSM_DEFAULT)
12085 aView->SetShadingModel (aModel);
12089 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
12093 else if (aFlag == "-pbrenvpow2size"
12094 || aFlag == "-pbrenvp2s"
12095 || aFlag == "-pep2s")
12097 if (++anArgIter >= theArgNb)
12099 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12103 const Standard_Integer aPbrEnvPow2Size = Draw::Atoi (theArgVec[anArgIter]);
12104 if (aPbrEnvPow2Size < 1)
12106 std::cout << "Error: 'Pow2Size' of PBR Environment has to be greater or equal 1\n";
12109 aParams.PbrEnvPow2Size = aPbrEnvPow2Size;
12111 else if (aFlag == "-pbrenvspecmaplevelsnumber"
12112 || aFlag == "-pbrenvspecmapnblevels"
12113 || aFlag == "-pbrenvspecmaplevels"
12114 || aFlag == "-pbrenvsmln"
12115 || aFlag == "-pesmln")
12117 if (++anArgIter >= theArgNb)
12119 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12123 const Standard_Integer aPbrEnvSpecMapNbLevels = Draw::Atoi (theArgVec[anArgIter]);
12124 if (aPbrEnvSpecMapNbLevels < 2)
12126 std::cout << "Error: 'SpecMapLevelsNumber' of PBR Environment has to be greater or equal 2\n";
12129 aParams.PbrEnvSpecMapNbLevels = aPbrEnvSpecMapNbLevels;
12131 else if (aFlag == "-pbrenvbakngdiffsamplesnumber"
12132 || aFlag == "-pbrenvbakingdiffsamples"
12133 || aFlag == "-pbrenvbdsn")
12135 if (++anArgIter >= theArgNb)
12137 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12141 const Standard_Integer aPbrEnvBakingDiffNbSamples = Draw::Atoi (theArgVec[anArgIter]);
12142 if (aPbrEnvBakingDiffNbSamples < 1)
12144 std::cout << "Error: 'BakingDiffSamplesNumber' of PBR Environtment has to be greater or equal 1\n";
12147 aParams.PbrEnvBakingDiffNbSamples = aPbrEnvBakingDiffNbSamples;
12149 else if (aFlag == "-pbrenvbakngspecsamplesnumber"
12150 || aFlag == "-pbrenvbakingspecsamples"
12151 || aFlag == "-pbrenvbssn")
12153 if (++anArgIter >= theArgNb)
12155 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12159 const Standard_Integer aPbrEnvBakingSpecNbSamples = Draw::Atoi(theArgVec[anArgIter]);
12160 if (aPbrEnvBakingSpecNbSamples < 1)
12162 std::cout << "Error: 'BakingSpecSamplesNumber' of PBR Environtment has to be greater or equal 1\n";
12165 aParams.PbrEnvBakingSpecNbSamples = aPbrEnvBakingSpecNbSamples;
12167 else if (aFlag == "-pbrenvbakingprobability"
12168 || aFlag == "-pbrenvbp")
12170 if (++anArgIter >= theArgNb)
12172 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12175 const Standard_ShortReal aPbrEnvBakingProbability = static_cast<Standard_ShortReal>(Draw::Atof (theArgVec[anArgIter]));
12176 if (aPbrEnvBakingProbability < 0.f
12177 || aPbrEnvBakingProbability > 1.f)
12179 std::cout << "Error: 'BakingProbability' of PBR Environtment has to be in range of [0, 1]\n";
12182 aParams.PbrEnvBakingProbability = aPbrEnvBakingProbability;
12184 else if (aFlag == "-resolution")
12186 if (++anArgIter >= theArgNb)
12188 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
12192 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
12193 if (aResolution.IsIntegerValue())
12195 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
12199 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12203 else if (aFlag == "-rebuildglsl"
12204 || aFlag == "-rebuild")
12208 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
12212 Standard_Boolean toEnable = Standard_True;
12213 if (++anArgIter < theArgNb
12214 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12218 aParams.RebuildRayTracingShaders = toEnable;
12220 else if (aFlag == "-focal")
12222 if (++anArgIter >= theArgNb)
12224 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12228 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12229 if (aParam.IsRealValue())
12231 float aFocalDist = static_cast<float> (aParam.RealValue());
12232 if (aFocalDist < 0)
12234 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12237 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
12241 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12245 else if (aFlag == "-aperture")
12247 if (++anArgIter >= theArgNb)
12249 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12253 TCollection_AsciiString aParam(theArgVec[anArgIter]);
12254 if (aParam.IsRealValue())
12256 float aApertureSize = static_cast<float> (aParam.RealValue());
12257 if (aApertureSize < 0)
12259 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12262 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
12266 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12270 else if (aFlag == "-exposure")
12272 if (++anArgIter >= theArgNb)
12274 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12278 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
12279 if (anExposure.IsRealValue())
12281 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
12285 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12289 else if (aFlag == "-whitepoint")
12291 if (++anArgIter >= theArgNb)
12293 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12297 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
12298 if (aWhitePoint.IsRealValue())
12300 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
12304 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12308 else if (aFlag == "-tonemapping")
12310 if (++anArgIter >= theArgNb)
12312 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12316 TCollection_AsciiString aMode (theArgVec[anArgIter]);
12319 if (aMode == "disabled")
12321 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
12323 else if (aMode == "filmic")
12325 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
12329 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12333 else if (aFlag == "-performancestats"
12334 || aFlag == "-performancecounters"
12335 || aFlag == "-perfstats"
12336 || aFlag == "-perfcounters"
12337 || aFlag == "-stats")
12339 if (++anArgIter >= theArgNb)
12341 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12345 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
12346 aFlagsStr.LowerCase();
12347 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
12348 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
12350 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12353 aView->ChangeRenderingParams().CollectedStats = aFlags;
12354 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
12356 else if (aFlag == "-perfupdateinterval"
12357 || aFlag == "-statsupdateinterval")
12359 if (++anArgIter >= theArgNb)
12361 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12364 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12366 else if (aFlag == "-perfchart"
12367 || aFlag == "-statschart")
12369 if (++anArgIter >= theArgNb)
12371 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12374 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
12376 else if (aFlag == "-perfchartmax"
12377 || aFlag == "-statschartmax")
12379 if (++anArgIter >= theArgNb)
12381 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12384 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12386 else if (aFlag == "-frustumculling"
12387 || aFlag == "-culling")
12391 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
12392 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
12393 "noUpdate") << " ";
12397 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
12398 if (++anArgIter < theArgNb)
12400 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
12401 aStateStr.LowerCase();
12402 bool toEnable = true;
12403 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
12405 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
12407 else if (aStateStr == "noupdate"
12408 || aStateStr == "freeze")
12410 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
12417 aParams.FrustumCullingState = aState;
12421 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
12429 //=======================================================================
12430 //function : searchInfo
12432 //=======================================================================
12433 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
12434 const TCollection_AsciiString& theKey)
12436 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
12438 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
12440 return anIter.Value();
12443 return TCollection_AsciiString();
12446 //=======================================================================
12447 //function : VStatProfiler
12449 //=======================================================================
12450 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
12451 Standard_Integer theArgNb,
12452 const char** theArgVec)
12454 Handle(V3d_View) aView = ViewerTest::CurrentView();
12455 if (aView.IsNull())
12457 std::cerr << "Error: no active viewer!\n";
12461 Standard_Boolean toRedraw = Standard_True;
12462 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
12463 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
12464 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
12465 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12467 Standard_CString anArg (theArgVec[anArgIter]);
12468 TCollection_AsciiString aFlag (anArg);
12470 if (aFlag == "-noredraw")
12472 toRedraw = Standard_False;
12476 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
12477 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
12478 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
12479 else if (aFlag == "alllayers"
12480 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
12481 else if (aFlag == "allstructs"
12482 || aFlag == "allstructures"
12483 || aFlag == "structs"
12484 || aFlag == "structures") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
12485 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
12486 else if (aFlag == "allarrays"
12487 || aFlag == "fillarrays"
12488 || aFlag == "linearrays"
12489 || aFlag == "pointarrays"
12490 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
12491 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
12492 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
12493 else if (aFlag == "geommem"
12494 || aFlag == "texturemem"
12495 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
12496 else if (aFlag == "elapsedframe"
12497 || aFlag == "cpuframeaverage"
12498 || aFlag == "cpupickingaverage"
12499 || aFlag == "cpucullingaverage"
12500 || aFlag == "cpudynaverage"
12501 || aFlag == "cpuframemax"
12502 || aFlag == "cpupickingmax"
12503 || aFlag == "cpucullingmax"
12504 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
12507 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
12511 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
12515 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
12517 aView->ChangeRenderingParams().CollectedStats =
12518 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
12522 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12524 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12527 TColStd_IndexedDataMapOfStringString aDict;
12528 aView->StatisticInformation (aDict);
12530 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
12532 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12534 Standard_CString anArg(theArgVec[anArgIter]);
12535 TCollection_AsciiString aFlag(anArg);
12537 if (aFlag == "fps")
12539 theDI << searchInfo (aDict, "FPS") << " ";
12541 else if (aFlag == "cpu")
12543 theDI << searchInfo (aDict, "CPU FPS") << " ";
12545 else if (aFlag == "alllayers")
12547 theDI << searchInfo (aDict, "Layers") << " ";
12549 else if (aFlag == "layers")
12551 theDI << searchInfo (aDict, "Rendered layers") << " ";
12553 else if (aFlag == "allstructs"
12554 || aFlag == "allstructures")
12556 theDI << searchInfo (aDict, "Structs") << " ";
12558 else if (aFlag == "structs"
12559 || aFlag == "structures")
12561 TCollection_AsciiString aRend = searchInfo (aDict, "Rendered structs");
12562 if (aRend.IsEmpty()) // all structures rendered
12564 aRend = searchInfo (aDict, "Structs");
12566 theDI << aRend << " ";
12568 else if (aFlag == "groups")
12570 theDI << searchInfo (aDict, "Rendered groups") << " ";
12572 else if (aFlag == "allarrays")
12574 theDI << searchInfo (aDict, "Rendered arrays") << " ";
12576 else if (aFlag == "fillarrays")
12578 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
12580 else if (aFlag == "linearrays")
12582 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
12584 else if (aFlag == "pointarrays")
12586 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
12588 else if (aFlag == "textarrays")
12590 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
12592 else if (aFlag == "triangles")
12594 theDI << searchInfo (aDict, "Rendered triangles") << " ";
12596 else if (aFlag == "points")
12598 theDI << searchInfo (aDict, "Rendered points") << " ";
12600 else if (aFlag == "geommem")
12602 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
12604 else if (aFlag == "texturemem")
12606 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
12608 else if (aFlag == "framemem")
12610 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
12612 else if (aFlag == "elapsedframe")
12614 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
12616 else if (aFlag == "cpuframe_average")
12618 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
12620 else if (aFlag == "cpupicking_average")
12622 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
12624 else if (aFlag == "cpuculling_average")
12626 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
12628 else if (aFlag == "cpudyn_average")
12630 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
12632 else if (aFlag == "cpuframe_max")
12634 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
12636 else if (aFlag == "cpupicking_max")
12638 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
12640 else if (aFlag == "cpuculling_max")
12642 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
12644 else if (aFlag == "cpudyn_max")
12646 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
12654 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12656 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12658 theDI << "Statistic info:\n" << aView->StatisticInformation();
12663 //=======================================================================
12664 //function : VXRotate
12666 //=======================================================================
12667 static Standard_Integer VXRotate (Draw_Interpretor& di,
12668 Standard_Integer argc,
12669 const char ** argv)
12671 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
12672 if (aContext.IsNull())
12674 di << argv[0] << "ERROR : use 'vinit' command before \n";
12680 di << "ERROR : Usage : " << argv[0] << " name angle\n";
12684 TCollection_AsciiString aName (argv[1]);
12685 Standard_Real anAngle = Draw::Atof (argv[2]);
12688 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
12689 Handle(AIS_InteractiveObject) anIObj;
12690 if (!aMap.Find2 (aName, anIObj))
12692 di << "Use 'vdisplay' before\n";
12696 gp_Trsf aTransform;
12697 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
12698 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
12700 aContext->SetLocation (anIObj, aTransform);
12701 aContext->UpdateCurrentViewer();
12705 //===============================================================================================
12706 //function : VManipulator
12708 //===============================================================================================
12709 static int VManipulator (Draw_Interpretor& theDi,
12710 Standard_Integer theArgsNb,
12711 const char** theArgVec)
12713 Handle(V3d_View) aCurrentView = ViewerTest::CurrentView();
12714 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
12715 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
12716 if (aCurrentView.IsNull()
12717 || aViewer.IsNull())
12719 std::cerr << "No active viewer!\n";
12723 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
12724 Standard_Integer anArgIter = 1;
12725 for (; anArgIter < theArgsNb; ++anArgIter)
12727 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
12730 ViewerTest_CmdParser aCmd;
12731 aCmd.SetDescription ("Manages manipulator for interactive objects:");
12732 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
12733 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
12734 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
12735 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
12736 aCmd.AddOption ("view", "... {active | [view name]} - define view in which manipulator will be displayed, 'all' by default");
12737 aCmd.AddOption ("detach", "... - detach manipulator");
12739 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
12740 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
12741 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
12743 aCmd.AddOption ("move", "... x y z - move object");
12744 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
12745 aCmd.AddOption ("scale", "... factor - scale object");
12747 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
12748 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
12749 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
12750 aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform");
12751 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
12752 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
12753 aCmd.AddOption ("parts", "... all axes mode {0|1} - set visual part");
12754 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
12755 aCmd.AddOption ("size", "... size - set size of manipulator");
12756 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
12758 aCmd.Parse (theArgsNb, theArgVec);
12760 if (aCmd.HasOption ("help"))
12762 theDi.PrintHelp (theArgVec[0]);
12766 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
12768 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
12770 if (aName.IsEmpty())
12772 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
12776 // ----------------------------------
12777 // detach existing manipulator object
12778 // ----------------------------------
12780 if (aCmd.HasOption ("detach"))
12782 if (!aMapAIS.IsBound2 (aName))
12784 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
12788 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12789 if (aManipulator.IsNull())
12791 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12795 aManipulator->Detach();
12796 aMapAIS.UnBind2 (aName);
12797 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
12802 // -----------------------------------------------
12803 // find or create manipulator if it does not exist
12804 // -----------------------------------------------
12806 Handle(AIS_Manipulator) aManipulator;
12807 if (!aMapAIS.IsBound2 (aName))
12809 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
12811 aManipulator = new AIS_Manipulator();
12812 aManipulator->SetModeActivationOnDetection (true);
12813 aMapAIS.Bind (aManipulator, aName);
12817 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12818 if (aManipulator.IsNull())
12820 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12825 // -----------------------------------------
12826 // change properties of manipulator instance
12827 // -----------------------------------------
12829 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
12831 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
12833 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
12835 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
12837 if (aCmd.HasOption ("followRotation", 1, Standard_True))
12839 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
12841 if (aCmd.HasOption("followDragging", 1, Standard_True))
12843 aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging"));
12845 if (aCmd.HasOption ("gap", 1, Standard_True))
12847 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
12849 if (aCmd.HasOption ("part", 3, Standard_True))
12851 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
12852 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
12853 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
12854 if (aMode < 1 || aMode > 4)
12856 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12860 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
12862 if (aCmd.HasOption("parts", 2, Standard_True))
12864 Standard_Integer aMode = aCmd.ArgInt("parts", 0);
12865 Standard_Boolean aOnOff = aCmd.ArgBool("parts", 1);
12866 if (aMode < 1 || aMode > 4)
12868 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12872 aManipulator->SetPart(static_cast<AIS_ManipulatorMode>(aMode), aOnOff);
12874 if (aCmd.HasOption ("pos", 3, Standard_True))
12876 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
12877 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
12878 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
12880 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
12882 if (aCmd.HasOption ("size", 1, Standard_True))
12884 aManipulator->SetSize (aCmd.ArgFloat ("size"));
12886 if (aCmd.HasOption ("zoomable", 1, Standard_True))
12888 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
12890 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
12892 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
12893 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
12897 // ---------------------------------------------------
12898 // attach, detach or access manipulator from an object
12899 // ---------------------------------------------------
12901 if (aCmd.HasOption ("attach"))
12903 // Find an object and attach manipulator to it
12904 if (!aCmd.HasOption ("attach", 1, Standard_True))
12909 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
12910 Handle(AIS_InteractiveObject) anObject;
12911 if (!aMapAIS.Find2 (anObjName, anObject))
12913 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
12917 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (aMapAIS);
12918 anIter.More(); anIter.Next())
12920 Handle(AIS_Manipulator) aManip = Handle(AIS_Manipulator)::DownCast (anIter.Key1());
12921 if (!aManip.IsNull()
12922 && aManip->IsAttached()
12923 && aManip->Object() == anObject)
12925 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
12930 AIS_Manipulator::OptionsForAttach anOptions;
12931 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
12933 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
12935 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
12937 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
12939 if (aCmd.HasOption ("enableModes", 1, Standard_True))
12941 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
12944 aManipulator->Attach (anObject, anOptions);
12946 // Check view option
12947 if (aCmd.HasOption ("view"))
12949 if (!aCmd.HasOption ("view", 1, Standard_True))
12953 TCollection_AsciiString aViewString (aCmd.Arg ("view", 0).c_str());
12954 Handle(V3d_View) aView;
12955 if (aViewString.IsEqual ("active"))
12957 aView = ViewerTest::CurrentView();
12959 else // Check view name
12961 ViewerTest_Names aViewNames (aViewString);
12962 if (!ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
12964 std::cerr << theArgVec[0] << " error: wrong view name '" << aViewString << "'\n";
12967 aView = ViewerTest_myViews.Find1 (aViewNames.GetViewName());
12968 if (aView.IsNull())
12970 std::cerr << theArgVec[0] << " error: cannot find view with name '" << aViewString << "'\n";
12974 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
12975 anIter (ViewerTest_myViews); anIter.More(); anIter.Next())
12977 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, anIter.Value(), Standard_False);
12979 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, aView, Standard_True);
12983 // --------------------------------------
12984 // apply transformation using manipulator
12985 // --------------------------------------
12987 if (aCmd.HasOption ("startTransform", 2, Standard_True))
12989 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
12991 if (aCmd.HasOption ("transform", 2, Standard_True))
12993 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
12995 if (aCmd.HasOption ("stopTransform"))
12997 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
12999 aManipulator->StopTransform (toApply);
13003 if (aCmd.HasOption ("move", 3, Standard_True))
13005 aT.SetTranslationPart (aCmd.ArgVec ("move"));
13007 if (aCmd.HasOption ("rotate", 7, Standard_True))
13009 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
13011 if (aCmd.HasOption ("scale", 1))
13013 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
13016 if (aT.Form() != gp_Identity)
13018 aManipulator->Transform (aT);
13021 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
13026 //===============================================================================================
13027 //function : VSelectionProperties
13029 //===============================================================================================
13030 static int VSelectionProperties (Draw_Interpretor& theDi,
13031 Standard_Integer theArgsNb,
13032 const char** theArgVec)
13034 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
13037 std::cerr << "No active viewer!\n";
13041 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
13043 // handle obsolete alias
13044 bool toEnable = true;
13047 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
13050 else if (theArgsNb != 2
13051 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
13053 std::cout << "Syntax error: wrong number of parameters.";
13056 if (toEnable != aCtx->ToHilightSelected())
13058 aCtx->ClearDetected();
13059 aCtx->SetToHilightSelected (toEnable);
13064 Standard_Boolean toPrint = theArgsNb == 1;
13065 Standard_Boolean toRedraw = Standard_False;
13066 Standard_Integer anArgIter = 1;
13067 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
13068 if (anArgIter < theArgsNb)
13070 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
13071 anArgFirst.LowerCase();
13073 if (anArgFirst == "dynhighlight"
13074 || anArgFirst == "dynhilight"
13075 || anArgFirst == "dynamichighlight"
13076 || anArgFirst == "dynamichilight")
13078 aType = Prs3d_TypeOfHighlight_Dynamic;
13080 else if (anArgFirst == "localdynhighlight"
13081 || anArgFirst == "localdynhilight"
13082 || anArgFirst == "localdynamichighlight"
13083 || anArgFirst == "localdynamichilight")
13085 aType = Prs3d_TypeOfHighlight_LocalDynamic;
13087 else if (anArgFirst == "selhighlight"
13088 || anArgFirst == "selhilight"
13089 || anArgFirst == "selectedhighlight"
13090 || anArgFirst == "selectedhilight")
13092 aType = Prs3d_TypeOfHighlight_Selected;
13094 else if (anArgFirst == "localselhighlight"
13095 || anArgFirst == "localselhilight"
13096 || anArgFirst == "localselectedhighlight"
13097 || anArgFirst == "localselectedhilight")
13099 aType = Prs3d_TypeOfHighlight_LocalSelected;
13106 for (; anArgIter < theArgsNb; ++anArgIter)
13108 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13110 if (anArg == "-help")
13112 theDi.PrintHelp (theArgVec[0]);
13115 else if (anArg == "-print")
13117 toPrint = Standard_True;
13119 else if (anArg == "-autoactivate")
13121 Standard_Boolean toEnable = Standard_True;
13122 if (anArgIter + 1 < theArgsNb
13123 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13127 aCtx->SetAutoActivateSelection (toEnable);
13129 else if (anArg == "-automatichighlight"
13130 || anArg == "-automatichilight"
13131 || anArg == "-autohighlight"
13132 || anArg == "-autohilight")
13134 Standard_Boolean toEnable = Standard_True;
13135 if (anArgIter + 1 < theArgsNb
13136 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13140 aCtx->ClearSelected (false);
13141 aCtx->ClearDetected();
13142 aCtx->SetAutomaticHilight (toEnable);
13145 else if (anArg == "-highlightselected"
13146 || anArg == "-hilightselected")
13148 Standard_Boolean toEnable = Standard_True;
13149 if (anArgIter + 1 < theArgsNb
13150 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
13154 aCtx->ClearDetected();
13155 aCtx->SetToHilightSelected (toEnable);
13158 else if (anArg == "-pickstrategy"
13159 || anArg == "-pickingstrategy")
13161 if (++anArgIter >= theArgsNb)
13163 std::cout << "Syntax error: type of highlighting is undefined\n";
13167 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
13168 TCollection_AsciiString aVal (theArgVec[anArgIter]);
13170 if (aVal == "first"
13171 || aVal == "firstaccepted"
13172 || aVal == "firstacceptable")
13174 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
13176 else if (aVal == "topmost"
13177 || aVal == "onlyTopmost")
13179 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
13183 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
13187 aCtx->SetPickingStrategy (aStrategy);
13189 else if (anArg == "-pixtol"
13190 && anArgIter + 1 < theArgsNb)
13192 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
13194 else if ((anArg == "-mode"
13195 || anArg == "-dispmode")
13196 && anArgIter + 1 < theArgsNb)
13198 if (aType == Prs3d_TypeOfHighlight_None)
13200 std::cout << "Syntax error: type of highlighting is undefined\n";
13204 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
13205 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13206 aStyle->SetDisplayMode (aDispMode);
13207 toRedraw = Standard_True;
13209 else if (anArg == "-layer"
13210 && anArgIter + 1 < theArgsNb)
13212 if (aType == Prs3d_TypeOfHighlight_None)
13214 std::cout << "Syntax error: type of highlighting is undefined\n";
13219 Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN;
13220 if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer))
13222 std::cerr << "Error: wrong syntax at " << theArgVec[anArgIter] << ".\n";
13226 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13227 aStyle->SetZLayer (aNewLayer);
13228 toRedraw = Standard_True;
13230 else if (anArg == "-hicolor"
13231 || anArg == "-selcolor"
13232 || anArg == "-color")
13234 if (anArg.StartsWith ("-hi"))
13236 aType = Prs3d_TypeOfHighlight_Dynamic;
13238 else if (anArg.StartsWith ("-sel"))
13240 aType = Prs3d_TypeOfHighlight_Selected;
13242 else if (aType == Prs3d_TypeOfHighlight_None)
13244 std::cout << "Syntax error: type of highlighting is undefined\n";
13248 Quantity_Color aColor;
13249 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
13250 theArgVec + anArgIter + 1,
13252 if (aNbParsed == 0)
13254 std::cout << "Syntax error: need more arguments.\n";
13257 anArgIter += aNbParsed;
13259 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13260 aStyle->SetColor (aColor);
13261 toRedraw = Standard_True;
13263 else if ((anArg == "-transp"
13264 || anArg == "-transparency"
13265 || anArg == "-hitransp"
13266 || anArg == "-seltransp"
13267 || anArg == "-hitransplocal"
13268 || anArg == "-seltransplocal")
13269 && anArgIter + 1 < theArgsNb)
13271 if (anArg.StartsWith ("-hi"))
13273 aType = Prs3d_TypeOfHighlight_Dynamic;
13275 else if (anArg.StartsWith ("-sel"))
13277 aType = Prs3d_TypeOfHighlight_Selected;
13279 else if (aType == Prs3d_TypeOfHighlight_None)
13281 std::cout << "Syntax error: type of highlighting is undefined\n";
13285 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
13286 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13287 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
13288 toRedraw = Standard_True;
13290 else if ((anArg == "-mat"
13291 || anArg == "-material")
13292 && anArgIter + 1 < theArgsNb)
13294 if (aType == Prs3d_TypeOfHighlight_None)
13296 std::cout << "Syntax error: type of highlighting is undefined\n";
13300 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13301 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
13302 if (aMatName != Graphic3d_NOM_DEFAULT)
13305 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
13306 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
13307 Graphic3d_MaterialAspect aMat (aMatName);
13308 aMat.SetColor (aStyle->Color());
13309 aMat.SetTransparency (aStyle->Transparency());
13310 anAspect->SetFrontMaterial (aMat);
13311 anAspect->SetInteriorColor (aStyle->Color());
13312 aStyle->SetBasicFillAreaAspect (anAspect);
13316 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
13318 toRedraw = Standard_True;
13322 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
13328 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
13329 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
13330 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
13331 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
13332 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
13333 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
13334 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
13335 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
13336 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
13337 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
13338 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
13339 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
13340 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
13341 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
13344 if (aCtx->NbSelected() != 0 && toRedraw)
13346 aCtx->HilightSelected (Standard_True);
13352 //===============================================================================================
13353 //function : VDumpSelectionImage
13355 //===============================================================================================
13356 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
13357 Standard_Integer theArgsNb,
13358 const char** theArgVec)
13362 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
13366 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13367 if (aContext.IsNull())
13369 std::cout << "Error: no active view.\n";
13373 TCollection_AsciiString aFile;
13374 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13375 Image_Format anImgFormat = Image_Format_BGR;
13376 Standard_Integer aPickedIndex = 1;
13377 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
13379 TCollection_AsciiString aParam (theArgVec[anArgIter]);
13380 aParam.LowerCase();
13381 if (aParam == "-type")
13383 if (++anArgIter >= theArgsNb)
13385 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
13389 TCollection_AsciiString aValue (theArgVec[anArgIter]);
13390 aValue.LowerCase();
13391 if (aValue == "depth"
13392 || aValue == "normdepth"
13393 || aValue == "normalizeddepth")
13395 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13396 anImgFormat = Image_Format_GrayF;
13398 if (aValue == "depthinverted"
13399 || aValue == "normdepthinverted"
13400 || aValue == "normalizeddepthinverted"
13401 || aValue == "inverted")
13403 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
13404 anImgFormat = Image_Format_GrayF;
13406 else if (aValue == "unnormdepth"
13407 || aValue == "unnormalizeddepth")
13409 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
13410 anImgFormat = Image_Format_GrayF;
13412 else if (aValue == "objectcolor"
13413 || aValue == "object"
13414 || aValue == "color")
13416 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
13418 else if (aValue == "entitycolor"
13419 || aValue == "entity")
13421 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
13423 else if (aValue == "ownercolor"
13424 || aValue == "owner")
13426 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
13428 else if (aValue == "selectionmodecolor"
13429 || aValue == "selectionmode"
13430 || aValue == "selmodecolor"
13431 || aValue == "selmode")
13433 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
13436 else if (aParam == "-picked"
13437 || aParam == "-pickeddepth"
13438 || aParam == "-pickedindex")
13440 if (++anArgIter >= theArgsNb)
13442 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
13446 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
13448 else if (aFile.IsEmpty())
13450 aFile = theArgVec[anArgIter];
13454 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
13458 if (aFile.IsEmpty())
13460 std::cout << "Syntax error: image file name is missing.\n";
13464 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13465 Standard_Integer aWidth = 0, aHeight = 0;
13466 aView->Window()->Size (aWidth, aHeight);
13468 Image_AlienPixMap aPixMap;
13469 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
13471 std::cout << "Error: can't allocate image.\n";
13474 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
13476 std::cout << "Error: can't generate selection image.\n";
13479 if (!aPixMap.Save (aFile))
13481 std::cout << "Error: can't save selection image.\n";
13487 //===============================================================================================
13488 //function : VViewCube
13490 //===============================================================================================
13491 static int VViewCube (Draw_Interpretor& ,
13492 Standard_Integer theNbArgs,
13493 const char** theArgVec)
13495 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13496 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13497 if (aContext.IsNull() || aView.IsNull())
13499 std::cout << "Error: no active view.\n";
13502 else if (theNbArgs < 2)
13504 std::cout << "Syntax error: wrong number arguments\n";
13508 Handle(AIS_ViewCube) aViewCube;
13509 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
13510 Quantity_Color aColorRgb;
13511 TCollection_AsciiString aName;
13512 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
13514 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13516 if (anUpdateTool.parseRedrawMode (anArg))
13520 else if (aViewCube.IsNull())
13522 aName = theArgVec[anArgIter];
13523 if (aName.StartsWith ("-"))
13525 std::cout << "Syntax error: object name should be specified.\n";
13528 Handle(AIS_InteractiveObject) aPrs;
13529 GetMapOfAIS().Find2 (aName, aPrs);
13530 aViewCube = Handle(AIS_ViewCube)::DownCast (aPrs);
13531 if (aViewCube.IsNull())
13533 aViewCube = new AIS_ViewCube();
13534 aViewCube->SetBoxColor (Quantity_NOC_GRAY50);
13535 aViewCube->SetViewAnimation (ViewerTest::CurrentEventManager()->ViewAnimation());
13536 aViewCube->SetFixedAnimationLoop (false);
13539 else if (anArg == "-reset")
13541 aViewCube->ResetStyles();
13543 else if (anArg == "-color"
13544 || anArg == "-boxcolor"
13545 || anArg == "-boxsidecolor"
13546 || anArg == "-sidecolor"
13547 || anArg == "-boxedgecolor"
13548 || anArg == "-edgecolor"
13549 || anArg == "-boxcornercolor"
13550 || anArg == "-cornercolor"
13551 || anArg == "-innercolor"
13552 || anArg == "-textcolor")
13554 Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - anArgIter - 1,
13555 theArgVec + anArgIter + 1,
13557 if (aNbParsed == 0)
13559 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
13562 anArgIter += aNbParsed;
13563 if (anArg == "-boxcolor")
13565 aViewCube->SetBoxColor (aColorRgb);
13567 else if (anArg == "-boxsidecolor"
13568 || anArg == "-sidecolor")
13570 aViewCube->BoxSideStyle()->SetColor (aColorRgb);
13571 aViewCube->SynchronizeAspects();
13573 else if (anArg == "-boxedgecolor"
13574 || anArg == "-edgecolor")
13576 aViewCube->BoxEdgeStyle()->SetColor (aColorRgb);
13577 aViewCube->SynchronizeAspects();
13579 else if (anArg == "-boxcornercolor"
13580 || anArg == "-cornercolor")
13582 aViewCube->BoxCornerStyle()->SetColor (aColorRgb);
13583 aViewCube->SynchronizeAspects();
13585 else if (anArg == "-innercolor")
13587 aViewCube->SetInnerColor (aColorRgb);
13589 else if (anArg == "-textcolor")
13591 aViewCube->SetTextColor (aColorRgb);
13595 aViewCube->SetColor (aColorRgb);
13598 else if (anArgIter + 1 < theNbArgs
13599 && (anArg == "-transparency"
13600 || anArg == "-boxtransparency"))
13602 const Standard_Real aValue = Draw::Atof (theArgVec[++anArgIter]);
13603 if (aValue < 0.0 || aValue > 1.0)
13605 std::cout << "Syntax error: invalid transparency value " << theArgVec[anArgIter] << "\n";
13609 if (anArg == "-boxtransparency")
13611 aViewCube->SetBoxTransparency (aValue);
13615 aViewCube->SetTransparency (aValue);
13618 else if (anArg == "-axes"
13619 || anArg == "-edges"
13620 || anArg == "-vertices"
13621 || anArg == "-vertexes"
13622 || anArg == "-fixedanimation")
13624 bool toShow = true;
13625 if (anArgIter + 1 < theNbArgs
13626 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShow))
13630 if (anArg == "-fixedanimation")
13632 aViewCube->SetFixedAnimationLoop (toShow);
13634 else if (anArg == "-axes")
13636 aViewCube->SetDrawAxes (toShow);
13638 else if (anArg == "-edges")
13640 aViewCube->SetDrawEdges (toShow);
13644 aViewCube->SetDrawVertices (toShow);
13647 else if (anArg == "-yup"
13648 || anArg == "-zup")
13651 if (anArgIter + 1 < theNbArgs
13652 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isOn))
13656 if (anArg == "-yup")
13658 aViewCube->SetYup (isOn);
13662 aViewCube->SetYup (!isOn);
13665 else if (anArgIter + 1 < theNbArgs
13666 && anArg == "-font")
13668 aViewCube->SetFont (theArgVec[++anArgIter]);
13670 else if (anArgIter + 1 < theNbArgs
13671 && anArg == "-fontheight")
13673 aViewCube->SetFontHeight (Draw::Atof (theArgVec[++anArgIter]));
13675 else if (anArgIter + 1 < theNbArgs
13676 && (anArg == "-size"
13677 || anArg == "-boxsize"))
13679 aViewCube->SetSize (Draw::Atof (theArgVec[++anArgIter]),
13680 anArg != "-boxsize");
13682 else if (anArgIter + 1 < theNbArgs
13683 && (anArg == "-boxfacet"
13684 || anArg == "-boxfacetextension"
13685 || anArg == "-facetextension"
13686 || anArg == "-extension"))
13688 aViewCube->SetBoxFacetExtension (Draw::Atof (theArgVec[++anArgIter]));
13690 else if (anArgIter + 1 < theNbArgs
13691 && (anArg == "-boxedgegap"
13692 || anArg == "-edgegap"))
13694 aViewCube->SetBoxEdgeGap (Draw::Atof (theArgVec[++anArgIter]));
13696 else if (anArgIter + 1 < theNbArgs
13697 && (anArg == "-boxedgeminsize"
13698 || anArg == "-edgeminsize"))
13700 aViewCube->SetBoxEdgeMinSize (Draw::Atof (theArgVec[++anArgIter]));
13702 else if (anArgIter + 1 < theNbArgs
13703 && (anArg == "-boxcornerminsize"
13704 || anArg == "-cornerminsize"))
13706 aViewCube->SetBoxCornerMinSize (Draw::Atof (theArgVec[++anArgIter]));
13708 else if (anArgIter + 1 < theNbArgs
13709 && anArg == "-axespadding")
13711 aViewCube->SetAxesPadding (Draw::Atof (theArgVec[++anArgIter]));
13713 else if (anArgIter + 1 < theNbArgs
13714 && anArg == "-roundradius")
13716 aViewCube->SetRoundRadius (Draw::Atof (theArgVec[++anArgIter]));
13718 else if (anArgIter + 1 < theNbArgs
13719 && anArg == "-duration")
13721 aViewCube->SetDuration (Draw::Atof (theArgVec[++anArgIter]));
13723 else if (anArgIter + 1 < theNbArgs
13724 && anArg == "-axesradius")
13726 aViewCube->SetAxesRadius (Draw::Atof (theArgVec[++anArgIter]));
13728 else if (anArgIter + 1 < theNbArgs
13729 && anArg == "-axesconeradius")
13731 aViewCube->SetAxesConeRadius (Draw::Atof (theArgVec[++anArgIter]));
13733 else if (anArgIter + 1 < theNbArgs
13734 && anArg == "-axessphereradius")
13736 aViewCube->SetAxesSphereRadius (Draw::Atof (theArgVec[++anArgIter]));
13740 std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
13744 if (aViewCube.IsNull())
13746 std::cout << "Syntax error: wrong number of arguments\n";
13750 ViewerTest::Display (aName, aViewCube, false);
13754 //=======================================================================
13755 //function : ViewerCommands
13757 //=======================================================================
13759 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
13762 const char *group = "ZeViewer";
13763 theCommands.Add("vinit",
13764 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
13765 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
13766 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13767 "\n\t\t: [-display displayName]"
13769 "\n\t\t: Creates new View window with specified name viewName."
13770 "\n\t\t: By default the new view is created in the viewer and in"
13771 "\n\t\t: graphic driver shared with active view."
13772 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
13773 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
13774 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
13775 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13776 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
13777 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
13779 "\n\t\t: -left, -top pixel position of left top corner of the window."
13780 "\n\t\t: -width, -height width and heigth of window respectively."
13781 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
13782 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
13783 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
13784 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
13785 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
13786 __FILE__,VInit,group);
13787 theCommands.Add("vclose" ,
13788 "[view_id [keep_context=0|1]]\n"
13789 "or vclose ALL - to remove all created views\n"
13790 " - removes view(viewer window) defined by its view_id.\n"
13791 " - keep_context: by default 0; if 1 and the last view is deleted"
13792 " the current context is not removed.",
13793 __FILE__,VClose,group);
13794 theCommands.Add("vactivate" ,
13795 "vactivate view_id [-noUpdate]"
13796 " - activates view(viewer window) defined by its view_id",
13797 __FILE__,VActivate,group);
13798 theCommands.Add("vviewlist",
13799 "vviewlist [format={tree, long}]"
13800 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
13801 " - format: format of result output, if tree the output is a tree view;"
13802 "otherwise it's a list of full view names. By default format = tree",
13803 __FILE__,VViewList,group);
13804 theCommands.Add("vhelp" ,
13805 "vhelp : display help on the viewer commands",
13806 __FILE__,VHelp,group);
13807 theCommands.Add("vviewproj",
13808 "vviewproj [top|bottom|left|right|front|back|axoLeft|axoRight]"
13809 "\n\t\t: [+-X+-Y+-Z] [-Zup|-Yup] [-frame +-X+-Y]"
13810 "\n\t\t: Setup view direction"
13811 "\n\t\t: -Yup use Y-up convention instead of Zup (which is default)."
13812 "\n\t\t: +-X+-Y+-Z define direction as combination of DX, DY and DZ;"
13813 "\n\t\t: for example '+Z' will show front of the model,"
13814 "\n\t\t: '-X-Y+Z' will define left axonometrical view."
13815 "\n\t\t: -frame define camera Up and Right directions (regardless Up convention);"
13816 "\n\t\t: for example '+X+Z' will show front of the model with Z-up."
13817 __FILE__,VViewProj,group);
13818 theCommands.Add("vtop" ,
13819 "vtop or <T> : Top view. Orientation +X+Y" ,
13820 __FILE__,VViewProj,group);
13821 theCommands.Add("vbottom" ,
13822 "vbottom : Bottom view. Orientation +X-Y" ,
13823 __FILE__,VViewProj,group);
13824 theCommands.Add("vleft" ,
13825 "vleft : Left view. Orientation -Y+Z" ,
13826 __FILE__,VViewProj,group);
13827 theCommands.Add("vright" ,
13828 "vright : Right view. Orientation +Y+Z" ,
13829 __FILE__,VViewProj,group);
13830 theCommands.Add("vaxo" ,
13831 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
13832 __FILE__,VViewProj,group);
13833 theCommands.Add("vfront" ,
13834 "vfront : Front view. Orientation +X+Z" ,
13835 __FILE__,VViewProj,group);
13836 theCommands.Add("vback" ,
13837 "vback : Back view. Orientation -X+Z" ,
13838 __FILE__,VViewProj,group);
13839 theCommands.Add("vpick" ,
13840 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
13842 theCommands.Add("vfit",
13843 "vfit or <F> [-selected] [-noupdate]"
13844 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
13845 __FILE__,VFit,group);
13846 theCommands.Add ("vfitarea",
13847 "vfitarea x1 y1 x2 y2"
13848 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
13849 "\n\t\t: Fit view to show area located between two points"
13850 "\n\t\t: given in world 2D or 3D corrdinates.",
13851 __FILE__, VFitArea, group);
13852 theCommands.Add ("vzfit", "vzfit [scale]\n"
13853 " Matches Z near, Z far view volume planes to the displayed objects.\n"
13854 " \"scale\" - specifies factor to scale computed z range.\n",
13855 __FILE__, VZFit, group);
13856 theCommands.Add("vrepaint",
13857 "vrepaint [-immediate] [-continuous FPS]"
13858 "\n\t\t: force redraw of active View"
13859 "\n\t\t: -immediate flag performs redraw of immediate layers only;"
13860 "\n\t\t: -continuous activates/deactivates continuous redraw of active View,"
13861 "\n\t\t: 0 means no continuous rendering,"
13862 "\n\t\t: -1 means non-stop redraws,"
13863 "\n\t\t: >0 specifies target framerate,",
13864 __FILE__,VRepaint,group);
13865 theCommands.Add("vclear",
13867 "\n\t\t: remove all the object from the viewer",
13868 __FILE__,VClear,group);
13871 "Changes background or some background settings.\n"
13874 " vbackground -imageFile ImageFile [-imageMode FillType]\n"
13875 " vbackground -imageMode FillType\n"
13876 " vbackground -gradient Color1 Color2 [-gradientMode FillMethod]\n"
13877 " vbackground -gradientMode FillMethod\n"
13878 " vbackground -cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]\n"
13879 " vbackground -color Color\n"
13880 " vbackground -default -gradient Color1 Color2 [-gradientMode FillType]\n"
13881 " vbackground -default -color Color\n"
13882 " vbackground -help\n"
13885 " -imageFile (-imgFile, -image, -img): sets filename of image used as background\n"
13886 " -imageMode (-imgMode, -imageMd, -imgMd): sets image fill type\n"
13887 " -gradient (-grad, -gr): sets background gradient starting and ending colors\n"
13888 " -gradientMode (-gradMode, -gradMd, -grMode, -grMd): sets gradient fill method\n"
13889 " -cubemap (-cmap, -cm): sets environmet cubemap as background\n"
13890 " -invertedz (-invz, -iz): sets inversion of Z axis for background cubemap rendering\n"
13891 " -order (-o): defines order of tiles in one image cubemap\n"
13892 " (has no effect in case of multi image cubemaps)\n"
13893 " -color (-col): sets background color\n"
13894 " -default (-def): sets background default gradient or color\n"
13895 " -help (-h): outputs short help message\n"
13898 " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n"
13899 " or reals within the range [0.0, 1.0]\n"
13900 " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n"
13901 " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n"
13902 " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, "
13904 " FillType: one of CENTERED, TILED, STRETCH, NONE\n"
13905 " ImageFile: a name of the file with the image used as a background\n"
13906 " CubemapFilei: a name of the file with one image packed cubemap or names of separate files with every cubemap side\n"
13907 " TileIndexi: a cubemap side index in range [0, 5] for i tile of one image packed cubemap\n",
13911 theCommands.Add ("vsetbg",
13912 "Loads image as background."
13913 "\n\t\t: vsetbg ImageFile [FillType]"
13914 "\n\t\t: vsetbg -imageFile ImageFile [-imageMode FillType]"
13915 "\n\t\t: Alias for 'vbackground -imageFile ImageFile [-imageMode FillType]'.",
13919 theCommands.Add ("vsetbgmode",
13920 "Changes background image fill type."
13921 "\n\t\t: vsetbgmode [-imageMode] FillType"
13922 "\n\t\t: Alias for 'vbackground -imageMode FillType'.",
13926 theCommands.Add ("vsetgradientbg",
13927 "Mounts gradient background."
13928 "\n\t\t: vsetgradientbg Color1 Color2 [FillMethod]"
13929 "\n\t\t: vsetgradientbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13930 "\n\t\t: Alias for 'vbackground -gradient Color1 Color2 -gradientMode FillMethod'.",
13934 theCommands.Add ("vsetgrbgmode",
13935 "Changes gradient background fill method."
13936 "\n\t\t: vsetgrbgmode [-gradientMode] FillMethod"
13937 "\n\t\t: Alias for 'vbackground -gradientMode FillMethod'.",
13941 theCommands.Add ("vsetcolorbg",
13942 "Sets background color."
13943 "\n\t\t: vsetcolorbg [-color] Color."
13944 "\n\t\t: Alias for 'vbackground -color Color'.",
13948 theCommands.Add ("vsetdefaultbg",
13949 "Sets default viewer background fill color (flat/gradient)."
13950 "\n\t\t: vsetdefaultbg Color1 Color2 [FillMethod]"
13951 "\n\t\t: vsetdefaultbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13952 "\n\t\t: Alias for 'vbackground -default -gradient Color1 Color2 [-gradientMode FillMethod]'."
13953 "\n\t\t: vsetdefaultbg [-color] Color"
13954 "\n\t\t: Alias for 'vbackground -default -color Color'.",
13958 theCommands.Add("vscale",
13959 "vscale : vscale X Y Z",
13960 __FILE__,VScale,group);
13961 theCommands.Add("vzbufftrihedron",
13962 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
13963 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
13964 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
13965 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
13966 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
13967 "\n\t\t: Displays a trihedron",
13968 __FILE__,VZBuffTrihedron,group);
13969 theCommands.Add("vrotate",
13970 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
13971 "\n : Option -mouseStart starts rotation according to the mouse position"
13972 "\n : Option -mouseMove continues rotation with angle computed"
13973 "\n : from last and new mouse position."
13974 "\n : vrotate AX AY AZ [X Y Z]",
13975 __FILE__,VRotate,group);
13976 theCommands.Add("vzoom",
13977 "vzoom : vzoom coef",
13978 __FILE__,VZoom,group);
13979 theCommands.Add("vpan",
13980 "vpan : vpan dx dy",
13981 __FILE__,VPan,group);
13982 theCommands.Add("vcolorscale",
13983 "vcolorscale name [-noupdate|-update] [-demo]"
13984 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
13985 "\n\t\t: [-font HeightFont=20]"
13986 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
13987 "\n\t\t: [-smoothTransition {on|off}=off]"
13988 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
13989 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
13990 "\n\t\t: [-textpos {left|right|center|none}=right]"
13991 "\n\t\t: [-labelAtBorder {on|off}=on]"
13992 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
13993 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
13994 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
13995 "\n\t\t: [-xy Left=0 Bottom=0]"
13996 "\n\t\t: -demo - displays a color scale with demonstratio values"
13997 "\n\t\t: -colors - set colors for all intervals"
13998 "\n\t\t: -color - set color for specific interval"
13999 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
14000 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
14001 "\n\t\t: at border means the value inbetween neighbor intervals,"
14002 "\n\t\t: at center means the center value within current interval"
14003 "\n\t\t: -labels - set labels for all intervals"
14004 "\n\t\t: -freeLabels - same as -labels but does not require"
14005 "\n\t\t: matching the number of intervals"
14006 "\n\t\t: -label - set label for specific interval"
14007 "\n\t\t: -title - set title"
14008 "\n\t\t: -reversed - setup smooth color transition between intervals"
14009 "\n\t\t: -smoothTransition - swap colorscale direction"
14010 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
14011 __FILE__, VColorScale, group);
14012 theCommands.Add("vgraduatedtrihedron",
14013 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
14014 "\t[-namefont Name] [-valuesfont Name]\n"
14015 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
14016 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
14017 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
14018 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
14019 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
14020 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
14021 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
14022 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
14023 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
14024 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
14025 " - Displays or erases graduated trihedron"
14026 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
14027 " - namefont - font of axes names. Default: Arial\n"
14028 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
14029 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
14030 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
14031 " - valuesfont - font of axes values. Default: Arial\n"
14032 " - xcolor, ycolor, zcolor - color of axis and values\n"
14033 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
14034 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
14035 __FILE__,VGraduatedTrihedron,group);
14036 theCommands.Add("vtile" ,
14037 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
14038 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
14039 "\n\t\t: -totalSize the size of virtual bigger viewport"
14040 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
14041 "\n\t\t: -lowerLeft tile offset as lower left corner"
14042 "\n\t\t: -upperLeft tile offset as upper left corner",
14043 __FILE__, VTile, group);
14044 theCommands.Add("vzlayer",
14045 "vzlayer [layerId]"
14046 "\n\t\t: [-add|-delete|-get|-settings] [-insertBefore AnotherLayer] [-insertAfter AnotherLayer]"
14047 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
14048 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
14049 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv|rayTracing}]"
14050 "\n\t\t: ZLayer list management:"
14051 "\n\t\t: -add add new z layer to viewer and print its id"
14052 "\n\t\t: -insertBefore add new z layer and insert it before existing one"
14053 "\n\t\t: -insertAfter add new z layer and insert it after existing one"
14054 "\n\t\t: -delete delete z layer"
14055 "\n\t\t: -get print sequence of z layers"
14056 "\n\t\t: -settings print status of z layer settings"
14057 "\n\t\t: -disable disables given setting"
14058 "\n\t\t: -enable enables given setting",
14059 __FILE__,VZLayer,group);
14060 theCommands.Add("vlayerline",
14061 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
14062 __FILE__,VLayerLine,group);
14063 theCommands.Add("vgrid",
14064 "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]"
14065 "\n\t\t: [-step X Y] [-size DX DY]"
14066 "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]",
14067 __FILE__, VGrid, group);
14068 theCommands.Add ("vpriviledgedplane",
14069 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
14070 "\n\t\t: Ox, Oy, Oz - plane origin"
14071 "\n\t\t: Nx, Ny, Nz - plane normal direction"
14072 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
14073 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
14074 __FILE__, VPriviledgedPlane, group);
14075 theCommands.Add ("vconvert",
14076 "vconvert v [Mode={window|view}]"
14077 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
14078 "\n\t\t: vconvert x y z [Mode={window|grid}]"
14079 "\n\t\t: window - convert to window coordinates, pixels"
14080 "\n\t\t: view - convert to view projection plane"
14081 "\n\t\t: grid - convert to model coordinates, given on grid"
14082 "\n\t\t: ray - convert projection ray to model coordiantes"
14083 "\n\t\t: - vconvert v window : convert view to window;"
14084 "\n\t\t: - vconvert v view : convert window to view;"
14085 "\n\t\t: - vconvert x y window : convert view to window;"
14086 "\n\t\t: - vconvert x y view : convert window to view;"
14087 "\n\t\t: - vconvert x y : convert window to model;"
14088 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
14089 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
14090 "\n\t\t: - vconvert x y z window : convert model to window;"
14091 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
14092 "\n\t\t: Converts the given coordinates to window/view/model space.",
14093 __FILE__, VConvert, group);
14094 theCommands.Add ("vfps",
14095 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
14096 __FILE__, VFps, group);
14097 theCommands.Add ("vgldebug",
14098 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
14099 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
14100 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
14101 "\n\t\t: Debug context can be requested only on Windows"
14102 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
14103 "\n\t\t: -sync - request synchronized debug GL context"
14104 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
14105 "\n\t\t: which are suppressed by default,"
14106 "\n\t\t: -glslCode - log GLSL program source code,"
14107 "\n\t\t: which are suppressed by default,"
14108 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
14109 "\n\t\t: which are suppressed by default",
14110 __FILE__, VGlDebug, group);
14111 theCommands.Add ("vvbo",
14112 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
14113 __FILE__, VVbo, group);
14114 theCommands.Add ("vstereo",
14115 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
14116 "\n\t\t: [-anaglyph Filter]"
14117 "\n\t\t: Control stereo output mode. Available modes for -mode:"
14118 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
14119 "\n\t\t: requires driver support."
14120 "\n\t\t: Should be called BEFORE vinit!"
14121 "\n\t\t: anaglyph - Anaglyph glasses"
14122 "\n\t\t: rowInterlaced - row-interlaced display"
14123 "\n\t\t: columnInterlaced - column-interlaced display"
14124 "\n\t\t: chessBoard - chess-board output"
14125 "\n\t\t: sideBySide - horizontal pair"
14126 "\n\t\t: overUnder - vertical pair"
14127 "\n\t\t: Available Anaglyph filters for -anaglyph:"
14128 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
14129 "\n\t\t: greenMagentaSimple",
14130 __FILE__, VStereo, group);
14131 theCommands.Add ("vcaps",
14132 "vcaps [-sRGB {0|1}] [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
14133 "\n\t\t: [-compatibleProfile {0|1}]"
14134 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
14135 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
14136 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
14137 "\n\t\t: [-noExtensions {0|1}] [-maxVersion Major Minor]"
14138 "\n\t\t: Modify particular graphic driver options:"
14139 "\n\t\t: sRGB - enable/disable sRGB rendering"
14140 "\n\t\t: FFP - use fixed-function pipeline instead of"
14141 "\n\t\t: built-in GLSL programs"
14142 "\n\t\t: (requires compatible profile)"
14143 "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs"
14144 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
14145 "\n\t\t: arrays to GPU memory)"
14146 "\n\t\t: sprite - use textured sprites instead of bitmaps"
14147 "\n\t\t: vsync - switch VSync on or off"
14148 "\n\t\t: winBuffer - allow using window buffer for rendering"
14149 "\n\t\t: Context creation options:"
14150 "\n\t\t: softMode - software OpenGL implementation"
14151 "\n\t\t: compatibleProfile - backward-compatible profile"
14152 "\n\t\t: quadbuffer - QuadBuffer"
14153 "\n\t\t: noExtensions - disallow usage of extensions"
14154 "\n\t\t: maxVersion - force upper OpenGL version to be used"
14155 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
14156 "\n\t\t: rendering paths producing the same visual result when"
14157 "\n\t\t: possible."
14158 "\n\t\t: Command is intended for testing old hardware compatibility.",
14159 __FILE__, VCaps, group);
14160 theCommands.Add ("vmemgpu",
14161 "vmemgpu [f]: print system-dependent GPU memory information if available;"
14162 " with f option returns free memory in bytes",
14163 __FILE__, VMemGpu, group);
14164 theCommands.Add ("vreadpixel",
14165 "vreadpixel xPixel yPixel [{rgb|rgba|sRGB|sRGBa|depth|hls|rgbf|rgbaf}=rgba] [-name|-hex]"
14166 " : Read pixel value for active view",
14167 __FILE__, VReadPixel, group);
14168 theCommands.Add("diffimage",
14169 "diffimage imageFile1 imageFile2 [diffImageFile]"
14170 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
14171 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
14172 "\n\t\t: Compare two images by content and generate difference image."
14173 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
14174 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
14175 __FILE__, VDiffImage, group);
14176 theCommands.Add ("vselect",
14177 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
14178 "- emulates different types of selection:\n"
14179 "- 1) single click selection\n"
14180 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
14181 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
14182 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
14183 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
14184 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
14185 " (partial inclusion - overlap - is not allowed by default)\n"
14186 "- 5) any of these selections with shift button pressed",
14187 __FILE__, VSelect, group);
14188 theCommands.Add ("vmoveto",
14189 "vmoveto [x y] [-reset]"
14190 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
14191 "\n\t\t: -reset resets current highlighting",
14192 __FILE__, VMoveTo, group);
14193 theCommands.Add ("vviewparams",
14194 "vviewparams [-args] [-scale [s]]"
14195 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
14196 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
14197 "\n\t\t: Manage current view parameters or prints all"
14198 "\n\t\t: current values when called without argument."
14199 "\n\t\t: -scale [s] prints or sets viewport relative scale"
14200 "\n\t\t: -eye [x y z] prints or sets eye location"
14201 "\n\t\t: -at [x y z] prints or sets center of look"
14202 "\n\t\t: -up [x y z] prints or sets direction of up vector"
14203 "\n\t\t: -proj [x y z] prints or sets direction of look"
14204 "\n\t\t: -center x y sets location of center of the screen in pixels"
14205 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
14206 "\n\t\t: or changes the size of its maximum dimension"
14207 "\n\t\t: -args prints vviewparams arguments for restoring current view",
14208 __FILE__, VViewParams, group);
14210 theCommands.Add("v2dmode",
14211 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
14212 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
14213 "\n\t\t: mode - switches On/Off rotation mode"
14214 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
14215 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
14216 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
14217 "\n\t\t: View camera position might be changed only by commands.",
14218 __FILE__, V2DMode, group);
14220 theCommands.Add("vanimation", "Alias for vanim",
14221 __FILE__, VAnimation, group);
14223 theCommands.Add("vanim",
14224 "List existing animations:"
14226 "\n\t\t: Animation playback:"
14227 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
14228 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
14229 "\n\t\t: -speed playback speed (1.0 is normal speed)"
14230 "\n\t\t: -freeLook skip camera animations"
14231 "\n\t\t: -lockLoop disable any interactions"
14233 "\n\t\t: Animation definition:"
14234 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
14235 "\n\t\t: [start TimeSec] [duration TimeSec]"
14237 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
14238 "\n\t\t: specifies nested animations."
14239 "\n\t\t: There is no syntax to explicitly add new animation,"
14240 "\n\t\t: and all non-existing animations within the name will be"
14241 "\n\t\t: implicitly created on first use (including parents)."
14243 "\n\t\t: Each animation might define the SINGLE action (see below),"
14244 "\n\t\t: like camera transition, object transformation or custom callback."
14245 "\n\t\t: Child animations can be used for defining concurrent actions."
14247 "\n\t\t: Camera animation:"
14248 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
14249 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
14250 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
14251 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
14252 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
14253 "\n\t\t: -atX camera Center positions pair"
14254 "\n\t\t: -upX camera Up directions pair"
14255 "\n\t\t: -scaleX camera Scale factors pair"
14256 "\n\t\t: Object animation:"
14257 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
14258 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
14259 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
14260 "\n\t\t: -locX object Location points pair (translation)"
14261 "\n\t\t: -rotX object Orientations pair (quaternions)"
14262 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
14263 "\n\t\t: Custom callback:"
14264 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
14265 "\n\t\t: %Pts overall animation presentation timestamp"
14266 "\n\t\t: %LocalPts local animation timestamp"
14267 "\n\t\t: %Normalized local animation normalized value in range 0..1"
14269 "\n\t\t: Video recording:"
14270 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
14271 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
14272 "\n\t\t: [-crf Value] [-preset Preset]"
14273 "\n\t\t: -fps video framerate"
14274 "\n\t\t: -format file format, container (matroska, etc.)"
14275 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
14276 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
14277 "\n\t\t: -crf constant rate factor (specific to codec)"
14278 "\n\t\t: -preset codec parameters preset (specific to codec)"
14279 __FILE__, VAnimation, group);
14281 theCommands.Add("vchangeselected",
14282 "vchangeselected shape"
14283 "- adds to shape to selection or remove one from it",
14284 __FILE__, VChangeSelected, group);
14285 theCommands.Add ("vnbselected",
14287 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
14288 theCommands.Add ("vcamera",
14289 "vcamera [PrsName] [-ortho] [-projtype]"
14291 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
14292 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
14293 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
14294 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
14295 "\n\t\t: Manages camera parameters."
14296 "\n\t\t: Displays frustum when presntation name PrsName is specified."
14297 "\n\t\t: Prints current value when option called without argument."
14298 "\n\t\t: Orthographic camera:"
14299 "\n\t\t: -ortho activate orthographic projection"
14300 "\n\t\t: Perspective camera:"
14301 "\n\t\t: -persp activate perspective projection (mono)"
14302 "\n\t\t: -fovy field of view in y axis, in degrees"
14303 "\n\t\t: -distance distance of eye from camera center"
14304 "\n\t\t: Stereoscopic camera:"
14305 "\n\t\t: -stereo perspective projection (stereo)"
14306 "\n\t\t: -leftEye perspective projection (left eye)"
14307 "\n\t\t: -rightEye perspective projection (right eye)"
14308 "\n\t\t: -iod intraocular distance value"
14309 "\n\t\t: -iodType distance type, absolute or relative"
14310 "\n\t\t: -zfocus stereographic focus value"
14311 "\n\t\t: -zfocusType focus type, absolute or relative",
14312 __FILE__, VCamera, group);
14313 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
14314 "- vautozfit [on={1|0}] [scale]\n"
14315 " Prints or changes parameters of automatic z-fit mode:\n"
14316 " \"on\" - turns automatic z-fit on or off\n"
14317 " \"scale\" - specifies factor to scale computed z range.\n",
14318 __FILE__, VAutoZFit, group);
14319 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
14320 " vzrange - without parameters shows current values\n"
14321 " vzrange [znear] [zfar] - applies provided values to view",
14322 __FILE__,VZRange, group);
14323 theCommands.Add ("vpurgedisplay",
14325 "- removes structures which don't belong to objects displayed in neutral point",
14326 __FILE__, VPurgeDisplay, group);
14327 theCommands.Add("vsetviewsize",
14328 "vsetviewsize size",
14329 __FILE__,VSetViewSize,group);
14330 theCommands.Add("vmoveview",
14331 "vmoveview Dx Dy Dz [Start = 1|0]",
14332 __FILE__,VMoveView,group);
14333 theCommands.Add("vtranslateview",
14334 "vtranslateview Dx Dy Dz [Start = 1|0)]",
14335 __FILE__,VTranslateView,group);
14336 theCommands.Add("vturnview",
14337 "vturnview Ax Ay Az [Start = 1|0]",
14338 __FILE__,VTurnView,group);
14339 theCommands.Add("vtextureenv",
14340 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
14341 "or user-defined file and optionally applying texture mapping parameters\n"
14343 " vtextureenv off - disables environment mapping\n"
14344 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
14345 " std_texture = (0..7)\n"
14346 " rep = {clamp|repeat}\n"
14347 " mod = {decal|modulate}\n"
14348 " flt = {nearest|bilinear|trilinear}\n"
14349 " ss, st - scale factors for s and t texture coordinates\n"
14350 " ts, tt - translation for s and t texture coordinates\n"
14351 " rot - texture rotation angle in degrees",
14352 __FILE__, VTextureEnv, group);
14353 theCommands.Add("vhlr",
14354 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
14355 "\n\t\t: Hidden Line Removal algorithm."
14356 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
14357 "\n\t\t: -algoType type of HLR algorithm.\n",
14358 __FILE__,VHLR,group);
14359 theCommands.Add("vhlrtype",
14360 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
14361 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
14362 "\n\t\t: 'algo' - exact HLR algorithm is applied"
14363 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
14364 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
14365 __FILE__,VHLRType,group);
14366 theCommands.Add("vclipplane",
14367 "vclipplane planeName [{0|1}]"
14368 "\n\t\t: [-equation1 A B C D]"
14369 "\n\t\t: [-equation2 A B C D]"
14370 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
14371 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
14372 "\n\t\t: [-maxPlanes]"
14373 "\n\t\t: [-capping {0|1}]"
14374 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
14375 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
14376 "\n\t\t: [-texRotate Angle]"
14377 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
14378 "\n\t\t: [-useObjShader {0|1}]"
14379 "\n\t\t: Clipping planes management:"
14380 "\n\t\t: -maxPlanes print plane limit for view"
14381 "\n\t\t: -delete delete plane with given name"
14382 "\n\t\t: {off|on|0|1} turn clipping on/off"
14383 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
14384 "\n\t\t: applied to active View when list is omitted"
14385 "\n\t\t: -equation A B C D change plane equation"
14386 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
14387 "\n\t\t: Capping options:"
14388 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
14389 "\n\t\t: -color R G B set capping color"
14390 "\n\t\t: -transparency Value set capping transparency 0..1"
14391 "\n\t\t: -texName Texture set capping texture"
14392 "\n\t\t: -texScale SX SY set capping tex scale"
14393 "\n\t\t: -texOrigin TX TY set capping tex origin"
14394 "\n\t\t: -texRotate Angle set capping tex rotation"
14395 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
14396 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
14397 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
14398 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
14399 __FILE__, VClipPlane, group);
14400 theCommands.Add("vdefaults",
14401 "vdefaults [-absDefl value]"
14402 "\n\t\t: [-devCoeff value]"
14403 "\n\t\t: [-angDefl value]"
14404 "\n\t\t: [-autoTriang {off/on | 0/1}]"
14405 , __FILE__, VDefaults, group);
14406 theCommands.Add("vlight",
14407 "tool to manage light sources, without arguments shows list of lights."
14408 "\n Main commands: "
14409 "\n '-clear' to clear lights"
14410 "\n '-{def}aults' to load deafault lights"
14411 "\n '-add' <type> to add any light source"
14412 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
14413 "\n 'change' <lightId> to edit light source with specified lightId"
14414 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
14416 "\n -{pos}ition X Y Z"
14417 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
14418 "\n -color colorName"
14419 "\n -{head}light 0|1"
14420 "\n -{sm}oothness value"
14421 "\n -{int}ensity value"
14422 "\n -{constAtten}uation value"
14423 "\n -{linearAtten}uation value"
14424 "\n -angle angleDeg"
14425 "\n -{spotexp}onent value"
14427 "\n -local|-global"
14428 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
14429 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
14430 __FILE__, VLight, group);
14431 theCommands.Add("vpbrenv",
14432 "vpbrenv -clear|-generate"
14433 "\n\t\t: Clears or generates PBR environment map of active view."
14434 "\n\t\t: -clear clears PBR environment (fills by white color)"
14435 "\n\t\t: -generate generates PBR environment from current background cubemap",
14436 __FILE__, VPBREnvironment, group);
14437 theCommands.Add("vraytrace",
14439 "\n\t\t: Turns on/off ray-tracing renderer."
14440 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
14441 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
14442 __FILE__, VRenderParams, group);
14443 theCommands.Add("vrenderparams",
14444 "\n Manages rendering parameters: "
14445 "\n '-raster' Disables GPU ray-tracing"
14446 "\n '-msaa 0..4' Specifies number of samples for MSAA"
14447 "\n '-lineFeather > 0' Sets line feather factor"
14448 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
14449 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
14450 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
14451 "\n '-rendScale value Rendering resolution scale factor"
14452 "\n '-rayTrace' Enables GPU ray-tracing"
14453 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
14454 "\n '-shadows on|off' Enables/disables shadows rendering"
14455 "\n '-reflections on|off' Enables/disables specular reflections"
14456 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
14457 "\n '-gleam on|off' Enables/disables transparency shadow effects"
14458 "\n '-gi on|off' Enables/disables global illumination effects"
14459 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
14460 "\n '-env on|off' Enables/disables environment map background"
14461 "\n '-ignoreNormalMap on|off' Enables/disables normal map ignoring during path tracing"
14462 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
14463 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
14464 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
14465 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
14466 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
14467 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
14468 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
14469 "\n '-shadingModel model' Controls shading model from enumeration"
14470 "\n unlit, flat, gouraud, phong"
14471 "\n '-pbrEnvPow2size > 0' Controls size of IBL maps (real size can be calculates as 2^pbrenvpow2size)"
14472 "\n '-pbrEnvSMLN > 1' Controls number of mipmap levels used in specular IBL map"
14473 "\n '-pbrEnvBDSN > 0' Controls number of samples in Monte-Carlo integration during diffuse IBL map's sherical harmonics calculation"
14474 "\n '-pbrEnvBSSN > 0' Controls maximum number of samples per mipmap level in Monte-Carlo integration during specular IBL maps generation"
14475 "\n '-pbrEnvBP [0, 1]' Controls strength of samples number reducing during specular IBL maps generation (1 disables reducing)"
14476 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
14477 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
14478 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
14479 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
14480 "\n '-whitepoint value' White point value for filmic tone mapping"
14481 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
14482 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triangles|points"
14483 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
14484 "\n Show/hide performance counters (flags can be combined)"
14485 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
14486 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
14487 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
14488 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
14489 "\n set state to check structures culled previously."
14490 "\n Unlike vcaps, these parameters dramatically change visual properties."
14491 "\n Command is intended to control presentation quality depending on"
14492 "\n hardware capabilities and performance.",
14493 __FILE__, VRenderParams, group);
14494 theCommands.Add("vstatprofiler",
14495 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
14496 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
14497 "\n |triangles|points|geomMem|textureMem|frameMem"
14498 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
14499 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
14501 "\n\t\t: Prints rendering statistics."
14502 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
14503 "\n\t\t: else - print all performance counters set previously."
14504 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
14505 __FILE__, VStatProfiler, group);
14506 theCommands.Add ("vplace",
14508 "\n\t\t: Places the point (in pixels) at the center of the window",
14509 __FILE__, VPlace, group);
14510 theCommands.Add("vxrotate",
14512 __FILE__,VXRotate,group);
14514 theCommands.Add("vmanipulator",
14515 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
14516 "\n tool to create and manage AIS manipulators."
14518 "\n '-attach AISObject' attach manipulator to AISObject"
14519 "\n '-adjustPosition {0|1}' adjust position when attaching"
14520 "\n '-adjustSize {0|1}' adjust size when attaching"
14521 "\n '-enableModes {0|1}' enable modes when attaching"
14522 "\n '-view {active | [name of view]}' display manipulator only in defined view,"
14523 "\n by default it is displayed in all views of the current viewer"
14524 "\n '-detach' detach manipulator"
14525 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
14526 "\n '-transform mouse_x mouse_y' - invoke transformation"
14527 "\n '-stopTransform [abort]' - invoke stop of transformation"
14528 "\n '-move x y z' - move attached object"
14529 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
14530 "\n '-scale factor' - scale attached object"
14531 "\n '-autoActivate {0|1}' - set activation on detection"
14532 "\n '-followTranslation {0|1}' - set following translation transform"
14533 "\n '-followRotation {0|1}' - set following rotation transform"
14534 "\n '-followDragging {0|1}' - set following dragging transform"
14535 "\n '-gap value' - set gap between sub-parts"
14536 "\n '-part axis mode {0|1}' - set visual part"
14537 "\n '-parts axis mode {0|1}' - set visual part"
14538 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
14539 "\n '-size value' - set size of manipulator"
14540 "\n '-zoomable {0|1}' - set zoom persistence",
14541 __FILE__, VManipulator, group);
14543 theCommands.Add("vselprops",
14544 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
14545 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
14546 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
14547 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
14548 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
14549 "\n -pickStrategy {first|topmost} : defines picking strategy"
14550 "\n 'first' to pick first acceptable (default)"
14551 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
14552 "\n -pixTol value : sets up pixel tolerance"
14553 "\n -dispMode dispMode : sets display mode for highlighting"
14554 "\n -layer ZLayer : sets ZLayer for highlighting"
14555 "\n -color {name|r g b} : sets highlight color"
14556 "\n -transp value : sets transparency coefficient for highlight"
14557 "\n -material material : sets highlight material"
14558 "\n -print : prints current state of all mentioned parameters",
14559 __FILE__, VSelectionProperties, group);
14560 theCommands.Add ("vhighlightselected",
14561 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
14562 __FILE__, VSelectionProperties, group);
14564 theCommands.Add ("vseldump",
14565 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
14566 "\n\t\t: Generate an image based on detection results:"
14567 "\n\t\t: depth normalized depth values"
14568 "\n\t\t: unnormDepth unnormalized depth values"
14569 "\n\t\t: object color of detected object"
14570 "\n\t\t: owner color of detected owner"
14571 "\n\t\t: selMode color of selection mode"
14572 "\n\t\t: entity color of etected entity",
14573 __FILE__, VDumpSelectionImage, group);
14575 theCommands.Add ("vviewcube",
14577 "\n\t\t: Displays interactive view manipualtion object."
14578 "\n\t\t: Options: "
14579 "\n\t\t: -reset reset geomertical and visual attributes'"
14580 "\n\t\t: -size Size adapted size of View Cube"
14581 "\n\t\t: -boxSize Size box size"
14582 "\n\t\t: -axes {0|1 } show/hide axes (trihedron)"
14583 "\n\t\t: -edges {0|1} show/hide edges of View Cube"
14584 "\n\t\t: -vertices {0|1} show/hide vertices of View Cube"
14585 "\n\t\t: -Yup {0|1} -Zup {0|1} set Y-up or Z-up view orientation"
14586 "\n\t\t: -color Color color of View Cube"
14587 "\n\t\t: -boxColor Color box color"
14588 "\n\t\t: -boxSideColor Color box sides color"
14589 "\n\t\t: -boxEdgeColor Color box edges color"
14590 "\n\t\t: -boxCornerColor Color box corner color"
14591 "\n\t\t: -textColor Color color of side text of view cube"
14592 "\n\t\t: -innerColor Color inner box color"
14593 "\n\t\t: -transparency Value transparency of object within [0, 1] range"
14594 "\n\t\t: -boxTransparency Value transparency of box within [0, 1] range"
14595 "\n\t\t: -font Name font name"
14596 "\n\t\t: -fontHeight Value font height"
14597 "\n\t\t: -boxFacetExtension Value box facet extension"
14598 "\n\t\t: -boxEdgeGap Value gap between box edges and box sides"
14599 "\n\t\t: -boxEdgeMinSize Value minimal box edge size"
14600 "\n\t\t: -boxCornerMinSize Value minimal box corner size"
14601 "\n\t\t: -axesPadding Value padding between box and arrows"
14602 "\n\t\t: -roundRadius Value relative radius of corners of sides within [0.0, 0.5] range"
14603 "\n\t\t: -axesRadius Value radius of axes of the trihedron"
14604 "\n\t\t: -axesConeRadius Value radius of the cone (arrow) of the trihedron"
14605 "\n\t\t: -axesSphereRadius Value radius of the sphere (central point) of trihedron"
14606 "\n\t\t: -fixedanimation {0|1} uninterruptible animation loop"
14607 "\n\t\t: -duration Seconds animation duration in seconds",
14608 __FILE__, VViewCube, group);