0030905: Modeling Algorithms - Faulty shapes in UnifySameDomain
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
CommitLineData
b311480e 1// Created on: 1998-09-01
2// Created by: Robert COUBLANC
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
58655684 17#include <OpenGl_GlCore20.hxx>
49582f9d 18#include <ViewerTest.hxx>
1beb58d7 19
1beb58d7 20#include <AIS_AnimationCamera.hxx>
21#include <AIS_AnimationObject.hxx>
30a1b24e 22#include <AIS_CameraFrustum.hxx>
7a324550 23#include <AIS_ColorScale.hxx>
49582f9d 24#include <AIS_InteractiveContext.hxx>
0a768f56 25#include <AIS_ListOfInteractive.hxx>
26#include <AIS_ListIteratorOfListOfInteractive.hxx>
49582f9d 27#include <AIS_Manipulator.hxx>
2108d9a2 28#include <AIS_ViewCube.hxx>
49582f9d 29#include <AIS_Shape.hxx>
30#include <Aspect_DisplayConnection.hxx>
8a590580 31#include <Aspect_Grid.hxx>
49582f9d 32#include <Aspect_TypeOfLine.hxx>
33#include <Draw.hxx>
34#include <Draw_Appli.hxx>
35#include <Draw_Interpretor.hxx>
08f8a185 36#include <Draw_ProgressIndicator.hxx>
49582f9d 37#include <gp_Dir.hxx>
38#include <gp_Pln.hxx>
39#include <gp_Pnt.hxx>
61b0191c 40#include <Graphic3d_ArrayOfPolylines.hxx>
49582f9d 41#include <Graphic3d_AspectFillArea3d.hxx>
2bd4c032 42#include <Graphic3d_AspectMarker3d.hxx>
49582f9d 43#include <Graphic3d_ClipPlane.hxx>
a79f67f8 44#include <Graphic3d_GraduatedTrihedron.hxx>
49582f9d 45#include <Graphic3d_NameOfTextureEnv.hxx>
46#include <Graphic3d_Texture2Dmanual.hxx>
269294d6 47#include <Graphic3d_TextureEnv.hxx>
48#include <Graphic3d_TextureParams.hxx>
49#include <Graphic3d_TypeOfTextureFilter.hxx>
49582f9d 50#include <Image_AlienPixMap.hxx>
51#include <Image_Diff.hxx>
52#include <Image_VideoRecorder.hxx>
08f8a185 53#include <Message_ProgressSentry.hxx>
49582f9d 54#include <NCollection_DataMap.hxx>
18d715bd 55#include <NCollection_List.hxx>
56#include <NCollection_Vector.hxx>
8693dfd0 57#include <OSD.hxx>
208e6839 58#include <OSD_Timer.hxx>
49582f9d 59#include <OpenGl_GraphicDriver.hxx>
4269bd1b 60#include <Prs3d_ShadingAspect.hxx>
6262338c 61#include <Prs3d_Drawer.hxx>
61b0191c 62#include <Prs3d_LineAspect.hxx>
63#include <Prs3d_Root.hxx>
fd3f6bd0 64#include <Prs3d_Text.hxx>
65#include <Select3D_SensitivePrimitiveArray.hxx>
49582f9d 66#include <TColStd_HSequenceOfAsciiString.hxx>
67#include <TColStd_SequenceOfInteger.hxx>
68#include <TColStd_HSequenceOfReal.hxx>
69#include <TColgp_Array1OfPnt2d.hxx>
70#include <TColStd_MapOfAsciiString.hxx>
71#include <ViewerTest_AutoUpdater.hxx>
72#include <ViewerTest_EventManager.hxx>
73#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
74#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
75#include <ViewerTest_CmdParser.hxx>
76#include <ViewerTest_V3dView.hxx>
77#include <V3d_AmbientLight.hxx>
78#include <V3d_DirectionalLight.hxx>
79#include <V3d_PositionalLight.hxx>
80#include <V3d_SpotLight.hxx>
7fd59977 81
293211ae 82#include <tcl.h>
83
692613e5 84#include <cstdlib>
25289ec1 85
58655684 86#if defined(_WIN32)
4fe56619 87 #include <WNT_WClass.hxx>
88 #include <WNT_Window.hxx>
4fe56619 89#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 90 #include <Cocoa_Window.hxx>
7fd59977 91#else
4fe56619 92 #include <Xw_Window.hxx>
93 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
94 #include <X11/Xutil.h>
95 #include <tk.h>
7fd59977 96#endif
97
7fd59977 98//==============================================================================
99// VIEWER GLOBAL VARIABLES
100//==============================================================================
101
102Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
b514beda 103Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
7fd59977 104
105Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
4754e164 106extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
7fd59977 107
58655684 108#if defined(_WIN32)
7fd59977 109static Handle(WNT_Window)& VT_GetWindow() {
110 static Handle(WNT_Window) WNTWin;
111 return WNTWin;
112}
4fe56619 113#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 114static Handle(Cocoa_Window)& VT_GetWindow()
115{
116 static Handle(Cocoa_Window) aWindow;
117 return aWindow;
118}
119extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
18d715bd 120extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
121
7fd59977 122#else
7fd59977 123static Handle(Xw_Window)& VT_GetWindow(){
124 static Handle(Xw_Window) XWWin;
125 return XWWin;
126}
7fd59977 127
128static void VProcessEvents(ClientData,int);
129#endif
130
18d715bd 131static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
132{
133 static Handle(Aspect_DisplayConnection) aDisplayConnection;
134 return aDisplayConnection;
135}
136
137static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
138{
139 GetDisplayConnection() = theDisplayConnection;
140}
141
18d715bd 142NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
58655684 143static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
18d715bd 144static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
58655684 145static OpenGl_Caps ViewerTest_myDefaultCaps;
18d715bd 146
7fd59977 147static void OSWindowSetup();
148
f42753ed 149static struct
150{
151 Quantity_Color FlatColor;
152 Quantity_Color GradientColor1;
153 Quantity_Color GradientColor2;
154 Aspect_GradientFillMethod FillMethod;
155} ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
156
7fd59977 157//==============================================================================
158// EVENT GLOBAL VARIABLES
159//==============================================================================
160
1beb58d7 161Standard_Boolean TheIsAnimating = Standard_False;
7fd59977 162
293211ae 163namespace
164{
165
166 //! Checks if some set is a subset of other set
167 //! @tparam TheSuperSet the type of the superset
168 //! @tparam TheSubSet the type of the subset
169 //! @param theSuperSet the superset
170 //! @param theSubSet the subset to be checked
171 //! @return true if the superset includes subset, or false otherwise
172 template <typename TheSuperSet, typename TheSubSet>
173 static bool includes (const TheSuperSet& theSuperSet, const TheSubSet& theSubSet)
174 {
175 return std::includes (theSuperSet.begin(), theSuperSet.end(), theSubSet.begin(), theSubSet.end());
176 }
177
178 //! A variable set of keys for command-line options.
179 //! It includes a set of mandatory keys and a set of all possible keys.
180 class CommandOptionKeyVariableSet
181 {
182 public:
183 //! Default constructor
184 CommandOptionKeyVariableSet()
185 {
186 }
187
188 //! Constructor
189 //! @param theMandatoryKeySet the set of the mandatory option keys
190 //! @param theAdditionalKeySet the set of additional options that could be omitted
191 CommandOptionKeyVariableSet (
192 const ViewerTest_CommandOptionKeySet& theMandatoryKeySet,
193 const ViewerTest_CommandOptionKeySet& theAdditionalKeySet = ViewerTest_CommandOptionKeySet())
194 : myMandatoryKeySet (theMandatoryKeySet)
195 {
196 std::set_union (theMandatoryKeySet.begin(),
197 theMandatoryKeySet.end(),
198 theAdditionalKeySet.begin(),
199 theAdditionalKeySet.end(),
200 std::inserter (myFullKeySet, myFullKeySet.begin()));
201 }
202
203 //! Checks if the set of option keys fits to the current variable set (it must contain all mandatory keys
204 //! and be contained in the full key set)
205 //! @param theCheckedKeySet the set of option keys to be checked
206 bool IsInSet (const ViewerTest_CommandOptionKeySet& theCheckedKeySet) const
207 {
208 return includes (theCheckedKeySet, myMandatoryKeySet) && includes (myFullKeySet, theCheckedKeySet);
209 }
210
211 private:
212 //! A set of mandatory command-line option keys
213 ViewerTest_CommandOptionKeySet myMandatoryKeySet;
214
215 //! A full set of command-line option keys (includes mandatory and additional option keys)
216 ViewerTest_CommandOptionKeySet myFullKeySet;
217 };
218
219 //! Gets some code by its name
220 //! @tparam TheCode the type of a code to be found
221 //! @param theCodeNameMap the map from code names to codes
222 //! @param theCodeName the name of a code to be found
223 //! @param theCode the code to be found
224 //! @return true if a code is found, or false otherwise
225 template <typename TheCode>
226 static bool getSomeCodeByName (const std::map<TCollection_AsciiString, TheCode>& theCodeNameMap,
227 TCollection_AsciiString theCodeName,
228 TheCode& theCode)
229 {
230 theCodeName.LowerCase();
231 const typename std::map<TCollection_AsciiString, TheCode>::const_iterator aCodeIterator = theCodeNameMap.find (
232 theCodeName);
233 if (aCodeIterator == theCodeNameMap.end())
234 {
235 return false;
236 }
237 theCode = aCodeIterator->second;
238 return true;
239 }
240
241 // Defines possible commands related to background changing
242 enum BackgroundCommand
243 {
244 BackgroundCommand_Main, //!< The main command that manages other commands through options
245 BackgroundCommand_Image, //!< Sets an image as a background
246 BackgroundCommand_ImageMode, //!< Changes a background image mode
247 BackgroundCommand_Gradient, //!< Sets a gradient as a background
248 BackgroundCommand_GradientMode, //!< Changes a background gradient mode
249 BackgroundCommand_Color, //!< Fills background with a specified color
250 BackgroundCommand_Default //!< Sets the background default color or gradient
251 };
252
253 //! Map from background command names to its codes
254 typedef std::map<TCollection_AsciiString, BackgroundCommand> BackgroundCommandNameMap;
255
256 //! Creates a map from background command names to its codes
257 //! @return a map from background command names to its codes
258 static BackgroundCommandNameMap createBackgroundCommandNameMap()
259 {
260 BackgroundCommandNameMap aBackgroundCommandNameMap;
261 aBackgroundCommandNameMap["vbackground"] = BackgroundCommand_Main;
262 aBackgroundCommandNameMap["vsetbg"] = BackgroundCommand_Image;
263 aBackgroundCommandNameMap["vsetbgmode"] = BackgroundCommand_ImageMode;
264 aBackgroundCommandNameMap["vsetgradientbg"] = BackgroundCommand_Gradient;
265 aBackgroundCommandNameMap["vsetgrbgmode"] = BackgroundCommand_GradientMode;
266 aBackgroundCommandNameMap["vsetcolorbg"] = BackgroundCommand_Color;
267 aBackgroundCommandNameMap["vsetdefaultbg"] = BackgroundCommand_Default;
268 return aBackgroundCommandNameMap;
269 }
270
271 //! Gets a background command by its name
272 //! @param theBackgroundCommandName the name of the background command
273 //! @param theBackgroundCommand the background command to be found
274 //! @return true if a background command is found, or false otherwise
275 static bool getBackgroundCommandByName (const TCollection_AsciiString& theBackgroundCommandName,
276 BackgroundCommand& theBackgroundCommand)
277 {
278 static const BackgroundCommandNameMap THE_BACKGROUND_COMMAND_NAME_MAP = createBackgroundCommandNameMap();
279 return getSomeCodeByName (THE_BACKGROUND_COMMAND_NAME_MAP, theBackgroundCommandName, theBackgroundCommand);
280 }
281
282 //! Map from background image fill method names to its codes
283 typedef std::map<TCollection_AsciiString, Aspect_FillMethod> BackgroundImageFillMethodNameMap;
284
285 //! Creates a map from background image fill method names to its codes
286 //! @return a map from background image fill method names to its codes
287 static BackgroundImageFillMethodNameMap createBackgroundImageFillMethodNameMap()
288 {
289 BackgroundImageFillMethodNameMap aBackgroundImageFillMethodNameMap;
290 aBackgroundImageFillMethodNameMap["none"] = Aspect_FM_NONE;
291 aBackgroundImageFillMethodNameMap["centered"] = Aspect_FM_CENTERED;
292 aBackgroundImageFillMethodNameMap["tiled"] = Aspect_FM_TILED;
293 aBackgroundImageFillMethodNameMap["stretch"] = Aspect_FM_STRETCH;
294 return aBackgroundImageFillMethodNameMap;
295 }
296
297 //! Gets a background image fill method by its name
298 //! @param theBackgroundImageFillMethodName the name of the background image fill method
299 //! @param theBackgroundImageFillMethod the background image fill method to be found
300 //! @return true if a background image fill method is found, or false otherwise
301 static bool getBackgroundImageFillMethodByName (const TCollection_AsciiString& theBackgroundImageFillMethodName,
302 Aspect_FillMethod& theBackgroundImageFillMethod)
303 {
304 static const BackgroundImageFillMethodNameMap THE_BACKGROUND_IMAGE_FILL_METHOD_NAME_MAP =
305 createBackgroundImageFillMethodNameMap();
306 return getSomeCodeByName (THE_BACKGROUND_IMAGE_FILL_METHOD_NAME_MAP,
307 theBackgroundImageFillMethodName,
308 theBackgroundImageFillMethod);
309 }
310
311 //! Map from background gradient fill method names to its codes
312 typedef std::map<TCollection_AsciiString, Aspect_GradientFillMethod> BackgroundGradientFillMethodNameMap;
313
314 //! Creates a map from background gradient fill method names to its codes
315 //! @return a map from background gradient fill method names to its codes
316 static BackgroundGradientFillMethodNameMap createBackgroundGradientFillMethodNameMap()
317 {
318 BackgroundGradientFillMethodNameMap aBackgroundGradientFillMethodNameMap;
319 aBackgroundGradientFillMethodNameMap["none"] = Aspect_GFM_NONE;
320 aBackgroundGradientFillMethodNameMap["hor"] = Aspect_GFM_HOR;
321 aBackgroundGradientFillMethodNameMap["horizontal"] = Aspect_GFM_HOR;
322 aBackgroundGradientFillMethodNameMap["ver"] = Aspect_GFM_VER;
323 aBackgroundGradientFillMethodNameMap["vertical"] = Aspect_GFM_VER;
324 aBackgroundGradientFillMethodNameMap["diag1"] = Aspect_GFM_DIAG1;
325 aBackgroundGradientFillMethodNameMap["diagonal1"] = Aspect_GFM_DIAG1;
326 aBackgroundGradientFillMethodNameMap["diag2"] = Aspect_GFM_DIAG2;
327 aBackgroundGradientFillMethodNameMap["diagonal2"] = Aspect_GFM_DIAG2;
328 aBackgroundGradientFillMethodNameMap["corner1"] = Aspect_GFM_CORNER1;
329 aBackgroundGradientFillMethodNameMap["corner2"] = Aspect_GFM_CORNER2;
330 aBackgroundGradientFillMethodNameMap["corner3"] = Aspect_GFM_CORNER3;
331 aBackgroundGradientFillMethodNameMap["corner4"] = Aspect_GFM_CORNER4;
332 return aBackgroundGradientFillMethodNameMap;
333 }
334
335 //! Gets a gradient fill method by its name
336 //! @param theBackgroundGradientFillMethodName the name of the gradient fill method
337 //! @param theBackgroundGradientFillMethod the gradient fill method to be found
338 //! @return true if a gradient fill method is found, or false otherwise
339 static bool getBackgroundGradientFillMethodByName (const TCollection_AsciiString& theBackgroundGradientFillMethodName,
340 Aspect_GradientFillMethod& theBackgroundGradientFillMethod)
341 {
342 static const BackgroundGradientFillMethodNameMap THE_BACKGROUND_GRADIENT_FILL_METHOD_NAME_MAP =
343 createBackgroundGradientFillMethodNameMap();
344 return getSomeCodeByName (THE_BACKGROUND_GRADIENT_FILL_METHOD_NAME_MAP,
345 theBackgroundGradientFillMethodName,
346 theBackgroundGradientFillMethod);
347 }
348
349 //! Changes the background in accordance with passed command line options
350 class BackgroundChanger
351 {
352 public:
353 //! Constructor. Prepares the command parser
354 BackgroundChanger()
355 {
356 prepareCommandParser();
357 }
358
359 //! Processes the command line and changes the background
360 //! @param theDrawInterpretor the interpreter of the Draw Harness application
361 //! @param theNumberOfCommandLineArguments the number of passed command line arguments
362 //! @param theCommandLineArguments the array of command line arguments
363 bool ProcessCommandLine (Draw_Interpretor& theDrawInterpretor,
364 const Standard_Integer theNumberOfCommandLineArguments,
365 const char* const* const theCommandLineArguments)
366 {
367 const char* const aBackgroundCommandName = theCommandLineArguments[0];
368 BackgroundCommand aBackgroundCommand = BackgroundCommand_Main;
369 if (!getBackgroundCommandByName (aBackgroundCommandName, aBackgroundCommand))
370 {
371 return false;
372 }
373 addCommandDescription (aBackgroundCommand);
374 myCommandParser.Parse (theNumberOfCommandLineArguments, theCommandLineArguments);
375 return processCommandOptions (aBackgroundCommandName, aBackgroundCommand, theDrawInterpretor);
376 }
377
378 private:
379 //! The type of functions that are able to set gradient background filling
380 typedef void SetGradientFunction (const Quantity_Color& /* theColor1 */,
381 const Quantity_Color& /* theColor2 */,
382 const Aspect_GradientFillMethod /* theGradientMode */);
383
384 //! The type of functions that are able to fill a background with a specific color
385 typedef void SetColorFunction (const Quantity_Color& /* theColor */);
386
387 //! the command parser used to parse command line options and its arguments
388 ViewerTest_CmdParser myCommandParser;
389
390 //! the option key for the command that sets an image as a background
391 ViewerTest_CommandOptionKey myImageOptionKey;
392
393 //! the option key for the command that sets a background image fill type
394 ViewerTest_CommandOptionKey myImageModeOptionKey;
395
396 //! the option key for the command that sets a gradient filling for the background
397 ViewerTest_CommandOptionKey myGradientOptionKey;
398
399 //! the option key for the command that sets a background gradient filling method
400 ViewerTest_CommandOptionKey myGradientModeOptionKey;
401
402 //! the option key for the command that fills background with a specific color
403 ViewerTest_CommandOptionKey myColorOptionKey;
404
405 //! the option key for the command that sets default background gradient or color
406 ViewerTest_CommandOptionKey myDefaultOptionKey;
407
408 //! the variable set of options that are allowed for the old scenario (without any option passed)
409 CommandOptionKeyVariableSet myUnnamedOptionVariableSet;
410
411 //! the variable set of options that are allowed for setting an image as a background
412 CommandOptionKeyVariableSet myImageOptionVariableSet;
413
414 //! the variable set of options that are allowed for setting a background image fill type
415 CommandOptionKeyVariableSet myImageModeOptionVariableSet;
416
417 //! the variable set of options that are allowed for setting a gradient filling for the background
418 CommandOptionKeyVariableSet myGradientOptionVariableSet;
419
420 //! the variable set of options that are allowed for setting a background gradient filling method
421 CommandOptionKeyVariableSet myGradientModeOptionVariableSet;
422
423 //! the variable set of options that are allowed for filling a background with a specific color
424 CommandOptionKeyVariableSet myColorOptionVariableSet;
425
426 //! the variable set of options that are allowed for setting a default background gradient
427 CommandOptionKeyVariableSet myDefaultGradientOptionVariableSet;
428
429 //! the variable set of options that are allowed for setting a default background color
430 CommandOptionKeyVariableSet myDefaultColorOptionVariableSet;
431
432 //! the variable set of options that are allowed for printing help
433 CommandOptionKeyVariableSet myHelpOptionVariableSet;
434
435 //! Adds options to command parser
436 void addOptionsToCommandParser()
437 {
438 myImageOptionKey = myCommandParser.AddOption ("imageFile|image|imgFile|img",
439 "filename of image used as background");
440 myImageModeOptionKey = myCommandParser.AddOption (
441 "imageMode|imgMode", "image fill type, should be one of CENTERED, TILED, STRETCH, NONE");
442 myGradientOptionKey = myCommandParser.AddOption ("gradient|grad|gr",
443 "sets background gradient starting and ending colors");
444 myGradientModeOptionKey =
445 myCommandParser.AddOption ("gradientMode|gradMode|gradMd|grMode|grMd",
446 "gradient fill method, should be one of NONE, HOR[IZONTAL], VER[TICAL], "
447 "DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, CORNER4");
448 myColorOptionKey = myCommandParser.AddOption ("color|col", "background color");
449 myDefaultOptionKey = myCommandParser.AddOption ("default|def", "sets background default gradient or color");
450 }
451
452 //! Creates option sets used to determine if a passed option set is valid or not
453 void createOptionSets()
454 {
455 ViewerTest_CommandOptionKeySet anUnnamedOptionSet;
456 anUnnamedOptionSet.insert (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
457 myUnnamedOptionVariableSet = CommandOptionKeyVariableSet (anUnnamedOptionSet);
458
459 ViewerTest_CommandOptionKeySet anImageOptionSet;
460 anImageOptionSet.insert (myImageOptionKey);
461 ViewerTest_CommandOptionKeySet anImageModeOptionSet;
462 anImageModeOptionSet.insert (myImageModeOptionKey);
463 myImageOptionVariableSet = CommandOptionKeyVariableSet (anImageOptionSet, anImageModeOptionSet);
464 myImageModeOptionVariableSet = CommandOptionKeyVariableSet (anImageModeOptionSet);
465
466 ViewerTest_CommandOptionKeySet aGradientOptionSet;
467 aGradientOptionSet.insert (myGradientOptionKey);
468 ViewerTest_CommandOptionKeySet aGradientModeOptionSet;
469 aGradientModeOptionSet.insert (myGradientModeOptionKey);
470 myGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet);
471 myGradientModeOptionVariableSet = CommandOptionKeyVariableSet (aGradientModeOptionSet);
472
473 ViewerTest_CommandOptionKeySet aColorOptionSet;
474 aColorOptionSet.insert (myColorOptionKey);
475 myColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet);
476
477 aGradientOptionSet.insert (myDefaultOptionKey);
478 myDefaultGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet);
479 aColorOptionSet.insert (myDefaultOptionKey);
480 myDefaultColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet);
481
482 ViewerTest_CommandOptionKeySet aHelpOptionSet;
483 aHelpOptionSet.insert (ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY);
484 myHelpOptionVariableSet = CommandOptionKeyVariableSet (aHelpOptionSet);
485 }
486
487 //! Prepares the command parser. Adds options and creates option sets used to determine
488 //! if a passed option set is valid or not
489 void prepareCommandParser()
490 {
491 addOptionsToCommandParser();
492 createOptionSets();
493 }
494
495 //! Adds a command description to the command parser
496 //! @param theBackgroundCommand the key of the command which description is added to the command parser
497 void addCommandDescription (const BackgroundCommand theBackgroundCommand)
498 {
499 std::string aDescription;
500 bool isMainCommand = false;
501 switch (theBackgroundCommand)
502 {
503 case BackgroundCommand_Main:
504 aDescription = "Command: vbackground (changes background or some background settings)";
505 isMainCommand = true;
506 break;
507 case BackgroundCommand_Image:
508 aDescription = "Command: vsetbg (loads image as a background)";
509 break;
510 case BackgroundCommand_ImageMode:
511 aDescription = "Command: vsetbgmode (changes background fill type)";
512 break;
513 case BackgroundCommand_Gradient:
514 aDescription = "Command: vsetgradientbg (mounts gradient background)";
515 break;
516 case BackgroundCommand_GradientMode:
517 aDescription = "Command: vsetgradientbgmode (changes gradient background fill method)";
518 break;
519 case BackgroundCommand_Color:
520 aDescription = "Command: vsetcolorbg (sets color background)";
521 break;
522 case BackgroundCommand_Default:
523 aDescription = "Command: vsetdefaultbg (sets default viewer background gradient or fill color)";
524 break;
525 default:
526 return;
527 }
528 if (!isMainCommand)
529 {
530 aDescription += "\nThis command is obsolete. Use vbackground instead.";
531 }
532 myCommandParser.SetDescription (aDescription);
533 }
534
535 //! Check if a viewer is needed to be initialized
536 //! @param theBackgroundCommand the key of the command that changes the background
537 //! @return true if processing was successful, or false otherwise
538 bool checkViewerIsNeeded (const BackgroundCommand theBackgroundCommand) const
539 {
540 const bool isMain = (theBackgroundCommand == BackgroundCommand_Main);
541 const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions();
542 const bool aViewerIsNotNeeded =
543 (theBackgroundCommand == BackgroundCommand_Default)
544 || (myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain)
545 || (myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain)
546 || myHelpOptionVariableSet.IsInSet (aUsedOptions);
547 return !aViewerIsNotNeeded;
548 }
549
550 //! Check if a viewer is initialized
551 //! @param theBackgroundCommandName the name of the command that changes the background
552 //! @param theDrawInterpretor the interpreter of the Draw Harness application
553 //! @return true if a viewer is initialized, or false otherwise
554 static bool checkViewerIsInitialized (const char* const theBackgroundCommandName,
555 Draw_Interpretor& theDrawInterpretor)
556 {
557 const Handle (AIS_InteractiveContext)& anAISContext = ViewerTest::GetAISContext();
558 if (anAISContext.IsNull())
559 {
560 theDrawInterpretor << "Use 'vinit' command before executing '" << theBackgroundCommandName << "' command.\n";
561 return false;
562 }
563 return true;
564 }
565
566 //! Processes command options
567 //! @param theBackgroundCommandName the name of the command that changes the background
568 //! @param theBackgroundCommand the key of the command that changes the background
569 //! @param theDrawInterpretor the interpreter of the Draw Harness application
570 //! @return true if processing was successful, or false otherwise
571 bool processCommandOptions (const char* const theBackgroundCommandName,
572 const BackgroundCommand theBackgroundCommand,
573 Draw_Interpretor& theDrawInterpretor) const
574 {
575 if (myCommandParser.HasNoOption())
576 {
577 return printHelp (theBackgroundCommandName, theDrawInterpretor);
578 }
579 if (checkViewerIsNeeded (theBackgroundCommand)
580 && !checkViewerIsInitialized (theBackgroundCommandName, theDrawInterpretor))
581 {
582 return false;
583 }
584 if (myCommandParser.HasOnlyUnnamedOption())
585 {
586 return processUnnamedOption (theBackgroundCommand);
587 }
588 return processNamedOptions (theBackgroundCommandName, theBackgroundCommand, theDrawInterpretor);
589 }
590
591 //! Processes the unnamed option
592 //! @param theBackgroundCommand the key of the command that changes the background
593 //! @return true if processing was successful, or false otherwise
594 bool processUnnamedOption (const BackgroundCommand theBackgroundCommand) const
595 {
596 switch (theBackgroundCommand)
597 {
598 case BackgroundCommand_Main:
599 return false;
600 case BackgroundCommand_Image:
601 return processImageUnnamedOption();
602 case BackgroundCommand_ImageMode:
603 return processImageModeUnnamedOption();
604 case BackgroundCommand_Gradient:
605 return processGradientUnnamedOption();
606 case BackgroundCommand_GradientMode:
607 return processGradientModeUnnamedOption();
608 case BackgroundCommand_Color:
609 return processColorUnnamedOption();
610 case BackgroundCommand_Default:
611 return processDefaultUnnamedOption();
612 default:
613 return false;
614 }
615 }
616
617 //! Processes the image unnamed option
618 //! @return true if processing was successful, or false otherwise
619 bool processImageUnnamedOption() const
620 {
621 const std::size_t aNumberOfImageUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments (
622 ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
623 if ((aNumberOfImageUnnamedOptionArguments != 1) && (aNumberOfImageUnnamedOptionArguments != 2))
624 {
625 return false;
626 }
627 std::string anImageFileName;
628 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0, anImageFileName))
629 {
630 return false;
631 }
632 Aspect_FillMethod anImageMode = Aspect_FM_CENTERED;
633 if (aNumberOfImageUnnamedOptionArguments == 2)
634 {
635 std::string anImageModeString;
636 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 1, anImageModeString))
637 {
638 return false;
639 }
640 if (!getBackgroundImageFillMethodByName (anImageModeString.c_str(), anImageMode))
641 {
642 return false;
643 }
644 }
645 setImage (anImageFileName.c_str(), anImageMode);
646 return true;
647 }
648
649 //! Processes the image mode unnamed option
650 //! @return true if processing was successful, or false otherwise
651 bool processImageModeUnnamedOption() const
652 {
653 return processImageModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
654 }
655
656 //! Processes the gradient unnamed option
657 //! @param theSetGradient the function used to set a background gradient filling
658 //! @return true if processing was successful, or false otherwise
659 bool processGradientUnnamedOption (SetGradientFunction* const theSetGradient = setGradient) const
660 {
661 const Standard_Integer aNumberOfGradientUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments (
662 ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
663 if (aNumberOfGradientUnnamedOptionArguments < 2)
664 {
665 return false;
666 }
667
668 Standard_Integer anArgumentIndex = 0;
669 Quantity_Color aColor1;
670 if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor1))
671 {
672 return false;
673 }
674 if (anArgumentIndex >= aNumberOfGradientUnnamedOptionArguments)
675 {
676 return false;
677 }
678
679 Quantity_Color aColor2;
680 if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor2))
681 {
682 return false;
683 }
684 if (anArgumentIndex > aNumberOfGradientUnnamedOptionArguments)
685 {
686 return false;
687 }
688
689 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR;
690 if (anArgumentIndex == aNumberOfGradientUnnamedOptionArguments - 1)
691 {
692 std::string anGradientModeString;
693
694 if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY,
695 anArgumentIndex,
696 anGradientModeString))
697 {
698 return false;
699 }
700 if (!getBackgroundGradientFillMethodByName (anGradientModeString.c_str(), aGradientMode))
701 {
702 return false;
703 }
704 ++anArgumentIndex;
705 }
706 if (anArgumentIndex != aNumberOfGradientUnnamedOptionArguments)
707 {
708 return false;
709 }
710 theSetGradient (aColor1, aColor2, aGradientMode);
711 return true;
712 }
713
714 //! Processes the gradient mode unnamed option
715 //! @return true if processing was successful, or false otherwise
716 bool processGradientModeUnnamedOption() const
717 {
718 return processGradientModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
719 }
720
721 //! Processes the color unnamed option
722 //! @param theSetColor the function used to set a background color
723 //! @return true if processing was successful, or false otherwise
724 bool processColorUnnamedOption (SetColorFunction* const theSetColor = setColor) const
725 {
726 return processColorOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, theSetColor);
727 }
728
729 //! Processes the default back unnamed option
730 //! @return true if processing was successful, or false otherwise
731 bool processDefaultUnnamedOption() const
732 {
733 if (processGradientUnnamedOption (setDefaultGradient))
734 {
735 return true;
736 }
737 return processColorUnnamedOption (setDefaultColor);
738 }
739
740 //! Processes named options
741 //! @param theBackgroundCommandName the name of the command that changes the background
742 //! @param theBackgroundCommand the key of the command that changes the background
743 //! @param theDrawInterpretor the interpreter of the Draw Harness application
744 //! @return true if processing was successful, or false otherwise
745 bool processNamedOptions (const char* const theBackgroundCommandName,
746 const BackgroundCommand theBackgroundCommand,
747 Draw_Interpretor& theDrawInterpretor) const
748 {
749 const bool isMain = (theBackgroundCommand == BackgroundCommand_Main);
750 const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions();
751 if (myImageOptionVariableSet.IsInSet (aUsedOptions)
752 && (isMain || (theBackgroundCommand == BackgroundCommand_Image)))
753 {
754 return processImageOptionSet();
755 }
756 if (myImageModeOptionVariableSet.IsInSet (aUsedOptions)
757 && (isMain || (theBackgroundCommand == BackgroundCommand_ImageMode)))
758 {
759 return processImageModeOptionSet();
760 }
761 if (myGradientOptionVariableSet.IsInSet (aUsedOptions)
762 && (isMain || (theBackgroundCommand == BackgroundCommand_Gradient)))
763 {
764 return processGradientOptionSet();
765 }
766 if (myGradientModeOptionVariableSet.IsInSet (aUsedOptions)
767 && (isMain || (theBackgroundCommand == BackgroundCommand_GradientMode)))
768 {
769 return processGradientModeOptionSet();
770 }
771 if (myColorOptionVariableSet.IsInSet (aUsedOptions)
772 && (isMain || (theBackgroundCommand == BackgroundCommand_Color)))
773 {
774 return processColorOptionSet();
775 }
776 if ((myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain)
777 || (myGradientOptionVariableSet.IsInSet (aUsedOptions)
778 && (theBackgroundCommand == BackgroundCommand_Default)))
779 {
780 return processDefaultGradientOptionSet();
781 }
782 if ((myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain)
783 || (myColorOptionVariableSet.IsInSet (aUsedOptions) && (theBackgroundCommand == BackgroundCommand_Default)))
784 {
785 return processDefaultColorOptionSet();
786 }
787 if (myHelpOptionVariableSet.IsInSet (aUsedOptions))
788 {
789 return processHelpOptionSet (theBackgroundCommandName, theDrawInterpretor);
790 }
791 return false;
792 }
793
794 //! Processes the image option set
795 //! @return true if processing was successful, or false otherwise
796 bool processImageOptionSet() const
797 {
798 std::string anImageFileName;
799 if (!processImageOption (anImageFileName))
800 {
801 return false;
802 }
803 Aspect_FillMethod anImageMode = Aspect_FM_CENTERED;
804 if (myCommandParser.HasOption (myImageModeOptionKey) && !processImageModeOption (anImageMode))
805 {
806 return false;
807 }
808 setImage (anImageFileName.c_str(), anImageMode);
809 return true;
810 }
811
812 //! Processes the image mode option set
813 //! @return true if processing was successful, or false otherwise
814 bool processImageModeOptionSet() const
815 {
816 return processImageModeOptionSet (myImageModeOptionKey);
817 }
818
819 //! Processes the image mode option set
820 //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option
821 //! @return true if processing was successful, or false otherwise
822 bool processImageModeOptionSet (const ViewerTest_CommandOptionKey theImageModeOptionKey) const
823 {
824 Aspect_FillMethod anImageMode = Aspect_FM_NONE;
825 if (!processImageModeOption (theImageModeOptionKey, anImageMode))
826 {
827 return false;
828 }
829 setImageMode (anImageMode);
830 return true;
831 }
832
833 //! Processes the gradient option set
834 //! @param theSetGradient the function used to set a background gradient filling
835 //! @return true if processing was successful, or false otherwise
836 bool processGradientOptionSet (SetGradientFunction* const theSetGradient = setGradient) const
837 {
838 Quantity_Color aColor1;
839 Quantity_Color aColor2;
840 if (!processGradientOption (aColor1, aColor2))
841 {
842 return false;
843 }
844 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR;
845 if (myCommandParser.HasOption (myGradientModeOptionKey) && !processGradientModeOption (aGradientMode))
846 {
847 return false;
848 }
849 theSetGradient (aColor1, aColor2, aGradientMode);
850 return true;
851 }
852
853 //! Processes the gradient mode option set
854 //! @return true if processing was successful, or false otherwise
855 bool processGradientModeOptionSet() const
856 {
857 return processGradientModeOptionSet (myGradientModeOptionKey);
858 }
859
860 //! Processes the gradient mode option set
861 //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option
862 //! @return true if processing was successful, or false otherwise
863 bool processGradientModeOptionSet (const ViewerTest_CommandOptionKey theGradientModeOptionKey) const
864 {
865 Aspect_GradientFillMethod aGradientMode = Aspect_GFM_NONE;
866 if (!processGradientModeOption (theGradientModeOptionKey, aGradientMode))
867 {
868 return false;
869 }
870 setGradientMode (aGradientMode);
871 return true;
872 }
873
874 //! Processes the color option set
875 //! @param theSetColor the function used to set a background color
876 //! @return true if processing was successful, or false otherwise
877 bool processColorOptionSet (SetColorFunction* const theSetColor = setColor) const
878 {
879 return processColorOptionSet (myColorOptionKey, theSetColor);
880 }
881
882 //! Processes the default color option set
883 //! @return true if processing was successful, or false otherwise
884 bool processDefaultGradientOptionSet() const
885 {
886 return processGradientOptionSet (setDefaultGradient);
887 }
888
889 //! Processes the default gradient option set
890 //! @return true if processing was successful, or false otherwise
891 bool processDefaultColorOptionSet() const
892 {
893 return processColorOptionSet (setDefaultColor);
894 }
895
896 //! Processes the color option set
897 //! @param theColorOptionKey the key of the option that is interpreted as a color option
898 //! @param theSetColor the function used to set a background color
899 //! @return true if processing was successful, or false otherwise
900 bool processColorOptionSet (const ViewerTest_CommandOptionKey theColorOptionKey,
901 SetColorFunction* const theSetColor = setColor) const
902 {
903 Quantity_Color aColor;
904 if (!processColorOption (theColorOptionKey, aColor))
905 {
906 return false;
907 }
908 theSetColor (aColor);
909 return true;
910 }
911
912 //! Processes the help option set
913 //! @param theBackgroundCommandName the name of the command that changes the background
914 //! @param theDrawInterpretor the interpreter of the Draw Harness application
915 //! @return true if processing was successful, or false otherwise
916 bool processHelpOptionSet (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor) const
917 {
918 const Standard_Integer aNumberOfHelpOptionArguments = myCommandParser.GetNumberOfOptionArguments (
919 ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY);
920 if (aNumberOfHelpOptionArguments != 0)
921 {
922 return false;
923 }
924 return printHelp (theBackgroundCommandName, theDrawInterpretor);
925 }
926
927 //! Processes the image option
928 //! @param theImageFileName the filename of the image to be used as a background
929 //! @return true if processing was successful, or false otherwise
930 bool processImageOption (std::string& theImageFileName) const
931 {
932 const Standard_Integer aNumberOfImageOptionArguments = myCommandParser.GetNumberOfOptionArguments (
933 myImageOptionKey);
934 if (aNumberOfImageOptionArguments != 1)
935 {
936 return false;
937 }
938 std::string anImageFileName;
939 if (!myCommandParser.Arg (myImageOptionKey, 0, anImageFileName))
940 {
941 return false;
942 }
943 theImageFileName = anImageFileName;
944 return true;
945 }
946
947 //! Processes the image mode option
948 //! @param theImageMode the fill type used for a background image
949 //! @return true if processing was successful, or false otherwise
950 bool processImageModeOption (Aspect_FillMethod& theImageMode) const
951 {
952 return processImageModeOption (myImageModeOptionKey, theImageMode);
953 }
954
955 //! Processes the image mode option
956 //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option
957 //! @param theImageMode the fill type used for a background image
958 //! @return true if processing was successful, or false otherwise
959 bool processImageModeOption (const ViewerTest_CommandOptionKey theImageModeOptionKey,
960 Aspect_FillMethod& theImageMode) const
961 {
962 return processModeOption (theImageModeOptionKey, getBackgroundImageFillMethodByName, theImageMode);
963 }
964
965 //! Processes the gradient option
966 //! @param theColor1 the gradient starting color
967 //! @param theColor2 the gradient ending color
968 //! @return true if processing was successful, or false otherwise
969 bool processGradientOption (Quantity_Color& theColor1, Quantity_Color& theColor2) const
970 {
971 Standard_Integer anArgumentIndex = 0;
972 Quantity_Color aColor1;
973 if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor1))
974 {
975 return false;
976 }
977 Quantity_Color aColor2;
978 if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor2))
979 {
980 return false;
981 }
982 const Standard_Integer aNumberOfGradientOptionArguments = myCommandParser.GetNumberOfOptionArguments (
983 myGradientOptionKey);
984 if (anArgumentIndex != aNumberOfGradientOptionArguments)
985 {
986 return false;
987 }
988 theColor1 = aColor1;
989 theColor2 = aColor2;
990 return true;
991 }
992
993 //! Processes the gradient mode option
994 //! @param theGradientMode the fill method used for a background gradient filling
995 //! @return true if processing was successful, or false otherwise
996 bool processGradientModeOption (Aspect_GradientFillMethod& theGradientMode) const
997 {
998 return processGradientModeOption (myGradientModeOptionKey, theGradientMode);
999 }
1000
1001 //! Processes the gradient mode option
1002 //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option
1003 //! @param theGradientMode the fill method used for a background gradient filling
1004 //! @return true if processing was successful, or false otherwise
1005 bool processGradientModeOption (const ViewerTest_CommandOptionKey theGradientModeOptionKey,
1006 Aspect_GradientFillMethod& theGradientMode) const
1007 {
1008 return processModeOption (theGradientModeOptionKey, getBackgroundGradientFillMethodByName, theGradientMode);
1009 }
1010
1011 //! Processes some mode option
1012 //! @tparam TheMode the type of a mode to be processed
1013 //! @param theModeOptionKey the key of the option that is interpreted as a mode option
1014 //! @param theMode a mode to be processed
1015 //! @return true if processing was successful, or false otherwise
1016 template <typename TheMode>
1017 bool processModeOption (const ViewerTest_CommandOptionKey theModeOptionKey,
1018 bool (*const theGetModeByName) (const TCollection_AsciiString& /* theModeName */,
1019 TheMode& /* theMode */),
1020 TheMode& theMode) const
1021 {
1022 const Standard_Integer aNumberOfModeOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1023 theModeOptionKey);
1024 if (aNumberOfModeOptionArguments != 1)
1025 {
1026 return false;
1027 }
1028 std::string aModeString;
1029 if (!myCommandParser.Arg (theModeOptionKey, 0, aModeString))
1030 {
1031 return false;
1032 }
1033 TheMode aMode = TheMode();
1034 if (!theGetModeByName (aModeString.c_str(), aMode))
1035 {
1036 return false;
1037 }
1038 theMode = aMode;
1039 return true;
1040 }
1041
1042 //! Processes the color option
1043 //! @param theColor a color used for filling a background
1044 //! @return true if processing was successful, or false otherwise
1045 bool processColorOption (Quantity_Color& theColor) const
1046 {
1047 return processColorOption (myColorOptionKey, theColor);
1048 }
1049
1050 //! Processes the color option
1051 //! @param theColorOptionKey the key of the option that is interpreted as a color option
1052 //! @param theColor a color used for filling a background
1053 //! @return true if processing was successful, or false otherwise
1054 bool processColorOption (const ViewerTest_CommandOptionKey theColorOptionKey, Quantity_Color& theColor) const
1055 {
1056 Standard_Integer anArgumentIndex = 0;
1057 Quantity_Color aColor;
1058 if (!myCommandParser.ArgColor (theColorOptionKey, anArgumentIndex, aColor))
1059 {
1060 return false;
1061 }
1062 const Standard_Integer aNumberOfColorOptionArguments = myCommandParser.GetNumberOfOptionArguments (
1063 theColorOptionKey);
1064 if (anArgumentIndex != aNumberOfColorOptionArguments)
1065 {
1066 return false;
1067 }
1068 theColor = aColor;
1069 return true;
1070 }
1071
1072 //! Prints helping message
1073 //! @param theBackgroundCommandName the name of the command that changes the background
1074 //! @param theDrawInterpretor the interpreter of the Draw Harness application
1075 //! @return true if printing was successful, or false otherwise
1076 static bool printHelp (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor)
1077 {
1078 return theDrawInterpretor.PrintHelp (theBackgroundCommandName) == TCL_OK;
1079 }
1080
1081 //! Sets the image as a background
1082 //! @param theImageFileName the filename of the image to be used as a background
1083 //! @param theImageMode the fill type used for a background image
1084 static void setImage (const Standard_CString theImageFileName, const Aspect_FillMethod theImageMode)
1085 {
1086 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1087 aCurrentView->SetBackgroundImage (theImageFileName, theImageMode, Standard_True);
1088 }
1089
1090 //! Sets the fill type used for a background image
1091 //! @param theImageMode the fill type used for a background image
1092 static void setImageMode (const Aspect_FillMethod theImageMode)
1093 {
1094 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1095 aCurrentView->SetBgImageStyle (theImageMode, Standard_True);
1096 }
1097
1098 //! Sets the gradient filling for a background
1099 //! @param theColor1 the gradient starting color
1100 //! @param theColor2 the gradient ending color
1101 //! @param theGradientMode the fill method used for a background gradient filling
1102 static void setGradient (const Quantity_Color& theColor1,
1103 const Quantity_Color& theColor2,
1104 const Aspect_GradientFillMethod theGradientMode)
1105 {
1106 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1107 aCurrentView->SetBgGradientColors (theColor1, theColor2, theGradientMode, Standard_True);
1108 }
1109
1110 //! Sets the fill method used for a background gradient filling
1111 //! @param theGradientMode the fill method used for a background gradient filling
1112 static void setGradientMode (const Aspect_GradientFillMethod theGradientMode)
1113 {
1114 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1115 aCurrentView->SetBgGradientStyle (theGradientMode, Standard_True);
1116 }
1117
1118 //! Sets the color used for filling a background
1119 //! @param theColor the color used for filling a background
1120 static void setColor (const Quantity_Color& theColor)
1121 {
1122 const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView();
1123 aCurrentView->SetBgGradientStyle (Aspect_GFM_NONE);
1124 aCurrentView->SetBackgroundColor (theColor);
1125 aCurrentView->Update();
1126 }
1127
1128 //! Sets the gradient filling for a background in a default viewer
1129 //! @param theColor1 the gradient starting color
1130 //! @param theColor2 the gradient ending color
1131 //! @param theGradientMode the fill method used for a background gradient filling
1132 static void setDefaultGradient (const Quantity_Color& theColor1,
1133 const Quantity_Color& theColor2,
1134 const Aspect_GradientFillMethod theGradientMode)
1135 {
1136 ViewerTest_DefaultBackground.GradientColor1 = theColor1;
1137 ViewerTest_DefaultBackground.GradientColor2 = theColor2;
1138 ViewerTest_DefaultBackground.FillMethod = theGradientMode;
1139 setDefaultGradient();
1140 }
1141
1142 //! Sets the color used for filling a background in a default viewer
1143 //! @param theColor the color used for filling a background
1144 static void setDefaultColor (const Quantity_Color& theColor)
1145 {
1146 ViewerTest_DefaultBackground.GradientColor1 = Quantity_Color();
1147 ViewerTest_DefaultBackground.GradientColor2 = Quantity_Color();
1148 ViewerTest_DefaultBackground.FillMethod = Aspect_GFM_NONE;
1149 ViewerTest_DefaultBackground.FlatColor = theColor;
1150 setDefaultGradient();
1151 setDefaultColor();
1152 }
1153
1154 //! Sets the gradient filling for a background in a default viewer.
1155 //! Gradient settings are taken from ViewerTest_DefaultBackground structure
1156 static void setDefaultGradient()
1157 {
1158 for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator
1159 anInteractiveContextIterator (ViewerTest_myContexts);
1160 anInteractiveContextIterator.More();
1161 anInteractiveContextIterator.Next())
1162 {
1163 const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer();
1164 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
1165 ViewerTest_DefaultBackground.GradientColor2,
1166 ViewerTest_DefaultBackground.FillMethod);
1167 }
1168 }
1169
1170 //! Sets the color used for filling a background in a default viewer.
1171 //! The color value is taken from ViewerTest_DefaultBackground structure
1172 static void setDefaultColor()
1173 {
1174 for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator
1175 anInteractiveContextIterator (ViewerTest_myContexts);
1176 anInteractiveContextIterator.More();
1177 anInteractiveContextIterator.Next())
1178 {
1179 const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer();
1180 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
1181 }
1182 }
1183 };
1184
1185} // namespace
b12e1c7b 1186
625e1958 1187typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
1188
1189Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
1190{
1191 static ViewerTest_MapOfAISManipulators aMap;
1192 return aMap;
1193}
1194
1195Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
1196{
1197 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
1198 for (; anIt.More(); anIt.Next())
1199 {
1200 if (anIt.Value()->HasActiveMode())
1201 {
1202 return anIt.Value();
1203 }
1204 }
1205 return NULL;
1206}
1207
7fd59977 1208//==============================================================================
1209
57c28b61 1210#ifdef _WIN32
7fd59977 1211static LRESULT WINAPI ViewerWindowProc(
1212 HWND hwnd,
1213 UINT uMsg,
1214 WPARAM wParam,
1215 LPARAM lParam );
1216static LRESULT WINAPI AdvViewerWindowProc(
1217 HWND hwnd,
1218 UINT uMsg,
1219 WPARAM wParam,
1220 LPARAM lParam );
1221#endif
1222
1223
1224//==============================================================================
1225//function : WClass
1226//purpose :
1227//==============================================================================
1228
ad03c234 1229const Handle(Standard_Transient)& ViewerTest::WClass()
7fd59977 1230{
ad03c234 1231 static Handle(Standard_Transient) theWClass;
58655684 1232#if defined(_WIN32)
4fe56619 1233 if (theWClass.IsNull())
1234 {
7c65581d 1235 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
ad03c234 1236 CS_VREDRAW | CS_HREDRAW, 0, 0,
c85a994a 1237 ::LoadCursor (NULL, IDC_ARROW));
7fd59977 1238 }
1239#endif
1240 return theWClass;
1241}
1242
18d715bd 1243//==============================================================================
1244//function : CreateName
1245//purpose : Create numerical name for new object in theMap
1246//==============================================================================
1247template <typename ObjectType>
1248TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
1249 const TCollection_AsciiString& theDefaultString)
1250{
1251 if (theObjectMap.IsEmpty())
1252 return theDefaultString + TCollection_AsciiString(1);
1253
1254 Standard_Integer aNextKey = 1;
1255 Standard_Boolean isFound = Standard_False;
1256 while (!isFound)
1257 {
1258 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
1259 // Look for objects with default names
1260 if (theObjectMap.IsBound1(aStringKey))
1261 {
1262 aNextKey++;
1263 }
1264 else
1265 isFound = Standard_True;
1266 }
1267
1268 return theDefaultString + TCollection_AsciiString(aNextKey);
1269}
1270
1271//==============================================================================
1272//structure : ViewerTest_Names
1273//purpose : Allow to operate with full view name: driverName/viewerName/viewName
1274//==============================================================================
1275struct ViewerTest_Names
1276{
1277private:
1278 TCollection_AsciiString myDriverName;
1279 TCollection_AsciiString myViewerName;
1280 TCollection_AsciiString myViewName;
1281
1282public:
1283
1284 const TCollection_AsciiString& GetDriverName () const
1285 {
1286 return myDriverName;
1287 }
1288 void SetDriverName (const TCollection_AsciiString& theDriverName)
1289 {
1290 myDriverName = theDriverName;
1291 }
1292 const TCollection_AsciiString& GetViewerName () const
1293 {
1294 return myViewerName;
1295 }
1296 void SetViewerName (const TCollection_AsciiString& theViewerName)
1297 {
1298 myViewerName = theViewerName;
1299 }
1300 const TCollection_AsciiString& GetViewName () const
1301 {
1302 return myViewName;
1303 }
1304 void SetViewName (const TCollection_AsciiString& theViewName)
1305 {
1306 myViewName = theViewName;
1307 }
1308
1309 //===========================================================================
1310 //function : Constructor for ViewerTest_Names
1311 //purpose : Get view, viewer, driver names from custom string
1312 //===========================================================================
1313
1314 ViewerTest_Names (const TCollection_AsciiString& theInputString)
1315 {
1316 TCollection_AsciiString aName(theInputString);
1317 if (theInputString.IsEmpty())
1318 {
1319 // Get current configuration
1320 if (ViewerTest_myDrivers.IsEmpty())
1321 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1322 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1323 else
1324 myDriverName = ViewerTest_myDrivers.Find2
1325 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1326
1327 if(ViewerTest_myContexts.IsEmpty())
1328 {
1329 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
1330 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
1331 }
1332 else
c48e2889 1333 {
18d715bd 1334 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
c48e2889 1335 }
18d715bd 1336
c48e2889 1337 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
18d715bd 1338 }
1339 else
1340 {
1341 // There is at least view name
1342 Standard_Integer aParserNumber = 0;
1343 for (Standard_Integer i = 0; i < 3; ++i)
1344 {
1345 Standard_Integer aParserPos = aName.SearchFromEnd("/");
1346 if(aParserPos != -1)
1347 {
1348 aParserNumber++;
1349 aName.Split(aParserPos-1);
1350 }
1351 else
1352 break;
1353 }
1354 if (aParserNumber == 0)
1355 {
1356 // Only view name
1357 if (!ViewerTest::GetAISContext().IsNull())
1358 {
1359 myDriverName = ViewerTest_myDrivers.Find2
1360 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1361 myViewerName = ViewerTest_myContexts.Find2
1362 (ViewerTest::GetAISContext());
1363 }
1364 else
1365 {
1366 // There is no opened contexts here, need to create names for viewer and driver
1367 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1368 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1369
1370 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
1371 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
1372 }
1373 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
1374 }
1375 else if (aParserNumber == 1)
1376 {
1377 // Here is viewerName/viewName
1378 if (!ViewerTest::GetAISContext().IsNull())
1379 myDriverName = ViewerTest_myDrivers.Find2
1380 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
1381 else
1382 {
1383 // There is no opened contexts here, need to create name for driver
1384 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
1385 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
1386 }
1387 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
1388
1389 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
1390 }
1391 else
1392 {
1393 //Here is driverName/viewerName/viewName
1394 myDriverName = TCollection_AsciiString(aName);
1395
1396 TCollection_AsciiString aViewerName(theInputString);
1397 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
1398 myViewerName = TCollection_AsciiString(aViewerName);
1399
1400 myViewName = TCollection_AsciiString(theInputString);
1401 }
1402 }
1403 }
1404};
1405
1406//==============================================================================
1407//function : FindContextByView
1408//purpose : Find AIS_InteractiveContext by View
1409//==============================================================================
1410
1411Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
1412{
1413 Handle(AIS_InteractiveContext) anAISContext;
1414
1415 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1416 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
1417 {
1418 if (anIter.Value()->CurrentViewer() == theView->Viewer())
1419 return anIter.Key2();
1420 }
1421 return anAISContext;
1422}
1423
18d715bd 1424//==============================================================================
1425//function : IsWindowOverlapped
1426//purpose : Check if theWindow overlapp another view
1427//==============================================================================
1428
1429Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
1430 const Standard_Integer thePxTop,
1431 const Standard_Integer thePxRight,
1432 const Standard_Integer thePxBottom,
1433 TCollection_AsciiString& theViewId)
1434{
1435 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1436 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1437 {
1438 Standard_Integer aTop = 0,
1439 aLeft = 0,
1440 aRight = 0,
1441 aBottom = 0;
1442 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
1443 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
1444 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
1445 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
1446 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
1447 {
1448 theViewId = anIter.Key1();
1449 return Standard_True;
1450 }
1451 }
1452 return Standard_False;
1453}
1454
1455// Workaround: to create and delete non-orthographic views outside ViewerTest
1456void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
1457{
1458 ViewerTest_myViews.UnBind1 (theName);
1459}
1460
1461void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
1462 const Handle(V3d_View)& theView)
1463{
1464 ViewerTest_myViews.Bind (theName, theView);
1465}
1466
1467TCollection_AsciiString ViewerTest::GetCurrentViewName ()
1468{
1469 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
1470}
8693dfd0 1471
1472//! Auxiliary tool performing continuous redraws of specified window.
1473class ViewerTest_ContinuousRedrawer
1474{
1475public:
1476 //! Return global instance.
1477 static ViewerTest_ContinuousRedrawer& Instance()
1478 {
1479 static ViewerTest_ContinuousRedrawer aRedrawer;
1480 return aRedrawer;
1481 }
1482public:
1483
1484 //! Destructor.
1485 ~ViewerTest_ContinuousRedrawer()
1486 {
1487 Stop();
1488 }
1489
1490 //! Start thread.
1491 void Start (const Handle(Aspect_Window)& theWindow,
1492 Standard_Real theTargetFps)
1493 {
1494 if (myWindow != theWindow
1495 || myTargetFps != theTargetFps)
1496 {
1497 Stop();
1498 myWindow = theWindow;
1499 myTargetFps = theTargetFps;
1500 }
1501 if (myThread.GetId() == 0)
1502 {
1503 myToStop = false;
1504 myThread.Run (this);
1505 }
1506 }
1507
1508 //! Stop thread.
1509 void Stop (const Handle(Aspect_Window)& theWindow = NULL)
1510 {
1511 if (!theWindow.IsNull()
1512 && myWindow != theWindow)
1513 {
1514 return;
1515 }
1516
1517 {
1518 Standard_Mutex::Sentry aLock (myMutex);
1519 myToStop = true;
1520 }
1521 myThread.Wait();
1522 myToStop = false;
1523 myWindow.Nullify();
1524 }
1525
1526private:
1527
1528 //! Thread loop.
1529 void doThreadLoop()
1530 {
1531 Handle(Aspect_DisplayConnection) aDisp = new Aspect_DisplayConnection();
1532 OSD_Timer aTimer;
1533 aTimer.Start();
1534 Standard_Real aTimeOld = 0.0;
1535 const Standard_Real aTargetDur = myTargetFps > 0.0 ? 1.0 / myTargetFps : -1.0;
1536 for (;;)
1537 {
1538 {
1539 Standard_Mutex::Sentry aLock (myMutex);
1540 if (myToStop)
1541 {
1542 return;
1543 }
1544 }
1545 if (myTargetFps > 0.0)
1546 {
1547 const Standard_Real aTimeNew = aTimer.ElapsedTime();
1548 const Standard_Real aDuration = aTimeNew - aTimeOld;
1549 if (aDuration >= aTargetDur)
1550 {
1551 myWindow->InvalidateContent (aDisp);
1552 aTimeOld = aTimeNew;
1553 }
1554 }
1555 else
1556 {
1557 myWindow->InvalidateContent (aDisp);
1558 }
1559
1560 OSD::MilliSecSleep (1);
1561 }
1562 }
1563
1564 //! Thread creation callback.
1565 static Standard_Address doThreadWrapper (Standard_Address theData)
1566 {
1567 ViewerTest_ContinuousRedrawer* aThis = (ViewerTest_ContinuousRedrawer* )theData;
1568 aThis->doThreadLoop();
1569 return 0;
1570 }
1571
1572 //! Empty constructor.
1573 ViewerTest_ContinuousRedrawer()
1574 : myThread (doThreadWrapper),
1575 myTargetFps (0.0),
1576 myToStop (false) {}
1577
1578private:
1579 Handle(Aspect_Window) myWindow;
1580 OSD_Thread myThread;
1581 Standard_Mutex myMutex;
1582 Standard_Real myTargetFps;
1583 volatile bool myToStop;
1584};
1585
7fd59977 1586//==============================================================================
1587//function : ViewerInit
1588//purpose : Create the window viewer and initialize all the global variable
1589//==============================================================================
1590
18d715bd 1591TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
1592 const Standard_Integer thePxTop,
1593 const Standard_Integer thePxWidth,
1594 const Standard_Integer thePxHeight,
9e04ccdc 1595 const TCollection_AsciiString& theViewName,
1596 const TCollection_AsciiString& theDisplayName,
1597 const Handle(V3d_View)& theViewToClone)
7fd59977 1598{
8c3c9904 1599 // Default position and dimension of the viewer window.
4fe56619 1600 // Note that left top corner is set to be sufficiently small to have
8c3c9904 1601 // window fit in the small screens (actual for remote desktops, see #23003).
4fe56619 1602 // The position corresponds to the window's client area, thus some
8c3c9904 1603 // gap is added for window frame to be visible.
1604 Standard_Integer aPxLeft = 20;
1605 Standard_Integer aPxTop = 40;
7fd59977 1606 Standard_Integer aPxWidth = 409;
1607 Standard_Integer aPxHeight = 409;
18d715bd 1608 Standard_Boolean toCreateViewer = Standard_False;
9e04ccdc 1609 if (!theViewToClone.IsNull())
1610 {
1611 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
1612 }
18d715bd 1613
58655684 1614 Handle(OpenGl_GraphicDriver) aGraphicDriver;
18d715bd 1615 ViewerTest_Names aViewNames(theViewName);
1616 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
1617 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
1618
1619 if (thePxLeft != 0)
1620 aPxLeft = thePxLeft;
1621 if (thePxTop != 0)
1622 aPxTop = thePxTop;
1623 if (thePxWidth != 0)
1624 aPxWidth = thePxWidth;
1625 if (thePxHeight != 0)
7fd59977 1626 aPxHeight = thePxHeight;
4269bd1b 1627
18d715bd 1628 // Get graphic driver (create it or get from another view)
8693dfd0 1629 const bool isNewDriver = !ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName());
1630 if (isNewDriver)
18d715bd 1631 {
1632 // Get connection string
58655684 1633 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8693dfd0 1634 if (!theDisplayName.IsEmpty())
1635 {
1636 SetDisplayConnection (new Aspect_DisplayConnection (theDisplayName));
1637 }
18d715bd 1638 else
8693dfd0 1639 {
1640 ::Display* aDispX = NULL;
1641 // create dedicated display connection instead of reusing Tk connection
1642 // so that to procede events independently through VProcessEvents()/ViewerMainLoop() callbacks
1643 /*Draw_Interpretor& aCommands = Draw::GetInterpretor();
1644 Tcl_Interp* aTclInterp = aCommands.Interp();
1645 Tk_Window aMainWindow = Tk_MainWindow (aTclInterp);
1646 aDispX = aMainWindow != NULL ? Tk_Display (aMainWindow) : NULL;*/
1647 SetDisplayConnection (new Aspect_DisplayConnection (aDispX));
1648 }
18d715bd 1649 #else
498ce76b 1650 (void)theDisplayName; // avoid warning on unused argument
18d715bd 1651 SetDisplayConnection (new Aspect_DisplayConnection ());
1652 #endif
14cb22a1 1653
1654 if (Draw_VirtualWindows)
1655 {
1656 // don't waste the time waiting for VSync when window is not displayed on the screen
1657 ViewerTest_myDefaultCaps.swapInterval = 0;
1658 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
1659 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
1660 }
59515ca6 1661 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection(), false);
58655684 1662 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
59515ca6 1663 aGraphicDriver->InitContext();
14cb22a1 1664
18d715bd 1665 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
1666 toCreateViewer = Standard_True;
1667 }
1668 else
1669 {
58655684 1670 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
7fd59977 1671 }
1672
18d715bd 1673 //Dispose the window if input parameters are default
1674 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
7fd59977 1675 {
18d715bd 1676 Standard_Integer aTop = 0,
1677 aLeft = 0,
1678 aRight = 0,
1679 aBottom = 0,
1680 aScreenWidth = 0,
1681 aScreenHeight = 0;
1682
1683 // Get screen resolution
1684#if defined(_WIN32) || defined(__WIN32__)
1685 RECT aWindowSize;
1686 GetClientRect(GetDesktopWindow(), &aWindowSize);
1687 aScreenHeight = aWindowSize.bottom;
1688 aScreenWidth = aWindowSize.right;
1689#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1690 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
1691#else
1692 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
1693 aScreenWidth = WidthOfScreen(aScreen);
1694 aScreenHeight = HeightOfScreen(aScreen);
1695#endif
1696
1697 TCollection_AsciiString anOverlappedViewId("");
773f53f1 1698
1699 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
dc3fe572 1700 {
18d715bd 1701 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
1702
1703 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
1704 && aRight + 2*aPxWidth + 40 > aScreenWidth)
1705 {
1706 if (aBottom + aPxHeight + 40 > aScreenHeight)
1707 {
1708 aPxLeft = 20;
1709 aPxTop = 40;
1710 break;
1711 }
1712 aPxLeft = 20;
1713 aPxTop = aBottom + 40;
1714 }
1715 else
1716 aPxLeft = aRight + 20;
dc3fe572 1717 }
18d715bd 1718 }
1719
1720 // Get viewer name
1721 TCollection_AsciiString aTitle("3D View - ");
1722 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
1723
1724 // Change name of current active window
49582f9d 1725 if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView())
18d715bd 1726 {
49582f9d 1727 aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView));
18d715bd 1728 }
1729
1730 // Create viewer
eb4320f2 1731 Handle(V3d_Viewer) a3DViewer;
18d715bd 1732 // If it's the single view, we first look for empty context
1733 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
1734 {
1735 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1736 anIter(ViewerTest_myContexts);
1737 if (anIter.More())
1738 ViewerTest::SetAISContext (anIter.Value());
1739 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 1740 }
1741 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
1742 {
1743 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
1744 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 1745 }
eb4320f2 1746 else if (a3DViewer.IsNull())
18d715bd 1747 {
1748 toCreateViewer = Standard_True;
6a24c6de 1749 a3DViewer = new V3d_Viewer(aGraphicDriver);
f42753ed 1750 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
1751 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
1752 ViewerTest_DefaultBackground.GradientColor2,
1753 ViewerTest_DefaultBackground.FillMethod);
18d715bd 1754 }
1755
1756 // AIS context setup
1757 if (ViewerTest::GetAISContext().IsNull() ||
1758 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
1759 {
e79a94b9 1760 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
18d715bd 1761 ViewerTest::SetAISContext (aContext);
1762 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
1763 }
1764 else
e79a94b9 1765 {
18d715bd 1766 ViewerTest::ResetEventManager();
e79a94b9 1767 }
18d715bd 1768
1769 // Create window
e79a94b9 1770#if defined(_WIN32)
1771 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
1772 Handle(WNT_WClass)::DownCast (WClass()),
62e1beed 1773 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
e79a94b9 1774 aPxLeft, aPxTop,
1775 aPxWidth, aPxHeight,
1776 Quantity_NOC_BLACK);
4fe56619 1777#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
e79a94b9 1778 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
1779 aPxLeft, aPxTop,
1780 aPxWidth, aPxHeight);
1781 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
7fd59977 1782#else
e79a94b9 1783 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
1784 aTitle.ToCString(),
1785 aPxLeft, aPxTop,
1786 aPxWidth, aPxHeight);
7fd59977 1787#endif
18d715bd 1788 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
7fd59977 1789
d09dda09 1790 // View setup
9e04ccdc 1791 Handle(V3d_View) aView;
1792 if (!theViewToClone.IsNull())
1793 {
2e93433e 1794 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
9e04ccdc 1795 }
1796 else
1797 {
2e93433e 1798 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
9e04ccdc 1799 }
1800
d09dda09 1801 aView->SetWindow (VT_GetWindow());
c3282ec1 1802 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
4269bd1b 1803
18d715bd 1804 ViewerTest::CurrentView(aView);
1805 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
7fd59977 1806
18d715bd 1807 // Setup for X11 or NT
1808 OSWindowSetup();
7fd59977 1809
18d715bd 1810 // Set parameters for V3d_View and V3d_Viewer
1811 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
1812 aV3dView->SetComputedMode(Standard_False);
7fd59977 1813
18d715bd 1814 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
1815 if (toCreateViewer)
1816 {
7fd59977 1817 a3DViewer->SetDefaultLights();
1818 a3DViewer->SetLightOn();
18d715bd 1819 }
7fd59977 1820
8693dfd0 1821#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1822 if (isNewDriver)
1823 {
1824 ::Display* aDispX = GetDisplayConnection()->GetDisplay();
1825 Tcl_CreateFileHandler (XConnectionNumber (aDispX), TCL_READABLE, VProcessEvents, (ClientData )aDispX);
1826 }
1827#endif
7fd59977 1828
7fd59977 1829 VT_GetWindow()->Map();
4269bd1b 1830
18d715bd 1831 // Set the handle of created view in the event manager
1832 ViewerTest::ResetEventManager();
1833
4fe56619 1834 ViewerTest::CurrentView()->Redraw();
18d715bd 1835
1836 aView.Nullify();
1837 a3DViewer.Nullify();
18d715bd 1838
1839 return aViewNames.GetViewName();
1840}
1841
4269bd1b 1842//==============================================================================
1843//function : RedrawAllViews
1844//purpose : Redraw all created views
1845//==============================================================================
1846void ViewerTest::RedrawAllViews()
1847{
1848 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
1849 for (; aViewIt.More(); aViewIt.Next())
1850 {
1851 const Handle(V3d_View)& aView = aViewIt.Key2();
1852 aView->Redraw();
1853 }
1854}
1855
7fd59977 1856//==============================================================================
1857//function : Vinit
1858//purpose : Create the window viewer and initialize all the global variable
e79a94b9 1859// Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
7fd59977 1860//==============================================================================
1861
18d715bd 1862static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 1863{
e79a94b9 1864 TCollection_AsciiString aViewName, aDisplayName;
1865 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
9e04ccdc 1866 Handle(V3d_View) aCopyFrom;
e79a94b9 1867 TCollection_AsciiString aName, aValue;
2e93433e 1868 int is2dMode = -1;
e79a94b9 1869 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
18d715bd 1870 {
e79a94b9 1871 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1872 TCollection_AsciiString anArgCase = anArg;
fd3f6bd0 1873 anArgCase.LowerCase();
1874 if (anArgIt + 1 < theArgsNb
1875 && anArgCase == "-name")
1876 {
1877 aViewName = theArgVec[++anArgIt];
1878 }
1879 else if (anArgIt + 1 < theArgsNb
1880 && (anArgCase == "-left"
1881 || anArgCase == "-l"))
1882 {
1883 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
1884 }
1885 else if (anArgIt + 1 < theArgsNb
1886 && (anArgCase == "-top"
1887 || anArgCase == "-t"))
1888 {
1889 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
1890 }
1891 else if (anArgIt + 1 < theArgsNb
1892 && (anArgCase == "-width"
1893 || anArgCase == "-w"))
1894 {
1895 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
1896 }
1897 else if (anArgIt + 1 < theArgsNb
1898 && (anArgCase == "-height"
1899 || anArgCase == "-h"))
18d715bd 1900 {
fd3f6bd0 1901 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
1902 }
1903 else if (anArgCase == "-exitonclose")
1904 {
49582f9d 1905 ViewerTest_EventManager::ToExitOnCloseView() = true;
fd3f6bd0 1906 if (anArgIt + 1 < theArgsNb
49582f9d 1907 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToExitOnCloseView()))
fd3f6bd0 1908 {
1909 ++anArgIt;
1910 }
1911 }
1912 else if (anArgCase == "-closeonescape"
1913 || anArgCase == "-closeonesc")
1914 {
49582f9d 1915 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
fd3f6bd0 1916 if (anArgIt + 1 < theArgsNb
49582f9d 1917 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
fd3f6bd0 1918 {
1919 ++anArgIt;
1920 }
1921 }
2e93433e 1922 else if (anArgCase == "-2d_mode"
1923 || anArgCase == "-2dmode"
1924 || anArgCase == "-2d")
1925 {
1926 bool toEnable = true;
1927 if (anArgIt + 1 < theArgsNb
1928 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
1929 {
1930 ++anArgIt;
1931 }
1932 is2dMode = toEnable ? 1 : 0;
1933 }
fd3f6bd0 1934 else if (anArgIt + 1 < theArgsNb
1935 && (anArgCase == "-disp"
1936 || anArgCase == "-display"))
1937 {
1938 aDisplayName = theArgVec[++anArgIt];
1939 }
9e04ccdc 1940 else if (!ViewerTest::CurrentView().IsNull()
1941 && aCopyFrom.IsNull()
1942 && (anArgCase == "-copy"
1943 || anArgCase == "-clone"
1944 || anArgCase == "-cloneactive"
1945 || anArgCase == "-cloneactiveview"))
1946 {
1947 aCopyFrom = ViewerTest::CurrentView();
1948 }
fd3f6bd0 1949 // old syntax
1950 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
1951 {
1952 aName.LowerCase();
1953 if (aName == "name")
18d715bd 1954 {
1955 aViewName = aValue;
1956 }
fd3f6bd0 1957 else if (aName == "l"
1958 || aName == "left")
e79a94b9 1959 {
18d715bd 1960 aPxLeft = aValue.IntegerValue();
e79a94b9 1961 }
fd3f6bd0 1962 else if (aName == "t"
1963 || aName == "top")
e79a94b9 1964 {
18d715bd 1965 aPxTop = aValue.IntegerValue();
e79a94b9 1966 }
fd3f6bd0 1967 else if (aName == "disp"
1968 || aName == "display")
e79a94b9 1969 {
18d715bd 1970 aDisplayName = aValue;
e79a94b9 1971 }
fd3f6bd0 1972 else if (aName == "w"
1973 || aName == "width")
e79a94b9 1974 {
18d715bd 1975 aPxWidth = aValue.IntegerValue();
e79a94b9 1976 }
fd3f6bd0 1977 else if (aName == "h"
1978 || aName == "height")
e79a94b9 1979 {
18d715bd 1980 aPxHeight = aValue.IntegerValue();
e79a94b9 1981 }
18d715bd 1982 else
1983 {
fd3f6bd0 1984 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
1985 return 1;
18d715bd 1986 }
1987 }
e79a94b9 1988 else if (aViewName.IsEmpty())
1989 {
1990 aViewName = anArg;
1991 }
1992 else
1993 {
fd3f6bd0 1994 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
1995 return 1;
e79a94b9 1996 }
18d715bd 1997 }
1998
fd3f6bd0 1999#if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
2000 if (!aDisplayName.IsEmpty())
2001 {
2002 aDisplayName.Clear();
2003 std::cout << "Warning: display parameter will be ignored.\n";
2004 }
2005#endif
2006
18d715bd 2007 ViewerTest_Names aViewNames (aViewName);
e79a94b9 2008 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
18d715bd 2009 {
e79a94b9 2010 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
2011 theDi.Eval (aCommand.ToCString());
2e93433e 2012 if (is2dMode != -1)
2013 {
2014 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
2015 }
18d715bd 2016 return 0;
2017 }
2018
2019 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
9e04ccdc 2020 aViewName, aDisplayName, aCopyFrom);
2e93433e 2021 if (is2dMode != -1)
2022 {
2023 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
2024 }
e79a94b9 2025 theDi << aViewId;
7fd59977 2026 return 0;
2027}
2028
1eeef710 2029//! Parse HLR algo type.
2030static Standard_Boolean parseHlrAlgoType (const char* theName,
2031 Prs3d_TypeOfHLR& theType)
2032{
2033 TCollection_AsciiString aName (theName);
2034 aName.LowerCase();
2035 if (aName == "polyalgo")
2036 {
2037 theType = Prs3d_TOH_PolyAlgo;
2038 }
2039 else if (aName == "algo")
2040 {
2041 theType = Prs3d_TOH_Algo;
2042 }
2043 else
2044 {
2045 return Standard_False;
2046 }
2047 return Standard_True;
2048}
2049
0a768f56 2050//==============================================================================
2051//function : VHLR
2052//purpose : hidden lines removal algorithm
2053//==============================================================================
2054
2055static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2056{
1eeef710 2057 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2058 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2059 if (aView.IsNull())
0a768f56 2060 {
1eeef710 2061 std::cerr << "Error: No opened viewer!\n";
0a768f56 2062 return 1;
2063 }
2064
1eeef710 2065 Standard_Boolean hasHlrOnArg = Standard_False;
2066 Standard_Boolean hasShowHiddenArg = Standard_False;
2067 Standard_Boolean isHLROn = Standard_False;
2068 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
2069 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
2070 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2071 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
0a768f56 2072 {
1eeef710 2073 TCollection_AsciiString anArg (argv[anArgIter]);
2074 anArg.LowerCase();
2075 if (anUpdateTool.parseRedrawMode (anArg))
2076 {
2077 continue;
2078 }
2079 else if (anArg == "-showhidden"
2080 && anArgIter + 1 < argc
2081 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
2082 {
2083 ++anArgIter;
2084 hasShowHiddenArg = Standard_True;
2085 continue;
2086 }
2087 else if ((anArg == "-type"
2088 || anArg == "-algo"
2089 || anArg == "-algotype")
2090 && anArgIter + 1 < argc
2091 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
2092 {
2093 ++anArgIter;
2094 continue;
2095 }
2096 else if (!hasHlrOnArg
2097 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
2098 {
2099 hasHlrOnArg = Standard_True;
2100 continue;
2101 }
2102 // old syntax
2103 else if (!hasShowHiddenArg
2104 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
2105 {
2106 hasShowHiddenArg = Standard_True;
2107 continue;
2108 }
2109 else
2110 {
2111 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
2112 return 1;
2113 }
0a768f56 2114 }
1eeef710 2115 if (!hasHlrOnArg)
0a768f56 2116 {
1eeef710 2117 di << "HLR: " << aView->ComputedMode() << "\n";
2118 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
2119 di << "HlrAlgo: ";
2120 switch (aCtx->DefaultDrawer()->TypeOfHLR())
2121 {
2122 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
2123 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
2124 case Prs3d_TOH_Algo: di << "Algo\n"; break;
2125 }
2126 anUpdateTool.Invalidate();
2127 return 0;
0a768f56 2128 }
2129
1eeef710 2130 Standard_Boolean toRecompute = Standard_False;
2131 if (aTypeOfHLR != Prs3d_TOH_NotSet
2132 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
e9224045 2133 {
1eeef710 2134 toRecompute = Standard_True;
2135 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
2136 }
2137 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
2138 {
2139 toRecompute = Standard_True;
2140 if (toShowHidden)
e9224045 2141 {
1eeef710 2142 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
e9224045 2143 }
2144 else
2145 {
1eeef710 2146 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
e9224045 2147 }
1eeef710 2148 }
e9224045 2149
1eeef710 2150 // redisplay shapes
2151 if (aView->ComputedMode() && isHLROn && toRecompute)
2152 {
2153 AIS_ListOfInteractive aListOfShapes;
2154 aCtx->DisplayedObjects (aListOfShapes);
2155 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
e9224045 2156 {
1eeef710 2157 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
e9224045 2158 {
1eeef710 2159 aCtx->Redisplay (aShape, Standard_False);
e9224045 2160 }
2161 }
2162 }
0a768f56 2163
1eeef710 2164 aView->SetComputedMode (isHLROn);
0a768f56 2165 return 0;
2166}
2167
2168//==============================================================================
2169//function : VHLRType
2170//purpose : change type of using HLR algorithm
2171//==============================================================================
2172
1eeef710 2173static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
0a768f56 2174{
1eeef710 2175 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2176 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2177 if (aView.IsNull())
0a768f56 2178 {
1eeef710 2179 std::cerr << "Error: No opened viewer!\n";
0a768f56 2180 return 1;
2181 }
2182
1eeef710 2183 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
2184 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2185 AIS_ListOfInteractive aListOfShapes;
2186 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
0a768f56 2187 {
1eeef710 2188 TCollection_AsciiString anArg (argv[anArgIter]);
2189 anArg.LowerCase();
2190 if (anUpdateTool.parseRedrawMode (anArg))
0a768f56 2191 {
1eeef710 2192 continue;
0a768f56 2193 }
1eeef710 2194 else if ((anArg == "-type"
2195 || anArg == "-algo"
2196 || anArg == "-algotype")
2197 && anArgIter + 1 < argc
2198 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
2199 {
2200 ++anArgIter;
2201 continue;
2202 }
2203 // old syntax
2204 else if (aTypeOfHLR == Prs3d_TOH_NotSet
2205 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
2206 {
2207 continue;
2208 }
2209 else
0a768f56 2210 {
2211 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1eeef710 2212 TCollection_AsciiString aName (argv[anArgIter]);
0a768f56 2213 if (!aMap.IsBound2 (aName))
2214 {
1eeef710 2215 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
2216 return 1;
0a768f56 2217 }
1eeef710 2218
2219 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
2220 if (aShape.IsNull())
2221 {
2222 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
2223 return 1;
2224 }
2225 aListOfShapes.Append (aShape);
2226 continue;
0a768f56 2227 }
1eeef710 2228 }
2229 if (aTypeOfHLR == Prs3d_TOH_NotSet)
2230 {
2231 std::cout << "Syntax error: wrong number of arguments!\n";
2232 return 1;
2233 }
2234
2235 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
2236 if (isGlobal)
2237 {
2238 aCtx->DisplayedObjects (aListOfShapes);
2239 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
0a768f56 2240 }
2241
1eeef710 2242 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
2243 {
2244 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
2245 if (aShape.IsNull())
2246 {
2247 continue;
2248 }
2249
2250 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
2251 && aView->ComputedMode();
2252 if (!isGlobal
2253 || aShape->TypeOfHLR() != aTypeOfHLR)
2254 {
2255 aShape->SetTypeOfHLR (aTypeOfHLR);
2256 }
2257 if (toUpdateShape)
2258 {
2259 aCtx->Redisplay (aShape, Standard_False);
2260 }
2261 }
0a768f56 2262 return 0;
2263}
2264
18d715bd 2265//==============================================================================
2266//function : FindViewIdByWindowHandle
2267//purpose : Find theView Id in the map of views by window handle
2268//==============================================================================
49582f9d 2269#if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2270TCollection_AsciiString FindViewIdByWindowHandle (Aspect_Drawable theWindowHandle)
18d715bd 2271{
2272 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
2273 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
2274 {
49582f9d 2275 Aspect_Drawable aWindowHandle = anIter.Value()->Window()->NativeHandle();
18d715bd 2276 if (aWindowHandle == theWindowHandle)
2277 return anIter.Key1();
2278 }
2279 return TCollection_AsciiString("");
2280}
2281#endif
2282
e084dbbc 2283//! Make the view active
2284void ActivateView (const TCollection_AsciiString& theViewName,
2285 Standard_Boolean theToUpdate = Standard_True)
18d715bd 2286{
2287 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
e084dbbc 2288 if (aView.IsNull())
18d715bd 2289 {
e084dbbc 2290 return;
2291 }
18d715bd 2292
e084dbbc 2293 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
2294 if (!anAISContext.IsNull())
2295 {
49582f9d 2296 if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView())
e084dbbc 2297 {
49582f9d 2298 aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView));
e084dbbc 2299 }
2300
2301 ViewerTest::CurrentView (aView);
2302 ViewerTest::SetAISContext (anAISContext);
49582f9d 2303 aView->Window()->SetTitle (TCollection_AsciiString("3D View - ") + theViewName + "(*)");
1eeef710 2304#if defined(_WIN32)
e084dbbc 2305 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
18d715bd 2306#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
e084dbbc 2307 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
18d715bd 2308#else
e084dbbc 2309 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
18d715bd 2310#endif
e084dbbc 2311 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2312 if (theToUpdate)
2313 {
18d715bd 2314 ViewerTest::CurrentView()->Redraw();
2315 }
2316 }
2317}
2318
0e93d9e5 2319//==============================================================================
2320//function : RemoveView
2321//purpose :
2322//==============================================================================
2323void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
2324 const Standard_Boolean theToRemoveContext)
2325{
2326 if (!ViewerTest_myViews.IsBound2 (theView))
2327 {
2328 return;
2329 }
2330
2331 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
2332 RemoveView (aViewName, theToRemoveContext);
2333}
2334
18d715bd 2335//==============================================================================
2336//function : RemoveView
2337//purpose : Close and remove view from display, clear maps if neccessary
2338//==============================================================================
2339void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
2340{
2341 if (!ViewerTest_myViews.IsBound1(theViewName))
2342 {
04232180 2343 std::cout << "Wrong view name\n";
18d715bd 2344 return;
2345 }
2346
2347 // Activate another view if it's active now
2348 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
2349 {
2350 if (ViewerTest_myViews.Extent() > 1)
2351 {
2352 TCollection_AsciiString aNewViewName;
c48e2889 2353 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
2354 anIter.More(); anIter.Next())
2355 {
18d715bd 2356 if (anIter.Key1() != theViewName)
2357 {
2358 aNewViewName = anIter.Key1();
2359 break;
2360 }
c48e2889 2361 }
2362 ActivateView (aNewViewName);
18d715bd 2363 }
2364 else
2365 {
e084dbbc 2366 VT_GetWindow().Nullify();
2367 ViewerTest::CurrentView (Handle(V3d_View)());
18d715bd 2368 if (isContextRemoved)
2369 {
2370 Handle(AIS_InteractiveContext) anEmptyContext;
2371 ViewerTest::SetAISContext(anEmptyContext);
2372 }
2373 }
2374 }
2375
2376 // Delete view
2377 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
2378 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
8693dfd0 2379 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
2380 aRedrawer.Stop (aView->Window());
18d715bd 2381
2382 // Remove view resources
18d715bd 2383 ViewerTest_myViews.UnBind1(theViewName);
851dacdb 2384 aView->Window()->Unmap();
18d715bd 2385 aView->Remove();
2386
2387#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2388 XFlush (GetDisplayConnection()->GetDisplay());
2389#endif
2390
2391 // Keep context opened only if the closed view is last to avoid
2392 // unused empty contexts
2393 if (!aCurrentContext.IsNull())
2394 {
2395 // Check if there are more difined views in the viewer
2396 aCurrentContext->CurrentViewer()->InitDefinedViews();
2397 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
2398 {
2399 // Remove driver if there is no viewers that use it
2400 Standard_Boolean isRemoveDriver = Standard_True;
2401 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2402 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
2403 {
2404 if (aCurrentContext != anIter.Key2() &&
2405 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
2406 {
2407 isRemoveDriver = Standard_False;
2408 break;
2409 }
2410 }
2ec85268 2411
2412 aCurrentContext->RemoveAll (Standard_False);
18d715bd 2413 if(isRemoveDriver)
2414 {
2415 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
2416 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8693dfd0 2417 Tcl_DeleteFileHandler (XConnectionNumber (aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
18d715bd 2418 #endif
2419 }
2420
2421 ViewerTest_myContexts.UnBind2(aCurrentContext);
2422 }
2423 }
04232180 2424 std::cout << "3D View - " << theViewName << " was deleted.\n";
49582f9d 2425 if (ViewerTest_EventManager::ToExitOnCloseView())
fd3f6bd0 2426 {
2427 Draw_Interprete ("exit");
2428 }
18d715bd 2429}
2430
2431//==============================================================================
2432//function : VClose
2433//purpose : Remove the view defined by its name
2434//==============================================================================
2435
d0cc1cb7 2436static int VClose (Draw_Interpretor& /*theDi*/,
2437 Standard_Integer theArgsNb,
2438 const char** theArgVec)
18d715bd 2439{
18d715bd 2440 NCollection_List<TCollection_AsciiString> aViewList;
d0cc1cb7 2441 if (theArgsNb > 1)
18d715bd 2442 {
d0cc1cb7 2443 TCollection_AsciiString anArg (theArgVec[1]);
2444 anArg.UpperCase();
2445 if (anArg.IsEqual ("ALL")
2446 || anArg.IsEqual ("*"))
2447 {
2448 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
2449 anIter.More(); anIter.Next())
2450 {
2451 aViewList.Append (anIter.Key1());
2452 }
2453 if (aViewList.IsEmpty())
2454 {
2455 std::cout << "No view to close\n";
2456 return 0;
2457 }
2458 }
2459 else
18d715bd 2460 {
d0cc1cb7 2461 ViewerTest_Names aViewName (theArgVec[1]);
2462 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
2463 {
2464 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
2465 return 1;
2466 }
2467 aViewList.Append (aViewName.GetViewName());
18d715bd 2468 }
2469 }
2470 else
2471 {
d0cc1cb7 2472 // close active view
2473 if (ViewerTest::CurrentView().IsNull())
2474 {
2475 std::cerr << "No active view!\n";
2476 return 1;
2477 }
2478 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
18d715bd 2479 }
2480
d0cc1cb7 2481 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
18d715bd 2482 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
2483 anIter.More(); anIter.Next())
2484 {
d0cc1cb7 2485 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
18d715bd 2486 }
2487
2488 return 0;
2489}
2490
2491//==============================================================================
2492//function : VActivate
2493//purpose : Activate the view defined by its ID
2494//==============================================================================
2495
2496static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2497{
e084dbbc 2498 if (theArgsNb == 1)
18d715bd 2499 {
2500 theDi.Eval("vviewlist");
2501 return 0;
2502 }
2503
e084dbbc 2504 TCollection_AsciiString aNameString;
2505 Standard_Boolean toUpdate = Standard_True;
2506 Standard_Boolean toActivate = Standard_True;
2507 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
18d715bd 2508 {
e084dbbc 2509 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2510 anArg.LowerCase();
2511 if (toUpdate
2512 && anArg == "-noupdate")
2513 {
2514 toUpdate = Standard_False;
2515 }
2516 else if (toActivate
2517 && aNameString.IsEmpty()
2518 && anArg == "none")
2519 {
49582f9d 2520 ViewerTest::CurrentView()->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
e084dbbc 2521 VT_GetWindow().Nullify();
2522 ViewerTest::CurrentView (Handle(V3d_View)());
2523 ViewerTest::ResetEventManager();
2524 theDi << theArgVec[0] << ": all views are inactive\n";
2525 toActivate = Standard_False;
2526 }
2527 else if (toActivate
2528 && aNameString.IsEmpty())
2529 {
2530 aNameString = theArgVec[anArgIter];
2531 }
2532 else
2533 {
2534 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
2535 return 1;
2536 }
18d715bd 2537 }
2538
e084dbbc 2539 if (!toActivate)
2540 {
2541 return 0;
2542 }
2543 else if (aNameString.IsEmpty())
2544 {
2545 std::cout << "Syntax error: wrong number of arguments\n";
2546 return 1;
2547 }
18d715bd 2548
2549 // Check if this view exists in the viewer with the driver
e084dbbc 2550 ViewerTest_Names aViewNames (aNameString);
18d715bd 2551 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
2552 {
e084dbbc 2553 theDi << "Syntax error: wrong view name '" << aNameString << "'\n";
18d715bd 2554 return 1;
2555 }
2556
2557 // Check if it is active already
2558 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
2559 {
2560 theDi << theArgVec[0] << ": the view is active already\n";
2561 return 0;
2562 }
2563
e084dbbc 2564 ActivateView (aViewNames.GetViewName(), toUpdate);
18d715bd 2565 return 0;
2566}
2567
2568//==============================================================================
2569//function : VViewList
2570//purpose : Print current list of views per viewer and graphic driver ID
2571// shared between viewers
2572//==============================================================================
2573
2574static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
2575{
2576 if (theArgsNb > 2)
2577 {
2578 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
29cb310a 2579 << "Usage: " << theArgVec[0] << " name";
18d715bd 2580 return 1;
2581 }
2582 if (ViewerTest_myContexts.Size() < 1)
2583 return 0;
2584
18d715bd 2585 Standard_Boolean isTreeView =
29cb310a 2586 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
18d715bd 2587
2588 if (isTreeView)
c48e2889 2589 {
18d715bd 2590 theDi << theArgVec[0] <<":\n";
c48e2889 2591 }
18d715bd 2592
c48e2889 2593 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
2594 aDriverIter.More(); aDriverIter.Next())
2595 {
2596 if (isTreeView)
2597 theDi << aDriverIter.Key1() << ":\n";
18d715bd 2598
c48e2889 2599 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2600 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
2601 {
2602 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
18d715bd 2603 {
c48e2889 2604 if (isTreeView)
18d715bd 2605 {
c48e2889 2606 TCollection_AsciiString aContextName(aContextIter.Key1());
2607 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
2608 }
18d715bd 2609
c48e2889 2610 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
2611 aViewIter.More(); aViewIter.Next())
2612 {
2613 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
18d715bd 2614 {
c48e2889 2615 TCollection_AsciiString aViewName(aViewIter.Key1());
2616 if (isTreeView)
18d715bd 2617 {
c48e2889 2618 if (aViewIter.Value() == ViewerTest::CurrentView())
2619 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
18d715bd 2620 else
c48e2889 2621 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
2622 }
2623 else
2624 {
2625 theDi << aViewName << " ";
18d715bd 2626 }
2627 }
2628 }
2629 }
2630 }
c48e2889 2631 }
18d715bd 2632 return 0;
2633}
2634
7fd59977 2635//==============================================================================
49582f9d 2636//function : GetMousePosition
2637//purpose :
7fd59977 2638//==============================================================================
49582f9d 2639void ViewerTest::GetMousePosition (Standard_Integer& theX,
2640 Standard_Integer& theY)
7fd59977 2641{
49582f9d 2642 if (Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager())
4fe56619 2643 {
49582f9d 2644 theX = aViewCtrl->LastMousePosition().x();
2645 theY = aViewCtrl->LastMousePosition().y();
4fe56619 2646 }
7fd59977 2647}
2648
44b8f2d6 2649//==============================================================================
fc552d84 2650//function : VViewProj
2651//purpose : Switch view projection
44b8f2d6 2652//==============================================================================
fc552d84 2653static int VViewProj (Draw_Interpretor& ,
2654 Standard_Integer theNbArgs,
2655 const char** theArgVec)
44b8f2d6 2656{
fc552d84 2657 static Standard_Boolean isYup = Standard_False;
2658 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2659 if (aView.IsNull())
44b8f2d6 2660 {
fc552d84 2661 std::cout << "Error: no active view\n";
44b8f2d6 2662 return 1;
2663 }
2664
fc552d84 2665 TCollection_AsciiString aCmdName (theArgVec[0]);
2666 Standard_Boolean isGeneralCmd = Standard_False;
2667 if (aCmdName == "vfront")
2668 {
2669 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup);
2670 }
2671 else if (aCmdName == "vback")
2672 {
2673 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup);
2674 }
2675 else if (aCmdName == "vtop")
2676 {
2677 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup);
2678 }
2679 else if (aCmdName == "vbottom")
2680 {
2681 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup);
2682 }
2683 else if (aCmdName == "vleft")
2684 {
2685 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup);
2686 }
2687 else if (aCmdName == "vright")
2688 {
2689 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup);
2690 }
2691 else if (aCmdName == "vaxo")
2692 {
2693 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup);
2694 }
2695 else
2696 {
2697 isGeneralCmd = Standard_True;
2698 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
2699 {
2700 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2701 anArgCase.LowerCase();
2702 if (anArgCase == "-zup")
2703 {
2704 isYup = Standard_False;
2705 }
2706 else if (anArgCase == "-yup")
2707 {
2708 isYup = Standard_True;
2709 }
2710 else if (anArgCase == "-front"
2711 || anArgCase == "front"
2712 || anArgCase == "-f"
2713 || anArgCase == "f")
2714 {
2715 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup);
2716 }
2717 else if (anArgCase == "-back"
2718 || anArgCase == "back"
2719 || anArgCase == "-b"
2720 || anArgCase == "b")
2721 {
2722 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup);
2723 }
2724 else if (anArgCase == "-top"
2725 || anArgCase == "top"
2726 || anArgCase == "-t"
2727 || anArgCase == "t")
2728 {
2729 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup);
2730 }
2731 else if (anArgCase == "-bottom"
2732 || anArgCase == "bottom"
2733 || anArgCase == "-bot"
2734 || anArgCase == "bot"
2735 || anArgCase == "-b"
2736 || anArgCase == "b")
2737 {
2738 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup);
2739 }
2740 else if (anArgCase == "-left"
2741 || anArgCase == "left"
2742 || anArgCase == "-l"
2743 || anArgCase == "l")
2744 {
2745 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup);
2746 }
2747 else if (anArgCase == "-right"
2748 || anArgCase == "right"
2749 || anArgCase == "-r"
2750 || anArgCase == "r")
2751 {
2752 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup);
2753 }
2754 else if (anArgCase == "-axoleft"
2755 || anArgCase == "-leftaxo"
2756 || anArgCase == "axoleft"
2757 || anArgCase == "leftaxo")
2758 {
2759 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoLeft : V3d_TypeOfOrientation_Zup_AxoLeft, isYup);
2760 }
2761 else if (anArgCase == "-axo"
2762 || anArgCase == "axo"
2763 || anArgCase == "-a"
2764 || anArgCase == "a"
2765 || anArgCase == "-axoright"
2766 || anArgCase == "-rightaxo"
2767 || anArgCase == "axoright"
2768 || anArgCase == "rightaxo")
2769 {
2770 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup);
2771 }
2772 else if (anArgCase == "+x")
2773 {
2774 aView->SetProj (V3d_Xpos, isYup);
2775 }
2776 else if (anArgCase == "-x")
2777 {
2778 aView->SetProj (V3d_Xneg, isYup);
2779 }
2780 else if (anArgCase == "+y")
2781 {
2782 aView->SetProj (V3d_Ypos, isYup);
2783 }
2784 else if (anArgCase == "-y")
2785 {
2786 aView->SetProj (V3d_Yneg, isYup);
2787 }
2788 else if (anArgCase == "+z")
2789 {
2790 aView->SetProj (V3d_Zpos, isYup);
2791 }
2792 else if (anArgCase == "-z")
2793 {
2794 aView->SetProj (V3d_Zneg, isYup);
2795 }
2796 else if (anArgCase == "+x+y+z")
2797 {
2798 aView->SetProj (V3d_XposYposZpos, isYup);
2799 }
2800 else if (anArgCase == "+x+y-z")
2801 {
2802 aView->SetProj (V3d_XposYposZneg, isYup);
2803 }
2804 else if (anArgCase == "+x-y+z")
2805 {
2806 aView->SetProj (V3d_XposYnegZpos, isYup);
2807 }
2808 else if (anArgCase == "+x-y-z")
2809 {
2810 aView->SetProj (V3d_XposYnegZneg, isYup);
2811 }
2812 else if (anArgCase == "-x+y+z")
2813 {
2814 aView->SetProj (V3d_XnegYposZpos, isYup);
2815 }
2816 else if (anArgCase == "-x+y-z")
2817 {
2818 aView->SetProj (V3d_XnegYposZneg, isYup);
2819 }
2820 else if (anArgCase == "-x-y+z")
2821 {
2822 aView->SetProj (V3d_XnegYnegZpos, isYup);
2823 }
2824 else if (anArgCase == "-x-y-z")
2825 {
2826 aView->SetProj (V3d_XnegYnegZneg, isYup);
2827 }
2828 else if (anArgCase == "+x+y")
2829 {
2830 aView->SetProj (V3d_XposYpos, isYup);
2831 }
2832 else if (anArgCase == "+x-y")
2833 {
2834 aView->SetProj (V3d_XposYneg, isYup);
2835 }
2836 else if (anArgCase == "-x+y")
2837 {
2838 aView->SetProj (V3d_XnegYpos, isYup);
2839 }
2840 else if (anArgCase == "-x-y")
2841 {
2842 aView->SetProj (V3d_XnegYneg, isYup);
2843 }
2844 else if (anArgCase == "+x+z")
2845 {
2846 aView->SetProj (V3d_XposZpos, isYup);
2847 }
2848 else if (anArgCase == "+x-z")
2849 {
2850 aView->SetProj (V3d_XposZneg, isYup);
2851 }
2852 else if (anArgCase == "-x+z")
2853 {
2854 aView->SetProj (V3d_XnegZpos, isYup);
2855 }
2856 else if (anArgCase == "-x-z")
2857 {
2858 aView->SetProj (V3d_XnegZneg, isYup);
2859 }
2860 else if (anArgCase == "+y+z")
2861 {
2862 aView->SetProj (V3d_YposZpos, isYup);
2863 }
2864 else if (anArgCase == "+y-z")
2865 {
2866 aView->SetProj (V3d_YposZneg, isYup);
2867 }
2868 else if (anArgCase == "-y+z")
2869 {
2870 aView->SetProj (V3d_YnegZpos, isYup);
2871 }
2872 else if (anArgCase == "-y-z")
2873 {
2874 aView->SetProj (V3d_YnegZneg, isYup);
2875 }
2876 else if (anArgIter + 1 < theNbArgs
2877 && anArgCase == "-frame"
2878 && TCollection_AsciiString (theArgVec[anArgIter + 1]).Length() == 4)
2879 {
2880 TCollection_AsciiString aFrameDef (theArgVec[++anArgIter]);
2881 aFrameDef.LowerCase();
2882 gp_Dir aRight, anUp;
2883 if (aFrameDef.Value (2) == aFrameDef.Value (4))
2884 {
2885 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
2886 return 1;
2887 }
44b8f2d6 2888
fc552d84 2889 if (aFrameDef.Value (2) == 'x')
2890 {
2891 aRight = aFrameDef.Value (1) == '+' ? gp::DX() : -gp::DX();
2892 }
2893 else if (aFrameDef.Value (2) == 'y')
2894 {
2895 aRight = aFrameDef.Value (1) == '+' ? gp::DY() : -gp::DY();
2896 }
2897 else if (aFrameDef.Value (2) == 'z')
2898 {
2899 aRight = aFrameDef.Value (1) == '+' ? gp::DZ() : -gp::DZ();
2900 }
2901 else
2902 {
2903 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
2904 return 1;
2905 }
7fd59977 2906
fc552d84 2907 if (aFrameDef.Value (4) == 'x')
2908 {
2909 anUp = aFrameDef.Value (3) == '+' ? gp::DX() : -gp::DX();
2910 }
2911 else if (aFrameDef.Value (4) == 'y')
2912 {
2913 anUp = aFrameDef.Value (3) == '+' ? gp::DY() : -gp::DY();
2914 }
2915 else if (aFrameDef.Value (4) == 'z')
2916 {
2917 anUp = aFrameDef.Value (3) == '+' ? gp::DZ() : -gp::DZ();
2918 }
2919 else
2920 {
2921 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
2922 return 1;
2923 }
44b8f2d6 2924
fc552d84 2925 const Handle(Graphic3d_Camera)& aCamera = aView->Camera();
2926 const gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin());
2927 const gp_Dir aDir = anUp.Crossed (aRight);
2928 aCamera->SetCenter (gp_Pnt (0, 0, 0));
2929 aCamera->SetDirection (aDir);
2930 aCamera->SetUp (anUp);
2931 aCamera->OrthogonalizeUp();
44b8f2d6 2932
fc552d84 2933 aView->Panning (anOriginVCS.X(), anOriginVCS.Y());
2934 aView->Update();
2935 }
2936 else
2937 {
2938 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
2939 return 1;
2940 }
2941 }
2942 }
44b8f2d6 2943
fc552d84 2944 if (!isGeneralCmd
2945 && theNbArgs != 1)
2946 {
2947 std::cout << "Syntax error: wrong number of arguments\n";
2948 return 1;
2949 }
2950 return 0;
7fd59977 2951}
2952
2953//==============================================================================
2954//function : VHelp
2955//purpose : Dsiplay help on viewer Keyboead and mouse commands
2956//Draw arg : No args
2957//==============================================================================
2958
2959static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2960{
586db386 2961 di << "=========================\n";
2962 di << "F : FitAll\n";
2963 di << "T : TopView\n";
2964 di << "B : BottomView\n";
2965 di << "R : RightView\n";
2966 di << "L : LeftView\n";
2967 di << "A : AxonometricView\n";
2968 di << "D : ResetView\n";
2969
2970 di << "=========================\n";
2971 di << "S : Shading\n";
2972 di << "W : Wireframe\n";
49582f9d 2973 di << "H : HiddenLineRemoval\n";
586db386 2974 di << "U : Unset display mode\n";
2975 di << "Delete : Remove selection from viewer\n";
2976
2977 di << "=========================\n";
2978 di << "Selection mode \n";
2979 di << "0 : Shape\n";
2980 di << "1 : Vertex\n";
2981 di << "2 : Edge\n";
2982 di << "3 : Wire\n";
2983 di << "4 : Face\n";
2984 di << "5 : Shell\n";
2985 di << "6 : Solid\n";
2986 di << "7 : Compound\n";
2987
2988 di << "=========================\n";
49582f9d 2989 di << "< : Hilight next detected\n";
2990 di << "> : Hilight previous detected\n";
7fd59977 2991
2992 return 0;
2993}
2994
57c28b61 2995#ifdef _WIN32
7fd59977 2996
49582f9d 2997static LRESULT WINAPI AdvViewerWindowProc (HWND theWinHandle,
2998 UINT theMsg,
2999 WPARAM wParam,
3000 LPARAM lParam )
7fd59977 3001{
49582f9d 3002 if (ViewerTest_myViews.IsEmpty())
3003 {
3004 return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam);
3005 }
7fd59977 3006
49582f9d 3007 switch (theMsg)
3008 {
18d715bd 3009 case WM_CLOSE:
49582f9d 3010 {
3011 // Delete view from map of views
3012 ViewerTest::RemoveView (FindViewIdByWindowHandle (theWinHandle));
3013 return 0;
3014 }
18d715bd 3015 case WM_ACTIVATE:
49582f9d 3016 {
3017 if (LOWORD(wParam) == WA_CLICKACTIVE
3018 || LOWORD(wParam) == WA_ACTIVE
3019 || ViewerTest::CurrentView().IsNull())
18d715bd 3020 {
3021 // Activate inactive window
49582f9d 3022 if (VT_GetWindow().IsNull()
3023 || (HWND )VT_GetWindow()->HWindow() != theWinHandle)
625e1958 3024 {
49582f9d 3025 ActivateView (FindViewIdByWindowHandle (theWinHandle));
625e1958 3026 }
7fd59977 3027 }
7fd59977 3028 break;
49582f9d 3029 }
7fd59977 3030 default:
49582f9d 3031 {
3032 return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam);
7fd59977 3033 }
7fd59977 3034 }
49582f9d 3035 return 0;
7fd59977 3036}
3037
49582f9d 3038static LRESULT WINAPI ViewerWindowProc (HWND theWinHandle,
3039 UINT theMsg,
3040 WPARAM wParam,
3041 LPARAM lParam)
7fd59977 3042{
f978241f 3043 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3044 if (aView.IsNull())
3045 {
49582f9d 3046 return DefWindowProcW (theWinHandle, theMsg, wParam, lParam);
f978241f 3047 }
7fd59977 3048
49582f9d 3049 switch (theMsg)
3050 {
7fd59977 3051 case WM_PAINT:
49582f9d 3052 {
3053 PAINTSTRUCT aPaint;
3054 BeginPaint(theWinHandle, &aPaint);
3055 EndPaint (theWinHandle, &aPaint);
3056 ViewerTest::CurrentEventManager()->ProcessExpose();
7fd59977 3057 break;
49582f9d 3058 }
7fd59977 3059 case WM_SIZE:
49582f9d 3060 {
3061 ViewerTest::CurrentEventManager()->ProcessConfigure();
7fd59977 3062 break;
49582f9d 3063 }
f978241f 3064 case WM_MOVE:
3065 case WM_MOVING:
3066 case WM_SIZING:
49582f9d 3067 {
f978241f 3068 switch (aView->RenderingParams().StereoMode)
3069 {
3070 case Graphic3d_StereoMode_RowInterlaced:
3071 case Graphic3d_StereoMode_ColumnInterlaced:
3072 case Graphic3d_StereoMode_ChessBoard:
49582f9d 3073 {
3074 // track window moves to reverse stereo pair
3075 aView->MustBeResized();
3076 aView->Update();
f978241f 3077 break;
49582f9d 3078 }
f978241f 3079 default:
3080 break;
3081 }
3082 break;
49582f9d 3083 }
3084 case WM_KEYUP:
7fd59977 3085 case WM_KEYDOWN:
49582f9d 3086 {
3087 const Aspect_VKey aVKey = WNT_Window::VirtualKeyFromNative ((Standard_Integer )wParam);
3088 if (aVKey != Aspect_VKey_UNKNOWN)
4fe56619 3089 {
49582f9d 3090 const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime();
3091 if (theMsg == WM_KEYDOWN)
f978241f 3092 {
49582f9d 3093 ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp);
f978241f 3094 }
49582f9d 3095 else
f978241f 3096 {
49582f9d 3097 ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp);
f978241f 3098 }
49582f9d 3099 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
7fd59977 3100 }
3101 break;
49582f9d 3102 }
7fd59977 3103 case WM_LBUTTONUP:
3104 case WM_MBUTTONUP:
3105 case WM_RBUTTONUP:
7fd59977 3106 case WM_LBUTTONDOWN:
3107 case WM_MBUTTONDOWN:
3108 case WM_RBUTTONDOWN:
49582f9d 3109 {
3110 const Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam));
3111 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam);
3112 Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE;
3113 switch (theMsg)
7fd59977 3114 {
49582f9d 3115 case WM_LBUTTONUP:
3116 case WM_LBUTTONDOWN:
3117 aButton = Aspect_VKeyMouse_LeftButton;
3118 break;
3119 case WM_MBUTTONUP:
3120 case WM_MBUTTONDOWN:
3121 aButton = Aspect_VKeyMouse_MiddleButton;
3122 break;
3123 case WM_RBUTTONUP:
3124 case WM_RBUTTONDOWN:
3125 aButton = Aspect_VKeyMouse_RightButton;
3126 break;
7fd59977 3127 }
49582f9d 3128 if (theMsg == WM_LBUTTONDOWN
3129 || theMsg == WM_MBUTTONDOWN
3130 || theMsg == WM_RBUTTONDOWN)
f978241f 3131 {
49582f9d 3132 if (aButton == Aspect_VKeyMouse_LeftButton)
f978241f 3133 {
49582f9d 3134 TheIsAnimating = Standard_False;
f978241f 3135 }
49582f9d 3136
3137 SetFocus (theWinHandle);
3138 SetCapture(theWinHandle);
3139 ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false);
f978241f 3140 }
3141 else
3142 {
49582f9d 3143 ReleaseCapture();
3144 ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false);
f978241f 3145 }
49582f9d 3146 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
f978241f 3147 break;
3148 }
49582f9d 3149 case WM_MOUSEWHEEL:
3150 {
3151 const int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
3152 const Standard_Real aDeltaF = Standard_Real(aDelta) / Standard_Real(WHEEL_DELTA);
3153 const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam);
3154 Graphic3d_Vec2i aPos (int(short(LOWORD(lParam))), int(short(HIWORD(lParam))));
3155 POINT aCursorPnt = { aPos.x(), aPos.y() };
3156 if (ScreenToClient (theWinHandle, &aCursorPnt))
7fd59977 3157 {
49582f9d 3158 aPos.SetValues (aCursorPnt.x, aCursorPnt.y);
3159 }
7fd59977 3160
49582f9d 3161 ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags));
3162 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
3163 break;
3164 }
3165 case WM_MOUSEMOVE:
3166 {
3167 Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam));
3168 Aspect_VKeyMouse aButtons = WNT_Window::MouseButtonsFromEvent (wParam);
3169 Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent(wParam);
7fd59977 3170
49582f9d 3171 // don't make a slide-show from input events - fetch the actual mouse cursor position
3172 CURSORINFO aCursor;
3173 aCursor.cbSize = sizeof(aCursor);
3174 if (::GetCursorInfo (&aCursor) != FALSE)
3175 {
3176 POINT aCursorPnt = { aCursor.ptScreenPos.x, aCursor.ptScreenPos.y };
3177 if (ScreenToClient (theWinHandle, &aCursorPnt))
3178 {
3179 // as we override mouse position, we need overriding also mouse state
3180 aPos.SetValues (aCursorPnt.x, aCursorPnt.y);
3181 aButtons = WNT_Window::MouseButtonsAsync();
3182 aFlags = WNT_Window::MouseKeyFlagsAsync();
3183 }
3184 }
7fd59977 3185
49582f9d 3186 if (VT_GetWindow().IsNull()
3187 || (HWND )VT_GetWindow()->HWindow() != theWinHandle)
3188 {
3189 // mouse move events come also for inactive windows
3190 break;
7fd59977 3191 }
7fd59977 3192
49582f9d 3193 ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
3194 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
3195 break;
3196 }
7fd59977 3197 default:
49582f9d 3198 {
3199 return DefWindowProcW (theWinHandle, theMsg, wParam, lParam);
7fd59977 3200 }
49582f9d 3201 }
3202 return 0L;
7fd59977 3203}
3204
7fd59977 3205//==============================================================================
3206//function : ViewerMainLoop
3207//purpose : Get a Event on the view and dispatch it
3208//==============================================================================
3209
49582f9d 3210int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec)
7fd59977 3211{
49582f9d 3212 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
3213 if (aViewCtrl.IsNull()
3214 || theNbArgs < 4)
3215 {
3216 return 0;
3217 }
7fd59977 3218
49582f9d 3219 aViewCtrl->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]);
7fd59977 3220
49582f9d 3221 std::cout << "Start picking\n";
7fd59977 3222
49582f9d 3223 MSG aMsg;
3224 aMsg.wParam = 1;
3225 while (aViewCtrl->ToPickPoint())
3226 {
3227 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
3228 if (GetMessageW (&aMsg, NULL, 0, 0))
3229 {
3230 TranslateMessage (&aMsg);
3231 DispatchMessageW (&aMsg);
7fd59977 3232 }
7fd59977 3233 }
3234
49582f9d 3235 std::cout << "Picking done\n";
3236 return 0;
7fd59977 3237}
3238
4fe56619 3239#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 3240
3241int min( int a, int b )
3242{
3243 if( a<b )
3244 return a;
3245 else
3246 return b;
3247}
3248
3249int max( int a, int b )
3250{
3251 if( a>b )
3252 return a;
3253 else
3254 return b;
3255}
3256
49582f9d 3257int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec)
4269bd1b 3258{
18d715bd 3259 static XEvent aReport;
49582f9d 3260 const Standard_Boolean toPick = theNbArgs > 0;
3261 if (theNbArgs > 0)
3262 {
3263 if (ViewerTest::CurrentEventManager().IsNull())
3264 {
3265 return 0;
3266 }
3267 ViewerTest::CurrentEventManager()->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]);
3268 }
3269
8693dfd0 3270 Display* aDisplay = GetDisplayConnection()->GetDisplay();
18d715bd 3271 XNextEvent (aDisplay, &aReport);
7fd59977 3272
18d715bd 3273 // Handle event for the chosen display connection
8693dfd0 3274 switch (aReport.type)
3275 {
3276 case ClientMessage:
3277 {
3278 if ((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
3279 {
3280 // Close the window
3281 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
3282 return toPick ? 0 : 1;
3283 }
3284 break;
3285 }
3286 case FocusIn:
3287 {
3288 // Activate inactive view
49582f9d 3289 Window aWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
8693dfd0 3290 if (aWindow != aReport.xfocus.window)
3291 {
3292 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
3293 }
3294 break;
3295 }
3296 case Expose:
3297 {
49582f9d 3298 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
8693dfd0 3299 if (anXWindow == aReport.xexpose.window)
3300 {
49582f9d 3301 ViewerTest::CurrentEventManager()->ProcessExpose();
8693dfd0 3302 }
3303
3304 // remove all the ExposureMask and process them at once
3305 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3306 {
3307 if (!XCheckWindowEvent (aDisplay, anXWindow, ExposureMask, &aReport))
18d715bd 3308 {
8693dfd0 3309 break;
18d715bd 3310 }
8693dfd0 3311 }
3312
3313 break;
3314 }
3315 case ConfigureNotify:
3316 {
3317 // remove all the StructureNotifyMask and process them at once
49582f9d 3318 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
8693dfd0 3319 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3320 {
3321 if (!XCheckWindowEvent (aDisplay, anXWindow, StructureNotifyMask, &aReport))
3322 {
3323 break;
3324 }
3325 }
3326
3327 if (anXWindow == aReport.xconfigure.window)
3328 {
49582f9d 3329 ViewerTest::CurrentEventManager()->ProcessConfigure();
8693dfd0 3330 }
3331 break;
3332 }
3333 case KeyPress:
49582f9d 3334 case KeyRelease:
8693dfd0 3335 {
49582f9d 3336 XKeyEvent* aKeyEvent = (XKeyEvent* )&aReport;
3337 const KeySym aKeySym = XLookupKeysym (aKeyEvent, 0);
3338 const Aspect_VKey aVKey = Xw_Window::VirtualKeyFromNative (aKeySym);
3339 if (aVKey != Aspect_VKey_UNKNOWN)
8693dfd0 3340 {
49582f9d 3341 const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime();
3342 if (aReport.type == KeyPress)
7fd59977 3343 {
49582f9d 3344 ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp);
7fd59977 3345 }
8693dfd0 3346 else
7fd59977 3347 {
49582f9d 3348 ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp);
7fd59977 3349 }
49582f9d 3350 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
8693dfd0 3351 }
3352 break;
3353 }
49582f9d 3354 case ButtonPress:
8693dfd0 3355 case ButtonRelease:
3356 {
49582f9d 3357 const Graphic3d_Vec2i aPos (aReport.xbutton.x, aReport.xbutton.y);
3358 Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
3359 Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE;
3360 if (aReport.xbutton.button == Button1)
8693dfd0 3361 {
49582f9d 3362 aButton = Aspect_VKeyMouse_LeftButton;
8693dfd0 3363 }
49582f9d 3364 if (aReport.xbutton.button == Button2)
8693dfd0 3365 {
49582f9d 3366 aButton = Aspect_VKeyMouse_MiddleButton;
8693dfd0 3367 }
49582f9d 3368 if (aReport.xbutton.button == Button3)
8693dfd0 3369 {
49582f9d 3370 aButton = Aspect_VKeyMouse_RightButton;
8693dfd0 3371 }
7fd59977 3372
49582f9d 3373 if (aReport.xbutton.state & ControlMask)
8693dfd0 3374 {
49582f9d 3375 aFlags |= Aspect_VKeyFlags_CTRL;
3376 }
3377 if (aReport.xbutton.state & ShiftMask)
3378 {
3379 aFlags |= Aspect_VKeyFlags_SHIFT;
3380 }
3381 if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt))
3382 {
3383 aFlags |= Aspect_VKeyFlags_ALT;
8693dfd0 3384 }
7fd59977 3385
49582f9d 3386 if (aReport.xbutton.button == Button4
3387 || aReport.xbutton.button == Button5)
8693dfd0 3388 {
49582f9d 3389 if (aReport.type != ButtonPress)
8693dfd0 3390 {
49582f9d 3391 break;
7fd59977 3392 }
49582f9d 3393
3394 const double aDeltaF = (aReport.xbutton.button == Button4 ? 1.0 : -1.0);
3395 ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags));
3396 }
3397 else if (aReport.type == ButtonPress)
3398 {
3399 if (aButton == Aspect_VKeyMouse_LeftButton)
7fd59977 3400 {
49582f9d 3401 TheIsAnimating = Standard_False;
7fd59977 3402 }
49582f9d 3403 ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false);
8693dfd0 3404 }
3405 else
3406 {
49582f9d 3407 ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false);
8693dfd0 3408 }
49582f9d 3409 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
8693dfd0 3410 break;
3411 }
3412 case MotionNotify:
3413 {
49582f9d 3414 Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
8693dfd0 3415 if (anXWindow != aReport.xmotion.window)
3416 {
7fd59977 3417 break;
8693dfd0 3418 }
3419
3420 // remove all the ButtonMotionMask and process them at once
3421 for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents)
3422 {
3423 if (!XCheckWindowEvent (aDisplay, anXWindow, ButtonMotionMask | PointerMotionMask, &aReport))
7fd59977 3424 {
8693dfd0 3425 break;
3426 }
3427 }
7fd59977 3428
49582f9d 3429 Graphic3d_Vec2i aPos (aReport.xmotion.x, aReport.xmotion.y);
3430 Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
3431 Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
3432 if ((aReport.xmotion.state & Button1Mask) != 0)
8693dfd0 3433 {
49582f9d 3434 aButtons |= Aspect_VKeyMouse_LeftButton;
3435 }
3436 else if ((aReport.xmotion.state & Button2Mask) != 0)
3437 {
3438 aButtons |= Aspect_VKeyMouse_MiddleButton;
3439 }
3440 else if ((aReport.xmotion.state & Button3Mask) != 0)
3441 {
3442 aButtons |= Aspect_VKeyMouse_RightButton;
3443 }
7fd59977 3444
49582f9d 3445 if (aReport.xmotion.state & ControlMask)
3446 {
3447 aFlags |= Aspect_VKeyFlags_CTRL;
8693dfd0 3448 }
49582f9d 3449 if (aReport.xmotion.state & ShiftMask)
8693dfd0 3450 {
49582f9d 3451 aFlags |= Aspect_VKeyFlags_SHIFT;
8693dfd0 3452 }
49582f9d 3453 if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt))
3454 {
3455 aFlags |= Aspect_VKeyFlags_ALT;
3456 }
3457
3458 ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
3459 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
8693dfd0 3460 break;
3461 }
3462 }
49582f9d 3463 return (!toPick || ViewerTest::CurrentEventManager()->ToPickPoint()) ? 1 : 0;
7fd59977 3464}
3465
3466//==============================================================================
3467//function : VProcessEvents
8693dfd0 3468//purpose : manage the event in the Viewer window (see Tcl_CreateFileHandler())
7fd59977 3469//==============================================================================
8693dfd0 3470static void VProcessEvents (ClientData theDispX, int)
7fd59977 3471{
8693dfd0 3472 Display* aDispX = (Display* )theDispX;
3473 Handle(Aspect_DisplayConnection) aDispConn;
3474 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
3475 aDriverIter (ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
18d715bd 3476 {
8693dfd0 3477 const Handle(Aspect_DisplayConnection)& aDispConnTmp = aDriverIter.Key2()->GetDisplayConnection();
3478 if (aDispConnTmp->GetDisplay() == aDispX)
3479 {
3480 aDispConn = aDispConnTmp;
3481 break;
3482 }
3483 }
3484 if (aDispConn.IsNull())
3485 {
3486 std::cerr << "Error: ViewerTest is unable processing messages for unknown X Display\n";
3487 return;
4269bd1b 3488 }
8693dfd0 3489
3490 // process new events in queue
3491 SetDisplayConnection (aDispConn);
3492 int aNbRemain = 0;
3493 for (int aNbEventsMax = XPending (aDispX), anEventIter (0);;)
18d715bd 3494 {
8693dfd0 3495 const int anEventResult = ViewerMainLoop (0, NULL);
3496 if (anEventResult == 0)
18d715bd 3497 {
8693dfd0 3498 return;
3499 }
3500
3501 aNbRemain = XPending (aDispX);
3502 if (++anEventIter >= aNbEventsMax
3503 || aNbRemain <= 0)
3504 {
3505 break;
18d715bd 3506 }
7fd59977 3507 }
4269bd1b 3508
8693dfd0 3509 // Listening X events through Tcl_CreateFileHandler() callback is fragile,
3510 // it is possible that new events will arrive to queue before the end of this callback
3511 // so that either this callback should go into an infinite loop (blocking processing of other events)
3512 // or to keep unprocessed events till the next queue update (which can arrive not soon).
3513 // Sending a dummy event in this case is a simple workaround (still, it is possible that new event will be queued in-between).
3514 if (aNbRemain != 0)
3515 {
3516 XEvent aDummyEvent;
3517 memset (&aDummyEvent, 0, sizeof(aDummyEvent));
3518 aDummyEvent.type = ClientMessage;
3519 aDummyEvent.xclient.format = 32;
3520 XSendEvent (aDispX, InputFocus, False, 0, &aDummyEvent);
3521 XFlush (aDispX);
3522 }
4269bd1b 3523
8693dfd0 3524 if (const Handle(AIS_InteractiveContext)& anActiveCtx = ViewerTest::GetAISContext())
3525 {
3526 SetDisplayConnection (anActiveCtx->CurrentViewer()->Driver()->GetDisplayConnection());
3527 }
7fd59977 3528}
3529#endif
3530
3531//==============================================================================
3532//function : OSWindowSetup
3533//purpose : Setup for the X11 window to be able to cath the event
3534//==============================================================================
3535
3536
3537static void OSWindowSetup()
3538{
4fe56619 3539#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 3540 // X11
3541
3542 Window window = VT_GetWindow()->XWindow();
18d715bd 3543 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
3544 Display *aDisplay = GetDisplayConnection()->GetDisplay();
3545 XSynchronize(aDisplay, 1);
7fd59977 3546
3547 // X11 : For keyboard on SUN
3548 XWMHints wmhints;
3549 wmhints.flags = InputHint;
3550 wmhints.input = 1;
3551
18d715bd 3552 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 3553
49582f9d 3554 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | KeyReleaseMask |
7fd59977 3555 ButtonPressMask | ButtonReleaseMask |
3556 StructureNotifyMask |
3557 PointerMotionMask |
3558 Button1MotionMask | Button2MotionMask |
18d715bd 3559 Button3MotionMask | FocusChangeMask
7fd59977 3560 );
18d715bd 3561 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
3562 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 3563
18d715bd 3564 XSynchronize(aDisplay, 0);
7fd59977 3565
3566#else
57c28b61 3567 // _WIN32
7fd59977 3568#endif
3569
3570}
3571
7fd59977 3572//==============================================================================
3573//function : VFit
1beb58d7 3574//purpose :
7fd59977 3575//==============================================================================
3576
1beb58d7 3577static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
7fd59977 3578{
1beb58d7 3579 const Handle(V3d_View) aView = ViewerTest::CurrentView();
3580 if (aView.IsNull())
b586500b 3581 {
1beb58d7 3582 std::cout << "Error: no active viewer!\n";
3583 return 1;
b586500b 3584 }
3585
1beb58d7 3586 Standard_Boolean toFit = Standard_True;
3587 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
3588 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
b586500b 3589 {
1beb58d7 3590 TCollection_AsciiString anArg (theArgv[anArgIter]);
b586500b 3591 anArg.LowerCase();
1beb58d7 3592 if (anUpdateTool.parseRedrawMode (anArg))
b586500b 3593 {
1beb58d7 3594 continue;
3595 }
3596 else if (anArg == "-selected")
3597 {
3598 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
3599 toFit = Standard_False;
3600 }
3601 else
3602 {
3603 std::cout << "Syntax error at '" << anArg << "'\n";
b586500b 3604 }
3605 }
3606
1beb58d7 3607 if (toFit)
3608 {
3609 aView->FitAll (0.01, Standard_False);
7fd59977 3610 }
3611 return 0;
3612}
3613
6262a303 3614//=======================================================================
3615//function : VFitArea
3616//purpose : Fit view to show area located between two points
3617// : given in world 2D or 3D coordinates.
3618//=======================================================================
3619static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3620{
3621 Handle(V3d_View) aView = ViewerTest::CurrentView();
3622 if (aView.IsNull())
3623 {
3624 std::cerr << theArgVec[0] << "Error: No active view.\n";
3625 return 1;
3626 }
3627
3628 // Parse arguments.
3629 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
3630 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
3631
3632 if (theArgNb == 5)
3633 {
3634 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
3635 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
3636 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
3637 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
3638 }
3639 else if (theArgNb == 7)
3640 {
3641 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
3642 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
3643 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
3644 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
3645 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
3646 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
3647 }
3648 else
3649 {
3650 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
3651 theDI.PrintHelp(theArgVec[0]);
3652 return 1;
3653 }
3654
3655 // Convert model coordinates to view space
3656 Handle(Graphic3d_Camera) aCamera = aView->Camera();
3657 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
3658 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
3659
3660 // Determine fit area
3661 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
3662 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
3663
3664 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
3665
3666 if (aDiagonal < Precision::Confusion())
3667 {
3668 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
3669 return 1;
3670 }
3671
3672 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
3673 return 0;
3674}
3675
7fd59977 3676//==============================================================================
3677//function : VZFit
3678//purpose : ZFitall, no DRAW arguments
3679//Draw arg : No args
3680//==============================================================================
197ac94e 3681static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 3682{
197ac94e 3683 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
3684
3685 if (aCurrentView.IsNull())
3686 {
3687 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
3688 return 1;
3689 }
3690
3691 if (theArgsNb == 1)
3692 {
c357e426 3693 aCurrentView->ZFitAll();
197ac94e 3694 aCurrentView->Redraw();
3695 return 0;
3696 }
3697
3698 Standard_Real aScale = 1.0;
3699
3700 if (theArgsNb >= 2)
3701 {
3702 aScale = Draw::Atoi (theArgVec[1]);
3703 }
3704
c357e426 3705 aCurrentView->ZFitAll (aScale);
197ac94e 3706 aCurrentView->Redraw();
7fd59977 3707
197ac94e 3708 return 0;
3709}
7fd59977 3710
197ac94e 3711//==============================================================================
3712//function : VRepaint
3713//purpose :
3714//==============================================================================
56689b27 3715static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
7fd59977 3716{
56689b27 3717 Handle(V3d_View) aView = ViewerTest::CurrentView();
3718 if (aView.IsNull())
3719 {
3720 std::cout << "Error: no active viewer!\n";
3721 return 1;
3722 }
3723
3724 Standard_Boolean isImmediateUpdate = Standard_False;
3725 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3726 {
3727 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3728 anArg.LowerCase();
8693dfd0 3729 if (anArg == "-immediate"
3730 || anArg == "-imm")
56689b27 3731 {
3732 isImmediateUpdate = Standard_True;
3733 if (anArgIter + 1 < theArgNb
3734 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
3735 {
3736 ++anArgIter;
3737 }
3738 }
8693dfd0 3739 else if (anArg == "-continuous"
3740 || anArg == "-cont"
3741 || anArg == "-fps"
3742 || anArg == "-framerate")
3743 {
3744 Standard_Real aFps = -1.0;
3745 if (anArgIter + 1 < theArgNb
3746 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue())
3747 {
3748 aFps = Draw::Atof (theArgVec[++anArgIter]);
3749 }
3750
3751 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
3752 if (Abs (aFps) >= 1.0)
3753 {
3754 aRedrawer.Start (aView->Window(), aFps);
3755 }
3756 else
3757 {
3758 aRedrawer.Stop();
3759 }
3760 }
56689b27 3761 else
3762 {
3763 std::cout << "Syntax error at '" << anArg << "'\n";
8693dfd0 3764 return 1;
56689b27 3765 }
3766 }
3767
3768 if (isImmediateUpdate)
3769 {
3770 aView->RedrawImmediate();
3771 }
3772 else
3773 {
3774 aView->Redraw();
3775 }
3776 return 0;
7fd59977 3777}
3778
7fd59977 3779//==============================================================================
3780//function : VClear
3781//purpose : Remove all the object from the viewer
3782//Draw arg : No args
3783//==============================================================================
3784
3785static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3786{
3787 Handle(V3d_View) V = ViewerTest::CurrentView();
3788 if(!V.IsNull())
3789 ViewerTest::Clear();
3790 return 0;
3791}
3792
3793//==============================================================================
3794//function : VPick
3795//purpose :
3796//==============================================================================
3797
49582f9d 3798static int VPick (Draw_Interpretor& ,
3799 Standard_Integer theNbArgs,
3800 const char** theArgVec)
3801{
3802 if (ViewerTest::CurrentView().IsNull())
3803 {
3804 return 1;
3805 }
7fd59977 3806
49582f9d 3807 if (theNbArgs < 4)
3808 {
3809 std::cout << "Syntax error: Invalid number of arguments\n";
3810 return 1;
3811 }
7fd59977 3812
49582f9d 3813 while (ViewerMainLoop (theNbArgs, theArgVec))
3814 {
3815 //
3816 }
7fd59977 3817
49582f9d 3818 return 0;
7fd59977 3819}
3820
293211ae 3821namespace
7fd59977 3822{
7fd59977 3823
293211ae 3824 //! Changes the background
3825 //! @param theDrawInterpretor the interpreter of the Draw Harness application
3826 //! @param theNumberOfCommandLineArguments the number of passed command line arguments
3827 //! @param theCommandLineArguments the array of command line arguments
3828 //! @return TCL_OK if changing was successful, or TCL_ERROR otherwise
3829 static int vbackground (Draw_Interpretor& theDrawInterpretor,
3830 const Standard_Integer theNumberOfCommandLineArguments,
3831 const char** const theCommandLineArguments)
7fd59977 3832 {
293211ae 3833 if (theNumberOfCommandLineArguments < 1)
7fd59977 3834 {
293211ae 3835 return TCL_ERROR;
7fd59977 3836 }
293211ae 3837 BackgroundChanger aBackgroundChanger;
3838 if (!aBackgroundChanger.ProcessCommandLine (theDrawInterpretor,
3839 theNumberOfCommandLineArguments,
3840 theCommandLineArguments))
f8b2ed36 3841 {
293211ae 3842 theDrawInterpretor << "Wrong command arguments.\n"
3843 "Type 'help "
3844 << theCommandLineArguments[0] << "' for information about command options and its arguments.\n";
3845 return TCL_ERROR;
f8b2ed36 3846 }
293211ae 3847 return TCL_OK;
f8b2ed36 3848 }
3849
293211ae 3850} // namespace
f42753ed 3851
7fd59977 3852//==============================================================================
3853//function : VScale
3854//purpose : View Scaling
3855//==============================================================================
3856
3857static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3858{
3859 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3860 if ( V3dView.IsNull() ) return 1;
3861
3862 if ( argc != 4 ) {
586db386 3863 di << argv[0] << "Invalid number of arguments\n";
7fd59977 3864 return 1;
3865 }
91322f44 3866 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
7fd59977 3867 return 0;
3868}
3869//==============================================================================
536d98e2 3870//function : VZBuffTrihedron
3871//purpose :
7fd59977 3872//==============================================================================
3873
536d98e2 3874static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3875 Standard_Integer theArgNb,
3876 const char** theArgVec)
7fd59977 3877{
536d98e2 3878 Handle(V3d_View) aView = ViewerTest::CurrentView();
3879 if (aView.IsNull())
3880 {
3881 std::cout << "Error: no active viewer!\n";
3882 return 1;
3883 }
7fd59977 3884
536d98e2 3885 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7c8a8fcc 3886
536d98e2 3887 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3888 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3889 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3890 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3891 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3892 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3893 Standard_Real aScale = 0.1;
3894 Standard_Real aSizeRatio = 0.8;
3895 Standard_Real anArrowDiam = 0.05;
3896 Standard_Integer aNbFacets = 12;
3897 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7c8a8fcc 3898 {
536d98e2 3899 Standard_CString anArg = theArgVec[anArgIter];
3900 TCollection_AsciiString aFlag (anArg);
3901 aFlag.LowerCase();
3902 if (anUpdateTool.parseRedrawMode (aFlag))
7c8a8fcc 3903 {
536d98e2 3904 continue;
3905 }
3906 else if (aFlag == "-on")
7c8a8fcc 3907 {
536d98e2 3908 continue;
3909 }
3910 else if (aFlag == "-off")
7c8a8fcc 3911 {
536d98e2 3912 aView->TriedronErase();
3913 return 0;
3914 }
3915 else if (aFlag == "-pos"
3916 || aFlag == "-position"
3917 || aFlag == "-corner")
7c8a8fcc 3918 {
536d98e2 3919 if (++anArgIter >= theArgNb)
3920 {
3921 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3922 return 1;
3923 }
3924
3925 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3926 aPosName.LowerCase();
3927 if (aPosName == "center")
3928 {
3929 aPosition = Aspect_TOTP_CENTER;
3930 }
3931 else if (aPosName == "left_lower"
3932 || aPosName == "lower_left"
3933 || aPosName == "leftlower"
3934 || aPosName == "lowerleft")
3935 {
3936 aPosition = Aspect_TOTP_LEFT_LOWER;
3937 }
3938 else if (aPosName == "left_upper"
3939 || aPosName == "upper_left"
3940 || aPosName == "leftupper"
3941 || aPosName == "upperleft")
3942 {
3943 aPosition = Aspect_TOTP_LEFT_UPPER;
3944 }
3945 else if (aPosName == "right_lower"
3946 || aPosName == "lower_right"
3947 || aPosName == "rightlower"
3948 || aPosName == "lowerright")
3949 {
3950 aPosition = Aspect_TOTP_RIGHT_LOWER;
3951 }
3952 else if (aPosName == "right_upper"
3953 || aPosName == "upper_right"
3954 || aPosName == "rightupper"
3955 || aPosName == "upperright")
3956 {
3957 aPosition = Aspect_TOTP_RIGHT_UPPER;
3958 }
3959 else
3960 {
3961 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3962 return 1;
3963 }
3964 }
3965 else if (aFlag == "-type")
7c8a8fcc 3966 {
536d98e2 3967 if (++anArgIter >= theArgNb)
3968 {
3969 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3970 return 1;
3971 }
3972
3973 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3974 aTypeName.LowerCase();
3975 if (aTypeName == "wireframe"
3976 || aTypeName == "wire")
3977 {
3978 aVisType = V3d_WIREFRAME;
3979 }
3980 else if (aTypeName == "zbuffer"
3981 || aTypeName == "shaded")
3982 {
3983 aVisType = V3d_ZBUFFER;
3984 }
3985 else
3986 {
3987 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3988 }
3989 }
3990 else if (aFlag == "-scale")
7c8a8fcc 3991 {
536d98e2 3992 if (++anArgIter >= theArgNb)
3993 {
3994 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3995 return 1;
3996 }
3997
3998 aScale = Draw::Atof (theArgVec[anArgIter]);
7c8a8fcc 3999 }
536d98e2 4000 else if (aFlag == "-size"
4001 || aFlag == "-sizeratio")
4002 {
4003 if (++anArgIter >= theArgNb)
4004 {
4005 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4006 return 1;
4007 }
7c8a8fcc 4008
536d98e2 4009 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
4010 }
4011 else if (aFlag == "-arrowdiam"
4012 || aFlag == "-arrowdiameter")
4013 {
4014 if (++anArgIter >= theArgNb)
4015 {
4016 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4017 return 1;
4018 }
7c8a8fcc 4019
536d98e2 4020 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
4021 }
4022 else if (aFlag == "-nbfacets")
4023 {
4024 if (++anArgIter >= theArgNb)
4025 {
4026 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4027 return 1;
4028 }
7c8a8fcc 4029
536d98e2 4030 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
4031 }
4032 else if (aFlag == "-colorlabel"
4033 || aFlag == "-colorlabels")
7c8a8fcc 4034 {
536d98e2 4035 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4036 theArgVec + anArgIter + 1,
4037 aLabelsColor);
4038 if (aNbParsed == 0)
4039 {
4040 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4041 return 1;
4042 }
4043 anArgIter += aNbParsed;
7c8a8fcc 4044 }
536d98e2 4045 else if (aFlag == "-colorarrowx")
7c8a8fcc 4046 {
536d98e2 4047 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4048 theArgVec + anArgIter + 1,
4049 anArrowColorX);
4050 if (aNbParsed == 0)
4051 {
4052 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4053 return 1;
4054 }
4055 anArgIter += aNbParsed;
4056 }
4057 else if (aFlag == "-colorarrowy")
7c8a8fcc 4058 {
536d98e2 4059 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4060 theArgVec + anArgIter + 1,
4061 anArrowColorY);
4062 if (aNbParsed == 0)
4063 {
4064 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4065 return 1;
4066 }
4067 anArgIter += aNbParsed;
4068 }
4069 else if (aFlag == "-colorarrowz")
7c8a8fcc 4070 {
536d98e2 4071 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
4072 theArgVec + anArgIter + 1,
4073 anArrowColorZ);
4074 if (aNbParsed == 0)
4075 {
4076 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4077 return 1;
4078 }
4079 anArgIter += aNbParsed;
4080 }
4081 else
4082 {
4083 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
7c8a8fcc 4084 return 1;
4085 }
7c8a8fcc 4086 }
4087
536d98e2 4088 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
4089 aSizeRatio, anArrowDiam, aNbFacets);
4090 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
c357e426 4091 aView->ZFitAll();
7fd59977 4092 return 0;
4093}
4094
4095//==============================================================================
4096//function : VRotate
4097//purpose : Camera Rotating
4098//==============================================================================
4099
4af098ba 4100static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
4101{
4102 Handle(V3d_View) aView = ViewerTest::CurrentView();
4103 if (aView.IsNull())
4104 {
4105 std::cout << "No active view!\n";
7fd59977 4106 return 1;
4107 }
4108
4af098ba 4109 Standard_Boolean hasFlags = Standard_False;
4110 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4111 {
4112 Standard_CString anArg (theArgVec[anArgIter]);
4113 TCollection_AsciiString aFlag (anArg);
4114 aFlag.LowerCase();
4115 if (aFlag == "-mousestart"
4116 || aFlag == "-mousefrom")
4117 {
4118 hasFlags = Standard_True;
4119 if (anArgIter + 2 >= theArgNb)
4120 {
4121 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4122 return 1;
4123 }
4124
4125 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
4126 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
4127 aView->StartRotation (anX, anY);
4128 }
4129 else if (aFlag == "-mousemove")
4130 {
4131 hasFlags = Standard_True;
4132 if (anArgIter + 2 >= theArgNb)
4133 {
4134 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4135 return 1;
4136 }
4137
4138 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
4139 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
4140 aView->Rotation (anX, anY);
4141 }
4142 else if (theArgNb != 4
4143 && theArgNb != 7)
4144 {
4145 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
4146 return 1;
4147 }
4148 }
4149
4150 if (hasFlags)
4151 {
7fd59977 4152 return 0;
4af098ba 4153 }
4154 else if (theArgNb == 4)
4155 {
4156 Standard_Real anAX = Draw::Atof (theArgVec[1]);
4157 Standard_Real anAY = Draw::Atof (theArgVec[2]);
4158 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
4159 aView->Rotate (anAX, anAY, anAZ);
4160 return 0;
4161 }
4162 else if (theArgNb == 7)
4163 {
4164 Standard_Real anAX = Draw::Atof (theArgVec[1]);
4165 Standard_Real anAY = Draw::Atof (theArgVec[2]);
4166 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
4167
4168 Standard_Real anX = Draw::Atof (theArgVec[4]);
4169 Standard_Real anY = Draw::Atof (theArgVec[5]);
4170 Standard_Real anZ = Draw::Atof (theArgVec[6]);
4171
4172 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
7fd59977 4173 return 0;
7fd59977 4174 }
4af098ba 4175
4176 std::cout << "Error: Invalid number of arguments\n";
4177 return 1;
7fd59977 4178}
4179
4180//==============================================================================
4181//function : VZoom
4182//purpose : View zoom in / out (relative to current zoom)
4183//==============================================================================
4184
4185static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4186 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4187 if ( V3dView.IsNull() ) {
4188 return 1;
4189 }
4190
4191 if ( argc == 2 ) {
91322f44 4192 Standard_Real coef = Draw::Atof(argv[1]);
7fd59977 4193 if ( coef <= 0.0 ) {
586db386 4194 di << argv[1] << "Invalid value\n";
7fd59977 4195 return 1;
4196 }
91322f44 4197 V3dView->SetZoom( Draw::Atof(argv[1]) );
7fd59977 4198 return 0;
4199 } else {
586db386 4200 di << argv[0] << " Invalid number of arguments\n";
7fd59977 4201 return 1;
4202 }
4203}
4204
4205//==============================================================================
4206//function : VPan
4207//purpose : View panning (in pixels)
4208//==============================================================================
4209
4210static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4211 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
4212 if ( V3dView.IsNull() ) return 1;
4213
4214 if ( argc == 3 ) {
91322f44 4215 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
7fd59977 4216 return 0;
4217 } else {
586db386 4218 di << argv[0] << " Invalid number of arguments\n";
7fd59977 4219 return 1;
4220 }
4221}
4222
49e1a5c7 4223//==============================================================================
4224//function : VPlace
4225//purpose : Place the point (in pixels) at the center of the window
4226//==============================================================================
4227static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
4228{
4229 Handle(V3d_View) aView = ViewerTest::CurrentView();
4230 if (aView.IsNull())
4231 {
4232 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
4233 return 1;
4234 }
4235
4236 if (theArgNb != 3)
4237 {
4238 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
4239 return 1;
4240 }
4241
4242 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
4243
4244 return 0;
4245}
7fd59977 4246
71215351 4247static int VColorScale (Draw_Interpretor& theDI,
4248 Standard_Integer theArgNb,
4249 const char** theArgVec)
4250{
7fd59977 4251 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
71215351 4252 Handle(V3d_View) aView = ViewerTest::CurrentView();
4253 if (aContext.IsNull())
4254 {
4255 std::cout << "Error: no active view!\n";
4256 return 1;
7fd59977 4257 }
24a88697 4258 if (theArgNb <= 1)
4259 {
4260 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
4261 return 1;
4262 }
7fd59977 4263
4b3d6eb1 4264 Handle(AIS_ColorScale) aColorScale;
7a324550 4265 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
71215351 4266 {
4b3d6eb1 4267 // find existing object
4268 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
4269 if (aColorScale.IsNull())
7a324550 4270 {
4271 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
4272 return 1;
4273 }
4274 }
71215351 4275
7a324550 4276 if (theArgNb <= 2)
4277 {
4b3d6eb1 4278 if (aColorScale.IsNull())
4279 {
4280 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
4281 return 1;
4282 }
4283
7a324550 4284 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
4b3d6eb1 4285 << "Min range: " << aColorScale->GetMin() << "\n"
4286 << "Max range: " << aColorScale->GetMax() << "\n"
4287 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
4288 << "Text height: " << aColorScale->GetTextHeight() << "\n"
4289 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
4290 << "Color scale title: " << aColorScale->GetTitle() << "\n"
71215351 4291 << "Label position: ";
4b3d6eb1 4292 switch (aColorScale->GetLabelPosition())
71215351 4293 {
4294 case Aspect_TOCSP_NONE:
4295 theDI << "None\n";
4296 break;
4297 case Aspect_TOCSP_LEFT:
4298 theDI << "Left\n";
4299 break;
4300 case Aspect_TOCSP_RIGHT:
4301 theDI << "Right\n";
4302 break;
4303 case Aspect_TOCSP_CENTER:
4304 theDI << "Center\n";
4305 break;
4306 }
4307 return 0;
4308 }
71215351 4309
4b3d6eb1 4310 if (aColorScale.IsNull())
4311 {
4312 aColorScale = new AIS_ColorScale();
4313 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4314 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
4315 }
4316
4317 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
7a324550 4318 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
71215351 4319 {
4320 Standard_CString anArg = theArgVec[anArgIter];
4321 TCollection_AsciiString aFlag (anArg);
4322 aFlag.LowerCase();
4323 if (anUpdateTool.parseRedrawMode (aFlag))
4324 {
4325 continue;
4326 }
4327 else if (aFlag == "-range")
4328 {
4329 if (anArgIter + 3 >= theArgNb)
4330 {
4331 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4332 return 1;
4333 }
4334
4b3d6eb1 4335 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
4336 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
4337 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
4338 if (!aRangeMin.IsRealValue()
4339 || !aRangeMax.IsRealValue())
71215351 4340 {
4b3d6eb1 4341 std::cout << "Error: the range values should be real!\n";
71215351 4342 return 1;
4343 }
4b3d6eb1 4344 else if (!aNbIntervals.IsIntegerValue())
71215351 4345 {
4346 std::cout << "Error: the number of intervals should be integer!\n";
4347 return 1;
4348 }
4349
4b3d6eb1 4350 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
4351 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
71215351 4352 }
4353 else if (aFlag == "-font")
4354 {
4355 if (anArgIter + 1 >= theArgNb)
4356 {
4357 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4358 return 1;
4359 }
51740958 4360 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
4361 if (!aFontArg.IsIntegerValue())
71215351 4362 {
4363 std::cout << "Error: HeightFont value should be integer!\n";
4364 return 1;
4365 }
4366
4b3d6eb1 4367 aColorScale->SetTextHeight (aFontArg.IntegerValue());
71215351 4368 anArgIter += 1;
4369 }
4370 else if (aFlag == "-textpos")
4371 {
4372 if (anArgIter + 1 >= theArgNb)
4373 {
4374 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4375 return 1;
4376 }
4b3d6eb1 4377
51740958 4378 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
4379 aTextPosArg.LowerCase();
4b3d6eb1 4380 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
51740958 4381 if (aTextPosArg == "none")
71215351 4382 {
4383 aLabPosition = Aspect_TOCSP_NONE;
4384 }
51740958 4385 else if (aTextPosArg == "left")
71215351 4386 {
4387 aLabPosition = Aspect_TOCSP_LEFT;
4388 }
51740958 4389 else if (aTextPosArg == "right")
71215351 4390 {
4391 aLabPosition = Aspect_TOCSP_RIGHT;
4392 }
51740958 4393 else if (aTextPosArg == "center")
71215351 4394 {
4395 aLabPosition = Aspect_TOCSP_CENTER;
4396 }
4397 else
4398 {
51740958 4399 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
71215351 4400 return 1;
4401 }
4b3d6eb1 4402 aColorScale->SetLabelPosition (aLabPosition);
71215351 4403 }
24a88697 4404 else if (aFlag == "-logarithmic"
4405 || aFlag == "-log")
4406 {
4407 if (anArgIter + 1 >= theArgNb)
4408 {
4409 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4410 return 1;
4411 }
4b3d6eb1 4412
24a88697 4413 Standard_Boolean IsLog;
4414 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
4415 {
4416 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4417 return 1;
4418 }
4b3d6eb1 4419 aColorScale->SetLogarithmic (IsLog);
4420 }
4421 else if (aFlag == "-huerange"
4422 || aFlag == "-hue")
4423 {
4424 if (anArgIter + 2 >= theArgNb)
4425 {
4426 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4427 return 1;
4428 }
4429
4430 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
4431 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
4432 aColorScale->SetHueRange (aHueMin, aHueMax);
4433 }
4434 else if (aFlag == "-colorrange")
4435 {
4436 Quantity_Color aColorMin, aColorMax;
4437 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4438 theArgVec + (anArgIter + 1),
4439 aColorMin);
4440 anArgIter += aNbParsed1;
4441 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4442 theArgVec + (anArgIter + 1),
4443 aColorMax);
4444 anArgIter += aNbParsed2;
4445 if (aNbParsed1 == 0
4446 || aNbParsed2 == 0)
4447 {
4448 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4449 return 1;
4450 }
4451
4452 aColorScale->SetColorRange (aColorMin, aColorMax);
4453 }
4454 else if (aFlag == "-reversed"
4455 || aFlag == "-inverted"
4456 || aFlag == "-topdown"
4457 || aFlag == "-bottomup")
4458 {
4459 Standard_Boolean toEnable = Standard_True;
4460 if (anArgIter + 1 < theArgNb
4461 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
4462 {
4463 ++anArgIter;
4464 }
4465 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
4466 }
4467 else if (aFlag == "-smooth"
4468 || aFlag == "-smoothtransition")
4469 {
4470 Standard_Boolean toEnable = Standard_True;
4471 if (anArgIter + 1 < theArgNb
4472 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4473 {
4474 ++anArgIter;
4475 }
4476 aColorScale->SetSmoothTransition (toEnable);
24a88697 4477 }
71215351 4478 else if (aFlag == "-xy")
4479 {
4480 if (anArgIter + 2 >= theArgNb)
4481 {
4482 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4483 return 1;
4484 }
4485
4b3d6eb1 4486 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
4487 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
4488 if (!anX.IsIntegerValue()
4489 || !anY.IsIntegerValue())
71215351 4490 {
b4b2ecca 4491 std::cout << "Error: coordinates should be integer values!\n";
71215351 4492 return 1;
4493 }
4494
4b3d6eb1 4495 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
b4b2ecca 4496 }
4497 else if (aFlag == "-width"
4b3d6eb1 4498 || aFlag == "-w"
4499 || aFlag == "-breadth")
b4b2ecca 4500 {
4501 if (anArgIter + 1 >= theArgNb)
4502 {
4503 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4504 return 1;
4505 }
4506
4b3d6eb1 4507 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
4508 if (!aBreadth.IsIntegerValue())
b4b2ecca 4509 {
4510 std::cout << "Error: a width should be an integer value!\n";
4511 return 1;
4512 }
4b3d6eb1 4513 aColorScale->SetBreadth (aBreadth.IntegerValue());
b4b2ecca 4514 }
4515 else if (aFlag == "-height"
4516 || aFlag == "-h")
4517 {
4518 if (anArgIter + 1 >= theArgNb)
4519 {
4520 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4521 return 1;
4522 }
4523
4b3d6eb1 4524 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
4525 if (!aHeight.IsIntegerValue())
b4b2ecca 4526 {
4527 std::cout << "Error: a width should be an integer value!\n";
4528 return 1;
4529 }
4b3d6eb1 4530 aColorScale->SetHeight (aHeight.IntegerValue());
71215351 4531 }
4532 else if (aFlag == "-color")
4533 {
4b3d6eb1 4534 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
71215351 4535 {
4536 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
4537 return 1;
4538 }
4b3d6eb1 4539 else if (anArgIter + 2 >= theArgNb)
71215351 4540 {
4b3d6eb1 4541 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4542 return 1;
71215351 4543 }
4544
4b3d6eb1 4545 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
71215351 4546 if (!anInd.IsIntegerValue())
4547 {
4548 std::cout << "Error: Index value should be integer!\n";
4549 return 1;
4550 }
4b3d6eb1 4551 const Standard_Integer anIndex = anInd.IntegerValue();
4552 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
71215351 4553 {
4b3d6eb1 4554 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
71215351 4555 return 1;
4556 }
4557
4b3d6eb1 4558 Quantity_Color aColor;
4559 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4560 theArgVec + (anArgIter + 1),
4561 aColor);
4562 if (aNbParsed == 0)
71215351 4563 {
4b3d6eb1 4564 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
71215351 4565 return 1;
4566 }
4b3d6eb1 4567 aColorScale->SetIntervalColor (aColor, anIndex);
4568 aColorScale->SetColorType (Aspect_TOCSD_USER);
4569 anArgIter += aNbParsed;
71215351 4570 }
4571 else if (aFlag == "-label")
4572 {
4b3d6eb1 4573 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
71215351 4574 {
4575 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
4576 return 1;
4577 }
4578 else if (anArgIter + 2 >= theArgNb)
4579 {
4580 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4581 return 1;
4582 }
4583
4584 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4b3d6eb1 4585 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
71215351 4586 {
4b3d6eb1 4587 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
71215351 4588 return 1;
4589 }
4590
4591 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4b3d6eb1 4592 aColorScale->SetLabel (aText, anIndex);
4593 aColorScale->SetLabelType (Aspect_TOCSD_USER);
71215351 4594 anArgIter += 2;
4595 }
4b3d6eb1 4596 else if (aFlag == "-labelat"
4597 || aFlag == "-labat"
4598 || aFlag == "-labelatborder"
4599 || aFlag == "-labatborder"
4600 || aFlag == "-labelatcenter"
4601 || aFlag == "-labatcenter")
71215351 4602 {
4b3d6eb1 4603 Standard_Boolean toEnable = Standard_True;
4604 if (aFlag == "-labelat"
4605 || aFlag == "-labat")
71215351 4606 {
4b3d6eb1 4607 Standard_Integer aLabAtBorder = -1;
4608 if (++anArgIter >= theArgNb)
71215351 4609 {
4b3d6eb1 4610 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4611 anAtBorder.LowerCase();
4612 if (anAtBorder == "border")
71215351 4613 {
4b3d6eb1 4614 aLabAtBorder = 1;
71215351 4615 }
4b3d6eb1 4616 else if (anAtBorder == "center")
71215351 4617 {
4b3d6eb1 4618 aLabAtBorder = 0;
71215351 4619 }
71215351 4620 }
4b3d6eb1 4621 if (aLabAtBorder == -1)
4622 {
4623 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4624 return 1;
4625 }
4626 toEnable = (aLabAtBorder == 1);
4627 }
4628 else if (anArgIter + 1 < theArgNb
4629 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4630 {
4631 ++anArgIter;
71215351 4632 }
4b3d6eb1 4633 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4634 || aFlag == "-labatcenter"
4635 ? !toEnable
4636 : toEnable);
4637 }
4638 else if (aFlag == "-colors")
4639 {
4640 Aspect_SequenceOfColor aSeq;
4641 for (;;)
4642 {
4643 Quantity_Color aColor;
4644 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4645 theArgVec + (anArgIter + 1),
4646 aColor);
4647 if (aNbParsed == 0)
4648 {
4649 break;
4650 }
4651 anArgIter += aNbParsed;
4652 aSeq.Append (aColor);
4653 }
4654 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
71215351 4655 {
4656 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4b3d6eb1 4657 << aColorScale->GetNumberOfIntervals() << " intervals\n";
71215351 4658 return 1;
4659 }
4660
4b3d6eb1 4661 aColorScale->SetColors (aSeq);
4662 aColorScale->SetColorType (Aspect_TOCSD_USER);
71215351 4663 }
4b3d6eb1 4664 else if (aFlag == "-labels"
4665 || aFlag == "-freelabels")
71215351 4666 {
4b3d6eb1 4667 if (anArgIter + 1 >= theArgNb)
4668 {
4669 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4670 return 1;
4671 }
4672
4673 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4674 ? aColorScale->GetNumberOfIntervals() + 1
4675 : aColorScale->GetNumberOfIntervals();
4676 if (aFlag == "-freelabels")
4677 {
4678 ++anArgIter;
4679 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4680 }
4681 if (anArgIter + aNbLabels >= theArgNb)
71215351 4682 {
4b3d6eb1 4683 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
71215351 4684 return 1;
4685 }
4686
4687 TColStd_SequenceOfExtendedString aSeq;
4b3d6eb1 4688 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
71215351 4689 {
4b3d6eb1 4690 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
71215351 4691 }
4b3d6eb1 4692 aColorScale->SetLabels (aSeq);
4693 aColorScale->SetLabelType (Aspect_TOCSD_USER);
71215351 4694 }
4695 else if (aFlag == "-title")
4696 {
4697 if (anArgIter + 1 >= theArgNb)
4698 {
4699 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4700 return 1;
4701 }
4702
4703 Standard_Boolean isTwoArgs = Standard_False;
4704 if (anArgIter + 2 < theArgNb)
4705 {
4706 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4707 aSecondArg.LowerCase();
4b3d6eb1 4708 Standard_DISABLE_DEPRECATION_WARNINGS
71215351 4709 if (aSecondArg == "none")
4710 {
4b3d6eb1 4711 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
71215351 4712 isTwoArgs = Standard_True;
4713 }
4714 else if (aSecondArg == "left")
4715 {
4b3d6eb1 4716 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
71215351 4717 isTwoArgs = Standard_True;
4718 }
4719 else if (aSecondArg == "right")
4720 {
4b3d6eb1 4721 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
71215351 4722 isTwoArgs = Standard_True;
4723 }
4724 else if (aSecondArg == "center")
4725 {
4b3d6eb1 4726 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
71215351 4727 isTwoArgs = Standard_True;
4728 }
4b3d6eb1 4729 Standard_ENABLE_DEPRECATION_WARNINGS
71215351 4730 }
4731
4b3d6eb1 4732 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
71215351 4733 if (isTwoArgs)
4734 {
4735 anArgIter += 1;
4736 }
4737 anArgIter += 1;
4738 }
4739 else if (aFlag == "-demoversion"
4740 || aFlag == "-demo")
4741 {
4b3d6eb1 4742 aColorScale->SetPosition (0, 0);
4743 aColorScale->SetTextHeight (16);
4744 aColorScale->SetRange (0.0, 100.0);
4745 aColorScale->SetNumberOfIntervals (10);
4746 aColorScale->SetBreadth (0);
4747 aColorScale->SetHeight (0);
4748 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4749 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4750 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
71215351 4751 }
d5514578 4752 else if (aFlag == "-findcolor")
4753 {
4754 if (anArgIter + 1 >= theArgNb)
4755 {
4756 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4757 return 1;
4758 }
4759
4760 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4761
4762 if (!anArg1.IsRealValue())
4763 {
4764 std::cout << "Error: the value should be real!\n";
4765 return 1;
4766 }
4767
4768 Quantity_Color aColor;
4b3d6eb1 4769 aColorScale->FindColor (anArg1.RealValue(), aColor);
d5514578 4770 theDI << Quantity_Color::StringName (aColor.Name());
4771 return 0;
4772 }
71215351 4773 else
4774 {
4775 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4776 return 1;
4777 }
4778 }
4b3d6eb1 4779
4780 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4781 aView->Window()->Size (aWinWidth, aWinHeight);
4782 if (aColorScale->GetBreadth() == 0)
b4b2ecca 4783 {
4b3d6eb1 4784 aColorScale->SetBreadth (aWinWidth);
b4b2ecca 4785 }
4b3d6eb1 4786 if (aColorScale->GetHeight() == 0)
4787 {
4788 aColorScale->SetHeight (aWinHeight);
4789 }
4790 aColorScale->SetToUpdate();
4791 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
7fd59977 4792 return 0;
4793}
4794
4795//==============================================================================
4796//function : VGraduatedTrihedron
a79f67f8 4797//purpose : Displays or hides a graduated trihedron
7fd59977 4798//==============================================================================
a79f67f8 4799static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4800 Quantity_Color& theColor)
13a22457 4801{
a79f67f8 4802 Quantity_NameOfColor aColorName;
4803 TCollection_AsciiString aVal = theValue;
4804 aVal.UpperCase();
4805 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
13a22457 4806 {
a79f67f8 4807 return Standard_False;
13a22457 4808 }
a79f67f8 4809 theColor = Quantity_Color (aColorName);
4810 return Standard_True;
13a22457
S
4811}
4812
a79f67f8 4813static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
7fd59977 4814{
a79f67f8 4815 if (theArgNum < 2)
13a22457 4816 {
a79f67f8 4817 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4818 << theArgs[0] <<"' for more information.\n";
4819 return 1; //TCL_ERROR
13a22457 4820 }
7fd59977 4821
a79f67f8 4822 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4823 TCollection_AsciiString aParseKey;
4824 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4825 {
4826 TCollection_AsciiString anArg (theArgs [anArgIt]);
4827
4828 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4829 {
4830 aParseKey = anArg;
4831 aParseKey.Remove (1);
4832 aParseKey.LowerCase();
4833 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4834 continue;
4835 }
13a22457 4836
a79f67f8 4837 if (aParseKey.IsEmpty())
4838 {
4839 continue;
4840 }
4841
4842 aMapOfArgs(aParseKey)->Append (anArg);
4843 }
4844
4845 // Check parameters
4846 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4847 aMapIt.More(); aMapIt.Next())
7fd59977 4848 {
a79f67f8 4849 const TCollection_AsciiString& aKey = aMapIt.Key();
4850 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4851
4852 // Bool key, without arguments
4853 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4854 && anArgs->IsEmpty())
4855 {
4856 continue;
4857 }
4858
4859 // One argument
4860 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4861 && anArgs->Length() == 1)
4862 {
4863 continue;
4864 }
4865
4866 // On/off arguments
4867 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4868 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
536d98e2 4869 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4870 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
a79f67f8 4871 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4872 {
4873 continue;
4874 }
4875
4876 // One string argument
4877 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4878 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4879 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4880 {
4881 continue;
4882 }
4883
4884 // One integer argument
4885 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4886 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4887 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4888 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4889 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4890 {
4891 continue;
4892 }
4893
4894 // One real argument
4895 if ( aKey.IsEqual ("arrowlength")
4896 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4897 {
4898 continue;
4899 }
4900
4901 // Two string arguments
4902 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4903 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
13a22457 4904 {
a79f67f8 4905 continue;
13a22457 4906 }
a79f67f8 4907
4908 TCollection_AsciiString aLowerKey;
4909 aLowerKey = "-";
4910 aLowerKey += aKey;
4911 aLowerKey.LowerCase();
4912 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4913 std::cout << "Type help for more information.\n";
4914 return 1;
7fd59977 4915 }
4916
a79f67f8 4917 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4918 if (anAISContext.IsNull())
4919 {
586db386 4920 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
a79f67f8 4921 return 1;
4922 }
7fd59977 4923
a79f67f8 4924 Standard_Boolean toDisplay = Standard_True;
4925 Quantity_Color aColor;
4926 Graphic3d_GraduatedTrihedron aTrihedronData;
4927 // Process parameters
4928 Handle(TColStd_HSequenceOfAsciiString) aValues;
4929 if (aMapOfArgs.Find ("off", aValues))
7fd59977 4930 {
a79f67f8 4931 toDisplay = Standard_False;
4932 }
13a22457 4933
a79f67f8 4934 // AXES NAMES
4935 if (aMapOfArgs.Find ("xname", aValues))
4936 {
4937 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4938 }
4939 if (aMapOfArgs.Find ("yname", aValues))
4940 {
4941 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4942 }
4943 if (aMapOfArgs.Find ("zname", aValues))
4944 {
4945 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4946 }
4947 if (aMapOfArgs.Find ("xdrawname", aValues))
4948 {
536d98e2 4949 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4950 }
4951 if (aMapOfArgs.Find ("ydrawname", aValues))
4952 {
536d98e2 4953 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4954 }
4955 if (aMapOfArgs.Find ("zdrawname", aValues))
4956 {
536d98e2 4957 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 4958 }
4959 if (aMapOfArgs.Find ("xnameoffset", aValues))
4960 {
4961 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4962 }
4963 if (aMapOfArgs.Find ("ynameoffset", aValues))
4964 {
4965 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4966 }
4967 if (aMapOfArgs.Find ("znameoffset", aValues))
4968 {
4969 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4970 }
13a22457 4971
a79f67f8 4972 // COLORS
4973 if (aMapOfArgs.Find ("xnamecolor", aValues))
4974 {
4975 if (!GetColor (aValues->Value(1), aColor))
13a22457 4976 {
a79f67f8 4977 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4978 return 1;
13a22457 4979 }
a79f67f8 4980 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4981 }
4982 if (aMapOfArgs.Find ("ynamecolor", aValues))
4983 {
4984 if (!GetColor (aValues->Value(1), aColor))
13a22457 4985 {
a79f67f8 4986 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4987 return 1;
4988 }
4989 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4990 }
4991 if (aMapOfArgs.Find ("znamecolor", aValues))
4992 {
4993 if (!GetColor (aValues->Value(1), aColor))
4994 {
4995 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4996 return 1;
4997 }
4998 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4999 }
5000 if (aMapOfArgs.Find ("xcolor", aValues))
5001 {
5002 if (!GetColor (aValues->Value(1), aColor))
5003 {
5004 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
5005 return 1;
5006 }
5007 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
5008 }
5009 if (aMapOfArgs.Find ("ycolor", aValues))
5010 {
5011 if (!GetColor (aValues->Value(1), aColor))
5012 {
5013 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
5014 return 1;
5015 }
5016 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
5017 }
5018 if (aMapOfArgs.Find ("zcolor", aValues))
5019 {
5020 if (!GetColor (aValues->Value(1), aColor))
5021 {
5022 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
5023 return 1;
5024 }
5025 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
5026 }
5027
5028 // TICKMARKS
5029 if (aMapOfArgs.Find ("xticks", aValues))
5030 {
536d98e2 5031 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 5032 }
5033 if (aMapOfArgs.Find ("yticks", aValues))
5034 {
536d98e2 5035 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 5036 }
5037 if (aMapOfArgs.Find ("zticks", aValues))
5038 {
536d98e2 5039 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 5040 }
5041 if (aMapOfArgs.Find ("xticklength", aValues))
5042 {
536d98e2 5043 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 5044 }
5045 if (aMapOfArgs.Find ("yticklength", aValues))
5046 {
536d98e2 5047 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 5048 }
5049 if (aMapOfArgs.Find ("zticklength", aValues))
5050 {
536d98e2 5051 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 5052 }
5053 if (aMapOfArgs.Find ("xdrawticks", aValues))
5054 {
536d98e2 5055 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 5056 }
5057 if (aMapOfArgs.Find ("ydrawticks", aValues))
5058 {
536d98e2 5059 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 5060 }
5061 if (aMapOfArgs.Find ("zdrawticks", aValues))
5062 {
536d98e2 5063 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 5064 }
5065
5066 // VALUES
5067 if (aMapOfArgs.Find ("xdrawvalues", aValues))
5068 {
536d98e2 5069 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 5070 }
5071 if (aMapOfArgs.Find ("ydrawvalues", aValues))
5072 {
536d98e2 5073 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 5074 }
5075 if (aMapOfArgs.Find ("zdrawvalues", aValues))
5076 {
536d98e2 5077 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 5078 }
5079 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
5080 {
5081 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5082 }
5083 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
5084 {
5085 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5086 }
5087 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
5088 {
5089 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
5090 }
5091
5092 // ARROWS
5093 if (aMapOfArgs.Find ("arrowlength", aValues))
5094 {
536d98e2 5095 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
a79f67f8 5096 }
5097
5098 // FONTS
5099 if (aMapOfArgs.Find ("namefont", aValues))
5100 {
5101 aTrihedronData.SetNamesFont (aValues->Value(1));
5102 }
5103 if (aMapOfArgs.Find ("valuesfont", aValues))
5104 {
5105 aTrihedronData.SetValuesFont (aValues->Value(1));
5106 }
5107
536d98e2 5108 if (aMapOfArgs.Find ("drawgrid", aValues))
5109 {
5110 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
5111 }
5112 if (aMapOfArgs.Find ("drawaxes", aValues))
5113 {
5114 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
5115 }
5116
a79f67f8 5117 // The final step: display of erase trihedron
5118 if (toDisplay)
5119 {
5120 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
13a22457 5121 }
7fd59977 5122 else
a79f67f8 5123 {
5124 ViewerTest::CurrentView()->GraduatedTrihedronErase();
5125 }
7fd59977 5126
5127 ViewerTest::GetAISContext()->UpdateCurrentViewer();
a79f67f8 5128 ViewerTest::CurrentView()->Redraw();
13a22457 5129
7fd59977 5130 return 0;
5131}
5132
3bffef55 5133//==============================================================================
5134//function : VTile
5135//purpose :
5136//==============================================================================
5137static int VTile (Draw_Interpretor& theDI,
5138 Standard_Integer theArgNb,
5139 const char** theArgVec)
5140{
5141 Handle(V3d_View) aView = ViewerTest::CurrentView();
5142 if (aView.IsNull())
5143 {
5144 std::cerr << "Error: no active viewer.\n";
5145 return 1;
5146 }
5147
5148 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
5149 if (theArgNb < 2)
5150 {
5151 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
5152 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
5153 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
5154 return 0;
5155 }
5156
5157 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
5158 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5159 {
5160 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5161 anArg.LowerCase();
5162 if (anArg == "-lowerleft"
5163 || anArg == "-upperleft")
5164 {
5165 if (anArgIter + 3 < theArgNb)
5166 {
5167 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5168 return 1;
5169 }
5170 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
5171 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5172 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5173 }
5174 else if (anArg == "-total"
5175 || anArg == "-totalsize"
5176 || anArg == "-viewsize")
5177 {
5178 if (anArgIter + 3 < theArgNb)
5179 {
5180 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5181 return 1;
5182 }
5183 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5184 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5185 if (aTile.TotalSize.x() < 1
5186 || aTile.TotalSize.y() < 1)
5187 {
5188 std::cerr << "Error: total size is incorrect.\n";
5189 return 1;
5190 }
5191 }
5192 else if (anArg == "-tilesize")
5193 {
5194 if (anArgIter + 3 < theArgNb)
5195 {
5196 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
5197 return 1;
5198 }
5199
5200 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
5201 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
5202 if (aTile.TileSize.x() < 1
5203 || aTile.TileSize.y() < 1)
5204 {
5205 std::cerr << "Error: tile size is incorrect.\n";
5206 return 1;
5207 }
5208 }
5209 else if (anArg == "-unset")
5210 {
5211 aView->Camera()->SetTile (Graphic3d_CameraTile());
5212 aView->Redraw();
5213 return 0;
5214 }
5215 }
5216
5217 if (aTile.TileSize.x() < 1
5218 || aTile.TileSize.y() < 1)
5219 {
5220 std::cerr << "Error: tile size is undefined.\n";
5221 return 1;
5222 }
5223 else if (aTile.TotalSize.x() < 1
5224 || aTile.TotalSize.y() < 1)
5225 {
5226 std::cerr << "Error: total size is undefined.\n";
5227 return 1;
5228 }
5229
5230 aView->Camera()->SetTile (aTile);
5231 aView->Redraw();
5232 return 0;
5233}
5234
7c3ef2f7 5235//! Format ZLayer ID.
5236inline const char* formZLayerId (const Standard_Integer theLayerId)
5237{
5238 switch (theLayerId)
5239 {
5240 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
5241 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
5242 case Graphic3d_ZLayerId_Top: return "[TOP]";
5243 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
5244 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
5245 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
5246 }
5247 return "";
5248}
5249
5250//! Print the ZLayer information.
5251inline void printZLayerInfo (Draw_Interpretor& theDI,
5252 const Graphic3d_ZLayerSettings& theLayer)
5253{
5254 if (!theLayer.Name().IsEmpty())
5255 {
5256 theDI << " Name: " << theLayer.Name() << "\n";
5257 }
5258 if (theLayer.IsImmediate())
5259 {
5260 theDI << " Immediate: TRUE\n";
5261 }
5262 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4ecf34cc 5263 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
5264 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
7c3ef2f7 5265 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
5266 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
5267 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
5268 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
5269 {
5270 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
5271 }
5272}
5273
59f45b7c 5274//==============================================================================
5275//function : VZLayer
5276//purpose : Test z layer operations for v3d viewer
5277//==============================================================================
7c3ef2f7 5278static int VZLayer (Draw_Interpretor& theDI,
5279 Standard_Integer theArgNb,
5280 const char** theArgVec)
59f45b7c 5281{
7c3ef2f7 5282 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
59f45b7c 5283 if (aContextAIS.IsNull())
5284 {
7c3ef2f7 5285 std::cout << "No active viewer!\n";
59f45b7c 5286 return 1;
5287 }
5288
5289 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
7c3ef2f7 5290 if (theArgNb < 2)
59f45b7c 5291 {
7c3ef2f7 5292 TColStd_SequenceOfInteger aLayers;
5293 aViewer->GetAllZLayers (aLayers);
5294 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5295 {
5296 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
5297 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
5298 printZLayerInfo (theDI, aSettings);
5299 }
59f45b7c 5300 return 1;
5301 }
5302
7c3ef2f7 5303 Standard_Integer anArgIter = 1;
5304 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5305 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
5306 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
59f45b7c 5307 {
7c3ef2f7 5308 ++anArgIter;
5309 }
59f45b7c 5310
7c3ef2f7 5311 {
55c8f0f7
BB
5312 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
5313 if (aFirstArg.IsIntegerValue())
c5751993 5314 {
7c3ef2f7 5315 ++anArgIter;
55c8f0f7 5316 aLayerId = aFirstArg.IntegerValue();
c5751993 5317 }
7c3ef2f7 5318 else
c5751993 5319 {
55c8f0f7 5320 if (ViewerTest::ParseZLayerName (aFirstArg.ToCString(), aLayerId))
7c3ef2f7 5321 {
55c8f0f7 5322 ++anArgIter;
7c3ef2f7 5323 }
c5751993 5324 }
7c3ef2f7 5325 }
c5751993 5326
1c728f2d 5327 Graphic3d_ZLayerId anOtherLayerId = Graphic3d_ZLayerId_UNKNOWN;
7c3ef2f7 5328 for (; anArgIter < theArgNb; ++anArgIter)
5329 {
5330 // perform operation
5331 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5332 anArg.LowerCase();
5333 if (anUpdateTool.parseRedrawMode (anArg))
c5751993 5334 {
7c3ef2f7 5335 //
c5751993 5336 }
7c3ef2f7 5337 else if (anArg == "-add"
5338 || anArg == "add")
c5751993 5339 {
7c3ef2f7 5340 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5341 if (!aViewer->AddZLayer (aLayerId))
5342 {
5343 std::cout << "Error: can not add a new z layer!\n";
5344 return 0;
5345 }
5346
5347 theDI << aLayerId;
c5751993 5348 }
1c728f2d 5349 else if (anArg == "-insertbefore"
5350 && anArgIter + 1 < theArgNb
5351 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
5352 {
5353 ++anArgIter;
5354 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5355 if (!aViewer->InsertLayerBefore (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
5356 {
5357 std::cout << "Error: can not add a new z layer!\n";
5358 return 0;
5359 }
5360
5361 theDI << aLayerId;
5362 }
5363 else if (anArg == "-insertafter"
5364 && anArgIter + 1 < theArgNb
5365 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
5366 {
5367 ++anArgIter;
5368 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
5369 if (!aViewer->InsertLayerAfter (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
5370 {
5371 std::cout << "Error: can not add a new z layer!\n";
5372 return 0;
5373 }
5374
5375 theDI << aLayerId;
5376 }
7c3ef2f7 5377 else if (anArg == "-del"
5378 || anArg == "-delete"
5379 || anArg == "del")
c5751993 5380 {
7c3ef2f7 5381 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5382 {
5383 if (++anArgIter >= theArgNb)
5384 {
5385 std::cout << "Syntax error: id of z layer to remove is missing\n";
5386 return 1;
5387 }
5388
5389 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5390 }
5391
5392 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
5393 || aLayerId == Graphic3d_ZLayerId_Default
5394 || aLayerId == Graphic3d_ZLayerId_Top
5395 || aLayerId == Graphic3d_ZLayerId_Topmost
5396 || aLayerId == Graphic3d_ZLayerId_TopOSD
5397 || aLayerId == Graphic3d_ZLayerId_BotOSD)
5398 {
5399 std::cout << "Syntax error: standard Z layer can not be removed\n";
5400 return 1;
5401 }
5402
5403 // move all object displayed in removing layer to default layer
5404 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5405 anObjIter.More(); anObjIter.Next())
5406 {
8f521168 5407 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
7c3ef2f7 5408 if (aPrs.IsNull()
5409 || aPrs->ZLayer() != aLayerId)
5410 {
5411 continue;
5412 }
5413 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
5414 }
5415
5416 if (!aViewer->RemoveZLayer (aLayerId))
5417 {
5418 std::cout << "Z layer can not be removed!\n";
5419 }
5420 else
5421 {
5422 theDI << aLayerId << " ";
5423 }
c5751993 5424 }
7c3ef2f7 5425 else if (anArg == "-get"
5426 || anArg == "get")
c5751993 5427 {
7c3ef2f7 5428 TColStd_SequenceOfInteger aLayers;
5429 aViewer->GetAllZLayers (aLayers);
5430 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
5431 {
5432 theDI << aLayeriter.Value() << " ";
5433 }
5434
5435 theDI << "\n";
c5751993 5436 }
7c3ef2f7 5437 else if (anArg == "-name")
c5751993 5438 {
7c3ef2f7 5439 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
c5751993 5440 {
7c3ef2f7 5441 std::cout << "Syntax error: id of Z layer is missing\n";
c5751993 5442 return 1;
5443 }
5444
7c3ef2f7 5445 if (++anArgIter >= theArgNb)
5446 {
5447 std::cout << "Syntax error: name is missing\n";
5448 return 1;
5449 }
c5751993 5450
7c3ef2f7 5451 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5452 aSettings.SetName (theArgVec[anArgIter]);
5453 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 5454 }
7c3ef2f7 5455 else if (anArg == "-origin")
c5751993 5456 {
7c3ef2f7 5457 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5458 {
5459 std::cout << "Syntax error: id of Z layer is missing\n";
5460 return 1;
5461 }
5462
5463 if (anArgIter + 2 >= theArgNb)
5464 {
5465 std::cout << "Syntax error: origin coordinates are missing\n";
5466 return 1;
5467 }
5468
5469 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5470 gp_XYZ anOrigin;
5471 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
5472 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
5473 anOrigin.SetZ (0.0);
5474 if (anArgIter + 3 < theArgNb)
5475 {
5476 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
5477 anArgIter += 3;
5478 }
5479 else
5480 {
5481 anArgIter += 2;
5482 }
5483 aSettings.SetOrigin (anOrigin);
5484 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 5485 }
4ecf34cc 5486 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5487 && anArgIter + 1 < theArgNb
5488 && (anArg == "-cullingdistance"
5489 || anArg == "-cullingdist"
5490 || anArg == "-culldistance"
5491 || anArg == "-culldist"
5492 || anArg == "-distcull"
5493 || anArg == "-distculling"
5494 || anArg == "-distanceculling"))
5495 {
5496 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5497 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
5498 aSettings.SetCullingDistance (aDist);
5499 aViewer->SetZLayerSettings (aLayerId, aSettings);
5500 }
5501 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
5502 && anArgIter + 1 < theArgNb
5503 && (anArg == "-cullingsize"
5504 || anArg == "-cullsize"
5505 || anArg == "-sizecull"
5506 || anArg == "-sizeculling"))
5507 {
5508 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5509 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
5510 aSettings.SetCullingSize (aSize);
5511 aViewer->SetZLayerSettings (aLayerId, aSettings);
5512 }
7c3ef2f7 5513 else if (anArg == "-settings"
5514 || anArg == "settings")
c5751993 5515 {
7c3ef2f7 5516 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5517 {
5518 if (++anArgIter >= theArgNb)
5519 {
5520 std::cout << "Syntax error: id of Z layer is missing\n";
5521 return 1;
5522 }
5523
5524 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5525 }
5526
5527 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5528 printZLayerInfo (theDI, aSettings);
c5751993 5529 }
7c3ef2f7 5530 else if (anArg == "-enable"
5531 || anArg == "enable"
5532 || anArg == "-disable"
5533 || anArg == "disable")
83da37b1 5534 {
7c3ef2f7 5535 const Standard_Boolean toEnable = anArg == "-enable"
5536 || anArg == "enable";
5537 if (++anArgIter >= theArgNb)
5538 {
5539 std::cout << "Syntax error: option name is missing\n";
5540 return 1;
5541 }
c5751993 5542
7c3ef2f7 5543 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
5544 aSubOp.LowerCase();
5545 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5546 {
5547 if (++anArgIter >= theArgNb)
5548 {
5549 std::cout << "Syntax error: id of Z layer is missing\n";
5550 return 1;
5551 }
c5751993 5552
7c3ef2f7 5553 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5554 }
c5751993 5555
7c3ef2f7 5556 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5557 if (aSubOp == "depthtest"
5558 || aSubOp == "test")
5559 {
5560 aSettings.SetEnableDepthTest (toEnable);
5561 }
5562 else if (aSubOp == "depthwrite"
5563 || aSubOp == "write")
5564 {
5565 aSettings.SetEnableDepthWrite (toEnable);
5566 }
5567 else if (aSubOp == "depthclear"
5568 || aSubOp == "clear")
5569 {
5570 aSettings.SetClearDepth (toEnable);
5571 }
5572 else if (aSubOp == "depthoffset"
5573 || aSubOp == "offset")
5574 {
5575 Graphic3d_PolygonOffset aParams;
5576 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5577 if (toEnable)
5578 {
5579 if (anArgIter + 2 >= theArgNb)
5580 {
5581 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5582 return 1;
5583 }
c5751993 5584
7c3ef2f7 5585 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5586 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5587 }
5588 aSettings.SetPolygonOffset (aParams);
5589 }
5590 else if (aSubOp == "positiveoffset"
5591 || aSubOp == "poffset")
5592 {
5593 if (toEnable)
5594 {
5595 aSettings.SetDepthOffsetPositive();
5596 }
5597 else
5598 {
5599 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5600 }
5601 }
5602 else if (aSubOp == "negativeoffset"
5603 || aSubOp == "noffset")
5604 {
5605 if (toEnable)
5606 {
5607 aSettings.SetDepthOffsetNegative();
5608 }
5609 else
5610 {
5611 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5612 }
5613 }
5614 else if (aSubOp == "textureenv")
5615 {
5616 aSettings.SetEnvironmentTexture (toEnable);
5617 }
1c728f2d 5618 else if (aSubOp == "raytracing")
5619 {
5620 aSettings.SetRaytracable (toEnable);
5621 }
7c3ef2f7 5622
5623 aViewer->SetZLayerSettings (aLayerId, aSettings);
c5751993 5624 }
7c3ef2f7 5625 else
83da37b1 5626 {
7c3ef2f7 5627 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5628 return 1;
83da37b1 5629 }
59f45b7c 5630 }
5631
5632 return 0;
5633}
5634
c357e426 5635// The interactive presentation of 2d layer item
5636// for "vlayerline" command it provides a presentation of
5637// line with user-defined linewidth, linetype and transparency.
61b0191c 5638class V3d_LineItem : public AIS_InteractiveObject
20637bd2 5639{
5640public:
5641 // CASCADE RTTI
92efcf78 5642 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
4fe56619 5643
20637bd2 5644 // constructor
5645 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5646 Standard_Real X2, Standard_Real Y2,
20637bd2 5647 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5648 Standard_Real theWidth = 0.5,
5649 Standard_Real theTransp = 1.0);
5650
61b0191c 5651 private:
5652
5653 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5654 const Handle(Prs3d_Presentation)& thePresentation,
79104795 5655 const Standard_Integer theMode) Standard_OVERRIDE;
61b0191c 5656
5657 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
79104795 5658 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5659 {}
20637bd2 5660
5661private:
5662
5663 Standard_Real myX1, myY1, myX2, myY2;
eafb234b 5664 Aspect_TypeOfLine myType;
20637bd2 5665 Standard_Real myWidth;
20637bd2 5666};
5667
20637bd2 5668// default constructor for line item
4fe56619 5669V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
20637bd2 5670 Standard_Real X2, Standard_Real Y2,
20637bd2 5671 Aspect_TypeOfLine theType,
5672 Standard_Real theWidth,
5673 Standard_Real theTransp) :
61b0191c 5674 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5675 myType(theType), myWidth(theWidth)
20637bd2 5676{
61b0191c 5677 SetTransparency (1-theTransp);
20637bd2 5678}
5679
5680// render line
61b0191c 5681void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5682 const Handle(Prs3d_Presentation)& thePresentation,
5683 const Standard_Integer /*theMode*/)
20637bd2 5684{
61b0191c 5685 thePresentation->Clear();
5686 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
5687 Standard_Integer aWidth, aHeight;
5688 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5689 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5690 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5691 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5692 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5693 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5694 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5695 aGroup->AddPrimitiveArray (aPrim);
20637bd2 5696}
5697
5698//=============================================================================
5699//function : VLayerLine
5700//purpose : Draws line in the v3d view layer with given attributes: linetype,
5701// : linewidth, transparency coefficient
5702//============================================================================
5703static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5704{
5705 // get the active view
5706 Handle(V3d_View) aView = ViewerTest::CurrentView();
5707 if (aView.IsNull())
5708 {
5709 di << "Call vinit before!\n";
5710 return 1;
5711 }
5712 else if (argc < 5)
5713 {
5714 di << "Use: " << argv[0];
5715 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5716 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5717 di << " 0 - solid \n";
5718 di << " 1 - dashed \n";
5719 di << " 2 - dot \n";
5720 di << " 3 - dashdot\n";
5721 di << " transparency : { 0.0 - 1.0 } \n";
5722 di << " 0.0 - transparent\n";
5723 di << " 1.0 - visible \n";
5724 return 1;
5725 }
5726
61b0191c 5727 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
20637bd2 5728 // get the input params
91322f44 5729 Standard_Real X1 = Draw::Atof(argv[1]);
5730 Standard_Real Y1 = Draw::Atof(argv[2]);
5731 Standard_Real X2 = Draw::Atof(argv[3]);
5732 Standard_Real Y2 = Draw::Atof(argv[4]);
20637bd2 5733
3a4a3962 5734 Standard_Real aWidth = 0.5;
5735 Standard_Real aTransparency = 1.0;
20637bd2 5736
5737 // has width
5738 if (argc > 5)
91322f44 5739 aWidth = Draw::Atof(argv[5]);
20637bd2 5740
3a4a3962 5741 // select appropriate line type
5742 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5743 if (argc > 6
5744 && !ViewerTest::ParseLineType (argv[6], aLineType))
5745 {
5746 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5747 return 1;
5748 }
20637bd2 5749
5750 // has transparency
5751 if (argc > 7)
5752 {
91322f44 5753 aTransparency = Draw::Atof(argv[7]);
4fe56619 5754 if (aTransparency < 0 || aTransparency > 1.0)
20637bd2 5755 aTransparency = 1.0;
5756 }
5757
61b0191c 5758 static Handle (V3d_LineItem) aLine;
5759 if (!aLine.IsNull())
25289ec1 5760 {
0577ae8c 5761 aContext->Erase (aLine, Standard_False);
25289ec1 5762 }
61b0191c 5763 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5764 aLineType, aWidth,
5765 aTransparency);
25289ec1 5766
778cd667 5767 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
61b0191c 5768 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5769 aLine->SetToUpdate();
5770 aContext->Display (aLine, Standard_True);
25289ec1 5771
5772 return 0;
5773}
5774
61b0191c 5775
2bd4c032 5776//==============================================================================
5777//function : VGrid
5778//purpose :
5779//==============================================================================
5780
35e08fe8 5781static int VGrid (Draw_Interpretor& /*theDI*/,
2bd4c032 5782 Standard_Integer theArgNb,
5783 const char** theArgVec)
5784{
2bd4c032 5785 Handle(V3d_View) aView = ViewerTest::CurrentView();
5786 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5787 if (aView.IsNull() || aViewer.IsNull())
5788 {
79931835 5789 std::cerr << "Error: no active view\n";
2bd4c032 5790 return 1;
5791 }
5792
5793 Aspect_GridType aType = aViewer->GridType();
5794 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
79931835 5795 Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY;
5796 Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0;
5797 bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false;
224f48fa 5798 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
79931835 5799 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2bd4c032 5800 {
79931835 5801 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5802 anArg.LowerCase();
5803 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
224f48fa 5804 {
5805 continue;
5806 }
79931835 5807 else if (anArgIter + 1 < theArgNb
5808 && anArg == "-type")
5809 {
5810 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5811 anArgNext.LowerCase();
5812 if (anArgNext == "r"
5813 || anArgNext == "rect"
5814 || anArgNext == "rectangular")
5815 {
5816 aType = Aspect_GT_Rectangular;
5817 }
5818 else if (anArgNext == "c"
5819 || anArgNext == "circ"
5820 || anArgNext == "circular")
5821 {
5822 aType = Aspect_GT_Circular;
5823 }
5824 else
5825 {
5826 std::cout << "Syntax error at '" << anArgNext << "'\n";
5827 return 1;
5828 }
5829 }
5830 else if (anArgIter + 1 < theArgNb
5831 && anArg == "-mode")
5832 {
5833 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5834 anArgNext.LowerCase();
5835 if (anArgNext == "l"
5836 || anArgNext == "line"
5837 || anArgNext == "lines")
5838 {
5839 aMode = Aspect_GDM_Lines;
5840 }
5841 else if (anArgNext == "p"
5842 || anArgNext == "point"
5843 || anArgNext == "points")
5844 {
5845 aMode = Aspect_GDM_Points;
5846 }
5847 else
5848 {
5849 std::cout << "Syntax error at '" << anArgNext << "'\n";
5850 return 1;
5851 }
5852 }
5853 else if (anArgIter + 2 < theArgNb
5854 && (anArg == "-origin"
5855 || anArg == "-orig"))
5856 {
5857 hasOrigin = true;
5858 aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5859 Draw::Atof (theArgVec[anArgIter + 2]));
5860 anArgIter += 2;
5861 }
5862 else if (anArgIter + 2 < theArgNb
5863 && anArg == "-step")
5864 {
5865 hasStep = true;
5866 aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5867 Draw::Atof (theArgVec[anArgIter + 2]));
5868 if (aNewStepXY.x() <= 0.0
5869 || aNewStepXY.y() <= 0.0)
5870 {
5871 std::cout << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
5872 return 1;
5873 }
5874 anArgIter += 2;
5875 }
5876 else if (anArgIter + 1 < theArgNb
5877 && (anArg == "-angle"
5878 || anArg == "-rotangle"
5879 || anArg == "-rotationangle"))
5880 {
5881 hasRotAngle = true;
5882 aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]);
5883 }
5884 else if (anArgIter + 1 < theArgNb
5885 && (anArg == "-zoffset"
5886 || anArg == "-dz"))
5887 {
5888 hasZOffset = true;
5889 aNewZOffset = Draw::Atof (theArgVec[++anArgIter]);
5890 }
5891 else if (anArgIter + 1 < theArgNb
5892 && anArg == "-radius")
5893 {
5894 hasSize = true;
5895 ++anArgIter;
5896 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0);
5897 if (aNewStepXY.x() <= 0.0)
5898 {
5899 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'\n";
5900 return 1;
5901 }
5902 }
5903 else if (anArgIter + 2 < theArgNb
5904 && anArg == "-size")
5905 {
5906 hasSize = true;
5907 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5908 Draw::Atof (theArgVec[anArgIter + 2]));
5909 if (aNewStepXY.x() <= 0.0
5910 || aNewStepXY.y() <= 0.0)
5911 {
5912 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
5913 return 1;
5914 }
5915 anArgIter += 2;
5916 }
5917 else if (anArg == "r"
5918 || anArg == "rect"
5919 || anArg == "rectangular")
2bd4c032 5920 {
5921 aType = Aspect_GT_Rectangular;
5922 }
79931835 5923 else if (anArg == "c"
5924 || anArg == "circ"
5925 || anArg == "circular")
2bd4c032 5926 {
5927 aType = Aspect_GT_Circular;
5928 }
79931835 5929 else if (anArg == "l"
5930 || anArg == "line"
5931 || anArg == "lines")
2bd4c032 5932 {
5933 aMode = Aspect_GDM_Lines;
5934 }
79931835 5935 else if (anArg == "p"
5936 || anArg == "point"
5937 || anArg == "points")
2bd4c032 5938 {
5939 aMode = Aspect_GDM_Points;
5940 }
79931835 5941 else if (anArgIter + 1 >= theArgNb
5942 && anArg == "off")
2bd4c032 5943 {
5944 aViewer->DeactivateGrid();
5945 return 0;
5946 }
5947 else
5948 {
79931835 5949 std::cout << "Syntax error at '" << anArg << "'\n";
5950 return 1;
2bd4c032 5951 }
5952 }
5953
2bd4c032 5954 if (aType == Aspect_GT_Rectangular)
5955 {
79931835 5956 Graphic3d_Vec2d anOrigXY, aStepXY;
5957 Standard_Real aRotAngle = 0.0;
5958 aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
5959 if (hasOrigin)
5960 {
5961 anOrigXY = aNewOriginXY;
5962 }
5963 if (hasStep)
5964 {
5965 aStepXY = aNewStepXY;
5966 }
5967 if (hasRotAngle)
5968 {
5969 aRotAngle = aNewRotAngle;
5970 }
5971 aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
5972 if (hasSize || hasZOffset)
2bd4c032 5973 {
79931835 5974 Graphic3d_Vec3d aSize;
5975 aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
5976 if (hasSize)
5977 {
5978 aSize.x() = aNewSizeXY.x();
5979 aSize.y() = aNewSizeXY.y();
5980 }
5981 if (hasZOffset)
5982 {
5983 aSize.z() = aNewZOffset;
5984 }
5985 aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
2bd4c032 5986 }
2bd4c032 5987 }
5988 else if (aType == Aspect_GT_Circular)
5989 {
79931835 5990 Graphic3d_Vec2d anOrigXY;
ee2be2a8 5991 Standard_Real aRadiusStep;
2bd4c032 5992 Standard_Integer aDivisionNumber;
79931835 5993 Standard_Real aRotAngle = 0.0;
5994 aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
5995 if (hasOrigin)
5996 {
5997 anOrigXY = aNewOriginXY;
5998 }
5999 if (hasStep)
6000 {
6001 aRadiusStep = aNewStepXY[0];
6002 aDivisionNumber = (int )aNewStepXY[1];
6003 if (aDivisionNumber < 1)
6004 {
6005 std::cout << "Syntax error: invalid division number '" << aNewStepXY[1] << "'\n";
6006 return 1;
6007 }
6008 }
6009 if (hasRotAngle)
2bd4c032 6010 {
79931835 6011 aRotAngle = aNewRotAngle;
2bd4c032 6012 }
6013
79931835 6014 aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
6015 if (hasSize || hasZOffset)
6016 {
6017 Standard_Real aRadius = 0.0, aZOffset = 0.0;
6018 aViewer->CircularGridGraphicValues (aRadius, aZOffset);
6019 if (hasSize)
6020 {
6021 aRadius = aNewSizeXY.x();
6022 if (aNewSizeXY.y() != 0.0)
6023 {
6024 std::cout << "Syntax error: circular size should be specified as radius\n";
6025 return 1;
6026 }
6027 }
6028 if (hasZOffset)
6029 {
6030 aZOffset = aNewZOffset;
6031 }
6032 aViewer->SetCircularGridGraphicValues (aRadius, aZOffset);
6033 }
2bd4c032 6034 }
79931835 6035 aViewer->ActivateGrid (aType, aMode);
2bd4c032 6036 return 0;
6037}
6038
c40b7d58 6039//==============================================================================
6040//function : VPriviledgedPlane
6041//purpose :
6042//==============================================================================
6043
6044static int VPriviledgedPlane (Draw_Interpretor& theDI,
6045 Standard_Integer theArgNb,
6046 const char** theArgVec)
6047{
6048 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
6049 {
6050 std::cerr << "Error: wrong number of arguments! See usage:\n";
6051 theDI.PrintHelp (theArgVec[0]);
6052 return 1;
6053 }
6054
6055 // get the active viewer
6056 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6057 if (aViewer.IsNull())
6058 {
6059 std::cerr << "Error: no active viewer. Please call vinit.\n";
6060 return 1;
6061 }
6062
6063 if (theArgNb == 1)
6064 {
6065 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
6066 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
6067 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
6068 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
6069 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
6070 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
6071 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
6072 return 0;
6073 }
6074
6075 Standard_Integer anArgIdx = 1;
6076 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
6077 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
6078 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
6079 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
6080 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
6081 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
6082
6083 gp_Ax3 aPriviledgedPlane;
6084 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
6085 gp_Dir aNorm (aNormX, aNormY, aNormZ);
6086 if (theArgNb > 7)
6087 {
6088 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
6089 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
6090 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
6091 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
6092 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
6093 }
6094 else
6095 {
6096 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
6097 }
6098
6099 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
6100
6101 return 0;
6102}
6103
f25b82d6 6104//==============================================================================
6105//function : VConvert
6106//purpose :
6107//==============================================================================
6108
6109static int VConvert (Draw_Interpretor& theDI,
6110 Standard_Integer theArgNb,
6111 const char** theArgVec)
6112{
6113 // get the active view
6114 Handle(V3d_View) aView = ViewerTest::CurrentView();
6115 if (aView.IsNull())
6116 {
c40b7d58 6117 std::cerr << "Error: no active view. Please call vinit.\n";
f25b82d6 6118 return 1;
6119 }
6120
6121 enum { Model, Ray, View, Window, Grid } aMode = Model;
6122
6123 // access coordinate arguments
6124 TColStd_SequenceOfReal aCoord;
6125 Standard_Integer anArgIdx = 1;
6126 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
6127 {
6128 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6129 if (!anArg.IsRealValue())
6130 {
6131 break;
6132 }
6133 aCoord.Append (anArg.RealValue());
6134 }
6135
6136 // non-numeric argument too early
6137 if (aCoord.IsEmpty())
6138 {
6139 std::cerr << "Error: wrong number of arguments! See usage:\n";
6140 theDI.PrintHelp (theArgVec[0]);
6141 return 1;
6142 }
6143
6144 // collect all other arguments and options
6145 for (; anArgIdx < theArgNb; ++anArgIdx)
6146 {
6147 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
6148 anArg.LowerCase();
6149 if (anArg == "window") aMode = Window;
6150 else if (anArg == "view") aMode = View;
6151 else if (anArg == "grid") aMode = Grid;
6152 else if (anArg == "ray") aMode = Ray;
6153 else
6154 {
6155 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
6156 theDI.PrintHelp (theArgVec[0]);
6157 return 1;
6158 }
6159 }
6160
6161 // complete input checks
6162 if ((aCoord.Length() == 1 && theArgNb > 3) ||
6163 (aCoord.Length() == 2 && theArgNb > 4) ||
6164 (aCoord.Length() == 3 && theArgNb > 5))
6165 {
6166 std::cerr << "Error: wrong number of arguments! See usage:\n";
6167 theDI.PrintHelp (theArgVec[0]);
6168 return 1;
6169 }
6170
6171 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
6172 Standard_Integer aXYp[2] = {0, 0};
6173
6174 // convert one-dimensional coordinate
6175 if (aCoord.Length() == 1)
6176 {
6177 switch (aMode)
6178 {
ee2be2a8 6179 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
6180 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
f25b82d6 6181 default:
6182 std::cerr << "Error: wrong arguments! See usage:\n";
6183 theDI.PrintHelp (theArgVec[0]);
6184 return 1;
6185 }
6186 }
6187
6188 // convert 2D coordinates from projection or view reference space
6189 if (aCoord.Length() == 2)
6190 {
6191 switch (aMode)
6192 {
6193 case Model :
6194 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6195 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6196 return 0;
6197
6198 case View :
6199 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
6200 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
6201 return 0;
6202
6203 case Window :
ee2be2a8 6204 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
f25b82d6 6205 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6206 return 0;
6207
6208 case Grid :
6209 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
6210 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
6211 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6212 return 0;
6213
6214 case Ray :
6215 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
6216 (Standard_Integer) aCoord (2),
6217 aXYZ[0], aXYZ[1], aXYZ[2],
6218 aXYZ[3], aXYZ[4], aXYZ[5]);
6219 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
6220 return 0;
6221
6222 default:
6223 std::cerr << "Error: wrong arguments! See usage:\n";
6224 theDI.PrintHelp (theArgVec[0]);
6225 return 1;
6226 }
6227 }
6228
6229 // convert 3D coordinates from view reference space
6230 else if (aCoord.Length() == 3)
6231 {
6232 switch (aMode)
6233 {
6234 case Window :
6235 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
6236 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
6237 return 0;
6238
6239 case Grid :
6240 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
6241 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
6242 return 0;
6243
6244 default:
6245 std::cerr << "Error: wrong arguments! See usage:\n";
6246 theDI.PrintHelp (theArgVec[0]);
6247 return 1;
6248 }
6249 }
6250
6251 return 0;
6252}
6253
208e6839 6254//==============================================================================
6255//function : VFps
6256//purpose :
6257//==============================================================================
6258
6259static int VFps (Draw_Interpretor& theDI,
6260 Standard_Integer theArgNb,
6261 const char** theArgVec)
6262{
6263 // get the active view
6264 Handle(V3d_View) aView = ViewerTest::CurrentView();
6265 if (aView.IsNull())
6266 {
6267 std::cerr << "No active view. Please call vinit.\n";
6268 return 1;
6269 }
6270
e084dbbc 6271 Standard_Integer aFramesNb = -1;
6272 Standard_Real aDuration = -1.0;
6273 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
208e6839 6274 {
e084dbbc 6275 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6276 anArg.LowerCase();
6277 if (aDuration < 0.0
6278 && anArgIter + 1 < theArgNb
6279 && (anArg == "-duration"
6280 || anArg == "-dur"
6281 || anArg == "-time"))
6282 {
6283 aDuration = Draw::Atof (theArgVec[++anArgIter]);
6284 }
6285 else if (aFramesNb < 0
6286 && anArg.IsIntegerValue())
6287 {
6288 aFramesNb = anArg.IntegerValue();
6289 if (aFramesNb <= 0)
6290 {
6291 std::cerr << "Syntax error at '" << anArg << "'\n";
6292 return 1;
6293 }
6294 }
6295 else
6296 {
6297 std::cerr << "Syntax error at '" << anArg << "'\n";
6298 return 1;
6299 }
6300 }
6301 if (aFramesNb < 0 && aDuration < 0.0)
6302 {
6303 aFramesNb = 100;
208e6839 6304 }
6305
6306 // the time is meaningless for first call
6307 // due to async OpenGl rendering
6308 aView->Redraw();
6309
6310 // redraw view in loop to estimate average values
6311 OSD_Timer aTimer;
6312 aTimer.Start();
e084dbbc 6313 Standard_Integer aFrameIter = 1;
6314 for (;; ++aFrameIter)
208e6839 6315 {
6316 aView->Redraw();
e084dbbc 6317 if ((aFramesNb > 0
6318 && aFrameIter >= aFramesNb)
6319 || (aDuration > 0.0
6320 && aTimer.ElapsedTime() >= aDuration))
6321 {
6322 break;
6323 }
208e6839 6324 }
6325 aTimer.Stop();
6326 Standard_Real aCpu;
6327 const Standard_Real aTime = aTimer.ElapsedTime();
6328 aTimer.OSD_Chronometer::Show (aCpu);
6329
e084dbbc 6330 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
6331 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
208e6839 6332
6333 // return statistics
6334 theDI << "FPS: " << aFpsAver << "\n"
6335 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
6336
8c820969 6337 // compute additional statistics in ray-tracing mode
e084dbbc 6338 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
8c820969 6339 if (aParams.Method == Graphic3d_RM_RAYTRACING)
6340 {
e084dbbc 6341 Graphic3d_Vec2i aWinSize (0, 0);
6342 aView->Window()->Size (aWinSize.x(), aWinSize.y());
8c820969 6343
6344 // 1 shadow ray and 1 secondary ray pew each bounce
e084dbbc 6345 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
8c820969 6346 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
6347 }
6348
208e6839 6349 return 0;
6350}
6351
84e84755 6352//! Auxiliary function for parsing glsl dump level argument.
6353static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
6354 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
6355{
6356 TCollection_AsciiString aTypeStr (theArg);
6357 aTypeStr.LowerCase();
6358 if (aTypeStr == "off"
6359 || aTypeStr == "0")
6360 {
6361 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6362 }
6363 else if (aTypeStr == "short")
6364 {
6365 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
6366 }
6367 else if (aTypeStr == "full"
6368 || aTypeStr == "1")
6369 {
6370 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6371 }
6372 else
6373 {
6374 return Standard_False;
6375 }
6376 return Standard_True;
6377}
6378
58655684 6379//==============================================================================
6380//function : VGlDebug
6381//purpose :
6382//==============================================================================
6383
6384static int VGlDebug (Draw_Interpretor& theDI,
6385 Standard_Integer theArgNb,
6386 const char** theArgVec)
6387{
aaf512f1 6388 Handle(OpenGl_GraphicDriver) aDriver;
6389 Handle(V3d_View) aView = ViewerTest::CurrentView();
6390 if (!aView.IsNull())
6391 {
6392 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
6393 }
c87535af 6394 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
6395 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
6396
58655684 6397 if (theArgNb < 2)
6398 {
c87535af 6399 TCollection_AsciiString aDebActive, aSyncActive;
6400 if (aCaps == NULL)
58655684 6401 {
c87535af 6402 aCaps = aDefCaps;
6403 }
6404 else
6405 {
6406 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
6407 "GL_ARB_debug_output");
6408 aDebActive = isActive ? " (active)" : " (inactive)";
6409 if (isActive)
6410 {
6411 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
6412 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
6413 }
58655684 6414 }
6415
84e84755 6416 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
6417 + "glslSourceCode: "
6418 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
6419 ? "Off"
6420 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
6421 ? "Short"
6422 : "Full")
6423 + "\n";
6424 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
6425 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
6426 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
6427 << aGlslCodeDebugStatus
6428 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
58655684 6429 return 0;
6430 }
6431
c87535af 6432 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
aaf512f1 6433 {
c87535af 6434 Standard_CString anArg = theArgVec[anArgIter];
6435 TCollection_AsciiString anArgCase (anArg);
6436 anArgCase.LowerCase();
6437 Standard_Boolean toEnableDebug = Standard_True;
6438 if (anArgCase == "-glsl"
6439 || anArgCase == "-glslwarn"
6440 || anArgCase == "-glslwarns"
6441 || anArgCase == "-glslwarnings")
6442 {
6443 Standard_Boolean toShowWarns = Standard_True;
6444 if (++anArgIter < theArgNb
a5565a3c 6445 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
c87535af 6446 {
6447 --anArgIter;
6448 }
6449 aDefCaps->glslWarnings = toShowWarns;
6450 if (aCaps != NULL)
6451 {
6452 aCaps->glslWarnings = toShowWarns;
6453 }
6454 }
6455 else if (anArgCase == "-extra"
6456 || anArgCase == "-extramsg"
6457 || anArgCase == "-extramessages")
6458 {
6459 Standard_Boolean toShow = Standard_True;
6460 if (++anArgIter < theArgNb
a5565a3c 6461 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
c87535af 6462 {
6463 --anArgIter;
6464 }
6465 aDefCaps->suppressExtraMsg = !toShow;
6466 if (aCaps != NULL)
6467 {
6468 aCaps->suppressExtraMsg = !toShow;
6469 }
6470 }
6471 else if (anArgCase == "-noextra"
6472 || anArgCase == "-noextramsg"
6473 || anArgCase == "-noextramessages")
6474 {
6475 Standard_Boolean toSuppress = Standard_True;
6476 if (++anArgIter < theArgNb
a5565a3c 6477 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
c87535af 6478 {
6479 --anArgIter;
6480 }
6481 aDefCaps->suppressExtraMsg = toSuppress;
6482 if (aCaps != NULL)
6483 {
6484 aCaps->suppressExtraMsg = toSuppress;
6485 }
6486 }
6487 else if (anArgCase == "-sync")
6488 {
6489 Standard_Boolean toSync = Standard_True;
6490 if (++anArgIter < theArgNb
a5565a3c 6491 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
c87535af 6492 {
6493 --anArgIter;
6494 }
6495 aDefCaps->contextSyncDebug = toSync;
6496 if (toSync)
6497 {
6498 aDefCaps->contextDebug = Standard_True;
6499 }
6500 }
84e84755 6501 else if (anArgCase == "-glslsourcecode"
6502 || anArgCase == "-glslcode")
6503 {
6504 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
6505 if (++anArgIter < theArgNb
6506 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
6507 {
6508 --anArgIter;
6509 }
6510 aDefCaps->glslDumpLevel = aGslsDumpLevel;
6511 if (aCaps != NULL)
6512 {
6513 aCaps->glslDumpLevel = aGslsDumpLevel;
6514 }
6515 }
c87535af 6516 else if (anArgCase == "-debug")
6517 {
6518 if (++anArgIter < theArgNb
a5565a3c 6519 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
c87535af 6520 {
6521 --anArgIter;
6522 }
6523 aDefCaps->contextDebug = toEnableDebug;
6524 }
a5565a3c 6525 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
c87535af 6526 && (anArgIter + 1 == theArgNb))
6527 {
6528 // simple alias to turn on almost everything
6529 aDefCaps->contextDebug = toEnableDebug;
6530 aDefCaps->contextSyncDebug = toEnableDebug;
6531 aDefCaps->glslWarnings = toEnableDebug;
3b4c6945 6532 if (!toEnableDebug)
6533 {
6534 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6535 }
84e84755 6536 aDefCaps->suppressExtraMsg = !toEnableDebug;
6537 if (aCaps != NULL)
6538 {
6539 aCaps->contextDebug = toEnableDebug;
6540 aCaps->contextSyncDebug = toEnableDebug;
6541 aCaps->glslWarnings = toEnableDebug;
3b4c6945 6542 if (!toEnableDebug)
6543 {
6544 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6545 }
84e84755 6546 aCaps->suppressExtraMsg = !toEnableDebug;
6547 }
c87535af 6548 }
6549 else
6550 {
6551 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
6552 return 1;
6553 }
aaf512f1 6554 }
6555
58655684 6556 return 0;
6557}
208e6839 6558
6559//==============================================================================
6560//function : VVbo
6561//purpose :
6562//==============================================================================
6563
58655684 6564static int VVbo (Draw_Interpretor& theDI,
208e6839 6565 Standard_Integer theArgNb,
6566 const char** theArgVec)
6567{
58655684 6568 const Standard_Boolean toSet = (theArgNb > 1);
6569 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
6570 if (toSet)
208e6839 6571 {
58655684 6572 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
208e6839 6573 }
6574
58655684 6575 // get the context
6576 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6577 if (aContextAIS.IsNull())
208e6839 6578 {
58655684 6579 if (!toSet)
6580 {
6581 std::cerr << "No active view!\n";
6582 }
208e6839 6583 return 1;
6584 }
58655684 6585 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
6586 if (!aDriver.IsNull())
208e6839 6587 {
58655684 6588 if (!toSet)
6589 {
6590 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
6591 }
6592 else
6593 {
6594 aDriver->ChangeOptions().vboDisable = toUseVbo;
6595 }
208e6839 6596 }
6597
208e6839 6598 return 0;
6599}
6600
a577aaab 6601//==============================================================================
6602//function : VCaps
6603//purpose :
6604//==============================================================================
6605
6606static int VCaps (Draw_Interpretor& theDI,
6607 Standard_Integer theArgNb,
6608 const char** theArgVec)
6609{
6610 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
6611 Handle(OpenGl_GraphicDriver) aDriver;
8625ef7e 6612 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6613 if (!aContext.IsNull())
a577aaab 6614 {
8625ef7e 6615 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
a577aaab 6616 aCaps = &aDriver->ChangeOptions();
6617 }
6618
6619 if (theArgNb < 2)
6620 {
6621 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
6622 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
abe46077 6623 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
8625ef7e 6624 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
2a332745 6625 theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n";
f978241f 6626 theDI << "VSync: " << aCaps->swapInterval << "\n";
4e1523ef 6627 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
f978241f 6628 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
56689b27 6629 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
59515ca6 6630 theDI << "NoExt:" << (aCaps->contextNoExtensions ? "1" : "0") << "\n";
6631 theDI << "MaxVersion:" << aCaps->contextMajorVersionUpper << "." << aCaps->contextMinorVersionUpper << "\n";
a577aaab 6632 return 0;
6633 }
6634
8625ef7e 6635 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
a577aaab 6636 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6637 {
8625ef7e 6638 Standard_CString anArg = theArgVec[anArgIter];
6639 TCollection_AsciiString anArgCase (anArg);
6640 anArgCase.LowerCase();
6641 if (anUpdateTool.parseRedrawMode (anArg))
6642 {
6643 continue;
6644 }
f978241f 6645 else if (anArgCase == "-vsync"
6646 || anArgCase == "-swapinterval")
6647 {
6648 Standard_Boolean toEnable = Standard_True;
6649 if (++anArgIter < theArgNb
a5565a3c 6650 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 6651 {
6652 --anArgIter;
6653 }
6654 aCaps->swapInterval = toEnable;
6655 }
8625ef7e 6656 else if (anArgCase == "-ffp")
6657 {
6658 Standard_Boolean toEnable = Standard_True;
6659 if (++anArgIter < theArgNb
a5565a3c 6660 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 6661 {
6662 --anArgIter;
6663 }
6664 aCaps->ffpEnable = toEnable;
6665 }
2a332745 6666 else if (anArgCase == "-polygonmode")
6667 {
6668 Standard_Boolean toEnable = Standard_True;
6669 if (++anArgIter < theArgNb
6670 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6671 {
6672 --anArgIter;
6673 }
6674 aCaps->usePolygonMode = toEnable;
6675 }
8625ef7e 6676 else if (anArgCase == "-vbo")
a577aaab 6677 {
8625ef7e 6678 Standard_Boolean toEnable = Standard_True;
6679 if (++anArgIter < theArgNb
a5565a3c 6680 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 6681 {
6682 --anArgIter;
6683 }
6684 aCaps->vboDisable = !toEnable;
a577aaab 6685 }
8625ef7e 6686 else if (anArgCase == "-sprite"
6687 || anArgCase == "-sprites")
a577aaab 6688 {
8625ef7e 6689 Standard_Boolean toEnable = Standard_True;
6690 if (++anArgIter < theArgNb
a5565a3c 6691 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 6692 {
6693 --anArgIter;
6694 }
6695 aCaps->pntSpritesDisable = !toEnable;
a577aaab 6696 }
8625ef7e 6697 else if (anArgCase == "-softmode")
abe46077 6698 {
8625ef7e 6699 Standard_Boolean toEnable = Standard_True;
6700 if (++anArgIter < theArgNb
a5565a3c 6701 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 6702 {
6703 --anArgIter;
6704 }
6705 aCaps->contextNoAccel = toEnable;
6706 }
56689b27 6707 else if (anArgCase == "-winbuffer"
6708 || anArgCase == "-windowbuffer"
6709 || anArgCase == "-usewinbuffer"
6710 || anArgCase == "-usewindowbuffer"
6711 || anArgCase == "-usesystembuffer")
6712 {
6713 Standard_Boolean toEnable = Standard_True;
6714 if (++anArgIter < theArgNb
6715 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6716 {
6717 --anArgIter;
6718 }
6719 aCaps->useSystemBuffer = toEnable;
6720 }
8625ef7e 6721 else if (anArgCase == "-accel"
6722 || anArgCase == "-acceleration")
6723 {
6724 Standard_Boolean toEnable = Standard_True;
6725 if (++anArgIter < theArgNb
a5565a3c 6726 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8625ef7e 6727 {
6728 --anArgIter;
6729 }
6730 aCaps->contextNoAccel = !toEnable;
abe46077 6731 }
4e1523ef 6732 else if (anArgCase == "-compat"
6733 || anArgCase == "-compatprofile"
6734 || anArgCase == "-compatible"
6735 || anArgCase == "-compatibleprofile")
6736 {
6737 Standard_Boolean toEnable = Standard_True;
6738 if (++anArgIter < theArgNb
a5565a3c 6739 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
4e1523ef 6740 {
6741 --anArgIter;
6742 }
6743 aCaps->contextCompatible = toEnable;
6744 if (!aCaps->contextCompatible)
6745 {
6746 aCaps->ffpEnable = Standard_False;
6747 }
6748 }
6749 else if (anArgCase == "-core"
6750 || anArgCase == "-coreprofile")
6751 {
6752 Standard_Boolean toEnable = Standard_True;
6753 if (++anArgIter < theArgNb
a5565a3c 6754 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
4e1523ef 6755 {
6756 --anArgIter;
6757 }
6758 aCaps->contextCompatible = !toEnable;
6759 if (!aCaps->contextCompatible)
6760 {
6761 aCaps->ffpEnable = Standard_False;
6762 }
6763 }
f978241f 6764 else if (anArgCase == "-stereo"
6765 || anArgCase == "-quadbuffer")
6766 {
6767 Standard_Boolean toEnable = Standard_True;
6768 if (++anArgIter < theArgNb
a5565a3c 6769 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 6770 {
6771 --anArgIter;
6772 }
6773 aCaps->contextStereo = toEnable;
6774 }
59515ca6 6775 else if (anArgCase == "-noext"
6776 || anArgCase == "-noextensions"
6777 || anArgCase == "-noextension")
6778 {
6779 Standard_Boolean toDisable = Standard_True;
6780 if (++anArgIter < theArgNb
6781 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
6782 {
6783 --anArgIter;
6784 }
6785 aCaps->contextNoExtensions = toDisable;
6786 }
6787 else if (anArgCase == "-maxversion"
6788 || anArgCase == "-upperversion"
6789 || anArgCase == "-limitversion")
6790 {
6791 Standard_Integer aVer[2] = { -2, -1 };
6792 for (Standard_Integer aValIter = 0; aValIter < 2; ++aValIter)
6793 {
6794 if (anArgIter + 1 < theArgNb)
6795 {
6796 const TCollection_AsciiString aStr (theArgVec[anArgIter + 1]);
6797 if (aStr.IsIntegerValue())
6798 {
6799 aVer[aValIter] = aStr.IntegerValue();
6800 ++anArgIter;
6801 }
6802 }
6803 }
6804 if (aVer[0] < -1
6805 || aVer[1] < -1)
6806 {
6807 std::cout << "Syntax error at '" << anArgCase << "'\n";
6808 return 1;
6809 }
6810 aCaps->contextMajorVersionUpper = aVer[0];
6811 aCaps->contextMinorVersionUpper = aVer[1];
6812 }
a577aaab 6813 else
6814 {
8625ef7e 6815 std::cout << "Error: unknown argument '" << anArg << "'\n";
6816 return 1;
a577aaab 6817 }
6818 }
6819 if (aCaps != &ViewerTest_myDefaultCaps)
6820 {
6821 ViewerTest_myDefaultCaps = *aCaps;
6822 }
6823 return 0;
6824}
6825
f0430952 6826//==============================================================================
6827//function : VMemGpu
6828//purpose :
6829//==============================================================================
6830
6831static int VMemGpu (Draw_Interpretor& theDI,
6832 Standard_Integer theArgNb,
6833 const char** theArgVec)
6834{
6835 // get the context
6836 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6837 if (aContextAIS.IsNull())
6838 {
6839 std::cerr << "No active view. Please call vinit.\n";
6840 return 1;
6841 }
6842
dc3fe572 6843 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
f0430952 6844 if (aDriver.IsNull())
6845 {
6846 std::cerr << "Graphic driver not available.\n";
6847 return 1;
6848 }
6849
6850 Standard_Size aFreeBytes = 0;
6851 TCollection_AsciiString anInfo;
6852 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
6853 {
6854 std::cerr << "Information not available.\n";
6855 return 1;
6856 }
6857
6858 if (theArgNb > 1 && *theArgVec[1] == 'f')
6859 {
6860 theDI << Standard_Real (aFreeBytes);
6861 }
6862 else
6863 {
6864 theDI << anInfo;
6865 }
6866
6867 return 0;
6868}
6869
85e096c3 6870// ==============================================================================
6871// function : VReadPixel
6872// purpose :
6873// ==============================================================================
6874static int VReadPixel (Draw_Interpretor& theDI,
6875 Standard_Integer theArgNb,
6876 const char** theArgVec)
6877{
6878 // get the active view
6879 Handle(V3d_View) aView = ViewerTest::CurrentView();
6880 if (aView.IsNull())
6881 {
6882 std::cerr << "No active view. Please call vinit.\n";
6883 return 1;
6884 }
6885 else if (theArgNb < 3)
6886 {
6887 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
6888 return 1;
6889 }
6890
dc858f4c 6891 Image_Format aFormat = Image_Format_RGBA;
6892 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
692613e5 6893
85e096c3 6894 Standard_Integer aWidth, aHeight;
6895 aView->Window()->Size (aWidth, aHeight);
91322f44 6896 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
6897 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
85e096c3 6898 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
6899 {
6900 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
6901 return 1;
6902 }
6903
6904 Standard_Boolean toShowName = Standard_False;
6905 Standard_Boolean toShowHls = Standard_False;
6906 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
6907 {
dc858f4c 6908 TCollection_AsciiString aParam (theArgVec[anIter]);
6909 aParam.LowerCase();
55c8f0f7
BB
6910 if (aParam == "-rgb"
6911 || aParam == "rgb")
85e096c3 6912 {
dc858f4c 6913 aFormat = Image_Format_RGB;
692613e5 6914 aBufferType = Graphic3d_BT_RGB;
85e096c3 6915 }
55c8f0f7
BB
6916 else if (aParam == "-hls"
6917 || aParam == "hls")
85e096c3 6918 {
dc858f4c 6919 aFormat = Image_Format_RGB;
692613e5 6920 aBufferType = Graphic3d_BT_RGB;
85e096c3 6921 toShowHls = Standard_True;
6922 }
55c8f0f7
BB
6923 else if (aParam == "-rgbf"
6924 || aParam == "rgbf")
85e096c3 6925 {
dc858f4c 6926 aFormat = Image_Format_RGBF;
692613e5 6927 aBufferType = Graphic3d_BT_RGB;
85e096c3 6928 }
55c8f0f7
BB
6929 else if (aParam == "-rgba"
6930 || aParam == "rgba")
85e096c3 6931 {
dc858f4c 6932 aFormat = Image_Format_RGBA;
692613e5 6933 aBufferType = Graphic3d_BT_RGBA;
85e096c3 6934 }
55c8f0f7
BB
6935 else if (aParam == "-rgbaf"
6936 || aParam == "rgbaf")
85e096c3 6937 {
dc858f4c 6938 aFormat = Image_Format_RGBAF;
692613e5 6939 aBufferType = Graphic3d_BT_RGBA;
85e096c3 6940 }
55c8f0f7
BB
6941 else if (aParam == "-depth"
6942 || aParam == "depth")
85e096c3 6943 {
dc858f4c 6944 aFormat = Image_Format_GrayF;
692613e5 6945 aBufferType = Graphic3d_BT_Depth;
85e096c3 6946 }
55c8f0f7
BB
6947 else if (aParam == "-name"
6948 || aParam == "name")
85e096c3 6949 {
6950 toShowName = Standard_True;
6951 }
55c8f0f7
BB
6952 else
6953 {
6954 std::cout << "Syntax error at '" << aParam << "'\n";
6955 }
85e096c3 6956 }
6957
692613e5 6958 Image_PixMap anImage;
6959 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
6960 {
6961 std::cerr << "Image allocation failed\n";
6962 return 1;
6963 }
6964 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
85e096c3 6965 {
6966 std::cerr << "Image dump failed\n";
6967 return 1;
6968 }
6969
68beaa3c 6970 // redirect possible warning messages that could have been added by ToPixMap
6971 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
6972 // contaminate result of the command
6973 Standard_CString aWarnLog = theDI.Result();
6974 if (aWarnLog != NULL && aWarnLog[0] != '\0')
6975 {
6976 std::cout << aWarnLog << std::endl;
6977 }
6978 theDI.Reset();
6979
e958a649 6980 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
85e096c3 6981 if (toShowName)
6982 {
692613e5 6983 if (aBufferType == Graphic3d_BT_RGBA)
85e096c3 6984 {
e958a649 6985 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
85e096c3 6986 }
6987 else
6988 {
e958a649 6989 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
85e096c3 6990 }
6991 }
6992 else
6993 {
6994 switch (aBufferType)
6995 {
6996 default:
692613e5 6997 case Graphic3d_BT_RGB:
85e096c3 6998 {
6999 if (toShowHls)
7000 {
e958a649 7001 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
85e096c3 7002 }
7003 else
7004 {
e958a649 7005 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
85e096c3 7006 }
7007 break;
7008 }
692613e5 7009 case Graphic3d_BT_RGBA:
85e096c3 7010 {
e958a649 7011 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
85e096c3 7012 break;
7013 }
692613e5 7014 case Graphic3d_BT_Depth:
85e096c3 7015 {
e958a649 7016 theDI << aColor.GetRGB().Red();
85e096c3 7017 break;
7018 }
7019 }
7020 }
7021
7022 return 0;
7023}
7024
fd3f6bd0 7025//! Auxiliary presentation for an image plane.
7026class ViewerTest_ImagePrs : public AIS_InteractiveObject
7027{
7028public:
7029 //! Main constructor.
7030 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
7031 const Standard_Real theWidth,
7032 const Standard_Real theHeight,
7033 const TCollection_AsciiString& theLabel)
7034 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
7035 {
7036 SetDisplayMode (0);
7037 SetHilightMode (1);
7038 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
7039 {
7040 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
7041 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
7042 Graphic3d_MaterialAspect aMat;
7043 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
7044 aMat.SetAmbient (1.0);
7045 aMat.SetDiffuse (1.0);
7046 aMat.SetSpecular (1.0);
7047 aMat.SetEmissive (1.0);
7048 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
7049 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
7050 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
7051 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
7052 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
7053 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
7054 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
7055 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
7056 aFillAspect->SetFrontMaterial (aMat);
7057 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
7058 aFillAspect->SetTextureMapOn();
7059 }
7060 {
7061 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
7062 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
7063 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
7064 myDrawer->SetTextAspect (aTextAspect);
7065 }
7066 {
7067 const gp_Dir aNorm (0.0, 0.0, 1.0);
7068 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
7069 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
7070 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
7071 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
7072 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
7073 myTris->AddEdge (1);
7074 myTris->AddEdge (2);
7075 myTris->AddEdge (3);
7076 myTris->AddEdge (3);
7077 myTris->AddEdge (2);
7078 myTris->AddEdge (4);
7079
7080 myRect = new Graphic3d_ArrayOfPolylines (4);
7081 myRect->AddVertex (myTris->Vertice (1));
7082 myRect->AddVertex (myTris->Vertice (3));
7083 myRect->AddVertex (myTris->Vertice (4));
7084 myRect->AddVertex (myTris->Vertice (2));
7085 }
7086 }
7087
7088 //! Returns TRUE for accepted display modes.
7089 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
7090
7091 //! Compute presentation.
7092 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
7093 {
7094 switch (theMode)
7095 {
7096 case 0:
7097 {
7098 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7099 aGroup->AddPrimitiveArray (myTris);
7100 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
7101 aGroup->AddPrimitiveArray (myRect);
7102 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7103 return;
7104 }
7105 case 1:
7106 {
7107 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
7108 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
7109 aGroup->AddPrimitiveArray (myRect);
7110 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
7111 return;
7112 }
7113 }
7114 }
7115
7116 //! Compute selection.
7117 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
7118 {
7119 if (theMode == 0)
7120 {
7121 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
7122 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
7123 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
7124 theSel->Add (aSensitive);
7125 }
7126 }
7127
7128private:
7129 Handle(Graphic3d_ArrayOfTriangles) myTris;
7130 Handle(Graphic3d_ArrayOfPolylines) myRect;
7131 TCollection_AsciiString myLabel;
7132 Standard_Real myWidth;
7133 Standard_Real myHeight;
7134};
7135
692613e5 7136//==============================================================================
7137//function : VDiffImage
7138//purpose : The draw-command compares two images.
7139//==============================================================================
7140
7141static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
7142{
fd3f6bd0 7143 if (theArgNb < 3)
692613e5 7144 {
fd3f6bd0 7145 std::cout << "Syntax error: not enough arguments.\n";
692613e5 7146 return 1;
7147 }
7148
fd3f6bd0 7149 Standard_Integer anArgIter = 1;
7150 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
7151 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
7152 TCollection_AsciiString aDiffImagePath;
7153 Standard_Real aTolColor = -1.0;
7154 Standard_Integer toBlackWhite = -1;
7155 Standard_Integer isBorderFilterOn = -1;
7156 Standard_Boolean isOldSyntax = Standard_False;
7157 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
7158 for (; anArgIter < theArgNb; ++anArgIter)
7159 {
7160 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7161 anArg.LowerCase();
7162 if (anArgIter + 1 < theArgNb
7163 && (anArg == "-toleranceofcolor"
7164 || anArg == "-tolerancecolor"
7165 || anArg == "-tolerance"
7166 || anArg == "-toler"))
7167 {
7168 aTolColor = Atof (theArgVec[++anArgIter]);
7169 if (aTolColor < 0.0 || aTolColor > 1.0)
7170 {
7171 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7172 return 1;
7173 }
7174 }
7175 else if (anArg == "-blackwhite")
7176 {
7177 Standard_Boolean toEnable = Standard_True;
7178 if (anArgIter + 1 < theArgNb
7179 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7180 {
7181 ++anArgIter;
7182 }
7183 toBlackWhite = toEnable ? 1 : 0;
7184 }
7185 else if (anArg == "-borderfilter")
7186 {
7187 Standard_Boolean toEnable = Standard_True;
7188 if (anArgIter + 1 < theArgNb
7189 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
7190 {
7191 ++anArgIter;
7192 }
7193 isBorderFilterOn = toEnable ? 1 : 0;
7194 }
7195 else if (anArg == "-exitonclose")
7196 {
49582f9d 7197 ViewerTest_EventManager::ToExitOnCloseView() = true;
fd3f6bd0 7198 if (anArgIter + 1 < theArgNb
49582f9d 7199 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToExitOnCloseView()))
fd3f6bd0 7200 {
7201 ++anArgIter;
7202 }
7203 }
7204 else if (anArg == "-closeonescape"
7205 || anArg == "-closeonesc")
7206 {
49582f9d 7207 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
fd3f6bd0 7208 if (anArgIter + 1 < theArgNb
49582f9d 7209 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
fd3f6bd0 7210 {
7211 ++anArgIter;
7212 }
7213 }
7214 else if (anArgIter + 3 < theArgNb
7215 && anArg == "-display")
7216 {
7217 aViewName = theArgVec[++anArgIter];
7218 aPrsNameRef = theArgVec[++anArgIter];
7219 aPrsNameNew = theArgVec[++anArgIter];
7220 if (anArgIter + 1 < theArgNb
7221 && *theArgVec[anArgIter + 1] != '-')
7222 {
7223 aPrsNameDiff = theArgVec[++anArgIter];
7224 }
7225 }
7226 else if (aTolColor < 0.0
7227 && anArg.IsRealValue())
7228 {
7229 isOldSyntax = Standard_True;
7230 aTolColor = anArg.RealValue();
7231 if (aTolColor < 0.0 || aTolColor > 1.0)
7232 {
7233 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
7234 return 1;
7235 }
7236 }
7237 else if (isOldSyntax
7238 && toBlackWhite == -1
7239 && (anArg == "0" || anArg == "1"))
7240 {
7241 toBlackWhite = anArg == "1" ? 1 : 0;
7242 }
7243 else if (isOldSyntax
7244 && isBorderFilterOn == -1
7245 && (anArg == "0" || anArg == "1"))
7246 {
7247 isBorderFilterOn = anArg == "1" ? 1 : 0;
7248 }
7249 else if (aDiffImagePath.IsEmpty())
7250 {
7251 aDiffImagePath = theArgVec[anArgIter];
7252 }
7253 else
7254 {
7255 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7256 return 1;
7257 }
7258 }
692613e5 7259
fd3f6bd0 7260 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
7261 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
7262 if (!anImgRef->Load (anImgPathRef))
7263 {
7264 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
7265 return 1;
7266 }
7267 if (!anImgNew->Load (anImgPathNew))
7268 {
7269 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
7270 return 1;
7271 }
692613e5 7272
7273 // compare the images
7274 Image_Diff aComparer;
fd3f6bd0 7275 Standard_Integer aDiffColorsNb = -1;
7276 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
692613e5 7277 {
fd3f6bd0 7278 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
7279 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
7280 aDiffColorsNb = aComparer.Compare();
7281 theDI << aDiffColorsNb << "\n";
692613e5 7282 }
7283
692613e5 7284 // save image of difference
fd3f6bd0 7285 Handle(Image_AlienPixMap) aDiff;
7286 if (aDiffColorsNb > 0
7287 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
7288 {
7289 aDiff = new Image_AlienPixMap();
7290 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
7291 {
7292 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
7293 return 1;
7294 }
7295 aComparer.SaveDiffImage (*aDiff);
7296 if (!aDiffImagePath.IsEmpty()
7297 && !aDiff->Save (aDiffImagePath))
7298 {
7299 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
7300 return 1;
7301 }
7302 }
7303
7304 if (aViewName.IsEmpty())
7305 {
7306 return 0;
7307 }
7308
7309 ViewerTest_Names aViewNames (aViewName);
7310 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
7311 {
7312 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
7313 theDI.Eval (aCommand.ToCString());
7314 }
7315
7316 Standard_Integer aPxLeft = 0;
7317 Standard_Integer aPxTop = 0;
7318 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
7319 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
7320 ? int(anImgRef->SizeY() * 2)
7321 : int(anImgRef->SizeY());
7322 TCollection_AsciiString aDisplayName;
9e04ccdc 7323 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
7324 aViewName, aDisplayName);
fd3f6bd0 7325
7326 Standard_Real aRatio = anImgRef->Ratio();
7327 Standard_Real aSizeX = 1.0;
7328 Standard_Real aSizeY = aSizeX / aRatio;
692613e5 7329 {
fd3f6bd0 7330 OSD_Path aPath (anImgPathRef);
7331 TCollection_AsciiString aLabelRef;
7332 if (!aPath.Name().IsEmpty())
7333 {
7334 aLabelRef = aPath.Name() + aPath.Extension();
7335 }
7336 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
7337
7338 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
7339 gp_Trsf aTrsfRef;
7340 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
7341 anImgRefPrs->SetLocalTransformation (aTrsfRef);
7342 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
692613e5 7343 }
fd3f6bd0 7344 {
7345 OSD_Path aPath (anImgPathNew);
7346 TCollection_AsciiString aLabelNew;
7347 if (!aPath.Name().IsEmpty())
7348 {
7349 aLabelNew = aPath.Name() + aPath.Extension();
7350 }
7351 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
692613e5 7352
fd3f6bd0 7353 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
7354 gp_Trsf aTrsfRef;
7355 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
7356 anImgNewPrs->SetLocalTransformation (aTrsfRef);
7357 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
7358 }
7359 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
7360 if (!aDiff.IsNull())
7361 {
7362 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
7363 gp_Trsf aTrsfDiff;
7364 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
7365 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
7366 }
7367 if (!aPrsNameDiff.IsEmpty())
7368 {
7369 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
7370 }
7371 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
7372 ViewerTest::CurrentView()->FitAll();
692613e5 7373 return 0;
7374}
7375
4754e164 7376//=======================================================================
7377//function : VSelect
7378//purpose : Emulates different types of selection by mouse:
7379// 1) single click selection
7380// 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
7381// 3) selection with polygon having corners at
dc3fe572 7382// pixel positions (x1,y1),...,(xn,yn)
4754e164 7383// 4) any of these selections with shift button pressed
7384//=======================================================================
49582f9d 7385static Standard_Integer VSelect (Draw_Interpretor& ,
7386 Standard_Integer theNbArgs,
7387 const char** theArgVec)
4754e164 7388{
49582f9d 7389 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7390 if (aCtx.IsNull())
4754e164 7391 {
49582f9d 7392 std::cout << "Error: no active View\n";
4754e164 7393 return 1;
7394 }
2157d6ac 7395
49582f9d 7396 NCollection_Sequence<Graphic3d_Vec2i> aPnts;
7397 bool isShiftSelection = false, toAllowOverlap = false;
7398 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
2157d6ac 7399 {
49582f9d 7400 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7401 anArg.LowerCase();
7402 if (anArg == "-allowoverlap")
7403 {
7404 toAllowOverlap = true;
7405 if (anArgIter + 1 < theNbArgs
7406 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toAllowOverlap))
7407 {
7408 ++anArgIter;
7409 }
7410 }
7411 else if (anArgIter + 1 < theNbArgs
7412 && anArg.IsIntegerValue()
7413 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
2157d6ac 7414 {
49582f9d 7415 const TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
7416 aPnts.Append (Graphic3d_Vec2i (anArg.IntegerValue(), anArgNext.IntegerValue()));
7417 }
7418 else if (anArgIter + 1 == theNbArgs
7419 && anArg.IsIntegerValue())
7420 {
7421 isShiftSelection = anArg.IntegerValue() == 1;
7422 }
7423 else
7424 {
7425 std::cout << "Syntax error at '" << anArg << "'\n";
2157d6ac 7426 return 1;
7427 }
49582f9d 7428 }
7429 if (toAllowOverlap
7430 && aPnts.Length() != 2)
7431 {
7432 std::cout << "Syntax error: -allowoverlap key is applied only for rectangle selection\n";
7433 return 1;
7434 }
7435 if (toAllowOverlap)
7436 {
7437 aCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
2157d6ac 7438 }
7439
4754e164 7440 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
49582f9d 7441 if (aPnts.IsEmpty())
4754e164 7442 {
49582f9d 7443 if (isShiftSelection)
7444 {
7445 aCtx->ShiftSelect (false);
7446 }
4754e164 7447 else
49582f9d 7448 {
7449 aCtx->Select (false);
7450 }
7451 aCtx->CurrentViewer()->Invalidate();
4754e164 7452 }
49582f9d 7453 else if (aPnts.Length() == 2)
4754e164 7454 {
49582f9d 7455 if (toAllowOverlap
7456 && aPnts.First().y() < aPnts.Last().y())
7457 {
7458 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7459 }
7460 else if (!toAllowOverlap
7461 && aPnts.First().y() > aPnts.Last().y())
7462 {
7463 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
7464 }
7465 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
4754e164 7466 }
7467 else
7468 {
49582f9d 7469 aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection);
4754e164 7470 }
49582f9d 7471 aCurrentEventManager->FlushViewEvents (aCtx, ViewerTest::CurrentView(), true);
4754e164 7472 return 0;
7473}
7474
7475//=======================================================================
7476//function : VMoveTo
dc3fe572 7477//purpose : Emulates cursor movement to defined pixel position
4754e164 7478//=======================================================================
1e756cb9 7479static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
8a590580 7480 Standard_Integer theNbArgs,
7481 const char** theArgVec)
4754e164 7482{
8a590580 7483 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
7484 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
7485 if (aContext.IsNull())
4754e164 7486 {
8a590580 7487 std::cout << "Error: no active View\n";
4754e164 7488 return 1;
7489 }
7490
8a590580 7491 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
7492 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4754e164 7493 {
8a590580 7494 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
7495 anArgStr.LowerCase();
7496 if (anArgStr == "-reset"
7497 || anArgStr == "-clear")
7498 {
7499 if (anArgIter + 1 < theNbArgs)
7500 {
7501 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
7502 return 1;
7503 }
7504
7505 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
7506 && aContext->CurrentViewer()->GridEcho();
7507 if (toEchoGrid)
7508 {
7509 aContext->CurrentViewer()->HideGridEcho (aView);
7510 }
7511 if (aContext->ClearDetected() || toEchoGrid)
7512 {
7513 aContext->CurrentViewer()->RedrawImmediate();
7514 }
7515 return 0;
7516 }
7517 else if (aMousePos.x() == IntegerLast()
7518 && anArgStr.IsIntegerValue())
7519 {
7520 aMousePos.x() = anArgStr.IntegerValue();
7521 }
7522 else if (aMousePos.y() == IntegerLast()
7523 && anArgStr.IsIntegerValue())
7524 {
7525 aMousePos.y() = anArgStr.IntegerValue();
7526 }
7527 else
7528 {
7529 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
7530 return 1;
7531 }
7532 }
7533
7534 if (aMousePos.x() == IntegerLast()
7535 || aMousePos.y() == IntegerLast())
7536 {
7537 std::cout << "Syntax error: wrong number of arguments\n";
4754e164 7538 return 1;
7539 }
8a590580 7540
49582f9d 7541 ViewerTest::CurrentEventManager()->ResetPreviousMoveTo();
7542 ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false);
7543 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
7544
1e756cb9 7545 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
7546 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
7547 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
7548 {
7549 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
7550 {
7551 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
7552 break;
7553 }
7554 }
7555 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
4754e164 7556 return 0;
7557}
7558
1beb58d7 7559namespace
7560{
7561 //! Global map storing all animations registered in ViewerTest.
7562 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
7563
7564 //! The animation calling the Draw Harness command.
7565 class ViewerTest_AnimationProc : public AIS_Animation
7566 {
7567 public:
7568
7569 //! Main constructor.
7570 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
7571 Draw_Interpretor* theDI,
7572 const TCollection_AsciiString& theCommand)
7573 : AIS_Animation (theAnimationName),
7574 myDrawInter(theDI),
7575 myCommand (theCommand)
7576 {
7577 //
7578 }
7579
7580 protected:
7581
7582 //! Evaluate the command.
7583 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
7584 {
7585 TCollection_AsciiString aCmd = myCommand;
7586 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
7587 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
7588 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
7589 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
7590 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
7591 myDrawInter->Eval (aCmd.ToCString());
7592 }
7593
7594 //! Find the keyword in the command and replace it with value.
7595 //! @return the position of the keyword to pass value
7596 void replace (TCollection_AsciiString& theCmd,
7597 const TCollection_AsciiString& theKey,
7598 const TCollection_AsciiString& theVal)
7599 {
7600 TCollection_AsciiString aCmd (theCmd);
7601 aCmd.LowerCase();
7602 const Standard_Integer aPos = aCmd.Search (theKey);
7603 if (aPos == -1)
7604 {
7605 return;
7606 }
7607
7608 TCollection_AsciiString aPart1, aPart2;
7609 Standard_Integer aPart1To = aPos - 1;
7610 if (aPart1To >= 1
7611 && aPart1To <= theCmd.Length())
7612 {
7613 aPart1 = theCmd.SubString (1, aPart1To);
7614 }
7615
7616 Standard_Integer aPart2From = aPos + theKey.Length();
7617 if (aPart2From >= 1
7618 && aPart2From <= theCmd.Length())
7619 {
7620 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
7621 }
7622
7623 theCmd = aPart1 + theVal + aPart2;
7624 }
7625
7626 protected:
7627
7628 Draw_Interpretor* myDrawInter;
7629 TCollection_AsciiString myCommand;
7630
7631 };
7632
7633 //! Replace the animation with the new one.
7634 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
7635 Handle(AIS_Animation)& theAnimation,
7636 const Handle(AIS_Animation)& theAnimationNew)
7637 {
7638 theAnimationNew->CopyFrom (theAnimation);
7639 if (!theParentAnimation.IsNull())
7640 {
7641 theParentAnimation->Replace (theAnimation, theAnimationNew);
7642 }
7643 else
7644 {
7645 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
7646 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
7647 }
7648 theAnimation = theAnimationNew;
7649 }
7650
7651 //! Parse the point.
7652 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
7653 {
7654 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
7655 if (!anXYZ[0].IsRealValue()
7656 || !anXYZ[1].IsRealValue()
7657 || !anXYZ[2].IsRealValue())
7658 {
7659 return Standard_False;
7660 }
7661
7662 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
7663 return Standard_True;
7664 }
7665
7666 //! Parse the quaternion.
7667 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
7668 {
7669 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
7670 if (!anXYZW[0].IsRealValue()
7671 || !anXYZW[1].IsRealValue()
7672 || !anXYZW[2].IsRealValue()
7673 || !anXYZW[3].IsRealValue())
7674 {
7675 return Standard_False;
7676 }
7677
7678 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
7679 return Standard_True;
7680 }
7681
08f8a185 7682 //! Auxiliary class for flipping image upside-down.
7683 class ImageFlipper
7684 {
7685 public:
7686
7687 //! Empty constructor.
7688 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
7689
7690 //! Perform flipping.
7691 Standard_Boolean FlipY (Image_PixMap& theImage)
7692 {
7693 if (theImage.IsEmpty()
7694 || theImage.SizeX() == 0
7695 || theImage.SizeY() == 0)
7696 {
7697 return Standard_False;
7698 }
7699
7700 const Standard_Size aRowSize = theImage.SizeRowBytes();
7701 if (myTmp.Size() < aRowSize
7702 && !myTmp.Allocate (aRowSize))
7703 {
7704 return Standard_False;
7705 }
7706
7707 // for odd height middle row should be left as is
7708 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
7709 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
7710 {
7711 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
7712 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
7713 memcpy (myTmp.ChangeData(), aTop, aRowSize);
7714 memcpy (aTop, aBot, aRowSize);
7715 memcpy (aBot, myTmp.Data(), aRowSize);
7716 }
7717 return Standard_True;
7718 }
7719
7720 private:
7721 NCollection_Buffer myTmp;
7722 };
7723
1beb58d7 7724}
7725
197ac94e 7726//=================================================================================================
4754e164 7727//function : VViewParams
dc3fe572 7728//purpose : Gets or sets AIS View characteristics
197ac94e 7729//=================================================================================================
7730static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4754e164 7731{
1beb58d7 7732 Handle(V3d_View) aView = ViewerTest::CurrentView();
7733 if (aView.IsNull())
4754e164 7734 {
197ac94e 7735 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
4754e164 7736 return 1;
7737 }
197ac94e 7738
1beb58d7 7739 Standard_Boolean toSetProj = Standard_False;
7740 Standard_Boolean toSetUp = Standard_False;
7741 Standard_Boolean toSetAt = Standard_False;
7742 Standard_Boolean toSetEye = Standard_False;
7743 Standard_Boolean toSetScale = Standard_False;
7744 Standard_Boolean toSetSize = Standard_False;
7745 Standard_Boolean toSetCenter2d = Standard_False;
ee2be2a8 7746 Standard_Real aViewScale = aView->Scale();
7747 Standard_Real aViewSize = 1.0;
1beb58d7 7748 Graphic3d_Vec2i aCenter2d;
7749 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
7750 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
7751 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
7752 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
7753 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
197ac94e 7754 if (theArgsNb == 1)
4754e164 7755 {
197ac94e 7756 // print all of the available view parameters
1beb58d7 7757 char aText[4096];
7758 Sprintf (aText,
7759 "Scale: %g\n"
7760 "Proj: %12g %12g %12g\n"
7761 "Up: %12g %12g %12g\n"
7762 "At: %12g %12g %12g\n"
7763 "Eye: %12g %12g %12g\n",
7764 aViewScale,
7765 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7766 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7767 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
7768 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7769 theDi << aText;
197ac94e 7770 return 0;
4754e164 7771 }
197ac94e 7772
1beb58d7 7773 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7774 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
197ac94e 7775 {
1beb58d7 7776 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7777 anArg.LowerCase();
7778 if (anUpdateTool.parseRedrawMode (anArg))
197ac94e 7779 {
197ac94e 7780 continue;
7781 }
1beb58d7 7782 else if (anArg == "-cmd"
7783 || anArg == "-command"
7784 || anArg == "-args")
7785 {
7786 char aText[4096];
7787 Sprintf (aText,
7788 "-scale %g "
7789 "-proj %g %g %g "
7790 "-up %g %g %g "
7791 "-at %g %g %g\n",
7792 aViewScale,
7793 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7794 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7795 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7796 theDi << aText;
7797 }
7798 else if (anArg == "-scale"
7799 || anArg == "-size")
7800 {
7801 if (anArgIter + 1 < theArgsNb
7802 && *theArgVec[anArgIter + 1] != '-')
7803 {
7804 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
7805 if (aValueArg.IsRealValue())
7806 {
7807 ++anArgIter;
7808 if (anArg == "-scale")
7809 {
7810 toSetScale = Standard_True;
7811 aViewScale = aValueArg.RealValue();
7812 }
7813 else if (anArg == "-size")
7814 {
7815 toSetSize = Standard_True;
7816 aViewSize = aValueArg.RealValue();
7817 }
7818 continue;
7819 }
7820 }
7821 if (anArg == "-scale")
7822 {
7823 theDi << "Scale: " << aView->Scale() << "\n";
7824 }
7825 else if (anArg == "-size")
7826 {
7827 Graphic3d_Vec2d aSizeXY;
7828 aView->Size (aSizeXY.x(), aSizeXY.y());
7829 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
7830 }
7831 }
7832 else if (anArg == "-eye"
7833 || anArg == "-at"
7834 || anArg == "-up"
7835 || anArg == "-proj")
7836 {
7837 if (anArgIter + 3 < theArgsNb)
7838 {
7839 gp_XYZ anXYZ;
7840 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
7841 {
7842 anArgIter += 3;
7843 if (anArg == "-eye")
7844 {
7845 toSetEye = Standard_True;
7846 aViewEye = anXYZ;
7847 }
7848 else if (anArg == "-at")
7849 {
7850 toSetAt = Standard_True;
7851 aViewAt = anXYZ;
7852 }
7853 else if (anArg == "-up")
7854 {
7855 toSetUp = Standard_True;
7856 aViewUp = anXYZ;
7857 }
7858 else if (anArg == "-proj")
7859 {
7860 toSetProj = Standard_True;
7861 aViewProj = anXYZ;
7862 }
7863 continue;
7864 }
7865 }
197ac94e 7866
1beb58d7 7867 if (anArg == "-eye")
7868 {
7869 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
7870 }
7871 else if (anArg == "-at")
7872 {
7873 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
7874 }
7875 else if (anArg == "-up")
7876 {
7877 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
7878 }
7879 else if (anArg == "-proj")
7880 {
7881 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
7882 }
7883 }
7884 else if (anArg == "-center")
3dfe95cd 7885 {
1beb58d7 7886 if (anArgIter + 2 < theArgsNb)
7887 {
7888 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
7889 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
7890 if (anX.IsIntegerValue()
7891 && anY.IsIntegerValue())
7892 {
7893 toSetCenter2d = Standard_True;
7894 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
7895 }
7896 }
7897 }
7898 else
7899 {
7900 std::cout << "Syntax error at '" << anArg << "'\n";
3dfe95cd 7901 return 1;
7902 }
1beb58d7 7903 }
3dfe95cd 7904
1beb58d7 7905 // change view parameters in proper order
7906 if (toSetScale)
7907 {
7908 aView->SetScale (aViewScale);
7909 }
7910 if (toSetSize)
7911 {
7912 aView->SetSize (aViewSize);
7913 }
7914 if (toSetEye)
7915 {
7916 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7917 }
7918 if (toSetAt)
7919 {
7920 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7921 }
7922 if (toSetProj)
7923 {
7924 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
7925 }
7926 if (toSetUp)
7927 {
7928 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
7929 }
7930 if (toSetCenter2d)
7931 {
7932 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
197ac94e 7933 }
7934
1beb58d7 7935 return 0;
7936}
197ac94e 7937
2e93433e 7938//==============================================================================
7939//function : V2DMode
7940//purpose :
7941//==============================================================================
7942static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
7943{
7944 bool is2dMode = true;
7945 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
7946 if (aV3dView.IsNull())
7947 {
7948 std::cout << "Error: no active view.\n";
7949 return 1;
7950 }
7951 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7952 {
7953 const TCollection_AsciiString anArg = theArgVec[anArgIt];
7954 TCollection_AsciiString anArgCase = anArg;
7955 anArgCase.LowerCase();
7956 if (anArgIt + 1 < theArgsNb
7957 && anArgCase == "-name")
7958 {
7959 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
7960 TCollection_AsciiString aViewName = aViewNames.GetViewName();
7961 if (!ViewerTest_myViews.IsBound1 (aViewName))
7962 {
7963 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
7964 return 1;
7965 }
7966 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
7967 }
7968 else if (anArgCase == "-mode")
7969 {
7970 if (anArgIt + 1 < theArgsNb
7971 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
7972 {
7973 ++anArgIt;
7974 }
7975 }
7976 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
7977 {
7978 //
7979 }
7980 else
7981 {
7982 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
7983 return 1;
7984 }
7985 }
7986
7987 aV3dView->SetView2DMode (is2dMode);
7988 return 0;
7989}
7990
1beb58d7 7991//==============================================================================
7992//function : VAnimation
7993//purpose :
7994//==============================================================================
7995static Standard_Integer VAnimation (Draw_Interpretor& theDI,
7996 Standard_Integer theArgNb,
7997 const char** theArgVec)
7998{
7999 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
8000 if (theArgNb < 2)
4754e164 8001 {
1beb58d7 8002 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
8003 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
8004 {
8005 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
197ac94e 8006 }
1beb58d7 8007 return 0;
8008 }
8009 if (aCtx.IsNull())
8010 {
8011 std::cout << "Error: no active view\n";
8012 return 1;
4754e164 8013 }
197ac94e 8014
1beb58d7 8015 Standard_Integer anArgIter = 1;
8016 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
8017 if (aNameArg.IsEmpty())
8018 {
8019 std::cout << "Syntax error: animation name is not defined.\n";
8020 return 1;
8021 }
8022
8023 TCollection_AsciiString aNameArgLower = aNameArg;
8024 aNameArgLower.LowerCase();
8025 if (aNameArgLower == "-reset"
8026 || aNameArgLower == "-clear")
8027 {
8028 ViewerTest_AnimationTimelineMap.Clear();
8029 return 0;
8030 }
8031 else if (aNameArg.Value (1) == '-')
8032 {
8033 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
8034 return 1;
8035 }
197ac94e 8036
1beb58d7 8037 const char* aNameSplitter = "/";
8038 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
8039 if (aSplitPos == -1)
197ac94e 8040 {
1beb58d7 8041 aNameSplitter = ".";
8042 aSplitPos = aNameArg.Search (aNameSplitter);
8043 }
8044
8045 // find existing or create a new animation by specified name within syntax "parent.child".
8046 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
8047 for (; !aNameArg.IsEmpty();)
8048 {
8049 TCollection_AsciiString aNameParent;
8050 if (aSplitPos != -1)
197ac94e 8051 {
1beb58d7 8052 if (aSplitPos == aNameArg.Length())
8053 {
8054 std::cout << "Syntax error: animation name is not defined.\n";
8055 return 1;
8056 }
8057
8058 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
8059 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
8060
8061 aSplitPos = aNameArg.Search (aNameSplitter);
197ac94e 8062 }
8063 else
8064 {
1beb58d7 8065 aNameParent = aNameArg;
8066 aNameArg.Clear();
197ac94e 8067 }
1beb58d7 8068
8069 if (anAnimation.IsNull())
3dfe95cd 8070 {
1beb58d7 8071 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
8072 {
8073 anAnimation = new AIS_Animation (aNameParent);
8074 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
8075 }
8076 aRootAnimation = anAnimation;
3dfe95cd 8077 }
8078 else
8079 {
1beb58d7 8080 aParentAnimation = anAnimation;
8081 anAnimation = aParentAnimation->Find (aNameParent);
8082 if (anAnimation.IsNull())
8083 {
8084 anAnimation = new AIS_Animation (aNameParent);
8085 aParentAnimation->Add (anAnimation);
8086 }
3dfe95cd 8087 }
8088 }
1beb58d7 8089
8090 if (anArgIter >= theArgNb)
197ac94e 8091 {
1beb58d7 8092 // just print the list of children
8093 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
197ac94e 8094 {
1beb58d7 8095 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
197ac94e 8096 }
1beb58d7 8097 return 0;
197ac94e 8098 }
1beb58d7 8099
bf7b2ceb 8100 // animation parameters
1beb58d7 8101 Standard_Boolean toPlay = Standard_False;
8102 Standard_Real aPlaySpeed = 1.0;
8103 Standard_Real aPlayStartTime = anAnimation->StartPts();
8104 Standard_Real aPlayDuration = anAnimation->Duration();
1beb58d7 8105 Standard_Boolean isFreeCamera = Standard_False;
8106 Standard_Boolean isLockLoop = Standard_False;
08f8a185 8107
8108 // video recording parameters
8109 TCollection_AsciiString aRecFile;
8110 Image_VideoParams aRecParams;
8111
1beb58d7 8112 Handle(V3d_View) aView = ViewerTest::CurrentView();
8113 for (; anArgIter < theArgNb; ++anArgIter)
197ac94e 8114 {
1beb58d7 8115 TCollection_AsciiString anArg (theArgVec[anArgIter]);
8116 anArg.LowerCase();
bf7b2ceb 8117 // general options
1beb58d7 8118 if (anArg == "-reset"
8119 || anArg == "-clear")
197ac94e 8120 {
1beb58d7 8121 anAnimation->Clear();
8122 }
8123 else if (anArg == "-remove"
8124 || anArg == "-del"
8125 || anArg == "-delete")
8126 {
8127 if (!aParentAnimation.IsNull())
8128 {
8129 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
8130 }
8131 else
8132 {
8133 aParentAnimation->Remove (anAnimation);
8134 }
8135 }
bf7b2ceb 8136 // playback options
1beb58d7 8137 else if (anArg == "-play")
8138 {
8139 toPlay = Standard_True;
8140 if (++anArgIter < theArgNb)
8141 {
8142 if (*theArgVec[anArgIter] == '-')
8143 {
8144 --anArgIter;
8145 continue;
8146 }
8147 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
8148
8149 if (++anArgIter < theArgNb)
8150 {
8151 if (*theArgVec[anArgIter] == '-')
8152 {
8153 --anArgIter;
8154 continue;
8155 }
8156 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8157 }
8158 }
8159 }
8160 else if (anArg == "-resume")
8161 {
8162 toPlay = Standard_True;
8163 aPlayStartTime = anAnimation->ElapsedTime();
8164 if (++anArgIter < theArgNb)
8165 {
8166 if (*theArgVec[anArgIter] == '-')
8167 {
8168 --anArgIter;
8169 continue;
8170 }
8171
8172 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
8173 }
8174 }
8175 else if (anArg == "-playspeed"
8176 || anArg == "-speed")
8177 {
8178 if (++anArgIter >= theArgNb)
8179 {
8180 std::cout << "Syntax error at " << anArg << ".\n";
8181 return 1;
8182 }
8183 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
8184 }
8185 else if (anArg == "-lock"
8186 || anArg == "-lockloop"
8187 || anArg == "-playlockloop")
8188 {
8189 isLockLoop = Standard_True;
8190 }
8191 else if (anArg == "-freecamera"
8192 || anArg == "-playfreecamera"
8193 || anArg == "-freelook")
8194 {
8195 isFreeCamera = Standard_True;
8196 }
08f8a185 8197 // video recodring options
8198 else if (anArg == "-rec"
8199 || anArg == "-record")
8200 {
8201 if (++anArgIter >= theArgNb)
8202 {
8203 std::cout << "Syntax error at " << anArg << ".\n";
8204 return 1;
8205 }
8206
8207 aRecFile = theArgVec[anArgIter];
8208 if (aRecParams.FpsNum <= 0)
8209 {
8210 aRecParams.FpsNum = 24;
8211 }
8212
8213 if (anArgIter + 2 < theArgNb
8214 && *theArgVec[anArgIter + 1] != '-'
8215 && *theArgVec[anArgIter + 2] != '-')
8216 {
8217 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
8218 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
8219 if (aWidthArg .IsIntegerValue()
8220 && aHeightArg.IsIntegerValue())
8221 {
8222 aRecParams.Width = aWidthArg .IntegerValue();
8223 aRecParams.Height = aHeightArg.IntegerValue();
8224 anArgIter += 2;
8225 }
8226 }
8227 }
1beb58d7 8228 else if (anArg == "-fps")
8229 {
8230 if (++anArgIter >= theArgNb)
8231 {
8232 std::cout << "Syntax error at " << anArg << ".\n";
8233 return 1;
8234 }
bf7b2ceb 8235
8236 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
8237 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
8238 if (aSplitIndex == 0)
8239 {
08f8a185 8240 aRecParams.FpsNum = aFpsArg.IntegerValue();
bf7b2ceb 8241 }
8242 else
8243 {
8244 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
8245 aFpsArg.Split (aFpsArg.Length() - 1);
8246 const TCollection_AsciiString aNumStr = aFpsArg;
08f8a185 8247 aRecParams.FpsNum = aNumStr.IntegerValue();
8248 aRecParams.FpsDen = aDenStr.IntegerValue();
8249 if (aRecParams.FpsDen < 1)
bf7b2ceb 8250 {
8251 std::cout << "Syntax error at " << anArg << ".\n";
8252 return 1;
8253 }
8254 }
1beb58d7 8255 }
08f8a185 8256 else if (anArg == "-format")
8257 {
8258 if (++anArgIter >= theArgNb)
8259 {
8260 std::cout << "Syntax error at " << anArg << ".\n";
8261 return 1;
8262 }
8263 aRecParams.Format = theArgVec[anArgIter];
8264 }
8265 else if (anArg == "-pix_fmt"
8266 || anArg == "-pixfmt"
8267 || anArg == "-pixelformat")
8268 {
8269 if (++anArgIter >= theArgNb)
8270 {
8271 std::cout << "Syntax error at " << anArg << ".\n";
8272 return 1;
8273 }
8274 aRecParams.PixelFormat = theArgVec[anArgIter];
8275 }
8276 else if (anArg == "-codec"
8277 || anArg == "-vcodec"
8278 || anArg == "-videocodec")
8279 {
8280 if (++anArgIter >= theArgNb)
8281 {
8282 std::cout << "Syntax error at " << anArg << ".\n";
8283 return 1;
8284 }
8285 aRecParams.VideoCodec = theArgVec[anArgIter];
8286 }
8287 else if (anArg == "-crf"
8288 || anArg == "-preset"
8289 || anArg == "-qp")
8290 {
8291 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
8292 if (++anArgIter >= theArgNb)
8293 {
8294 std::cout << "Syntax error at " << anArg << ".\n";
8295 return 1;
8296 }
8297
8298 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
8299 }
bf7b2ceb 8300 // animation definition options
1beb58d7 8301 else if (anArg == "-start"
8302 || anArg == "-starttime"
8303 || anArg == "-startpts")
8304 {
8305 if (++anArgIter >= theArgNb)
8306 {
8307 std::cout << "Syntax error at " << anArg << ".\n";
8308 return 1;
8309 }
8310
8311 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
8312 aRootAnimation->UpdateTotalDuration();
8313 }
8314 else if (anArg == "-end"
8315 || anArg == "-endtime"
8316 || anArg == "-endpts")
8317 {
8318 if (++anArgIter >= theArgNb)
8319 {
8320 std::cout << "Syntax error at " << anArg << ".\n";
8321 return 1;
8322 }
8323
8324 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
8325 aRootAnimation->UpdateTotalDuration();
8326 }
8327 else if (anArg == "-dur"
8328 || anArg == "-duration")
8329 {
8330 if (++anArgIter >= theArgNb)
8331 {
8332 std::cout << "Syntax error at " << anArg << ".\n";
8333 return 1;
8334 }
8335
8336 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
8337 aRootAnimation->UpdateTotalDuration();
8338 }
8339 else if (anArg == "-command"
8340 || anArg == "-cmd"
8341 || anArg == "-invoke"
8342 || anArg == "-eval"
8343 || anArg == "-proc")
8344 {
8345 if (++anArgIter >= theArgNb)
8346 {
8347 std::cout << "Syntax error at " << anArg << ".\n";
8348 return 1;
8349 }
8350
8351 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
8352 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
8353 }
8354 else if (anArg == "-objecttrsf"
8355 || anArg == "-objectransformation"
8356 || anArg == "-objtransformation"
8357 || anArg == "-objtrsf"
8358 || anArg == "-object"
8359 || anArg == "-obj")
8360 {
8361 if (++anArgIter >= theArgNb)
8362 {
8363 std::cout << "Syntax error at " << anArg << ".\n";
8364 return 1;
8365 }
8366
8367 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
8368 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
8f521168 8369 Handle(AIS_InteractiveObject) anObject;
8370 if (!aMapOfAIS.Find2 (anObjName, anObject))
1beb58d7 8371 {
8372 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
8373 return 1;
8374 }
8375
1beb58d7 8376 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
8377 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
8378 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
8379 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
8380 Standard_Boolean isTrsfSet = Standard_False;
8381 Standard_Integer aTrsfArgIter = anArgIter + 1;
8382 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
8383 {
8384 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
8385 aTrsfArg.LowerCase();
8386 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
8387 if (aTrsfArg.StartsWith ("-rotation")
8388 || aTrsfArg.StartsWith ("-rot"))
8389 {
8390 isTrsfSet = Standard_True;
8391 if (aTrsfArgIter + 4 >= theArgNb
8392 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
8393 {
8394 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8395 return 1;
8396 }
8397 aTrsfArgIter += 4;
8398 }
8399 else if (aTrsfArg.StartsWith ("-location")
8400 || aTrsfArg.StartsWith ("-loc"))
8401 {
8402 isTrsfSet = Standard_True;
8403 if (aTrsfArgIter + 3 >= theArgNb
8404 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
8405 {
8406 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8407 return 1;
8408 }
8409 aTrsfArgIter += 3;
8410 }
8411 else if (aTrsfArg.StartsWith ("-scale"))
8412 {
8413 isTrsfSet = Standard_True;
8414 if (++aTrsfArgIter >= theArgNb)
8415 {
8416 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8417 return 1;
8418 }
8419
8420 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
8421 if (!aScaleStr.IsRealValue())
8422 {
8423 std::cout << "Syntax error at " << aTrsfArg << ".\n";
8424 return 1;
8425 }
8426 aScales[anIndex] = aScaleStr.RealValue();
8427 }
8428 else
8429 {
8430 anArgIter = aTrsfArgIter - 1;
8431 break;
8432 }
8433 }
8434 if (!isTrsfSet)
8435 {
8436 std::cout << "Syntax error at " << anArg << ".\n";
8437 return 1;
8438 }
8439 else if (aTrsfArgIter >= theArgNb)
8440 {
8441 anArgIter = theArgNb;
8442 }
8443
8444 aTrsfs[0].SetRotation (aRotQuats[0]);
8445 aTrsfs[1].SetRotation (aRotQuats[1]);
8446 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
8447 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
8448 aTrsfs[0].SetScaleFactor (aScales[0]);
8449 aTrsfs[1].SetScaleFactor (aScales[1]);
8450
8451 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
8452 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
8453 }
8454 else if (anArg == "-viewtrsf"
8455 || anArg == "-view")
8456 {
8457 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
8458 if (aCamAnimation.IsNull())
8459 {
8460 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
8461 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
8462 }
8463
8464 Handle(Graphic3d_Camera) aCams[2] =
8465 {
8466 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
8467 new Graphic3d_Camera (aCamAnimation->View()->Camera())
8468 };
8469
8470 Standard_Boolean isTrsfSet = Standard_False;
8471 Standard_Integer aViewArgIter = anArgIter + 1;
8472 for (; aViewArgIter < theArgNb; ++aViewArgIter)
8473 {
8474 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
8475 aViewArg.LowerCase();
8476 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
8477 if (aViewArg.StartsWith ("-scale"))
8478 {
8479 isTrsfSet = Standard_True;
8480 if (++aViewArgIter >= theArgNb)
8481 {
8482 std::cout << "Syntax error at " << anArg << ".\n";
8483 return 1;
8484 }
8485
8486 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
8487 if (!aScaleStr.IsRealValue())
8488 {
8489 std::cout << "Syntax error at " << aViewArg << ".\n";
8490 return 1;
8491 }
8492 Standard_Real aScale = aScaleStr.RealValue();
8493 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
8494 aCams[anIndex]->SetScale (aScale);
8495 }
8496 else if (aViewArg.StartsWith ("-eye")
8497 || aViewArg.StartsWith ("-center")
8498 || aViewArg.StartsWith ("-at")
8499 || aViewArg.StartsWith ("-up"))
8500 {
8501 isTrsfSet = Standard_True;
8502 gp_XYZ anXYZ;
8503 if (aViewArgIter + 3 >= theArgNb
8504 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
8505 {
8506 std::cout << "Syntax error at " << aViewArg << ".\n";
8507 return 1;
8508 }
8509 aViewArgIter += 3;
8510
8511 if (aViewArg.StartsWith ("-eye"))
8512 {
8513 aCams[anIndex]->SetEye (anXYZ);
8514 }
8515 else if (aViewArg.StartsWith ("-center")
8516 || aViewArg.StartsWith ("-at"))
8517 {
8518 aCams[anIndex]->SetCenter (anXYZ);
8519 }
8520 else if (aViewArg.StartsWith ("-up"))
8521 {
8522 aCams[anIndex]->SetUp (anXYZ);
8523 }
8524 }
8525 else
8526 {
8527 anArgIter = aViewArgIter - 1;
8528 break;
8529 }
8530 }
8531 if (!isTrsfSet)
8532 {
8533 std::cout << "Syntax error at " << anArg << ".\n";
8534 return 1;
8535 }
8536 else if (aViewArgIter >= theArgNb)
8537 {
8538 anArgIter = theArgNb;
8539 }
8540
8541 aCamAnimation->SetCameraStart(aCams[0]);
8542 aCamAnimation->SetCameraEnd (aCams[1]);
197ac94e 8543 }
8544 else
8545 {
1beb58d7 8546 std::cout << "Syntax error at " << anArg << ".\n";
8547 return 1;
197ac94e 8548 }
8549 }
1beb58d7 8550
08f8a185 8551 if (!toPlay && aRecFile.IsEmpty())
197ac94e 8552 {
1beb58d7 8553 return 0;
8554 }
8555
8556 // Start animation timeline and process frame updating.
8557 TheIsAnimating = Standard_True;
8558 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
8559 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
bf7b2ceb 8560 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
1beb58d7 8561 if (isFreeCamera)
8562 {
8563 aView->Camera()->Copy (aCameraBack);
8564 }
8565
8566 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
08f8a185 8567 if (aRecParams.FpsNum <= 0)
1beb58d7 8568 {
8569 while (!anAnimation->IsStopped())
197ac94e 8570 {
1beb58d7 8571 aCameraBack->Copy (aView->Camera());
8572 const Standard_Real aPts = anAnimation->UpdateTimer();
8573 if (isFreeCamera)
8574 {
8575 aView->Camera()->Copy (aCameraBack);
8576 }
8577
8578 if (aPts >= anUpperPts)
8579 {
8580 anAnimation->Pause();
8581 break;
8582 }
8583
8584 if (aView->IsInvalidated())
8585 {
8586 aView->Redraw();
8587 }
8588 else
8589 {
8590 aView->RedrawImmediate();
8591 }
8592
8593 if (!isLockLoop)
8594 {
8595 // handle user events
8596 theDI.Eval ("after 1 set waiter 1");
8597 theDI.Eval ("vwait waiter");
8598 }
8599 if (!TheIsAnimating)
8600 {
8601 anAnimation->Pause();
8602 theDI << aPts;
8603 break;
8604 }
8605 }
8606
8607 if (aView->IsInvalidated())
8608 {
8609 aView->Redraw();
197ac94e 8610 }
8611 else
8612 {
1beb58d7 8613 aView->RedrawImmediate();
197ac94e 8614 }
8615 }
1beb58d7 8616 else
197ac94e 8617 {
bf7b2ceb 8618 OSD_Timer aPerfTimer;
8619 aPerfTimer.Start();
1beb58d7 8620
08f8a185 8621 Handle(Image_VideoRecorder) aRecorder;
8622 ImageFlipper aFlipper;
8623 Handle(Draw_ProgressIndicator) aProgress;
8624 if (!aRecFile.IsEmpty())
8625 {
8626 if (aRecParams.Width <= 0
8627 || aRecParams.Height <= 0)
8628 {
8629 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
8630 }
8631
8632 aRecorder = new Image_VideoRecorder();
8633 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
8634 {
8635 std::cout << "Error: failed to open video file for recording\n";
8636 return 0;
8637 }
8638
8639 aProgress = new Draw_ProgressIndicator (theDI, 1);
8640 }
8641
1beb58d7 8642 // Manage frame-rated animation here
8643 Standard_Real aPts = aPlayStartTime;
bf7b2ceb 8644 int64_t aNbFrames = 0;
08f8a185 8645 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
8646 Standard_Integer aSecondsProgress = 0;
8647 for (; aPts <= anUpperPts && aPSentry.More();)
197ac94e 8648 {
08f8a185 8649 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
bf7b2ceb 8650 aPts = aPlayStartTime + aRecPts;
8651 ++aNbFrames;
1beb58d7 8652 if (!anAnimation->Update (aPts))
8653 {
8654 break;
8655 }
8656
08f8a185 8657 if (!aRecorder.IsNull())
8658 {
8659 V3d_ImageDumpOptions aDumpParams;
8660 aDumpParams.Width = aRecParams.Width;
8661 aDumpParams.Height = aRecParams.Height;
8662 aDumpParams.BufferType = Graphic3d_BT_RGBA;
8663 aDumpParams.StereoOptions = V3d_SDO_MONO;
8664 aDumpParams.ToAdjustAspect = Standard_True;
8665 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
8666 {
8667 std::cout << "Error: view dump is failed!\n";
8668 return 0;
8669 }
8670 aFlipper.FlipY (aRecorder->ChangeFrame());
8671 if (!aRecorder->PushFrame())
8672 {
8673 return 0;
8674 }
8675 }
8676 else
8677 {
8678 aView->Redraw();
8679 }
8680
8681 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
8682 {
8683 aPSentry.Next();
8684 ++aSecondsProgress;
8685 }
197ac94e 8686 }
bf7b2ceb 8687
8688 aPerfTimer.Stop();
1beb58d7 8689 anAnimation->Stop();
bf7b2ceb 8690 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
8691 theDI << "Average FPS: " << aRecFps << "\n"
8692 << "Nb. Frames: " << Standard_Real(aNbFrames);
8693
8694 aView->Redraw();
197ac94e 8695 }
8696
1beb58d7 8697 aView->SetImmediateUpdate (wasImmediateUpdate);
8698 TheIsAnimating = Standard_False;
4754e164 8699 return 0;
8700}
8701
1beb58d7 8702
4754e164 8703//=======================================================================
8704//function : VChangeSelected
dc3fe572 8705//purpose : Adds the shape to selection or remove one from it
4754e164 8706//=======================================================================
8707static Standard_Integer VChangeSelected (Draw_Interpretor& di,
8708 Standard_Integer argc,
8709 const char ** argv)
8710{
8711 if(argc != 2)
8712 {
8713 di<<"Usage : " << argv[0] << " shape \n";
8714 return 1;
8715 }
8716 //get AIS_Shape:
4754e164 8717 TCollection_AsciiString aName(argv[1]);
8718 Handle(AIS_InteractiveObject) anAISObject;
8f521168 8719 if (!GetMapOfAIS().Find2 (aName, anAISObject)
8720 || anAISObject.IsNull())
4754e164 8721 {
8722 di<<"Use 'vdisplay' before";
8723 return 1;
8724 }
4754e164 8725
8f521168 8726 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
4754e164 8727 return 0;
8728}
8729
4754e164 8730//=======================================================================
8731//function : VNbSelected
dc3fe572 8732//purpose : Returns number of selected objects
4754e164 8733//=======================================================================
8734static Standard_Integer VNbSelected (Draw_Interpretor& di,
8735 Standard_Integer argc,
8736 const char ** argv)
8737{
8738 if(argc != 1)
8739 {
8740 di << "Usage : " << argv[0] << "\n";
8741 return 1;
8742 }
8743 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8744 if(aContext.IsNull())
8745 {
8746 di << "use 'vinit' command before " << argv[0] << "\n";
8747 return 1;
8748 }
8749 di << aContext->NbSelected() << "\n";
8750 return 0;
8751}
8752
4754e164 8753//=======================================================================
8754//function : VPurgeDisplay
dc3fe572 8755//purpose : Switches altialiasing on or off
4754e164 8756//=======================================================================
8757static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
8758 Standard_Integer argc,
8759 const char ** argv)
8760{
eb4320f2 8761 if (argc > 1)
4754e164 8762 {
eb4320f2 8763 di << "Usage : " << argv[0] << "\n";
4754e164 8764 return 1;
8765 }
4754e164 8766 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8767 if (aContext.IsNull())
8768 {
8769 di << "use 'vinit' command before " << argv[0] << "\n";
8770 return 1;
8771 }
404c8936 8772
eb4320f2 8773 di << aContext->PurgeDisplay() << "\n";
4754e164 8774 return 0;
8775}
8776
8777//=======================================================================
8778//function : VSetViewSize
8779//purpose :
8780//=======================================================================
8781static Standard_Integer VSetViewSize (Draw_Interpretor& di,
8782 Standard_Integer argc,
8783 const char ** argv)
8784{
8785 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8786 if(aContext.IsNull())
8787 {
8788 di << "use 'vinit' command before " << argv[0] << "\n";
8789 return 1;
8790 }
8791 if(argc != 2)
8792 {
8793 di<<"Usage : " << argv[0] << " Size\n";
8794 return 1;
8795 }
6b62b2da 8796 Standard_Real aSize = Draw::Atof (argv[1]);
4754e164 8797 if (aSize <= 0.)
8798 {
8799 di<<"Bad Size value : " << aSize << "\n";
8800 return 1;
8801 }
8802
8803 Handle(V3d_View) aView = ViewerTest::CurrentView();
8804 aView->SetSize(aSize);
8805 return 0;
8806}
8807
8808//=======================================================================
8809//function : VMoveView
8810//purpose :
8811//=======================================================================
8812static Standard_Integer VMoveView (Draw_Interpretor& di,
8813 Standard_Integer argc,
8814 const char ** argv)
8815{
8816 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8817 if(aContext.IsNull())
8818 {
8819 di << "use 'vinit' command before " << argv[0] << "\n";
8820 return 1;
8821 }
8822 if(argc < 4 || argc > 5)
8823 {
8824 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8825 return 1;
8826 }
6b62b2da 8827 Standard_Real Dx = Draw::Atof (argv[1]);
8828 Standard_Real Dy = Draw::Atof (argv[2]);
8829 Standard_Real Dz = Draw::Atof (argv[3]);
4754e164 8830 Standard_Boolean aStart = Standard_True;
8831 if (argc == 5)
8832 {
6b62b2da 8833 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 8834 }
8835
8836 Handle(V3d_View) aView = ViewerTest::CurrentView();
8837 aView->Move(Dx,Dy,Dz,aStart);
8838 return 0;
8839}
8840
8841//=======================================================================
8842//function : VTranslateView
8843//purpose :
8844//=======================================================================
8845static Standard_Integer VTranslateView (Draw_Interpretor& di,
8846 Standard_Integer argc,
8847 const char ** argv)
8848{
8849 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8850 if(aContext.IsNull())
8851 {
8852 di << "use 'vinit' command before " << argv[0] << "\n";
8853 return 1;
8854 }
8855 if(argc < 4 || argc > 5)
8856 {
8857 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8858 return 1;
8859 }
6b62b2da 8860 Standard_Real Dx = Draw::Atof (argv[1]);
8861 Standard_Real Dy = Draw::Atof (argv[2]);
8862 Standard_Real Dz = Draw::Atof (argv[3]);
4754e164 8863 Standard_Boolean aStart = Standard_True;
dc3fe572 8864 if (argc == 5)
4754e164 8865 {
6b62b2da 8866 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 8867 }
8868
8869 Handle(V3d_View) aView = ViewerTest::CurrentView();
8870 aView->Translate(Dx,Dy,Dz,aStart);
8871 return 0;
8872}
8873
8874//=======================================================================
8875//function : VTurnView
8876//purpose :
8877//=======================================================================
8878static Standard_Integer VTurnView (Draw_Interpretor& di,
8879 Standard_Integer argc,
8880 const char ** argv)
8881{
8882 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8883 if(aContext.IsNull()) {
8884 di << "use 'vinit' command before " << argv[0] << "\n";
8885 return 1;
8886 }
8887 if(argc < 4 || argc > 5){
8888 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
8889 return 1;
8890 }
6b62b2da 8891 Standard_Real Ax = Draw::Atof (argv[1]);
8892 Standard_Real Ay = Draw::Atof (argv[2]);
8893 Standard_Real Az = Draw::Atof (argv[3]);
4754e164 8894 Standard_Boolean aStart = Standard_True;
dc3fe572 8895 if (argc == 5)
4754e164 8896 {
6b62b2da 8897 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 8898 }
8899
8900 Handle(V3d_View) aView = ViewerTest::CurrentView();
8901 aView->Turn(Ax,Ay,Az,aStart);
8902 return 0;
8903}
8904
269294d6 8905//==============================================================================
8906//function : VTextureEnv
8907//purpose : ENables or disables environment mapping
8908//==============================================================================
8909class OCC_TextureEnv : public Graphic3d_TextureEnv
8910{
8911public:
8912 OCC_TextureEnv(const Standard_CString FileName);
8913 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
8914 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
8915 const Standard_Boolean theModulateFlag,
8916 const Graphic3d_TypeOfTextureFilter theFilter,
8917 const Standard_ShortReal theXScale,
8918 const Standard_ShortReal theYScale,
8919 const Standard_ShortReal theXShift,
8920 const Standard_ShortReal theYShift,
8921 const Standard_ShortReal theAngle);
68858c7d 8922 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
269294d6 8923};
a3f6f591 8924DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
ec357c5c 8925
269294d6 8926OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
8927 : Graphic3d_TextureEnv(theFileName)
8928{
8929}
8930
8931OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
8932 : Graphic3d_TextureEnv(theTexId)
8933{
8934}
8935
8936void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
8937 const Standard_Boolean theModulateFlag,
8938 const Graphic3d_TypeOfTextureFilter theFilter,
8939 const Standard_ShortReal theXScale,
8940 const Standard_ShortReal theYScale,
8941 const Standard_ShortReal theXShift,
8942 const Standard_ShortReal theYShift,
8943 const Standard_ShortReal theAngle)
8944{
8945 myParams->SetRepeat (theRepeatFlag);
8946 myParams->SetModulate (theModulateFlag);
8947 myParams->SetFilter (theFilter);
8948 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
8949 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
8950 myParams->SetRotation (theAngle);
8951}
8952
35e08fe8 8953static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
269294d6 8954{
8955 // get the active view
8956 Handle(V3d_View) aView = ViewerTest::CurrentView();
8957 if (aView.IsNull())
8958 {
8959 std::cerr << "No active view. Please call vinit.\n";
8960 return 1;
8961 }
8962
8963 // Checking the input arguments
8964 Standard_Boolean anEnableFlag = Standard_False;
8965 Standard_Boolean isOk = theArgNb >= 2;
8966 if (isOk)
8967 {
8968 TCollection_AsciiString anEnableOpt(theArgVec[1]);
8969 anEnableFlag = anEnableOpt.IsEqual("on");
8970 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
8971 }
8972 if (anEnableFlag)
8973 {
8974 isOk = (theArgNb == 3 || theArgNb == 11);
8975 if (isOk)
8976 {
8977 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8978 isOk = (!aTextureOpt.IsIntegerValue() ||
8979 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
8980
8981 if (isOk && theArgNb == 11)
8982 {
8983 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
8984 aModulateOpt(theArgVec[4]),
8985 aFilterOpt (theArgVec[5]),
8986 aSScaleOpt (theArgVec[6]),
8987 aTScaleOpt (theArgVec[7]),
8988 aSTransOpt (theArgVec[8]),
8989 aTTransOpt (theArgVec[9]),
8990 anAngleOpt (theArgVec[10]);
8991 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
8992 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
8993 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
8994 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
8995 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
8996 anAngleOpt.IsRealValue());
8997 }
8998 }
8999 }
9000
9001 if (!isOk)
9002 {
9003 std::cerr << "Usage :" << std::endl;
9004 std::cerr << theArgVec[0] << " off" << std::endl;
9005 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;
9006 return 1;
9007 }
9008
9009 if (anEnableFlag)
9010 {
9011 TCollection_AsciiString aTextureOpt(theArgVec[2]);
9012 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
9013 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
9014 new OCC_TextureEnv(theArgVec[2]);
9015
9016 if (theArgNb == 11)
9017 {
9018 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
9019 aTexEnv->SetTextureParameters(
9020 aRepeatOpt. IsEqual("repeat"),
9021 aModulateOpt.IsEqual("modulate"),
9022 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
9023 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
9024 Graphic3d_TOTF_TRILINEAR,
9025 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
9026 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
9027 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
9028 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
9029 (Standard_ShortReal)Draw::Atof(theArgVec[10])
9030 );
9031 }
9032 aView->SetTextureEnv(aTexEnv);
269294d6 9033 }
9034 else // Disabling environment mapping
9035 {
269294d6 9036 Handle(Graphic3d_TextureEnv) aTexture;
9037 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
9038 }
9039
9040 aView->Redraw();
9041 return 0;
9042}
9043
3e05329c 9044namespace
9045{
9046 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
9047
9048 //! Remove registered clipping plane from all views and objects.
9049 static void removePlane (MapOfPlanes& theRegPlanes,
9050 const TCollection_AsciiString& theName)
9051 {
9052 Handle(Graphic3d_ClipPlane) aClipPlane;
9053 if (!theRegPlanes.Find (theName, aClipPlane))
9054 {
9055 std::cout << "Warning: no such plane.\n";
9056 return;
9057 }
9058
9059 theRegPlanes.UnBind (theName);
9060 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
9061 anIObjIt.More(); anIObjIt.Next())
9062 {
8f521168 9063 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
3e05329c 9064 aPrs->RemoveClipPlane (aClipPlane);
9065 }
9066
9067 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
9068 aViewIt.More(); aViewIt.Next())
9069 {
9070 const Handle(V3d_View)& aView = aViewIt.Key2();
9071 aView->RemoveClipPlane(aClipPlane);
9072 }
9073
9074 ViewerTest::RedrawAllViews();
9075 }
9076}
9077
4269bd1b 9078//===============================================================================================
9079//function : VClipPlane
9080//purpose :
9081//===============================================================================================
9082static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9083{
9084 // use short-cut for created clip planes map of created (or "registered by name") clip planes
4269bd1b 9085 static MapOfPlanes aRegPlanes;
9086
9087 if (theArgsNb < 2)
9088 {
3e05329c 9089 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
9090 {
9091 theDi << aPlaneIter.Key() << " ";
9092 }
9093 return 0;
4269bd1b 9094 }
9095
9096 TCollection_AsciiString aCommand (theArgVec[1]);
3e05329c 9097 aCommand.LowerCase();
9098 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
9099 if (anActiveView.IsNull())
9100 {
9101 std::cout << "Error: no active view.\n";
9102 return 1;
9103 }
4269bd1b 9104
9105 // print maximum number of planes for current viewer
3e05329c 9106 if (aCommand == "-maxplanes"
9107 || aCommand == "maxplanes")
4269bd1b 9108 {
3e05329c 9109 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
9110 << " plane slots provided by driver.\n";
4269bd1b 9111 return 0;
9112 }
9113
9114 // create / delete plane instance
3e05329c 9115 if (aCommand == "-create"
9116 || aCommand == "create"
9117 || aCommand == "-delete"
9118 || aCommand == "delete"
9119 || aCommand == "-clone"
9120 || aCommand == "clone")
4269bd1b 9121 {
9122 if (theArgsNb < 3)
9123 {
3e05329c 9124 std::cout << "Syntax error: plane name is required.\n";
4269bd1b 9125 return 1;
9126 }
9127
3e05329c 9128 Standard_Boolean toCreate = aCommand == "-create"
9129 || aCommand == "create";
9130 Standard_Boolean toClone = aCommand == "-clone"
9131 || aCommand == "clone";
9132 Standard_Boolean toDelete = aCommand == "-delete"
9133 || aCommand == "delete";
4269bd1b 9134 TCollection_AsciiString aPlane (theArgVec[2]);
9135
9136 if (toCreate)
9137 {
9138 if (aRegPlanes.IsBound (aPlane))
9139 {
3e05329c 9140 std::cout << "Warning: existing plane has been overridden.\n";
9141 toDelete = true;
9142 }
9143 else
9144 {
9145 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9146 return 0;
4269bd1b 9147 }
4269bd1b 9148 }
9149 else if (toClone) // toClone
9150 {
9151 if (!aRegPlanes.IsBound (aPlane))
9152 {
3e05329c 9153 std::cout << "Error: no such plane.\n";
4269bd1b 9154 return 1;
9155 }
3e05329c 9156 else if (theArgsNb < 4)
4269bd1b 9157 {
3e05329c 9158 std::cout << "Syntax error: enter name for new plane.\n";
4269bd1b 9159 return 1;
9160 }
9161
9162 TCollection_AsciiString aClone (theArgVec[3]);
9163 if (aRegPlanes.IsBound (aClone))
9164 {
3e05329c 9165 std::cout << "Error: plane name is in use.\n";
4269bd1b 9166 return 1;
9167 }
9168
9169 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
9170
9171 aRegPlanes.Bind (aClone, aClipPlane->Clone());
3e05329c 9172 return 0;
4269bd1b 9173 }
4269bd1b 9174
3e05329c 9175 if (toDelete)
9176 {
9177 if (aPlane == "ALL"
9178 || aPlane == "all"
9179 || aPlane == "*")
4269bd1b 9180 {
3e05329c 9181 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
9182 {
9183 aPlane = aPlaneIter.Key();
9184 removePlane (aRegPlanes, aPlane);
9185 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
9186 }
4269bd1b 9187 }
3e05329c 9188 else
4269bd1b 9189 {
3e05329c 9190 removePlane (aRegPlanes, aPlane);
4269bd1b 9191 }
4269bd1b 9192 }
9193
3e05329c 9194 if (toCreate)
9195 {
9196 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
9197 }
4269bd1b 9198 return 0;
9199 }
9200
9201 // set / unset plane command
3e05329c 9202 if (aCommand == "set"
9203 || aCommand == "unset")
4269bd1b 9204 {
3e05329c 9205 if (theArgsNb < 5)
4269bd1b 9206 {
3e05329c 9207 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 9208 return 1;
9209 }
9210
3e05329c 9211 // redirect to new syntax
9212 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
9213 anArgVec.SetValue (1, theArgVec[0]);
9214 anArgVec.SetValue (2, theArgVec[2]);
9215 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
9216 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
4269bd1b 9217 {
3e05329c 9218 anArgVec.SetValue (anIt, theArgVec[anIt]);
4269bd1b 9219 }
9220
3e05329c 9221 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
4269bd1b 9222 }
9223
9224 // change plane command
3e05329c 9225 TCollection_AsciiString aPlaneName;
9226 Handle(Graphic3d_ClipPlane) aClipPlane;
9227 Standard_Integer anArgIter = 0;
9228 if (aCommand == "-change"
9229 || aCommand == "change")
4269bd1b 9230 {
3e05329c 9231 // old syntax support
9232 if (theArgsNb < 3)
4269bd1b 9233 {
3e05329c 9234 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 9235 return 1;
9236 }
9237
3e05329c 9238 anArgIter = 3;
9239 aPlaneName = theArgVec[2];
9240 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
4269bd1b 9241 {
3e05329c 9242 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
4269bd1b 9243 return 1;
9244 }
3e05329c 9245 }
9246 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
9247 {
9248 anArgIter = 2;
9249 aPlaneName = theArgVec[1];
9250 }
9251 else
9252 {
9253 anArgIter = 2;
9254 aPlaneName = theArgVec[1];
9255 aClipPlane = new Graphic3d_ClipPlane();
9256 aRegPlanes.Bind (aPlaneName, aClipPlane);
9257 theDi << "Created new plane " << aPlaneName << ".\n";
9258 }
4269bd1b 9259
3e05329c 9260 if (theArgsNb - anArgIter < 1)
9261 {
9262 std::cout << "Syntax error: need more arguments.\n";
9263 return 1;
9264 }
4269bd1b 9265
3e05329c 9266 for (; anArgIter < theArgsNb; ++anArgIter)
9267 {
9268 const char** aChangeArgs = theArgVec + anArgIter;
9269 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
9270 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
9271 aChangeArg.LowerCase();
4269bd1b 9272
3e05329c 9273 Standard_Boolean toEnable = Standard_True;
9274 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
4269bd1b 9275 {
3e05329c 9276 aClipPlane->SetOn (toEnable);
4269bd1b 9277 }
25c35042 9278 else if (aChangeArg.StartsWith ("-equation")
9279 || aChangeArg.StartsWith ("equation"))
4269bd1b 9280 {
3e05329c 9281 if (aNbChangeArgs < 5)
4269bd1b 9282 {
3e05329c 9283 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 9284 return 1;
9285 }
9286
25c35042 9287 Standard_Integer aSubIndex = 1;
9288 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
9289 if (aPrefixLen < aChangeArg.Length())
9290 {
9291 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
9292 if (!aSubStr.IsIntegerValue()
9293 || aSubStr.IntegerValue() <= 0)
9294 {
9295 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9296 return 1;
9297 }
9298 aSubIndex = aSubStr.IntegerValue();
9299 }
9300
9301 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
9302 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
9303 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
9304 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
9305 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9306 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
9307 {
9308 if (aSubPln->ChainNextPlane().IsNull())
9309 {
9310 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9311 }
9312 aSubPln = aSubPln->ChainNextPlane();
9313 }
9314 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9315 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
3e05329c 9316 anArgIter += 4;
4269bd1b 9317 }
25c35042 9318 else if ((aChangeArg == "-boxinterior"
9319 || aChangeArg == "-boxint"
9320 || aChangeArg == "-box")
9321 && aNbChangeArgs >= 7)
9322 {
9323 Graphic3d_BndBox3d aBndBox;
9324 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
9325 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
9326 anArgIter += 6;
9327
9328 Standard_Integer aNbSubPlanes = 6;
9329 const Graphic3d_Vec3d aDirArray[6] =
9330 {
9331 Graphic3d_Vec3d (-1, 0, 0),
9332 Graphic3d_Vec3d ( 1, 0, 0),
9333 Graphic3d_Vec3d ( 0,-1, 0),
9334 Graphic3d_Vec3d ( 0, 1, 0),
9335 Graphic3d_Vec3d ( 0, 0,-1),
9336 Graphic3d_Vec3d ( 0, 0, 1),
9337 };
9338 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
9339 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
9340 {
9341 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
9342 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
9343 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
9344 if (aSubPlaneIter + 1 == aNbSubPlanes)
9345 {
9346 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
9347 }
9348 else
9349 {
9350 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
9351 }
9352 aSubPln = aSubPln->ChainNextPlane();
9353 }
9354 }
3e05329c 9355 else if (aChangeArg == "-capping"
9356 || aChangeArg == "capping")
4269bd1b 9357 {
3e05329c 9358 if (aNbChangeArgs < 2)
4269bd1b 9359 {
3e05329c 9360 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 9361 return 1;
9362 }
9363
3e05329c 9364 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
4269bd1b 9365 {
3e05329c 9366 aClipPlane->SetCapping (toEnable);
9367 anArgIter += 1;
9368 }
9369 else
9370 {
9371 // just skip otherwise (old syntax)
9372 }
9373 }
9374 else if (aChangeArg == "-useobjectmaterial"
9375 || aChangeArg == "-useobjectmat"
9376 || aChangeArg == "-useobjmat"
9377 || aChangeArg == "-useobjmaterial")
9378 {
9379 if (aNbChangeArgs < 2)
9380 {
9381 std::cout << "Syntax error: need more arguments.\n";
4269bd1b 9382 return 1;
9383 }
9384
3e05329c 9385 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
4269bd1b 9386 {
3e05329c 9387 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
9388 anArgIter += 1;
4269bd1b 9389 }
3e05329c 9390 }
9391 else if (aChangeArg == "-useobjecttexture"
9392 || aChangeArg == "-useobjecttex"
9393 || aChangeArg == "-useobjtexture"
9394 || aChangeArg == "-useobjtex")
9395 {
9396 if (aNbChangeArgs < 2)
4269bd1b 9397 {
3e05329c 9398 std::cout << "Syntax error: need more arguments.\n";
9399 return 1;
9400 }
4269bd1b 9401
3e05329c 9402 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9403 {
9404 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
9405 anArgIter += 1;
9406 }
9407 }
9408 else if (aChangeArg == "-useobjectshader"
9409 || aChangeArg == "-useobjshader")
9410 {
9411 if (aNbChangeArgs < 2)
9412 {
9413 std::cout << "Syntax error: need more arguments.\n";
9414 return 1;
9415 }
4269bd1b 9416
3e05329c 9417 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
9418 {
9419 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
9420 anArgIter += 1;
4269bd1b 9421 }
3e05329c 9422 }
9423 else if (aChangeArg == "-color"
9424 || aChangeArg == "color")
9425 {
9426 Quantity_Color aColor;
9427 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
9428 aChangeArgs + 1,
9429 aColor);
9430 if (aNbParsed == 0)
4269bd1b 9431 {
3e05329c 9432 std::cout << "Syntax error: need more arguments.\n";
9433 return 1;
9434 }
4269bd1b 9435
3e05329c 9436 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
9437 aMat.SetAmbientColor (aColor);
9438 aMat.SetDiffuseColor (aColor);
9439 aClipPlane->SetCappingMaterial (aMat);
9440 anArgIter += aNbParsed;
9441 }
1b661a81 9442 else if ((aChangeArg == "-transparency"
9443 || aChangeArg == "-transp")
9444 && aNbChangeArgs >= 2)
9445 {
9446 TCollection_AsciiString aValStr (aChangeArgs[1]);
9447 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
9448 if (aValStr.IsRealValue())
9449 {
9450 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
9451 aMat.SetTransparency ((float )aValStr.RealValue());
9452 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
9453 aClipPlane->SetCappingMaterial (aMat);
9454 }
9455 else
9456 {
9457 aValStr.LowerCase();
9458 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
9459 if (aValStr == "opaque")
9460 {
9461 aMode = Graphic3d_AlphaMode_Opaque;
9462 }
9463 else if (aValStr == "mask")
9464 {
9465 aMode = Graphic3d_AlphaMode_Mask;
9466 }
9467 else if (aValStr == "blend")
9468 {
9469 aMode = Graphic3d_AlphaMode_Blend;
9470 }
9471 else if (aValStr == "blendauto")
9472 {
9473 aMode = Graphic3d_AlphaMode_BlendAuto;
9474 }
9475 else
9476 {
9477 std::cout << "Syntax error at '" << aValStr << "'\n";
9478 return 1;
9479 }
9480 anAspect->SetAlphaMode (aMode);
9481 aClipPlane->SetCappingAspect (anAspect);
9482 }
9483 anArgIter += 1;
9484 }
3e05329c 9485 else if (aChangeArg == "-texname"
9486 || aChangeArg == "texname")
9487 {
9488 if (aNbChangeArgs < 2)
9489 {
9490 std::cout << "Syntax error: need more arguments.\n";
9491 return 1;
9492 }
4269bd1b 9493
3e05329c 9494 TCollection_AsciiString aTextureName (aChangeArgs[1]);
9495 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
9496 if (!aTexture->IsDone())
9497 {
9498 aClipPlane->SetCappingTexture (NULL);
4269bd1b 9499 }
3e05329c 9500 else
4269bd1b 9501 {
3e05329c 9502 aTexture->EnableModulate();
9503 aTexture->EnableRepeat();
9504 aClipPlane->SetCappingTexture (aTexture);
9505 }
9506 anArgIter += 1;
9507 }
9508 else if (aChangeArg == "-texscale"
9509 || aChangeArg == "texscale")
9510 {
9511 if (aClipPlane->CappingTexture().IsNull())
9512 {
9513 std::cout << "Error: no texture is set.\n";
9514 return 1;
9515 }
4269bd1b 9516
3e05329c 9517 if (aNbChangeArgs < 3)
9518 {
9519 std::cout << "Syntax error: need more arguments.\n";
9520 return 1;
9521 }
4269bd1b 9522
3e05329c 9523 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9524 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9525 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
9526 anArgIter += 2;
9527 }
9528 else if (aChangeArg == "-texorigin"
9529 || aChangeArg == "texorigin") // texture origin
9530 {
9531 if (aClipPlane->CappingTexture().IsNull())
9532 {
9533 std::cout << "Error: no texture is set.\n";
9534 return 1;
9535 }
4269bd1b 9536
3e05329c 9537 if (aNbChangeArgs < 3)
9538 {
9539 std::cout << "Syntax error: need more arguments.\n";
9540 return 1;
4269bd1b 9541 }
3e05329c 9542
9543 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9544 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
9545
9546 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
9547 anArgIter += 2;
9548 }
9549 else if (aChangeArg == "-texrotate"
9550 || aChangeArg == "texrotate") // texture rotation
9551 {
9552 if (aClipPlane->CappingTexture().IsNull())
4269bd1b 9553 {
3e05329c 9554 std::cout << "Error: no texture is set.\n";
9555 return 1;
9556 }
4269bd1b 9557
3e05329c 9558 if (aNbChangeArgs < 2)
9559 {
9560 std::cout << "Syntax error: need more arguments.\n";
9561 return 1;
9562 }
4269bd1b 9563
3e05329c 9564 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
9565 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
9566 anArgIter += 1;
9567 }
9568 else if (aChangeArg == "-hatch"
9569 || aChangeArg == "hatch")
9570 {
9571 if (aNbChangeArgs < 2)
9572 {
9573 std::cout << "Syntax error: need more arguments.\n";
9574 return 1;
9575 }
4269bd1b 9576
3e05329c 9577 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
9578 aHatchStr.LowerCase();
9579 if (aHatchStr == "on")
9580 {
9581 aClipPlane->SetCappingHatchOn();
9582 }
9583 else if (aHatchStr == "off")
9584 {
9585 aClipPlane->SetCappingHatchOff();
4269bd1b 9586 }
3e05329c 9587 else
4269bd1b 9588 {
3e05329c 9589 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
9590 }
9591 anArgIter += 1;
9592 }
9593 else if (aChangeArg == "-delete"
9594 || aChangeArg == "delete")
9595 {
9596 removePlane (aRegPlanes, aPlaneName);
9597 return 0;
9598 }
9599 else if (aChangeArg == "-set"
32ca7711 9600 || aChangeArg == "-unset"
9601 || aChangeArg == "-setoverrideglobal")
3e05329c 9602 {
9603 // set / unset plane command
32ca7711 9604 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
9605 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
3e05329c 9606 Standard_Integer anIt = 1;
9607 for (; anIt < aNbChangeArgs; ++anIt)
9608 {
9609 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
9610 if (anEntityName.IsEmpty()
9611 || anEntityName.Value (1) == '-')
4269bd1b 9612 {
3e05329c 9613 break;
4269bd1b 9614 }
32ca7711 9615 else if (!toOverrideGlobal
9616 && ViewerTest_myViews.IsBound1 (anEntityName))
4269bd1b 9617 {
3e05329c 9618 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
9619 if (toSet)
9620 {
9621 aView->AddClipPlane (aClipPlane);
9622 }
9623 else
9624 {
9625 aView->RemoveClipPlane (aClipPlane);
9626 }
9627 continue;
4269bd1b 9628 }
3e05329c 9629 else if (GetMapOfAIS().IsBound2 (anEntityName))
4269bd1b 9630 {
8f521168 9631 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
3e05329c 9632 if (toSet)
9633 {
9634 aIObj->AddClipPlane (aClipPlane);
9635 }
9636 else
9637 {
9638 aIObj->RemoveClipPlane (aClipPlane);
9639 }
32ca7711 9640 if (!aIObj->ClipPlanes().IsNull())
9641 {
9642 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
9643 }
4269bd1b 9644 }
3e05329c 9645 else
4269bd1b 9646 {
3e05329c 9647 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
9648 return 1;
4269bd1b 9649 }
3e05329c 9650 }
9651
9652 if (anIt == 1)
9653 {
9654 // apply to active view
9655 if (toSet)
4269bd1b 9656 {
3e05329c 9657 anActiveView->AddClipPlane (aClipPlane);
4269bd1b 9658 }
9659 else
9660 {
3e05329c 9661 anActiveView->RemoveClipPlane (aClipPlane);
4269bd1b 9662 }
9663 }
3e05329c 9664 else
9665 {
9666 anArgIter = anArgIter + anIt - 1;
9667 }
9668 }
9669 else
9670 {
9671 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9672 return 1;
4269bd1b 9673 }
4269bd1b 9674 }
9675
3e05329c 9676 ViewerTest::RedrawAllViews();
9677 return 0;
4269bd1b 9678}
9679
b5ac8292 9680//===============================================================================================
9681//function : VZRange
9682//purpose :
9683//===============================================================================================
9684static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9685{
197ac94e 9686 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9687
9688 if (aCurrentView.IsNull())
b5ac8292 9689 {
197ac94e 9690 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 9691 return 1;
9692 }
9693
197ac94e 9694 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
b5ac8292 9695
9696 if (theArgsNb < 2)
9697 {
9698 theDi << "ZNear: " << aCamera->ZNear() << "\n";
9699 theDi << "ZFar: " << aCamera->ZFar() << "\n";
9700 return 0;
9701 }
9702
9703 if (theArgsNb == 3)
9704 {
6b62b2da 9705 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
9706 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
197ac94e 9707
9708 if (aNewZNear >= aNewZFar)
9709 {
9710 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
9711 return 1;
9712 }
9713
9714 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
9715 {
9716 std::cout << theArgVec[0] << ": invalid arguments: ";
9717 std::cout << "znear, zfar should be positive for perspective camera.\n";
9718 return 1;
9719 }
9720
9721 aCamera->SetZRange (aNewZNear, aNewZFar);
b5ac8292 9722 }
9723 else
9724 {
197ac94e 9725 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
b5ac8292 9726 return 1;
9727 }
9728
197ac94e 9729 aCurrentView->Redraw();
9730
b5ac8292 9731 return 0;
9732}
9733
9734//===============================================================================================
9735//function : VAutoZFit
9736//purpose :
9737//===============================================================================================
9738static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9739{
197ac94e 9740 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9741
9742 if (aCurrentView.IsNull())
b5ac8292 9743 {
197ac94e 9744 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 9745 return 1;
9746 }
9747
c357e426 9748 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
197ac94e 9749
9750 if (theArgsNb > 3)
b5ac8292 9751 {
197ac94e 9752 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9753 return 1;
b5ac8292 9754 }
9755
197ac94e 9756 if (theArgsNb < 2)
b5ac8292 9757 {
586db386 9758 theDi << "Auto z-fit mode: \n"
c357e426 9759 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
197ac94e 9760 << "Scale: " << aScale << "\n";
9761 return 0;
b5ac8292 9762 }
197ac94e 9763
9764 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
9765
9766 if (theArgsNb >= 3)
b5ac8292 9767 {
197ac94e 9768 aScale = Draw::Atoi (theArgVec[2]);
b5ac8292 9769 }
9770
c357e426 9771 aCurrentView->SetAutoZFitMode (isOn, aScale);
9772 aCurrentView->AutoZFit();
197ac94e 9773 aCurrentView->Redraw();
9774
b5ac8292 9775 return 0;
9776}
9777
6b62b2da 9778//! Auxiliary function to print projection type
9779inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
9780{
9781 switch (theProjType)
9782 {
9783 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
9784 case Graphic3d_Camera::Projection_Perspective: return "perspective";
9785 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
9786 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
9787 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
9788 }
9789 return "UNKNOWN";
9790}
9791
b5ac8292 9792//===============================================================================================
6b62b2da 9793//function : VCamera
b5ac8292 9794//purpose :
9795//===============================================================================================
6b62b2da 9796static int VCamera (Draw_Interpretor& theDI,
9797 Standard_Integer theArgsNb,
9798 const char** theArgVec)
b5ac8292 9799{
6b62b2da 9800 Handle(V3d_View) aView = ViewerTest::CurrentView();
9801 if (aView.IsNull())
b5ac8292 9802 {
6b62b2da 9803 std::cout << "Error: no active view.\n";
b5ac8292 9804 return 1;
9805 }
9806
6b62b2da 9807 Handle(Graphic3d_Camera) aCamera = aView->Camera();
9808 if (theArgsNb < 2)
b5ac8292 9809 {
6b62b2da 9810 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
9811 theDI << "FOVy: " << aCamera->FOVy() << "\n";
9812 theDI << "Distance: " << aCamera->Distance() << "\n";
9813 theDI << "IOD: " << aCamera->IOD() << "\n";
9814 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
9815 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
9816 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
9817 return 0;
b5ac8292 9818 }
9819
30a1b24e 9820 TCollection_AsciiString aPrsName;
6b62b2da 9821 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
b5ac8292 9822 {
6b62b2da 9823 Standard_CString anArg = theArgVec[anArgIter];
9824 TCollection_AsciiString anArgCase (anArg);
9825 anArgCase.LowerCase();
9826 if (anArgCase == "-proj"
9827 || anArgCase == "-projection"
9828 || anArgCase == "-projtype"
9829 || anArgCase == "-projectiontype")
9830 {
9831 theDI << projTypeName (aCamera->ProjectionType()) << " ";
9832 }
9833 else if (anArgCase == "-ortho"
9834 || anArgCase == "-orthographic")
b5ac8292 9835 {
9836 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
6b62b2da 9837 }
9838 else if (anArgCase == "-persp"
9839 || anArgCase == "-perspective"
9840 || anArgCase == "-perspmono"
9841 || anArgCase == "-perspectivemono"
9842 || anArgCase == "-mono")
b5ac8292 9843 {
9844 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9845 }
6b62b2da 9846 else if (anArgCase == "-stereo"
9847 || anArgCase == "-stereoscopic"
9848 || anArgCase == "-perspstereo"
9849 || anArgCase == "-perspectivestereo")
9850 {
9851 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9852 }
9853 else if (anArgCase == "-left"
9854 || anArgCase == "-lefteye"
9855 || anArgCase == "-monoleft"
9856 || anArgCase == "-monolefteye"
9857 || anArgCase == "-perpsleft"
9858 || anArgCase == "-perpslefteye")
b5ac8292 9859 {
9860 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
9861 }
6b62b2da 9862 else if (anArgCase == "-right"
9863 || anArgCase == "-righteye"
9864 || anArgCase == "-monoright"
9865 || anArgCase == "-monorighteye"
9866 || anArgCase == "-perpsright")
b5ac8292 9867 {
9868 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
9869 }
6b62b2da 9870 else if (anArgCase == "-dist"
9871 || anArgCase == "-distance")
b5ac8292 9872 {
6b62b2da 9873 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9874 if (anArgValue != NULL
9875 && *anArgValue != '-')
9876 {
9877 ++anArgIter;
9878 aCamera->SetDistance (Draw::Atof (anArgValue));
9879 continue;
9880 }
9881 theDI << aCamera->Distance() << " ";
b5ac8292 9882 }
6b62b2da 9883 else if (anArgCase == "-iod")
b5ac8292 9884 {
6b62b2da 9885 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9886 if (anArgValue != NULL
9887 && *anArgValue != '-')
9888 {
9889 ++anArgIter;
9890 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
9891 continue;
9892 }
9893 theDI << aCamera->IOD() << " ";
b5ac8292 9894 }
6b62b2da 9895 else if (anArgCase == "-iodtype")
b5ac8292 9896 {
6b62b2da 9897 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9898 TCollection_AsciiString anValueCase (anArgValue);
9899 anValueCase.LowerCase();
9900 if (anValueCase == "abs"
9901 || anValueCase == "absolute")
9902 {
9903 ++anArgIter;
9904 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
9905 continue;
9906 }
9907 else if (anValueCase == "rel"
9908 || anValueCase == "relative")
9909 {
9910 ++anArgIter;
9911 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
9912 continue;
9913 }
9914 else if (*anArgValue != '-')
9915 {
9916 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
9917 return 1;
9918 }
9919 switch (aCamera->GetIODType())
9920 {
9921 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
9922 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
9923 }
b5ac8292 9924 }
6b62b2da 9925 else if (anArgCase == "-zfocus")
b5ac8292 9926 {
6b62b2da 9927 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9928 if (anArgValue != NULL
9929 && *anArgValue != '-')
9930 {
9931 ++anArgIter;
9932 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
9933 continue;
9934 }
9935 theDI << aCamera->ZFocus() << " ";
b5ac8292 9936 }
6b62b2da 9937 else if (anArgCase == "-zfocustype")
b5ac8292 9938 {
6b62b2da 9939 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9940 TCollection_AsciiString anValueCase (anArgValue);
9941 anValueCase.LowerCase();
9942 if (anValueCase == "abs"
9943 || anValueCase == "absolute")
9944 {
9945 ++anArgIter;
9946 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
9947 continue;
9948 }
9949 else if (anValueCase == "rel"
9950 || anValueCase == "relative")
9951 {
9952 ++anArgIter;
9953 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
9954 continue;
9955 }
9956 else if (*anArgValue != '-')
9957 {
9958 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
9959 return 1;
9960 }
9961 switch (aCamera->ZFocusType())
9962 {
9963 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
9964 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
9965 }
9966 }
9967 else if (anArgCase == "-fov"
9968 || anArgCase == "-fovy")
b5ac8292 9969 {
6b62b2da 9970 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9971 if (anArgValue != NULL
9972 && *anArgValue != '-')
9973 {
9974 ++anArgIter;
9975 aCamera->SetFOVy (Draw::Atof (anArgValue));
9976 continue;
9977 }
9978 theDI << aCamera->FOVy() << " ";
b5ac8292 9979 }
30a1b24e 9980 else if (aPrsName.IsEmpty()
9981 && !anArgCase.StartsWith ("-"))
9982 {
9983 aPrsName = anArg;
9984 }
b5ac8292 9985 else
9986 {
6b62b2da 9987 std::cout << "Error: unknown argument '" << anArg << "'\n";
b5ac8292 9988 return 1;
9989 }
9990 }
b5ac8292 9991
30a1b24e 9992 if (aPrsName.IsEmpty()
9993 || theArgsNb > 2)
9994 {
9995 aView->AutoZFit();
9996 aView->Redraw();
9997 }
9998
9999 if (!aPrsName.IsEmpty())
10000 {
10001 Handle(AIS_CameraFrustum) aCameraFrustum;
10002 if (GetMapOfAIS().IsBound2 (aPrsName))
10003 {
10004 // find existing object
10005 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
10006 if (aCameraFrustum.IsNull())
10007 {
10008 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
10009 return 1;
10010 }
10011 }
10012
10013 if (aCameraFrustum.IsNull())
10014 {
10015 aCameraFrustum = new AIS_CameraFrustum();
10016 }
10017 else
10018 {
10019 // not include displayed object of old camera frustum in the new one.
10020 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
10021 aView->ZFitAll();
10022 }
10023 aCameraFrustum->SetCameraFrustum (aView->Camera());
10024
10025 ViewerTest::Display (aPrsName, aCameraFrustum);
10026 }
b5ac8292 10027
10028 return 0;
10029}
10030
f978241f 10031//! Parse stereo output mode
10032inline Standard_Boolean parseStereoMode (Standard_CString theArg,
10033 Graphic3d_StereoMode& theMode)
10034{
10035 TCollection_AsciiString aFlag (theArg);
10036 aFlag.LowerCase();
10037 if (aFlag == "quadbuffer")
10038 {
10039 theMode = Graphic3d_StereoMode_QuadBuffer;
10040 }
10041 else if (aFlag == "anaglyph")
10042 {
10043 theMode = Graphic3d_StereoMode_Anaglyph;
10044 }
10045 else if (aFlag == "row"
10046 || aFlag == "rowinterlaced")
10047 {
10048 theMode = Graphic3d_StereoMode_RowInterlaced;
10049 }
10050 else if (aFlag == "col"
10051 || aFlag == "colinterlaced"
10052 || aFlag == "columninterlaced")
10053 {
10054 theMode = Graphic3d_StereoMode_ColumnInterlaced;
10055 }
10056 else if (aFlag == "chess"
10057 || aFlag == "chessboard")
10058 {
10059 theMode = Graphic3d_StereoMode_ChessBoard;
10060 }
10061 else if (aFlag == "sbs"
10062 || aFlag == "sidebyside")
10063 {
10064 theMode = Graphic3d_StereoMode_SideBySide;
10065 }
10066 else if (aFlag == "ou"
10067 || aFlag == "overunder")
10068 {
10069 theMode = Graphic3d_StereoMode_OverUnder;
10070 }
10071 else if (aFlag == "pageflip"
10072 || aFlag == "softpageflip")
10073 {
10074 theMode = Graphic3d_StereoMode_SoftPageFlip;
10075 }
10076 else
10077 {
10078 return Standard_False;
10079 }
10080 return Standard_True;
10081}
10082
10083//! Parse anaglyph filter
10084inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
10085 Graphic3d_RenderingParams::Anaglyph& theFilter)
10086{
10087 TCollection_AsciiString aFlag (theArg);
10088 aFlag.LowerCase();
10089 if (aFlag == "redcyansimple")
10090 {
10091 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10092 }
10093 else if (aFlag == "redcyan"
10094 || aFlag == "redcyanoptimized")
10095 {
10096 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
10097 }
10098 else if (aFlag == "yellowbluesimple")
10099 {
10100 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
10101 }
10102 else if (aFlag == "yellowblue"
10103 || aFlag == "yellowblueoptimized")
10104 {
10105 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
10106 }
10107 else if (aFlag == "greenmagenta"
10108 || aFlag == "greenmagentasimple")
10109 {
10110 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
10111 }
10112 else
10113 {
10114 return Standard_False;
10115 }
10116 return Standard_True;
10117}
10118
b5ac8292 10119//==============================================================================
10120//function : VStereo
10121//purpose :
10122//==============================================================================
10123
10124static int VStereo (Draw_Interpretor& theDI,
10125 Standard_Integer theArgNb,
10126 const char** theArgVec)
10127{
f978241f 10128 Handle(V3d_View) aView = ViewerTest::CurrentView();
b5ac8292 10129 if (theArgNb < 2)
10130 {
b5ac8292 10131 if (aView.IsNull())
10132 {
f978241f 10133 std::cout << "Error: no active viewer!\n";
b5ac8292 10134 return 0;
10135 }
10136
10137 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
10138 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
bf02aa7d 10139 if (isActive)
10140 {
10141 TCollection_AsciiString aMode;
10142 switch (aView->RenderingParams().StereoMode)
10143 {
10144 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
10145 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
10146 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
10147 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
10148 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
10149 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
10150 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
10151 case Graphic3d_StereoMode_Anaglyph :
10152 aMode = "anaglyph";
10153 switch (aView->RenderingParams().AnaglyphFilter)
10154 {
10155 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
10156 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
10157 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
10158 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
10159 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
10160 default: break;
10161 }
10162 default: break;
10163 }
10164 theDI << "Mode " << aMode << "\n";
10165 }
b5ac8292 10166 return 0;
10167 }
10168
f978241f 10169 Handle(Graphic3d_Camera) aCamera;
10170 Graphic3d_RenderingParams* aParams = NULL;
10171 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
10172 if (!aView.IsNull())
10173 {
10174 aParams = &aView->ChangeRenderingParams();
10175 aMode = aParams->StereoMode;
10176 aCamera = aView->Camera();
10177 }
10178
10179 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10180 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10181 {
10182 Standard_CString anArg = theArgVec[anArgIter];
10183 TCollection_AsciiString aFlag (anArg);
10184 aFlag.LowerCase();
10185 if (anUpdateTool.parseRedrawMode (aFlag))
10186 {
10187 continue;
10188 }
10189 else if (aFlag == "0"
10190 || aFlag == "off")
10191 {
10192 if (++anArgIter < theArgNb)
10193 {
10194 std::cout << "Error: wrong number of arguments!\n";
10195 return 1;
10196 }
10197
10198 if (!aCamera.IsNull()
10199 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
10200 {
10201 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
10202 }
10203 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
10204 return 0;
10205 }
10206 else if (aFlag == "1"
10207 || aFlag == "on")
10208 {
10209 if (++anArgIter < theArgNb)
10210 {
10211 std::cout << "Error: wrong number of arguments!\n";
10212 return 1;
10213 }
10214
10215 if (!aCamera.IsNull())
10216 {
10217 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10218 }
10219 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10220 return 0;
10221 }
10222 else if (aFlag == "-reverse"
10223 || aFlag == "-reversed"
10224 || aFlag == "-swap")
10225 {
10226 Standard_Boolean toEnable = Standard_True;
10227 if (++anArgIter < theArgNb
a5565a3c 10228 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
f978241f 10229 {
10230 --anArgIter;
10231 }
10232 aParams->ToReverseStereo = toEnable;
10233 }
10234 else if (aFlag == "-noreverse"
10235 || aFlag == "-noswap")
10236 {
10237 Standard_Boolean toDisable = Standard_True;
10238 if (++anArgIter < theArgNb
a5565a3c 10239 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
f978241f 10240 {
10241 --anArgIter;
10242 }
10243 aParams->ToReverseStereo = !toDisable;
10244 }
10245 else if (aFlag == "-mode"
10246 || aFlag == "-stereomode")
10247 {
10248 if (++anArgIter >= theArgNb
10249 || !parseStereoMode (theArgVec[anArgIter], aMode))
10250 {
10251 std::cout << "Error: syntax error at '" << anArg << "'\n";
10252 return 1;
10253 }
10254
10255 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10256 {
10257 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10258 }
10259 }
10260 else if (aFlag == "-anaglyph"
10261 || aFlag == "-anaglyphfilter")
10262 {
10263 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
10264 if (++anArgIter >= theArgNb
10265 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
10266 {
10267 std::cout << "Error: syntax error at '" << anArg << "'\n";
10268 return 1;
10269 }
10270
10271 aMode = Graphic3d_StereoMode_Anaglyph;
10272 aParams->AnaglyphFilter = aFilter;
10273 }
10274 else if (parseStereoMode (anArg, aMode)) // short syntax
10275 {
10276 if (aMode == Graphic3d_StereoMode_QuadBuffer)
10277 {
10278 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
10279 }
10280 }
10281 else
10282 {
10283 std::cout << "Error: syntax error at '" << anArg << "'\n";
10284 return 1;
10285 }
10286 }
10287
10288 if (!aView.IsNull())
10289 {
10290 aParams->StereoMode = aMode;
10291 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
10292 }
b5ac8292 10293 return 0;
10294}
10295
392ac980 10296//===============================================================================================
10297//function : VDefaults
10298//purpose :
10299//===============================================================================================
10300static int VDefaults (Draw_Interpretor& theDi,
10301 Standard_Integer theArgsNb,
10302 const char** theArgVec)
10303{
10304 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
10305 if (aCtx.IsNull())
10306 {
10307 std::cerr << "No active viewer!\n";
10308 return 1;
10309 }
10310
10311 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
10312 if (theArgsNb < 2)
10313 {
10314 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
10315 {
10316 theDi << "DeflType: relative\n"
10317 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
10318 }
10319 else
10320 {
10321 theDi << "DeflType: absolute\n"
10322 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
10323 }
10324 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
4c513386 10325 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
392ac980 10326 return 0;
10327 }
10328
10329 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10330 {
10331 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4c513386 10332 anArg.UpperCase();
10333 if (anArg == "-ABSDEFL"
10334 || anArg == "-ABSOLUTEDEFLECTION"
10335 || anArg == "-DEFL"
10336 || anArg == "-DEFLECTION")
392ac980 10337 {
4c513386 10338 if (++anArgIter >= theArgsNb)
10339 {
10340 std::cout << "Error: wrong syntax at " << anArg << "\n";
10341 return 1;
10342 }
392ac980 10343 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
4c513386 10344 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
392ac980 10345 }
4c513386 10346 else if (anArg == "-RELDEFL"
10347 || anArg == "-RELATIVEDEFLECTION"
10348 || anArg == "-DEVCOEFF"
10349 || anArg == "-DEVIATIONCOEFF"
10350 || anArg == "-DEVIATIONCOEFFICIENT")
392ac980 10351 {
4c513386 10352 if (++anArgIter >= theArgsNb)
10353 {
10354 std::cout << "Error: wrong syntax at " << anArg << "\n";
10355 return 1;
10356 }
392ac980 10357 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
4c513386 10358 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
392ac980 10359 }
4c513386 10360 else if (anArg == "-ANGDEFL"
10361 || anArg == "-ANGULARDEFL"
10362 || anArg == "-ANGULARDEFLECTION")
392ac980 10363 {
4c513386 10364 if (++anArgIter >= theArgsNb)
10365 {
10366 std::cout << "Error: wrong syntax at " << anArg << "\n";
10367 return 1;
10368 }
392ac980 10369 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
4c513386 10370 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
10371 }
385c43e7 10372 else if (anArg == "-AUTOTR"
10373 || anArg == "-AUTOTRIANG"
10374 || anArg == "-AUTOTRIANGULATION")
4c513386 10375 {
10376 if (++anArgIter >= theArgsNb)
10377 {
10378 std::cout << "Error: wrong syntax at " << anArg << "\n";
10379 return 1;
10380 }
10381 TCollection_AsciiString aValue (theArgVec[anArgIter]);
10382 aValue.LowerCase();
10383 if (aValue == "on"
10384 || aValue == "1")
10385 {
10386 aDefParams->SetAutoTriangulation (Standard_True);
10387 }
10388 else if (aValue == "off"
10389 || aValue == "0")
10390 {
10391 aDefParams->SetAutoTriangulation (Standard_False);
10392 }
392ac980 10393 }
10394 else
10395 {
10396 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
10397 }
10398 }
10399
10400 return 0;
10401}
10402
12381341 10403//! Auxiliary method
10404inline void addLight (const Handle(V3d_Light)& theLightNew,
992ed6b3 10405 const Graphic3d_ZLayerId theLayer,
12381341 10406 const Standard_Boolean theIsGlobal)
10407{
10408 if (theLightNew.IsNull())
10409 {
10410 return;
10411 }
10412
992ed6b3 10413 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10414 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
12381341 10415 {
992ed6b3 10416 aViewer->AddLight (theLightNew);
10417 if (theIsGlobal)
10418 {
10419 aViewer->SetLightOn (theLightNew);
10420 }
10421 else
10422 {
10423 ViewerTest::CurrentView()->SetLightOn (theLightNew);
10424 }
12381341 10425 }
10426 else
10427 {
992ed6b3 10428 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
10429 if (aSettings.Lights().IsNull())
10430 {
10431 aSettings.SetLights (new Graphic3d_LightSet());
10432 }
10433 aSettings.Lights()->Add (theLightNew);
10434 aViewer->SetZLayerSettings (theLayer, aSettings);
12381341 10435 }
10436}
10437
10438//! Auxiliary method
10439inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
10440{
10441 TCollection_AsciiString anArgNextCase (theArgNext);
10442 anArgNextCase.UpperCase();
10443 if (anArgNextCase.Length() > 5
10444 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
10445 {
10446 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
10447 }
10448 else
10449 {
10450 return theArgNext.IntegerValue();
10451 }
10452}
10453
10454//===============================================================================================
10455//function : VLight
10456//purpose :
10457//===============================================================================================
10458static int VLight (Draw_Interpretor& theDi,
10459 Standard_Integer theArgsNb,
10460 const char** theArgVec)
10461{
10462 Handle(V3d_View) aView = ViewerTest::CurrentView();
10463 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10464 if (aView.IsNull()
10465 || aViewer.IsNull())
10466 {
10467 std::cerr << "No active viewer!\n";
10468 return 1;
10469 }
10470
ee2be2a8 10471 Standard_Real anXYZ[3] = {};
10472 Standard_Real anAtten[2] = {};
12381341 10473 if (theArgsNb < 2)
10474 {
10475 // print lights info
10476 Standard_Integer aLightId = 0;
6a24c6de 10477 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
12381341 10478 {
6a24c6de 10479 Handle(V3d_Light) aLight = aLightIter.Value();
12381341 10480 const Quantity_Color aColor = aLight->Color();
992ed6b3 10481 theDi << "Light #" << aLightId
10482 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
10483 << " [" << aLight->GetId() << "]" << "\n";
12381341 10484 switch (aLight->Type())
10485 {
10486 case V3d_AMBIENT:
10487 {
189f85a3 10488 theDi << " Type: Ambient\n";
10489 theDi << " Intensity: " << aLight->Intensity() << "\n";
12381341 10490 break;
10491 }
10492 case V3d_DIRECTIONAL:
10493 {
189f85a3 10494 theDi << " Type: Directional\n";
10495 theDi << " Intensity: " << aLight->Intensity() << "\n";
10496 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10497 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
992ed6b3 10498 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10499 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
12381341 10500 break;
10501 }
10502 case V3d_POSITIONAL:
10503 {
189f85a3 10504 theDi << " Type: Positional\n";
10505 theDi << " Intensity: " << aLight->Intensity() << "\n";
10506 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
10507 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
992ed6b3 10508 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10509 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10510 aLight->Attenuation (anAtten[0], anAtten[1]);
10511 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
12381341 10512 break;
10513 }
10514 case V3d_SPOT:
10515 {
189f85a3 10516 theDi << " Type: Spot\n";
10517 theDi << " Intensity: " << aLight->Intensity() << "\n";
10518 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
992ed6b3 10519 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
10520 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10521 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
10522 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
10523 aLight->Attenuation (anAtten[0], anAtten[1]);
10524 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
10525 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
10526 theDi << " Exponent: " << aLight->Concentration() << "\n";
12381341 10527 break;
10528 }
10529 default:
10530 {
189f85a3 10531 theDi << " Type: UNKNOWN\n";
12381341 10532 break;
10533 }
10534 }
992ed6b3 10535 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
12381341 10536 }
10537 }
10538
10539 Handle(V3d_Light) aLightNew;
10540 Handle(V3d_Light) aLightOld;
992ed6b3 10541 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
12381341 10542 Standard_Boolean isGlobal = Standard_True;
10543 Standard_Boolean toCreate = Standard_False;
761d8807 10544 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
12381341 10545 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
10546 {
992ed6b3 10547 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
12381341 10548
10549 TCollection_AsciiString aName, aValue;
10550 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
10551 TCollection_AsciiString anArgCase (anArg);
10552 anArgCase.UpperCase();
761d8807 10553 if (anUpdateTool.parseRedrawMode (anArg))
10554 {
10555 continue;
10556 }
10557
12381341 10558 if (anArgCase.IsEqual ("NEW")
10559 || anArgCase.IsEqual ("ADD")
992ed6b3 10560 || anArgCase.IsEqual ("CREATE")
10561 || anArgCase.IsEqual ("-NEW")
10562 || anArgCase.IsEqual ("-ADD")
10563 || anArgCase.IsEqual ("-CREATE"))
12381341 10564 {
10565 toCreate = Standard_True;
10566 }
992ed6b3 10567 else if (anArgCase.IsEqual ("-LAYER")
10568 || anArgCase.IsEqual ("-ZLAYER"))
10569 {
10570 if (++anArgIt >= theArgsNb)
10571 {
10572 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10573 return 1;
10574 }
10575
10576 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
10577 aValStr.LowerCase();
10578 if (aValStr == "default"
10579 || aValStr == "def")
10580 {
10581 aLayer = Graphic3d_ZLayerId_Default;
10582 }
10583 else if (aValStr == "top")
10584 {
10585 aLayer = Graphic3d_ZLayerId_Top;
10586 }
10587 else if (aValStr == "topmost")
10588 {
10589 aLayer = Graphic3d_ZLayerId_Topmost;
10590 }
10591 else if (aValStr == "toposd"
10592 || aValStr == "osd")
10593 {
10594 aLayer = Graphic3d_ZLayerId_TopOSD;
10595 }
10596 else if (aValStr == "botosd"
10597 || aValStr == "bottom")
10598 {
10599 aLayer = Graphic3d_ZLayerId_BotOSD;
10600 }
10601 else if (aValStr.IsIntegerValue())
10602 {
10603 aLayer = Draw::Atoi (theArgVec[anArgIt]);
10604 }
10605 else
10606 {
10607 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
10608 return 1;
10609 }
10610 }
12381341 10611 else if (anArgCase.IsEqual ("GLOB")
992ed6b3 10612 || anArgCase.IsEqual ("GLOBAL")
10613 || anArgCase.IsEqual ("-GLOB")
10614 || anArgCase.IsEqual ("-GLOBAL"))
12381341 10615 {
10616 isGlobal = Standard_True;
10617 }
10618 else if (anArgCase.IsEqual ("LOC")
992ed6b3 10619 || anArgCase.IsEqual ("LOCAL")
10620 || anArgCase.IsEqual ("-LOC")
10621 || anArgCase.IsEqual ("-LOCAL"))
12381341 10622 {
10623 isGlobal = Standard_False;
10624 }
4fe9ad57 10625 else if (anArgCase.IsEqual ("DEF")
992ed6b3 10626 || anArgCase.IsEqual ("DEFAULTS")
10627 || anArgCase.IsEqual ("-DEF")
10628 || anArgCase.IsEqual ("-DEFAULTS"))
4fe9ad57 10629 {
10630 toCreate = Standard_False;
10631 aViewer->SetDefaultLights();
10632 }
10633 else if (anArgCase.IsEqual ("CLR")
992ed6b3 10634 || anArgCase.IsEqual ("CLEAR")
10635 || anArgCase.IsEqual ("-CLR")
10636 || anArgCase.IsEqual ("-CLEAR"))
4fe9ad57 10637 {
10638 toCreate = Standard_False;
992ed6b3 10639
10640 TColStd_SequenceOfInteger aLayers;
10641 aViewer->GetAllZLayers (aLayers);
10642 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4fe9ad57 10643 {
992ed6b3 10644 if (aLayeriter.Value() == aLayer
10645 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10646 {
10647 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10648 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10649 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10650 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10651 {
10652 break;
10653 }
10654 }
10655 }
10656
10657 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10658 {
10659 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
10660 {
10661 Handle(V3d_Light) aLight = aLightIter.Value();
10662 aViewer->DelLight (aLight);
10663 aLightIter = aView->ActiveLightIterator();
10664 }
4fe9ad57 10665 }
10666 }
12381341 10667 else if (anArgCase.IsEqual ("AMB")
10668 || anArgCase.IsEqual ("AMBIENT")
10669 || anArgCase.IsEqual ("AMBLIGHT"))
10670 {
12381341 10671 if (!toCreate)
10672 {
10673 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10674 return 1;
10675 }
992ed6b3 10676
10677 addLight (aLightNew, aLayer, isGlobal);
12381341 10678 toCreate = Standard_False;
992ed6b3 10679 aLightNew = new V3d_AmbientLight();
12381341 10680 }
10681 else if (anArgCase.IsEqual ("DIRECTIONAL")
10682 || anArgCase.IsEqual ("DIRLIGHT"))
10683 {
12381341 10684 if (!toCreate)
10685 {
10686 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10687 return 1;
10688 }
992ed6b3 10689
10690 addLight (aLightNew, aLayer, isGlobal);
12381341 10691 toCreate = Standard_False;
992ed6b3 10692 aLightNew = new V3d_DirectionalLight();
12381341 10693 }
10694 else if (anArgCase.IsEqual ("SPOT")
10695 || anArgCase.IsEqual ("SPOTLIGHT"))
10696 {
12381341 10697 if (!toCreate)
10698 {
10699 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10700 return 1;
10701 }
992ed6b3 10702
10703 addLight (aLightNew, aLayer, isGlobal);
12381341 10704 toCreate = Standard_False;
992ed6b3 10705 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
12381341 10706 }
10707 else if (anArgCase.IsEqual ("POSLIGHT")
10708 || anArgCase.IsEqual ("POSITIONAL"))
10709 {
12381341 10710 if (!toCreate)
10711 {
10712 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10713 return 1;
10714 }
992ed6b3 10715
10716 addLight (aLightNew, aLayer, isGlobal);
12381341 10717 toCreate = Standard_False;
992ed6b3 10718 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
12381341 10719 }
992ed6b3 10720 else if (anArgCase.IsEqual ("CHANGE")
10721 || anArgCase.IsEqual ("-CHANGE"))
12381341 10722 {
12381341 10723 if (++anArgIt >= theArgsNb)
10724 {
10725 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10726 return 1;
10727 }
10728
992ed6b3 10729 addLight (aLightNew, aLayer, isGlobal);
10730 aLightNew.Nullify();
12381341 10731 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
10732 Standard_Integer aLightIt = 0;
6a24c6de 10733 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
12381341 10734 {
10735 if (aLightIt == aLightId)
10736 {
6a24c6de 10737 aLightOld = aLightIter.Value();
12381341 10738 break;
10739 }
10740 }
10741
10742 if (aLightOld.IsNull())
10743 {
10744 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
10745 return 1;
10746 }
10747 }
10748 else if (anArgCase.IsEqual ("DEL")
992ed6b3 10749 || anArgCase.IsEqual ("DELETE")
10750 || anArgCase.IsEqual ("-DEL")
10751 || anArgCase.IsEqual ("-DELETE"))
12381341 10752 {
10753 Handle(V3d_Light) aLightDel;
10754 if (++anArgIt >= theArgsNb)
10755 {
10756 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10757 return 1;
10758 }
10759
10760 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10761 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
10762 Standard_Integer aLightIt = 0;
6a24c6de 10763 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
12381341 10764 {
6a24c6de 10765 aLightDel = aLightIter.Value();
12381341 10766 if (aLightIt == aLightDelId)
10767 {
10768 break;
10769 }
10770 }
992ed6b3 10771 if (aLightDel.IsNull())
10772 {
10773 continue;
10774 }
10775
10776 TColStd_SequenceOfInteger aLayers;
10777 aViewer->GetAllZLayers (aLayers);
10778 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10779 {
10780 if (aLayeriter.Value() == aLayer
10781 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10782 {
10783 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10784 if (!aSettings.Lights().IsNull())
10785 {
10786 aSettings.Lights()->Remove (aLightDel);
10787 if (aSettings.Lights()->IsEmpty())
10788 {
10789 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10790 }
10791 }
10792 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10793 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10794 {
10795 break;
10796 }
10797 }
10798 }
10799
10800 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
12381341 10801 {
10802 aViewer->DelLight (aLightDel);
10803 }
10804 }
10805 else if (anArgCase.IsEqual ("COLOR")
992ed6b3 10806 || anArgCase.IsEqual ("COLOUR")
10807 || anArgCase.IsEqual ("-COLOR")
10808 || anArgCase.IsEqual ("-COLOUR"))
12381341 10809 {
992ed6b3 10810 if (++anArgIt >= theArgsNb
10811 || aLightCurr.IsNull())
12381341 10812 {
10813 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10814 return 1;
10815 }
10816
10817 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10818 anArgNext.UpperCase();
10819 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
992ed6b3 10820 aLightCurr->SetColor (aColor);
12381341 10821 }
10822 else if (anArgCase.IsEqual ("POS")
992ed6b3 10823 || anArgCase.IsEqual ("POSITION")
10824 || anArgCase.IsEqual ("-POS")
10825 || anArgCase.IsEqual ("-POSITION"))
12381341 10826 {
992ed6b3 10827 if ((anArgIt + 3) >= theArgsNb
10828 || aLightCurr.IsNull()
10829 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10830 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 10831 {
10832 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10833 return 1;
10834 }
10835
10836 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10837 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10838 anXYZ[2] = Atof (theArgVec[++anArgIt]);
992ed6b3 10839 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
12381341 10840 }
10841 else if (anArgCase.IsEqual ("DIR")
992ed6b3 10842 || anArgCase.IsEqual ("DIRECTION")
10843 || anArgCase.IsEqual ("-DIR")
10844 || anArgCase.IsEqual ("-DIRECTION"))
12381341 10845 {
992ed6b3 10846 if ((anArgIt + 3) >= theArgsNb
10847 || aLightCurr.IsNull()
10848 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
10849 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 10850 {
10851 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10852 return 1;
10853 }
10854
10855 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10856 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10857 anXYZ[2] = Atof (theArgVec[++anArgIt]);
992ed6b3 10858 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
12381341 10859 }
189f85a3 10860 else if (anArgCase.IsEqual ("SM")
992ed6b3 10861 || anArgCase.IsEqual ("SMOOTHNESS")
10862 || anArgCase.IsEqual ("-SM")
10863 || anArgCase.IsEqual ("-SMOOTHNESS"))
189f85a3 10864 {
992ed6b3 10865 if (++anArgIt >= theArgsNb
10866 || aLightCurr.IsNull())
189f85a3 10867 {
10868 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10869 return 1;
10870 }
10871
992ed6b3 10872 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10873 if (Abs (aSmoothness) <= ShortRealEpsilon())
189f85a3 10874 {
10875 aLightCurr->SetIntensity (1.f);
10876 }
992ed6b3 10877 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
189f85a3 10878 {
10879 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
10880 }
10881 else
10882 {
10883 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
10884 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
10885 }
10886
992ed6b3 10887 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
189f85a3 10888 {
992ed6b3 10889 aLightCurr->SetSmoothRadius (aSmoothness);
189f85a3 10890 }
992ed6b3 10891 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
189f85a3 10892 {
992ed6b3 10893 aLightCurr->SetSmoothAngle (aSmoothness);
189f85a3 10894 }
10895 }
10896 else if (anArgCase.IsEqual ("INT")
992ed6b3 10897 || anArgCase.IsEqual ("INTENSITY")
10898 || anArgCase.IsEqual ("-INT")
10899 || anArgCase.IsEqual ("-INTENSITY"))
189f85a3 10900 {
992ed6b3 10901 if (++anArgIt >= theArgsNb
10902 || aLightCurr.IsNull())
189f85a3 10903 {
10904 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10905 return 1;
10906 }
10907
992ed6b3 10908 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10909 aLightCurr->SetIntensity (aIntensity);
189f85a3 10910 }
4fe9ad57 10911 else if (anArgCase.IsEqual ("ANG")
992ed6b3 10912 || anArgCase.IsEqual ("ANGLE")
10913 || anArgCase.IsEqual ("-ANG")
10914 || anArgCase.IsEqual ("-ANGLE"))
4fe9ad57 10915 {
992ed6b3 10916 if (++anArgIt >= theArgsNb
10917 || aLightCurr.IsNull()
10918 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
4fe9ad57 10919 {
10920 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10921 return 1;
10922 }
10923
992ed6b3 10924 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10925 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
4fe9ad57 10926 }
12381341 10927 else if (anArgCase.IsEqual ("CONSTATTEN")
992ed6b3 10928 || anArgCase.IsEqual ("CONSTATTENUATION")
10929 || anArgCase.IsEqual ("-CONSTATTEN")
10930 || anArgCase.IsEqual ("-CONSTATTENUATION"))
12381341 10931 {
992ed6b3 10932 if (++anArgIt >= theArgsNb
10933 || aLightCurr.IsNull()
10934 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10935 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 10936 {
10937 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10938 return 1;
10939 }
10940
992ed6b3 10941 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10942 anAtten[0] = Atof (theArgVec[anArgIt]);
10943 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
12381341 10944 }
10945 else if (anArgCase.IsEqual ("LINATTEN")
10946 || anArgCase.IsEqual ("LINEARATTEN")
992ed6b3 10947 || anArgCase.IsEqual ("LINEARATTENUATION")
10948 || anArgCase.IsEqual ("-LINATTEN")
10949 || anArgCase.IsEqual ("-LINEARATTEN")
10950 || anArgCase.IsEqual ("-LINEARATTENUATION"))
12381341 10951 {
992ed6b3 10952 if (++anArgIt >= theArgsNb
10953 || aLightCurr.IsNull()
10954 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10955 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
12381341 10956 {
10957 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10958 return 1;
10959 }
10960
992ed6b3 10961 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10962 anAtten[1] = Atof (theArgVec[anArgIt]);
10963 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
12381341 10964 }
10965 else if (anArgCase.IsEqual ("EXP")
10966 || anArgCase.IsEqual ("EXPONENT")
10967 || anArgCase.IsEqual ("SPOTEXP")
992ed6b3 10968 || anArgCase.IsEqual ("SPOTEXPONENT")
10969 || anArgCase.IsEqual ("-EXP")
10970 || anArgCase.IsEqual ("-EXPONENT")
10971 || anArgCase.IsEqual ("-SPOTEXP")
10972 || anArgCase.IsEqual ("-SPOTEXPONENT"))
12381341 10973 {
992ed6b3 10974 if (++anArgIt >= theArgsNb
10975 || aLightCurr.IsNull()
10976 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
12381341 10977 {
10978 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10979 return 1;
10980 }
10981
992ed6b3 10982 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
12381341 10983 }
10984 else if (anArgCase.IsEqual ("HEAD")
992ed6b3 10985 || anArgCase.IsEqual ("HEADLIGHT")
10986 || anArgCase.IsEqual ("-HEAD")
10987 || anArgCase.IsEqual ("-HEADLIGHT"))
12381341 10988 {
992ed6b3 10989 if (aLightCurr.IsNull()
10990 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
12381341 10991 {
10992 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10993 return 1;
10994 }
10995
992ed6b3 10996 Standard_Boolean isHeadLight = Standard_True;
10997 if (anArgIt + 1 < theArgsNb
10998 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
12381341 10999 {
992ed6b3 11000 ++anArgIt;
12381341 11001 }
992ed6b3 11002 aLightCurr->SetHeadlight (isHeadLight);
12381341 11003 }
11004 else
11005 {
11006 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
11007 }
11008 }
11009
992ed6b3 11010 addLight (aLightNew, aLayer, isGlobal);
12381341 11011 return 0;
11012}
11013
15669413 11014//! Read Graphic3d_RenderingParams::PerfCounters flag.
11015static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
11016 Standard_Boolean& theToReset,
11017 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
11018 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
11019{
11020 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
11021 TCollection_AsciiString aVal = theValue;
11022 Standard_Boolean toReverse = Standard_False;
11023 if (aVal == "none")
11024 {
11025 theToReset = Standard_True;
11026 return Standard_True;
11027 }
11028 else if (aVal.StartsWith ("-"))
11029 {
11030 toReverse = Standard_True;
11031 aVal = aVal.SubString (2, aVal.Length());
11032 }
11033 else if (aVal.StartsWith ("no"))
11034 {
11035 toReverse = Standard_True;
11036 aVal = aVal.SubString (3, aVal.Length());
11037 }
11038 else if (aVal.StartsWith ("+"))
11039 {
11040 aVal = aVal.SubString (2, aVal.Length());
11041 }
11042 else
11043 {
11044 theToReset = Standard_True;
11045 }
11046
11047 if ( aVal == "fps"
11048 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11049 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
11050 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
11051 else if (aVal == "structs"
11052 || aVal == "structures"
11053 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
11054 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
11055 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11056 else if (aVal == "tris"
11057 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
11058 else if (aVal == "pnts"
11059 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
11060 else if (aVal == "mem"
11061 || aVal == "gpumem"
11062 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
5e30547b 11063 else if (aVal == "skipimmediate"
11064 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
11065 else if (aVal == "frametime"
11066 || aVal == "frametimers"
11067 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
15669413 11068 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
11069 else if (aVal == "extended"
11070 || aVal == "verbose"
11071 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
5e30547b 11072 else if (aVal == "full"
11073 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
15669413 11074 else
11075 {
11076 return Standard_False;
11077 }
11078
11079 if (toReverse)
11080 {
11081 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
11082 }
11083 else
11084 {
11085 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
11086 }
11087 return Standard_True;
11088}
11089
11090//! Read Graphic3d_RenderingParams::PerfCounters flags.
11091static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
11092 Graphic3d_RenderingParams::PerfCounters& theFlags)
11093{
11094 TCollection_AsciiString aValue = theValue;
11095 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
11096 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
11097 Standard_Boolean toReset = Standard_False;
11098 for (;;)
11099 {
11100 Standard_Integer aSplitPos = aValue.Search ("|");
11101 if (aSplitPos <= 0)
11102 {
11103 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
11104 {
11105 return Standard_False;
11106 }
11107 if (toReset)
11108 {
11109 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
11110 }
11111 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
11112 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
11113 return Standard_True;
11114 }
11115
11116 if (aSplitPos > 1)
11117 {
11118 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
11119 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
11120 {
11121 return Standard_False;
11122 }
11123 }
11124 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
11125 }
11126}
11127
e276548b 11128//=======================================================================
bc8c79bb 11129//function : VRenderParams
11130//purpose : Enables/disables rendering features
e276548b 11131//=======================================================================
11132
bc8c79bb 11133static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
11134 Standard_Integer theArgNb,
11135 const char** theArgVec)
e276548b 11136{
7ae4a307 11137 Handle(V3d_View) aView = ViewerTest::CurrentView();
11138 if (aView.IsNull())
e276548b 11139 {
bc8c79bb 11140 std::cerr << "Error: no active viewer!\n";
e276548b 11141 return 1;
11142 }
bc8c79bb 11143
11144 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
6b62b2da 11145 TCollection_AsciiString aCmdName (theArgVec[0]);
11146 aCmdName.LowerCase();
11147 if (aCmdName == "vraytrace")
11148 {
11149 if (theArgNb == 1)
11150 {
11151 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
11152 return 0;
11153 }
11154 else if (theArgNb == 2)
11155 {
11156 TCollection_AsciiString aValue (theArgVec[1]);
11157 aValue.LowerCase();
11158 if (aValue == "on"
11159 || aValue == "1")
11160 {
11161 aParams.Method = Graphic3d_RM_RAYTRACING;
11162 aView->Redraw();
11163 return 0;
11164 }
11165 else if (aValue == "off"
11166 || aValue == "0")
11167 {
11168 aParams.Method = Graphic3d_RM_RASTERIZATION;
11169 aView->Redraw();
11170 return 0;
11171 }
11172 else
11173 {
11174 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
11175 return 1;
11176 }
11177 }
11178 else
11179 {
11180 std::cout << "Error: wrong number of arguments\n";
11181 return 1;
11182 }
11183 }
bc8c79bb 11184
11185 if (theArgNb < 2)
e276548b 11186 {
bc8c79bb 11187 theDI << "renderMode: ";
11188 switch (aParams.Method)
11189 {
11190 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11191 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
11192 }
11193 theDI << "\n";
a1073ae2 11194 theDI << "transparency: ";
11195 switch (aParams.TransparencyMethod)
11196 {
11197 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
11198 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
11199 << TCollection_AsciiString (aParams.OitDepthFactor); break;
11200 }
11201 theDI << "\n";
b4327ba8 11202 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
56689b27 11203 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
b4327ba8 11204 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
11205 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
11206 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
11207 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
11208 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
11209 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
11210 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
11211 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
11212 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
11213 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
b09447ed 11214 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
4eaaf9d8 11215 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
66d1cdc6 11216 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
8625ef7e 11217 theDI << "shadingModel: ";
11218 switch (aView->ShadingModel())
11219 {
dc89236f 11220 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11221 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
11222 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
11223 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
11224 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
8625ef7e 11225 }
15669413 11226 {
11227 theDI << "perfCounters:";
11228 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
11229 {
11230 theDI << " fps";
11231 }
11232 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
11233 {
11234 theDI << " cpu";
11235 }
11236 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
11237 {
11238 theDI << " structs";
11239 }
11240 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
11241 {
11242 theDI << " groups";
11243 }
11244 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
11245 {
11246 theDI << " arrays";
11247 }
11248 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
11249 {
11250 theDI << " tris";
11251 }
11252 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
11253 {
11254 theDI << " pnts";
11255 }
11256 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
11257 {
11258 theDI << " gpumem";
11259 }
5e30547b 11260 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
11261 {
11262 theDI << " frameTime";
11263 }
11264 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
11265 {
11266 theDI << " skipimmediate";
11267 }
15669413 11268 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
11269 {
11270 theDI << " none";
11271 }
11272 theDI << "\n";
11273 }
f88457e6 11274 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
c40eb6b9 11275 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
0e3025bc 11276 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
11277 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
11278 "noUpdate") << "\n";
8625ef7e 11279 theDI << "\n";
bc8c79bb 11280 return 0;
e276548b 11281 }
11282
bc8c79bb 11283 Standard_Boolean toPrint = Standard_False;
8625ef7e 11284 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
e276548b 11285 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11286 {
bc8c79bb 11287 Standard_CString anArg (theArgVec[anArgIter]);
11288 TCollection_AsciiString aFlag (anArg);
11289 aFlag.LowerCase();
8625ef7e 11290 if (anUpdateTool.parseRedrawMode (aFlag))
11291 {
11292 continue;
11293 }
11294 else if (aFlag == "-echo"
11295 || aFlag == "-print")
e276548b 11296 {
bc8c79bb 11297 toPrint = Standard_True;
8625ef7e 11298 anUpdateTool.Invalidate();
e276548b 11299 }
bc8c79bb 11300 else if (aFlag == "-mode"
11301 || aFlag == "-rendermode"
11302 || aFlag == "-render_mode")
e276548b 11303 {
bc8c79bb 11304 if (toPrint)
11305 {
11306 switch (aParams.Method)
11307 {
11308 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
11309 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
11310 }
11311 continue;
11312 }
e276548b 11313 else
bc8c79bb 11314 {
11315 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11316 return 1;
11317 }
11318 }
11319 else if (aFlag == "-ray"
11320 || aFlag == "-raytrace")
11321 {
11322 if (toPrint)
11323 {
11324 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
11325 continue;
11326 }
11327
11328 aParams.Method = Graphic3d_RM_RAYTRACING;
e276548b 11329 }
bc8c79bb 11330 else if (aFlag == "-rast"
11331 || aFlag == "-raster"
11332 || aFlag == "-rasterization")
e276548b 11333 {
bc8c79bb 11334 if (toPrint)
11335 {
11336 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
11337 continue;
11338 }
11339
11340 aParams.Method = Graphic3d_RM_RASTERIZATION;
11341 }
3c4b62a4 11342 else if (aFlag == "-msaa")
11343 {
11344 if (toPrint)
11345 {
11346 theDI << aParams.NbMsaaSamples << " ";
11347 continue;
11348 }
11349 else if (++anArgIter >= theArgNb)
11350 {
11351 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11352 return 1;
11353 }
11354
11355 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
11356 if (aNbSamples < 0)
11357 {
11358 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
11359 return 1;
11360 }
11361 else
11362 {
11363 aParams.NbMsaaSamples = aNbSamples;
11364 }
11365 }
2a332745 11366 else if (aFlag == "-linefeather"
11367 || aFlag == "-edgefeather"
11368 || aFlag == "-feather")
11369 {
11370 if (toPrint)
11371 {
11372 theDI << " " << aParams.LineFeather << " ";
11373 continue;
11374 }
11375 else if (++anArgIter >= theArgNb)
11376 {
11377 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11378 return 1;
11379 }
11380
11381 TCollection_AsciiString aParam = theArgVec[anArgIter];
11382 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11383 if (aFeather <= 0.0f)
11384 {
11385 std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n";
11386 return 1;
11387 }
11388 aParams.LineFeather = aFeather;
11389 }
a1073ae2 11390 else if (aFlag == "-oit")
11391 {
11392 if (toPrint)
11393 {
11394 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
11395 {
11396 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
11397 }
11398 else
11399 {
11400 theDI << "off" << " ";
11401 }
11402 continue;
11403 }
11404 else if (++anArgIter >= theArgNb)
11405 {
11406 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11407 return 1;
11408 }
11409
11410 TCollection_AsciiString aParam = theArgVec[anArgIter];
11411 aParam.LowerCase();
11412 if (aParam.IsRealValue())
11413 {
11414 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11415 if (aWeight < 0.f || aWeight > 1.f)
11416 {
11417 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
11418 return 1;
11419 }
11420
11421 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
11422 aParams.OitDepthFactor = aWeight;
11423 }
11424 else if (aParam == "off")
11425 {
11426 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
11427 }
11428 else
11429 {
11430 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11431 return 1;
11432 }
11433 }
f88457e6 11434 else if (aFlag == "-depthprepass")
11435 {
11436 if (toPrint)
11437 {
11438 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
11439 continue;
11440 }
11441 aParams.ToEnableDepthPrepass = Standard_True;
11442 if (anArgIter + 1 < theArgNb
11443 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
11444 {
11445 ++anArgIter;
11446 }
11447 }
c40eb6b9 11448 else if (aFlag == "-samplealphatocoverage"
11449 || aFlag == "-alphatocoverage")
11450 {
11451 if (toPrint)
11452 {
11453 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
11454 continue;
11455 }
11456 aParams.ToEnableAlphaToCoverage = Standard_True;
11457 if (anArgIter + 1 < theArgNb
11458 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
11459 {
11460 ++anArgIter;
11461 }
11462 }
56689b27 11463 else if (aFlag == "-rendscale"
11464 || aFlag == "-renderscale"
11465 || aFlag == "-renderresolutionscale")
11466 {
11467 if (toPrint)
11468 {
11469 theDI << aParams.RenderResolutionScale << " ";
11470 continue;
11471 }
11472 else if (++anArgIter >= theArgNb)
11473 {
11474 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11475 return 1;
11476 }
11477
11478 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
11479 if (aScale < 0.01)
11480 {
11481 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
11482 return 1;
11483 }
11484 else
11485 {
11486 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
11487 }
11488 }
bc8c79bb 11489 else if (aFlag == "-raydepth"
11490 || aFlag == "-ray_depth")
11491 {
11492 if (toPrint)
11493 {
11494 theDI << aParams.RaytracingDepth << " ";
11495 continue;
11496 }
11497 else if (++anArgIter >= theArgNb)
11498 {
11499 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11500 return 1;
11501 }
11502
11503 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
189f85a3 11504
11505 // We allow RaytracingDepth be more than 10 in case of GI enabled
11506 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
bc8c79bb 11507 {
11508 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
11509 return 1;
11510 }
e276548b 11511 else
bc8c79bb 11512 {
11513 aParams.RaytracingDepth = aDepth;
11514 }
11515 }
11516 else if (aFlag == "-shad"
11517 || aFlag == "-shadows")
11518 {
11519 if (toPrint)
11520 {
11521 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
11522 continue;
11523 }
11524
11525 Standard_Boolean toEnable = Standard_True;
11526 if (++anArgIter < theArgNb
a5565a3c 11527 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 11528 {
11529 --anArgIter;
11530 }
11531 aParams.IsShadowEnabled = toEnable;
11532 }
11533 else if (aFlag == "-refl"
11534 || aFlag == "-reflections")
11535 {
11536 if (toPrint)
11537 {
11538 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
11539 continue;
11540 }
11541
11542 Standard_Boolean toEnable = Standard_True;
11543 if (++anArgIter < theArgNb
a5565a3c 11544 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 11545 {
11546 --anArgIter;
11547 }
11548 aParams.IsReflectionEnabled = toEnable;
11549 }
11550 else if (aFlag == "-fsaa")
11551 {
11552 if (toPrint)
11553 {
11554 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
11555 continue;
11556 }
11557
11558 Standard_Boolean toEnable = Standard_True;
11559 if (++anArgIter < theArgNb
a5565a3c 11560 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 11561 {
11562 --anArgIter;
11563 }
11564 aParams.IsAntialiasingEnabled = toEnable;
11565 }
11566 else if (aFlag == "-gleam")
11567 {
11568 if (toPrint)
11569 {
11570 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
11571 continue;
11572 }
11573
11574 Standard_Boolean toEnable = Standard_True;
11575 if (++anArgIter < theArgNb
a5565a3c 11576 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
bc8c79bb 11577 {
11578 --anArgIter;
11579 }
11580 aParams.IsTransparentShadowEnabled = toEnable;
e276548b 11581 }
189f85a3 11582 else if (aFlag == "-gi")
11583 {
11584 if (toPrint)
11585 {
11586 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
11587 continue;
11588 }
11589
11590 Standard_Boolean toEnable = Standard_True;
11591 if (++anArgIter < theArgNb
a5565a3c 11592 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
189f85a3 11593 {
11594 --anArgIter;
11595 }
11596 aParams.IsGlobalIlluminationEnabled = toEnable;
11597 if (!toEnable)
11598 {
11599 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
11600 }
11601 }
8c820969 11602 else if (aFlag == "-blockedrng"
11603 || aFlag == "-brng")
11604 {
11605 if (toPrint)
11606 {
11607 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
11608 continue;
11609 }
11610
11611 Standard_Boolean toEnable = Standard_True;
11612 if (++anArgIter < theArgNb
a5565a3c 11613 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8c820969 11614 {
11615 --anArgIter;
11616 }
11617 aParams.CoherentPathTracingMode = toEnable;
11618 }
b09447ed 11619 else if (aFlag == "-maxrad")
11620 {
11621 if (toPrint)
11622 {
11623 theDI << aParams.RadianceClampingValue << " ";
11624 continue;
11625 }
11626 else if (++anArgIter >= theArgNb)
11627 {
11628 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11629 return 1;
11630 }
11631
11632 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
11633 if (!aMaxRadStr.IsRealValue())
11634 {
11635 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11636 return 1;
11637 }
11638
11639 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
11640 if (aMaxRadiance <= 0.0)
11641 {
11642 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
11643 return 1;
11644 }
11645 else
11646 {
11647 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
11648 }
11649 }
3a9b5dc8 11650 else if (aFlag == "-iss")
11651 {
11652 if (toPrint)
11653 {
11654 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
11655 continue;
11656 }
11657
11658 Standard_Boolean toEnable = Standard_True;
11659 if (++anArgIter < theArgNb
11660 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11661 {
11662 --anArgIter;
11663 }
11664 aParams.AdaptiveScreenSampling = toEnable;
11665 }
e084dbbc 11666 else if (aFlag == "-issatomic")
11667 {
11668 if (toPrint)
11669 {
11670 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
11671 continue;
11672 }
11673
11674 Standard_Boolean toEnable = Standard_True;
11675 if (++anArgIter < theArgNb
11676 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11677 {
11678 --anArgIter;
11679 }
11680 aParams.AdaptiveScreenSamplingAtomic = toEnable;
11681 }
3a9b5dc8 11682 else if (aFlag == "-issd")
11683 {
11684 if (toPrint)
11685 {
11686 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
11687 continue;
11688 }
11689
11690 Standard_Boolean toEnable = Standard_True;
11691 if (++anArgIter < theArgNb
11692 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11693 {
11694 --anArgIter;
11695 }
11696 aParams.ShowSamplingTiles = toEnable;
11697 }
66d1cdc6 11698 else if (aFlag == "-tilesize")
11699 {
11700 if (toPrint)
11701 {
11702 theDI << aParams.RayTracingTileSize << " ";
11703 continue;
11704 }
11705 else if (++anArgIter >= theArgNb)
11706 {
11707 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11708 return 1;
11709 }
11710
11711 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
11712 if (aTileSize < 1)
11713 {
11714 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
11715 return 1;
11716 }
11717 aParams.RayTracingTileSize = aTileSize;
11718 }
4eaaf9d8 11719 else if (aFlag == "-nbtiles")
11720 {
11721 if (toPrint)
11722 {
11723 theDI << aParams.NbRayTracingTiles << " ";
11724 continue;
11725 }
11726 else if (++anArgIter >= theArgNb)
11727 {
11728 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11729 return 1;
11730 }
11731
11732 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
66d1cdc6 11733 if (aNbTiles < -1)
4eaaf9d8 11734 {
11735 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
4eaaf9d8 11736 return 1;
11737 }
66d1cdc6 11738 else if (aNbTiles > 0
11739 && (aNbTiles < 64
11740 || aNbTiles > 1024))
4eaaf9d8 11741 {
66d1cdc6 11742 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
4eaaf9d8 11743 }
66d1cdc6 11744 aParams.NbRayTracingTiles = aNbTiles;
4eaaf9d8 11745 }
189f85a3 11746 else if (aFlag == "-env")
11747 {
11748 if (toPrint)
11749 {
11750 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
11751 continue;
11752 }
11753
11754 Standard_Boolean toEnable = Standard_True;
11755 if (++anArgIter < theArgNb
a5565a3c 11756 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
189f85a3 11757 {
11758 --anArgIter;
11759 }
11760 aParams.UseEnvironmentMapBackground = toEnable;
11761 }
b4327ba8 11762 else if (aFlag == "-twoside")
11763 {
11764 if (toPrint)
11765 {
11766 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
11767 continue;
11768 }
11769
11770 Standard_Boolean toEnable = Standard_True;
11771 if (++anArgIter < theArgNb
11772 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11773 {
11774 --anArgIter;
11775 }
11776 aParams.TwoSidedBsdfModels = toEnable;
11777 }
8625ef7e 11778 else if (aFlag == "-shademodel"
11779 || aFlag == "-shadingmodel"
11780 || aFlag == "-shading")
11781 {
11782 if (toPrint)
11783 {
11784 switch (aView->ShadingModel())
11785 {
dc89236f 11786 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11787 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
11788 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
11789 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
11790 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
8625ef7e 11791 }
11792 continue;
11793 }
11794
11795 if (++anArgIter >= theArgNb)
11796 {
11797 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11798 }
11799
dc89236f 11800 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
11801 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
11802 && aModel != Graphic3d_TOSM_DEFAULT)
8625ef7e 11803 {
dc89236f 11804 aView->SetShadingModel (aModel);
8625ef7e 11805 }
11806 else
11807 {
dc89236f 11808 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
8625ef7e 11809 return 1;
11810 }
11811 }
4b1c8733 11812 else if (aFlag == "-resolution")
11813 {
11814 if (++anArgIter >= theArgNb)
11815 {
11816 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11817 return 1;
11818 }
11819
11820 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
11821 if (aResolution.IsIntegerValue())
11822 {
11823 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
11824 }
11825 else
11826 {
11827 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11828 return 1;
11829 }
11830 }
d877e610 11831 else if (aFlag == "-rebuildglsl"
11832 || aFlag == "-rebuild")
11833 {
11834 if (toPrint)
11835 {
11836 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
11837 continue;
11838 }
11839
11840 Standard_Boolean toEnable = Standard_True;
11841 if (++anArgIter < theArgNb
11842 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11843 {
11844 --anArgIter;
11845 }
11846 aParams.RebuildRayTracingShaders = toEnable;
11847 }
b27ab03d 11848 else if (aFlag == "-focal")
11849 {
11850 if (++anArgIter >= theArgNb)
11851 {
11852 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11853 return 1;
11854 }
11855
11856 TCollection_AsciiString aParam (theArgVec[anArgIter]);
11857 if (aParam.IsRealValue())
11858 {
11859 float aFocalDist = static_cast<float> (aParam.RealValue());
11860 if (aFocalDist < 0)
11861 {
11862 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
11863 return 1;
11864 }
11865 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
11866 }
11867 else
11868 {
11869 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11870 return 1;
11871 }
11872 }
11873 else if (aFlag == "-aperture")
11874 {
11875 if (++anArgIter >= theArgNb)
11876 {
11877 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11878 return 1;
11879 }
11880
11881 TCollection_AsciiString aParam(theArgVec[anArgIter]);
11882 if (aParam.IsRealValue())
11883 {
11884 float aApertureSize = static_cast<float> (aParam.RealValue());
11885 if (aApertureSize < 0)
11886 {
11887 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
11888 return 1;
11889 }
11890 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
11891 }
11892 else
11893 {
11894 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11895 return 1;
11896 }
11897 }
eb85ed36 11898 else if (aFlag == "-exposure")
11899 {
11900 if (++anArgIter >= theArgNb)
11901 {
11902 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11903 return 1;
11904 }
11905
11906 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
11907 if (anExposure.IsRealValue())
11908 {
11909 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
11910 }
11911 else
11912 {
11913 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11914 return 1;
11915 }
11916 }
11917 else if (aFlag == "-whitepoint")
11918 {
11919 if (++anArgIter >= theArgNb)
11920 {
11921 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11922 return 1;
11923 }
11924
11925 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
11926 if (aWhitePoint.IsRealValue())
11927 {
11928 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
11929 }
11930 else
11931 {
11932 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11933 return 1;
11934 }
11935 }
11936 else if (aFlag == "-tonemapping")
11937 {
11938 if (++anArgIter >= theArgNb)
11939 {
11940 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11941 return 1;
11942 }
11943
11944 TCollection_AsciiString aMode (theArgVec[anArgIter]);
11945 aMode.LowerCase();
11946
11947 if (aMode == "disabled")
11948 {
11949 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
11950 }
11951 else if (aMode == "filmic")
11952 {
11953 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
11954 }
11955 else
11956 {
11957 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11958 return 1;
11959 }
11960 }
15669413 11961 else if (aFlag == "-performancestats"
11962 || aFlag == "-performancecounters"
11963 || aFlag == "-perfstats"
11964 || aFlag == "-perfcounters"
11965 || aFlag == "-stats")
11966 {
11967 if (++anArgIter >= theArgNb)
11968 {
11969 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11970 return 1;
11971 }
11972
11973 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
11974 aFlagsStr.LowerCase();
11975 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
11976 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
11977 {
11978 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11979 return 1;
11980 }
11981 aView->ChangeRenderingParams().CollectedStats = aFlags;
11982 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
11983 }
11984 else if (aFlag == "-perfupdateinterval"
11985 || aFlag == "-statsupdateinterval")
11986 {
11987 if (++anArgIter >= theArgNb)
11988 {
11989 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11990 return 1;
11991 }
11992 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11993 }
5e30547b 11994 else if (aFlag == "-perfchart"
11995 || aFlag == "-statschart")
11996 {
11997 if (++anArgIter >= theArgNb)
11998 {
11999 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12000 return 1;
12001 }
12002 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
12003 }
12004 else if (aFlag == "-perfchartmax"
12005 || aFlag == "-statschartmax")
12006 {
12007 if (++anArgIter >= theArgNb)
12008 {
12009 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
12010 return 1;
12011 }
12012 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
12013 }
0e3025bc 12014 else if (aFlag == "-frustumculling"
12015 || aFlag == "-culling")
12016 {
12017 if (toPrint)
12018 {
12019 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
12020 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
12021 "noUpdate") << " ";
12022 continue;
12023 }
12024
12025 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
12026 if (++anArgIter < theArgNb)
12027 {
12028 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
12029 aStateStr.LowerCase();
12030 bool toEnable = true;
12031 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
12032 {
12033 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
12034 }
12035 else if (aStateStr == "noupdate"
12036 || aStateStr == "freeze")
12037 {
12038 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
12039 }
12040 else
12041 {
12042 --anArgIter;
12043 }
12044 }
12045 aParams.FrustumCullingState = aState;
12046 }
e276548b 12047 else
12048 {
bc8c79bb 12049 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
12050 return 1;
e276548b 12051 }
12052 }
189f85a3 12053
12054 return 0;
12055}
12056
79b544e6 12057//=======================================================================
12058//function : searchInfo
12059//purpose :
12060//=======================================================================
12061inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
12062 const TCollection_AsciiString& theKey)
12063{
12064 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
12065 {
12066 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
12067 {
12068 return anIter.Value();
12069 }
12070 }
12071 return TCollection_AsciiString();
12072}
12073
12074//=======================================================================
12075//function : VStatProfiler
12076//purpose :
12077//=======================================================================
12078static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
12079 Standard_Integer theArgNb,
12080 const char** theArgVec)
12081{
12082 Handle(V3d_View) aView = ViewerTest::CurrentView();
12083 if (aView.IsNull())
12084 {
12085 std::cerr << "Error: no active viewer!\n";
12086 return 1;
12087 }
12088
12089 Standard_Boolean toRedraw = Standard_True;
12090 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
12091 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
12092 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
12093 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12094 {
12095 Standard_CString anArg (theArgVec[anArgIter]);
12096 TCollection_AsciiString aFlag (anArg);
12097 aFlag.LowerCase();
12098 if (aFlag == "-noredraw")
12099 {
12100 toRedraw = Standard_False;
12101 }
12102 else
12103 {
12104 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
12105 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
12106 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
12107 else if (aFlag == "alllayers"
12108 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
12109 else if (aFlag == "allstructs"
12110 || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
12111 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
12112 else if (aFlag == "allarrays"
12113 || aFlag == "fillarrays"
12114 || aFlag == "linearrays"
12115 || aFlag == "pointarrays"
12116 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
12117 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
12118 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
12119 else if (aFlag == "geommem"
12120 || aFlag == "texturemem"
12121 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
12122 else if (aFlag == "elapsedframe"
12123 || aFlag == "cpuframeaverage"
12124 || aFlag == "cpupickingaverage"
12125 || aFlag == "cpucullingaverage"
12126 || aFlag == "cpudynaverage"
12127 || aFlag == "cpuframemax"
12128 || aFlag == "cpupickingmax"
12129 || aFlag == "cpucullingmax"
12130 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
12131 else
12132 {
12133 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
12134 continue;
12135 }
12136
12137 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
12138 }
12139 }
12140
12141 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
12142 {
12143 aView->ChangeRenderingParams().CollectedStats =
12144 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
12145
12146 if (toRedraw)
12147 {
12148 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12149 aView->Redraw();
12150 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12151 }
12152
12153 TColStd_IndexedDataMapOfStringString aDict;
12154 aView->StatisticInformation (aDict);
12155
12156 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
12157
12158 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12159 {
12160 Standard_CString anArg(theArgVec[anArgIter]);
12161 TCollection_AsciiString aFlag(anArg);
12162 aFlag.LowerCase();
12163 if (aFlag == "fps")
12164 {
12165 theDI << searchInfo (aDict, "FPS") << " ";
12166 }
12167 else if (aFlag == "cpu")
12168 {
12169 theDI << searchInfo (aDict, "CPU FPS") << " ";
12170 }
12171 else if (aFlag == "alllayers")
12172 {
12173 theDI << searchInfo (aDict, "Layers") << " ";
12174 }
12175 else if (aFlag == "layers")
12176 {
12177 theDI << searchInfo (aDict, "Rendered layers") << " ";
12178 }
12179 else if (aFlag == "allstructs")
12180 {
12181 theDI << searchInfo (aDict, "Structs") << " ";
12182 }
12183 else if (aFlag == "structs")
12184 {
12185 theDI << searchInfo (aDict, "Rendered structs") << " ";
12186 }
12187 else if (aFlag == "groups")
12188 {
12189 theDI << searchInfo (aDict, "Rendered groups") << " ";
12190 }
12191 else if (aFlag == "allarrays")
12192 {
12193 theDI << searchInfo (aDict, "Rendered arrays") << " ";
12194 }
12195 else if (aFlag == "fillarrays")
12196 {
12197 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
12198 }
12199 else if (aFlag == "linearrays")
12200 {
12201 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
12202 }
12203 else if (aFlag == "pointarrays")
12204 {
12205 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
12206 }
12207 else if (aFlag == "textarrays")
12208 {
12209 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
12210 }
12211 else if (aFlag == "triangles")
12212 {
12213 theDI << searchInfo (aDict, "Rendered triangles") << " ";
12214 }
12215 else if (aFlag == "points")
12216 {
12217 theDI << searchInfo (aDict, "Rendered points") << " ";
12218 }
12219 else if (aFlag == "geommem")
12220 {
12221 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
12222 }
12223 else if (aFlag == "texturemem")
12224 {
12225 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
12226 }
12227 else if (aFlag == "framemem")
12228 {
12229 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
12230 }
12231 else if (aFlag == "elapsedframe")
12232 {
12233 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
12234 }
12235 else if (aFlag == "cpuframe_average")
12236 {
12237 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
12238 }
12239 else if (aFlag == "cpupicking_average")
12240 {
12241 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
12242 }
12243 else if (aFlag == "cpuculling_average")
12244 {
12245 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
12246 }
12247 else if (aFlag == "cpudyn_average")
12248 {
12249 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
12250 }
12251 else if (aFlag == "cpuframe_max")
12252 {
12253 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
12254 }
12255 else if (aFlag == "cpupicking_max")
12256 {
12257 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
12258 }
12259 else if (aFlag == "cpuculling_max")
12260 {
12261 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
12262 }
12263 else if (aFlag == "cpudyn_max")
12264 {
12265 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
12266 }
12267 }
12268 }
12269 else
12270 {
12271 if (toRedraw)
12272 {
12273 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12274 aView->Redraw();
12275 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12276 }
12277 theDI << "Statistic info:\n" << aView->StatisticInformation();
12278 }
12279 return 0;
12280}
12281
0717ddc1 12282//=======================================================================
12283//function : VXRotate
12284//purpose :
12285//=======================================================================
12286static Standard_Integer VXRotate (Draw_Interpretor& di,
12287 Standard_Integer argc,
12288 const char ** argv)
12289{
12290 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
12291 if (aContext.IsNull())
12292 {
586db386 12293 di << argv[0] << "ERROR : use 'vinit' command before \n";
0717ddc1 12294 return 1;
12295 }
8693dfd0 12296
0717ddc1 12297 if (argc != 3)
12298 {
586db386 12299 di << "ERROR : Usage : " << argv[0] << " name angle\n";
0717ddc1 12300 return 1;
12301 }
12302
12303 TCollection_AsciiString aName (argv[1]);
12304 Standard_Real anAngle = Draw::Atof (argv[2]);
12305
12306 // find object
12307 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
12308 Handle(AIS_InteractiveObject) anIObj;
8f521168 12309 if (!aMap.Find2 (aName, anIObj))
0717ddc1 12310 {
586db386 12311 di << "Use 'vdisplay' before\n";
0717ddc1 12312 return 1;
12313 }
0717ddc1 12314
8f521168 12315 gp_Trsf aTransform;
12316 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
12317 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
0717ddc1 12318
8f521168 12319 aContext->SetLocation (anIObj, aTransform);
12320 aContext->UpdateCurrentViewer();
0717ddc1 12321 return 0;
12322}
12323
625e1958 12324//===============================================================================================
12325//class : ViewerTest_AISManipulator
12326//purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
12327//===============================================================================================
12328DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
12329
12330class ViewerTest_AISManipulator : public AIS_Manipulator
12331{
12332public:
12333
12334 ViewerTest_AISManipulator() : AIS_Manipulator()
12335 {
12336 GetMapOfAISManipulators().Add (this);
12337 }
12338
12339 virtual ~ViewerTest_AISManipulator()
12340 {
12341 GetMapOfAISManipulators().Remove (this);
12342 }
12343
12344 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
12345};
12346
12347IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
12348IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
12349
12350//===============================================================================================
12351//function : VManipulator
12352//purpose :
12353//===============================================================================================
12354static int VManipulator (Draw_Interpretor& theDi,
12355 Standard_Integer theArgsNb,
12356 const char** theArgVec)
12357{
bbf3fcde 12358 Handle(V3d_View) aCurrentView = ViewerTest::CurrentView();
625e1958 12359 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
12360 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
bbf3fcde 12361 if (aCurrentView.IsNull()
625e1958 12362 || aViewer.IsNull())
12363 {
12364 std::cerr << "No active viewer!\n";
12365 return 1;
12366 }
12367
12368 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
12369 Standard_Integer anArgIter = 1;
12370 for (; anArgIter < theArgsNb; ++anArgIter)
12371 {
12372 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
12373 }
12374
12375 ViewerTest_CmdParser aCmd;
293211ae 12376 aCmd.SetDescription ("Manages manipulator for interactive objects:");
625e1958 12377 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
12378 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
12379 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
12380 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
bbf3fcde 12381 aCmd.AddOption ("view", "... {active | [view name]} - define view in which manipulator will be displayed, 'all' by default");
625e1958 12382 aCmd.AddOption ("detach", "... - detach manipulator");
12383
12384 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
12385 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
12386 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
12387
12388 aCmd.AddOption ("move", "... x y z - move object");
12389 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
12390 aCmd.AddOption ("scale", "... factor - scale object");
12391
12392 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
12393 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
12394 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
f522ce50 12395 aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform");
625e1958 12396 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
12397 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
84b904bc 12398 aCmd.AddOption ("parts", "... all axes mode {0|1} - set visual part");
625e1958 12399 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
12400 aCmd.AddOption ("size", "... size - set size of manipulator");
12401 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
12402
12403 aCmd.Parse (theArgsNb, theArgVec);
12404
12405 if (aCmd.HasOption ("help"))
12406 {
12407 theDi.PrintHelp (theArgVec[0]);
12408 return 0;
12409 }
12410
12411 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
12412
293211ae 12413 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
625e1958 12414
12415 if (aName.IsEmpty())
12416 {
12417 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
12418 return 1;
12419 }
12420
12421 // ----------------------------------
12422 // detach existing manipulator object
12423 // ----------------------------------
12424
12425 if (aCmd.HasOption ("detach"))
12426 {
12427 if (!aMapAIS.IsBound2 (aName))
12428 {
12429 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
12430 return 1;
12431 }
12432
12433 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12434 if (aManipulator.IsNull())
12435 {
12436 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12437 return 1;
12438 }
12439
12440 aManipulator->Detach();
12441 aMapAIS.UnBind2 (aName);
0577ae8c 12442 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
625e1958 12443
12444 return 0;
12445 }
12446
12447 // -----------------------------------------------
12448 // find or create manipulator if it does not exist
12449 // -----------------------------------------------
12450
12451 Handle(AIS_Manipulator) aManipulator;
12452 if (!aMapAIS.IsBound2 (aName))
12453 {
12454 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
12455
12456 aManipulator = new ViewerTest_AISManipulator();
49582f9d 12457 aManipulator->SetModeActivationOnDetection (true);
625e1958 12458 aMapAIS.Bind (aManipulator, aName);
12459 }
12460 else
12461 {
12462 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12463 if (aManipulator.IsNull())
12464 {
12465 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
12466 return 1;
12467 }
12468 }
12469
12470 // -----------------------------------------
12471 // change properties of manipulator instance
12472 // -----------------------------------------
12473
12474 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
12475 {
12476 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
12477 }
12478 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
12479 {
12480 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
12481 }
12482 if (aCmd.HasOption ("followRotation", 1, Standard_True))
12483 {
12484 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
12485 }
f522ce50 12486 if (aCmd.HasOption("followDragging", 1, Standard_True))
12487 {
12488 aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging"));
12489 }
625e1958 12490 if (aCmd.HasOption ("gap", 1, Standard_True))
12491 {
12492 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
12493 }
12494 if (aCmd.HasOption ("part", 3, Standard_True))
12495 {
12496 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
12497 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
12498 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
f522ce50 12499 if (aMode < 1 || aMode > 4)
625e1958 12500 {
f522ce50 12501 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
625e1958 12502 return 1;
12503 }
12504
12505 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
12506 }
84b904bc 12507 if (aCmd.HasOption("parts", 2, Standard_True))
12508 {
12509 Standard_Integer aMode = aCmd.ArgInt("parts", 0);
12510 Standard_Boolean aOnOff = aCmd.ArgBool("parts", 1);
12511 if (aMode < 1 || aMode > 4)
12512 {
12513 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
12514 return 1;
12515 }
12516
12517 aManipulator->SetPart(static_cast<AIS_ManipulatorMode>(aMode), aOnOff);
12518 }
625e1958 12519 if (aCmd.HasOption ("pos", 3, Standard_True))
12520 {
12521 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
12522 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
12523 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
12524
12525 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
12526 }
12527 if (aCmd.HasOption ("size", 1, Standard_True))
12528 {
12529 aManipulator->SetSize (aCmd.ArgFloat ("size"));
12530 }
12531 if (aCmd.HasOption ("zoomable", 1, Standard_True))
12532 {
12533 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
12534
12535 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
12536 {
12537 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
12538 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
12539 }
12540 }
12541
12542 // ---------------------------------------------------
12543 // attach, detach or access manipulator from an object
12544 // ---------------------------------------------------
12545
12546 if (aCmd.HasOption ("attach"))
12547 {
12548 // Find an object and attach manipulator to it
12549 if (!aCmd.HasOption ("attach", 1, Standard_True))
12550 {
12551 return 1;
12552 }
12553
12554 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
8f521168 12555 Handle(AIS_InteractiveObject) anObject;
12556 if (!aMapAIS.Find2 (anObjName, anObject))
625e1958 12557 {
12558 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
12559 return 1;
12560 }
12561
8f521168 12562 for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next())
625e1958 12563 {
12564 if (anIt.Value()->IsAttached()
12565 && anIt.Value()->Object() == anObject)
12566 {
12567 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
12568 return 1;
12569 }
12570 }
12571
12572 AIS_Manipulator::OptionsForAttach anOptions;
12573 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
12574 {
12575 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
12576 }
12577 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
12578 {
12579 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
12580 }
12581 if (aCmd.HasOption ("enableModes", 1, Standard_True))
12582 {
12583 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
12584 }
12585
12586 aManipulator->Attach (anObject, anOptions);
bbf3fcde 12587
12588 // Check view option
12589 if (aCmd.HasOption ("view"))
12590 {
12591 if (!aCmd.HasOption ("view", 1, Standard_True))
12592 {
12593 return 1;
12594 }
12595 TCollection_AsciiString aViewString (aCmd.Arg ("view", 0).c_str());
12596 Handle(V3d_View) aView;
12597 if (aViewString.IsEqual ("active"))
12598 {
12599 aView = ViewerTest::CurrentView();
12600 }
12601 else // Check view name
12602 {
12603 ViewerTest_Names aViewNames (aViewString);
12604 if (!ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
12605 {
12606 std::cerr << theArgVec[0] << " error: wrong view name '" << aViewString << "'\n";
12607 return 1;
12608 }
12609 aView = ViewerTest_myViews.Find1 (aViewNames.GetViewName());
12610 if (aView.IsNull())
12611 {
12612 std::cerr << theArgVec[0] << " error: cannot find view with name '" << aViewString << "'\n";
12613 return 1;
12614 }
12615 }
12616 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
12617 anIter (ViewerTest_myViews); anIter.More(); anIter.Next())
12618 {
12619 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, anIter.Value(), Standard_False);
12620 }
12621 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, aView, Standard_True);
12622 }
625e1958 12623 }
12624
12625 // --------------------------------------
12626 // apply transformation using manipulator
12627 // --------------------------------------
12628
12629 if (aCmd.HasOption ("startTransform", 2, Standard_True))
12630 {
12631 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
12632 }
12633 if (aCmd.HasOption ("transform", 2, Standard_True))
12634 {
12635 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
12636 }
12637 if (aCmd.HasOption ("stopTransform"))
12638 {
12639 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
12640
12641 aManipulator->StopTransform (toApply);
12642 }
12643
12644 gp_Trsf aT;
12645 if (aCmd.HasOption ("move", 3, Standard_True))
12646 {
12647 aT.SetTranslationPart (aCmd.ArgVec ("move"));
12648 }
12649 if (aCmd.HasOption ("rotate", 7, Standard_True))
12650 {
12651 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
12652 }
12653 if (aCmd.HasOption ("scale", 1))
12654 {
12655 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
12656 }
12657
12658 if (aT.Form() != gp_Identity)
12659 {
12660 aManipulator->Transform (aT);
12661 }
12662
0577ae8c 12663 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
625e1958 12664
12665 return 0;
12666}
12667
8e5fb5ea 12668//===============================================================================================
12669//function : VSelectionProperties
12670//purpose :
12671//===============================================================================================
12672static int VSelectionProperties (Draw_Interpretor& theDi,
12673 Standard_Integer theArgsNb,
12674 const char** theArgVec)
12675{
12676 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
12677 if (aCtx.IsNull())
12678 {
12679 std::cerr << "No active viewer!\n";
12680 return 1;
12681 }
12682
be3d8cbc 12683 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
12684 {
12685 // handle obsolete alias
12686 bool toEnable = true;
12687 if (theArgsNb < 2)
12688 {
12689 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
12690 return 0;
12691 }
12692 else if (theArgsNb != 2
12693 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
12694 {
12695 std::cout << "Syntax error: wrong number of parameters.";
12696 return 1;
12697 }
12698 if (toEnable != aCtx->ToHilightSelected())
12699 {
12700 aCtx->ClearDetected();
12701 aCtx->SetToHilightSelected (toEnable);
12702 }
12703 return 0;
12704 }
12705
f838dac4 12706 Standard_Boolean toPrint = theArgsNb == 1;
12707 Standard_Boolean toRedraw = Standard_False;
12708 Standard_Integer anArgIter = 1;
12709 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
12710 if (anArgIter < theArgsNb)
12711 {
12712 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
12713 anArgFirst.LowerCase();
12714 ++anArgIter;
12715 if (anArgFirst == "dynhighlight"
12716 || anArgFirst == "dynhilight"
12717 || anArgFirst == "dynamichighlight"
12718 || anArgFirst == "dynamichilight")
12719 {
12720 aType = Prs3d_TypeOfHighlight_Dynamic;
12721 }
12722 else if (anArgFirst == "localdynhighlight"
12723 || anArgFirst == "localdynhilight"
12724 || anArgFirst == "localdynamichighlight"
12725 || anArgFirst == "localdynamichilight")
12726 {
12727 aType = Prs3d_TypeOfHighlight_LocalDynamic;
12728 }
12729 else if (anArgFirst == "selhighlight"
12730 || anArgFirst == "selhilight"
12731 || anArgFirst == "selectedhighlight"
12732 || anArgFirst == "selectedhilight")
12733 {
12734 aType = Prs3d_TypeOfHighlight_Selected;
12735 }
12736 else if (anArgFirst == "localselhighlight"
12737 || anArgFirst == "localselhilight"
12738 || anArgFirst == "localselectedhighlight"
12739 || anArgFirst == "localselectedhilight")
12740 {
12741 aType = Prs3d_TypeOfHighlight_LocalSelected;
12742 }
12743 else
12744 {
12745 --anArgIter;
12746 }
12747 }
12748 for (; anArgIter < theArgsNb; ++anArgIter)
12749 {
12750 TCollection_AsciiString anArg (theArgVec[anArgIter]);
12751 anArg.LowerCase();
12752 if (anArg == "-help")
12753 {
12754 theDi.PrintHelp (theArgVec[0]);
12755 return 0;
12756 }
12757 else if (anArg == "-print")
12758 {
12759 toPrint = Standard_True;
12760 }
12761 else if (anArg == "-autoactivate")
12762 {
12763 Standard_Boolean toEnable = Standard_True;
12764 if (anArgIter + 1 < theArgsNb
12765 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12766 {
12767 ++anArgIter;
12768 }
12769 aCtx->SetAutoActivateSelection (toEnable);
12770 }
be3d8cbc 12771 else if (anArg == "-automatichighlight"
12772 || anArg == "-automatichilight"
12773 || anArg == "-autohighlight"
12774 || anArg == "-autohilight")
12775 {
12776 Standard_Boolean toEnable = Standard_True;
12777 if (anArgIter + 1 < theArgsNb
12778 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12779 {
12780 ++anArgIter;
12781 }
12782 aCtx->ClearSelected (false);
12783 aCtx->ClearDetected();
12784 aCtx->SetAutomaticHilight (toEnable);
12785 toRedraw = true;
12786 }
12787 else if (anArg == "-highlightselected"
12788 || anArg == "-hilightselected")
12789 {
12790 Standard_Boolean toEnable = Standard_True;
12791 if (anArgIter + 1 < theArgsNb
12792 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12793 {
12794 ++anArgIter;
12795 }
12796 aCtx->ClearDetected();
12797 aCtx->SetToHilightSelected (toEnable);
12798 toRedraw = true;
12799 }
14c4193d 12800 else if (anArg == "-pickstrategy"
12801 || anArg == "-pickingstrategy")
12802 {
12803 if (++anArgIter >= theArgsNb)
12804 {
12805 std::cout << "Syntax error: type of highlighting is undefined\n";
12806 return 1;
12807 }
12808
12809 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12810 TCollection_AsciiString aVal (theArgVec[anArgIter]);
12811 aVal.LowerCase();
12812 if (aVal == "first"
12813 || aVal == "firstaccepted"
12814 || aVal == "firstacceptable")
12815 {
12816 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12817 }
12818 else if (aVal == "topmost"
12819 || aVal == "onlyTopmost")
12820 {
12821 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
12822 }
12823 else
12824 {
12825 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
12826 return 1;
12827 }
12828
12829 aCtx->SetPickingStrategy (aStrategy);
12830 }
f838dac4 12831 else if (anArg == "-pixtol"
12832 && anArgIter + 1 < theArgsNb)
12833 {
12834 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
12835 }
12836 else if ((anArg == "-mode"
12837 || anArg == "-dispmode")
12838 && anArgIter + 1 < theArgsNb)
12839 {
12840 if (aType == Prs3d_TypeOfHighlight_None)
12841 {
12842 std::cout << "Syntax error: type of highlighting is undefined\n";
12843 return 1;
12844 }
8e5fb5ea 12845
f838dac4 12846 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
12847 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12848 aStyle->SetDisplayMode (aDispMode);
12849 toRedraw = Standard_True;
12850 }
12851 else if (anArg == "-layer"
12852 && anArgIter + 1 < theArgsNb)
12853 {
12854 if (aType == Prs3d_TypeOfHighlight_None)
12855 {
12856 std::cout << "Syntax error: type of highlighting is undefined\n";
12857 return 1;
12858 }
8e5fb5ea 12859
55c8f0f7
BB
12860 ++anArgIter;
12861 Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN;
12862 if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer))
f838dac4 12863 {
55c8f0f7
BB
12864 std::cerr << "Error: wrong syntax at " << theArgVec[anArgIter] << ".\n";
12865 return 1;
f838dac4 12866 }
8e5fb5ea 12867
f838dac4 12868 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12869 aStyle->SetZLayer (aNewLayer);
12870 toRedraw = Standard_True;
12871 }
12872 else if (anArg == "-hicolor"
12873 || anArg == "-selcolor"
12874 || anArg == "-color")
12875 {
12876 if (anArg.StartsWith ("-hi"))
12877 {
12878 aType = Prs3d_TypeOfHighlight_Dynamic;
12879 }
12880 else if (anArg.StartsWith ("-sel"))
12881 {
12882 aType = Prs3d_TypeOfHighlight_Selected;
12883 }
12884 else if (aType == Prs3d_TypeOfHighlight_None)
12885 {
12886 std::cout << "Syntax error: type of highlighting is undefined\n";
12887 return 1;
12888 }
8e5fb5ea 12889
f838dac4 12890 Quantity_Color aColor;
12891 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
12892 theArgVec + anArgIter + 1,
12893 aColor);
12894 if (aNbParsed == 0)
12895 {
12896 std::cout << "Syntax error: need more arguments.\n";
12897 return 1;
12898 }
12899 anArgIter += aNbParsed;
8e5fb5ea 12900
f838dac4 12901 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12902 aStyle->SetColor (aColor);
12903 toRedraw = Standard_True;
12904 }
12905 else if ((anArg == "-transp"
12906 || anArg == "-transparency"
12907 || anArg == "-hitransp"
12908 || anArg == "-seltransp"
12909 || anArg == "-hitransplocal"
12910 || anArg == "-seltransplocal")
12911 && anArgIter + 1 < theArgsNb)
12912 {
12913 if (anArg.StartsWith ("-hi"))
12914 {
12915 aType = Prs3d_TypeOfHighlight_Dynamic;
12916 }
12917 else if (anArg.StartsWith ("-sel"))
12918 {
12919 aType = Prs3d_TypeOfHighlight_Selected;
12920 }
12921 else if (aType == Prs3d_TypeOfHighlight_None)
12922 {
12923 std::cout << "Syntax error: type of highlighting is undefined\n";
12924 return 1;
12925 }
8e5fb5ea 12926
f838dac4 12927 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
12928 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12929 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
12930 toRedraw = Standard_True;
12931 }
12932 else if ((anArg == "-mat"
12933 || anArg == "-material")
12934 && anArgIter + 1 < theArgsNb)
12935 {
12936 if (aType == Prs3d_TypeOfHighlight_None)
12937 {
12938 std::cout << "Syntax error: type of highlighting is undefined\n";
12939 return 1;
12940 }
8e5fb5ea 12941
f838dac4 12942 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12943 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
12944 if (aMatName != Graphic3d_NOM_DEFAULT)
12945 {
12946 ++anArgIter;
12947 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
12948 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
12949 Graphic3d_MaterialAspect aMat (aMatName);
12950 aMat.SetColor (aStyle->Color());
12951 aMat.SetTransparency (aStyle->Transparency());
12952 anAspect->SetFrontMaterial (aMat);
12953 anAspect->SetInteriorColor (aStyle->Color());
12954 aStyle->SetBasicFillAreaAspect (anAspect);
12955 }
12956 else
12957 {
12958 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
12959 }
12960 toRedraw = Standard_True;
12961 }
12962 else
12963 {
12964 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
12965 }
8e5fb5ea 12966 }
12967
f838dac4 12968 if (toPrint)
8e5fb5ea 12969 {
f838dac4 12970 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
12971 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
8e5fb5ea 12972 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
be3d8cbc 12973 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
12974 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
8e5fb5ea 12975 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
f838dac4 12976 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
12977 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
12978 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
12979 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
12980 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
12981 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
12982 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
12983 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
8e5fb5ea 12984 }
12985
12986 if (aCtx->NbSelected() != 0 && toRedraw)
12987 {
12988 aCtx->HilightSelected (Standard_True);
12989 }
12990
12991 return 0;
12992}
12993
decdee7d 12994//===============================================================================================
12995//function : VDumpSelectionImage
12996//purpose :
12997//===============================================================================================
12998static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
12999 Standard_Integer theArgsNb,
13000 const char** theArgVec)
13001{
13002 if (theArgsNb < 2)
13003 {
13004 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
13005 return 1;
13006 }
13007
13008 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13009 if (aContext.IsNull())
13010 {
13011 std::cout << "Error: no active view.\n";
13012 return 1;
13013 }
13014
13015 TCollection_AsciiString aFile;
13016 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
dc858f4c 13017 Image_Format anImgFormat = Image_Format_BGR;
decdee7d 13018 Standard_Integer aPickedIndex = 1;
13019 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
13020 {
13021 TCollection_AsciiString aParam (theArgVec[anArgIter]);
13022 aParam.LowerCase();
13023 if (aParam == "-type")
13024 {
13025 if (++anArgIter >= theArgsNb)
13026 {
13027 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
13028 return 1;
13029 }
13030
13031 TCollection_AsciiString aValue (theArgVec[anArgIter]);
13032 aValue.LowerCase();
13033 if (aValue == "depth"
13034 || aValue == "normdepth"
13035 || aValue == "normalizeddepth")
13036 {
13037 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
dc858f4c 13038 anImgFormat = Image_Format_GrayF;
decdee7d 13039 }
13040 if (aValue == "depthinverted"
13041 || aValue == "normdepthinverted"
13042 || aValue == "normalizeddepthinverted"
13043 || aValue == "inverted")
13044 {
13045 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
dc858f4c 13046 anImgFormat = Image_Format_GrayF;
decdee7d 13047 }
13048 else if (aValue == "unnormdepth"
13049 || aValue == "unnormalizeddepth")
13050 {
13051 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
dc858f4c 13052 anImgFormat = Image_Format_GrayF;
decdee7d 13053 }
13054 else if (aValue == "objectcolor"
13055 || aValue == "object"
13056 || aValue == "color")
13057 {
13058 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
13059 }
13060 else if (aValue == "entitycolor"
13061 || aValue == "entity")
13062 {
13063 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
13064 }
13065 else if (aValue == "ownercolor"
13066 || aValue == "owner")
13067 {
13068 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
13069 }
13070 else if (aValue == "selectionmodecolor"
13071 || aValue == "selectionmode"
13072 || aValue == "selmodecolor"
13073 || aValue == "selmode")
13074 {
13075 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
13076 }
13077 }
13078 else if (aParam == "-picked"
13079 || aParam == "-pickeddepth"
13080 || aParam == "-pickedindex")
13081 {
13082 if (++anArgIter >= theArgsNb)
13083 {
13084 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
13085 return 1;
13086 }
13087
13088 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
13089 }
13090 else if (aFile.IsEmpty())
13091 {
13092 aFile = theArgVec[anArgIter];
13093 }
13094 else
13095 {
13096 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
13097 return 1;
13098 }
13099 }
13100 if (aFile.IsEmpty())
13101 {
13102 std::cout << "Syntax error: image file name is missing.\n";
13103 return 1;
13104 }
13105
13106 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13107 Standard_Integer aWidth = 0, aHeight = 0;
13108 aView->Window()->Size (aWidth, aHeight);
13109
13110 Image_AlienPixMap aPixMap;
13111 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
13112 {
13113 std::cout << "Error: can't allocate image.\n";
13114 return 1;
13115 }
13116 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
13117 {
13118 std::cout << "Error: can't generate selection image.\n";
13119 return 1;
13120 }
13121 if (!aPixMap.Save (aFile))
13122 {
13123 std::cout << "Error: can't save selection image.\n";
13124 return 0;
13125 }
13126 return 0;
13127}
13128
2108d9a2 13129//===============================================================================================
13130//function : VViewCube
13131//purpose :
13132//===============================================================================================
13133static int VViewCube (Draw_Interpretor& ,
13134 Standard_Integer theNbArgs,
13135 const char** theArgVec)
13136{
13137 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13138 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13139 if (aContext.IsNull() || aView.IsNull())
13140 {
13141 std::cout << "Error: no active view.\n";
13142 return 1;
13143 }
13144 else if (theNbArgs < 2)
13145 {
13146 std::cout << "Syntax error: wrong number arguments\n";
13147 return 1;
13148 }
13149
13150 Handle(AIS_ViewCube) aViewCube;
13151 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
13152 Quantity_Color aColorRgb;
13153 TCollection_AsciiString aName;
13154 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
13155 {
13156 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13157 anArg.LowerCase();
13158 if (anUpdateTool.parseRedrawMode (anArg))
13159 {
13160 //
13161 }
13162 else if (aViewCube.IsNull())
13163 {
13164 aName = theArgVec[anArgIter];
13165 if (aName.StartsWith ("-"))
13166 {
13167 std::cout << "Syntax error: object name should be specified.\n";
13168 return 1;
13169 }
13170 Handle(AIS_InteractiveObject) aPrs;
13171 GetMapOfAIS().Find2 (aName, aPrs);
13172 aViewCube = Handle(AIS_ViewCube)::DownCast (aPrs);
13173 if (aViewCube.IsNull())
13174 {
13175 aViewCube = new AIS_ViewCube();
13176 aViewCube->SetBoxColor (Quantity_NOC_GRAY50);
13177 aViewCube->SetViewAnimation (ViewerTest::CurrentEventManager()->ViewAnimation());
13178 aViewCube->SetFixedAnimationLoop (false);
13179 }
13180 }
13181 else if (anArg == "-reset")
13182 {
13183 aViewCube->ResetStyles();
13184 }
13185 else if (anArg == "-color"
13186 || anArg == "-boxcolor"
13187 || anArg == "-boxsidecolor"
13188 || anArg == "-sidecolor"
13189 || anArg == "-boxedgecolor"
13190 || anArg == "-edgecolor"
13191 || anArg == "-boxcornercolor"
13192 || anArg == "-cornercolor"
13193 || anArg == "-innercolor"
13194 || anArg == "-textcolor")
13195 {
13196 Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - anArgIter - 1,
13197 theArgVec + anArgIter + 1,
13198 aColorRgb);
13199 if (aNbParsed == 0)
13200 {
13201 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
13202 return 1;
13203 }
13204 anArgIter += aNbParsed;
13205 if (anArg == "-boxcolor")
13206 {
13207 aViewCube->SetBoxColor (aColorRgb);
13208 }
13209 else if (anArg == "-boxsidecolor"
13210 || anArg == "-sidecolor")
13211 {
13212 aViewCube->BoxSideStyle()->SetColor (aColorRgb);
13213 aViewCube->SynchronizeAspects();
13214 }
13215 else if (anArg == "-boxedgecolor"
13216 || anArg == "-edgecolor")
13217 {
13218 aViewCube->BoxEdgeStyle()->SetColor (aColorRgb);
13219 aViewCube->SynchronizeAspects();
13220 }
13221 else if (anArg == "-boxcornercolor"
13222 || anArg == "-cornercolor")
13223 {
13224 aViewCube->BoxCornerStyle()->SetColor (aColorRgb);
13225 aViewCube->SynchronizeAspects();
13226 }
13227 else if (anArg == "-innercolor")
13228 {
13229 aViewCube->SetInnerColor (aColorRgb);
13230 }
13231 else if (anArg == "-textcolor")
13232 {
13233 aViewCube->SetTextColor (aColorRgb);
13234 }
13235 else
13236 {
13237 aViewCube->SetColor (aColorRgb);
13238 }
13239 }
13240 else if (anArgIter + 1 < theNbArgs
13241 && (anArg == "-transparency"
13242 || anArg == "-boxtransparency"))
13243 {
13244 const Standard_Real aValue = Draw::Atof (theArgVec[++anArgIter]);
13245 if (aValue < 0.0 || aValue > 1.0)
13246 {
13247 std::cout << "Syntax error: invalid transparency value " << theArgVec[anArgIter] << "\n";
13248 return 1;
13249 }
13250
13251 if (anArg == "-boxtransparency")
13252 {
13253 aViewCube->SetBoxTransparency (aValue);
13254 }
13255 else
13256 {
13257 aViewCube->SetTransparency (aValue);
13258 }
13259 }
13260 else if (anArg == "-axes"
13261 || anArg == "-edges"
13262 || anArg == "-vertices"
13263 || anArg == "-vertexes"
13264 || anArg == "-fixedanimation")
13265 {
13266 bool toShow = true;
13267 if (anArgIter + 1 < theNbArgs
13268 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShow))
13269 {
13270 ++anArgIter;
13271 }
13272 if (anArg == "-fixedanimation")
13273 {
13274 aViewCube->SetFixedAnimationLoop (toShow);
13275 }
13276 else if (anArg == "-axes")
13277 {
13278 aViewCube->SetDrawAxes (toShow);
13279 }
13280 else if (anArg == "-edges")
13281 {
13282 aViewCube->SetDrawEdges (toShow);
13283 }
13284 else
13285 {
13286 aViewCube->SetDrawVertices (toShow);
13287 }
13288 }
13289 else if (anArg == "-yup"
13290 || anArg == "-zup")
13291 {
13292 bool isOn = true;
13293 if (anArgIter + 1 < theNbArgs
13294 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isOn))
13295 {
13296 ++anArgIter;
13297 }
13298 if (anArg == "-yup")
13299 {
13300 aViewCube->SetYup (isOn);
13301 }
13302 else
13303 {
13304 aViewCube->SetYup (!isOn);
13305 }
13306 }
13307 else if (anArgIter + 1 < theNbArgs
13308 && anArg == "-font")
13309 {
13310 aViewCube->SetFont (theArgVec[++anArgIter]);
13311 }
13312 else if (anArgIter + 1 < theNbArgs
13313 && anArg == "-fontheight")
13314 {
13315 aViewCube->SetFontHeight (Draw::Atof (theArgVec[++anArgIter]));
13316 }
13317 else if (anArgIter + 1 < theNbArgs
13318 && (anArg == "-size"
13319 || anArg == "-boxsize"))
13320 {
13321 aViewCube->SetSize (Draw::Atof (theArgVec[++anArgIter]),
13322 anArg != "-boxsize");
13323 }
13324 else if (anArgIter + 1 < theNbArgs
13325 && (anArg == "-boxfacet"
13326 || anArg == "-boxfacetextension"
13327 || anArg == "-facetextension"
13328 || anArg == "-extension"))
13329 {
13330 aViewCube->SetBoxFacetExtension (Draw::Atof (theArgVec[++anArgIter]));
13331 }
13332 else if (anArgIter + 1 < theNbArgs
13333 && (anArg == "-boxedgegap"
13334 || anArg == "-edgegap"))
13335 {
13336 aViewCube->SetBoxEdgeGap (Draw::Atof (theArgVec[++anArgIter]));
13337 }
13338 else if (anArgIter + 1 < theNbArgs
13339 && (anArg == "-boxedgeminsize"
13340 || anArg == "-edgeminsize"))
13341 {
13342 aViewCube->SetBoxEdgeMinSize (Draw::Atof (theArgVec[++anArgIter]));
13343 }
13344 else if (anArgIter + 1 < theNbArgs
13345 && (anArg == "-boxcornerminsize"
13346 || anArg == "-cornerminsize"))
13347 {
13348 aViewCube->SetBoxCornerMinSize (Draw::Atof (theArgVec[++anArgIter]));
13349 }
13350 else if (anArgIter + 1 < theNbArgs
13351 && anArg == "-axespadding")
13352 {
13353 aViewCube->SetAxesPadding (Draw::Atof (theArgVec[++anArgIter]));
13354 }
13355 else if (anArgIter + 1 < theNbArgs
13356 && anArg == "-roundradius")
13357 {
13358 aViewCube->SetRoundRadius (Draw::Atof (theArgVec[++anArgIter]));
13359 }
13360 else if (anArgIter + 1 < theNbArgs
13361 && anArg == "-duration")
13362 {
13363 aViewCube->SetDuration (Draw::Atof (theArgVec[++anArgIter]));
13364 }
13365 else
13366 {
13367 std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
13368 return 1;
13369 }
13370 }
13371 if (aViewCube.IsNull())
13372 {
13373 std::cout << "Syntax error: wrong number of arguments\n";
13374 return 1;
13375 }
13376
13377 ViewerTest::Display (aName, aViewCube, false);
13378 return 0;
13379}
13380
7fd59977 13381//=======================================================================
13382//function : ViewerCommands
13383//purpose :
13384//=======================================================================
13385
13386void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
13387{
13388
13389 const char *group = "ZeViewer";
18d715bd 13390 theCommands.Add("vinit",
fd3f6bd0 13391 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
2e93433e 13392 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
fd3f6bd0 13393 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13394 "\n\t\t: [-display displayName]"
13395 #endif
13396 "\n\t\t: Creates new View window with specified name viewName."
13397 "\n\t\t: By default the new view is created in the viewer and in"
13398 "\n\t\t: graphic driver shared with active view."
13399 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
13400 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
13401 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
13402#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
13403 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
13404 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
18d715bd 13405#endif
fd3f6bd0 13406 "\n\t\t: -left, -top pixel position of left top corner of the window."
13407 "\n\t\t: -width, -height width and heigth of window respectively."
9e04ccdc 13408 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
fd3f6bd0 13409 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
13410 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
2e93433e 13411 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
fd3f6bd0 13412 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
7fd59977 13413 __FILE__,VInit,group);
18d715bd 13414 theCommands.Add("vclose" ,
d0cc1cb7 13415 "[view_id [keep_context=0|1]]\n"
18d715bd 13416 "or vclose ALL - to remove all created views\n"
13417 " - removes view(viewer window) defined by its view_id.\n"
13418 " - keep_context: by default 0; if 1 and the last view is deleted"
13419 " the current context is not removed.",
13420 __FILE__,VClose,group);
13421 theCommands.Add("vactivate" ,
e084dbbc 13422 "vactivate view_id [-noUpdate]"
18d715bd 13423 " - activates view(viewer window) defined by its view_id",
13424 __FILE__,VActivate,group);
13425 theCommands.Add("vviewlist",
13426 "vviewlist [format={tree, long}]"
13427 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
13428 " - format: format of result output, if tree the output is a tree view;"
13429 "otherwise it's a list of full view names. By default format = tree",
13430 __FILE__,VViewList,group);
7fd59977 13431 theCommands.Add("vhelp" ,
13432 "vhelp : display help on the viewer commands",
13433 __FILE__,VHelp,group);
fc552d84 13434 theCommands.Add("vviewproj",
13435 "vviewproj [top|bottom|left|right|front|back|axoLeft|axoRight]"
13436 "\n\t\t: [+-X+-Y+-Z] [-Zup|-Yup] [-frame +-X+-Y]"
13437 "\n\t\t: Setup view direction"
13438 "\n\t\t: -Yup use Y-up convention instead of Zup (which is default)."
13439 "\n\t\t: +-X+-Y+-Z define direction as combination of DX, DY and DZ;"
13440 "\n\t\t: for example '+Z' will show front of the model,"
13441 "\n\t\t: '-X-Y+Z' will define left axonometrical view."
13442 "\n\t\t: -frame define camera Up and Right directions (regardless Up convention);"
13443 "\n\t\t: for example '+X+Z' will show front of the model with Z-up."
13444 __FILE__,VViewProj,group);
7fd59977 13445 theCommands.Add("vtop" ,
27af3052 13446 "vtop or <T> : Top view. Orientation +X+Y" ,
fc552d84 13447 __FILE__,VViewProj,group);
44b8f2d6 13448 theCommands.Add("vbottom" ,
27af3052 13449 "vbottom : Bottom view. Orientation +X-Y" ,
fc552d84 13450 __FILE__,VViewProj,group);
44b8f2d6 13451 theCommands.Add("vleft" ,
27af3052 13452 "vleft : Left view. Orientation -Y+Z" ,
fc552d84 13453 __FILE__,VViewProj,group);
44b8f2d6 13454 theCommands.Add("vright" ,
27af3052 13455 "vright : Right view. Orientation +Y+Z" ,
fc552d84 13456 __FILE__,VViewProj,group);
7fd59977 13457 theCommands.Add("vaxo" ,
27af3052 13458 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
fc552d84 13459 __FILE__,VViewProj,group);
44b8f2d6 13460 theCommands.Add("vfront" ,
27af3052 13461 "vfront : Front view. Orientation +X+Z" ,
fc552d84 13462 __FILE__,VViewProj,group);
44b8f2d6 13463 theCommands.Add("vback" ,
27af3052 13464 "vback : Back view. Orientation -X+Z" ,
fc552d84 13465 __FILE__,VViewProj,group);
7fd59977 13466 theCommands.Add("vpick" ,
13467 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
13468 VPick,group);
1beb58d7 13469 theCommands.Add("vfit",
13470 "vfit or <F> [-selected] [-noupdate]"
b586500b 13471 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
7fd59977 13472 __FILE__,VFit,group);
6262a303 13473 theCommands.Add ("vfitarea",
13474 "vfitarea x1 y1 x2 y2"
13475 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
13476 "\n\t\t: Fit view to show area located between two points"
13477 "\n\t\t: given in world 2D or 3D corrdinates.",
13478 __FILE__, VFitArea, group);
197ac94e 13479 theCommands.Add ("vzfit", "vzfit [scale]\n"
13480 " Matches Z near, Z far view volume planes to the displayed objects.\n"
13481 " \"scale\" - specifies factor to scale computed z range.\n",
13482 __FILE__, VZFit, group);
7fd59977 13483 theCommands.Add("vrepaint",
8693dfd0 13484 "vrepaint [-immediate] [-continuous FPS]"
13485 "\n\t\t: force redraw of active View"
13486 "\n\t\t: -immediate flag performs redraw of immediate layers only;"
13487 "\n\t\t: -continuous activates/deactivates continuous redraw of active View,"
13488 "\n\t\t: 0 means no continuous rendering,"
13489 "\n\t\t: -1 means non-stop redraws,"
13490 "\n\t\t: >0 specifies target framerate,",
7fd59977 13491 __FILE__,VRepaint,group);
13492 theCommands.Add("vclear",
faea8b40 13493 "vclear : vclear"
13494 "\n\t\t: remove all the object from the viewer",
7fd59977 13495 __FILE__,VClear,group);
293211ae 13496 theCommands.Add (
13497 "vbackground",
13498 "Changes background or some background settings.\n"
13499 "\n"
13500 "Usage:\n"
13501 " vbackground -imageFile ImageFile [-imageMode FillType]\n"
13502 " vbackground -imageMode FillType\n"
13503 " vbackground -gradient Color1 Color2 [-gradientMode FillMethod]\n"
13504 " vbackground -gradientMode FillMethod\n"
13505 " vbackground -color Color\n"
13506 " vbackground -default -gradient Color1 Color2 [-gradientMode FillType]\n"
13507 " vbackground -default -color Color\n"
13508 " vbackground -help\n"
13509 "\n"
13510 "Options:\n"
13511 " -imageFile (-imgFile, -image, -img): sets filename of image used as background\n"
13512 " -imageMode (-imgMode, -imageMd, -imgMd): sets image fill type\n"
13513 " -gradient (-grad, -gr): sets background gradient starting and ending colors\n"
13514 " -gradientMode (-gradMode, -gradMd, -grMode, -grMd): sets gradient fill method\n"
13515 " -color (-col): sets background color\n"
13516 " -default (-def): sets background default gradient or color\n"
13517 " -help (-h): outputs short help message\n"
13518 "\n"
13519 "Arguments:\n"
13520 " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n"
13521 " or reals within the range [0.0, 1.0]\n"
13522 " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n"
13523 " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n"
13524 " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, "
13525 "CORNER4\n"
13526 " FillType: one of CENTERED, TILED, STRETCH, NONE\n"
13527 " ImageFile: a name of the file with the image used as a background\n",
13528 __FILE__,
13529 vbackground,
13530 group);
13531 theCommands.Add ("vsetbg",
13532 "Loads image as background."
13533 "\n\t\t: vsetbg ImageFile [FillType]"
13534 "\n\t\t: vsetbg -imageFile ImageFile [-imageMode FillType]"
13535 "\n\t\t: Alias for 'vbackground -imageFile ImageFile [-imageMode FillType]'.",
13536 __FILE__,
13537 vbackground,
13538 group);
13539 theCommands.Add ("vsetbgmode",
13540 "Changes background image fill type."
13541 "\n\t\t: vsetbgmode [-imageMode] FillType"
13542 "\n\t\t: Alias for 'vbackground -imageMode FillType'.",
13543 __FILE__,
13544 vbackground,
13545 group);
13546 theCommands.Add ("vsetgradientbg",
13547 "Mounts gradient background."
13548 "\n\t\t: vsetgradientbg Color1 Color2 [FillMethod]"
13549 "\n\t\t: vsetgradientbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13550 "\n\t\t: Alias for 'vbackground -gradient Color1 Color2 -gradientMode FillMethod'.",
13551 __FILE__,
13552 vbackground,
13553 group);
13554 theCommands.Add ("vsetgrbgmode",
13555 "Changes gradient background fill method."
13556 "\n\t\t: vsetgrbgmode [-gradientMode] FillMethod"
13557 "\n\t\t: Alias for 'vbackground -gradientMode FillMethod'.",
13558 __FILE__,
13559 vbackground,
13560 group);
13561 theCommands.Add ("vsetcolorbg",
13562 "Sets background color."
13563 "\n\t\t: vsetcolorbg [-color] Color."
13564 "\n\t\t: Alias for 'vbackground -color Color'.",
13565 __FILE__,
13566 vbackground,
13567 group);
13568 theCommands.Add ("vsetdefaultbg",
13569 "Sets default viewer background fill color (flat/gradient)."
13570 "\n\t\t: vsetdefaultbg Color1 Color2 [FillMethod]"
13571 "\n\t\t: vsetdefaultbg -gradient Color1 Color2 [-gradientMode FillMethod]"
13572 "\n\t\t: Alias for 'vbackground -default -gradient Color1 Color2 [-gradientMode FillMethod]'."
13573 "\n\t\t: vsetdefaultbg [-color] Color"
13574 "\n\t\t: Alias for 'vbackground -default -color Color'.",
13575 __FILE__,
13576 vbackground,
13577 group);
7fd59977 13578 theCommands.Add("vscale",
13579 "vscale : vscale X Y Z",
13580 __FILE__,VScale,group);
13581 theCommands.Add("vzbufftrihedron",
536d98e2 13582 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
13583 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
13584 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
13585 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
13586 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
13587 "\n\t\t: Displays a trihedron",
13588 __FILE__,VZBuffTrihedron,group);
7fd59977 13589 theCommands.Add("vrotate",
4af098ba 13590 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
13591 "\n : Option -mouseStart starts rotation according to the mouse position"
13592 "\n : Option -mouseMove continues rotation with angle computed"
13593 "\n : from last and new mouse position."
13594 "\n : vrotate AX AY AZ [X Y Z]",
7fd59977 13595 __FILE__,VRotate,group);
13596 theCommands.Add("vzoom",
13597 "vzoom : vzoom coef",
13598 __FILE__,VZoom,group);
13599 theCommands.Add("vpan",
13600 "vpan : vpan dx dy",
13601 __FILE__,VPan,group);
7fd59977 13602 theCommands.Add("vcolorscale",
4b3d6eb1 13603 "vcolorscale name [-noupdate|-update] [-demo]"
13604 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
13605 "\n\t\t: [-font HeightFont=20]"
13606 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
13607 "\n\t\t: [-smoothTransition {on|off}=off]"
13608 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
13609 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
13610 "\n\t\t: [-textpos {left|right|center|none}=right]"
13611 "\n\t\t: [-labelAtBorder {on|off}=on]"
13612 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
13613 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
13614 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
13615 "\n\t\t: [-xy Left=0 Bottom=0]"
13616 "\n\t\t: -demo - displays a color scale with demonstratio values"
13617 "\n\t\t: -colors - set colors for all intervals"
13618 "\n\t\t: -color - set color for specific interval"
13619 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
13620 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
13621 "\n\t\t: at border means the value inbetween neighbor intervals,"
13622 "\n\t\t: at center means the center value within current interval"
13623 "\n\t\t: -labels - set labels for all intervals"
13624 "\n\t\t: -freeLabels - same as -labels but does not require"
13625 "\n\t\t: matching the number of intervals"
13626 "\n\t\t: -label - set label for specific interval"
13627 "\n\t\t: -title - set title"
13628 "\n\t\t: -reversed - setup smooth color transition between intervals"
13629 "\n\t\t: -smoothTransition - swap colorscale direction"
13630 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
13631 __FILE__, VColorScale, group);
7fd59977 13632 theCommands.Add("vgraduatedtrihedron",
a79f67f8 13633 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
13634 "\t[-namefont Name] [-valuesfont Name]\n"
13635 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
13636 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
13637 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
13638 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
13639 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
13640 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
13641 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
13642 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
13643 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
536d98e2 13644 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
a79f67f8 13645 " - Displays or erases graduated trihedron"
13646 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
13647 " - namefont - font of axes names. Default: Arial\n"
13648 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
13649 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
13650 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
13651 " - valuesfont - font of axes values. Default: Arial\n"
13652 " - xcolor, ycolor, zcolor - color of axis and values\n"
13653 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
13654 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
7fd59977 13655 __FILE__,VGraduatedTrihedron,group);
3bffef55 13656 theCommands.Add("vtile" ,
13657 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
13658 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
13659 "\n\t\t: -totalSize the size of virtual bigger viewport"
13660 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
13661 "\n\t\t: -lowerLeft tile offset as lower left corner"
13662 "\n\t\t: -upperLeft tile offset as upper left corner",
13663 __FILE__, VTile, group);
59f45b7c 13664 theCommands.Add("vzlayer",
7c3ef2f7 13665 "vzlayer [layerId]"
1c728f2d 13666 "\n\t\t: [-add|-delete|-get|-settings] [-insertBefore AnotherLayer] [-insertAfter AnotherLayer]"
4ecf34cc 13667 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
7c3ef2f7 13668 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
1c728f2d 13669 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv|rayTracing}]"
7c3ef2f7 13670 "\n\t\t: ZLayer list management:"
13671 "\n\t\t: -add add new z layer to viewer and print its id"
1c728f2d 13672 "\n\t\t: -insertBefore add new z layer and insert it before existing one"
13673 "\n\t\t: -insertAfter add new z layer and insert it after existing one"
7c3ef2f7 13674 "\n\t\t: -delete delete z layer"
13675 "\n\t\t: -get print sequence of z layers"
13676 "\n\t\t: -settings print status of z layer settings"
13677 "\n\t\t: -disable disables given setting"
13678 "\n\t\t: -enable enables given setting",
59f45b7c 13679 __FILE__,VZLayer,group);
20637bd2 13680 theCommands.Add("vlayerline",
13681 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
13682 __FILE__,VLayerLine,group);
79931835 13683 theCommands.Add("vgrid",
13684 "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]"
13685 "\n\t\t: [-step X Y] [-size DX DY]"
13686 "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]",
2bd4c032 13687 __FILE__, VGrid, group);
c40b7d58 13688 theCommands.Add ("vpriviledgedplane",
13689 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
13690 "\n\t\t: Ox, Oy, Oz - plane origin"
13691 "\n\t\t: Nx, Ny, Nz - plane normal direction"
13692 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
13693 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
13694 __FILE__, VPriviledgedPlane, group);
f25b82d6 13695 theCommands.Add ("vconvert",
13696 "vconvert v [Mode={window|view}]"
13697 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
13698 "\n\t\t: vconvert x y z [Mode={window|grid}]"
13699 "\n\t\t: window - convert to window coordinates, pixels"
13700 "\n\t\t: view - convert to view projection plane"
13701 "\n\t\t: grid - convert to model coordinates, given on grid"
13702 "\n\t\t: ray - convert projection ray to model coordiantes"
13703 "\n\t\t: - vconvert v window : convert view to window;"
13704 "\n\t\t: - vconvert v view : convert window to view;"
13705 "\n\t\t: - vconvert x y window : convert view to window;"
13706 "\n\t\t: - vconvert x y view : convert window to view;"
13707 "\n\t\t: - vconvert x y : convert window to model;"
13708 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
13709 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
13710 "\n\t\t: - vconvert x y z window : convert model to window;"
13711 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
13712 "\n\t\t: Converts the given coordinates to window/view/model space.",
13713 __FILE__, VConvert, group);
208e6839 13714 theCommands.Add ("vfps",
e084dbbc 13715 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
208e6839 13716 __FILE__, VFps, group);
58655684 13717 theCommands.Add ("vgldebug",
c87535af 13718 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
84e84755 13719 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
c87535af 13720 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
13721 "\n\t\t: Debug context can be requested only on Windows"
13722 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
13723 "\n\t\t: -sync - request synchronized debug GL context"
13724 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
13725 "\n\t\t: which are suppressed by default,"
84e84755 13726 "\n\t\t: -glslCode - log GLSL program source code,"
13727 "\n\t\t: which are suppressed by default,"
c87535af 13728 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
13729 "\n\t\t: which are suppressed by default",
58655684 13730 __FILE__, VGlDebug, group);
208e6839 13731 theCommands.Add ("vvbo",
58655684 13732 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
208e6839 13733 __FILE__, VVbo, group);
b5ac8292 13734 theCommands.Add ("vstereo",
f978241f 13735 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
13736 "\n\t\t: [-anaglyph Filter]"
13737 "\n\t\t: Control stereo output mode. Available modes for -mode:"
13738 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
13739 "\n\t\t: requires driver support."
13740 "\n\t\t: Should be called BEFORE vinit!"
13741 "\n\t\t: anaglyph - Anaglyph glasses"
13742 "\n\t\t: rowInterlaced - row-interlaced display"
13743 "\n\t\t: columnInterlaced - column-interlaced display"
13744 "\n\t\t: chessBoard - chess-board output"
13745 "\n\t\t: sideBySide - horizontal pair"
13746 "\n\t\t: overUnder - vertical pair"
13747 "\n\t\t: Available Anaglyph filters for -anaglyph:"
13748 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
13749 "\n\t\t: greenMagentaSimple",
b5ac8292 13750 __FILE__, VStereo, group);
a577aaab 13751 theCommands.Add ("vcaps",
2a332745 13752 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
1dfe71a6 13753 "\n\t\t: [-compatibleProfile {0|1}]"
56689b27 13754 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
f978241f 13755 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
8625ef7e 13756 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
59515ca6 13757 "\n\t\t: [-noExtensions {0|1}] [-maxVersion Major Minor]"
8625ef7e 13758 "\n\t\t: Modify particular graphic driver options:"
13759 "\n\t\t: FFP - use fixed-function pipeline instead of"
13760 "\n\t\t: built-in GLSL programs"
4e1523ef 13761 "\n\t\t: (requires compatible profile)"
2a332745 13762 "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs"
8625ef7e 13763 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
13764 "\n\t\t: arrays to GPU memory)"
13765 "\n\t\t: sprite - use textured sprites instead of bitmaps"
f978241f 13766 "\n\t\t: vsync - switch VSync on or off"
56689b27 13767 "\n\t\t: winBuffer - allow using window buffer for rendering"
4e1523ef 13768 "\n\t\t: Context creation options:"
13769 "\n\t\t: softMode - software OpenGL implementation"
13770 "\n\t\t: compatibleProfile - backward-compatible profile"
f978241f 13771 "\n\t\t: quadbuffer - QuadBuffer"
59515ca6 13772 "\n\t\t: noExtensions - disallow usage of extensions"
13773 "\n\t\t: maxVersion - force upper OpenGL version to be used"
8625ef7e 13774 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
13775 "\n\t\t: rendering paths producing the same visual result when"
13776 "\n\t\t: possible."
13777 "\n\t\t: Command is intended for testing old hardware compatibility.",
a577aaab 13778 __FILE__, VCaps, group);
f0430952 13779 theCommands.Add ("vmemgpu",
13780 "vmemgpu [f]: print system-dependent GPU memory information if available;"
13781 " with f option returns free memory in bytes",
13782 __FILE__, VMemGpu, group);
85e096c3 13783 theCommands.Add ("vreadpixel",
55c8f0f7 13784 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [-name]"
85e096c3 13785 " : Read pixel value for active view",
13786 __FILE__, VReadPixel, group);
692613e5 13787 theCommands.Add("diffimage",
fd3f6bd0 13788 "diffimage imageFile1 imageFile2 [diffImageFile]"
13789 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
13790 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
13791 "\n\t\t: Compare two images by content and generate difference image."
13792 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
13793 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
692613e5 13794 __FILE__, VDiffImage, group);
4754e164 13795 theCommands.Add ("vselect",
2157d6ac 13796 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
4754e164 13797 "- emulates different types of selection:\n"
13798 "- 1) single click selection\n"
13799 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
13800 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
faea8b40 13801 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
13802 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
13803 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
2157d6ac 13804 " (partial inclusion - overlap - is not allowed by default)\n"
13805 "- 5) any of these selections with shift button pressed",
4754e164 13806 __FILE__, VSelect, group);
13807 theCommands.Add ("vmoveto",
8a590580 13808 "vmoveto [x y] [-reset]"
13809 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
13810 "\n\t\t: -reset resets current highlighting",
4754e164 13811 __FILE__, VMoveTo, group);
1beb58d7 13812 theCommands.Add ("vviewparams",
13813 "vviewparams [-args] [-scale [s]]"
13814 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
13815 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
13816 "\n\t\t: Manage current view parameters or prints all"
13817 "\n\t\t: current values when called without argument."
13818 "\n\t\t: -scale [s] prints or sets viewport relative scale"
13819 "\n\t\t: -eye [x y z] prints or sets eye location"
13820 "\n\t\t: -at [x y z] prints or sets center of look"
13821 "\n\t\t: -up [x y z] prints or sets direction of up vector"
13822 "\n\t\t: -proj [x y z] prints or sets direction of look"
13823 "\n\t\t: -center x y sets location of center of the screen in pixels"
13824 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
13825 "\n\t\t: or changes the size of its maximum dimension"
13826 "\n\t\t: -args prints vviewparams arguments for restoring current view",
197ac94e 13827 __FILE__, VViewParams, group);
1beb58d7 13828
2e93433e 13829 theCommands.Add("v2dmode",
13830 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
13831 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
13832 "\n\t\t: mode - switches On/Off rotation mode"
13833 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
13834 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
13835 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
13836 "\n\t\t: View camera position might be changed only by commands.",
13837 __FILE__, V2DMode, group);
13838
1beb58d7 13839 theCommands.Add("vanimation", "Alias for vanim",
13840 __FILE__, VAnimation, group);
13841
13842 theCommands.Add("vanim",
13843 "List existing animations:"
13844 "\n\t\t: vanim"
13845 "\n\t\t: Animation playback:"
13846 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
13847 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
13848 "\n\t\t: -speed playback speed (1.0 is normal speed)"
13849 "\n\t\t: -freeLook skip camera animations"
13850 "\n\t\t: -lockLoop disable any interactions"
13851 "\n\t\t:"
13852 "\n\t\t: Animation definition:"
13853 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
13854 "\n\t\t: [start TimeSec] [duration TimeSec]"
13855 "\n\t\t:"
13856 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
13857 "\n\t\t: specifies nested animations."
13858 "\n\t\t: There is no syntax to explicitly add new animation,"
13859 "\n\t\t: and all non-existing animations within the name will be"
13860 "\n\t\t: implicitly created on first use (including parents)."
13861 "\n\t\t:"
13862 "\n\t\t: Each animation might define the SINGLE action (see below),"
13863 "\n\t\t: like camera transition, object transformation or custom callback."
13864 "\n\t\t: Child animations can be used for defining concurrent actions."
13865 "\n\t\t:"
13866 "\n\t\t: Camera animation:"
13867 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
13868 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
13869 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
13870 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
13871 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
13872 "\n\t\t: -atX camera Center positions pair"
13873 "\n\t\t: -upX camera Up directions pair"
13874 "\n\t\t: -scaleX camera Scale factors pair"
13875 "\n\t\t: Object animation:"
13876 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
13877 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
13878 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
13879 "\n\t\t: -locX object Location points pair (translation)"
13880 "\n\t\t: -rotX object Orientations pair (quaternions)"
13881 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
13882 "\n\t\t: Custom callback:"
13883 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
13884 "\n\t\t: %Pts overall animation presentation timestamp"
13885 "\n\t\t: %LocalPts local animation timestamp"
13886 "\n\t\t: %Normalized local animation normalized value in range 0..1"
08f8a185 13887 "\n\t\t:"
13888 "\n\t\t: Video recording:"
13889 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
13890 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
13891 "\n\t\t: [-crf Value] [-preset Preset]"
13892 "\n\t\t: -fps video framerate"
13893 "\n\t\t: -format file format, container (matroska, etc.)"
13894 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
13895 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
13896 "\n\t\t: -crf constant rate factor (specific to codec)"
13897 "\n\t\t: -preset codec parameters preset (specific to codec)"
1beb58d7 13898 __FILE__, VAnimation, group);
13899
4754e164 13900 theCommands.Add("vchangeselected",
dc3fe572 13901 "vchangeselected shape"
4754e164 13902 "- adds to shape to selection or remove one from it",
13903 __FILE__, VChangeSelected, group);
4754e164 13904 theCommands.Add ("vnbselected",
faea8b40 13905 "vnbselected"
13906 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
6b62b2da 13907 theCommands.Add ("vcamera",
30a1b24e 13908 "vcamera [PrsName] [-ortho] [-projtype]"
6b62b2da 13909 "\n\t\t: [-persp]"
13910 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
13911 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
13912 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
13913 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
30a1b24e 13914 "\n\t\t: Manages camera parameters."
13915 "\n\t\t: Displays frustum when presntation name PrsName is specified."
6b62b2da 13916 "\n\t\t: Prints current value when option called without argument."
13917 "\n\t\t: Orthographic camera:"
13918 "\n\t\t: -ortho activate orthographic projection"
13919 "\n\t\t: Perspective camera:"
13920 "\n\t\t: -persp activate perspective projection (mono)"
13921 "\n\t\t: -fovy field of view in y axis, in degrees"
13922 "\n\t\t: -distance distance of eye from camera center"
13923 "\n\t\t: Stereoscopic camera:"
13924 "\n\t\t: -stereo perspective projection (stereo)"
13925 "\n\t\t: -leftEye perspective projection (left eye)"
13926 "\n\t\t: -rightEye perspective projection (right eye)"
13927 "\n\t\t: -iod intraocular distance value"
13928 "\n\t\t: -iodType distance type, absolute or relative"
13929 "\n\t\t: -zfocus stereographic focus value"
13930 "\n\t\t: -zfocusType focus type, absolute or relative",
13931 __FILE__, VCamera, group);
b5ac8292 13932 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
197ac94e 13933 "- vautozfit [on={1|0}] [scale]\n"
13934 " Prints or changes parameters of automatic z-fit mode:\n"
13935 " \"on\" - turns automatic z-fit on or off\n"
13936 " \"scale\" - specifies factor to scale computed z range.\n",
13937 __FILE__, VAutoZFit, group);
b5ac8292 13938 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
13939 " vzrange - without parameters shows current values\n"
13940 " vzrange [znear] [zfar] - applies provided values to view",
13941 __FILE__,VZRange, group);
4754e164 13942 theCommands.Add ("vpurgedisplay",
eb4320f2 13943 "vpurgedisplay"
4754e164 13944 "- removes structures which don't belong to objects displayed in neutral point",
13945 __FILE__, VPurgeDisplay, group);
13946 theCommands.Add("vsetviewsize",
13947 "vsetviewsize size",
13948 __FILE__,VSetViewSize,group);
13949 theCommands.Add("vmoveview",
13950 "vmoveview Dx Dy Dz [Start = 1|0]",
13951 __FILE__,VMoveView,group);
13952 theCommands.Add("vtranslateview",
13953 "vtranslateview Dx Dy Dz [Start = 1|0)]",
13954 __FILE__,VTranslateView,group);
13955 theCommands.Add("vturnview",
13956 "vturnview Ax Ay Az [Start = 1|0]",
13957 __FILE__,VTurnView,group);
269294d6 13958 theCommands.Add("vtextureenv",
13959 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
13960 "or user-defined file and optionally applying texture mapping parameters\n"
13961 " Usage:\n"
13962 " vtextureenv off - disables environment mapping\n"
13963 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
13964 " std_texture = (0..7)\n"
13965 " rep = {clamp|repeat}\n"
13966 " mod = {decal|modulate}\n"
13967 " flt = {nearest|bilinear|trilinear}\n"
13968 " ss, st - scale factors for s and t texture coordinates\n"
13969 " ts, tt - translation for s and t texture coordinates\n"
13970 " rot - texture rotation angle in degrees",
13971 __FILE__, VTextureEnv, group);
1eeef710 13972 theCommands.Add("vhlr",
13973 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
13974 "\n\t\t: Hidden Line Removal algorithm."
13975 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
13976 "\n\t\t: -algoType type of HLR algorithm.\n",
0a768f56 13977 __FILE__,VHLR,group);
1eeef710 13978 theCommands.Add("vhlrtype",
13979 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
13980 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
13981 "\n\t\t: 'algo' - exact HLR algorithm is applied"
13982 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
13983 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
0a768f56 13984 __FILE__,VHLRType,group);
3e05329c 13985 theCommands.Add("vclipplane",
13986 "vclipplane planeName [{0|1}]"
25c35042 13987 "\n\t\t: [-equation1 A B C D]"
13988 "\n\t\t: [-equation2 A B C D]"
13989 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
32ca7711 13990 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
3e05329c 13991 "\n\t\t: [-maxPlanes]"
13992 "\n\t\t: [-capping {0|1}]"
1b661a81 13993 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
3e05329c 13994 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
13995 "\n\t\t: [-texRotate Angle]"
13996 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
13997 "\n\t\t: [-useObjShader {0|1}]"
13998 "\n\t\t: Clipping planes management:"
13999 "\n\t\t: -maxPlanes print plane limit for view"
14000 "\n\t\t: -delete delete plane with given name"
14001 "\n\t\t: {off|on|0|1} turn clipping on/off"
14002 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
14003 "\n\t\t: applied to active View when list is omitted"
14004 "\n\t\t: -equation A B C D change plane equation"
14005 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
14006 "\n\t\t: Capping options:"
14007 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
14008 "\n\t\t: -color R G B set capping color"
1b661a81 14009 "\n\t\t: -transparency Value set capping transparency 0..1"
3e05329c 14010 "\n\t\t: -texName Texture set capping texture"
14011 "\n\t\t: -texScale SX SY set capping tex scale"
14012 "\n\t\t: -texOrigin TX TY set capping tex origin"
14013 "\n\t\t: -texRotate Angle set capping tex rotation"
14014 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
14015 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
14016 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
14017 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
14018 __FILE__, VClipPlane, group);
392ac980 14019 theCommands.Add("vdefaults",
4c513386 14020 "vdefaults [-absDefl value]"
14021 "\n\t\t: [-devCoeff value]"
14022 "\n\t\t: [-angDefl value]"
14023 "\n\t\t: [-autoTriang {off/on | 0/1}]"
14024 , __FILE__, VDefaults, group);
12381341 14025 theCommands.Add("vlight",
816d03ee 14026 "tool to manage light sources, without arguments shows list of lights."
14027 "\n Main commands: "
992ed6b3 14028 "\n '-clear' to clear lights"
14029 "\n '-{def}aults' to load deafault lights"
14030 "\n '-add' <type> to add any light source"
816d03ee 14031 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
14032 "\n 'change' <lightId> to edit light source with specified lightId"
14033 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
992ed6b3 14034 "\n -layer Id"
14035 "\n -{pos}ition X Y Z"
14036 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
14037 "\n -color colorName"
14038 "\n -{head}light 0|1"
14039 "\n -{sm}oothness value"
14040 "\n -{int}ensity value"
14041 "\n -{constAtten}uation value"
14042 "\n -{linearAtten}uation value"
14043 "\n -angle angleDeg"
14044 "\n -{spotexp}onent value"
14045 "\n -local|-global"
14046 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
14047 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
12381341 14048 __FILE__, VLight, group);
6b62b2da 14049 theCommands.Add("vraytrace",
14050 "vraytrace [0|1]"
189f85a3 14051 "\n\t\t: Turns on/off ray-tracing renderer."
6b62b2da 14052 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
14053 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
14054 __FILE__, VRenderParams, group);
bc8c79bb 14055 theCommands.Add("vrenderparams",
14056 "\n Manages rendering parameters: "
a1073ae2 14057 "\n '-raster' Disables GPU ray-tracing"
14058 "\n '-msaa 0..4' Specifies number of samples for MSAA"
2a332745 14059 "\n '-lineFeather > 0' Sets line feather factor"
a1073ae2 14060 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
f88457e6 14061 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
c40eb6b9 14062 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
a1073ae2 14063 "\n '-rendScale value Rendering resolution scale factor"
14064 "\n '-rayTrace' Enables GPU ray-tracing"
14065 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
14066 "\n '-shadows on|off' Enables/disables shadows rendering"
14067 "\n '-reflections on|off' Enables/disables specular reflections"
14068 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
14069 "\n '-gleam on|off' Enables/disables transparency shadow effects"
14070 "\n '-gi on|off' Enables/disables global illumination effects"
14071 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
14072 "\n '-env on|off' Enables/disables environment map background"
14073 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
14074 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
14075 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
14076 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
66d1cdc6 14077 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
14078 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
a1073ae2 14079 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
14080 "\n '-shadingModel model' Controls shading model from enumeration"
14081 "\n color, flat, gouraud, phong"
14082 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
b27ab03d 14083 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
14084 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
eb85ed36 14085 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
14086 "\n '-whitepoint value' White point value for filmic tone mapping"
14087 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
5e30547b 14088 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points"
14089 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
15669413 14090 "\n Show/hide performance counters (flags can be combined)"
14091 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
5e30547b 14092 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
14093 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
0e3025bc 14094 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
14095 "\n set state to check structures culled previously."
8625ef7e 14096 "\n Unlike vcaps, these parameters dramatically change visual properties."
14097 "\n Command is intended to control presentation quality depending on"
14098 "\n hardware capabilities and performance.",
bc8c79bb 14099 __FILE__, VRenderParams, group);
79b544e6 14100 theCommands.Add("vstatprofiler",
14101 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
14102 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
14103 "\n |triagles|points|geomMem|textureMem|frameMem"
14104 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
14105 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
14106 "\n [-noredraw]"
14107 "\n\t\t: Prints rendering statistics."
14108 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
14109 "\n\t\t: else - print all performance counters set previously."
14110 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
14111 __FILE__, VStatProfiler, group);
49e1a5c7 14112 theCommands.Add ("vplace",
14113 "vplace dx dy"
14114 "\n\t\t: Places the point (in pixels) at the center of the window",
14115 __FILE__, VPlace, group);
0717ddc1 14116 theCommands.Add("vxrotate",
14117 "vxrotate",
14118 __FILE__,VXRotate,group);
14119
625e1958 14120 theCommands.Add("vmanipulator",
14121 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
14122 "\n tool to create and manage AIS manipulators."
14123 "\n Options: "
14124 "\n '-attach AISObject' attach manipulator to AISObject"
14125 "\n '-adjustPosition {0|1}' adjust position when attaching"
14126 "\n '-adjustSize {0|1}' adjust size when attaching"
14127 "\n '-enableModes {0|1}' enable modes when attaching"
bbf3fcde 14128 "\n '-view {active | [name of view]}' display manipulator only in defined view,"
14129 "\n by default it is displayed in all views of the current viewer"
625e1958 14130 "\n '-detach' detach manipulator"
14131 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
14132 "\n '-transform mouse_x mouse_y' - invoke transformation"
14133 "\n '-stopTransform [abort]' - invoke stop of transformation"
14134 "\n '-move x y z' - move attached object"
14135 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
14136 "\n '-scale factor' - scale attached object"
14137 "\n '-autoActivate {0|1}' - set activation on detection"
14138 "\n '-followTranslation {0|1}' - set following translation transform"
14139 "\n '-followRotation {0|1}' - set following rotation transform"
f522ce50 14140 "\n '-followDragging {0|1}' - set following dragging transform"
625e1958 14141 "\n '-gap value' - set gap between sub-parts"
14142 "\n '-part axis mode {0|1}' - set visual part"
84b904bc 14143 "\n '-parts axis mode {0|1}' - set visual part"
625e1958 14144 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
14145 "\n '-size value' - set size of manipulator"
14146 "\n '-zoomable {0|1}' - set zoom persistence",
14147 __FILE__, VManipulator, group);
14148
8e5fb5ea 14149 theCommands.Add("vselprops",
f838dac4 14150 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
8e5fb5ea 14151 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
14152 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
be3d8cbc 14153 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
14154 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
14c4193d 14155 "\n -pickStrategy {first|topmost} : defines picking strategy"
14156 "\n 'first' to pick first acceptable (default)"
14157 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
8e5fb5ea 14158 "\n -pixTol value : sets up pixel tolerance"
f838dac4 14159 "\n -dispMode dispMode : sets display mode for highlighting"
14160 "\n -layer ZLayer : sets ZLayer for highlighting"
14161 "\n -color {name|r g b} : sets highlight color"
14162 "\n -transp value : sets transparency coefficient for highlight"
14163 "\n -material material : sets highlight material"
8e5fb5ea 14164 "\n -print : prints current state of all mentioned parameters",
14165 __FILE__, VSelectionProperties, group);
be3d8cbc 14166 theCommands.Add ("vhighlightselected",
14167 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
14168 __FILE__, VSelectionProperties, group);
8e5fb5ea 14169
decdee7d 14170 theCommands.Add ("vseldump",
14171 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
14172 "\n\t\t: Generate an image based on detection results:"
14173 "\n\t\t: depth normalized depth values"
14174 "\n\t\t: unnormDepth unnormalized depth values"
14175 "\n\t\t: object color of detected object"
14176 "\n\t\t: owner color of detected owner"
14177 "\n\t\t: selMode color of selection mode"
14178 "\n\t\t: entity color of etected entity",
14179 __FILE__, VDumpSelectionImage, group);
293211ae 14180
2108d9a2 14181 theCommands.Add ("vviewcube",
14182 "vviewcube name"
14183 "\n\t\t: Displays interactive view manipualtion object."
14184 "\n\t\t: Options: "
14185 "\n\t\t: -reset reset geomertical and visual attributes'"
14186 "\n\t\t: -size Size adapted size of View Cube"
14187 "\n\t\t: -boxSize Size box size"
14188 "\n\t\t: -axes {0|1 } show/hide axes (trihedron)"
14189 "\n\t\t: -edges {0|1} show/hide edges of View Cube"
14190 "\n\t\t: -vertices {0|1} show/hide vertices of View Cube"
14191 "\n\t\t: -Yup {0|1} -Zup {0|1} set Y-up or Z-up view orientation"
14192 "\n\t\t: -color Color color of View Cube"
14193 "\n\t\t: -boxColor Color box color"
14194 "\n\t\t: -boxSideColor Color box sides color"
14195 "\n\t\t: -boxEdgeColor Color box edges color"
14196 "\n\t\t: -boxCornerColor Color box corner color"
14197 "\n\t\t: -textColor Color color of side text of view cube"
14198 "\n\t\t: -innerColor Color inner box color"
14199 "\n\t\t: -transparency Value transparency of object within [0, 1] range"
14200 "\n\t\t: -boxTransparency Value transparency of box within [0, 1] range"
14201 "\n\t\t: -font Name font name"
14202 "\n\t\t: -fontHeight Value font height"
14203 "\n\t\t: -boxFacetExtension Value box facet extension"
14204 "\n\t\t: -boxEdgeGap Value gap between box edges and box sides"
14205 "\n\t\t: -boxEdgeMinSize Value minimal box edge size"
14206 "\n\t\t: -boxCornerMinSize Value minimal box corner size"
14207 "\n\t\t: -axesPadding Value padding between box and arrows"
14208 "\n\t\t: -roundRadius Value relative radius of corners of sides within [0.0, 0.5] range"
14209 "\n\t\t: -fixedanimation {0|1} uninterruptible animation loop"
14210 "\n\t\t: -duration Seconds animation duration in seconds",
14211 __FILE__, VViewCube, group);
14212
14213}