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.SetAmbientColor (Quantity_NOC_BLACK);
7207 aMat.SetDiffuseColor (Quantity_NOC_WHITE);
7208 aMat.SetSpecularColor (Quantity_NOC_BLACK);
7209 aMat.SetEmissiveColor (Quantity_NOC_BLACK);
7210 aFillAspect->SetFrontMaterial (aMat);
7211 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
7212 aFillAspect->SetTextureMapOn();
7215 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
7216 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
7217 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
7218 myDrawer->SetTextAspect (aTextAspect);
7221 const gp_Dir aNorm (0.0, 0.0, 1.0);
7222 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
7223 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
7224 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
7225 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
7226 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
7227 myTris->AddEdge (1);
7228 myTris->AddEdge (2);
7229 myTris->AddEdge (3);
7230 myTris->AddEdge (3);
7231 myTris->AddEdge (2);
7232 myTris->AddEdge (4);
7234 myRect = new Graphic3d_ArrayOfPolylines (4);
7235 myRect->AddVertex (myTris->Vertice (1));
7236 myRect->AddVertex (myTris->Vertice (3));
7237 myRect->AddVertex (myTris->Vertice (4));
7238 myRect->AddVertex (myTris->Vertice (2));
7242 //! Returns TRUE for accepted display modes.
7243 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
7245 //! Compute presentation.
7246 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
7252 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7253 aGroup->AddPrimitiveArray (myTris);
7254 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
7255 aGroup->AddPrimitiveArray (myRect);
7256 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7261 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
7262 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7263 aGroup->AddPrimitiveArray (myRect);
7264 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7270 //! Compute selection.
7271 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
7275 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
7276 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
7277 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
7278 theSel->Add (aSensitive);
7283 Handle(Graphic3d_ArrayOfTriangles) myTris;
7284 Handle(Graphic3d_ArrayOfPolylines) myRect;
7285 TCollection_AsciiString myLabel;
7286 Standard_Real myWidth;
7287 Standard_Real myHeight;
7290 //==============================================================================
7291 //function : VDiffImage
7292 //purpose : The draw-command compares two images.
7293 //==============================================================================
7295 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
7299 std::cout << "Syntax error: not enough arguments.\n";
7303 Standard_Integer anArgIter = 1;
7304 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
7305 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
7306 TCollection_AsciiString aDiffImagePath;
7307 Standard_Real aTolColor = -1.0;
7308 Standard_Integer toBlackWhite = -1;
7309 Standard_Integer isBorderFilterOn = -1;
7310 Standard_Boolean isOldSyntax = Standard_False;
7311 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
7312 for (; anArgIter < theArgNb; ++anArgIter)
7314 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7316 if (anArgIter + 1 < theArgNb
7317 && (anArg == "-toleranceofcolor"
7318 || anArg == "-tolerancecolor"
7319 || anArg == "-tolerance"
7320 || anArg == "-toler"))
7322 aTolColor = Atof (theArgVec[++anArgIter]);
7323 if (aTolColor < 0.0 || aTolColor > 1.0)
7325 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7329 else if (anArg == "-blackwhite")
7331 Standard_Boolean toEnable = Standard_True;
7332 if (anArgIter + 1 < theArgNb
7333 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7337 toBlackWhite = toEnable ? 1 : 0;
7339 else if (anArg == "-borderfilter")
7341 Standard_Boolean toEnable = Standard_True;
7342 if (anArgIter + 1 < theArgNb
7343 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7347 isBorderFilterOn = toEnable ? 1 : 0;
7349 else if (anArg == "-exitonclose")
7351 ViewerTest_EventManager::ToExitOnCloseView() = true;
7352 if (anArgIter + 1 < theArgNb
7353 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToExitOnCloseView()))
7358 else if (anArg == "-closeonescape"
7359 || anArg == "-closeonesc")
7361 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
7362 if (anArgIter + 1 < theArgNb
7363 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
7368 else if (anArgIter + 3 < theArgNb
7369 && anArg == "-display")
7371 aViewName = theArgVec[++anArgIter];
7372 aPrsNameRef = theArgVec[++anArgIter];
7373 aPrsNameNew = theArgVec[++anArgIter];
7374 if (anArgIter + 1 < theArgNb
7375 && *theArgVec[anArgIter + 1] != '-')
7377 aPrsNameDiff = theArgVec[++anArgIter];
7380 else if (aTolColor < 0.0
7381 && anArg.IsRealValue())
7383 isOldSyntax = Standard_True;
7384 aTolColor = anArg.RealValue();
7385 if (aTolColor < 0.0 || aTolColor > 1.0)
7387 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7391 else if (isOldSyntax
7392 && toBlackWhite == -1
7393 && (anArg == "0" || anArg == "1"))
7395 toBlackWhite = anArg == "1" ? 1 : 0;
7397 else if (isOldSyntax
7398 && isBorderFilterOn == -1
7399 && (anArg == "0" || anArg == "1"))
7401 isBorderFilterOn = anArg == "1" ? 1 : 0;
7403 else if (aDiffImagePath.IsEmpty())
7405 aDiffImagePath = theArgVec[anArgIter];
7409 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7414 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
7415 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
7416 if (!anImgRef->Load (anImgPathRef))
7418 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
7421 if (!anImgNew->Load (anImgPathNew))
7423 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
7427 // compare the images
7428 Image_Diff aComparer;
7429 Standard_Integer aDiffColorsNb = -1;
7430 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
7432 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
7433 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
7434 aDiffColorsNb = aComparer.Compare();
7435 theDI << aDiffColorsNb << "\n";
7438 // save image of difference
7439 Handle(Image_AlienPixMap) aDiff;
7440 if (aDiffColorsNb > 0
7441 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
7443 aDiff = new Image_AlienPixMap();
7444 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
7446 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
7449 aComparer.SaveDiffImage (*aDiff);
7450 if (!aDiffImagePath.IsEmpty()
7451 && !aDiff->Save (aDiffImagePath))
7453 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
7458 if (aViewName.IsEmpty())
7463 ViewerTest_Names aViewNames (aViewName);
7464 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
7466 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
7467 theDI.Eval (aCommand.ToCString());
7470 Standard_Integer aPxLeft = 0;
7471 Standard_Integer aPxTop = 0;
7472 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
7473 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
7474 ? int(anImgRef->SizeY() * 2)
7475 : int(anImgRef->SizeY());
7476 TCollection_AsciiString aDisplayName;
7477 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
7478 aViewName, aDisplayName);
7480 Standard_Real aRatio = anImgRef->Ratio();
7481 Standard_Real aSizeX = 1.0;
7482 Standard_Real aSizeY = aSizeX / aRatio;
7484 OSD_Path aPath (anImgPathRef);
7485 TCollection_AsciiString aLabelRef;
7486 if (!aPath.Name().IsEmpty())
7488 aLabelRef = aPath.Name() + aPath.Extension();
7490 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
7492 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
7494 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
7495 anImgRefPrs->SetLocalTransformation (aTrsfRef);
7496 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
7499 OSD_Path aPath (anImgPathNew);
7500 TCollection_AsciiString aLabelNew;
7501 if (!aPath.Name().IsEmpty())
7503 aLabelNew = aPath.Name() + aPath.Extension();
7505 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
7507 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
7509 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
7510 anImgNewPrs->SetLocalTransformation (aTrsfRef);
7511 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
7513 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
7514 if (!aDiff.IsNull())
7516 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
7518 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
7519 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
7521 if (!aPrsNameDiff.IsEmpty())
7523 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
7525 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
7526 ViewerTest::CurrentView()->FitAll();
7530 //=======================================================================
7531 //function : VSelect
7532 //purpose : Emulates different types of selection by mouse:
7533 // 1) single click selection
7534 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
7535 // 3) selection with polygon having corners at
7536 // pixel positions (x1,y1),...,(xn,yn)
7537 // 4) any of these selections with shift button pressed
7538 //=======================================================================
7539 static Standard_Integer VSelect (Draw_Interpretor& ,
7540 Standard_Integer theNbArgs,
7541 const char** theArgVec)
7543 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7546 std::cout << "Error: no active View\n";
7550 NCollection_Sequence<Graphic3d_Vec2i> aPnts;
7551 bool isShiftSelection = false, toAllowOverlap = false;
7552 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7554 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7556 if (anArg == "-allowoverlap")
7558 toAllowOverlap = true;
7559 if (anArgIter + 1 < theNbArgs
7560 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toAllowOverlap))
7565 else if (anArgIter + 1 < theNbArgs
7566 && anArg.IsIntegerValue()
7567 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
7569 const TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
7570 aPnts.Append (Graphic3d_Vec2i (anArg.IntegerValue(), anArgNext.IntegerValue()));
7572 else if (anArgIter + 1 == theNbArgs
7573 && anArg.IsIntegerValue())
7575 isShiftSelection = anArg.IntegerValue() == 1;
7579 std::cout << "Syntax error at '" << anArg << "'\n";
7584 && aPnts.Length() != 2)
7586 std::cout << "Syntax error: -allowoverlap key is applied only for rectangle selection\n";
7591 aCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
7594 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
7595 if (aPnts.IsEmpty())
7597 if (isShiftSelection)
7599 aCtx->ShiftSelect (false);
7603 aCtx->Select (false);
7605 aCtx->CurrentViewer()->Invalidate();
7607 else if (aPnts.Length() == 2)
7610 && aPnts.First().y() < aPnts.Last().y())
7612 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7614 else if (!toAllowOverlap
7615 && aPnts.First().y() > aPnts.Last().y())
7617 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7619 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
7623 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
7625 aCurrentEventManager->FlushViewEvents (aCtx, ViewerTest::CurrentView(), true);
7629 //=======================================================================
7630 //function : VMoveTo
7631 //purpose : Emulates cursor movement to defined pixel position
7632 //=======================================================================
7633 static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
7634 Standard_Integer theNbArgs,
7635 const char** theArgVec)
7637 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
7638 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
7639 if (aContext.IsNull())
7641 std::cout << "Error: no active View\n";
7645 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
7646 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
7648 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
7649 anArgStr.LowerCase();
7650 if (anArgStr == "-reset"
7651 || anArgStr == "-clear")
7653 if (anArgIter + 1 < theNbArgs)
7655 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
7659 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
7660 && aContext->CurrentViewer()->GridEcho();
7663 aContext->CurrentViewer()->HideGridEcho (aView);
7665 if (aContext->ClearDetected() || toEchoGrid)
7667 aContext->CurrentViewer()->RedrawImmediate();
7671 else if (aMousePos.x() == IntegerLast()
7672 && anArgStr.IsIntegerValue())
7674 aMousePos.x() = anArgStr.IntegerValue();
7676 else if (aMousePos.y() == IntegerLast()
7677 && anArgStr.IsIntegerValue())
7679 aMousePos.y() = anArgStr.IntegerValue();
7683 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7688 if (aMousePos.x() == IntegerLast()
7689 || aMousePos.y() == IntegerLast())
7691 std::cout << "Syntax error: wrong number of arguments\n";
7695 ViewerTest::CurrentEventManager()->ResetPreviousMoveTo();
7696 ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false);
7697 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
7699 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
7700 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
7701 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
7703 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
7705 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
7709 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
7715 //! Global map storing all animations registered in ViewerTest.
7716 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
7718 //! The animation calling the Draw Harness command.
7719 class ViewerTest_AnimationProc : public AIS_Animation
7723 //! Main constructor.
7724 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
7725 Draw_Interpretor* theDI,
7726 const TCollection_AsciiString& theCommand)
7727 : AIS_Animation (theAnimationName),
7729 myCommand (theCommand)
7736 //! Evaluate the command.
7737 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
7739 TCollection_AsciiString aCmd = myCommand;
7740 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
7741 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
7742 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
7743 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
7744 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
7745 myDrawInter->Eval (aCmd.ToCString());
7748 //! Find the keyword in the command and replace it with value.
7749 //! @return the position of the keyword to pass value
7750 void replace (TCollection_AsciiString& theCmd,
7751 const TCollection_AsciiString& theKey,
7752 const TCollection_AsciiString& theVal)
7754 TCollection_AsciiString aCmd (theCmd);
7756 const Standard_Integer aPos = aCmd.Search (theKey);
7762 TCollection_AsciiString aPart1, aPart2;
7763 Standard_Integer aPart1To = aPos - 1;
7765 && aPart1To <= theCmd.Length())
7767 aPart1 = theCmd.SubString (1, aPart1To);
7770 Standard_Integer aPart2From = aPos + theKey.Length();
7772 && aPart2From <= theCmd.Length())
7774 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
7777 theCmd = aPart1 + theVal + aPart2;
7782 Draw_Interpretor* myDrawInter;
7783 TCollection_AsciiString myCommand;
7787 //! Replace the animation with the new one.
7788 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
7789 Handle(AIS_Animation)& theAnimation,
7790 const Handle(AIS_Animation)& theAnimationNew)
7792 theAnimationNew->CopyFrom (theAnimation);
7793 if (!theParentAnimation.IsNull())
7795 theParentAnimation->Replace (theAnimation, theAnimationNew);
7799 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
7800 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
7802 theAnimation = theAnimationNew;
7805 //! Parse the point.
7806 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
7808 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
7809 if (!anXYZ[0].IsRealValue()
7810 || !anXYZ[1].IsRealValue()
7811 || !anXYZ[2].IsRealValue())
7813 return Standard_False;
7816 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
7817 return Standard_True;
7820 //! Parse the quaternion.
7821 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
7823 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
7824 if (!anXYZW[0].IsRealValue()
7825 || !anXYZW[1].IsRealValue()
7826 || !anXYZW[2].IsRealValue()
7827 || !anXYZW[3].IsRealValue())
7829 return Standard_False;
7832 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
7833 return Standard_True;
7836 //! Auxiliary class for flipping image upside-down.
7841 //! Empty constructor.
7842 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
7844 //! Perform flipping.
7845 Standard_Boolean FlipY (Image_PixMap& theImage)
7847 if (theImage.IsEmpty()
7848 || theImage.SizeX() == 0
7849 || theImage.SizeY() == 0)
7851 return Standard_False;
7854 const Standard_Size aRowSize = theImage.SizeRowBytes();
7855 if (myTmp.Size() < aRowSize
7856 && !myTmp.Allocate (aRowSize))
7858 return Standard_False;
7861 // for odd height middle row should be left as is
7862 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
7863 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
7865 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
7866 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
7867 memcpy (myTmp.ChangeData(), aTop, aRowSize);
7868 memcpy (aTop, aBot, aRowSize);
7869 memcpy (aBot, myTmp.Data(), aRowSize);
7871 return Standard_True;
7875 NCollection_Buffer myTmp;
7880 //=================================================================================================
7881 //function : VViewParams
7882 //purpose : Gets or sets AIS View characteristics
7883 //=================================================================================================
7884 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7886 Handle(V3d_View) aView = ViewerTest::CurrentView();
7889 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
7893 Standard_Boolean toSetProj = Standard_False;
7894 Standard_Boolean toSetUp = Standard_False;
7895 Standard_Boolean toSetAt = Standard_False;
7896 Standard_Boolean toSetEye = Standard_False;
7897 Standard_Boolean toSetScale = Standard_False;
7898 Standard_Boolean toSetSize = Standard_False;
7899 Standard_Boolean toSetCenter2d = Standard_False;
7900 Standard_Real aViewScale = aView->Scale();
7901 Standard_Real aViewSize = 1.0;
7902 Graphic3d_Vec2i aCenter2d;
7903 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
7904 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
7905 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
7906 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
7907 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
7910 // print all of the available view parameters
7914 "Proj: %12g %12g %12g\n"
7915 "Up: %12g %12g %12g\n"
7916 "At: %12g %12g %12g\n"
7917 "Eye: %12g %12g %12g\n",
7919 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7920 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7921 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
7922 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7927 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7928 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7930 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7932 if (anUpdateTool.parseRedrawMode (anArg))
7936 else if (anArg == "-cmd"
7937 || anArg == "-command"
7938 || anArg == "-args")
7947 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7948 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7949 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7952 else if (anArg == "-scale"
7953 || anArg == "-size")
7955 if (anArgIter + 1 < theArgsNb
7956 && *theArgVec[anArgIter + 1] != '-')
7958 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
7959 if (aValueArg.IsRealValue())
7962 if (anArg == "-scale")
7964 toSetScale = Standard_True;
7965 aViewScale = aValueArg.RealValue();
7967 else if (anArg == "-size")
7969 toSetSize = Standard_True;
7970 aViewSize = aValueArg.RealValue();
7975 if (anArg == "-scale")
7977 theDi << "Scale: " << aView->Scale() << "\n";
7979 else if (anArg == "-size")
7981 Graphic3d_Vec2d aSizeXY;
7982 aView->Size (aSizeXY.x(), aSizeXY.y());
7983 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
7986 else if (anArg == "-eye"
7989 || anArg == "-proj")
7991 if (anArgIter + 3 < theArgsNb)
7994 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
7997 if (anArg == "-eye")
7999 toSetEye = Standard_True;
8002 else if (anArg == "-at")
8004 toSetAt = Standard_True;
8007 else if (anArg == "-up")
8009 toSetUp = Standard_True;
8012 else if (anArg == "-proj")
8014 toSetProj = Standard_True;
8021 if (anArg == "-eye")
8023 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
8025 else if (anArg == "-at")
8027 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
8029 else if (anArg == "-up")
8031 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
8033 else if (anArg == "-proj")
8035 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
8038 else if (anArg == "-center")
8040 if (anArgIter + 2 < theArgsNb)
8042 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
8043 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
8044 if (anX.IsIntegerValue()
8045 && anY.IsIntegerValue())
8047 toSetCenter2d = Standard_True;
8048 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
8054 std::cout << "Syntax error at '" << anArg << "'\n";
8059 // change view parameters in proper order
8062 aView->SetScale (aViewScale);
8066 aView->SetSize (aViewSize);
8070 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
8074 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
8078 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
8082 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
8086 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
8092 //==============================================================================
8093 //function : V2DMode
8095 //==============================================================================
8096 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
8098 bool is2dMode = true;
8099 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
8100 if (aV3dView.IsNull())
8102 std::cout << "Error: no active view.\n";
8105 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
8107 const TCollection_AsciiString anArg = theArgVec[anArgIt];
8108 TCollection_AsciiString anArgCase = anArg;
8109 anArgCase.LowerCase();
8110 if (anArgIt + 1 < theArgsNb
8111 && anArgCase == "-name")
8113 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
8114 TCollection_AsciiString aViewName = aViewNames.GetViewName();
8115 if (!ViewerTest_myViews.IsBound1 (aViewName))
8117 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
8120 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
8122 else if (anArgCase == "-mode")
8124 if (anArgIt + 1 < theArgsNb
8125 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
8130 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
8136 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
8141 aV3dView->SetView2DMode (is2dMode);
8145 //==============================================================================
8146 //function : VAnimation
8148 //==============================================================================
8149 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
8150 Standard_Integer theArgNb,
8151 const char** theArgVec)
8153 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
8156 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
8157 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
8159 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
8165 std::cout << "Error: no active view\n";
8169 Standard_Integer anArgIter = 1;
8170 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
8171 if (aNameArg.IsEmpty())
8173 std::cout << "Syntax error: animation name is not defined.\n";
8177 TCollection_AsciiString aNameArgLower = aNameArg;
8178 aNameArgLower.LowerCase();
8179 if (aNameArgLower == "-reset"
8180 || aNameArgLower == "-clear")
8182 ViewerTest_AnimationTimelineMap.Clear();
8185 else if (aNameArg.Value (1) == '-')
8187 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
8191 const char* aNameSplitter = "/";
8192 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
8193 if (aSplitPos == -1)
8195 aNameSplitter = ".";
8196 aSplitPos = aNameArg.Search (aNameSplitter);
8199 // find existing or create a new animation by specified name within syntax "parent.child".
8200 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
8201 for (; !aNameArg.IsEmpty();)
8203 TCollection_AsciiString aNameParent;
8204 if (aSplitPos != -1)
8206 if (aSplitPos == aNameArg.Length())
8208 std::cout << "Syntax error: animation name is not defined.\n";
8212 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
8213 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
8215 aSplitPos = aNameArg.Search (aNameSplitter);
8219 aNameParent = aNameArg;
8223 if (anAnimation.IsNull())
8225 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
8227 anAnimation = new AIS_Animation (aNameParent);
8228 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
8230 aRootAnimation = anAnimation;
8234 aParentAnimation = anAnimation;
8235 anAnimation = aParentAnimation->Find (aNameParent);
8236 if (anAnimation.IsNull())
8238 anAnimation = new AIS_Animation (aNameParent);
8239 aParentAnimation->Add (anAnimation);
8244 if (anArgIter >= theArgNb)
8246 // just print the list of children
8247 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
8249 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
8254 // animation parameters
8255 Standard_Boolean toPlay = Standard_False;
8256 Standard_Real aPlaySpeed = 1.0;
8257 Standard_Real aPlayStartTime = anAnimation->StartPts();
8258 Standard_Real aPlayDuration = anAnimation->Duration();
8259 Standard_Boolean isFreeCamera = Standard_False;
8260 Standard_Boolean isLockLoop = Standard_False;
8262 // video recording parameters
8263 TCollection_AsciiString aRecFile;
8264 Image_VideoParams aRecParams;
8266 Handle(V3d_View) aView = ViewerTest::CurrentView();
8267 for (; anArgIter < theArgNb; ++anArgIter)
8269 TCollection_AsciiString anArg (theArgVec[anArgIter]);
8272 if (anArg == "-reset"
8273 || anArg == "-clear")
8275 anAnimation->Clear();
8277 else if (anArg == "-remove"
8279 || anArg == "-delete")
8281 if (!aParentAnimation.IsNull())
8283 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
8287 aParentAnimation->Remove (anAnimation);
8291 else if (anArg == "-play")
8293 toPlay = Standard_True;
8294 if (++anArgIter < theArgNb)
8296 if (*theArgVec[anArgIter] == '-')
8301 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
8303 if (++anArgIter < theArgNb)
8305 if (*theArgVec[anArgIter] == '-')
8310 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8314 else if (anArg == "-resume")
8316 toPlay = Standard_True;
8317 aPlayStartTime = anAnimation->ElapsedTime();
8318 if (++anArgIter < theArgNb)
8320 if (*theArgVec[anArgIter] == '-')
8326 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8329 else if (anArg == "-playspeed"
8330 || anArg == "-speed")
8332 if (++anArgIter >= theArgNb)
8334 std::cout << "Syntax error at " << anArg << ".\n";
8337 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
8339 else if (anArg == "-lock"
8340 || anArg == "-lockloop"
8341 || anArg == "-playlockloop")
8343 isLockLoop = Standard_True;
8345 else if (anArg == "-freecamera"
8346 || anArg == "-playfreecamera"
8347 || anArg == "-freelook")
8349 isFreeCamera = Standard_True;
8351 // video recodring options
8352 else if (anArg == "-rec"
8353 || anArg == "-record")
8355 if (++anArgIter >= theArgNb)
8357 std::cout << "Syntax error at " << anArg << ".\n";
8361 aRecFile = theArgVec[anArgIter];
8362 if (aRecParams.FpsNum <= 0)
8364 aRecParams.FpsNum = 24;
8367 if (anArgIter + 2 < theArgNb
8368 && *theArgVec[anArgIter + 1] != '-'
8369 && *theArgVec[anArgIter + 2] != '-')
8371 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
8372 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
8373 if (aWidthArg .IsIntegerValue()
8374 && aHeightArg.IsIntegerValue())
8376 aRecParams.Width = aWidthArg .IntegerValue();
8377 aRecParams.Height = aHeightArg.IntegerValue();
8382 else if (anArg == "-fps")
8384 if (++anArgIter >= theArgNb)
8386 std::cout << "Syntax error at " << anArg << ".\n";
8390 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
8391 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
8392 if (aSplitIndex == 0)
8394 aRecParams.FpsNum = aFpsArg.IntegerValue();
8398 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
8399 aFpsArg.Split (aFpsArg.Length() - 1);
8400 const TCollection_AsciiString aNumStr = aFpsArg;
8401 aRecParams.FpsNum = aNumStr.IntegerValue();
8402 aRecParams.FpsDen = aDenStr.IntegerValue();
8403 if (aRecParams.FpsDen < 1)
8405 std::cout << "Syntax error at " << anArg << ".\n";
8410 else if (anArg == "-format")
8412 if (++anArgIter >= theArgNb)
8414 std::cout << "Syntax error at " << anArg << ".\n";
8417 aRecParams.Format = theArgVec[anArgIter];
8419 else if (anArg == "-pix_fmt"
8420 || anArg == "-pixfmt"
8421 || anArg == "-pixelformat")
8423 if (++anArgIter >= theArgNb)
8425 std::cout << "Syntax error at " << anArg << ".\n";
8428 aRecParams.PixelFormat = theArgVec[anArgIter];
8430 else if (anArg == "-codec"
8431 || anArg == "-vcodec"
8432 || anArg == "-videocodec")
8434 if (++anArgIter >= theArgNb)
8436 std::cout << "Syntax error at " << anArg << ".\n";
8439 aRecParams.VideoCodec = theArgVec[anArgIter];
8441 else if (anArg == "-crf"
8442 || anArg == "-preset"
8445 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
8446 if (++anArgIter >= theArgNb)
8448 std::cout << "Syntax error at " << anArg << ".\n";
8452 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
8454 // animation definition options
8455 else if (anArg == "-start"
8456 || anArg == "-starttime"
8457 || anArg == "-startpts")
8459 if (++anArgIter >= theArgNb)
8461 std::cout << "Syntax error at " << anArg << ".\n";
8465 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
8466 aRootAnimation->UpdateTotalDuration();
8468 else if (anArg == "-end"
8469 || anArg == "-endtime"
8470 || anArg == "-endpts")
8472 if (++anArgIter >= theArgNb)
8474 std::cout << "Syntax error at " << anArg << ".\n";
8478 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
8479 aRootAnimation->UpdateTotalDuration();
8481 else if (anArg == "-dur"
8482 || anArg == "-duration")
8484 if (++anArgIter >= theArgNb)
8486 std::cout << "Syntax error at " << anArg << ".\n";
8490 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
8491 aRootAnimation->UpdateTotalDuration();
8493 else if (anArg == "-command"
8495 || anArg == "-invoke"
8497 || anArg == "-proc")
8499 if (++anArgIter >= theArgNb)
8501 std::cout << "Syntax error at " << anArg << ".\n";
8505 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
8506 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
8508 else if (anArg == "-objecttrsf"
8509 || anArg == "-objectransformation"
8510 || anArg == "-objtransformation"
8511 || anArg == "-objtrsf"
8512 || anArg == "-object"
8515 if (++anArgIter >= theArgNb)
8517 std::cout << "Syntax error at " << anArg << ".\n";
8521 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
8522 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
8523 Handle(AIS_InteractiveObject) anObject;
8524 if (!aMapOfAIS.Find2 (anObjName, anObject))
8526 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
8530 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
8531 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
8532 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
8533 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
8534 Standard_Boolean isTrsfSet = Standard_False;
8535 Standard_Integer aTrsfArgIter = anArgIter + 1;
8536 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
8538 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
8539 aTrsfArg.LowerCase();
8540 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
8541 if (aTrsfArg.StartsWith ("-rotation")
8542 || aTrsfArg.StartsWith ("-rot"))
8544 isTrsfSet = Standard_True;
8545 if (aTrsfArgIter + 4 >= theArgNb
8546 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
8548 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8553 else if (aTrsfArg.StartsWith ("-location")
8554 || aTrsfArg.StartsWith ("-loc"))
8556 isTrsfSet = Standard_True;
8557 if (aTrsfArgIter + 3 >= theArgNb
8558 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
8560 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8565 else if (aTrsfArg.StartsWith ("-scale"))
8567 isTrsfSet = Standard_True;
8568 if (++aTrsfArgIter >= theArgNb)
8570 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8574 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
8575 if (!aScaleStr.IsRealValue())
8577 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8580 aScales[anIndex] = aScaleStr.RealValue();
8584 anArgIter = aTrsfArgIter - 1;
8590 std::cout << "Syntax error at " << anArg << ".\n";
8593 else if (aTrsfArgIter >= theArgNb)
8595 anArgIter = theArgNb;
8598 aTrsfs[0].SetRotation (aRotQuats[0]);
8599 aTrsfs[1].SetRotation (aRotQuats[1]);
8600 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
8601 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
8602 aTrsfs[0].SetScaleFactor (aScales[0]);
8603 aTrsfs[1].SetScaleFactor (aScales[1]);
8605 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
8606 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
8608 else if (anArg == "-viewtrsf"
8609 || anArg == "-view")
8611 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
8612 if (aCamAnimation.IsNull())
8614 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
8615 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
8618 Handle(Graphic3d_Camera) aCams[2] =
8620 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
8621 new Graphic3d_Camera (aCamAnimation->View()->Camera())
8624 Standard_Boolean isTrsfSet = Standard_False;
8625 Standard_Integer aViewArgIter = anArgIter + 1;
8626 for (; aViewArgIter < theArgNb; ++aViewArgIter)
8628 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
8629 aViewArg.LowerCase();
8630 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
8631 if (aViewArg.StartsWith ("-scale"))
8633 isTrsfSet = Standard_True;
8634 if (++aViewArgIter >= theArgNb)
8636 std::cout << "Syntax error at " << anArg << ".\n";
8640 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
8641 if (!aScaleStr.IsRealValue())
8643 std::cout << "Syntax error at " << aViewArg << ".\n";
8646 Standard_Real aScale = aScaleStr.RealValue();
8647 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
8648 aCams[anIndex]->SetScale (aScale);
8650 else if (aViewArg.StartsWith ("-eye")
8651 || aViewArg.StartsWith ("-center")
8652 || aViewArg.StartsWith ("-at")
8653 || aViewArg.StartsWith ("-up"))
8655 isTrsfSet = Standard_True;
8657 if (aViewArgIter + 3 >= theArgNb
8658 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
8660 std::cout << "Syntax error at " << aViewArg << ".\n";
8665 if (aViewArg.StartsWith ("-eye"))
8667 aCams[anIndex]->SetEye (anXYZ);
8669 else if (aViewArg.StartsWith ("-center")
8670 || aViewArg.StartsWith ("-at"))
8672 aCams[anIndex]->SetCenter (anXYZ);
8674 else if (aViewArg.StartsWith ("-up"))
8676 aCams[anIndex]->SetUp (anXYZ);
8681 anArgIter = aViewArgIter - 1;
8687 std::cout << "Syntax error at " << anArg << ".\n";
8690 else if (aViewArgIter >= theArgNb)
8692 anArgIter = theArgNb;
8695 aCamAnimation->SetCameraStart(aCams[0]);
8696 aCamAnimation->SetCameraEnd (aCams[1]);
8700 std::cout << "Syntax error at " << anArg << ".\n";
8705 if (!toPlay && aRecFile.IsEmpty())
8710 // Start animation timeline and process frame updating.
8711 TheIsAnimating = Standard_True;
8712 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
8713 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
8714 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
8717 aView->Camera()->Copy (aCameraBack);
8720 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
8721 if (aRecParams.FpsNum <= 0)
8723 while (!anAnimation->IsStopped())
8725 aCameraBack->Copy (aView->Camera());
8726 const Standard_Real aPts = anAnimation->UpdateTimer();
8729 aView->Camera()->Copy (aCameraBack);
8732 if (aPts >= anUpperPts)
8734 anAnimation->Pause();
8738 if (aView->IsInvalidated())
8744 aView->RedrawImmediate();
8749 // handle user events
8750 theDI.Eval ("after 1 set waiter 1");
8751 theDI.Eval ("vwait waiter");
8753 if (!TheIsAnimating)
8755 anAnimation->Pause();
8761 if (aView->IsInvalidated())
8767 aView->RedrawImmediate();
8772 OSD_Timer aPerfTimer;
8775 Handle(Image_VideoRecorder) aRecorder;
8776 ImageFlipper aFlipper;
8777 Handle(Draw_ProgressIndicator) aProgress;
8778 if (!aRecFile.IsEmpty())
8780 if (aRecParams.Width <= 0
8781 || aRecParams.Height <= 0)
8783 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
8786 aRecorder = new Image_VideoRecorder();
8787 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
8789 std::cout << "Error: failed to open video file for recording\n";
8793 aProgress = new Draw_ProgressIndicator (theDI, 1);
8796 // Manage frame-rated animation here
8797 Standard_Real aPts = aPlayStartTime;
8798 int64_t aNbFrames = 0;
8799 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
8800 Standard_Integer aSecondsProgress = 0;
8801 for (; aPts <= anUpperPts && aPSentry.More();)
8803 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
8804 aPts = aPlayStartTime + aRecPts;
8806 if (!anAnimation->Update (aPts))
8811 if (!aRecorder.IsNull())
8813 V3d_ImageDumpOptions aDumpParams;
8814 aDumpParams.Width = aRecParams.Width;
8815 aDumpParams.Height = aRecParams.Height;
8816 aDumpParams.BufferType = Graphic3d_BT_RGBA;
8817 aDumpParams.StereoOptions = V3d_SDO_MONO;
8818 aDumpParams.ToAdjustAspect = Standard_True;
8819 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
8821 std::cout << "Error: view dump is failed!\n";
8824 aFlipper.FlipY (aRecorder->ChangeFrame());
8825 if (!aRecorder->PushFrame())
8835 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
8843 anAnimation->Stop();
8844 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
8845 theDI << "Average FPS: " << aRecFps << "\n"
8846 << "Nb. Frames: " << Standard_Real(aNbFrames);
8851 aView->SetImmediateUpdate (wasImmediateUpdate);
8852 TheIsAnimating = Standard_False;
8857 //=======================================================================
8858 //function : VChangeSelected
8859 //purpose : Adds the shape to selection or remove one from it
8860 //=======================================================================
8861 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
8862 Standard_Integer argc,
8867 di<<"Usage : " << argv[0] << " shape \n";
8871 TCollection_AsciiString aName(argv[1]);
8872 Handle(AIS_InteractiveObject) anAISObject;
8873 if (!GetMapOfAIS().Find2 (aName, anAISObject)
8874 || anAISObject.IsNull())
8876 di<<"Use 'vdisplay' before";
8880 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
8884 //=======================================================================
8885 //function : VNbSelected
8886 //purpose : Returns number of selected objects
8887 //=======================================================================
8888 static Standard_Integer VNbSelected (Draw_Interpretor& di,
8889 Standard_Integer argc,
8894 di << "Usage : " << argv[0] << "\n";
8897 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8898 if(aContext.IsNull())
8900 di << "use 'vinit' command before " << argv[0] << "\n";
8903 di << aContext->NbSelected() << "\n";
8907 //=======================================================================
8908 //function : VPurgeDisplay
8909 //purpose : Switches altialiasing on or off
8910 //=======================================================================
8911 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
8912 Standard_Integer argc,
8917 di << "Usage : " << argv[0] << "\n";
8920 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8921 if (aContext.IsNull())
8923 di << "use 'vinit' command before " << argv[0] << "\n";
8927 di << aContext->PurgeDisplay() << "\n";
8931 //=======================================================================
8932 //function : VSetViewSize
8934 //=======================================================================
8935 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
8936 Standard_Integer argc,
8939 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8940 if(aContext.IsNull())
8942 di << "use 'vinit' command before " << argv[0] << "\n";
8947 di<<"Usage : " << argv[0] << " Size\n";
8950 Standard_Real aSize = Draw::Atof (argv[1]);
8953 di<<"Bad Size value : " << aSize << "\n";
8957 Handle(V3d_View) aView = ViewerTest::CurrentView();
8958 aView->SetSize(aSize);
8962 //=======================================================================
8963 //function : VMoveView
8965 //=======================================================================
8966 static Standard_Integer VMoveView (Draw_Interpretor& di,
8967 Standard_Integer argc,
8970 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8971 if(aContext.IsNull())
8973 di << "use 'vinit' command before " << argv[0] << "\n";
8976 if(argc < 4 || argc > 5)
8978 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8981 Standard_Real Dx = Draw::Atof (argv[1]);
8982 Standard_Real Dy = Draw::Atof (argv[2]);
8983 Standard_Real Dz = Draw::Atof (argv[3]);
8984 Standard_Boolean aStart = Standard_True;
8987 aStart = (Draw::Atoi (argv[4]) > 0);
8990 Handle(V3d_View) aView = ViewerTest::CurrentView();
8991 aView->Move(Dx,Dy,Dz,aStart);
8995 //=======================================================================
8996 //function : VTranslateView
8998 //=======================================================================
8999 static Standard_Integer VTranslateView (Draw_Interpretor& di,
9000 Standard_Integer argc,
9003 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9004 if(aContext.IsNull())
9006 di << "use 'vinit' command before " << argv[0] << "\n";
9009 if(argc < 4 || argc > 5)
9011 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
9014 Standard_Real Dx = Draw::Atof (argv[1]);
9015 Standard_Real Dy = Draw::Atof (argv[2]);
9016 Standard_Real Dz = Draw::Atof (argv[3]);
9017 Standard_Boolean aStart = Standard_True;
9020 aStart = (Draw::Atoi (argv[4]) > 0);
9023 Handle(V3d_View) aView = ViewerTest::CurrentView();
9024 aView->Translate(Dx,Dy,Dz,aStart);
9028 //=======================================================================
9029 //function : VTurnView
9031 //=======================================================================
9032 static Standard_Integer VTurnView (Draw_Interpretor& di,
9033 Standard_Integer argc,
9036 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9037 if(aContext.IsNull()) {
9038 di << "use 'vinit' command before " << argv[0] << "\n";
9041 if(argc < 4 || argc > 5){
9042 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
9045 Standard_Real Ax = Draw::Atof (argv[1]);
9046 Standard_Real Ay = Draw::Atof (argv[2]);
9047 Standard_Real Az = Draw::Atof (argv[3]);
9048 Standard_Boolean aStart = Standard_True;
9051 aStart = (Draw::Atoi (argv[4]) > 0);
9054 Handle(V3d_View) aView = ViewerTest::CurrentView();
9055 aView->Turn(Ax,Ay,Az,aStart);
9059 //==============================================================================
9060 //function : VTextureEnv
9061 //purpose : ENables or disables environment mapping
9062 //==============================================================================
9063 class OCC_TextureEnv : public Graphic3d_TextureEnv
9066 OCC_TextureEnv(const Standard_CString FileName);
9067 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
9068 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
9069 const Standard_Boolean theModulateFlag,
9070 const Graphic3d_TypeOfTextureFilter theFilter,
9071 const Standard_ShortReal theXScale,
9072 const Standard_ShortReal theYScale,
9073 const Standard_ShortReal theXShift,
9074 const Standard_ShortReal theYShift,
9075 const Standard_ShortReal theAngle);
9076 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
9078 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
9080 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
9081 : Graphic3d_TextureEnv(theFileName)
9085 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
9086 : Graphic3d_TextureEnv(theTexId)
9090 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
9091 const Standard_Boolean theModulateFlag,
9092 const Graphic3d_TypeOfTextureFilter theFilter,
9093 const Standard_ShortReal theXScale,
9094 const Standard_ShortReal theYScale,
9095 const Standard_ShortReal theXShift,
9096 const Standard_ShortReal theYShift,
9097 const Standard_ShortReal theAngle)
9099 myParams->SetRepeat (theRepeatFlag);
9100 myParams->SetModulate (theModulateFlag);
9101 myParams->SetFilter (theFilter);
9102 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
9103 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
9104 myParams->SetRotation (theAngle);
9107 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
9109 // get the active view
9110 Handle(V3d_View) aView = ViewerTest::CurrentView();
9113 std::cerr << "No active view. Please call vinit.\n";
9117 // Checking the input arguments
9118 Standard_Boolean anEnableFlag = Standard_False;
9119 Standard_Boolean isOk = theArgNb >= 2;
9122 TCollection_AsciiString anEnableOpt(theArgVec[1]);
9123 anEnableFlag = anEnableOpt.IsEqual("on");
9124 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
9128 isOk = (theArgNb == 3 || theArgNb == 11);
9131 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9132 isOk = (!aTextureOpt.IsIntegerValue() ||
9133 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
9135 if (isOk && theArgNb == 11)
9137 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
9138 aModulateOpt(theArgVec[4]),
9139 aFilterOpt (theArgVec[5]),
9140 aSScaleOpt (theArgVec[6]),
9141 aTScaleOpt (theArgVec[7]),
9142 aSTransOpt (theArgVec[8]),
9143 aTTransOpt (theArgVec[9]),
9144 anAngleOpt (theArgVec[10]);
9145 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
9146 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
9147 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
9148 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
9149 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
9150 anAngleOpt.IsRealValue());
9157 std::cerr << "Usage :" << std::endl;
9158 std::cerr << theArgVec[0] << " off" << std::endl;
9159 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;
9165 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9166 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
9167 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
9168 new OCC_TextureEnv(theArgVec[2]);
9172 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
9173 aTexEnv->SetTextureParameters(
9174 aRepeatOpt. IsEqual("repeat"),
9175 aModulateOpt.IsEqual("modulate"),
9176 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
9177 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
9178 Graphic3d_TOTF_TRILINEAR,
9179 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
9180 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
9181 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
9182 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
9183 (Standard_ShortReal)Draw::Atof(theArgVec[10])
9186 aView->SetTextureEnv(aTexEnv);
9188 else // Disabling environment mapping
9190 Handle(Graphic3d_TextureEnv) aTexture;
9191 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
9200 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
9202 //! Remove registered clipping plane from all views and objects.
9203 static void removePlane (MapOfPlanes& theRegPlanes,
9204 const TCollection_AsciiString& theName)
9206 Handle(Graphic3d_ClipPlane) aClipPlane;
9207 if (!theRegPlanes.Find (theName, aClipPlane))
9209 std::cout << "Warning: no such plane.\n";
9213 theRegPlanes.UnBind (theName);
9214 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
9215 anIObjIt.More(); anIObjIt.Next())
9217 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
9218 aPrs->RemoveClipPlane (aClipPlane);
9221 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
9222 aViewIt.More(); aViewIt.Next())
9224 const Handle(V3d_View)& aView = aViewIt.Key2();
9225 aView->RemoveClipPlane(aClipPlane);
9228 ViewerTest::RedrawAllViews();
9232 //===============================================================================================
9233 //function : VClipPlane
9235 //===============================================================================================
9236 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9238 // use short-cut for created clip planes map of created (or "registered by name") clip planes
9239 static MapOfPlanes aRegPlanes;
9243 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
9245 theDi << aPlaneIter.Key() << " ";
9250 TCollection_AsciiString aCommand (theArgVec[1]);
9251 aCommand.LowerCase();
9252 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
9253 if (anActiveView.IsNull())
9255 std::cout << "Error: no active view.\n";
9259 // print maximum number of planes for current viewer
9260 if (aCommand == "-maxplanes"
9261 || aCommand == "maxplanes")
9263 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
9264 << " plane slots provided by driver.\n";
9268 // create / delete plane instance
9269 if (aCommand == "-create"
9270 || aCommand == "create"
9271 || aCommand == "-delete"
9272 || aCommand == "delete"
9273 || aCommand == "-clone"
9274 || aCommand == "clone")
9278 std::cout << "Syntax error: plane name is required.\n";
9282 Standard_Boolean toCreate = aCommand == "-create"
9283 || aCommand == "create";
9284 Standard_Boolean toClone = aCommand == "-clone"
9285 || aCommand == "clone";
9286 Standard_Boolean toDelete = aCommand == "-delete"
9287 || aCommand == "delete";
9288 TCollection_AsciiString aPlane (theArgVec[2]);
9292 if (aRegPlanes.IsBound (aPlane))
9294 std::cout << "Warning: existing plane has been overridden.\n";
9299 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9303 else if (toClone) // toClone
9305 if (!aRegPlanes.IsBound (aPlane))
9307 std::cout << "Error: no such plane.\n";
9310 else if (theArgsNb < 4)
9312 std::cout << "Syntax error: enter name for new plane.\n";
9316 TCollection_AsciiString aClone (theArgVec[3]);
9317 if (aRegPlanes.IsBound (aClone))
9319 std::cout << "Error: plane name is in use.\n";
9323 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
9325 aRegPlanes.Bind (aClone, aClipPlane->Clone());
9335 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
9337 aPlane = aPlaneIter.Key();
9338 removePlane (aRegPlanes, aPlane);
9339 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
9344 removePlane (aRegPlanes, aPlane);
9350 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9355 // set / unset plane command
9356 if (aCommand == "set"
9357 || aCommand == "unset")
9361 std::cout << "Syntax error: need more arguments.\n";
9365 // redirect to new syntax
9366 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
9367 anArgVec.SetValue (1, theArgVec[0]);
9368 anArgVec.SetValue (2, theArgVec[2]);
9369 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
9370 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
9372 anArgVec.SetValue (anIt, theArgVec[anIt]);
9375 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
9378 // change plane command
9379 TCollection_AsciiString aPlaneName;
9380 Handle(Graphic3d_ClipPlane) aClipPlane;
9381 Standard_Integer anArgIter = 0;
9382 if (aCommand == "-change"
9383 || aCommand == "change")
9385 // old syntax support
9388 std::cout << "Syntax error: need more arguments.\n";
9393 aPlaneName = theArgVec[2];
9394 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
9396 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
9400 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
9403 aPlaneName = theArgVec[1];
9408 aPlaneName = theArgVec[1];
9409 aClipPlane = new Graphic3d_ClipPlane();
9410 aRegPlanes.Bind (aPlaneName, aClipPlane);
9411 theDi << "Created new plane " << aPlaneName << ".\n";
9414 if (theArgsNb - anArgIter < 1)
9416 std::cout << "Syntax error: need more arguments.\n";
9420 for (; anArgIter < theArgsNb; ++anArgIter)
9422 const char** aChangeArgs = theArgVec + anArgIter;
9423 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
9424 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
9425 aChangeArg.LowerCase();
9427 Standard_Boolean toEnable = Standard_True;
9428 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
9430 aClipPlane->SetOn (toEnable);
9432 else if (aChangeArg.StartsWith ("-equation")
9433 || aChangeArg.StartsWith ("equation"))
9435 if (aNbChangeArgs < 5)
9437 std::cout << "Syntax error: need more arguments.\n";
9441 Standard_Integer aSubIndex = 1;
9442 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
9443 if (aPrefixLen < aChangeArg.Length())
9445 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
9446 if (!aSubStr.IsIntegerValue()
9447 || aSubStr.IntegerValue() <= 0)
9449 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9452 aSubIndex = aSubStr.IntegerValue();
9455 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
9456 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
9457 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
9458 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
9459 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9460 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
9462 if (aSubPln->ChainNextPlane().IsNull())
9464 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9466 aSubPln = aSubPln->ChainNextPlane();
9468 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9469 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
9472 else if ((aChangeArg == "-boxinterior"
9473 || aChangeArg == "-boxint"
9474 || aChangeArg == "-box")
9475 && aNbChangeArgs >= 7)
9477 Graphic3d_BndBox3d aBndBox;
9478 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
9479 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
9482 Standard_Integer aNbSubPlanes = 6;
9483 const Graphic3d_Vec3d aDirArray[6] =
9485 Graphic3d_Vec3d (-1, 0, 0),
9486 Graphic3d_Vec3d ( 1, 0, 0),
9487 Graphic3d_Vec3d ( 0,-1, 0),
9488 Graphic3d_Vec3d ( 0, 1, 0),
9489 Graphic3d_Vec3d ( 0, 0,-1),
9490 Graphic3d_Vec3d ( 0, 0, 1),
9492 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9493 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
9495 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
9496 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
9497 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
9498 if (aSubPlaneIter + 1 == aNbSubPlanes)
9500 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9504 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9506 aSubPln = aSubPln->ChainNextPlane();
9509 else if (aChangeArg == "-capping"
9510 || aChangeArg == "capping")
9512 if (aNbChangeArgs < 2)
9514 std::cout << "Syntax error: need more arguments.\n";
9518 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9520 aClipPlane->SetCapping (toEnable);
9525 // just skip otherwise (old syntax)
9528 else if (aChangeArg == "-useobjectmaterial"
9529 || aChangeArg == "-useobjectmat"
9530 || aChangeArg == "-useobjmat"
9531 || aChangeArg == "-useobjmaterial")
9533 if (aNbChangeArgs < 2)
9535 std::cout << "Syntax error: need more arguments.\n";
9539 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9541 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
9545 else if (aChangeArg == "-useobjecttexture"
9546 || aChangeArg == "-useobjecttex"
9547 || aChangeArg == "-useobjtexture"
9548 || aChangeArg == "-useobjtex")
9550 if (aNbChangeArgs < 2)
9552 std::cout << "Syntax error: need more arguments.\n";
9556 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9558 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
9562 else if (aChangeArg == "-useobjectshader"
9563 || aChangeArg == "-useobjshader")
9565 if (aNbChangeArgs < 2)
9567 std::cout << "Syntax error: need more arguments.\n";
9571 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9573 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
9577 else if (aChangeArg == "-color"
9578 || aChangeArg == "color")
9580 Quantity_Color aColor;
9581 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
9586 std::cout << "Syntax error: need more arguments.\n";
9589 aClipPlane->SetCappingColor (aColor);
9590 anArgIter += aNbParsed;
9592 else if (aNbChangeArgs >= 1
9593 && (aChangeArg == "-material"
9594 || aChangeArg == "material"))
9597 Graphic3d_NameOfMaterial aMatName;
9598 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeArgs[1], aMatName))
9600 std::cout << "Syntax error: unknown material '" << aChangeArgs[1] << "'.\n";
9603 aClipPlane->SetCappingMaterial (aMatName);
9605 else if ((aChangeArg == "-transparency"
9606 || aChangeArg == "-transp")
9607 && aNbChangeArgs >= 2)
9609 TCollection_AsciiString aValStr (aChangeArgs[1]);
9610 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
9611 if (aValStr.IsRealValue())
9613 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
9614 aMat.SetTransparency ((float )aValStr.RealValue());
9615 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
9616 aClipPlane->SetCappingMaterial (aMat);
9620 aValStr.LowerCase();
9621 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
9622 if (aValStr == "opaque")
9624 aMode = Graphic3d_AlphaMode_Opaque;
9626 else if (aValStr == "mask")
9628 aMode = Graphic3d_AlphaMode_Mask;
9630 else if (aValStr == "blend")
9632 aMode = Graphic3d_AlphaMode_Blend;
9634 else if (aValStr == "blendauto")
9636 aMode = Graphic3d_AlphaMode_BlendAuto;
9640 std::cout << "Syntax error at '" << aValStr << "'\n";
9643 anAspect->SetAlphaMode (aMode);
9644 aClipPlane->SetCappingAspect (anAspect);
9648 else if (aChangeArg == "-texname"
9649 || aChangeArg == "texname")
9651 if (aNbChangeArgs < 2)
9653 std::cout << "Syntax error: need more arguments.\n";
9657 TCollection_AsciiString aTextureName (aChangeArgs[1]);
9658 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
9659 if (!aTexture->IsDone())
9661 aClipPlane->SetCappingTexture (NULL);
9665 aTexture->EnableModulate();
9666 aTexture->EnableRepeat();
9667 aClipPlane->SetCappingTexture (aTexture);
9671 else if (aChangeArg == "-texscale"
9672 || aChangeArg == "texscale")
9674 if (aClipPlane->CappingTexture().IsNull())
9676 std::cout << "Error: no texture is set.\n";
9680 if (aNbChangeArgs < 3)
9682 std::cout << "Syntax error: need more arguments.\n";
9686 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9687 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9688 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
9691 else if (aChangeArg == "-texorigin"
9692 || aChangeArg == "texorigin") // texture origin
9694 if (aClipPlane->CappingTexture().IsNull())
9696 std::cout << "Error: no texture is set.\n";
9700 if (aNbChangeArgs < 3)
9702 std::cout << "Syntax error: need more arguments.\n";
9706 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9707 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9709 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
9712 else if (aChangeArg == "-texrotate"
9713 || aChangeArg == "texrotate") // texture rotation
9715 if (aClipPlane->CappingTexture().IsNull())
9717 std::cout << "Error: no texture is set.\n";
9721 if (aNbChangeArgs < 2)
9723 std::cout << "Syntax error: need more arguments.\n";
9727 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9728 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
9731 else if (aChangeArg == "-hatch"
9732 || aChangeArg == "hatch")
9734 if (aNbChangeArgs < 2)
9736 std::cout << "Syntax error: need more arguments.\n";
9740 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
9741 aHatchStr.LowerCase();
9742 if (aHatchStr == "on")
9744 aClipPlane->SetCappingHatchOn();
9746 else if (aHatchStr == "off")
9748 aClipPlane->SetCappingHatchOff();
9752 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
9756 else if (aChangeArg == "-delete"
9757 || aChangeArg == "delete")
9759 removePlane (aRegPlanes, aPlaneName);
9762 else if (aChangeArg == "-set"
9763 || aChangeArg == "-unset"
9764 || aChangeArg == "-setoverrideglobal")
9766 // set / unset plane command
9767 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
9768 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
9769 Standard_Integer anIt = 1;
9770 for (; anIt < aNbChangeArgs; ++anIt)
9772 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
9773 if (anEntityName.IsEmpty()
9774 || anEntityName.Value (1) == '-')
9778 else if (!toOverrideGlobal
9779 && ViewerTest_myViews.IsBound1 (anEntityName))
9781 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
9784 aView->AddClipPlane (aClipPlane);
9788 aView->RemoveClipPlane (aClipPlane);
9792 else if (GetMapOfAIS().IsBound2 (anEntityName))
9794 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
9797 aIObj->AddClipPlane (aClipPlane);
9801 aIObj->RemoveClipPlane (aClipPlane);
9803 if (!aIObj->ClipPlanes().IsNull())
9805 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
9810 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
9817 // apply to active view
9820 anActiveView->AddClipPlane (aClipPlane);
9824 anActiveView->RemoveClipPlane (aClipPlane);
9829 anArgIter = anArgIter + anIt - 1;
9834 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9839 ViewerTest::RedrawAllViews();
9843 //===============================================================================================
9844 //function : VZRange
9846 //===============================================================================================
9847 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9849 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9851 if (aCurrentView.IsNull())
9853 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9857 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
9861 theDi << "ZNear: " << aCamera->ZNear() << "\n";
9862 theDi << "ZFar: " << aCamera->ZFar() << "\n";
9868 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
9869 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
9871 if (aNewZNear >= aNewZFar)
9873 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
9877 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
9879 std::cout << theArgVec[0] << ": invalid arguments: ";
9880 std::cout << "znear, zfar should be positive for perspective camera.\n";
9884 aCamera->SetZRange (aNewZNear, aNewZFar);
9888 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9892 aCurrentView->Redraw();
9897 //===============================================================================================
9898 //function : VAutoZFit
9900 //===============================================================================================
9901 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9903 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9905 if (aCurrentView.IsNull())
9907 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9911 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
9915 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9921 theDi << "Auto z-fit mode: \n"
9922 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
9923 << "Scale: " << aScale << "\n";
9927 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
9931 aScale = Draw::Atoi (theArgVec[2]);
9934 aCurrentView->SetAutoZFitMode (isOn, aScale);
9935 aCurrentView->AutoZFit();
9936 aCurrentView->Redraw();
9941 //! Auxiliary function to print projection type
9942 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
9944 switch (theProjType)
9946 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
9947 case Graphic3d_Camera::Projection_Perspective: return "perspective";
9948 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
9949 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
9950 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
9955 //===============================================================================================
9956 //function : VCamera
9958 //===============================================================================================
9959 static int VCamera (Draw_Interpretor& theDI,
9960 Standard_Integer theArgsNb,
9961 const char** theArgVec)
9963 Handle(V3d_View) aView = ViewerTest::CurrentView();
9966 std::cout << "Error: no active view.\n";
9970 Handle(Graphic3d_Camera) aCamera = aView->Camera();
9973 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
9974 theDI << "FOVy: " << aCamera->FOVy() << "\n";
9975 theDI << "Distance: " << aCamera->Distance() << "\n";
9976 theDI << "IOD: " << aCamera->IOD() << "\n";
9977 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
9978 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
9979 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
9983 TCollection_AsciiString aPrsName;
9984 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9986 Standard_CString anArg = theArgVec[anArgIter];
9987 TCollection_AsciiString anArgCase (anArg);
9988 anArgCase.LowerCase();
9989 if (anArgCase == "-proj"
9990 || anArgCase == "-projection"
9991 || anArgCase == "-projtype"
9992 || anArgCase == "-projectiontype")
9994 theDI << projTypeName (aCamera->ProjectionType()) << " ";
9996 else if (anArgCase == "-ortho"
9997 || anArgCase == "-orthographic")
9999 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
10001 else if (anArgCase == "-persp"
10002 || anArgCase == "-perspective"
10003 || anArgCase == "-perspmono"
10004 || anArgCase == "-perspectivemono"
10005 || anArgCase == "-mono")
10007 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10009 else if (anArgCase == "-stereo"
10010 || anArgCase == "-stereoscopic"
10011 || anArgCase == "-perspstereo"
10012 || anArgCase == "-perspectivestereo")
10014 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10016 else if (anArgCase == "-left"
10017 || anArgCase == "-lefteye"
10018 || anArgCase == "-monoleft"
10019 || anArgCase == "-monolefteye"
10020 || anArgCase == "-perpsleft"
10021 || anArgCase == "-perpslefteye")
10023 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
10025 else if (anArgCase == "-right"
10026 || anArgCase == "-righteye"
10027 || anArgCase == "-monoright"
10028 || anArgCase == "-monorighteye"
10029 || anArgCase == "-perpsright")
10031 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
10033 else if (anArgCase == "-dist"
10034 || anArgCase == "-distance")
10036 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10037 if (anArgValue != NULL
10038 && *anArgValue != '-')
10041 aCamera->SetDistance (Draw::Atof (anArgValue));
10044 theDI << aCamera->Distance() << " ";
10046 else if (anArgCase == "-iod")
10048 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10049 if (anArgValue != NULL
10050 && *anArgValue != '-')
10053 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
10056 theDI << aCamera->IOD() << " ";
10058 else if (anArgCase == "-iodtype")
10060 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10061 TCollection_AsciiString anValueCase (anArgValue);
10062 anValueCase.LowerCase();
10063 if (anValueCase == "abs"
10064 || anValueCase == "absolute")
10067 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
10070 else if (anValueCase == "rel"
10071 || anValueCase == "relative")
10074 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
10077 else if (*anArgValue != '-')
10079 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
10082 switch (aCamera->GetIODType())
10084 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
10085 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
10088 else if (anArgCase == "-zfocus")
10090 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10091 if (anArgValue != NULL
10092 && *anArgValue != '-')
10095 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
10098 theDI << aCamera->ZFocus() << " ";
10100 else if (anArgCase == "-zfocustype")
10102 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
10103 TCollection_AsciiString anValueCase (anArgValue);
10104 anValueCase.LowerCase();
10105 if (anValueCase == "abs"
10106 || anValueCase == "absolute")
10109 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
10112 else if (anValueCase == "rel"
10113 || anValueCase == "relative")
10116 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
10119 else if (*anArgValue != '-')
10121 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
10124 switch (aCamera->ZFocusType())
10126 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
10127 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
10130 else if (anArgCase == "-fov"
10131 || anArgCase == "-fovy")
10133 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
10134 if (anArgValue != NULL
10135 && *anArgValue != '-')
10138 aCamera->SetFOVy (Draw::Atof (anArgValue));
10141 theDI << aCamera->FOVy() << " ";
10143 else if (aPrsName.IsEmpty()
10144 && !anArgCase.StartsWith ("-"))
10150 std::cout << "Error: unknown argument '" << anArg << "'\n";
10155 if (aPrsName.IsEmpty()
10162 if (!aPrsName.IsEmpty())
10164 Handle(AIS_CameraFrustum) aCameraFrustum;
10165 if (GetMapOfAIS().IsBound2 (aPrsName))
10167 // find existing object
10168 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
10169 if (aCameraFrustum.IsNull())
10171 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
10176 if (aCameraFrustum.IsNull())
10178 aCameraFrustum = new AIS_CameraFrustum();
10182 // not include displayed object of old camera frustum in the new one.
10183 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
10186 aCameraFrustum->SetCameraFrustum (aView->Camera());
10188 ViewerTest::Display (aPrsName, aCameraFrustum);
10194 //! Parse stereo output mode
10195 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
10196 Graphic3d_StereoMode& theMode)
10198 TCollection_AsciiString aFlag (theArg);
10200 if (aFlag == "quadbuffer")
10202 theMode = Graphic3d_StereoMode_QuadBuffer;
10204 else if (aFlag == "anaglyph")
10206 theMode = Graphic3d_StereoMode_Anaglyph;
10208 else if (aFlag == "row"
10209 || aFlag == "rowinterlaced")
10211 theMode = Graphic3d_StereoMode_RowInterlaced;
10213 else if (aFlag == "col"
10214 || aFlag == "colinterlaced"
10215 || aFlag == "columninterlaced")
10217 theMode = Graphic3d_StereoMode_ColumnInterlaced;
10219 else if (aFlag == "chess"
10220 || aFlag == "chessboard")
10222 theMode = Graphic3d_StereoMode_ChessBoard;
10224 else if (aFlag == "sbs"
10225 || aFlag == "sidebyside")
10227 theMode = Graphic3d_StereoMode_SideBySide;
10229 else if (aFlag == "ou"
10230 || aFlag == "overunder")
10232 theMode = Graphic3d_StereoMode_OverUnder;
10234 else if (aFlag == "pageflip"
10235 || aFlag == "softpageflip")
10237 theMode = Graphic3d_StereoMode_SoftPageFlip;
10241 return Standard_False;
10243 return Standard_True;
10246 //! Parse anaglyph filter
10247 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
10248 Graphic3d_RenderingParams::Anaglyph& theFilter)
10250 TCollection_AsciiString aFlag (theArg);
10252 if (aFlag == "redcyansimple")
10254 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10256 else if (aFlag == "redcyan"
10257 || aFlag == "redcyanoptimized")
10259 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
10261 else if (aFlag == "yellowbluesimple")
10263 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
10265 else if (aFlag == "yellowblue"
10266 || aFlag == "yellowblueoptimized")
10268 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
10270 else if (aFlag == "greenmagenta"
10271 || aFlag == "greenmagentasimple")
10273 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
10277 return Standard_False;
10279 return Standard_True;
10282 //==============================================================================
10283 //function : VStereo
10285 //==============================================================================
10287 static int VStereo (Draw_Interpretor& theDI,
10288 Standard_Integer theArgNb,
10289 const char** theArgVec)
10291 Handle(V3d_View) aView = ViewerTest::CurrentView();
10294 if (aView.IsNull())
10296 std::cout << "Error: no active viewer!\n";
10300 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
10301 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
10304 TCollection_AsciiString aMode;
10305 switch (aView->RenderingParams().StereoMode)
10307 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
10308 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
10309 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
10310 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
10311 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
10312 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
10313 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
10314 case Graphic3d_StereoMode_Anaglyph :
10315 aMode = "anaglyph";
10316 switch (aView->RenderingParams().AnaglyphFilter)
10318 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
10319 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
10320 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
10321 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
10322 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
10327 theDI << "Mode " << aMode << "\n";
10332 Handle(Graphic3d_Camera) aCamera;
10333 Graphic3d_RenderingParams* aParams = NULL;
10334 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
10335 if (!aView.IsNull())
10337 aParams = &aView->ChangeRenderingParams();
10338 aMode = aParams->StereoMode;
10339 aCamera = aView->Camera();
10342 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10343 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10345 Standard_CString anArg = theArgVec[anArgIter];
10346 TCollection_AsciiString aFlag (anArg);
10348 if (anUpdateTool.parseRedrawMode (aFlag))
10352 else if (aFlag == "0"
10355 if (++anArgIter < theArgNb)
10357 std::cout << "Error: wrong number of arguments!\n";
10361 if (!aCamera.IsNull()
10362 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
10364 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10366 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
10369 else if (aFlag == "1"
10372 if (++anArgIter < theArgNb)
10374 std::cout << "Error: wrong number of arguments!\n";
10378 if (!aCamera.IsNull())
10380 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10382 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10385 else if (aFlag == "-reverse"
10386 || aFlag == "-reversed"
10387 || aFlag == "-swap")
10389 Standard_Boolean toEnable = Standard_True;
10390 if (++anArgIter < theArgNb
10391 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10395 aParams->ToReverseStereo = toEnable;
10397 else if (aFlag == "-noreverse"
10398 || aFlag == "-noswap")
10400 Standard_Boolean toDisable = Standard_True;
10401 if (++anArgIter < theArgNb
10402 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
10406 aParams->ToReverseStereo = !toDisable;
10408 else if (aFlag == "-mode"
10409 || aFlag == "-stereomode")
10411 if (++anArgIter >= theArgNb
10412 || !parseStereoMode (theArgVec[anArgIter], aMode))
10414 std::cout << "Error: syntax error at '" << anArg << "'\n";
10418 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10420 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10423 else if (aFlag == "-anaglyph"
10424 || aFlag == "-anaglyphfilter")
10426 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10427 if (++anArgIter >= theArgNb
10428 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
10430 std::cout << "Error: syntax error at '" << anArg << "'\n";
10434 aMode = Graphic3d_StereoMode_Anaglyph;
10435 aParams->AnaglyphFilter = aFilter;
10437 else if (parseStereoMode (anArg, aMode)) // short syntax
10439 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10441 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10446 std::cout << "Error: syntax error at '" << anArg << "'\n";
10451 if (!aView.IsNull())
10453 aParams->StereoMode = aMode;
10454 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10459 //===============================================================================================
10460 //function : VDefaults
10462 //===============================================================================================
10463 static int VDefaults (Draw_Interpretor& theDi,
10464 Standard_Integer theArgsNb,
10465 const char** theArgVec)
10467 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
10470 std::cout << "Error: no active viewer\n";
10474 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
10477 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
10479 theDi << "DeflType: relative\n"
10480 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
10484 theDi << "DeflType: absolute\n"
10485 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
10487 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
10488 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
10492 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10494 TCollection_AsciiString anArg (theArgVec[anArgIter]);
10496 if (anArg == "-ABSDEFL"
10497 || anArg == "-ABSOLUTEDEFLECTION"
10498 || anArg == "-DEFL"
10499 || anArg == "-DEFLECTION")
10501 if (++anArgIter >= theArgsNb)
10503 std::cout << "Error: wrong syntax at " << anArg << "\n";
10506 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
10507 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
10509 else if (anArg == "-RELDEFL"
10510 || anArg == "-RELATIVEDEFLECTION"
10511 || anArg == "-DEVCOEFF"
10512 || anArg == "-DEVIATIONCOEFF"
10513 || anArg == "-DEVIATIONCOEFFICIENT")
10515 if (++anArgIter >= theArgsNb)
10517 std::cout << "Error: wrong syntax at " << anArg << "\n";
10520 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
10521 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
10523 else if (anArg == "-ANGDEFL"
10524 || anArg == "-ANGULARDEFL"
10525 || anArg == "-ANGULARDEFLECTION")
10527 if (++anArgIter >= theArgsNb)
10529 std::cout << "Error: wrong syntax at " << anArg << "\n";
10532 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
10533 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
10535 else if (anArg == "-AUTOTR"
10536 || anArg == "-AUTOTRIANG"
10537 || anArg == "-AUTOTRIANGULATION")
10540 bool toTurnOn = true;
10541 if (anArgIter >= theArgsNb
10542 || !ViewerTest::ParseOnOff (theArgVec[anArgIter], toTurnOn))
10544 std::cout << "Syntax error at '" << anArg << "'\n";
10547 aDefParams->SetAutoTriangulation (toTurnOn);
10551 std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
10559 //! Auxiliary method
10560 inline void addLight (const Handle(V3d_Light)& theLightNew,
10561 const Graphic3d_ZLayerId theLayer,
10562 const Standard_Boolean theIsGlobal)
10564 if (theLightNew.IsNull())
10569 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10570 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
10572 aViewer->AddLight (theLightNew);
10575 aViewer->SetLightOn (theLightNew);
10579 ViewerTest::CurrentView()->SetLightOn (theLightNew);
10584 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
10585 if (aSettings.Lights().IsNull())
10587 aSettings.SetLights (new Graphic3d_LightSet());
10589 aSettings.Lights()->Add (theLightNew);
10590 aViewer->SetZLayerSettings (theLayer, aSettings);
10594 //! Auxiliary method
10595 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
10597 TCollection_AsciiString anArgNextCase (theArgNext);
10598 anArgNextCase.UpperCase();
10599 if (anArgNextCase.Length() > 5
10600 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
10602 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
10606 return theArgNext.IntegerValue();
10610 //===============================================================================================
10611 //function : VLight
10613 //===============================================================================================
10614 static int VLight (Draw_Interpretor& theDi,
10615 Standard_Integer theArgsNb,
10616 const char** theArgVec)
10618 Handle(V3d_View) aView = ViewerTest::CurrentView();
10619 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10621 || aViewer.IsNull())
10623 std::cerr << "No active viewer!\n";
10627 Standard_Real anXYZ[3] = {};
10628 Standard_Real anAtten[2] = {};
10631 // print lights info
10632 Standard_Integer aLightId = 0;
10633 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
10635 Handle(V3d_Light) aLight = aLightIter.Value();
10636 const Quantity_Color aColor = aLight->Color();
10637 theDi << "Light #" << aLightId
10638 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
10639 << " [" << aLight->GetId() << "]" << "\n";
10640 switch (aLight->Type())
10644 theDi << " Type: Ambient\n";
10645 theDi << " Intensity: " << aLight->Intensity() << "\n";
10648 case V3d_DIRECTIONAL:
10650 theDi << " Type: Directional\n";
10651 theDi << " Intensity: " << aLight->Intensity() << "\n";
10652 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10653 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10654 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10655 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10658 case V3d_POSITIONAL:
10660 theDi << " Type: Positional\n";
10661 theDi << " Intensity: " << aLight->Intensity() << "\n";
10662 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10663 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
10664 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10665 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10666 aLight->Attenuation (anAtten[0], anAtten[1]);
10667 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10672 theDi << " Type: Spot\n";
10673 theDi << " Intensity: " << aLight->Intensity() << "\n";
10674 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10675 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10676 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10677 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10678 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10679 aLight->Attenuation (anAtten[0], anAtten[1]);
10680 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10681 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
10682 theDi << " Exponent: " << aLight->Concentration() << "\n";
10687 theDi << " Type: UNKNOWN\n";
10691 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
10695 Handle(V3d_Light) aLightNew;
10696 Handle(V3d_Light) aLightOld;
10697 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
10698 Standard_Boolean isGlobal = Standard_True;
10699 Standard_Boolean toCreate = Standard_False;
10700 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10701 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
10703 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
10705 TCollection_AsciiString aName, aValue;
10706 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
10707 TCollection_AsciiString anArgCase (anArg);
10708 anArgCase.UpperCase();
10709 if (anUpdateTool.parseRedrawMode (anArg))
10714 if (anArgCase.IsEqual ("NEW")
10715 || anArgCase.IsEqual ("ADD")
10716 || anArgCase.IsEqual ("CREATE")
10717 || anArgCase.IsEqual ("-NEW")
10718 || anArgCase.IsEqual ("-ADD")
10719 || anArgCase.IsEqual ("-CREATE"))
10721 toCreate = Standard_True;
10723 else if (anArgCase.IsEqual ("-LAYER")
10724 || anArgCase.IsEqual ("-ZLAYER"))
10726 if (++anArgIt >= theArgsNb)
10728 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10732 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
10733 aValStr.LowerCase();
10734 if (aValStr == "default"
10735 || aValStr == "def")
10737 aLayer = Graphic3d_ZLayerId_Default;
10739 else if (aValStr == "top")
10741 aLayer = Graphic3d_ZLayerId_Top;
10743 else if (aValStr == "topmost")
10745 aLayer = Graphic3d_ZLayerId_Topmost;
10747 else if (aValStr == "toposd"
10748 || aValStr == "osd")
10750 aLayer = Graphic3d_ZLayerId_TopOSD;
10752 else if (aValStr == "botosd"
10753 || aValStr == "bottom")
10755 aLayer = Graphic3d_ZLayerId_BotOSD;
10757 else if (aValStr.IsIntegerValue())
10759 aLayer = Draw::Atoi (theArgVec[anArgIt]);
10763 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
10767 else if (anArgCase.IsEqual ("GLOB")
10768 || anArgCase.IsEqual ("GLOBAL")
10769 || anArgCase.IsEqual ("-GLOB")
10770 || anArgCase.IsEqual ("-GLOBAL"))
10772 isGlobal = Standard_True;
10774 else if (anArgCase.IsEqual ("LOC")
10775 || anArgCase.IsEqual ("LOCAL")
10776 || anArgCase.IsEqual ("-LOC")
10777 || anArgCase.IsEqual ("-LOCAL"))
10779 isGlobal = Standard_False;
10781 else if (anArgCase.IsEqual ("DEF")
10782 || anArgCase.IsEqual ("DEFAULTS")
10783 || anArgCase.IsEqual ("-DEF")
10784 || anArgCase.IsEqual ("-DEFAULTS"))
10786 toCreate = Standard_False;
10787 aViewer->SetDefaultLights();
10789 else if (anArgCase.IsEqual ("CLR")
10790 || anArgCase.IsEqual ("CLEAR")
10791 || anArgCase.IsEqual ("-CLR")
10792 || anArgCase.IsEqual ("-CLEAR"))
10794 toCreate = Standard_False;
10796 TColStd_SequenceOfInteger aLayers;
10797 aViewer->GetAllZLayers (aLayers);
10798 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10800 if (aLayeriter.Value() == aLayer
10801 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10803 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10804 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10805 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10806 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10813 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10815 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
10817 Handle(V3d_Light) aLight = aLightIter.Value();
10818 aViewer->DelLight (aLight);
10819 aLightIter = aView->ActiveLightIterator();
10823 else if (anArgCase.IsEqual ("AMB")
10824 || anArgCase.IsEqual ("AMBIENT")
10825 || anArgCase.IsEqual ("AMBLIGHT"))
10829 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10833 addLight (aLightNew, aLayer, isGlobal);
10834 toCreate = Standard_False;
10835 aLightNew = new V3d_AmbientLight();
10837 else if (anArgCase.IsEqual ("DIRECTIONAL")
10838 || anArgCase.IsEqual ("DIRLIGHT"))
10842 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10846 addLight (aLightNew, aLayer, isGlobal);
10847 toCreate = Standard_False;
10848 aLightNew = new V3d_DirectionalLight();
10850 else if (anArgCase.IsEqual ("SPOT")
10851 || anArgCase.IsEqual ("SPOTLIGHT"))
10855 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10859 addLight (aLightNew, aLayer, isGlobal);
10860 toCreate = Standard_False;
10861 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
10863 else if (anArgCase.IsEqual ("POSLIGHT")
10864 || anArgCase.IsEqual ("POSITIONAL"))
10868 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10872 addLight (aLightNew, aLayer, isGlobal);
10873 toCreate = Standard_False;
10874 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
10876 else if (anArgCase.IsEqual ("CHANGE")
10877 || anArgCase.IsEqual ("-CHANGE"))
10879 if (++anArgIt >= theArgsNb)
10881 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10885 addLight (aLightNew, aLayer, isGlobal);
10886 aLightNew.Nullify();
10887 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
10888 Standard_Integer aLightIt = 0;
10889 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10891 if (aLightIt == aLightId)
10893 aLightOld = aLightIter.Value();
10898 if (aLightOld.IsNull())
10900 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
10904 else if (anArgCase.IsEqual ("DEL")
10905 || anArgCase.IsEqual ("DELETE")
10906 || anArgCase.IsEqual ("-DEL")
10907 || anArgCase.IsEqual ("-DELETE"))
10909 Handle(V3d_Light) aLightDel;
10910 if (++anArgIt >= theArgsNb)
10912 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10916 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10917 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
10918 Standard_Integer aLightIt = 0;
10919 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10921 aLightDel = aLightIter.Value();
10922 if (aLightIt == aLightDelId)
10927 if (aLightDel.IsNull())
10932 TColStd_SequenceOfInteger aLayers;
10933 aViewer->GetAllZLayers (aLayers);
10934 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10936 if (aLayeriter.Value() == aLayer
10937 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10939 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10940 if (!aSettings.Lights().IsNull())
10942 aSettings.Lights()->Remove (aLightDel);
10943 if (aSettings.Lights()->IsEmpty())
10945 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10948 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10949 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10956 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10958 aViewer->DelLight (aLightDel);
10961 else if (anArgCase.IsEqual ("COLOR")
10962 || anArgCase.IsEqual ("COLOUR")
10963 || anArgCase.IsEqual ("-COLOR")
10964 || anArgCase.IsEqual ("-COLOUR"))
10966 if (++anArgIt >= theArgsNb
10967 || aLightCurr.IsNull())
10969 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10973 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10974 anArgNext.UpperCase();
10975 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
10976 aLightCurr->SetColor (aColor);
10978 else if (anArgCase.IsEqual ("POS")
10979 || anArgCase.IsEqual ("POSITION")
10980 || anArgCase.IsEqual ("-POS")
10981 || anArgCase.IsEqual ("-POSITION"))
10983 if ((anArgIt + 3) >= theArgsNb
10984 || aLightCurr.IsNull()
10985 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10986 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10988 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10992 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10993 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10994 anXYZ[2] = Atof (theArgVec[++anArgIt]);
10995 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
10997 else if (anArgCase.IsEqual ("DIR")
10998 || anArgCase.IsEqual ("DIRECTION")
10999 || anArgCase.IsEqual ("-DIR")
11000 || anArgCase.IsEqual ("-DIRECTION"))
11002 if ((anArgIt + 3) >= theArgsNb
11003 || aLightCurr.IsNull()
11004 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
11005 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11007 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11011 anXYZ[0] = Atof (theArgVec[++anArgIt]);
11012 anXYZ[1] = Atof (theArgVec[++anArgIt]);
11013 anXYZ[2] = Atof (theArgVec[++anArgIt]);
11014 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
11016 else if (anArgCase.IsEqual ("SM")
11017 || anArgCase.IsEqual ("SMOOTHNESS")
11018 || anArgCase.IsEqual ("-SM")
11019 || anArgCase.IsEqual ("-SMOOTHNESS"))
11021 if (++anArgIt >= theArgsNb
11022 || aLightCurr.IsNull())
11024 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11028 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11029 if (Abs (aSmoothness) <= ShortRealEpsilon())
11031 aLightCurr->SetIntensity (1.f);
11033 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
11035 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
11039 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
11040 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
11043 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
11045 aLightCurr->SetSmoothRadius (aSmoothness);
11047 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
11049 aLightCurr->SetSmoothAngle (aSmoothness);
11052 else if (anArgCase.IsEqual ("INT")
11053 || anArgCase.IsEqual ("INTENSITY")
11054 || anArgCase.IsEqual ("-INT")
11055 || anArgCase.IsEqual ("-INTENSITY"))
11057 if (++anArgIt >= theArgsNb
11058 || aLightCurr.IsNull())
11060 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11064 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11065 aLightCurr->SetIntensity (aIntensity);
11067 else if (anArgCase.IsEqual ("ANG")
11068 || anArgCase.IsEqual ("ANGLE")
11069 || anArgCase.IsEqual ("-ANG")
11070 || anArgCase.IsEqual ("-ANGLE"))
11072 if (++anArgIt >= theArgsNb
11073 || aLightCurr.IsNull()
11074 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11076 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11080 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
11081 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
11083 else if (anArgCase.IsEqual ("CONSTATTEN")
11084 || anArgCase.IsEqual ("CONSTATTENUATION")
11085 || anArgCase.IsEqual ("-CONSTATTEN")
11086 || anArgCase.IsEqual ("-CONSTATTENUATION"))
11088 if (++anArgIt >= theArgsNb
11089 || aLightCurr.IsNull()
11090 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11091 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11093 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11097 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11098 anAtten[0] = Atof (theArgVec[anArgIt]);
11099 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11101 else if (anArgCase.IsEqual ("LINATTEN")
11102 || anArgCase.IsEqual ("LINEARATTEN")
11103 || anArgCase.IsEqual ("LINEARATTENUATION")
11104 || anArgCase.IsEqual ("-LINATTEN")
11105 || anArgCase.IsEqual ("-LINEARATTEN")
11106 || anArgCase.IsEqual ("-LINEARATTENUATION"))
11108 if (++anArgIt >= theArgsNb
11109 || aLightCurr.IsNull()
11110 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
11111 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
11113 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11117 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
11118 anAtten[1] = Atof (theArgVec[anArgIt]);
11119 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
11121 else if (anArgCase.IsEqual ("EXP")
11122 || anArgCase.IsEqual ("EXPONENT")
11123 || anArgCase.IsEqual ("SPOTEXP")
11124 || anArgCase.IsEqual ("SPOTEXPONENT")
11125 || anArgCase.IsEqual ("-EXP")
11126 || anArgCase.IsEqual ("-EXPONENT")
11127 || anArgCase.IsEqual ("-SPOTEXP")
11128 || anArgCase.IsEqual ("-SPOTEXPONENT"))
11130 if (++anArgIt >= theArgsNb
11131 || aLightCurr.IsNull()
11132 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
11134 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11138 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
11140 else if (anArgCase.IsEqual ("HEAD")
11141 || anArgCase.IsEqual ("HEADLIGHT")
11142 || anArgCase.IsEqual ("-HEAD")
11143 || anArgCase.IsEqual ("-HEADLIGHT"))
11145 if (aLightCurr.IsNull()
11146 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
11148 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
11152 Standard_Boolean isHeadLight = Standard_True;
11153 if (anArgIt + 1 < theArgsNb
11154 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
11158 aLightCurr->SetHeadlight (isHeadLight);
11162 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
11166 addLight (aLightNew, aLayer, isGlobal);
11170 //! Read Graphic3d_RenderingParams::PerfCounters flag.
11171 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
11172 Standard_Boolean& theToReset,
11173 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
11174 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
11176 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
11177 TCollection_AsciiString aVal = theValue;
11178 Standard_Boolean toReverse = Standard_False;
11179 if (aVal == "none")
11181 theToReset = Standard_True;
11182 return Standard_True;
11184 else if (aVal.StartsWith ("-"))
11186 toReverse = Standard_True;
11187 aVal = aVal.SubString (2, aVal.Length());
11189 else if (aVal.StartsWith ("no"))
11191 toReverse = Standard_True;
11192 aVal = aVal.SubString (3, aVal.Length());
11194 else if (aVal.StartsWith ("+"))
11196 aVal = aVal.SubString (2, aVal.Length());
11200 theToReset = Standard_True;
11204 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11205 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
11206 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
11207 else if (aVal == "structs"
11208 || aVal == "structures"
11209 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
11210 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
11211 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11212 else if (aVal == "tris"
11213 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
11214 else if (aVal == "pnts"
11215 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
11216 else if (aVal == "mem"
11217 || aVal == "gpumem"
11218 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11219 else if (aVal == "skipimmediate"
11220 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
11221 else if (aVal == "frametime"
11222 || aVal == "frametimers"
11223 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11224 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
11225 else if (aVal == "extended"
11226 || aVal == "verbose"
11227 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
11228 else if (aVal == "full"
11229 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
11232 return Standard_False;
11237 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
11241 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
11243 return Standard_True;
11246 //! Read Graphic3d_RenderingParams::PerfCounters flags.
11247 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
11248 Graphic3d_RenderingParams::PerfCounters& theFlags)
11250 TCollection_AsciiString aValue = theValue;
11251 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
11252 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
11253 Standard_Boolean toReset = Standard_False;
11256 Standard_Integer aSplitPos = aValue.Search ("|");
11257 if (aSplitPos <= 0)
11259 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
11261 return Standard_False;
11265 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
11267 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
11268 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
11269 return Standard_True;
11274 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
11275 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
11277 return Standard_False;
11280 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
11284 //=======================================================================
11285 //function : VRenderParams
11286 //purpose : Enables/disables rendering features
11287 //=======================================================================
11289 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
11290 Standard_Integer theArgNb,
11291 const char** theArgVec)
11293 Handle(V3d_View) aView = ViewerTest::CurrentView();
11294 if (aView.IsNull())
11296 std::cerr << "Error: no active viewer!\n";
11300 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
11301 TCollection_AsciiString aCmdName (theArgVec[0]);
11302 aCmdName.LowerCase();
11303 if (aCmdName == "vraytrace")
11307 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
11310 else if (theArgNb == 2)
11312 TCollection_AsciiString aValue (theArgVec[1]);
11313 aValue.LowerCase();
11317 aParams.Method = Graphic3d_RM_RAYTRACING;
11321 else if (aValue == "off"
11324 aParams.Method = Graphic3d_RM_RASTERIZATION;
11330 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
11336 std::cout << "Error: wrong number of arguments\n";
11343 theDI << "renderMode: ";
11344 switch (aParams.Method)
11346 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11347 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
11350 theDI << "transparency: ";
11351 switch (aParams.TransparencyMethod)
11353 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
11354 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
11355 << TCollection_AsciiString (aParams.OitDepthFactor); break;
11358 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
11359 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
11360 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
11361 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
11362 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
11363 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
11364 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
11365 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
11366 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
11367 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
11368 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
11369 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
11370 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
11371 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
11372 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
11373 theDI << "shadingModel: ";
11374 switch (aView->ShadingModel())
11376 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11377 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
11378 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
11379 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
11380 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
11383 theDI << "perfCounters:";
11384 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
11388 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
11392 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
11394 theDI << " structs";
11396 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
11398 theDI << " groups";
11400 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
11402 theDI << " arrays";
11404 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
11408 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
11412 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
11414 theDI << " gpumem";
11416 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
11418 theDI << " frameTime";
11420 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
11422 theDI << " skipimmediate";
11424 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
11430 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
11431 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
11432 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
11433 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
11434 "noUpdate") << "\n";
11439 Standard_Boolean toPrint = Standard_False;
11440 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
11441 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11443 Standard_CString anArg (theArgVec[anArgIter]);
11444 TCollection_AsciiString aFlag (anArg);
11446 if (anUpdateTool.parseRedrawMode (aFlag))
11450 else if (aFlag == "-echo"
11451 || aFlag == "-print")
11453 toPrint = Standard_True;
11454 anUpdateTool.Invalidate();
11456 else if (aFlag == "-mode"
11457 || aFlag == "-rendermode"
11458 || aFlag == "-render_mode")
11462 switch (aParams.Method)
11464 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11465 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
11471 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11475 else if (aFlag == "-ray"
11476 || aFlag == "-raytrace")
11480 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
11484 aParams.Method = Graphic3d_RM_RAYTRACING;
11486 else if (aFlag == "-rast"
11487 || aFlag == "-raster"
11488 || aFlag == "-rasterization")
11492 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
11496 aParams.Method = Graphic3d_RM_RASTERIZATION;
11498 else if (aFlag == "-msaa")
11502 theDI << aParams.NbMsaaSamples << " ";
11505 else if (++anArgIter >= theArgNb)
11507 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11511 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
11512 if (aNbSamples < 0)
11514 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
11519 aParams.NbMsaaSamples = aNbSamples;
11522 else if (aFlag == "-linefeather"
11523 || aFlag == "-edgefeather"
11524 || aFlag == "-feather")
11528 theDI << " " << aParams.LineFeather << " ";
11531 else if (++anArgIter >= theArgNb)
11533 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11537 TCollection_AsciiString aParam = theArgVec[anArgIter];
11538 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11539 if (aFeather <= 0.0f)
11541 std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n";
11544 aParams.LineFeather = aFeather;
11546 else if (aFlag == "-oit")
11550 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
11552 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
11556 theDI << "off" << " ";
11560 else if (++anArgIter >= theArgNb)
11562 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11566 TCollection_AsciiString aParam = theArgVec[anArgIter];
11567 aParam.LowerCase();
11568 if (aParam.IsRealValue())
11570 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11571 if (aWeight < 0.f || aWeight > 1.f)
11573 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
11577 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
11578 aParams.OitDepthFactor = aWeight;
11580 else if (aParam == "off")
11582 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
11586 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11590 else if (aFlag == "-depthprepass")
11594 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
11597 aParams.ToEnableDepthPrepass = Standard_True;
11598 if (anArgIter + 1 < theArgNb
11599 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
11604 else if (aFlag == "-samplealphatocoverage"
11605 || aFlag == "-alphatocoverage")
11609 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
11612 aParams.ToEnableAlphaToCoverage = Standard_True;
11613 if (anArgIter + 1 < theArgNb
11614 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
11619 else if (aFlag == "-rendscale"
11620 || aFlag == "-renderscale"
11621 || aFlag == "-renderresolutionscale")
11625 theDI << aParams.RenderResolutionScale << " ";
11628 else if (++anArgIter >= theArgNb)
11630 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11634 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
11637 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
11642 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
11645 else if (aFlag == "-raydepth"
11646 || aFlag == "-ray_depth")
11650 theDI << aParams.RaytracingDepth << " ";
11653 else if (++anArgIter >= theArgNb)
11655 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11659 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
11661 // We allow RaytracingDepth be more than 10 in case of GI enabled
11662 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
11664 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
11669 aParams.RaytracingDepth = aDepth;
11672 else if (aFlag == "-shad"
11673 || aFlag == "-shadows")
11677 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
11681 Standard_Boolean toEnable = Standard_True;
11682 if (++anArgIter < theArgNb
11683 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11687 aParams.IsShadowEnabled = toEnable;
11689 else if (aFlag == "-refl"
11690 || aFlag == "-reflections")
11694 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
11698 Standard_Boolean toEnable = Standard_True;
11699 if (++anArgIter < theArgNb
11700 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11704 aParams.IsReflectionEnabled = toEnable;
11706 else if (aFlag == "-fsaa")
11710 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
11714 Standard_Boolean toEnable = Standard_True;
11715 if (++anArgIter < theArgNb
11716 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11720 aParams.IsAntialiasingEnabled = toEnable;
11722 else if (aFlag == "-gleam")
11726 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
11730 Standard_Boolean toEnable = Standard_True;
11731 if (++anArgIter < theArgNb
11732 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11736 aParams.IsTransparentShadowEnabled = toEnable;
11738 else if (aFlag == "-gi")
11742 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
11746 Standard_Boolean toEnable = Standard_True;
11747 if (++anArgIter < theArgNb
11748 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11752 aParams.IsGlobalIlluminationEnabled = toEnable;
11755 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
11758 else if (aFlag == "-blockedrng"
11759 || aFlag == "-brng")
11763 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
11767 Standard_Boolean toEnable = Standard_True;
11768 if (++anArgIter < theArgNb
11769 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11773 aParams.CoherentPathTracingMode = toEnable;
11775 else if (aFlag == "-maxrad")
11779 theDI << aParams.RadianceClampingValue << " ";
11782 else if (++anArgIter >= theArgNb)
11784 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11788 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
11789 if (!aMaxRadStr.IsRealValue())
11791 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11795 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
11796 if (aMaxRadiance <= 0.0)
11798 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
11803 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
11806 else if (aFlag == "-iss")
11810 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
11814 Standard_Boolean toEnable = Standard_True;
11815 if (++anArgIter < theArgNb
11816 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11820 aParams.AdaptiveScreenSampling = toEnable;
11822 else if (aFlag == "-issatomic")
11826 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
11830 Standard_Boolean toEnable = Standard_True;
11831 if (++anArgIter < theArgNb
11832 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11836 aParams.AdaptiveScreenSamplingAtomic = toEnable;
11838 else if (aFlag == "-issd")
11842 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
11846 Standard_Boolean toEnable = Standard_True;
11847 if (++anArgIter < theArgNb
11848 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11852 aParams.ShowSamplingTiles = toEnable;
11854 else if (aFlag == "-tilesize")
11858 theDI << aParams.RayTracingTileSize << " ";
11861 else if (++anArgIter >= theArgNb)
11863 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11867 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
11870 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
11873 aParams.RayTracingTileSize = aTileSize;
11875 else if (aFlag == "-nbtiles")
11879 theDI << aParams.NbRayTracingTiles << " ";
11882 else if (++anArgIter >= theArgNb)
11884 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11888 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
11891 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
11894 else if (aNbTiles > 0
11896 || aNbTiles > 1024))
11898 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
11900 aParams.NbRayTracingTiles = aNbTiles;
11902 else if (aFlag == "-env")
11906 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
11910 Standard_Boolean toEnable = Standard_True;
11911 if (++anArgIter < theArgNb
11912 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11916 aParams.UseEnvironmentMapBackground = toEnable;
11918 else if (aFlag == "-twoside")
11922 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
11926 Standard_Boolean toEnable = Standard_True;
11927 if (++anArgIter < theArgNb
11928 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11932 aParams.TwoSidedBsdfModels = toEnable;
11934 else if (aFlag == "-shademodel"
11935 || aFlag == "-shadingmodel"
11936 || aFlag == "-shading")
11940 switch (aView->ShadingModel())
11942 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11943 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
11944 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
11945 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
11946 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
11951 if (++anArgIter >= theArgNb)
11953 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11956 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
11957 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
11958 && aModel != Graphic3d_TOSM_DEFAULT)
11960 aView->SetShadingModel (aModel);
11964 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
11968 else if (aFlag == "-resolution")
11970 if (++anArgIter >= theArgNb)
11972 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11976 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
11977 if (aResolution.IsIntegerValue())
11979 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
11983 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11987 else if (aFlag == "-rebuildglsl"
11988 || aFlag == "-rebuild")
11992 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
11996 Standard_Boolean toEnable = Standard_True;
11997 if (++anArgIter < theArgNb
11998 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
12002 aParams.RebuildRayTracingShaders = toEnable;
12004 else if (aFlag == "-focal")
12006 if (++anArgIter >= theArgNb)
12008 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12012 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12013 if (aParam.IsRealValue())
12015 float aFocalDist = static_cast<float> (aParam.RealValue());
12016 if (aFocalDist < 0)
12018 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12021 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
12025 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12029 else if (aFlag == "-aperture")
12031 if (++anArgIter >= theArgNb)
12033 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12037 TCollection_AsciiString aParam(theArgVec[anArgIter]);
12038 if (aParam.IsRealValue())
12040 float aApertureSize = static_cast<float> (aParam.RealValue());
12041 if (aApertureSize < 0)
12043 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
12046 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
12050 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12054 else if (aFlag == "-exposure")
12056 if (++anArgIter >= theArgNb)
12058 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12062 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
12063 if (anExposure.IsRealValue())
12065 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
12069 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12073 else if (aFlag == "-whitepoint")
12075 if (++anArgIter >= theArgNb)
12077 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12081 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
12082 if (aWhitePoint.IsRealValue())
12084 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
12088 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12092 else if (aFlag == "-tonemapping")
12094 if (++anArgIter >= theArgNb)
12096 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12100 TCollection_AsciiString aMode (theArgVec[anArgIter]);
12103 if (aMode == "disabled")
12105 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
12107 else if (aMode == "filmic")
12109 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
12113 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
12117 else if (aFlag == "-performancestats"
12118 || aFlag == "-performancecounters"
12119 || aFlag == "-perfstats"
12120 || aFlag == "-perfcounters"
12121 || aFlag == "-stats")
12123 if (++anArgIter >= theArgNb)
12125 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12129 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
12130 aFlagsStr.LowerCase();
12131 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
12132 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
12134 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12137 aView->ChangeRenderingParams().CollectedStats = aFlags;
12138 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
12140 else if (aFlag == "-perfupdateinterval"
12141 || aFlag == "-statsupdateinterval")
12143 if (++anArgIter >= theArgNb)
12145 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12148 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12150 else if (aFlag == "-perfchart"
12151 || aFlag == "-statschart")
12153 if (++anArgIter >= theArgNb)
12155 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12158 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
12160 else if (aFlag == "-perfchartmax"
12161 || aFlag == "-statschartmax")
12163 if (++anArgIter >= theArgNb)
12165 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12168 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12170 else if (aFlag == "-frustumculling"
12171 || aFlag == "-culling")
12175 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
12176 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
12177 "noUpdate") << " ";
12181 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
12182 if (++anArgIter < theArgNb)
12184 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
12185 aStateStr.LowerCase();
12186 bool toEnable = true;
12187 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
12189 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
12191 else if (aStateStr == "noupdate"
12192 || aStateStr == "freeze")
12194 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
12201 aParams.FrustumCullingState = aState;
12205 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
12213 //=======================================================================
12214 //function : searchInfo
12216 //=======================================================================
12217 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
12218 const TCollection_AsciiString& theKey)
12220 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
12222 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
12224 return anIter.Value();
12227 return TCollection_AsciiString();
12230 //=======================================================================
12231 //function : VStatProfiler
12233 //=======================================================================
12234 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
12235 Standard_Integer theArgNb,
12236 const char** theArgVec)
12238 Handle(V3d_View) aView = ViewerTest::CurrentView();
12239 if (aView.IsNull())
12241 std::cerr << "Error: no active viewer!\n";
12245 Standard_Boolean toRedraw = Standard_True;
12246 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
12247 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
12248 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
12249 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12251 Standard_CString anArg (theArgVec[anArgIter]);
12252 TCollection_AsciiString aFlag (anArg);
12254 if (aFlag == "-noredraw")
12256 toRedraw = Standard_False;
12260 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
12261 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
12262 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
12263 else if (aFlag == "alllayers"
12264 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
12265 else if (aFlag == "allstructs"
12266 || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
12267 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
12268 else if (aFlag == "allarrays"
12269 || aFlag == "fillarrays"
12270 || aFlag == "linearrays"
12271 || aFlag == "pointarrays"
12272 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
12273 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
12274 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
12275 else if (aFlag == "geommem"
12276 || aFlag == "texturemem"
12277 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
12278 else if (aFlag == "elapsedframe"
12279 || aFlag == "cpuframeaverage"
12280 || aFlag == "cpupickingaverage"
12281 || aFlag == "cpucullingaverage"
12282 || aFlag == "cpudynaverage"
12283 || aFlag == "cpuframemax"
12284 || aFlag == "cpupickingmax"
12285 || aFlag == "cpucullingmax"
12286 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
12289 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
12293 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
12297 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
12299 aView->ChangeRenderingParams().CollectedStats =
12300 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
12304 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12306 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12309 TColStd_IndexedDataMapOfStringString aDict;
12310 aView->StatisticInformation (aDict);
12312 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
12314 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12316 Standard_CString anArg(theArgVec[anArgIter]);
12317 TCollection_AsciiString aFlag(anArg);
12319 if (aFlag == "fps")
12321 theDI << searchInfo (aDict, "FPS") << " ";
12323 else if (aFlag == "cpu")
12325 theDI << searchInfo (aDict, "CPU FPS") << " ";
12327 else if (aFlag == "alllayers")
12329 theDI << searchInfo (aDict, "Layers") << " ";
12331 else if (aFlag == "layers")
12333 theDI << searchInfo (aDict, "Rendered layers") << " ";
12335 else if (aFlag == "allstructs")
12337 theDI << searchInfo (aDict, "Structs") << " ";
12339 else if (aFlag == "structs")
12341 theDI << searchInfo (aDict, "Rendered structs") << " ";
12343 else if (aFlag == "groups")
12345 theDI << searchInfo (aDict, "Rendered groups") << " ";
12347 else if (aFlag == "allarrays")
12349 theDI << searchInfo (aDict, "Rendered arrays") << " ";
12351 else if (aFlag == "fillarrays")
12353 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
12355 else if (aFlag == "linearrays")
12357 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
12359 else if (aFlag == "pointarrays")
12361 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
12363 else if (aFlag == "textarrays")
12365 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
12367 else if (aFlag == "triangles")
12369 theDI << searchInfo (aDict, "Rendered triangles") << " ";
12371 else if (aFlag == "points")
12373 theDI << searchInfo (aDict, "Rendered points") << " ";
12375 else if (aFlag == "geommem")
12377 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
12379 else if (aFlag == "texturemem")
12381 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
12383 else if (aFlag == "framemem")
12385 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
12387 else if (aFlag == "elapsedframe")
12389 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
12391 else if (aFlag == "cpuframe_average")
12393 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
12395 else if (aFlag == "cpupicking_average")
12397 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
12399 else if (aFlag == "cpuculling_average")
12401 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
12403 else if (aFlag == "cpudyn_average")
12405 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
12407 else if (aFlag == "cpuframe_max")
12409 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
12411 else if (aFlag == "cpupicking_max")
12413 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
12415 else if (aFlag == "cpuculling_max")
12417 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
12419 else if (aFlag == "cpudyn_max")
12421 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
12429 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12431 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12433 theDI << "Statistic info:\n" << aView->StatisticInformation();
12438 //=======================================================================
12439 //function : VXRotate
12441 //=======================================================================
12442 static Standard_Integer VXRotate (Draw_Interpretor& di,
12443 Standard_Integer argc,
12444 const char ** argv)
12446 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
12447 if (aContext.IsNull())
12449 di << argv[0] << "ERROR : use 'vinit' command before \n";
12455 di << "ERROR : Usage : " << argv[0] << " name angle\n";
12459 TCollection_AsciiString aName (argv[1]);
12460 Standard_Real anAngle = Draw::Atof (argv[2]);
12463 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
12464 Handle(AIS_InteractiveObject) anIObj;
12465 if (!aMap.Find2 (aName, anIObj))
12467 di << "Use 'vdisplay' before\n";
12471 gp_Trsf aTransform;
12472 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
12473 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
12475 aContext->SetLocation (anIObj, aTransform);
12476 aContext->UpdateCurrentViewer();
12480 //===============================================================================================
12481 //class : ViewerTest_AISManipulator
12482 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
12483 //===============================================================================================
12484 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
12486 class ViewerTest_AISManipulator : public AIS_Manipulator
12490 ViewerTest_AISManipulator() : AIS_Manipulator()
12492 GetMapOfAISManipulators().Add (this);
12495 virtual ~ViewerTest_AISManipulator()
12497 GetMapOfAISManipulators().Remove (this);
12500 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
12503 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
12504 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
12506 //===============================================================================================
12507 //function : VManipulator
12509 //===============================================================================================
12510 static int VManipulator (Draw_Interpretor& theDi,
12511 Standard_Integer theArgsNb,
12512 const char** theArgVec)
12514 Handle(V3d_View) aCurrentView = ViewerTest::CurrentView();
12515 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
12516 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
12517 if (aCurrentView.IsNull()
12518 || aViewer.IsNull())
12520 std::cerr << "No active viewer!\n";
12524 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
12525 Standard_Integer anArgIter = 1;
12526 for (; anArgIter < theArgsNb; ++anArgIter)
12528 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
12531 ViewerTest_CmdParser aCmd;
12532 aCmd.SetDescription ("Manages manipulator for interactive objects:");
12533 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
12534 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
12535 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
12536 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
12537 aCmd.AddOption ("view", "... {active | [view name]} - define view in which manipulator will be displayed, 'all' by default");
12538 aCmd.AddOption ("detach", "... - detach manipulator");
12540 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
12541 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
12542 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
12544 aCmd.AddOption ("move", "... x y z - move object");
12545 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
12546 aCmd.AddOption ("scale", "... factor - scale object");
12548 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
12549 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
12550 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
12551 aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform");
12552 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
12553 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
12554 aCmd.AddOption ("parts", "... all axes mode {0|1} - set visual part");
12555 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
12556 aCmd.AddOption ("size", "... size - set size of manipulator");
12557 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
12559 aCmd.Parse (theArgsNb, theArgVec);
12561 if (aCmd.HasOption ("help"))
12563 theDi.PrintHelp (theArgVec[0]);
12567 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
12569 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
12571 if (aName.IsEmpty())
12573 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
12577 // ----------------------------------
12578 // detach existing manipulator object
12579 // ----------------------------------
12581 if (aCmd.HasOption ("detach"))
12583 if (!aMapAIS.IsBound2 (aName))
12585 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
12589 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12590 if (aManipulator.IsNull())
12592 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12596 aManipulator->Detach();
12597 aMapAIS.UnBind2 (aName);
12598 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
12603 // -----------------------------------------------
12604 // find or create manipulator if it does not exist
12605 // -----------------------------------------------
12607 Handle(AIS_Manipulator) aManipulator;
12608 if (!aMapAIS.IsBound2 (aName))
12610 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
12612 aManipulator = new ViewerTest_AISManipulator();
12613 aManipulator->SetModeActivationOnDetection (true);
12614 aMapAIS.Bind (aManipulator, aName);
12618 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12619 if (aManipulator.IsNull())
12621 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12626 // -----------------------------------------
12627 // change properties of manipulator instance
12628 // -----------------------------------------
12630 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
12632 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
12634 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
12636 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
12638 if (aCmd.HasOption ("followRotation", 1, Standard_True))
12640 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
12642 if (aCmd.HasOption("followDragging", 1, Standard_True))
12644 aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging"));
12646 if (aCmd.HasOption ("gap", 1, Standard_True))
12648 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
12650 if (aCmd.HasOption ("part", 3, Standard_True))
12652 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
12653 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
12654 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
12655 if (aMode < 1 || aMode > 4)
12657 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12661 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
12663 if (aCmd.HasOption("parts", 2, Standard_True))
12665 Standard_Integer aMode = aCmd.ArgInt("parts", 0);
12666 Standard_Boolean aOnOff = aCmd.ArgBool("parts", 1);
12667 if (aMode < 1 || aMode > 4)
12669 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12673 aManipulator->SetPart(static_cast<AIS_ManipulatorMode>(aMode), aOnOff);
12675 if (aCmd.HasOption ("pos", 3, Standard_True))
12677 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
12678 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
12679 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
12681 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
12683 if (aCmd.HasOption ("size", 1, Standard_True))
12685 aManipulator->SetSize (aCmd.ArgFloat ("size"));
12687 if (aCmd.HasOption ("zoomable", 1, Standard_True))
12689 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
12691 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
12693 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
12694 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
12698 // ---------------------------------------------------
12699 // attach, detach or access manipulator from an object
12700 // ---------------------------------------------------
12702 if (aCmd.HasOption ("attach"))
12704 // Find an object and attach manipulator to it
12705 if (!aCmd.HasOption ("attach", 1, Standard_True))
12710 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
12711 Handle(AIS_InteractiveObject) anObject;
12712 if (!aMapAIS.Find2 (anObjName, anObject))
12714 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
12718 for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next())
12720 if (anIt.Value()->IsAttached()
12721 && anIt.Value()->Object() == anObject)
12723 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
12728 AIS_Manipulator::OptionsForAttach anOptions;
12729 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
12731 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
12733 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
12735 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
12737 if (aCmd.HasOption ("enableModes", 1, Standard_True))
12739 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
12742 aManipulator->Attach (anObject, anOptions);
12744 // Check view option
12745 if (aCmd.HasOption ("view"))
12747 if (!aCmd.HasOption ("view", 1, Standard_True))
12751 TCollection_AsciiString aViewString (aCmd.Arg ("view", 0).c_str());
12752 Handle(V3d_View) aView;
12753 if (aViewString.IsEqual ("active"))
12755 aView = ViewerTest::CurrentView();
12757 else // Check view name
12759 ViewerTest_Names aViewNames (aViewString);
12760 if (!ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
12762 std::cerr << theArgVec[0] << " error: wrong view name '" << aViewString << "'\n";
12765 aView = ViewerTest_myViews.Find1 (aViewNames.GetViewName());
12766 if (aView.IsNull())
12768 std::cerr << theArgVec[0] << " error: cannot find view with name '" << aViewString << "'\n";
12772 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
12773 anIter (ViewerTest_myViews); anIter.More(); anIter.Next())
12775 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, anIter.Value(), Standard_False);
12777 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, aView, Standard_True);
12781 // --------------------------------------
12782 // apply transformation using manipulator
12783 // --------------------------------------
12785 if (aCmd.HasOption ("startTransform", 2, Standard_True))
12787 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
12789 if (aCmd.HasOption ("transform", 2, Standard_True))
12791 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
12793 if (aCmd.HasOption ("stopTransform"))
12795 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
12797 aManipulator->StopTransform (toApply);
12801 if (aCmd.HasOption ("move", 3, Standard_True))
12803 aT.SetTranslationPart (aCmd.ArgVec ("move"));
12805 if (aCmd.HasOption ("rotate", 7, Standard_True))
12807 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
12809 if (aCmd.HasOption ("scale", 1))
12811 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
12814 if (aT.Form() != gp_Identity)
12816 aManipulator->Transform (aT);
12819 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
12824 //===============================================================================================
12825 //function : VSelectionProperties
12827 //===============================================================================================
12828 static int VSelectionProperties (Draw_Interpretor& theDi,
12829 Standard_Integer theArgsNb,
12830 const char** theArgVec)
12832 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
12835 std::cerr << "No active viewer!\n";
12839 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
12841 // handle obsolete alias
12842 bool toEnable = true;
12845 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
12848 else if (theArgsNb != 2
12849 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
12851 std::cout << "Syntax error: wrong number of parameters.";
12854 if (toEnable != aCtx->ToHilightSelected())
12856 aCtx->ClearDetected();
12857 aCtx->SetToHilightSelected (toEnable);
12862 Standard_Boolean toPrint = theArgsNb == 1;
12863 Standard_Boolean toRedraw = Standard_False;
12864 Standard_Integer anArgIter = 1;
12865 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
12866 if (anArgIter < theArgsNb)
12868 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
12869 anArgFirst.LowerCase();
12871 if (anArgFirst == "dynhighlight"
12872 || anArgFirst == "dynhilight"
12873 || anArgFirst == "dynamichighlight"
12874 || anArgFirst == "dynamichilight")
12876 aType = Prs3d_TypeOfHighlight_Dynamic;
12878 else if (anArgFirst == "localdynhighlight"
12879 || anArgFirst == "localdynhilight"
12880 || anArgFirst == "localdynamichighlight"
12881 || anArgFirst == "localdynamichilight")
12883 aType = Prs3d_TypeOfHighlight_LocalDynamic;
12885 else if (anArgFirst == "selhighlight"
12886 || anArgFirst == "selhilight"
12887 || anArgFirst == "selectedhighlight"
12888 || anArgFirst == "selectedhilight")
12890 aType = Prs3d_TypeOfHighlight_Selected;
12892 else if (anArgFirst == "localselhighlight"
12893 || anArgFirst == "localselhilight"
12894 || anArgFirst == "localselectedhighlight"
12895 || anArgFirst == "localselectedhilight")
12897 aType = Prs3d_TypeOfHighlight_LocalSelected;
12904 for (; anArgIter < theArgsNb; ++anArgIter)
12906 TCollection_AsciiString anArg (theArgVec[anArgIter]);
12908 if (anArg == "-help")
12910 theDi.PrintHelp (theArgVec[0]);
12913 else if (anArg == "-print")
12915 toPrint = Standard_True;
12917 else if (anArg == "-autoactivate")
12919 Standard_Boolean toEnable = Standard_True;
12920 if (anArgIter + 1 < theArgsNb
12921 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12925 aCtx->SetAutoActivateSelection (toEnable);
12927 else if (anArg == "-automatichighlight"
12928 || anArg == "-automatichilight"
12929 || anArg == "-autohighlight"
12930 || anArg == "-autohilight")
12932 Standard_Boolean toEnable = Standard_True;
12933 if (anArgIter + 1 < theArgsNb
12934 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12938 aCtx->ClearSelected (false);
12939 aCtx->ClearDetected();
12940 aCtx->SetAutomaticHilight (toEnable);
12943 else if (anArg == "-highlightselected"
12944 || anArg == "-hilightselected")
12946 Standard_Boolean toEnable = Standard_True;
12947 if (anArgIter + 1 < theArgsNb
12948 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12952 aCtx->ClearDetected();
12953 aCtx->SetToHilightSelected (toEnable);
12956 else if (anArg == "-pickstrategy"
12957 || anArg == "-pickingstrategy")
12959 if (++anArgIter >= theArgsNb)
12961 std::cout << "Syntax error: type of highlighting is undefined\n";
12965 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12966 TCollection_AsciiString aVal (theArgVec[anArgIter]);
12968 if (aVal == "first"
12969 || aVal == "firstaccepted"
12970 || aVal == "firstacceptable")
12972 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12974 else if (aVal == "topmost"
12975 || aVal == "onlyTopmost")
12977 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
12981 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
12985 aCtx->SetPickingStrategy (aStrategy);
12987 else if (anArg == "-pixtol"
12988 && anArgIter + 1 < theArgsNb)
12990 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
12992 else if ((anArg == "-mode"
12993 || anArg == "-dispmode")
12994 && anArgIter + 1 < theArgsNb)
12996 if (aType == Prs3d_TypeOfHighlight_None)
12998 std::cout << "Syntax error: type of highlighting is undefined\n";
13002 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
13003 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13004 aStyle->SetDisplayMode (aDispMode);
13005 toRedraw = Standard_True;
13007 else if (anArg == "-layer"
13008 && anArgIter + 1 < theArgsNb)
13010 if (aType == Prs3d_TypeOfHighlight_None)
13012 std::cout << "Syntax error: type of highlighting is undefined\n";
13017 Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN;
13018 if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer))
13020 std::cerr << "Error: wrong syntax at " << theArgVec[anArgIter] << ".\n";
13024 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13025 aStyle->SetZLayer (aNewLayer);
13026 toRedraw = Standard_True;
13028 else if (anArg == "-hicolor"
13029 || anArg == "-selcolor"
13030 || anArg == "-color")
13032 if (anArg.StartsWith ("-hi"))
13034 aType = Prs3d_TypeOfHighlight_Dynamic;
13036 else if (anArg.StartsWith ("-sel"))
13038 aType = Prs3d_TypeOfHighlight_Selected;
13040 else if (aType == Prs3d_TypeOfHighlight_None)
13042 std::cout << "Syntax error: type of highlighting is undefined\n";
13046 Quantity_Color aColor;
13047 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
13048 theArgVec + anArgIter + 1,
13050 if (aNbParsed == 0)
13052 std::cout << "Syntax error: need more arguments.\n";
13055 anArgIter += aNbParsed;
13057 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13058 aStyle->SetColor (aColor);
13059 toRedraw = Standard_True;
13061 else if ((anArg == "-transp"
13062 || anArg == "-transparency"
13063 || anArg == "-hitransp"
13064 || anArg == "-seltransp"
13065 || anArg == "-hitransplocal"
13066 || anArg == "-seltransplocal")
13067 && anArgIter + 1 < theArgsNb)
13069 if (anArg.StartsWith ("-hi"))
13071 aType = Prs3d_TypeOfHighlight_Dynamic;
13073 else if (anArg.StartsWith ("-sel"))
13075 aType = Prs3d_TypeOfHighlight_Selected;
13077 else if (aType == Prs3d_TypeOfHighlight_None)
13079 std::cout << "Syntax error: type of highlighting is undefined\n";
13083 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
13084 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13085 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
13086 toRedraw = Standard_True;
13088 else if ((anArg == "-mat"
13089 || anArg == "-material")
13090 && anArgIter + 1 < theArgsNb)
13092 if (aType == Prs3d_TypeOfHighlight_None)
13094 std::cout << "Syntax error: type of highlighting is undefined\n";
13098 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13099 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
13100 if (aMatName != Graphic3d_NOM_DEFAULT)
13103 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
13104 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
13105 Graphic3d_MaterialAspect aMat (aMatName);
13106 aMat.SetColor (aStyle->Color());
13107 aMat.SetTransparency (aStyle->Transparency());
13108 anAspect->SetFrontMaterial (aMat);
13109 anAspect->SetInteriorColor (aStyle->Color());
13110 aStyle->SetBasicFillAreaAspect (anAspect);
13114 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
13116 toRedraw = Standard_True;
13120 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
13126 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
13127 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
13128 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
13129 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
13130 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
13131 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
13132 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
13133 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
13134 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
13135 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
13136 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
13137 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
13138 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
13139 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
13142 if (aCtx->NbSelected() != 0 && toRedraw)
13144 aCtx->HilightSelected (Standard_True);
13150 //===============================================================================================
13151 //function : VDumpSelectionImage
13153 //===============================================================================================
13154 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
13155 Standard_Integer theArgsNb,
13156 const char** theArgVec)
13160 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
13164 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13165 if (aContext.IsNull())
13167 std::cout << "Error: no active view.\n";
13171 TCollection_AsciiString aFile;
13172 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13173 Image_Format anImgFormat = Image_Format_BGR;
13174 Standard_Integer aPickedIndex = 1;
13175 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
13177 TCollection_AsciiString aParam (theArgVec[anArgIter]);
13178 aParam.LowerCase();
13179 if (aParam == "-type")
13181 if (++anArgIter >= theArgsNb)
13183 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
13187 TCollection_AsciiString aValue (theArgVec[anArgIter]);
13188 aValue.LowerCase();
13189 if (aValue == "depth"
13190 || aValue == "normdepth"
13191 || aValue == "normalizeddepth")
13193 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13194 anImgFormat = Image_Format_GrayF;
13196 if (aValue == "depthinverted"
13197 || aValue == "normdepthinverted"
13198 || aValue == "normalizeddepthinverted"
13199 || aValue == "inverted")
13201 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
13202 anImgFormat = Image_Format_GrayF;
13204 else if (aValue == "unnormdepth"
13205 || aValue == "unnormalizeddepth")
13207 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
13208 anImgFormat = Image_Format_GrayF;
13210 else if (aValue == "objectcolor"
13211 || aValue == "object"
13212 || aValue == "color")
13214 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
13216 else if (aValue == "entitycolor"
13217 || aValue == "entity")
13219 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
13221 else if (aValue == "ownercolor"
13222 || aValue == "owner")
13224 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
13226 else if (aValue == "selectionmodecolor"
13227 || aValue == "selectionmode"
13228 || aValue == "selmodecolor"
13229 || aValue == "selmode")
13231 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
13234 else if (aParam == "-picked"
13235 || aParam == "-pickeddepth"
13236 || aParam == "-pickedindex")
13238 if (++anArgIter >= theArgsNb)
13240 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
13244 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
13246 else if (aFile.IsEmpty())
13248 aFile = theArgVec[anArgIter];
13252 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
13256 if (aFile.IsEmpty())
13258 std::cout << "Syntax error: image file name is missing.\n";
13262 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13263 Standard_Integer aWidth = 0, aHeight = 0;
13264 aView->Window()->Size (aWidth, aHeight);
13266 Image_AlienPixMap aPixMap;
13267 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
13269 std::cout << "Error: can't allocate image.\n";
13272 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
13274 std::cout << "Error: can't generate selection image.\n";
13277 if (!aPixMap.Save (aFile))
13279 std::cout << "Error: can't save selection image.\n";
13285 //===============================================================================================
13286 //function : VViewCube
13288 //===============================================================================================
13289 static int VViewCube (Draw_Interpretor& ,
13290 Standard_Integer theNbArgs,
13291 const char** theArgVec)
13293 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13294 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13295 if (aContext.IsNull() || aView.IsNull())
13297 std::cout << "Error: no active view.\n";
13300 else if (theNbArgs < 2)
13302 std::cout << "Syntax error: wrong number arguments\n";
13306 Handle(AIS_ViewCube) aViewCube;
13307 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
13308 Quantity_Color aColorRgb;
13309 TCollection_AsciiString aName;
13310 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
13312 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13314 if (anUpdateTool.parseRedrawMode (anArg))
13318 else if (aViewCube.IsNull())
13320 aName = theArgVec[anArgIter];
13321 if (aName.StartsWith ("-"))
13323 std::cout << "Syntax error: object name should be specified.\n";
13326 Handle(AIS_InteractiveObject) aPrs;
13327 GetMapOfAIS().Find2 (aName, aPrs);
13328 aViewCube = Handle(AIS_ViewCube)::DownCast (aPrs);
13329 if (aViewCube.IsNull())
13331 aViewCube = new AIS_ViewCube();
13332 aViewCube->SetBoxColor (Quantity_NOC_GRAY50);
13333 aViewCube->SetViewAnimation (ViewerTest::CurrentEventManager()->ViewAnimation());
13334 aViewCube->SetFixedAnimationLoop (false);
13337 else if (anArg == "-reset")
13339 aViewCube->ResetStyles();
13341 else if (anArg == "-color"
13342 || anArg == "-boxcolor"
13343 || anArg == "-boxsidecolor"
13344 || anArg == "-sidecolor"
13345 || anArg == "-boxedgecolor"
13346 || anArg == "-edgecolor"
13347 || anArg == "-boxcornercolor"
13348 || anArg == "-cornercolor"
13349 || anArg == "-innercolor"
13350 || anArg == "-textcolor")
13352 Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - anArgIter - 1,
13353 theArgVec + anArgIter + 1,
13355 if (aNbParsed == 0)
13357 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
13360 anArgIter += aNbParsed;
13361 if (anArg == "-boxcolor")
13363 aViewCube->SetBoxColor (aColorRgb);
13365 else if (anArg == "-boxsidecolor"
13366 || anArg == "-sidecolor")
13368 aViewCube->BoxSideStyle()->SetColor (aColorRgb);
13369 aViewCube->SynchronizeAspects();
13371 else if (anArg == "-boxedgecolor"
13372 || anArg == "-edgecolor")
13374 aViewCube->BoxEdgeStyle()->SetColor (aColorRgb);
13375 aViewCube->SynchronizeAspects();
13377 else if (anArg == "-boxcornercolor"
13378 || anArg == "-cornercolor")
13380 aViewCube->BoxCornerStyle()->SetColor (aColorRgb);
13381 aViewCube->SynchronizeAspects();
13383 else if (anArg == "-innercolor")
13385 aViewCube->SetInnerColor (aColorRgb);
13387 else if (anArg == "-textcolor")
13389 aViewCube->SetTextColor (aColorRgb);
13393 aViewCube->SetColor (aColorRgb);
13396 else if (anArgIter + 1 < theNbArgs
13397 && (anArg == "-transparency"
13398 || anArg == "-boxtransparency"))
13400 const Standard_Real aValue = Draw::Atof (theArgVec[++anArgIter]);
13401 if (aValue < 0.0 || aValue > 1.0)
13403 std::cout << "Syntax error: invalid transparency value " << theArgVec[anArgIter] << "\n";
13407 if (anArg == "-boxtransparency")
13409 aViewCube->SetBoxTransparency (aValue);
13413 aViewCube->SetTransparency (aValue);
13416 else if (anArg == "-axes"
13417 || anArg == "-edges"
13418 || anArg == "-vertices"
13419 || anArg == "-vertexes"
13420 || anArg == "-fixedanimation")
13422 bool toShow = true;
13423 if (anArgIter + 1 < theNbArgs
13424 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShow))
13428 if (anArg == "-fixedanimation")
13430 aViewCube->SetFixedAnimationLoop (toShow);
13432 else if (anArg == "-axes")
13434 aViewCube->SetDrawAxes (toShow);
13436 else if (anArg == "-edges")
13438 aViewCube->SetDrawEdges (toShow);
13442 aViewCube->SetDrawVertices (toShow);
13445 else if (anArg == "-yup"
13446 || anArg == "-zup")
13449 if (anArgIter + 1 < theNbArgs
13450 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isOn))
13454 if (anArg == "-yup")
13456 aViewCube->SetYup (isOn);
13460 aViewCube->SetYup (!isOn);
13463 else if (anArgIter + 1 < theNbArgs
13464 && anArg == "-font")
13466 aViewCube->SetFont (theArgVec[++anArgIter]);
13468 else if (anArgIter + 1 < theNbArgs
13469 && anArg == "-fontheight")
13471 aViewCube->SetFontHeight (Draw::Atof (theArgVec[++anArgIter]));
13473 else if (anArgIter + 1 < theNbArgs
13474 && (anArg == "-size"
13475 || anArg == "-boxsize"))
13477 aViewCube->SetSize (Draw::Atof (theArgVec[++anArgIter]),
13478 anArg != "-boxsize");
13480 else if (anArgIter + 1 < theNbArgs
13481 && (anArg == "-boxfacet"
13482 || anArg == "-boxfacetextension"
13483 || anArg == "-facetextension"
13484 || anArg == "-extension"))
13486 aViewCube->SetBoxFacetExtension (Draw::Atof (theArgVec[++anArgIter]));
13488 else if (anArgIter + 1 < theNbArgs
13489 && (anArg == "-boxedgegap"
13490 || anArg == "-edgegap"))
13492 aViewCube->SetBoxEdgeGap (Draw::Atof (theArgVec[++anArgIter]));
13494 else if (anArgIter + 1 < theNbArgs
13495 && (anArg == "-boxedgeminsize"
13496 || anArg == "-edgeminsize"))
13498 aViewCube->SetBoxEdgeMinSize (Draw::Atof (theArgVec[++anArgIter]));
13500 else if (anArgIter + 1 < theNbArgs
13501 && (anArg == "-boxcornerminsize"
13502 || anArg == "-cornerminsize"))
13504 aViewCube->SetBoxCornerMinSize (Draw::Atof (theArgVec[++anArgIter]));
13506 else if (anArgIter + 1 < theNbArgs
13507 && anArg == "-axespadding")
13509 aViewCube->SetAxesPadding (Draw::Atof (theArgVec[++anArgIter]));
13511 else if (anArgIter + 1 < theNbArgs
13512 && anArg == "-roundradius")
13514 aViewCube->SetRoundRadius (Draw::Atof (theArgVec[++anArgIter]));
13516 else if (anArgIter + 1 < theNbArgs
13517 && anArg == "-duration")
13519 aViewCube->SetDuration (Draw::Atof (theArgVec[++anArgIter]));
13523 std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
13527 if (aViewCube.IsNull())
13529 std::cout << "Syntax error: wrong number of arguments\n";
13533 ViewerTest::Display (aName, aViewCube, false);
13537 //=======================================================================
13538 //function : ViewerCommands
13540 //=======================================================================
13542 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
13545 const char *group = "ZeViewer";
13546 theCommands.Add("vinit",
13547 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
13548 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
13549 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13550 "\n\t\t: [-display displayName]"
13552 "\n\t\t: Creates new View window with specified name viewName."
13553 "\n\t\t: By default the new view is created in the viewer and in"
13554 "\n\t\t: graphic driver shared with active view."
13555 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
13556 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
13557 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
13558 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13559 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
13560 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
13562 "\n\t\t: -left, -top pixel position of left top corner of the window."
13563 "\n\t\t: -width, -height width and heigth of window respectively."
13564 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
13565 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
13566 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
13567 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
13568 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
13569 __FILE__,VInit,group);
13570 theCommands.Add("vclose" ,
13571 "[view_id [keep_context=0|1]]\n"
13572 "or vclose ALL - to remove all created views\n"
13573 " - removes view(viewer window) defined by its view_id.\n"
13574 " - keep_context: by default 0; if 1 and the last view is deleted"
13575 " the current context is not removed.",
13576 __FILE__,VClose,group);
13577 theCommands.Add("vactivate" ,
13578 "vactivate view_id [-noUpdate]"
13579 " - activates view(viewer window) defined by its view_id",
13580 __FILE__,VActivate,group);
13581 theCommands.Add("vviewlist",
13582 "vviewlist [format={tree, long}]"
13583 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
13584 " - format: format of result output, if tree the output is a tree view;"
13585 "otherwise it's a list of full view names. By default format = tree",
13586 __FILE__,VViewList,group);
13587 theCommands.Add("vhelp" ,
13588 "vhelp : display help on the viewer commands",
13589 __FILE__,VHelp,group);
13590 theCommands.Add("vviewproj",
13591 "vviewproj [top|bottom|left|right|front|back|axoLeft|axoRight]"
13592 "\n\t\t: [+-X+-Y+-Z] [-Zup|-Yup] [-frame +-X+-Y]"
13593 "\n\t\t: Setup view direction"
13594 "\n\t\t: -Yup use Y-up convention instead of Zup (which is default)."
13595 "\n\t\t: +-X+-Y+-Z define direction as combination of DX, DY and DZ;"
13596 "\n\t\t: for example '+Z' will show front of the model,"
13597 "\n\t\t: '-X-Y+Z' will define left axonometrical view."
13598 "\n\t\t: -frame define camera Up and Right directions (regardless Up convention);"
13599 "\n\t\t: for example '+X+Z' will show front of the model with Z-up."
13600 __FILE__,VViewProj,group);
13601 theCommands.Add("vtop" ,
13602 "vtop or <T> : Top view. Orientation +X+Y" ,
13603 __FILE__,VViewProj,group);
13604 theCommands.Add("vbottom" ,
13605 "vbottom : Bottom view. Orientation +X-Y" ,
13606 __FILE__,VViewProj,group);
13607 theCommands.Add("vleft" ,
13608 "vleft : Left view. Orientation -Y+Z" ,
13609 __FILE__,VViewProj,group);
13610 theCommands.Add("vright" ,
13611 "vright : Right view. Orientation +Y+Z" ,
13612 __FILE__,VViewProj,group);
13613 theCommands.Add("vaxo" ,
13614 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
13615 __FILE__,VViewProj,group);
13616 theCommands.Add("vfront" ,
13617 "vfront : Front view. Orientation +X+Z" ,
13618 __FILE__,VViewProj,group);
13619 theCommands.Add("vback" ,
13620 "vback : Back view. Orientation -X+Z" ,
13621 __FILE__,VViewProj,group);
13622 theCommands.Add("vpick" ,
13623 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
13625 theCommands.Add("vfit",
13626 "vfit or <F> [-selected] [-noupdate]"
13627 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
13628 __FILE__,VFit,group);
13629 theCommands.Add ("vfitarea",
13630 "vfitarea x1 y1 x2 y2"
13631 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
13632 "\n\t\t: Fit view to show area located between two points"
13633 "\n\t\t: given in world 2D or 3D corrdinates.",
13634 __FILE__, VFitArea, group);
13635 theCommands.Add ("vzfit", "vzfit [scale]\n"
13636 " Matches Z near, Z far view volume planes to the displayed objects.\n"
13637 " \"scale\" - specifies factor to scale computed z range.\n",
13638 __FILE__, VZFit, group);
13639 theCommands.Add("vrepaint",
13640 "vrepaint [-immediate] [-continuous FPS]"
13641 "\n\t\t: force redraw of active View"
13642 "\n\t\t: -immediate flag performs redraw of immediate layers only;"
13643 "\n\t\t: -continuous activates/deactivates continuous redraw of active View,"
13644 "\n\t\t: 0 means no continuous rendering,"
13645 "\n\t\t: -1 means non-stop redraws,"
13646 "\n\t\t: >0 specifies target framerate,",
13647 __FILE__,VRepaint,group);
13648 theCommands.Add("vclear",
13650 "\n\t\t: remove all the object from the viewer",
13651 __FILE__,VClear,group);
13654 "Changes background or some background settings.\n"
13657 " vbackground -imageFile ImageFile [-imageMode FillType]\n"
13658 " vbackground -imageMode FillType\n"
13659 " vbackground -gradient Color1 Color2 [-gradientMode FillMethod]\n"
13660 " vbackground -gradientMode FillMethod\n"
13661 " vbackground -cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]\n"
13662 " vbackground -color Color\n"
13663 " vbackground -default -gradient Color1 Color2 [-gradientMode FillType]\n"
13664 " vbackground -default -color Color\n"
13665 " vbackground -help\n"
13668 " -imageFile (-imgFile, -image, -img): sets filename of image used as background\n"
13669 " -imageMode (-imgMode, -imageMd, -imgMd): sets image fill type\n"
13670 " -gradient (-grad, -gr): sets background gradient starting and ending colors\n"
13671 " -gradientMode (-gradMode, -gradMd, -grMode, -grMd): sets gradient fill method\n"
13672 " -cubemap (-cmap, -cm): sets environmet cubemap as background\n"
13673 " -invertedz (-invz, -iz): sets inversion of Z axis for background cubemap rendering\n"
13674 " -order (-o): defines order of tiles in one image cubemap\n"
13675 " (has no effect in case of multi image cubemaps)\n"
13676 " -color (-col): sets background color\n"
13677 " -default (-def): sets background default gradient or color\n"
13678 " -help (-h): outputs short help message\n"
13681 " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n"
13682 " or reals within the range [0.0, 1.0]\n"
13683 " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n"
13684 " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n"
13685 " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, "
13687 " FillType: one of CENTERED, TILED, STRETCH, NONE\n"
13688 " ImageFile: a name of the file with the image used as a background\n"
13689 " CubemapFilei: a name of the file with one image packed cubemap or names of separate files with every cubemap side\n"
13690 " TileIndexi: a cubemap side index in range [0, 5] for i tile of one image packed cubemap\n",
13694 theCommands.Add ("vsetbg",
13695 "Loads image as background."
13696 "\n\t\t: vsetbg ImageFile [FillType]"
13697 "\n\t\t: vsetbg -imageFile ImageFile [-imageMode FillType]"
13698 "\n\t\t: Alias for 'vbackground -imageFile ImageFile [-imageMode FillType]'.",
13702 theCommands.Add ("vsetbgmode",
13703 "Changes background image fill type."
13704 "\n\t\t: vsetbgmode [-imageMode] FillType"
13705 "\n\t\t: Alias for 'vbackground -imageMode FillType'.",
13709 theCommands.Add ("vsetgradientbg",
13710 "Mounts gradient background."
13711 "\n\t\t: vsetgradientbg Color1 Color2 [FillMethod]"
13712 "\n\t\t: vsetgradientbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13713 "\n\t\t: Alias for 'vbackground -gradient Color1 Color2 -gradientMode FillMethod'.",
13717 theCommands.Add ("vsetgrbgmode",
13718 "Changes gradient background fill method."
13719 "\n\t\t: vsetgrbgmode [-gradientMode] FillMethod"
13720 "\n\t\t: Alias for 'vbackground -gradientMode FillMethod'.",
13724 theCommands.Add ("vsetcolorbg",
13725 "Sets background color."
13726 "\n\t\t: vsetcolorbg [-color] Color."
13727 "\n\t\t: Alias for 'vbackground -color Color'.",
13731 theCommands.Add ("vsetdefaultbg",
13732 "Sets default viewer background fill color (flat/gradient)."
13733 "\n\t\t: vsetdefaultbg Color1 Color2 [FillMethod]"
13734 "\n\t\t: vsetdefaultbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13735 "\n\t\t: Alias for 'vbackground -default -gradient Color1 Color2 [-gradientMode FillMethod]'."
13736 "\n\t\t: vsetdefaultbg [-color] Color"
13737 "\n\t\t: Alias for 'vbackground -default -color Color'.",
13741 theCommands.Add("vscale",
13742 "vscale : vscale X Y Z",
13743 __FILE__,VScale,group);
13744 theCommands.Add("vzbufftrihedron",
13745 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
13746 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
13747 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
13748 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
13749 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
13750 "\n\t\t: Displays a trihedron",
13751 __FILE__,VZBuffTrihedron,group);
13752 theCommands.Add("vrotate",
13753 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
13754 "\n : Option -mouseStart starts rotation according to the mouse position"
13755 "\n : Option -mouseMove continues rotation with angle computed"
13756 "\n : from last and new mouse position."
13757 "\n : vrotate AX AY AZ [X Y Z]",
13758 __FILE__,VRotate,group);
13759 theCommands.Add("vzoom",
13760 "vzoom : vzoom coef",
13761 __FILE__,VZoom,group);
13762 theCommands.Add("vpan",
13763 "vpan : vpan dx dy",
13764 __FILE__,VPan,group);
13765 theCommands.Add("vcolorscale",
13766 "vcolorscale name [-noupdate|-update] [-demo]"
13767 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
13768 "\n\t\t: [-font HeightFont=20]"
13769 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
13770 "\n\t\t: [-smoothTransition {on|off}=off]"
13771 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
13772 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
13773 "\n\t\t: [-textpos {left|right|center|none}=right]"
13774 "\n\t\t: [-labelAtBorder {on|off}=on]"
13775 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
13776 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
13777 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
13778 "\n\t\t: [-xy Left=0 Bottom=0]"
13779 "\n\t\t: -demo - displays a color scale with demonstratio values"
13780 "\n\t\t: -colors - set colors for all intervals"
13781 "\n\t\t: -color - set color for specific interval"
13782 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
13783 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
13784 "\n\t\t: at border means the value inbetween neighbor intervals,"
13785 "\n\t\t: at center means the center value within current interval"
13786 "\n\t\t: -labels - set labels for all intervals"
13787 "\n\t\t: -freeLabels - same as -labels but does not require"
13788 "\n\t\t: matching the number of intervals"
13789 "\n\t\t: -label - set label for specific interval"
13790 "\n\t\t: -title - set title"
13791 "\n\t\t: -reversed - setup smooth color transition between intervals"
13792 "\n\t\t: -smoothTransition - swap colorscale direction"
13793 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
13794 __FILE__, VColorScale, group);
13795 theCommands.Add("vgraduatedtrihedron",
13796 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
13797 "\t[-namefont Name] [-valuesfont Name]\n"
13798 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
13799 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
13800 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
13801 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
13802 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
13803 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
13804 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
13805 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
13806 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
13807 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
13808 " - Displays or erases graduated trihedron"
13809 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
13810 " - namefont - font of axes names. Default: Arial\n"
13811 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
13812 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
13813 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
13814 " - valuesfont - font of axes values. Default: Arial\n"
13815 " - xcolor, ycolor, zcolor - color of axis and values\n"
13816 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
13817 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
13818 __FILE__,VGraduatedTrihedron,group);
13819 theCommands.Add("vtile" ,
13820 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
13821 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
13822 "\n\t\t: -totalSize the size of virtual bigger viewport"
13823 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
13824 "\n\t\t: -lowerLeft tile offset as lower left corner"
13825 "\n\t\t: -upperLeft tile offset as upper left corner",
13826 __FILE__, VTile, group);
13827 theCommands.Add("vzlayer",
13828 "vzlayer [layerId]"
13829 "\n\t\t: [-add|-delete|-get|-settings] [-insertBefore AnotherLayer] [-insertAfter AnotherLayer]"
13830 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
13831 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
13832 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv|rayTracing}]"
13833 "\n\t\t: ZLayer list management:"
13834 "\n\t\t: -add add new z layer to viewer and print its id"
13835 "\n\t\t: -insertBefore add new z layer and insert it before existing one"
13836 "\n\t\t: -insertAfter add new z layer and insert it after existing one"
13837 "\n\t\t: -delete delete z layer"
13838 "\n\t\t: -get print sequence of z layers"
13839 "\n\t\t: -settings print status of z layer settings"
13840 "\n\t\t: -disable disables given setting"
13841 "\n\t\t: -enable enables given setting",
13842 __FILE__,VZLayer,group);
13843 theCommands.Add("vlayerline",
13844 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
13845 __FILE__,VLayerLine,group);
13846 theCommands.Add("vgrid",
13847 "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]"
13848 "\n\t\t: [-step X Y] [-size DX DY]"
13849 "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]",
13850 __FILE__, VGrid, group);
13851 theCommands.Add ("vpriviledgedplane",
13852 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
13853 "\n\t\t: Ox, Oy, Oz - plane origin"
13854 "\n\t\t: Nx, Ny, Nz - plane normal direction"
13855 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
13856 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
13857 __FILE__, VPriviledgedPlane, group);
13858 theCommands.Add ("vconvert",
13859 "vconvert v [Mode={window|view}]"
13860 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
13861 "\n\t\t: vconvert x y z [Mode={window|grid}]"
13862 "\n\t\t: window - convert to window coordinates, pixels"
13863 "\n\t\t: view - convert to view projection plane"
13864 "\n\t\t: grid - convert to model coordinates, given on grid"
13865 "\n\t\t: ray - convert projection ray to model coordiantes"
13866 "\n\t\t: - vconvert v window : convert view to window;"
13867 "\n\t\t: - vconvert v view : convert window to view;"
13868 "\n\t\t: - vconvert x y window : convert view to window;"
13869 "\n\t\t: - vconvert x y view : convert window to view;"
13870 "\n\t\t: - vconvert x y : convert window to model;"
13871 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
13872 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
13873 "\n\t\t: - vconvert x y z window : convert model to window;"
13874 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
13875 "\n\t\t: Converts the given coordinates to window/view/model space.",
13876 __FILE__, VConvert, group);
13877 theCommands.Add ("vfps",
13878 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
13879 __FILE__, VFps, group);
13880 theCommands.Add ("vgldebug",
13881 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
13882 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
13883 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
13884 "\n\t\t: Debug context can be requested only on Windows"
13885 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
13886 "\n\t\t: -sync - request synchronized debug GL context"
13887 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
13888 "\n\t\t: which are suppressed by default,"
13889 "\n\t\t: -glslCode - log GLSL program source code,"
13890 "\n\t\t: which are suppressed by default,"
13891 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
13892 "\n\t\t: which are suppressed by default",
13893 __FILE__, VGlDebug, group);
13894 theCommands.Add ("vvbo",
13895 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
13896 __FILE__, VVbo, group);
13897 theCommands.Add ("vstereo",
13898 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
13899 "\n\t\t: [-anaglyph Filter]"
13900 "\n\t\t: Control stereo output mode. Available modes for -mode:"
13901 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
13902 "\n\t\t: requires driver support."
13903 "\n\t\t: Should be called BEFORE vinit!"
13904 "\n\t\t: anaglyph - Anaglyph glasses"
13905 "\n\t\t: rowInterlaced - row-interlaced display"
13906 "\n\t\t: columnInterlaced - column-interlaced display"
13907 "\n\t\t: chessBoard - chess-board output"
13908 "\n\t\t: sideBySide - horizontal pair"
13909 "\n\t\t: overUnder - vertical pair"
13910 "\n\t\t: Available Anaglyph filters for -anaglyph:"
13911 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
13912 "\n\t\t: greenMagentaSimple",
13913 __FILE__, VStereo, group);
13914 theCommands.Add ("vcaps",
13915 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
13916 "\n\t\t: [-compatibleProfile {0|1}]"
13917 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
13918 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
13919 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
13920 "\n\t\t: [-noExtensions {0|1}] [-maxVersion Major Minor]"
13921 "\n\t\t: Modify particular graphic driver options:"
13922 "\n\t\t: FFP - use fixed-function pipeline instead of"
13923 "\n\t\t: built-in GLSL programs"
13924 "\n\t\t: (requires compatible profile)"
13925 "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs"
13926 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
13927 "\n\t\t: arrays to GPU memory)"
13928 "\n\t\t: sprite - use textured sprites instead of bitmaps"
13929 "\n\t\t: vsync - switch VSync on or off"
13930 "\n\t\t: winBuffer - allow using window buffer for rendering"
13931 "\n\t\t: Context creation options:"
13932 "\n\t\t: softMode - software OpenGL implementation"
13933 "\n\t\t: compatibleProfile - backward-compatible profile"
13934 "\n\t\t: quadbuffer - QuadBuffer"
13935 "\n\t\t: noExtensions - disallow usage of extensions"
13936 "\n\t\t: maxVersion - force upper OpenGL version to be used"
13937 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
13938 "\n\t\t: rendering paths producing the same visual result when"
13939 "\n\t\t: possible."
13940 "\n\t\t: Command is intended for testing old hardware compatibility.",
13941 __FILE__, VCaps, group);
13942 theCommands.Add ("vmemgpu",
13943 "vmemgpu [f]: print system-dependent GPU memory information if available;"
13944 " with f option returns free memory in bytes",
13945 __FILE__, VMemGpu, group);
13946 theCommands.Add ("vreadpixel",
13947 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [-name]"
13948 " : Read pixel value for active view",
13949 __FILE__, VReadPixel, group);
13950 theCommands.Add("diffimage",
13951 "diffimage imageFile1 imageFile2 [diffImageFile]"
13952 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
13953 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
13954 "\n\t\t: Compare two images by content and generate difference image."
13955 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
13956 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
13957 __FILE__, VDiffImage, group);
13958 theCommands.Add ("vselect",
13959 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
13960 "- emulates different types of selection:\n"
13961 "- 1) single click selection\n"
13962 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
13963 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
13964 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
13965 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
13966 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
13967 " (partial inclusion - overlap - is not allowed by default)\n"
13968 "- 5) any of these selections with shift button pressed",
13969 __FILE__, VSelect, group);
13970 theCommands.Add ("vmoveto",
13971 "vmoveto [x y] [-reset]"
13972 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
13973 "\n\t\t: -reset resets current highlighting",
13974 __FILE__, VMoveTo, group);
13975 theCommands.Add ("vviewparams",
13976 "vviewparams [-args] [-scale [s]]"
13977 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
13978 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
13979 "\n\t\t: Manage current view parameters or prints all"
13980 "\n\t\t: current values when called without argument."
13981 "\n\t\t: -scale [s] prints or sets viewport relative scale"
13982 "\n\t\t: -eye [x y z] prints or sets eye location"
13983 "\n\t\t: -at [x y z] prints or sets center of look"
13984 "\n\t\t: -up [x y z] prints or sets direction of up vector"
13985 "\n\t\t: -proj [x y z] prints or sets direction of look"
13986 "\n\t\t: -center x y sets location of center of the screen in pixels"
13987 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
13988 "\n\t\t: or changes the size of its maximum dimension"
13989 "\n\t\t: -args prints vviewparams arguments for restoring current view",
13990 __FILE__, VViewParams, group);
13992 theCommands.Add("v2dmode",
13993 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
13994 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
13995 "\n\t\t: mode - switches On/Off rotation mode"
13996 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
13997 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
13998 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
13999 "\n\t\t: View camera position might be changed only by commands.",
14000 __FILE__, V2DMode, group);
14002 theCommands.Add("vanimation", "Alias for vanim",
14003 __FILE__, VAnimation, group);
14005 theCommands.Add("vanim",
14006 "List existing animations:"
14008 "\n\t\t: Animation playback:"
14009 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
14010 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
14011 "\n\t\t: -speed playback speed (1.0 is normal speed)"
14012 "\n\t\t: -freeLook skip camera animations"
14013 "\n\t\t: -lockLoop disable any interactions"
14015 "\n\t\t: Animation definition:"
14016 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
14017 "\n\t\t: [start TimeSec] [duration TimeSec]"
14019 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
14020 "\n\t\t: specifies nested animations."
14021 "\n\t\t: There is no syntax to explicitly add new animation,"
14022 "\n\t\t: and all non-existing animations within the name will be"
14023 "\n\t\t: implicitly created on first use (including parents)."
14025 "\n\t\t: Each animation might define the SINGLE action (see below),"
14026 "\n\t\t: like camera transition, object transformation or custom callback."
14027 "\n\t\t: Child animations can be used for defining concurrent actions."
14029 "\n\t\t: Camera animation:"
14030 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
14031 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
14032 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
14033 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
14034 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
14035 "\n\t\t: -atX camera Center positions pair"
14036 "\n\t\t: -upX camera Up directions pair"
14037 "\n\t\t: -scaleX camera Scale factors pair"
14038 "\n\t\t: Object animation:"
14039 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
14040 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
14041 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
14042 "\n\t\t: -locX object Location points pair (translation)"
14043 "\n\t\t: -rotX object Orientations pair (quaternions)"
14044 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
14045 "\n\t\t: Custom callback:"
14046 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
14047 "\n\t\t: %Pts overall animation presentation timestamp"
14048 "\n\t\t: %LocalPts local animation timestamp"
14049 "\n\t\t: %Normalized local animation normalized value in range 0..1"
14051 "\n\t\t: Video recording:"
14052 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
14053 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
14054 "\n\t\t: [-crf Value] [-preset Preset]"
14055 "\n\t\t: -fps video framerate"
14056 "\n\t\t: -format file format, container (matroska, etc.)"
14057 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
14058 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
14059 "\n\t\t: -crf constant rate factor (specific to codec)"
14060 "\n\t\t: -preset codec parameters preset (specific to codec)"
14061 __FILE__, VAnimation, group);
14063 theCommands.Add("vchangeselected",
14064 "vchangeselected shape"
14065 "- adds to shape to selection or remove one from it",
14066 __FILE__, VChangeSelected, group);
14067 theCommands.Add ("vnbselected",
14069 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
14070 theCommands.Add ("vcamera",
14071 "vcamera [PrsName] [-ortho] [-projtype]"
14073 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
14074 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
14075 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
14076 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
14077 "\n\t\t: Manages camera parameters."
14078 "\n\t\t: Displays frustum when presntation name PrsName is specified."
14079 "\n\t\t: Prints current value when option called without argument."
14080 "\n\t\t: Orthographic camera:"
14081 "\n\t\t: -ortho activate orthographic projection"
14082 "\n\t\t: Perspective camera:"
14083 "\n\t\t: -persp activate perspective projection (mono)"
14084 "\n\t\t: -fovy field of view in y axis, in degrees"
14085 "\n\t\t: -distance distance of eye from camera center"
14086 "\n\t\t: Stereoscopic camera:"
14087 "\n\t\t: -stereo perspective projection (stereo)"
14088 "\n\t\t: -leftEye perspective projection (left eye)"
14089 "\n\t\t: -rightEye perspective projection (right eye)"
14090 "\n\t\t: -iod intraocular distance value"
14091 "\n\t\t: -iodType distance type, absolute or relative"
14092 "\n\t\t: -zfocus stereographic focus value"
14093 "\n\t\t: -zfocusType focus type, absolute or relative",
14094 __FILE__, VCamera, group);
14095 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
14096 "- vautozfit [on={1|0}] [scale]\n"
14097 " Prints or changes parameters of automatic z-fit mode:\n"
14098 " \"on\" - turns automatic z-fit on or off\n"
14099 " \"scale\" - specifies factor to scale computed z range.\n",
14100 __FILE__, VAutoZFit, group);
14101 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
14102 " vzrange - without parameters shows current values\n"
14103 " vzrange [znear] [zfar] - applies provided values to view",
14104 __FILE__,VZRange, group);
14105 theCommands.Add ("vpurgedisplay",
14107 "- removes structures which don't belong to objects displayed in neutral point",
14108 __FILE__, VPurgeDisplay, group);
14109 theCommands.Add("vsetviewsize",
14110 "vsetviewsize size",
14111 __FILE__,VSetViewSize,group);
14112 theCommands.Add("vmoveview",
14113 "vmoveview Dx Dy Dz [Start = 1|0]",
14114 __FILE__,VMoveView,group);
14115 theCommands.Add("vtranslateview",
14116 "vtranslateview Dx Dy Dz [Start = 1|0)]",
14117 __FILE__,VTranslateView,group);
14118 theCommands.Add("vturnview",
14119 "vturnview Ax Ay Az [Start = 1|0]",
14120 __FILE__,VTurnView,group);
14121 theCommands.Add("vtextureenv",
14122 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
14123 "or user-defined file and optionally applying texture mapping parameters\n"
14125 " vtextureenv off - disables environment mapping\n"
14126 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
14127 " std_texture = (0..7)\n"
14128 " rep = {clamp|repeat}\n"
14129 " mod = {decal|modulate}\n"
14130 " flt = {nearest|bilinear|trilinear}\n"
14131 " ss, st - scale factors for s and t texture coordinates\n"
14132 " ts, tt - translation for s and t texture coordinates\n"
14133 " rot - texture rotation angle in degrees",
14134 __FILE__, VTextureEnv, group);
14135 theCommands.Add("vhlr",
14136 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
14137 "\n\t\t: Hidden Line Removal algorithm."
14138 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
14139 "\n\t\t: -algoType type of HLR algorithm.\n",
14140 __FILE__,VHLR,group);
14141 theCommands.Add("vhlrtype",
14142 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
14143 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
14144 "\n\t\t: 'algo' - exact HLR algorithm is applied"
14145 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
14146 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
14147 __FILE__,VHLRType,group);
14148 theCommands.Add("vclipplane",
14149 "vclipplane planeName [{0|1}]"
14150 "\n\t\t: [-equation1 A B C D]"
14151 "\n\t\t: [-equation2 A B C D]"
14152 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
14153 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
14154 "\n\t\t: [-maxPlanes]"
14155 "\n\t\t: [-capping {0|1}]"
14156 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
14157 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
14158 "\n\t\t: [-texRotate Angle]"
14159 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
14160 "\n\t\t: [-useObjShader {0|1}]"
14161 "\n\t\t: Clipping planes management:"
14162 "\n\t\t: -maxPlanes print plane limit for view"
14163 "\n\t\t: -delete delete plane with given name"
14164 "\n\t\t: {off|on|0|1} turn clipping on/off"
14165 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
14166 "\n\t\t: applied to active View when list is omitted"
14167 "\n\t\t: -equation A B C D change plane equation"
14168 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
14169 "\n\t\t: Capping options:"
14170 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
14171 "\n\t\t: -color R G B set capping color"
14172 "\n\t\t: -transparency Value set capping transparency 0..1"
14173 "\n\t\t: -texName Texture set capping texture"
14174 "\n\t\t: -texScale SX SY set capping tex scale"
14175 "\n\t\t: -texOrigin TX TY set capping tex origin"
14176 "\n\t\t: -texRotate Angle set capping tex rotation"
14177 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
14178 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
14179 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
14180 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
14181 __FILE__, VClipPlane, group);
14182 theCommands.Add("vdefaults",
14183 "vdefaults [-absDefl value]"
14184 "\n\t\t: [-devCoeff value]"
14185 "\n\t\t: [-angDefl value]"
14186 "\n\t\t: [-autoTriang {off/on | 0/1}]"
14187 , __FILE__, VDefaults, group);
14188 theCommands.Add("vlight",
14189 "tool to manage light sources, without arguments shows list of lights."
14190 "\n Main commands: "
14191 "\n '-clear' to clear lights"
14192 "\n '-{def}aults' to load deafault lights"
14193 "\n '-add' <type> to add any light source"
14194 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
14195 "\n 'change' <lightId> to edit light source with specified lightId"
14196 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
14198 "\n -{pos}ition X Y Z"
14199 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
14200 "\n -color colorName"
14201 "\n -{head}light 0|1"
14202 "\n -{sm}oothness value"
14203 "\n -{int}ensity value"
14204 "\n -{constAtten}uation value"
14205 "\n -{linearAtten}uation value"
14206 "\n -angle angleDeg"
14207 "\n -{spotexp}onent value"
14208 "\n -local|-global"
14209 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
14210 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
14211 __FILE__, VLight, group);
14212 theCommands.Add("vraytrace",
14214 "\n\t\t: Turns on/off ray-tracing renderer."
14215 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
14216 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
14217 __FILE__, VRenderParams, group);
14218 theCommands.Add("vrenderparams",
14219 "\n Manages rendering parameters: "
14220 "\n '-raster' Disables GPU ray-tracing"
14221 "\n '-msaa 0..4' Specifies number of samples for MSAA"
14222 "\n '-lineFeather > 0' Sets line feather factor"
14223 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
14224 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
14225 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
14226 "\n '-rendScale value Rendering resolution scale factor"
14227 "\n '-rayTrace' Enables GPU ray-tracing"
14228 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
14229 "\n '-shadows on|off' Enables/disables shadows rendering"
14230 "\n '-reflections on|off' Enables/disables specular reflections"
14231 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
14232 "\n '-gleam on|off' Enables/disables transparency shadow effects"
14233 "\n '-gi on|off' Enables/disables global illumination effects"
14234 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
14235 "\n '-env on|off' Enables/disables environment map background"
14236 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
14237 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
14238 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
14239 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
14240 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
14241 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
14242 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
14243 "\n '-shadingModel model' Controls shading model from enumeration"
14244 "\n unlit, flat, gouraud, phong"
14245 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
14246 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
14247 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
14248 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
14249 "\n '-whitepoint value' White point value for filmic tone mapping"
14250 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
14251 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points"
14252 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
14253 "\n Show/hide performance counters (flags can be combined)"
14254 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
14255 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
14256 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
14257 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
14258 "\n set state to check structures culled previously."
14259 "\n Unlike vcaps, these parameters dramatically change visual properties."
14260 "\n Command is intended to control presentation quality depending on"
14261 "\n hardware capabilities and performance.",
14262 __FILE__, VRenderParams, group);
14263 theCommands.Add("vstatprofiler",
14264 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
14265 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
14266 "\n |triagles|points|geomMem|textureMem|frameMem"
14267 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
14268 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
14270 "\n\t\t: Prints rendering statistics."
14271 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
14272 "\n\t\t: else - print all performance counters set previously."
14273 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
14274 __FILE__, VStatProfiler, group);
14275 theCommands.Add ("vplace",
14277 "\n\t\t: Places the point (in pixels) at the center of the window",
14278 __FILE__, VPlace, group);
14279 theCommands.Add("vxrotate",
14281 __FILE__,VXRotate,group);
14283 theCommands.Add("vmanipulator",
14284 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
14285 "\n tool to create and manage AIS manipulators."
14287 "\n '-attach AISObject' attach manipulator to AISObject"
14288 "\n '-adjustPosition {0|1}' adjust position when attaching"
14289 "\n '-adjustSize {0|1}' adjust size when attaching"
14290 "\n '-enableModes {0|1}' enable modes when attaching"
14291 "\n '-view {active | [name of view]}' display manipulator only in defined view,"
14292 "\n by default it is displayed in all views of the current viewer"
14293 "\n '-detach' detach manipulator"
14294 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
14295 "\n '-transform mouse_x mouse_y' - invoke transformation"
14296 "\n '-stopTransform [abort]' - invoke stop of transformation"
14297 "\n '-move x y z' - move attached object"
14298 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
14299 "\n '-scale factor' - scale attached object"
14300 "\n '-autoActivate {0|1}' - set activation on detection"
14301 "\n '-followTranslation {0|1}' - set following translation transform"
14302 "\n '-followRotation {0|1}' - set following rotation transform"
14303 "\n '-followDragging {0|1}' - set following dragging transform"
14304 "\n '-gap value' - set gap between sub-parts"
14305 "\n '-part axis mode {0|1}' - set visual part"
14306 "\n '-parts axis mode {0|1}' - set visual part"
14307 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
14308 "\n '-size value' - set size of manipulator"
14309 "\n '-zoomable {0|1}' - set zoom persistence",
14310 __FILE__, VManipulator, group);
14312 theCommands.Add("vselprops",
14313 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
14314 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
14315 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
14316 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
14317 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
14318 "\n -pickStrategy {first|topmost} : defines picking strategy"
14319 "\n 'first' to pick first acceptable (default)"
14320 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
14321 "\n -pixTol value : sets up pixel tolerance"
14322 "\n -dispMode dispMode : sets display mode for highlighting"
14323 "\n -layer ZLayer : sets ZLayer for highlighting"
14324 "\n -color {name|r g b} : sets highlight color"
14325 "\n -transp value : sets transparency coefficient for highlight"
14326 "\n -material material : sets highlight material"
14327 "\n -print : prints current state of all mentioned parameters",
14328 __FILE__, VSelectionProperties, group);
14329 theCommands.Add ("vhighlightselected",
14330 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
14331 __FILE__, VSelectionProperties, group);
14333 theCommands.Add ("vseldump",
14334 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
14335 "\n\t\t: Generate an image based on detection results:"
14336 "\n\t\t: depth normalized depth values"
14337 "\n\t\t: unnormDepth unnormalized depth values"
14338 "\n\t\t: object color of detected object"
14339 "\n\t\t: owner color of detected owner"
14340 "\n\t\t: selMode color of selection mode"
14341 "\n\t\t: entity color of etected entity",
14342 __FILE__, VDumpSelectionImage, group);
14344 theCommands.Add ("vviewcube",
14346 "\n\t\t: Displays interactive view manipualtion object."
14347 "\n\t\t: Options: "
14348 "\n\t\t: -reset reset geomertical and visual attributes'"
14349 "\n\t\t: -size Size adapted size of View Cube"
14350 "\n\t\t: -boxSize Size box size"
14351 "\n\t\t: -axes {0|1 } show/hide axes (trihedron)"
14352 "\n\t\t: -edges {0|1} show/hide edges of View Cube"
14353 "\n\t\t: -vertices {0|1} show/hide vertices of View Cube"
14354 "\n\t\t: -Yup {0|1} -Zup {0|1} set Y-up or Z-up view orientation"
14355 "\n\t\t: -color Color color of View Cube"
14356 "\n\t\t: -boxColor Color box color"
14357 "\n\t\t: -boxSideColor Color box sides color"
14358 "\n\t\t: -boxEdgeColor Color box edges color"
14359 "\n\t\t: -boxCornerColor Color box corner color"
14360 "\n\t\t: -textColor Color color of side text of view cube"
14361 "\n\t\t: -innerColor Color inner box color"
14362 "\n\t\t: -transparency Value transparency of object within [0, 1] range"
14363 "\n\t\t: -boxTransparency Value transparency of box within [0, 1] range"
14364 "\n\t\t: -font Name font name"
14365 "\n\t\t: -fontHeight Value font height"
14366 "\n\t\t: -boxFacetExtension Value box facet extension"
14367 "\n\t\t: -boxEdgeGap Value gap between box edges and box sides"
14368 "\n\t\t: -boxEdgeMinSize Value minimal box edge size"
14369 "\n\t\t: -boxCornerMinSize Value minimal box corner size"
14370 "\n\t\t: -axesPadding Value padding between box and arrows"
14371 "\n\t\t: -roundRadius Value relative radius of corners of sides within [0.0, 0.5] range"
14372 "\n\t\t: -fixedanimation {0|1} uninterruptible animation loop"
14373 "\n\t\t: -duration Seconds animation duration in seconds",
14374 __FILE__, VViewCube, group);