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 variable set of options that are allowed for the old scenario (without any option passed)
420 CommandOptionKeyVariableSet myUnnamedOptionVariableSet;
422 //! the variable set of options that are allowed for setting an environment cubemap as background
423 CommandOptionKeyVariableSet myCubeMapOptionVariableSet;
425 //! the variable set of options that are allowed for setting an image as a background
426 CommandOptionKeyVariableSet myImageOptionVariableSet;
428 //! the variable set of options that are allowed for setting a background image fill type
429 CommandOptionKeyVariableSet myImageModeOptionVariableSet;
431 //! the variable set of options that are allowed for setting a gradient filling for the background
432 CommandOptionKeyVariableSet myGradientOptionVariableSet;
434 //! the variable set of options that are allowed for setting a background gradient filling method
435 CommandOptionKeyVariableSet myGradientModeOptionVariableSet;
437 //! the variable set of options that are allowed for filling a background with a specific color
438 CommandOptionKeyVariableSet myColorOptionVariableSet;
440 //! the variable set of options that are allowed for setting a default background gradient
441 CommandOptionKeyVariableSet myDefaultGradientOptionVariableSet;
443 //! the variable set of options that are allowed for setting a default background color
444 CommandOptionKeyVariableSet myDefaultColorOptionVariableSet;
446 //! the variable set of options that are allowed for printing help
447 CommandOptionKeyVariableSet myHelpOptionVariableSet;
449 //! Adds options to command parser
450 void addOptionsToCommandParser()
452 myImageOptionKey = myCommandParser.AddOption ("imageFile|image|imgFile|img",
453 "filename of image used as background");
454 myImageModeOptionKey = myCommandParser.AddOption (
455 "imageMode|imgMode", "image fill type, should be one of CENTERED, TILED, STRETCH, NONE");
456 myGradientOptionKey = myCommandParser.AddOption ("gradient|grad|gr",
457 "sets background gradient starting and ending colors");
458 myGradientModeOptionKey =
459 myCommandParser.AddOption ("gradientMode|gradMode|gradMd|grMode|grMd",
460 "gradient fill method, should be one of NONE, HOR[IZONTAL], VER[TICAL], "
461 "DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, CORNER4");
462 myColorOptionKey = myCommandParser.AddOption ("color|col", "background color");
463 myDefaultOptionKey = myCommandParser.AddOption ("default|def", "sets background default gradient or color");
465 myCubeMapOptionKey = myCommandParser.AddOption ("cubemap|cmap|cm", "background cubemap");
466 myCubeMapOrderOptionKey = myCommandParser.AddOption ("order|o", "order of sides in one image packed cubemap");
467 myCubeMapInvertedZOptionKey = myCommandParser.AddOption (
468 "invertedz|invz|iz", "whether Z axis is inverted or not during background cubemap rendering");
471 //! Creates option sets used to determine if a passed option set is valid or not
472 void createOptionSets()
474 ViewerTest_CommandOptionKeySet anUnnamedOptionSet;
475 anUnnamedOptionSet.insert (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
476 myUnnamedOptionVariableSet = CommandOptionKeyVariableSet (anUnnamedOptionSet);
478 ViewerTest_CommandOptionKeySet aCubeMapOptionSet;
479 aCubeMapOptionSet.insert (myCubeMapOptionKey);
480 ViewerTest_CommandOptionKeySet aCubeMapAdditionalOptionKeySet;
481 aCubeMapAdditionalOptionKeySet.insert (myCubeMapInvertedZOptionKey);
482 aCubeMapAdditionalOptionKeySet.insert (myCubeMapOrderOptionKey);
483 myCubeMapOptionVariableSet = CommandOptionKeyVariableSet (aCubeMapOptionSet, aCubeMapAdditionalOptionKeySet);
485 ViewerTest_CommandOptionKeySet anImageOptionSet;
486 anImageOptionSet.insert (myImageOptionKey);
487 ViewerTest_CommandOptionKeySet anImageModeOptionSet;
488 anImageModeOptionSet.insert (myImageModeOptionKey);
489 myImageOptionVariableSet = CommandOptionKeyVariableSet (anImageOptionSet, anImageModeOptionSet);
490 myImageModeOptionVariableSet = CommandOptionKeyVariableSet (anImageModeOptionSet);
492 ViewerTest_CommandOptionKeySet aGradientOptionSet;
493 aGradientOptionSet.insert (myGradientOptionKey);
494 ViewerTest_CommandOptionKeySet aGradientModeOptionSet;
495 aGradientModeOptionSet.insert (myGradientModeOptionKey);
496 myGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet);
497 myGradientModeOptionVariableSet = CommandOptionKeyVariableSet (aGradientModeOptionSet);
499 ViewerTest_CommandOptionKeySet aColorOptionSet;
500 aColorOptionSet.insert (myColorOptionKey);
501 myColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet);
503 aGradientOptionSet.insert (myDefaultOptionKey);
504 myDefaultGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet);
505 aColorOptionSet.insert (myDefaultOptionKey);
506 myDefaultColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet);
508 ViewerTest_CommandOptionKeySet aHelpOptionSet;
509 aHelpOptionSet.insert (ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY);
510 myHelpOptionVariableSet = CommandOptionKeyVariableSet (aHelpOptionSet);
513 //! Prepares the command parser. Adds options and creates option sets used to determine
514 //! if a passed option set is valid or not
515 void prepareCommandParser()
517 addOptionsToCommandParser();
521 //! Adds a command description to the command parser
522 //! @param theBackgroundCommand the key of the command which description is added to the command parser
523 void addCommandDescription (const BackgroundCommand theBackgroundCommand)
525 std::string aDescription;
526 bool isMainCommand = false;
527 switch (theBackgroundCommand)
529 case BackgroundCommand_Main:
530 aDescription = "Command: vbackground (changes background or some background settings)";
531 isMainCommand = true;
533 case BackgroundCommand_Image:
534 aDescription = "Command: vsetbg (loads image as a background)";
536 case BackgroundCommand_ImageMode:
537 aDescription = "Command: vsetbgmode (changes background fill type)";
539 case BackgroundCommand_Gradient:
540 aDescription = "Command: vsetgradientbg (mounts gradient background)";
542 case BackgroundCommand_GradientMode:
543 aDescription = "Command: vsetgradientbgmode (changes gradient background fill method)";
545 case BackgroundCommand_Color:
546 aDescription = "Command: vsetcolorbg (sets color background)";
548 case BackgroundCommand_Default:
549 aDescription = "Command: vsetdefaultbg (sets default viewer background gradient or fill color)";
556 aDescription += "\nThis command is obsolete. Use vbackground instead.";
558 myCommandParser.SetDescription (aDescription);
561 //! Check if a viewer is needed to be initialized
562 //! @param theBackgroundCommand the key of the command that changes the background
563 //! @return true if processing was successful, or false otherwise
564 bool checkViewerIsNeeded (const BackgroundCommand theBackgroundCommand) const
566 const bool isMain = (theBackgroundCommand == BackgroundCommand_Main);
567 const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions();
568 const bool aViewerIsNotNeeded =
569 (theBackgroundCommand == BackgroundCommand_Default)
570 || (myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain)
571 || (myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain)
572 || myHelpOptionVariableSet.IsInSet (aUsedOptions);
573 return !aViewerIsNotNeeded;
576 //! Check if a viewer is initialized
577 //! @param theBackgroundCommandName the name of the command that changes the background
578 //! @param theDrawInterpretor the interpreter of the Draw Harness application
579 //! @return true if a viewer is initialized, or false otherwise
580 static bool checkViewerIsInitialized (const char* const theBackgroundCommandName,
581 Draw_Interpretor& theDrawInterpretor)
583 const Handle (AIS_InteractiveContext)& anAISContext = ViewerTest::GetAISContext();
584 if (anAISContext.IsNull())
586 theDrawInterpretor << "Use 'vinit' command before executing '" << theBackgroundCommandName << "' command.\n";
592 //! Processes command options
593 //! @param theBackgroundCommandName the name of the command that changes the background
594 //! @param theBackgroundCommand the key of the command that changes the background
595 //! @param theDrawInterpretor the interpreter of the Draw Harness application
596 //! @return true if processing was successful, or false otherwise
597 bool processCommandOptions (const char* const theBackgroundCommandName,
598 const BackgroundCommand theBackgroundCommand,
599 Draw_Interpretor& theDrawInterpretor) const
601 if (myCommandParser.HasNoOption())
603 return printHelp (theBackgroundCommandName, theDrawInterpretor);
605 if (checkViewerIsNeeded (theBackgroundCommand)
606 && !checkViewerIsInitialized (theBackgroundCommandName, theDrawInterpretor))
610 if (myCommandParser.HasOnlyUnnamedOption())
612 return processUnnamedOption (theBackgroundCommand);
614 return processNamedOptions (theBackgroundCommandName, theBackgroundCommand, theDrawInterpretor);
617 //! Processes the unnamed option
618 //! @param theBackgroundCommand the key of the command that changes the background
619 //! @return true if processing was successful, or false otherwise
620 bool processUnnamedOption (const BackgroundCommand theBackgroundCommand) const
622 switch (theBackgroundCommand)
624 case BackgroundCommand_Main:
626 case BackgroundCommand_Image:
627 return processImageUnnamedOption();
628 case BackgroundCommand_ImageMode:
629 return processImageModeUnnamedOption();
630 case BackgroundCommand_Gradient:
631 return processGradientUnnamedOption();
632 case BackgroundCommand_GradientMode:
633 return processGradientModeUnnamedOption();
634 case BackgroundCommand_Color:
635 return processColorUnnamedOption();
636 case BackgroundCommand_Default:
637 return processDefaultUnnamedOption();
643 //! Processes the image unnamed option
644 //! @return true if processing was successful, or false otherwise
645 bool processImageUnnamedOption() const
647 const std::size_t aNumberOfImageUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments (
648 ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
649 if ((aNumberOfImageUnnamedOptionArguments != 1) && (aNumberOfImageUnnamedOptionArguments != 2))
653 std::string anImageFileName;
654 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0, anImageFileName))
658 Aspect_FillMethod anImageMode = Aspect_FM_CENTERED;
659 if (aNumberOfImageUnnamedOptionArguments == 2)
661 std::string anImageModeString;
662 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 1, anImageModeString))
666 if (!getBackgroundImageFillMethodByName (anImageModeString.c_str(), anImageMode))
671 setImage (anImageFileName.c_str(), anImageMode);
675 //! Processes the image mode unnamed option
676 //! @return true if processing was successful, or false otherwise
677 bool processImageModeUnnamedOption() const
679 return processImageModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
682 //! Processes the gradient unnamed option
683 //! @param theSetGradient the function used to set a background gradient filling
684 //! @return true if processing was successful, or false otherwise
685 bool processGradientUnnamedOption (SetGradientFunction* const theSetGradient = setGradient) const
687 const Standard_Integer aNumberOfGradientUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments (
688 ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
689 if (aNumberOfGradientUnnamedOptionArguments < 2)
694 Standard_Integer anArgumentIndex = 0;
695 Quantity_Color aColor1;
696 if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor1))
700 if (anArgumentIndex >= aNumberOfGradientUnnamedOptionArguments)
705 Quantity_Color aColor2;
706 if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor2))
710 if (anArgumentIndex > aNumberOfGradientUnnamedOptionArguments)
715 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR;
716 if (anArgumentIndex == aNumberOfGradientUnnamedOptionArguments - 1)
718 std::string anGradientModeString;
720 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY,
722 anGradientModeString))
726 if (!getBackgroundGradientFillMethodByName (anGradientModeString.c_str(), aGradientMode))
732 if (anArgumentIndex != aNumberOfGradientUnnamedOptionArguments)
736 theSetGradient (aColor1, aColor2, aGradientMode);
740 //! Processes the gradient mode unnamed option
741 //! @return true if processing was successful, or false otherwise
742 bool processGradientModeUnnamedOption() const
744 return processGradientModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
747 //! Processes the color unnamed option
748 //! @param theSetColor the function used to set a background color
749 //! @return true if processing was successful, or false otherwise
750 bool processColorUnnamedOption (SetColorFunction* const theSetColor = setColor) const
752 return processColorOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, theSetColor);
755 //! Processes the default back unnamed option
756 //! @return true if processing was successful, or false otherwise
757 bool processDefaultUnnamedOption() const
759 if (processGradientUnnamedOption (setDefaultGradient))
763 return processColorUnnamedOption (setDefaultColor);
766 //! Processes named options
767 //! @param theBackgroundCommandName the name of the command that changes the background
768 //! @param theBackgroundCommand the key of the command that changes the background
769 //! @param theDrawInterpretor the interpreter of the Draw Harness application
770 //! @return true if processing was successful, or false otherwise
771 bool processNamedOptions (const char* const theBackgroundCommandName,
772 const BackgroundCommand theBackgroundCommand,
773 Draw_Interpretor& theDrawInterpretor) const
775 const bool isMain = (theBackgroundCommand == BackgroundCommand_Main);
776 const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions();
777 if (myCubeMapOptionVariableSet.IsInSet (aUsedOptions) && isMain)
779 return processCubeMapOptionSet();
781 if (myImageOptionVariableSet.IsInSet (aUsedOptions)
782 && (isMain || (theBackgroundCommand == BackgroundCommand_Image)))
784 return processImageOptionSet();
786 if (myImageModeOptionVariableSet.IsInSet (aUsedOptions)
787 && (isMain || (theBackgroundCommand == BackgroundCommand_ImageMode)))
789 return processImageModeOptionSet();
791 if (myGradientOptionVariableSet.IsInSet (aUsedOptions)
792 && (isMain || (theBackgroundCommand == BackgroundCommand_Gradient)))
794 return processGradientOptionSet();
796 if (myGradientModeOptionVariableSet.IsInSet (aUsedOptions)
797 && (isMain || (theBackgroundCommand == BackgroundCommand_GradientMode)))
799 return processGradientModeOptionSet();
801 if (myColorOptionVariableSet.IsInSet (aUsedOptions)
802 && (isMain || (theBackgroundCommand == BackgroundCommand_Color)))
804 return processColorOptionSet();
806 if ((myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain)
807 || (myGradientOptionVariableSet.IsInSet (aUsedOptions)
808 && (theBackgroundCommand == BackgroundCommand_Default)))
810 return processDefaultGradientOptionSet();
812 if ((myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain)
813 || (myColorOptionVariableSet.IsInSet (aUsedOptions) && (theBackgroundCommand == BackgroundCommand_Default)))
815 return processDefaultColorOptionSet();
817 if (myHelpOptionVariableSet.IsInSet (aUsedOptions))
819 return processHelpOptionSet (theBackgroundCommandName, theDrawInterpretor);
824 //! Process the cubemap option set in named and unnamed case.
825 //! @return true if processing was successful, or false otherwise
826 bool processCubeMapOptionSet() const
828 NCollection_Array1<TCollection_AsciiString> aFilePaths;
830 if (!processCubeMapOptions (aFilePaths))
835 Graphic3d_CubeMapOrder anOrder = Graphic3d_CubeMapOrder::Default();
837 if (myCommandParser.HasOption (myCubeMapOrderOptionKey))
839 if (!processCubeMapOrderOptions (anOrder))
845 bool aZIsInverted = false;
846 if (myCommandParser.HasOption (myCubeMapInvertedZOptionKey))
848 if (!processCubeMapInvertedZOptionSet())
855 setCubeMap (aFilePaths, anOrder.Validated(), aZIsInverted);
859 //! Processes the image option set
860 //! @return true if processing was successful, or false otherwise
861 bool processImageOptionSet() const
863 std::string anImageFileName;
864 if (!processImageOption (anImageFileName))
868 Aspect_FillMethod anImageMode = Aspect_FM_CENTERED;
869 if (myCommandParser.HasOption (myImageModeOptionKey) && !processImageModeOption (anImageMode))
873 setImage (anImageFileName.c_str(), anImageMode);
877 //! Processes the image mode option set
878 //! @return true if processing was successful, or false otherwise
879 bool processImageModeOptionSet() const
881 return processImageModeOptionSet (myImageModeOptionKey);
884 //! Processes the image mode option set
885 //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option
886 //! @return true if processing was successful, or false otherwise
887 bool processImageModeOptionSet (const ViewerTest_CommandOptionKey theImageModeOptionKey) const
889 Aspect_FillMethod anImageMode = Aspect_FM_NONE;
890 if (!processImageModeOption (theImageModeOptionKey, anImageMode))
894 setImageMode (anImageMode);
898 //! Processes the gradient option set
899 //! @param theSetGradient the function used to set a background gradient filling
900 //! @return true if processing was successful, or false otherwise
901 bool processGradientOptionSet (SetGradientFunction* const theSetGradient = setGradient) const
903 Quantity_Color aColor1;
904 Quantity_Color aColor2;
905 if (!processGradientOption (aColor1, aColor2))
909 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR;
910 if (myCommandParser.HasOption (myGradientModeOptionKey) && !processGradientModeOption (aGradientMode))
914 theSetGradient (aColor1, aColor2, aGradientMode);
918 //! Processes the gradient mode option set
919 //! @return true if processing was successful, or false otherwise
920 bool processGradientModeOptionSet() const
922 return processGradientModeOptionSet (myGradientModeOptionKey);
925 //! Processes the gradient mode option set
926 //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option
927 //! @return true if processing was successful, or false otherwise
928 bool processGradientModeOptionSet (const ViewerTest_CommandOptionKey theGradientModeOptionKey) const
930 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_NONE;
931 if (!processGradientModeOption (theGradientModeOptionKey, aGradientMode))
935 setGradientMode (aGradientMode);
939 //! Processes the color option set
940 //! @param theSetColor the function used to set a background color
941 //! @return true if processing was successful, or false otherwise
942 bool processColorOptionSet (SetColorFunction* const theSetColor = setColor) const
944 return processColorOptionSet (myColorOptionKey, theSetColor);
947 //! Processes the default color option set
948 //! @return true if processing was successful, or false otherwise
949 bool processDefaultGradientOptionSet() const
951 return processGradientOptionSet (setDefaultGradient);
954 //! Processes the default gradient option set
955 //! @return true if processing was successful, or false otherwise
956 bool processDefaultColorOptionSet() const
958 return processColorOptionSet (setDefaultColor);
961 //! Processes the color option set
962 //! @param theColorOptionKey the key of the option that is interpreted as a color option
963 //! @param theSetColor the function used to set a background color
964 //! @return true if processing was successful, or false otherwise
965 bool processColorOptionSet (const ViewerTest_CommandOptionKey theColorOptionKey,
966 SetColorFunction* const theSetColor = setColor) const
968 Quantity_Color aColor;
969 if (!processColorOption (theColorOptionKey, aColor))
973 theSetColor (aColor);
977 //! Processes the help option set
978 //! @param theBackgroundCommandName the name of the command that changes the background
979 //! @param theDrawInterpretor the interpreter of the Draw Harness application
980 //! @return true if processing was successful, or false otherwise
981 bool processHelpOptionSet (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor) const
983 const Standard_Integer aNumberOfHelpOptionArguments = myCommandParser.GetNumberOfOptionArguments (
984 ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY);
985 if (aNumberOfHelpOptionArguments != 0)
989 return printHelp (theBackgroundCommandName, theDrawInterpretor);
992 //! Processes the cubemap option
993 //! @param theFilePaths the array of filenames of cubemap sides
994 //! @return true if processing was successful, or false otherwise
995 bool processCubeMapOptions (NCollection_Array1<TCollection_AsciiString> &theFilePaths) const
997 const Standard_Integer aNumberOfCubeMapOptionArguments = myCommandParser.GetNumberOfOptionArguments (myCubeMapOptionKey);
999 if (aNumberOfCubeMapOptionArguments != 1
1000 && aNumberOfCubeMapOptionArguments != 6)
1005 theFilePaths.Resize(0, aNumberOfCubeMapOptionArguments - 1, Standard_False);
1007 for (int i = 0; i < aNumberOfCubeMapOptionArguments; ++i)
1009 std::string aCubeMapFileName;
1010 if (!myCommandParser.Arg (myCubeMapOptionKey, i, aCubeMapFileName))
1014 theFilePaths[i] = aCubeMapFileName.c_str();
1020 //! Processes the cubemap option
1021 //! @param theIsNeededToRedraw defines need of redraw after option's processing
1022 //! @return true if processing was successful, or false otherwise
1023 bool processCubeMapInvertedZOptionSet () const
1025 const Standard_Integer aNumberOfCubeMapZInversionOptionArguments =
1026 myCommandParser.GetNumberOfOptionArguments (myCubeMapInvertedZOptionKey);
1028 if (aNumberOfCubeMapZInversionOptionArguments != 0)
1036 //! Processes the tiles order option
1037 //! @param theOrder the array of indexes if cubemap sides in tile grid
1038 //! @return true if processing was successful, or false otherwise
1039 bool processCubeMapOrderOptions (Graphic3d_CubeMapOrder& theOrder) const
1041 const Standard_Integer aNumberOfCubeMapOrderOptionArguments = myCommandParser.GetNumberOfOptionArguments(
1042 myCubeMapOrderOptionKey);
1044 if (aNumberOfCubeMapOrderOptionArguments != 6)
1050 for (unsigned int i = 0; i < 6; ++i)
1052 std::string anOrderItem;
1053 if (!myCommandParser.Arg (myCubeMapOrderOptionKey, i, anOrderItem))
1058 theOrder.Set (Graphic3d_CubeMapSide (i),
1059 static_cast<unsigned char> (Draw::Atoi (anOrderItem.c_str())));
1062 return theOrder.IsValid();
1065 //! Processes the image option
1066 //! @param theImageFileName the filename of the image to be used as a background
1067 //! @return true if processing was successful, or false otherwise
1068 bool processImageOption (std::string& theImageFileName) const
1070 const Standard_Integer aNumberOfImageOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1072 if (aNumberOfImageOptionArguments != 1)
1076 std::string anImageFileName;
1077 if (!myCommandParser.Arg (myImageOptionKey, 0, anImageFileName))
1081 theImageFileName = anImageFileName;
1085 //! Processes the image mode option
1086 //! @param theImageMode the fill type used for a background image
1087 //! @return true if processing was successful, or false otherwise
1088 bool processImageModeOption (Aspect_FillMethod& theImageMode) const
1090 return processImageModeOption (myImageModeOptionKey, theImageMode);
1093 //! Processes the image mode option
1094 //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option
1095 //! @param theImageMode the fill type used for a background image
1096 //! @return true if processing was successful, or false otherwise
1097 bool processImageModeOption (const ViewerTest_CommandOptionKey theImageModeOptionKey,
1098 Aspect_FillMethod& theImageMode) const
1100 return processModeOption (theImageModeOptionKey, getBackgroundImageFillMethodByName, theImageMode);
1103 //! Processes the gradient option
1104 //! @param theColor1 the gradient starting color
1105 //! @param theColor2 the gradient ending color
1106 //! @return true if processing was successful, or false otherwise
1107 bool processGradientOption (Quantity_Color& theColor1, Quantity_Color& theColor2) const
1109 Standard_Integer anArgumentIndex = 0;
1110 Quantity_Color aColor1;
1111 if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor1))
1115 Quantity_Color aColor2;
1116 if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor2))
1120 const Standard_Integer aNumberOfGradientOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1121 myGradientOptionKey);
1122 if (anArgumentIndex != aNumberOfGradientOptionArguments)
1126 theColor1 = aColor1;
1127 theColor2 = aColor2;
1131 //! Processes the gradient mode option
1132 //! @param theGradientMode the fill method used for a background gradient filling
1133 //! @return true if processing was successful, or false otherwise
1134 bool processGradientModeOption (Aspect_GradientFillMethod& theGradientMode) const
1136 return processGradientModeOption (myGradientModeOptionKey, theGradientMode);
1139 //! Processes the gradient mode option
1140 //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option
1141 //! @param theGradientMode the fill method used for a background gradient filling
1142 //! @return true if processing was successful, or false otherwise
1143 bool processGradientModeOption (const ViewerTest_CommandOptionKey theGradientModeOptionKey,
1144 Aspect_GradientFillMethod& theGradientMode) const
1146 return processModeOption (theGradientModeOptionKey, getBackgroundGradientFillMethodByName, theGradientMode);
1149 //! Processes some mode option
1150 //! @tparam TheMode the type of a mode to be processed
1151 //! @param theModeOptionKey the key of the option that is interpreted as a mode option
1152 //! @param theMode a mode to be processed
1153 //! @return true if processing was successful, or false otherwise
1154 template <typename TheMode>
1155 bool processModeOption (const ViewerTest_CommandOptionKey theModeOptionKey,
1156 bool (*const theGetModeByName) (const TCollection_AsciiString& /* theModeName */,
1157 TheMode& /* theMode */),
1158 TheMode& theMode) const
1160 const Standard_Integer aNumberOfModeOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1162 if (aNumberOfModeOptionArguments != 1)
1166 std::string aModeString;
1167 if (!myCommandParser.Arg (theModeOptionKey, 0, aModeString))
1171 TheMode aMode = TheMode();
1172 if (!theGetModeByName (aModeString.c_str(), aMode))
1180 //! Processes the color option
1181 //! @param theColor a color used for filling a background
1182 //! @return true if processing was successful, or false otherwise
1183 bool processColorOption (Quantity_Color& theColor) const
1185 return processColorOption (myColorOptionKey, theColor);
1188 //! Processes the color option
1189 //! @param theColorOptionKey the key of the option that is interpreted as a color option
1190 //! @param theColor a color used for filling a background
1191 //! @return true if processing was successful, or false otherwise
1192 bool processColorOption (const ViewerTest_CommandOptionKey theColorOptionKey, Quantity_Color& theColor) const
1194 Standard_Integer anArgumentIndex = 0;
1195 Quantity_Color aColor;
1196 if (!myCommandParser.ArgColor (theColorOptionKey, anArgumentIndex, aColor))
1200 const Standard_Integer aNumberOfColorOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1202 if (anArgumentIndex != aNumberOfColorOptionArguments)
1210 //! Prints helping message
1211 //! @param theBackgroundCommandName the name of the command that changes the background
1212 //! @param theDrawInterpretor the interpreter of the Draw Harness application
1213 //! @return true if printing was successful, or false otherwise
1214 static bool printHelp (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor)
1216 return theDrawInterpretor.PrintHelp (theBackgroundCommandName) == TCL_OK;
1219 //! Sets the cubemap as a background
1220 //! @param theFileNames the array of filenames of packed or multifile cubemap
1221 //! @param theOrder array of cubemap sides indexes mapping them from tiles in packed cubemap
1222 static void setCubeMap (const NCollection_Array1<TCollection_AsciiString>& theFileNames,
1223 const Graphic3d_ValidatedCubeMapOrder theOrder = Graphic3d_CubeMapOrder::Default(),
1224 bool theZIsInverted = false)
1226 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
1227 Handle(Graphic3d_CubeMap) aCubeMap;
1229 if (theFileNames.Size() == 1)
1230 aCubeMap = new Graphic3d_CubeMapPacked(theFileNames[0], theOrder);
1232 aCubeMap = new Graphic3d_CubeMapSeparate(theFileNames);
1234 aCubeMap->SetZInversion (theZIsInverted);
1236 aCubeMap->GetParams()->SetFilter(Graphic3d_TOTF_BILINEAR);
1237 aCubeMap->GetParams()->SetRepeat(Standard_False);
1238 aCubeMap->GetParams()->SetTextureUnit(Graphic3d_TextureUnit_EnvMap);
1240 aCurrentView->SetBackgroundCubeMap (aCubeMap, Standard_True);
1243 //! Sets the image as a background
1244 //! @param theImageFileName the filename of the image to be used as a background
1245 //! @param theImageMode the fill type used for a background image
1246 static void setImage (const Standard_CString theImageFileName, const Aspect_FillMethod theImageMode)
1248 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1249 aCurrentView->SetBackgroundImage (theImageFileName, theImageMode, Standard_True);
1252 //! Sets the fill type used for a background image
1253 //! @param theImageMode the fill type used for a background image
1254 static void setImageMode (const Aspect_FillMethod theImageMode)
1256 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1257 aCurrentView->SetBgImageStyle (theImageMode, Standard_True);
1260 //! Sets the gradient filling for a background
1261 //! @param theColor1 the gradient starting color
1262 //! @param theColor2 the gradient ending color
1263 //! @param theGradientMode the fill method used for a background gradient filling
1264 static void setGradient (const Quantity_Color& theColor1,
1265 const Quantity_Color& theColor2,
1266 const Aspect_GradientFillMethod theGradientMode)
1268 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1269 aCurrentView->SetBgGradientColors (theColor1, theColor2, theGradientMode, Standard_True);
1272 //! Sets the fill method used for a background gradient filling
1273 //! @param theGradientMode the fill method used for a background gradient filling
1274 static void setGradientMode (const Aspect_GradientFillMethod theGradientMode)
1276 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1277 aCurrentView->SetBgGradientStyle (theGradientMode, Standard_True);
1280 //! Sets the color used for filling a background
1281 //! @param theColor the color used for filling a background
1282 static void setColor (const Quantity_Color& theColor)
1284 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1285 aCurrentView->SetBgGradientStyle (Aspect_GFM_NONE);
1286 aCurrentView->SetBackgroundColor (theColor);
1287 aCurrentView->Update();
1290 //! Sets the gradient filling for a background in a default viewer
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 setDefaultGradient (const Quantity_Color& theColor1,
1295 const Quantity_Color& theColor2,
1296 const Aspect_GradientFillMethod theGradientMode)
1298 ViewerTest_DefaultBackground.GradientColor1 = theColor1;
1299 ViewerTest_DefaultBackground.GradientColor2 = theColor2;
1300 ViewerTest_DefaultBackground.FillMethod = theGradientMode;
1301 setDefaultGradient();
1304 //! Sets the color used for filling a background in a default viewer
1305 //! @param theColor the color used for filling a background
1306 static void setDefaultColor (const Quantity_Color& theColor)
1308 ViewerTest_DefaultBackground.GradientColor1 = Quantity_Color();
1309 ViewerTest_DefaultBackground.GradientColor2 = Quantity_Color();
1310 ViewerTest_DefaultBackground.FillMethod = Aspect_GFM_NONE;
1311 ViewerTest_DefaultBackground.FlatColor = theColor;
1312 setDefaultGradient();
1316 //! Sets the gradient filling for a background in a default viewer.
1317 //! Gradient settings are taken from ViewerTest_DefaultBackground structure
1318 static void setDefaultGradient()
1320 for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator
1321 anInteractiveContextIterator (ViewerTest_myContexts);
1322 anInteractiveContextIterator.More();
1323 anInteractiveContextIterator.Next())
1325 const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer();
1326 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
1327 ViewerTest_DefaultBackground.GradientColor2,
1328 ViewerTest_DefaultBackground.FillMethod);
1332 //! Sets the color used for filling a background in a default viewer.
1333 //! The color value is taken from ViewerTest_DefaultBackground structure
1334 static void setDefaultColor()
1336 for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator
1337 anInteractiveContextIterator (ViewerTest_myContexts);
1338 anInteractiveContextIterator.More();
1339 anInteractiveContextIterator.Next())
1341 const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer();
1342 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
1349 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
1351 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
1353 static ViewerTest_MapOfAISManipulators aMap;
1357 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
1359 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
1360 for (; anIt.More(); anIt.Next())
1362 if (anIt.Value()->HasActiveMode())
1364 return anIt.Value();
1370 //==============================================================================
1373 static LRESULT WINAPI ViewerWindowProc(
1378 static LRESULT WINAPI AdvViewerWindowProc(
1386 //==============================================================================
1389 //==============================================================================
1391 const Handle(Standard_Transient)& ViewerTest::WClass()
1393 static Handle(Standard_Transient) theWClass;
1395 if (theWClass.IsNull())
1397 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
1398 CS_VREDRAW | CS_HREDRAW, 0, 0,
1399 ::LoadCursor (NULL, IDC_ARROW));
1405 //==============================================================================
1406 //function : CreateName
1407 //purpose : Create numerical name for new object in theMap
1408 //==============================================================================
1409 template <typename ObjectType>
1410 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
1411 const TCollection_AsciiString& theDefaultString)
1413 if (theObjectMap.IsEmpty())
1414 return theDefaultString + TCollection_AsciiString(1);
1416 Standard_Integer aNextKey = 1;
1417 Standard_Boolean isFound = Standard_False;
1420 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
1421 // Look for objects with default names
1422 if (theObjectMap.IsBound1(aStringKey))
1427 isFound = Standard_True;
1430 return theDefaultString + TCollection_AsciiString(aNextKey);
1433 //==============================================================================
1434 //structure : ViewerTest_Names
1435 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
1436 //==============================================================================
1437 struct ViewerTest_Names
1440 TCollection_AsciiString myDriverName;
1441 TCollection_AsciiString myViewerName;
1442 TCollection_AsciiString myViewName;
1446 const TCollection_AsciiString& GetDriverName () const
1448 return myDriverName;
1450 void SetDriverName (const TCollection_AsciiString& theDriverName)
1452 myDriverName = theDriverName;
1454 const TCollection_AsciiString& GetViewerName () const
1456 return myViewerName;
1458 void SetViewerName (const TCollection_AsciiString& theViewerName)
1460 myViewerName = theViewerName;
1462 const TCollection_AsciiString& GetViewName () const
1466 void SetViewName (const TCollection_AsciiString& theViewName)
1468 myViewName = theViewName;
1471 //===========================================================================
1472 //function : Constructor for ViewerTest_Names
1473 //purpose : Get view, viewer, driver names from custom string
1474 //===========================================================================
1476 ViewerTest_Names (const TCollection_AsciiString& theInputString)
1478 TCollection_AsciiString aName(theInputString);
1479 if (theInputString.IsEmpty())
1481 // Get current configuration
1482 if (ViewerTest_myDrivers.IsEmpty())
1483 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1484 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1486 myDriverName = ViewerTest_myDrivers.Find2
1487 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1489 if(ViewerTest_myContexts.IsEmpty())
1491 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
1492 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
1496 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
1499 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
1503 // There is at least view name
1504 Standard_Integer aParserNumber = 0;
1505 for (Standard_Integer i = 0; i < 3; ++i)
1507 Standard_Integer aParserPos = aName.SearchFromEnd("/");
1508 if(aParserPos != -1)
1511 aName.Split(aParserPos-1);
1516 if (aParserNumber == 0)
1519 if (!ViewerTest::GetAISContext().IsNull())
1521 myDriverName = ViewerTest_myDrivers.Find2
1522 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1523 myViewerName = ViewerTest_myContexts.Find2
1524 (ViewerTest::GetAISContext());
1528 // There is no opened contexts here, need to create names for viewer and driver
1529 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1530 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1532 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
1533 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
1535 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
1537 else if (aParserNumber == 1)
1539 // Here is viewerName/viewName
1540 if (!ViewerTest::GetAISContext().IsNull())
1541 myDriverName = ViewerTest_myDrivers.Find2
1542 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1545 // There is no opened contexts here, need to create name for driver
1546 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1547 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1549 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
1551 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
1555 //Here is driverName/viewerName/viewName
1556 myDriverName = TCollection_AsciiString(aName);
1558 TCollection_AsciiString aViewerName(theInputString);
1559 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
1560 myViewerName = TCollection_AsciiString(aViewerName);
1562 myViewName = TCollection_AsciiString(theInputString);
1568 //==============================================================================
1569 //function : FindContextByView
1570 //purpose : Find AIS_InteractiveContext by View
1571 //==============================================================================
1573 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
1575 Handle(AIS_InteractiveContext) anAISContext;
1577 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1578 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
1580 if (anIter.Value()->CurrentViewer() == theView->Viewer())
1581 return anIter.Key2();
1583 return anAISContext;
1586 //==============================================================================
1587 //function : IsWindowOverlapped
1588 //purpose : Check if theWindow overlapp another view
1589 //==============================================================================
1591 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
1592 const Standard_Integer thePxTop,
1593 const Standard_Integer thePxRight,
1594 const Standard_Integer thePxBottom,
1595 TCollection_AsciiString& theViewId)
1597 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1598 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1600 Standard_Integer aTop = 0,
1604 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
1605 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
1606 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
1607 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
1608 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
1610 theViewId = anIter.Key1();
1611 return Standard_True;
1614 return Standard_False;
1617 // Workaround: to create and delete non-orthographic views outside ViewerTest
1618 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
1620 ViewerTest_myViews.UnBind1 (theName);
1623 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
1624 const Handle(V3d_View)& theView)
1626 ViewerTest_myViews.Bind (theName, theView);
1629 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
1631 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
1634 //! Auxiliary tool performing continuous redraws of specified window.
1635 class ViewerTest_ContinuousRedrawer
1638 //! Return global instance.
1639 static ViewerTest_ContinuousRedrawer& Instance()
1641 static ViewerTest_ContinuousRedrawer aRedrawer;
1647 ~ViewerTest_ContinuousRedrawer()
1653 void Start (const Handle(Aspect_Window)& theWindow,
1654 Standard_Real theTargetFps)
1656 if (myWindow != theWindow
1657 || myTargetFps != theTargetFps)
1660 myWindow = theWindow;
1661 myTargetFps = theTargetFps;
1663 if (myThread.GetId() == 0)
1666 myThread.Run (this);
1671 void Stop (const Handle(Aspect_Window)& theWindow = NULL)
1673 if (!theWindow.IsNull()
1674 && myWindow != theWindow)
1680 Standard_Mutex::Sentry aLock (myMutex);
1693 Handle(Aspect_DisplayConnection) aDisp = new Aspect_DisplayConnection();
1696 Standard_Real aTimeOld = 0.0;
1697 const Standard_Real aTargetDur = myTargetFps > 0.0 ? 1.0 / myTargetFps : -1.0;
1701 Standard_Mutex::Sentry aLock (myMutex);
1707 if (myTargetFps > 0.0)
1709 const Standard_Real aTimeNew = aTimer.ElapsedTime();
1710 const Standard_Real aDuration = aTimeNew - aTimeOld;
1711 if (aDuration >= aTargetDur)
1713 myWindow->InvalidateContent (aDisp);
1714 aTimeOld = aTimeNew;
1719 myWindow->InvalidateContent (aDisp);
1722 OSD::MilliSecSleep (1);
1726 //! Thread creation callback.
1727 static Standard_Address doThreadWrapper (Standard_Address theData)
1729 ViewerTest_ContinuousRedrawer* aThis = (ViewerTest_ContinuousRedrawer* )theData;
1730 aThis->doThreadLoop();
1734 //! Empty constructor.
1735 ViewerTest_ContinuousRedrawer()
1736 : myThread (doThreadWrapper),
1741 Handle(Aspect_Window) myWindow;
1742 OSD_Thread myThread;
1743 Standard_Mutex myMutex;
1744 Standard_Real myTargetFps;
1745 volatile bool myToStop;
1748 //==============================================================================
1749 //function : ViewerInit
1750 //purpose : Create the window viewer and initialize all the global variable
1751 //==============================================================================
1753 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
1754 const Standard_Integer thePxTop,
1755 const Standard_Integer thePxWidth,
1756 const Standard_Integer thePxHeight,
1757 const TCollection_AsciiString& theViewName,
1758 const TCollection_AsciiString& theDisplayName,
1759 const Handle(V3d_View)& theViewToClone)
1761 // Default position and dimension of the viewer window.
1762 // Note that left top corner is set to be sufficiently small to have
1763 // window fit in the small screens (actual for remote desktops, see #23003).
1764 // The position corresponds to the window's client area, thus some
1765 // gap is added for window frame to be visible.
1766 Standard_Integer aPxLeft = 20;
1767 Standard_Integer aPxTop = 40;
1768 Standard_Integer aPxWidth = 409;
1769 Standard_Integer aPxHeight = 409;
1770 Standard_Boolean toCreateViewer = Standard_False;
1771 if (!theViewToClone.IsNull())
1773 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
1776 Handle(OpenGl_GraphicDriver) aGraphicDriver;
1777 ViewerTest_Names aViewNames(theViewName);
1778 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
1779 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
1782 aPxLeft = thePxLeft;
1785 if (thePxWidth != 0)
1786 aPxWidth = thePxWidth;
1787 if (thePxHeight != 0)
1788 aPxHeight = thePxHeight;
1790 // Get graphic driver (create it or get from another view)
1791 const bool isNewDriver = !ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName());
1794 // Get connection string
1795 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1796 if (!theDisplayName.IsEmpty())
1798 SetDisplayConnection (new Aspect_DisplayConnection (theDisplayName));
1802 ::Display* aDispX = NULL;
1803 // create dedicated display connection instead of reusing Tk connection
1804 // so that to procede events independently through VProcessEvents()/ViewerMainLoop() callbacks
1805 /*Draw_Interpretor& aCommands = Draw::GetInterpretor();
1806 Tcl_Interp* aTclInterp = aCommands.Interp();
1807 Tk_Window aMainWindow = Tk_MainWindow (aTclInterp);
1808 aDispX = aMainWindow != NULL ? Tk_Display (aMainWindow) : NULL;*/
1809 SetDisplayConnection (new Aspect_DisplayConnection (aDispX));
1812 (void)theDisplayName; // avoid warning on unused argument
1813 SetDisplayConnection (new Aspect_DisplayConnection ());
1816 if (Draw_VirtualWindows)
1818 // don't waste the time waiting for VSync when window is not displayed on the screen
1819 ViewerTest_myDefaultCaps.swapInterval = 0;
1820 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
1821 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
1823 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection(), false);
1824 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
1825 aGraphicDriver->InitContext();
1827 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
1828 toCreateViewer = Standard_True;
1832 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
1835 //Dispose the window if input parameters are default
1836 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
1838 Standard_Integer aTop = 0,
1845 // Get screen resolution
1846 #if defined(_WIN32) || defined(__WIN32__)
1848 GetClientRect(GetDesktopWindow(), &aWindowSize);
1849 aScreenHeight = aWindowSize.bottom;
1850 aScreenWidth = aWindowSize.right;
1851 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1852 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
1854 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
1855 aScreenWidth = WidthOfScreen(aScreen);
1856 aScreenHeight = HeightOfScreen(aScreen);
1859 TCollection_AsciiString anOverlappedViewId("");
1861 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
1863 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
1865 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
1866 && aRight + 2*aPxWidth + 40 > aScreenWidth)
1868 if (aBottom + aPxHeight + 40 > aScreenHeight)
1875 aPxTop = aBottom + 40;
1878 aPxLeft = aRight + 20;
1883 TCollection_AsciiString aTitle("3D View - ");
1884 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
1886 // Change name of current active window
1887 if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView())
1889 aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView));
1893 Handle(V3d_Viewer) a3DViewer;
1894 // If it's the single view, we first look for empty context
1895 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
1897 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1898 anIter(ViewerTest_myContexts);
1900 ViewerTest::SetAISContext (anIter.Value());
1901 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
1903 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
1905 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
1906 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
1908 else if (a3DViewer.IsNull())
1910 toCreateViewer = Standard_True;
1911 a3DViewer = new V3d_Viewer(aGraphicDriver);
1912 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
1913 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
1914 ViewerTest_DefaultBackground.GradientColor2,
1915 ViewerTest_DefaultBackground.FillMethod);
1918 // AIS context setup
1919 if (ViewerTest::GetAISContext().IsNull() ||
1920 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
1922 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
1923 ViewerTest::SetAISContext (aContext);
1924 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
1928 ViewerTest::ResetEventManager();
1933 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
1934 Handle(WNT_WClass)::DownCast (WClass()),
1935 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
1937 aPxWidth, aPxHeight,
1938 Quantity_NOC_BLACK);
1939 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1940 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
1942 aPxWidth, aPxHeight);
1943 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
1945 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
1948 aPxWidth, aPxHeight);
1950 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
1953 Handle(V3d_View) aView;
1954 if (!theViewToClone.IsNull())
1956 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
1960 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
1963 aView->SetWindow (VT_GetWindow());
1964 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
1966 ViewerTest::CurrentView(aView);
1967 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
1969 // Setup for X11 or NT
1972 // Set parameters for V3d_View and V3d_Viewer
1973 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
1974 aV3dView->SetComputedMode(Standard_False);
1976 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
1979 a3DViewer->SetDefaultLights();
1980 a3DViewer->SetLightOn();
1983 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1986 ::Display* aDispX = GetDisplayConnection()->GetDisplay();
1987 Tcl_CreateFileHandler (XConnectionNumber (aDispX), TCL_READABLE, VProcessEvents, (ClientData )aDispX);
1991 VT_GetWindow()->Map();
1993 // Set the handle of created view in the event manager
1994 ViewerTest::ResetEventManager();
1996 ViewerTest::CurrentView()->Redraw();
1999 a3DViewer.Nullify();
2001 return aViewNames.GetViewName();
2004 //==============================================================================
2005 //function : RedrawAllViews
2006 //purpose : Redraw all created views
2007 //==============================================================================
2008 void ViewerTest::RedrawAllViews()
2010 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
2011 for (; aViewIt.More(); aViewIt.Next())
2013 const Handle(V3d_View)& aView = aViewIt.Key2();
2018 //==============================================================================
2020 //purpose : Create the window viewer and initialize all the global variable
2021 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
2022 //==============================================================================
2024 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2026 TCollection_AsciiString aViewName, aDisplayName;
2027 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
2028 Handle(V3d_View) aCopyFrom;
2029 TCollection_AsciiString aName, aValue;
2031 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2033 const TCollection_AsciiString anArg = theArgVec[anArgIt];
2034 TCollection_AsciiString anArgCase = anArg;
2035 anArgCase.LowerCase();
2036 if (anArgIt + 1 < theArgsNb
2037 && anArgCase == "-name")
2039 aViewName = theArgVec[++anArgIt];
2041 else if (anArgIt + 1 < theArgsNb
2042 && (anArgCase == "-left"
2043 || anArgCase == "-l"))
2045 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
2047 else if (anArgIt + 1 < theArgsNb
2048 && (anArgCase == "-top"
2049 || anArgCase == "-t"))
2051 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
2053 else if (anArgIt + 1 < theArgsNb
2054 && (anArgCase == "-width"
2055 || anArgCase == "-w"))
2057 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
2059 else if (anArgIt + 1 < theArgsNb
2060 && (anArgCase == "-height"
2061 || anArgCase == "-h"))
2063 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
2065 else if (anArgCase == "-exitonclose")
2067 ViewerTest_EventManager::ToExitOnCloseView() = true;
2068 if (anArgIt + 1 < theArgsNb
2069 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToExitOnCloseView()))
2074 else if (anArgCase == "-closeonescape"
2075 || anArgCase == "-closeonesc")
2077 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
2078 if (anArgIt + 1 < theArgsNb
2079 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
2084 else if (anArgCase == "-2d_mode"
2085 || anArgCase == "-2dmode"
2086 || anArgCase == "-2d")
2088 bool toEnable = true;
2089 if (anArgIt + 1 < theArgsNb
2090 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
2094 is2dMode = toEnable ? 1 : 0;
2096 else if (anArgIt + 1 < theArgsNb
2097 && (anArgCase == "-disp"
2098 || anArgCase == "-display"))
2100 aDisplayName = theArgVec[++anArgIt];
2102 else if (!ViewerTest::CurrentView().IsNull()
2103 && aCopyFrom.IsNull()
2104 && (anArgCase == "-copy"
2105 || anArgCase == "-clone"
2106 || anArgCase == "-cloneactive"
2107 || anArgCase == "-cloneactiveview"))
2109 aCopyFrom = ViewerTest::CurrentView();
2112 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
2115 if (aName == "name")
2119 else if (aName == "l"
2122 aPxLeft = aValue.IntegerValue();
2124 else if (aName == "t"
2127 aPxTop = aValue.IntegerValue();
2129 else if (aName == "disp"
2130 || aName == "display")
2132 aDisplayName = aValue;
2134 else if (aName == "w"
2135 || aName == "width")
2137 aPxWidth = aValue.IntegerValue();
2139 else if (aName == "h"
2140 || aName == "height")
2142 aPxHeight = aValue.IntegerValue();
2146 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
2150 else if (aViewName.IsEmpty())
2156 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
2161 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
2162 if (!aDisplayName.IsEmpty())
2164 aDisplayName.Clear();
2165 std::cout << "Warning: display parameter will be ignored.\n";
2169 ViewerTest_Names aViewNames (aViewName);
2170 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
2172 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
2173 theDi.Eval (aCommand.ToCString());
2176 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
2181 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
2182 aViewName, aDisplayName, aCopyFrom);
2185 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
2191 //! Parse HLR algo type.
2192 static Standard_Boolean parseHlrAlgoType (const char* theName,
2193 Prs3d_TypeOfHLR& theType)
2195 TCollection_AsciiString aName (theName);
2197 if (aName == "polyalgo")
2199 theType = Prs3d_TOH_PolyAlgo;
2201 else if (aName == "algo")
2203 theType = Prs3d_TOH_Algo;
2207 return Standard_False;
2209 return Standard_True;
2212 //==============================================================================
2214 //purpose : hidden lines removal algorithm
2215 //==============================================================================
2217 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2219 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2220 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2223 std::cerr << "Error: No opened viewer!\n";
2227 Standard_Boolean hasHlrOnArg = Standard_False;
2228 Standard_Boolean hasShowHiddenArg = Standard_False;
2229 Standard_Boolean isHLROn = Standard_False;
2230 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
2231 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
2232 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2233 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
2235 TCollection_AsciiString anArg (argv[anArgIter]);
2237 if (anUpdateTool.parseRedrawMode (anArg))
2241 else if (anArg == "-showhidden"
2242 && anArgIter + 1 < argc
2243 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
2246 hasShowHiddenArg = Standard_True;
2249 else if ((anArg == "-type"
2251 || anArg == "-algotype")
2252 && anArgIter + 1 < argc
2253 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
2258 else if (!hasHlrOnArg
2259 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
2261 hasHlrOnArg = Standard_True;
2265 else if (!hasShowHiddenArg
2266 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
2268 hasShowHiddenArg = Standard_True;
2273 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
2279 di << "HLR: " << aView->ComputedMode() << "\n";
2280 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
2282 switch (aCtx->DefaultDrawer()->TypeOfHLR())
2284 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
2285 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
2286 case Prs3d_TOH_Algo: di << "Algo\n"; break;
2288 anUpdateTool.Invalidate();
2292 Standard_Boolean toRecompute = Standard_False;
2293 if (aTypeOfHLR != Prs3d_TOH_NotSet
2294 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
2296 toRecompute = Standard_True;
2297 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
2299 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
2301 toRecompute = Standard_True;
2304 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
2308 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
2313 if (aView->ComputedMode() && isHLROn && toRecompute)
2315 AIS_ListOfInteractive aListOfShapes;
2316 aCtx->DisplayedObjects (aListOfShapes);
2317 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
2319 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
2321 aCtx->Redisplay (aShape, Standard_False);
2326 aView->SetComputedMode (isHLROn);
2330 //==============================================================================
2331 //function : VHLRType
2332 //purpose : change type of using HLR algorithm
2333 //==============================================================================
2335 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
2337 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2338 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2341 std::cerr << "Error: No opened viewer!\n";
2345 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
2346 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2347 AIS_ListOfInteractive aListOfShapes;
2348 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
2350 TCollection_AsciiString anArg (argv[anArgIter]);
2352 if (anUpdateTool.parseRedrawMode (anArg))
2356 else if ((anArg == "-type"
2358 || anArg == "-algotype")
2359 && anArgIter + 1 < argc
2360 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
2366 else if (aTypeOfHLR == Prs3d_TOH_NotSet
2367 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
2373 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
2374 TCollection_AsciiString aName (argv[anArgIter]);
2375 if (!aMap.IsBound2 (aName))
2377 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
2381 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
2382 if (aShape.IsNull())
2384 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
2387 aListOfShapes.Append (aShape);
2391 if (aTypeOfHLR == Prs3d_TOH_NotSet)
2393 std::cout << "Syntax error: wrong number of arguments!\n";
2397 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
2400 aCtx->DisplayedObjects (aListOfShapes);
2401 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
2404 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
2406 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
2407 if (aShape.IsNull())
2412 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
2413 && aView->ComputedMode();
2415 || aShape->TypeOfHLR() != aTypeOfHLR)
2417 aShape->SetTypeOfHLR (aTypeOfHLR);
2421 aCtx->Redisplay (aShape, Standard_False);
2427 //==============================================================================
2428 //function : FindViewIdByWindowHandle
2429 //purpose : Find theView Id in the map of views by window handle
2430 //==============================================================================
2431 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2432 TCollection_AsciiString FindViewIdByWindowHandle (Aspect_Drawable theWindowHandle)
2434 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
2435 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
2437 Aspect_Drawable aWindowHandle = anIter.Value()->Window()->NativeHandle();
2438 if (aWindowHandle == theWindowHandle)
2439 return anIter.Key1();
2441 return TCollection_AsciiString("");
2445 //! Make the view active
2446 void ActivateView (const TCollection_AsciiString& theViewName,
2447 Standard_Boolean theToUpdate = Standard_True)
2449 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
2455 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
2456 if (!anAISContext.IsNull())
2458 if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView())
2460 aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView));
2463 ViewerTest::CurrentView (aView);
2464 ViewerTest::SetAISContext (anAISContext);
2465 aView->Window()->SetTitle (TCollection_AsciiString("3D View - ") + theViewName + "(*)");
2467 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
2468 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
2469 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
2471 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
2473 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2476 ViewerTest::CurrentView()->Redraw();
2481 //==============================================================================
2482 //function : RemoveView
2484 //==============================================================================
2485 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
2486 const Standard_Boolean theToRemoveContext)
2488 if (!ViewerTest_myViews.IsBound2 (theView))
2493 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
2494 RemoveView (aViewName, theToRemoveContext);
2497 //==============================================================================
2498 //function : RemoveView
2499 //purpose : Close and remove view from display, clear maps if neccessary
2500 //==============================================================================
2501 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
2503 if (!ViewerTest_myViews.IsBound1(theViewName))
2505 std::cout << "Wrong view name\n";
2509 // Activate another view if it's active now
2510 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
2512 if (ViewerTest_myViews.Extent() > 1)
2514 TCollection_AsciiString aNewViewName;
2515 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
2516 anIter.More(); anIter.Next())
2518 if (anIter.Key1() != theViewName)
2520 aNewViewName = anIter.Key1();
2524 ActivateView (aNewViewName);
2528 VT_GetWindow().Nullify();
2529 ViewerTest::CurrentView (Handle(V3d_View)());
2530 if (isContextRemoved)
2532 Handle(AIS_InteractiveContext) anEmptyContext;
2533 ViewerTest::SetAISContext(anEmptyContext);
2539 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
2540 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
2541 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
2542 aRedrawer.Stop (aView->Window());
2544 // Remove view resources
2545 ViewerTest_myViews.UnBind1(theViewName);
2546 aView->Window()->Unmap();
2549 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2550 XFlush (GetDisplayConnection()->GetDisplay());
2553 // Keep context opened only if the closed view is last to avoid
2554 // unused empty contexts
2555 if (!aCurrentContext.IsNull())
2557 // Check if there are more difined views in the viewer
2558 aCurrentContext->CurrentViewer()->InitDefinedViews();
2559 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
2561 // Remove driver if there is no viewers that use it
2562 Standard_Boolean isRemoveDriver = Standard_True;
2563 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2564 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
2566 if (aCurrentContext != anIter.Key2() &&
2567 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
2569 isRemoveDriver = Standard_False;
2574 aCurrentContext->RemoveAll (Standard_False);
2577 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
2578 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2579 Tcl_DeleteFileHandler (XConnectionNumber (aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
2583 ViewerTest_myContexts.UnBind2(aCurrentContext);
2586 std::cout << "3D View - " << theViewName << " was deleted.\n";
2587 if (ViewerTest_EventManager::ToExitOnCloseView())
2589 Draw_Interprete ("exit");
2593 //==============================================================================
2595 //purpose : Remove the view defined by its name
2596 //==============================================================================
2598 static int VClose (Draw_Interpretor& /*theDi*/,
2599 Standard_Integer theArgsNb,
2600 const char** theArgVec)
2602 NCollection_List<TCollection_AsciiString> aViewList;
2605 TCollection_AsciiString anArg (theArgVec[1]);
2607 if (anArg.IsEqual ("ALL")
2608 || anArg.IsEqual ("*"))
2610 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
2611 anIter.More(); anIter.Next())
2613 aViewList.Append (anIter.Key1());
2615 if (aViewList.IsEmpty())
2617 std::cout << "No view to close\n";
2623 ViewerTest_Names aViewName (theArgVec[1]);
2624 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
2626 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
2629 aViewList.Append (aViewName.GetViewName());
2634 // close active view
2635 if (ViewerTest::CurrentView().IsNull())
2637 std::cerr << "No active view!\n";
2640 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
2643 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
2644 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
2645 anIter.More(); anIter.Next())
2647 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
2653 //==============================================================================
2654 //function : VActivate
2655 //purpose : Activate the view defined by its ID
2656 //==============================================================================
2658 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2662 theDi.Eval("vviewlist");
2666 TCollection_AsciiString aNameString;
2667 Standard_Boolean toUpdate = Standard_True;
2668 Standard_Boolean toActivate = Standard_True;
2669 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
2671 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2674 && anArg == "-noupdate")
2676 toUpdate = Standard_False;
2679 && aNameString.IsEmpty()
2682 ViewerTest::CurrentView()->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
2683 VT_GetWindow().Nullify();
2684 ViewerTest::CurrentView (Handle(V3d_View)());
2685 ViewerTest::ResetEventManager();
2686 theDi << theArgVec[0] << ": all views are inactive\n";
2687 toActivate = Standard_False;
2690 && aNameString.IsEmpty())
2692 aNameString = theArgVec[anArgIter];
2696 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
2705 else if (aNameString.IsEmpty())
2707 std::cout << "Syntax error: wrong number of arguments\n";
2711 // Check if this view exists in the viewer with the driver
2712 ViewerTest_Names aViewNames (aNameString);
2713 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
2715 theDi << "Syntax error: wrong view name '" << aNameString << "'\n";
2719 // Check if it is active already
2720 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
2722 theDi << theArgVec[0] << ": the view is active already\n";
2726 ActivateView (aViewNames.GetViewName(), toUpdate);
2730 //==============================================================================
2731 //function : VViewList
2732 //purpose : Print current list of views per viewer and graphic driver ID
2733 // shared between viewers
2734 //==============================================================================
2736 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2740 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
2741 << "Usage: " << theArgVec[0] << " name";
2744 if (ViewerTest_myContexts.Size() < 1)
2747 Standard_Boolean isTreeView =
2748 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
2752 theDi << theArgVec[0] <<":\n";
2755 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
2756 aDriverIter.More(); aDriverIter.Next())
2759 theDi << aDriverIter.Key1() << ":\n";
2761 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2762 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
2764 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
2768 TCollection_AsciiString aContextName(aContextIter.Key1());
2769 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
2772 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
2773 aViewIter.More(); aViewIter.Next())
2775 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
2777 TCollection_AsciiString aViewName(aViewIter.Key1());
2780 if (aViewIter.Value() == ViewerTest::CurrentView())
2781 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
2783 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
2787 theDi << aViewName << " ";
2797 //==============================================================================
2798 //function : GetMousePosition
2800 //==============================================================================
2801 void ViewerTest::GetMousePosition (Standard_Integer& theX,
2802 Standard_Integer& theY)
2804 if (Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager())
2806 theX = aViewCtrl->LastMousePosition().x();
2807 theY = aViewCtrl->LastMousePosition().y();
2811 //==============================================================================
2812 //function : VViewProj
2813 //purpose : Switch view projection
2814 //==============================================================================
2815 static int VViewProj (Draw_Interpretor& ,
2816 Standard_Integer theNbArgs,
2817 const char** theArgVec)
2819 static Standard_Boolean isYup = Standard_False;
2820 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2823 std::cout << "Error: no active view\n";
2827 TCollection_AsciiString aCmdName (theArgVec[0]);
2828 Standard_Boolean isGeneralCmd = Standard_False;
2829 if (aCmdName == "vfront")
2831 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup);
2833 else if (aCmdName == "vback")
2835 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup);
2837 else if (aCmdName == "vtop")
2839 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup);
2841 else if (aCmdName == "vbottom")
2843 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup);
2845 else if (aCmdName == "vleft")
2847 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup);
2849 else if (aCmdName == "vright")
2851 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup);
2853 else if (aCmdName == "vaxo")
2855 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup);
2859 isGeneralCmd = Standard_True;
2860 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
2862 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2863 anArgCase.LowerCase();
2864 if (anArgCase == "-zup")
2866 isYup = Standard_False;
2868 else if (anArgCase == "-yup")
2870 isYup = Standard_True;
2872 else if (anArgCase == "-front"
2873 || anArgCase == "front"
2874 || anArgCase == "-f"
2875 || anArgCase == "f")
2877 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup);
2879 else if (anArgCase == "-back"
2880 || anArgCase == "back"
2881 || anArgCase == "-b"
2882 || anArgCase == "b")
2884 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup);
2886 else if (anArgCase == "-top"
2887 || anArgCase == "top"
2888 || anArgCase == "-t"
2889 || anArgCase == "t")
2891 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup);
2893 else if (anArgCase == "-bottom"
2894 || anArgCase == "bottom"
2895 || anArgCase == "-bot"
2896 || anArgCase == "bot"
2897 || anArgCase == "-b"
2898 || anArgCase == "b")
2900 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup);
2902 else if (anArgCase == "-left"
2903 || anArgCase == "left"
2904 || anArgCase == "-l"
2905 || anArgCase == "l")
2907 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup);
2909 else if (anArgCase == "-right"
2910 || anArgCase == "right"
2911 || anArgCase == "-r"
2912 || anArgCase == "r")
2914 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup);
2916 else if (anArgCase == "-axoleft"
2917 || anArgCase == "-leftaxo"
2918 || anArgCase == "axoleft"
2919 || anArgCase == "leftaxo")
2921 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoLeft : V3d_TypeOfOrientation_Zup_AxoLeft, isYup);
2923 else if (anArgCase == "-axo"
2924 || anArgCase == "axo"
2925 || anArgCase == "-a"
2927 || anArgCase == "-axoright"
2928 || anArgCase == "-rightaxo"
2929 || anArgCase == "axoright"
2930 || anArgCase == "rightaxo")
2932 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup);
2934 else if (anArgCase == "+x")
2936 aView->SetProj (V3d_Xpos, isYup);
2938 else if (anArgCase == "-x")
2940 aView->SetProj (V3d_Xneg, isYup);
2942 else if (anArgCase == "+y")
2944 aView->SetProj (V3d_Ypos, isYup);
2946 else if (anArgCase == "-y")
2948 aView->SetProj (V3d_Yneg, isYup);
2950 else if (anArgCase == "+z")
2952 aView->SetProj (V3d_Zpos, isYup);
2954 else if (anArgCase == "-z")
2956 aView->SetProj (V3d_Zneg, isYup);
2958 else if (anArgCase == "+x+y+z")
2960 aView->SetProj (V3d_XposYposZpos, isYup);
2962 else if (anArgCase == "+x+y-z")
2964 aView->SetProj (V3d_XposYposZneg, isYup);
2966 else if (anArgCase == "+x-y+z")
2968 aView->SetProj (V3d_XposYnegZpos, isYup);
2970 else if (anArgCase == "+x-y-z")
2972 aView->SetProj (V3d_XposYnegZneg, isYup);
2974 else if (anArgCase == "-x+y+z")
2976 aView->SetProj (V3d_XnegYposZpos, isYup);
2978 else if (anArgCase == "-x+y-z")
2980 aView->SetProj (V3d_XnegYposZneg, isYup);
2982 else if (anArgCase == "-x-y+z")
2984 aView->SetProj (V3d_XnegYnegZpos, isYup);
2986 else if (anArgCase == "-x-y-z")
2988 aView->SetProj (V3d_XnegYnegZneg, isYup);
2990 else if (anArgCase == "+x+y")
2992 aView->SetProj (V3d_XposYpos, isYup);
2994 else if (anArgCase == "+x-y")
2996 aView->SetProj (V3d_XposYneg, isYup);
2998 else if (anArgCase == "-x+y")
3000 aView->SetProj (V3d_XnegYpos, isYup);
3002 else if (anArgCase == "-x-y")
3004 aView->SetProj (V3d_XnegYneg, isYup);
3006 else if (anArgCase == "+x+z")
3008 aView->SetProj (V3d_XposZpos, isYup);
3010 else if (anArgCase == "+x-z")
3012 aView->SetProj (V3d_XposZneg, isYup);
3014 else if (anArgCase == "-x+z")
3016 aView->SetProj (V3d_XnegZpos, isYup);
3018 else if (anArgCase == "-x-z")
3020 aView->SetProj (V3d_XnegZneg, isYup);
3022 else if (anArgCase == "+y+z")
3024 aView->SetProj (V3d_YposZpos, isYup);
3026 else if (anArgCase == "+y-z")
3028 aView->SetProj (V3d_YposZneg, isYup);
3030 else if (anArgCase == "-y+z")
3032 aView->SetProj (V3d_YnegZpos, isYup);
3034 else if (anArgCase == "-y-z")
3036 aView->SetProj (V3d_YnegZneg, isYup);
3038 else if (anArgIter + 1 < theNbArgs
3039 && anArgCase == "-frame"
3040 && TCollection_AsciiString (theArgVec[anArgIter + 1]).Length() == 4)
3042 TCollection_AsciiString aFrameDef (theArgVec[++anArgIter]);
3043 aFrameDef.LowerCase();
3044 gp_Dir aRight, anUp;
3045 if (aFrameDef.Value (2) == aFrameDef.Value (4))
3047 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3051 if (aFrameDef.Value (2) == 'x')
3053 aRight = aFrameDef.Value (1) == '+' ? gp::DX() : -gp::DX();
3055 else if (aFrameDef.Value (2) == 'y')
3057 aRight = aFrameDef.Value (1) == '+' ? gp::DY() : -gp::DY();
3059 else if (aFrameDef.Value (2) == 'z')
3061 aRight = aFrameDef.Value (1) == '+' ? gp::DZ() : -gp::DZ();
3065 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3069 if (aFrameDef.Value (4) == 'x')
3071 anUp = aFrameDef.Value (3) == '+' ? gp::DX() : -gp::DX();
3073 else if (aFrameDef.Value (4) == 'y')
3075 anUp = aFrameDef.Value (3) == '+' ? gp::DY() : -gp::DY();
3077 else if (aFrameDef.Value (4) == 'z')
3079 anUp = aFrameDef.Value (3) == '+' ? gp::DZ() : -gp::DZ();
3083 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3087 const Handle(Graphic3d_Camera)& aCamera = aView->Camera();
3088 const gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin());
3089 const gp_Dir aDir = anUp.Crossed (aRight);
3090 aCamera->SetCenter (gp_Pnt (0, 0, 0));
3091 aCamera->SetDirection (aDir);
3092 aCamera->SetUp (anUp);
3093 aCamera->OrthogonalizeUp();
3095 aView->Panning (anOriginVCS.X(), anOriginVCS.Y());
3100 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
3109 std::cout << "Syntax error: wrong number of arguments\n";
3115 //==============================================================================
3117 //purpose : Dsiplay help on viewer Keyboead and mouse commands
3118 //Draw arg : No args
3119 //==============================================================================
3121 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
3123 di << "=========================\n";
3124 di << "F : FitAll\n";
3125 di << "T : TopView\n";
3126 di << "B : BottomView\n";
3127 di << "R : RightView\n";
3128 di << "L : LeftView\n";
3129 di << "A : AxonometricView\n";
3130 di << "D : ResetView\n";
3132 di << "=========================\n";
3133 di << "S : Shading\n";
3134 di << "W : Wireframe\n";
3135 di << "H : HiddenLineRemoval\n";
3136 di << "U : Unset display mode\n";
3137 di << "Delete : Remove selection from viewer\n";
3139 di << "=========================\n";
3140 di << "Selection mode \n";
3141 di << "0 : Shape\n";
3142 di << "1 : Vertex\n";
3146 di << "5 : Shell\n";
3147 di << "6 : Solid\n";
3148 di << "7 : Compound\n";
3150 di << "=========================\n";
3151 di << "< : Hilight next detected\n";
3152 di << "> : Hilight previous detected\n";
3159 static LRESULT WINAPI AdvViewerWindowProc (HWND theWinHandle,
3164 if (ViewerTest_myViews.IsEmpty())
3166 return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam);
3173 // Delete view from map of views
3174 ViewerTest::RemoveView (FindViewIdByWindowHandle (theWinHandle));
3179 if (LOWORD(wParam) == WA_CLICKACTIVE
3180 || LOWORD(wParam) == WA_ACTIVE
3181 || ViewerTest::CurrentView().IsNull())
3183 // Activate inactive window
3184 if (VT_GetWindow().IsNull()
3185 || (HWND )VT_GetWindow()->HWindow() != theWinHandle)
3187 ActivateView (FindViewIdByWindowHandle (theWinHandle));
3194 return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam);
3200 static LRESULT WINAPI ViewerWindowProc (HWND theWinHandle,
3205 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3208 return DefWindowProcW (theWinHandle, theMsg, wParam, lParam);
3216 BeginPaint(theWinHandle, &aPaint);
3217 EndPaint (theWinHandle, &aPaint);
3218 ViewerTest::CurrentEventManager()->ProcessExpose();
3223 ViewerTest::CurrentEventManager()->ProcessConfigure();
3230 switch (aView->RenderingParams().StereoMode)
3232 case Graphic3d_StereoMode_RowInterlaced:
3233 case Graphic3d_StereoMode_ColumnInterlaced:
3234 case Graphic3d_StereoMode_ChessBoard:
3236 // track window moves to reverse stereo pair
3237 aView->MustBeResized();
3249 const Aspect_VKey aVKey = WNT_Window::VirtualKeyFromNative ((Standard_Integer )wParam);
3250 if (aVKey != Aspect_VKey_UNKNOWN)
3252 const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime();
3253 if (theMsg == WM_KEYDOWN)
3255 ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp);
3259 ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp);
3261 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3268 case WM_LBUTTONDOWN:
3269 case WM_MBUTTONDOWN:
3270 case WM_RBUTTONDOWN:
3272 const Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam));
3273 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam);
3274 Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE;
3278 case WM_LBUTTONDOWN:
3279 aButton = Aspect_VKeyMouse_LeftButton;
3282 case WM_MBUTTONDOWN:
3283 aButton = Aspect_VKeyMouse_MiddleButton;
3286 case WM_RBUTTONDOWN:
3287 aButton = Aspect_VKeyMouse_RightButton;
3290 if (theMsg == WM_LBUTTONDOWN
3291 || theMsg == WM_MBUTTONDOWN
3292 || theMsg == WM_RBUTTONDOWN)
3294 if (aButton == Aspect_VKeyMouse_LeftButton)
3296 TheIsAnimating = Standard_False;
3299 SetFocus (theWinHandle);
3300 SetCapture(theWinHandle);
3301 ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false);
3306 ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false);
3308 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3313 const int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
3314 const Standard_Real aDeltaF = Standard_Real(aDelta) / Standard_Real(WHEEL_DELTA);
3315 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam);
3316 Graphic3d_Vec2i aPos (int(short(LOWORD(lParam))), int(short(HIWORD(lParam))));
3317 POINT aCursorPnt = { aPos.x(), aPos.y() };
3318 if (ScreenToClient (theWinHandle, &aCursorPnt))
3320 aPos.SetValues (aCursorPnt.x, aCursorPnt.y);
3323 ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags));
3324 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3329 Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam));
3330 Aspect_VKeyMouse aButtons = WNT_Window::MouseButtonsFromEvent (wParam);
3331 Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent(wParam);
3333 // don't make a slide-show from input events - fetch the actual mouse cursor position
3335 aCursor.cbSize = sizeof(aCursor);
3336 if (::GetCursorInfo (&aCursor) != FALSE)
3338 POINT aCursorPnt = { aCursor.ptScreenPos.x, aCursor.ptScreenPos.y };
3339 if (ScreenToClient (theWinHandle, &aCursorPnt))
3341 // as we override mouse position, we need overriding also mouse state
3342 aPos.SetValues (aCursorPnt.x, aCursorPnt.y);
3343 aButtons = WNT_Window::MouseButtonsAsync();
3344 aFlags = WNT_Window::MouseKeyFlagsAsync();
3348 if (VT_GetWindow().IsNull()
3349 || (HWND )VT_GetWindow()->HWindow() != theWinHandle)
3351 // mouse move events come also for inactive windows
3355 ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
3356 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
3361 return DefWindowProcW (theWinHandle, theMsg, wParam, lParam);
3367 //==============================================================================
3368 //function : ViewerMainLoop
3369 //purpose : Get a Event on the view and dispatch it
3370 //==============================================================================
3372 int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec)
3374 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
3375 if (aViewCtrl.IsNull()
3381 aViewCtrl->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]);
3383 std::cout << "Start picking\n";
3387 while (aViewCtrl->ToPickPoint())
3389 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
3390 if (GetMessageW (&aMsg, NULL, 0, 0))
3392 TranslateMessage (&aMsg);
3393 DispatchMessageW (&aMsg);
3397 std::cout << "Picking done\n";
3401 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
3403 int min( int a, int b )
3411 int max( int a, int b )
3419 int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec)
3421 static XEvent aReport;
3422 const Standard_Boolean toPick = theNbArgs > 0;
3425 if (ViewerTest::CurrentEventManager().IsNull())
3429 ViewerTest::CurrentEventManager()->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]);
3432 Display* aDisplay = GetDisplayConnection()->GetDisplay();
3433 XNextEvent (aDisplay, &aReport);
3435 // Handle event for the chosen display connection
3436 switch (aReport.type)
3440 if ((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
3443 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
3444 return toPick ? 0 : 1;
3450 // Activate inactive view
3451 Window aWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3452 if (aWindow != aReport.xfocus.window)
3454 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
3460 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3461 if (anXWindow == aReport.xexpose.window)
3463 ViewerTest::CurrentEventManager()->ProcessExpose();
3466 // remove all the ExposureMask and process them at once
3467 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3469 if (!XCheckWindowEvent (aDisplay, anXWindow, ExposureMask, &aReport))
3477 case ConfigureNotify:
3479 // remove all the StructureNotifyMask and process them at once
3480 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3481 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3483 if (!XCheckWindowEvent (aDisplay, anXWindow, StructureNotifyMask, &aReport))
3489 if (anXWindow == aReport.xconfigure.window)
3491 ViewerTest::CurrentEventManager()->ProcessConfigure();
3498 XKeyEvent* aKeyEvent = (XKeyEvent* )&aReport;
3499 const KeySym aKeySym = XLookupKeysym (aKeyEvent, 0);
3500 const Aspect_VKey aVKey = Xw_Window::VirtualKeyFromNative (aKeySym);
3501 if (aVKey != Aspect_VKey_UNKNOWN)
3503 const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime();
3504 if (aReport.type == KeyPress)
3506 ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp);
3510 ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp);
3512 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3519 const Graphic3d_Vec2i aPos (aReport.xbutton.x, aReport.xbutton.y);
3520 Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
3521 Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE;
3522 if (aReport.xbutton.button == Button1)
3524 aButton = Aspect_VKeyMouse_LeftButton;
3526 if (aReport.xbutton.button == Button2)
3528 aButton = Aspect_VKeyMouse_MiddleButton;
3530 if (aReport.xbutton.button == Button3)
3532 aButton = Aspect_VKeyMouse_RightButton;
3535 if (aReport.xbutton.state & ControlMask)
3537 aFlags |= Aspect_VKeyFlags_CTRL;
3539 if (aReport.xbutton.state & ShiftMask)
3541 aFlags |= Aspect_VKeyFlags_SHIFT;
3543 if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt))
3545 aFlags |= Aspect_VKeyFlags_ALT;
3548 if (aReport.xbutton.button == Button4
3549 || aReport.xbutton.button == Button5)
3551 if (aReport.type != ButtonPress)
3556 const double aDeltaF = (aReport.xbutton.button == Button4 ? 1.0 : -1.0);
3557 ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags));
3559 else if (aReport.type == ButtonPress)
3561 if (aButton == Aspect_VKeyMouse_LeftButton)
3563 TheIsAnimating = Standard_False;
3565 ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false);
3569 ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false);
3571 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3576 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
3577 if (anXWindow != aReport.xmotion.window)
3582 // remove all the ButtonMotionMask and process them at once
3583 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3585 if (!XCheckWindowEvent (aDisplay, anXWindow, ButtonMotionMask | PointerMotionMask, &aReport))
3591 Graphic3d_Vec2i aPos (aReport.xmotion.x, aReport.xmotion.y);
3592 Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
3593 Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
3594 if ((aReport.xmotion.state & Button1Mask) != 0)
3596 aButtons |= Aspect_VKeyMouse_LeftButton;
3598 else if ((aReport.xmotion.state & Button2Mask) != 0)
3600 aButtons |= Aspect_VKeyMouse_MiddleButton;
3602 else if ((aReport.xmotion.state & Button3Mask) != 0)
3604 aButtons |= Aspect_VKeyMouse_RightButton;
3607 if (aReport.xmotion.state & ControlMask)
3609 aFlags |= Aspect_VKeyFlags_CTRL;
3611 if (aReport.xmotion.state & ShiftMask)
3613 aFlags |= Aspect_VKeyFlags_SHIFT;
3615 if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt))
3617 aFlags |= Aspect_VKeyFlags_ALT;
3620 ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
3621 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3625 return (!toPick || ViewerTest::CurrentEventManager()->ToPickPoint()) ? 1 : 0;
3628 //==============================================================================
3629 //function : VProcessEvents
3630 //purpose : manage the event in the Viewer window (see Tcl_CreateFileHandler())
3631 //==============================================================================
3632 static void VProcessEvents (ClientData theDispX, int)
3634 Display* aDispX = (Display* )theDispX;
3635 Handle(Aspect_DisplayConnection) aDispConn;
3636 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
3637 aDriverIter (ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
3639 const Handle(Aspect_DisplayConnection)& aDispConnTmp = aDriverIter.Key2()->GetDisplayConnection();
3640 if (aDispConnTmp->GetDisplay() == aDispX)
3642 aDispConn = aDispConnTmp;
3646 if (aDispConn.IsNull())
3648 std::cerr << "Error: ViewerTest is unable processing messages for unknown X Display\n";
3652 // process new events in queue
3653 SetDisplayConnection (aDispConn);
3655 for (int aNbEventsMax = XPending (aDispX), anEventIter (0);;)
3657 const int anEventResult = ViewerMainLoop (0, NULL);
3658 if (anEventResult == 0)
3663 aNbRemain = XPending (aDispX);
3664 if (++anEventIter >= aNbEventsMax
3671 // Listening X events through Tcl_CreateFileHandler() callback is fragile,
3672 // it is possible that new events will arrive to queue before the end of this callback
3673 // so that either this callback should go into an infinite loop (blocking processing of other events)
3674 // or to keep unprocessed events till the next queue update (which can arrive not soon).
3675 // Sending a dummy event in this case is a simple workaround (still, it is possible that new event will be queued in-between).
3679 memset (&aDummyEvent, 0, sizeof(aDummyEvent));
3680 aDummyEvent.type = ClientMessage;
3681 aDummyEvent.xclient.format = 32;
3682 XSendEvent (aDispX, InputFocus, False, 0, &aDummyEvent);
3686 if (const Handle(AIS_InteractiveContext)& anActiveCtx = ViewerTest::GetAISContext())
3688 SetDisplayConnection (anActiveCtx->CurrentViewer()->Driver()->GetDisplayConnection());
3693 //==============================================================================
3694 //function : OSWindowSetup
3695 //purpose : Setup for the X11 window to be able to cath the event
3696 //==============================================================================
3699 static void OSWindowSetup()
3701 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
3704 Window window = VT_GetWindow()->XWindow();
3705 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
3706 Display *aDisplay = GetDisplayConnection()->GetDisplay();
3707 XSynchronize(aDisplay, 1);
3709 // X11 : For keyboard on SUN
3711 wmhints.flags = InputHint;
3714 XSetWMHints( aDisplay, window, &wmhints);
3716 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | KeyReleaseMask |
3717 ButtonPressMask | ButtonReleaseMask |
3718 StructureNotifyMask |
3720 Button1MotionMask | Button2MotionMask |
3721 Button3MotionMask | FocusChangeMask
3723 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
3724 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
3726 XSynchronize(aDisplay, 0);
3734 //==============================================================================
3737 //==============================================================================
3739 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
3741 const Handle(V3d_View) aView = ViewerTest::CurrentView();
3744 std::cout << "Error: no active viewer!\n";
3748 Standard_Boolean toFit = Standard_True;
3749 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
3750 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3752 TCollection_AsciiString anArg (theArgv[anArgIter]);
3754 if (anUpdateTool.parseRedrawMode (anArg))
3758 else if (anArg == "-selected")
3760 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
3761 toFit = Standard_False;
3765 std::cout << "Syntax error at '" << anArg << "'\n";
3771 aView->FitAll (0.01, Standard_False);
3776 //=======================================================================
3777 //function : VFitArea
3778 //purpose : Fit view to show area located between two points
3779 // : given in world 2D or 3D coordinates.
3780 //=======================================================================
3781 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3783 Handle(V3d_View) aView = ViewerTest::CurrentView();
3786 std::cerr << theArgVec[0] << "Error: No active view.\n";
3791 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
3792 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
3796 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
3797 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
3798 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
3799 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
3801 else if (theArgNb == 7)
3803 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
3804 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
3805 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
3806 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
3807 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
3808 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
3812 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
3813 theDI.PrintHelp(theArgVec[0]);
3817 // Convert model coordinates to view space
3818 Handle(Graphic3d_Camera) aCamera = aView->Camera();
3819 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
3820 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
3822 // Determine fit area
3823 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
3824 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
3826 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
3828 if (aDiagonal < Precision::Confusion())
3830 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
3834 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
3838 //==============================================================================
3840 //purpose : ZFitall, no DRAW arguments
3841 //Draw arg : No args
3842 //==============================================================================
3843 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3845 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
3847 if (aCurrentView.IsNull())
3849 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
3855 aCurrentView->ZFitAll();
3856 aCurrentView->Redraw();
3860 Standard_Real aScale = 1.0;
3864 aScale = Draw::Atoi (theArgVec[1]);
3867 aCurrentView->ZFitAll (aScale);
3868 aCurrentView->Redraw();
3873 //==============================================================================
3874 //function : VRepaint
3876 //==============================================================================
3877 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
3879 Handle(V3d_View) aView = ViewerTest::CurrentView();
3882 std::cout << "Error: no active viewer!\n";
3886 Standard_Boolean isImmediateUpdate = Standard_False;
3887 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3889 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3891 if (anArg == "-immediate"
3894 isImmediateUpdate = Standard_True;
3895 if (anArgIter + 1 < theArgNb
3896 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
3901 else if (anArg == "-continuous"
3904 || anArg == "-framerate")
3906 Standard_Real aFps = -1.0;
3907 if (anArgIter + 1 < theArgNb
3908 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue())
3910 aFps = Draw::Atof (theArgVec[++anArgIter]);
3913 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
3914 if (Abs (aFps) >= 1.0)
3916 aRedrawer.Start (aView->Window(), aFps);
3925 std::cout << "Syntax error at '" << anArg << "'\n";
3930 if (isImmediateUpdate)
3932 aView->RedrawImmediate();
3941 //==============================================================================
3943 //purpose : Remove all the object from the viewer
3944 //Draw arg : No args
3945 //==============================================================================
3947 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3949 Handle(V3d_View) V = ViewerTest::CurrentView();
3951 ViewerTest::Clear();
3955 //==============================================================================
3958 //==============================================================================
3960 static int VPick (Draw_Interpretor& ,
3961 Standard_Integer theNbArgs,
3962 const char** theArgVec)
3964 if (ViewerTest::CurrentView().IsNull())
3971 std::cout << "Syntax error: Invalid number of arguments\n";
3975 while (ViewerMainLoop (theNbArgs, theArgVec))
3986 //! Changes the background
3987 //! @param theDrawInterpretor the interpreter of the Draw Harness application
3988 //! @param theNumberOfCommandLineArguments the number of passed command line arguments
3989 //! @param theCommandLineArguments the array of command line arguments
3990 //! @return TCL_OK if changing was successful, or TCL_ERROR otherwise
3991 static int vbackground (Draw_Interpretor& theDrawInterpretor,
3992 const Standard_Integer theNumberOfCommandLineArguments,
3993 const char** const theCommandLineArguments)
3995 if (theNumberOfCommandLineArguments < 1)
3999 BackgroundChanger aBackgroundChanger;
4000 if (!aBackgroundChanger.ProcessCommandLine (theDrawInterpretor,
4001 theNumberOfCommandLineArguments,
4002 theCommandLineArguments))
4004 theDrawInterpretor << "Wrong command arguments.\n"
4006 << theCommandLineArguments[0] << "' for information about command options and its arguments.\n";
4014 //==============================================================================
4016 //purpose : View Scaling
4017 //==============================================================================
4019 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4021 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4022 if ( V3dView.IsNull() ) return 1;
4025 di << argv[0] << "Invalid number of arguments\n";
4028 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
4031 //==============================================================================
4032 //function : VZBuffTrihedron
4034 //==============================================================================
4036 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
4037 Standard_Integer theArgNb,
4038 const char** theArgVec)
4040 Handle(V3d_View) aView = ViewerTest::CurrentView();
4043 std::cout << "Error: no active viewer!\n";
4047 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
4049 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
4050 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
4051 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
4052 Quantity_Color anArrowColorX = Quantity_NOC_RED;
4053 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
4054 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
4055 Standard_Real aScale = 0.1;
4056 Standard_Real aSizeRatio = 0.8;
4057 Standard_Real anArrowDiam = 0.05;
4058 Standard_Integer aNbFacets = 12;
4059 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4061 Standard_CString anArg = theArgVec[anArgIter];
4062 TCollection_AsciiString aFlag (anArg);
4064 if (anUpdateTool.parseRedrawMode (aFlag))
4068 else if (aFlag == "-on")
4072 else if (aFlag == "-off")
4074 aView->TriedronErase();
4077 else if (aFlag == "-pos"
4078 || aFlag == "-position"
4079 || aFlag == "-corner")
4081 if (++anArgIter >= theArgNb)
4083 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4087 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
4088 aPosName.LowerCase();
4089 if (aPosName == "center")
4091 aPosition = Aspect_TOTP_CENTER;
4093 else if (aPosName == "left_lower"
4094 || aPosName == "lower_left"
4095 || aPosName == "leftlower"
4096 || aPosName == "lowerleft")
4098 aPosition = Aspect_TOTP_LEFT_LOWER;
4100 else if (aPosName == "left_upper"
4101 || aPosName == "upper_left"
4102 || aPosName == "leftupper"
4103 || aPosName == "upperleft")
4105 aPosition = Aspect_TOTP_LEFT_UPPER;
4107 else if (aPosName == "right_lower"
4108 || aPosName == "lower_right"
4109 || aPosName == "rightlower"
4110 || aPosName == "lowerright")
4112 aPosition = Aspect_TOTP_RIGHT_LOWER;
4114 else if (aPosName == "right_upper"
4115 || aPosName == "upper_right"
4116 || aPosName == "rightupper"
4117 || aPosName == "upperright")
4119 aPosition = Aspect_TOTP_RIGHT_UPPER;
4123 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
4127 else if (aFlag == "-type")
4129 if (++anArgIter >= theArgNb)
4131 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4135 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
4136 aTypeName.LowerCase();
4137 if (aTypeName == "wireframe"
4138 || aTypeName == "wire")
4140 aVisType = V3d_WIREFRAME;
4142 else if (aTypeName == "zbuffer"
4143 || aTypeName == "shaded")
4145 aVisType = V3d_ZBUFFER;
4149 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
4152 else if (aFlag == "-scale")
4154 if (++anArgIter >= theArgNb)
4156 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4160 aScale = Draw::Atof (theArgVec[anArgIter]);
4162 else if (aFlag == "-size"
4163 || aFlag == "-sizeratio")
4165 if (++anArgIter >= theArgNb)
4167 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4171 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
4173 else if (aFlag == "-arrowdiam"
4174 || aFlag == "-arrowdiameter")
4176 if (++anArgIter >= theArgNb)
4178 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4182 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
4184 else if (aFlag == "-nbfacets")
4186 if (++anArgIter >= theArgNb)
4188 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4192 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
4194 else if (aFlag == "-colorlabel"
4195 || aFlag == "-colorlabels")
4197 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4198 theArgVec + anArgIter + 1,
4202 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4205 anArgIter += aNbParsed;
4207 else if (aFlag == "-colorarrowx")
4209 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4210 theArgVec + anArgIter + 1,
4214 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4217 anArgIter += aNbParsed;
4219 else if (aFlag == "-colorarrowy")
4221 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4222 theArgVec + anArgIter + 1,
4226 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4229 anArgIter += aNbParsed;
4231 else if (aFlag == "-colorarrowz")
4233 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4234 theArgVec + anArgIter + 1,
4238 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4241 anArgIter += aNbParsed;
4245 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4250 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
4251 aSizeRatio, anArrowDiam, aNbFacets);
4252 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
4257 //==============================================================================
4258 //function : VRotate
4259 //purpose : Camera Rotating
4260 //==============================================================================
4262 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
4264 Handle(V3d_View) aView = ViewerTest::CurrentView();
4267 std::cout << "No active view!\n";
4271 Standard_Boolean hasFlags = Standard_False;
4272 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4274 Standard_CString anArg (theArgVec[anArgIter]);
4275 TCollection_AsciiString aFlag (anArg);
4277 if (aFlag == "-mousestart"
4278 || aFlag == "-mousefrom")
4280 hasFlags = Standard_True;
4281 if (anArgIter + 2 >= theArgNb)
4283 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4287 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
4288 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
4289 aView->StartRotation (anX, anY);
4291 else if (aFlag == "-mousemove")
4293 hasFlags = Standard_True;
4294 if (anArgIter + 2 >= theArgNb)
4296 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4300 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
4301 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
4302 aView->Rotation (anX, anY);
4304 else if (theArgNb != 4
4307 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4316 else if (theArgNb == 4)
4318 Standard_Real anAX = Draw::Atof (theArgVec[1]);
4319 Standard_Real anAY = Draw::Atof (theArgVec[2]);
4320 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
4321 aView->Rotate (anAX, anAY, anAZ);
4324 else if (theArgNb == 7)
4326 Standard_Real anAX = Draw::Atof (theArgVec[1]);
4327 Standard_Real anAY = Draw::Atof (theArgVec[2]);
4328 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
4330 Standard_Real anX = Draw::Atof (theArgVec[4]);
4331 Standard_Real anY = Draw::Atof (theArgVec[5]);
4332 Standard_Real anZ = Draw::Atof (theArgVec[6]);
4334 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
4338 std::cout << "Error: Invalid number of arguments\n";
4342 //==============================================================================
4344 //purpose : View zoom in / out (relative to current zoom)
4345 //==============================================================================
4347 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4348 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4349 if ( V3dView.IsNull() ) {
4354 Standard_Real coef = Draw::Atof(argv[1]);
4355 if ( coef <= 0.0 ) {
4356 di << argv[1] << "Invalid value\n";
4359 V3dView->SetZoom( Draw::Atof(argv[1]) );
4362 di << argv[0] << " Invalid number of arguments\n";
4367 //==============================================================================
4369 //purpose : View panning (in pixels)
4370 //==============================================================================
4372 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4373 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4374 if ( V3dView.IsNull() ) return 1;
4377 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
4380 di << argv[0] << " Invalid number of arguments\n";
4385 //==============================================================================
4387 //purpose : Place the point (in pixels) at the center of the window
4388 //==============================================================================
4389 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
4391 Handle(V3d_View) aView = ViewerTest::CurrentView();
4394 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
4400 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
4404 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
4409 static int VColorScale (Draw_Interpretor& theDI,
4410 Standard_Integer theArgNb,
4411 const char** theArgVec)
4413 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4414 Handle(V3d_View) aView = ViewerTest::CurrentView();
4415 if (aContext.IsNull())
4417 std::cout << "Error: no active view!\n";
4422 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
4426 Handle(AIS_ColorScale) aColorScale;
4427 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
4429 // find existing object
4430 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
4431 if (aColorScale.IsNull())
4433 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
4440 if (aColorScale.IsNull())
4442 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
4446 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
4447 << "Min range: " << aColorScale->GetMin() << "\n"
4448 << "Max range: " << aColorScale->GetMax() << "\n"
4449 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
4450 << "Text height: " << aColorScale->GetTextHeight() << "\n"
4451 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
4452 << "Color scale title: " << aColorScale->GetTitle() << "\n"
4453 << "Label position: ";
4454 switch (aColorScale->GetLabelPosition())
4456 case Aspect_TOCSP_NONE:
4459 case Aspect_TOCSP_LEFT:
4462 case Aspect_TOCSP_RIGHT:
4465 case Aspect_TOCSP_CENTER:
4466 theDI << "Center\n";
4472 if (aColorScale.IsNull())
4474 aColorScale = new AIS_ColorScale();
4475 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4476 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
4479 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
4480 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
4482 Standard_CString anArg = theArgVec[anArgIter];
4483 TCollection_AsciiString aFlag (anArg);
4485 if (anUpdateTool.parseRedrawMode (aFlag))
4489 else if (aFlag == "-range")
4491 if (anArgIter + 3 >= theArgNb)
4493 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4497 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
4498 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
4499 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
4500 if (!aRangeMin.IsRealValue()
4501 || !aRangeMax.IsRealValue())
4503 std::cout << "Error: the range values should be real!\n";
4506 else if (!aNbIntervals.IsIntegerValue())
4508 std::cout << "Error: the number of intervals should be integer!\n";
4512 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
4513 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
4515 else if (aFlag == "-font")
4517 if (anArgIter + 1 >= theArgNb)
4519 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4522 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
4523 if (!aFontArg.IsIntegerValue())
4525 std::cout << "Error: HeightFont value should be integer!\n";
4529 aColorScale->SetTextHeight (aFontArg.IntegerValue());
4532 else if (aFlag == "-textpos")
4534 if (anArgIter + 1 >= theArgNb)
4536 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4540 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
4541 aTextPosArg.LowerCase();
4542 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
4543 if (aTextPosArg == "none")
4545 aLabPosition = Aspect_TOCSP_NONE;
4547 else if (aTextPosArg == "left")
4549 aLabPosition = Aspect_TOCSP_LEFT;
4551 else if (aTextPosArg == "right")
4553 aLabPosition = Aspect_TOCSP_RIGHT;
4555 else if (aTextPosArg == "center")
4557 aLabPosition = Aspect_TOCSP_CENTER;
4561 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
4564 aColorScale->SetLabelPosition (aLabPosition);
4566 else if (aFlag == "-logarithmic"
4569 if (anArgIter + 1 >= theArgNb)
4571 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4575 Standard_Boolean IsLog;
4576 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
4578 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4581 aColorScale->SetLogarithmic (IsLog);
4583 else if (aFlag == "-huerange"
4586 if (anArgIter + 2 >= theArgNb)
4588 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4592 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
4593 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
4594 aColorScale->SetHueRange (aHueMin, aHueMax);
4596 else if (aFlag == "-colorrange")
4598 Quantity_Color aColorMin, aColorMax;
4599 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4600 theArgVec + (anArgIter + 1),
4602 anArgIter += aNbParsed1;
4603 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4604 theArgVec + (anArgIter + 1),
4606 anArgIter += aNbParsed2;
4610 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4614 aColorScale->SetColorRange (aColorMin, aColorMax);
4616 else if (aFlag == "-reversed"
4617 || aFlag == "-inverted"
4618 || aFlag == "-topdown"
4619 || aFlag == "-bottomup")
4621 Standard_Boolean toEnable = Standard_True;
4622 if (anArgIter + 1 < theArgNb
4623 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
4627 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
4629 else if (aFlag == "-smooth"
4630 || aFlag == "-smoothtransition")
4632 Standard_Boolean toEnable = Standard_True;
4633 if (anArgIter + 1 < theArgNb
4634 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4638 aColorScale->SetSmoothTransition (toEnable);
4640 else if (aFlag == "-xy")
4642 if (anArgIter + 2 >= theArgNb)
4644 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4648 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
4649 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
4650 if (!anX.IsIntegerValue()
4651 || !anY.IsIntegerValue())
4653 std::cout << "Error: coordinates should be integer values!\n";
4657 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
4659 else if (aFlag == "-width"
4661 || aFlag == "-breadth")
4663 if (anArgIter + 1 >= theArgNb)
4665 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4669 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
4670 if (!aBreadth.IsIntegerValue())
4672 std::cout << "Error: a width should be an integer value!\n";
4675 aColorScale->SetBreadth (aBreadth.IntegerValue());
4677 else if (aFlag == "-height"
4680 if (anArgIter + 1 >= theArgNb)
4682 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4686 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
4687 if (!aHeight.IsIntegerValue())
4689 std::cout << "Error: a width should be an integer value!\n";
4692 aColorScale->SetHeight (aHeight.IntegerValue());
4694 else if (aFlag == "-color")
4696 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4698 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
4701 else if (anArgIter + 2 >= theArgNb)
4703 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4707 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
4708 if (!anInd.IsIntegerValue())
4710 std::cout << "Error: Index value should be integer!\n";
4713 const Standard_Integer anIndex = anInd.IntegerValue();
4714 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
4716 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
4720 Quantity_Color aColor;
4721 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4722 theArgVec + (anArgIter + 1),
4726 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4729 aColorScale->SetIntervalColor (aColor, anIndex);
4730 aColorScale->SetColorType (Aspect_TOCSD_USER);
4731 anArgIter += aNbParsed;
4733 else if (aFlag == "-label")
4735 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4737 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
4740 else if (anArgIter + 2 >= theArgNb)
4742 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4746 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4747 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
4749 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
4753 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4754 aColorScale->SetLabel (aText, anIndex);
4755 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4758 else if (aFlag == "-labelat"
4759 || aFlag == "-labat"
4760 || aFlag == "-labelatborder"
4761 || aFlag == "-labatborder"
4762 || aFlag == "-labelatcenter"
4763 || aFlag == "-labatcenter")
4765 Standard_Boolean toEnable = Standard_True;
4766 if (aFlag == "-labelat"
4767 || aFlag == "-labat")
4769 Standard_Integer aLabAtBorder = -1;
4770 if (++anArgIter >= theArgNb)
4772 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4773 anAtBorder.LowerCase();
4774 if (anAtBorder == "border")
4778 else if (anAtBorder == "center")
4783 if (aLabAtBorder == -1)
4785 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4788 toEnable = (aLabAtBorder == 1);
4790 else if (anArgIter + 1 < theArgNb
4791 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4795 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4796 || aFlag == "-labatcenter"
4800 else if (aFlag == "-colors")
4802 Aspect_SequenceOfColor aSeq;
4805 Quantity_Color aColor;
4806 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4807 theArgVec + (anArgIter + 1),
4813 anArgIter += aNbParsed;
4814 aSeq.Append (aColor);
4816 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
4818 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4819 << aColorScale->GetNumberOfIntervals() << " intervals\n";
4823 aColorScale->SetColors (aSeq);
4824 aColorScale->SetColorType (Aspect_TOCSD_USER);
4826 else if (aFlag == "-labels"
4827 || aFlag == "-freelabels")
4829 if (anArgIter + 1 >= theArgNb)
4831 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4835 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4836 ? aColorScale->GetNumberOfIntervals() + 1
4837 : aColorScale->GetNumberOfIntervals();
4838 if (aFlag == "-freelabels")
4841 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4843 if (anArgIter + aNbLabels >= theArgNb)
4845 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
4849 TColStd_SequenceOfExtendedString aSeq;
4850 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
4852 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
4854 aColorScale->SetLabels (aSeq);
4855 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4857 else if (aFlag == "-title")
4859 if (anArgIter + 1 >= theArgNb)
4861 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4865 Standard_Boolean isTwoArgs = Standard_False;
4866 if (anArgIter + 2 < theArgNb)
4868 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4869 aSecondArg.LowerCase();
4870 Standard_DISABLE_DEPRECATION_WARNINGS
4871 if (aSecondArg == "none")
4873 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
4874 isTwoArgs = Standard_True;
4876 else if (aSecondArg == "left")
4878 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
4879 isTwoArgs = Standard_True;
4881 else if (aSecondArg == "right")
4883 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
4884 isTwoArgs = Standard_True;
4886 else if (aSecondArg == "center")
4888 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
4889 isTwoArgs = Standard_True;
4891 Standard_ENABLE_DEPRECATION_WARNINGS
4894 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
4901 else if (aFlag == "-demoversion"
4902 || aFlag == "-demo")
4904 aColorScale->SetPosition (0, 0);
4905 aColorScale->SetTextHeight (16);
4906 aColorScale->SetRange (0.0, 100.0);
4907 aColorScale->SetNumberOfIntervals (10);
4908 aColorScale->SetBreadth (0);
4909 aColorScale->SetHeight (0);
4910 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4911 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4912 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
4914 else if (aFlag == "-findcolor")
4916 if (anArgIter + 1 >= theArgNb)
4918 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4922 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4924 if (!anArg1.IsRealValue())
4926 std::cout << "Error: the value should be real!\n";
4930 Quantity_Color aColor;
4931 aColorScale->FindColor (anArg1.RealValue(), aColor);
4932 theDI << Quantity_Color::StringName (aColor.Name());
4937 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4942 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4943 aView->Window()->Size (aWinWidth, aWinHeight);
4944 if (aColorScale->GetBreadth() == 0)
4946 aColorScale->SetBreadth (aWinWidth);
4948 if (aColorScale->GetHeight() == 0)
4950 aColorScale->SetHeight (aWinHeight);
4952 aColorScale->SetToUpdate();
4953 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
4957 //==============================================================================
4958 //function : VGraduatedTrihedron
4959 //purpose : Displays or hides a graduated trihedron
4960 //==============================================================================
4961 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4962 Quantity_Color& theColor)
4964 Quantity_NameOfColor aColorName;
4965 TCollection_AsciiString aVal = theValue;
4967 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
4969 return Standard_False;
4971 theColor = Quantity_Color (aColorName);
4972 return Standard_True;
4975 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
4979 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4980 << theArgs[0] <<"' for more information.\n";
4981 return 1; //TCL_ERROR
4984 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4985 TCollection_AsciiString aParseKey;
4986 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4988 TCollection_AsciiString anArg (theArgs [anArgIt]);
4990 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4993 aParseKey.Remove (1);
4994 aParseKey.LowerCase();
4995 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4999 if (aParseKey.IsEmpty())
5004 aMapOfArgs(aParseKey)->Append (anArg);
5008 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
5009 aMapIt.More(); aMapIt.Next())
5011 const TCollection_AsciiString& aKey = aMapIt.Key();
5012 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
5014 // Bool key, without arguments
5015 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
5016 && anArgs->IsEmpty())
5022 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
5023 && anArgs->Length() == 1)
5029 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
5030 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
5031 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
5032 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
5033 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
5038 // One string argument
5039 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
5040 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
5041 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
5046 // One integer argument
5047 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
5048 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
5049 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
5050 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
5051 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
5056 // One real argument
5057 if ( aKey.IsEqual ("arrowlength")
5058 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
5063 // Two string arguments
5064 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
5065 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
5070 TCollection_AsciiString aLowerKey;
5073 aLowerKey.LowerCase();
5074 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
5075 std::cout << "Type help for more information.\n";
5079 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5080 if (anAISContext.IsNull())
5082 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
5086 Standard_Boolean toDisplay = Standard_True;
5087 Quantity_Color aColor;
5088 Graphic3d_GraduatedTrihedron aTrihedronData;
5089 // Process parameters
5090 Handle(TColStd_HSequenceOfAsciiString) aValues;
5091 if (aMapOfArgs.Find ("off", aValues))
5093 toDisplay = Standard_False;
5097 if (aMapOfArgs.Find ("xname", aValues))
5099 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
5101 if (aMapOfArgs.Find ("yname", aValues))
5103 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
5105 if (aMapOfArgs.Find ("zname", aValues))
5107 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
5109 if (aMapOfArgs.Find ("xdrawname", aValues))
5111 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5113 if (aMapOfArgs.Find ("ydrawname", aValues))
5115 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5117 if (aMapOfArgs.Find ("zdrawname", aValues))
5119 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
5121 if (aMapOfArgs.Find ("xnameoffset", aValues))
5123 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5125 if (aMapOfArgs.Find ("ynameoffset", aValues))
5127 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5129 if (aMapOfArgs.Find ("znameoffset", aValues))
5131 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
5135 if (aMapOfArgs.Find ("xnamecolor", aValues))
5137 if (!GetColor (aValues->Value(1), aColor))
5139 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
5142 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
5144 if (aMapOfArgs.Find ("ynamecolor", aValues))
5146 if (!GetColor (aValues->Value(1), aColor))
5148 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
5151 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
5153 if (aMapOfArgs.Find ("znamecolor", aValues))
5155 if (!GetColor (aValues->Value(1), aColor))
5157 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
5160 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
5162 if (aMapOfArgs.Find ("xcolor", aValues))
5164 if (!GetColor (aValues->Value(1), aColor))
5166 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
5169 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
5171 if (aMapOfArgs.Find ("ycolor", aValues))
5173 if (!GetColor (aValues->Value(1), aColor))
5175 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
5178 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
5180 if (aMapOfArgs.Find ("zcolor", aValues))
5182 if (!GetColor (aValues->Value(1), aColor))
5184 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
5187 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
5191 if (aMapOfArgs.Find ("xticks", aValues))
5193 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5195 if (aMapOfArgs.Find ("yticks", aValues))
5197 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5199 if (aMapOfArgs.Find ("zticks", aValues))
5201 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
5203 if (aMapOfArgs.Find ("xticklength", aValues))
5205 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5207 if (aMapOfArgs.Find ("yticklength", aValues))
5209 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5211 if (aMapOfArgs.Find ("zticklength", aValues))
5213 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
5215 if (aMapOfArgs.Find ("xdrawticks", aValues))
5217 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5219 if (aMapOfArgs.Find ("ydrawticks", aValues))
5221 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5223 if (aMapOfArgs.Find ("zdrawticks", aValues))
5225 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
5229 if (aMapOfArgs.Find ("xdrawvalues", aValues))
5231 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5233 if (aMapOfArgs.Find ("ydrawvalues", aValues))
5235 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5237 if (aMapOfArgs.Find ("zdrawvalues", aValues))
5239 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
5241 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
5243 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5245 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
5247 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5249 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
5251 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5255 if (aMapOfArgs.Find ("arrowlength", aValues))
5257 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
5261 if (aMapOfArgs.Find ("namefont", aValues))
5263 aTrihedronData.SetNamesFont (aValues->Value(1));
5265 if (aMapOfArgs.Find ("valuesfont", aValues))
5267 aTrihedronData.SetValuesFont (aValues->Value(1));
5270 if (aMapOfArgs.Find ("drawgrid", aValues))
5272 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
5274 if (aMapOfArgs.Find ("drawaxes", aValues))
5276 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
5279 // The final step: display of erase trihedron
5282 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
5286 ViewerTest::CurrentView()->GraduatedTrihedronErase();
5289 ViewerTest::GetAISContext()->UpdateCurrentViewer();
5290 ViewerTest::CurrentView()->Redraw();
5295 //==============================================================================
5298 //==============================================================================
5299 static int VTile (Draw_Interpretor& theDI,
5300 Standard_Integer theArgNb,
5301 const char** theArgVec)
5303 Handle(V3d_View) aView = ViewerTest::CurrentView();
5306 std::cerr << "Error: no active viewer.\n";
5310 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
5313 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
5314 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
5315 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
5319 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
5320 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5322 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5324 if (anArg == "-lowerleft"
5325 || anArg == "-upperleft")
5327 if (anArgIter + 3 < theArgNb)
5329 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5332 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
5333 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5334 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5336 else if (anArg == "-total"
5337 || anArg == "-totalsize"
5338 || anArg == "-viewsize")
5340 if (anArgIter + 3 < theArgNb)
5342 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5345 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5346 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5347 if (aTile.TotalSize.x() < 1
5348 || aTile.TotalSize.y() < 1)
5350 std::cerr << "Error: total size is incorrect.\n";
5354 else if (anArg == "-tilesize")
5356 if (anArgIter + 3 < theArgNb)
5358 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5362 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5363 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5364 if (aTile.TileSize.x() < 1
5365 || aTile.TileSize.y() < 1)
5367 std::cerr << "Error: tile size is incorrect.\n";
5371 else if (anArg == "-unset")
5373 aView->Camera()->SetTile (Graphic3d_CameraTile());
5379 if (aTile.TileSize.x() < 1
5380 || aTile.TileSize.y() < 1)
5382 std::cerr << "Error: tile size is undefined.\n";
5385 else if (aTile.TotalSize.x() < 1
5386 || aTile.TotalSize.y() < 1)
5388 std::cerr << "Error: total size is undefined.\n";
5392 aView->Camera()->SetTile (aTile);
5397 //! Format ZLayer ID.
5398 inline const char* formZLayerId (const Standard_Integer theLayerId)
5402 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
5403 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
5404 case Graphic3d_ZLayerId_Top: return "[TOP]";
5405 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
5406 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
5407 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
5412 //! Print the ZLayer information.
5413 inline void printZLayerInfo (Draw_Interpretor& theDI,
5414 const Graphic3d_ZLayerSettings& theLayer)
5416 if (!theLayer.Name().IsEmpty())
5418 theDI << " Name: " << theLayer.Name() << "\n";
5420 if (theLayer.IsImmediate())
5422 theDI << " Immediate: TRUE\n";
5424 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
5425 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
5426 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
5427 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
5428 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
5429 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
5430 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
5432 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
5436 //==============================================================================
5437 //function : VZLayer
5438 //purpose : Test z layer operations for v3d viewer
5439 //==============================================================================
5440 static int VZLayer (Draw_Interpretor& theDI,
5441 Standard_Integer theArgNb,
5442 const char** theArgVec)
5444 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5445 if (aContextAIS.IsNull())
5447 std::cout << "No active viewer!\n";
5451 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
5454 TColStd_SequenceOfInteger aLayers;
5455 aViewer->GetAllZLayers (aLayers);
5456 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5458 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
5459 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
5460 printZLayerInfo (theDI, aSettings);
5465 Standard_Integer anArgIter = 1;
5466 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5467 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
5468 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5474 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
5475 if (aFirstArg.IsIntegerValue())
5478 aLayerId = aFirstArg.IntegerValue();
5482 if (ViewerTest::ParseZLayerName (aFirstArg.ToCString(), aLayerId))
5489 Graphic3d_ZLayerId anOtherLayerId = Graphic3d_ZLayerId_UNKNOWN;
5490 for (; anArgIter < theArgNb; ++anArgIter)
5492 // perform operation
5493 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5495 if (anUpdateTool.parseRedrawMode (anArg))
5499 else if (anArg == "-add"
5502 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5503 if (!aViewer->AddZLayer (aLayerId))
5505 std::cout << "Error: can not add a new z layer!\n";
5511 else if (anArg == "-insertbefore"
5512 && anArgIter + 1 < theArgNb
5513 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
5516 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5517 if (!aViewer->InsertLayerBefore (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
5519 std::cout << "Error: can not add a new z layer!\n";
5525 else if (anArg == "-insertafter"
5526 && anArgIter + 1 < theArgNb
5527 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
5530 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5531 if (!aViewer->InsertLayerAfter (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
5533 std::cout << "Error: can not add a new z layer!\n";
5539 else if (anArg == "-del"
5540 || anArg == "-delete"
5543 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5545 if (++anArgIter >= theArgNb)
5547 std::cout << "Syntax error: id of z layer to remove is missing\n";
5551 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5554 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
5555 || aLayerId == Graphic3d_ZLayerId_Default
5556 || aLayerId == Graphic3d_ZLayerId_Top
5557 || aLayerId == Graphic3d_ZLayerId_Topmost
5558 || aLayerId == Graphic3d_ZLayerId_TopOSD
5559 || aLayerId == Graphic3d_ZLayerId_BotOSD)
5561 std::cout << "Syntax error: standard Z layer can not be removed\n";
5565 // move all object displayed in removing layer to default layer
5566 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5567 anObjIter.More(); anObjIter.Next())
5569 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
5571 || aPrs->ZLayer() != aLayerId)
5575 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
5578 if (!aViewer->RemoveZLayer (aLayerId))
5580 std::cout << "Z layer can not be removed!\n";
5584 theDI << aLayerId << " ";
5587 else if (anArg == "-get"
5590 TColStd_SequenceOfInteger aLayers;
5591 aViewer->GetAllZLayers (aLayers);
5592 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5594 theDI << aLayeriter.Value() << " ";
5599 else if (anArg == "-name")
5601 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5603 std::cout << "Syntax error: id of Z layer is missing\n";
5607 if (++anArgIter >= theArgNb)
5609 std::cout << "Syntax error: name is missing\n";
5613 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5614 aSettings.SetName (theArgVec[anArgIter]);
5615 aViewer->SetZLayerSettings (aLayerId, aSettings);
5617 else if (anArg == "-origin")
5619 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5621 std::cout << "Syntax error: id of Z layer is missing\n";
5625 if (anArgIter + 2 >= theArgNb)
5627 std::cout << "Syntax error: origin coordinates are missing\n";
5631 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5633 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
5634 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
5635 anOrigin.SetZ (0.0);
5636 if (anArgIter + 3 < theArgNb)
5638 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
5645 aSettings.SetOrigin (anOrigin);
5646 aViewer->SetZLayerSettings (aLayerId, aSettings);
5648 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5649 && anArgIter + 1 < theArgNb
5650 && (anArg == "-cullingdistance"
5651 || anArg == "-cullingdist"
5652 || anArg == "-culldistance"
5653 || anArg == "-culldist"
5654 || anArg == "-distcull"
5655 || anArg == "-distculling"
5656 || anArg == "-distanceculling"))
5658 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5659 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
5660 aSettings.SetCullingDistance (aDist);
5661 aViewer->SetZLayerSettings (aLayerId, aSettings);
5663 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5664 && anArgIter + 1 < theArgNb
5665 && (anArg == "-cullingsize"
5666 || anArg == "-cullsize"
5667 || anArg == "-sizecull"
5668 || anArg == "-sizeculling"))
5670 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5671 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
5672 aSettings.SetCullingSize (aSize);
5673 aViewer->SetZLayerSettings (aLayerId, aSettings);
5675 else if (anArg == "-settings"
5676 || anArg == "settings")
5678 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5680 if (++anArgIter >= theArgNb)
5682 std::cout << "Syntax error: id of Z layer is missing\n";
5686 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5689 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5690 printZLayerInfo (theDI, aSettings);
5692 else if (anArg == "-enable"
5693 || anArg == "enable"
5694 || anArg == "-disable"
5695 || anArg == "disable")
5697 const Standard_Boolean toEnable = anArg == "-enable"
5698 || anArg == "enable";
5699 if (++anArgIter >= theArgNb)
5701 std::cout << "Syntax error: option name is missing\n";
5705 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
5707 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5709 if (++anArgIter >= theArgNb)
5711 std::cout << "Syntax error: id of Z layer is missing\n";
5715 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5718 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5719 if (aSubOp == "depthtest"
5720 || aSubOp == "test")
5722 aSettings.SetEnableDepthTest (toEnable);
5724 else if (aSubOp == "depthwrite"
5725 || aSubOp == "write")
5727 aSettings.SetEnableDepthWrite (toEnable);
5729 else if (aSubOp == "depthclear"
5730 || aSubOp == "clear")
5732 aSettings.SetClearDepth (toEnable);
5734 else if (aSubOp == "depthoffset"
5735 || aSubOp == "offset")
5737 Graphic3d_PolygonOffset aParams;
5738 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5741 if (anArgIter + 2 >= theArgNb)
5743 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5747 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5748 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5750 aSettings.SetPolygonOffset (aParams);
5752 else if (aSubOp == "positiveoffset"
5753 || aSubOp == "poffset")
5757 aSettings.SetDepthOffsetPositive();
5761 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5764 else if (aSubOp == "negativeoffset"
5765 || aSubOp == "noffset")
5769 aSettings.SetDepthOffsetNegative();
5773 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5776 else if (aSubOp == "textureenv")
5778 aSettings.SetEnvironmentTexture (toEnable);
5780 else if (aSubOp == "raytracing")
5782 aSettings.SetRaytracable (toEnable);
5785 aViewer->SetZLayerSettings (aLayerId, aSettings);
5789 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5797 // The interactive presentation of 2d layer item
5798 // for "vlayerline" command it provides a presentation of
5799 // line with user-defined linewidth, linetype and transparency.
5800 class V3d_LineItem : public AIS_InteractiveObject
5804 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
5807 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5808 Standard_Real X2, Standard_Real Y2,
5809 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5810 Standard_Real theWidth = 0.5,
5811 Standard_Real theTransp = 1.0);
5815 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5816 const Handle(Prs3d_Presentation)& thePresentation,
5817 const Standard_Integer theMode) Standard_OVERRIDE;
5819 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
5820 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5825 Standard_Real myX1, myY1, myX2, myY2;
5826 Aspect_TypeOfLine myType;
5827 Standard_Real myWidth;
5830 // default constructor for line item
5831 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5832 Standard_Real X2, Standard_Real Y2,
5833 Aspect_TypeOfLine theType,
5834 Standard_Real theWidth,
5835 Standard_Real theTransp) :
5836 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5837 myType(theType), myWidth(theWidth)
5839 SetTransparency (1-theTransp);
5843 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5844 const Handle(Prs3d_Presentation)& thePresentation,
5845 const Standard_Integer /*theMode*/)
5847 thePresentation->Clear();
5848 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
5849 Standard_Integer aWidth, aHeight;
5850 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5851 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5852 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5853 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5854 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5855 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5856 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5857 aGroup->AddPrimitiveArray (aPrim);
5860 //=============================================================================
5861 //function : VLayerLine
5862 //purpose : Draws line in the v3d view layer with given attributes: linetype,
5863 // : linewidth, transparency coefficient
5864 //============================================================================
5865 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5867 // get the active view
5868 Handle(V3d_View) aView = ViewerTest::CurrentView();
5871 di << "Call vinit before!\n";
5876 di << "Use: " << argv[0];
5877 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5878 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5879 di << " 0 - solid \n";
5880 di << " 1 - dashed \n";
5881 di << " 2 - dot \n";
5882 di << " 3 - dashdot\n";
5883 di << " transparency : { 0.0 - 1.0 } \n";
5884 di << " 0.0 - transparent\n";
5885 di << " 1.0 - visible \n";
5889 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5890 // get the input params
5891 Standard_Real X1 = Draw::Atof(argv[1]);
5892 Standard_Real Y1 = Draw::Atof(argv[2]);
5893 Standard_Real X2 = Draw::Atof(argv[3]);
5894 Standard_Real Y2 = Draw::Atof(argv[4]);
5896 Standard_Real aWidth = 0.5;
5897 Standard_Real aTransparency = 1.0;
5901 aWidth = Draw::Atof(argv[5]);
5903 // select appropriate line type
5904 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5906 && !ViewerTest::ParseLineType (argv[6], aLineType))
5908 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5915 aTransparency = Draw::Atof(argv[7]);
5916 if (aTransparency < 0 || aTransparency > 1.0)
5917 aTransparency = 1.0;
5920 static Handle (V3d_LineItem) aLine;
5921 if (!aLine.IsNull())
5923 aContext->Erase (aLine, Standard_False);
5925 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5929 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5930 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5931 aLine->SetToUpdate();
5932 aContext->Display (aLine, Standard_True);
5938 //==============================================================================
5941 //==============================================================================
5943 static int VGrid (Draw_Interpretor& /*theDI*/,
5944 Standard_Integer theArgNb,
5945 const char** theArgVec)
5947 Handle(V3d_View) aView = ViewerTest::CurrentView();
5948 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5949 if (aView.IsNull() || aViewer.IsNull())
5951 std::cerr << "Error: no active view\n";
5955 Aspect_GridType aType = aViewer->GridType();
5956 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5957 Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY;
5958 Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0;
5959 bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false;
5960 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5961 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5963 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5965 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5969 else if (anArgIter + 1 < theArgNb
5970 && anArg == "-type")
5972 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5973 anArgNext.LowerCase();
5974 if (anArgNext == "r"
5975 || anArgNext == "rect"
5976 || anArgNext == "rectangular")
5978 aType = Aspect_GT_Rectangular;
5980 else if (anArgNext == "c"
5981 || anArgNext == "circ"
5982 || anArgNext == "circular")
5984 aType = Aspect_GT_Circular;
5988 std::cout << "Syntax error at '" << anArgNext << "'\n";
5992 else if (anArgIter + 1 < theArgNb
5993 && anArg == "-mode")
5995 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5996 anArgNext.LowerCase();
5997 if (anArgNext == "l"
5998 || anArgNext == "line"
5999 || anArgNext == "lines")
6001 aMode = Aspect_GDM_Lines;
6003 else if (anArgNext == "p"
6004 || anArgNext == "point"
6005 || anArgNext == "points")
6007 aMode = Aspect_GDM_Points;
6011 std::cout << "Syntax error at '" << anArgNext << "'\n";
6015 else if (anArgIter + 2 < theArgNb
6016 && (anArg == "-origin"
6017 || anArg == "-orig"))
6020 aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6021 Draw::Atof (theArgVec[anArgIter + 2]));
6024 else if (anArgIter + 2 < theArgNb
6025 && anArg == "-step")
6028 aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6029 Draw::Atof (theArgVec[anArgIter + 2]));
6030 if (aNewStepXY.x() <= 0.0
6031 || aNewStepXY.y() <= 0.0)
6033 std::cout << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
6038 else if (anArgIter + 1 < theArgNb
6039 && (anArg == "-angle"
6040 || anArg == "-rotangle"
6041 || anArg == "-rotationangle"))
6044 aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]);
6046 else if (anArgIter + 1 < theArgNb
6047 && (anArg == "-zoffset"
6051 aNewZOffset = Draw::Atof (theArgVec[++anArgIter]);
6053 else if (anArgIter + 1 < theArgNb
6054 && anArg == "-radius")
6058 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0);
6059 if (aNewStepXY.x() <= 0.0)
6061 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'\n";
6065 else if (anArgIter + 2 < theArgNb
6066 && anArg == "-size")
6069 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
6070 Draw::Atof (theArgVec[anArgIter + 2]));
6071 if (aNewStepXY.x() <= 0.0
6072 || aNewStepXY.y() <= 0.0)
6074 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
6079 else if (anArg == "r"
6081 || anArg == "rectangular")
6083 aType = Aspect_GT_Rectangular;
6085 else if (anArg == "c"
6087 || anArg == "circular")
6089 aType = Aspect_GT_Circular;
6091 else if (anArg == "l"
6093 || anArg == "lines")
6095 aMode = Aspect_GDM_Lines;
6097 else if (anArg == "p"
6099 || anArg == "points")
6101 aMode = Aspect_GDM_Points;
6103 else if (anArgIter + 1 >= theArgNb
6106 aViewer->DeactivateGrid();
6111 std::cout << "Syntax error at '" << anArg << "'\n";
6116 if (aType == Aspect_GT_Rectangular)
6118 Graphic3d_Vec2d anOrigXY, aStepXY;
6119 Standard_Real aRotAngle = 0.0;
6120 aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
6123 anOrigXY = aNewOriginXY;
6127 aStepXY = aNewStepXY;
6131 aRotAngle = aNewRotAngle;
6133 aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
6134 if (hasSize || hasZOffset)
6136 Graphic3d_Vec3d aSize;
6137 aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
6140 aSize.x() = aNewSizeXY.x();
6141 aSize.y() = aNewSizeXY.y();
6145 aSize.z() = aNewZOffset;
6147 aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
6150 else if (aType == Aspect_GT_Circular)
6152 Graphic3d_Vec2d anOrigXY;
6153 Standard_Real aRadiusStep;
6154 Standard_Integer aDivisionNumber;
6155 Standard_Real aRotAngle = 0.0;
6156 aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6159 anOrigXY = aNewOriginXY;
6163 aRadiusStep = aNewStepXY[0];
6164 aDivisionNumber = (int )aNewStepXY[1];
6165 if (aDivisionNumber < 1)
6167 std::cout << "Syntax error: invalid division number '" << aNewStepXY[1] << "'\n";
6173 aRotAngle = aNewRotAngle;
6176 aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6177 if (hasSize || hasZOffset)
6179 Standard_Real aRadius = 0.0, aZOffset = 0.0;
6180 aViewer->CircularGridGraphicValues (aRadius, aZOffset);
6183 aRadius = aNewSizeXY.x();
6184 if (aNewSizeXY.y() != 0.0)
6186 std::cout << "Syntax error: circular size should be specified as radius\n";
6192 aZOffset = aNewZOffset;
6194 aViewer->SetCircularGridGraphicValues (aRadius, aZOffset);
6197 aViewer->ActivateGrid (aType, aMode);
6201 //==============================================================================
6202 //function : VPriviledgedPlane
6204 //==============================================================================
6206 static int VPriviledgedPlane (Draw_Interpretor& theDI,
6207 Standard_Integer theArgNb,
6208 const char** theArgVec)
6210 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
6212 std::cerr << "Error: wrong number of arguments! See usage:\n";
6213 theDI.PrintHelp (theArgVec[0]);
6217 // get the active viewer
6218 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6219 if (aViewer.IsNull())
6221 std::cerr << "Error: no active viewer. Please call vinit.\n";
6227 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
6228 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
6229 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
6230 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
6231 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
6232 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
6233 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
6237 Standard_Integer anArgIdx = 1;
6238 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
6239 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
6240 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
6241 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
6242 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
6243 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
6245 gp_Ax3 aPriviledgedPlane;
6246 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
6247 gp_Dir aNorm (aNormX, aNormY, aNormZ);
6250 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
6251 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
6252 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
6253 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
6254 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
6258 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
6261 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
6266 //==============================================================================
6267 //function : VConvert
6269 //==============================================================================
6271 static int VConvert (Draw_Interpretor& theDI,
6272 Standard_Integer theArgNb,
6273 const char** theArgVec)
6275 // get the active view
6276 Handle(V3d_View) aView = ViewerTest::CurrentView();
6279 std::cerr << "Error: no active view. Please call vinit.\n";
6283 enum { Model, Ray, View, Window, Grid } aMode = Model;
6285 // access coordinate arguments
6286 TColStd_SequenceOfReal aCoord;
6287 Standard_Integer anArgIdx = 1;
6288 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
6290 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6291 if (!anArg.IsRealValue())
6295 aCoord.Append (anArg.RealValue());
6298 // non-numeric argument too early
6299 if (aCoord.IsEmpty())
6301 std::cerr << "Error: wrong number of arguments! See usage:\n";
6302 theDI.PrintHelp (theArgVec[0]);
6306 // collect all other arguments and options
6307 for (; anArgIdx < theArgNb; ++anArgIdx)
6309 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6311 if (anArg == "window") aMode = Window;
6312 else if (anArg == "view") aMode = View;
6313 else if (anArg == "grid") aMode = Grid;
6314 else if (anArg == "ray") aMode = Ray;
6317 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
6318 theDI.PrintHelp (theArgVec[0]);
6323 // complete input checks
6324 if ((aCoord.Length() == 1 && theArgNb > 3) ||
6325 (aCoord.Length() == 2 && theArgNb > 4) ||
6326 (aCoord.Length() == 3 && theArgNb > 5))
6328 std::cerr << "Error: wrong number of arguments! See usage:\n";
6329 theDI.PrintHelp (theArgVec[0]);
6333 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
6334 Standard_Integer aXYp[2] = {0, 0};
6336 // convert one-dimensional coordinate
6337 if (aCoord.Length() == 1)
6341 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
6342 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
6344 std::cerr << "Error: wrong arguments! See usage:\n";
6345 theDI.PrintHelp (theArgVec[0]);
6350 // convert 2D coordinates from projection or view reference space
6351 if (aCoord.Length() == 2)
6356 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6357 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6361 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
6362 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
6366 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
6367 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6371 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6372 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
6373 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6377 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
6378 (Standard_Integer) aCoord (2),
6379 aXYZ[0], aXYZ[1], aXYZ[2],
6380 aXYZ[3], aXYZ[4], aXYZ[5]);
6381 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6385 std::cerr << "Error: wrong arguments! See usage:\n";
6386 theDI.PrintHelp (theArgVec[0]);
6391 // convert 3D coordinates from view reference space
6392 else if (aCoord.Length() == 3)
6397 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
6398 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6402 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
6403 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6407 std::cerr << "Error: wrong arguments! See usage:\n";
6408 theDI.PrintHelp (theArgVec[0]);
6416 //==============================================================================
6419 //==============================================================================
6421 static int VFps (Draw_Interpretor& theDI,
6422 Standard_Integer theArgNb,
6423 const char** theArgVec)
6425 // get the active view
6426 Handle(V3d_View) aView = ViewerTest::CurrentView();
6429 std::cerr << "No active view. Please call vinit.\n";
6433 Standard_Integer aFramesNb = -1;
6434 Standard_Real aDuration = -1.0;
6435 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6437 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6440 && anArgIter + 1 < theArgNb
6441 && (anArg == "-duration"
6443 || anArg == "-time"))
6445 aDuration = Draw::Atof (theArgVec[++anArgIter]);
6447 else if (aFramesNb < 0
6448 && anArg.IsIntegerValue())
6450 aFramesNb = anArg.IntegerValue();
6453 std::cerr << "Syntax error at '" << anArg << "'\n";
6459 std::cerr << "Syntax error at '" << anArg << "'\n";
6463 if (aFramesNb < 0 && aDuration < 0.0)
6468 // the time is meaningless for first call
6469 // due to async OpenGl rendering
6472 // redraw view in loop to estimate average values
6475 Standard_Integer aFrameIter = 1;
6476 for (;; ++aFrameIter)
6480 && aFrameIter >= aFramesNb)
6482 && aTimer.ElapsedTime() >= aDuration))
6489 const Standard_Real aTime = aTimer.ElapsedTime();
6490 aTimer.OSD_Chronometer::Show (aCpu);
6492 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
6493 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
6495 // return statistics
6496 theDI << "FPS: " << aFpsAver << "\n"
6497 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
6499 // compute additional statistics in ray-tracing mode
6500 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
6501 if (aParams.Method == Graphic3d_RM_RAYTRACING)
6503 Graphic3d_Vec2i aWinSize (0, 0);
6504 aView->Window()->Size (aWinSize.x(), aWinSize.y());
6506 // 1 shadow ray and 1 secondary ray pew each bounce
6507 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
6508 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
6514 //! Auxiliary function for parsing glsl dump level argument.
6515 static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
6516 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
6518 TCollection_AsciiString aTypeStr (theArg);
6519 aTypeStr.LowerCase();
6520 if (aTypeStr == "off"
6523 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6525 else if (aTypeStr == "short")
6527 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
6529 else if (aTypeStr == "full"
6532 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6536 return Standard_False;
6538 return Standard_True;
6541 //==============================================================================
6542 //function : VGlDebug
6544 //==============================================================================
6546 static int VGlDebug (Draw_Interpretor& theDI,
6547 Standard_Integer theArgNb,
6548 const char** theArgVec)
6550 Handle(OpenGl_GraphicDriver) aDriver;
6551 Handle(V3d_View) aView = ViewerTest::CurrentView();
6552 if (!aView.IsNull())
6554 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
6556 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
6557 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
6561 TCollection_AsciiString aDebActive, aSyncActive;
6568 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
6569 "GL_ARB_debug_output");
6570 aDebActive = isActive ? " (active)" : " (inactive)";
6573 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
6574 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
6578 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
6579 + "glslSourceCode: "
6580 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
6582 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
6586 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
6587 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
6588 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
6589 << aGlslCodeDebugStatus
6590 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
6594 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6596 Standard_CString anArg = theArgVec[anArgIter];
6597 TCollection_AsciiString anArgCase (anArg);
6598 anArgCase.LowerCase();
6599 Standard_Boolean toEnableDebug = Standard_True;
6600 if (anArgCase == "-glsl"
6601 || anArgCase == "-glslwarn"
6602 || anArgCase == "-glslwarns"
6603 || anArgCase == "-glslwarnings")
6605 Standard_Boolean toShowWarns = Standard_True;
6606 if (++anArgIter < theArgNb
6607 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
6611 aDefCaps->glslWarnings = toShowWarns;
6614 aCaps->glslWarnings = toShowWarns;
6617 else if (anArgCase == "-extra"
6618 || anArgCase == "-extramsg"
6619 || anArgCase == "-extramessages")
6621 Standard_Boolean toShow = Standard_True;
6622 if (++anArgIter < theArgNb
6623 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
6627 aDefCaps->suppressExtraMsg = !toShow;
6630 aCaps->suppressExtraMsg = !toShow;
6633 else if (anArgCase == "-noextra"
6634 || anArgCase == "-noextramsg"
6635 || anArgCase == "-noextramessages")
6637 Standard_Boolean toSuppress = Standard_True;
6638 if (++anArgIter < theArgNb
6639 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
6643 aDefCaps->suppressExtraMsg = toSuppress;
6646 aCaps->suppressExtraMsg = toSuppress;
6649 else if (anArgCase == "-sync")
6651 Standard_Boolean toSync = Standard_True;
6652 if (++anArgIter < theArgNb
6653 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
6657 aDefCaps->contextSyncDebug = toSync;
6660 aDefCaps->contextDebug = Standard_True;
6663 else if (anArgCase == "-glslsourcecode"
6664 || anArgCase == "-glslcode")
6666 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6667 if (++anArgIter < theArgNb
6668 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
6672 aDefCaps->glslDumpLevel = aGslsDumpLevel;
6675 aCaps->glslDumpLevel = aGslsDumpLevel;
6678 else if (anArgCase == "-debug")
6680 if (++anArgIter < theArgNb
6681 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
6685 aDefCaps->contextDebug = toEnableDebug;
6687 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
6688 && (anArgIter + 1 == theArgNb))
6690 // simple alias to turn on almost everything
6691 aDefCaps->contextDebug = toEnableDebug;
6692 aDefCaps->contextSyncDebug = toEnableDebug;
6693 aDefCaps->glslWarnings = toEnableDebug;
6696 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6698 aDefCaps->suppressExtraMsg = !toEnableDebug;
6701 aCaps->contextDebug = toEnableDebug;
6702 aCaps->contextSyncDebug = toEnableDebug;
6703 aCaps->glslWarnings = toEnableDebug;
6706 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6708 aCaps->suppressExtraMsg = !toEnableDebug;
6713 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
6721 //==============================================================================
6724 //==============================================================================
6726 static int VVbo (Draw_Interpretor& theDI,
6727 Standard_Integer theArgNb,
6728 const char** theArgVec)
6730 const Standard_Boolean toSet = (theArgNb > 1);
6731 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
6734 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
6738 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6739 if (aContextAIS.IsNull())
6743 std::cerr << "No active view!\n";
6747 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
6748 if (!aDriver.IsNull())
6752 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
6756 aDriver->ChangeOptions().vboDisable = toUseVbo;
6763 //==============================================================================
6766 //==============================================================================
6768 static int VCaps (Draw_Interpretor& theDI,
6769 Standard_Integer theArgNb,
6770 const char** theArgVec)
6772 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
6773 Handle(OpenGl_GraphicDriver) aDriver;
6774 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6775 if (!aContext.IsNull())
6777 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
6778 aCaps = &aDriver->ChangeOptions();
6783 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
6784 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
6785 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
6786 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
6787 theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n";
6788 theDI << "VSync: " << aCaps->swapInterval << "\n";
6789 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
6790 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
6791 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
6792 theDI << "NoExt:" << (aCaps->contextNoExtensions ? "1" : "0") << "\n";
6793 theDI << "MaxVersion:" << aCaps->contextMajorVersionUpper << "." << aCaps->contextMinorVersionUpper << "\n";
6797 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6798 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6800 Standard_CString anArg = theArgVec[anArgIter];
6801 TCollection_AsciiString anArgCase (anArg);
6802 anArgCase.LowerCase();
6803 if (anUpdateTool.parseRedrawMode (anArg))
6807 else if (anArgCase == "-vsync"
6808 || anArgCase == "-swapinterval")
6810 Standard_Boolean toEnable = Standard_True;
6811 if (++anArgIter < theArgNb
6812 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6816 aCaps->swapInterval = toEnable;
6818 else if (anArgCase == "-ffp")
6820 Standard_Boolean toEnable = Standard_True;
6821 if (++anArgIter < theArgNb
6822 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6826 aCaps->ffpEnable = toEnable;
6828 else if (anArgCase == "-polygonmode")
6830 Standard_Boolean toEnable = Standard_True;
6831 if (++anArgIter < theArgNb
6832 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6836 aCaps->usePolygonMode = toEnable;
6838 else if (anArgCase == "-vbo")
6840 Standard_Boolean toEnable = Standard_True;
6841 if (++anArgIter < theArgNb
6842 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6846 aCaps->vboDisable = !toEnable;
6848 else if (anArgCase == "-sprite"
6849 || anArgCase == "-sprites")
6851 Standard_Boolean toEnable = Standard_True;
6852 if (++anArgIter < theArgNb
6853 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6857 aCaps->pntSpritesDisable = !toEnable;
6859 else if (anArgCase == "-softmode")
6861 Standard_Boolean toEnable = Standard_True;
6862 if (++anArgIter < theArgNb
6863 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6867 aCaps->contextNoAccel = toEnable;
6869 else if (anArgCase == "-winbuffer"
6870 || anArgCase == "-windowbuffer"
6871 || anArgCase == "-usewinbuffer"
6872 || anArgCase == "-usewindowbuffer"
6873 || anArgCase == "-usesystembuffer")
6875 Standard_Boolean toEnable = Standard_True;
6876 if (++anArgIter < theArgNb
6877 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6881 aCaps->useSystemBuffer = toEnable;
6883 else if (anArgCase == "-accel"
6884 || anArgCase == "-acceleration")
6886 Standard_Boolean toEnable = Standard_True;
6887 if (++anArgIter < theArgNb
6888 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6892 aCaps->contextNoAccel = !toEnable;
6894 else if (anArgCase == "-compat"
6895 || anArgCase == "-compatprofile"
6896 || anArgCase == "-compatible"
6897 || anArgCase == "-compatibleprofile")
6899 Standard_Boolean toEnable = Standard_True;
6900 if (++anArgIter < theArgNb
6901 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6905 aCaps->contextCompatible = toEnable;
6906 if (!aCaps->contextCompatible)
6908 aCaps->ffpEnable = Standard_False;
6911 else if (anArgCase == "-core"
6912 || anArgCase == "-coreprofile")
6914 Standard_Boolean toEnable = Standard_True;
6915 if (++anArgIter < theArgNb
6916 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6920 aCaps->contextCompatible = !toEnable;
6921 if (!aCaps->contextCompatible)
6923 aCaps->ffpEnable = Standard_False;
6926 else if (anArgCase == "-stereo"
6927 || anArgCase == "-quadbuffer")
6929 Standard_Boolean toEnable = Standard_True;
6930 if (++anArgIter < theArgNb
6931 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6935 aCaps->contextStereo = toEnable;
6937 else if (anArgCase == "-noext"
6938 || anArgCase == "-noextensions"
6939 || anArgCase == "-noextension")
6941 Standard_Boolean toDisable = Standard_True;
6942 if (++anArgIter < theArgNb
6943 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
6947 aCaps->contextNoExtensions = toDisable;
6949 else if (anArgCase == "-maxversion"
6950 || anArgCase == "-upperversion"
6951 || anArgCase == "-limitversion")
6953 Standard_Integer aVer[2] = { -2, -1 };
6954 for (Standard_Integer aValIter = 0; aValIter < 2; ++aValIter)
6956 if (anArgIter + 1 < theArgNb)
6958 const TCollection_AsciiString aStr (theArgVec[anArgIter + 1]);
6959 if (aStr.IsIntegerValue())
6961 aVer[aValIter] = aStr.IntegerValue();
6969 std::cout << "Syntax error at '" << anArgCase << "'\n";
6972 aCaps->contextMajorVersionUpper = aVer[0];
6973 aCaps->contextMinorVersionUpper = aVer[1];
6977 std::cout << "Error: unknown argument '" << anArg << "'\n";
6981 if (aCaps != &ViewerTest_myDefaultCaps)
6983 ViewerTest_myDefaultCaps = *aCaps;
6988 //==============================================================================
6989 //function : VMemGpu
6991 //==============================================================================
6993 static int VMemGpu (Draw_Interpretor& theDI,
6994 Standard_Integer theArgNb,
6995 const char** theArgVec)
6998 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6999 if (aContextAIS.IsNull())
7001 std::cerr << "No active view. Please call vinit.\n";
7005 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
7006 if (aDriver.IsNull())
7008 std::cerr << "Graphic driver not available.\n";
7012 Standard_Size aFreeBytes = 0;
7013 TCollection_AsciiString anInfo;
7014 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
7016 std::cerr << "Information not available.\n";
7020 if (theArgNb > 1 && *theArgVec[1] == 'f')
7022 theDI << Standard_Real (aFreeBytes);
7032 // ==============================================================================
7033 // function : VReadPixel
7035 // ==============================================================================
7036 static int VReadPixel (Draw_Interpretor& theDI,
7037 Standard_Integer theArgNb,
7038 const char** theArgVec)
7040 // get the active view
7041 Handle(V3d_View) aView = ViewerTest::CurrentView();
7044 std::cerr << "No active view. Please call vinit.\n";
7047 else if (theArgNb < 3)
7049 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
7053 Image_Format aFormat = Image_Format_RGBA;
7054 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
7056 Standard_Integer aWidth, aHeight;
7057 aView->Window()->Size (aWidth, aHeight);
7058 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
7059 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
7060 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
7062 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
7066 Standard_Boolean toShowName = Standard_False;
7067 Standard_Boolean toShowHls = Standard_False;
7068 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
7070 TCollection_AsciiString aParam (theArgVec[anIter]);
7072 if (aParam == "-rgb"
7075 aFormat = Image_Format_RGB;
7076 aBufferType = Graphic3d_BT_RGB;
7078 else if (aParam == "-hls"
7081 aFormat = Image_Format_RGB;
7082 aBufferType = Graphic3d_BT_RGB;
7083 toShowHls = Standard_True;
7085 else if (aParam == "-rgbf"
7086 || aParam == "rgbf")
7088 aFormat = Image_Format_RGBF;
7089 aBufferType = Graphic3d_BT_RGB;
7091 else if (aParam == "-rgba"
7092 || aParam == "rgba")
7094 aFormat = Image_Format_RGBA;
7095 aBufferType = Graphic3d_BT_RGBA;
7097 else if (aParam == "-rgbaf"
7098 || aParam == "rgbaf")
7100 aFormat = Image_Format_RGBAF;
7101 aBufferType = Graphic3d_BT_RGBA;
7103 else if (aParam == "-depth"
7104 || aParam == "depth")
7106 aFormat = Image_Format_GrayF;
7107 aBufferType = Graphic3d_BT_Depth;
7109 else if (aParam == "-name"
7110 || aParam == "name")
7112 toShowName = Standard_True;
7116 std::cout << "Syntax error at '" << aParam << "'\n";
7120 Image_PixMap anImage;
7121 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
7123 std::cerr << "Image allocation failed\n";
7126 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
7128 std::cerr << "Image dump failed\n";
7132 // redirect possible warning messages that could have been added by ToPixMap
7133 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
7134 // contaminate result of the command
7135 Standard_CString aWarnLog = theDI.Result();
7136 if (aWarnLog != NULL && aWarnLog[0] != '\0')
7138 std::cout << aWarnLog << std::endl;
7142 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
7145 if (aBufferType == Graphic3d_BT_RGBA)
7147 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
7151 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
7156 switch (aBufferType)
7159 case Graphic3d_BT_RGB:
7163 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
7167 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
7171 case Graphic3d_BT_RGBA:
7173 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
7176 case Graphic3d_BT_Depth:
7178 theDI << aColor.GetRGB().Red();
7187 //! Auxiliary presentation for an image plane.
7188 class ViewerTest_ImagePrs : public AIS_InteractiveObject
7191 //! Main constructor.
7192 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
7193 const Standard_Real theWidth,
7194 const Standard_Real theHeight,
7195 const TCollection_AsciiString& theLabel)
7196 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
7200 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
7202 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
7203 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
7204 Graphic3d_MaterialAspect aMat;
7205 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
7206 aMat.SetAmbient (1.0);
7207 aMat.SetDiffuse (1.0);
7208 aMat.SetSpecular (1.0);
7209 aMat.SetEmissive (1.0);
7210 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
7211 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
7212 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
7213 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
7214 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
7215 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
7216 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
7217 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
7218 aFillAspect->SetFrontMaterial (aMat);
7219 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
7220 aFillAspect->SetTextureMapOn();
7223 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
7224 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
7225 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
7226 myDrawer->SetTextAspect (aTextAspect);
7229 const gp_Dir aNorm (0.0, 0.0, 1.0);
7230 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
7231 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
7232 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
7233 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
7234 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
7235 myTris->AddEdge (1);
7236 myTris->AddEdge (2);
7237 myTris->AddEdge (3);
7238 myTris->AddEdge (3);
7239 myTris->AddEdge (2);
7240 myTris->AddEdge (4);
7242 myRect = new Graphic3d_ArrayOfPolylines (4);
7243 myRect->AddVertex (myTris->Vertice (1));
7244 myRect->AddVertex (myTris->Vertice (3));
7245 myRect->AddVertex (myTris->Vertice (4));
7246 myRect->AddVertex (myTris->Vertice (2));
7250 //! Returns TRUE for accepted display modes.
7251 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
7253 //! Compute presentation.
7254 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
7260 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7261 aGroup->AddPrimitiveArray (myTris);
7262 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
7263 aGroup->AddPrimitiveArray (myRect);
7264 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7269 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
7270 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7271 aGroup->AddPrimitiveArray (myRect);
7272 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7278 //! Compute selection.
7279 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
7283 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
7284 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
7285 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
7286 theSel->Add (aSensitive);
7291 Handle(Graphic3d_ArrayOfTriangles) myTris;
7292 Handle(Graphic3d_ArrayOfPolylines) myRect;
7293 TCollection_AsciiString myLabel;
7294 Standard_Real myWidth;
7295 Standard_Real myHeight;
7298 //==============================================================================
7299 //function : VDiffImage
7300 //purpose : The draw-command compares two images.
7301 //==============================================================================
7303 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
7307 std::cout << "Syntax error: not enough arguments.\n";
7311 Standard_Integer anArgIter = 1;
7312 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
7313 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
7314 TCollection_AsciiString aDiffImagePath;
7315 Standard_Real aTolColor = -1.0;
7316 Standard_Integer toBlackWhite = -1;
7317 Standard_Integer isBorderFilterOn = -1;
7318 Standard_Boolean isOldSyntax = Standard_False;
7319 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
7320 for (; anArgIter < theArgNb; ++anArgIter)
7322 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7324 if (anArgIter + 1 < theArgNb
7325 && (anArg == "-toleranceofcolor"
7326 || anArg == "-tolerancecolor"
7327 || anArg == "-tolerance"
7328 || anArg == "-toler"))
7330 aTolColor = Atof (theArgVec[++anArgIter]);
7331 if (aTolColor < 0.0 || aTolColor > 1.0)
7333 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7337 else if (anArg == "-blackwhite")
7339 Standard_Boolean toEnable = Standard_True;
7340 if (anArgIter + 1 < theArgNb
7341 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7345 toBlackWhite = toEnable ? 1 : 0;
7347 else if (anArg == "-borderfilter")
7349 Standard_Boolean toEnable = Standard_True;
7350 if (anArgIter + 1 < theArgNb
7351 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7355 isBorderFilterOn = toEnable ? 1 : 0;
7357 else if (anArg == "-exitonclose")
7359 ViewerTest_EventManager::ToExitOnCloseView() = true;
7360 if (anArgIter + 1 < theArgNb
7361 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToExitOnCloseView()))
7366 else if (anArg == "-closeonescape"
7367 || anArg == "-closeonesc")
7369 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
7370 if (anArgIter + 1 < theArgNb
7371 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
7376 else if (anArgIter + 3 < theArgNb
7377 && anArg == "-display")
7379 aViewName = theArgVec[++anArgIter];
7380 aPrsNameRef = theArgVec[++anArgIter];
7381 aPrsNameNew = theArgVec[++anArgIter];
7382 if (anArgIter + 1 < theArgNb
7383 && *theArgVec[anArgIter + 1] != '-')
7385 aPrsNameDiff = theArgVec[++anArgIter];
7388 else if (aTolColor < 0.0
7389 && anArg.IsRealValue())
7391 isOldSyntax = Standard_True;
7392 aTolColor = anArg.RealValue();
7393 if (aTolColor < 0.0 || aTolColor > 1.0)
7395 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7399 else if (isOldSyntax
7400 && toBlackWhite == -1
7401 && (anArg == "0" || anArg == "1"))
7403 toBlackWhite = anArg == "1" ? 1 : 0;
7405 else if (isOldSyntax
7406 && isBorderFilterOn == -1
7407 && (anArg == "0" || anArg == "1"))
7409 isBorderFilterOn = anArg == "1" ? 1 : 0;
7411 else if (aDiffImagePath.IsEmpty())
7413 aDiffImagePath = theArgVec[anArgIter];
7417 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7422 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
7423 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
7424 if (!anImgRef->Load (anImgPathRef))
7426 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
7429 if (!anImgNew->Load (anImgPathNew))
7431 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
7435 // compare the images
7436 Image_Diff aComparer;
7437 Standard_Integer aDiffColorsNb = -1;
7438 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
7440 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
7441 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
7442 aDiffColorsNb = aComparer.Compare();
7443 theDI << aDiffColorsNb << "\n";
7446 // save image of difference
7447 Handle(Image_AlienPixMap) aDiff;
7448 if (aDiffColorsNb > 0
7449 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
7451 aDiff = new Image_AlienPixMap();
7452 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
7454 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
7457 aComparer.SaveDiffImage (*aDiff);
7458 if (!aDiffImagePath.IsEmpty()
7459 && !aDiff->Save (aDiffImagePath))
7461 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
7466 if (aViewName.IsEmpty())
7471 ViewerTest_Names aViewNames (aViewName);
7472 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
7474 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
7475 theDI.Eval (aCommand.ToCString());
7478 Standard_Integer aPxLeft = 0;
7479 Standard_Integer aPxTop = 0;
7480 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
7481 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
7482 ? int(anImgRef->SizeY() * 2)
7483 : int(anImgRef->SizeY());
7484 TCollection_AsciiString aDisplayName;
7485 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
7486 aViewName, aDisplayName);
7488 Standard_Real aRatio = anImgRef->Ratio();
7489 Standard_Real aSizeX = 1.0;
7490 Standard_Real aSizeY = aSizeX / aRatio;
7492 OSD_Path aPath (anImgPathRef);
7493 TCollection_AsciiString aLabelRef;
7494 if (!aPath.Name().IsEmpty())
7496 aLabelRef = aPath.Name() + aPath.Extension();
7498 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
7500 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
7502 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
7503 anImgRefPrs->SetLocalTransformation (aTrsfRef);
7504 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
7507 OSD_Path aPath (anImgPathNew);
7508 TCollection_AsciiString aLabelNew;
7509 if (!aPath.Name().IsEmpty())
7511 aLabelNew = aPath.Name() + aPath.Extension();
7513 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
7515 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
7517 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
7518 anImgNewPrs->SetLocalTransformation (aTrsfRef);
7519 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
7521 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
7522 if (!aDiff.IsNull())
7524 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
7526 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
7527 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
7529 if (!aPrsNameDiff.IsEmpty())
7531 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
7533 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
7534 ViewerTest::CurrentView()->FitAll();
7538 //=======================================================================
7539 //function : VSelect
7540 //purpose : Emulates different types of selection by mouse:
7541 // 1) single click selection
7542 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
7543 // 3) selection with polygon having corners at
7544 // pixel positions (x1,y1),...,(xn,yn)
7545 // 4) any of these selections with shift button pressed
7546 //=======================================================================
7547 static Standard_Integer VSelect (Draw_Interpretor& ,
7548 Standard_Integer theNbArgs,
7549 const char** theArgVec)
7551 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7554 std::cout << "Error: no active View\n";
7558 NCollection_Sequence<Graphic3d_Vec2i> aPnts;
7559 bool isShiftSelection = false, toAllowOverlap = false;
7560 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7562 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7564 if (anArg == "-allowoverlap")
7566 toAllowOverlap = true;
7567 if (anArgIter + 1 < theNbArgs
7568 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toAllowOverlap))
7573 else if (anArgIter + 1 < theNbArgs
7574 && anArg.IsIntegerValue()
7575 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
7577 const TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
7578 aPnts.Append (Graphic3d_Vec2i (anArg.IntegerValue(), anArgNext.IntegerValue()));
7580 else if (anArgIter + 1 == theNbArgs
7581 && anArg.IsIntegerValue())
7583 isShiftSelection = anArg.IntegerValue() == 1;
7587 std::cout << "Syntax error at '" << anArg << "'\n";
7592 && aPnts.Length() != 2)
7594 std::cout << "Syntax error: -allowoverlap key is applied only for rectangle selection\n";
7599 aCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
7602 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
7603 if (aPnts.IsEmpty())
7605 if (isShiftSelection)
7607 aCtx->ShiftSelect (false);
7611 aCtx->Select (false);
7613 aCtx->CurrentViewer()->Invalidate();
7615 else if (aPnts.Length() == 2)
7618 && aPnts.First().y() < aPnts.Last().y())
7620 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7622 else if (!toAllowOverlap
7623 && aPnts.First().y() > aPnts.Last().y())
7625 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7627 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
7631 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
7633 aCurrentEventManager->FlushViewEvents (aCtx, ViewerTest::CurrentView(), true);
7637 //=======================================================================
7638 //function : VMoveTo
7639 //purpose : Emulates cursor movement to defined pixel position
7640 //=======================================================================
7641 static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
7642 Standard_Integer theNbArgs,
7643 const char** theArgVec)
7645 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
7646 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
7647 if (aContext.IsNull())
7649 std::cout << "Error: no active View\n";
7653 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
7654 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7656 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
7657 anArgStr.LowerCase();
7658 if (anArgStr == "-reset"
7659 || anArgStr == "-clear")
7661 if (anArgIter + 1 < theNbArgs)
7663 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
7667 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
7668 && aContext->CurrentViewer()->GridEcho();
7671 aContext->CurrentViewer()->HideGridEcho (aView);
7673 if (aContext->ClearDetected() || toEchoGrid)
7675 aContext->CurrentViewer()->RedrawImmediate();
7679 else if (aMousePos.x() == IntegerLast()
7680 && anArgStr.IsIntegerValue())
7682 aMousePos.x() = anArgStr.IntegerValue();
7684 else if (aMousePos.y() == IntegerLast()
7685 && anArgStr.IsIntegerValue())
7687 aMousePos.y() = anArgStr.IntegerValue();
7691 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7696 if (aMousePos.x() == IntegerLast()
7697 || aMousePos.y() == IntegerLast())
7699 std::cout << "Syntax error: wrong number of arguments\n";
7703 ViewerTest::CurrentEventManager()->ResetPreviousMoveTo();
7704 ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false);
7705 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
7707 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
7708 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
7709 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
7711 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
7713 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
7717 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
7723 //! Global map storing all animations registered in ViewerTest.
7724 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
7726 //! The animation calling the Draw Harness command.
7727 class ViewerTest_AnimationProc : public AIS_Animation
7731 //! Main constructor.
7732 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
7733 Draw_Interpretor* theDI,
7734 const TCollection_AsciiString& theCommand)
7735 : AIS_Animation (theAnimationName),
7737 myCommand (theCommand)
7744 //! Evaluate the command.
7745 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
7747 TCollection_AsciiString aCmd = myCommand;
7748 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
7749 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
7750 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
7751 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
7752 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
7753 myDrawInter->Eval (aCmd.ToCString());
7756 //! Find the keyword in the command and replace it with value.
7757 //! @return the position of the keyword to pass value
7758 void replace (TCollection_AsciiString& theCmd,
7759 const TCollection_AsciiString& theKey,
7760 const TCollection_AsciiString& theVal)
7762 TCollection_AsciiString aCmd (theCmd);
7764 const Standard_Integer aPos = aCmd.Search (theKey);
7770 TCollection_AsciiString aPart1, aPart2;
7771 Standard_Integer aPart1To = aPos - 1;
7773 && aPart1To <= theCmd.Length())
7775 aPart1 = theCmd.SubString (1, aPart1To);
7778 Standard_Integer aPart2From = aPos + theKey.Length();
7780 && aPart2From <= theCmd.Length())
7782 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
7785 theCmd = aPart1 + theVal + aPart2;
7790 Draw_Interpretor* myDrawInter;
7791 TCollection_AsciiString myCommand;
7795 //! Replace the animation with the new one.
7796 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
7797 Handle(AIS_Animation)& theAnimation,
7798 const Handle(AIS_Animation)& theAnimationNew)
7800 theAnimationNew->CopyFrom (theAnimation);
7801 if (!theParentAnimation.IsNull())
7803 theParentAnimation->Replace (theAnimation, theAnimationNew);
7807 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
7808 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
7810 theAnimation = theAnimationNew;
7813 //! Parse the point.
7814 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
7816 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
7817 if (!anXYZ[0].IsRealValue()
7818 || !anXYZ[1].IsRealValue()
7819 || !anXYZ[2].IsRealValue())
7821 return Standard_False;
7824 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
7825 return Standard_True;
7828 //! Parse the quaternion.
7829 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
7831 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
7832 if (!anXYZW[0].IsRealValue()
7833 || !anXYZW[1].IsRealValue()
7834 || !anXYZW[2].IsRealValue()
7835 || !anXYZW[3].IsRealValue())
7837 return Standard_False;
7840 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
7841 return Standard_True;
7844 //! Auxiliary class for flipping image upside-down.
7849 //! Empty constructor.
7850 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
7852 //! Perform flipping.
7853 Standard_Boolean FlipY (Image_PixMap& theImage)
7855 if (theImage.IsEmpty()
7856 || theImage.SizeX() == 0
7857 || theImage.SizeY() == 0)
7859 return Standard_False;
7862 const Standard_Size aRowSize = theImage.SizeRowBytes();
7863 if (myTmp.Size() < aRowSize
7864 && !myTmp.Allocate (aRowSize))
7866 return Standard_False;
7869 // for odd height middle row should be left as is
7870 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
7871 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
7873 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
7874 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
7875 memcpy (myTmp.ChangeData(), aTop, aRowSize);
7876 memcpy (aTop, aBot, aRowSize);
7877 memcpy (aBot, myTmp.Data(), aRowSize);
7879 return Standard_True;
7883 NCollection_Buffer myTmp;
7888 //=================================================================================================
7889 //function : VViewParams
7890 //purpose : Gets or sets AIS View characteristics
7891 //=================================================================================================
7892 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7894 Handle(V3d_View) aView = ViewerTest::CurrentView();
7897 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
7901 Standard_Boolean toSetProj = Standard_False;
7902 Standard_Boolean toSetUp = Standard_False;
7903 Standard_Boolean toSetAt = Standard_False;
7904 Standard_Boolean toSetEye = Standard_False;
7905 Standard_Boolean toSetScale = Standard_False;
7906 Standard_Boolean toSetSize = Standard_False;
7907 Standard_Boolean toSetCenter2d = Standard_False;
7908 Standard_Real aViewScale = aView->Scale();
7909 Standard_Real aViewSize = 1.0;
7910 Graphic3d_Vec2i aCenter2d;
7911 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
7912 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
7913 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
7914 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
7915 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
7918 // print all of the available view parameters
7922 "Proj: %12g %12g %12g\n"
7923 "Up: %12g %12g %12g\n"
7924 "At: %12g %12g %12g\n"
7925 "Eye: %12g %12g %12g\n",
7927 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7928 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7929 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
7930 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7935 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7936 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7938 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7940 if (anUpdateTool.parseRedrawMode (anArg))
7944 else if (anArg == "-cmd"
7945 || anArg == "-command"
7946 || anArg == "-args")
7955 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7956 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7957 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7960 else if (anArg == "-scale"
7961 || anArg == "-size")
7963 if (anArgIter + 1 < theArgsNb
7964 && *theArgVec[anArgIter + 1] != '-')
7966 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
7967 if (aValueArg.IsRealValue())
7970 if (anArg == "-scale")
7972 toSetScale = Standard_True;
7973 aViewScale = aValueArg.RealValue();
7975 else if (anArg == "-size")
7977 toSetSize = Standard_True;
7978 aViewSize = aValueArg.RealValue();
7983 if (anArg == "-scale")
7985 theDi << "Scale: " << aView->Scale() << "\n";
7987 else if (anArg == "-size")
7989 Graphic3d_Vec2d aSizeXY;
7990 aView->Size (aSizeXY.x(), aSizeXY.y());
7991 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
7994 else if (anArg == "-eye"
7997 || anArg == "-proj")
7999 if (anArgIter + 3 < theArgsNb)
8002 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
8005 if (anArg == "-eye")
8007 toSetEye = Standard_True;
8010 else if (anArg == "-at")
8012 toSetAt = Standard_True;
8015 else if (anArg == "-up")
8017 toSetUp = Standard_True;
8020 else if (anArg == "-proj")
8022 toSetProj = Standard_True;
8029 if (anArg == "-eye")
8031 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
8033 else if (anArg == "-at")
8035 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
8037 else if (anArg == "-up")
8039 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
8041 else if (anArg == "-proj")
8043 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
8046 else if (anArg == "-center")
8048 if (anArgIter + 2 < theArgsNb)
8050 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
8051 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
8052 if (anX.IsIntegerValue()
8053 && anY.IsIntegerValue())
8055 toSetCenter2d = Standard_True;
8056 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
8062 std::cout << "Syntax error at '" << anArg << "'\n";
8067 // change view parameters in proper order
8070 aView->SetScale (aViewScale);
8074 aView->SetSize (aViewSize);
8078 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
8082 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
8086 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
8090 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
8094 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
8100 //==============================================================================
8101 //function : V2DMode
8103 //==============================================================================
8104 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
8106 bool is2dMode = true;
8107 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
8108 if (aV3dView.IsNull())
8110 std::cout << "Error: no active view.\n";
8113 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
8115 const TCollection_AsciiString anArg = theArgVec[anArgIt];
8116 TCollection_AsciiString anArgCase = anArg;
8117 anArgCase.LowerCase();
8118 if (anArgIt + 1 < theArgsNb
8119 && anArgCase == "-name")
8121 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
8122 TCollection_AsciiString aViewName = aViewNames.GetViewName();
8123 if (!ViewerTest_myViews.IsBound1 (aViewName))
8125 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
8128 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
8130 else if (anArgCase == "-mode")
8132 if (anArgIt + 1 < theArgsNb
8133 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
8138 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
8144 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
8149 aV3dView->SetView2DMode (is2dMode);
8153 //==============================================================================
8154 //function : VAnimation
8156 //==============================================================================
8157 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
8158 Standard_Integer theArgNb,
8159 const char** theArgVec)
8161 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
8164 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
8165 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
8167 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
8173 std::cout << "Error: no active view\n";
8177 Standard_Integer anArgIter = 1;
8178 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
8179 if (aNameArg.IsEmpty())
8181 std::cout << "Syntax error: animation name is not defined.\n";
8185 TCollection_AsciiString aNameArgLower = aNameArg;
8186 aNameArgLower.LowerCase();
8187 if (aNameArgLower == "-reset"
8188 || aNameArgLower == "-clear")
8190 ViewerTest_AnimationTimelineMap.Clear();
8193 else if (aNameArg.Value (1) == '-')
8195 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
8199 const char* aNameSplitter = "/";
8200 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
8201 if (aSplitPos == -1)
8203 aNameSplitter = ".";
8204 aSplitPos = aNameArg.Search (aNameSplitter);
8207 // find existing or create a new animation by specified name within syntax "parent.child".
8208 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
8209 for (; !aNameArg.IsEmpty();)
8211 TCollection_AsciiString aNameParent;
8212 if (aSplitPos != -1)
8214 if (aSplitPos == aNameArg.Length())
8216 std::cout << "Syntax error: animation name is not defined.\n";
8220 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
8221 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
8223 aSplitPos = aNameArg.Search (aNameSplitter);
8227 aNameParent = aNameArg;
8231 if (anAnimation.IsNull())
8233 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
8235 anAnimation = new AIS_Animation (aNameParent);
8236 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
8238 aRootAnimation = anAnimation;
8242 aParentAnimation = anAnimation;
8243 anAnimation = aParentAnimation->Find (aNameParent);
8244 if (anAnimation.IsNull())
8246 anAnimation = new AIS_Animation (aNameParent);
8247 aParentAnimation->Add (anAnimation);
8252 if (anArgIter >= theArgNb)
8254 // just print the list of children
8255 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
8257 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
8262 // animation parameters
8263 Standard_Boolean toPlay = Standard_False;
8264 Standard_Real aPlaySpeed = 1.0;
8265 Standard_Real aPlayStartTime = anAnimation->StartPts();
8266 Standard_Real aPlayDuration = anAnimation->Duration();
8267 Standard_Boolean isFreeCamera = Standard_False;
8268 Standard_Boolean isLockLoop = Standard_False;
8270 // video recording parameters
8271 TCollection_AsciiString aRecFile;
8272 Image_VideoParams aRecParams;
8274 Handle(V3d_View) aView = ViewerTest::CurrentView();
8275 for (; anArgIter < theArgNb; ++anArgIter)
8277 TCollection_AsciiString anArg (theArgVec[anArgIter]);
8280 if (anArg == "-reset"
8281 || anArg == "-clear")
8283 anAnimation->Clear();
8285 else if (anArg == "-remove"
8287 || anArg == "-delete")
8289 if (!aParentAnimation.IsNull())
8291 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
8295 aParentAnimation->Remove (anAnimation);
8299 else if (anArg == "-play")
8301 toPlay = Standard_True;
8302 if (++anArgIter < theArgNb)
8304 if (*theArgVec[anArgIter] == '-')
8309 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
8311 if (++anArgIter < theArgNb)
8313 if (*theArgVec[anArgIter] == '-')
8318 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8322 else if (anArg == "-resume")
8324 toPlay = Standard_True;
8325 aPlayStartTime = anAnimation->ElapsedTime();
8326 if (++anArgIter < theArgNb)
8328 if (*theArgVec[anArgIter] == '-')
8334 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8337 else if (anArg == "-playspeed"
8338 || anArg == "-speed")
8340 if (++anArgIter >= theArgNb)
8342 std::cout << "Syntax error at " << anArg << ".\n";
8345 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
8347 else if (anArg == "-lock"
8348 || anArg == "-lockloop"
8349 || anArg == "-playlockloop")
8351 isLockLoop = Standard_True;
8353 else if (anArg == "-freecamera"
8354 || anArg == "-playfreecamera"
8355 || anArg == "-freelook")
8357 isFreeCamera = Standard_True;
8359 // video recodring options
8360 else if (anArg == "-rec"
8361 || anArg == "-record")
8363 if (++anArgIter >= theArgNb)
8365 std::cout << "Syntax error at " << anArg << ".\n";
8369 aRecFile = theArgVec[anArgIter];
8370 if (aRecParams.FpsNum <= 0)
8372 aRecParams.FpsNum = 24;
8375 if (anArgIter + 2 < theArgNb
8376 && *theArgVec[anArgIter + 1] != '-'
8377 && *theArgVec[anArgIter + 2] != '-')
8379 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
8380 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
8381 if (aWidthArg .IsIntegerValue()
8382 && aHeightArg.IsIntegerValue())
8384 aRecParams.Width = aWidthArg .IntegerValue();
8385 aRecParams.Height = aHeightArg.IntegerValue();
8390 else if (anArg == "-fps")
8392 if (++anArgIter >= theArgNb)
8394 std::cout << "Syntax error at " << anArg << ".\n";
8398 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
8399 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
8400 if (aSplitIndex == 0)
8402 aRecParams.FpsNum = aFpsArg.IntegerValue();
8406 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
8407 aFpsArg.Split (aFpsArg.Length() - 1);
8408 const TCollection_AsciiString aNumStr = aFpsArg;
8409 aRecParams.FpsNum = aNumStr.IntegerValue();
8410 aRecParams.FpsDen = aDenStr.IntegerValue();
8411 if (aRecParams.FpsDen < 1)
8413 std::cout << "Syntax error at " << anArg << ".\n";
8418 else if (anArg == "-format")
8420 if (++anArgIter >= theArgNb)
8422 std::cout << "Syntax error at " << anArg << ".\n";
8425 aRecParams.Format = theArgVec[anArgIter];
8427 else if (anArg == "-pix_fmt"
8428 || anArg == "-pixfmt"
8429 || anArg == "-pixelformat")
8431 if (++anArgIter >= theArgNb)
8433 std::cout << "Syntax error at " << anArg << ".\n";
8436 aRecParams.PixelFormat = theArgVec[anArgIter];
8438 else if (anArg == "-codec"
8439 || anArg == "-vcodec"
8440 || anArg == "-videocodec")
8442 if (++anArgIter >= theArgNb)
8444 std::cout << "Syntax error at " << anArg << ".\n";
8447 aRecParams.VideoCodec = theArgVec[anArgIter];
8449 else if (anArg == "-crf"
8450 || anArg == "-preset"
8453 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
8454 if (++anArgIter >= theArgNb)
8456 std::cout << "Syntax error at " << anArg << ".\n";
8460 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
8462 // animation definition options
8463 else if (anArg == "-start"
8464 || anArg == "-starttime"
8465 || anArg == "-startpts")
8467 if (++anArgIter >= theArgNb)
8469 std::cout << "Syntax error at " << anArg << ".\n";
8473 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
8474 aRootAnimation->UpdateTotalDuration();
8476 else if (anArg == "-end"
8477 || anArg == "-endtime"
8478 || anArg == "-endpts")
8480 if (++anArgIter >= theArgNb)
8482 std::cout << "Syntax error at " << anArg << ".\n";
8486 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
8487 aRootAnimation->UpdateTotalDuration();
8489 else if (anArg == "-dur"
8490 || anArg == "-duration")
8492 if (++anArgIter >= theArgNb)
8494 std::cout << "Syntax error at " << anArg << ".\n";
8498 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
8499 aRootAnimation->UpdateTotalDuration();
8501 else if (anArg == "-command"
8503 || anArg == "-invoke"
8505 || anArg == "-proc")
8507 if (++anArgIter >= theArgNb)
8509 std::cout << "Syntax error at " << anArg << ".\n";
8513 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
8514 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
8516 else if (anArg == "-objecttrsf"
8517 || anArg == "-objectransformation"
8518 || anArg == "-objtransformation"
8519 || anArg == "-objtrsf"
8520 || anArg == "-object"
8523 if (++anArgIter >= theArgNb)
8525 std::cout << "Syntax error at " << anArg << ".\n";
8529 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
8530 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
8531 Handle(AIS_InteractiveObject) anObject;
8532 if (!aMapOfAIS.Find2 (anObjName, anObject))
8534 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
8538 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
8539 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
8540 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
8541 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
8542 Standard_Boolean isTrsfSet = Standard_False;
8543 Standard_Integer aTrsfArgIter = anArgIter + 1;
8544 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
8546 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
8547 aTrsfArg.LowerCase();
8548 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
8549 if (aTrsfArg.StartsWith ("-rotation")
8550 || aTrsfArg.StartsWith ("-rot"))
8552 isTrsfSet = Standard_True;
8553 if (aTrsfArgIter + 4 >= theArgNb
8554 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
8556 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8561 else if (aTrsfArg.StartsWith ("-location")
8562 || aTrsfArg.StartsWith ("-loc"))
8564 isTrsfSet = Standard_True;
8565 if (aTrsfArgIter + 3 >= theArgNb
8566 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
8568 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8573 else if (aTrsfArg.StartsWith ("-scale"))
8575 isTrsfSet = Standard_True;
8576 if (++aTrsfArgIter >= theArgNb)
8578 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8582 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
8583 if (!aScaleStr.IsRealValue())
8585 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8588 aScales[anIndex] = aScaleStr.RealValue();
8592 anArgIter = aTrsfArgIter - 1;
8598 std::cout << "Syntax error at " << anArg << ".\n";
8601 else if (aTrsfArgIter >= theArgNb)
8603 anArgIter = theArgNb;
8606 aTrsfs[0].SetRotation (aRotQuats[0]);
8607 aTrsfs[1].SetRotation (aRotQuats[1]);
8608 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
8609 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
8610 aTrsfs[0].SetScaleFactor (aScales[0]);
8611 aTrsfs[1].SetScaleFactor (aScales[1]);
8613 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
8614 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
8616 else if (anArg == "-viewtrsf"
8617 || anArg == "-view")
8619 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
8620 if (aCamAnimation.IsNull())
8622 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
8623 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
8626 Handle(Graphic3d_Camera) aCams[2] =
8628 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
8629 new Graphic3d_Camera (aCamAnimation->View()->Camera())
8632 Standard_Boolean isTrsfSet = Standard_False;
8633 Standard_Integer aViewArgIter = anArgIter + 1;
8634 for (; aViewArgIter < theArgNb; ++aViewArgIter)
8636 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
8637 aViewArg.LowerCase();
8638 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
8639 if (aViewArg.StartsWith ("-scale"))
8641 isTrsfSet = Standard_True;
8642 if (++aViewArgIter >= theArgNb)
8644 std::cout << "Syntax error at " << anArg << ".\n";
8648 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
8649 if (!aScaleStr.IsRealValue())
8651 std::cout << "Syntax error at " << aViewArg << ".\n";
8654 Standard_Real aScale = aScaleStr.RealValue();
8655 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
8656 aCams[anIndex]->SetScale (aScale);
8658 else if (aViewArg.StartsWith ("-eye")
8659 || aViewArg.StartsWith ("-center")
8660 || aViewArg.StartsWith ("-at")
8661 || aViewArg.StartsWith ("-up"))
8663 isTrsfSet = Standard_True;
8665 if (aViewArgIter + 3 >= theArgNb
8666 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
8668 std::cout << "Syntax error at " << aViewArg << ".\n";
8673 if (aViewArg.StartsWith ("-eye"))
8675 aCams[anIndex]->SetEye (anXYZ);
8677 else if (aViewArg.StartsWith ("-center")
8678 || aViewArg.StartsWith ("-at"))
8680 aCams[anIndex]->SetCenter (anXYZ);
8682 else if (aViewArg.StartsWith ("-up"))
8684 aCams[anIndex]->SetUp (anXYZ);
8689 anArgIter = aViewArgIter - 1;
8695 std::cout << "Syntax error at " << anArg << ".\n";
8698 else if (aViewArgIter >= theArgNb)
8700 anArgIter = theArgNb;
8703 aCamAnimation->SetCameraStart(aCams[0]);
8704 aCamAnimation->SetCameraEnd (aCams[1]);
8708 std::cout << "Syntax error at " << anArg << ".\n";
8713 if (!toPlay && aRecFile.IsEmpty())
8718 // Start animation timeline and process frame updating.
8719 TheIsAnimating = Standard_True;
8720 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
8721 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
8722 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
8725 aView->Camera()->Copy (aCameraBack);
8728 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
8729 if (aRecParams.FpsNum <= 0)
8731 while (!anAnimation->IsStopped())
8733 aCameraBack->Copy (aView->Camera());
8734 const Standard_Real aPts = anAnimation->UpdateTimer();
8737 aView->Camera()->Copy (aCameraBack);
8740 if (aPts >= anUpperPts)
8742 anAnimation->Pause();
8746 if (aView->IsInvalidated())
8752 aView->RedrawImmediate();
8757 // handle user events
8758 theDI.Eval ("after 1 set waiter 1");
8759 theDI.Eval ("vwait waiter");
8761 if (!TheIsAnimating)
8763 anAnimation->Pause();
8769 if (aView->IsInvalidated())
8775 aView->RedrawImmediate();
8780 OSD_Timer aPerfTimer;
8783 Handle(Image_VideoRecorder) aRecorder;
8784 ImageFlipper aFlipper;
8785 Handle(Draw_ProgressIndicator) aProgress;
8786 if (!aRecFile.IsEmpty())
8788 if (aRecParams.Width <= 0
8789 || aRecParams.Height <= 0)
8791 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
8794 aRecorder = new Image_VideoRecorder();
8795 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
8797 std::cout << "Error: failed to open video file for recording\n";
8801 aProgress = new Draw_ProgressIndicator (theDI, 1);
8804 // Manage frame-rated animation here
8805 Standard_Real aPts = aPlayStartTime;
8806 int64_t aNbFrames = 0;
8807 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
8808 Standard_Integer aSecondsProgress = 0;
8809 for (; aPts <= anUpperPts && aPSentry.More();)
8811 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
8812 aPts = aPlayStartTime + aRecPts;
8814 if (!anAnimation->Update (aPts))
8819 if (!aRecorder.IsNull())
8821 V3d_ImageDumpOptions aDumpParams;
8822 aDumpParams.Width = aRecParams.Width;
8823 aDumpParams.Height = aRecParams.Height;
8824 aDumpParams.BufferType = Graphic3d_BT_RGBA;
8825 aDumpParams.StereoOptions = V3d_SDO_MONO;
8826 aDumpParams.ToAdjustAspect = Standard_True;
8827 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
8829 std::cout << "Error: view dump is failed!\n";
8832 aFlipper.FlipY (aRecorder->ChangeFrame());
8833 if (!aRecorder->PushFrame())
8843 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
8851 anAnimation->Stop();
8852 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
8853 theDI << "Average FPS: " << aRecFps << "\n"
8854 << "Nb. Frames: " << Standard_Real(aNbFrames);
8859 aView->SetImmediateUpdate (wasImmediateUpdate);
8860 TheIsAnimating = Standard_False;
8865 //=======================================================================
8866 //function : VChangeSelected
8867 //purpose : Adds the shape to selection or remove one from it
8868 //=======================================================================
8869 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
8870 Standard_Integer argc,
8875 di<<"Usage : " << argv[0] << " shape \n";
8879 TCollection_AsciiString aName(argv[1]);
8880 Handle(AIS_InteractiveObject) anAISObject;
8881 if (!GetMapOfAIS().Find2 (aName, anAISObject)
8882 || anAISObject.IsNull())
8884 di<<"Use 'vdisplay' before";
8888 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
8892 //=======================================================================
8893 //function : VNbSelected
8894 //purpose : Returns number of selected objects
8895 //=======================================================================
8896 static Standard_Integer VNbSelected (Draw_Interpretor& di,
8897 Standard_Integer argc,
8902 di << "Usage : " << argv[0] << "\n";
8905 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8906 if(aContext.IsNull())
8908 di << "use 'vinit' command before " << argv[0] << "\n";
8911 di << aContext->NbSelected() << "\n";
8915 //=======================================================================
8916 //function : VPurgeDisplay
8917 //purpose : Switches altialiasing on or off
8918 //=======================================================================
8919 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
8920 Standard_Integer argc,
8925 di << "Usage : " << argv[0] << "\n";
8928 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8929 if (aContext.IsNull())
8931 di << "use 'vinit' command before " << argv[0] << "\n";
8935 di << aContext->PurgeDisplay() << "\n";
8939 //=======================================================================
8940 //function : VSetViewSize
8942 //=======================================================================
8943 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
8944 Standard_Integer argc,
8947 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8948 if(aContext.IsNull())
8950 di << "use 'vinit' command before " << argv[0] << "\n";
8955 di<<"Usage : " << argv[0] << " Size\n";
8958 Standard_Real aSize = Draw::Atof (argv[1]);
8961 di<<"Bad Size value : " << aSize << "\n";
8965 Handle(V3d_View) aView = ViewerTest::CurrentView();
8966 aView->SetSize(aSize);
8970 //=======================================================================
8971 //function : VMoveView
8973 //=======================================================================
8974 static Standard_Integer VMoveView (Draw_Interpretor& di,
8975 Standard_Integer argc,
8978 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8979 if(aContext.IsNull())
8981 di << "use 'vinit' command before " << argv[0] << "\n";
8984 if(argc < 4 || argc > 5)
8986 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8989 Standard_Real Dx = Draw::Atof (argv[1]);
8990 Standard_Real Dy = Draw::Atof (argv[2]);
8991 Standard_Real Dz = Draw::Atof (argv[3]);
8992 Standard_Boolean aStart = Standard_True;
8995 aStart = (Draw::Atoi (argv[4]) > 0);
8998 Handle(V3d_View) aView = ViewerTest::CurrentView();
8999 aView->Move(Dx,Dy,Dz,aStart);
9003 //=======================================================================
9004 //function : VTranslateView
9006 //=======================================================================
9007 static Standard_Integer VTranslateView (Draw_Interpretor& di,
9008 Standard_Integer argc,
9011 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9012 if(aContext.IsNull())
9014 di << "use 'vinit' command before " << argv[0] << "\n";
9017 if(argc < 4 || argc > 5)
9019 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
9022 Standard_Real Dx = Draw::Atof (argv[1]);
9023 Standard_Real Dy = Draw::Atof (argv[2]);
9024 Standard_Real Dz = Draw::Atof (argv[3]);
9025 Standard_Boolean aStart = Standard_True;
9028 aStart = (Draw::Atoi (argv[4]) > 0);
9031 Handle(V3d_View) aView = ViewerTest::CurrentView();
9032 aView->Translate(Dx,Dy,Dz,aStart);
9036 //=======================================================================
9037 //function : VTurnView
9039 //=======================================================================
9040 static Standard_Integer VTurnView (Draw_Interpretor& di,
9041 Standard_Integer argc,
9044 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9045 if(aContext.IsNull()) {
9046 di << "use 'vinit' command before " << argv[0] << "\n";
9049 if(argc < 4 || argc > 5){
9050 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
9053 Standard_Real Ax = Draw::Atof (argv[1]);
9054 Standard_Real Ay = Draw::Atof (argv[2]);
9055 Standard_Real Az = Draw::Atof (argv[3]);
9056 Standard_Boolean aStart = Standard_True;
9059 aStart = (Draw::Atoi (argv[4]) > 0);
9062 Handle(V3d_View) aView = ViewerTest::CurrentView();
9063 aView->Turn(Ax,Ay,Az,aStart);
9067 //==============================================================================
9068 //function : VTextureEnv
9069 //purpose : ENables or disables environment mapping
9070 //==============================================================================
9071 class OCC_TextureEnv : public Graphic3d_TextureEnv
9074 OCC_TextureEnv(const Standard_CString FileName);
9075 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
9076 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
9077 const Standard_Boolean theModulateFlag,
9078 const Graphic3d_TypeOfTextureFilter theFilter,
9079 const Standard_ShortReal theXScale,
9080 const Standard_ShortReal theYScale,
9081 const Standard_ShortReal theXShift,
9082 const Standard_ShortReal theYShift,
9083 const Standard_ShortReal theAngle);
9084 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
9086 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
9088 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
9089 : Graphic3d_TextureEnv(theFileName)
9093 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
9094 : Graphic3d_TextureEnv(theTexId)
9098 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
9099 const Standard_Boolean theModulateFlag,
9100 const Graphic3d_TypeOfTextureFilter theFilter,
9101 const Standard_ShortReal theXScale,
9102 const Standard_ShortReal theYScale,
9103 const Standard_ShortReal theXShift,
9104 const Standard_ShortReal theYShift,
9105 const Standard_ShortReal theAngle)
9107 myParams->SetRepeat (theRepeatFlag);
9108 myParams->SetModulate (theModulateFlag);
9109 myParams->SetFilter (theFilter);
9110 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
9111 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
9112 myParams->SetRotation (theAngle);
9115 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
9117 // get the active view
9118 Handle(V3d_View) aView = ViewerTest::CurrentView();
9121 std::cerr << "No active view. Please call vinit.\n";
9125 // Checking the input arguments
9126 Standard_Boolean anEnableFlag = Standard_False;
9127 Standard_Boolean isOk = theArgNb >= 2;
9130 TCollection_AsciiString anEnableOpt(theArgVec[1]);
9131 anEnableFlag = anEnableOpt.IsEqual("on");
9132 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
9136 isOk = (theArgNb == 3 || theArgNb == 11);
9139 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9140 isOk = (!aTextureOpt.IsIntegerValue() ||
9141 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
9143 if (isOk && theArgNb == 11)
9145 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
9146 aModulateOpt(theArgVec[4]),
9147 aFilterOpt (theArgVec[5]),
9148 aSScaleOpt (theArgVec[6]),
9149 aTScaleOpt (theArgVec[7]),
9150 aSTransOpt (theArgVec[8]),
9151 aTTransOpt (theArgVec[9]),
9152 anAngleOpt (theArgVec[10]);
9153 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
9154 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
9155 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
9156 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
9157 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
9158 anAngleOpt.IsRealValue());
9165 std::cerr << "Usage :" << std::endl;
9166 std::cerr << theArgVec[0] << " off" << std::endl;
9167 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;
9173 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9174 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
9175 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
9176 new OCC_TextureEnv(theArgVec[2]);
9180 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
9181 aTexEnv->SetTextureParameters(
9182 aRepeatOpt. IsEqual("repeat"),
9183 aModulateOpt.IsEqual("modulate"),
9184 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
9185 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
9186 Graphic3d_TOTF_TRILINEAR,
9187 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
9188 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
9189 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
9190 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
9191 (Standard_ShortReal)Draw::Atof(theArgVec[10])
9194 aView->SetTextureEnv(aTexEnv);
9196 else // Disabling environment mapping
9198 Handle(Graphic3d_TextureEnv) aTexture;
9199 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
9208 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
9210 //! Remove registered clipping plane from all views and objects.
9211 static void removePlane (MapOfPlanes& theRegPlanes,
9212 const TCollection_AsciiString& theName)
9214 Handle(Graphic3d_ClipPlane) aClipPlane;
9215 if (!theRegPlanes.Find (theName, aClipPlane))
9217 std::cout << "Warning: no such plane.\n";
9221 theRegPlanes.UnBind (theName);
9222 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
9223 anIObjIt.More(); anIObjIt.Next())
9225 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
9226 aPrs->RemoveClipPlane (aClipPlane);
9229 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
9230 aViewIt.More(); aViewIt.Next())
9232 const Handle(V3d_View)& aView = aViewIt.Key2();
9233 aView->RemoveClipPlane(aClipPlane);
9236 ViewerTest::RedrawAllViews();
9240 //===============================================================================================
9241 //function : VClipPlane
9243 //===============================================================================================
9244 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9246 // use short-cut for created clip planes map of created (or "registered by name") clip planes
9247 static MapOfPlanes aRegPlanes;
9251 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
9253 theDi << aPlaneIter.Key() << " ";
9258 TCollection_AsciiString aCommand (theArgVec[1]);
9259 aCommand.LowerCase();
9260 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
9261 if (anActiveView.IsNull())
9263 std::cout << "Error: no active view.\n";
9267 // print maximum number of planes for current viewer
9268 if (aCommand == "-maxplanes"
9269 || aCommand == "maxplanes")
9271 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
9272 << " plane slots provided by driver.\n";
9276 // create / delete plane instance
9277 if (aCommand == "-create"
9278 || aCommand == "create"
9279 || aCommand == "-delete"
9280 || aCommand == "delete"
9281 || aCommand == "-clone"
9282 || aCommand == "clone")
9286 std::cout << "Syntax error: plane name is required.\n";
9290 Standard_Boolean toCreate = aCommand == "-create"
9291 || aCommand == "create";
9292 Standard_Boolean toClone = aCommand == "-clone"
9293 || aCommand == "clone";
9294 Standard_Boolean toDelete = aCommand == "-delete"
9295 || aCommand == "delete";
9296 TCollection_AsciiString aPlane (theArgVec[2]);
9300 if (aRegPlanes.IsBound (aPlane))
9302 std::cout << "Warning: existing plane has been overridden.\n";
9307 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9311 else if (toClone) // toClone
9313 if (!aRegPlanes.IsBound (aPlane))
9315 std::cout << "Error: no such plane.\n";
9318 else if (theArgsNb < 4)
9320 std::cout << "Syntax error: enter name for new plane.\n";
9324 TCollection_AsciiString aClone (theArgVec[3]);
9325 if (aRegPlanes.IsBound (aClone))
9327 std::cout << "Error: plane name is in use.\n";
9331 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
9333 aRegPlanes.Bind (aClone, aClipPlane->Clone());
9343 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
9345 aPlane = aPlaneIter.Key();
9346 removePlane (aRegPlanes, aPlane);
9347 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
9352 removePlane (aRegPlanes, aPlane);
9358 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9363 // set / unset plane command
9364 if (aCommand == "set"
9365 || aCommand == "unset")
9369 std::cout << "Syntax error: need more arguments.\n";
9373 // redirect to new syntax
9374 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
9375 anArgVec.SetValue (1, theArgVec[0]);
9376 anArgVec.SetValue (2, theArgVec[2]);
9377 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
9378 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
9380 anArgVec.SetValue (anIt, theArgVec[anIt]);
9383 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
9386 // change plane command
9387 TCollection_AsciiString aPlaneName;
9388 Handle(Graphic3d_ClipPlane) aClipPlane;
9389 Standard_Integer anArgIter = 0;
9390 if (aCommand == "-change"
9391 || aCommand == "change")
9393 // old syntax support
9396 std::cout << "Syntax error: need more arguments.\n";
9401 aPlaneName = theArgVec[2];
9402 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
9404 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
9408 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
9411 aPlaneName = theArgVec[1];
9416 aPlaneName = theArgVec[1];
9417 aClipPlane = new Graphic3d_ClipPlane();
9418 aRegPlanes.Bind (aPlaneName, aClipPlane);
9419 theDi << "Created new plane " << aPlaneName << ".\n";
9422 if (theArgsNb - anArgIter < 1)
9424 std::cout << "Syntax error: need more arguments.\n";
9428 for (; anArgIter < theArgsNb; ++anArgIter)
9430 const char** aChangeArgs = theArgVec + anArgIter;
9431 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
9432 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
9433 aChangeArg.LowerCase();
9435 Standard_Boolean toEnable = Standard_True;
9436 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
9438 aClipPlane->SetOn (toEnable);
9440 else if (aChangeArg.StartsWith ("-equation")
9441 || aChangeArg.StartsWith ("equation"))
9443 if (aNbChangeArgs < 5)
9445 std::cout << "Syntax error: need more arguments.\n";
9449 Standard_Integer aSubIndex = 1;
9450 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
9451 if (aPrefixLen < aChangeArg.Length())
9453 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
9454 if (!aSubStr.IsIntegerValue()
9455 || aSubStr.IntegerValue() <= 0)
9457 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9460 aSubIndex = aSubStr.IntegerValue();
9463 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
9464 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
9465 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
9466 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
9467 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9468 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
9470 if (aSubPln->ChainNextPlane().IsNull())
9472 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9474 aSubPln = aSubPln->ChainNextPlane();
9476 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9477 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
9480 else if ((aChangeArg == "-boxinterior"
9481 || aChangeArg == "-boxint"
9482 || aChangeArg == "-box")
9483 && aNbChangeArgs >= 7)
9485 Graphic3d_BndBox3d aBndBox;
9486 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
9487 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
9490 Standard_Integer aNbSubPlanes = 6;
9491 const Graphic3d_Vec3d aDirArray[6] =
9493 Graphic3d_Vec3d (-1, 0, 0),
9494 Graphic3d_Vec3d ( 1, 0, 0),
9495 Graphic3d_Vec3d ( 0,-1, 0),
9496 Graphic3d_Vec3d ( 0, 1, 0),
9497 Graphic3d_Vec3d ( 0, 0,-1),
9498 Graphic3d_Vec3d ( 0, 0, 1),
9500 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9501 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
9503 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
9504 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
9505 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
9506 if (aSubPlaneIter + 1 == aNbSubPlanes)
9508 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9512 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9514 aSubPln = aSubPln->ChainNextPlane();
9517 else if (aChangeArg == "-capping"
9518 || aChangeArg == "capping")
9520 if (aNbChangeArgs < 2)
9522 std::cout << "Syntax error: need more arguments.\n";
9526 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9528 aClipPlane->SetCapping (toEnable);
9533 // just skip otherwise (old syntax)
9536 else if (aChangeArg == "-useobjectmaterial"
9537 || aChangeArg == "-useobjectmat"
9538 || aChangeArg == "-useobjmat"
9539 || aChangeArg == "-useobjmaterial")
9541 if (aNbChangeArgs < 2)
9543 std::cout << "Syntax error: need more arguments.\n";
9547 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9549 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
9553 else if (aChangeArg == "-useobjecttexture"
9554 || aChangeArg == "-useobjecttex"
9555 || aChangeArg == "-useobjtexture"
9556 || aChangeArg == "-useobjtex")
9558 if (aNbChangeArgs < 2)
9560 std::cout << "Syntax error: need more arguments.\n";
9564 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9566 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
9570 else if (aChangeArg == "-useobjectshader"
9571 || aChangeArg == "-useobjshader")
9573 if (aNbChangeArgs < 2)
9575 std::cout << "Syntax error: need more arguments.\n";
9579 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9581 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
9585 else if (aChangeArg == "-color"
9586 || aChangeArg == "color")
9588 Quantity_Color aColor;
9589 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
9594 std::cout << "Syntax error: need more arguments.\n";
9598 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
9599 aMat.SetAmbientColor (aColor);
9600 aMat.SetDiffuseColor (aColor);
9601 aClipPlane->SetCappingMaterial (aMat);
9602 anArgIter += aNbParsed;
9604 else if ((aChangeArg == "-transparency"
9605 || aChangeArg == "-transp")
9606 && aNbChangeArgs >= 2)
9608 TCollection_AsciiString aValStr (aChangeArgs[1]);
9609 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
9610 if (aValStr.IsRealValue())
9612 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
9613 aMat.SetTransparency ((float )aValStr.RealValue());
9614 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
9615 aClipPlane->SetCappingMaterial (aMat);
9619 aValStr.LowerCase();
9620 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
9621 if (aValStr == "opaque")
9623 aMode = Graphic3d_AlphaMode_Opaque;
9625 else if (aValStr == "mask")
9627 aMode = Graphic3d_AlphaMode_Mask;
9629 else if (aValStr == "blend")
9631 aMode = Graphic3d_AlphaMode_Blend;
9633 else if (aValStr == "blendauto")
9635 aMode = Graphic3d_AlphaMode_BlendAuto;
9639 std::cout << "Syntax error at '" << aValStr << "'\n";
9642 anAspect->SetAlphaMode (aMode);
9643 aClipPlane->SetCappingAspect (anAspect);
9647 else if (aChangeArg == "-texname"
9648 || aChangeArg == "texname")
9650 if (aNbChangeArgs < 2)
9652 std::cout << "Syntax error: need more arguments.\n";
9656 TCollection_AsciiString aTextureName (aChangeArgs[1]);
9657 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
9658 if (!aTexture->IsDone())
9660 aClipPlane->SetCappingTexture (NULL);
9664 aTexture->EnableModulate();
9665 aTexture->EnableRepeat();
9666 aClipPlane->SetCappingTexture (aTexture);
9670 else if (aChangeArg == "-texscale"
9671 || aChangeArg == "texscale")
9673 if (aClipPlane->CappingTexture().IsNull())
9675 std::cout << "Error: no texture is set.\n";
9679 if (aNbChangeArgs < 3)
9681 std::cout << "Syntax error: need more arguments.\n";
9685 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9686 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9687 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
9690 else if (aChangeArg == "-texorigin"
9691 || aChangeArg == "texorigin") // texture origin
9693 if (aClipPlane->CappingTexture().IsNull())
9695 std::cout << "Error: no texture is set.\n";
9699 if (aNbChangeArgs < 3)
9701 std::cout << "Syntax error: need more arguments.\n";
9705 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9706 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9708 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
9711 else if (aChangeArg == "-texrotate"
9712 || aChangeArg == "texrotate") // texture rotation
9714 if (aClipPlane->CappingTexture().IsNull())
9716 std::cout << "Error: no texture is set.\n";
9720 if (aNbChangeArgs < 2)
9722 std::cout << "Syntax error: need more arguments.\n";
9726 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9727 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
9730 else if (aChangeArg == "-hatch"
9731 || aChangeArg == "hatch")
9733 if (aNbChangeArgs < 2)
9735 std::cout << "Syntax error: need more arguments.\n";
9739 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
9740 aHatchStr.LowerCase();
9741 if (aHatchStr == "on")
9743 aClipPlane->SetCappingHatchOn();
9745 else if (aHatchStr == "off")
9747 aClipPlane->SetCappingHatchOff();
9751 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
9755 else if (aChangeArg == "-delete"
9756 || aChangeArg == "delete")
9758 removePlane (aRegPlanes, aPlaneName);
9761 else if (aChangeArg == "-set"
9762 || aChangeArg == "-unset"
9763 || aChangeArg == "-setoverrideglobal")
9765 // set / unset plane command
9766 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
9767 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
9768 Standard_Integer anIt = 1;
9769 for (; anIt < aNbChangeArgs; ++anIt)
9771 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
9772 if (anEntityName.IsEmpty()
9773 || anEntityName.Value (1) == '-')
9777 else if (!toOverrideGlobal
9778 && ViewerTest_myViews.IsBound1 (anEntityName))
9780 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
9783 aView->AddClipPlane (aClipPlane);
9787 aView->RemoveClipPlane (aClipPlane);
9791 else if (GetMapOfAIS().IsBound2 (anEntityName))
9793 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
9796 aIObj->AddClipPlane (aClipPlane);
9800 aIObj->RemoveClipPlane (aClipPlane);
9802 if (!aIObj->ClipPlanes().IsNull())
9804 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
9809 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
9816 // apply to active view
9819 anActiveView->AddClipPlane (aClipPlane);
9823 anActiveView->RemoveClipPlane (aClipPlane);
9828 anArgIter = anArgIter + anIt - 1;
9833 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9838 ViewerTest::RedrawAllViews();
9842 //===============================================================================================
9843 //function : VZRange
9845 //===============================================================================================
9846 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9848 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9850 if (aCurrentView.IsNull())
9852 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9856 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
9860 theDi << "ZNear: " << aCamera->ZNear() << "\n";
9861 theDi << "ZFar: " << aCamera->ZFar() << "\n";
9867 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
9868 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
9870 if (aNewZNear >= aNewZFar)
9872 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
9876 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
9878 std::cout << theArgVec[0] << ": invalid arguments: ";
9879 std::cout << "znear, zfar should be positive for perspective camera.\n";
9883 aCamera->SetZRange (aNewZNear, aNewZFar);
9887 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9891 aCurrentView->Redraw();
9896 //===============================================================================================
9897 //function : VAutoZFit
9899 //===============================================================================================
9900 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9902 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9904 if (aCurrentView.IsNull())
9906 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9910 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
9914 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9920 theDi << "Auto z-fit mode: \n"
9921 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
9922 << "Scale: " << aScale << "\n";
9926 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
9930 aScale = Draw::Atoi (theArgVec[2]);
9933 aCurrentView->SetAutoZFitMode (isOn, aScale);
9934 aCurrentView->AutoZFit();
9935 aCurrentView->Redraw();
9940 //! Auxiliary function to print projection type
9941 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
9943 switch (theProjType)
9945 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
9946 case Graphic3d_Camera::Projection_Perspective: return "perspective";
9947 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
9948 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
9949 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
9954 //===============================================================================================
9955 //function : VCamera
9957 //===============================================================================================
9958 static int VCamera (Draw_Interpretor& theDI,
9959 Standard_Integer theArgsNb,
9960 const char** theArgVec)
9962 Handle(V3d_View) aView = ViewerTest::CurrentView();
9965 std::cout << "Error: no active view.\n";
9969 Handle(Graphic3d_Camera) aCamera = aView->Camera();
9972 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
9973 theDI << "FOVy: " << aCamera->FOVy() << "\n";
9974 theDI << "Distance: " << aCamera->Distance() << "\n";
9975 theDI << "IOD: " << aCamera->IOD() << "\n";
9976 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
9977 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
9978 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
9982 TCollection_AsciiString aPrsName;
9983 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9985 Standard_CString anArg = theArgVec[anArgIter];
9986 TCollection_AsciiString anArgCase (anArg);
9987 anArgCase.LowerCase();
9988 if (anArgCase == "-proj"
9989 || anArgCase == "-projection"
9990 || anArgCase == "-projtype"
9991 || anArgCase == "-projectiontype")
9993 theDI << projTypeName (aCamera->ProjectionType()) << " ";
9995 else if (anArgCase == "-ortho"
9996 || anArgCase == "-orthographic")
9998 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
10000 else if (anArgCase == "-persp"
10001 || anArgCase == "-perspective"
10002 || anArgCase == "-perspmono"
10003 || anArgCase == "-perspectivemono"
10004 || anArgCase == "-mono")
10006 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10008 else if (anArgCase == "-stereo"
10009 || anArgCase == "-stereoscopic"
10010 || anArgCase == "-perspstereo"
10011 || anArgCase == "-perspectivestereo")
10013 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10015 else if (anArgCase == "-left"
10016 || anArgCase == "-lefteye"
10017 || anArgCase == "-monoleft"
10018 || anArgCase == "-monolefteye"
10019 || anArgCase == "-perpsleft"
10020 || anArgCase == "-perpslefteye")
10022 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
10024 else if (anArgCase == "-right"
10025 || anArgCase == "-righteye"
10026 || anArgCase == "-monoright"
10027 || anArgCase == "-monorighteye"
10028 || anArgCase == "-perpsright")
10030 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
10032 else if (anArgCase == "-dist"
10033 || anArgCase == "-distance")
10035 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10036 if (anArgValue != NULL
10037 && *anArgValue != '-')
10040 aCamera->SetDistance (Draw::Atof (anArgValue));
10043 theDI << aCamera->Distance() << " ";
10045 else if (anArgCase == "-iod")
10047 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10048 if (anArgValue != NULL
10049 && *anArgValue != '-')
10052 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
10055 theDI << aCamera->IOD() << " ";
10057 else if (anArgCase == "-iodtype")
10059 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10060 TCollection_AsciiString anValueCase (anArgValue);
10061 anValueCase.LowerCase();
10062 if (anValueCase == "abs"
10063 || anValueCase == "absolute")
10066 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
10069 else if (anValueCase == "rel"
10070 || anValueCase == "relative")
10073 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
10076 else if (*anArgValue != '-')
10078 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
10081 switch (aCamera->GetIODType())
10083 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
10084 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
10087 else if (anArgCase == "-zfocus")
10089 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10090 if (anArgValue != NULL
10091 && *anArgValue != '-')
10094 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
10097 theDI << aCamera->ZFocus() << " ";
10099 else if (anArgCase == "-zfocustype")
10101 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10102 TCollection_AsciiString anValueCase (anArgValue);
10103 anValueCase.LowerCase();
10104 if (anValueCase == "abs"
10105 || anValueCase == "absolute")
10108 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
10111 else if (anValueCase == "rel"
10112 || anValueCase == "relative")
10115 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
10118 else if (*anArgValue != '-')
10120 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
10123 switch (aCamera->ZFocusType())
10125 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
10126 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
10129 else if (anArgCase == "-fov"
10130 || anArgCase == "-fovy")
10132 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10133 if (anArgValue != NULL
10134 && *anArgValue != '-')
10137 aCamera->SetFOVy (Draw::Atof (anArgValue));
10140 theDI << aCamera->FOVy() << " ";
10142 else if (aPrsName.IsEmpty()
10143 && !anArgCase.StartsWith ("-"))
10149 std::cout << "Error: unknown argument '" << anArg << "'\n";
10154 if (aPrsName.IsEmpty()
10161 if (!aPrsName.IsEmpty())
10163 Handle(AIS_CameraFrustum) aCameraFrustum;
10164 if (GetMapOfAIS().IsBound2 (aPrsName))
10166 // find existing object
10167 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
10168 if (aCameraFrustum.IsNull())
10170 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
10175 if (aCameraFrustum.IsNull())
10177 aCameraFrustum = new AIS_CameraFrustum();
10181 // not include displayed object of old camera frustum in the new one.
10182 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
10185 aCameraFrustum->SetCameraFrustum (aView->Camera());
10187 ViewerTest::Display (aPrsName, aCameraFrustum);
10193 //! Parse stereo output mode
10194 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
10195 Graphic3d_StereoMode& theMode)
10197 TCollection_AsciiString aFlag (theArg);
10199 if (aFlag == "quadbuffer")
10201 theMode = Graphic3d_StereoMode_QuadBuffer;
10203 else if (aFlag == "anaglyph")
10205 theMode = Graphic3d_StereoMode_Anaglyph;
10207 else if (aFlag == "row"
10208 || aFlag == "rowinterlaced")
10210 theMode = Graphic3d_StereoMode_RowInterlaced;
10212 else if (aFlag == "col"
10213 || aFlag == "colinterlaced"
10214 || aFlag == "columninterlaced")
10216 theMode = Graphic3d_StereoMode_ColumnInterlaced;
10218 else if (aFlag == "chess"
10219 || aFlag == "chessboard")
10221 theMode = Graphic3d_StereoMode_ChessBoard;
10223 else if (aFlag == "sbs"
10224 || aFlag == "sidebyside")
10226 theMode = Graphic3d_StereoMode_SideBySide;
10228 else if (aFlag == "ou"
10229 || aFlag == "overunder")
10231 theMode = Graphic3d_StereoMode_OverUnder;
10233 else if (aFlag == "pageflip"
10234 || aFlag == "softpageflip")
10236 theMode = Graphic3d_StereoMode_SoftPageFlip;
10240 return Standard_False;
10242 return Standard_True;
10245 //! Parse anaglyph filter
10246 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
10247 Graphic3d_RenderingParams::Anaglyph& theFilter)
10249 TCollection_AsciiString aFlag (theArg);
10251 if (aFlag == "redcyansimple")
10253 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10255 else if (aFlag == "redcyan"
10256 || aFlag == "redcyanoptimized")
10258 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
10260 else if (aFlag == "yellowbluesimple")
10262 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
10264 else if (aFlag == "yellowblue"
10265 || aFlag == "yellowblueoptimized")
10267 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
10269 else if (aFlag == "greenmagenta"
10270 || aFlag == "greenmagentasimple")
10272 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
10276 return Standard_False;
10278 return Standard_True;
10281 //==============================================================================
10282 //function : VStereo
10284 //==============================================================================
10286 static int VStereo (Draw_Interpretor& theDI,
10287 Standard_Integer theArgNb,
10288 const char** theArgVec)
10290 Handle(V3d_View) aView = ViewerTest::CurrentView();
10293 if (aView.IsNull())
10295 std::cout << "Error: no active viewer!\n";
10299 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
10300 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
10303 TCollection_AsciiString aMode;
10304 switch (aView->RenderingParams().StereoMode)
10306 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
10307 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
10308 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
10309 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
10310 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
10311 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
10312 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
10313 case Graphic3d_StereoMode_Anaglyph :
10314 aMode = "anaglyph";
10315 switch (aView->RenderingParams().AnaglyphFilter)
10317 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
10318 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
10319 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
10320 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
10321 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
10326 theDI << "Mode " << aMode << "\n";
10331 Handle(Graphic3d_Camera) aCamera;
10332 Graphic3d_RenderingParams* aParams = NULL;
10333 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
10334 if (!aView.IsNull())
10336 aParams = &aView->ChangeRenderingParams();
10337 aMode = aParams->StereoMode;
10338 aCamera = aView->Camera();
10341 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10342 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10344 Standard_CString anArg = theArgVec[anArgIter];
10345 TCollection_AsciiString aFlag (anArg);
10347 if (anUpdateTool.parseRedrawMode (aFlag))
10351 else if (aFlag == "0"
10354 if (++anArgIter < theArgNb)
10356 std::cout << "Error: wrong number of arguments!\n";
10360 if (!aCamera.IsNull()
10361 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
10363 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10365 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
10368 else if (aFlag == "1"
10371 if (++anArgIter < theArgNb)
10373 std::cout << "Error: wrong number of arguments!\n";
10377 if (!aCamera.IsNull())
10379 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10381 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10384 else if (aFlag == "-reverse"
10385 || aFlag == "-reversed"
10386 || aFlag == "-swap")
10388 Standard_Boolean toEnable = Standard_True;
10389 if (++anArgIter < theArgNb
10390 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10394 aParams->ToReverseStereo = toEnable;
10396 else if (aFlag == "-noreverse"
10397 || aFlag == "-noswap")
10399 Standard_Boolean toDisable = Standard_True;
10400 if (++anArgIter < theArgNb
10401 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
10405 aParams->ToReverseStereo = !toDisable;
10407 else if (aFlag == "-mode"
10408 || aFlag == "-stereomode")
10410 if (++anArgIter >= theArgNb
10411 || !parseStereoMode (theArgVec[anArgIter], aMode))
10413 std::cout << "Error: syntax error at '" << anArg << "'\n";
10417 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10419 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10422 else if (aFlag == "-anaglyph"
10423 || aFlag == "-anaglyphfilter")
10425 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10426 if (++anArgIter >= theArgNb
10427 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
10429 std::cout << "Error: syntax error at '" << anArg << "'\n";
10433 aMode = Graphic3d_StereoMode_Anaglyph;
10434 aParams->AnaglyphFilter = aFilter;
10436 else if (parseStereoMode (anArg, aMode)) // short syntax
10438 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10440 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10445 std::cout << "Error: syntax error at '" << anArg << "'\n";
10450 if (!aView.IsNull())
10452 aParams->StereoMode = aMode;
10453 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10458 //===============================================================================================
10459 //function : VDefaults
10461 //===============================================================================================
10462 static int VDefaults (Draw_Interpretor& theDi,
10463 Standard_Integer theArgsNb,
10464 const char** theArgVec)
10466 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
10469 std::cerr << "No active viewer!\n";
10473 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
10476 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
10478 theDi << "DeflType: relative\n"
10479 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
10483 theDi << "DeflType: absolute\n"
10484 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
10486 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
10487 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
10491 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10493 TCollection_AsciiString anArg (theArgVec[anArgIter]);
10495 if (anArg == "-ABSDEFL"
10496 || anArg == "-ABSOLUTEDEFLECTION"
10497 || anArg == "-DEFL"
10498 || anArg == "-DEFLECTION")
10500 if (++anArgIter >= theArgsNb)
10502 std::cout << "Error: wrong syntax at " << anArg << "\n";
10505 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
10506 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
10508 else if (anArg == "-RELDEFL"
10509 || anArg == "-RELATIVEDEFLECTION"
10510 || anArg == "-DEVCOEFF"
10511 || anArg == "-DEVIATIONCOEFF"
10512 || anArg == "-DEVIATIONCOEFFICIENT")
10514 if (++anArgIter >= theArgsNb)
10516 std::cout << "Error: wrong syntax at " << anArg << "\n";
10519 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
10520 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
10522 else if (anArg == "-ANGDEFL"
10523 || anArg == "-ANGULARDEFL"
10524 || anArg == "-ANGULARDEFLECTION")
10526 if (++anArgIter >= theArgsNb)
10528 std::cout << "Error: wrong syntax at " << anArg << "\n";
10531 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
10532 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
10534 else if (anArg == "-AUTOTR"
10535 || anArg == "-AUTOTRIANG"
10536 || anArg == "-AUTOTRIANGULATION")
10538 if (++anArgIter >= theArgsNb)
10540 std::cout << "Error: wrong syntax at " << anArg << "\n";
10543 TCollection_AsciiString aValue (theArgVec[anArgIter]);
10544 aValue.LowerCase();
10548 aDefParams->SetAutoTriangulation (Standard_True);
10550 else if (aValue == "off"
10553 aDefParams->SetAutoTriangulation (Standard_False);
10558 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
10565 //! Auxiliary method
10566 inline void addLight (const Handle(V3d_Light)& theLightNew,
10567 const Graphic3d_ZLayerId theLayer,
10568 const Standard_Boolean theIsGlobal)
10570 if (theLightNew.IsNull())
10575 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10576 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
10578 aViewer->AddLight (theLightNew);
10581 aViewer->SetLightOn (theLightNew);
10585 ViewerTest::CurrentView()->SetLightOn (theLightNew);
10590 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
10591 if (aSettings.Lights().IsNull())
10593 aSettings.SetLights (new Graphic3d_LightSet());
10595 aSettings.Lights()->Add (theLightNew);
10596 aViewer->SetZLayerSettings (theLayer, aSettings);
10600 //! Auxiliary method
10601 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
10603 TCollection_AsciiString anArgNextCase (theArgNext);
10604 anArgNextCase.UpperCase();
10605 if (anArgNextCase.Length() > 5
10606 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
10608 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
10612 return theArgNext.IntegerValue();
10616 //===============================================================================================
10617 //function : VLight
10619 //===============================================================================================
10620 static int VLight (Draw_Interpretor& theDi,
10621 Standard_Integer theArgsNb,
10622 const char** theArgVec)
10624 Handle(V3d_View) aView = ViewerTest::CurrentView();
10625 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10627 || aViewer.IsNull())
10629 std::cerr << "No active viewer!\n";
10633 Standard_Real anXYZ[3] = {};
10634 Standard_Real anAtten[2] = {};
10637 // print lights info
10638 Standard_Integer aLightId = 0;
10639 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
10641 Handle(V3d_Light) aLight = aLightIter.Value();
10642 const Quantity_Color aColor = aLight->Color();
10643 theDi << "Light #" << aLightId
10644 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
10645 << " [" << aLight->GetId() << "]" << "\n";
10646 switch (aLight->Type())
10650 theDi << " Type: Ambient\n";
10651 theDi << " Intensity: " << aLight->Intensity() << "\n";
10654 case V3d_DIRECTIONAL:
10656 theDi << " Type: Directional\n";
10657 theDi << " Intensity: " << aLight->Intensity() << "\n";
10658 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10659 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10660 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10661 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10664 case V3d_POSITIONAL:
10666 theDi << " Type: Positional\n";
10667 theDi << " Intensity: " << aLight->Intensity() << "\n";
10668 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10669 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10670 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10671 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10672 aLight->Attenuation (anAtten[0], anAtten[1]);
10673 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10678 theDi << " Type: Spot\n";
10679 theDi << " Intensity: " << aLight->Intensity() << "\n";
10680 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10681 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10682 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10683 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10684 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10685 aLight->Attenuation (anAtten[0], anAtten[1]);
10686 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10687 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
10688 theDi << " Exponent: " << aLight->Concentration() << "\n";
10693 theDi << " Type: UNKNOWN\n";
10697 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
10701 Handle(V3d_Light) aLightNew;
10702 Handle(V3d_Light) aLightOld;
10703 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
10704 Standard_Boolean isGlobal = Standard_True;
10705 Standard_Boolean toCreate = Standard_False;
10706 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10707 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
10709 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
10711 TCollection_AsciiString aName, aValue;
10712 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
10713 TCollection_AsciiString anArgCase (anArg);
10714 anArgCase.UpperCase();
10715 if (anUpdateTool.parseRedrawMode (anArg))
10720 if (anArgCase.IsEqual ("NEW")
10721 || anArgCase.IsEqual ("ADD")
10722 || anArgCase.IsEqual ("CREATE")
10723 || anArgCase.IsEqual ("-NEW")
10724 || anArgCase.IsEqual ("-ADD")
10725 || anArgCase.IsEqual ("-CREATE"))
10727 toCreate = Standard_True;
10729 else if (anArgCase.IsEqual ("-LAYER")
10730 || anArgCase.IsEqual ("-ZLAYER"))
10732 if (++anArgIt >= theArgsNb)
10734 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10738 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
10739 aValStr.LowerCase();
10740 if (aValStr == "default"
10741 || aValStr == "def")
10743 aLayer = Graphic3d_ZLayerId_Default;
10745 else if (aValStr == "top")
10747 aLayer = Graphic3d_ZLayerId_Top;
10749 else if (aValStr == "topmost")
10751 aLayer = Graphic3d_ZLayerId_Topmost;
10753 else if (aValStr == "toposd"
10754 || aValStr == "osd")
10756 aLayer = Graphic3d_ZLayerId_TopOSD;
10758 else if (aValStr == "botosd"
10759 || aValStr == "bottom")
10761 aLayer = Graphic3d_ZLayerId_BotOSD;
10763 else if (aValStr.IsIntegerValue())
10765 aLayer = Draw::Atoi (theArgVec[anArgIt]);
10769 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
10773 else if (anArgCase.IsEqual ("GLOB")
10774 || anArgCase.IsEqual ("GLOBAL")
10775 || anArgCase.IsEqual ("-GLOB")
10776 || anArgCase.IsEqual ("-GLOBAL"))
10778 isGlobal = Standard_True;
10780 else if (anArgCase.IsEqual ("LOC")
10781 || anArgCase.IsEqual ("LOCAL")
10782 || anArgCase.IsEqual ("-LOC")
10783 || anArgCase.IsEqual ("-LOCAL"))
10785 isGlobal = Standard_False;
10787 else if (anArgCase.IsEqual ("DEF")
10788 || anArgCase.IsEqual ("DEFAULTS")
10789 || anArgCase.IsEqual ("-DEF")
10790 || anArgCase.IsEqual ("-DEFAULTS"))
10792 toCreate = Standard_False;
10793 aViewer->SetDefaultLights();
10795 else if (anArgCase.IsEqual ("CLR")
10796 || anArgCase.IsEqual ("CLEAR")
10797 || anArgCase.IsEqual ("-CLR")
10798 || anArgCase.IsEqual ("-CLEAR"))
10800 toCreate = Standard_False;
10802 TColStd_SequenceOfInteger aLayers;
10803 aViewer->GetAllZLayers (aLayers);
10804 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10806 if (aLayeriter.Value() == aLayer
10807 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10809 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10810 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10811 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10812 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10819 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10821 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
10823 Handle(V3d_Light) aLight = aLightIter.Value();
10824 aViewer->DelLight (aLight);
10825 aLightIter = aView->ActiveLightIterator();
10829 else if (anArgCase.IsEqual ("AMB")
10830 || anArgCase.IsEqual ("AMBIENT")
10831 || anArgCase.IsEqual ("AMBLIGHT"))
10835 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10839 addLight (aLightNew, aLayer, isGlobal);
10840 toCreate = Standard_False;
10841 aLightNew = new V3d_AmbientLight();
10843 else if (anArgCase.IsEqual ("DIRECTIONAL")
10844 || anArgCase.IsEqual ("DIRLIGHT"))
10848 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10852 addLight (aLightNew, aLayer, isGlobal);
10853 toCreate = Standard_False;
10854 aLightNew = new V3d_DirectionalLight();
10856 else if (anArgCase.IsEqual ("SPOT")
10857 || anArgCase.IsEqual ("SPOTLIGHT"))
10861 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10865 addLight (aLightNew, aLayer, isGlobal);
10866 toCreate = Standard_False;
10867 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
10869 else if (anArgCase.IsEqual ("POSLIGHT")
10870 || anArgCase.IsEqual ("POSITIONAL"))
10874 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10878 addLight (aLightNew, aLayer, isGlobal);
10879 toCreate = Standard_False;
10880 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
10882 else if (anArgCase.IsEqual ("CHANGE")
10883 || anArgCase.IsEqual ("-CHANGE"))
10885 if (++anArgIt >= theArgsNb)
10887 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10891 addLight (aLightNew, aLayer, isGlobal);
10892 aLightNew.Nullify();
10893 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
10894 Standard_Integer aLightIt = 0;
10895 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10897 if (aLightIt == aLightId)
10899 aLightOld = aLightIter.Value();
10904 if (aLightOld.IsNull())
10906 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
10910 else if (anArgCase.IsEqual ("DEL")
10911 || anArgCase.IsEqual ("DELETE")
10912 || anArgCase.IsEqual ("-DEL")
10913 || anArgCase.IsEqual ("-DELETE"))
10915 Handle(V3d_Light) aLightDel;
10916 if (++anArgIt >= theArgsNb)
10918 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10922 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10923 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
10924 Standard_Integer aLightIt = 0;
10925 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10927 aLightDel = aLightIter.Value();
10928 if (aLightIt == aLightDelId)
10933 if (aLightDel.IsNull())
10938 TColStd_SequenceOfInteger aLayers;
10939 aViewer->GetAllZLayers (aLayers);
10940 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10942 if (aLayeriter.Value() == aLayer
10943 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10945 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10946 if (!aSettings.Lights().IsNull())
10948 aSettings.Lights()->Remove (aLightDel);
10949 if (aSettings.Lights()->IsEmpty())
10951 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10954 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10955 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10962 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10964 aViewer->DelLight (aLightDel);
10967 else if (anArgCase.IsEqual ("COLOR")
10968 || anArgCase.IsEqual ("COLOUR")
10969 || anArgCase.IsEqual ("-COLOR")
10970 || anArgCase.IsEqual ("-COLOUR"))
10972 if (++anArgIt >= theArgsNb
10973 || aLightCurr.IsNull())
10975 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10979 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10980 anArgNext.UpperCase();
10981 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
10982 aLightCurr->SetColor (aColor);
10984 else if (anArgCase.IsEqual ("POS")
10985 || anArgCase.IsEqual ("POSITION")
10986 || anArgCase.IsEqual ("-POS")
10987 || anArgCase.IsEqual ("-POSITION"))
10989 if ((anArgIt + 3) >= theArgsNb
10990 || aLightCurr.IsNull()
10991 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10992 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10994 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10998 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10999 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11000 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11001 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
11003 else if (anArgCase.IsEqual ("DIR")
11004 || anArgCase.IsEqual ("DIRECTION")
11005 || anArgCase.IsEqual ("-DIR")
11006 || anArgCase.IsEqual ("-DIRECTION"))
11008 if ((anArgIt + 3) >= theArgsNb
11009 || aLightCurr.IsNull()
11010 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
11011 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11013 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11017 anXYZ[0] = Atof (theArgVec[++anArgIt]);
11018 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11019 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11020 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
11022 else if (anArgCase.IsEqual ("SM")
11023 || anArgCase.IsEqual ("SMOOTHNESS")
11024 || anArgCase.IsEqual ("-SM")
11025 || anArgCase.IsEqual ("-SMOOTHNESS"))
11027 if (++anArgIt >= theArgsNb
11028 || aLightCurr.IsNull())
11030 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11034 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11035 if (Abs (aSmoothness) <= ShortRealEpsilon())
11037 aLightCurr->SetIntensity (1.f);
11039 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
11041 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
11045 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
11046 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
11049 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
11051 aLightCurr->SetSmoothRadius (aSmoothness);
11053 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
11055 aLightCurr->SetSmoothAngle (aSmoothness);
11058 else if (anArgCase.IsEqual ("INT")
11059 || anArgCase.IsEqual ("INTENSITY")
11060 || anArgCase.IsEqual ("-INT")
11061 || anArgCase.IsEqual ("-INTENSITY"))
11063 if (++anArgIt >= theArgsNb
11064 || aLightCurr.IsNull())
11066 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11070 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11071 aLightCurr->SetIntensity (aIntensity);
11073 else if (anArgCase.IsEqual ("ANG")
11074 || anArgCase.IsEqual ("ANGLE")
11075 || anArgCase.IsEqual ("-ANG")
11076 || anArgCase.IsEqual ("-ANGLE"))
11078 if (++anArgIt >= theArgsNb
11079 || aLightCurr.IsNull()
11080 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11082 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11086 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11087 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
11089 else if (anArgCase.IsEqual ("CONSTATTEN")
11090 || anArgCase.IsEqual ("CONSTATTENUATION")
11091 || anArgCase.IsEqual ("-CONSTATTEN")
11092 || anArgCase.IsEqual ("-CONSTATTENUATION"))
11094 if (++anArgIt >= theArgsNb
11095 || aLightCurr.IsNull()
11096 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11097 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11099 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11103 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11104 anAtten[0] = Atof (theArgVec[anArgIt]);
11105 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11107 else if (anArgCase.IsEqual ("LINATTEN")
11108 || anArgCase.IsEqual ("LINEARATTEN")
11109 || anArgCase.IsEqual ("LINEARATTENUATION")
11110 || anArgCase.IsEqual ("-LINATTEN")
11111 || anArgCase.IsEqual ("-LINEARATTEN")
11112 || anArgCase.IsEqual ("-LINEARATTENUATION"))
11114 if (++anArgIt >= theArgsNb
11115 || aLightCurr.IsNull()
11116 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11117 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11119 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11123 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11124 anAtten[1] = Atof (theArgVec[anArgIt]);
11125 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11127 else if (anArgCase.IsEqual ("EXP")
11128 || anArgCase.IsEqual ("EXPONENT")
11129 || anArgCase.IsEqual ("SPOTEXP")
11130 || anArgCase.IsEqual ("SPOTEXPONENT")
11131 || anArgCase.IsEqual ("-EXP")
11132 || anArgCase.IsEqual ("-EXPONENT")
11133 || anArgCase.IsEqual ("-SPOTEXP")
11134 || anArgCase.IsEqual ("-SPOTEXPONENT"))
11136 if (++anArgIt >= theArgsNb
11137 || aLightCurr.IsNull()
11138 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11140 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11144 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
11146 else if (anArgCase.IsEqual ("HEAD")
11147 || anArgCase.IsEqual ("HEADLIGHT")
11148 || anArgCase.IsEqual ("-HEAD")
11149 || anArgCase.IsEqual ("-HEADLIGHT"))
11151 if (aLightCurr.IsNull()
11152 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
11154 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11158 Standard_Boolean isHeadLight = Standard_True;
11159 if (anArgIt + 1 < theArgsNb
11160 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
11164 aLightCurr->SetHeadlight (isHeadLight);
11168 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
11172 addLight (aLightNew, aLayer, isGlobal);
11176 //! Read Graphic3d_RenderingParams::PerfCounters flag.
11177 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
11178 Standard_Boolean& theToReset,
11179 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
11180 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
11182 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
11183 TCollection_AsciiString aVal = theValue;
11184 Standard_Boolean toReverse = Standard_False;
11185 if (aVal == "none")
11187 theToReset = Standard_True;
11188 return Standard_True;
11190 else if (aVal.StartsWith ("-"))
11192 toReverse = Standard_True;
11193 aVal = aVal.SubString (2, aVal.Length());
11195 else if (aVal.StartsWith ("no"))
11197 toReverse = Standard_True;
11198 aVal = aVal.SubString (3, aVal.Length());
11200 else if (aVal.StartsWith ("+"))
11202 aVal = aVal.SubString (2, aVal.Length());
11206 theToReset = Standard_True;
11210 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11211 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
11212 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
11213 else if (aVal == "structs"
11214 || aVal == "structures"
11215 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
11216 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
11217 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11218 else if (aVal == "tris"
11219 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
11220 else if (aVal == "pnts"
11221 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
11222 else if (aVal == "mem"
11223 || aVal == "gpumem"
11224 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11225 else if (aVal == "skipimmediate"
11226 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
11227 else if (aVal == "frametime"
11228 || aVal == "frametimers"
11229 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11230 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
11231 else if (aVal == "extended"
11232 || aVal == "verbose"
11233 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
11234 else if (aVal == "full"
11235 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
11238 return Standard_False;
11243 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
11247 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
11249 return Standard_True;
11252 //! Read Graphic3d_RenderingParams::PerfCounters flags.
11253 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
11254 Graphic3d_RenderingParams::PerfCounters& theFlags)
11256 TCollection_AsciiString aValue = theValue;
11257 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
11258 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
11259 Standard_Boolean toReset = Standard_False;
11262 Standard_Integer aSplitPos = aValue.Search ("|");
11263 if (aSplitPos <= 0)
11265 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
11267 return Standard_False;
11271 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
11273 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
11274 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
11275 return Standard_True;
11280 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
11281 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
11283 return Standard_False;
11286 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
11290 //=======================================================================
11291 //function : VRenderParams
11292 //purpose : Enables/disables rendering features
11293 //=======================================================================
11295 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
11296 Standard_Integer theArgNb,
11297 const char** theArgVec)
11299 Handle(V3d_View) aView = ViewerTest::CurrentView();
11300 if (aView.IsNull())
11302 std::cerr << "Error: no active viewer!\n";
11306 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
11307 TCollection_AsciiString aCmdName (theArgVec[0]);
11308 aCmdName.LowerCase();
11309 if (aCmdName == "vraytrace")
11313 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
11316 else if (theArgNb == 2)
11318 TCollection_AsciiString aValue (theArgVec[1]);
11319 aValue.LowerCase();
11323 aParams.Method = Graphic3d_RM_RAYTRACING;
11327 else if (aValue == "off"
11330 aParams.Method = Graphic3d_RM_RASTERIZATION;
11336 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
11342 std::cout << "Error: wrong number of arguments\n";
11349 theDI << "renderMode: ";
11350 switch (aParams.Method)
11352 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11353 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
11356 theDI << "transparency: ";
11357 switch (aParams.TransparencyMethod)
11359 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
11360 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
11361 << TCollection_AsciiString (aParams.OitDepthFactor); break;
11364 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
11365 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
11366 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
11367 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
11368 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
11369 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
11370 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
11371 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
11372 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
11373 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
11374 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
11375 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
11376 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
11377 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
11378 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
11379 theDI << "shadingModel: ";
11380 switch (aView->ShadingModel())
11382 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11383 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
11384 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
11385 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
11386 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
11389 theDI << "perfCounters:";
11390 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
11394 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
11398 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
11400 theDI << " structs";
11402 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
11404 theDI << " groups";
11406 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
11408 theDI << " arrays";
11410 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
11414 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
11418 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
11420 theDI << " gpumem";
11422 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
11424 theDI << " frameTime";
11426 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
11428 theDI << " skipimmediate";
11430 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
11436 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
11437 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
11438 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
11439 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
11440 "noUpdate") << "\n";
11445 Standard_Boolean toPrint = Standard_False;
11446 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
11447 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11449 Standard_CString anArg (theArgVec[anArgIter]);
11450 TCollection_AsciiString aFlag (anArg);
11452 if (anUpdateTool.parseRedrawMode (aFlag))
11456 else if (aFlag == "-echo"
11457 || aFlag == "-print")
11459 toPrint = Standard_True;
11460 anUpdateTool.Invalidate();
11462 else if (aFlag == "-mode"
11463 || aFlag == "-rendermode"
11464 || aFlag == "-render_mode")
11468 switch (aParams.Method)
11470 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11471 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
11477 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11481 else if (aFlag == "-ray"
11482 || aFlag == "-raytrace")
11486 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
11490 aParams.Method = Graphic3d_RM_RAYTRACING;
11492 else if (aFlag == "-rast"
11493 || aFlag == "-raster"
11494 || aFlag == "-rasterization")
11498 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
11502 aParams.Method = Graphic3d_RM_RASTERIZATION;
11504 else if (aFlag == "-msaa")
11508 theDI << aParams.NbMsaaSamples << " ";
11511 else if (++anArgIter >= theArgNb)
11513 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11517 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
11518 if (aNbSamples < 0)
11520 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
11525 aParams.NbMsaaSamples = aNbSamples;
11528 else if (aFlag == "-linefeather"
11529 || aFlag == "-edgefeather"
11530 || aFlag == "-feather")
11534 theDI << " " << aParams.LineFeather << " ";
11537 else if (++anArgIter >= theArgNb)
11539 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11543 TCollection_AsciiString aParam = theArgVec[anArgIter];
11544 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11545 if (aFeather <= 0.0f)
11547 std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n";
11550 aParams.LineFeather = aFeather;
11552 else if (aFlag == "-oit")
11556 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
11558 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
11562 theDI << "off" << " ";
11566 else if (++anArgIter >= theArgNb)
11568 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11572 TCollection_AsciiString aParam = theArgVec[anArgIter];
11573 aParam.LowerCase();
11574 if (aParam.IsRealValue())
11576 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11577 if (aWeight < 0.f || aWeight > 1.f)
11579 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
11583 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
11584 aParams.OitDepthFactor = aWeight;
11586 else if (aParam == "off")
11588 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
11592 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11596 else if (aFlag == "-depthprepass")
11600 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
11603 aParams.ToEnableDepthPrepass = Standard_True;
11604 if (anArgIter + 1 < theArgNb
11605 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
11610 else if (aFlag == "-samplealphatocoverage"
11611 || aFlag == "-alphatocoverage")
11615 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
11618 aParams.ToEnableAlphaToCoverage = Standard_True;
11619 if (anArgIter + 1 < theArgNb
11620 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
11625 else if (aFlag == "-rendscale"
11626 || aFlag == "-renderscale"
11627 || aFlag == "-renderresolutionscale")
11631 theDI << aParams.RenderResolutionScale << " ";
11634 else if (++anArgIter >= theArgNb)
11636 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11640 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
11643 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
11648 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
11651 else if (aFlag == "-raydepth"
11652 || aFlag == "-ray_depth")
11656 theDI << aParams.RaytracingDepth << " ";
11659 else if (++anArgIter >= theArgNb)
11661 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11665 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
11667 // We allow RaytracingDepth be more than 10 in case of GI enabled
11668 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
11670 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
11675 aParams.RaytracingDepth = aDepth;
11678 else if (aFlag == "-shad"
11679 || aFlag == "-shadows")
11683 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
11687 Standard_Boolean toEnable = Standard_True;
11688 if (++anArgIter < theArgNb
11689 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11693 aParams.IsShadowEnabled = toEnable;
11695 else if (aFlag == "-refl"
11696 || aFlag == "-reflections")
11700 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
11704 Standard_Boolean toEnable = Standard_True;
11705 if (++anArgIter < theArgNb
11706 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11710 aParams.IsReflectionEnabled = toEnable;
11712 else if (aFlag == "-fsaa")
11716 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
11720 Standard_Boolean toEnable = Standard_True;
11721 if (++anArgIter < theArgNb
11722 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11726 aParams.IsAntialiasingEnabled = toEnable;
11728 else if (aFlag == "-gleam")
11732 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
11736 Standard_Boolean toEnable = Standard_True;
11737 if (++anArgIter < theArgNb
11738 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11742 aParams.IsTransparentShadowEnabled = toEnable;
11744 else if (aFlag == "-gi")
11748 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
11752 Standard_Boolean toEnable = Standard_True;
11753 if (++anArgIter < theArgNb
11754 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11758 aParams.IsGlobalIlluminationEnabled = toEnable;
11761 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
11764 else if (aFlag == "-blockedrng"
11765 || aFlag == "-brng")
11769 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
11773 Standard_Boolean toEnable = Standard_True;
11774 if (++anArgIter < theArgNb
11775 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11779 aParams.CoherentPathTracingMode = toEnable;
11781 else if (aFlag == "-maxrad")
11785 theDI << aParams.RadianceClampingValue << " ";
11788 else if (++anArgIter >= theArgNb)
11790 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11794 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
11795 if (!aMaxRadStr.IsRealValue())
11797 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11801 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
11802 if (aMaxRadiance <= 0.0)
11804 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
11809 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
11812 else if (aFlag == "-iss")
11816 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
11820 Standard_Boolean toEnable = Standard_True;
11821 if (++anArgIter < theArgNb
11822 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11826 aParams.AdaptiveScreenSampling = toEnable;
11828 else if (aFlag == "-issatomic")
11832 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
11836 Standard_Boolean toEnable = Standard_True;
11837 if (++anArgIter < theArgNb
11838 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11842 aParams.AdaptiveScreenSamplingAtomic = toEnable;
11844 else if (aFlag == "-issd")
11848 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
11852 Standard_Boolean toEnable = Standard_True;
11853 if (++anArgIter < theArgNb
11854 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11858 aParams.ShowSamplingTiles = toEnable;
11860 else if (aFlag == "-tilesize")
11864 theDI << aParams.RayTracingTileSize << " ";
11867 else if (++anArgIter >= theArgNb)
11869 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11873 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
11876 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
11879 aParams.RayTracingTileSize = aTileSize;
11881 else if (aFlag == "-nbtiles")
11885 theDI << aParams.NbRayTracingTiles << " ";
11888 else if (++anArgIter >= theArgNb)
11890 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11894 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
11897 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
11900 else if (aNbTiles > 0
11902 || aNbTiles > 1024))
11904 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
11906 aParams.NbRayTracingTiles = aNbTiles;
11908 else if (aFlag == "-env")
11912 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
11916 Standard_Boolean toEnable = Standard_True;
11917 if (++anArgIter < theArgNb
11918 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11922 aParams.UseEnvironmentMapBackground = toEnable;
11924 else if (aFlag == "-twoside")
11928 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
11932 Standard_Boolean toEnable = Standard_True;
11933 if (++anArgIter < theArgNb
11934 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11938 aParams.TwoSidedBsdfModels = toEnable;
11940 else if (aFlag == "-shademodel"
11941 || aFlag == "-shadingmodel"
11942 || aFlag == "-shading")
11946 switch (aView->ShadingModel())
11948 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11949 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
11950 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
11951 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
11952 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
11957 if (++anArgIter >= theArgNb)
11959 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11962 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
11963 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
11964 && aModel != Graphic3d_TOSM_DEFAULT)
11966 aView->SetShadingModel (aModel);
11970 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
11974 else if (aFlag == "-resolution")
11976 if (++anArgIter >= theArgNb)
11978 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11982 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
11983 if (aResolution.IsIntegerValue())
11985 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
11989 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11993 else if (aFlag == "-rebuildglsl"
11994 || aFlag == "-rebuild")
11998 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
12002 Standard_Boolean toEnable = Standard_True;
12003 if (++anArgIter < theArgNb
12004 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12008 aParams.RebuildRayTracingShaders = toEnable;
12010 else if (aFlag == "-focal")
12012 if (++anArgIter >= theArgNb)
12014 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12018 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12019 if (aParam.IsRealValue())
12021 float aFocalDist = static_cast<float> (aParam.RealValue());
12022 if (aFocalDist < 0)
12024 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12027 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
12031 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12035 else if (aFlag == "-aperture")
12037 if (++anArgIter >= theArgNb)
12039 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12043 TCollection_AsciiString aParam(theArgVec[anArgIter]);
12044 if (aParam.IsRealValue())
12046 float aApertureSize = static_cast<float> (aParam.RealValue());
12047 if (aApertureSize < 0)
12049 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12052 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
12056 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12060 else if (aFlag == "-exposure")
12062 if (++anArgIter >= theArgNb)
12064 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12068 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
12069 if (anExposure.IsRealValue())
12071 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
12075 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12079 else if (aFlag == "-whitepoint")
12081 if (++anArgIter >= theArgNb)
12083 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12087 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
12088 if (aWhitePoint.IsRealValue())
12090 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
12094 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12098 else if (aFlag == "-tonemapping")
12100 if (++anArgIter >= theArgNb)
12102 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12106 TCollection_AsciiString aMode (theArgVec[anArgIter]);
12109 if (aMode == "disabled")
12111 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
12113 else if (aMode == "filmic")
12115 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
12119 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12123 else if (aFlag == "-performancestats"
12124 || aFlag == "-performancecounters"
12125 || aFlag == "-perfstats"
12126 || aFlag == "-perfcounters"
12127 || aFlag == "-stats")
12129 if (++anArgIter >= theArgNb)
12131 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12135 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
12136 aFlagsStr.LowerCase();
12137 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
12138 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
12140 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12143 aView->ChangeRenderingParams().CollectedStats = aFlags;
12144 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
12146 else if (aFlag == "-perfupdateinterval"
12147 || aFlag == "-statsupdateinterval")
12149 if (++anArgIter >= theArgNb)
12151 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12154 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12156 else if (aFlag == "-perfchart"
12157 || aFlag == "-statschart")
12159 if (++anArgIter >= theArgNb)
12161 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12164 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
12166 else if (aFlag == "-perfchartmax"
12167 || aFlag == "-statschartmax")
12169 if (++anArgIter >= theArgNb)
12171 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12174 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12176 else if (aFlag == "-frustumculling"
12177 || aFlag == "-culling")
12181 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
12182 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
12183 "noUpdate") << " ";
12187 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
12188 if (++anArgIter < theArgNb)
12190 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
12191 aStateStr.LowerCase();
12192 bool toEnable = true;
12193 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
12195 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
12197 else if (aStateStr == "noupdate"
12198 || aStateStr == "freeze")
12200 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
12207 aParams.FrustumCullingState = aState;
12211 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
12219 //=======================================================================
12220 //function : searchInfo
12222 //=======================================================================
12223 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
12224 const TCollection_AsciiString& theKey)
12226 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
12228 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
12230 return anIter.Value();
12233 return TCollection_AsciiString();
12236 //=======================================================================
12237 //function : VStatProfiler
12239 //=======================================================================
12240 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
12241 Standard_Integer theArgNb,
12242 const char** theArgVec)
12244 Handle(V3d_View) aView = ViewerTest::CurrentView();
12245 if (aView.IsNull())
12247 std::cerr << "Error: no active viewer!\n";
12251 Standard_Boolean toRedraw = Standard_True;
12252 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
12253 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
12254 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
12255 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12257 Standard_CString anArg (theArgVec[anArgIter]);
12258 TCollection_AsciiString aFlag (anArg);
12260 if (aFlag == "-noredraw")
12262 toRedraw = Standard_False;
12266 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
12267 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
12268 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
12269 else if (aFlag == "alllayers"
12270 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
12271 else if (aFlag == "allstructs"
12272 || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
12273 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
12274 else if (aFlag == "allarrays"
12275 || aFlag == "fillarrays"
12276 || aFlag == "linearrays"
12277 || aFlag == "pointarrays"
12278 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
12279 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
12280 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
12281 else if (aFlag == "geommem"
12282 || aFlag == "texturemem"
12283 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
12284 else if (aFlag == "elapsedframe"
12285 || aFlag == "cpuframeaverage"
12286 || aFlag == "cpupickingaverage"
12287 || aFlag == "cpucullingaverage"
12288 || aFlag == "cpudynaverage"
12289 || aFlag == "cpuframemax"
12290 || aFlag == "cpupickingmax"
12291 || aFlag == "cpucullingmax"
12292 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
12295 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
12299 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
12303 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
12305 aView->ChangeRenderingParams().CollectedStats =
12306 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
12310 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12312 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12315 TColStd_IndexedDataMapOfStringString aDict;
12316 aView->StatisticInformation (aDict);
12318 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
12320 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12322 Standard_CString anArg(theArgVec[anArgIter]);
12323 TCollection_AsciiString aFlag(anArg);
12325 if (aFlag == "fps")
12327 theDI << searchInfo (aDict, "FPS") << " ";
12329 else if (aFlag == "cpu")
12331 theDI << searchInfo (aDict, "CPU FPS") << " ";
12333 else if (aFlag == "alllayers")
12335 theDI << searchInfo (aDict, "Layers") << " ";
12337 else if (aFlag == "layers")
12339 theDI << searchInfo (aDict, "Rendered layers") << " ";
12341 else if (aFlag == "allstructs")
12343 theDI << searchInfo (aDict, "Structs") << " ";
12345 else if (aFlag == "structs")
12347 theDI << searchInfo (aDict, "Rendered structs") << " ";
12349 else if (aFlag == "groups")
12351 theDI << searchInfo (aDict, "Rendered groups") << " ";
12353 else if (aFlag == "allarrays")
12355 theDI << searchInfo (aDict, "Rendered arrays") << " ";
12357 else if (aFlag == "fillarrays")
12359 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
12361 else if (aFlag == "linearrays")
12363 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
12365 else if (aFlag == "pointarrays")
12367 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
12369 else if (aFlag == "textarrays")
12371 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
12373 else if (aFlag == "triangles")
12375 theDI << searchInfo (aDict, "Rendered triangles") << " ";
12377 else if (aFlag == "points")
12379 theDI << searchInfo (aDict, "Rendered points") << " ";
12381 else if (aFlag == "geommem")
12383 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
12385 else if (aFlag == "texturemem")
12387 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
12389 else if (aFlag == "framemem")
12391 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
12393 else if (aFlag == "elapsedframe")
12395 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
12397 else if (aFlag == "cpuframe_average")
12399 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
12401 else if (aFlag == "cpupicking_average")
12403 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
12405 else if (aFlag == "cpuculling_average")
12407 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
12409 else if (aFlag == "cpudyn_average")
12411 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
12413 else if (aFlag == "cpuframe_max")
12415 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
12417 else if (aFlag == "cpupicking_max")
12419 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
12421 else if (aFlag == "cpuculling_max")
12423 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
12425 else if (aFlag == "cpudyn_max")
12427 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
12435 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12437 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12439 theDI << "Statistic info:\n" << aView->StatisticInformation();
12444 //=======================================================================
12445 //function : VXRotate
12447 //=======================================================================
12448 static Standard_Integer VXRotate (Draw_Interpretor& di,
12449 Standard_Integer argc,
12450 const char ** argv)
12452 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
12453 if (aContext.IsNull())
12455 di << argv[0] << "ERROR : use 'vinit' command before \n";
12461 di << "ERROR : Usage : " << argv[0] << " name angle\n";
12465 TCollection_AsciiString aName (argv[1]);
12466 Standard_Real anAngle = Draw::Atof (argv[2]);
12469 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
12470 Handle(AIS_InteractiveObject) anIObj;
12471 if (!aMap.Find2 (aName, anIObj))
12473 di << "Use 'vdisplay' before\n";
12477 gp_Trsf aTransform;
12478 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
12479 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
12481 aContext->SetLocation (anIObj, aTransform);
12482 aContext->UpdateCurrentViewer();
12486 //===============================================================================================
12487 //class : ViewerTest_AISManipulator
12488 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
12489 //===============================================================================================
12490 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
12492 class ViewerTest_AISManipulator : public AIS_Manipulator
12496 ViewerTest_AISManipulator() : AIS_Manipulator()
12498 GetMapOfAISManipulators().Add (this);
12501 virtual ~ViewerTest_AISManipulator()
12503 GetMapOfAISManipulators().Remove (this);
12506 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
12509 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
12510 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
12512 //===============================================================================================
12513 //function : VManipulator
12515 //===============================================================================================
12516 static int VManipulator (Draw_Interpretor& theDi,
12517 Standard_Integer theArgsNb,
12518 const char** theArgVec)
12520 Handle(V3d_View) aCurrentView = ViewerTest::CurrentView();
12521 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
12522 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
12523 if (aCurrentView.IsNull()
12524 || aViewer.IsNull())
12526 std::cerr << "No active viewer!\n";
12530 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
12531 Standard_Integer anArgIter = 1;
12532 for (; anArgIter < theArgsNb; ++anArgIter)
12534 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
12537 ViewerTest_CmdParser aCmd;
12538 aCmd.SetDescription ("Manages manipulator for interactive objects:");
12539 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
12540 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
12541 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
12542 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
12543 aCmd.AddOption ("view", "... {active | [view name]} - define view in which manipulator will be displayed, 'all' by default");
12544 aCmd.AddOption ("detach", "... - detach manipulator");
12546 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
12547 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
12548 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
12550 aCmd.AddOption ("move", "... x y z - move object");
12551 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
12552 aCmd.AddOption ("scale", "... factor - scale object");
12554 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
12555 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
12556 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
12557 aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform");
12558 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
12559 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
12560 aCmd.AddOption ("parts", "... all axes mode {0|1} - set visual part");
12561 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
12562 aCmd.AddOption ("size", "... size - set size of manipulator");
12563 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
12565 aCmd.Parse (theArgsNb, theArgVec);
12567 if (aCmd.HasOption ("help"))
12569 theDi.PrintHelp (theArgVec[0]);
12573 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
12575 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
12577 if (aName.IsEmpty())
12579 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
12583 // ----------------------------------
12584 // detach existing manipulator object
12585 // ----------------------------------
12587 if (aCmd.HasOption ("detach"))
12589 if (!aMapAIS.IsBound2 (aName))
12591 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
12595 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12596 if (aManipulator.IsNull())
12598 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12602 aManipulator->Detach();
12603 aMapAIS.UnBind2 (aName);
12604 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
12609 // -----------------------------------------------
12610 // find or create manipulator if it does not exist
12611 // -----------------------------------------------
12613 Handle(AIS_Manipulator) aManipulator;
12614 if (!aMapAIS.IsBound2 (aName))
12616 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
12618 aManipulator = new ViewerTest_AISManipulator();
12619 aManipulator->SetModeActivationOnDetection (true);
12620 aMapAIS.Bind (aManipulator, aName);
12624 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12625 if (aManipulator.IsNull())
12627 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12632 // -----------------------------------------
12633 // change properties of manipulator instance
12634 // -----------------------------------------
12636 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
12638 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
12640 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
12642 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
12644 if (aCmd.HasOption ("followRotation", 1, Standard_True))
12646 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
12648 if (aCmd.HasOption("followDragging", 1, Standard_True))
12650 aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging"));
12652 if (aCmd.HasOption ("gap", 1, Standard_True))
12654 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
12656 if (aCmd.HasOption ("part", 3, Standard_True))
12658 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
12659 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
12660 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
12661 if (aMode < 1 || aMode > 4)
12663 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12667 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
12669 if (aCmd.HasOption("parts", 2, Standard_True))
12671 Standard_Integer aMode = aCmd.ArgInt("parts", 0);
12672 Standard_Boolean aOnOff = aCmd.ArgBool("parts", 1);
12673 if (aMode < 1 || aMode > 4)
12675 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12679 aManipulator->SetPart(static_cast<AIS_ManipulatorMode>(aMode), aOnOff);
12681 if (aCmd.HasOption ("pos", 3, Standard_True))
12683 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
12684 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
12685 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
12687 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
12689 if (aCmd.HasOption ("size", 1, Standard_True))
12691 aManipulator->SetSize (aCmd.ArgFloat ("size"));
12693 if (aCmd.HasOption ("zoomable", 1, Standard_True))
12695 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
12697 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
12699 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
12700 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
12704 // ---------------------------------------------------
12705 // attach, detach or access manipulator from an object
12706 // ---------------------------------------------------
12708 if (aCmd.HasOption ("attach"))
12710 // Find an object and attach manipulator to it
12711 if (!aCmd.HasOption ("attach", 1, Standard_True))
12716 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
12717 Handle(AIS_InteractiveObject) anObject;
12718 if (!aMapAIS.Find2 (anObjName, anObject))
12720 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
12724 for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next())
12726 if (anIt.Value()->IsAttached()
12727 && anIt.Value()->Object() == anObject)
12729 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
12734 AIS_Manipulator::OptionsForAttach anOptions;
12735 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
12737 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
12739 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
12741 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
12743 if (aCmd.HasOption ("enableModes", 1, Standard_True))
12745 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
12748 aManipulator->Attach (anObject, anOptions);
12750 // Check view option
12751 if (aCmd.HasOption ("view"))
12753 if (!aCmd.HasOption ("view", 1, Standard_True))
12757 TCollection_AsciiString aViewString (aCmd.Arg ("view", 0).c_str());
12758 Handle(V3d_View) aView;
12759 if (aViewString.IsEqual ("active"))
12761 aView = ViewerTest::CurrentView();
12763 else // Check view name
12765 ViewerTest_Names aViewNames (aViewString);
12766 if (!ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
12768 std::cerr << theArgVec[0] << " error: wrong view name '" << aViewString << "'\n";
12771 aView = ViewerTest_myViews.Find1 (aViewNames.GetViewName());
12772 if (aView.IsNull())
12774 std::cerr << theArgVec[0] << " error: cannot find view with name '" << aViewString << "'\n";
12778 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
12779 anIter (ViewerTest_myViews); anIter.More(); anIter.Next())
12781 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, anIter.Value(), Standard_False);
12783 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, aView, Standard_True);
12787 // --------------------------------------
12788 // apply transformation using manipulator
12789 // --------------------------------------
12791 if (aCmd.HasOption ("startTransform", 2, Standard_True))
12793 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
12795 if (aCmd.HasOption ("transform", 2, Standard_True))
12797 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
12799 if (aCmd.HasOption ("stopTransform"))
12801 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
12803 aManipulator->StopTransform (toApply);
12807 if (aCmd.HasOption ("move", 3, Standard_True))
12809 aT.SetTranslationPart (aCmd.ArgVec ("move"));
12811 if (aCmd.HasOption ("rotate", 7, Standard_True))
12813 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
12815 if (aCmd.HasOption ("scale", 1))
12817 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
12820 if (aT.Form() != gp_Identity)
12822 aManipulator->Transform (aT);
12825 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
12830 //===============================================================================================
12831 //function : VSelectionProperties
12833 //===============================================================================================
12834 static int VSelectionProperties (Draw_Interpretor& theDi,
12835 Standard_Integer theArgsNb,
12836 const char** theArgVec)
12838 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
12841 std::cerr << "No active viewer!\n";
12845 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
12847 // handle obsolete alias
12848 bool toEnable = true;
12851 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
12854 else if (theArgsNb != 2
12855 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
12857 std::cout << "Syntax error: wrong number of parameters.";
12860 if (toEnable != aCtx->ToHilightSelected())
12862 aCtx->ClearDetected();
12863 aCtx->SetToHilightSelected (toEnable);
12868 Standard_Boolean toPrint = theArgsNb == 1;
12869 Standard_Boolean toRedraw = Standard_False;
12870 Standard_Integer anArgIter = 1;
12871 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
12872 if (anArgIter < theArgsNb)
12874 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
12875 anArgFirst.LowerCase();
12877 if (anArgFirst == "dynhighlight"
12878 || anArgFirst == "dynhilight"
12879 || anArgFirst == "dynamichighlight"
12880 || anArgFirst == "dynamichilight")
12882 aType = Prs3d_TypeOfHighlight_Dynamic;
12884 else if (anArgFirst == "localdynhighlight"
12885 || anArgFirst == "localdynhilight"
12886 || anArgFirst == "localdynamichighlight"
12887 || anArgFirst == "localdynamichilight")
12889 aType = Prs3d_TypeOfHighlight_LocalDynamic;
12891 else if (anArgFirst == "selhighlight"
12892 || anArgFirst == "selhilight"
12893 || anArgFirst == "selectedhighlight"
12894 || anArgFirst == "selectedhilight")
12896 aType = Prs3d_TypeOfHighlight_Selected;
12898 else if (anArgFirst == "localselhighlight"
12899 || anArgFirst == "localselhilight"
12900 || anArgFirst == "localselectedhighlight"
12901 || anArgFirst == "localselectedhilight")
12903 aType = Prs3d_TypeOfHighlight_LocalSelected;
12910 for (; anArgIter < theArgsNb; ++anArgIter)
12912 TCollection_AsciiString anArg (theArgVec[anArgIter]);
12914 if (anArg == "-help")
12916 theDi.PrintHelp (theArgVec[0]);
12919 else if (anArg == "-print")
12921 toPrint = Standard_True;
12923 else if (anArg == "-autoactivate")
12925 Standard_Boolean toEnable = Standard_True;
12926 if (anArgIter + 1 < theArgsNb
12927 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12931 aCtx->SetAutoActivateSelection (toEnable);
12933 else if (anArg == "-automatichighlight"
12934 || anArg == "-automatichilight"
12935 || anArg == "-autohighlight"
12936 || anArg == "-autohilight")
12938 Standard_Boolean toEnable = Standard_True;
12939 if (anArgIter + 1 < theArgsNb
12940 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12944 aCtx->ClearSelected (false);
12945 aCtx->ClearDetected();
12946 aCtx->SetAutomaticHilight (toEnable);
12949 else if (anArg == "-highlightselected"
12950 || anArg == "-hilightselected")
12952 Standard_Boolean toEnable = Standard_True;
12953 if (anArgIter + 1 < theArgsNb
12954 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12958 aCtx->ClearDetected();
12959 aCtx->SetToHilightSelected (toEnable);
12962 else if (anArg == "-pickstrategy"
12963 || anArg == "-pickingstrategy")
12965 if (++anArgIter >= theArgsNb)
12967 std::cout << "Syntax error: type of highlighting is undefined\n";
12971 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12972 TCollection_AsciiString aVal (theArgVec[anArgIter]);
12974 if (aVal == "first"
12975 || aVal == "firstaccepted"
12976 || aVal == "firstacceptable")
12978 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12980 else if (aVal == "topmost"
12981 || aVal == "onlyTopmost")
12983 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
12987 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
12991 aCtx->SetPickingStrategy (aStrategy);
12993 else if (anArg == "-pixtol"
12994 && anArgIter + 1 < theArgsNb)
12996 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
12998 else if ((anArg == "-mode"
12999 || anArg == "-dispmode")
13000 && anArgIter + 1 < theArgsNb)
13002 if (aType == Prs3d_TypeOfHighlight_None)
13004 std::cout << "Syntax error: type of highlighting is undefined\n";
13008 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
13009 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13010 aStyle->SetDisplayMode (aDispMode);
13011 toRedraw = Standard_True;
13013 else if (anArg == "-layer"
13014 && anArgIter + 1 < theArgsNb)
13016 if (aType == Prs3d_TypeOfHighlight_None)
13018 std::cout << "Syntax error: type of highlighting is undefined\n";
13023 Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN;
13024 if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer))
13026 std::cerr << "Error: wrong syntax at " << theArgVec[anArgIter] << ".\n";
13030 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13031 aStyle->SetZLayer (aNewLayer);
13032 toRedraw = Standard_True;
13034 else if (anArg == "-hicolor"
13035 || anArg == "-selcolor"
13036 || anArg == "-color")
13038 if (anArg.StartsWith ("-hi"))
13040 aType = Prs3d_TypeOfHighlight_Dynamic;
13042 else if (anArg.StartsWith ("-sel"))
13044 aType = Prs3d_TypeOfHighlight_Selected;
13046 else if (aType == Prs3d_TypeOfHighlight_None)
13048 std::cout << "Syntax error: type of highlighting is undefined\n";
13052 Quantity_Color aColor;
13053 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
13054 theArgVec + anArgIter + 1,
13056 if (aNbParsed == 0)
13058 std::cout << "Syntax error: need more arguments.\n";
13061 anArgIter += aNbParsed;
13063 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13064 aStyle->SetColor (aColor);
13065 toRedraw = Standard_True;
13067 else if ((anArg == "-transp"
13068 || anArg == "-transparency"
13069 || anArg == "-hitransp"
13070 || anArg == "-seltransp"
13071 || anArg == "-hitransplocal"
13072 || anArg == "-seltransplocal")
13073 && anArgIter + 1 < theArgsNb)
13075 if (anArg.StartsWith ("-hi"))
13077 aType = Prs3d_TypeOfHighlight_Dynamic;
13079 else if (anArg.StartsWith ("-sel"))
13081 aType = Prs3d_TypeOfHighlight_Selected;
13083 else if (aType == Prs3d_TypeOfHighlight_None)
13085 std::cout << "Syntax error: type of highlighting is undefined\n";
13089 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
13090 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13091 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
13092 toRedraw = Standard_True;
13094 else if ((anArg == "-mat"
13095 || anArg == "-material")
13096 && anArgIter + 1 < theArgsNb)
13098 if (aType == Prs3d_TypeOfHighlight_None)
13100 std::cout << "Syntax error: type of highlighting is undefined\n";
13104 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13105 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
13106 if (aMatName != Graphic3d_NOM_DEFAULT)
13109 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
13110 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
13111 Graphic3d_MaterialAspect aMat (aMatName);
13112 aMat.SetColor (aStyle->Color());
13113 aMat.SetTransparency (aStyle->Transparency());
13114 anAspect->SetFrontMaterial (aMat);
13115 anAspect->SetInteriorColor (aStyle->Color());
13116 aStyle->SetBasicFillAreaAspect (anAspect);
13120 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
13122 toRedraw = Standard_True;
13126 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
13132 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
13133 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
13134 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
13135 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
13136 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
13137 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
13138 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
13139 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
13140 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
13141 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
13142 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
13143 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
13144 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
13145 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
13148 if (aCtx->NbSelected() != 0 && toRedraw)
13150 aCtx->HilightSelected (Standard_True);
13156 //===============================================================================================
13157 //function : VDumpSelectionImage
13159 //===============================================================================================
13160 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
13161 Standard_Integer theArgsNb,
13162 const char** theArgVec)
13166 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
13170 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13171 if (aContext.IsNull())
13173 std::cout << "Error: no active view.\n";
13177 TCollection_AsciiString aFile;
13178 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13179 Image_Format anImgFormat = Image_Format_BGR;
13180 Standard_Integer aPickedIndex = 1;
13181 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
13183 TCollection_AsciiString aParam (theArgVec[anArgIter]);
13184 aParam.LowerCase();
13185 if (aParam == "-type")
13187 if (++anArgIter >= theArgsNb)
13189 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
13193 TCollection_AsciiString aValue (theArgVec[anArgIter]);
13194 aValue.LowerCase();
13195 if (aValue == "depth"
13196 || aValue == "normdepth"
13197 || aValue == "normalizeddepth")
13199 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13200 anImgFormat = Image_Format_GrayF;
13202 if (aValue == "depthinverted"
13203 || aValue == "normdepthinverted"
13204 || aValue == "normalizeddepthinverted"
13205 || aValue == "inverted")
13207 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
13208 anImgFormat = Image_Format_GrayF;
13210 else if (aValue == "unnormdepth"
13211 || aValue == "unnormalizeddepth")
13213 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
13214 anImgFormat = Image_Format_GrayF;
13216 else if (aValue == "objectcolor"
13217 || aValue == "object"
13218 || aValue == "color")
13220 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
13222 else if (aValue == "entitycolor"
13223 || aValue == "entity")
13225 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
13227 else if (aValue == "ownercolor"
13228 || aValue == "owner")
13230 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
13232 else if (aValue == "selectionmodecolor"
13233 || aValue == "selectionmode"
13234 || aValue == "selmodecolor"
13235 || aValue == "selmode")
13237 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
13240 else if (aParam == "-picked"
13241 || aParam == "-pickeddepth"
13242 || aParam == "-pickedindex")
13244 if (++anArgIter >= theArgsNb)
13246 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
13250 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
13252 else if (aFile.IsEmpty())
13254 aFile = theArgVec[anArgIter];
13258 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
13262 if (aFile.IsEmpty())
13264 std::cout << "Syntax error: image file name is missing.\n";
13268 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13269 Standard_Integer aWidth = 0, aHeight = 0;
13270 aView->Window()->Size (aWidth, aHeight);
13272 Image_AlienPixMap aPixMap;
13273 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
13275 std::cout << "Error: can't allocate image.\n";
13278 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
13280 std::cout << "Error: can't generate selection image.\n";
13283 if (!aPixMap.Save (aFile))
13285 std::cout << "Error: can't save selection image.\n";
13291 //===============================================================================================
13292 //function : VViewCube
13294 //===============================================================================================
13295 static int VViewCube (Draw_Interpretor& ,
13296 Standard_Integer theNbArgs,
13297 const char** theArgVec)
13299 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13300 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13301 if (aContext.IsNull() || aView.IsNull())
13303 std::cout << "Error: no active view.\n";
13306 else if (theNbArgs < 2)
13308 std::cout << "Syntax error: wrong number arguments\n";
13312 Handle(AIS_ViewCube) aViewCube;
13313 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
13314 Quantity_Color aColorRgb;
13315 TCollection_AsciiString aName;
13316 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
13318 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13320 if (anUpdateTool.parseRedrawMode (anArg))
13324 else if (aViewCube.IsNull())
13326 aName = theArgVec[anArgIter];
13327 if (aName.StartsWith ("-"))
13329 std::cout << "Syntax error: object name should be specified.\n";
13332 Handle(AIS_InteractiveObject) aPrs;
13333 GetMapOfAIS().Find2 (aName, aPrs);
13334 aViewCube = Handle(AIS_ViewCube)::DownCast (aPrs);
13335 if (aViewCube.IsNull())
13337 aViewCube = new AIS_ViewCube();
13338 aViewCube->SetBoxColor (Quantity_NOC_GRAY50);
13339 aViewCube->SetViewAnimation (ViewerTest::CurrentEventManager()->ViewAnimation());
13340 aViewCube->SetFixedAnimationLoop (false);
13343 else if (anArg == "-reset")
13345 aViewCube->ResetStyles();
13347 else if (anArg == "-color"
13348 || anArg == "-boxcolor"
13349 || anArg == "-boxsidecolor"
13350 || anArg == "-sidecolor"
13351 || anArg == "-boxedgecolor"
13352 || anArg == "-edgecolor"
13353 || anArg == "-boxcornercolor"
13354 || anArg == "-cornercolor"
13355 || anArg == "-innercolor"
13356 || anArg == "-textcolor")
13358 Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - anArgIter - 1,
13359 theArgVec + anArgIter + 1,
13361 if (aNbParsed == 0)
13363 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
13366 anArgIter += aNbParsed;
13367 if (anArg == "-boxcolor")
13369 aViewCube->SetBoxColor (aColorRgb);
13371 else if (anArg == "-boxsidecolor"
13372 || anArg == "-sidecolor")
13374 aViewCube->BoxSideStyle()->SetColor (aColorRgb);
13375 aViewCube->SynchronizeAspects();
13377 else if (anArg == "-boxedgecolor"
13378 || anArg == "-edgecolor")
13380 aViewCube->BoxEdgeStyle()->SetColor (aColorRgb);
13381 aViewCube->SynchronizeAspects();
13383 else if (anArg == "-boxcornercolor"
13384 || anArg == "-cornercolor")
13386 aViewCube->BoxCornerStyle()->SetColor (aColorRgb);
13387 aViewCube->SynchronizeAspects();
13389 else if (anArg == "-innercolor")
13391 aViewCube->SetInnerColor (aColorRgb);
13393 else if (anArg == "-textcolor")
13395 aViewCube->SetTextColor (aColorRgb);
13399 aViewCube->SetColor (aColorRgb);
13402 else if (anArgIter + 1 < theNbArgs
13403 && (anArg == "-transparency"
13404 || anArg == "-boxtransparency"))
13406 const Standard_Real aValue = Draw::Atof (theArgVec[++anArgIter]);
13407 if (aValue < 0.0 || aValue > 1.0)
13409 std::cout << "Syntax error: invalid transparency value " << theArgVec[anArgIter] << "\n";
13413 if (anArg == "-boxtransparency")
13415 aViewCube->SetBoxTransparency (aValue);
13419 aViewCube->SetTransparency (aValue);
13422 else if (anArg == "-axes"
13423 || anArg == "-edges"
13424 || anArg == "-vertices"
13425 || anArg == "-vertexes"
13426 || anArg == "-fixedanimation")
13428 bool toShow = true;
13429 if (anArgIter + 1 < theNbArgs
13430 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShow))
13434 if (anArg == "-fixedanimation")
13436 aViewCube->SetFixedAnimationLoop (toShow);
13438 else if (anArg == "-axes")
13440 aViewCube->SetDrawAxes (toShow);
13442 else if (anArg == "-edges")
13444 aViewCube->SetDrawEdges (toShow);
13448 aViewCube->SetDrawVertices (toShow);
13451 else if (anArg == "-yup"
13452 || anArg == "-zup")
13455 if (anArgIter + 1 < theNbArgs
13456 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isOn))
13460 if (anArg == "-yup")
13462 aViewCube->SetYup (isOn);
13466 aViewCube->SetYup (!isOn);
13469 else if (anArgIter + 1 < theNbArgs
13470 && anArg == "-font")
13472 aViewCube->SetFont (theArgVec[++anArgIter]);
13474 else if (anArgIter + 1 < theNbArgs
13475 && anArg == "-fontheight")
13477 aViewCube->SetFontHeight (Draw::Atof (theArgVec[++anArgIter]));
13479 else if (anArgIter + 1 < theNbArgs
13480 && (anArg == "-size"
13481 || anArg == "-boxsize"))
13483 aViewCube->SetSize (Draw::Atof (theArgVec[++anArgIter]),
13484 anArg != "-boxsize");
13486 else if (anArgIter + 1 < theNbArgs
13487 && (anArg == "-boxfacet"
13488 || anArg == "-boxfacetextension"
13489 || anArg == "-facetextension"
13490 || anArg == "-extension"))
13492 aViewCube->SetBoxFacetExtension (Draw::Atof (theArgVec[++anArgIter]));
13494 else if (anArgIter + 1 < theNbArgs
13495 && (anArg == "-boxedgegap"
13496 || anArg == "-edgegap"))
13498 aViewCube->SetBoxEdgeGap (Draw::Atof (theArgVec[++anArgIter]));
13500 else if (anArgIter + 1 < theNbArgs
13501 && (anArg == "-boxedgeminsize"
13502 || anArg == "-edgeminsize"))
13504 aViewCube->SetBoxEdgeMinSize (Draw::Atof (theArgVec[++anArgIter]));
13506 else if (anArgIter + 1 < theNbArgs
13507 && (anArg == "-boxcornerminsize"
13508 || anArg == "-cornerminsize"))
13510 aViewCube->SetBoxCornerMinSize (Draw::Atof (theArgVec[++anArgIter]));
13512 else if (anArgIter + 1 < theNbArgs
13513 && anArg == "-axespadding")
13515 aViewCube->SetAxesPadding (Draw::Atof (theArgVec[++anArgIter]));
13517 else if (anArgIter + 1 < theNbArgs
13518 && anArg == "-roundradius")
13520 aViewCube->SetRoundRadius (Draw::Atof (theArgVec[++anArgIter]));
13522 else if (anArgIter + 1 < theNbArgs
13523 && anArg == "-duration")
13525 aViewCube->SetDuration (Draw::Atof (theArgVec[++anArgIter]));
13529 std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
13533 if (aViewCube.IsNull())
13535 std::cout << "Syntax error: wrong number of arguments\n";
13539 ViewerTest::Display (aName, aViewCube, false);
13543 //=======================================================================
13544 //function : ViewerCommands
13546 //=======================================================================
13548 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
13551 const char *group = "ZeViewer";
13552 theCommands.Add("vinit",
13553 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
13554 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
13555 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13556 "\n\t\t: [-display displayName]"
13558 "\n\t\t: Creates new View window with specified name viewName."
13559 "\n\t\t: By default the new view is created in the viewer and in"
13560 "\n\t\t: graphic driver shared with active view."
13561 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
13562 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
13563 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
13564 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13565 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
13566 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
13568 "\n\t\t: -left, -top pixel position of left top corner of the window."
13569 "\n\t\t: -width, -height width and heigth of window respectively."
13570 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
13571 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
13572 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
13573 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
13574 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
13575 __FILE__,VInit,group);
13576 theCommands.Add("vclose" ,
13577 "[view_id [keep_context=0|1]]\n"
13578 "or vclose ALL - to remove all created views\n"
13579 " - removes view(viewer window) defined by its view_id.\n"
13580 " - keep_context: by default 0; if 1 and the last view is deleted"
13581 " the current context is not removed.",
13582 __FILE__,VClose,group);
13583 theCommands.Add("vactivate" ,
13584 "vactivate view_id [-noUpdate]"
13585 " - activates view(viewer window) defined by its view_id",
13586 __FILE__,VActivate,group);
13587 theCommands.Add("vviewlist",
13588 "vviewlist [format={tree, long}]"
13589 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
13590 " - format: format of result output, if tree the output is a tree view;"
13591 "otherwise it's a list of full view names. By default format = tree",
13592 __FILE__,VViewList,group);
13593 theCommands.Add("vhelp" ,
13594 "vhelp : display help on the viewer commands",
13595 __FILE__,VHelp,group);
13596 theCommands.Add("vviewproj",
13597 "vviewproj [top|bottom|left|right|front|back|axoLeft|axoRight]"
13598 "\n\t\t: [+-X+-Y+-Z] [-Zup|-Yup] [-frame +-X+-Y]"
13599 "\n\t\t: Setup view direction"
13600 "\n\t\t: -Yup use Y-up convention instead of Zup (which is default)."
13601 "\n\t\t: +-X+-Y+-Z define direction as combination of DX, DY and DZ;"
13602 "\n\t\t: for example '+Z' will show front of the model,"
13603 "\n\t\t: '-X-Y+Z' will define left axonometrical view."
13604 "\n\t\t: -frame define camera Up and Right directions (regardless Up convention);"
13605 "\n\t\t: for example '+X+Z' will show front of the model with Z-up."
13606 __FILE__,VViewProj,group);
13607 theCommands.Add("vtop" ,
13608 "vtop or <T> : Top view. Orientation +X+Y" ,
13609 __FILE__,VViewProj,group);
13610 theCommands.Add("vbottom" ,
13611 "vbottom : Bottom view. Orientation +X-Y" ,
13612 __FILE__,VViewProj,group);
13613 theCommands.Add("vleft" ,
13614 "vleft : Left view. Orientation -Y+Z" ,
13615 __FILE__,VViewProj,group);
13616 theCommands.Add("vright" ,
13617 "vright : Right view. Orientation +Y+Z" ,
13618 __FILE__,VViewProj,group);
13619 theCommands.Add("vaxo" ,
13620 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
13621 __FILE__,VViewProj,group);
13622 theCommands.Add("vfront" ,
13623 "vfront : Front view. Orientation +X+Z" ,
13624 __FILE__,VViewProj,group);
13625 theCommands.Add("vback" ,
13626 "vback : Back view. Orientation -X+Z" ,
13627 __FILE__,VViewProj,group);
13628 theCommands.Add("vpick" ,
13629 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
13631 theCommands.Add("vfit",
13632 "vfit or <F> [-selected] [-noupdate]"
13633 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
13634 __FILE__,VFit,group);
13635 theCommands.Add ("vfitarea",
13636 "vfitarea x1 y1 x2 y2"
13637 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
13638 "\n\t\t: Fit view to show area located between two points"
13639 "\n\t\t: given in world 2D or 3D corrdinates.",
13640 __FILE__, VFitArea, group);
13641 theCommands.Add ("vzfit", "vzfit [scale]\n"
13642 " Matches Z near, Z far view volume planes to the displayed objects.\n"
13643 " \"scale\" - specifies factor to scale computed z range.\n",
13644 __FILE__, VZFit, group);
13645 theCommands.Add("vrepaint",
13646 "vrepaint [-immediate] [-continuous FPS]"
13647 "\n\t\t: force redraw of active View"
13648 "\n\t\t: -immediate flag performs redraw of immediate layers only;"
13649 "\n\t\t: -continuous activates/deactivates continuous redraw of active View,"
13650 "\n\t\t: 0 means no continuous rendering,"
13651 "\n\t\t: -1 means non-stop redraws,"
13652 "\n\t\t: >0 specifies target framerate,",
13653 __FILE__,VRepaint,group);
13654 theCommands.Add("vclear",
13656 "\n\t\t: remove all the object from the viewer",
13657 __FILE__,VClear,group);
13660 "Changes background or some background settings.\n"
13663 " vbackground -imageFile ImageFile [-imageMode FillType]\n"
13664 " vbackground -imageMode FillType\n"
13665 " vbackground -gradient Color1 Color2 [-gradientMode FillMethod]\n"
13666 " vbackground -gradientMode FillMethod\n"
13667 " vbackground -cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]\n"
13668 " vbackground -color Color\n"
13669 " vbackground -default -gradient Color1 Color2 [-gradientMode FillType]\n"
13670 " vbackground -default -color Color\n"
13671 " vbackground -help\n"
13674 " -imageFile (-imgFile, -image, -img): sets filename of image used as background\n"
13675 " -imageMode (-imgMode, -imageMd, -imgMd): sets image fill type\n"
13676 " -gradient (-grad, -gr): sets background gradient starting and ending colors\n"
13677 " -gradientMode (-gradMode, -gradMd, -grMode, -grMd): sets gradient fill method\n"
13678 " -cubemap (-cmap, -cm): sets environmet cubemap as background\n"
13679 " -invertedz (-invz, -iz): sets inversion of Z axis for background cubemap rendering\n"
13680 " -order (-o): defines order of tiles in one image cubemap\n"
13681 " (has no effect in case of multi image cubemaps)\n"
13682 " -color (-col): sets background color\n"
13683 " -default (-def): sets background default gradient or color\n"
13684 " -help (-h): outputs short help message\n"
13687 " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n"
13688 " or reals within the range [0.0, 1.0]\n"
13689 " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n"
13690 " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n"
13691 " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, "
13693 " FillType: one of CENTERED, TILED, STRETCH, NONE\n"
13694 " ImageFile: a name of the file with the image used as a background\n"
13695 " CubemapFilei: a name of the file with one image packed cubemap or names of separate files with every cubemap side\n"
13696 " TileIndexi: a cubemap side index in range [0, 5] for i tile of one image packed cubemap\n",
13700 theCommands.Add ("vsetbg",
13701 "Loads image as background."
13702 "\n\t\t: vsetbg ImageFile [FillType]"
13703 "\n\t\t: vsetbg -imageFile ImageFile [-imageMode FillType]"
13704 "\n\t\t: Alias for 'vbackground -imageFile ImageFile [-imageMode FillType]'.",
13708 theCommands.Add ("vsetbgmode",
13709 "Changes background image fill type."
13710 "\n\t\t: vsetbgmode [-imageMode] FillType"
13711 "\n\t\t: Alias for 'vbackground -imageMode FillType'.",
13715 theCommands.Add ("vsetgradientbg",
13716 "Mounts gradient background."
13717 "\n\t\t: vsetgradientbg Color1 Color2 [FillMethod]"
13718 "\n\t\t: vsetgradientbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13719 "\n\t\t: Alias for 'vbackground -gradient Color1 Color2 -gradientMode FillMethod'.",
13723 theCommands.Add ("vsetgrbgmode",
13724 "Changes gradient background fill method."
13725 "\n\t\t: vsetgrbgmode [-gradientMode] FillMethod"
13726 "\n\t\t: Alias for 'vbackground -gradientMode FillMethod'.",
13730 theCommands.Add ("vsetcolorbg",
13731 "Sets background color."
13732 "\n\t\t: vsetcolorbg [-color] Color."
13733 "\n\t\t: Alias for 'vbackground -color Color'.",
13737 theCommands.Add ("vsetdefaultbg",
13738 "Sets default viewer background fill color (flat/gradient)."
13739 "\n\t\t: vsetdefaultbg Color1 Color2 [FillMethod]"
13740 "\n\t\t: vsetdefaultbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13741 "\n\t\t: Alias for 'vbackground -default -gradient Color1 Color2 [-gradientMode FillMethod]'."
13742 "\n\t\t: vsetdefaultbg [-color] Color"
13743 "\n\t\t: Alias for 'vbackground -default -color Color'.",
13747 theCommands.Add("vscale",
13748 "vscale : vscale X Y Z",
13749 __FILE__,VScale,group);
13750 theCommands.Add("vzbufftrihedron",
13751 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
13752 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
13753 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
13754 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
13755 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
13756 "\n\t\t: Displays a trihedron",
13757 __FILE__,VZBuffTrihedron,group);
13758 theCommands.Add("vrotate",
13759 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
13760 "\n : Option -mouseStart starts rotation according to the mouse position"
13761 "\n : Option -mouseMove continues rotation with angle computed"
13762 "\n : from last and new mouse position."
13763 "\n : vrotate AX AY AZ [X Y Z]",
13764 __FILE__,VRotate,group);
13765 theCommands.Add("vzoom",
13766 "vzoom : vzoom coef",
13767 __FILE__,VZoom,group);
13768 theCommands.Add("vpan",
13769 "vpan : vpan dx dy",
13770 __FILE__,VPan,group);
13771 theCommands.Add("vcolorscale",
13772 "vcolorscale name [-noupdate|-update] [-demo]"
13773 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
13774 "\n\t\t: [-font HeightFont=20]"
13775 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
13776 "\n\t\t: [-smoothTransition {on|off}=off]"
13777 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
13778 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
13779 "\n\t\t: [-textpos {left|right|center|none}=right]"
13780 "\n\t\t: [-labelAtBorder {on|off}=on]"
13781 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
13782 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
13783 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
13784 "\n\t\t: [-xy Left=0 Bottom=0]"
13785 "\n\t\t: -demo - displays a color scale with demonstratio values"
13786 "\n\t\t: -colors - set colors for all intervals"
13787 "\n\t\t: -color - set color for specific interval"
13788 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
13789 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
13790 "\n\t\t: at border means the value inbetween neighbor intervals,"
13791 "\n\t\t: at center means the center value within current interval"
13792 "\n\t\t: -labels - set labels for all intervals"
13793 "\n\t\t: -freeLabels - same as -labels but does not require"
13794 "\n\t\t: matching the number of intervals"
13795 "\n\t\t: -label - set label for specific interval"
13796 "\n\t\t: -title - set title"
13797 "\n\t\t: -reversed - setup smooth color transition between intervals"
13798 "\n\t\t: -smoothTransition - swap colorscale direction"
13799 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
13800 __FILE__, VColorScale, group);
13801 theCommands.Add("vgraduatedtrihedron",
13802 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
13803 "\t[-namefont Name] [-valuesfont Name]\n"
13804 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
13805 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
13806 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
13807 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
13808 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
13809 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
13810 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
13811 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
13812 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
13813 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
13814 " - Displays or erases graduated trihedron"
13815 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
13816 " - namefont - font of axes names. Default: Arial\n"
13817 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
13818 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
13819 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
13820 " - valuesfont - font of axes values. Default: Arial\n"
13821 " - xcolor, ycolor, zcolor - color of axis and values\n"
13822 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
13823 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
13824 __FILE__,VGraduatedTrihedron,group);
13825 theCommands.Add("vtile" ,
13826 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
13827 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
13828 "\n\t\t: -totalSize the size of virtual bigger viewport"
13829 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
13830 "\n\t\t: -lowerLeft tile offset as lower left corner"
13831 "\n\t\t: -upperLeft tile offset as upper left corner",
13832 __FILE__, VTile, group);
13833 theCommands.Add("vzlayer",
13834 "vzlayer [layerId]"
13835 "\n\t\t: [-add|-delete|-get|-settings] [-insertBefore AnotherLayer] [-insertAfter AnotherLayer]"
13836 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
13837 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
13838 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv|rayTracing}]"
13839 "\n\t\t: ZLayer list management:"
13840 "\n\t\t: -add add new z layer to viewer and print its id"
13841 "\n\t\t: -insertBefore add new z layer and insert it before existing one"
13842 "\n\t\t: -insertAfter add new z layer and insert it after existing one"
13843 "\n\t\t: -delete delete z layer"
13844 "\n\t\t: -get print sequence of z layers"
13845 "\n\t\t: -settings print status of z layer settings"
13846 "\n\t\t: -disable disables given setting"
13847 "\n\t\t: -enable enables given setting",
13848 __FILE__,VZLayer,group);
13849 theCommands.Add("vlayerline",
13850 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
13851 __FILE__,VLayerLine,group);
13852 theCommands.Add("vgrid",
13853 "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]"
13854 "\n\t\t: [-step X Y] [-size DX DY]"
13855 "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]",
13856 __FILE__, VGrid, group);
13857 theCommands.Add ("vpriviledgedplane",
13858 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
13859 "\n\t\t: Ox, Oy, Oz - plane origin"
13860 "\n\t\t: Nx, Ny, Nz - plane normal direction"
13861 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
13862 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
13863 __FILE__, VPriviledgedPlane, group);
13864 theCommands.Add ("vconvert",
13865 "vconvert v [Mode={window|view}]"
13866 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
13867 "\n\t\t: vconvert x y z [Mode={window|grid}]"
13868 "\n\t\t: window - convert to window coordinates, pixels"
13869 "\n\t\t: view - convert to view projection plane"
13870 "\n\t\t: grid - convert to model coordinates, given on grid"
13871 "\n\t\t: ray - convert projection ray to model coordiantes"
13872 "\n\t\t: - vconvert v window : convert view to window;"
13873 "\n\t\t: - vconvert v view : convert window to view;"
13874 "\n\t\t: - vconvert x y window : convert view to window;"
13875 "\n\t\t: - vconvert x y view : convert window to view;"
13876 "\n\t\t: - vconvert x y : convert window to model;"
13877 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
13878 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
13879 "\n\t\t: - vconvert x y z window : convert model to window;"
13880 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
13881 "\n\t\t: Converts the given coordinates to window/view/model space.",
13882 __FILE__, VConvert, group);
13883 theCommands.Add ("vfps",
13884 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
13885 __FILE__, VFps, group);
13886 theCommands.Add ("vgldebug",
13887 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
13888 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
13889 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
13890 "\n\t\t: Debug context can be requested only on Windows"
13891 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
13892 "\n\t\t: -sync - request synchronized debug GL context"
13893 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
13894 "\n\t\t: which are suppressed by default,"
13895 "\n\t\t: -glslCode - log GLSL program source code,"
13896 "\n\t\t: which are suppressed by default,"
13897 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
13898 "\n\t\t: which are suppressed by default",
13899 __FILE__, VGlDebug, group);
13900 theCommands.Add ("vvbo",
13901 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
13902 __FILE__, VVbo, group);
13903 theCommands.Add ("vstereo",
13904 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
13905 "\n\t\t: [-anaglyph Filter]"
13906 "\n\t\t: Control stereo output mode. Available modes for -mode:"
13907 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
13908 "\n\t\t: requires driver support."
13909 "\n\t\t: Should be called BEFORE vinit!"
13910 "\n\t\t: anaglyph - Anaglyph glasses"
13911 "\n\t\t: rowInterlaced - row-interlaced display"
13912 "\n\t\t: columnInterlaced - column-interlaced display"
13913 "\n\t\t: chessBoard - chess-board output"
13914 "\n\t\t: sideBySide - horizontal pair"
13915 "\n\t\t: overUnder - vertical pair"
13916 "\n\t\t: Available Anaglyph filters for -anaglyph:"
13917 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
13918 "\n\t\t: greenMagentaSimple",
13919 __FILE__, VStereo, group);
13920 theCommands.Add ("vcaps",
13921 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
13922 "\n\t\t: [-compatibleProfile {0|1}]"
13923 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
13924 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
13925 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
13926 "\n\t\t: [-noExtensions {0|1}] [-maxVersion Major Minor]"
13927 "\n\t\t: Modify particular graphic driver options:"
13928 "\n\t\t: FFP - use fixed-function pipeline instead of"
13929 "\n\t\t: built-in GLSL programs"
13930 "\n\t\t: (requires compatible profile)"
13931 "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs"
13932 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
13933 "\n\t\t: arrays to GPU memory)"
13934 "\n\t\t: sprite - use textured sprites instead of bitmaps"
13935 "\n\t\t: vsync - switch VSync on or off"
13936 "\n\t\t: winBuffer - allow using window buffer for rendering"
13937 "\n\t\t: Context creation options:"
13938 "\n\t\t: softMode - software OpenGL implementation"
13939 "\n\t\t: compatibleProfile - backward-compatible profile"
13940 "\n\t\t: quadbuffer - QuadBuffer"
13941 "\n\t\t: noExtensions - disallow usage of extensions"
13942 "\n\t\t: maxVersion - force upper OpenGL version to be used"
13943 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
13944 "\n\t\t: rendering paths producing the same visual result when"
13945 "\n\t\t: possible."
13946 "\n\t\t: Command is intended for testing old hardware compatibility.",
13947 __FILE__, VCaps, group);
13948 theCommands.Add ("vmemgpu",
13949 "vmemgpu [f]: print system-dependent GPU memory information if available;"
13950 " with f option returns free memory in bytes",
13951 __FILE__, VMemGpu, group);
13952 theCommands.Add ("vreadpixel",
13953 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [-name]"
13954 " : Read pixel value for active view",
13955 __FILE__, VReadPixel, group);
13956 theCommands.Add("diffimage",
13957 "diffimage imageFile1 imageFile2 [diffImageFile]"
13958 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
13959 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
13960 "\n\t\t: Compare two images by content and generate difference image."
13961 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
13962 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
13963 __FILE__, VDiffImage, group);
13964 theCommands.Add ("vselect",
13965 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
13966 "- emulates different types of selection:\n"
13967 "- 1) single click selection\n"
13968 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
13969 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
13970 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
13971 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
13972 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
13973 " (partial inclusion - overlap - is not allowed by default)\n"
13974 "- 5) any of these selections with shift button pressed",
13975 __FILE__, VSelect, group);
13976 theCommands.Add ("vmoveto",
13977 "vmoveto [x y] [-reset]"
13978 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
13979 "\n\t\t: -reset resets current highlighting",
13980 __FILE__, VMoveTo, group);
13981 theCommands.Add ("vviewparams",
13982 "vviewparams [-args] [-scale [s]]"
13983 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
13984 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
13985 "\n\t\t: Manage current view parameters or prints all"
13986 "\n\t\t: current values when called without argument."
13987 "\n\t\t: -scale [s] prints or sets viewport relative scale"
13988 "\n\t\t: -eye [x y z] prints or sets eye location"
13989 "\n\t\t: -at [x y z] prints or sets center of look"
13990 "\n\t\t: -up [x y z] prints or sets direction of up vector"
13991 "\n\t\t: -proj [x y z] prints or sets direction of look"
13992 "\n\t\t: -center x y sets location of center of the screen in pixels"
13993 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
13994 "\n\t\t: or changes the size of its maximum dimension"
13995 "\n\t\t: -args prints vviewparams arguments for restoring current view",
13996 __FILE__, VViewParams, group);
13998 theCommands.Add("v2dmode",
13999 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
14000 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
14001 "\n\t\t: mode - switches On/Off rotation mode"
14002 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
14003 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
14004 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
14005 "\n\t\t: View camera position might be changed only by commands.",
14006 __FILE__, V2DMode, group);
14008 theCommands.Add("vanimation", "Alias for vanim",
14009 __FILE__, VAnimation, group);
14011 theCommands.Add("vanim",
14012 "List existing animations:"
14014 "\n\t\t: Animation playback:"
14015 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
14016 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
14017 "\n\t\t: -speed playback speed (1.0 is normal speed)"
14018 "\n\t\t: -freeLook skip camera animations"
14019 "\n\t\t: -lockLoop disable any interactions"
14021 "\n\t\t: Animation definition:"
14022 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
14023 "\n\t\t: [start TimeSec] [duration TimeSec]"
14025 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
14026 "\n\t\t: specifies nested animations."
14027 "\n\t\t: There is no syntax to explicitly add new animation,"
14028 "\n\t\t: and all non-existing animations within the name will be"
14029 "\n\t\t: implicitly created on first use (including parents)."
14031 "\n\t\t: Each animation might define the SINGLE action (see below),"
14032 "\n\t\t: like camera transition, object transformation or custom callback."
14033 "\n\t\t: Child animations can be used for defining concurrent actions."
14035 "\n\t\t: Camera animation:"
14036 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
14037 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
14038 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
14039 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
14040 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
14041 "\n\t\t: -atX camera Center positions pair"
14042 "\n\t\t: -upX camera Up directions pair"
14043 "\n\t\t: -scaleX camera Scale factors pair"
14044 "\n\t\t: Object animation:"
14045 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
14046 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
14047 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
14048 "\n\t\t: -locX object Location points pair (translation)"
14049 "\n\t\t: -rotX object Orientations pair (quaternions)"
14050 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
14051 "\n\t\t: Custom callback:"
14052 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
14053 "\n\t\t: %Pts overall animation presentation timestamp"
14054 "\n\t\t: %LocalPts local animation timestamp"
14055 "\n\t\t: %Normalized local animation normalized value in range 0..1"
14057 "\n\t\t: Video recording:"
14058 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
14059 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
14060 "\n\t\t: [-crf Value] [-preset Preset]"
14061 "\n\t\t: -fps video framerate"
14062 "\n\t\t: -format file format, container (matroska, etc.)"
14063 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
14064 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
14065 "\n\t\t: -crf constant rate factor (specific to codec)"
14066 "\n\t\t: -preset codec parameters preset (specific to codec)"
14067 __FILE__, VAnimation, group);
14069 theCommands.Add("vchangeselected",
14070 "vchangeselected shape"
14071 "- adds to shape to selection or remove one from it",
14072 __FILE__, VChangeSelected, group);
14073 theCommands.Add ("vnbselected",
14075 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
14076 theCommands.Add ("vcamera",
14077 "vcamera [PrsName] [-ortho] [-projtype]"
14079 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
14080 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
14081 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
14082 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
14083 "\n\t\t: Manages camera parameters."
14084 "\n\t\t: Displays frustum when presntation name PrsName is specified."
14085 "\n\t\t: Prints current value when option called without argument."
14086 "\n\t\t: Orthographic camera:"
14087 "\n\t\t: -ortho activate orthographic projection"
14088 "\n\t\t: Perspective camera:"
14089 "\n\t\t: -persp activate perspective projection (mono)"
14090 "\n\t\t: -fovy field of view in y axis, in degrees"
14091 "\n\t\t: -distance distance of eye from camera center"
14092 "\n\t\t: Stereoscopic camera:"
14093 "\n\t\t: -stereo perspective projection (stereo)"
14094 "\n\t\t: -leftEye perspective projection (left eye)"
14095 "\n\t\t: -rightEye perspective projection (right eye)"
14096 "\n\t\t: -iod intraocular distance value"
14097 "\n\t\t: -iodType distance type, absolute or relative"
14098 "\n\t\t: -zfocus stereographic focus value"
14099 "\n\t\t: -zfocusType focus type, absolute or relative",
14100 __FILE__, VCamera, group);
14101 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
14102 "- vautozfit [on={1|0}] [scale]\n"
14103 " Prints or changes parameters of automatic z-fit mode:\n"
14104 " \"on\" - turns automatic z-fit on or off\n"
14105 " \"scale\" - specifies factor to scale computed z range.\n",
14106 __FILE__, VAutoZFit, group);
14107 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
14108 " vzrange - without parameters shows current values\n"
14109 " vzrange [znear] [zfar] - applies provided values to view",
14110 __FILE__,VZRange, group);
14111 theCommands.Add ("vpurgedisplay",
14113 "- removes structures which don't belong to objects displayed in neutral point",
14114 __FILE__, VPurgeDisplay, group);
14115 theCommands.Add("vsetviewsize",
14116 "vsetviewsize size",
14117 __FILE__,VSetViewSize,group);
14118 theCommands.Add("vmoveview",
14119 "vmoveview Dx Dy Dz [Start = 1|0]",
14120 __FILE__,VMoveView,group);
14121 theCommands.Add("vtranslateview",
14122 "vtranslateview Dx Dy Dz [Start = 1|0)]",
14123 __FILE__,VTranslateView,group);
14124 theCommands.Add("vturnview",
14125 "vturnview Ax Ay Az [Start = 1|0]",
14126 __FILE__,VTurnView,group);
14127 theCommands.Add("vtextureenv",
14128 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
14129 "or user-defined file and optionally applying texture mapping parameters\n"
14131 " vtextureenv off - disables environment mapping\n"
14132 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
14133 " std_texture = (0..7)\n"
14134 " rep = {clamp|repeat}\n"
14135 " mod = {decal|modulate}\n"
14136 " flt = {nearest|bilinear|trilinear}\n"
14137 " ss, st - scale factors for s and t texture coordinates\n"
14138 " ts, tt - translation for s and t texture coordinates\n"
14139 " rot - texture rotation angle in degrees",
14140 __FILE__, VTextureEnv, group);
14141 theCommands.Add("vhlr",
14142 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
14143 "\n\t\t: Hidden Line Removal algorithm."
14144 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
14145 "\n\t\t: -algoType type of HLR algorithm.\n",
14146 __FILE__,VHLR,group);
14147 theCommands.Add("vhlrtype",
14148 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
14149 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
14150 "\n\t\t: 'algo' - exact HLR algorithm is applied"
14151 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
14152 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
14153 __FILE__,VHLRType,group);
14154 theCommands.Add("vclipplane",
14155 "vclipplane planeName [{0|1}]"
14156 "\n\t\t: [-equation1 A B C D]"
14157 "\n\t\t: [-equation2 A B C D]"
14158 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
14159 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
14160 "\n\t\t: [-maxPlanes]"
14161 "\n\t\t: [-capping {0|1}]"
14162 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
14163 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
14164 "\n\t\t: [-texRotate Angle]"
14165 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
14166 "\n\t\t: [-useObjShader {0|1}]"
14167 "\n\t\t: Clipping planes management:"
14168 "\n\t\t: -maxPlanes print plane limit for view"
14169 "\n\t\t: -delete delete plane with given name"
14170 "\n\t\t: {off|on|0|1} turn clipping on/off"
14171 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
14172 "\n\t\t: applied to active View when list is omitted"
14173 "\n\t\t: -equation A B C D change plane equation"
14174 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
14175 "\n\t\t: Capping options:"
14176 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
14177 "\n\t\t: -color R G B set capping color"
14178 "\n\t\t: -transparency Value set capping transparency 0..1"
14179 "\n\t\t: -texName Texture set capping texture"
14180 "\n\t\t: -texScale SX SY set capping tex scale"
14181 "\n\t\t: -texOrigin TX TY set capping tex origin"
14182 "\n\t\t: -texRotate Angle set capping tex rotation"
14183 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
14184 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
14185 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
14186 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
14187 __FILE__, VClipPlane, group);
14188 theCommands.Add("vdefaults",
14189 "vdefaults [-absDefl value]"
14190 "\n\t\t: [-devCoeff value]"
14191 "\n\t\t: [-angDefl value]"
14192 "\n\t\t: [-autoTriang {off/on | 0/1}]"
14193 , __FILE__, VDefaults, group);
14194 theCommands.Add("vlight",
14195 "tool to manage light sources, without arguments shows list of lights."
14196 "\n Main commands: "
14197 "\n '-clear' to clear lights"
14198 "\n '-{def}aults' to load deafault lights"
14199 "\n '-add' <type> to add any light source"
14200 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
14201 "\n 'change' <lightId> to edit light source with specified lightId"
14202 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
14204 "\n -{pos}ition X Y Z"
14205 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
14206 "\n -color colorName"
14207 "\n -{head}light 0|1"
14208 "\n -{sm}oothness value"
14209 "\n -{int}ensity value"
14210 "\n -{constAtten}uation value"
14211 "\n -{linearAtten}uation value"
14212 "\n -angle angleDeg"
14213 "\n -{spotexp}onent value"
14214 "\n -local|-global"
14215 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
14216 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
14217 __FILE__, VLight, group);
14218 theCommands.Add("vraytrace",
14220 "\n\t\t: Turns on/off ray-tracing renderer."
14221 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
14222 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
14223 __FILE__, VRenderParams, group);
14224 theCommands.Add("vrenderparams",
14225 "\n Manages rendering parameters: "
14226 "\n '-raster' Disables GPU ray-tracing"
14227 "\n '-msaa 0..4' Specifies number of samples for MSAA"
14228 "\n '-lineFeather > 0' Sets line feather factor"
14229 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
14230 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
14231 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
14232 "\n '-rendScale value Rendering resolution scale factor"
14233 "\n '-rayTrace' Enables GPU ray-tracing"
14234 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
14235 "\n '-shadows on|off' Enables/disables shadows rendering"
14236 "\n '-reflections on|off' Enables/disables specular reflections"
14237 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
14238 "\n '-gleam on|off' Enables/disables transparency shadow effects"
14239 "\n '-gi on|off' Enables/disables global illumination effects"
14240 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
14241 "\n '-env on|off' Enables/disables environment map background"
14242 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
14243 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
14244 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
14245 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
14246 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
14247 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
14248 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
14249 "\n '-shadingModel model' Controls shading model from enumeration"
14250 "\n color, flat, gouraud, phong"
14251 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
14252 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
14253 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
14254 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
14255 "\n '-whitepoint value' White point value for filmic tone mapping"
14256 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
14257 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points"
14258 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
14259 "\n Show/hide performance counters (flags can be combined)"
14260 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
14261 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
14262 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
14263 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
14264 "\n set state to check structures culled previously."
14265 "\n Unlike vcaps, these parameters dramatically change visual properties."
14266 "\n Command is intended to control presentation quality depending on"
14267 "\n hardware capabilities and performance.",
14268 __FILE__, VRenderParams, group);
14269 theCommands.Add("vstatprofiler",
14270 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
14271 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
14272 "\n |triagles|points|geomMem|textureMem|frameMem"
14273 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
14274 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
14276 "\n\t\t: Prints rendering statistics."
14277 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
14278 "\n\t\t: else - print all performance counters set previously."
14279 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
14280 __FILE__, VStatProfiler, group);
14281 theCommands.Add ("vplace",
14283 "\n\t\t: Places the point (in pixels) at the center of the window",
14284 __FILE__, VPlace, group);
14285 theCommands.Add("vxrotate",
14287 __FILE__,VXRotate,group);
14289 theCommands.Add("vmanipulator",
14290 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
14291 "\n tool to create and manage AIS manipulators."
14293 "\n '-attach AISObject' attach manipulator to AISObject"
14294 "\n '-adjustPosition {0|1}' adjust position when attaching"
14295 "\n '-adjustSize {0|1}' adjust size when attaching"
14296 "\n '-enableModes {0|1}' enable modes when attaching"
14297 "\n '-view {active | [name of view]}' display manipulator only in defined view,"
14298 "\n by default it is displayed in all views of the current viewer"
14299 "\n '-detach' detach manipulator"
14300 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
14301 "\n '-transform mouse_x mouse_y' - invoke transformation"
14302 "\n '-stopTransform [abort]' - invoke stop of transformation"
14303 "\n '-move x y z' - move attached object"
14304 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
14305 "\n '-scale factor' - scale attached object"
14306 "\n '-autoActivate {0|1}' - set activation on detection"
14307 "\n '-followTranslation {0|1}' - set following translation transform"
14308 "\n '-followRotation {0|1}' - set following rotation transform"
14309 "\n '-followDragging {0|1}' - set following dragging transform"
14310 "\n '-gap value' - set gap between sub-parts"
14311 "\n '-part axis mode {0|1}' - set visual part"
14312 "\n '-parts axis mode {0|1}' - set visual part"
14313 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
14314 "\n '-size value' - set size of manipulator"
14315 "\n '-zoomable {0|1}' - set zoom persistence",
14316 __FILE__, VManipulator, group);
14318 theCommands.Add("vselprops",
14319 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
14320 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
14321 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
14322 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
14323 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
14324 "\n -pickStrategy {first|topmost} : defines picking strategy"
14325 "\n 'first' to pick first acceptable (default)"
14326 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
14327 "\n -pixTol value : sets up pixel tolerance"
14328 "\n -dispMode dispMode : sets display mode for highlighting"
14329 "\n -layer ZLayer : sets ZLayer for highlighting"
14330 "\n -color {name|r g b} : sets highlight color"
14331 "\n -transp value : sets transparency coefficient for highlight"
14332 "\n -material material : sets highlight material"
14333 "\n -print : prints current state of all mentioned parameters",
14334 __FILE__, VSelectionProperties, group);
14335 theCommands.Add ("vhighlightselected",
14336 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
14337 __FILE__, VSelectionProperties, group);
14339 theCommands.Add ("vseldump",
14340 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
14341 "\n\t\t: Generate an image based on detection results:"
14342 "\n\t\t: depth normalized depth values"
14343 "\n\t\t: unnormDepth unnormalized depth values"
14344 "\n\t\t: object color of detected object"
14345 "\n\t\t: owner color of detected owner"
14346 "\n\t\t: selMode color of selection mode"
14347 "\n\t\t: entity color of etected entity",
14348 __FILE__, VDumpSelectionImage, group);
14350 theCommands.Add ("vviewcube",
14352 "\n\t\t: Displays interactive view manipualtion object."
14353 "\n\t\t: Options: "
14354 "\n\t\t: -reset reset geomertical and visual attributes'"
14355 "\n\t\t: -size Size adapted size of View Cube"
14356 "\n\t\t: -boxSize Size box size"
14357 "\n\t\t: -axes {0|1 } show/hide axes (trihedron)"
14358 "\n\t\t: -edges {0|1} show/hide edges of View Cube"
14359 "\n\t\t: -vertices {0|1} show/hide vertices of View Cube"
14360 "\n\t\t: -Yup {0|1} -Zup {0|1} set Y-up or Z-up view orientation"
14361 "\n\t\t: -color Color color of View Cube"
14362 "\n\t\t: -boxColor Color box color"
14363 "\n\t\t: -boxSideColor Color box sides color"
14364 "\n\t\t: -boxEdgeColor Color box edges color"
14365 "\n\t\t: -boxCornerColor Color box corner color"
14366 "\n\t\t: -textColor Color color of side text of view cube"
14367 "\n\t\t: -innerColor Color inner box color"
14368 "\n\t\t: -transparency Value transparency of object within [0, 1] range"
14369 "\n\t\t: -boxTransparency Value transparency of box within [0, 1] range"
14370 "\n\t\t: -font Name font name"
14371 "\n\t\t: -fontHeight Value font height"
14372 "\n\t\t: -boxFacetExtension Value box facet extension"
14373 "\n\t\t: -boxEdgeGap Value gap between box edges and box sides"
14374 "\n\t\t: -boxEdgeMinSize Value minimal box edge size"
14375 "\n\t\t: -boxCornerMinSize Value minimal box corner size"
14376 "\n\t\t: -axesPadding Value padding between box and arrows"
14377 "\n\t\t: -roundRadius Value relative radius of corners of sides within [0.0, 0.5] range"
14378 "\n\t\t: -fixedanimation {0|1} uninterruptible animation loop"
14379 "\n\t\t: -duration Seconds animation duration in seconds",
14380 __FILE__, VViewCube, group);