Commit | Line | Data |
---|---|---|
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> |
077a220c | 44 | #include <Graphic3d_CubeMapPacked.hxx> |
45 | #include <Graphic3d_CubeMapSeparate.hxx> | |
a79f67f8 | 46 | #include <Graphic3d_GraduatedTrihedron.hxx> |
49582f9d | 47 | #include <Graphic3d_NameOfTextureEnv.hxx> |
48 | #include <Graphic3d_Texture2Dmanual.hxx> | |
269294d6 | 49 | #include <Graphic3d_TextureEnv.hxx> |
50 | #include <Graphic3d_TextureParams.hxx> | |
51 | #include <Graphic3d_TypeOfTextureFilter.hxx> | |
49582f9d | 52 | #include <Image_AlienPixMap.hxx> |
53 | #include <Image_Diff.hxx> | |
54 | #include <Image_VideoRecorder.hxx> | |
08f8a185 | 55 | #include <Message_ProgressSentry.hxx> |
49582f9d | 56 | #include <NCollection_DataMap.hxx> |
18d715bd | 57 | #include <NCollection_List.hxx> |
58 | #include <NCollection_Vector.hxx> | |
8693dfd0 | 59 | #include <OSD.hxx> |
208e6839 | 60 | #include <OSD_Timer.hxx> |
49582f9d | 61 | #include <OpenGl_GraphicDriver.hxx> |
4269bd1b | 62 | #include <Prs3d_ShadingAspect.hxx> |
6262338c | 63 | #include <Prs3d_Drawer.hxx> |
61b0191c | 64 | #include <Prs3d_LineAspect.hxx> |
65 | #include <Prs3d_Root.hxx> | |
fd3f6bd0 | 66 | #include <Prs3d_Text.hxx> |
67 | #include <Select3D_SensitivePrimitiveArray.hxx> | |
49582f9d | 68 | #include <TColStd_HSequenceOfAsciiString.hxx> |
69 | #include <TColStd_SequenceOfInteger.hxx> | |
70 | #include <TColStd_HSequenceOfReal.hxx> | |
71 | #include <TColgp_Array1OfPnt2d.hxx> | |
72 | #include <TColStd_MapOfAsciiString.hxx> | |
73 | #include <ViewerTest_AutoUpdater.hxx> | |
74 | #include <ViewerTest_EventManager.hxx> | |
75 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> | |
76 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> | |
77 | #include <ViewerTest_CmdParser.hxx> | |
78 | #include <ViewerTest_V3dView.hxx> | |
79 | #include <V3d_AmbientLight.hxx> | |
80 | #include <V3d_DirectionalLight.hxx> | |
81 | #include <V3d_PositionalLight.hxx> | |
82 | #include <V3d_SpotLight.hxx> | |
7fd59977 | 83 | |
293211ae | 84 | #include <tcl.h> |
85 | ||
692613e5 | 86 | #include <cstdlib> |
25289ec1 | 87 | |
58655684 | 88 | #if defined(_WIN32) |
4fe56619 | 89 | #include <WNT_WClass.hxx> |
90 | #include <WNT_Window.hxx> | |
4fe56619 | 91 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
4fe56619 | 92 | #include <Cocoa_Window.hxx> |
7fd59977 | 93 | #else |
4fe56619 | 94 | #include <Xw_Window.hxx> |
95 | #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */ | |
96 | #include <X11/Xutil.h> | |
97 | #include <tk.h> | |
7fd59977 | 98 | #endif |
99 | ||
7fd59977 | 100 | //============================================================================== |
101 | // VIEWER GLOBAL VARIABLES | |
102 | //============================================================================== | |
103 | ||
104 | Standard_IMPORT Standard_Boolean Draw_VirtualWindows; | |
b514beda | 105 | Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand); |
7fd59977 | 106 | |
107 | Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv); | |
4754e164 | 108 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
7fd59977 | 109 | |
58655684 | 110 | #if defined(_WIN32) |
7fd59977 | 111 | static Handle(WNT_Window)& VT_GetWindow() { |
112 | static Handle(WNT_Window) WNTWin; | |
113 | return WNTWin; | |
114 | } | |
4fe56619 | 115 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
4fe56619 | 116 | static Handle(Cocoa_Window)& VT_GetWindow() |
117 | { | |
118 | static Handle(Cocoa_Window) aWindow; | |
119 | return aWindow; | |
120 | } | |
121 | extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow); | |
18d715bd | 122 | extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight); |
123 | ||
7fd59977 | 124 | #else |
7fd59977 | 125 | static Handle(Xw_Window)& VT_GetWindow(){ |
126 | static Handle(Xw_Window) XWWin; | |
127 | return XWWin; | |
128 | } | |
7fd59977 | 129 | |
130 | static void VProcessEvents(ClientData,int); | |
131 | #endif | |
132 | ||
18d715bd | 133 | static Handle(Aspect_DisplayConnection)& GetDisplayConnection() |
134 | { | |
135 | static Handle(Aspect_DisplayConnection) aDisplayConnection; | |
136 | return aDisplayConnection; | |
137 | } | |
138 | ||
139 | static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection) | |
140 | { | |
141 | GetDisplayConnection() = theDisplayConnection; | |
142 | } | |
143 | ||
18d715bd | 144 | NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews; |
58655684 | 145 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts; |
18d715bd | 146 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers; |
58655684 | 147 | static OpenGl_Caps ViewerTest_myDefaultCaps; |
18d715bd | 148 | |
7fd59977 | 149 | static void OSWindowSetup(); |
150 | ||
f42753ed | 151 | static struct |
152 | { | |
153 | Quantity_Color FlatColor; | |
154 | Quantity_Color GradientColor1; | |
155 | Quantity_Color GradientColor2; | |
156 | Aspect_GradientFillMethod FillMethod; | |
157 | } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE }; | |
158 | ||
7fd59977 | 159 | //============================================================================== |
160 | // EVENT GLOBAL VARIABLES | |
161 | //============================================================================== | |
162 | ||
1beb58d7 | 163 | Standard_Boolean TheIsAnimating = Standard_False; |
7fd59977 | 164 | |
293211ae | 165 | namespace |
166 | { | |
167 | ||
168 | //! Checks if some set is a subset of other set | |
169 | //! @tparam TheSuperSet the type of the superset | |
170 | //! @tparam TheSubSet the type of the subset | |
171 | //! @param theSuperSet the superset | |
172 | //! @param theSubSet the subset to be checked | |
173 | //! @return true if the superset includes subset, or false otherwise | |
174 | template <typename TheSuperSet, typename TheSubSet> | |
175 | static bool includes (const TheSuperSet& theSuperSet, const TheSubSet& theSubSet) | |
176 | { | |
177 | return std::includes (theSuperSet.begin(), theSuperSet.end(), theSubSet.begin(), theSubSet.end()); | |
178 | } | |
179 | ||
180 | //! A variable set of keys for command-line options. | |
181 | //! It includes a set of mandatory keys and a set of all possible keys. | |
182 | class CommandOptionKeyVariableSet | |
183 | { | |
184 | public: | |
185 | //! Default constructor | |
186 | CommandOptionKeyVariableSet() | |
187 | { | |
188 | } | |
189 | ||
190 | //! Constructor | |
191 | //! @param theMandatoryKeySet the set of the mandatory option keys | |
192 | //! @param theAdditionalKeySet the set of additional options that could be omitted | |
193 | CommandOptionKeyVariableSet ( | |
194 | const ViewerTest_CommandOptionKeySet& theMandatoryKeySet, | |
195 | const ViewerTest_CommandOptionKeySet& theAdditionalKeySet = ViewerTest_CommandOptionKeySet()) | |
196 | : myMandatoryKeySet (theMandatoryKeySet) | |
197 | { | |
198 | std::set_union (theMandatoryKeySet.begin(), | |
199 | theMandatoryKeySet.end(), | |
200 | theAdditionalKeySet.begin(), | |
201 | theAdditionalKeySet.end(), | |
202 | std::inserter (myFullKeySet, myFullKeySet.begin())); | |
203 | } | |
204 | ||
205 | //! Checks if the set of option keys fits to the current variable set (it must contain all mandatory keys | |
206 | //! and be contained in the full key set) | |
207 | //! @param theCheckedKeySet the set of option keys to be checked | |
208 | bool IsInSet (const ViewerTest_CommandOptionKeySet& theCheckedKeySet) const | |
209 | { | |
210 | return includes (theCheckedKeySet, myMandatoryKeySet) && includes (myFullKeySet, theCheckedKeySet); | |
211 | } | |
212 | ||
213 | private: | |
214 | //! A set of mandatory command-line option keys | |
215 | ViewerTest_CommandOptionKeySet myMandatoryKeySet; | |
216 | ||
217 | //! A full set of command-line option keys (includes mandatory and additional option keys) | |
218 | ViewerTest_CommandOptionKeySet myFullKeySet; | |
219 | }; | |
220 | ||
221 | //! Gets some code by its name | |
222 | //! @tparam TheCode the type of a code to be found | |
223 | //! @param theCodeNameMap the map from code names to codes | |
224 | //! @param theCodeName the name of a code to be found | |
225 | //! @param theCode the code to be found | |
226 | //! @return true if a code is found, or false otherwise | |
227 | template <typename TheCode> | |
228 | static bool getSomeCodeByName (const std::map<TCollection_AsciiString, TheCode>& theCodeNameMap, | |
229 | TCollection_AsciiString theCodeName, | |
230 | TheCode& theCode) | |
231 | { | |
232 | theCodeName.LowerCase(); | |
233 | const typename std::map<TCollection_AsciiString, TheCode>::const_iterator aCodeIterator = theCodeNameMap.find ( | |
234 | theCodeName); | |
235 | if (aCodeIterator == theCodeNameMap.end()) | |
236 | { | |
237 | return false; | |
238 | } | |
239 | theCode = aCodeIterator->second; | |
240 | return true; | |
241 | } | |
242 | ||
243 | // Defines possible commands related to background changing | |
244 | enum BackgroundCommand | |
245 | { | |
077a220c | 246 | BackgroundCommand_Main, //!< The main command that manages other commands through options |
247 | BackgroundCommand_Image, //!< Sets an image as a background | |
248 | BackgroundCommand_ImageMode, //!< Changes a background image mode | |
249 | BackgroundCommand_Gradient, //!< Sets a gradient as a background | |
250 | BackgroundCommand_GradientMode, //!< Changes a background gradient mode | |
251 | BackgroundCommand_Color, //!< Fills background with a specified color | |
252 | BackgroundCommand_Default //!< Sets the background default color or gradient | |
293211ae | 253 | }; |
254 | ||
255 | //! Map from background command names to its codes | |
256 | typedef std::map<TCollection_AsciiString, BackgroundCommand> BackgroundCommandNameMap; | |
257 | ||
258 | //! Creates a map from background command names to its codes | |
259 | //! @return a map from background command names to its codes | |
260 | static BackgroundCommandNameMap createBackgroundCommandNameMap() | |
261 | { | |
262 | BackgroundCommandNameMap aBackgroundCommandNameMap; | |
077a220c | 263 | aBackgroundCommandNameMap["vbackground"] = BackgroundCommand_Main; |
264 | aBackgroundCommandNameMap["vsetbg"] = BackgroundCommand_Image; | |
265 | aBackgroundCommandNameMap["vsetbgmode"] = BackgroundCommand_ImageMode; | |
266 | aBackgroundCommandNameMap["vsetgradientbg"] = BackgroundCommand_Gradient; | |
267 | aBackgroundCommandNameMap["vsetgrbgmode"] = BackgroundCommand_GradientMode; | |
268 | aBackgroundCommandNameMap["vsetcolorbg"] = BackgroundCommand_Color; | |
269 | aBackgroundCommandNameMap["vsetdefaultbg"] = BackgroundCommand_Default; | |
293211ae | 270 | return aBackgroundCommandNameMap; |
271 | } | |
272 | ||
273 | //! Gets a background command by its name | |
274 | //! @param theBackgroundCommandName the name of the background command | |
275 | //! @param theBackgroundCommand the background command to be found | |
276 | //! @return true if a background command is found, or false otherwise | |
277 | static bool getBackgroundCommandByName (const TCollection_AsciiString& theBackgroundCommandName, | |
278 | BackgroundCommand& theBackgroundCommand) | |
279 | { | |
280 | static const BackgroundCommandNameMap THE_BACKGROUND_COMMAND_NAME_MAP = createBackgroundCommandNameMap(); | |
281 | return getSomeCodeByName (THE_BACKGROUND_COMMAND_NAME_MAP, theBackgroundCommandName, theBackgroundCommand); | |
282 | } | |
283 | ||
284 | //! Map from background image fill method names to its codes | |
285 | typedef std::map<TCollection_AsciiString, Aspect_FillMethod> BackgroundImageFillMethodNameMap; | |
286 | ||
287 | //! Creates a map from background image fill method names to its codes | |
288 | //! @return a map from background image fill method names to its codes | |
289 | static BackgroundImageFillMethodNameMap createBackgroundImageFillMethodNameMap() | |
290 | { | |
291 | BackgroundImageFillMethodNameMap aBackgroundImageFillMethodNameMap; | |
292 | aBackgroundImageFillMethodNameMap["none"] = Aspect_FM_NONE; | |
293 | aBackgroundImageFillMethodNameMap["centered"] = Aspect_FM_CENTERED; | |
294 | aBackgroundImageFillMethodNameMap["tiled"] = Aspect_FM_TILED; | |
295 | aBackgroundImageFillMethodNameMap["stretch"] = Aspect_FM_STRETCH; | |
296 | return aBackgroundImageFillMethodNameMap; | |
297 | } | |
298 | ||
299 | //! Gets a background image fill method by its name | |
300 | //! @param theBackgroundImageFillMethodName the name of the background image fill method | |
301 | //! @param theBackgroundImageFillMethod the background image fill method to be found | |
302 | //! @return true if a background image fill method is found, or false otherwise | |
303 | static bool getBackgroundImageFillMethodByName (const TCollection_AsciiString& theBackgroundImageFillMethodName, | |
304 | Aspect_FillMethod& theBackgroundImageFillMethod) | |
305 | { | |
306 | static const BackgroundImageFillMethodNameMap THE_BACKGROUND_IMAGE_FILL_METHOD_NAME_MAP = | |
307 | createBackgroundImageFillMethodNameMap(); | |
308 | return getSomeCodeByName (THE_BACKGROUND_IMAGE_FILL_METHOD_NAME_MAP, | |
309 | theBackgroundImageFillMethodName, | |
310 | theBackgroundImageFillMethod); | |
311 | } | |
312 | ||
313 | //! Map from background gradient fill method names to its codes | |
314 | typedef std::map<TCollection_AsciiString, Aspect_GradientFillMethod> BackgroundGradientFillMethodNameMap; | |
315 | ||
316 | //! Creates a map from background gradient fill method names to its codes | |
317 | //! @return a map from background gradient fill method names to its codes | |
318 | static BackgroundGradientFillMethodNameMap createBackgroundGradientFillMethodNameMap() | |
319 | { | |
320 | BackgroundGradientFillMethodNameMap aBackgroundGradientFillMethodNameMap; | |
321 | aBackgroundGradientFillMethodNameMap["none"] = Aspect_GFM_NONE; | |
322 | aBackgroundGradientFillMethodNameMap["hor"] = Aspect_GFM_HOR; | |
323 | aBackgroundGradientFillMethodNameMap["horizontal"] = Aspect_GFM_HOR; | |
324 | aBackgroundGradientFillMethodNameMap["ver"] = Aspect_GFM_VER; | |
325 | aBackgroundGradientFillMethodNameMap["vertical"] = Aspect_GFM_VER; | |
326 | aBackgroundGradientFillMethodNameMap["diag1"] = Aspect_GFM_DIAG1; | |
327 | aBackgroundGradientFillMethodNameMap["diagonal1"] = Aspect_GFM_DIAG1; | |
328 | aBackgroundGradientFillMethodNameMap["diag2"] = Aspect_GFM_DIAG2; | |
329 | aBackgroundGradientFillMethodNameMap["diagonal2"] = Aspect_GFM_DIAG2; | |
330 | aBackgroundGradientFillMethodNameMap["corner1"] = Aspect_GFM_CORNER1; | |
331 | aBackgroundGradientFillMethodNameMap["corner2"] = Aspect_GFM_CORNER2; | |
332 | aBackgroundGradientFillMethodNameMap["corner3"] = Aspect_GFM_CORNER3; | |
333 | aBackgroundGradientFillMethodNameMap["corner4"] = Aspect_GFM_CORNER4; | |
334 | return aBackgroundGradientFillMethodNameMap; | |
335 | } | |
336 | ||
337 | //! Gets a gradient fill method by its name | |
338 | //! @param theBackgroundGradientFillMethodName the name of the gradient fill method | |
339 | //! @param theBackgroundGradientFillMethod the gradient fill method to be found | |
340 | //! @return true if a gradient fill method is found, or false otherwise | |
341 | static bool getBackgroundGradientFillMethodByName (const TCollection_AsciiString& theBackgroundGradientFillMethodName, | |
342 | Aspect_GradientFillMethod& theBackgroundGradientFillMethod) | |
343 | { | |
344 | static const BackgroundGradientFillMethodNameMap THE_BACKGROUND_GRADIENT_FILL_METHOD_NAME_MAP = | |
345 | createBackgroundGradientFillMethodNameMap(); | |
346 | return getSomeCodeByName (THE_BACKGROUND_GRADIENT_FILL_METHOD_NAME_MAP, | |
347 | theBackgroundGradientFillMethodName, | |
348 | theBackgroundGradientFillMethod); | |
349 | } | |
350 | ||
351 | //! Changes the background in accordance with passed command line options | |
352 | class BackgroundChanger | |
353 | { | |
354 | public: | |
355 | //! Constructor. Prepares the command parser | |
356 | BackgroundChanger() | |
357 | { | |
358 | prepareCommandParser(); | |
359 | } | |
360 | ||
361 | //! Processes the command line and changes the background | |
362 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
363 | //! @param theNumberOfCommandLineArguments the number of passed command line arguments | |
364 | //! @param theCommandLineArguments the array of command line arguments | |
365 | bool ProcessCommandLine (Draw_Interpretor& theDrawInterpretor, | |
366 | const Standard_Integer theNumberOfCommandLineArguments, | |
367 | const char* const* const theCommandLineArguments) | |
368 | { | |
369 | const char* const aBackgroundCommandName = theCommandLineArguments[0]; | |
370 | BackgroundCommand aBackgroundCommand = BackgroundCommand_Main; | |
371 | if (!getBackgroundCommandByName (aBackgroundCommandName, aBackgroundCommand)) | |
372 | { | |
373 | return false; | |
374 | } | |
375 | addCommandDescription (aBackgroundCommand); | |
376 | myCommandParser.Parse (theNumberOfCommandLineArguments, theCommandLineArguments); | |
377 | return processCommandOptions (aBackgroundCommandName, aBackgroundCommand, theDrawInterpretor); | |
378 | } | |
379 | ||
380 | private: | |
381 | //! The type of functions that are able to set gradient background filling | |
382 | typedef void SetGradientFunction (const Quantity_Color& /* theColor1 */, | |
383 | const Quantity_Color& /* theColor2 */, | |
384 | const Aspect_GradientFillMethod /* theGradientMode */); | |
385 | ||
386 | //! The type of functions that are able to fill a background with a specific color | |
387 | typedef void SetColorFunction (const Quantity_Color& /* theColor */); | |
388 | ||
389 | //! the command parser used to parse command line options and its arguments | |
390 | ViewerTest_CmdParser myCommandParser; | |
391 | ||
392 | //! the option key for the command that sets an image as a background | |
393 | ViewerTest_CommandOptionKey myImageOptionKey; | |
394 | ||
395 | //! the option key for the command that sets a background image fill type | |
396 | ViewerTest_CommandOptionKey myImageModeOptionKey; | |
397 | ||
398 | //! the option key for the command that sets a gradient filling for the background | |
399 | ViewerTest_CommandOptionKey myGradientOptionKey; | |
400 | ||
401 | //! the option key for the command that sets a background gradient filling method | |
402 | ViewerTest_CommandOptionKey myGradientModeOptionKey; | |
403 | ||
404 | //! the option key for the command that fills background with a specific color | |
405 | ViewerTest_CommandOptionKey myColorOptionKey; | |
406 | ||
407 | //! the option key for the command that sets default background gradient or color | |
408 | ViewerTest_CommandOptionKey myDefaultOptionKey; | |
409 | ||
077a220c | 410 | //! the option key for the command that sets an environment cubemap as a background |
411 | ViewerTest_CommandOptionKey myCubeMapOptionKey; | |
412 | ||
413 | //! the option key for the command that defines order of tiles in one image packed cubemap | |
414 | ViewerTest_CommandOptionKey myCubeMapOrderOptionKey; | |
415 | ||
416 | //! the option key for the command that sets inversion of Z axis for background cubemap | |
417 | ViewerTest_CommandOptionKey myCubeMapInvertedZOptionKey; | |
418 | ||
67312b79 | 419 | //! the option key for the command that allows skip IBL map generation |
420 | ViewerTest_CommandOptionKey myCubeMapDoNotGenPBREnvOptionKey; | |
421 | ||
293211ae | 422 | //! the variable set of options that are allowed for the old scenario (without any option passed) |
423 | CommandOptionKeyVariableSet myUnnamedOptionVariableSet; | |
424 | ||
077a220c | 425 | //! the variable set of options that are allowed for setting an environment cubemap as background |
426 | CommandOptionKeyVariableSet myCubeMapOptionVariableSet; | |
427 | ||
293211ae | 428 | //! the variable set of options that are allowed for setting an image as a background |
429 | CommandOptionKeyVariableSet myImageOptionVariableSet; | |
430 | ||
431 | //! the variable set of options that are allowed for setting a background image fill type | |
432 | CommandOptionKeyVariableSet myImageModeOptionVariableSet; | |
433 | ||
434 | //! the variable set of options that are allowed for setting a gradient filling for the background | |
435 | CommandOptionKeyVariableSet myGradientOptionVariableSet; | |
436 | ||
437 | //! the variable set of options that are allowed for setting a background gradient filling method | |
438 | CommandOptionKeyVariableSet myGradientModeOptionVariableSet; | |
439 | ||
440 | //! the variable set of options that are allowed for filling a background with a specific color | |
441 | CommandOptionKeyVariableSet myColorOptionVariableSet; | |
442 | ||
443 | //! the variable set of options that are allowed for setting a default background gradient | |
444 | CommandOptionKeyVariableSet myDefaultGradientOptionVariableSet; | |
445 | ||
446 | //! the variable set of options that are allowed for setting a default background color | |
447 | CommandOptionKeyVariableSet myDefaultColorOptionVariableSet; | |
448 | ||
449 | //! the variable set of options that are allowed for printing help | |
450 | CommandOptionKeyVariableSet myHelpOptionVariableSet; | |
451 | ||
452 | //! Adds options to command parser | |
453 | void addOptionsToCommandParser() | |
454 | { | |
455 | myImageOptionKey = myCommandParser.AddOption ("imageFile|image|imgFile|img", | |
456 | "filename of image used as background"); | |
457 | myImageModeOptionKey = myCommandParser.AddOption ( | |
458 | "imageMode|imgMode", "image fill type, should be one of CENTERED, TILED, STRETCH, NONE"); | |
459 | myGradientOptionKey = myCommandParser.AddOption ("gradient|grad|gr", | |
460 | "sets background gradient starting and ending colors"); | |
461 | myGradientModeOptionKey = | |
462 | myCommandParser.AddOption ("gradientMode|gradMode|gradMd|grMode|grMd", | |
463 | "gradient fill method, should be one of NONE, HOR[IZONTAL], VER[TICAL], " | |
464 | "DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, CORNER4"); | |
465 | myColorOptionKey = myCommandParser.AddOption ("color|col", "background color"); | |
466 | myDefaultOptionKey = myCommandParser.AddOption ("default|def", "sets background default gradient or color"); | |
077a220c | 467 | |
468 | myCubeMapOptionKey = myCommandParser.AddOption ("cubemap|cmap|cm", "background cubemap"); | |
469 | myCubeMapOrderOptionKey = myCommandParser.AddOption ("order|o", "order of sides in one image packed cubemap"); | |
470 | myCubeMapInvertedZOptionKey = myCommandParser.AddOption ( | |
471 | "invertedz|invz|iz", "whether Z axis is inverted or not during background cubemap rendering"); | |
67312b79 | 472 | myCubeMapDoNotGenPBREnvOptionKey = myCommandParser.AddOption ("nopbrenv", "whether IBL map generation should be skipped"); |
293211ae | 473 | } |
474 | ||
475 | //! Creates option sets used to determine if a passed option set is valid or not | |
476 | void createOptionSets() | |
477 | { | |
478 | ViewerTest_CommandOptionKeySet anUnnamedOptionSet; | |
479 | anUnnamedOptionSet.insert (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY); | |
480 | myUnnamedOptionVariableSet = CommandOptionKeyVariableSet (anUnnamedOptionSet); | |
481 | ||
077a220c | 482 | ViewerTest_CommandOptionKeySet aCubeMapOptionSet; |
483 | aCubeMapOptionSet.insert (myCubeMapOptionKey); | |
484 | ViewerTest_CommandOptionKeySet aCubeMapAdditionalOptionKeySet; | |
485 | aCubeMapAdditionalOptionKeySet.insert (myCubeMapInvertedZOptionKey); | |
67312b79 | 486 | aCubeMapAdditionalOptionKeySet.insert (myCubeMapDoNotGenPBREnvOptionKey); |
077a220c | 487 | aCubeMapAdditionalOptionKeySet.insert (myCubeMapOrderOptionKey); |
488 | myCubeMapOptionVariableSet = CommandOptionKeyVariableSet (aCubeMapOptionSet, aCubeMapAdditionalOptionKeySet); | |
489 | ||
293211ae | 490 | ViewerTest_CommandOptionKeySet anImageOptionSet; |
491 | anImageOptionSet.insert (myImageOptionKey); | |
492 | ViewerTest_CommandOptionKeySet anImageModeOptionSet; | |
493 | anImageModeOptionSet.insert (myImageModeOptionKey); | |
494 | myImageOptionVariableSet = CommandOptionKeyVariableSet (anImageOptionSet, anImageModeOptionSet); | |
495 | myImageModeOptionVariableSet = CommandOptionKeyVariableSet (anImageModeOptionSet); | |
496 | ||
497 | ViewerTest_CommandOptionKeySet aGradientOptionSet; | |
498 | aGradientOptionSet.insert (myGradientOptionKey); | |
499 | ViewerTest_CommandOptionKeySet aGradientModeOptionSet; | |
500 | aGradientModeOptionSet.insert (myGradientModeOptionKey); | |
501 | myGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet); | |
502 | myGradientModeOptionVariableSet = CommandOptionKeyVariableSet (aGradientModeOptionSet); | |
503 | ||
504 | ViewerTest_CommandOptionKeySet aColorOptionSet; | |
505 | aColorOptionSet.insert (myColorOptionKey); | |
506 | myColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet); | |
507 | ||
508 | aGradientOptionSet.insert (myDefaultOptionKey); | |
509 | myDefaultGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet); | |
510 | aColorOptionSet.insert (myDefaultOptionKey); | |
511 | myDefaultColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet); | |
512 | ||
513 | ViewerTest_CommandOptionKeySet aHelpOptionSet; | |
514 | aHelpOptionSet.insert (ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY); | |
515 | myHelpOptionVariableSet = CommandOptionKeyVariableSet (aHelpOptionSet); | |
516 | } | |
517 | ||
518 | //! Prepares the command parser. Adds options and creates option sets used to determine | |
519 | //! if a passed option set is valid or not | |
520 | void prepareCommandParser() | |
521 | { | |
522 | addOptionsToCommandParser(); | |
523 | createOptionSets(); | |
524 | } | |
525 | ||
526 | //! Adds a command description to the command parser | |
527 | //! @param theBackgroundCommand the key of the command which description is added to the command parser | |
528 | void addCommandDescription (const BackgroundCommand theBackgroundCommand) | |
529 | { | |
530 | std::string aDescription; | |
531 | bool isMainCommand = false; | |
532 | switch (theBackgroundCommand) | |
533 | { | |
534 | case BackgroundCommand_Main: | |
535 | aDescription = "Command: vbackground (changes background or some background settings)"; | |
536 | isMainCommand = true; | |
537 | break; | |
538 | case BackgroundCommand_Image: | |
539 | aDescription = "Command: vsetbg (loads image as a background)"; | |
540 | break; | |
541 | case BackgroundCommand_ImageMode: | |
542 | aDescription = "Command: vsetbgmode (changes background fill type)"; | |
543 | break; | |
544 | case BackgroundCommand_Gradient: | |
545 | aDescription = "Command: vsetgradientbg (mounts gradient background)"; | |
546 | break; | |
547 | case BackgroundCommand_GradientMode: | |
548 | aDescription = "Command: vsetgradientbgmode (changes gradient background fill method)"; | |
549 | break; | |
550 | case BackgroundCommand_Color: | |
551 | aDescription = "Command: vsetcolorbg (sets color background)"; | |
552 | break; | |
553 | case BackgroundCommand_Default: | |
554 | aDescription = "Command: vsetdefaultbg (sets default viewer background gradient or fill color)"; | |
555 | break; | |
556 | default: | |
557 | return; | |
558 | } | |
559 | if (!isMainCommand) | |
560 | { | |
561 | aDescription += "\nThis command is obsolete. Use vbackground instead."; | |
562 | } | |
563 | myCommandParser.SetDescription (aDescription); | |
564 | } | |
565 | ||
566 | //! Check if a viewer is needed to be initialized | |
567 | //! @param theBackgroundCommand the key of the command that changes the background | |
568 | //! @return true if processing was successful, or false otherwise | |
569 | bool checkViewerIsNeeded (const BackgroundCommand theBackgroundCommand) const | |
570 | { | |
571 | const bool isMain = (theBackgroundCommand == BackgroundCommand_Main); | |
572 | const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions(); | |
573 | const bool aViewerIsNotNeeded = | |
574 | (theBackgroundCommand == BackgroundCommand_Default) | |
575 | || (myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain) | |
576 | || (myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain) | |
577 | || myHelpOptionVariableSet.IsInSet (aUsedOptions); | |
578 | return !aViewerIsNotNeeded; | |
579 | } | |
580 | ||
581 | //! Check if a viewer is initialized | |
582 | //! @param theBackgroundCommandName the name of the command that changes the background | |
583 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
584 | //! @return true if a viewer is initialized, or false otherwise | |
585 | static bool checkViewerIsInitialized (const char* const theBackgroundCommandName, | |
586 | Draw_Interpretor& theDrawInterpretor) | |
587 | { | |
588 | const Handle (AIS_InteractiveContext)& anAISContext = ViewerTest::GetAISContext(); | |
589 | if (anAISContext.IsNull()) | |
590 | { | |
591 | theDrawInterpretor << "Use 'vinit' command before executing '" << theBackgroundCommandName << "' command.\n"; | |
592 | return false; | |
593 | } | |
594 | return true; | |
595 | } | |
596 | ||
597 | //! Processes command options | |
598 | //! @param theBackgroundCommandName the name of the command that changes the background | |
599 | //! @param theBackgroundCommand the key of the command that changes the background | |
600 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
601 | //! @return true if processing was successful, or false otherwise | |
602 | bool processCommandOptions (const char* const theBackgroundCommandName, | |
603 | const BackgroundCommand theBackgroundCommand, | |
604 | Draw_Interpretor& theDrawInterpretor) const | |
605 | { | |
606 | if (myCommandParser.HasNoOption()) | |
607 | { | |
608 | return printHelp (theBackgroundCommandName, theDrawInterpretor); | |
609 | } | |
610 | if (checkViewerIsNeeded (theBackgroundCommand) | |
611 | && !checkViewerIsInitialized (theBackgroundCommandName, theDrawInterpretor)) | |
612 | { | |
613 | return false; | |
614 | } | |
615 | if (myCommandParser.HasOnlyUnnamedOption()) | |
616 | { | |
617 | return processUnnamedOption (theBackgroundCommand); | |
618 | } | |
619 | return processNamedOptions (theBackgroundCommandName, theBackgroundCommand, theDrawInterpretor); | |
620 | } | |
621 | ||
622 | //! Processes the unnamed option | |
623 | //! @param theBackgroundCommand the key of the command that changes the background | |
624 | //! @return true if processing was successful, or false otherwise | |
625 | bool processUnnamedOption (const BackgroundCommand theBackgroundCommand) const | |
626 | { | |
627 | switch (theBackgroundCommand) | |
628 | { | |
629 | case BackgroundCommand_Main: | |
630 | return false; | |
631 | case BackgroundCommand_Image: | |
632 | return processImageUnnamedOption(); | |
633 | case BackgroundCommand_ImageMode: | |
634 | return processImageModeUnnamedOption(); | |
635 | case BackgroundCommand_Gradient: | |
636 | return processGradientUnnamedOption(); | |
637 | case BackgroundCommand_GradientMode: | |
638 | return processGradientModeUnnamedOption(); | |
639 | case BackgroundCommand_Color: | |
640 | return processColorUnnamedOption(); | |
641 | case BackgroundCommand_Default: | |
642 | return processDefaultUnnamedOption(); | |
643 | default: | |
644 | return false; | |
645 | } | |
646 | } | |
647 | ||
648 | //! Processes the image unnamed option | |
649 | //! @return true if processing was successful, or false otherwise | |
650 | bool processImageUnnamedOption() const | |
651 | { | |
652 | const std::size_t aNumberOfImageUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
653 | ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY); | |
654 | if ((aNumberOfImageUnnamedOptionArguments != 1) && (aNumberOfImageUnnamedOptionArguments != 2)) | |
655 | { | |
656 | return false; | |
657 | } | |
658 | std::string anImageFileName; | |
659 | if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0, anImageFileName)) | |
660 | { | |
661 | return false; | |
662 | } | |
663 | Aspect_FillMethod anImageMode = Aspect_FM_CENTERED; | |
664 | if (aNumberOfImageUnnamedOptionArguments == 2) | |
665 | { | |
666 | std::string anImageModeString; | |
667 | if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 1, anImageModeString)) | |
668 | { | |
669 | return false; | |
670 | } | |
671 | if (!getBackgroundImageFillMethodByName (anImageModeString.c_str(), anImageMode)) | |
672 | { | |
673 | return false; | |
674 | } | |
675 | } | |
676 | setImage (anImageFileName.c_str(), anImageMode); | |
677 | return true; | |
678 | } | |
679 | ||
680 | //! Processes the image mode unnamed option | |
681 | //! @return true if processing was successful, or false otherwise | |
682 | bool processImageModeUnnamedOption() const | |
683 | { | |
684 | return processImageModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY); | |
685 | } | |
686 | ||
687 | //! Processes the gradient unnamed option | |
688 | //! @param theSetGradient the function used to set a background gradient filling | |
689 | //! @return true if processing was successful, or false otherwise | |
690 | bool processGradientUnnamedOption (SetGradientFunction* const theSetGradient = setGradient) const | |
691 | { | |
692 | const Standard_Integer aNumberOfGradientUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
693 | ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY); | |
694 | if (aNumberOfGradientUnnamedOptionArguments < 2) | |
695 | { | |
696 | return false; | |
697 | } | |
698 | ||
699 | Standard_Integer anArgumentIndex = 0; | |
700 | Quantity_Color aColor1; | |
701 | if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor1)) | |
702 | { | |
703 | return false; | |
704 | } | |
705 | if (anArgumentIndex >= aNumberOfGradientUnnamedOptionArguments) | |
706 | { | |
707 | return false; | |
708 | } | |
709 | ||
710 | Quantity_Color aColor2; | |
711 | if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor2)) | |
712 | { | |
713 | return false; | |
714 | } | |
715 | if (anArgumentIndex > aNumberOfGradientUnnamedOptionArguments) | |
716 | { | |
717 | return false; | |
718 | } | |
719 | ||
720 | Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR; | |
721 | if (anArgumentIndex == aNumberOfGradientUnnamedOptionArguments - 1) | |
722 | { | |
723 | std::string anGradientModeString; | |
724 | ||
725 | if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, | |
726 | anArgumentIndex, | |
727 | anGradientModeString)) | |
728 | { | |
729 | return false; | |
730 | } | |
731 | if (!getBackgroundGradientFillMethodByName (anGradientModeString.c_str(), aGradientMode)) | |
732 | { | |
733 | return false; | |
734 | } | |
735 | ++anArgumentIndex; | |
736 | } | |
737 | if (anArgumentIndex != aNumberOfGradientUnnamedOptionArguments) | |
738 | { | |
739 | return false; | |
740 | } | |
741 | theSetGradient (aColor1, aColor2, aGradientMode); | |
742 | return true; | |
743 | } | |
744 | ||
745 | //! Processes the gradient mode unnamed option | |
746 | //! @return true if processing was successful, or false otherwise | |
747 | bool processGradientModeUnnamedOption() const | |
748 | { | |
749 | return processGradientModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY); | |
750 | } | |
751 | ||
752 | //! Processes the color unnamed option | |
753 | //! @param theSetColor the function used to set a background color | |
754 | //! @return true if processing was successful, or false otherwise | |
755 | bool processColorUnnamedOption (SetColorFunction* const theSetColor = setColor) const | |
756 | { | |
757 | return processColorOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, theSetColor); | |
758 | } | |
759 | ||
760 | //! Processes the default back unnamed option | |
761 | //! @return true if processing was successful, or false otherwise | |
762 | bool processDefaultUnnamedOption() const | |
763 | { | |
764 | if (processGradientUnnamedOption (setDefaultGradient)) | |
765 | { | |
766 | return true; | |
767 | } | |
768 | return processColorUnnamedOption (setDefaultColor); | |
769 | } | |
770 | ||
771 | //! Processes named options | |
772 | //! @param theBackgroundCommandName the name of the command that changes the background | |
773 | //! @param theBackgroundCommand the key of the command that changes the background | |
774 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
775 | //! @return true if processing was successful, or false otherwise | |
776 | bool processNamedOptions (const char* const theBackgroundCommandName, | |
777 | const BackgroundCommand theBackgroundCommand, | |
778 | Draw_Interpretor& theDrawInterpretor) const | |
779 | { | |
780 | const bool isMain = (theBackgroundCommand == BackgroundCommand_Main); | |
781 | const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions(); | |
077a220c | 782 | if (myCubeMapOptionVariableSet.IsInSet (aUsedOptions) && isMain) |
783 | { | |
784 | return processCubeMapOptionSet(); | |
785 | } | |
293211ae | 786 | if (myImageOptionVariableSet.IsInSet (aUsedOptions) |
787 | && (isMain || (theBackgroundCommand == BackgroundCommand_Image))) | |
788 | { | |
789 | return processImageOptionSet(); | |
790 | } | |
791 | if (myImageModeOptionVariableSet.IsInSet (aUsedOptions) | |
792 | && (isMain || (theBackgroundCommand == BackgroundCommand_ImageMode))) | |
793 | { | |
794 | return processImageModeOptionSet(); | |
795 | } | |
796 | if (myGradientOptionVariableSet.IsInSet (aUsedOptions) | |
797 | && (isMain || (theBackgroundCommand == BackgroundCommand_Gradient))) | |
798 | { | |
799 | return processGradientOptionSet(); | |
800 | } | |
801 | if (myGradientModeOptionVariableSet.IsInSet (aUsedOptions) | |
802 | && (isMain || (theBackgroundCommand == BackgroundCommand_GradientMode))) | |
803 | { | |
804 | return processGradientModeOptionSet(); | |
805 | } | |
806 | if (myColorOptionVariableSet.IsInSet (aUsedOptions) | |
807 | && (isMain || (theBackgroundCommand == BackgroundCommand_Color))) | |
808 | { | |
809 | return processColorOptionSet(); | |
810 | } | |
811 | if ((myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain) | |
812 | || (myGradientOptionVariableSet.IsInSet (aUsedOptions) | |
813 | && (theBackgroundCommand == BackgroundCommand_Default))) | |
814 | { | |
815 | return processDefaultGradientOptionSet(); | |
816 | } | |
817 | if ((myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain) | |
818 | || (myColorOptionVariableSet.IsInSet (aUsedOptions) && (theBackgroundCommand == BackgroundCommand_Default))) | |
819 | { | |
820 | return processDefaultColorOptionSet(); | |
821 | } | |
822 | if (myHelpOptionVariableSet.IsInSet (aUsedOptions)) | |
823 | { | |
824 | return processHelpOptionSet (theBackgroundCommandName, theDrawInterpretor); | |
825 | } | |
826 | return false; | |
827 | } | |
828 | ||
077a220c | 829 | //! Process the cubemap option set in named and unnamed case. |
830 | //! @return true if processing was successful, or false otherwise | |
831 | bool processCubeMapOptionSet() const | |
832 | { | |
833 | NCollection_Array1<TCollection_AsciiString> aFilePaths; | |
834 | ||
835 | if (!processCubeMapOptions (aFilePaths)) | |
836 | { | |
837 | return false; | |
838 | } | |
839 | ||
840 | Graphic3d_CubeMapOrder anOrder = Graphic3d_CubeMapOrder::Default(); | |
841 | ||
842 | if (myCommandParser.HasOption (myCubeMapOrderOptionKey)) | |
843 | { | |
844 | if (!processCubeMapOrderOptions (anOrder)) | |
845 | { | |
846 | return false; | |
847 | } | |
848 | } | |
849 | ||
850 | bool aZIsInverted = false; | |
851 | if (myCommandParser.HasOption (myCubeMapInvertedZOptionKey)) | |
852 | { | |
853 | if (!processCubeMapInvertedZOptionSet()) | |
854 | { | |
855 | return false; | |
856 | } | |
857 | aZIsInverted = true; | |
858 | } | |
859 | ||
67312b79 | 860 | bool aToGenPBREnv = true; |
861 | if (myCommandParser.HasOption (myCubeMapDoNotGenPBREnvOptionKey)) | |
862 | { | |
863 | if (!processCubeMapDoNotGenPBREnvOptionSet()) | |
864 | { | |
865 | return false; | |
866 | } | |
867 | aToGenPBREnv = false; | |
868 | } | |
869 | ||
870 | setCubeMap (aFilePaths, anOrder.Validated(), aZIsInverted, aToGenPBREnv); | |
077a220c | 871 | return true; |
872 | } | |
873 | ||
293211ae | 874 | //! Processes the image option set |
875 | //! @return true if processing was successful, or false otherwise | |
876 | bool processImageOptionSet() const | |
877 | { | |
878 | std::string anImageFileName; | |
879 | if (!processImageOption (anImageFileName)) | |
880 | { | |
881 | return false; | |
882 | } | |
883 | Aspect_FillMethod anImageMode = Aspect_FM_CENTERED; | |
884 | if (myCommandParser.HasOption (myImageModeOptionKey) && !processImageModeOption (anImageMode)) | |
885 | { | |
886 | return false; | |
887 | } | |
888 | setImage (anImageFileName.c_str(), anImageMode); | |
889 | return true; | |
890 | } | |
891 | ||
892 | //! Processes the image mode option set | |
893 | //! @return true if processing was successful, or false otherwise | |
894 | bool processImageModeOptionSet() const | |
895 | { | |
896 | return processImageModeOptionSet (myImageModeOptionKey); | |
897 | } | |
898 | ||
899 | //! Processes the image mode option set | |
900 | //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option | |
901 | //! @return true if processing was successful, or false otherwise | |
902 | bool processImageModeOptionSet (const ViewerTest_CommandOptionKey theImageModeOptionKey) const | |
903 | { | |
904 | Aspect_FillMethod anImageMode = Aspect_FM_NONE; | |
905 | if (!processImageModeOption (theImageModeOptionKey, anImageMode)) | |
906 | { | |
907 | return false; | |
908 | } | |
909 | setImageMode (anImageMode); | |
910 | return true; | |
911 | } | |
912 | ||
913 | //! Processes the gradient option set | |
914 | //! @param theSetGradient the function used to set a background gradient filling | |
915 | //! @return true if processing was successful, or false otherwise | |
916 | bool processGradientOptionSet (SetGradientFunction* const theSetGradient = setGradient) const | |
917 | { | |
918 | Quantity_Color aColor1; | |
919 | Quantity_Color aColor2; | |
920 | if (!processGradientOption (aColor1, aColor2)) | |
921 | { | |
922 | return false; | |
923 | } | |
924 | Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR; | |
925 | if (myCommandParser.HasOption (myGradientModeOptionKey) && !processGradientModeOption (aGradientMode)) | |
926 | { | |
927 | return false; | |
928 | } | |
929 | theSetGradient (aColor1, aColor2, aGradientMode); | |
930 | return true; | |
931 | } | |
932 | ||
933 | //! Processes the gradient mode option set | |
934 | //! @return true if processing was successful, or false otherwise | |
935 | bool processGradientModeOptionSet() const | |
936 | { | |
937 | return processGradientModeOptionSet (myGradientModeOptionKey); | |
938 | } | |
939 | ||
940 | //! Processes the gradient mode option set | |
941 | //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option | |
942 | //! @return true if processing was successful, or false otherwise | |
943 | bool processGradientModeOptionSet (const ViewerTest_CommandOptionKey theGradientModeOptionKey) const | |
944 | { | |
945 | Aspect_GradientFillMethod aGradientMode = Aspect_GFM_NONE; | |
946 | if (!processGradientModeOption (theGradientModeOptionKey, aGradientMode)) | |
947 | { | |
948 | return false; | |
949 | } | |
950 | setGradientMode (aGradientMode); | |
951 | return true; | |
952 | } | |
953 | ||
954 | //! Processes the color option set | |
955 | //! @param theSetColor the function used to set a background color | |
956 | //! @return true if processing was successful, or false otherwise | |
957 | bool processColorOptionSet (SetColorFunction* const theSetColor = setColor) const | |
958 | { | |
959 | return processColorOptionSet (myColorOptionKey, theSetColor); | |
960 | } | |
961 | ||
962 | //! Processes the default color option set | |
963 | //! @return true if processing was successful, or false otherwise | |
964 | bool processDefaultGradientOptionSet() const | |
965 | { | |
966 | return processGradientOptionSet (setDefaultGradient); | |
967 | } | |
968 | ||
969 | //! Processes the default gradient option set | |
970 | //! @return true if processing was successful, or false otherwise | |
971 | bool processDefaultColorOptionSet() const | |
972 | { | |
973 | return processColorOptionSet (setDefaultColor); | |
974 | } | |
975 | ||
976 | //! Processes the color option set | |
977 | //! @param theColorOptionKey the key of the option that is interpreted as a color option | |
978 | //! @param theSetColor the function used to set a background color | |
979 | //! @return true if processing was successful, or false otherwise | |
980 | bool processColorOptionSet (const ViewerTest_CommandOptionKey theColorOptionKey, | |
981 | SetColorFunction* const theSetColor = setColor) const | |
982 | { | |
983 | Quantity_Color aColor; | |
984 | if (!processColorOption (theColorOptionKey, aColor)) | |
985 | { | |
986 | return false; | |
987 | } | |
988 | theSetColor (aColor); | |
989 | return true; | |
990 | } | |
991 | ||
992 | //! Processes the help option set | |
993 | //! @param theBackgroundCommandName the name of the command that changes the background | |
994 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
995 | //! @return true if processing was successful, or false otherwise | |
996 | bool processHelpOptionSet (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor) const | |
997 | { | |
998 | const Standard_Integer aNumberOfHelpOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
999 | ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY); | |
1000 | if (aNumberOfHelpOptionArguments != 0) | |
1001 | { | |
1002 | return false; | |
1003 | } | |
1004 | return printHelp (theBackgroundCommandName, theDrawInterpretor); | |
1005 | } | |
1006 | ||
077a220c | 1007 | //! Processes the cubemap option |
1008 | //! @param theFilePaths the array of filenames of cubemap sides | |
1009 | //! @return true if processing was successful, or false otherwise | |
1010 | bool processCubeMapOptions (NCollection_Array1<TCollection_AsciiString> &theFilePaths) const | |
1011 | { | |
1012 | const Standard_Integer aNumberOfCubeMapOptionArguments = myCommandParser.GetNumberOfOptionArguments (myCubeMapOptionKey); | |
1013 | ||
1014 | if (aNumberOfCubeMapOptionArguments != 1 | |
1015 | && aNumberOfCubeMapOptionArguments != 6) | |
1016 | { | |
1017 | return false; | |
1018 | } | |
1019 | ||
1020 | theFilePaths.Resize(0, aNumberOfCubeMapOptionArguments - 1, Standard_False); | |
1021 | ||
1022 | for (int i = 0; i < aNumberOfCubeMapOptionArguments; ++i) | |
1023 | { | |
1024 | std::string aCubeMapFileName; | |
1025 | if (!myCommandParser.Arg (myCubeMapOptionKey, i, aCubeMapFileName)) | |
1026 | { | |
1027 | return false; | |
1028 | } | |
1029 | theFilePaths[i] = aCubeMapFileName.c_str(); | |
1030 | } | |
1031 | ||
1032 | return true; | |
1033 | } | |
1034 | ||
67312b79 | 1035 | //! Processes the inverted z cubemap option |
077a220c | 1036 | //! @return true if processing was successful, or false otherwise |
1037 | bool processCubeMapInvertedZOptionSet () const | |
1038 | { | |
1039 | const Standard_Integer aNumberOfCubeMapZInversionOptionArguments = | |
1040 | myCommandParser.GetNumberOfOptionArguments (myCubeMapInvertedZOptionKey); | |
1041 | ||
1042 | if (aNumberOfCubeMapZInversionOptionArguments != 0) | |
1043 | { | |
1044 | return false; | |
1045 | } | |
1046 | ||
1047 | return true; | |
1048 | } | |
1049 | ||
67312b79 | 1050 | //! Processes the option allowing to skip IBM maps generation |
1051 | //! @return true if processing was successful, or false otherwise | |
1052 | bool processCubeMapDoNotGenPBREnvOptionSet() const | |
1053 | { | |
1054 | const Standard_Integer aNumberOfCubeMapDoNotGenPBREnvOptionArguments = | |
1055 | myCommandParser.GetNumberOfOptionArguments(myCubeMapDoNotGenPBREnvOptionKey); | |
1056 | ||
1057 | if (aNumberOfCubeMapDoNotGenPBREnvOptionArguments != 0) | |
1058 | { | |
1059 | return false; | |
1060 | } | |
1061 | ||
1062 | return true; | |
1063 | } | |
1064 | ||
077a220c | 1065 | //! Processes the tiles order option |
1066 | //! @param theOrder the array of indexes if cubemap sides in tile grid | |
1067 | //! @return true if processing was successful, or false otherwise | |
1068 | bool processCubeMapOrderOptions (Graphic3d_CubeMapOrder& theOrder) const | |
1069 | { | |
1070 | const Standard_Integer aNumberOfCubeMapOrderOptionArguments = myCommandParser.GetNumberOfOptionArguments( | |
1071 | myCubeMapOrderOptionKey); | |
1072 | ||
1073 | if (aNumberOfCubeMapOrderOptionArguments != 6) | |
1074 | { | |
1075 | return false; | |
1076 | } | |
1077 | ||
1078 | ||
1079 | for (unsigned int i = 0; i < 6; ++i) | |
1080 | { | |
1081 | std::string anOrderItem; | |
1082 | if (!myCommandParser.Arg (myCubeMapOrderOptionKey, i, anOrderItem)) | |
1083 | { | |
1084 | return false; | |
1085 | } | |
1086 | ||
1087 | theOrder.Set (Graphic3d_CubeMapSide (i), | |
1088 | static_cast<unsigned char> (Draw::Atoi (anOrderItem.c_str()))); | |
1089 | } | |
1090 | ||
1091 | return theOrder.IsValid(); | |
1092 | } | |
1093 | ||
293211ae | 1094 | //! Processes the image option |
1095 | //! @param theImageFileName the filename of the image to be used as a background | |
1096 | //! @return true if processing was successful, or false otherwise | |
1097 | bool processImageOption (std::string& theImageFileName) const | |
1098 | { | |
1099 | const Standard_Integer aNumberOfImageOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
1100 | myImageOptionKey); | |
1101 | if (aNumberOfImageOptionArguments != 1) | |
1102 | { | |
1103 | return false; | |
1104 | } | |
1105 | std::string anImageFileName; | |
1106 | if (!myCommandParser.Arg (myImageOptionKey, 0, anImageFileName)) | |
1107 | { | |
1108 | return false; | |
1109 | } | |
1110 | theImageFileName = anImageFileName; | |
1111 | return true; | |
1112 | } | |
1113 | ||
1114 | //! Processes the image mode option | |
1115 | //! @param theImageMode the fill type used for a background image | |
1116 | //! @return true if processing was successful, or false otherwise | |
1117 | bool processImageModeOption (Aspect_FillMethod& theImageMode) const | |
1118 | { | |
1119 | return processImageModeOption (myImageModeOptionKey, theImageMode); | |
1120 | } | |
1121 | ||
1122 | //! Processes the image mode option | |
1123 | //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option | |
1124 | //! @param theImageMode the fill type used for a background image | |
1125 | //! @return true if processing was successful, or false otherwise | |
1126 | bool processImageModeOption (const ViewerTest_CommandOptionKey theImageModeOptionKey, | |
1127 | Aspect_FillMethod& theImageMode) const | |
1128 | { | |
1129 | return processModeOption (theImageModeOptionKey, getBackgroundImageFillMethodByName, theImageMode); | |
1130 | } | |
1131 | ||
1132 | //! Processes the gradient option | |
1133 | //! @param theColor1 the gradient starting color | |
1134 | //! @param theColor2 the gradient ending color | |
1135 | //! @return true if processing was successful, or false otherwise | |
1136 | bool processGradientOption (Quantity_Color& theColor1, Quantity_Color& theColor2) const | |
1137 | { | |
1138 | Standard_Integer anArgumentIndex = 0; | |
1139 | Quantity_Color aColor1; | |
1140 | if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor1)) | |
1141 | { | |
1142 | return false; | |
1143 | } | |
1144 | Quantity_Color aColor2; | |
1145 | if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor2)) | |
1146 | { | |
1147 | return false; | |
1148 | } | |
1149 | const Standard_Integer aNumberOfGradientOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
1150 | myGradientOptionKey); | |
1151 | if (anArgumentIndex != aNumberOfGradientOptionArguments) | |
1152 | { | |
1153 | return false; | |
1154 | } | |
1155 | theColor1 = aColor1; | |
1156 | theColor2 = aColor2; | |
1157 | return true; | |
1158 | } | |
1159 | ||
1160 | //! Processes the gradient mode option | |
1161 | //! @param theGradientMode the fill method used for a background gradient filling | |
1162 | //! @return true if processing was successful, or false otherwise | |
1163 | bool processGradientModeOption (Aspect_GradientFillMethod& theGradientMode) const | |
1164 | { | |
1165 | return processGradientModeOption (myGradientModeOptionKey, theGradientMode); | |
1166 | } | |
1167 | ||
1168 | //! Processes the gradient mode option | |
1169 | //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option | |
1170 | //! @param theGradientMode the fill method used for a background gradient filling | |
1171 | //! @return true if processing was successful, or false otherwise | |
1172 | bool processGradientModeOption (const ViewerTest_CommandOptionKey theGradientModeOptionKey, | |
1173 | Aspect_GradientFillMethod& theGradientMode) const | |
1174 | { | |
1175 | return processModeOption (theGradientModeOptionKey, getBackgroundGradientFillMethodByName, theGradientMode); | |
1176 | } | |
1177 | ||
1178 | //! Processes some mode option | |
1179 | //! @tparam TheMode the type of a mode to be processed | |
1180 | //! @param theModeOptionKey the key of the option that is interpreted as a mode option | |
1181 | //! @param theMode a mode to be processed | |
1182 | //! @return true if processing was successful, or false otherwise | |
1183 | template <typename TheMode> | |
1184 | bool processModeOption (const ViewerTest_CommandOptionKey theModeOptionKey, | |
1185 | bool (*const theGetModeByName) (const TCollection_AsciiString& /* theModeName */, | |
1186 | TheMode& /* theMode */), | |
1187 | TheMode& theMode) const | |
1188 | { | |
1189 | const Standard_Integer aNumberOfModeOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
1190 | theModeOptionKey); | |
1191 | if (aNumberOfModeOptionArguments != 1) | |
1192 | { | |
1193 | return false; | |
1194 | } | |
1195 | std::string aModeString; | |
1196 | if (!myCommandParser.Arg (theModeOptionKey, 0, aModeString)) | |
1197 | { | |
1198 | return false; | |
1199 | } | |
1200 | TheMode aMode = TheMode(); | |
1201 | if (!theGetModeByName (aModeString.c_str(), aMode)) | |
1202 | { | |
1203 | return false; | |
1204 | } | |
1205 | theMode = aMode; | |
1206 | return true; | |
1207 | } | |
1208 | ||
1209 | //! Processes the color option | |
1210 | //! @param theColor a color used for filling a background | |
1211 | //! @return true if processing was successful, or false otherwise | |
1212 | bool processColorOption (Quantity_Color& theColor) const | |
1213 | { | |
1214 | return processColorOption (myColorOptionKey, theColor); | |
1215 | } | |
1216 | ||
1217 | //! Processes the color option | |
1218 | //! @param theColorOptionKey the key of the option that is interpreted as a color option | |
1219 | //! @param theColor a color used for filling a background | |
1220 | //! @return true if processing was successful, or false otherwise | |
1221 | bool processColorOption (const ViewerTest_CommandOptionKey theColorOptionKey, Quantity_Color& theColor) const | |
1222 | { | |
1223 | Standard_Integer anArgumentIndex = 0; | |
1224 | Quantity_Color aColor; | |
1225 | if (!myCommandParser.ArgColor (theColorOptionKey, anArgumentIndex, aColor)) | |
1226 | { | |
1227 | return false; | |
1228 | } | |
1229 | const Standard_Integer aNumberOfColorOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
1230 | theColorOptionKey); | |
1231 | if (anArgumentIndex != aNumberOfColorOptionArguments) | |
1232 | { | |
1233 | return false; | |
1234 | } | |
1235 | theColor = aColor; | |
1236 | return true; | |
1237 | } | |
1238 | ||
1239 | //! Prints helping message | |
1240 | //! @param theBackgroundCommandName the name of the command that changes the background | |
1241 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
1242 | //! @return true if printing was successful, or false otherwise | |
1243 | static bool printHelp (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor) | |
1244 | { | |
1245 | return theDrawInterpretor.PrintHelp (theBackgroundCommandName) == TCL_OK; | |
1246 | } | |
1247 | ||
077a220c | 1248 | //! Sets the cubemap as a background |
1249 | //! @param theFileNames the array of filenames of packed or multifile cubemap | |
1250 | //! @param theOrder array of cubemap sides indexes mapping them from tiles in packed cubemap | |
1251 | static void setCubeMap (const NCollection_Array1<TCollection_AsciiString>& theFileNames, | |
1252 | const Graphic3d_ValidatedCubeMapOrder theOrder = Graphic3d_CubeMapOrder::Default(), | |
67312b79 | 1253 | bool theZIsInverted = false, |
1254 | bool theToGenPBREnv = true) | |
077a220c | 1255 | { |
1256 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1257 | Handle(Graphic3d_CubeMap) aCubeMap; | |
1258 | ||
1259 | if (theFileNames.Size() == 1) | |
1260 | aCubeMap = new Graphic3d_CubeMapPacked(theFileNames[0], theOrder); | |
1261 | else | |
1262 | aCubeMap = new Graphic3d_CubeMapSeparate(theFileNames); | |
1263 | ||
1264 | aCubeMap->SetZInversion (theZIsInverted); | |
1265 | ||
1266 | aCubeMap->GetParams()->SetFilter(Graphic3d_TOTF_BILINEAR); | |
1267 | aCubeMap->GetParams()->SetRepeat(Standard_False); | |
1268 | aCubeMap->GetParams()->SetTextureUnit(Graphic3d_TextureUnit_EnvMap); | |
1269 | ||
67312b79 | 1270 | aCurrentView->SetBackgroundCubeMap (aCubeMap, theToGenPBREnv, Standard_True); |
077a220c | 1271 | } |
1272 | ||
293211ae | 1273 | //! Sets the image as a background |
1274 | //! @param theImageFileName the filename of the image to be used as a background | |
1275 | //! @param theImageMode the fill type used for a background image | |
1276 | static void setImage (const Standard_CString theImageFileName, const Aspect_FillMethod theImageMode) | |
1277 | { | |
1278 | const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1279 | aCurrentView->SetBackgroundImage (theImageFileName, theImageMode, Standard_True); | |
1280 | } | |
1281 | ||
1282 | //! Sets the fill type used for a background image | |
1283 | //! @param theImageMode the fill type used for a background image | |
1284 | static void setImageMode (const Aspect_FillMethod theImageMode) | |
1285 | { | |
1286 | const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1287 | aCurrentView->SetBgImageStyle (theImageMode, Standard_True); | |
1288 | } | |
1289 | ||
1290 | //! Sets the gradient filling for a background | |
1291 | //! @param theColor1 the gradient starting color | |
1292 | //! @param theColor2 the gradient ending color | |
1293 | //! @param theGradientMode the fill method used for a background gradient filling | |
1294 | static void setGradient (const Quantity_Color& theColor1, | |
1295 | const Quantity_Color& theColor2, | |
1296 | const Aspect_GradientFillMethod theGradientMode) | |
1297 | { | |
1298 | const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1299 | aCurrentView->SetBgGradientColors (theColor1, theColor2, theGradientMode, Standard_True); | |
1300 | } | |
1301 | ||
1302 | //! Sets the fill method used for a background gradient filling | |
1303 | //! @param theGradientMode the fill method used for a background gradient filling | |
1304 | static void setGradientMode (const Aspect_GradientFillMethod theGradientMode) | |
1305 | { | |
1306 | const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1307 | aCurrentView->SetBgGradientStyle (theGradientMode, Standard_True); | |
1308 | } | |
1309 | ||
1310 | //! Sets the color used for filling a background | |
1311 | //! @param theColor the color used for filling a background | |
1312 | static void setColor (const Quantity_Color& theColor) | |
1313 | { | |
1314 | const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1315 | aCurrentView->SetBgGradientStyle (Aspect_GFM_NONE); | |
1316 | aCurrentView->SetBackgroundColor (theColor); | |
1317 | aCurrentView->Update(); | |
1318 | } | |
1319 | ||
1320 | //! Sets the gradient filling for a background in a default viewer | |
1321 | //! @param theColor1 the gradient starting color | |
1322 | //! @param theColor2 the gradient ending color | |
1323 | //! @param theGradientMode the fill method used for a background gradient filling | |
1324 | static void setDefaultGradient (const Quantity_Color& theColor1, | |
1325 | const Quantity_Color& theColor2, | |
1326 | const Aspect_GradientFillMethod theGradientMode) | |
1327 | { | |
1328 | ViewerTest_DefaultBackground.GradientColor1 = theColor1; | |
1329 | ViewerTest_DefaultBackground.GradientColor2 = theColor2; | |
1330 | ViewerTest_DefaultBackground.FillMethod = theGradientMode; | |
1331 | setDefaultGradient(); | |
1332 | } | |
1333 | ||
1334 | //! Sets the color used for filling a background in a default viewer | |
1335 | //! @param theColor the color used for filling a background | |
1336 | static void setDefaultColor (const Quantity_Color& theColor) | |
1337 | { | |
1338 | ViewerTest_DefaultBackground.GradientColor1 = Quantity_Color(); | |
1339 | ViewerTest_DefaultBackground.GradientColor2 = Quantity_Color(); | |
1340 | ViewerTest_DefaultBackground.FillMethod = Aspect_GFM_NONE; | |
1341 | ViewerTest_DefaultBackground.FlatColor = theColor; | |
1342 | setDefaultGradient(); | |
1343 | setDefaultColor(); | |
1344 | } | |
1345 | ||
1346 | //! Sets the gradient filling for a background in a default viewer. | |
1347 | //! Gradient settings are taken from ViewerTest_DefaultBackground structure | |
1348 | static void setDefaultGradient() | |
1349 | { | |
1350 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator | |
1351 | anInteractiveContextIterator (ViewerTest_myContexts); | |
1352 | anInteractiveContextIterator.More(); | |
1353 | anInteractiveContextIterator.Next()) | |
1354 | { | |
1355 | const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer(); | |
1356 | aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1, | |
1357 | ViewerTest_DefaultBackground.GradientColor2, | |
1358 | ViewerTest_DefaultBackground.FillMethod); | |
1359 | } | |
1360 | } | |
1361 | ||
1362 | //! Sets the color used for filling a background in a default viewer. | |
1363 | //! The color value is taken from ViewerTest_DefaultBackground structure | |
1364 | static void setDefaultColor() | |
1365 | { | |
1366 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator | |
1367 | anInteractiveContextIterator (ViewerTest_myContexts); | |
1368 | anInteractiveContextIterator.More(); | |
1369 | anInteractiveContextIterator.Next()) | |
1370 | { | |
1371 | const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer(); | |
1372 | aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor); | |
1373 | } | |
1374 | } | |
1375 | }; | |
1376 | ||
1377 | } // namespace | |
b12e1c7b | 1378 | |
7fd59977 | 1379 | //============================================================================== |
1380 | ||
57c28b61 | 1381 | #ifdef _WIN32 |
7fd59977 | 1382 | static LRESULT WINAPI ViewerWindowProc( |
1383 | HWND hwnd, | |
1384 | UINT uMsg, | |
1385 | WPARAM wParam, | |
1386 | LPARAM lParam ); | |
1387 | static LRESULT WINAPI AdvViewerWindowProc( | |
1388 | HWND hwnd, | |
1389 | UINT uMsg, | |
1390 | WPARAM wParam, | |
1391 | LPARAM lParam ); | |
1392 | #endif | |
1393 | ||
1394 | ||
1395 | //============================================================================== | |
1396 | //function : WClass | |
1397 | //purpose : | |
1398 | //============================================================================== | |
1399 | ||
1bd04b5a | 1400 | const Handle(WNT_WClass)& ViewerTest::WClass() |
7fd59977 | 1401 | { |
1bd04b5a | 1402 | static Handle(WNT_WClass) theWClass; |
58655684 | 1403 | #if defined(_WIN32) |
4fe56619 | 1404 | if (theWClass.IsNull()) |
1405 | { | |
7c65581d | 1406 | theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc, |
ad03c234 | 1407 | CS_VREDRAW | CS_HREDRAW, 0, 0, |
c85a994a | 1408 | ::LoadCursor (NULL, IDC_ARROW)); |
7fd59977 | 1409 | } |
1410 | #endif | |
1411 | return theWClass; | |
1412 | } | |
1413 | ||
18d715bd | 1414 | //============================================================================== |
1415 | //function : CreateName | |
1416 | //purpose : Create numerical name for new object in theMap | |
1417 | //============================================================================== | |
1418 | template <typename ObjectType> | |
1419 | TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap, | |
1420 | const TCollection_AsciiString& theDefaultString) | |
1421 | { | |
1422 | if (theObjectMap.IsEmpty()) | |
1423 | return theDefaultString + TCollection_AsciiString(1); | |
1424 | ||
1425 | Standard_Integer aNextKey = 1; | |
1426 | Standard_Boolean isFound = Standard_False; | |
1427 | while (!isFound) | |
1428 | { | |
1429 | TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey); | |
1430 | // Look for objects with default names | |
1431 | if (theObjectMap.IsBound1(aStringKey)) | |
1432 | { | |
1433 | aNextKey++; | |
1434 | } | |
1435 | else | |
1436 | isFound = Standard_True; | |
1437 | } | |
1438 | ||
1439 | return theDefaultString + TCollection_AsciiString(aNextKey); | |
1440 | } | |
1441 | ||
1442 | //============================================================================== | |
1443 | //structure : ViewerTest_Names | |
1444 | //purpose : Allow to operate with full view name: driverName/viewerName/viewName | |
1445 | //============================================================================== | |
1446 | struct ViewerTest_Names | |
1447 | { | |
1448 | private: | |
1449 | TCollection_AsciiString myDriverName; | |
1450 | TCollection_AsciiString myViewerName; | |
1451 | TCollection_AsciiString myViewName; | |
1452 | ||
1453 | public: | |
1454 | ||
1455 | const TCollection_AsciiString& GetDriverName () const | |
1456 | { | |
1457 | return myDriverName; | |
1458 | } | |
1459 | void SetDriverName (const TCollection_AsciiString& theDriverName) | |
1460 | { | |
1461 | myDriverName = theDriverName; | |
1462 | } | |
1463 | const TCollection_AsciiString& GetViewerName () const | |
1464 | { | |
1465 | return myViewerName; | |
1466 | } | |
1467 | void SetViewerName (const TCollection_AsciiString& theViewerName) | |
1468 | { | |
1469 | myViewerName = theViewerName; | |
1470 | } | |
1471 | const TCollection_AsciiString& GetViewName () const | |
1472 | { | |
1473 | return myViewName; | |
1474 | } | |
1475 | void SetViewName (const TCollection_AsciiString& theViewName) | |
1476 | { | |
1477 | myViewName = theViewName; | |
1478 | } | |
1479 | ||
1480 | //=========================================================================== | |
1481 | //function : Constructor for ViewerTest_Names | |
1482 | //purpose : Get view, viewer, driver names from custom string | |
1483 | //=========================================================================== | |
1484 | ||
1485 | ViewerTest_Names (const TCollection_AsciiString& theInputString) | |
1486 | { | |
1487 | TCollection_AsciiString aName(theInputString); | |
1488 | if (theInputString.IsEmpty()) | |
1489 | { | |
1490 | // Get current configuration | |
1491 | if (ViewerTest_myDrivers.IsEmpty()) | |
1492 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
1493 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
1494 | else | |
1495 | myDriverName = ViewerTest_myDrivers.Find2 | |
1496 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
1497 | ||
1498 | if(ViewerTest_myContexts.IsEmpty()) | |
1499 | { | |
1500 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
1501 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
1502 | } | |
1503 | else | |
c48e2889 | 1504 | { |
18d715bd | 1505 | myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext()); |
c48e2889 | 1506 | } |
18d715bd | 1507 | |
c48e2889 | 1508 | myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View")); |
18d715bd | 1509 | } |
1510 | else | |
1511 | { | |
1512 | // There is at least view name | |
1513 | Standard_Integer aParserNumber = 0; | |
1514 | for (Standard_Integer i = 0; i < 3; ++i) | |
1515 | { | |
1516 | Standard_Integer aParserPos = aName.SearchFromEnd("/"); | |
1517 | if(aParserPos != -1) | |
1518 | { | |
1519 | aParserNumber++; | |
1520 | aName.Split(aParserPos-1); | |
1521 | } | |
1522 | else | |
1523 | break; | |
1524 | } | |
1525 | if (aParserNumber == 0) | |
1526 | { | |
1527 | // Only view name | |
1528 | if (!ViewerTest::GetAISContext().IsNull()) | |
1529 | { | |
1530 | myDriverName = ViewerTest_myDrivers.Find2 | |
1531 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
1532 | myViewerName = ViewerTest_myContexts.Find2 | |
1533 | (ViewerTest::GetAISContext()); | |
1534 | } | |
1535 | else | |
1536 | { | |
1537 | // There is no opened contexts here, need to create names for viewer and driver | |
1538 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
1539 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
1540 | ||
1541 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
1542 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
1543 | } | |
1544 | myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString); | |
1545 | } | |
1546 | else if (aParserNumber == 1) | |
1547 | { | |
1548 | // Here is viewerName/viewName | |
1549 | if (!ViewerTest::GetAISContext().IsNull()) | |
1550 | myDriverName = ViewerTest_myDrivers.Find2 | |
1551 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
1552 | else | |
1553 | { | |
1554 | // There is no opened contexts here, need to create name for driver | |
1555 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
1556 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
1557 | } | |
1558 | myViewerName = TCollection_AsciiString(myDriverName + "/" + aName); | |
1559 | ||
1560 | myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString); | |
1561 | } | |
1562 | else | |
1563 | { | |
1564 | //Here is driverName/viewerName/viewName | |
1565 | myDriverName = TCollection_AsciiString(aName); | |
1566 | ||
1567 | TCollection_AsciiString aViewerName(theInputString); | |
1568 | aViewerName.Split(aViewerName.SearchFromEnd("/") - 1); | |
1569 | myViewerName = TCollection_AsciiString(aViewerName); | |
1570 | ||
1571 | myViewName = TCollection_AsciiString(theInputString); | |
1572 | } | |
1573 | } | |
1574 | } | |
1575 | }; | |
1576 | ||
1577 | //============================================================================== | |
1578 | //function : FindContextByView | |
1579 | //purpose : Find AIS_InteractiveContext by View | |
1580 | //============================================================================== | |
1581 | ||
1582 | Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView) | |
1583 | { | |
1584 | Handle(AIS_InteractiveContext) anAISContext; | |
1585 | ||
1586 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1587 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
1588 | { | |
1589 | if (anIter.Value()->CurrentViewer() == theView->Viewer()) | |
1590 | return anIter.Key2(); | |
1591 | } | |
1592 | return anAISContext; | |
1593 | } | |
1594 | ||
18d715bd | 1595 | //============================================================================== |
1596 | //function : IsWindowOverlapped | |
1597 | //purpose : Check if theWindow overlapp another view | |
1598 | //============================================================================== | |
1599 | ||
1600 | Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft, | |
1601 | const Standard_Integer thePxTop, | |
1602 | const Standard_Integer thePxRight, | |
1603 | const Standard_Integer thePxBottom, | |
1604 | TCollection_AsciiString& theViewId) | |
1605 | { | |
1606 | for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
1607 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
1608 | { | |
1609 | Standard_Integer aTop = 0, | |
1610 | aLeft = 0, | |
1611 | aRight = 0, | |
1612 | aBottom = 0; | |
1613 | anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom); | |
1614 | if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
1615 | (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) || | |
1616 | (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
1617 | (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom)) | |
1618 | { | |
1619 | theViewId = anIter.Key1(); | |
1620 | return Standard_True; | |
1621 | } | |
1622 | } | |
1623 | return Standard_False; | |
1624 | } | |
1625 | ||
1626 | // Workaround: to create and delete non-orthographic views outside ViewerTest | |
1627 | void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName) | |
1628 | { | |
1629 | ViewerTest_myViews.UnBind1 (theName); | |
1630 | } | |
1631 | ||
1632 | void ViewerTest::InitViewName (const TCollection_AsciiString& theName, | |
1633 | const Handle(V3d_View)& theView) | |
1634 | { | |
1635 | ViewerTest_myViews.Bind (theName, theView); | |
1636 | } | |
1637 | ||
1638 | TCollection_AsciiString ViewerTest::GetCurrentViewName () | |
1639 | { | |
1640 | return ViewerTest_myViews.Find2( ViewerTest::CurrentView()); | |
1641 | } | |
8693dfd0 | 1642 | |
1643 | //! Auxiliary tool performing continuous redraws of specified window. | |
1644 | class ViewerTest_ContinuousRedrawer | |
1645 | { | |
1646 | public: | |
1647 | //! Return global instance. | |
1648 | static ViewerTest_ContinuousRedrawer& Instance() | |
1649 | { | |
1650 | static ViewerTest_ContinuousRedrawer aRedrawer; | |
1651 | return aRedrawer; | |
1652 | } | |
1653 | public: | |
1654 | ||
1655 | //! Destructor. | |
1656 | ~ViewerTest_ContinuousRedrawer() | |
1657 | { | |
1658 | Stop(); | |
1659 | } | |
1660 | ||
1661 | //! Start thread. | |
1662 | void Start (const Handle(Aspect_Window)& theWindow, | |
1663 | Standard_Real theTargetFps) | |
1664 | { | |
1665 | if (myWindow != theWindow | |
1666 | || myTargetFps != theTargetFps) | |
1667 | { | |
1668 | Stop(); | |
1669 | myWindow = theWindow; | |
1670 | myTargetFps = theTargetFps; | |
1671 | } | |
1672 | if (myThread.GetId() == 0) | |
1673 | { | |
1674 | myToStop = false; | |
1675 | myThread.Run (this); | |
1676 | } | |
1677 | } | |
1678 | ||
1679 | //! Stop thread. | |
1680 | void Stop (const Handle(Aspect_Window)& theWindow = NULL) | |
1681 | { | |
1682 | if (!theWindow.IsNull() | |
1683 | && myWindow != theWindow) | |
1684 | { | |
1685 | return; | |
1686 | } | |
1687 | ||
1688 | { | |
1689 | Standard_Mutex::Sentry aLock (myMutex); | |
1690 | myToStop = true; | |
1691 | } | |
1692 | myThread.Wait(); | |
1693 | myToStop = false; | |
1694 | myWindow.Nullify(); | |
1695 | } | |
1696 | ||
1697 | private: | |
1698 | ||
1699 | //! Thread loop. | |
1700 | void doThreadLoop() | |
1701 | { | |
1702 | Handle(Aspect_DisplayConnection) aDisp = new Aspect_DisplayConnection(); | |
1703 | OSD_Timer aTimer; | |
1704 | aTimer.Start(); | |
1705 | Standard_Real aTimeOld = 0.0; | |
1706 | const Standard_Real aTargetDur = myTargetFps > 0.0 ? 1.0 / myTargetFps : -1.0; | |
1707 | for (;;) | |
1708 | { | |
1709 | { | |
1710 | Standard_Mutex::Sentry aLock (myMutex); | |
1711 | if (myToStop) | |
1712 | { | |
1713 | return; | |
1714 | } | |
1715 | } | |
1716 | if (myTargetFps > 0.0) | |
1717 | { | |
1718 | const Standard_Real aTimeNew = aTimer.ElapsedTime(); | |
1719 | const Standard_Real aDuration = aTimeNew - aTimeOld; | |
1720 | if (aDuration >= aTargetDur) | |
1721 | { | |
1722 | myWindow->InvalidateContent (aDisp); | |
1723 | aTimeOld = aTimeNew; | |
1724 | } | |
1725 | } | |
1726 | else | |
1727 | { | |
1728 | myWindow->InvalidateContent (aDisp); | |
1729 | } | |
1730 | ||
1731 | OSD::MilliSecSleep (1); | |
1732 | } | |
1733 | } | |
1734 | ||
1735 | //! Thread creation callback. | |
1736 | static Standard_Address doThreadWrapper (Standard_Address theData) | |
1737 | { | |
1738 | ViewerTest_ContinuousRedrawer* aThis = (ViewerTest_ContinuousRedrawer* )theData; | |
1739 | aThis->doThreadLoop(); | |
1740 | return 0; | |
1741 | } | |
1742 | ||
1743 | //! Empty constructor. | |
1744 | ViewerTest_ContinuousRedrawer() | |
1745 | : myThread (doThreadWrapper), | |
1746 | myTargetFps (0.0), | |
1747 | myToStop (false) {} | |
1748 | ||
1749 | private: | |
1750 | Handle(Aspect_Window) myWindow; | |
1751 | OSD_Thread myThread; | |
1752 | Standard_Mutex myMutex; | |
1753 | Standard_Real myTargetFps; | |
1754 | volatile bool myToStop; | |
1755 | }; | |
1756 | ||
7fd59977 | 1757 | //============================================================================== |
1758 | //function : ViewerInit | |
1759 | //purpose : Create the window viewer and initialize all the global variable | |
1760 | //============================================================================== | |
1761 | ||
18d715bd | 1762 | TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft, |
1763 | const Standard_Integer thePxTop, | |
1764 | const Standard_Integer thePxWidth, | |
1765 | const Standard_Integer thePxHeight, | |
9e04ccdc | 1766 | const TCollection_AsciiString& theViewName, |
1767 | const TCollection_AsciiString& theDisplayName, | |
1768 | const Handle(V3d_View)& theViewToClone) | |
7fd59977 | 1769 | { |
8c3c9904 | 1770 | // Default position and dimension of the viewer window. |
4fe56619 | 1771 | // Note that left top corner is set to be sufficiently small to have |
8c3c9904 | 1772 | // window fit in the small screens (actual for remote desktops, see #23003). |
4fe56619 | 1773 | // The position corresponds to the window's client area, thus some |
8c3c9904 | 1774 | // gap is added for window frame to be visible. |
1775 | Standard_Integer aPxLeft = 20; | |
1776 | Standard_Integer aPxTop = 40; | |
7fd59977 | 1777 | Standard_Integer aPxWidth = 409; |
1778 | Standard_Integer aPxHeight = 409; | |
18d715bd | 1779 | Standard_Boolean toCreateViewer = Standard_False; |
9e04ccdc | 1780 | if (!theViewToClone.IsNull()) |
1781 | { | |
1782 | theViewToClone->Window()->Size (aPxWidth, aPxHeight); | |
1783 | } | |
18d715bd | 1784 | |
58655684 | 1785 | Handle(OpenGl_GraphicDriver) aGraphicDriver; |
18d715bd | 1786 | ViewerTest_Names aViewNames(theViewName); |
1787 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ())) | |
1788 | aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View")); | |
1789 | ||
1790 | if (thePxLeft != 0) | |
1791 | aPxLeft = thePxLeft; | |
1792 | if (thePxTop != 0) | |
1793 | aPxTop = thePxTop; | |
1794 | if (thePxWidth != 0) | |
1795 | aPxWidth = thePxWidth; | |
1796 | if (thePxHeight != 0) | |
7fd59977 | 1797 | aPxHeight = thePxHeight; |
4269bd1b | 1798 | |
18d715bd | 1799 | // Get graphic driver (create it or get from another view) |
8693dfd0 | 1800 | const bool isNewDriver = !ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()); |
1801 | if (isNewDriver) | |
18d715bd | 1802 | { |
1803 | // Get connection string | |
58655684 | 1804 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
8693dfd0 | 1805 | if (!theDisplayName.IsEmpty()) |
1806 | { | |
1807 | SetDisplayConnection (new Aspect_DisplayConnection (theDisplayName)); | |
1808 | } | |
18d715bd | 1809 | else |
8693dfd0 | 1810 | { |
1811 | ::Display* aDispX = NULL; | |
1812 | // create dedicated display connection instead of reusing Tk connection | |
1813 | // so that to procede events independently through VProcessEvents()/ViewerMainLoop() callbacks | |
1814 | /*Draw_Interpretor& aCommands = Draw::GetInterpretor(); | |
1815 | Tcl_Interp* aTclInterp = aCommands.Interp(); | |
1816 | Tk_Window aMainWindow = Tk_MainWindow (aTclInterp); | |
1817 | aDispX = aMainWindow != NULL ? Tk_Display (aMainWindow) : NULL;*/ | |
1818 | SetDisplayConnection (new Aspect_DisplayConnection (aDispX)); | |
1819 | } | |
18d715bd | 1820 | #else |
498ce76b | 1821 | (void)theDisplayName; // avoid warning on unused argument |
18d715bd | 1822 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
1823 | #endif | |
14cb22a1 | 1824 | |
1825 | if (Draw_VirtualWindows) | |
1826 | { | |
1827 | // don't waste the time waiting for VSync when window is not displayed on the screen | |
1828 | ViewerTest_myDefaultCaps.swapInterval = 0; | |
1829 | // alternatively we can disable buffer swap at all, but this might be inappropriate for testing | |
1830 | //ViewerTest_myDefaultCaps.buffersNoSwap = true; | |
1831 | } | |
59515ca6 | 1832 | aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection(), false); |
58655684 | 1833 | aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps; |
59515ca6 | 1834 | aGraphicDriver->InitContext(); |
14cb22a1 | 1835 | |
18d715bd | 1836 | ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver); |
1837 | toCreateViewer = Standard_True; | |
1838 | } | |
1839 | else | |
1840 | { | |
58655684 | 1841 | aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName())); |
7fd59977 | 1842 | } |
1843 | ||
18d715bd | 1844 | //Dispose the window if input parameters are default |
1845 | if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0) | |
7fd59977 | 1846 | { |
18d715bd | 1847 | Standard_Integer aTop = 0, |
1848 | aLeft = 0, | |
1849 | aRight = 0, | |
1850 | aBottom = 0, | |
1851 | aScreenWidth = 0, | |
1852 | aScreenHeight = 0; | |
1853 | ||
1854 | // Get screen resolution | |
1855 | #if defined(_WIN32) || defined(__WIN32__) | |
1856 | RECT aWindowSize; | |
1857 | GetClientRect(GetDesktopWindow(), &aWindowSize); | |
1858 | aScreenHeight = aWindowSize.bottom; | |
1859 | aScreenWidth = aWindowSize.right; | |
1860 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1861 | GetCocoaScreenResolution (aScreenWidth, aScreenHeight); | |
1862 | #else | |
1863 | Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay()); | |
1864 | aScreenWidth = WidthOfScreen(aScreen); | |
1865 | aScreenHeight = HeightOfScreen(aScreen); | |
1866 | #endif | |
1867 | ||
1868 | TCollection_AsciiString anOverlappedViewId(""); | |
773f53f1 | 1869 | |
1870 | while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)) | |
dc3fe572 | 1871 | { |
18d715bd | 1872 | ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom); |
1873 | ||
1874 | if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId) | |
1875 | && aRight + 2*aPxWidth + 40 > aScreenWidth) | |
1876 | { | |
1877 | if (aBottom + aPxHeight + 40 > aScreenHeight) | |
1878 | { | |
1879 | aPxLeft = 20; | |
1880 | aPxTop = 40; | |
1881 | break; | |
1882 | } | |
1883 | aPxLeft = 20; | |
1884 | aPxTop = aBottom + 40; | |
1885 | } | |
1886 | else | |
1887 | aPxLeft = aRight + 20; | |
dc3fe572 | 1888 | } |
18d715bd | 1889 | } |
1890 | ||
1891 | // Get viewer name | |
1892 | TCollection_AsciiString aTitle("3D View - "); | |
1893 | aTitle = aTitle + aViewNames.GetViewName() + "(*)"; | |
1894 | ||
1895 | // Change name of current active window | |
49582f9d | 1896 | if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView()) |
18d715bd | 1897 | { |
49582f9d | 1898 | aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView)); |
18d715bd | 1899 | } |
1900 | ||
1901 | // Create viewer | |
eb4320f2 | 1902 | Handle(V3d_Viewer) a3DViewer; |
18d715bd | 1903 | // If it's the single view, we first look for empty context |
1904 | if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty()) | |
1905 | { | |
1906 | NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1907 | anIter(ViewerTest_myContexts); | |
1908 | if (anIter.More()) | |
1909 | ViewerTest::SetAISContext (anIter.Value()); | |
1910 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 1911 | } |
1912 | else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())) | |
1913 | { | |
1914 | ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName())); | |
1915 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 1916 | } |
eb4320f2 | 1917 | else if (a3DViewer.IsNull()) |
18d715bd | 1918 | { |
1919 | toCreateViewer = Standard_True; | |
6a24c6de | 1920 | a3DViewer = new V3d_Viewer(aGraphicDriver); |
f42753ed | 1921 | a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor); |
1922 | a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1, | |
1923 | ViewerTest_DefaultBackground.GradientColor2, | |
1924 | ViewerTest_DefaultBackground.FillMethod); | |
18d715bd | 1925 | } |
1926 | ||
1927 | // AIS context setup | |
1928 | if (ViewerTest::GetAISContext().IsNull() || | |
1929 | !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))) | |
1930 | { | |
e79a94b9 | 1931 | Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer); |
18d715bd | 1932 | ViewerTest::SetAISContext (aContext); |
1933 | ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext()); | |
1934 | } | |
1935 | else | |
e79a94b9 | 1936 | { |
18d715bd | 1937 | ViewerTest::ResetEventManager(); |
e79a94b9 | 1938 | } |
18d715bd | 1939 | |
1940 | // Create window | |
e79a94b9 | 1941 | #if defined(_WIN32) |
1bd04b5a | 1942 | VT_GetWindow() = new WNT_Window (aTitle.ToCString(), WClass(), |
62e1beed | 1943 | Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW, |
e79a94b9 | 1944 | aPxLeft, aPxTop, |
1945 | aPxWidth, aPxHeight, | |
1946 | Quantity_NOC_BLACK); | |
4fe56619 | 1947 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
e79a94b9 | 1948 | VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(), |
1949 | aPxLeft, aPxTop, | |
1950 | aPxWidth, aPxHeight); | |
1951 | ViewerTest_SetCocoaEventManagerView (VT_GetWindow()); | |
7fd59977 | 1952 | #else |
e79a94b9 | 1953 | VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(), |
1954 | aTitle.ToCString(), | |
1955 | aPxLeft, aPxTop, | |
1956 | aPxWidth, aPxHeight); | |
7fd59977 | 1957 | #endif |
18d715bd | 1958 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); |
7fd59977 | 1959 | |
d09dda09 | 1960 | // View setup |
9e04ccdc | 1961 | Handle(V3d_View) aView; |
1962 | if (!theViewToClone.IsNull()) | |
1963 | { | |
2e93433e | 1964 | aView = new ViewerTest_V3dView (a3DViewer, theViewToClone); |
9e04ccdc | 1965 | } |
1966 | else | |
1967 | { | |
2e93433e | 1968 | aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView()); |
9e04ccdc | 1969 | } |
1970 | ||
d09dda09 | 1971 | aView->SetWindow (VT_GetWindow()); |
c3282ec1 | 1972 | ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer); |
4269bd1b | 1973 | |
18d715bd | 1974 | ViewerTest::CurrentView(aView); |
1975 | ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView); | |
7fd59977 | 1976 | |
18d715bd | 1977 | // Setup for X11 or NT |
1978 | OSWindowSetup(); | |
7fd59977 | 1979 | |
18d715bd | 1980 | // Set parameters for V3d_View and V3d_Viewer |
1981 | const Handle (V3d_View) aV3dView = ViewerTest::CurrentView(); | |
1982 | aV3dView->SetComputedMode(Standard_False); | |
7fd59977 | 1983 | |
18d715bd | 1984 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
1985 | if (toCreateViewer) | |
1986 | { | |
7fd59977 | 1987 | a3DViewer->SetDefaultLights(); |
1988 | a3DViewer->SetLightOn(); | |
18d715bd | 1989 | } |
7fd59977 | 1990 | |
8693dfd0 | 1991 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
1992 | if (isNewDriver) | |
1993 | { | |
1994 | ::Display* aDispX = GetDisplayConnection()->GetDisplay(); | |
1995 | Tcl_CreateFileHandler (XConnectionNumber (aDispX), TCL_READABLE, VProcessEvents, (ClientData )aDispX); | |
1996 | } | |
1997 | #endif | |
7fd59977 | 1998 | |
7fd59977 | 1999 | VT_GetWindow()->Map(); |
4269bd1b | 2000 | |
18d715bd | 2001 | // Set the handle of created view in the event manager |
2002 | ViewerTest::ResetEventManager(); | |
2003 | ||
4fe56619 | 2004 | ViewerTest::CurrentView()->Redraw(); |
18d715bd | 2005 | |
2006 | aView.Nullify(); | |
2007 | a3DViewer.Nullify(); | |
18d715bd | 2008 | |
2009 | return aViewNames.GetViewName(); | |
2010 | } | |
2011 | ||
4269bd1b | 2012 | //============================================================================== |
2013 | //function : RedrawAllViews | |
2014 | //purpose : Redraw all created views | |
2015 | //============================================================================== | |
2016 | void ViewerTest::RedrawAllViews() | |
2017 | { | |
2018 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
2019 | for (; aViewIt.More(); aViewIt.Next()) | |
2020 | { | |
2021 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
2022 | aView->Redraw(); | |
2023 | } | |
2024 | } | |
2025 | ||
7fd59977 | 2026 | //============================================================================== |
2027 | //function : Vinit | |
2028 | //purpose : Create the window viewer and initialize all the global variable | |
e79a94b9 | 2029 | // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event |
7fd59977 | 2030 | //============================================================================== |
2031 | ||
18d715bd | 2032 | static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 2033 | { |
e79a94b9 | 2034 | TCollection_AsciiString aViewName, aDisplayName; |
2035 | Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0; | |
9e04ccdc | 2036 | Handle(V3d_View) aCopyFrom; |
e79a94b9 | 2037 | TCollection_AsciiString aName, aValue; |
2e93433e | 2038 | int is2dMode = -1; |
e79a94b9 | 2039 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
18d715bd | 2040 | { |
e79a94b9 | 2041 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; |
2042 | TCollection_AsciiString anArgCase = anArg; | |
fd3f6bd0 | 2043 | anArgCase.LowerCase(); |
2044 | if (anArgIt + 1 < theArgsNb | |
2045 | && anArgCase == "-name") | |
2046 | { | |
2047 | aViewName = theArgVec[++anArgIt]; | |
2048 | } | |
2049 | else if (anArgIt + 1 < theArgsNb | |
2050 | && (anArgCase == "-left" | |
2051 | || anArgCase == "-l")) | |
2052 | { | |
2053 | aPxLeft = Draw::Atoi (theArgVec[++anArgIt]); | |
2054 | } | |
2055 | else if (anArgIt + 1 < theArgsNb | |
2056 | && (anArgCase == "-top" | |
2057 | || anArgCase == "-t")) | |
2058 | { | |
2059 | aPxTop = Draw::Atoi (theArgVec[++anArgIt]); | |
2060 | } | |
2061 | else if (anArgIt + 1 < theArgsNb | |
2062 | && (anArgCase == "-width" | |
2063 | || anArgCase == "-w")) | |
2064 | { | |
2065 | aPxWidth = Draw::Atoi (theArgVec[++anArgIt]); | |
2066 | } | |
2067 | else if (anArgIt + 1 < theArgsNb | |
2068 | && (anArgCase == "-height" | |
2069 | || anArgCase == "-h")) | |
18d715bd | 2070 | { |
fd3f6bd0 | 2071 | aPxHeight = Draw::Atoi (theArgVec[++anArgIt]); |
2072 | } | |
2073 | else if (anArgCase == "-exitonclose") | |
2074 | { | |
49582f9d | 2075 | ViewerTest_EventManager::ToExitOnCloseView() = true; |
fd3f6bd0 | 2076 | if (anArgIt + 1 < theArgsNb |
49582f9d | 2077 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToExitOnCloseView())) |
fd3f6bd0 | 2078 | { |
2079 | ++anArgIt; | |
2080 | } | |
2081 | } | |
2082 | else if (anArgCase == "-closeonescape" | |
2083 | || anArgCase == "-closeonesc") | |
2084 | { | |
49582f9d | 2085 | ViewerTest_EventManager::ToCloseViewOnEscape() = true; |
fd3f6bd0 | 2086 | if (anArgIt + 1 < theArgsNb |
49582f9d | 2087 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToCloseViewOnEscape())) |
fd3f6bd0 | 2088 | { |
2089 | ++anArgIt; | |
2090 | } | |
2091 | } | |
2e93433e | 2092 | else if (anArgCase == "-2d_mode" |
2093 | || anArgCase == "-2dmode" | |
2094 | || anArgCase == "-2d") | |
2095 | { | |
2096 | bool toEnable = true; | |
2097 | if (anArgIt + 1 < theArgsNb | |
2098 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable)) | |
2099 | { | |
2100 | ++anArgIt; | |
2101 | } | |
2102 | is2dMode = toEnable ? 1 : 0; | |
2103 | } | |
fd3f6bd0 | 2104 | else if (anArgIt + 1 < theArgsNb |
2105 | && (anArgCase == "-disp" | |
2106 | || anArgCase == "-display")) | |
2107 | { | |
2108 | aDisplayName = theArgVec[++anArgIt]; | |
2109 | } | |
9e04ccdc | 2110 | else if (!ViewerTest::CurrentView().IsNull() |
2111 | && aCopyFrom.IsNull() | |
2112 | && (anArgCase == "-copy" | |
2113 | || anArgCase == "-clone" | |
2114 | || anArgCase == "-cloneactive" | |
2115 | || anArgCase == "-cloneactiveview")) | |
2116 | { | |
2117 | aCopyFrom = ViewerTest::CurrentView(); | |
2118 | } | |
fd3f6bd0 | 2119 | // old syntax |
2120 | else if (ViewerTest::SplitParameter (anArg, aName, aValue)) | |
2121 | { | |
2122 | aName.LowerCase(); | |
2123 | if (aName == "name") | |
18d715bd | 2124 | { |
2125 | aViewName = aValue; | |
2126 | } | |
fd3f6bd0 | 2127 | else if (aName == "l" |
2128 | || aName == "left") | |
e79a94b9 | 2129 | { |
18d715bd | 2130 | aPxLeft = aValue.IntegerValue(); |
e79a94b9 | 2131 | } |
fd3f6bd0 | 2132 | else if (aName == "t" |
2133 | || aName == "top") | |
e79a94b9 | 2134 | { |
18d715bd | 2135 | aPxTop = aValue.IntegerValue(); |
e79a94b9 | 2136 | } |
fd3f6bd0 | 2137 | else if (aName == "disp" |
2138 | || aName == "display") | |
e79a94b9 | 2139 | { |
18d715bd | 2140 | aDisplayName = aValue; |
e79a94b9 | 2141 | } |
fd3f6bd0 | 2142 | else if (aName == "w" |
2143 | || aName == "width") | |
e79a94b9 | 2144 | { |
18d715bd | 2145 | aPxWidth = aValue.IntegerValue(); |
e79a94b9 | 2146 | } |
fd3f6bd0 | 2147 | else if (aName == "h" |
2148 | || aName == "height") | |
e79a94b9 | 2149 | { |
18d715bd | 2150 | aPxHeight = aValue.IntegerValue(); |
e79a94b9 | 2151 | } |
18d715bd | 2152 | else |
2153 | { | |
23fe70ec | 2154 | Message::SendFail() << "Syntax error: unknown argument " << anArg; |
fd3f6bd0 | 2155 | return 1; |
18d715bd | 2156 | } |
2157 | } | |
e79a94b9 | 2158 | else if (aViewName.IsEmpty()) |
2159 | { | |
2160 | aViewName = anArg; | |
2161 | } | |
2162 | else | |
2163 | { | |
23fe70ec | 2164 | Message::SendFail() << "Syntax error: unknown argument " << anArg; |
fd3f6bd0 | 2165 | return 1; |
e79a94b9 | 2166 | } |
18d715bd | 2167 | } |
2168 | ||
fd3f6bd0 | 2169 | #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) |
2170 | if (!aDisplayName.IsEmpty()) | |
2171 | { | |
2172 | aDisplayName.Clear(); | |
23fe70ec | 2173 | Message::SendWarning() << "Warning: display parameter will be ignored.\n"; |
fd3f6bd0 | 2174 | } |
2175 | #endif | |
2176 | ||
18d715bd | 2177 | ViewerTest_Names aViewNames (aViewName); |
e79a94b9 | 2178 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) |
18d715bd | 2179 | { |
e79a94b9 | 2180 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName(); |
2181 | theDi.Eval (aCommand.ToCString()); | |
2e93433e | 2182 | if (is2dMode != -1) |
2183 | { | |
2184 | ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1); | |
2185 | } | |
18d715bd | 2186 | return 0; |
2187 | } | |
2188 | ||
2189 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight, | |
9e04ccdc | 2190 | aViewName, aDisplayName, aCopyFrom); |
2e93433e | 2191 | if (is2dMode != -1) |
2192 | { | |
2193 | ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1); | |
2194 | } | |
e79a94b9 | 2195 | theDi << aViewId; |
7fd59977 | 2196 | return 0; |
2197 | } | |
2198 | ||
1eeef710 | 2199 | //! Parse HLR algo type. |
2200 | static Standard_Boolean parseHlrAlgoType (const char* theName, | |
2201 | Prs3d_TypeOfHLR& theType) | |
2202 | { | |
2203 | TCollection_AsciiString aName (theName); | |
2204 | aName.LowerCase(); | |
2205 | if (aName == "polyalgo") | |
2206 | { | |
2207 | theType = Prs3d_TOH_PolyAlgo; | |
2208 | } | |
2209 | else if (aName == "algo") | |
2210 | { | |
2211 | theType = Prs3d_TOH_Algo; | |
2212 | } | |
2213 | else | |
2214 | { | |
2215 | return Standard_False; | |
2216 | } | |
2217 | return Standard_True; | |
2218 | } | |
2219 | ||
0a768f56 | 2220 | //============================================================================== |
2221 | //function : VHLR | |
2222 | //purpose : hidden lines removal algorithm | |
2223 | //============================================================================== | |
2224 | ||
2225 | static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2226 | { | |
1eeef710 | 2227 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2228 | const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
2229 | if (aView.IsNull()) | |
0a768f56 | 2230 | { |
23fe70ec | 2231 | Message::SendFail ("Error: no active viewer"); |
0a768f56 | 2232 | return 1; |
2233 | } | |
2234 | ||
1eeef710 | 2235 | Standard_Boolean hasHlrOnArg = Standard_False; |
2236 | Standard_Boolean hasShowHiddenArg = Standard_False; | |
2237 | Standard_Boolean isHLROn = Standard_False; | |
2238 | Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine(); | |
2239 | Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet; | |
2240 | ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView); | |
2241 | for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter) | |
0a768f56 | 2242 | { |
1eeef710 | 2243 | TCollection_AsciiString anArg (argv[anArgIter]); |
2244 | anArg.LowerCase(); | |
2245 | if (anUpdateTool.parseRedrawMode (anArg)) | |
2246 | { | |
2247 | continue; | |
2248 | } | |
2249 | else if (anArg == "-showhidden" | |
2250 | && anArgIter + 1 < argc | |
2251 | && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden)) | |
2252 | { | |
2253 | ++anArgIter; | |
2254 | hasShowHiddenArg = Standard_True; | |
2255 | continue; | |
2256 | } | |
2257 | else if ((anArg == "-type" | |
2258 | || anArg == "-algo" | |
2259 | || anArg == "-algotype") | |
2260 | && anArgIter + 1 < argc | |
2261 | && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR)) | |
2262 | { | |
2263 | ++anArgIter; | |
2264 | continue; | |
2265 | } | |
2266 | else if (!hasHlrOnArg | |
2267 | && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn)) | |
2268 | { | |
2269 | hasHlrOnArg = Standard_True; | |
2270 | continue; | |
2271 | } | |
2272 | // old syntax | |
2273 | else if (!hasShowHiddenArg | |
2274 | && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden)) | |
2275 | { | |
2276 | hasShowHiddenArg = Standard_True; | |
2277 | continue; | |
2278 | } | |
2279 | else | |
2280 | { | |
23fe70ec | 2281 | Message::SendFail() << "Syntax error at '" << argv[anArgIter] << "'"; |
1eeef710 | 2282 | return 1; |
2283 | } | |
0a768f56 | 2284 | } |
1eeef710 | 2285 | if (!hasHlrOnArg) |
0a768f56 | 2286 | { |
1eeef710 | 2287 | di << "HLR: " << aView->ComputedMode() << "\n"; |
2288 | di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n"; | |
2289 | di << "HlrAlgo: "; | |
2290 | switch (aCtx->DefaultDrawer()->TypeOfHLR()) | |
2291 | { | |
2292 | case Prs3d_TOH_NotSet: di << "NotSet\n"; break; | |
2293 | case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break; | |
2294 | case Prs3d_TOH_Algo: di << "Algo\n"; break; | |
2295 | } | |
2296 | anUpdateTool.Invalidate(); | |
2297 | return 0; | |
0a768f56 | 2298 | } |
2299 | ||
1eeef710 | 2300 | Standard_Boolean toRecompute = Standard_False; |
2301 | if (aTypeOfHLR != Prs3d_TOH_NotSet | |
2302 | && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR()) | |
e9224045 | 2303 | { |
1eeef710 | 2304 | toRecompute = Standard_True; |
2305 | aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR); | |
2306 | } | |
2307 | if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine()) | |
2308 | { | |
2309 | toRecompute = Standard_True; | |
2310 | if (toShowHidden) | |
e9224045 | 2311 | { |
1eeef710 | 2312 | aCtx->DefaultDrawer()->EnableDrawHiddenLine(); |
e9224045 | 2313 | } |
2314 | else | |
2315 | { | |
1eeef710 | 2316 | aCtx->DefaultDrawer()->DisableDrawHiddenLine(); |
e9224045 | 2317 | } |
1eeef710 | 2318 | } |
e9224045 | 2319 | |
1eeef710 | 2320 | // redisplay shapes |
2321 | if (aView->ComputedMode() && isHLROn && toRecompute) | |
2322 | { | |
2323 | AIS_ListOfInteractive aListOfShapes; | |
2324 | aCtx->DisplayedObjects (aListOfShapes); | |
2325 | for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next()) | |
e9224045 | 2326 | { |
1eeef710 | 2327 | if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value())) |
e9224045 | 2328 | { |
1eeef710 | 2329 | aCtx->Redisplay (aShape, Standard_False); |
e9224045 | 2330 | } |
2331 | } | |
2332 | } | |
0a768f56 | 2333 | |
1eeef710 | 2334 | aView->SetComputedMode (isHLROn); |
0a768f56 | 2335 | return 0; |
2336 | } | |
2337 | ||
2338 | //============================================================================== | |
2339 | //function : VHLRType | |
2340 | //purpose : change type of using HLR algorithm | |
2341 | //============================================================================== | |
2342 | ||
1eeef710 | 2343 | static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
0a768f56 | 2344 | { |
1eeef710 | 2345 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2346 | const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
2347 | if (aView.IsNull()) | |
0a768f56 | 2348 | { |
23fe70ec | 2349 | Message::SendFail ("Error: no active viewer"); |
0a768f56 | 2350 | return 1; |
2351 | } | |
2352 | ||
1eeef710 | 2353 | Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet; |
2354 | ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView); | |
2355 | AIS_ListOfInteractive aListOfShapes; | |
2356 | for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter) | |
0a768f56 | 2357 | { |
1eeef710 | 2358 | TCollection_AsciiString anArg (argv[anArgIter]); |
2359 | anArg.LowerCase(); | |
2360 | if (anUpdateTool.parseRedrawMode (anArg)) | |
0a768f56 | 2361 | { |
1eeef710 | 2362 | continue; |
0a768f56 | 2363 | } |
1eeef710 | 2364 | else if ((anArg == "-type" |
2365 | || anArg == "-algo" | |
2366 | || anArg == "-algotype") | |
2367 | && anArgIter + 1 < argc | |
2368 | && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR)) | |
2369 | { | |
2370 | ++anArgIter; | |
2371 | continue; | |
2372 | } | |
2373 | // old syntax | |
2374 | else if (aTypeOfHLR == Prs3d_TOH_NotSet | |
2375 | && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR)) | |
2376 | { | |
2377 | continue; | |
2378 | } | |
2379 | else | |
0a768f56 | 2380 | { |
2381 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
1eeef710 | 2382 | TCollection_AsciiString aName (argv[anArgIter]); |
0a768f56 | 2383 | if (!aMap.IsBound2 (aName)) |
2384 | { | |
23fe70ec | 2385 | Message::SendFail() << "Syntax error: Wrong shape name '" << aName << "'"; |
1eeef710 | 2386 | return 1; |
0a768f56 | 2387 | } |
1eeef710 | 2388 | |
2389 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName)); | |
2390 | if (aShape.IsNull()) | |
2391 | { | |
23fe70ec | 2392 | Message::SendFail() << "Syntax error: '" << aName << "' is not a shape presentation"; |
1eeef710 | 2393 | return 1; |
2394 | } | |
2395 | aListOfShapes.Append (aShape); | |
2396 | continue; | |
0a768f56 | 2397 | } |
1eeef710 | 2398 | } |
2399 | if (aTypeOfHLR == Prs3d_TOH_NotSet) | |
2400 | { | |
23fe70ec | 2401 | Message::SendFail ("Syntax error: wrong number of arguments"); |
1eeef710 | 2402 | return 1; |
2403 | } | |
2404 | ||
2405 | const Standard_Boolean isGlobal = aListOfShapes.IsEmpty(); | |
2406 | if (isGlobal) | |
2407 | { | |
2408 | aCtx->DisplayedObjects (aListOfShapes); | |
2409 | aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR); | |
0a768f56 | 2410 | } |
2411 | ||
1eeef710 | 2412 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next()) |
2413 | { | |
2414 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
2415 | if (aShape.IsNull()) | |
2416 | { | |
2417 | continue; | |
2418 | } | |
2419 | ||
2420 | const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR | |
2421 | && aView->ComputedMode(); | |
2422 | if (!isGlobal | |
2423 | || aShape->TypeOfHLR() != aTypeOfHLR) | |
2424 | { | |
2425 | aShape->SetTypeOfHLR (aTypeOfHLR); | |
2426 | } | |
2427 | if (toUpdateShape) | |
2428 | { | |
2429 | aCtx->Redisplay (aShape, Standard_False); | |
2430 | } | |
2431 | } | |
0a768f56 | 2432 | return 0; |
2433 | } | |
2434 | ||
18d715bd | 2435 | //============================================================================== |
2436 | //function : FindViewIdByWindowHandle | |
2437 | //purpose : Find theView Id in the map of views by window handle | |
2438 | //============================================================================== | |
49582f9d | 2439 | #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
2440 | TCollection_AsciiString FindViewIdByWindowHandle (Aspect_Drawable theWindowHandle) | |
18d715bd | 2441 | { |
2442 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
2443 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
2444 | { | |
49582f9d | 2445 | Aspect_Drawable aWindowHandle = anIter.Value()->Window()->NativeHandle(); |
18d715bd | 2446 | if (aWindowHandle == theWindowHandle) |
2447 | return anIter.Key1(); | |
2448 | } | |
2449 | return TCollection_AsciiString(""); | |
2450 | } | |
2451 | #endif | |
2452 | ||
e084dbbc | 2453 | //! Make the view active |
2454 | void ActivateView (const TCollection_AsciiString& theViewName, | |
2455 | Standard_Boolean theToUpdate = Standard_True) | |
18d715bd | 2456 | { |
2457 | const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
e084dbbc | 2458 | if (aView.IsNull()) |
18d715bd | 2459 | { |
e084dbbc | 2460 | return; |
2461 | } | |
18d715bd | 2462 | |
e084dbbc | 2463 | Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView); |
2464 | if (!anAISContext.IsNull()) | |
2465 | { | |
49582f9d | 2466 | if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView()) |
e084dbbc | 2467 | { |
49582f9d | 2468 | aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView)); |
e084dbbc | 2469 | } |
2470 | ||
2471 | ViewerTest::CurrentView (aView); | |
2472 | ViewerTest::SetAISContext (anAISContext); | |
49582f9d | 2473 | aView->Window()->SetTitle (TCollection_AsciiString("3D View - ") + theViewName + "(*)"); |
1eeef710 | 2474 | #if defined(_WIN32) |
e084dbbc | 2475 | VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
18d715bd | 2476 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
e084dbbc | 2477 | VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
18d715bd | 2478 | #else |
e084dbbc | 2479 | VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
18d715bd | 2480 | #endif |
e084dbbc | 2481 | SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
2482 | if (theToUpdate) | |
2483 | { | |
18d715bd | 2484 | ViewerTest::CurrentView()->Redraw(); |
2485 | } | |
2486 | } | |
2487 | } | |
2488 | ||
0e93d9e5 | 2489 | //============================================================================== |
2490 | //function : RemoveView | |
2491 | //purpose : | |
2492 | //============================================================================== | |
2493 | void ViewerTest::RemoveView (const Handle(V3d_View)& theView, | |
2494 | const Standard_Boolean theToRemoveContext) | |
2495 | { | |
2496 | if (!ViewerTest_myViews.IsBound2 (theView)) | |
2497 | { | |
2498 | return; | |
2499 | } | |
2500 | ||
2501 | const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView); | |
2502 | RemoveView (aViewName, theToRemoveContext); | |
2503 | } | |
2504 | ||
18d715bd | 2505 | //============================================================================== |
2506 | //function : RemoveView | |
2507 | //purpose : Close and remove view from display, clear maps if neccessary | |
2508 | //============================================================================== | |
2509 | void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved) | |
2510 | { | |
2511 | if (!ViewerTest_myViews.IsBound1(theViewName)) | |
2512 | { | |
23fe70ec | 2513 | Message::SendFail() << "Wrong view name"; |
18d715bd | 2514 | return; |
2515 | } | |
2516 | ||
2517 | // Activate another view if it's active now | |
2518 | if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView()) | |
2519 | { | |
2520 | if (ViewerTest_myViews.Extent() > 1) | |
2521 | { | |
2522 | TCollection_AsciiString aNewViewName; | |
c48e2889 | 2523 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); |
2524 | anIter.More(); anIter.Next()) | |
2525 | { | |
18d715bd | 2526 | if (anIter.Key1() != theViewName) |
2527 | { | |
2528 | aNewViewName = anIter.Key1(); | |
2529 | break; | |
2530 | } | |
c48e2889 | 2531 | } |
2532 | ActivateView (aNewViewName); | |
18d715bd | 2533 | } |
2534 | else | |
2535 | { | |
e084dbbc | 2536 | VT_GetWindow().Nullify(); |
2537 | ViewerTest::CurrentView (Handle(V3d_View)()); | |
18d715bd | 2538 | if (isContextRemoved) |
2539 | { | |
2540 | Handle(AIS_InteractiveContext) anEmptyContext; | |
2541 | ViewerTest::SetAISContext(anEmptyContext); | |
2542 | } | |
2543 | } | |
2544 | } | |
2545 | ||
2546 | // Delete view | |
2547 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
2548 | Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView); | |
8693dfd0 | 2549 | ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance(); |
2550 | aRedrawer.Stop (aView->Window()); | |
18d715bd | 2551 | |
2552 | // Remove view resources | |
18d715bd | 2553 | ViewerTest_myViews.UnBind1(theViewName); |
851dacdb | 2554 | aView->Window()->Unmap(); |
18d715bd | 2555 | aView->Remove(); |
2556 | ||
2557 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
2558 | XFlush (GetDisplayConnection()->GetDisplay()); | |
2559 | #endif | |
2560 | ||
2561 | // Keep context opened only if the closed view is last to avoid | |
2562 | // unused empty contexts | |
2563 | if (!aCurrentContext.IsNull()) | |
2564 | { | |
2565 | // Check if there are more difined views in the viewer | |
f7fc0c03 | 2566 | if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) |
2567 | && aCurrentContext->CurrentViewer()->DefinedViews().IsEmpty()) | |
18d715bd | 2568 | { |
2569 | // Remove driver if there is no viewers that use it | |
2570 | Standard_Boolean isRemoveDriver = Standard_True; | |
2571 | for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
2572 | anIter(ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
2573 | { | |
2574 | if (aCurrentContext != anIter.Key2() && | |
2575 | aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver()) | |
2576 | { | |
2577 | isRemoveDriver = Standard_False; | |
2578 | break; | |
2579 | } | |
2580 | } | |
2ec85268 | 2581 | |
2582 | aCurrentContext->RemoveAll (Standard_False); | |
18d715bd | 2583 | if(isRemoveDriver) |
2584 | { | |
2585 | ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver()); | |
2586 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
8693dfd0 | 2587 | Tcl_DeleteFileHandler (XConnectionNumber (aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); |
18d715bd | 2588 | #endif |
2589 | } | |
2590 | ||
2591 | ViewerTest_myContexts.UnBind2(aCurrentContext); | |
2592 | } | |
2593 | } | |
23fe70ec | 2594 | Message::SendInfo() << "3D View - " << theViewName << " was deleted.\n"; |
49582f9d | 2595 | if (ViewerTest_EventManager::ToExitOnCloseView()) |
fd3f6bd0 | 2596 | { |
2597 | Draw_Interprete ("exit"); | |
2598 | } | |
18d715bd | 2599 | } |
2600 | ||
2601 | //============================================================================== | |
2602 | //function : VClose | |
2603 | //purpose : Remove the view defined by its name | |
2604 | //============================================================================== | |
2605 | ||
d0cc1cb7 | 2606 | static int VClose (Draw_Interpretor& /*theDi*/, |
2607 | Standard_Integer theArgsNb, | |
2608 | const char** theArgVec) | |
18d715bd | 2609 | { |
18d715bd | 2610 | NCollection_List<TCollection_AsciiString> aViewList; |
d0cc1cb7 | 2611 | if (theArgsNb > 1) |
18d715bd | 2612 | { |
d0cc1cb7 | 2613 | TCollection_AsciiString anArg (theArgVec[1]); |
2614 | anArg.UpperCase(); | |
2615 | if (anArg.IsEqual ("ALL") | |
2616 | || anArg.IsEqual ("*")) | |
2617 | { | |
2618 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); | |
2619 | anIter.More(); anIter.Next()) | |
2620 | { | |
2621 | aViewList.Append (anIter.Key1()); | |
2622 | } | |
2623 | if (aViewList.IsEmpty()) | |
2624 | { | |
2625 | std::cout << "No view to close\n"; | |
2626 | return 0; | |
2627 | } | |
2628 | } | |
2629 | else | |
18d715bd | 2630 | { |
d0cc1cb7 | 2631 | ViewerTest_Names aViewName (theArgVec[1]); |
2632 | if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName())) | |
2633 | { | |
23fe70ec | 2634 | Message::SendFail() << "Error: the view with name '" << theArgVec[1] << "' does not exist"; |
d0cc1cb7 | 2635 | return 1; |
2636 | } | |
2637 | aViewList.Append (aViewName.GetViewName()); | |
18d715bd | 2638 | } |
2639 | } | |
2640 | else | |
2641 | { | |
d0cc1cb7 | 2642 | // close active view |
2643 | if (ViewerTest::CurrentView().IsNull()) | |
2644 | { | |
23fe70ec | 2645 | Message::SendFail ("Error: no active view"); |
d0cc1cb7 | 2646 | return 1; |
2647 | } | |
2648 | aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); | |
18d715bd | 2649 | } |
2650 | ||
d0cc1cb7 | 2651 | Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1); |
18d715bd | 2652 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList); |
2653 | anIter.More(); anIter.Next()) | |
2654 | { | |
d0cc1cb7 | 2655 | ViewerTest::RemoveView (anIter.Value(), toRemoveContext); |
18d715bd | 2656 | } |
2657 | ||
2658 | return 0; | |
2659 | } | |
2660 | ||
2661 | //============================================================================== | |
2662 | //function : VActivate | |
2663 | //purpose : Activate the view defined by its ID | |
2664 | //============================================================================== | |
2665 | ||
2666 | static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
2667 | { | |
e084dbbc | 2668 | if (theArgsNb == 1) |
18d715bd | 2669 | { |
2670 | theDi.Eval("vviewlist"); | |
2671 | return 0; | |
2672 | } | |
2673 | ||
e084dbbc | 2674 | TCollection_AsciiString aNameString; |
2675 | Standard_Boolean toUpdate = Standard_True; | |
2676 | Standard_Boolean toActivate = Standard_True; | |
2677 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
18d715bd | 2678 | { |
e084dbbc | 2679 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
2680 | anArg.LowerCase(); | |
2681 | if (toUpdate | |
2682 | && anArg == "-noupdate") | |
2683 | { | |
2684 | toUpdate = Standard_False; | |
2685 | } | |
2686 | else if (toActivate | |
2687 | && aNameString.IsEmpty() | |
2688 | && anArg == "none") | |
2689 | { | |
49582f9d | 2690 | ViewerTest::CurrentView()->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); |
e084dbbc | 2691 | VT_GetWindow().Nullify(); |
2692 | ViewerTest::CurrentView (Handle(V3d_View)()); | |
2693 | ViewerTest::ResetEventManager(); | |
2694 | theDi << theArgVec[0] << ": all views are inactive\n"; | |
2695 | toActivate = Standard_False; | |
2696 | } | |
2697 | else if (toActivate | |
2698 | && aNameString.IsEmpty()) | |
2699 | { | |
2700 | aNameString = theArgVec[anArgIter]; | |
2701 | } | |
2702 | else | |
2703 | { | |
23fe70ec | 2704 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
e084dbbc | 2705 | return 1; |
2706 | } | |
18d715bd | 2707 | } |
2708 | ||
e084dbbc | 2709 | if (!toActivate) |
2710 | { | |
2711 | return 0; | |
2712 | } | |
2713 | else if (aNameString.IsEmpty()) | |
2714 | { | |
23fe70ec | 2715 | Message::SendFail ("Syntax error: wrong number of arguments"); |
e084dbbc | 2716 | return 1; |
2717 | } | |
18d715bd | 2718 | |
2719 | // Check if this view exists in the viewer with the driver | |
e084dbbc | 2720 | ViewerTest_Names aViewNames (aNameString); |
18d715bd | 2721 | if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName())) |
2722 | { | |
e084dbbc | 2723 | theDi << "Syntax error: wrong view name '" << aNameString << "'\n"; |
18d715bd | 2724 | return 1; |
2725 | } | |
2726 | ||
2727 | // Check if it is active already | |
2728 | if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName())) | |
2729 | { | |
2730 | theDi << theArgVec[0] << ": the view is active already\n"; | |
2731 | return 0; | |
2732 | } | |
2733 | ||
e084dbbc | 2734 | ActivateView (aViewNames.GetViewName(), toUpdate); |
18d715bd | 2735 | return 0; |
2736 | } | |
2737 | ||
2738 | //============================================================================== | |
2739 | //function : VViewList | |
2740 | //purpose : Print current list of views per viewer and graphic driver ID | |
2741 | // shared between viewers | |
2742 | //============================================================================== | |
2743 | ||
2744 | static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
2745 | { | |
2746 | if (theArgsNb > 2) | |
2747 | { | |
2748 | theDi << theArgVec[0] << ": Wrong number of command arguments\n" | |
29cb310a | 2749 | << "Usage: " << theArgVec[0] << " name"; |
18d715bd | 2750 | return 1; |
2751 | } | |
2752 | if (ViewerTest_myContexts.Size() < 1) | |
2753 | return 0; | |
2754 | ||
18d715bd | 2755 | Standard_Boolean isTreeView = |
29cb310a | 2756 | (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 )); |
18d715bd | 2757 | |
2758 | if (isTreeView) | |
c48e2889 | 2759 | { |
18d715bd | 2760 | theDi << theArgVec[0] <<":\n"; |
c48e2889 | 2761 | } |
18d715bd | 2762 | |
c48e2889 | 2763 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers); |
2764 | aDriverIter.More(); aDriverIter.Next()) | |
2765 | { | |
2766 | if (isTreeView) | |
2767 | theDi << aDriverIter.Key1() << ":\n"; | |
18d715bd | 2768 | |
c48e2889 | 2769 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator |
2770 | aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next()) | |
2771 | { | |
2772 | if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1) | |
18d715bd | 2773 | { |
c48e2889 | 2774 | if (isTreeView) |
18d715bd | 2775 | { |
c48e2889 | 2776 | TCollection_AsciiString aContextName(aContextIter.Key1()); |
2777 | theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n"; | |
2778 | } | |
18d715bd | 2779 | |
c48e2889 | 2780 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews); |
2781 | aViewIter.More(); aViewIter.Next()) | |
2782 | { | |
2783 | if (aViewIter.Key1().Search(aContextIter.Key1()) != -1) | |
18d715bd | 2784 | { |
c48e2889 | 2785 | TCollection_AsciiString aViewName(aViewIter.Key1()); |
2786 | if (isTreeView) | |
18d715bd | 2787 | { |
c48e2889 | 2788 | if (aViewIter.Value() == ViewerTest::CurrentView()) |
2789 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n"; | |
18d715bd | 2790 | else |
c48e2889 | 2791 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n"; |
2792 | } | |
2793 | else | |
2794 | { | |
2795 | theDi << aViewName << " "; | |
18d715bd | 2796 | } |
2797 | } | |
2798 | } | |
2799 | } | |
2800 | } | |
c48e2889 | 2801 | } |
18d715bd | 2802 | return 0; |
2803 | } | |
2804 | ||
7fd59977 | 2805 | //============================================================================== |
49582f9d | 2806 | //function : GetMousePosition |
2807 | //purpose : | |
7fd59977 | 2808 | //============================================================================== |
49582f9d | 2809 | void ViewerTest::GetMousePosition (Standard_Integer& theX, |
2810 | Standard_Integer& theY) | |
7fd59977 | 2811 | { |
49582f9d | 2812 | if (Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager()) |
4fe56619 | 2813 | { |
49582f9d | 2814 | theX = aViewCtrl->LastMousePosition().x(); |
2815 | theY = aViewCtrl->LastMousePosition().y(); | |
4fe56619 | 2816 | } |
7fd59977 | 2817 | } |
2818 | ||
44b8f2d6 | 2819 | //============================================================================== |
fc552d84 | 2820 | //function : VViewProj |
2821 | //purpose : Switch view projection | |
44b8f2d6 | 2822 | //============================================================================== |
fc552d84 | 2823 | static int VViewProj (Draw_Interpretor& , |
2824 | Standard_Integer theNbArgs, | |
2825 | const char** theArgVec) | |
44b8f2d6 | 2826 | { |
fc552d84 | 2827 | static Standard_Boolean isYup = Standard_False; |
2828 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
2829 | if (aView.IsNull()) | |
44b8f2d6 | 2830 | { |
23fe70ec | 2831 | Message::SendFail ("Error: no active viewer"); |
44b8f2d6 | 2832 | return 1; |
2833 | } | |
2834 | ||
fc552d84 | 2835 | TCollection_AsciiString aCmdName (theArgVec[0]); |
2836 | Standard_Boolean isGeneralCmd = Standard_False; | |
2837 | if (aCmdName == "vfront") | |
2838 | { | |
2839 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup); | |
2840 | } | |
2841 | else if (aCmdName == "vback") | |
2842 | { | |
2843 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup); | |
2844 | } | |
2845 | else if (aCmdName == "vtop") | |
2846 | { | |
2847 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup); | |
2848 | } | |
2849 | else if (aCmdName == "vbottom") | |
2850 | { | |
2851 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup); | |
2852 | } | |
2853 | else if (aCmdName == "vleft") | |
2854 | { | |
2855 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup); | |
2856 | } | |
2857 | else if (aCmdName == "vright") | |
2858 | { | |
2859 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup); | |
2860 | } | |
2861 | else if (aCmdName == "vaxo") | |
2862 | { | |
2863 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup); | |
2864 | } | |
2865 | else | |
2866 | { | |
2867 | isGeneralCmd = Standard_True; | |
2868 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
2869 | { | |
2870 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); | |
2871 | anArgCase.LowerCase(); | |
2872 | if (anArgCase == "-zup") | |
2873 | { | |
2874 | isYup = Standard_False; | |
2875 | } | |
2876 | else if (anArgCase == "-yup") | |
2877 | { | |
2878 | isYup = Standard_True; | |
2879 | } | |
2880 | else if (anArgCase == "-front" | |
2881 | || anArgCase == "front" | |
2882 | || anArgCase == "-f" | |
2883 | || anArgCase == "f") | |
2884 | { | |
2885 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup); | |
2886 | } | |
2887 | else if (anArgCase == "-back" | |
2888 | || anArgCase == "back" | |
2889 | || anArgCase == "-b" | |
2890 | || anArgCase == "b") | |
2891 | { | |
2892 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup); | |
2893 | } | |
2894 | else if (anArgCase == "-top" | |
2895 | || anArgCase == "top" | |
2896 | || anArgCase == "-t" | |
2897 | || anArgCase == "t") | |
2898 | { | |
2899 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup); | |
2900 | } | |
2901 | else if (anArgCase == "-bottom" | |
2902 | || anArgCase == "bottom" | |
2903 | || anArgCase == "-bot" | |
2904 | || anArgCase == "bot" | |
2905 | || anArgCase == "-b" | |
2906 | || anArgCase == "b") | |
2907 | { | |
2908 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup); | |
2909 | } | |
2910 | else if (anArgCase == "-left" | |
2911 | || anArgCase == "left" | |
2912 | || anArgCase == "-l" | |
2913 | || anArgCase == "l") | |
2914 | { | |
2915 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup); | |
2916 | } | |
2917 | else if (anArgCase == "-right" | |
2918 | || anArgCase == "right" | |
2919 | || anArgCase == "-r" | |
2920 | || anArgCase == "r") | |
2921 | { | |
2922 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup); | |
2923 | } | |
2924 | else if (anArgCase == "-axoleft" | |
2925 | || anArgCase == "-leftaxo" | |
2926 | || anArgCase == "axoleft" | |
2927 | || anArgCase == "leftaxo") | |
2928 | { | |
2929 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoLeft : V3d_TypeOfOrientation_Zup_AxoLeft, isYup); | |
2930 | } | |
2931 | else if (anArgCase == "-axo" | |
2932 | || anArgCase == "axo" | |
2933 | || anArgCase == "-a" | |
2934 | || anArgCase == "a" | |
2935 | || anArgCase == "-axoright" | |
2936 | || anArgCase == "-rightaxo" | |
2937 | || anArgCase == "axoright" | |
2938 | || anArgCase == "rightaxo") | |
2939 | { | |
2940 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup); | |
2941 | } | |
2942 | else if (anArgCase == "+x") | |
2943 | { | |
2944 | aView->SetProj (V3d_Xpos, isYup); | |
2945 | } | |
2946 | else if (anArgCase == "-x") | |
2947 | { | |
2948 | aView->SetProj (V3d_Xneg, isYup); | |
2949 | } | |
2950 | else if (anArgCase == "+y") | |
2951 | { | |
2952 | aView->SetProj (V3d_Ypos, isYup); | |
2953 | } | |
2954 | else if (anArgCase == "-y") | |
2955 | { | |
2956 | aView->SetProj (V3d_Yneg, isYup); | |
2957 | } | |
2958 | else if (anArgCase == "+z") | |
2959 | { | |
2960 | aView->SetProj (V3d_Zpos, isYup); | |
2961 | } | |
2962 | else if (anArgCase == "-z") | |
2963 | { | |
2964 | aView->SetProj (V3d_Zneg, isYup); | |
2965 | } | |
2966 | else if (anArgCase == "+x+y+z") | |
2967 | { | |
2968 | aView->SetProj (V3d_XposYposZpos, isYup); | |
2969 | } | |
2970 | else if (anArgCase == "+x+y-z") | |
2971 | { | |
2972 | aView->SetProj (V3d_XposYposZneg, isYup); | |
2973 | } | |
2974 | else if (anArgCase == "+x-y+z") | |
2975 | { | |
2976 | aView->SetProj (V3d_XposYnegZpos, isYup); | |
2977 | } | |
2978 | else if (anArgCase == "+x-y-z") | |
2979 | { | |
2980 | aView->SetProj (V3d_XposYnegZneg, isYup); | |
2981 | } | |
2982 | else if (anArgCase == "-x+y+z") | |
2983 | { | |
2984 | aView->SetProj (V3d_XnegYposZpos, isYup); | |
2985 | } | |
2986 | else if (anArgCase == "-x+y-z") | |
2987 | { | |
2988 | aView->SetProj (V3d_XnegYposZneg, isYup); | |
2989 | } | |
2990 | else if (anArgCase == "-x-y+z") | |
2991 | { | |
2992 | aView->SetProj (V3d_XnegYnegZpos, isYup); | |
2993 | } | |
2994 | else if (anArgCase == "-x-y-z") | |
2995 | { | |
2996 | aView->SetProj (V3d_XnegYnegZneg, isYup); | |
2997 | } | |
2998 | else if (anArgCase == "+x+y") | |
2999 | { | |
3000 | aView->SetProj (V3d_XposYpos, isYup); | |
3001 | } | |
3002 | else if (anArgCase == "+x-y") | |
3003 | { | |
3004 | aView->SetProj (V3d_XposYneg, isYup); | |
3005 | } | |
3006 | else if (anArgCase == "-x+y") | |
3007 | { | |
3008 | aView->SetProj (V3d_XnegYpos, isYup); | |
3009 | } | |
3010 | else if (anArgCase == "-x-y") | |
3011 | { | |
3012 | aView->SetProj (V3d_XnegYneg, isYup); | |
3013 | } | |
3014 | else if (anArgCase == "+x+z") | |
3015 | { | |
3016 | aView->SetProj (V3d_XposZpos, isYup); | |
3017 | } | |
3018 | else if (anArgCase == "+x-z") | |
3019 | { | |
3020 | aView->SetProj (V3d_XposZneg, isYup); | |
3021 | } | |
3022 | else if (anArgCase == "-x+z") | |
3023 | { | |
3024 | aView->SetProj (V3d_XnegZpos, isYup); | |
3025 | } | |
3026 | else if (anArgCase == "-x-z") | |
3027 | { | |
3028 | aView->SetProj (V3d_XnegZneg, isYup); | |
3029 | } | |
3030 | else if (anArgCase == "+y+z") | |
3031 | { | |
3032 | aView->SetProj (V3d_YposZpos, isYup); | |
3033 | } | |
3034 | else if (anArgCase == "+y-z") | |
3035 | { | |
3036 | aView->SetProj (V3d_YposZneg, isYup); | |
3037 | } | |
3038 | else if (anArgCase == "-y+z") | |
3039 | { | |
3040 | aView->SetProj (V3d_YnegZpos, isYup); | |
3041 | } | |
3042 | else if (anArgCase == "-y-z") | |
3043 | { | |
3044 | aView->SetProj (V3d_YnegZneg, isYup); | |
3045 | } | |
3046 | else if (anArgIter + 1 < theNbArgs | |
3047 | && anArgCase == "-frame" | |
3048 | && TCollection_AsciiString (theArgVec[anArgIter + 1]).Length() == 4) | |
3049 | { | |
3050 | TCollection_AsciiString aFrameDef (theArgVec[++anArgIter]); | |
3051 | aFrameDef.LowerCase(); | |
3052 | gp_Dir aRight, anUp; | |
3053 | if (aFrameDef.Value (2) == aFrameDef.Value (4)) | |
3054 | { | |
23fe70ec | 3055 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
fc552d84 | 3056 | return 1; |
3057 | } | |
44b8f2d6 | 3058 | |
fc552d84 | 3059 | if (aFrameDef.Value (2) == 'x') |
3060 | { | |
3061 | aRight = aFrameDef.Value (1) == '+' ? gp::DX() : -gp::DX(); | |
3062 | } | |
3063 | else if (aFrameDef.Value (2) == 'y') | |
3064 | { | |
3065 | aRight = aFrameDef.Value (1) == '+' ? gp::DY() : -gp::DY(); | |
3066 | } | |
3067 | else if (aFrameDef.Value (2) == 'z') | |
3068 | { | |
3069 | aRight = aFrameDef.Value (1) == '+' ? gp::DZ() : -gp::DZ(); | |
3070 | } | |
3071 | else | |
3072 | { | |
23fe70ec | 3073 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
fc552d84 | 3074 | return 1; |
3075 | } | |
7fd59977 | 3076 | |
fc552d84 | 3077 | if (aFrameDef.Value (4) == 'x') |
3078 | { | |
3079 | anUp = aFrameDef.Value (3) == '+' ? gp::DX() : -gp::DX(); | |
3080 | } | |
3081 | else if (aFrameDef.Value (4) == 'y') | |
3082 | { | |
3083 | anUp = aFrameDef.Value (3) == '+' ? gp::DY() : -gp::DY(); | |
3084 | } | |
3085 | else if (aFrameDef.Value (4) == 'z') | |
3086 | { | |
3087 | anUp = aFrameDef.Value (3) == '+' ? gp::DZ() : -gp::DZ(); | |
3088 | } | |
3089 | else | |
3090 | { | |
23fe70ec | 3091 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
fc552d84 | 3092 | return 1; |
3093 | } | |
44b8f2d6 | 3094 | |
fc552d84 | 3095 | const Handle(Graphic3d_Camera)& aCamera = aView->Camera(); |
3096 | const gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin()); | |
3097 | const gp_Dir aDir = anUp.Crossed (aRight); | |
3098 | aCamera->SetCenter (gp_Pnt (0, 0, 0)); | |
3099 | aCamera->SetDirection (aDir); | |
3100 | aCamera->SetUp (anUp); | |
3101 | aCamera->OrthogonalizeUp(); | |
44b8f2d6 | 3102 | |
fc552d84 | 3103 | aView->Panning (anOriginVCS.X(), anOriginVCS.Y()); |
3104 | aView->Update(); | |
3105 | } | |
3106 | else | |
3107 | { | |
23fe70ec | 3108 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
fc552d84 | 3109 | return 1; |
3110 | } | |
3111 | } | |
3112 | } | |
44b8f2d6 | 3113 | |
fc552d84 | 3114 | if (!isGeneralCmd |
3115 | && theNbArgs != 1) | |
3116 | { | |
23fe70ec | 3117 | Message::SendFail ("Syntax error: wrong number of arguments"); |
fc552d84 | 3118 | return 1; |
3119 | } | |
3120 | return 0; | |
7fd59977 | 3121 | } |
3122 | ||
3123 | //============================================================================== | |
3124 | //function : VHelp | |
3125 | //purpose : Dsiplay help on viewer Keyboead and mouse commands | |
3126 | //Draw arg : No args | |
3127 | //============================================================================== | |
3128 | ||
3129 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) | |
3130 | { | |
586db386 | 3131 | di << "=========================\n"; |
3132 | di << "F : FitAll\n"; | |
3133 | di << "T : TopView\n"; | |
3134 | di << "B : BottomView\n"; | |
3135 | di << "R : RightView\n"; | |
3136 | di << "L : LeftView\n"; | |
3137 | di << "A : AxonometricView\n"; | |
3138 | di << "D : ResetView\n"; | |
3139 | ||
3140 | di << "=========================\n"; | |
3141 | di << "S : Shading\n"; | |
3142 | di << "W : Wireframe\n"; | |
49582f9d | 3143 | di << "H : HiddenLineRemoval\n"; |
586db386 | 3144 | di << "U : Unset display mode\n"; |
3145 | di << "Delete : Remove selection from viewer\n"; | |
3146 | ||
3147 | di << "=========================\n"; | |
3148 | di << "Selection mode \n"; | |
3149 | di << "0 : Shape\n"; | |
3150 | di << "1 : Vertex\n"; | |
3151 | di << "2 : Edge\n"; | |
3152 | di << "3 : Wire\n"; | |
3153 | di << "4 : Face\n"; | |
3154 | di << "5 : Shell\n"; | |
3155 | di << "6 : Solid\n"; | |
3156 | di << "7 : Compound\n"; | |
3157 | ||
3158 | di << "=========================\n"; | |
49582f9d | 3159 | di << "< : Hilight next detected\n"; |
3160 | di << "> : Hilight previous detected\n"; | |
7fd59977 | 3161 | |
3162 | return 0; | |
3163 | } | |
3164 | ||
57c28b61 | 3165 | #ifdef _WIN32 |
7fd59977 | 3166 | |
49582f9d | 3167 | static LRESULT WINAPI AdvViewerWindowProc (HWND theWinHandle, |
3168 | UINT theMsg, | |
3169 | WPARAM wParam, | |
3170 | LPARAM lParam ) | |
7fd59977 | 3171 | { |
49582f9d | 3172 | if (ViewerTest_myViews.IsEmpty()) |
3173 | { | |
3174 | return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam); | |
3175 | } | |
7fd59977 | 3176 | |
49582f9d | 3177 | switch (theMsg) |
3178 | { | |
18d715bd | 3179 | case WM_CLOSE: |
49582f9d | 3180 | { |
3181 | // Delete view from map of views | |
3182 | ViewerTest::RemoveView (FindViewIdByWindowHandle (theWinHandle)); | |
3183 | return 0; | |
3184 | } | |
18d715bd | 3185 | case WM_ACTIVATE: |
49582f9d | 3186 | { |
3187 | if (LOWORD(wParam) == WA_CLICKACTIVE | |
3188 | || LOWORD(wParam) == WA_ACTIVE | |
3189 | || ViewerTest::CurrentView().IsNull()) | |
18d715bd | 3190 | { |
3191 | // Activate inactive window | |
49582f9d | 3192 | if (VT_GetWindow().IsNull() |
3193 | || (HWND )VT_GetWindow()->HWindow() != theWinHandle) | |
625e1958 | 3194 | { |
49582f9d | 3195 | ActivateView (FindViewIdByWindowHandle (theWinHandle)); |
625e1958 | 3196 | } |
7fd59977 | 3197 | } |
7fd59977 | 3198 | break; |
49582f9d | 3199 | } |
7fd59977 | 3200 | default: |
49582f9d | 3201 | { |
3202 | return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam); | |
7fd59977 | 3203 | } |
7fd59977 | 3204 | } |
49582f9d | 3205 | return 0; |
7fd59977 | 3206 | } |
3207 | ||
49582f9d | 3208 | static LRESULT WINAPI ViewerWindowProc (HWND theWinHandle, |
3209 | UINT theMsg, | |
3210 | WPARAM wParam, | |
3211 | LPARAM lParam) | |
7fd59977 | 3212 | { |
f978241f | 3213 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); |
3214 | if (aView.IsNull()) | |
3215 | { | |
49582f9d | 3216 | return DefWindowProcW (theWinHandle, theMsg, wParam, lParam); |
f978241f | 3217 | } |
7fd59977 | 3218 | |
49582f9d | 3219 | switch (theMsg) |
3220 | { | |
7fd59977 | 3221 | case WM_PAINT: |
49582f9d | 3222 | { |
3223 | PAINTSTRUCT aPaint; | |
3224 | BeginPaint(theWinHandle, &aPaint); | |
3225 | EndPaint (theWinHandle, &aPaint); | |
3226 | ViewerTest::CurrentEventManager()->ProcessExpose(); | |
7fd59977 | 3227 | break; |
49582f9d | 3228 | } |
7fd59977 | 3229 | case WM_SIZE: |
49582f9d | 3230 | { |
3231 | ViewerTest::CurrentEventManager()->ProcessConfigure(); | |
7fd59977 | 3232 | break; |
49582f9d | 3233 | } |
f978241f | 3234 | case WM_MOVE: |
3235 | case WM_MOVING: | |
3236 | case WM_SIZING: | |
49582f9d | 3237 | { |
f978241f | 3238 | switch (aView->RenderingParams().StereoMode) |
3239 | { | |
3240 | case Graphic3d_StereoMode_RowInterlaced: | |
3241 | case Graphic3d_StereoMode_ColumnInterlaced: | |
3242 | case Graphic3d_StereoMode_ChessBoard: | |
49582f9d | 3243 | { |
3244 | // track window moves to reverse stereo pair | |
3245 | aView->MustBeResized(); | |
3246 | aView->Update(); | |
f978241f | 3247 | break; |
49582f9d | 3248 | } |
f978241f | 3249 | default: |
3250 | break; | |
3251 | } | |
3252 | break; | |
49582f9d | 3253 | } |
3254 | case WM_KEYUP: | |
7fd59977 | 3255 | case WM_KEYDOWN: |
49582f9d | 3256 | { |
3257 | const Aspect_VKey aVKey = WNT_Window::VirtualKeyFromNative ((Standard_Integer )wParam); | |
3258 | if (aVKey != Aspect_VKey_UNKNOWN) | |
4fe56619 | 3259 | { |
49582f9d | 3260 | const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime(); |
3261 | if (theMsg == WM_KEYDOWN) | |
f978241f | 3262 | { |
49582f9d | 3263 | ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp); |
f978241f | 3264 | } |
49582f9d | 3265 | else |
f978241f | 3266 | { |
49582f9d | 3267 | ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp); |
f978241f | 3268 | } |
49582f9d | 3269 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); |
7fd59977 | 3270 | } |
3271 | break; | |
49582f9d | 3272 | } |
7fd59977 | 3273 | case WM_LBUTTONUP: |
3274 | case WM_MBUTTONUP: | |
3275 | case WM_RBUTTONUP: | |
7fd59977 | 3276 | case WM_LBUTTONDOWN: |
3277 | case WM_MBUTTONDOWN: | |
3278 | case WM_RBUTTONDOWN: | |
49582f9d | 3279 | { |
3280 | const Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam)); | |
3281 | const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam); | |
3282 | Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE; | |
3283 | switch (theMsg) | |
7fd59977 | 3284 | { |
49582f9d | 3285 | case WM_LBUTTONUP: |
3286 | case WM_LBUTTONDOWN: | |
3287 | aButton = Aspect_VKeyMouse_LeftButton; | |
3288 | break; | |
3289 | case WM_MBUTTONUP: | |
3290 | case WM_MBUTTONDOWN: | |
3291 | aButton = Aspect_VKeyMouse_MiddleButton; | |
3292 | break; | |
3293 | case WM_RBUTTONUP: | |
3294 | case WM_RBUTTONDOWN: | |
3295 | aButton = Aspect_VKeyMouse_RightButton; | |
3296 | break; | |
7fd59977 | 3297 | } |
49582f9d | 3298 | if (theMsg == WM_LBUTTONDOWN |
3299 | || theMsg == WM_MBUTTONDOWN | |
3300 | || theMsg == WM_RBUTTONDOWN) | |
f978241f | 3301 | { |
49582f9d | 3302 | if (aButton == Aspect_VKeyMouse_LeftButton) |
f978241f | 3303 | { |
49582f9d | 3304 | TheIsAnimating = Standard_False; |
f978241f | 3305 | } |
49582f9d | 3306 | |
3307 | SetFocus (theWinHandle); | |
3308 | SetCapture(theWinHandle); | |
3309 | ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false); | |
f978241f | 3310 | } |
3311 | else | |
3312 | { | |
49582f9d | 3313 | ReleaseCapture(); |
3314 | ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false); | |
f978241f | 3315 | } |
49582f9d | 3316 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); |
f978241f | 3317 | break; |
3318 | } | |
49582f9d | 3319 | case WM_MOUSEWHEEL: |
3320 | { | |
3321 | const int aDelta = GET_WHEEL_DELTA_WPARAM (wParam); | |
3322 | const Standard_Real aDeltaF = Standard_Real(aDelta) / Standard_Real(WHEEL_DELTA); | |
3323 | const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam); | |
3324 | Graphic3d_Vec2i aPos (int(short(LOWORD(lParam))), int(short(HIWORD(lParam)))); | |
3325 | POINT aCursorPnt = { aPos.x(), aPos.y() }; | |
3326 | if (ScreenToClient (theWinHandle, &aCursorPnt)) | |
7fd59977 | 3327 | { |
49582f9d | 3328 | aPos.SetValues (aCursorPnt.x, aCursorPnt.y); |
3329 | } | |
7fd59977 | 3330 | |
49582f9d | 3331 | ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags)); |
3332 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); | |
3333 | break; | |
3334 | } | |
3335 | case WM_MOUSEMOVE: | |
3336 | { | |
3337 | Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam)); | |
3338 | Aspect_VKeyMouse aButtons = WNT_Window::MouseButtonsFromEvent (wParam); | |
3339 | Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent(wParam); | |
7fd59977 | 3340 | |
49582f9d | 3341 | // don't make a slide-show from input events - fetch the actual mouse cursor position |
3342 | CURSORINFO aCursor; | |
3343 | aCursor.cbSize = sizeof(aCursor); | |
3344 | if (::GetCursorInfo (&aCursor) != FALSE) | |
3345 | { | |
3346 | POINT aCursorPnt = { aCursor.ptScreenPos.x, aCursor.ptScreenPos.y }; | |
3347 | if (ScreenToClient (theWinHandle, &aCursorPnt)) | |
3348 | { | |
3349 | // as we override mouse position, we need overriding also mouse state | |
3350 | aPos.SetValues (aCursorPnt.x, aCursorPnt.y); | |
3351 | aButtons = WNT_Window::MouseButtonsAsync(); | |
3352 | aFlags = WNT_Window::MouseKeyFlagsAsync(); | |
3353 | } | |
3354 | } | |
7fd59977 | 3355 | |
49582f9d | 3356 | if (VT_GetWindow().IsNull() |
3357 | || (HWND )VT_GetWindow()->HWindow() != theWinHandle) | |
3358 | { | |
3359 | // mouse move events come also for inactive windows | |
3360 | break; | |
7fd59977 | 3361 | } |
7fd59977 | 3362 | |
49582f9d | 3363 | ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false); |
3364 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true); | |
3365 | break; | |
3366 | } | |
7fd59977 | 3367 | default: |
49582f9d | 3368 | { |
3369 | return DefWindowProcW (theWinHandle, theMsg, wParam, lParam); | |
7fd59977 | 3370 | } |
49582f9d | 3371 | } |
3372 | return 0L; | |
7fd59977 | 3373 | } |
3374 | ||
7fd59977 | 3375 | //============================================================================== |
3376 | //function : ViewerMainLoop | |
3377 | //purpose : Get a Event on the view and dispatch it | |
3378 | //============================================================================== | |
3379 | ||
49582f9d | 3380 | int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec) |
7fd59977 | 3381 | { |
49582f9d | 3382 | Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager(); |
3383 | if (aViewCtrl.IsNull() | |
3384 | || theNbArgs < 4) | |
3385 | { | |
3386 | return 0; | |
3387 | } | |
7fd59977 | 3388 | |
49582f9d | 3389 | aViewCtrl->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]); |
7fd59977 | 3390 | |
49582f9d | 3391 | std::cout << "Start picking\n"; |
7fd59977 | 3392 | |
49582f9d | 3393 | MSG aMsg; |
3394 | aMsg.wParam = 1; | |
3395 | while (aViewCtrl->ToPickPoint()) | |
3396 | { | |
3397 | // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 | |
3398 | if (GetMessageW (&aMsg, NULL, 0, 0)) | |
3399 | { | |
3400 | TranslateMessage (&aMsg); | |
3401 | DispatchMessageW (&aMsg); | |
7fd59977 | 3402 | } |
7fd59977 | 3403 | } |
3404 | ||
49582f9d | 3405 | std::cout << "Picking done\n"; |
3406 | return 0; | |
7fd59977 | 3407 | } |
3408 | ||
4fe56619 | 3409 | #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 3410 | |
3411 | int min( int a, int b ) | |
3412 | { | |
3413 | if( a<b ) | |
3414 | return a; | |
3415 | else | |
3416 | return b; | |
3417 | } | |
3418 | ||
3419 | int max( int a, int b ) | |
3420 | { | |
3421 | if( a>b ) | |
3422 | return a; | |
3423 | else | |
3424 | return b; | |
3425 | } | |
3426 | ||
49582f9d | 3427 | int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec) |
4269bd1b | 3428 | { |
18d715bd | 3429 | static XEvent aReport; |
49582f9d | 3430 | const Standard_Boolean toPick = theNbArgs > 0; |
3431 | if (theNbArgs > 0) | |
3432 | { | |
3433 | if (ViewerTest::CurrentEventManager().IsNull()) | |
3434 | { | |
3435 | return 0; | |
3436 | } | |
3437 | ViewerTest::CurrentEventManager()->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]); | |
3438 | } | |
3439 | ||
8693dfd0 | 3440 | Display* aDisplay = GetDisplayConnection()->GetDisplay(); |
18d715bd | 3441 | XNextEvent (aDisplay, &aReport); |
7fd59977 | 3442 | |
18d715bd | 3443 | // Handle event for the chosen display connection |
8693dfd0 | 3444 | switch (aReport.type) |
3445 | { | |
3446 | case ClientMessage: | |
3447 | { | |
3448 | if ((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW)) | |
3449 | { | |
3450 | // Close the window | |
3451 | ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window)); | |
3452 | return toPick ? 0 : 1; | |
3453 | } | |
3454 | break; | |
3455 | } | |
3456 | case FocusIn: | |
3457 | { | |
3458 | // Activate inactive view | |
49582f9d | 3459 | Window aWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0; |
8693dfd0 | 3460 | if (aWindow != aReport.xfocus.window) |
3461 | { | |
3462 | ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window)); | |
3463 | } | |
3464 | break; | |
3465 | } | |
3466 | case Expose: | |
3467 | { | |
49582f9d | 3468 | Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0; |
8693dfd0 | 3469 | if (anXWindow == aReport.xexpose.window) |
3470 | { | |
49582f9d | 3471 | ViewerTest::CurrentEventManager()->ProcessExpose(); |
8693dfd0 | 3472 | } |
3473 | ||
3474 | // remove all the ExposureMask and process them at once | |
3475 | for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents) | |
3476 | { | |
3477 | if (!XCheckWindowEvent (aDisplay, anXWindow, ExposureMask, &aReport)) | |
18d715bd | 3478 | { |
8693dfd0 | 3479 | break; |
18d715bd | 3480 | } |
8693dfd0 | 3481 | } |
3482 | ||
3483 | break; | |
3484 | } | |
3485 | case ConfigureNotify: | |
3486 | { | |
3487 | // remove all the StructureNotifyMask and process them at once | |
49582f9d | 3488 | Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0; |
8693dfd0 | 3489 | for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents) |
3490 | { | |
3491 | if (!XCheckWindowEvent (aDisplay, anXWindow, StructureNotifyMask, &aReport)) | |
3492 | { | |
3493 | break; | |
3494 | } | |
3495 | } | |
3496 | ||
3497 | if (anXWindow == aReport.xconfigure.window) | |
3498 | { | |
49582f9d | 3499 | ViewerTest::CurrentEventManager()->ProcessConfigure(); |
8693dfd0 | 3500 | } |
3501 | break; | |
3502 | } | |
3503 | case KeyPress: | |
49582f9d | 3504 | case KeyRelease: |
8693dfd0 | 3505 | { |
49582f9d | 3506 | XKeyEvent* aKeyEvent = (XKeyEvent* )&aReport; |
3507 | const KeySym aKeySym = XLookupKeysym (aKeyEvent, 0); | |
3508 | const Aspect_VKey aVKey = Xw_Window::VirtualKeyFromNative (aKeySym); | |
3509 | if (aVKey != Aspect_VKey_UNKNOWN) | |
8693dfd0 | 3510 | { |
49582f9d | 3511 | const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime(); |
3512 | if (aReport.type == KeyPress) | |
7fd59977 | 3513 | { |
49582f9d | 3514 | ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp); |
7fd59977 | 3515 | } |
8693dfd0 | 3516 | else |
7fd59977 | 3517 | { |
49582f9d | 3518 | ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp); |
7fd59977 | 3519 | } |
49582f9d | 3520 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); |
8693dfd0 | 3521 | } |
3522 | break; | |
3523 | } | |
49582f9d | 3524 | case ButtonPress: |
8693dfd0 | 3525 | case ButtonRelease: |
3526 | { | |
49582f9d | 3527 | const Graphic3d_Vec2i aPos (aReport.xbutton.x, aReport.xbutton.y); |
3528 | Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE; | |
3529 | Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE; | |
3530 | if (aReport.xbutton.button == Button1) | |
8693dfd0 | 3531 | { |
49582f9d | 3532 | aButton = Aspect_VKeyMouse_LeftButton; |
8693dfd0 | 3533 | } |
49582f9d | 3534 | if (aReport.xbutton.button == Button2) |
8693dfd0 | 3535 | { |
49582f9d | 3536 | aButton = Aspect_VKeyMouse_MiddleButton; |
8693dfd0 | 3537 | } |
49582f9d | 3538 | if (aReport.xbutton.button == Button3) |
8693dfd0 | 3539 | { |
49582f9d | 3540 | aButton = Aspect_VKeyMouse_RightButton; |
8693dfd0 | 3541 | } |
7fd59977 | 3542 | |
49582f9d | 3543 | if (aReport.xbutton.state & ControlMask) |
8693dfd0 | 3544 | { |
49582f9d | 3545 | aFlags |= Aspect_VKeyFlags_CTRL; |
3546 | } | |
3547 | if (aReport.xbutton.state & ShiftMask) | |
3548 | { | |
3549 | aFlags |= Aspect_VKeyFlags_SHIFT; | |
3550 | } | |
3551 | if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt)) | |
3552 | { | |
3553 | aFlags |= Aspect_VKeyFlags_ALT; | |
8693dfd0 | 3554 | } |
7fd59977 | 3555 | |
49582f9d | 3556 | if (aReport.xbutton.button == Button4 |
3557 | || aReport.xbutton.button == Button5) | |
8693dfd0 | 3558 | { |
49582f9d | 3559 | if (aReport.type != ButtonPress) |
8693dfd0 | 3560 | { |
49582f9d | 3561 | break; |
7fd59977 | 3562 | } |
49582f9d | 3563 | |
3564 | const double aDeltaF = (aReport.xbutton.button == Button4 ? 1.0 : -1.0); | |
3565 | ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags)); | |
3566 | } | |
3567 | else if (aReport.type == ButtonPress) | |
3568 | { | |
3569 | if (aButton == Aspect_VKeyMouse_LeftButton) | |
7fd59977 | 3570 | { |
49582f9d | 3571 | TheIsAnimating = Standard_False; |
7fd59977 | 3572 | } |
49582f9d | 3573 | ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false); |
8693dfd0 | 3574 | } |
3575 | else | |
3576 | { | |
49582f9d | 3577 | ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false); |
8693dfd0 | 3578 | } |
49582f9d | 3579 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); |
8693dfd0 | 3580 | break; |
3581 | } | |
3582 | case MotionNotify: | |
3583 | { | |
49582f9d | 3584 | Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0; |
8693dfd0 | 3585 | if (anXWindow != aReport.xmotion.window) |
3586 | { | |
7fd59977 | 3587 | break; |
8693dfd0 | 3588 | } |
3589 | ||
3590 | // remove all the ButtonMotionMask and process them at once | |
3591 | for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents) | |
3592 | { | |
3593 | if (!XCheckWindowEvent (aDisplay, anXWindow, ButtonMotionMask | PointerMotionMask, &aReport)) | |
7fd59977 | 3594 | { |
8693dfd0 | 3595 | break; |
3596 | } | |
3597 | } | |
7fd59977 | 3598 | |
49582f9d | 3599 | Graphic3d_Vec2i aPos (aReport.xmotion.x, aReport.xmotion.y); |
3600 | Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE; | |
3601 | Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE; | |
3602 | if ((aReport.xmotion.state & Button1Mask) != 0) | |
8693dfd0 | 3603 | { |
49582f9d | 3604 | aButtons |= Aspect_VKeyMouse_LeftButton; |
3605 | } | |
3606 | else if ((aReport.xmotion.state & Button2Mask) != 0) | |
3607 | { | |
3608 | aButtons |= Aspect_VKeyMouse_MiddleButton; | |
3609 | } | |
3610 | else if ((aReport.xmotion.state & Button3Mask) != 0) | |
3611 | { | |
3612 | aButtons |= Aspect_VKeyMouse_RightButton; | |
3613 | } | |
7fd59977 | 3614 | |
49582f9d | 3615 | if (aReport.xmotion.state & ControlMask) |
3616 | { | |
3617 | aFlags |= Aspect_VKeyFlags_CTRL; | |
8693dfd0 | 3618 | } |
49582f9d | 3619 | if (aReport.xmotion.state & ShiftMask) |
8693dfd0 | 3620 | { |
49582f9d | 3621 | aFlags |= Aspect_VKeyFlags_SHIFT; |
8693dfd0 | 3622 | } |
49582f9d | 3623 | if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt)) |
3624 | { | |
3625 | aFlags |= Aspect_VKeyFlags_ALT; | |
3626 | } | |
3627 | ||
3628 | ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false); | |
3629 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); | |
8693dfd0 | 3630 | break; |
3631 | } | |
3632 | } | |
49582f9d | 3633 | return (!toPick || ViewerTest::CurrentEventManager()->ToPickPoint()) ? 1 : 0; |
7fd59977 | 3634 | } |
3635 | ||
3636 | //============================================================================== | |
3637 | //function : VProcessEvents | |
8693dfd0 | 3638 | //purpose : manage the event in the Viewer window (see Tcl_CreateFileHandler()) |
7fd59977 | 3639 | //============================================================================== |
8693dfd0 | 3640 | static void VProcessEvents (ClientData theDispX, int) |
7fd59977 | 3641 | { |
8693dfd0 | 3642 | Display* aDispX = (Display* )theDispX; |
3643 | Handle(Aspect_DisplayConnection) aDispConn; | |
3644 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
3645 | aDriverIter (ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next()) | |
18d715bd | 3646 | { |
8693dfd0 | 3647 | const Handle(Aspect_DisplayConnection)& aDispConnTmp = aDriverIter.Key2()->GetDisplayConnection(); |
3648 | if (aDispConnTmp->GetDisplay() == aDispX) | |
3649 | { | |
3650 | aDispConn = aDispConnTmp; | |
3651 | break; | |
3652 | } | |
3653 | } | |
3654 | if (aDispConn.IsNull()) | |
3655 | { | |
23fe70ec | 3656 | Message::SendFail ("Error: ViewerTest is unable processing messages for unknown X Display"); |
8693dfd0 | 3657 | return; |
4269bd1b | 3658 | } |
8693dfd0 | 3659 | |
3660 | // process new events in queue | |
3661 | SetDisplayConnection (aDispConn); | |
3662 | int aNbRemain = 0; | |
3663 | for (int aNbEventsMax = XPending (aDispX), anEventIter (0);;) | |
18d715bd | 3664 | { |
8693dfd0 | 3665 | const int anEventResult = ViewerMainLoop (0, NULL); |
3666 | if (anEventResult == 0) | |
18d715bd | 3667 | { |
8693dfd0 | 3668 | return; |
3669 | } | |
3670 | ||
3671 | aNbRemain = XPending (aDispX); | |
3672 | if (++anEventIter >= aNbEventsMax | |
3673 | || aNbRemain <= 0) | |
3674 | { | |
3675 | break; | |
18d715bd | 3676 | } |
7fd59977 | 3677 | } |
4269bd1b | 3678 | |
8693dfd0 | 3679 | // Listening X events through Tcl_CreateFileHandler() callback is fragile, |
3680 | // it is possible that new events will arrive to queue before the end of this callback | |
3681 | // so that either this callback should go into an infinite loop (blocking processing of other events) | |
3682 | // or to keep unprocessed events till the next queue update (which can arrive not soon). | |
3683 | // Sending a dummy event in this case is a simple workaround (still, it is possible that new event will be queued in-between). | |
3684 | if (aNbRemain != 0) | |
3685 | { | |
3686 | XEvent aDummyEvent; | |
3687 | memset (&aDummyEvent, 0, sizeof(aDummyEvent)); | |
3688 | aDummyEvent.type = ClientMessage; | |
3689 | aDummyEvent.xclient.format = 32; | |
3690 | XSendEvent (aDispX, InputFocus, False, 0, &aDummyEvent); | |
3691 | XFlush (aDispX); | |
3692 | } | |
4269bd1b | 3693 | |
8693dfd0 | 3694 | if (const Handle(AIS_InteractiveContext)& anActiveCtx = ViewerTest::GetAISContext()) |
3695 | { | |
3696 | SetDisplayConnection (anActiveCtx->CurrentViewer()->Driver()->GetDisplayConnection()); | |
3697 | } | |
7fd59977 | 3698 | } |
3699 | #endif | |
3700 | ||
3701 | //============================================================================== | |
3702 | //function : OSWindowSetup | |
3703 | //purpose : Setup for the X11 window to be able to cath the event | |
3704 | //============================================================================== | |
3705 | ||
3706 | ||
3707 | static void OSWindowSetup() | |
3708 | { | |
4fe56619 | 3709 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 3710 | // X11 |
3711 | ||
3712 | Window window = VT_GetWindow()->XWindow(); | |
18d715bd | 3713 | SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
3714 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
3715 | XSynchronize(aDisplay, 1); | |
7fd59977 | 3716 | |
3717 | // X11 : For keyboard on SUN | |
3718 | XWMHints wmhints; | |
3719 | wmhints.flags = InputHint; | |
3720 | wmhints.input = 1; | |
3721 | ||
18d715bd | 3722 | XSetWMHints( aDisplay, window, &wmhints); |
7fd59977 | 3723 | |
49582f9d | 3724 | XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | KeyReleaseMask | |
7fd59977 | 3725 | ButtonPressMask | ButtonReleaseMask | |
3726 | StructureNotifyMask | | |
3727 | PointerMotionMask | | |
3728 | Button1MotionMask | Button2MotionMask | | |
18d715bd | 3729 | Button3MotionMask | FocusChangeMask |
7fd59977 | 3730 | ); |
18d715bd | 3731 | Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW); |
3732 | XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1); | |
7fd59977 | 3733 | |
18d715bd | 3734 | XSynchronize(aDisplay, 0); |
7fd59977 | 3735 | |
3736 | #else | |
57c28b61 | 3737 | // _WIN32 |
7fd59977 | 3738 | #endif |
3739 | ||
3740 | } | |
3741 | ||
7fd59977 | 3742 | //============================================================================== |
3743 | //function : VFit | |
1beb58d7 | 3744 | //purpose : |
7fd59977 | 3745 | //============================================================================== |
3746 | ||
1beb58d7 | 3747 | static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv) |
7fd59977 | 3748 | { |
1beb58d7 | 3749 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3750 | if (aView.IsNull()) | |
b586500b | 3751 | { |
23fe70ec | 3752 | Message::SendFail ("Error: no active viewer"); |
1beb58d7 | 3753 | return 1; |
b586500b | 3754 | } |
3755 | ||
1beb58d7 | 3756 | Standard_Boolean toFit = Standard_True; |
3757 | ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView); | |
3758 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
b586500b | 3759 | { |
1beb58d7 | 3760 | TCollection_AsciiString anArg (theArgv[anArgIter]); |
b586500b | 3761 | anArg.LowerCase(); |
1beb58d7 | 3762 | if (anUpdateTool.parseRedrawMode (anArg)) |
b586500b | 3763 | { |
1beb58d7 | 3764 | continue; |
3765 | } | |
3766 | else if (anArg == "-selected") | |
3767 | { | |
3768 | ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False); | |
3769 | toFit = Standard_False; | |
3770 | } | |
3771 | else | |
3772 | { | |
23fe70ec | 3773 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
b586500b | 3774 | } |
3775 | } | |
3776 | ||
1beb58d7 | 3777 | if (toFit) |
3778 | { | |
3779 | aView->FitAll (0.01, Standard_False); | |
7fd59977 | 3780 | } |
3781 | return 0; | |
3782 | } | |
3783 | ||
6262a303 | 3784 | //======================================================================= |
3785 | //function : VFitArea | |
3786 | //purpose : Fit view to show area located between two points | |
3787 | // : given in world 2D or 3D coordinates. | |
3788 | //======================================================================= | |
3789 | static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
3790 | { | |
3791 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3792 | if (aView.IsNull()) | |
3793 | { | |
23fe70ec | 3794 | Message::SendFail ("Error: No active viewer"); |
6262a303 | 3795 | return 1; |
3796 | } | |
3797 | ||
3798 | // Parse arguments. | |
3799 | gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0); | |
3800 | gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0); | |
3801 | ||
3802 | if (theArgNb == 5) | |
3803 | { | |
3804 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
3805 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
3806 | aWorldPnt2.SetX (Draw::Atof (theArgVec[3])); | |
3807 | aWorldPnt2.SetY (Draw::Atof (theArgVec[4])); | |
3808 | } | |
3809 | else if (theArgNb == 7) | |
3810 | { | |
3811 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
3812 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
3813 | aWorldPnt1.SetZ (Draw::Atof (theArgVec[3])); | |
3814 | aWorldPnt2.SetX (Draw::Atof (theArgVec[4])); | |
3815 | aWorldPnt2.SetY (Draw::Atof (theArgVec[5])); | |
3816 | aWorldPnt2.SetZ (Draw::Atof (theArgVec[6])); | |
3817 | } | |
3818 | else | |
3819 | { | |
23fe70ec | 3820 | Message::SendFail ("Syntax error: Invalid number of arguments"); |
6262a303 | 3821 | theDI.PrintHelp(theArgVec[0]); |
3822 | return 1; | |
3823 | } | |
3824 | ||
3825 | // Convert model coordinates to view space | |
3826 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
3827 | gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1); | |
3828 | gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2); | |
3829 | ||
3830 | // Determine fit area | |
3831 | gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y())); | |
3832 | gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y())); | |
3833 | ||
3834 | Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner); | |
3835 | ||
3836 | if (aDiagonal < Precision::Confusion()) | |
3837 | { | |
23fe70ec | 3838 | Message::SendFail ("Error: view area is too small"); |
6262a303 | 3839 | return 1; |
3840 | } | |
3841 | ||
3842 | aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y()); | |
3843 | return 0; | |
3844 | } | |
3845 | ||
7fd59977 | 3846 | //============================================================================== |
3847 | //function : VZFit | |
3848 | //purpose : ZFitall, no DRAW arguments | |
3849 | //Draw arg : No args | |
3850 | //============================================================================== | |
197ac94e | 3851 | static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 3852 | { |
197ac94e | 3853 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
3854 | ||
3855 | if (aCurrentView.IsNull()) | |
3856 | { | |
23fe70ec | 3857 | Message::SendFail ("Error: no active viewer"); |
197ac94e | 3858 | return 1; |
3859 | } | |
3860 | ||
3861 | if (theArgsNb == 1) | |
3862 | { | |
c357e426 | 3863 | aCurrentView->ZFitAll(); |
197ac94e | 3864 | aCurrentView->Redraw(); |
3865 | return 0; | |
3866 | } | |
3867 | ||
3868 | Standard_Real aScale = 1.0; | |
3869 | ||
3870 | if (theArgsNb >= 2) | |
3871 | { | |
3872 | aScale = Draw::Atoi (theArgVec[1]); | |
3873 | } | |
3874 | ||
c357e426 | 3875 | aCurrentView->ZFitAll (aScale); |
197ac94e | 3876 | aCurrentView->Redraw(); |
7fd59977 | 3877 | |
197ac94e | 3878 | return 0; |
3879 | } | |
7fd59977 | 3880 | |
197ac94e | 3881 | //============================================================================== |
3882 | //function : VRepaint | |
3883 | //purpose : | |
3884 | //============================================================================== | |
56689b27 | 3885 | static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec) |
7fd59977 | 3886 | { |
56689b27 | 3887 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3888 | if (aView.IsNull()) | |
3889 | { | |
23fe70ec | 3890 | Message::SendFail ("Error: no active viewer"); |
56689b27 | 3891 | return 1; |
3892 | } | |
3893 | ||
3894 | Standard_Boolean isImmediateUpdate = Standard_False; | |
3895 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
3896 | { | |
3897 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
3898 | anArg.LowerCase(); | |
8693dfd0 | 3899 | if (anArg == "-immediate" |
3900 | || anArg == "-imm") | |
56689b27 | 3901 | { |
3902 | isImmediateUpdate = Standard_True; | |
3903 | if (anArgIter + 1 < theArgNb | |
3904 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate)) | |
3905 | { | |
3906 | ++anArgIter; | |
3907 | } | |
3908 | } | |
8693dfd0 | 3909 | else if (anArg == "-continuous" |
3910 | || anArg == "-cont" | |
3911 | || anArg == "-fps" | |
3912 | || anArg == "-framerate") | |
3913 | { | |
3914 | Standard_Real aFps = -1.0; | |
3915 | if (anArgIter + 1 < theArgNb | |
3916 | && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue()) | |
3917 | { | |
3918 | aFps = Draw::Atof (theArgVec[++anArgIter]); | |
3919 | } | |
3920 | ||
3921 | ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance(); | |
3922 | if (Abs (aFps) >= 1.0) | |
3923 | { | |
3924 | aRedrawer.Start (aView->Window(), aFps); | |
3925 | } | |
3926 | else | |
3927 | { | |
3928 | aRedrawer.Stop(); | |
3929 | } | |
3930 | } | |
56689b27 | 3931 | else |
3932 | { | |
23fe70ec | 3933 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
8693dfd0 | 3934 | return 1; |
56689b27 | 3935 | } |
3936 | } | |
3937 | ||
3938 | if (isImmediateUpdate) | |
3939 | { | |
3940 | aView->RedrawImmediate(); | |
3941 | } | |
3942 | else | |
3943 | { | |
3944 | aView->Redraw(); | |
3945 | } | |
3946 | return 0; | |
7fd59977 | 3947 | } |
3948 | ||
7fd59977 | 3949 | //============================================================================== |
3950 | //function : VClear | |
3951 | //purpose : Remove all the object from the viewer | |
3952 | //Draw arg : No args | |
3953 | //============================================================================== | |
3954 | ||
3955 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) | |
3956 | { | |
3957 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
3958 | if(!V.IsNull()) | |
3959 | ViewerTest::Clear(); | |
3960 | return 0; | |
3961 | } | |
3962 | ||
3963 | //============================================================================== | |
3964 | //function : VPick | |
3965 | //purpose : | |
3966 | //============================================================================== | |
3967 | ||
49582f9d | 3968 | static int VPick (Draw_Interpretor& , |
3969 | Standard_Integer theNbArgs, | |
3970 | const char** theArgVec) | |
3971 | { | |
3972 | if (ViewerTest::CurrentView().IsNull()) | |
3973 | { | |
3974 | return 1; | |
3975 | } | |
7fd59977 | 3976 | |
49582f9d | 3977 | if (theNbArgs < 4) |
3978 | { | |
23fe70ec | 3979 | Message::SendFail ("Syntax error: wrong number of arguments"); |
49582f9d | 3980 | return 1; |
3981 | } | |
7fd59977 | 3982 | |
49582f9d | 3983 | while (ViewerMainLoop (theNbArgs, theArgVec)) |
3984 | { | |
3985 | // | |
3986 | } | |
7fd59977 | 3987 | |
49582f9d | 3988 | return 0; |
7fd59977 | 3989 | } |
3990 | ||
293211ae | 3991 | namespace |
7fd59977 | 3992 | { |
7fd59977 | 3993 | |
293211ae | 3994 | //! Changes the background |
3995 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
3996 | //! @param theNumberOfCommandLineArguments the number of passed command line arguments | |
3997 | //! @param theCommandLineArguments the array of command line arguments | |
3998 | //! @return TCL_OK if changing was successful, or TCL_ERROR otherwise | |
3999 | static int vbackground (Draw_Interpretor& theDrawInterpretor, | |
4000 | const Standard_Integer theNumberOfCommandLineArguments, | |
4001 | const char** const theCommandLineArguments) | |
7fd59977 | 4002 | { |
293211ae | 4003 | if (theNumberOfCommandLineArguments < 1) |
7fd59977 | 4004 | { |
293211ae | 4005 | return TCL_ERROR; |
7fd59977 | 4006 | } |
293211ae | 4007 | BackgroundChanger aBackgroundChanger; |
4008 | if (!aBackgroundChanger.ProcessCommandLine (theDrawInterpretor, | |
4009 | theNumberOfCommandLineArguments, | |
4010 | theCommandLineArguments)) | |
f8b2ed36 | 4011 | { |
293211ae | 4012 | theDrawInterpretor << "Wrong command arguments.\n" |
4013 | "Type 'help " | |
4014 | << theCommandLineArguments[0] << "' for information about command options and its arguments.\n"; | |
4015 | return TCL_ERROR; | |
f8b2ed36 | 4016 | } |
293211ae | 4017 | return TCL_OK; |
f8b2ed36 | 4018 | } |
4019 | ||
293211ae | 4020 | } // namespace |
f42753ed | 4021 | |
7fd59977 | 4022 | //============================================================================== |
4023 | //function : VScale | |
4024 | //purpose : View Scaling | |
4025 | //============================================================================== | |
4026 | ||
4027 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
4028 | { | |
4029 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
4030 | if ( V3dView.IsNull() ) return 1; | |
4031 | ||
4032 | if ( argc != 4 ) { | |
586db386 | 4033 | di << argv[0] << "Invalid number of arguments\n"; |
7fd59977 | 4034 | return 1; |
4035 | } | |
91322f44 | 4036 | V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 4037 | return 0; |
4038 | } | |
4039 | //============================================================================== | |
536d98e2 | 4040 | //function : VZBuffTrihedron |
4041 | //purpose : | |
7fd59977 | 4042 | //============================================================================== |
4043 | ||
536d98e2 | 4044 | static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/, |
4045 | Standard_Integer theArgNb, | |
4046 | const char** theArgVec) | |
7fd59977 | 4047 | { |
536d98e2 | 4048 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
4049 | if (aView.IsNull()) | |
4050 | { | |
23fe70ec | 4051 | Message::SendFail ("Error: no active viewer"); |
536d98e2 | 4052 | return 1; |
4053 | } | |
7fd59977 | 4054 | |
536d98e2 | 4055 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
7c8a8fcc | 4056 | |
536d98e2 | 4057 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; |
4058 | V3d_TypeOfVisualization aVisType = V3d_ZBUFFER; | |
4059 | Quantity_Color aLabelsColor = Quantity_NOC_WHITE; | |
4060 | Quantity_Color anArrowColorX = Quantity_NOC_RED; | |
4061 | Quantity_Color anArrowColorY = Quantity_NOC_GREEN; | |
4062 | Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1; | |
4063 | Standard_Real aScale = 0.1; | |
4064 | Standard_Real aSizeRatio = 0.8; | |
4065 | Standard_Real anArrowDiam = 0.05; | |
4066 | Standard_Integer aNbFacets = 12; | |
4067 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
7c8a8fcc | 4068 | { |
536d98e2 | 4069 | Standard_CString anArg = theArgVec[anArgIter]; |
4070 | TCollection_AsciiString aFlag (anArg); | |
4071 | aFlag.LowerCase(); | |
4072 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
7c8a8fcc | 4073 | { |
536d98e2 | 4074 | continue; |
4075 | } | |
4076 | else if (aFlag == "-on") | |
7c8a8fcc | 4077 | { |
536d98e2 | 4078 | continue; |
4079 | } | |
4080 | else if (aFlag == "-off") | |
7c8a8fcc | 4081 | { |
536d98e2 | 4082 | aView->TriedronErase(); |
4083 | return 0; | |
4084 | } | |
4085 | else if (aFlag == "-pos" | |
4086 | || aFlag == "-position" | |
4087 | || aFlag == "-corner") | |
7c8a8fcc | 4088 | { |
536d98e2 | 4089 | if (++anArgIter >= theArgNb) |
4090 | { | |
23fe70ec | 4091 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
536d98e2 | 4092 | return 1; |
4093 | } | |
4094 | ||
4095 | TCollection_AsciiString aPosName (theArgVec[anArgIter]); | |
4096 | aPosName.LowerCase(); | |
4097 | if (aPosName == "center") | |
4098 | { | |
4099 | aPosition = Aspect_TOTP_CENTER; | |
4100 | } | |
4101 | else if (aPosName == "left_lower" | |
4102 | || aPosName == "lower_left" | |
4103 | || aPosName == "leftlower" | |
4104 | || aPosName == "lowerleft") | |
4105 | { | |
4106 | aPosition = Aspect_TOTP_LEFT_LOWER; | |
4107 | } | |
4108 | else if (aPosName == "left_upper" | |
4109 | || aPosName == "upper_left" | |
4110 | || aPosName == "leftupper" | |
4111 | || aPosName == "upperleft") | |
4112 | { | |
4113 | aPosition = Aspect_TOTP_LEFT_UPPER; | |
4114 | } | |
4115 | else if (aPosName == "right_lower" | |
4116 | || aPosName == "lower_right" | |
4117 | || aPosName == "rightlower" | |
4118 | || aPosName == "lowerright") | |
4119 | { | |
4120 | aPosition = Aspect_TOTP_RIGHT_LOWER; | |
4121 | } | |
4122 | else if (aPosName == "right_upper" | |
4123 | || aPosName == "upper_right" | |
4124 | || aPosName == "rightupper" | |
4125 | || aPosName == "upperright") | |
4126 | { | |
4127 | aPosition = Aspect_TOTP_RIGHT_UPPER; | |
4128 | } | |
4129 | else | |
4130 | { | |
23fe70ec | 4131 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'"; |
536d98e2 | 4132 | return 1; |
4133 | } | |
4134 | } | |
4135 | else if (aFlag == "-type") | |
7c8a8fcc | 4136 | { |
536d98e2 | 4137 | if (++anArgIter >= theArgNb) |
4138 | { | |
23fe70ec | 4139 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
536d98e2 | 4140 | return 1; |
4141 | } | |
4142 | ||
4143 | TCollection_AsciiString aTypeName (theArgVec[anArgIter]); | |
4144 | aTypeName.LowerCase(); | |
4145 | if (aTypeName == "wireframe" | |
4146 | || aTypeName == "wire") | |
4147 | { | |
4148 | aVisType = V3d_WIREFRAME; | |
4149 | } | |
4150 | else if (aTypeName == "zbuffer" | |
4151 | || aTypeName == "shaded") | |
4152 | { | |
4153 | aVisType = V3d_ZBUFFER; | |
4154 | } | |
4155 | else | |
4156 | { | |
23fe70ec | 4157 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'"; |
536d98e2 | 4158 | } |
4159 | } | |
4160 | else if (aFlag == "-scale") | |
7c8a8fcc | 4161 | { |
536d98e2 | 4162 | if (++anArgIter >= theArgNb) |
4163 | { | |
23fe70ec | 4164 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
536d98e2 | 4165 | return 1; |
4166 | } | |
4167 | ||
4168 | aScale = Draw::Atof (theArgVec[anArgIter]); | |
7c8a8fcc | 4169 | } |
536d98e2 | 4170 | else if (aFlag == "-size" |
4171 | || aFlag == "-sizeratio") | |
4172 | { | |
4173 | if (++anArgIter >= theArgNb) | |
4174 | { | |
23fe70ec | 4175 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
536d98e2 | 4176 | return 1; |
4177 | } | |
7c8a8fcc | 4178 | |
536d98e2 | 4179 | aSizeRatio = Draw::Atof (theArgVec[anArgIter]); |
4180 | } | |
4181 | else if (aFlag == "-arrowdiam" | |
4182 | || aFlag == "-arrowdiameter") | |
4183 | { | |
4184 | if (++anArgIter >= theArgNb) | |
4185 | { | |
23fe70ec | 4186 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
536d98e2 | 4187 | return 1; |
4188 | } | |
7c8a8fcc | 4189 | |
536d98e2 | 4190 | anArrowDiam = Draw::Atof (theArgVec[anArgIter]); |
4191 | } | |
4192 | else if (aFlag == "-nbfacets") | |
4193 | { | |
4194 | if (++anArgIter >= theArgNb) | |
4195 | { | |
23fe70ec | 4196 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
536d98e2 | 4197 | return 1; |
4198 | } | |
7c8a8fcc | 4199 | |
536d98e2 | 4200 | aNbFacets = Draw::Atoi (theArgVec[anArgIter]); |
4201 | } | |
4202 | else if (aFlag == "-colorlabel" | |
4203 | || aFlag == "-colorlabels") | |
7c8a8fcc | 4204 | { |
536d98e2 | 4205 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
4206 | theArgVec + anArgIter + 1, | |
4207 | aLabelsColor); | |
4208 | if (aNbParsed == 0) | |
4209 | { | |
23fe70ec | 4210 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
536d98e2 | 4211 | return 1; |
4212 | } | |
4213 | anArgIter += aNbParsed; | |
7c8a8fcc | 4214 | } |
536d98e2 | 4215 | else if (aFlag == "-colorarrowx") |
7c8a8fcc | 4216 | { |
536d98e2 | 4217 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
4218 | theArgVec + anArgIter + 1, | |
4219 | anArrowColorX); | |
4220 | if (aNbParsed == 0) | |
4221 | { | |
23fe70ec | 4222 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
536d98e2 | 4223 | return 1; |
4224 | } | |
4225 | anArgIter += aNbParsed; | |
4226 | } | |
4227 | else if (aFlag == "-colorarrowy") | |
7c8a8fcc | 4228 | { |
536d98e2 | 4229 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
4230 | theArgVec + anArgIter + 1, | |
4231 | anArrowColorY); | |
4232 | if (aNbParsed == 0) | |
4233 | { | |
23fe70ec | 4234 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
536d98e2 | 4235 | return 1; |
4236 | } | |
4237 | anArgIter += aNbParsed; | |
4238 | } | |
4239 | else if (aFlag == "-colorarrowz") | |
7c8a8fcc | 4240 | { |
536d98e2 | 4241 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
4242 | theArgVec + anArgIter + 1, | |
4243 | anArrowColorZ); | |
4244 | if (aNbParsed == 0) | |
4245 | { | |
23fe70ec | 4246 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
536d98e2 | 4247 | return 1; |
4248 | } | |
4249 | anArgIter += aNbParsed; | |
4250 | } | |
4251 | else | |
4252 | { | |
23fe70ec | 4253 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
7c8a8fcc | 4254 | return 1; |
4255 | } | |
7c8a8fcc | 4256 | } |
4257 | ||
536d98e2 | 4258 | aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(), |
4259 | aSizeRatio, anArrowDiam, aNbFacets); | |
4260 | aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType); | |
c357e426 | 4261 | aView->ZFitAll(); |
7fd59977 | 4262 | return 0; |
4263 | } | |
4264 | ||
4265 | //============================================================================== | |
4266 | //function : VRotate | |
4267 | //purpose : Camera Rotating | |
4268 | //============================================================================== | |
4269 | ||
4af098ba | 4270 | static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec) |
4271 | { | |
4272 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4273 | if (aView.IsNull()) | |
4274 | { | |
23fe70ec | 4275 | Message::SendFail ("Error: no active viewer"); |
7fd59977 | 4276 | return 1; |
4277 | } | |
4278 | ||
4af098ba | 4279 | Standard_Boolean hasFlags = Standard_False; |
4280 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
4281 | { | |
4282 | Standard_CString anArg (theArgVec[anArgIter]); | |
4283 | TCollection_AsciiString aFlag (anArg); | |
4284 | aFlag.LowerCase(); | |
4285 | if (aFlag == "-mousestart" | |
4286 | || aFlag == "-mousefrom") | |
4287 | { | |
4288 | hasFlags = Standard_True; | |
4289 | if (anArgIter + 2 >= theArgNb) | |
4290 | { | |
23fe70ec | 4291 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
4af098ba | 4292 | return 1; |
4293 | } | |
4294 | ||
4295 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
4296 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
4297 | aView->StartRotation (anX, anY); | |
4298 | } | |
4299 | else if (aFlag == "-mousemove") | |
4300 | { | |
4301 | hasFlags = Standard_True; | |
4302 | if (anArgIter + 2 >= theArgNb) | |
4303 | { | |
23fe70ec | 4304 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
4af098ba | 4305 | return 1; |
4306 | } | |
4307 | ||
4308 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
4309 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
4310 | aView->Rotation (anX, anY); | |
4311 | } | |
4312 | else if (theArgNb != 4 | |
4313 | && theArgNb != 7) | |
4314 | { | |
23fe70ec | 4315 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
4af098ba | 4316 | return 1; |
4317 | } | |
4318 | } | |
4319 | ||
4320 | if (hasFlags) | |
4321 | { | |
7fd59977 | 4322 | return 0; |
4af098ba | 4323 | } |
4324 | else if (theArgNb == 4) | |
4325 | { | |
4326 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
4327 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
4328 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
4329 | aView->Rotate (anAX, anAY, anAZ); | |
4330 | return 0; | |
4331 | } | |
4332 | else if (theArgNb == 7) | |
4333 | { | |
4334 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
4335 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
4336 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
4337 | ||
4338 | Standard_Real anX = Draw::Atof (theArgVec[4]); | |
4339 | Standard_Real anY = Draw::Atof (theArgVec[5]); | |
4340 | Standard_Real anZ = Draw::Atof (theArgVec[6]); | |
4341 | ||
4342 | aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ); | |
7fd59977 | 4343 | return 0; |
7fd59977 | 4344 | } |
4af098ba | 4345 | |
23fe70ec | 4346 | Message::SendFail ("Error: Invalid number of arguments"); |
4af098ba | 4347 | return 1; |
7fd59977 | 4348 | } |
4349 | ||
4350 | //============================================================================== | |
4351 | //function : VZoom | |
4352 | //purpose : View zoom in / out (relative to current zoom) | |
4353 | //============================================================================== | |
4354 | ||
4355 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
4356 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
4357 | if ( V3dView.IsNull() ) { | |
4358 | return 1; | |
4359 | } | |
4360 | ||
4361 | if ( argc == 2 ) { | |
91322f44 | 4362 | Standard_Real coef = Draw::Atof(argv[1]); |
7fd59977 | 4363 | if ( coef <= 0.0 ) { |
586db386 | 4364 | di << argv[1] << "Invalid value\n"; |
7fd59977 | 4365 | return 1; |
4366 | } | |
91322f44 | 4367 | V3dView->SetZoom( Draw::Atof(argv[1]) ); |
7fd59977 | 4368 | return 0; |
4369 | } else { | |
586db386 | 4370 | di << argv[0] << " Invalid number of arguments\n"; |
7fd59977 | 4371 | return 1; |
4372 | } | |
4373 | } | |
4374 | ||
4375 | //============================================================================== | |
4376 | //function : VPan | |
4377 | //purpose : View panning (in pixels) | |
4378 | //============================================================================== | |
4379 | ||
4380 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
4381 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
4382 | if ( V3dView.IsNull() ) return 1; | |
4383 | ||
4384 | if ( argc == 3 ) { | |
91322f44 | 4385 | V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) ); |
7fd59977 | 4386 | return 0; |
4387 | } else { | |
586db386 | 4388 | di << argv[0] << " Invalid number of arguments\n"; |
7fd59977 | 4389 | return 1; |
4390 | } | |
4391 | } | |
4392 | ||
49e1a5c7 | 4393 | //============================================================================== |
4394 | //function : VPlace | |
4395 | //purpose : Place the point (in pixels) at the center of the window | |
4396 | //============================================================================== | |
4397 | static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs) | |
4398 | { | |
4399 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4400 | if (aView.IsNull()) | |
4401 | { | |
23fe70ec | 4402 | Message::SendFail ("Error: no active viewer"); |
49e1a5c7 | 4403 | return 1; |
4404 | } | |
4405 | ||
4406 | if (theArgNb != 3) | |
4407 | { | |
23fe70ec | 4408 | Message::SendFail ("Syntax error: wrong number of arguments"); |
49e1a5c7 | 4409 | return 1; |
4410 | } | |
4411 | ||
4412 | aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale()); | |
4413 | ||
4414 | return 0; | |
4415 | } | |
7fd59977 | 4416 | |
71215351 | 4417 | static int VColorScale (Draw_Interpretor& theDI, |
4418 | Standard_Integer theArgNb, | |
4419 | const char** theArgVec) | |
4420 | { | |
7fd59977 | 4421 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
71215351 | 4422 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
4423 | if (aContext.IsNull()) | |
4424 | { | |
23fe70ec | 4425 | Message::SendFail ("Error: no active viewer"); |
71215351 | 4426 | return 1; |
7fd59977 | 4427 | } |
24a88697 | 4428 | if (theArgNb <= 1) |
4429 | { | |
23fe70ec | 4430 | Message::SendFail() << "Error: wrong syntax at command '" << theArgVec[0] << "'"; |
24a88697 | 4431 | return 1; |
4432 | } | |
7fd59977 | 4433 | |
4b3d6eb1 | 4434 | Handle(AIS_ColorScale) aColorScale; |
7a324550 | 4435 | if (GetMapOfAIS().IsBound2 (theArgVec[1])) |
71215351 | 4436 | { |
4b3d6eb1 | 4437 | // find existing object |
4438 | aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1])); | |
4439 | if (aColorScale.IsNull()) | |
7a324550 | 4440 | { |
23fe70ec | 4441 | Message::SendFail() << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale"; |
7a324550 | 4442 | return 1; |
4443 | } | |
4444 | } | |
71215351 | 4445 | |
7a324550 | 4446 | if (theArgNb <= 2) |
4447 | { | |
4b3d6eb1 | 4448 | if (aColorScale.IsNull()) |
4449 | { | |
23fe70ec | 4450 | Message::SendFail() << "Syntax error: colorscale with a given name does not exist"; |
4b3d6eb1 | 4451 | return 1; |
4452 | } | |
4453 | ||
7a324550 | 4454 | theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n" |
4b3d6eb1 | 4455 | << "Min range: " << aColorScale->GetMin() << "\n" |
4456 | << "Max range: " << aColorScale->GetMax() << "\n" | |
4457 | << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n" | |
4458 | << "Text height: " << aColorScale->GetTextHeight() << "\n" | |
4459 | << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n" | |
4460 | << "Color scale title: " << aColorScale->GetTitle() << "\n" | |
71215351 | 4461 | << "Label position: "; |
4b3d6eb1 | 4462 | switch (aColorScale->GetLabelPosition()) |
71215351 | 4463 | { |
4464 | case Aspect_TOCSP_NONE: | |
4465 | theDI << "None\n"; | |
4466 | break; | |
4467 | case Aspect_TOCSP_LEFT: | |
4468 | theDI << "Left\n"; | |
4469 | break; | |
4470 | case Aspect_TOCSP_RIGHT: | |
4471 | theDI << "Right\n"; | |
4472 | break; | |
4473 | case Aspect_TOCSP_CENTER: | |
4474 | theDI << "Center\n"; | |
4475 | break; | |
4476 | } | |
4477 | return 0; | |
4478 | } | |
71215351 | 4479 | |
4b3d6eb1 | 4480 | if (aColorScale.IsNull()) |
4481 | { | |
4482 | aColorScale = new AIS_ColorScale(); | |
4483 | aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD); | |
4484 | aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); | |
4485 | } | |
4486 | ||
4487 | ViewerTest_AutoUpdater anUpdateTool (aContext, aView); | |
7a324550 | 4488 | for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter) |
71215351 | 4489 | { |
4490 | Standard_CString anArg = theArgVec[anArgIter]; | |
4491 | TCollection_AsciiString aFlag (anArg); | |
4492 | aFlag.LowerCase(); | |
4493 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
4494 | { | |
4495 | continue; | |
4496 | } | |
4497 | else if (aFlag == "-range") | |
4498 | { | |
4499 | if (anArgIter + 3 >= theArgNb) | |
4500 | { | |
23fe70ec | 4501 | Message::SendFail() << "Error: wrong syntax at argument '" << anArg << "'"; |
71215351 | 4502 | return 1; |
4503 | } | |
4504 | ||
4b3d6eb1 | 4505 | const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]); |
4506 | const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]); | |
4507 | const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]); | |
4508 | if (!aRangeMin.IsRealValue() | |
4509 | || !aRangeMax.IsRealValue()) | |
71215351 | 4510 | { |
23fe70ec | 4511 | Message::SendFail ("Syntax error: the range values should be real"); |
71215351 | 4512 | return 1; |
4513 | } | |
4b3d6eb1 | 4514 | else if (!aNbIntervals.IsIntegerValue()) |
71215351 | 4515 | { |
23fe70ec | 4516 | Message::SendFail ("Syntax error: the number of intervals should be integer"); |
71215351 | 4517 | return 1; |
4518 | } | |
4519 | ||
4b3d6eb1 | 4520 | aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue()); |
4521 | aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue()); | |
71215351 | 4522 | } |
4523 | else if (aFlag == "-font") | |
4524 | { | |
4525 | if (anArgIter + 1 >= theArgNb) | |
4526 | { | |
23fe70ec | 4527 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
71215351 | 4528 | return 1; |
4529 | } | |
51740958 | 4530 | TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]); |
4531 | if (!aFontArg.IsIntegerValue()) | |
71215351 | 4532 | { |
23fe70ec | 4533 | Message::SendFail ("Syntax error: HeightFont value should be integer"); |
71215351 | 4534 | return 1; |
4535 | } | |
4536 | ||
4b3d6eb1 | 4537 | aColorScale->SetTextHeight (aFontArg.IntegerValue()); |
71215351 | 4538 | anArgIter += 1; |
4539 | } | |
4540 | else if (aFlag == "-textpos") | |
4541 | { | |
4542 | if (anArgIter + 1 >= theArgNb) | |
4543 | { | |
23fe70ec | 4544 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
71215351 | 4545 | return 1; |
4546 | } | |
4b3d6eb1 | 4547 | |
51740958 | 4548 | TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]); |
4549 | aTextPosArg.LowerCase(); | |
4b3d6eb1 | 4550 | Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE; |
51740958 | 4551 | if (aTextPosArg == "none") |
71215351 | 4552 | { |
4553 | aLabPosition = Aspect_TOCSP_NONE; | |
4554 | } | |
51740958 | 4555 | else if (aTextPosArg == "left") |
71215351 | 4556 | { |
4557 | aLabPosition = Aspect_TOCSP_LEFT; | |
4558 | } | |
51740958 | 4559 | else if (aTextPosArg == "right") |
71215351 | 4560 | { |
4561 | aLabPosition = Aspect_TOCSP_RIGHT; | |
4562 | } | |
51740958 | 4563 | else if (aTextPosArg == "center") |
71215351 | 4564 | { |
4565 | aLabPosition = Aspect_TOCSP_CENTER; | |
4566 | } | |
4567 | else | |
4568 | { | |
23fe70ec | 4569 | Message::SendFail() << "Syntax error: unknown position '" << aTextPosArg << "'"; |
71215351 | 4570 | return 1; |
4571 | } | |
4b3d6eb1 | 4572 | aColorScale->SetLabelPosition (aLabPosition); |
71215351 | 4573 | } |
24a88697 | 4574 | else if (aFlag == "-logarithmic" |
4575 | || aFlag == "-log") | |
4576 | { | |
4577 | if (anArgIter + 1 >= theArgNb) | |
4578 | { | |
23fe70ec | 4579 | Message::SendFail() << "Synta error at argument '" << anArg << "'"; |
24a88697 | 4580 | return 1; |
4581 | } | |
4b3d6eb1 | 4582 | |
24a88697 | 4583 | Standard_Boolean IsLog; |
4584 | if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog)) | |
4585 | { | |
23fe70ec | 4586 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
24a88697 | 4587 | return 1; |
4588 | } | |
4b3d6eb1 | 4589 | aColorScale->SetLogarithmic (IsLog); |
4590 | } | |
4591 | else if (aFlag == "-huerange" | |
4592 | || aFlag == "-hue") | |
4593 | { | |
4594 | if (anArgIter + 2 >= theArgNb) | |
4595 | { | |
23fe70ec | 4596 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
4b3d6eb1 | 4597 | return 1; |
4598 | } | |
4599 | ||
4600 | const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]); | |
4601 | const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]); | |
4602 | aColorScale->SetHueRange (aHueMin, aHueMax); | |
4603 | } | |
4604 | else if (aFlag == "-colorrange") | |
4605 | { | |
4606 | Quantity_Color aColorMin, aColorMax; | |
4607 | Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
4608 | theArgVec + (anArgIter + 1), | |
4609 | aColorMin); | |
4610 | anArgIter += aNbParsed1; | |
4611 | Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
4612 | theArgVec + (anArgIter + 1), | |
4613 | aColorMax); | |
4614 | anArgIter += aNbParsed2; | |
4615 | if (aNbParsed1 == 0 | |
4616 | || aNbParsed2 == 0) | |
4617 | { | |
23fe70ec | 4618 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
4b3d6eb1 | 4619 | return 1; |
4620 | } | |
4621 | ||
4622 | aColorScale->SetColorRange (aColorMin, aColorMax); | |
4623 | } | |
4624 | else if (aFlag == "-reversed" | |
4625 | || aFlag == "-inverted" | |
4626 | || aFlag == "-topdown" | |
4627 | || aFlag == "-bottomup") | |
4628 | { | |
4629 | Standard_Boolean toEnable = Standard_True; | |
4630 | if (anArgIter + 1 < theArgNb | |
4631 | && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable)) | |
4632 | { | |
4633 | ++anArgIter; | |
4634 | } | |
4635 | aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable); | |
4636 | } | |
4637 | else if (aFlag == "-smooth" | |
4638 | || aFlag == "-smoothtransition") | |
4639 | { | |
4640 | Standard_Boolean toEnable = Standard_True; | |
4641 | if (anArgIter + 1 < theArgNb | |
4642 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
4643 | { | |
4644 | ++anArgIter; | |
4645 | } | |
4646 | aColorScale->SetSmoothTransition (toEnable); | |
24a88697 | 4647 | } |
71215351 | 4648 | else if (aFlag == "-xy") |
4649 | { | |
4650 | if (anArgIter + 2 >= theArgNb) | |
4651 | { | |
23fe70ec | 4652 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
71215351 | 4653 | return 1; |
4654 | } | |
4655 | ||
4b3d6eb1 | 4656 | const TCollection_AsciiString anX (theArgVec[++anArgIter]); |
4657 | const TCollection_AsciiString anY (theArgVec[++anArgIter]); | |
4658 | if (!anX.IsIntegerValue() | |
4659 | || !anY.IsIntegerValue()) | |
71215351 | 4660 | { |
23fe70ec | 4661 | Message::SendFail ("Syntax error: coordinates should be integer values"); |
71215351 | 4662 | return 1; |
4663 | } | |
4664 | ||
4b3d6eb1 | 4665 | aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue()); |
b4b2ecca | 4666 | } |
4667 | else if (aFlag == "-width" | |
4b3d6eb1 | 4668 | || aFlag == "-w" |
4669 | || aFlag == "-breadth") | |
b4b2ecca | 4670 | { |
4671 | if (anArgIter + 1 >= theArgNb) | |
4672 | { | |
23fe70ec | 4673 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
b4b2ecca | 4674 | return 1; |
4675 | } | |
4676 | ||
4b3d6eb1 | 4677 | const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]); |
4678 | if (!aBreadth.IsIntegerValue()) | |
b4b2ecca | 4679 | { |
23fe70ec | 4680 | Message::SendFail ("Syntax error: a width should be an integer value"); |
b4b2ecca | 4681 | return 1; |
4682 | } | |
4b3d6eb1 | 4683 | aColorScale->SetBreadth (aBreadth.IntegerValue()); |
b4b2ecca | 4684 | } |
4685 | else if (aFlag == "-height" | |
4686 | || aFlag == "-h") | |
4687 | { | |
4688 | if (anArgIter + 1 >= theArgNb) | |
4689 | { | |
23fe70ec | 4690 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
b4b2ecca | 4691 | return 1; |
4692 | } | |
4693 | ||
4b3d6eb1 | 4694 | const TCollection_AsciiString aHeight (theArgVec[++anArgIter]); |
4695 | if (!aHeight.IsIntegerValue()) | |
b4b2ecca | 4696 | { |
23fe70ec | 4697 | Message::SendFail ("Syntax error: a width should be an integer value"); |
b4b2ecca | 4698 | return 1; |
4699 | } | |
4b3d6eb1 | 4700 | aColorScale->SetHeight (aHeight.IntegerValue()); |
71215351 | 4701 | } |
4702 | else if (aFlag == "-color") | |
4703 | { | |
4b3d6eb1 | 4704 | if (aColorScale->GetColorType() != Aspect_TOCSD_USER) |
71215351 | 4705 | { |
23fe70ec | 4706 | Message::SendFail ("Syntax error: wrong color type. Call -colors before to set user-specified colors"); |
71215351 | 4707 | return 1; |
4708 | } | |
4b3d6eb1 | 4709 | else if (anArgIter + 2 >= theArgNb) |
71215351 | 4710 | { |
23fe70ec | 4711 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
4b3d6eb1 | 4712 | return 1; |
71215351 | 4713 | } |
4714 | ||
4b3d6eb1 | 4715 | const TCollection_AsciiString anInd (theArgVec[++anArgIter]); |
71215351 | 4716 | if (!anInd.IsIntegerValue()) |
4717 | { | |
23fe70ec | 4718 | Message::SendFail ("Syntax error: Index value should be integer"); |
71215351 | 4719 | return 1; |
4720 | } | |
4b3d6eb1 | 4721 | const Standard_Integer anIndex = anInd.IntegerValue(); |
4722 | if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals()) | |
71215351 | 4723 | { |
23fe70ec | 4724 | Message::SendFail() << "Syntax error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals(); |
71215351 | 4725 | return 1; |
4726 | } | |
4727 | ||
4b3d6eb1 | 4728 | Quantity_Color aColor; |
4729 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
4730 | theArgVec + (anArgIter + 1), | |
4731 | aColor); | |
4732 | if (aNbParsed == 0) | |
71215351 | 4733 | { |
23fe70ec | 4734 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
71215351 | 4735 | return 1; |
4736 | } | |
4b3d6eb1 | 4737 | aColorScale->SetIntervalColor (aColor, anIndex); |
4738 | aColorScale->SetColorType (Aspect_TOCSD_USER); | |
4739 | anArgIter += aNbParsed; | |
71215351 | 4740 | } |
4741 | else if (aFlag == "-label") | |
4742 | { | |
4b3d6eb1 | 4743 | if (aColorScale->GetColorType() != Aspect_TOCSD_USER) |
71215351 | 4744 | { |
23fe70ec | 4745 | Message::SendFail ("Syntax error: wrong label type. Call -labels before to set user-specified labels"); |
71215351 | 4746 | return 1; |
4747 | } | |
4748 | else if (anArgIter + 2 >= theArgNb) | |
4749 | { | |
23fe70ec | 4750 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
71215351 | 4751 | return 1; |
4752 | } | |
4753 | ||
4754 | Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]); | |
4b3d6eb1 | 4755 | if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1) |
71215351 | 4756 | { |
23fe70ec | 4757 | Message::SendFail() << "Syntax error: Index value should be within range 1.." << (aColorScale->GetNumberOfIntervals() + 1); |
71215351 | 4758 | return 1; |
4759 | } | |
4760 | ||
4761 | TCollection_ExtendedString aText (theArgVec[anArgIter + 2]); | |
4b3d6eb1 | 4762 | aColorScale->SetLabel (aText, anIndex); |
4763 | aColorScale->SetLabelType (Aspect_TOCSD_USER); | |
71215351 | 4764 | anArgIter += 2; |
4765 | } | |
4b3d6eb1 | 4766 | else if (aFlag == "-labelat" |
4767 | || aFlag == "-labat" | |
4768 | || aFlag == "-labelatborder" | |
4769 | || aFlag == "-labatborder" | |
4770 | || aFlag == "-labelatcenter" | |
4771 | || aFlag == "-labatcenter") | |
71215351 | 4772 | { |
4b3d6eb1 | 4773 | Standard_Boolean toEnable = Standard_True; |
4774 | if (aFlag == "-labelat" | |
4775 | || aFlag == "-labat") | |
71215351 | 4776 | { |
4b3d6eb1 | 4777 | Standard_Integer aLabAtBorder = -1; |
4778 | if (++anArgIter >= theArgNb) | |
71215351 | 4779 | { |
4b3d6eb1 | 4780 | TCollection_AsciiString anAtBorder (theArgVec[anArgIter]); |
4781 | anAtBorder.LowerCase(); | |
4782 | if (anAtBorder == "border") | |
71215351 | 4783 | { |
4b3d6eb1 | 4784 | aLabAtBorder = 1; |
71215351 | 4785 | } |
4b3d6eb1 | 4786 | else if (anAtBorder == "center") |
71215351 | 4787 | { |
4b3d6eb1 | 4788 | aLabAtBorder = 0; |
71215351 | 4789 | } |
71215351 | 4790 | } |
4b3d6eb1 | 4791 | if (aLabAtBorder == -1) |
4792 | { | |
23fe70ec | 4793 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
4b3d6eb1 | 4794 | return 1; |
4795 | } | |
4796 | toEnable = (aLabAtBorder == 1); | |
4797 | } | |
4798 | else if (anArgIter + 1 < theArgNb | |
4799 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
4800 | { | |
4801 | ++anArgIter; | |
71215351 | 4802 | } |
4b3d6eb1 | 4803 | aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter" |
4804 | || aFlag == "-labatcenter" | |
4805 | ? !toEnable | |
4806 | : toEnable); | |
4807 | } | |
4808 | else if (aFlag == "-colors") | |
4809 | { | |
4810 | Aspect_SequenceOfColor aSeq; | |
4811 | for (;;) | |
4812 | { | |
4813 | Quantity_Color aColor; | |
4814 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
4815 | theArgVec + (anArgIter + 1), | |
4816 | aColor); | |
4817 | if (aNbParsed == 0) | |
4818 | { | |
4819 | break; | |
4820 | } | |
4821 | anArgIter += aNbParsed; | |
4822 | aSeq.Append (aColor); | |
4823 | } | |
4824 | if (aSeq.Length() != aColorScale->GetNumberOfIntervals()) | |
71215351 | 4825 | { |
23fe70ec | 4826 | Message::SendFail() << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " |
4827 | << aColorScale->GetNumberOfIntervals() << " intervals"; | |
71215351 | 4828 | return 1; |
4829 | } | |
4830 | ||
4b3d6eb1 | 4831 | aColorScale->SetColors (aSeq); |
4832 | aColorScale->SetColorType (Aspect_TOCSD_USER); | |
71215351 | 4833 | } |
14b741b0 | 4834 | else if (aFlag == "-uniform") |
4835 | { | |
4836 | const Standard_Real aLightness = Draw::Atof (theArgVec[++anArgIter]); | |
4837 | const Standard_Real aHueStart = Draw::Atof (theArgVec[++anArgIter]); | |
4838 | const Standard_Real aHueEnd = Draw::Atof (theArgVec[++anArgIter]); | |
4839 | aColorScale->SetUniformColors (aLightness, aHueStart, aHueEnd); | |
4840 | aColorScale->SetColorType (Aspect_TOCSD_USER); | |
4841 | } | |
4b3d6eb1 | 4842 | else if (aFlag == "-labels" |
4843 | || aFlag == "-freelabels") | |
71215351 | 4844 | { |
4b3d6eb1 | 4845 | if (anArgIter + 1 >= theArgNb) |
4846 | { | |
23fe70ec | 4847 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
4b3d6eb1 | 4848 | return 1; |
4849 | } | |
4850 | ||
4851 | Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder() | |
4852 | ? aColorScale->GetNumberOfIntervals() + 1 | |
4853 | : aColorScale->GetNumberOfIntervals(); | |
4854 | if (aFlag == "-freelabels") | |
4855 | { | |
4856 | ++anArgIter; | |
4857 | aNbLabels = Draw::Atoi (theArgVec[anArgIter]); | |
4858 | } | |
4859 | if (anArgIter + aNbLabels >= theArgNb) | |
71215351 | 4860 | { |
23fe70ec | 4861 | Message::SendFail() << "Syntax error: not enough arguments. " << aNbLabels << " text labels are expected"; |
71215351 | 4862 | return 1; |
4863 | } | |
4864 | ||
4865 | TColStd_SequenceOfExtendedString aSeq; | |
4b3d6eb1 | 4866 | for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter) |
71215351 | 4867 | { |
4b3d6eb1 | 4868 | aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter])); |
71215351 | 4869 | } |
4b3d6eb1 | 4870 | aColorScale->SetLabels (aSeq); |
4871 | aColorScale->SetLabelType (Aspect_TOCSD_USER); | |
71215351 | 4872 | } |
4873 | else if (aFlag == "-title") | |
4874 | { | |
4875 | if (anArgIter + 1 >= theArgNb) | |
4876 | { | |
23fe70ec | 4877 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
71215351 | 4878 | return 1; |
4879 | } | |
4880 | ||
4881 | Standard_Boolean isTwoArgs = Standard_False; | |
4882 | if (anArgIter + 2 < theArgNb) | |
4883 | { | |
4884 | TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]); | |
4885 | aSecondArg.LowerCase(); | |
4b3d6eb1 | 4886 | Standard_DISABLE_DEPRECATION_WARNINGS |
71215351 | 4887 | if (aSecondArg == "none") |
4888 | { | |
4b3d6eb1 | 4889 | aColorScale->SetTitlePosition (Aspect_TOCSP_NONE); |
71215351 | 4890 | isTwoArgs = Standard_True; |
4891 | } | |
4892 | else if (aSecondArg == "left") | |
4893 | { | |
4b3d6eb1 | 4894 | aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT); |
71215351 | 4895 | isTwoArgs = Standard_True; |
4896 | } | |
4897 | else if (aSecondArg == "right") | |
4898 | { | |
4b3d6eb1 | 4899 | aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT); |
71215351 | 4900 | isTwoArgs = Standard_True; |
4901 | } | |
4902 | else if (aSecondArg == "center") | |
4903 | { | |
4b3d6eb1 | 4904 | aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER); |
71215351 | 4905 | isTwoArgs = Standard_True; |
4906 | } | |
4b3d6eb1 | 4907 | Standard_ENABLE_DEPRECATION_WARNINGS |
71215351 | 4908 | } |
4909 | ||
4b3d6eb1 | 4910 | aColorScale->SetTitle (theArgVec[anArgIter + 1]); |
71215351 | 4911 | if (isTwoArgs) |
4912 | { | |
4913 | anArgIter += 1; | |
4914 | } | |
4915 | anArgIter += 1; | |
4916 | } | |
4917 | else if (aFlag == "-demoversion" | |
4918 | || aFlag == "-demo") | |
4919 | { | |
4b3d6eb1 | 4920 | aColorScale->SetPosition (0, 0); |
4921 | aColorScale->SetTextHeight (16); | |
4922 | aColorScale->SetRange (0.0, 100.0); | |
4923 | aColorScale->SetNumberOfIntervals (10); | |
4924 | aColorScale->SetBreadth (0); | |
4925 | aColorScale->SetHeight (0); | |
4926 | aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT); | |
4927 | aColorScale->SetColorType (Aspect_TOCSD_AUTO); | |
4928 | aColorScale->SetLabelType (Aspect_TOCSD_AUTO); | |
71215351 | 4929 | } |
d5514578 | 4930 | else if (aFlag == "-findcolor") |
4931 | { | |
4932 | if (anArgIter + 1 >= theArgNb) | |
4933 | { | |
23fe70ec | 4934 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
d5514578 | 4935 | return 1; |
4936 | } | |
4937 | ||
4938 | TCollection_AsciiString anArg1 (theArgVec[++anArgIter]); | |
4939 | ||
4940 | if (!anArg1.IsRealValue()) | |
4941 | { | |
23fe70ec | 4942 | Message::SendFail ("Syntax error: the value should be real"); |
d5514578 | 4943 | return 1; |
4944 | } | |
4945 | ||
4946 | Quantity_Color aColor; | |
4b3d6eb1 | 4947 | aColorScale->FindColor (anArg1.RealValue(), aColor); |
d5514578 | 4948 | theDI << Quantity_Color::StringName (aColor.Name()); |
4949 | return 0; | |
4950 | } | |
71215351 | 4951 | else |
4952 | { | |
23fe70ec | 4953 | Message::SendFail() << "Syntax error at " << anArg << " - unknown argument"; |
71215351 | 4954 | return 1; |
4955 | } | |
4956 | } | |
4b3d6eb1 | 4957 | |
4958 | Standard_Integer aWinWidth = 0, aWinHeight = 0; | |
4959 | aView->Window()->Size (aWinWidth, aWinHeight); | |
4960 | if (aColorScale->GetBreadth() == 0) | |
b4b2ecca | 4961 | { |
4b3d6eb1 | 4962 | aColorScale->SetBreadth (aWinWidth); |
b4b2ecca | 4963 | } |
4b3d6eb1 | 4964 | if (aColorScale->GetHeight() == 0) |
4965 | { | |
4966 | aColorScale->SetHeight (aWinHeight); | |
4967 | } | |
4968 | aColorScale->SetToUpdate(); | |
4969 | ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True); | |
7fd59977 | 4970 | return 0; |
4971 | } | |
4972 | ||
4973 | //============================================================================== | |
4974 | //function : VGraduatedTrihedron | |
a79f67f8 | 4975 | //purpose : Displays or hides a graduated trihedron |
7fd59977 | 4976 | //============================================================================== |
a79f67f8 | 4977 | static Standard_Boolean GetColor (const TCollection_AsciiString& theValue, |
4978 | Quantity_Color& theColor) | |
13a22457 | 4979 | { |
a79f67f8 | 4980 | Quantity_NameOfColor aColorName; |
4981 | TCollection_AsciiString aVal = theValue; | |
4982 | aVal.UpperCase(); | |
4983 | if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName)) | |
13a22457 | 4984 | { |
a79f67f8 | 4985 | return Standard_False; |
13a22457 | 4986 | } |
a79f67f8 | 4987 | theColor = Quantity_Color (aColorName); |
4988 | return Standard_True; | |
13a22457 S |
4989 | } |
4990 | ||
a79f67f8 | 4991 | static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs) |
7fd59977 | 4992 | { |
a79f67f8 | 4993 | if (theArgNum < 2) |
13a22457 | 4994 | { |
23fe70ec | 4995 | Message::SendFail() << "Syntax error: wrong number of parameters. Type 'help" |
4996 | << theArgs[0] <<"' for more information"; | |
4997 | return 1; | |
13a22457 | 4998 | } |
7fd59977 | 4999 | |
a79f67f8 | 5000 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs; |
5001 | TCollection_AsciiString aParseKey; | |
5002 | for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt) | |
5003 | { | |
5004 | TCollection_AsciiString anArg (theArgs [anArgIt]); | |
5005 | ||
5006 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
5007 | { | |
5008 | aParseKey = anArg; | |
5009 | aParseKey.Remove (1); | |
5010 | aParseKey.LowerCase(); | |
5011 | aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); | |
5012 | continue; | |
5013 | } | |
13a22457 | 5014 | |
a79f67f8 | 5015 | if (aParseKey.IsEmpty()) |
5016 | { | |
5017 | continue; | |
5018 | } | |
5019 | ||
5020 | aMapOfArgs(aParseKey)->Append (anArg); | |
5021 | } | |
5022 | ||
5023 | // Check parameters | |
5024 | for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs); | |
5025 | aMapIt.More(); aMapIt.Next()) | |
7fd59977 | 5026 | { |
a79f67f8 | 5027 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
5028 | const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); | |
5029 | ||
5030 | // Bool key, without arguments | |
5031 | if ((aKey.IsEqual ("on") || aKey.IsEqual ("off")) | |
5032 | && anArgs->IsEmpty()) | |
5033 | { | |
5034 | continue; | |
5035 | } | |
5036 | ||
5037 | // One argument | |
5038 | if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname")) | |
5039 | && anArgs->Length() == 1) | |
5040 | { | |
5041 | continue; | |
5042 | } | |
5043 | ||
5044 | // On/off arguments | |
5045 | if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname") | |
5046 | || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks") | |
536d98e2 | 5047 | || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues") |
5048 | || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes")) | |
a79f67f8 | 5049 | && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off"))) |
5050 | { | |
5051 | continue; | |
5052 | } | |
5053 | ||
5054 | // One string argument | |
5055 | if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor") | |
5056 | || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor")) | |
5057 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
5058 | { | |
5059 | continue; | |
5060 | } | |
5061 | ||
5062 | // One integer argument | |
5063 | if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks") | |
5064 | || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength") | |
5065 | || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset") | |
5066 | || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset")) | |
5067 | && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue()) | |
5068 | { | |
5069 | continue; | |
5070 | } | |
5071 | ||
5072 | // One real argument | |
5073 | if ( aKey.IsEqual ("arrowlength") | |
5074 | && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue())) | |
5075 | { | |
5076 | continue; | |
5077 | } | |
5078 | ||
5079 | // Two string arguments | |
5080 | if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont")) | |
5081 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
13a22457 | 5082 | { |
a79f67f8 | 5083 | continue; |
13a22457 | 5084 | } |
a79f67f8 | 5085 | |
5086 | TCollection_AsciiString aLowerKey; | |
5087 | aLowerKey = "-"; | |
5088 | aLowerKey += aKey; | |
5089 | aLowerKey.LowerCase(); | |
23fe70ec | 5090 | Message::SendFail() << "Syntax error: " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n" |
5091 | << "Type help for more information"; | |
a79f67f8 | 5092 | return 1; |
7fd59977 | 5093 | } |
5094 | ||
a79f67f8 | 5095 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); |
5096 | if (anAISContext.IsNull()) | |
5097 | { | |
23fe70ec | 5098 | Message::SendFail ("Error: no active viewer"); |
a79f67f8 | 5099 | return 1; |
5100 | } | |
7fd59977 | 5101 | |
a79f67f8 | 5102 | Standard_Boolean toDisplay = Standard_True; |
5103 | Quantity_Color aColor; | |
5104 | Graphic3d_GraduatedTrihedron aTrihedronData; | |
5105 | // Process parameters | |
5106 | Handle(TColStd_HSequenceOfAsciiString) aValues; | |
5107 | if (aMapOfArgs.Find ("off", aValues)) | |
7fd59977 | 5108 | { |
a79f67f8 | 5109 | toDisplay = Standard_False; |
5110 | } | |
13a22457 | 5111 | |
a79f67f8 | 5112 | // AXES NAMES |
5113 | if (aMapOfArgs.Find ("xname", aValues)) | |
5114 | { | |
5115 | aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1)); | |
5116 | } | |
5117 | if (aMapOfArgs.Find ("yname", aValues)) | |
5118 | { | |
5119 | aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1)); | |
5120 | } | |
5121 | if (aMapOfArgs.Find ("zname", aValues)) | |
5122 | { | |
5123 | aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1)); | |
5124 | } | |
5125 | if (aMapOfArgs.Find ("xdrawname", aValues)) | |
5126 | { | |
536d98e2 | 5127 | aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5128 | } |
5129 | if (aMapOfArgs.Find ("ydrawname", aValues)) | |
5130 | { | |
536d98e2 | 5131 | aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5132 | } |
5133 | if (aMapOfArgs.Find ("zdrawname", aValues)) | |
5134 | { | |
536d98e2 | 5135 | aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5136 | } |
5137 | if (aMapOfArgs.Find ("xnameoffset", aValues)) | |
5138 | { | |
5139 | aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
5140 | } | |
5141 | if (aMapOfArgs.Find ("ynameoffset", aValues)) | |
5142 | { | |
5143 | aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
5144 | } | |
5145 | if (aMapOfArgs.Find ("znameoffset", aValues)) | |
5146 | { | |
5147 | aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
5148 | } | |
13a22457 | 5149 | |
a79f67f8 | 5150 | // COLORS |
5151 | if (aMapOfArgs.Find ("xnamecolor", aValues)) | |
5152 | { | |
5153 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 5154 | { |
23fe70ec | 5155 | Message::SendFail ("Syntax error: -xnamecolor wrong color name"); |
a79f67f8 | 5156 | return 1; |
13a22457 | 5157 | } |
a79f67f8 | 5158 | aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor); |
5159 | } | |
5160 | if (aMapOfArgs.Find ("ynamecolor", aValues)) | |
5161 | { | |
5162 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 5163 | { |
23fe70ec | 5164 | Message::SendFail ("Syntax error: -ynamecolor wrong color name"); |
a79f67f8 | 5165 | return 1; |
5166 | } | |
5167 | aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor); | |
5168 | } | |
5169 | if (aMapOfArgs.Find ("znamecolor", aValues)) | |
5170 | { | |
5171 | if (!GetColor (aValues->Value(1), aColor)) | |
5172 | { | |
23fe70ec | 5173 | Message::SendFail ("Syntax error: -znamecolor wrong color name"); |
a79f67f8 | 5174 | return 1; |
5175 | } | |
5176 | aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor); | |
5177 | } | |
5178 | if (aMapOfArgs.Find ("xcolor", aValues)) | |
5179 | { | |
5180 | if (!GetColor (aValues->Value(1), aColor)) | |
5181 | { | |
23fe70ec | 5182 | Message::SendFail ("Syntax error: -xcolor wrong color name"); |
a79f67f8 | 5183 | return 1; |
5184 | } | |
5185 | aTrihedronData.ChangeXAxisAspect().SetColor (aColor); | |
5186 | } | |
5187 | if (aMapOfArgs.Find ("ycolor", aValues)) | |
5188 | { | |
5189 | if (!GetColor (aValues->Value(1), aColor)) | |
5190 | { | |
23fe70ec | 5191 | Message::SendFail ("Syntax error: -ycolor wrong color name"); |
a79f67f8 | 5192 | return 1; |
5193 | } | |
5194 | aTrihedronData.ChangeYAxisAspect().SetColor (aColor); | |
5195 | } | |
5196 | if (aMapOfArgs.Find ("zcolor", aValues)) | |
5197 | { | |
5198 | if (!GetColor (aValues->Value(1), aColor)) | |
5199 | { | |
23fe70ec | 5200 | Message::SendFail ("Syntax error: -zcolor wrong color name"); |
a79f67f8 | 5201 | return 1; |
5202 | } | |
5203 | aTrihedronData.ChangeZAxisAspect().SetColor (aColor); | |
5204 | } | |
5205 | ||
5206 | // TICKMARKS | |
5207 | if (aMapOfArgs.Find ("xticks", aValues)) | |
5208 | { | |
536d98e2 | 5209 | aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5210 | } |
5211 | if (aMapOfArgs.Find ("yticks", aValues)) | |
5212 | { | |
536d98e2 | 5213 | aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5214 | } |
5215 | if (aMapOfArgs.Find ("zticks", aValues)) | |
5216 | { | |
536d98e2 | 5217 | aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5218 | } |
5219 | if (aMapOfArgs.Find ("xticklength", aValues)) | |
5220 | { | |
536d98e2 | 5221 | aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5222 | } |
5223 | if (aMapOfArgs.Find ("yticklength", aValues)) | |
5224 | { | |
536d98e2 | 5225 | aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5226 | } |
5227 | if (aMapOfArgs.Find ("zticklength", aValues)) | |
5228 | { | |
536d98e2 | 5229 | aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5230 | } |
5231 | if (aMapOfArgs.Find ("xdrawticks", aValues)) | |
5232 | { | |
536d98e2 | 5233 | aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5234 | } |
5235 | if (aMapOfArgs.Find ("ydrawticks", aValues)) | |
5236 | { | |
536d98e2 | 5237 | aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5238 | } |
5239 | if (aMapOfArgs.Find ("zdrawticks", aValues)) | |
5240 | { | |
536d98e2 | 5241 | aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5242 | } |
5243 | ||
5244 | // VALUES | |
5245 | if (aMapOfArgs.Find ("xdrawvalues", aValues)) | |
5246 | { | |
536d98e2 | 5247 | aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5248 | } |
5249 | if (aMapOfArgs.Find ("ydrawvalues", aValues)) | |
5250 | { | |
536d98e2 | 5251 | aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5252 | } |
5253 | if (aMapOfArgs.Find ("zdrawvalues", aValues)) | |
5254 | { | |
536d98e2 | 5255 | aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5256 | } |
5257 | if (aMapOfArgs.Find ("xvaluesoffset", aValues)) | |
5258 | { | |
5259 | aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
5260 | } | |
5261 | if (aMapOfArgs.Find ("yvaluesoffset", aValues)) | |
5262 | { | |
5263 | aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
5264 | } | |
5265 | if (aMapOfArgs.Find ("zvaluesoffset", aValues)) | |
5266 | { | |
5267 | aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
5268 | } | |
5269 | ||
5270 | // ARROWS | |
5271 | if (aMapOfArgs.Find ("arrowlength", aValues)) | |
5272 | { | |
536d98e2 | 5273 | aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue()); |
a79f67f8 | 5274 | } |
5275 | ||
5276 | // FONTS | |
5277 | if (aMapOfArgs.Find ("namefont", aValues)) | |
5278 | { | |
5279 | aTrihedronData.SetNamesFont (aValues->Value(1)); | |
5280 | } | |
5281 | if (aMapOfArgs.Find ("valuesfont", aValues)) | |
5282 | { | |
5283 | aTrihedronData.SetValuesFont (aValues->Value(1)); | |
5284 | } | |
5285 | ||
536d98e2 | 5286 | if (aMapOfArgs.Find ("drawgrid", aValues)) |
5287 | { | |
5288 | aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on")); | |
5289 | } | |
5290 | if (aMapOfArgs.Find ("drawaxes", aValues)) | |
5291 | { | |
5292 | aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on")); | |
5293 | } | |
5294 | ||
a79f67f8 | 5295 | // The final step: display of erase trihedron |
5296 | if (toDisplay) | |
5297 | { | |
5298 | ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData); | |
13a22457 | 5299 | } |
7fd59977 | 5300 | else |
a79f67f8 | 5301 | { |
5302 | ViewerTest::CurrentView()->GraduatedTrihedronErase(); | |
5303 | } | |
7fd59977 | 5304 | |
5305 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); | |
a79f67f8 | 5306 | ViewerTest::CurrentView()->Redraw(); |
13a22457 | 5307 | |
7fd59977 | 5308 | return 0; |
5309 | } | |
5310 | ||
3bffef55 | 5311 | //============================================================================== |
5312 | //function : VTile | |
5313 | //purpose : | |
5314 | //============================================================================== | |
5315 | static int VTile (Draw_Interpretor& theDI, | |
5316 | Standard_Integer theArgNb, | |
5317 | const char** theArgVec) | |
5318 | { | |
5319 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5320 | if (aView.IsNull()) | |
5321 | { | |
23fe70ec | 5322 | Message::SendFail ("Error: no active viewer"); |
3bffef55 | 5323 | return 1; |
5324 | } | |
5325 | ||
5326 | Graphic3d_CameraTile aTile = aView->Camera()->Tile(); | |
5327 | if (theArgNb < 2) | |
5328 | { | |
5329 | theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n" | |
5330 | << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n" | |
5331 | << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n"; | |
5332 | return 0; | |
5333 | } | |
5334 | ||
5335 | aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y()); | |
5336 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
5337 | { | |
5338 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5339 | anArg.LowerCase(); | |
5340 | if (anArg == "-lowerleft" | |
5341 | || anArg == "-upperleft") | |
5342 | { | |
5343 | if (anArgIter + 3 < theArgNb) | |
5344 | { | |
23fe70ec | 5345 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
3bffef55 | 5346 | return 1; |
5347 | } | |
5348 | aTile.IsTopDown = (anArg == "-upperleft") == Standard_True; | |
5349 | aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
5350 | aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
5351 | } | |
5352 | else if (anArg == "-total" | |
5353 | || anArg == "-totalsize" | |
5354 | || anArg == "-viewsize") | |
5355 | { | |
5356 | if (anArgIter + 3 < theArgNb) | |
5357 | { | |
23fe70ec | 5358 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
3bffef55 | 5359 | return 1; |
5360 | } | |
5361 | aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
5362 | aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
5363 | if (aTile.TotalSize.x() < 1 | |
5364 | || aTile.TotalSize.y() < 1) | |
5365 | { | |
23fe70ec | 5366 | Message::SendFail ("Error: total size is incorrect"); |
3bffef55 | 5367 | return 1; |
5368 | } | |
5369 | } | |
5370 | else if (anArg == "-tilesize") | |
5371 | { | |
5372 | if (anArgIter + 3 < theArgNb) | |
5373 | { | |
23fe70ec | 5374 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
3bffef55 | 5375 | return 1; |
5376 | } | |
5377 | ||
5378 | aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
5379 | aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
5380 | if (aTile.TileSize.x() < 1 | |
5381 | || aTile.TileSize.y() < 1) | |
5382 | { | |
23fe70ec | 5383 | Message::SendFail ("Error: tile size is incorrect"); |
3bffef55 | 5384 | return 1; |
5385 | } | |
5386 | } | |
5387 | else if (anArg == "-unset") | |
5388 | { | |
5389 | aView->Camera()->SetTile (Graphic3d_CameraTile()); | |
5390 | aView->Redraw(); | |
5391 | return 0; | |
5392 | } | |
5393 | } | |
5394 | ||
5395 | if (aTile.TileSize.x() < 1 | |
5396 | || aTile.TileSize.y() < 1) | |
5397 | { | |
23fe70ec | 5398 | Message::SendFail ("Error: tile size is undefined"); |
3bffef55 | 5399 | return 1; |
5400 | } | |
5401 | else if (aTile.TotalSize.x() < 1 | |
5402 | || aTile.TotalSize.y() < 1) | |
5403 | { | |
23fe70ec | 5404 | Message::SendFail ("Error: total size is undefined"); |
3bffef55 | 5405 | return 1; |
5406 | } | |
5407 | ||
5408 | aView->Camera()->SetTile (aTile); | |
5409 | aView->Redraw(); | |
5410 | return 0; | |
5411 | } | |
5412 | ||
7c3ef2f7 | 5413 | //! Format ZLayer ID. |
5414 | inline const char* formZLayerId (const Standard_Integer theLayerId) | |
5415 | { | |
5416 | switch (theLayerId) | |
5417 | { | |
5418 | case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]"; | |
5419 | case Graphic3d_ZLayerId_Default: return "[DEFAULT]"; | |
5420 | case Graphic3d_ZLayerId_Top: return "[TOP]"; | |
5421 | case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]"; | |
5422 | case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]"; | |
5423 | case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]"; | |
5424 | } | |
5425 | return ""; | |
5426 | } | |
5427 | ||
5428 | //! Print the ZLayer information. | |
5429 | inline void printZLayerInfo (Draw_Interpretor& theDI, | |
5430 | const Graphic3d_ZLayerSettings& theLayer) | |
5431 | { | |
5432 | if (!theLayer.Name().IsEmpty()) | |
5433 | { | |
5434 | theDI << " Name: " << theLayer.Name() << "\n"; | |
5435 | } | |
5436 | if (theLayer.IsImmediate()) | |
5437 | { | |
5438 | theDI << " Immediate: TRUE\n"; | |
5439 | } | |
5440 | theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n"; | |
4ecf34cc | 5441 | theDI << " Culling distance: " << theLayer.CullingDistance() << "\n"; |
5442 | theDI << " Culling size: " << theLayer.CullingSize() << "\n"; | |
7c3ef2f7 | 5443 | theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n"; |
5444 | theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n"; | |
5445 | theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n"; | |
5446 | if (theLayer.PolygonOffset().Mode != Aspect_POM_None) | |
5447 | { | |
5448 | theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n"; | |
5449 | } | |
5450 | } | |
5451 | ||
59f45b7c | 5452 | //============================================================================== |
5453 | //function : VZLayer | |
5454 | //purpose : Test z layer operations for v3d viewer | |
5455 | //============================================================================== | |
7c3ef2f7 | 5456 | static int VZLayer (Draw_Interpretor& theDI, |
5457 | Standard_Integer theArgNb, | |
5458 | const char** theArgVec) | |
59f45b7c | 5459 | { |
7c3ef2f7 | 5460 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
59f45b7c | 5461 | if (aContextAIS.IsNull()) |
5462 | { | |
23fe70ec | 5463 | Message::SendFail ("Error: no active viewer"); |
59f45b7c | 5464 | return 1; |
5465 | } | |
5466 | ||
5467 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
7c3ef2f7 | 5468 | if (theArgNb < 2) |
59f45b7c | 5469 | { |
7c3ef2f7 | 5470 | TColStd_SequenceOfInteger aLayers; |
5471 | aViewer->GetAllZLayers (aLayers); | |
5472 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
5473 | { | |
5474 | theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n"; | |
5475 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
5476 | printZLayerInfo (theDI, aSettings); | |
5477 | } | |
59f45b7c | 5478 | return 1; |
5479 | } | |
5480 | ||
7c3ef2f7 | 5481 | Standard_Integer anArgIter = 1; |
5482 | Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN; | |
5483 | ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView()); | |
5484 | if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) | |
59f45b7c | 5485 | { |
7c3ef2f7 | 5486 | ++anArgIter; |
5487 | } | |
59f45b7c | 5488 | |
7c3ef2f7 | 5489 | { |
55c8f0f7 BB |
5490 | TCollection_AsciiString aFirstArg (theArgVec[anArgIter]); |
5491 | if (aFirstArg.IsIntegerValue()) | |
c5751993 | 5492 | { |
7c3ef2f7 | 5493 | ++anArgIter; |
55c8f0f7 | 5494 | aLayerId = aFirstArg.IntegerValue(); |
c5751993 | 5495 | } |
7c3ef2f7 | 5496 | else |
c5751993 | 5497 | { |
55c8f0f7 | 5498 | if (ViewerTest::ParseZLayerName (aFirstArg.ToCString(), aLayerId)) |
7c3ef2f7 | 5499 | { |
55c8f0f7 | 5500 | ++anArgIter; |
7c3ef2f7 | 5501 | } |
c5751993 | 5502 | } |
7c3ef2f7 | 5503 | } |
c5751993 | 5504 | |
1c728f2d | 5505 | Graphic3d_ZLayerId anOtherLayerId = Graphic3d_ZLayerId_UNKNOWN; |
7c3ef2f7 | 5506 | for (; anArgIter < theArgNb; ++anArgIter) |
5507 | { | |
5508 | // perform operation | |
5509 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5510 | anArg.LowerCase(); | |
5511 | if (anUpdateTool.parseRedrawMode (anArg)) | |
c5751993 | 5512 | { |
7c3ef2f7 | 5513 | // |
c5751993 | 5514 | } |
7c3ef2f7 | 5515 | else if (anArg == "-add" |
5516 | || anArg == "add") | |
c5751993 | 5517 | { |
7c3ef2f7 | 5518 | aLayerId = Graphic3d_ZLayerId_UNKNOWN; |
5519 | if (!aViewer->AddZLayer (aLayerId)) | |
5520 | { | |
23fe70ec | 5521 | Message::SendFail ("Error: can not add a new z layer"); |
7c3ef2f7 | 5522 | return 0; |
5523 | } | |
5524 | ||
5525 | theDI << aLayerId; | |
c5751993 | 5526 | } |
1c728f2d | 5527 | else if (anArg == "-insertbefore" |
5528 | && anArgIter + 1 < theArgNb | |
5529 | && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId)) | |
5530 | { | |
5531 | ++anArgIter; | |
5532 | aLayerId = Graphic3d_ZLayerId_UNKNOWN; | |
5533 | if (!aViewer->InsertLayerBefore (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId)) | |
5534 | { | |
23fe70ec | 5535 | Message::SendFail ("Error: can not add a new z layer"); |
1c728f2d | 5536 | return 0; |
5537 | } | |
5538 | ||
5539 | theDI << aLayerId; | |
5540 | } | |
5541 | else if (anArg == "-insertafter" | |
5542 | && anArgIter + 1 < theArgNb | |
5543 | && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId)) | |
5544 | { | |
5545 | ++anArgIter; | |
5546 | aLayerId = Graphic3d_ZLayerId_UNKNOWN; | |
5547 | if (!aViewer->InsertLayerAfter (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId)) | |
5548 | { | |
23fe70ec | 5549 | Message::SendFail ("Error: can not add a new z layer"); |
1c728f2d | 5550 | return 0; |
5551 | } | |
5552 | ||
5553 | theDI << aLayerId; | |
5554 | } | |
7c3ef2f7 | 5555 | else if (anArg == "-del" |
5556 | || anArg == "-delete" | |
5557 | || anArg == "del") | |
c5751993 | 5558 | { |
7c3ef2f7 | 5559 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
5560 | { | |
5561 | if (++anArgIter >= theArgNb) | |
5562 | { | |
23fe70ec | 5563 | Message::SendFail ("Syntax error: id of z layer to remove is missing"); |
7c3ef2f7 | 5564 | return 1; |
5565 | } | |
5566 | ||
5567 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); | |
5568 | } | |
5569 | ||
5570 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN | |
5571 | || aLayerId == Graphic3d_ZLayerId_Default | |
5572 | || aLayerId == Graphic3d_ZLayerId_Top | |
5573 | || aLayerId == Graphic3d_ZLayerId_Topmost | |
5574 | || aLayerId == Graphic3d_ZLayerId_TopOSD | |
5575 | || aLayerId == Graphic3d_ZLayerId_BotOSD) | |
5576 | { | |
23fe70ec | 5577 | Message::SendFail ("Syntax error: standard Z layer can not be removed"); |
7c3ef2f7 | 5578 | return 1; |
5579 | } | |
5580 | ||
5581 | // move all object displayed in removing layer to default layer | |
5582 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); | |
5583 | anObjIter.More(); anObjIter.Next()) | |
5584 | { | |
8f521168 | 5585 | const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1(); |
7c3ef2f7 | 5586 | if (aPrs.IsNull() |
5587 | || aPrs->ZLayer() != aLayerId) | |
5588 | { | |
5589 | continue; | |
5590 | } | |
5591 | aPrs->SetZLayer (Graphic3d_ZLayerId_Default); | |
5592 | } | |
5593 | ||
5594 | if (!aViewer->RemoveZLayer (aLayerId)) | |
5595 | { | |
23fe70ec | 5596 | Message::SendFail ("Z layer can not be removed"); |
7c3ef2f7 | 5597 | } |
5598 | else | |
5599 | { | |
5600 | theDI << aLayerId << " "; | |
5601 | } | |
c5751993 | 5602 | } |
7c3ef2f7 | 5603 | else if (anArg == "-get" |
5604 | || anArg == "get") | |
c5751993 | 5605 | { |
7c3ef2f7 | 5606 | TColStd_SequenceOfInteger aLayers; |
5607 | aViewer->GetAllZLayers (aLayers); | |
5608 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
5609 | { | |
5610 | theDI << aLayeriter.Value() << " "; | |
5611 | } | |
5612 | ||
5613 | theDI << "\n"; | |
c5751993 | 5614 | } |
7c3ef2f7 | 5615 | else if (anArg == "-name") |
c5751993 | 5616 | { |
7c3ef2f7 | 5617 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
c5751993 | 5618 | { |
23fe70ec | 5619 | Message::SendFail ("Syntax error: id of Z layer is missing"); |
c5751993 | 5620 | return 1; |
5621 | } | |
5622 | ||
7c3ef2f7 | 5623 | if (++anArgIter >= theArgNb) |
5624 | { | |
23fe70ec | 5625 | Message::SendFail ("Syntax error: name is missing"); |
7c3ef2f7 | 5626 | return 1; |
5627 | } | |
c5751993 | 5628 | |
7c3ef2f7 | 5629 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); |
5630 | aSettings.SetName (theArgVec[anArgIter]); | |
5631 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 5632 | } |
7c3ef2f7 | 5633 | else if (anArg == "-origin") |
c5751993 | 5634 | { |
7c3ef2f7 | 5635 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
5636 | { | |
23fe70ec | 5637 | Message::SendFail ("Syntax error: id of Z layer is missing"); |
7c3ef2f7 | 5638 | return 1; |
5639 | } | |
5640 | ||
5641 | if (anArgIter + 2 >= theArgNb) | |
5642 | { | |
23fe70ec | 5643 | Message::SendFail ("Syntax error: origin coordinates are missing"); |
7c3ef2f7 | 5644 | return 1; |
5645 | } | |
5646 | ||
5647 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
5648 | gp_XYZ anOrigin; | |
5649 | anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1])); | |
5650 | anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2])); | |
5651 | anOrigin.SetZ (0.0); | |
5652 | if (anArgIter + 3 < theArgNb) | |
5653 | { | |
5654 | anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3])); | |
5655 | anArgIter += 3; | |
5656 | } | |
5657 | else | |
5658 | { | |
5659 | anArgIter += 2; | |
5660 | } | |
5661 | aSettings.SetOrigin (anOrigin); | |
5662 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 5663 | } |
4ecf34cc | 5664 | else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN |
5665 | && anArgIter + 1 < theArgNb | |
5666 | && (anArg == "-cullingdistance" | |
5667 | || anArg == "-cullingdist" | |
5668 | || anArg == "-culldistance" | |
5669 | || anArg == "-culldist" | |
5670 | || anArg == "-distcull" | |
5671 | || anArg == "-distculling" | |
5672 | || anArg == "-distanceculling")) | |
5673 | { | |
5674 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
5675 | const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]); | |
5676 | aSettings.SetCullingDistance (aDist); | |
5677 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
5678 | } | |
5679 | else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN | |
5680 | && anArgIter + 1 < theArgNb | |
5681 | && (anArg == "-cullingsize" | |
5682 | || anArg == "-cullsize" | |
5683 | || anArg == "-sizecull" | |
5684 | || anArg == "-sizeculling")) | |
5685 | { | |
5686 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
5687 | const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]); | |
5688 | aSettings.SetCullingSize (aSize); | |
5689 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
5690 | } | |
7c3ef2f7 | 5691 | else if (anArg == "-settings" |
5692 | || anArg == "settings") | |
c5751993 | 5693 | { |
7c3ef2f7 | 5694 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
5695 | { | |
5696 | if (++anArgIter >= theArgNb) | |
5697 | { | |
23fe70ec | 5698 | Message::SendFail ("Syntax error: id of Z layer is missing"); |
7c3ef2f7 | 5699 | return 1; |
5700 | } | |
5701 | ||
5702 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); | |
5703 | } | |
5704 | ||
5705 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
5706 | printZLayerInfo (theDI, aSettings); | |
c5751993 | 5707 | } |
7c3ef2f7 | 5708 | else if (anArg == "-enable" |
5709 | || anArg == "enable" | |
5710 | || anArg == "-disable" | |
5711 | || anArg == "disable") | |
83da37b1 | 5712 | { |
7c3ef2f7 | 5713 | const Standard_Boolean toEnable = anArg == "-enable" |
5714 | || anArg == "enable"; | |
5715 | if (++anArgIter >= theArgNb) | |
5716 | { | |
23fe70ec | 5717 | Message::SendFail ("Syntax error: option name is missing"); |
7c3ef2f7 | 5718 | return 1; |
5719 | } | |
c5751993 | 5720 | |
7c3ef2f7 | 5721 | TCollection_AsciiString aSubOp (theArgVec[anArgIter]); |
5722 | aSubOp.LowerCase(); | |
5723 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) | |
5724 | { | |
5725 | if (++anArgIter >= theArgNb) | |
5726 | { | |
23fe70ec | 5727 | Message::SendFail ("Syntax error: id of Z layer is missing"); |
7c3ef2f7 | 5728 | return 1; |
5729 | } | |
c5751993 | 5730 | |
7c3ef2f7 | 5731 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); |
5732 | } | |
c5751993 | 5733 | |
7c3ef2f7 | 5734 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); |
5735 | if (aSubOp == "depthtest" | |
5736 | || aSubOp == "test") | |
5737 | { | |
5738 | aSettings.SetEnableDepthTest (toEnable); | |
5739 | } | |
5740 | else if (aSubOp == "depthwrite" | |
5741 | || aSubOp == "write") | |
5742 | { | |
5743 | aSettings.SetEnableDepthWrite (toEnable); | |
5744 | } | |
5745 | else if (aSubOp == "depthclear" | |
5746 | || aSubOp == "clear") | |
5747 | { | |
5748 | aSettings.SetClearDepth (toEnable); | |
5749 | } | |
5750 | else if (aSubOp == "depthoffset" | |
5751 | || aSubOp == "offset") | |
5752 | { | |
5753 | Graphic3d_PolygonOffset aParams; | |
5754 | aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None; | |
5755 | if (toEnable) | |
5756 | { | |
5757 | if (anArgIter + 2 >= theArgNb) | |
5758 | { | |
23fe70ec | 5759 | Message::SendFail ("Syntax error: factor and units values for depth offset are missing"); |
7c3ef2f7 | 5760 | return 1; |
5761 | } | |
c5751993 | 5762 | |
7c3ef2f7 | 5763 | aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter])); |
5764 | aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter])); | |
5765 | } | |
5766 | aSettings.SetPolygonOffset (aParams); | |
5767 | } | |
5768 | else if (aSubOp == "positiveoffset" | |
5769 | || aSubOp == "poffset") | |
5770 | { | |
5771 | if (toEnable) | |
5772 | { | |
5773 | aSettings.SetDepthOffsetPositive(); | |
5774 | } | |
5775 | else | |
5776 | { | |
5777 | aSettings.SetPolygonOffset (Graphic3d_PolygonOffset()); | |
5778 | } | |
5779 | } | |
5780 | else if (aSubOp == "negativeoffset" | |
5781 | || aSubOp == "noffset") | |
5782 | { | |
5783 | if (toEnable) | |
5784 | { | |
5785 | aSettings.SetDepthOffsetNegative(); | |
5786 | } | |
5787 | else | |
5788 | { | |
5789 | aSettings.SetPolygonOffset(Graphic3d_PolygonOffset()); | |
5790 | } | |
5791 | } | |
5792 | else if (aSubOp == "textureenv") | |
5793 | { | |
5794 | aSettings.SetEnvironmentTexture (toEnable); | |
5795 | } | |
1c728f2d | 5796 | else if (aSubOp == "raytracing") |
5797 | { | |
5798 | aSettings.SetRaytracable (toEnable); | |
5799 | } | |
7c3ef2f7 | 5800 | |
5801 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 5802 | } |
7c3ef2f7 | 5803 | else |
83da37b1 | 5804 | { |
23fe70ec | 5805 | Message::SendFail() << "Syntax error: unknown option " << theArgVec[anArgIter]; |
7c3ef2f7 | 5806 | return 1; |
83da37b1 | 5807 | } |
59f45b7c | 5808 | } |
5809 | ||
5810 | return 0; | |
5811 | } | |
5812 | ||
c357e426 | 5813 | // The interactive presentation of 2d layer item |
5814 | // for "vlayerline" command it provides a presentation of | |
5815 | // line with user-defined linewidth, linetype and transparency. | |
61b0191c | 5816 | class V3d_LineItem : public AIS_InteractiveObject |
20637bd2 | 5817 | { |
5818 | public: | |
5819 | // CASCADE RTTI | |
92efcf78 | 5820 | DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject) |
4fe56619 | 5821 | |
20637bd2 | 5822 | // constructor |
5823 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
5824 | Standard_Real X2, Standard_Real Y2, | |
20637bd2 | 5825 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, |
5826 | Standard_Real theWidth = 0.5, | |
5827 | Standard_Real theTransp = 1.0); | |
5828 | ||
61b0191c | 5829 | private: |
5830 | ||
5831 | void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
5832 | const Handle(Prs3d_Presentation)& thePresentation, | |
79104795 | 5833 | const Standard_Integer theMode) Standard_OVERRIDE; |
61b0191c | 5834 | |
5835 | void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/, | |
79104795 | 5836 | const Standard_Integer /*aMode*/) Standard_OVERRIDE |
5837 | {} | |
20637bd2 | 5838 | |
5839 | private: | |
5840 | ||
5841 | Standard_Real myX1, myY1, myX2, myY2; | |
eafb234b | 5842 | Aspect_TypeOfLine myType; |
20637bd2 | 5843 | Standard_Real myWidth; |
20637bd2 | 5844 | }; |
5845 | ||
20637bd2 | 5846 | // default constructor for line item |
4fe56619 | 5847 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
20637bd2 | 5848 | Standard_Real X2, Standard_Real Y2, |
20637bd2 | 5849 | Aspect_TypeOfLine theType, |
5850 | Standard_Real theWidth, | |
5851 | Standard_Real theTransp) : | |
61b0191c | 5852 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), |
5853 | myType(theType), myWidth(theWidth) | |
20637bd2 | 5854 | { |
61b0191c | 5855 | SetTransparency (1-theTransp); |
20637bd2 | 5856 | } |
5857 | ||
5858 | // render line | |
61b0191c | 5859 | void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/, |
5860 | const Handle(Prs3d_Presentation)& thePresentation, | |
5861 | const Standard_Integer /*theMode*/) | |
20637bd2 | 5862 | { |
61b0191c | 5863 | thePresentation->Clear(); |
ba00aab7 | 5864 | Quantity_Color aColor (Quantity_NOC_RED); |
61b0191c | 5865 | Standard_Integer aWidth, aHeight; |
5866 | ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight); | |
5867 | Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); | |
5868 | Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5); | |
5869 | aPrim->AddVertex(myX1, aHeight-myY1, 0.); | |
5870 | aPrim->AddVertex(myX2, aHeight-myY2, 0.); | |
5871 | Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth); | |
5872 | aGroup->SetPrimitivesAspect (anAspect->Aspect()); | |
5873 | aGroup->AddPrimitiveArray (aPrim); | |
20637bd2 | 5874 | } |
5875 | ||
5876 | //============================================================================= | |
5877 | //function : VLayerLine | |
5878 | //purpose : Draws line in the v3d view layer with given attributes: linetype, | |
5879 | // : linewidth, transparency coefficient | |
5880 | //============================================================================ | |
5881 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
5882 | { | |
5883 | // get the active view | |
5884 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5885 | if (aView.IsNull()) | |
5886 | { | |
5887 | di << "Call vinit before!\n"; | |
5888 | return 1; | |
5889 | } | |
5890 | else if (argc < 5) | |
5891 | { | |
5892 | di << "Use: " << argv[0]; | |
5893 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; | |
5894 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; | |
5895 | di << " 0 - solid \n"; | |
5896 | di << " 1 - dashed \n"; | |
5897 | di << " 2 - dot \n"; | |
5898 | di << " 3 - dashdot\n"; | |
5899 | di << " transparency : { 0.0 - 1.0 } \n"; | |
5900 | di << " 0.0 - transparent\n"; | |
5901 | di << " 1.0 - visible \n"; | |
5902 | return 1; | |
5903 | } | |
5904 | ||
61b0191c | 5905 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
20637bd2 | 5906 | // get the input params |
91322f44 | 5907 | Standard_Real X1 = Draw::Atof(argv[1]); |
5908 | Standard_Real Y1 = Draw::Atof(argv[2]); | |
5909 | Standard_Real X2 = Draw::Atof(argv[3]); | |
5910 | Standard_Real Y2 = Draw::Atof(argv[4]); | |
20637bd2 | 5911 | |
3a4a3962 | 5912 | Standard_Real aWidth = 0.5; |
5913 | Standard_Real aTransparency = 1.0; | |
20637bd2 | 5914 | |
5915 | // has width | |
5916 | if (argc > 5) | |
91322f44 | 5917 | aWidth = Draw::Atof(argv[5]); |
20637bd2 | 5918 | |
3a4a3962 | 5919 | // select appropriate line type |
5920 | Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID; | |
5921 | if (argc > 6 | |
5922 | && !ViewerTest::ParseLineType (argv[6], aLineType)) | |
5923 | { | |
23fe70ec | 5924 | Message::SendFail() << "Syntax error: unknown line type '" << argv[6] << "'"; |
3a4a3962 | 5925 | return 1; |
5926 | } | |
20637bd2 | 5927 | |
5928 | // has transparency | |
5929 | if (argc > 7) | |
5930 | { | |
91322f44 | 5931 | aTransparency = Draw::Atof(argv[7]); |
4fe56619 | 5932 | if (aTransparency < 0 || aTransparency > 1.0) |
20637bd2 | 5933 | aTransparency = 1.0; |
5934 | } | |
5935 | ||
61b0191c | 5936 | static Handle (V3d_LineItem) aLine; |
5937 | if (!aLine.IsNull()) | |
25289ec1 | 5938 | { |
0577ae8c | 5939 | aContext->Erase (aLine, Standard_False); |
25289ec1 | 5940 | } |
61b0191c | 5941 | aLine = new V3d_LineItem (X1, Y1, X2, Y2, |
5942 | aLineType, aWidth, | |
5943 | aTransparency); | |
25289ec1 | 5944 | |
778cd667 | 5945 | aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); |
61b0191c | 5946 | aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD); |
5947 | aLine->SetToUpdate(); | |
5948 | aContext->Display (aLine, Standard_True); | |
25289ec1 | 5949 | |
5950 | return 0; | |
5951 | } | |
5952 | ||
61b0191c | 5953 | |
2bd4c032 | 5954 | //============================================================================== |
5955 | //function : VGrid | |
5956 | //purpose : | |
5957 | //============================================================================== | |
5958 | ||
35e08fe8 | 5959 | static int VGrid (Draw_Interpretor& /*theDI*/, |
2bd4c032 | 5960 | Standard_Integer theArgNb, |
5961 | const char** theArgVec) | |
5962 | { | |
2bd4c032 | 5963 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
5964 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
5965 | if (aView.IsNull() || aViewer.IsNull()) | |
5966 | { | |
23fe70ec | 5967 | Message::SendFail ("Error: no active viewer"); |
2bd4c032 | 5968 | return 1; |
5969 | } | |
5970 | ||
5971 | Aspect_GridType aType = aViewer->GridType(); | |
5972 | Aspect_GridDrawMode aMode = aViewer->GridDrawMode(); | |
79931835 | 5973 | Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY; |
5974 | Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0; | |
5975 | bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false; | |
224f48fa | 5976 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
79931835 | 5977 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
2bd4c032 | 5978 | { |
79931835 | 5979 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
5980 | anArg.LowerCase(); | |
5981 | if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) | |
224f48fa | 5982 | { |
5983 | continue; | |
5984 | } | |
79931835 | 5985 | else if (anArgIter + 1 < theArgNb |
5986 | && anArg == "-type") | |
5987 | { | |
5988 | TCollection_AsciiString anArgNext (theArgVec[++anArgIter]); | |
5989 | anArgNext.LowerCase(); | |
5990 | if (anArgNext == "r" | |
5991 | || anArgNext == "rect" | |
5992 | || anArgNext == "rectangular") | |
5993 | { | |
5994 | aType = Aspect_GT_Rectangular; | |
5995 | } | |
5996 | else if (anArgNext == "c" | |
5997 | || anArgNext == "circ" | |
5998 | || anArgNext == "circular") | |
5999 | { | |
6000 | aType = Aspect_GT_Circular; | |
6001 | } | |
6002 | else | |
6003 | { | |
23fe70ec | 6004 | Message::SendFail() << "Syntax error at '" << anArgNext << "'"; |
79931835 | 6005 | return 1; |
6006 | } | |
6007 | } | |
6008 | else if (anArgIter + 1 < theArgNb | |
6009 | && anArg == "-mode") | |
6010 | { | |
6011 | TCollection_AsciiString anArgNext (theArgVec[++anArgIter]); | |
6012 | anArgNext.LowerCase(); | |
6013 | if (anArgNext == "l" | |
6014 | || anArgNext == "line" | |
6015 | || anArgNext == "lines") | |
6016 | { | |
6017 | aMode = Aspect_GDM_Lines; | |
6018 | } | |
6019 | else if (anArgNext == "p" | |
6020 | || anArgNext == "point" | |
6021 | || anArgNext == "points") | |
6022 | { | |
6023 | aMode = Aspect_GDM_Points; | |
6024 | } | |
6025 | else | |
6026 | { | |
23fe70ec | 6027 | Message::SendFail() << "Syntax error at '" << anArgNext << "'"; |
79931835 | 6028 | return 1; |
6029 | } | |
6030 | } | |
6031 | else if (anArgIter + 2 < theArgNb | |
6032 | && (anArg == "-origin" | |
6033 | || anArg == "-orig")) | |
6034 | { | |
6035 | hasOrigin = true; | |
6036 | aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]), | |
6037 | Draw::Atof (theArgVec[anArgIter + 2])); | |
6038 | anArgIter += 2; | |
6039 | } | |
6040 | else if (anArgIter + 2 < theArgNb | |
6041 | && anArg == "-step") | |
6042 | { | |
6043 | hasStep = true; | |
6044 | aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]), | |
6045 | Draw::Atof (theArgVec[anArgIter + 2])); | |
6046 | if (aNewStepXY.x() <= 0.0 | |
6047 | || aNewStepXY.y() <= 0.0) | |
6048 | { | |
23fe70ec | 6049 | Message::SendFail() << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'"; |
79931835 | 6050 | return 1; |
6051 | } | |
6052 | anArgIter += 2; | |
6053 | } | |
6054 | else if (anArgIter + 1 < theArgNb | |
6055 | && (anArg == "-angle" | |
6056 | || anArg == "-rotangle" | |
6057 | || anArg == "-rotationangle")) | |
6058 | { | |
6059 | hasRotAngle = true; | |
6060 | aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]); | |
6061 | } | |
6062 | else if (anArgIter + 1 < theArgNb | |
6063 | && (anArg == "-zoffset" | |
6064 | || anArg == "-dz")) | |
6065 | { | |
6066 | hasZOffset = true; | |
6067 | aNewZOffset = Draw::Atof (theArgVec[++anArgIter]); | |
6068 | } | |
6069 | else if (anArgIter + 1 < theArgNb | |
6070 | && anArg == "-radius") | |
6071 | { | |
6072 | hasSize = true; | |
6073 | ++anArgIter; | |
6074 | aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0); | |
6075 | if (aNewStepXY.x() <= 0.0) | |
6076 | { | |
23fe70ec | 6077 | Message::SendFail() << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'"; |
79931835 | 6078 | return 1; |
6079 | } | |
6080 | } | |
6081 | else if (anArgIter + 2 < theArgNb | |
6082 | && anArg == "-size") | |
6083 | { | |
6084 | hasSize = true; | |
6085 | aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]), | |
6086 | Draw::Atof (theArgVec[anArgIter + 2])); | |
6087 | if (aNewStepXY.x() <= 0.0 | |
6088 | || aNewStepXY.y() <= 0.0) | |
6089 | { | |
23fe70ec | 6090 | Message::SendFail() << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'"; |
79931835 | 6091 | return 1; |
6092 | } | |
6093 | anArgIter += 2; | |
6094 | } | |
6095 | else if (anArg == "r" | |
6096 | || anArg == "rect" | |
6097 | || anArg == "rectangular") | |
2bd4c032 | 6098 | { |
6099 | aType = Aspect_GT_Rectangular; | |
6100 | } | |
79931835 | 6101 | else if (anArg == "c" |
6102 | || anArg == "circ" | |
6103 | || anArg == "circular") | |
2bd4c032 | 6104 | { |
6105 | aType = Aspect_GT_Circular; | |
6106 | } | |
79931835 | 6107 | else if (anArg == "l" |
6108 | || anArg == "line" | |
6109 | || anArg == "lines") | |
2bd4c032 | 6110 | { |
6111 | aMode = Aspect_GDM_Lines; | |
6112 | } | |
79931835 | 6113 | else if (anArg == "p" |
6114 | || anArg == "point" | |
6115 | || anArg == "points") | |
2bd4c032 | 6116 | { |
6117 | aMode = Aspect_GDM_Points; | |
6118 | } | |
79931835 | 6119 | else if (anArgIter + 1 >= theArgNb |
6120 | && anArg == "off") | |
2bd4c032 | 6121 | { |
6122 | aViewer->DeactivateGrid(); | |
6123 | return 0; | |
6124 | } | |
6125 | else | |
6126 | { | |
23fe70ec | 6127 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
79931835 | 6128 | return 1; |
2bd4c032 | 6129 | } |
6130 | } | |
6131 | ||
2bd4c032 | 6132 | if (aType == Aspect_GT_Rectangular) |
6133 | { | |
79931835 | 6134 | Graphic3d_Vec2d anOrigXY, aStepXY; |
6135 | Standard_Real aRotAngle = 0.0; | |
6136 | aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle); | |
6137 | if (hasOrigin) | |
6138 | { | |
6139 | anOrigXY = aNewOriginXY; | |
6140 | } | |
6141 | if (hasStep) | |
6142 | { | |
6143 | aStepXY = aNewStepXY; | |
6144 | } | |
6145 | if (hasRotAngle) | |
6146 | { | |
6147 | aRotAngle = aNewRotAngle; | |
6148 | } | |
6149 | aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle); | |
6150 | if (hasSize || hasZOffset) | |
2bd4c032 | 6151 | { |
79931835 | 6152 | Graphic3d_Vec3d aSize; |
6153 | aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z()); | |
6154 | if (hasSize) | |
6155 | { | |
6156 | aSize.x() = aNewSizeXY.x(); | |
6157 | aSize.y() = aNewSizeXY.y(); | |
6158 | } | |
6159 | if (hasZOffset) | |
6160 | { | |
6161 | aSize.z() = aNewZOffset; | |
6162 | } | |
6163 | aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z()); | |
2bd4c032 | 6164 | } |
2bd4c032 | 6165 | } |
6166 | else if (aType == Aspect_GT_Circular) | |
6167 | { | |
79931835 | 6168 | Graphic3d_Vec2d anOrigXY; |
ee2be2a8 | 6169 | Standard_Real aRadiusStep; |
2bd4c032 | 6170 | Standard_Integer aDivisionNumber; |
79931835 | 6171 | Standard_Real aRotAngle = 0.0; |
6172 | aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle); | |
6173 | if (hasOrigin) | |
6174 | { | |
6175 | anOrigXY = aNewOriginXY; | |
6176 | } | |
6177 | if (hasStep) | |
6178 | { | |
6179 | aRadiusStep = aNewStepXY[0]; | |
6180 | aDivisionNumber = (int )aNewStepXY[1]; | |
6181 | if (aDivisionNumber < 1) | |
6182 | { | |
23fe70ec | 6183 | Message::SendFail() << "Syntax error: invalid division number '" << aNewStepXY[1] << "'"; |
79931835 | 6184 | return 1; |
6185 | } | |
6186 | } | |
6187 | if (hasRotAngle) | |
2bd4c032 | 6188 | { |
79931835 | 6189 | aRotAngle = aNewRotAngle; |
2bd4c032 | 6190 | } |
6191 | ||
79931835 | 6192 | aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle); |
6193 | if (hasSize || hasZOffset) | |
6194 | { | |
6195 | Standard_Real aRadius = 0.0, aZOffset = 0.0; | |
6196 | aViewer->CircularGridGraphicValues (aRadius, aZOffset); | |
6197 | if (hasSize) | |
6198 | { | |
6199 | aRadius = aNewSizeXY.x(); | |
6200 | if (aNewSizeXY.y() != 0.0) | |
6201 | { | |
23fe70ec | 6202 | Message::SendFail ("Syntax error: circular size should be specified as radius"); |
79931835 | 6203 | return 1; |
6204 | } | |
6205 | } | |
6206 | if (hasZOffset) | |
6207 | { | |
6208 | aZOffset = aNewZOffset; | |
6209 | } | |
6210 | aViewer->SetCircularGridGraphicValues (aRadius, aZOffset); | |
6211 | } | |
2bd4c032 | 6212 | } |
79931835 | 6213 | aViewer->ActivateGrid (aType, aMode); |
2bd4c032 | 6214 | return 0; |
6215 | } | |
6216 | ||
c40b7d58 | 6217 | //============================================================================== |
6218 | //function : VPriviledgedPlane | |
6219 | //purpose : | |
6220 | //============================================================================== | |
6221 | ||
6222 | static int VPriviledgedPlane (Draw_Interpretor& theDI, | |
6223 | Standard_Integer theArgNb, | |
6224 | const char** theArgVec) | |
6225 | { | |
6226 | if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10) | |
6227 | { | |
23fe70ec | 6228 | Message::SendFail ("Error: wrong number of arguments! See usage:"); |
c40b7d58 | 6229 | theDI.PrintHelp (theArgVec[0]); |
6230 | return 1; | |
6231 | } | |
6232 | ||
6233 | // get the active viewer | |
6234 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
6235 | if (aViewer.IsNull()) | |
6236 | { | |
23fe70ec | 6237 | Message::SendFail ("Error: no active viewer"); |
c40b7d58 | 6238 | return 1; |
6239 | } | |
6240 | ||
6241 | if (theArgNb == 1) | |
6242 | { | |
6243 | gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane(); | |
6244 | const gp_Pnt& anOrig = aPriviledgedPlane.Location(); | |
6245 | const gp_Dir& aNorm = aPriviledgedPlane.Direction(); | |
6246 | const gp_Dir& aXDir = aPriviledgedPlane.XDirection(); | |
6247 | theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " " | |
6248 | << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " " | |
6249 | << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n"; | |
6250 | return 0; | |
6251 | } | |
6252 | ||
6253 | Standard_Integer anArgIdx = 1; | |
6254 | Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]); | |
6255 | Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]); | |
6256 | Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]); | |
6257 | Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]); | |
6258 | Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]); | |
6259 | Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]); | |
6260 | ||
6261 | gp_Ax3 aPriviledgedPlane; | |
6262 | gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ); | |
6263 | gp_Dir aNorm (aNormX, aNormY, aNormZ); | |
6264 | if (theArgNb > 7) | |
6265 | { | |
6266 | Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]); | |
6267 | Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]); | |
6268 | Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]); | |
6269 | gp_Dir aXDir (aXDirX, aXDirY, aXDirZ); | |
6270 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir); | |
6271 | } | |
6272 | else | |
6273 | { | |
6274 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm); | |
6275 | } | |
6276 | ||
6277 | aViewer->SetPrivilegedPlane (aPriviledgedPlane); | |
6278 | ||
6279 | return 0; | |
6280 | } | |
6281 | ||
f25b82d6 | 6282 | //============================================================================== |
6283 | //function : VConvert | |
6284 | //purpose : | |
6285 | //============================================================================== | |
6286 | ||
6287 | static int VConvert (Draw_Interpretor& theDI, | |
6288 | Standard_Integer theArgNb, | |
6289 | const char** theArgVec) | |
6290 | { | |
6291 | // get the active view | |
6292 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6293 | if (aView.IsNull()) | |
6294 | { | |
23fe70ec | 6295 | Message::SendFail ("Error: no active viewer"); |
f25b82d6 | 6296 | return 1; |
6297 | } | |
6298 | ||
6299 | enum { Model, Ray, View, Window, Grid } aMode = Model; | |
6300 | ||
6301 | // access coordinate arguments | |
6302 | TColStd_SequenceOfReal aCoord; | |
6303 | Standard_Integer anArgIdx = 1; | |
6304 | for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx) | |
6305 | { | |
6306 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
6307 | if (!anArg.IsRealValue()) | |
6308 | { | |
6309 | break; | |
6310 | } | |
6311 | aCoord.Append (anArg.RealValue()); | |
6312 | } | |
6313 | ||
6314 | // non-numeric argument too early | |
6315 | if (aCoord.IsEmpty()) | |
6316 | { | |
23fe70ec | 6317 | Message::SendFail ("Error: wrong number of arguments! See usage:"); |
f25b82d6 | 6318 | theDI.PrintHelp (theArgVec[0]); |
6319 | return 1; | |
6320 | } | |
6321 | ||
6322 | // collect all other arguments and options | |
6323 | for (; anArgIdx < theArgNb; ++anArgIdx) | |
6324 | { | |
6325 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
6326 | anArg.LowerCase(); | |
6327 | if (anArg == "window") aMode = Window; | |
6328 | else if (anArg == "view") aMode = View; | |
6329 | else if (anArg == "grid") aMode = Grid; | |
6330 | else if (anArg == "ray") aMode = Ray; | |
6331 | else | |
6332 | { | |
23fe70ec | 6333 | Message::SendFail() << "Error: wrong argument " << anArg << "! See usage:"; |
f25b82d6 | 6334 | theDI.PrintHelp (theArgVec[0]); |
6335 | return 1; | |
6336 | } | |
6337 | } | |
6338 | ||
6339 | // complete input checks | |
6340 | if ((aCoord.Length() == 1 && theArgNb > 3) || | |
6341 | (aCoord.Length() == 2 && theArgNb > 4) || | |
6342 | (aCoord.Length() == 3 && theArgNb > 5)) | |
6343 | { | |
23fe70ec | 6344 | Message::SendFail ("Error: wrong number of arguments! See usage:"); |
f25b82d6 | 6345 | theDI.PrintHelp (theArgVec[0]); |
6346 | return 1; | |
6347 | } | |
6348 | ||
6349 | Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; | |
6350 | Standard_Integer aXYp[2] = {0, 0}; | |
6351 | ||
6352 | // convert one-dimensional coordinate | |
6353 | if (aCoord.Length() == 1) | |
6354 | { | |
6355 | switch (aMode) | |
6356 | { | |
ee2be2a8 | 6357 | case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0; |
6358 | case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0; | |
f25b82d6 | 6359 | default: |
23fe70ec | 6360 | Message::SendFail ("Error: wrong arguments! See usage:"); |
f25b82d6 | 6361 | theDI.PrintHelp (theArgVec[0]); |
6362 | return 1; | |
6363 | } | |
6364 | } | |
6365 | ||
6366 | // convert 2D coordinates from projection or view reference space | |
6367 | if (aCoord.Length() == 2) | |
6368 | { | |
6369 | switch (aMode) | |
6370 | { | |
6371 | case Model : | |
6372 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
6373 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
6374 | return 0; | |
6375 | ||
6376 | case View : | |
6377 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]); | |
6378 | theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n"; | |
6379 | return 0; | |
6380 | ||
6381 | case Window : | |
ee2be2a8 | 6382 | aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]); |
f25b82d6 | 6383 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; |
6384 | return 0; | |
6385 | ||
6386 | case Grid : | |
6387 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
6388 | aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]); | |
6389 | theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
6390 | return 0; | |
6391 | ||
6392 | case Ray : | |
6393 | aView->ConvertWithProj ((Standard_Integer) aCoord (1), | |
6394 | (Standard_Integer) aCoord (2), | |
6395 | aXYZ[0], aXYZ[1], aXYZ[2], | |
6396 | aXYZ[3], aXYZ[4], aXYZ[5]); | |
6397 | theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
6398 | return 0; | |
6399 | ||
6400 | default: | |
23fe70ec | 6401 | Message::SendFail ("Error: wrong arguments! See usage:"); |
f25b82d6 | 6402 | theDI.PrintHelp (theArgVec[0]); |
6403 | return 1; | |
6404 | } | |
6405 | } | |
6406 | ||
6407 | // convert 3D coordinates from view reference space | |
6408 | else if (aCoord.Length() == 3) | |
6409 | { | |
6410 | switch (aMode) | |
6411 | { | |
6412 | case Window : | |
6413 | aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]); | |
6414 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; | |
6415 | return 0; | |
6416 | ||
6417 | case Grid : | |
6418 | aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]); | |
6419 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
6420 | return 0; | |
6421 | ||
6422 | default: | |
23fe70ec | 6423 | Message::SendFail ("Error: wrong arguments! See usage:"); |
f25b82d6 | 6424 | theDI.PrintHelp (theArgVec[0]); |
6425 | return 1; | |
6426 | } | |
6427 | } | |
6428 | ||
6429 | return 0; | |
6430 | } | |
6431 | ||
208e6839 | 6432 | //============================================================================== |
6433 | //function : VFps | |
6434 | //purpose : | |
6435 | //============================================================================== | |
6436 | ||
6437 | static int VFps (Draw_Interpretor& theDI, | |
6438 | Standard_Integer theArgNb, | |
6439 | const char** theArgVec) | |
6440 | { | |
6441 | // get the active view | |
6442 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6443 | if (aView.IsNull()) | |
6444 | { | |
23fe70ec | 6445 | Message::SendFail ("Error: no active viewer"); |
208e6839 | 6446 | return 1; |
6447 | } | |
6448 | ||
e084dbbc | 6449 | Standard_Integer aFramesNb = -1; |
6450 | Standard_Real aDuration = -1.0; | |
6451 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
208e6839 | 6452 | { |
e084dbbc | 6453 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
6454 | anArg.LowerCase(); | |
6455 | if (aDuration < 0.0 | |
6456 | && anArgIter + 1 < theArgNb | |
6457 | && (anArg == "-duration" | |
6458 | || anArg == "-dur" | |
6459 | || anArg == "-time")) | |
6460 | { | |
6461 | aDuration = Draw::Atof (theArgVec[++anArgIter]); | |
6462 | } | |
6463 | else if (aFramesNb < 0 | |
6464 | && anArg.IsIntegerValue()) | |
6465 | { | |
6466 | aFramesNb = anArg.IntegerValue(); | |
6467 | if (aFramesNb <= 0) | |
6468 | { | |
23fe70ec | 6469 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
e084dbbc | 6470 | return 1; |
6471 | } | |
6472 | } | |
6473 | else | |
6474 | { | |
23fe70ec | 6475 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
e084dbbc | 6476 | return 1; |
6477 | } | |
6478 | } | |
6479 | if (aFramesNb < 0 && aDuration < 0.0) | |
6480 | { | |
6481 | aFramesNb = 100; | |
208e6839 | 6482 | } |
6483 | ||
6484 | // the time is meaningless for first call | |
6485 | // due to async OpenGl rendering | |
6486 | aView->Redraw(); | |
6487 | ||
6488 | // redraw view in loop to estimate average values | |
6489 | OSD_Timer aTimer; | |
6490 | aTimer.Start(); | |
e084dbbc | 6491 | Standard_Integer aFrameIter = 1; |
6492 | for (;; ++aFrameIter) | |
208e6839 | 6493 | { |
6494 | aView->Redraw(); | |
e084dbbc | 6495 | if ((aFramesNb > 0 |
6496 | && aFrameIter >= aFramesNb) | |
6497 | || (aDuration > 0.0 | |
6498 | && aTimer.ElapsedTime() >= aDuration)) | |
6499 | { | |
6500 | break; | |
6501 | } | |
208e6839 | 6502 | } |
6503 | aTimer.Stop(); | |
6504 | Standard_Real aCpu; | |
6505 | const Standard_Real aTime = aTimer.ElapsedTime(); | |
6506 | aTimer.OSD_Chronometer::Show (aCpu); | |
6507 | ||
e084dbbc | 6508 | const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime; |
6509 | const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter); | |
208e6839 | 6510 | |
6511 | // return statistics | |
6512 | theDI << "FPS: " << aFpsAver << "\n" | |
6513 | << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; | |
6514 | ||
8c820969 | 6515 | // compute additional statistics in ray-tracing mode |
e084dbbc | 6516 | const Graphic3d_RenderingParams& aParams = aView->RenderingParams(); |
8c820969 | 6517 | if (aParams.Method == Graphic3d_RM_RAYTRACING) |
6518 | { | |
e084dbbc | 6519 | Graphic3d_Vec2i aWinSize (0, 0); |
6520 | aView->Window()->Size (aWinSize.x(), aWinSize.y()); | |
8c820969 | 6521 | |
6522 | // 1 shadow ray and 1 secondary ray pew each bounce | |
e084dbbc | 6523 | const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f; |
8c820969 | 6524 | theDI << "MRays/sec (upper bound): " << aMRays << "\n"; |
6525 | } | |
6526 | ||
208e6839 | 6527 | return 0; |
6528 | } | |
6529 | ||
84e84755 | 6530 | //! Auxiliary function for parsing glsl dump level argument. |
6531 | static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg, | |
6532 | OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel) | |
6533 | { | |
6534 | TCollection_AsciiString aTypeStr (theArg); | |
6535 | aTypeStr.LowerCase(); | |
6536 | if (aTypeStr == "off" | |
6537 | || aTypeStr == "0") | |
6538 | { | |
6539 | theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off; | |
6540 | } | |
6541 | else if (aTypeStr == "short") | |
6542 | { | |
6543 | theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short; | |
6544 | } | |
6545 | else if (aTypeStr == "full" | |
6546 | || aTypeStr == "1") | |
6547 | { | |
6548 | theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full; | |
6549 | } | |
6550 | else | |
6551 | { | |
6552 | return Standard_False; | |
6553 | } | |
6554 | return Standard_True; | |
6555 | } | |
6556 | ||
58655684 | 6557 | //============================================================================== |
6558 | //function : VGlDebug | |
6559 | //purpose : | |
6560 | //============================================================================== | |
6561 | ||
6562 | static int VGlDebug (Draw_Interpretor& theDI, | |
6563 | Standard_Integer theArgNb, | |
6564 | const char** theArgVec) | |
6565 | { | |
aaf512f1 | 6566 | Handle(OpenGl_GraphicDriver) aDriver; |
6567 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6568 | if (!aView.IsNull()) | |
6569 | { | |
6570 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver()); | |
6571 | } | |
c87535af | 6572 | OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps; |
6573 | OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL; | |
6574 | ||
58655684 | 6575 | if (theArgNb < 2) |
6576 | { | |
c87535af | 6577 | TCollection_AsciiString aDebActive, aSyncActive; |
6578 | if (aCaps == NULL) | |
58655684 | 6579 | { |
c87535af | 6580 | aCaps = aDefCaps; |
6581 | } | |
6582 | else | |
6583 | { | |
6584 | Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS), | |
6585 | "GL_ARB_debug_output"); | |
6586 | aDebActive = isActive ? " (active)" : " (inactive)"; | |
6587 | if (isActive) | |
6588 | { | |
6589 | // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB | |
6590 | aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)"; | |
6591 | } | |
58655684 | 6592 | } |
6593 | ||
84e84755 | 6594 | TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString() |
6595 | + "glslSourceCode: " | |
6596 | + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off | |
6597 | ? "Off" | |
6598 | : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short | |
6599 | ? "Short" | |
6600 | : "Full") | |
6601 | + "\n"; | |
6602 | theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n" | |
6603 | << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n" | |
6604 | << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n" | |
6605 | << aGlslCodeDebugStatus | |
6606 | << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n"; | |
58655684 | 6607 | return 0; |
6608 | } | |
6609 | ||
c87535af | 6610 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
aaf512f1 | 6611 | { |
c87535af | 6612 | Standard_CString anArg = theArgVec[anArgIter]; |
6613 | TCollection_AsciiString anArgCase (anArg); | |
6614 | anArgCase.LowerCase(); | |
6615 | Standard_Boolean toEnableDebug = Standard_True; | |
6616 | if (anArgCase == "-glsl" | |
6617 | || anArgCase == "-glslwarn" | |
6618 | || anArgCase == "-glslwarns" | |
6619 | || anArgCase == "-glslwarnings") | |
6620 | { | |
6621 | Standard_Boolean toShowWarns = Standard_True; | |
6622 | if (++anArgIter < theArgNb | |
a5565a3c | 6623 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns)) |
c87535af | 6624 | { |
6625 | --anArgIter; | |
6626 | } | |
6627 | aDefCaps->glslWarnings = toShowWarns; | |
6628 | if (aCaps != NULL) | |
6629 | { | |
6630 | aCaps->glslWarnings = toShowWarns; | |
6631 | } | |
6632 | } | |
6633 | else if (anArgCase == "-extra" | |
6634 | || anArgCase == "-extramsg" | |
6635 | || anArgCase == "-extramessages") | |
6636 | { | |
6637 | Standard_Boolean toShow = Standard_True; | |
6638 | if (++anArgIter < theArgNb | |
a5565a3c | 6639 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow)) |
c87535af | 6640 | { |
6641 | --anArgIter; | |
6642 | } | |
6643 | aDefCaps->suppressExtraMsg = !toShow; | |
6644 | if (aCaps != NULL) | |
6645 | { | |
6646 | aCaps->suppressExtraMsg = !toShow; | |
6647 | } | |
6648 | } | |
6649 | else if (anArgCase == "-noextra" | |
6650 | || anArgCase == "-noextramsg" | |
6651 | || anArgCase == "-noextramessages") | |
6652 | { | |
6653 | Standard_Boolean toSuppress = Standard_True; | |
6654 | if (++anArgIter < theArgNb | |
a5565a3c | 6655 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress)) |
c87535af | 6656 | { |
6657 | --anArgIter; | |
6658 | } | |
6659 | aDefCaps->suppressExtraMsg = toSuppress; | |
6660 | if (aCaps != NULL) | |
6661 | { | |
6662 | aCaps->suppressExtraMsg = toSuppress; | |
6663 | } | |
6664 | } | |
6665 | else if (anArgCase == "-sync") | |
6666 | { | |
6667 | Standard_Boolean toSync = Standard_True; | |
6668 | if (++anArgIter < theArgNb | |
a5565a3c | 6669 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync)) |
c87535af | 6670 | { |
6671 | --anArgIter; | |
6672 | } | |
6673 | aDefCaps->contextSyncDebug = toSync; | |
6674 | if (toSync) | |
6675 | { | |
6676 | aDefCaps->contextDebug = Standard_True; | |
6677 | } | |
6678 | } | |
84e84755 | 6679 | else if (anArgCase == "-glslsourcecode" |
6680 | || anArgCase == "-glslcode") | |
6681 | { | |
6682 | OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full; | |
6683 | if (++anArgIter < theArgNb | |
6684 | && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel)) | |
6685 | { | |
6686 | --anArgIter; | |
6687 | } | |
6688 | aDefCaps->glslDumpLevel = aGslsDumpLevel; | |
6689 | if (aCaps != NULL) | |
6690 | { | |
6691 | aCaps->glslDumpLevel = aGslsDumpLevel; | |
6692 | } | |
6693 | } | |
c87535af | 6694 | else if (anArgCase == "-debug") |
6695 | { | |
6696 | if (++anArgIter < theArgNb | |
a5565a3c | 6697 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug)) |
c87535af | 6698 | { |
6699 | --anArgIter; | |
6700 | } | |
6701 | aDefCaps->contextDebug = toEnableDebug; | |
6702 | } | |
a5565a3c | 6703 | else if (ViewerTest::ParseOnOff (anArg, toEnableDebug) |
c87535af | 6704 | && (anArgIter + 1 == theArgNb)) |
6705 | { | |
6706 | // simple alias to turn on almost everything | |
6707 | aDefCaps->contextDebug = toEnableDebug; | |
6708 | aDefCaps->contextSyncDebug = toEnableDebug; | |
6709 | aDefCaps->glslWarnings = toEnableDebug; | |
3b4c6945 | 6710 | if (!toEnableDebug) |
6711 | { | |
6712 | aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off; | |
6713 | } | |
84e84755 | 6714 | aDefCaps->suppressExtraMsg = !toEnableDebug; |
6715 | if (aCaps != NULL) | |
6716 | { | |
6717 | aCaps->contextDebug = toEnableDebug; | |
6718 | aCaps->contextSyncDebug = toEnableDebug; | |
6719 | aCaps->glslWarnings = toEnableDebug; | |
3b4c6945 | 6720 | if (!toEnableDebug) |
6721 | { | |
6722 | aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off; | |
6723 | } | |
84e84755 | 6724 | aCaps->suppressExtraMsg = !toEnableDebug; |
6725 | } | |
c87535af | 6726 | } |
6727 | else | |
6728 | { | |
23fe70ec | 6729 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
c87535af | 6730 | return 1; |
6731 | } | |
aaf512f1 | 6732 | } |
6733 | ||
58655684 | 6734 | return 0; |
6735 | } | |
208e6839 | 6736 | |
6737 | //============================================================================== | |
6738 | //function : VVbo | |
6739 | //purpose : | |
6740 | //============================================================================== | |
6741 | ||
58655684 | 6742 | static int VVbo (Draw_Interpretor& theDI, |
208e6839 | 6743 | Standard_Integer theArgNb, |
6744 | const char** theArgVec) | |
6745 | { | |
58655684 | 6746 | const Standard_Boolean toSet = (theArgNb > 1); |
6747 | const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1; | |
6748 | if (toSet) | |
208e6839 | 6749 | { |
58655684 | 6750 | ViewerTest_myDefaultCaps.vboDisable = toUseVbo; |
208e6839 | 6751 | } |
6752 | ||
58655684 | 6753 | // get the context |
6754 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
6755 | if (aContextAIS.IsNull()) | |
208e6839 | 6756 | { |
58655684 | 6757 | if (!toSet) |
6758 | { | |
23fe70ec | 6759 | Message::SendFail ("Error: no active viewer"); |
58655684 | 6760 | } |
208e6839 | 6761 | return 1; |
6762 | } | |
58655684 | 6763 | Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); |
6764 | if (!aDriver.IsNull()) | |
208e6839 | 6765 | { |
58655684 | 6766 | if (!toSet) |
6767 | { | |
6768 | theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n"; | |
6769 | } | |
6770 | else | |
6771 | { | |
6772 | aDriver->ChangeOptions().vboDisable = toUseVbo; | |
6773 | } | |
208e6839 | 6774 | } |
6775 | ||
208e6839 | 6776 | return 0; |
6777 | } | |
6778 | ||
a577aaab | 6779 | //============================================================================== |
6780 | //function : VCaps | |
6781 | //purpose : | |
6782 | //============================================================================== | |
6783 | ||
6784 | static int VCaps (Draw_Interpretor& theDI, | |
6785 | Standard_Integer theArgNb, | |
6786 | const char** theArgVec) | |
6787 | { | |
6788 | OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps; | |
6789 | Handle(OpenGl_GraphicDriver) aDriver; | |
8625ef7e | 6790 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
6791 | if (!aContext.IsNull()) | |
a577aaab | 6792 | { |
8625ef7e | 6793 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver()); |
a577aaab | 6794 | aCaps = &aDriver->ChangeOptions(); |
6795 | } | |
6796 | ||
6797 | if (theArgNb < 2) | |
6798 | { | |
ba00aab7 | 6799 | theDI << "sRGB: " << (aCaps->sRGBDisable ? "0" : "1") << "\n"; |
a577aaab | 6800 | theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n"; |
6801 | theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n"; | |
abe46077 | 6802 | theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n"; |
8625ef7e | 6803 | theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n"; |
2a332745 | 6804 | theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n"; |
f978241f | 6805 | theDI << "VSync: " << aCaps->swapInterval << "\n"; |
4e1523ef | 6806 | theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n"; |
f978241f | 6807 | theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n"; |
56689b27 | 6808 | theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n"; |
59515ca6 | 6809 | theDI << "NoExt:" << (aCaps->contextNoExtensions ? "1" : "0") << "\n"; |
6810 | theDI << "MaxVersion:" << aCaps->contextMajorVersionUpper << "." << aCaps->contextMinorVersionUpper << "\n"; | |
a577aaab | 6811 | return 0; |
6812 | } | |
6813 | ||
8625ef7e | 6814 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
a577aaab | 6815 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
6816 | { | |
8625ef7e | 6817 | Standard_CString anArg = theArgVec[anArgIter]; |
6818 | TCollection_AsciiString anArgCase (anArg); | |
6819 | anArgCase.LowerCase(); | |
6820 | if (anUpdateTool.parseRedrawMode (anArg)) | |
6821 | { | |
6822 | continue; | |
6823 | } | |
f978241f | 6824 | else if (anArgCase == "-vsync" |
6825 | || anArgCase == "-swapinterval") | |
6826 | { | |
6827 | Standard_Boolean toEnable = Standard_True; | |
6828 | if (++anArgIter < theArgNb | |
a5565a3c | 6829 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 6830 | { |
6831 | --anArgIter; | |
6832 | } | |
6833 | aCaps->swapInterval = toEnable; | |
6834 | } | |
8625ef7e | 6835 | else if (anArgCase == "-ffp") |
6836 | { | |
6837 | Standard_Boolean toEnable = Standard_True; | |
6838 | if (++anArgIter < theArgNb | |
a5565a3c | 6839 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6840 | { |
6841 | --anArgIter; | |
6842 | } | |
6843 | aCaps->ffpEnable = toEnable; | |
6844 | } | |
2a332745 | 6845 | else if (anArgCase == "-polygonmode") |
6846 | { | |
6847 | Standard_Boolean toEnable = Standard_True; | |
6848 | if (++anArgIter < theArgNb | |
6849 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
6850 | { | |
6851 | --anArgIter; | |
6852 | } | |
6853 | aCaps->usePolygonMode = toEnable; | |
6854 | } | |
ba00aab7 | 6855 | else if (anArgCase == "-srgb") |
6856 | { | |
6857 | Standard_Boolean toEnable = Standard_True; | |
6858 | if (++anArgIter < theArgNb | |
6859 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
6860 | { | |
6861 | --anArgIter; | |
6862 | } | |
6863 | aCaps->sRGBDisable = !toEnable; | |
6864 | } | |
8625ef7e | 6865 | else if (anArgCase == "-vbo") |
a577aaab | 6866 | { |
8625ef7e | 6867 | Standard_Boolean toEnable = Standard_True; |
6868 | if (++anArgIter < theArgNb | |
a5565a3c | 6869 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6870 | { |
6871 | --anArgIter; | |
6872 | } | |
6873 | aCaps->vboDisable = !toEnable; | |
a577aaab | 6874 | } |
8625ef7e | 6875 | else if (anArgCase == "-sprite" |
6876 | || anArgCase == "-sprites") | |
a577aaab | 6877 | { |
8625ef7e | 6878 | Standard_Boolean toEnable = Standard_True; |
6879 | if (++anArgIter < theArgNb | |
a5565a3c | 6880 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6881 | { |
6882 | --anArgIter; | |
6883 | } | |
6884 | aCaps->pntSpritesDisable = !toEnable; | |
a577aaab | 6885 | } |
8625ef7e | 6886 | else if (anArgCase == "-softmode") |
abe46077 | 6887 | { |
8625ef7e | 6888 | Standard_Boolean toEnable = Standard_True; |
6889 | if (++anArgIter < theArgNb | |
a5565a3c | 6890 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6891 | { |
6892 | --anArgIter; | |
6893 | } | |
6894 | aCaps->contextNoAccel = toEnable; | |
6895 | } | |
56689b27 | 6896 | else if (anArgCase == "-winbuffer" |
6897 | || anArgCase == "-windowbuffer" | |
6898 | || anArgCase == "-usewinbuffer" | |
6899 | || anArgCase == "-usewindowbuffer" | |
6900 | || anArgCase == "-usesystembuffer") | |
6901 | { | |
6902 | Standard_Boolean toEnable = Standard_True; | |
6903 | if (++anArgIter < theArgNb | |
6904 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
6905 | { | |
6906 | --anArgIter; | |
6907 | } | |
6908 | aCaps->useSystemBuffer = toEnable; | |
6909 | } | |
8625ef7e | 6910 | else if (anArgCase == "-accel" |
6911 | || anArgCase == "-acceleration") | |
6912 | { | |
6913 | Standard_Boolean toEnable = Standard_True; | |
6914 | if (++anArgIter < theArgNb | |
a5565a3c | 6915 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6916 | { |
6917 | --anArgIter; | |
6918 | } | |
6919 | aCaps->contextNoAccel = !toEnable; | |
abe46077 | 6920 | } |
4e1523ef | 6921 | else if (anArgCase == "-compat" |
6922 | || anArgCase == "-compatprofile" | |
6923 | || anArgCase == "-compatible" | |
6924 | || anArgCase == "-compatibleprofile") | |
6925 | { | |
6926 | Standard_Boolean toEnable = Standard_True; | |
6927 | if (++anArgIter < theArgNb | |
a5565a3c | 6928 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
4e1523ef | 6929 | { |
6930 | --anArgIter; | |
6931 | } | |
6932 | aCaps->contextCompatible = toEnable; | |
6933 | if (!aCaps->contextCompatible) | |
6934 | { | |
6935 | aCaps->ffpEnable = Standard_False; | |
6936 | } | |
6937 | } | |
6938 | else if (anArgCase == "-core" | |
6939 | || anArgCase == "-coreprofile") | |
6940 | { | |
6941 | Standard_Boolean toEnable = Standard_True; | |
6942 | if (++anArgIter < theArgNb | |
a5565a3c | 6943 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
4e1523ef | 6944 | { |
6945 | --anArgIter; | |
6946 | } | |
6947 | aCaps->contextCompatible = !toEnable; | |
6948 | if (!aCaps->contextCompatible) | |
6949 | { | |
6950 | aCaps->ffpEnable = Standard_False; | |
6951 | } | |
6952 | } | |
f978241f | 6953 | else if (anArgCase == "-stereo" |
6954 | || anArgCase == "-quadbuffer") | |
6955 | { | |
6956 | Standard_Boolean toEnable = Standard_True; | |
6957 | if (++anArgIter < theArgNb | |
a5565a3c | 6958 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 6959 | { |
6960 | --anArgIter; | |
6961 | } | |
6962 | aCaps->contextStereo = toEnable; | |
6963 | } | |
59515ca6 | 6964 | else if (anArgCase == "-noext" |
6965 | || anArgCase == "-noextensions" | |
6966 | || anArgCase == "-noextension") | |
6967 | { | |
6968 | Standard_Boolean toDisable = Standard_True; | |
6969 | if (++anArgIter < theArgNb | |
6970 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable)) | |
6971 | { | |
6972 | --anArgIter; | |
6973 | } | |
6974 | aCaps->contextNoExtensions = toDisable; | |
6975 | } | |
6976 | else if (anArgCase == "-maxversion" | |
6977 | || anArgCase == "-upperversion" | |
6978 | || anArgCase == "-limitversion") | |
6979 | { | |
6980 | Standard_Integer aVer[2] = { -2, -1 }; | |
6981 | for (Standard_Integer aValIter = 0; aValIter < 2; ++aValIter) | |
6982 | { | |
6983 | if (anArgIter + 1 < theArgNb) | |
6984 | { | |
6985 | const TCollection_AsciiString aStr (theArgVec[anArgIter + 1]); | |
6986 | if (aStr.IsIntegerValue()) | |
6987 | { | |
6988 | aVer[aValIter] = aStr.IntegerValue(); | |
6989 | ++anArgIter; | |
6990 | } | |
6991 | } | |
6992 | } | |
6993 | if (aVer[0] < -1 | |
6994 | || aVer[1] < -1) | |
6995 | { | |
23fe70ec | 6996 | Message::SendFail() << "Syntax error at '" << anArgCase << "'"; |
59515ca6 | 6997 | return 1; |
6998 | } | |
6999 | aCaps->contextMajorVersionUpper = aVer[0]; | |
7000 | aCaps->contextMinorVersionUpper = aVer[1]; | |
7001 | } | |
a577aaab | 7002 | else |
7003 | { | |
23fe70ec | 7004 | Message::SendFail() << "Error: unknown argument '" << anArg << "'"; |
8625ef7e | 7005 | return 1; |
a577aaab | 7006 | } |
7007 | } | |
7008 | if (aCaps != &ViewerTest_myDefaultCaps) | |
7009 | { | |
7010 | ViewerTest_myDefaultCaps = *aCaps; | |
7011 | } | |
7012 | return 0; | |
7013 | } | |
7014 | ||
f0430952 | 7015 | //============================================================================== |
7016 | //function : VMemGpu | |
7017 | //purpose : | |
7018 | //============================================================================== | |
7019 | ||
7020 | static int VMemGpu (Draw_Interpretor& theDI, | |
7021 | Standard_Integer theArgNb, | |
7022 | const char** theArgVec) | |
7023 | { | |
7024 | // get the context | |
7025 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
7026 | if (aContextAIS.IsNull()) | |
7027 | { | |
23fe70ec | 7028 | Message::SendFail ("Error: no active viewer"); |
f0430952 | 7029 | return 1; |
7030 | } | |
7031 | ||
dc3fe572 | 7032 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
f0430952 | 7033 | if (aDriver.IsNull()) |
7034 | { | |
23fe70ec | 7035 | Message::SendFail ("Error: graphic driver not available"); |
f0430952 | 7036 | return 1; |
7037 | } | |
7038 | ||
7039 | Standard_Size aFreeBytes = 0; | |
7040 | TCollection_AsciiString anInfo; | |
7041 | if (!aDriver->MemoryInfo (aFreeBytes, anInfo)) | |
7042 | { | |
23fe70ec | 7043 | Message::SendFail ("Error: information not available"); |
f0430952 | 7044 | return 1; |
7045 | } | |
7046 | ||
7047 | if (theArgNb > 1 && *theArgVec[1] == 'f') | |
7048 | { | |
7049 | theDI << Standard_Real (aFreeBytes); | |
7050 | } | |
7051 | else | |
7052 | { | |
7053 | theDI << anInfo; | |
7054 | } | |
7055 | ||
7056 | return 0; | |
7057 | } | |
7058 | ||
85e096c3 | 7059 | // ============================================================================== |
7060 | // function : VReadPixel | |
7061 | // purpose : | |
7062 | // ============================================================================== | |
7063 | static int VReadPixel (Draw_Interpretor& theDI, | |
7064 | Standard_Integer theArgNb, | |
7065 | const char** theArgVec) | |
7066 | { | |
7067 | // get the active view | |
7068 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7069 | if (aView.IsNull()) | |
7070 | { | |
23fe70ec | 7071 | Message::SendFail ("Error: no active viewer"); |
85e096c3 | 7072 | return 1; |
7073 | } | |
7074 | else if (theArgNb < 3) | |
7075 | { | |
23fe70ec | 7076 | Message::SendFail() << "Syntax error: wrong number of arguments.\n" |
7077 | << "Usage: " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"; | |
85e096c3 | 7078 | return 1; |
7079 | } | |
7080 | ||
dc858f4c | 7081 | Image_Format aFormat = Image_Format_RGBA; |
7082 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA; | |
692613e5 | 7083 | |
85e096c3 | 7084 | Standard_Integer aWidth, aHeight; |
7085 | aView->Window()->Size (aWidth, aHeight); | |
91322f44 | 7086 | const Standard_Integer anX = Draw::Atoi (theArgVec[1]); |
7087 | const Standard_Integer anY = Draw::Atoi (theArgVec[2]); | |
85e096c3 | 7088 | if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight) |
7089 | { | |
23fe70ec | 7090 | Message::SendFail() << "Error: pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")"; |
85e096c3 | 7091 | return 1; |
7092 | } | |
7093 | ||
ba00aab7 | 7094 | bool toShowName = false, toShowHls = false, toShowHex = false, toShow_sRGB = false; |
85e096c3 | 7095 | for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) |
7096 | { | |
dc858f4c | 7097 | TCollection_AsciiString aParam (theArgVec[anIter]); |
7098 | aParam.LowerCase(); | |
55c8f0f7 | 7099 | if (aParam == "-rgb" |
ba00aab7 | 7100 | || aParam == "rgb" |
7101 | || aParam == "-srgb" | |
7102 | || aParam == "srgb") | |
85e096c3 | 7103 | { |
dc858f4c | 7104 | aFormat = Image_Format_RGB; |
692613e5 | 7105 | aBufferType = Graphic3d_BT_RGB; |
ba00aab7 | 7106 | toShow_sRGB = aParam == "-srgb" || aParam == "srgb"; |
85e096c3 | 7107 | } |
55c8f0f7 BB |
7108 | else if (aParam == "-hls" |
7109 | || aParam == "hls") | |
85e096c3 | 7110 | { |
dc858f4c | 7111 | aFormat = Image_Format_RGB; |
692613e5 | 7112 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 7113 | toShowHls = Standard_True; |
7114 | } | |
55c8f0f7 BB |
7115 | else if (aParam == "-rgbf" |
7116 | || aParam == "rgbf") | |
85e096c3 | 7117 | { |
dc858f4c | 7118 | aFormat = Image_Format_RGBF; |
692613e5 | 7119 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 7120 | } |
55c8f0f7 | 7121 | else if (aParam == "-rgba" |
ba00aab7 | 7122 | || aParam == "rgba" |
7123 | || aParam == "-srgba" | |
7124 | || aParam == "srgba") | |
85e096c3 | 7125 | { |
dc858f4c | 7126 | aFormat = Image_Format_RGBA; |
692613e5 | 7127 | aBufferType = Graphic3d_BT_RGBA; |
ba00aab7 | 7128 | toShow_sRGB = aParam == "-srgba" || aParam == "srgba"; |
85e096c3 | 7129 | } |
55c8f0f7 BB |
7130 | else if (aParam == "-rgbaf" |
7131 | || aParam == "rgbaf") | |
85e096c3 | 7132 | { |
dc858f4c | 7133 | aFormat = Image_Format_RGBAF; |
692613e5 | 7134 | aBufferType = Graphic3d_BT_RGBA; |
85e096c3 | 7135 | } |
55c8f0f7 BB |
7136 | else if (aParam == "-depth" |
7137 | || aParam == "depth") | |
85e096c3 | 7138 | { |
dc858f4c | 7139 | aFormat = Image_Format_GrayF; |
692613e5 | 7140 | aBufferType = Graphic3d_BT_Depth; |
85e096c3 | 7141 | } |
55c8f0f7 BB |
7142 | else if (aParam == "-name" |
7143 | || aParam == "name") | |
85e096c3 | 7144 | { |
7145 | toShowName = Standard_True; | |
7146 | } | |
9196ea9d | 7147 | else if (aParam == "-hex" |
7148 | || aParam == "hex") | |
7149 | { | |
7150 | toShowHex = Standard_True; | |
7151 | } | |
55c8f0f7 BB |
7152 | else |
7153 | { | |
23fe70ec | 7154 | Message::SendFail() << "Syntax error at '" << aParam << "'"; |
9196ea9d | 7155 | return 1; |
55c8f0f7 | 7156 | } |
85e096c3 | 7157 | } |
7158 | ||
692613e5 | 7159 | Image_PixMap anImage; |
7160 | if (!anImage.InitTrash (aFormat, aWidth, aHeight)) | |
7161 | { | |
23fe70ec | 7162 | Message::SendFail ("Error: image allocation failed"); |
692613e5 | 7163 | return 1; |
7164 | } | |
7165 | else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType)) | |
85e096c3 | 7166 | { |
23fe70ec | 7167 | Message::SendFail ("Error: image dump failed"); |
85e096c3 | 7168 | return 1; |
7169 | } | |
7170 | ||
68beaa3c | 7171 | // redirect possible warning messages that could have been added by ToPixMap |
7172 | // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not | |
7173 | // contaminate result of the command | |
7174 | Standard_CString aWarnLog = theDI.Result(); | |
7175 | if (aWarnLog != NULL && aWarnLog[0] != '\0') | |
7176 | { | |
7177 | std::cout << aWarnLog << std::endl; | |
7178 | } | |
7179 | theDI.Reset(); | |
7180 | ||
ba00aab7 | 7181 | Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY, true); |
85e096c3 | 7182 | if (toShowName) |
7183 | { | |
692613e5 | 7184 | if (aBufferType == Graphic3d_BT_RGBA) |
85e096c3 | 7185 | { |
e958a649 | 7186 | theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha(); |
85e096c3 | 7187 | } |
7188 | else | |
7189 | { | |
e958a649 | 7190 | theDI << Quantity_Color::StringName (aColor.GetRGB().Name()); |
85e096c3 | 7191 | } |
7192 | } | |
9196ea9d | 7193 | else if (toShowHex) |
7194 | { | |
7195 | if (aBufferType == Graphic3d_BT_RGBA) | |
7196 | { | |
7197 | theDI << Quantity_ColorRGBA::ColorToHex (aColor); | |
7198 | } | |
7199 | else | |
7200 | { | |
7201 | theDI << Quantity_Color::ColorToHex (aColor.GetRGB()); | |
7202 | } | |
7203 | } | |
85e096c3 | 7204 | else |
7205 | { | |
7206 | switch (aBufferType) | |
7207 | { | |
7208 | default: | |
692613e5 | 7209 | case Graphic3d_BT_RGB: |
85e096c3 | 7210 | { |
7211 | if (toShowHls) | |
7212 | { | |
e958a649 | 7213 | theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation(); |
85e096c3 | 7214 | } |
ba00aab7 | 7215 | else if (toShow_sRGB) |
7216 | { | |
7217 | const Graphic3d_Vec4 aColor_sRGB = Quantity_ColorRGBA::Convert_LinearRGB_To_sRGB ((Graphic3d_Vec4 )aColor); | |
7218 | theDI << aColor_sRGB.r() << " " << aColor_sRGB.g() << " " << aColor_sRGB.b(); | |
7219 | } | |
85e096c3 | 7220 | else |
7221 | { | |
e958a649 | 7222 | theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue(); |
85e096c3 | 7223 | } |
7224 | break; | |
7225 | } | |
692613e5 | 7226 | case Graphic3d_BT_RGBA: |
85e096c3 | 7227 | { |
ba00aab7 | 7228 | const Graphic3d_Vec4 aVec4 = toShow_sRGB ? Quantity_ColorRGBA::Convert_LinearRGB_To_sRGB ((Graphic3d_Vec4 )aColor) : (Graphic3d_Vec4 )aColor; |
7229 | theDI << aVec4.r() << " " << aVec4.g() << " " << aVec4.b() << " " << aVec4.a(); | |
85e096c3 | 7230 | break; |
7231 | } | |
692613e5 | 7232 | case Graphic3d_BT_Depth: |
85e096c3 | 7233 | { |
e958a649 | 7234 | theDI << aColor.GetRGB().Red(); |
85e096c3 | 7235 | break; |
7236 | } | |
7237 | } | |
7238 | } | |
7239 | ||
7240 | return 0; | |
7241 | } | |
7242 | ||
fd3f6bd0 | 7243 | //! Auxiliary presentation for an image plane. |
7244 | class ViewerTest_ImagePrs : public AIS_InteractiveObject | |
7245 | { | |
7246 | public: | |
7247 | //! Main constructor. | |
7248 | ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage, | |
7249 | const Standard_Real theWidth, | |
7250 | const Standard_Real theHeight, | |
7251 | const TCollection_AsciiString& theLabel) | |
7252 | : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight) | |
7253 | { | |
7254 | SetDisplayMode (0); | |
7255 | SetHilightMode (1); | |
7256 | myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost); | |
7257 | { | |
7258 | myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); | |
7259 | const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect(); | |
7260 | Graphic3d_MaterialAspect aMat; | |
7261 | aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC); | |
61168418 | 7262 | aMat.SetAmbientColor (Quantity_NOC_BLACK); |
7263 | aMat.SetDiffuseColor (Quantity_NOC_WHITE); | |
7264 | aMat.SetSpecularColor (Quantity_NOC_BLACK); | |
7265 | aMat.SetEmissiveColor (Quantity_NOC_BLACK); | |
fd3f6bd0 | 7266 | aFillAspect->SetFrontMaterial (aMat); |
7267 | aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage)); | |
7268 | aFillAspect->SetTextureMapOn(); | |
7269 | } | |
7270 | { | |
7271 | Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect(); | |
7272 | aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER); | |
7273 | aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER); | |
7274 | myDrawer->SetTextAspect (aTextAspect); | |
7275 | } | |
7276 | { | |
7277 | const gp_Dir aNorm (0.0, 0.0, 1.0); | |
7278 | myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true); | |
7279 | myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0)); | |
7280 | myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0)); | |
7281 | myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0)); | |
7282 | myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0)); | |
7283 | myTris->AddEdge (1); | |
7284 | myTris->AddEdge (2); | |
7285 | myTris->AddEdge (3); | |
7286 | myTris->AddEdge (3); | |
7287 | myTris->AddEdge (2); | |
7288 | myTris->AddEdge (4); | |
7289 | ||
7290 | myRect = new Graphic3d_ArrayOfPolylines (4); | |
7291 | myRect->AddVertex (myTris->Vertice (1)); | |
7292 | myRect->AddVertex (myTris->Vertice (3)); | |
7293 | myRect->AddVertex (myTris->Vertice (4)); | |
7294 | myRect->AddVertex (myTris->Vertice (2)); | |
7295 | } | |
7296 | } | |
7297 | ||
7298 | //! Returns TRUE for accepted display modes. | |
7299 | virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; } | |
7300 | ||
7301 | //! Compute presentation. | |
7302 | virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE | |
7303 | { | |
7304 | switch (theMode) | |
7305 | { | |
7306 | case 0: | |
7307 | { | |
7308 | Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); | |
7309 | aGroup->AddPrimitiveArray (myTris); | |
7310 | aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect()); | |
7311 | aGroup->AddPrimitiveArray (myRect); | |
7312 | aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect()); | |
7313 | return; | |
7314 | } | |
7315 | case 1: | |
7316 | { | |
7317 | Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0)); | |
7318 | Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); | |
7319 | aGroup->AddPrimitiveArray (myRect); | |
7320 | aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect()); | |
7321 | return; | |
7322 | } | |
7323 | } | |
7324 | } | |
7325 | ||
7326 | //! Compute selection. | |
7327 | virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE | |
7328 | { | |
7329 | if (theMode == 0) | |
7330 | { | |
7331 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5); | |
7332 | Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner); | |
7333 | aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location()); | |
7334 | theSel->Add (aSensitive); | |
7335 | } | |
7336 | } | |
7337 | ||
7338 | private: | |
7339 | Handle(Graphic3d_ArrayOfTriangles) myTris; | |
7340 | Handle(Graphic3d_ArrayOfPolylines) myRect; | |
7341 | TCollection_AsciiString myLabel; | |
7342 | Standard_Real myWidth; | |
7343 | Standard_Real myHeight; | |
7344 | }; | |
7345 | ||
692613e5 | 7346 | //============================================================================== |
7347 | //function : VDiffImage | |
7348 | //purpose : The draw-command compares two images. | |
7349 | //============================================================================== | |
7350 | ||
7351 | static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
7352 | { | |
fd3f6bd0 | 7353 | if (theArgNb < 3) |
692613e5 | 7354 | { |
23fe70ec | 7355 | Message::SendFail ("Syntax error: not enough arguments"); |
692613e5 | 7356 | return 1; |
7357 | } | |
7358 | ||
fd3f6bd0 | 7359 | Standard_Integer anArgIter = 1; |
7360 | TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]); | |
7361 | TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]); | |
7362 | TCollection_AsciiString aDiffImagePath; | |
7363 | Standard_Real aTolColor = -1.0; | |
7364 | Standard_Integer toBlackWhite = -1; | |
7365 | Standard_Integer isBorderFilterOn = -1; | |
7366 | Standard_Boolean isOldSyntax = Standard_False; | |
7367 | TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff; | |
7368 | for (; anArgIter < theArgNb; ++anArgIter) | |
7369 | { | |
7370 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
7371 | anArg.LowerCase(); | |
7372 | if (anArgIter + 1 < theArgNb | |
7373 | && (anArg == "-toleranceofcolor" | |
7374 | || anArg == "-tolerancecolor" | |
7375 | || anArg == "-tolerance" | |
7376 | || anArg == "-toler")) | |
7377 | { | |
7378 | aTolColor = Atof (theArgVec[++anArgIter]); | |
7379 | if (aTolColor < 0.0 || aTolColor > 1.0) | |
7380 | { | |
23fe70ec | 7381 | Message::SendFail() << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'"; |
fd3f6bd0 | 7382 | return 1; |
7383 | } | |
7384 | } | |
7385 | else if (anArg == "-blackwhite") | |
7386 | { | |
7387 | Standard_Boolean toEnable = Standard_True; | |
7388 | if (anArgIter + 1 < theArgNb | |
7389 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
7390 | { | |
7391 | ++anArgIter; | |
7392 | } | |
7393 | toBlackWhite = toEnable ? 1 : 0; | |
7394 | } | |
7395 | else if (anArg == "-borderfilter") | |
7396 | { | |
7397 | Standard_Boolean toEnable = Standard_True; | |
7398 | if (anArgIter + 1 < theArgNb | |
7399 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
7400 | { | |
7401 | ++anArgIter; | |
7402 | } | |
7403 | isBorderFilterOn = toEnable ? 1 : 0; | |
7404 | } | |
7405 | else if (anArg == "-exitonclose") | |
7406 | { | |
49582f9d | 7407 | ViewerTest_EventManager::ToExitOnCloseView() = true; |
fd3f6bd0 | 7408 | if (anArgIter + 1 < theArgNb |
49582f9d | 7409 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToExitOnCloseView())) |
fd3f6bd0 | 7410 | { |
7411 | ++anArgIter; | |
7412 | } | |
7413 | } | |
7414 | else if (anArg == "-closeonescape" | |
7415 | || anArg == "-closeonesc") | |
7416 | { | |
49582f9d | 7417 | ViewerTest_EventManager::ToCloseViewOnEscape() = true; |
fd3f6bd0 | 7418 | if (anArgIter + 1 < theArgNb |
49582f9d | 7419 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToCloseViewOnEscape())) |
fd3f6bd0 | 7420 | { |
7421 | ++anArgIter; | |
7422 | } | |
7423 | } | |
7424 | else if (anArgIter + 3 < theArgNb | |
7425 | && anArg == "-display") | |
7426 | { | |
7427 | aViewName = theArgVec[++anArgIter]; | |
7428 | aPrsNameRef = theArgVec[++anArgIter]; | |
7429 | aPrsNameNew = theArgVec[++anArgIter]; | |
7430 | if (anArgIter + 1 < theArgNb | |
7431 | && *theArgVec[anArgIter + 1] != '-') | |
7432 | { | |
7433 | aPrsNameDiff = theArgVec[++anArgIter]; | |
7434 | } | |
7435 | } | |
7436 | else if (aTolColor < 0.0 | |
7437 | && anArg.IsRealValue()) | |
7438 | { | |
7439 | isOldSyntax = Standard_True; | |
7440 | aTolColor = anArg.RealValue(); | |
7441 | if (aTolColor < 0.0 || aTolColor > 1.0) | |
7442 | { | |
23fe70ec | 7443 | Message::SendFail() << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'"; |
fd3f6bd0 | 7444 | return 1; |
7445 | } | |
7446 | } | |
7447 | else if (isOldSyntax | |
7448 | && toBlackWhite == -1 | |
7449 | && (anArg == "0" || anArg == "1")) | |
7450 | { | |
7451 | toBlackWhite = anArg == "1" ? 1 : 0; | |
7452 | } | |
7453 | else if (isOldSyntax | |
7454 | && isBorderFilterOn == -1 | |
7455 | && (anArg == "0" || anArg == "1")) | |
7456 | { | |
7457 | isBorderFilterOn = anArg == "1" ? 1 : 0; | |
7458 | } | |
7459 | else if (aDiffImagePath.IsEmpty()) | |
7460 | { | |
7461 | aDiffImagePath = theArgVec[anArgIter]; | |
7462 | } | |
7463 | else | |
7464 | { | |
23fe70ec | 7465 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
fd3f6bd0 | 7466 | return 1; |
7467 | } | |
7468 | } | |
692613e5 | 7469 | |
fd3f6bd0 | 7470 | Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap(); |
7471 | Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap(); | |
7472 | if (!anImgRef->Load (anImgPathRef)) | |
7473 | { | |
23fe70ec | 7474 | Message::SendFail() << "Error: image file '" << anImgPathRef << "' cannot be read"; |
fd3f6bd0 | 7475 | return 1; |
7476 | } | |
7477 | if (!anImgNew->Load (anImgPathNew)) | |
7478 | { | |
23fe70ec | 7479 | Message::SendFail() << "Error: image file '" << anImgPathNew << "' cannot be read"; |
fd3f6bd0 | 7480 | return 1; |
7481 | } | |
692613e5 | 7482 | |
7483 | // compare the images | |
7484 | Image_Diff aComparer; | |
fd3f6bd0 | 7485 | Standard_Integer aDiffColorsNb = -1; |
7486 | if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1)) | |
692613e5 | 7487 | { |
fd3f6bd0 | 7488 | aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0); |
7489 | aComparer.SetBorderFilterOn (isBorderFilterOn == 1); | |
7490 | aDiffColorsNb = aComparer.Compare(); | |
7491 | theDI << aDiffColorsNb << "\n"; | |
692613e5 | 7492 | } |
7493 | ||
692613e5 | 7494 | // save image of difference |
fd3f6bd0 | 7495 | Handle(Image_AlienPixMap) aDiff; |
7496 | if (aDiffColorsNb > 0 | |
7497 | && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty())) | |
7498 | { | |
7499 | aDiff = new Image_AlienPixMap(); | |
7500 | if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY())) | |
7501 | { | |
23fe70ec | 7502 | Message::SendFail() << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY(); |
fd3f6bd0 | 7503 | return 1; |
7504 | } | |
7505 | aComparer.SaveDiffImage (*aDiff); | |
7506 | if (!aDiffImagePath.IsEmpty() | |
7507 | && !aDiff->Save (aDiffImagePath)) | |
7508 | { | |
23fe70ec | 7509 | Message::SendFail() << "Error: diff image file '" << aDiffImagePath << "' cannot be written"; |
fd3f6bd0 | 7510 | return 1; |
7511 | } | |
7512 | } | |
7513 | ||
7514 | if (aViewName.IsEmpty()) | |
7515 | { | |
7516 | return 0; | |
7517 | } | |
7518 | ||
7519 | ViewerTest_Names aViewNames (aViewName); | |
7520 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) | |
7521 | { | |
7522 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName(); | |
7523 | theDI.Eval (aCommand.ToCString()); | |
7524 | } | |
7525 | ||
7526 | Standard_Integer aPxLeft = 0; | |
7527 | Standard_Integer aPxTop = 0; | |
7528 | Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2); | |
7529 | Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty() | |
7530 | ? int(anImgRef->SizeY() * 2) | |
7531 | : int(anImgRef->SizeY()); | |
7532 | TCollection_AsciiString aDisplayName; | |
9e04ccdc | 7533 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY, |
7534 | aViewName, aDisplayName); | |
fd3f6bd0 | 7535 | |
7536 | Standard_Real aRatio = anImgRef->Ratio(); | |
7537 | Standard_Real aSizeX = 1.0; | |
7538 | Standard_Real aSizeY = aSizeX / aRatio; | |
692613e5 | 7539 | { |
fd3f6bd0 | 7540 | OSD_Path aPath (anImgPathRef); |
7541 | TCollection_AsciiString aLabelRef; | |
7542 | if (!aPath.Name().IsEmpty()) | |
7543 | { | |
7544 | aLabelRef = aPath.Name() + aPath.Extension(); | |
7545 | } | |
7546 | aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY()); | |
7547 | ||
7548 | Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef); | |
7549 | gp_Trsf aTrsfRef; | |
7550 | aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0)); | |
7551 | anImgRefPrs->SetLocalTransformation (aTrsfRef); | |
7552 | ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true); | |
692613e5 | 7553 | } |
fd3f6bd0 | 7554 | { |
7555 | OSD_Path aPath (anImgPathNew); | |
7556 | TCollection_AsciiString aLabelNew; | |
7557 | if (!aPath.Name().IsEmpty()) | |
7558 | { | |
7559 | aLabelNew = aPath.Name() + aPath.Extension(); | |
7560 | } | |
7561 | aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY()); | |
692613e5 | 7562 | |
fd3f6bd0 | 7563 | Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew); |
7564 | gp_Trsf aTrsfRef; | |
7565 | aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0)); | |
7566 | anImgNewPrs->SetLocalTransformation (aTrsfRef); | |
7567 | ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true); | |
7568 | } | |
7569 | Handle(ViewerTest_ImagePrs) anImgDiffPrs; | |
7570 | if (!aDiff.IsNull()) | |
7571 | { | |
7572 | anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels"); | |
7573 | gp_Trsf aTrsfDiff; | |
7574 | aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0)); | |
7575 | anImgDiffPrs->SetLocalTransformation (aTrsfDiff); | |
7576 | } | |
7577 | if (!aPrsNameDiff.IsEmpty()) | |
7578 | { | |
7579 | ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true); | |
7580 | } | |
7581 | ViewerTest::CurrentView()->SetProj (V3d_Zpos); | |
7582 | ViewerTest::CurrentView()->FitAll(); | |
692613e5 | 7583 | return 0; |
7584 | } | |
7585 | ||
4754e164 | 7586 | //======================================================================= |
7587 | //function : VSelect | |
7588 | //purpose : Emulates different types of selection by mouse: | |
7589 | // 1) single click selection | |
7590 | // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) | |
7591 | // 3) selection with polygon having corners at | |
dc3fe572 | 7592 | // pixel positions (x1,y1),...,(xn,yn) |
4754e164 | 7593 | // 4) any of these selections with shift button pressed |
7594 | //======================================================================= | |
49582f9d | 7595 | static Standard_Integer VSelect (Draw_Interpretor& , |
7596 | Standard_Integer theNbArgs, | |
7597 | const char** theArgVec) | |
4754e164 | 7598 | { |
49582f9d | 7599 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
7600 | if (aCtx.IsNull()) | |
4754e164 | 7601 | { |
23fe70ec | 7602 | Message::SendFail ("Error: no active viewer"); |
4754e164 | 7603 | return 1; |
7604 | } | |
2157d6ac | 7605 | |
49582f9d | 7606 | NCollection_Sequence<Graphic3d_Vec2i> aPnts; |
7607 | bool isShiftSelection = false, toAllowOverlap = false; | |
7608 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
2157d6ac | 7609 | { |
49582f9d | 7610 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
7611 | anArg.LowerCase(); | |
7612 | if (anArg == "-allowoverlap") | |
7613 | { | |
7614 | toAllowOverlap = true; | |
7615 | if (anArgIter + 1 < theNbArgs | |
7616 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toAllowOverlap)) | |
7617 | { | |
7618 | ++anArgIter; | |
7619 | } | |
7620 | } | |
7621 | else if (anArgIter + 1 < theNbArgs | |
7622 | && anArg.IsIntegerValue() | |
7623 | && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue()) | |
2157d6ac | 7624 | { |
49582f9d | 7625 | const TCollection_AsciiString anArgNext (theArgVec[++anArgIter]); |
7626 | aPnts.Append (Graphic3d_Vec2i (anArg.IntegerValue(), anArgNext.IntegerValue())); | |
7627 | } | |
7628 | else if (anArgIter + 1 == theNbArgs | |
7629 | && anArg.IsIntegerValue()) | |
7630 | { | |
7631 | isShiftSelection = anArg.IntegerValue() == 1; | |
7632 | } | |
7633 | else | |
7634 | { | |
23fe70ec | 7635 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
2157d6ac | 7636 | return 1; |
7637 | } | |
49582f9d | 7638 | } |
a24a7821 | 7639 | |
49582f9d | 7640 | if (toAllowOverlap) |
7641 | { | |
7642 | aCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap); | |
2157d6ac | 7643 | } |
7644 | ||
4754e164 | 7645 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); |
49582f9d | 7646 | if (aPnts.IsEmpty()) |
4754e164 | 7647 | { |
49582f9d | 7648 | if (isShiftSelection) |
7649 | { | |
7650 | aCtx->ShiftSelect (false); | |
7651 | } | |
4754e164 | 7652 | else |
49582f9d | 7653 | { |
7654 | aCtx->Select (false); | |
7655 | } | |
7656 | aCtx->CurrentViewer()->Invalidate(); | |
4754e164 | 7657 | } |
49582f9d | 7658 | else if (aPnts.Length() == 2) |
4754e164 | 7659 | { |
49582f9d | 7660 | if (toAllowOverlap |
7661 | && aPnts.First().y() < aPnts.Last().y()) | |
7662 | { | |
7663 | std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast()); | |
7664 | } | |
7665 | else if (!toAllowOverlap | |
7666 | && aPnts.First().y() > aPnts.Last().y()) | |
7667 | { | |
7668 | std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast()); | |
7669 | } | |
7670 | aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection); | |
4754e164 | 7671 | } |
7672 | else | |
7673 | { | |
49582f9d | 7674 | aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection); |
4754e164 | 7675 | } |
49582f9d | 7676 | aCurrentEventManager->FlushViewEvents (aCtx, ViewerTest::CurrentView(), true); |
4754e164 | 7677 | return 0; |
7678 | } | |
7679 | ||
7680 | //======================================================================= | |
7681 | //function : VMoveTo | |
dc3fe572 | 7682 | //purpose : Emulates cursor movement to defined pixel position |
4754e164 | 7683 | //======================================================================= |
1e756cb9 | 7684 | static Standard_Integer VMoveTo (Draw_Interpretor& theDI, |
8a590580 | 7685 | Standard_Integer theNbArgs, |
7686 | const char** theArgVec) | |
4754e164 | 7687 | { |
8a590580 | 7688 | const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext(); |
7689 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
7690 | if (aContext.IsNull()) | |
4754e164 | 7691 | { |
23fe70ec | 7692 | Message::SendFail ("Error: no active viewer"); |
4754e164 | 7693 | return 1; |
7694 | } | |
7695 | ||
8a590580 | 7696 | Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast()); |
7697 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
4754e164 | 7698 | { |
8a590580 | 7699 | TCollection_AsciiString anArgStr (theArgVec[anArgIter]); |
7700 | anArgStr.LowerCase(); | |
7701 | if (anArgStr == "-reset" | |
7702 | || anArgStr == "-clear") | |
7703 | { | |
7704 | if (anArgIter + 1 < theNbArgs) | |
7705 | { | |
23fe70ec | 7706 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter + 1] << "'"; |
8a590580 | 7707 | return 1; |
7708 | } | |
7709 | ||
7710 | const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive() | |
7711 | && aContext->CurrentViewer()->GridEcho(); | |
7712 | if (toEchoGrid) | |
7713 | { | |
7714 | aContext->CurrentViewer()->HideGridEcho (aView); | |
7715 | } | |
7716 | if (aContext->ClearDetected() || toEchoGrid) | |
7717 | { | |
7718 | aContext->CurrentViewer()->RedrawImmediate(); | |
7719 | } | |
7720 | return 0; | |
7721 | } | |
7722 | else if (aMousePos.x() == IntegerLast() | |
7723 | && anArgStr.IsIntegerValue()) | |
7724 | { | |
7725 | aMousePos.x() = anArgStr.IntegerValue(); | |
7726 | } | |
7727 | else if (aMousePos.y() == IntegerLast() | |
7728 | && anArgStr.IsIntegerValue()) | |
7729 | { | |
7730 | aMousePos.y() = anArgStr.IntegerValue(); | |
7731 | } | |
7732 | else | |
7733 | { | |
23fe70ec | 7734 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
8a590580 | 7735 | return 1; |
7736 | } | |
7737 | } | |
7738 | ||
7739 | if (aMousePos.x() == IntegerLast() | |
7740 | || aMousePos.y() == IntegerLast()) | |
7741 | { | |
23fe70ec | 7742 | Message::SendFail ("Syntax error: wrong number of arguments"); |
4754e164 | 7743 | return 1; |
7744 | } | |
8a590580 | 7745 | |
49582f9d | 7746 | ViewerTest::CurrentEventManager()->ResetPreviousMoveTo(); |
7747 | ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false); | |
7748 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true); | |
7749 | ||
1e756cb9 | 7750 | gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast()); |
7751 | const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner(); | |
7752 | for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter) | |
7753 | { | |
7754 | if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner) | |
7755 | { | |
7756 | aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter); | |
7757 | break; | |
7758 | } | |
7759 | } | |
7760 | theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z(); | |
4754e164 | 7761 | return 0; |
7762 | } | |
7763 | ||
1beb58d7 | 7764 | namespace |
7765 | { | |
7766 | //! Global map storing all animations registered in ViewerTest. | |
7767 | static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap; | |
7768 | ||
7769 | //! The animation calling the Draw Harness command. | |
7770 | class ViewerTest_AnimationProc : public AIS_Animation | |
7771 | { | |
7772 | public: | |
7773 | ||
7774 | //! Main constructor. | |
7775 | ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName, | |
7776 | Draw_Interpretor* theDI, | |
7777 | const TCollection_AsciiString& theCommand) | |
7778 | : AIS_Animation (theAnimationName), | |
7779 | myDrawInter(theDI), | |
7780 | myCommand (theCommand) | |
7781 | { | |
7782 | // | |
7783 | } | |
7784 | ||
7785 | protected: | |
7786 | ||
7787 | //! Evaluate the command. | |
7788 | virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE | |
7789 | { | |
7790 | TCollection_AsciiString aCmd = myCommand; | |
7791 | replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts)); | |
7792 | replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts)); | |
7793 | replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts)); | |
7794 | replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized)); | |
7795 | replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized)); | |
7796 | myDrawInter->Eval (aCmd.ToCString()); | |
7797 | } | |
7798 | ||
7799 | //! Find the keyword in the command and replace it with value. | |
7800 | //! @return the position of the keyword to pass value | |
7801 | void replace (TCollection_AsciiString& theCmd, | |
7802 | const TCollection_AsciiString& theKey, | |
7803 | const TCollection_AsciiString& theVal) | |
7804 | { | |
7805 | TCollection_AsciiString aCmd (theCmd); | |
7806 | aCmd.LowerCase(); | |
7807 | const Standard_Integer aPos = aCmd.Search (theKey); | |
7808 | if (aPos == -1) | |
7809 | { | |
7810 | return; | |
7811 | } | |
7812 | ||
7813 | TCollection_AsciiString aPart1, aPart2; | |
7814 | Standard_Integer aPart1To = aPos - 1; | |
7815 | if (aPart1To >= 1 | |
7816 | && aPart1To <= theCmd.Length()) | |
7817 | { | |
7818 | aPart1 = theCmd.SubString (1, aPart1To); | |
7819 | } | |
7820 | ||
7821 | Standard_Integer aPart2From = aPos + theKey.Length(); | |
7822 | if (aPart2From >= 1 | |
7823 | && aPart2From <= theCmd.Length()) | |
7824 | { | |
7825 | aPart2 = theCmd.SubString (aPart2From, theCmd.Length()); | |
7826 | } | |
7827 | ||
7828 | theCmd = aPart1 + theVal + aPart2; | |
7829 | } | |
7830 | ||
7831 | protected: | |
7832 | ||
7833 | Draw_Interpretor* myDrawInter; | |
7834 | TCollection_AsciiString myCommand; | |
7835 | ||
7836 | }; | |
7837 | ||
7838 | //! Replace the animation with the new one. | |
7839 | static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation, | |
7840 | Handle(AIS_Animation)& theAnimation, | |
7841 | const Handle(AIS_Animation)& theAnimationNew) | |
7842 | { | |
7843 | theAnimationNew->CopyFrom (theAnimation); | |
7844 | if (!theParentAnimation.IsNull()) | |
7845 | { | |
7846 | theParentAnimation->Replace (theAnimation, theAnimationNew); | |
7847 | } | |
7848 | else | |
7849 | { | |
7850 | ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name()); | |
7851 | ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew); | |
7852 | } | |
7853 | theAnimation = theAnimationNew; | |
7854 | } | |
7855 | ||
7856 | //! Parse the point. | |
7857 | static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt) | |
7858 | { | |
7859 | const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] }; | |
7860 | if (!anXYZ[0].IsRealValue() | |
7861 | || !anXYZ[1].IsRealValue() | |
7862 | || !anXYZ[2].IsRealValue()) | |
7863 | { | |
7864 | return Standard_False; | |
7865 | } | |
7866 | ||
7867 | thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue()); | |
7868 | return Standard_True; | |
7869 | } | |
7870 | ||
7871 | //! Parse the quaternion. | |
7872 | static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot) | |
7873 | { | |
7874 | const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]}; | |
7875 | if (!anXYZW[0].IsRealValue() | |
7876 | || !anXYZW[1].IsRealValue() | |
7877 | || !anXYZW[2].IsRealValue() | |
7878 | || !anXYZW[3].IsRealValue()) | |
7879 | { | |
7880 | return Standard_False; | |
7881 | } | |
7882 | ||
7883 | theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue()); | |
7884 | return Standard_True; | |
7885 | } | |
7886 | ||
08f8a185 | 7887 | //! Auxiliary class for flipping image upside-down. |
7888 | class ImageFlipper | |
7889 | { | |
7890 | public: | |
7891 | ||
7892 | //! Empty constructor. | |
7893 | ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {} | |
7894 | ||
7895 | //! Perform flipping. | |
7896 | Standard_Boolean FlipY (Image_PixMap& theImage) | |
7897 | { | |
7898 | if (theImage.IsEmpty() | |
7899 | || theImage.SizeX() == 0 | |
7900 | || theImage.SizeY() == 0) | |
7901 | { | |
7902 | return Standard_False; | |
7903 | } | |
7904 | ||
7905 | const Standard_Size aRowSize = theImage.SizeRowBytes(); | |
7906 | if (myTmp.Size() < aRowSize | |
7907 | && !myTmp.Allocate (aRowSize)) | |
7908 | { | |
7909 | return Standard_False; | |
7910 | } | |
7911 | ||
7912 | // for odd height middle row should be left as is | |
7913 | Standard_Size aNbRowsHalf = theImage.SizeY() / 2; | |
7914 | for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB) | |
7915 | { | |
7916 | Standard_Byte* aTop = theImage.ChangeRow (aRowT); | |
7917 | Standard_Byte* aBot = theImage.ChangeRow (aRowB); | |
7918 | memcpy (myTmp.ChangeData(), aTop, aRowSize); | |
7919 | memcpy (aTop, aBot, aRowSize); | |
7920 | memcpy (aBot, myTmp.Data(), aRowSize); | |
7921 | } | |
7922 | return Standard_True; | |
7923 | } | |
7924 | ||
7925 | private: | |
7926 | NCollection_Buffer myTmp; | |
7927 | }; | |
7928 | ||
1beb58d7 | 7929 | } |
7930 | ||
197ac94e | 7931 | //================================================================================================= |
4754e164 | 7932 | //function : VViewParams |
dc3fe572 | 7933 | //purpose : Gets or sets AIS View characteristics |
197ac94e | 7934 | //================================================================================================= |
7935 | static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
4754e164 | 7936 | { |
1beb58d7 | 7937 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
7938 | if (aView.IsNull()) | |
4754e164 | 7939 | { |
23fe70ec | 7940 | Message::SendFail ("Error: no active viewer"); |
4754e164 | 7941 | return 1; |
7942 | } | |
197ac94e | 7943 | |
1beb58d7 | 7944 | Standard_Boolean toSetProj = Standard_False; |
7945 | Standard_Boolean toSetUp = Standard_False; | |
7946 | Standard_Boolean toSetAt = Standard_False; | |
7947 | Standard_Boolean toSetEye = Standard_False; | |
7948 | Standard_Boolean toSetScale = Standard_False; | |
7949 | Standard_Boolean toSetSize = Standard_False; | |
7950 | Standard_Boolean toSetCenter2d = Standard_False; | |
ee2be2a8 | 7951 | Standard_Real aViewScale = aView->Scale(); |
7952 | Standard_Real aViewSize = 1.0; | |
1beb58d7 | 7953 | Graphic3d_Vec2i aCenter2d; |
7954 | gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye; | |
7955 | aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3)); | |
7956 | aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3)); | |
7957 | aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3)); | |
7958 | aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3)); | |
197ac94e | 7959 | if (theArgsNb == 1) |
4754e164 | 7960 | { |
197ac94e | 7961 | // print all of the available view parameters |
1beb58d7 | 7962 | char aText[4096]; |
7963 | Sprintf (aText, | |
7964 | "Scale: %g\n" | |
7965 | "Proj: %12g %12g %12g\n" | |
7966 | "Up: %12g %12g %12g\n" | |
7967 | "At: %12g %12g %12g\n" | |
7968 | "Eye: %12g %12g %12g\n", | |
7969 | aViewScale, | |
7970 | aViewProj.X(), aViewProj.Y(), aViewProj.Z(), | |
7971 | aViewUp.X(), aViewUp.Y(), aViewUp.Z(), | |
7972 | aViewAt.X(), aViewAt.Y(), aViewAt.Z(), | |
7973 | aViewEye.X(), aViewEye.Y(), aViewEye.Z()); | |
7974 | theDi << aText; | |
197ac94e | 7975 | return 0; |
4754e164 | 7976 | } |
197ac94e | 7977 | |
1beb58d7 | 7978 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
7979 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
197ac94e | 7980 | { |
1beb58d7 | 7981 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
7982 | anArg.LowerCase(); | |
7983 | if (anUpdateTool.parseRedrawMode (anArg)) | |
197ac94e | 7984 | { |
197ac94e | 7985 | continue; |
7986 | } | |
1beb58d7 | 7987 | else if (anArg == "-cmd" |
7988 | || anArg == "-command" | |
7989 | || anArg == "-args") | |
7990 | { | |
7991 | char aText[4096]; | |
7992 | Sprintf (aText, | |
7993 | "-scale %g " | |
7994 | "-proj %g %g %g " | |
7995 | "-up %g %g %g " | |
7996 | "-at %g %g %g\n", | |
7997 | aViewScale, | |
7998 | aViewProj.X(), aViewProj.Y(), aViewProj.Z(), | |
7999 | aViewUp.X(), aViewUp.Y(), aViewUp.Z(), | |
8000 | aViewAt.X(), aViewAt.Y(), aViewAt.Z()); | |
8001 | theDi << aText; | |
8002 | } | |
8003 | else if (anArg == "-scale" | |
8004 | || anArg == "-size") | |
8005 | { | |
8006 | if (anArgIter + 1 < theArgsNb | |
8007 | && *theArgVec[anArgIter + 1] != '-') | |
8008 | { | |
8009 | const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]); | |
8010 | if (aValueArg.IsRealValue()) | |
8011 | { | |
8012 | ++anArgIter; | |
8013 | if (anArg == "-scale") | |
8014 | { | |
8015 | toSetScale = Standard_True; | |
8016 | aViewScale = aValueArg.RealValue(); | |
8017 | } | |
8018 | else if (anArg == "-size") | |
8019 | { | |
8020 | toSetSize = Standard_True; | |
8021 | aViewSize = aValueArg.RealValue(); | |
8022 | } | |
8023 | continue; | |
8024 | } | |
8025 | } | |
8026 | if (anArg == "-scale") | |
8027 | { | |
8028 | theDi << "Scale: " << aView->Scale() << "\n"; | |
8029 | } | |
8030 | else if (anArg == "-size") | |
8031 | { | |
8032 | Graphic3d_Vec2d aSizeXY; | |
8033 | aView->Size (aSizeXY.x(), aSizeXY.y()); | |
8034 | theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n"; | |
8035 | } | |
8036 | } | |
8037 | else if (anArg == "-eye" | |
8038 | || anArg == "-at" | |
8039 | || anArg == "-up" | |
8040 | || anArg == "-proj") | |
8041 | { | |
8042 | if (anArgIter + 3 < theArgsNb) | |
8043 | { | |
8044 | gp_XYZ anXYZ; | |
8045 | if (parseXYZ (theArgVec + anArgIter + 1, anXYZ)) | |
8046 | { | |
8047 | anArgIter += 3; | |
8048 | if (anArg == "-eye") | |
8049 | { | |
8050 | toSetEye = Standard_True; | |
8051 | aViewEye = anXYZ; | |
8052 | } | |
8053 | else if (anArg == "-at") | |
8054 | { | |
8055 | toSetAt = Standard_True; | |
8056 | aViewAt = anXYZ; | |
8057 | } | |
8058 | else if (anArg == "-up") | |
8059 | { | |
8060 | toSetUp = Standard_True; | |
8061 | aViewUp = anXYZ; | |
8062 | } | |
8063 | else if (anArg == "-proj") | |
8064 | { | |
8065 | toSetProj = Standard_True; | |
8066 | aViewProj = anXYZ; | |
8067 | } | |
8068 | continue; | |
8069 | } | |
8070 | } | |
197ac94e | 8071 | |
1beb58d7 | 8072 | if (anArg == "-eye") |
8073 | { | |
8074 | theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n"; | |
8075 | } | |
8076 | else if (anArg == "-at") | |
8077 | { | |
8078 | theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n"; | |
8079 | } | |
8080 | else if (anArg == "-up") | |
8081 | { | |
8082 | theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n"; | |
8083 | } | |
8084 | else if (anArg == "-proj") | |
8085 | { | |
8086 | theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n"; | |
8087 | } | |
8088 | } | |
8089 | else if (anArg == "-center") | |
3dfe95cd | 8090 | { |
1beb58d7 | 8091 | if (anArgIter + 2 < theArgsNb) |
8092 | { | |
8093 | const TCollection_AsciiString anX (theArgVec[anArgIter + 1]); | |
8094 | const TCollection_AsciiString anY (theArgVec[anArgIter + 2]); | |
8095 | if (anX.IsIntegerValue() | |
8096 | && anY.IsIntegerValue()) | |
8097 | { | |
8098 | toSetCenter2d = Standard_True; | |
8099 | aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()); | |
8100 | } | |
8101 | } | |
8102 | } | |
8103 | else | |
8104 | { | |
23fe70ec | 8105 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
3dfe95cd | 8106 | return 1; |
8107 | } | |
1beb58d7 | 8108 | } |
3dfe95cd | 8109 | |
1beb58d7 | 8110 | // change view parameters in proper order |
8111 | if (toSetScale) | |
8112 | { | |
8113 | aView->SetScale (aViewScale); | |
8114 | } | |
8115 | if (toSetSize) | |
8116 | { | |
8117 | aView->SetSize (aViewSize); | |
8118 | } | |
8119 | if (toSetEye) | |
8120 | { | |
8121 | aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z()); | |
8122 | } | |
8123 | if (toSetAt) | |
8124 | { | |
8125 | aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z()); | |
8126 | } | |
8127 | if (toSetProj) | |
8128 | { | |
8129 | aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z()); | |
8130 | } | |
8131 | if (toSetUp) | |
8132 | { | |
8133 | aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z()); | |
8134 | } | |
8135 | if (toSetCenter2d) | |
8136 | { | |
8137 | aView->SetCenter (aCenter2d.x(), aCenter2d.y()); | |
197ac94e | 8138 | } |
8139 | ||
1beb58d7 | 8140 | return 0; |
8141 | } | |
197ac94e | 8142 | |
2e93433e | 8143 | //============================================================================== |
8144 | //function : V2DMode | |
8145 | //purpose : | |
8146 | //============================================================================== | |
8147 | static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec) | |
8148 | { | |
8149 | bool is2dMode = true; | |
8150 | Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()); | |
8151 | if (aV3dView.IsNull()) | |
8152 | { | |
23fe70ec | 8153 | Message::SendFail ("Error: no active viewer"); |
2e93433e | 8154 | return 1; |
8155 | } | |
8156 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
8157 | { | |
8158 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; | |
8159 | TCollection_AsciiString anArgCase = anArg; | |
8160 | anArgCase.LowerCase(); | |
8161 | if (anArgIt + 1 < theArgsNb | |
8162 | && anArgCase == "-name") | |
8163 | { | |
8164 | ViewerTest_Names aViewNames (theArgVec[++anArgIt]); | |
8165 | TCollection_AsciiString aViewName = aViewNames.GetViewName(); | |
8166 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
8167 | { | |
23fe70ec | 8168 | Message::SendFail() << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'"; |
2e93433e | 8169 | return 1; |
8170 | } | |
8171 | aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName)); | |
8172 | } | |
8173 | else if (anArgCase == "-mode") | |
8174 | { | |
8175 | if (anArgIt + 1 < theArgsNb | |
8176 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode)) | |
8177 | { | |
8178 | ++anArgIt; | |
8179 | } | |
8180 | } | |
8181 | else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode)) | |
8182 | { | |
8183 | // | |
8184 | } | |
8185 | else | |
8186 | { | |
23fe70ec | 8187 | Message::SendFail() << "Syntax error: unknown argument " << anArg; |
2e93433e | 8188 | return 1; |
8189 | } | |
8190 | } | |
8191 | ||
8192 | aV3dView->SetView2DMode (is2dMode); | |
8193 | return 0; | |
8194 | } | |
8195 | ||
1beb58d7 | 8196 | //============================================================================== |
8197 | //function : VAnimation | |
8198 | //purpose : | |
8199 | //============================================================================== | |
8200 | static Standard_Integer VAnimation (Draw_Interpretor& theDI, | |
8201 | Standard_Integer theArgNb, | |
8202 | const char** theArgVec) | |
8203 | { | |
8204 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
8205 | if (theArgNb < 2) | |
4754e164 | 8206 | { |
1beb58d7 | 8207 | for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator |
8208 | anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next()) | |
8209 | { | |
8210 | theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n"; | |
197ac94e | 8211 | } |
1beb58d7 | 8212 | return 0; |
8213 | } | |
8214 | if (aCtx.IsNull()) | |
8215 | { | |
23fe70ec | 8216 | Message::SendFail ("Error: no active viewer"); |
1beb58d7 | 8217 | return 1; |
4754e164 | 8218 | } |
197ac94e | 8219 | |
1beb58d7 | 8220 | Standard_Integer anArgIter = 1; |
8221 | TCollection_AsciiString aNameArg (theArgVec[anArgIter++]); | |
8222 | if (aNameArg.IsEmpty()) | |
8223 | { | |
23fe70ec | 8224 | Message::SendFail ("Syntax error: animation name is not defined"); |
1beb58d7 | 8225 | return 1; |
8226 | } | |
8227 | ||
8228 | TCollection_AsciiString aNameArgLower = aNameArg; | |
8229 | aNameArgLower.LowerCase(); | |
8230 | if (aNameArgLower == "-reset" | |
8231 | || aNameArgLower == "-clear") | |
8232 | { | |
8233 | ViewerTest_AnimationTimelineMap.Clear(); | |
8234 | return 0; | |
8235 | } | |
8236 | else if (aNameArg.Value (1) == '-') | |
8237 | { | |
23fe70ec | 8238 | Message::SendFail() << "Syntax error: invalid animation name '" << aNameArg << "'"; |
1beb58d7 | 8239 | return 1; |
8240 | } | |
197ac94e | 8241 | |
1beb58d7 | 8242 | const char* aNameSplitter = "/"; |
8243 | Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter); | |
8244 | if (aSplitPos == -1) | |
197ac94e | 8245 | { |
1beb58d7 | 8246 | aNameSplitter = "."; |
8247 | aSplitPos = aNameArg.Search (aNameSplitter); | |
8248 | } | |
8249 | ||
8250 | // find existing or create a new animation by specified name within syntax "parent.child". | |
8251 | Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation; | |
8252 | for (; !aNameArg.IsEmpty();) | |
8253 | { | |
8254 | TCollection_AsciiString aNameParent; | |
8255 | if (aSplitPos != -1) | |
197ac94e | 8256 | { |
1beb58d7 | 8257 | if (aSplitPos == aNameArg.Length()) |
8258 | { | |
23fe70ec | 8259 | Message::SendFail ("Syntax error: animation name is not defined"); |
1beb58d7 | 8260 | return 1; |
8261 | } | |
8262 | ||
8263 | aNameParent = aNameArg.SubString ( 1, aSplitPos - 1); | |
8264 | aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length()); | |
8265 | ||
8266 | aSplitPos = aNameArg.Search (aNameSplitter); | |
197ac94e | 8267 | } |
8268 | else | |
8269 | { | |
1beb58d7 | 8270 | aNameParent = aNameArg; |
8271 | aNameArg.Clear(); | |
197ac94e | 8272 | } |
1beb58d7 | 8273 | |
8274 | if (anAnimation.IsNull()) | |
3dfe95cd | 8275 | { |
1beb58d7 | 8276 | if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation)) |
8277 | { | |
8278 | anAnimation = new AIS_Animation (aNameParent); | |
8279 | ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation); | |
8280 | } | |
8281 | aRootAnimation = anAnimation; | |
3dfe95cd | 8282 | } |
8283 | else | |
8284 | { | |
1beb58d7 | 8285 | aParentAnimation = anAnimation; |
8286 | anAnimation = aParentAnimation->Find (aNameParent); | |
8287 | if (anAnimation.IsNull()) | |
8288 | { | |
8289 | anAnimation = new AIS_Animation (aNameParent); | |
8290 | aParentAnimation->Add (anAnimation); | |
8291 | } | |
3dfe95cd | 8292 | } |
8293 | } | |
1beb58d7 | 8294 | |
8295 | if (anArgIter >= theArgNb) | |
197ac94e | 8296 | { |
1beb58d7 | 8297 | // just print the list of children |
8298 | for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next()) | |
197ac94e | 8299 | { |
1beb58d7 | 8300 | theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n"; |
197ac94e | 8301 | } |
1beb58d7 | 8302 | return 0; |
197ac94e | 8303 | } |
1beb58d7 | 8304 | |
bf7b2ceb | 8305 | // animation parameters |
1beb58d7 | 8306 | Standard_Boolean toPlay = Standard_False; |
8307 | Standard_Real aPlaySpeed = 1.0; | |
8308 | Standard_Real aPlayStartTime = anAnimation->StartPts(); | |
8309 | Standard_Real aPlayDuration = anAnimation->Duration(); | |
1beb58d7 | 8310 | Standard_Boolean isFreeCamera = Standard_False; |
8311 | Standard_Boolean isLockLoop = Standard_False; | |
08f8a185 | 8312 | |
8313 | // video recording parameters | |
8314 | TCollection_AsciiString aRecFile; | |
8315 | Image_VideoParams aRecParams; | |
8316 | ||
1beb58d7 | 8317 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
8318 | for (; anArgIter < theArgNb; ++anArgIter) | |
197ac94e | 8319 | { |
1beb58d7 | 8320 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
8321 | anArg.LowerCase(); | |
bf7b2ceb | 8322 | // general options |
1beb58d7 | 8323 | if (anArg == "-reset" |
8324 | || anArg == "-clear") | |
197ac94e | 8325 | { |
1beb58d7 | 8326 | anAnimation->Clear(); |
8327 | } | |
8328 | else if (anArg == "-remove" | |
8329 | || anArg == "-del" | |
8330 | || anArg == "-delete") | |
8331 | { | |
8332 | if (!aParentAnimation.IsNull()) | |
8333 | { | |
8334 | ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name()); | |
8335 | } | |
8336 | else | |
8337 | { | |
8338 | aParentAnimation->Remove (anAnimation); | |
8339 | } | |
8340 | } | |
bf7b2ceb | 8341 | // playback options |
1beb58d7 | 8342 | else if (anArg == "-play") |
8343 | { | |
8344 | toPlay = Standard_True; | |
8345 | if (++anArgIter < theArgNb) | |
8346 | { | |
8347 | if (*theArgVec[anArgIter] == '-') | |
8348 | { | |
8349 | --anArgIter; | |
8350 | continue; | |
8351 | } | |
8352 | aPlayStartTime = Draw::Atof (theArgVec[anArgIter]); | |
8353 | ||
8354 | if (++anArgIter < theArgNb) | |
8355 | { | |
8356 | if (*theArgVec[anArgIter] == '-') | |
8357 | { | |
8358 | --anArgIter; | |
8359 | continue; | |
8360 | } | |
8361 | aPlayDuration = Draw::Atof (theArgVec[anArgIter]); | |
8362 | } | |
8363 | } | |
8364 | } | |
8365 | else if (anArg == "-resume") | |
8366 | { | |
8367 | toPlay = Standard_True; | |
8368 | aPlayStartTime = anAnimation->ElapsedTime(); | |
8369 | if (++anArgIter < theArgNb) | |
8370 | { | |
8371 | if (*theArgVec[anArgIter] == '-') | |
8372 | { | |
8373 | --anArgIter; | |
8374 | continue; | |
8375 | } | |
8376 | ||
8377 | aPlayDuration = Draw::Atof (theArgVec[anArgIter]); | |
8378 | } | |
8379 | } | |
8380 | else if (anArg == "-playspeed" | |
8381 | || anArg == "-speed") | |
8382 | { | |
8383 | if (++anArgIter >= theArgNb) | |
8384 | { | |
23fe70ec | 8385 | Message::SendFail() << "Syntax error at " << anArg << ""; |
1beb58d7 | 8386 | return 1; |
8387 | } | |
8388 | aPlaySpeed = Draw::Atof (theArgVec[anArgIter]); | |
8389 | } | |
8390 | else if (anArg == "-lock" | |
8391 | || anArg == "-lockloop" | |
8392 | || anArg == "-playlockloop") | |
8393 | { | |
8394 | isLockLoop = Standard_True; | |
8395 | } | |
8396 | else if (anArg == "-freecamera" | |
8397 | || anArg == "-playfreecamera" | |
8398 | || anArg == "-freelook") | |
8399 | { | |
8400 | isFreeCamera = Standard_True; | |
8401 | } | |
08f8a185 | 8402 | // video recodring options |
8403 | else if (anArg == "-rec" | |
8404 | || anArg == "-record") | |
8405 | { | |
8406 | if (++anArgIter >= theArgNb) | |
8407 | { | |
23fe70ec | 8408 | Message::SendFail() << "Syntax error at " << anArg; |
08f8a185 | 8409 | return 1; |
8410 | } | |
8411 | ||
8412 | aRecFile = theArgVec[anArgIter]; | |
8413 | if (aRecParams.FpsNum <= 0) | |
8414 | { | |
8415 | aRecParams.FpsNum = 24; | |
8416 | } | |
8417 | ||
8418 | if (anArgIter + 2 < theArgNb | |
8419 | && *theArgVec[anArgIter + 1] != '-' | |
8420 | && *theArgVec[anArgIter + 2] != '-') | |
8421 | { | |
8422 | TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]); | |
8423 | TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]); | |
8424 | if (aWidthArg .IsIntegerValue() | |
8425 | && aHeightArg.IsIntegerValue()) | |
8426 | { | |
8427 | aRecParams.Width = aWidthArg .IntegerValue(); | |
8428 | aRecParams.Height = aHeightArg.IntegerValue(); | |
8429 | anArgIter += 2; | |
8430 | } | |
8431 | } | |
8432 | } | |
1beb58d7 | 8433 | else if (anArg == "-fps") |
8434 | { | |
8435 | if (++anArgIter >= theArgNb) | |
8436 | { | |
23fe70ec | 8437 | Message::SendFail() << "Syntax error at " << anArg; |
1beb58d7 | 8438 | return 1; |
8439 | } | |
bf7b2ceb | 8440 | |
8441 | TCollection_AsciiString aFpsArg (theArgVec[anArgIter]); | |
8442 | Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length()); | |
8443 | if (aSplitIndex == 0) | |
8444 | { | |
08f8a185 | 8445 | aRecParams.FpsNum = aFpsArg.IntegerValue(); |
bf7b2ceb | 8446 | } |
8447 | else | |
8448 | { | |
8449 | const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex); | |
8450 | aFpsArg.Split (aFpsArg.Length() - 1); | |
8451 | const TCollection_AsciiString aNumStr = aFpsArg; | |
08f8a185 | 8452 | aRecParams.FpsNum = aNumStr.IntegerValue(); |
8453 | aRecParams.FpsDen = aDenStr.IntegerValue(); | |
8454 | if (aRecParams.FpsDen < 1) | |
bf7b2ceb | 8455 | { |
23fe70ec | 8456 | Message::SendFail() << "Syntax error at " << anArg; |
bf7b2ceb | 8457 | return 1; |
8458 | } | |
8459 | } | |
1beb58d7 | 8460 | } |
08f8a185 | 8461 | else if (anArg == "-format") |
8462 | { | |
8463 | if (++anArgIter >= theArgNb) | |
8464 | { | |
23fe70ec | 8465 | Message::SendFail() << "Syntax error at " << anArg; |
08f8a185 | 8466 | return 1; |
8467 | } | |
8468 | aRecParams.Format = theArgVec[anArgIter]; | |
8469 | } | |
8470 | else if (anArg == "-pix_fmt" | |
8471 | || anArg == "-pixfmt" | |
8472 | || anArg == "-pixelformat") | |
8473 | { | |
8474 | if (++anArgIter >= theArgNb) | |
8475 | { | |
23fe70ec | 8476 | Message::SendFail() << "Syntax error at " << anArg; |
08f8a185 | 8477 | return 1; |
8478 | } | |
8479 | aRecParams.PixelFormat = theArgVec[anArgIter]; | |
8480 | } | |
8481 | else if (anArg == "-codec" | |
8482 | || anArg == "-vcodec" | |
8483 | || anArg == "-videocodec") | |
8484 | { | |
8485 | if (++anArgIter >= theArgNb) | |
8486 | { | |
23fe70ec | 8487 | Message::SendFail() << "Syntax error at " << anArg; |
08f8a185 | 8488 | return 1; |
8489 | } | |
8490 | aRecParams.VideoCodec = theArgVec[anArgIter]; | |
8491 | } | |
8492 | else if (anArg == "-crf" | |
8493 | || anArg == "-preset" | |
8494 | || anArg == "-qp") | |
8495 | { | |
8496 | const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length()); | |
8497 | if (++anArgIter >= theArgNb) | |
8498 | { | |
23fe70ec | 8499 | Message::SendFail() << "Syntax error at " << anArg; |
08f8a185 | 8500 | return 1; |
8501 | } | |
8502 | ||
8503 | aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]); | |
8504 | } | |
bf7b2ceb | 8505 | // animation definition options |
1beb58d7 | 8506 | else if (anArg == "-start" |
8507 | || anArg == "-starttime" | |
8508 | || anArg == "-startpts") | |
8509 | { | |
8510 | if (++anArgIter >= theArgNb) | |
8511 | { | |
23fe70ec | 8512 | Message::SendFail() << "Syntax error at " << anArg; |
1beb58d7 | 8513 | return 1; |
8514 | } | |
8515 | ||
8516 | anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter])); | |
8517 | aRootAnimation->UpdateTotalDuration(); | |
8518 | } | |
8519 | else if (anArg == "-end" | |
8520 | || anArg == "-endtime" | |
8521 | || anArg == "-endpts") | |
8522 | { | |
8523 | if (++anArgIter >= theArgNb) | |
8524 | { | |
23fe70ec | 8525 | Message::SendFail() << "Syntax error at " << anArg; |
1beb58d7 | 8526 | return 1; |
8527 | } | |
8528 | ||
8529 | anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts()); | |
8530 | aRootAnimation->UpdateTotalDuration(); | |
8531 | } | |
8532 | else if (anArg == "-dur" | |
8533 | || anArg == "-duration") | |
8534 | { | |
8535 | if (++anArgIter >= theArgNb) | |
8536 | { | |
23fe70ec | 8537 | Message::SendFail() << "Syntax error at " << anArg; |
1beb58d7 | 8538 | return 1; |
8539 | } | |
8540 | ||
8541 | anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter])); | |
8542 | aRootAnimation->UpdateTotalDuration(); | |
8543 | } | |
8544 | else if (anArg == "-command" | |
8545 | || anArg == "-cmd" | |
8546 | || anArg == "-invoke" | |
8547 | || anArg == "-eval" | |
8548 | || anArg == "-proc") | |
8549 | { | |
8550 | if (++anArgIter >= theArgNb) | |
8551 | { | |
23fe70ec | 8552 | Message::SendFail() << "Syntax error at " << anArg; |
1beb58d7 | 8553 | return 1; |
8554 | } | |
8555 | ||
8556 | Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]); | |
8557 | replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation); | |
8558 | } | |
8559 | else if (anArg == "-objecttrsf" | |
8560 | || anArg == "-objectransformation" | |
8561 | || anArg == "-objtransformation" | |
8562 | || anArg == "-objtrsf" | |
8563 | || anArg == "-object" | |
8564 | || anArg == "-obj") | |
8565 | { | |
8566 | if (++anArgIter >= theArgNb) | |
8567 | { | |
23fe70ec | 8568 | Message::SendFail() << "Syntax error at " << anArg; |
1beb58d7 | 8569 | return 1; |
8570 | } | |
8571 | ||
8572 | TCollection_AsciiString anObjName (theArgVec[anArgIter]); | |
8573 | const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS(); | |
8f521168 | 8574 | Handle(AIS_InteractiveObject) anObject; |
8575 | if (!aMapOfAIS.Find2 (anObjName, anObject)) | |
1beb58d7 | 8576 | { |
23fe70ec | 8577 | Message::SendFail() << "Syntax error: wrong object name at " << anArg; |
1beb58d7 | 8578 | return 1; |
8579 | } | |
8580 | ||
1beb58d7 | 8581 | gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() }; |
8582 | gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() }; | |
8583 | gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() }; | |
8584 | Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() }; | |
8585 | Standard_Boolean isTrsfSet = Standard_False; | |
8586 | Standard_Integer aTrsfArgIter = anArgIter + 1; | |
8587 | for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter) | |
8588 | { | |
8589 | TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]); | |
8590 | aTrsfArg.LowerCase(); | |
8591 | const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1; | |
8592 | if (aTrsfArg.StartsWith ("-rotation") | |
8593 | || aTrsfArg.StartsWith ("-rot")) | |
8594 | { | |
8595 | isTrsfSet = Standard_True; | |
8596 | if (aTrsfArgIter + 4 >= theArgNb | |
8597 | || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex])) | |
8598 | { | |
23fe70ec | 8599 | Message::SendFail() << "Syntax error at " << aTrsfArg; |
1beb58d7 | 8600 | return 1; |
8601 | } | |
8602 | aTrsfArgIter += 4; | |
8603 | } | |
8604 | else if (aTrsfArg.StartsWith ("-location") | |
8605 | || aTrsfArg.StartsWith ("-loc")) | |
8606 | { | |
8607 | isTrsfSet = Standard_True; | |
8608 | if (aTrsfArgIter + 3 >= theArgNb | |
8609 | || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex])) | |
8610 | { | |
23fe70ec | 8611 | Message::SendFail() << "Syntax error at " << aTrsfArg; |
1beb58d7 | 8612 | return 1; |
8613 | } | |
8614 | aTrsfArgIter += 3; | |
8615 | } | |
8616 | else if (aTrsfArg.StartsWith ("-scale")) | |
8617 | { | |
8618 | isTrsfSet = Standard_True; | |
8619 | if (++aTrsfArgIter >= theArgNb) | |
8620 | { | |
23fe70ec | 8621 | Message::SendFail() << "Syntax error at " << aTrsfArg; |
1beb58d7 | 8622 | return 1; |
8623 | } | |
8624 | ||
8625 | const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]); | |
8626 | if (!aScaleStr.IsRealValue()) | |
8627 | { | |
23fe70ec | 8628 | Message::SendFail() << "Syntax error at " << aTrsfArg; |
1beb58d7 | 8629 | return 1; |
8630 | } | |
8631 | aScales[anIndex] = aScaleStr.RealValue(); | |
8632 | } | |
8633 | else | |
8634 | { | |
8635 | anArgIter = aTrsfArgIter - 1; | |
8636 | break; | |
8637 | } | |
8638 | } | |
8639 | if (!isTrsfSet) | |
8640 | { | |
23fe70ec | 8641 | Message::SendFail() << "Syntax error at " << anArg; |
1beb58d7 | 8642 | return 1; |
8643 | } | |
8644 | else if (aTrsfArgIter >= theArgNb) | |
8645 | { | |
8646 | anArgIter = theArgNb; | |
8647 | } | |
8648 | ||
8649 | aTrsfs[0].SetRotation (aRotQuats[0]); | |
8650 | aTrsfs[1].SetRotation (aRotQuats[1]); | |
8651 | aTrsfs[0].SetTranslationPart (aLocPnts[0]); | |
8652 | aTrsfs[1].SetTranslationPart (aLocPnts[1]); | |
8653 | aTrsfs[0].SetScaleFactor (aScales[0]); | |
8654 | aTrsfs[1].SetScaleFactor (aScales[1]); | |
8655 | ||
8656 | Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]); | |
8657 | replaceAnimation (aParentAnimation, anAnimation, anObjAnimation); | |
8658 | } | |
8659 | else if (anArg == "-viewtrsf" | |
8660 | || anArg == "-view") | |
8661 | { | |
8662 | Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation); | |
8663 | if (aCamAnimation.IsNull()) | |
8664 | { | |
8665 | aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView); | |
8666 | replaceAnimation (aParentAnimation, anAnimation, aCamAnimation); | |
8667 | } | |
8668 | ||
8669 | Handle(Graphic3d_Camera) aCams[2] = | |
8670 | { | |
8671 | new Graphic3d_Camera (aCamAnimation->View()->Camera()), | |
8672 | new Graphic3d_Camera (aCamAnimation->View()->Camera()) | |
8673 | }; | |
8674 | ||
8675 | Standard_Boolean isTrsfSet = Standard_False; | |
8676 | Standard_Integer aViewArgIter = anArgIter + 1; | |
8677 | for (; aViewArgIter < theArgNb; ++aViewArgIter) | |
8678 | { | |
8679 | TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]); | |
8680 | aViewArg.LowerCase(); | |
8681 | const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1; | |
8682 | if (aViewArg.StartsWith ("-scale")) | |
8683 | { | |
8684 | isTrsfSet = Standard_True; | |
8685 | if (++aViewArgIter >= theArgNb) | |
8686 | { | |
23fe70ec | 8687 | Message::SendFail() << "Syntax error at " << anArg; |
1beb58d7 | 8688 | return 1; |
8689 | } | |
8690 | ||
8691 | const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]); | |
8692 | if (!aScaleStr.IsRealValue()) | |
8693 | { | |
23fe70ec | 8694 | Message::SendFail() << "Syntax error at " << aViewArg; |
1beb58d7 | 8695 | return 1; |
8696 | } | |
8697 | Standard_Real aScale = aScaleStr.RealValue(); | |
8698 | aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale; | |
8699 | aCams[anIndex]->SetScale (aScale); | |
8700 | } | |
8701 | else if (aViewArg.StartsWith ("-eye") | |
8702 | || aViewArg.StartsWith ("-center") | |
8703 | || aViewArg.StartsWith ("-at") | |
8704 | || aViewArg.StartsWith ("-up")) | |
8705 | { | |
8706 | isTrsfSet = Standard_True; | |
8707 | gp_XYZ anXYZ; | |
8708 | if (aViewArgIter + 3 >= theArgNb | |
8709 | || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ)) | |
8710 | { | |
23fe70ec | 8711 | Message::SendFail() << "Syntax error at " << aViewArg; |
1beb58d7 | 8712 | return 1; |
8713 | } | |
8714 | aViewArgIter += 3; | |
8715 | ||
8716 | if (aViewArg.StartsWith ("-eye")) | |
8717 | { | |
8718 | aCams[anIndex]->SetEye (anXYZ); | |
8719 | } | |
8720 | else if (aViewArg.StartsWith ("-center") | |
8721 | || aViewArg.StartsWith ("-at")) | |
8722 | { | |
8723 | aCams[anIndex]->SetCenter (anXYZ); | |
8724 | } | |
8725 | else if (aViewArg.StartsWith ("-up")) | |
8726 | { | |
8727 | aCams[anIndex]->SetUp (anXYZ); | |
8728 | } | |
8729 | } | |
8730 | else | |
8731 | { | |
8732 | anArgIter = aViewArgIter - 1; | |
8733 | break; | |
8734 | } | |
8735 | } | |
8736 | if (!isTrsfSet) | |
8737 | { | |
23fe70ec | 8738 | Message::SendFail() << "Syntax error at " << anArg; |
1beb58d7 | 8739 | return 1; |
8740 | } | |
8741 | else if (aViewArgIter >= theArgNb) | |
8742 | { | |
8743 | anArgIter = theArgNb; | |
8744 | } | |
8745 | ||
8746 | aCamAnimation->SetCameraStart(aCams[0]); | |
8747 | aCamAnimation->SetCameraEnd (aCams[1]); | |
197ac94e | 8748 | } |
8749 | else | |
8750 | { | |
23fe70ec | 8751 | Message::SendFail() << "Syntax error at " << anArg; |
1beb58d7 | 8752 | return 1; |
197ac94e | 8753 | } |
8754 | } | |
1beb58d7 | 8755 | |
08f8a185 | 8756 | if (!toPlay && aRecFile.IsEmpty()) |
197ac94e | 8757 | { |
1beb58d7 | 8758 | return 0; |
8759 | } | |
8760 | ||
8761 | // Start animation timeline and process frame updating. | |
8762 | TheIsAnimating = Standard_True; | |
8763 | const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False); | |
8764 | Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera()); | |
bf7b2ceb | 8765 | anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0); |
1beb58d7 | 8766 | if (isFreeCamera) |
8767 | { | |
8768 | aView->Camera()->Copy (aCameraBack); | |
8769 | } | |
8770 | ||
8771 | const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration; | |
08f8a185 | 8772 | if (aRecParams.FpsNum <= 0) |
1beb58d7 | 8773 | { |
8774 | while (!anAnimation->IsStopped()) | |
197ac94e | 8775 | { |
1beb58d7 | 8776 | aCameraBack->Copy (aView->Camera()); |
8777 | const Standard_Real aPts = anAnimation->UpdateTimer(); | |
8778 | if (isFreeCamera) | |
8779 | { | |
8780 | aView->Camera()->Copy (aCameraBack); | |
8781 | } | |
8782 | ||
8783 | if (aPts >= anUpperPts) | |
8784 | { | |
8785 | anAnimation->Pause(); | |
8786 | break; | |
8787 | } | |
8788 | ||
8789 | if (aView->IsInvalidated()) | |
8790 | { | |
8791 | aView->Redraw(); | |
8792 | } | |
8793 | else | |
8794 | { | |
8795 | aView->RedrawImmediate(); | |
8796 | } | |
8797 | ||
8798 | if (!isLockLoop) | |
8799 | { | |
8800 | // handle user events | |
8801 | theDI.Eval ("after 1 set waiter 1"); | |
8802 | theDI.Eval ("vwait waiter"); | |
8803 | } | |
8804 | if (!TheIsAnimating) | |
8805 | { | |
8806 | anAnimation->Pause(); | |
8807 | theDI << aPts; | |
8808 | break; | |
8809 | } | |
8810 | } | |
8811 | ||
8812 | if (aView->IsInvalidated()) | |
8813 | { | |
8814 | aView->Redraw(); | |
197ac94e | 8815 | } |
8816 | else | |
8817 | { | |
1beb58d7 | 8818 | aView->RedrawImmediate(); |
197ac94e | 8819 | } |
8820 | } | |
1beb58d7 | 8821 | else |
197ac94e | 8822 | { |
bf7b2ceb | 8823 | OSD_Timer aPerfTimer; |
8824 | aPerfTimer.Start(); | |
1beb58d7 | 8825 | |
08f8a185 | 8826 | Handle(Image_VideoRecorder) aRecorder; |
8827 | ImageFlipper aFlipper; | |
8828 | Handle(Draw_ProgressIndicator) aProgress; | |
8829 | if (!aRecFile.IsEmpty()) | |
8830 | { | |
8831 | if (aRecParams.Width <= 0 | |
8832 | || aRecParams.Height <= 0) | |
8833 | { | |
8834 | aView->Window()->Size (aRecParams.Width, aRecParams.Height); | |
8835 | } | |
8836 | ||
8837 | aRecorder = new Image_VideoRecorder(); | |
8838 | if (!aRecorder->Open (aRecFile.ToCString(), aRecParams)) | |
8839 | { | |
23fe70ec | 8840 | Message::SendFail ("Error: failed to open video file for recording"); |
08f8a185 | 8841 | return 0; |
8842 | } | |
8843 | ||
8844 | aProgress = new Draw_ProgressIndicator (theDI, 1); | |
8845 | } | |
8846 | ||
1beb58d7 | 8847 | // Manage frame-rated animation here |
8848 | Standard_Real aPts = aPlayStartTime; | |
bf7b2ceb | 8849 | int64_t aNbFrames = 0; |
08f8a185 | 8850 | Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1); |
8851 | Standard_Integer aSecondsProgress = 0; | |
8852 | for (; aPts <= anUpperPts && aPSentry.More();) | |
197ac94e | 8853 | { |
08f8a185 | 8854 | const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames)); |
bf7b2ceb | 8855 | aPts = aPlayStartTime + aRecPts; |
8856 | ++aNbFrames; | |
1beb58d7 | 8857 | if (!anAnimation->Update (aPts)) |
8858 | { | |
8859 | break; | |
8860 | } | |
8861 | ||
08f8a185 | 8862 | if (!aRecorder.IsNull()) |
8863 | { | |
8864 | V3d_ImageDumpOptions aDumpParams; | |
8865 | aDumpParams.Width = aRecParams.Width; | |
8866 | aDumpParams.Height = aRecParams.Height; | |
8867 | aDumpParams.BufferType = Graphic3d_BT_RGBA; | |
8868 | aDumpParams.StereoOptions = V3d_SDO_MONO; | |
8869 | aDumpParams.ToAdjustAspect = Standard_True; | |
8870 | if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams)) | |
8871 | { | |
23fe70ec | 8872 | Message::SendFail ("Error: view dump is failed"); |
08f8a185 | 8873 | return 0; |
8874 | } | |
8875 | aFlipper.FlipY (aRecorder->ChangeFrame()); | |
8876 | if (!aRecorder->PushFrame()) | |
8877 | { | |
8878 | return 0; | |
8879 | } | |
8880 | } | |
8881 | else | |
8882 | { | |
8883 | aView->Redraw(); | |
8884 | } | |
8885 | ||
8886 | while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed)) | |
8887 | { | |
8888 | aPSentry.Next(); | |
8889 | ++aSecondsProgress; | |
8890 | } | |
197ac94e | 8891 | } |
bf7b2ceb | 8892 | |
8893 | aPerfTimer.Stop(); | |
1beb58d7 | 8894 | anAnimation->Stop(); |
bf7b2ceb | 8895 | const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime(); |
8896 | theDI << "Average FPS: " << aRecFps << "\n" | |
8897 | << "Nb. Frames: " << Standard_Real(aNbFrames); | |
8898 | ||
8899 | aView->Redraw(); | |
197ac94e | 8900 | } |
8901 | ||
1beb58d7 | 8902 | aView->SetImmediateUpdate (wasImmediateUpdate); |
8903 | TheIsAnimating = Standard_False; | |
4754e164 | 8904 | return 0; |
8905 | } | |
8906 | ||
1beb58d7 | 8907 | |
4754e164 | 8908 | //======================================================================= |
8909 | //function : VChangeSelected | |
dc3fe572 | 8910 | //purpose : Adds the shape to selection or remove one from it |
4754e164 | 8911 | //======================================================================= |
8912 | static Standard_Integer VChangeSelected (Draw_Interpretor& di, | |
8913 | Standard_Integer argc, | |
8914 | const char ** argv) | |
8915 | { | |
8916 | if(argc != 2) | |
8917 | { | |
8918 | di<<"Usage : " << argv[0] << " shape \n"; | |
8919 | return 1; | |
8920 | } | |
8921 | //get AIS_Shape: | |
4754e164 | 8922 | TCollection_AsciiString aName(argv[1]); |
8923 | Handle(AIS_InteractiveObject) anAISObject; | |
8f521168 | 8924 | if (!GetMapOfAIS().Find2 (aName, anAISObject) |
8925 | || anAISObject.IsNull()) | |
4754e164 | 8926 | { |
8927 | di<<"Use 'vdisplay' before"; | |
8928 | return 1; | |
8929 | } | |
4754e164 | 8930 | |
8f521168 | 8931 | ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True); |
4754e164 | 8932 | return 0; |
8933 | } | |
8934 | ||
4754e164 | 8935 | //======================================================================= |
8936 | //function : VNbSelected | |
dc3fe572 | 8937 | //purpose : Returns number of selected objects |
4754e164 | 8938 | //======================================================================= |
8939 | static Standard_Integer VNbSelected (Draw_Interpretor& di, | |
8940 | Standard_Integer argc, | |
8941 | const char ** argv) | |
8942 | { | |
8943 | if(argc != 1) | |
8944 | { | |
8945 | di << "Usage : " << argv[0] << "\n"; | |
8946 | return 1; | |
8947 | } | |
8948 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8949 | if(aContext.IsNull()) | |
8950 | { | |
8951 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8952 | return 1; | |
8953 | } | |
8954 | di << aContext->NbSelected() << "\n"; | |
8955 | return 0; | |
8956 | } | |
8957 | ||
4754e164 | 8958 | //======================================================================= |
8959 | //function : VPurgeDisplay | |
dc3fe572 | 8960 | //purpose : Switches altialiasing on or off |
4754e164 | 8961 | //======================================================================= |
8962 | static Standard_Integer VPurgeDisplay (Draw_Interpretor& di, | |
8963 | Standard_Integer argc, | |
8964 | const char ** argv) | |
8965 | { | |
eb4320f2 | 8966 | if (argc > 1) |
4754e164 | 8967 | { |
eb4320f2 | 8968 | di << "Usage : " << argv[0] << "\n"; |
4754e164 | 8969 | return 1; |
8970 | } | |
4754e164 | 8971 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
8972 | if (aContext.IsNull()) | |
8973 | { | |
8974 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8975 | return 1; | |
8976 | } | |
404c8936 | 8977 | |
eb4320f2 | 8978 | di << aContext->PurgeDisplay() << "\n"; |
4754e164 | 8979 | return 0; |
8980 | } | |
8981 | ||
8982 | //======================================================================= | |
8983 | //function : VSetViewSize | |
8984 | //purpose : | |
8985 | //======================================================================= | |
8986 | static Standard_Integer VSetViewSize (Draw_Interpretor& di, | |
8987 | Standard_Integer argc, | |
8988 | const char ** argv) | |
8989 | { | |
8990 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8991 | if(aContext.IsNull()) | |
8992 | { | |
8993 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8994 | return 1; | |
8995 | } | |
8996 | if(argc != 2) | |
8997 | { | |
8998 | di<<"Usage : " << argv[0] << " Size\n"; | |
8999 | return 1; | |
9000 | } | |
6b62b2da | 9001 | Standard_Real aSize = Draw::Atof (argv[1]); |
4754e164 | 9002 | if (aSize <= 0.) |
9003 | { | |
9004 | di<<"Bad Size value : " << aSize << "\n"; | |
9005 | return 1; | |
9006 | } | |
9007 | ||
9008 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9009 | aView->SetSize(aSize); | |
9010 | return 0; | |
9011 | } | |
9012 | ||
9013 | //======================================================================= | |
9014 | //function : VMoveView | |
9015 | //purpose : | |
9016 | //======================================================================= | |
9017 | static Standard_Integer VMoveView (Draw_Interpretor& di, | |
9018 | Standard_Integer argc, | |
9019 | const char ** argv) | |
9020 | { | |
9021 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
9022 | if(aContext.IsNull()) | |
9023 | { | |
9024 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
9025 | return 1; | |
9026 | } | |
9027 | if(argc < 4 || argc > 5) | |
9028 | { | |
9029 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
9030 | return 1; | |
9031 | } | |
6b62b2da | 9032 | Standard_Real Dx = Draw::Atof (argv[1]); |
9033 | Standard_Real Dy = Draw::Atof (argv[2]); | |
9034 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 9035 | Standard_Boolean aStart = Standard_True; |
9036 | if (argc == 5) | |
9037 | { | |
6b62b2da | 9038 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 9039 | } |
9040 | ||
9041 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9042 | aView->Move(Dx,Dy,Dz,aStart); | |
9043 | return 0; | |
9044 | } | |
9045 | ||
9046 | //======================================================================= | |
9047 | //function : VTranslateView | |
9048 | //purpose : | |
9049 | //======================================================================= | |
9050 | static Standard_Integer VTranslateView (Draw_Interpretor& di, | |
9051 | Standard_Integer argc, | |
9052 | const char ** argv) | |
9053 | { | |
9054 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
9055 | if(aContext.IsNull()) | |
9056 | { | |
9057 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
9058 | return 1; | |
9059 | } | |
9060 | if(argc < 4 || argc > 5) | |
9061 | { | |
9062 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
9063 | return 1; | |
9064 | } | |
6b62b2da | 9065 | Standard_Real Dx = Draw::Atof (argv[1]); |
9066 | Standard_Real Dy = Draw::Atof (argv[2]); | |
9067 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 9068 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 9069 | if (argc == 5) |
4754e164 | 9070 | { |
6b62b2da | 9071 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 9072 | } |
9073 | ||
9074 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9075 | aView->Translate(Dx,Dy,Dz,aStart); | |
9076 | return 0; | |
9077 | } | |
9078 | ||
9079 | //======================================================================= | |
9080 | //function : VTurnView | |
9081 | //purpose : | |
9082 | //======================================================================= | |
9083 | static Standard_Integer VTurnView (Draw_Interpretor& di, | |
9084 | Standard_Integer argc, | |
9085 | const char ** argv) | |
9086 | { | |
9087 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
9088 | if(aContext.IsNull()) { | |
9089 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
9090 | return 1; | |
9091 | } | |
9092 | if(argc < 4 || argc > 5){ | |
9093 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n"; | |
9094 | return 1; | |
9095 | } | |
6b62b2da | 9096 | Standard_Real Ax = Draw::Atof (argv[1]); |
9097 | Standard_Real Ay = Draw::Atof (argv[2]); | |
9098 | Standard_Real Az = Draw::Atof (argv[3]); | |
4754e164 | 9099 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 9100 | if (argc == 5) |
4754e164 | 9101 | { |
6b62b2da | 9102 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 9103 | } |
9104 | ||
9105 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9106 | aView->Turn(Ax,Ay,Az,aStart); | |
9107 | return 0; | |
9108 | } | |
9109 | ||
269294d6 | 9110 | //============================================================================== |
9111 | //function : VTextureEnv | |
9112 | //purpose : ENables or disables environment mapping | |
9113 | //============================================================================== | |
9114 | class OCC_TextureEnv : public Graphic3d_TextureEnv | |
9115 | { | |
9116 | public: | |
9117 | OCC_TextureEnv(const Standard_CString FileName); | |
9118 | OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName); | |
9119 | void SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
9120 | const Standard_Boolean theModulateFlag, | |
9121 | const Graphic3d_TypeOfTextureFilter theFilter, | |
9122 | const Standard_ShortReal theXScale, | |
9123 | const Standard_ShortReal theYScale, | |
9124 | const Standard_ShortReal theXShift, | |
9125 | const Standard_ShortReal theYShift, | |
9126 | const Standard_ShortReal theAngle); | |
68858c7d | 9127 | DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv) |
269294d6 | 9128 | }; |
a3f6f591 | 9129 | DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv) |
ec357c5c | 9130 | |
269294d6 | 9131 | OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName) |
9132 | : Graphic3d_TextureEnv(theFileName) | |
9133 | { | |
9134 | } | |
9135 | ||
9136 | OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId) | |
9137 | : Graphic3d_TextureEnv(theTexId) | |
9138 | { | |
9139 | } | |
9140 | ||
9141 | void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
9142 | const Standard_Boolean theModulateFlag, | |
9143 | const Graphic3d_TypeOfTextureFilter theFilter, | |
9144 | const Standard_ShortReal theXScale, | |
9145 | const Standard_ShortReal theYScale, | |
9146 | const Standard_ShortReal theXShift, | |
9147 | const Standard_ShortReal theYShift, | |
9148 | const Standard_ShortReal theAngle) | |
9149 | { | |
9150 | myParams->SetRepeat (theRepeatFlag); | |
9151 | myParams->SetModulate (theModulateFlag); | |
9152 | myParams->SetFilter (theFilter); | |
9153 | myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale)); | |
9154 | myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift)); | |
9155 | myParams->SetRotation (theAngle); | |
9156 | } | |
9157 | ||
35e08fe8 | 9158 | static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) |
269294d6 | 9159 | { |
9160 | // get the active view | |
9161 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9162 | if (aView.IsNull()) | |
9163 | { | |
23fe70ec | 9164 | Message::SendFail ("Error: no active viewer"); |
269294d6 | 9165 | return 1; |
9166 | } | |
9167 | ||
9168 | // Checking the input arguments | |
9169 | Standard_Boolean anEnableFlag = Standard_False; | |
9170 | Standard_Boolean isOk = theArgNb >= 2; | |
9171 | if (isOk) | |
9172 | { | |
9173 | TCollection_AsciiString anEnableOpt(theArgVec[1]); | |
9174 | anEnableFlag = anEnableOpt.IsEqual("on"); | |
9175 | isOk = anEnableFlag || anEnableOpt.IsEqual("off"); | |
9176 | } | |
9177 | if (anEnableFlag) | |
9178 | { | |
9179 | isOk = (theArgNb == 3 || theArgNb == 11); | |
9180 | if (isOk) | |
9181 | { | |
9182 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
9183 | isOk = (!aTextureOpt.IsIntegerValue() || | |
9184 | (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN)); | |
9185 | ||
9186 | if (isOk && theArgNb == 11) | |
9187 | { | |
9188 | TCollection_AsciiString aRepeatOpt (theArgVec[3]), | |
9189 | aModulateOpt(theArgVec[4]), | |
9190 | aFilterOpt (theArgVec[5]), | |
9191 | aSScaleOpt (theArgVec[6]), | |
9192 | aTScaleOpt (theArgVec[7]), | |
9193 | aSTransOpt (theArgVec[8]), | |
9194 | aTTransOpt (theArgVec[9]), | |
9195 | anAngleOpt (theArgVec[10]); | |
9196 | isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) && | |
9197 | (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) && | |
9198 | (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) && | |
9199 | aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() && | |
9200 | aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() && | |
9201 | anAngleOpt.IsRealValue()); | |
9202 | } | |
9203 | } | |
9204 | } | |
9205 | ||
9206 | if (!isOk) | |
9207 | { | |
23fe70ec | 9208 | Message::SendFail() << "Usage:\n" |
9209 | << theArgVec[0] << " off\n" | |
9210 | << 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]"; | |
269294d6 | 9211 | return 1; |
9212 | } | |
9213 | ||
9214 | if (anEnableFlag) | |
9215 | { | |
9216 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
9217 | Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ? | |
9218 | new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) : | |
9219 | new OCC_TextureEnv(theArgVec[2]); | |
9220 | ||
9221 | if (theArgNb == 11) | |
9222 | { | |
9223 | TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]); | |
9224 | aTexEnv->SetTextureParameters( | |
9225 | aRepeatOpt. IsEqual("repeat"), | |
9226 | aModulateOpt.IsEqual("modulate"), | |
9227 | aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST : | |
9228 | aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR : | |
9229 | Graphic3d_TOTF_TRILINEAR, | |
9230 | (Standard_ShortReal)Draw::Atof(theArgVec[6]), | |
9231 | (Standard_ShortReal)Draw::Atof(theArgVec[7]), | |
9232 | (Standard_ShortReal)Draw::Atof(theArgVec[8]), | |
9233 | (Standard_ShortReal)Draw::Atof(theArgVec[9]), | |
9234 | (Standard_ShortReal)Draw::Atof(theArgVec[10]) | |
9235 | ); | |
9236 | } | |
9237 | aView->SetTextureEnv(aTexEnv); | |
269294d6 | 9238 | } |
9239 | else // Disabling environment mapping | |
9240 | { | |
269294d6 | 9241 | Handle(Graphic3d_TextureEnv) aTexture; |
9242 | aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data | |
9243 | } | |
9244 | ||
9245 | aView->Redraw(); | |
9246 | return 0; | |
9247 | } | |
9248 | ||
3e05329c | 9249 | namespace |
9250 | { | |
9251 | typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes; | |
9252 | ||
9253 | //! Remove registered clipping plane from all views and objects. | |
9254 | static void removePlane (MapOfPlanes& theRegPlanes, | |
9255 | const TCollection_AsciiString& theName) | |
9256 | { | |
9257 | Handle(Graphic3d_ClipPlane) aClipPlane; | |
9258 | if (!theRegPlanes.Find (theName, aClipPlane)) | |
9259 | { | |
23fe70ec | 9260 | Message::SendWarning ("Warning: no such plane"); |
3e05329c | 9261 | return; |
9262 | } | |
9263 | ||
9264 | theRegPlanes.UnBind (theName); | |
9265 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS()); | |
9266 | anIObjIt.More(); anIObjIt.Next()) | |
9267 | { | |
8f521168 | 9268 | const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1(); |
3e05329c | 9269 | aPrs->RemoveClipPlane (aClipPlane); |
9270 | } | |
9271 | ||
9272 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
9273 | aViewIt.More(); aViewIt.Next()) | |
9274 | { | |
9275 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
9276 | aView->RemoveClipPlane(aClipPlane); | |
9277 | } | |
9278 | ||
9279 | ViewerTest::RedrawAllViews(); | |
9280 | } | |
9281 | } | |
9282 | ||
4269bd1b | 9283 | //=============================================================================================== |
9284 | //function : VClipPlane | |
9285 | //purpose : | |
9286 | //=============================================================================================== | |
9287 | static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
9288 | { | |
9289 | // use short-cut for created clip planes map of created (or "registered by name") clip planes | |
4269bd1b | 9290 | static MapOfPlanes aRegPlanes; |
9291 | ||
9292 | if (theArgsNb < 2) | |
9293 | { | |
3e05329c | 9294 | for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next()) |
9295 | { | |
9296 | theDi << aPlaneIter.Key() << " "; | |
9297 | } | |
9298 | return 0; | |
4269bd1b | 9299 | } |
9300 | ||
9301 | TCollection_AsciiString aCommand (theArgVec[1]); | |
3e05329c | 9302 | aCommand.LowerCase(); |
9303 | const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView(); | |
9304 | if (anActiveView.IsNull()) | |
9305 | { | |
23fe70ec | 9306 | Message::SendFail ("Error: no active viewer"); |
3e05329c | 9307 | return 1; |
9308 | } | |
4269bd1b | 9309 | |
9310 | // print maximum number of planes for current viewer | |
3e05329c | 9311 | if (aCommand == "-maxplanes" |
9312 | || aCommand == "maxplanes") | |
4269bd1b | 9313 | { |
3e05329c | 9314 | theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit() |
9315 | << " plane slots provided by driver.\n"; | |
4269bd1b | 9316 | return 0; |
9317 | } | |
9318 | ||
9319 | // create / delete plane instance | |
3e05329c | 9320 | if (aCommand == "-create" |
9321 | || aCommand == "create" | |
9322 | || aCommand == "-delete" | |
9323 | || aCommand == "delete" | |
9324 | || aCommand == "-clone" | |
9325 | || aCommand == "clone") | |
4269bd1b | 9326 | { |
9327 | if (theArgsNb < 3) | |
9328 | { | |
23fe70ec | 9329 | Message::SendFail ("Syntax error: plane name is required"); |
4269bd1b | 9330 | return 1; |
9331 | } | |
9332 | ||
3e05329c | 9333 | Standard_Boolean toCreate = aCommand == "-create" |
9334 | || aCommand == "create"; | |
9335 | Standard_Boolean toClone = aCommand == "-clone" | |
9336 | || aCommand == "clone"; | |
9337 | Standard_Boolean toDelete = aCommand == "-delete" | |
9338 | || aCommand == "delete"; | |
4269bd1b | 9339 | TCollection_AsciiString aPlane (theArgVec[2]); |
9340 | ||
9341 | if (toCreate) | |
9342 | { | |
9343 | if (aRegPlanes.IsBound (aPlane)) | |
9344 | { | |
3e05329c | 9345 | std::cout << "Warning: existing plane has been overridden.\n"; |
9346 | toDelete = true; | |
9347 | } | |
9348 | else | |
9349 | { | |
9350 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
9351 | return 0; | |
4269bd1b | 9352 | } |
4269bd1b | 9353 | } |
9354 | else if (toClone) // toClone | |
9355 | { | |
9356 | if (!aRegPlanes.IsBound (aPlane)) | |
9357 | { | |
23fe70ec | 9358 | Message::SendFail ("Error: no such plane"); |
4269bd1b | 9359 | return 1; |
9360 | } | |
3e05329c | 9361 | else if (theArgsNb < 4) |
4269bd1b | 9362 | { |
23fe70ec | 9363 | Message::SendFail ("Syntax error: enter name for new plane"); |
4269bd1b | 9364 | return 1; |
9365 | } | |
9366 | ||
9367 | TCollection_AsciiString aClone (theArgVec[3]); | |
9368 | if (aRegPlanes.IsBound (aClone)) | |
9369 | { | |
23fe70ec | 9370 | Message::SendFail ("Error: plane name is in use"); |
4269bd1b | 9371 | return 1; |
9372 | } | |
9373 | ||
9374 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
9375 | ||
9376 | aRegPlanes.Bind (aClone, aClipPlane->Clone()); | |
3e05329c | 9377 | return 0; |
4269bd1b | 9378 | } |
4269bd1b | 9379 | |
3e05329c | 9380 | if (toDelete) |
9381 | { | |
9382 | if (aPlane == "ALL" | |
9383 | || aPlane == "all" | |
9384 | || aPlane == "*") | |
4269bd1b | 9385 | { |
3e05329c | 9386 | for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();) |
9387 | { | |
9388 | aPlane = aPlaneIter.Key(); | |
9389 | removePlane (aRegPlanes, aPlane); | |
9390 | aPlaneIter = MapOfPlanes::Iterator (aRegPlanes); | |
9391 | } | |
4269bd1b | 9392 | } |
3e05329c | 9393 | else |
4269bd1b | 9394 | { |
3e05329c | 9395 | removePlane (aRegPlanes, aPlane); |
4269bd1b | 9396 | } |
4269bd1b | 9397 | } |
9398 | ||
3e05329c | 9399 | if (toCreate) |
9400 | { | |
9401 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
9402 | } | |
4269bd1b | 9403 | return 0; |
9404 | } | |
9405 | ||
9406 | // set / unset plane command | |
3e05329c | 9407 | if (aCommand == "set" |
9408 | || aCommand == "unset") | |
4269bd1b | 9409 | { |
3e05329c | 9410 | if (theArgsNb < 5) |
4269bd1b | 9411 | { |
23fe70ec | 9412 | Message::SendFail ("Syntax error: need more arguments"); |
4269bd1b | 9413 | return 1; |
9414 | } | |
9415 | ||
3e05329c | 9416 | // redirect to new syntax |
9417 | NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1); | |
9418 | anArgVec.SetValue (1, theArgVec[0]); | |
9419 | anArgVec.SetValue (2, theArgVec[2]); | |
9420 | anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset"); | |
9421 | for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt) | |
4269bd1b | 9422 | { |
3e05329c | 9423 | anArgVec.SetValue (anIt, theArgVec[anIt]); |
4269bd1b | 9424 | } |
9425 | ||
3e05329c | 9426 | return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst()); |
4269bd1b | 9427 | } |
9428 | ||
9429 | // change plane command | |
3e05329c | 9430 | TCollection_AsciiString aPlaneName; |
9431 | Handle(Graphic3d_ClipPlane) aClipPlane; | |
9432 | Standard_Integer anArgIter = 0; | |
9433 | if (aCommand == "-change" | |
9434 | || aCommand == "change") | |
4269bd1b | 9435 | { |
3e05329c | 9436 | // old syntax support |
9437 | if (theArgsNb < 3) | |
4269bd1b | 9438 | { |
23fe70ec | 9439 | Message::SendFail ("Syntax error: need more arguments"); |
4269bd1b | 9440 | return 1; |
9441 | } | |
9442 | ||
3e05329c | 9443 | anArgIter = 3; |
9444 | aPlaneName = theArgVec[2]; | |
9445 | if (!aRegPlanes.Find (aPlaneName, aClipPlane)) | |
4269bd1b | 9446 | { |
23fe70ec | 9447 | Message::SendFail() << "Error: no such plane '" << aPlaneName << "'"; |
4269bd1b | 9448 | return 1; |
9449 | } | |
3e05329c | 9450 | } |
9451 | else if (aRegPlanes.Find (theArgVec[1], aClipPlane)) | |
9452 | { | |
9453 | anArgIter = 2; | |
9454 | aPlaneName = theArgVec[1]; | |
9455 | } | |
9456 | else | |
9457 | { | |
9458 | anArgIter = 2; | |
9459 | aPlaneName = theArgVec[1]; | |
9460 | aClipPlane = new Graphic3d_ClipPlane(); | |
9461 | aRegPlanes.Bind (aPlaneName, aClipPlane); | |
9462 | theDi << "Created new plane " << aPlaneName << ".\n"; | |
9463 | } | |
4269bd1b | 9464 | |
3e05329c | 9465 | if (theArgsNb - anArgIter < 1) |
9466 | { | |
23fe70ec | 9467 | Message::SendFail ("Syntax error: need more arguments"); |
3e05329c | 9468 | return 1; |
9469 | } | |
4269bd1b | 9470 | |
3e05329c | 9471 | for (; anArgIter < theArgsNb; ++anArgIter) |
9472 | { | |
9473 | const char** aChangeArgs = theArgVec + anArgIter; | |
9474 | Standard_Integer aNbChangeArgs = theArgsNb - anArgIter; | |
9475 | TCollection_AsciiString aChangeArg (aChangeArgs[0]); | |
9476 | aChangeArg.LowerCase(); | |
4269bd1b | 9477 | |
3e05329c | 9478 | Standard_Boolean toEnable = Standard_True; |
9479 | if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable)) | |
4269bd1b | 9480 | { |
3e05329c | 9481 | aClipPlane->SetOn (toEnable); |
4269bd1b | 9482 | } |
25c35042 | 9483 | else if (aChangeArg.StartsWith ("-equation") |
9484 | || aChangeArg.StartsWith ("equation")) | |
4269bd1b | 9485 | { |
3e05329c | 9486 | if (aNbChangeArgs < 5) |
4269bd1b | 9487 | { |
23fe70ec | 9488 | Message::SendFail ("Syntax error: need more arguments"); |
4269bd1b | 9489 | return 1; |
9490 | } | |
9491 | ||
25c35042 | 9492 | Standard_Integer aSubIndex = 1; |
9493 | Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0); | |
9494 | if (aPrefixLen < aChangeArg.Length()) | |
9495 | { | |
9496 | TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length()); | |
9497 | if (!aSubStr.IsIntegerValue() | |
9498 | || aSubStr.IntegerValue() <= 0) | |
9499 | { | |
23fe70ec | 9500 | Message::SendFail() << "Syntax error: unknown argument '" << aChangeArg << "'"; |
25c35042 | 9501 | return 1; |
9502 | } | |
9503 | aSubIndex = aSubStr.IntegerValue(); | |
9504 | } | |
9505 | ||
9506 | Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]); | |
9507 | Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]); | |
9508 | Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]); | |
9509 | Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]); | |
9510 | Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane; | |
9511 | for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter) | |
9512 | { | |
9513 | if (aSubPln->ChainNextPlane().IsNull()) | |
9514 | { | |
9515 | aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln)); | |
9516 | } | |
9517 | aSubPln = aSubPln->ChainNextPlane(); | |
9518 | } | |
9519 | aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)()); | |
9520 | aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD)); | |
3e05329c | 9521 | anArgIter += 4; |
4269bd1b | 9522 | } |
25c35042 | 9523 | else if ((aChangeArg == "-boxinterior" |
9524 | || aChangeArg == "-boxint" | |
9525 | || aChangeArg == "-box") | |
9526 | && aNbChangeArgs >= 7) | |
9527 | { | |
9528 | Graphic3d_BndBox3d aBndBox; | |
9529 | aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3]))); | |
9530 | aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6]))); | |
9531 | anArgIter += 6; | |
9532 | ||
9533 | Standard_Integer aNbSubPlanes = 6; | |
9534 | const Graphic3d_Vec3d aDirArray[6] = | |
9535 | { | |
9536 | Graphic3d_Vec3d (-1, 0, 0), | |
9537 | Graphic3d_Vec3d ( 1, 0, 0), | |
9538 | Graphic3d_Vec3d ( 0,-1, 0), | |
9539 | Graphic3d_Vec3d ( 0, 1, 0), | |
9540 | Graphic3d_Vec3d ( 0, 0,-1), | |
9541 | Graphic3d_Vec3d ( 0, 0, 1), | |
9542 | }; | |
9543 | Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane; | |
9544 | for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter) | |
9545 | { | |
9546 | const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter]; | |
9547 | const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin()); | |
9548 | aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW)); | |
9549 | if (aSubPlaneIter + 1 == aNbSubPlanes) | |
9550 | { | |
9551 | aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)()); | |
9552 | } | |
9553 | else | |
9554 | { | |
9555 | aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln)); | |
9556 | } | |
9557 | aSubPln = aSubPln->ChainNextPlane(); | |
9558 | } | |
9559 | } | |
3e05329c | 9560 | else if (aChangeArg == "-capping" |
9561 | || aChangeArg == "capping") | |
4269bd1b | 9562 | { |
3e05329c | 9563 | if (aNbChangeArgs < 2) |
4269bd1b | 9564 | { |
23fe70ec | 9565 | Message::SendFail ("Syntax error: need more arguments"); |
4269bd1b | 9566 | return 1; |
9567 | } | |
9568 | ||
3e05329c | 9569 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
4269bd1b | 9570 | { |
3e05329c | 9571 | aClipPlane->SetCapping (toEnable); |
9572 | anArgIter += 1; | |
9573 | } | |
9574 | else | |
9575 | { | |
9576 | // just skip otherwise (old syntax) | |
9577 | } | |
9578 | } | |
9579 | else if (aChangeArg == "-useobjectmaterial" | |
9580 | || aChangeArg == "-useobjectmat" | |
9581 | || aChangeArg == "-useobjmat" | |
9582 | || aChangeArg == "-useobjmaterial") | |
9583 | { | |
9584 | if (aNbChangeArgs < 2) | |
9585 | { | |
23fe70ec | 9586 | Message::SendFail ("Syntax error: need more arguments"); |
4269bd1b | 9587 | return 1; |
9588 | } | |
9589 | ||
3e05329c | 9590 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
4269bd1b | 9591 | { |
3e05329c | 9592 | aClipPlane->SetUseObjectMaterial (toEnable == Standard_True); |
9593 | anArgIter += 1; | |
4269bd1b | 9594 | } |
3e05329c | 9595 | } |
9596 | else if (aChangeArg == "-useobjecttexture" | |
9597 | || aChangeArg == "-useobjecttex" | |
9598 | || aChangeArg == "-useobjtexture" | |
9599 | || aChangeArg == "-useobjtex") | |
9600 | { | |
9601 | if (aNbChangeArgs < 2) | |
4269bd1b | 9602 | { |
23fe70ec | 9603 | Message::SendFail ("Syntax error: need more arguments"); |
3e05329c | 9604 | return 1; |
9605 | } | |
4269bd1b | 9606 | |
3e05329c | 9607 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
9608 | { | |
9609 | aClipPlane->SetUseObjectTexture (toEnable == Standard_True); | |
9610 | anArgIter += 1; | |
9611 | } | |
9612 | } | |
9613 | else if (aChangeArg == "-useobjectshader" | |
9614 | || aChangeArg == "-useobjshader") | |
9615 | { | |
9616 | if (aNbChangeArgs < 2) | |
9617 | { | |
23fe70ec | 9618 | Message::SendFail ("Syntax error: need more arguments"); |
3e05329c | 9619 | return 1; |
9620 | } | |
4269bd1b | 9621 | |
3e05329c | 9622 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
9623 | { | |
9624 | aClipPlane->SetUseObjectShader (toEnable == Standard_True); | |
9625 | anArgIter += 1; | |
4269bd1b | 9626 | } |
3e05329c | 9627 | } |
9628 | else if (aChangeArg == "-color" | |
9629 | || aChangeArg == "color") | |
9630 | { | |
9631 | Quantity_Color aColor; | |
9632 | Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1, | |
9633 | aChangeArgs + 1, | |
9634 | aColor); | |
9635 | if (aNbParsed == 0) | |
4269bd1b | 9636 | { |
23fe70ec | 9637 | Message::SendFail ("Syntax error: need more arguments"); |
3e05329c | 9638 | return 1; |
9639 | } | |
61168418 | 9640 | aClipPlane->SetCappingColor (aColor); |
3e05329c | 9641 | anArgIter += aNbParsed; |
9642 | } | |
61168418 | 9643 | else if (aNbChangeArgs >= 1 |
9644 | && (aChangeArg == "-material" | |
9645 | || aChangeArg == "material")) | |
9646 | { | |
9647 | ++anArgIter; | |
9648 | Graphic3d_NameOfMaterial aMatName; | |
9649 | if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeArgs[1], aMatName)) | |
9650 | { | |
23fe70ec | 9651 | Message::SendFail() << "Syntax error: unknown material '" << aChangeArgs[1] << "'"; |
61168418 | 9652 | return 1; |
9653 | } | |
9654 | aClipPlane->SetCappingMaterial (aMatName); | |
9655 | } | |
1b661a81 | 9656 | else if ((aChangeArg == "-transparency" |
9657 | || aChangeArg == "-transp") | |
9658 | && aNbChangeArgs >= 2) | |
9659 | { | |
9660 | TCollection_AsciiString aValStr (aChangeArgs[1]); | |
9661 | Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect(); | |
9662 | if (aValStr.IsRealValue()) | |
9663 | { | |
9664 | Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); | |
9665 | aMat.SetTransparency ((float )aValStr.RealValue()); | |
9666 | anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto); | |
9667 | aClipPlane->SetCappingMaterial (aMat); | |
9668 | } | |
9669 | else | |
9670 | { | |
9671 | aValStr.LowerCase(); | |
9672 | Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto; | |
9673 | if (aValStr == "opaque") | |
9674 | { | |
9675 | aMode = Graphic3d_AlphaMode_Opaque; | |
9676 | } | |
9677 | else if (aValStr == "mask") | |
9678 | { | |
9679 | aMode = Graphic3d_AlphaMode_Mask; | |
9680 | } | |
9681 | else if (aValStr == "blend") | |
9682 | { | |
9683 | aMode = Graphic3d_AlphaMode_Blend; | |
9684 | } | |
9685 | else if (aValStr == "blendauto") | |
9686 | { | |
9687 | aMode = Graphic3d_AlphaMode_BlendAuto; | |
9688 | } | |
9689 | else | |
9690 | { | |
23fe70ec | 9691 | Message::SendFail() << "Syntax error at '" << aValStr << "'"; |
1b661a81 | 9692 | return 1; |
9693 | } | |
9694 | anAspect->SetAlphaMode (aMode); | |
9695 | aClipPlane->SetCappingAspect (anAspect); | |
9696 | } | |
9697 | anArgIter += 1; | |
9698 | } | |
3e05329c | 9699 | else if (aChangeArg == "-texname" |
9700 | || aChangeArg == "texname") | |
9701 | { | |
9702 | if (aNbChangeArgs < 2) | |
9703 | { | |
23fe70ec | 9704 | Message::SendFail ("Syntax error: need more arguments"); |
3e05329c | 9705 | return 1; |
9706 | } | |
4269bd1b | 9707 | |
3e05329c | 9708 | TCollection_AsciiString aTextureName (aChangeArgs[1]); |
9709 | Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); | |
9710 | if (!aTexture->IsDone()) | |
9711 | { | |
9712 | aClipPlane->SetCappingTexture (NULL); | |
4269bd1b | 9713 | } |
3e05329c | 9714 | else |
4269bd1b | 9715 | { |
3e05329c | 9716 | aTexture->EnableModulate(); |
9717 | aTexture->EnableRepeat(); | |
9718 | aClipPlane->SetCappingTexture (aTexture); | |
9719 | } | |
9720 | anArgIter += 1; | |
9721 | } | |
9722 | else if (aChangeArg == "-texscale" | |
9723 | || aChangeArg == "texscale") | |
9724 | { | |
9725 | if (aClipPlane->CappingTexture().IsNull()) | |
9726 | { | |
23fe70ec | 9727 | Message::SendFail ("Error: no texture is set"); |
3e05329c | 9728 | return 1; |
9729 | } | |
4269bd1b | 9730 | |
3e05329c | 9731 | if (aNbChangeArgs < 3) |
9732 | { | |
23fe70ec | 9733 | Message::SendFail ("Syntax error: need more arguments"); |
3e05329c | 9734 | return 1; |
9735 | } | |
4269bd1b | 9736 | |
3e05329c | 9737 | Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); |
9738 | Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); | |
9739 | aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); | |
9740 | anArgIter += 2; | |
9741 | } | |
9742 | else if (aChangeArg == "-texorigin" | |
9743 | || aChangeArg == "texorigin") // texture origin | |
9744 | { | |
9745 | if (aClipPlane->CappingTexture().IsNull()) | |
9746 | { | |
23fe70ec | 9747 | Message::SendFail ("Error: no texture is set"); |
3e05329c | 9748 | return 1; |
9749 | } | |
4269bd1b | 9750 | |
3e05329c | 9751 | if (aNbChangeArgs < 3) |
9752 | { | |
23fe70ec | 9753 | Message::SendFail ("Syntax error: need more arguments"); |
3e05329c | 9754 | return 1; |
4269bd1b | 9755 | } |
3e05329c | 9756 | |
9757 | Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); | |
9758 | Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); | |
9759 | ||
9760 | aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); | |
9761 | anArgIter += 2; | |
9762 | } | |
9763 | else if (aChangeArg == "-texrotate" | |
9764 | || aChangeArg == "texrotate") // texture rotation | |
9765 | { | |
9766 | if (aClipPlane->CappingTexture().IsNull()) | |
4269bd1b | 9767 | { |
23fe70ec | 9768 | Message::SendFail ("Error: no texture is set"); |
3e05329c | 9769 | return 1; |
9770 | } | |
4269bd1b | 9771 | |
3e05329c | 9772 | if (aNbChangeArgs < 2) |
9773 | { | |
23fe70ec | 9774 | Message::SendFail ("Syntax error: need more arguments"); |
3e05329c | 9775 | return 1; |
9776 | } | |
4269bd1b | 9777 | |
3e05329c | 9778 | Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); |
9779 | aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot); | |
9780 | anArgIter += 1; | |
9781 | } | |
9782 | else if (aChangeArg == "-hatch" | |
9783 | || aChangeArg == "hatch") | |
9784 | { | |
9785 | if (aNbChangeArgs < 2) | |
9786 | { | |
23fe70ec | 9787 | Message::SendFail ("Syntax error: need more arguments"); |
3e05329c | 9788 | return 1; |
9789 | } | |
4269bd1b | 9790 | |
3e05329c | 9791 | TCollection_AsciiString aHatchStr (aChangeArgs[1]); |
9792 | aHatchStr.LowerCase(); | |
9793 | if (aHatchStr == "on") | |
9794 | { | |
9795 | aClipPlane->SetCappingHatchOn(); | |
9796 | } | |
9797 | else if (aHatchStr == "off") | |
9798 | { | |
9799 | aClipPlane->SetCappingHatchOff(); | |
4269bd1b | 9800 | } |
3e05329c | 9801 | else |
4269bd1b | 9802 | { |
3e05329c | 9803 | aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1])); |
9804 | } | |
9805 | anArgIter += 1; | |
9806 | } | |
9807 | else if (aChangeArg == "-delete" | |
9808 | || aChangeArg == "delete") | |
9809 | { | |
9810 | removePlane (aRegPlanes, aPlaneName); | |
9811 | return 0; | |
9812 | } | |
9813 | else if (aChangeArg == "-set" | |
32ca7711 | 9814 | || aChangeArg == "-unset" |
9815 | || aChangeArg == "-setoverrideglobal") | |
3e05329c | 9816 | { |
9817 | // set / unset plane command | |
32ca7711 | 9818 | const Standard_Boolean toSet = aChangeArg.StartsWith ("-set"); |
9819 | const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal"; | |
3e05329c | 9820 | Standard_Integer anIt = 1; |
9821 | for (; anIt < aNbChangeArgs; ++anIt) | |
9822 | { | |
9823 | TCollection_AsciiString anEntityName (aChangeArgs[anIt]); | |
9824 | if (anEntityName.IsEmpty() | |
9825 | || anEntityName.Value (1) == '-') | |
4269bd1b | 9826 | { |
3e05329c | 9827 | break; |
4269bd1b | 9828 | } |
32ca7711 | 9829 | else if (!toOverrideGlobal |
9830 | && ViewerTest_myViews.IsBound1 (anEntityName)) | |
4269bd1b | 9831 | { |
3e05329c | 9832 | Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName); |
9833 | if (toSet) | |
9834 | { | |
9835 | aView->AddClipPlane (aClipPlane); | |
9836 | } | |
9837 | else | |
9838 | { | |
9839 | aView->RemoveClipPlane (aClipPlane); | |
9840 | } | |
9841 | continue; | |
4269bd1b | 9842 | } |
3e05329c | 9843 | else if (GetMapOfAIS().IsBound2 (anEntityName)) |
4269bd1b | 9844 | { |
8f521168 | 9845 | Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName); |
3e05329c | 9846 | if (toSet) |
9847 | { | |
9848 | aIObj->AddClipPlane (aClipPlane); | |
9849 | } | |
9850 | else | |
9851 | { | |
9852 | aIObj->RemoveClipPlane (aClipPlane); | |
9853 | } | |
32ca7711 | 9854 | if (!aIObj->ClipPlanes().IsNull()) |
9855 | { | |
9856 | aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal); | |
9857 | } | |
4269bd1b | 9858 | } |
3e05329c | 9859 | else |
4269bd1b | 9860 | { |
23fe70ec | 9861 | Message::SendFail() << "Error: object/view '" << anEntityName << "' is not found"; |
3e05329c | 9862 | return 1; |
4269bd1b | 9863 | } |
3e05329c | 9864 | } |
9865 | ||
9866 | if (anIt == 1) | |
9867 | { | |
9868 | // apply to active view | |
9869 | if (toSet) | |
4269bd1b | 9870 | { |
3e05329c | 9871 | anActiveView->AddClipPlane (aClipPlane); |
4269bd1b | 9872 | } |
9873 | else | |
9874 | { | |
3e05329c | 9875 | anActiveView->RemoveClipPlane (aClipPlane); |
4269bd1b | 9876 | } |
9877 | } | |
3e05329c | 9878 | else |
9879 | { | |
9880 | anArgIter = anArgIter + anIt - 1; | |
9881 | } | |
9882 | } | |
9883 | else | |
9884 | { | |
23fe70ec | 9885 | Message::SendFail() << "Syntax error: unknown argument '" << aChangeArg << "'"; |
3e05329c | 9886 | return 1; |
4269bd1b | 9887 | } |
4269bd1b | 9888 | } |
9889 | ||
3e05329c | 9890 | ViewerTest::RedrawAllViews(); |
9891 | return 0; | |
4269bd1b | 9892 | } |
9893 | ||
b5ac8292 | 9894 | //=============================================================================================== |
9895 | //function : VZRange | |
9896 | //purpose : | |
9897 | //=============================================================================================== | |
9898 | static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
9899 | { | |
197ac94e | 9900 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
9901 | ||
9902 | if (aCurrentView.IsNull()) | |
b5ac8292 | 9903 | { |
23fe70ec | 9904 | Message::SendFail ("Error: no active viewer"); |
b5ac8292 | 9905 | return 1; |
9906 | } | |
9907 | ||
197ac94e | 9908 | Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera(); |
b5ac8292 | 9909 | |
9910 | if (theArgsNb < 2) | |
9911 | { | |
9912 | theDi << "ZNear: " << aCamera->ZNear() << "\n"; | |
9913 | theDi << "ZFar: " << aCamera->ZFar() << "\n"; | |
9914 | return 0; | |
9915 | } | |
9916 | ||
9917 | if (theArgsNb == 3) | |
9918 | { | |
6b62b2da | 9919 | Standard_Real aNewZNear = Draw::Atof (theArgVec[1]); |
9920 | Standard_Real aNewZFar = Draw::Atof (theArgVec[2]); | |
197ac94e | 9921 | |
9922 | if (aNewZNear >= aNewZFar) | |
9923 | { | |
23fe70ec | 9924 | Message::SendFail ("Syntax error: invalid arguments: znear should be less than zfar"); |
197ac94e | 9925 | return 1; |
9926 | } | |
9927 | ||
9928 | if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0)) | |
9929 | { | |
23fe70ec | 9930 | Message::SendFail ("Syntax error: invalid arguments: znear, zfar should be positive for perspective camera"); |
197ac94e | 9931 | return 1; |
9932 | } | |
9933 | ||
9934 | aCamera->SetZRange (aNewZNear, aNewZFar); | |
b5ac8292 | 9935 | } |
9936 | else | |
9937 | { | |
23fe70ec | 9938 | Message::SendFail ("Syntax error: wrong command arguments"); |
b5ac8292 | 9939 | return 1; |
9940 | } | |
9941 | ||
197ac94e | 9942 | aCurrentView->Redraw(); |
9943 | ||
b5ac8292 | 9944 | return 0; |
9945 | } | |
9946 | ||
9947 | //=============================================================================================== | |
9948 | //function : VAutoZFit | |
9949 | //purpose : | |
9950 | //=============================================================================================== | |
9951 | static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
9952 | { | |
197ac94e | 9953 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
9954 | ||
9955 | if (aCurrentView.IsNull()) | |
b5ac8292 | 9956 | { |
23fe70ec | 9957 | Message::SendFail ("Error: no active viewer"); |
b5ac8292 | 9958 | return 1; |
9959 | } | |
9960 | ||
c357e426 | 9961 | Standard_Real aScale = aCurrentView->AutoZFitScaleFactor(); |
197ac94e | 9962 | |
9963 | if (theArgsNb > 3) | |
b5ac8292 | 9964 | { |
23fe70ec | 9965 | Message::SendFail ("Syntax error: wrong command arguments"); |
197ac94e | 9966 | return 1; |
b5ac8292 | 9967 | } |
9968 | ||
197ac94e | 9969 | if (theArgsNb < 2) |
b5ac8292 | 9970 | { |
586db386 | 9971 | theDi << "Auto z-fit mode: \n" |
c357e426 | 9972 | << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n" |
197ac94e | 9973 | << "Scale: " << aScale << "\n"; |
9974 | return 0; | |
b5ac8292 | 9975 | } |
197ac94e | 9976 | |
9977 | Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1; | |
9978 | ||
9979 | if (theArgsNb >= 3) | |
b5ac8292 | 9980 | { |
197ac94e | 9981 | aScale = Draw::Atoi (theArgVec[2]); |
b5ac8292 | 9982 | } |
9983 | ||
c357e426 | 9984 | aCurrentView->SetAutoZFitMode (isOn, aScale); |
197ac94e | 9985 | aCurrentView->Redraw(); |
b5ac8292 | 9986 | return 0; |
9987 | } | |
9988 | ||
6b62b2da | 9989 | //! Auxiliary function to print projection type |
9990 | inline const char* projTypeName (Graphic3d_Camera::Projection theProjType) | |
9991 | { | |
9992 | switch (theProjType) | |
9993 | { | |
9994 | case Graphic3d_Camera::Projection_Orthographic: return "orthographic"; | |
9995 | case Graphic3d_Camera::Projection_Perspective: return "perspective"; | |
9996 | case Graphic3d_Camera::Projection_Stereo: return "stereoscopic"; | |
9997 | case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye"; | |
9998 | case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye"; | |
9999 | } | |
10000 | return "UNKNOWN"; | |
10001 | } | |
10002 | ||
b5ac8292 | 10003 | //=============================================================================================== |
6b62b2da | 10004 | //function : VCamera |
b5ac8292 | 10005 | //purpose : |
10006 | //=============================================================================================== | |
6b62b2da | 10007 | static int VCamera (Draw_Interpretor& theDI, |
10008 | Standard_Integer theArgsNb, | |
10009 | const char** theArgVec) | |
b5ac8292 | 10010 | { |
6b62b2da | 10011 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
10012 | if (aView.IsNull()) | |
b5ac8292 | 10013 | { |
23fe70ec | 10014 | Message::SendFail ("Error: no active viewer"); |
b5ac8292 | 10015 | return 1; |
10016 | } | |
10017 | ||
6b62b2da | 10018 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); |
10019 | if (theArgsNb < 2) | |
b5ac8292 | 10020 | { |
6b62b2da | 10021 | theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n"; |
10022 | theDI << "FOVy: " << aCamera->FOVy() << "\n"; | |
b40cdc2b | 10023 | theDI << "FOVx: " << aCamera->FOVx() << "\n"; |
10024 | theDI << "FOV2d: " << aCamera->FOV2d() << "\n"; | |
6b62b2da | 10025 | theDI << "Distance: " << aCamera->Distance() << "\n"; |
10026 | theDI << "IOD: " << aCamera->IOD() << "\n"; | |
10027 | theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n"; | |
10028 | theDI << "ZFocus: " << aCamera->ZFocus() << "\n"; | |
10029 | theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n"; | |
10030 | return 0; | |
b5ac8292 | 10031 | } |
10032 | ||
30a1b24e | 10033 | TCollection_AsciiString aPrsName; |
6b62b2da | 10034 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
b5ac8292 | 10035 | { |
6b62b2da | 10036 | Standard_CString anArg = theArgVec[anArgIter]; |
10037 | TCollection_AsciiString anArgCase (anArg); | |
10038 | anArgCase.LowerCase(); | |
10039 | if (anArgCase == "-proj" | |
10040 | || anArgCase == "-projection" | |
10041 | || anArgCase == "-projtype" | |
10042 | || anArgCase == "-projectiontype") | |
10043 | { | |
10044 | theDI << projTypeName (aCamera->ProjectionType()) << " "; | |
10045 | } | |
10046 | else if (anArgCase == "-ortho" | |
10047 | || anArgCase == "-orthographic") | |
b5ac8292 | 10048 | { |
10049 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic); | |
6b62b2da | 10050 | } |
10051 | else if (anArgCase == "-persp" | |
10052 | || anArgCase == "-perspective" | |
10053 | || anArgCase == "-perspmono" | |
10054 | || anArgCase == "-perspectivemono" | |
10055 | || anArgCase == "-mono") | |
b5ac8292 | 10056 | { |
10057 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
10058 | } | |
6b62b2da | 10059 | else if (anArgCase == "-stereo" |
10060 | || anArgCase == "-stereoscopic" | |
10061 | || anArgCase == "-perspstereo" | |
10062 | || anArgCase == "-perspectivestereo") | |
10063 | { | |
10064 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
10065 | } | |
10066 | else if (anArgCase == "-left" | |
10067 | || anArgCase == "-lefteye" | |
10068 | || anArgCase == "-monoleft" | |
10069 | || anArgCase == "-monolefteye" | |
10070 | || anArgCase == "-perpsleft" | |
10071 | || anArgCase == "-perpslefteye") | |
b5ac8292 | 10072 | { |
10073 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); | |
10074 | } | |
6b62b2da | 10075 | else if (anArgCase == "-right" |
10076 | || anArgCase == "-righteye" | |
10077 | || anArgCase == "-monoright" | |
10078 | || anArgCase == "-monorighteye" | |
10079 | || anArgCase == "-perpsright") | |
b5ac8292 | 10080 | { |
10081 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); | |
10082 | } | |
6b62b2da | 10083 | else if (anArgCase == "-dist" |
10084 | || anArgCase == "-distance") | |
b5ac8292 | 10085 | { |
6b62b2da | 10086 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
10087 | if (anArgValue != NULL | |
10088 | && *anArgValue != '-') | |
10089 | { | |
10090 | ++anArgIter; | |
10091 | aCamera->SetDistance (Draw::Atof (anArgValue)); | |
10092 | continue; | |
10093 | } | |
10094 | theDI << aCamera->Distance() << " "; | |
b5ac8292 | 10095 | } |
6b62b2da | 10096 | else if (anArgCase == "-iod") |
b5ac8292 | 10097 | { |
6b62b2da | 10098 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
10099 | if (anArgValue != NULL | |
10100 | && *anArgValue != '-') | |
10101 | { | |
10102 | ++anArgIter; | |
10103 | aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue)); | |
10104 | continue; | |
10105 | } | |
10106 | theDI << aCamera->IOD() << " "; | |
b5ac8292 | 10107 | } |
6b62b2da | 10108 | else if (anArgCase == "-iodtype") |
b5ac8292 | 10109 | { |
6b62b2da | 10110 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
10111 | TCollection_AsciiString anValueCase (anArgValue); | |
10112 | anValueCase.LowerCase(); | |
10113 | if (anValueCase == "abs" | |
10114 | || anValueCase == "absolute") | |
10115 | { | |
10116 | ++anArgIter; | |
10117 | aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD()); | |
10118 | continue; | |
10119 | } | |
10120 | else if (anValueCase == "rel" | |
10121 | || anValueCase == "relative") | |
10122 | { | |
10123 | ++anArgIter; | |
10124 | aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD()); | |
10125 | continue; | |
10126 | } | |
10127 | else if (*anArgValue != '-') | |
10128 | { | |
23fe70ec | 10129 | Message::SendFail() << "Error: unknown IOD type '" << anArgValue << "'"; |
6b62b2da | 10130 | return 1; |
10131 | } | |
10132 | switch (aCamera->GetIODType()) | |
10133 | { | |
10134 | case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break; | |
10135 | case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break; | |
10136 | } | |
b5ac8292 | 10137 | } |
6b62b2da | 10138 | else if (anArgCase == "-zfocus") |
b5ac8292 | 10139 | { |
6b62b2da | 10140 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
10141 | if (anArgValue != NULL | |
10142 | && *anArgValue != '-') | |
10143 | { | |
10144 | ++anArgIter; | |
10145 | aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue)); | |
10146 | continue; | |
10147 | } | |
10148 | theDI << aCamera->ZFocus() << " "; | |
b5ac8292 | 10149 | } |
6b62b2da | 10150 | else if (anArgCase == "-zfocustype") |
b5ac8292 | 10151 | { |
6b62b2da | 10152 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
10153 | TCollection_AsciiString anValueCase (anArgValue); | |
10154 | anValueCase.LowerCase(); | |
10155 | if (anValueCase == "abs" | |
10156 | || anValueCase == "absolute") | |
10157 | { | |
10158 | ++anArgIter; | |
10159 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus()); | |
10160 | continue; | |
10161 | } | |
10162 | else if (anValueCase == "rel" | |
10163 | || anValueCase == "relative") | |
10164 | { | |
10165 | ++anArgIter; | |
10166 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus()); | |
10167 | continue; | |
10168 | } | |
10169 | else if (*anArgValue != '-') | |
10170 | { | |
23fe70ec | 10171 | Message::SendFail() << "Error: unknown ZFocus type '" << anArgValue << "'"; |
6b62b2da | 10172 | return 1; |
10173 | } | |
10174 | switch (aCamera->ZFocusType()) | |
10175 | { | |
10176 | case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break; | |
10177 | case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break; | |
10178 | } | |
10179 | } | |
b40cdc2b | 10180 | else if (anArgCase == "-lockzup" |
10181 | || anArgCase == "-turntable") | |
10182 | { | |
10183 | bool toLockUp = true; | |
10184 | if (++anArgIter < theArgsNb | |
10185 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toLockUp)) | |
10186 | { | |
10187 | --anArgIter; | |
10188 | } | |
10189 | ViewerTest::CurrentEventManager()->SetLockOrbitZUp (toLockUp); | |
10190 | } | |
6b62b2da | 10191 | else if (anArgCase == "-fov" |
b40cdc2b | 10192 | || anArgCase == "-fovy" |
10193 | || anArgCase == "-fovx" | |
10194 | || anArgCase == "-fov2d") | |
b5ac8292 | 10195 | { |
6b62b2da | 10196 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
10197 | if (anArgValue != NULL | |
10198 | && *anArgValue != '-') | |
10199 | { | |
10200 | ++anArgIter; | |
b40cdc2b | 10201 | if (anArgCase == "-fov2d") |
10202 | { | |
10203 | aCamera->SetFOV2d (Draw::Atof (anArgValue)); | |
10204 | } | |
10205 | else if (anArgCase == "-fovx") | |
10206 | { | |
10207 | aCamera->SetFOVy (Draw::Atof (anArgValue) / aCamera->Aspect());/// | |
10208 | } | |
10209 | else | |
10210 | { | |
10211 | aCamera->SetFOVy (Draw::Atof (anArgValue)); | |
10212 | } | |
6b62b2da | 10213 | continue; |
10214 | } | |
b40cdc2b | 10215 | if (anArgCase == "-fov2d") |
10216 | { | |
10217 | theDI << aCamera->FOV2d() << " "; | |
10218 | } | |
10219 | else if (anArgCase == "-fovx") | |
10220 | { | |
10221 | theDI << aCamera->FOVx() << " "; | |
10222 | } | |
10223 | else | |
10224 | { | |
10225 | theDI << aCamera->FOVy() << " "; | |
10226 | } | |
10227 | } | |
10228 | else if (anArgIter + 1 < theArgsNb | |
10229 | && anArgCase == "-xrpose") | |
10230 | { | |
10231 | TCollection_AsciiString anXRArg (theArgVec[++anArgIter]); | |
10232 | anXRArg.LowerCase(); | |
10233 | if (anXRArg == "base") | |
10234 | { | |
10235 | aCamera = aView->View()->BaseXRCamera(); | |
10236 | } | |
10237 | else if (anXRArg == "head") | |
10238 | { | |
10239 | aCamera = aView->View()->PosedXRCamera(); | |
10240 | } | |
10241 | else | |
10242 | { | |
10243 | Message::SendFail() << "Syntax error: unknown XR pose '" << anXRArg << "'"; | |
10244 | return 1; | |
10245 | } | |
10246 | if (aCamera.IsNull()) | |
10247 | { | |
10248 | Message::SendFail() << "Error: undefined XR pose"; | |
10249 | return 0; | |
10250 | } | |
10251 | if (aView->AutoZFitMode()) | |
10252 | { | |
10253 | const Bnd_Box aMinMaxBox = aView->View()->MinMaxValues (false); | |
10254 | const Bnd_Box aGraphicBox = aView->View()->MinMaxValues (true); | |
10255 | aCamera->ZFitAll (aView->AutoZFitScaleFactor(), aMinMaxBox, aGraphicBox); | |
10256 | } | |
b5ac8292 | 10257 | } |
30a1b24e | 10258 | else if (aPrsName.IsEmpty() |
10259 | && !anArgCase.StartsWith ("-")) | |
10260 | { | |
10261 | aPrsName = anArg; | |
10262 | } | |
b5ac8292 | 10263 | else |
10264 | { | |
23fe70ec | 10265 | Message::SendFail() << "Error: unknown argument '" << anArg << "'"; |
b5ac8292 | 10266 | return 1; |
10267 | } | |
10268 | } | |
b5ac8292 | 10269 | |
30a1b24e | 10270 | if (aPrsName.IsEmpty() |
10271 | || theArgsNb > 2) | |
10272 | { | |
30a1b24e | 10273 | aView->Redraw(); |
10274 | } | |
10275 | ||
10276 | if (!aPrsName.IsEmpty()) | |
10277 | { | |
10278 | Handle(AIS_CameraFrustum) aCameraFrustum; | |
10279 | if (GetMapOfAIS().IsBound2 (aPrsName)) | |
10280 | { | |
10281 | // find existing object | |
10282 | aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1])); | |
10283 | if (aCameraFrustum.IsNull()) | |
10284 | { | |
23fe70ec | 10285 | Message::SendFail() << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum"; |
30a1b24e | 10286 | return 1; |
10287 | } | |
10288 | } | |
10289 | ||
10290 | if (aCameraFrustum.IsNull()) | |
10291 | { | |
10292 | aCameraFrustum = new AIS_CameraFrustum(); | |
10293 | } | |
10294 | else | |
10295 | { | |
10296 | // not include displayed object of old camera frustum in the new one. | |
10297 | ViewerTest::GetAISContext()->Erase (aCameraFrustum, false); | |
10298 | aView->ZFitAll(); | |
10299 | } | |
b40cdc2b | 10300 | aCameraFrustum->SetCameraFrustum (aCamera); |
30a1b24e | 10301 | |
10302 | ViewerTest::Display (aPrsName, aCameraFrustum); | |
10303 | } | |
b5ac8292 | 10304 | |
10305 | return 0; | |
10306 | } | |
10307 | ||
f978241f | 10308 | //! Parse stereo output mode |
10309 | inline Standard_Boolean parseStereoMode (Standard_CString theArg, | |
10310 | Graphic3d_StereoMode& theMode) | |
10311 | { | |
10312 | TCollection_AsciiString aFlag (theArg); | |
10313 | aFlag.LowerCase(); | |
10314 | if (aFlag == "quadbuffer") | |
10315 | { | |
10316 | theMode = Graphic3d_StereoMode_QuadBuffer; | |
10317 | } | |
10318 | else if (aFlag == "anaglyph") | |
10319 | { | |
10320 | theMode = Graphic3d_StereoMode_Anaglyph; | |
10321 | } | |
10322 | else if (aFlag == "row" | |
10323 | || aFlag == "rowinterlaced") | |
10324 | { | |
10325 | theMode = Graphic3d_StereoMode_RowInterlaced; | |
10326 | } | |
10327 | else if (aFlag == "col" | |
10328 | || aFlag == "colinterlaced" | |
10329 | || aFlag == "columninterlaced") | |
10330 | { | |
10331 | theMode = Graphic3d_StereoMode_ColumnInterlaced; | |
10332 | } | |
10333 | else if (aFlag == "chess" | |
10334 | || aFlag == "chessboard") | |
10335 | { | |
10336 | theMode = Graphic3d_StereoMode_ChessBoard; | |
10337 | } | |
10338 | else if (aFlag == "sbs" | |
10339 | || aFlag == "sidebyside") | |
10340 | { | |
10341 | theMode = Graphic3d_StereoMode_SideBySide; | |
10342 | } | |
10343 | else if (aFlag == "ou" | |
10344 | || aFlag == "overunder") | |
10345 | { | |
10346 | theMode = Graphic3d_StereoMode_OverUnder; | |
10347 | } | |
10348 | else if (aFlag == "pageflip" | |
10349 | || aFlag == "softpageflip") | |
10350 | { | |
10351 | theMode = Graphic3d_StereoMode_SoftPageFlip; | |
10352 | } | |
b40cdc2b | 10353 | else if (aFlag == "openvr" |
10354 | || aFlag == "vr") | |
10355 | { | |
10356 | theMode = Graphic3d_StereoMode_OpenVR; | |
10357 | } | |
f978241f | 10358 | else |
10359 | { | |
10360 | return Standard_False; | |
10361 | } | |
10362 | return Standard_True; | |
10363 | } | |
10364 | ||
10365 | //! Parse anaglyph filter | |
10366 | inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg, | |
10367 | Graphic3d_RenderingParams::Anaglyph& theFilter) | |
10368 | { | |
10369 | TCollection_AsciiString aFlag (theArg); | |
10370 | aFlag.LowerCase(); | |
10371 | if (aFlag == "redcyansimple") | |
10372 | { | |
10373 | theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple; | |
10374 | } | |
10375 | else if (aFlag == "redcyan" | |
10376 | || aFlag == "redcyanoptimized") | |
10377 | { | |
10378 | theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized; | |
10379 | } | |
10380 | else if (aFlag == "yellowbluesimple") | |
10381 | { | |
10382 | theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple; | |
10383 | } | |
10384 | else if (aFlag == "yellowblue" | |
10385 | || aFlag == "yellowblueoptimized") | |
10386 | { | |
10387 | theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized; | |
10388 | } | |
10389 | else if (aFlag == "greenmagenta" | |
10390 | || aFlag == "greenmagentasimple") | |
10391 | { | |
10392 | theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple; | |
10393 | } | |
10394 | else | |
10395 | { | |
10396 | return Standard_False; | |
10397 | } | |
10398 | return Standard_True; | |
10399 | } | |
10400 | ||
b5ac8292 | 10401 | //============================================================================== |
10402 | //function : VStereo | |
10403 | //purpose : | |
10404 | //============================================================================== | |
10405 | ||
10406 | static int VStereo (Draw_Interpretor& theDI, | |
10407 | Standard_Integer theArgNb, | |
10408 | const char** theArgVec) | |
10409 | { | |
f978241f | 10410 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
b5ac8292 | 10411 | if (theArgNb < 2) |
10412 | { | |
b5ac8292 | 10413 | if (aView.IsNull()) |
10414 | { | |
23fe70ec | 10415 | Message::SendFail ("Error: no active viewer"); |
b5ac8292 | 10416 | return 0; |
10417 | } | |
10418 | ||
10419 | Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo; | |
10420 | theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n"; | |
bf02aa7d | 10421 | if (isActive) |
10422 | { | |
10423 | TCollection_AsciiString aMode; | |
10424 | switch (aView->RenderingParams().StereoMode) | |
10425 | { | |
10426 | case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break; | |
10427 | case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break; | |
10428 | case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break; | |
10429 | case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break; | |
10430 | case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break; | |
10431 | case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break; | |
10432 | case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break; | |
b40cdc2b | 10433 | case Graphic3d_StereoMode_OpenVR : aMode = "openVR"; break; |
bf02aa7d | 10434 | case Graphic3d_StereoMode_Anaglyph : |
10435 | aMode = "anaglyph"; | |
10436 | switch (aView->RenderingParams().AnaglyphFilter) | |
10437 | { | |
10438 | case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break; | |
10439 | case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break; | |
10440 | case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break; | |
10441 | case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break; | |
10442 | case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break; | |
10443 | default: break; | |
10444 | } | |
10445 | default: break; | |
10446 | } | |
10447 | theDI << "Mode " << aMode << "\n"; | |
10448 | } | |
b5ac8292 | 10449 | return 0; |
10450 | } | |
10451 | ||
f978241f | 10452 | Handle(Graphic3d_Camera) aCamera; |
10453 | Graphic3d_RenderingParams* aParams = NULL; | |
10454 | Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer; | |
10455 | if (!aView.IsNull()) | |
10456 | { | |
10457 | aParams = &aView->ChangeRenderingParams(); | |
10458 | aMode = aParams->StereoMode; | |
10459 | aCamera = aView->Camera(); | |
10460 | } | |
10461 | ||
10462 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); | |
10463 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
10464 | { | |
10465 | Standard_CString anArg = theArgVec[anArgIter]; | |
10466 | TCollection_AsciiString aFlag (anArg); | |
10467 | aFlag.LowerCase(); | |
10468 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
10469 | { | |
10470 | continue; | |
10471 | } | |
10472 | else if (aFlag == "0" | |
10473 | || aFlag == "off") | |
10474 | { | |
10475 | if (++anArgIter < theArgNb) | |
10476 | { | |
23fe70ec | 10477 | Message::SendFail ("Error: wrong number of arguments"); |
f978241f | 10478 | return 1; |
10479 | } | |
10480 | ||
10481 | if (!aCamera.IsNull() | |
10482 | && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo) | |
10483 | { | |
10484 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
10485 | } | |
10486 | ViewerTest_myDefaultCaps.contextStereo = Standard_False; | |
10487 | return 0; | |
10488 | } | |
10489 | else if (aFlag == "1" | |
10490 | || aFlag == "on") | |
10491 | { | |
10492 | if (++anArgIter < theArgNb) | |
10493 | { | |
23fe70ec | 10494 | Message::SendFail ("Error: wrong number of arguments"); |
f978241f | 10495 | return 1; |
10496 | } | |
10497 | ||
10498 | if (!aCamera.IsNull()) | |
10499 | { | |
10500 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
10501 | } | |
10502 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
b40cdc2b | 10503 | if (aParams->StereoMode != Graphic3d_StereoMode_OpenVR) |
10504 | { | |
10505 | return 0; | |
10506 | } | |
f978241f | 10507 | } |
10508 | else if (aFlag == "-reverse" | |
10509 | || aFlag == "-reversed" | |
10510 | || aFlag == "-swap") | |
10511 | { | |
10512 | Standard_Boolean toEnable = Standard_True; | |
10513 | if (++anArgIter < theArgNb | |
a5565a3c | 10514 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 10515 | { |
10516 | --anArgIter; | |
10517 | } | |
10518 | aParams->ToReverseStereo = toEnable; | |
10519 | } | |
10520 | else if (aFlag == "-noreverse" | |
10521 | || aFlag == "-noswap") | |
10522 | { | |
10523 | Standard_Boolean toDisable = Standard_True; | |
10524 | if (++anArgIter < theArgNb | |
a5565a3c | 10525 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable)) |
f978241f | 10526 | { |
10527 | --anArgIter; | |
10528 | } | |
10529 | aParams->ToReverseStereo = !toDisable; | |
10530 | } | |
10531 | else if (aFlag == "-mode" | |
10532 | || aFlag == "-stereomode") | |
10533 | { | |
10534 | if (++anArgIter >= theArgNb | |
10535 | || !parseStereoMode (theArgVec[anArgIter], aMode)) | |
10536 | { | |
23fe70ec | 10537 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
f978241f | 10538 | return 1; |
10539 | } | |
10540 | ||
10541 | if (aMode == Graphic3d_StereoMode_QuadBuffer) | |
10542 | { | |
10543 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
10544 | } | |
10545 | } | |
10546 | else if (aFlag == "-anaglyph" | |
10547 | || aFlag == "-anaglyphfilter") | |
10548 | { | |
10549 | Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple; | |
10550 | if (++anArgIter >= theArgNb | |
10551 | || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter)) | |
10552 | { | |
23fe70ec | 10553 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
f978241f | 10554 | return 1; |
10555 | } | |
10556 | ||
10557 | aMode = Graphic3d_StereoMode_Anaglyph; | |
10558 | aParams->AnaglyphFilter = aFilter; | |
10559 | } | |
10560 | else if (parseStereoMode (anArg, aMode)) // short syntax | |
10561 | { | |
10562 | if (aMode == Graphic3d_StereoMode_QuadBuffer) | |
10563 | { | |
10564 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
10565 | } | |
10566 | } | |
b40cdc2b | 10567 | else if (anArgIter + 1 < theArgNb |
10568 | && aFlag == "-hmdfov2d") | |
10569 | { | |
10570 | aParams->HmdFov2d = (float )Draw::Atof (theArgVec[++anArgIter]); | |
10571 | if (aParams->HmdFov2d < 10.0f | |
10572 | || aParams->HmdFov2d > 180.0f) | |
10573 | { | |
10574 | Message::SendFail() << "Error: FOV is out of range"; | |
10575 | return 1; | |
10576 | } | |
10577 | } | |
10578 | else if (aFlag == "-mirror" | |
10579 | || aFlag == "-mirrorcomposer") | |
10580 | { | |
10581 | Standard_Boolean toEnable = Standard_True; | |
10582 | if (++anArgIter < theArgNb | |
10583 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
10584 | { | |
10585 | --anArgIter; | |
10586 | } | |
10587 | aParams->ToMirrorComposer = toEnable; | |
10588 | } | |
10589 | else if (anArgIter + 1 < theArgNb | |
10590 | && (aFlag == "-unitfactor" | |
10591 | || aFlag == "-unitscale")) | |
10592 | { | |
10593 | aView->View()->SetUnitFactor (Draw::Atof (theArgVec[++anArgIter])); | |
10594 | } | |
f978241f | 10595 | else |
10596 | { | |
23fe70ec | 10597 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
f978241f | 10598 | return 1; |
10599 | } | |
10600 | } | |
10601 | ||
10602 | if (!aView.IsNull()) | |
10603 | { | |
10604 | aParams->StereoMode = aMode; | |
10605 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
b40cdc2b | 10606 | if (aParams->StereoMode == Graphic3d_StereoMode_OpenVR) |
10607 | { | |
10608 | // initiate implicit continuous rendering | |
10609 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true); | |
10610 | } | |
f978241f | 10611 | } |
b5ac8292 | 10612 | return 0; |
10613 | } | |
10614 | ||
392ac980 | 10615 | //=============================================================================================== |
10616 | //function : VDefaults | |
10617 | //purpose : | |
10618 | //=============================================================================================== | |
10619 | static int VDefaults (Draw_Interpretor& theDi, | |
10620 | Standard_Integer theArgsNb, | |
10621 | const char** theArgVec) | |
10622 | { | |
10623 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
10624 | if (aCtx.IsNull()) | |
10625 | { | |
23fe70ec | 10626 | Message::SendFail ("Error: no active viewer"); |
392ac980 | 10627 | return 1; |
10628 | } | |
10629 | ||
10630 | Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer(); | |
10631 | if (theArgsNb < 2) | |
10632 | { | |
10633 | if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE) | |
10634 | { | |
10635 | theDi << "DeflType: relative\n" | |
10636 | << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n"; | |
10637 | } | |
10638 | else | |
10639 | { | |
10640 | theDi << "DeflType: absolute\n" | |
10641 | << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n"; | |
10642 | } | |
67441d0c | 10643 | theDi << "AngularDeflection: " << (180.0 * aDefParams->DeviationAngle() / M_PI) << "\n"; |
4c513386 | 10644 | theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n"; |
392ac980 | 10645 | return 0; |
10646 | } | |
10647 | ||
10648 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
10649 | { | |
10650 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4c513386 | 10651 | anArg.UpperCase(); |
10652 | if (anArg == "-ABSDEFL" | |
10653 | || anArg == "-ABSOLUTEDEFLECTION" | |
10654 | || anArg == "-DEFL" | |
10655 | || anArg == "-DEFLECTION") | |
392ac980 | 10656 | { |
4c513386 | 10657 | if (++anArgIter >= theArgsNb) |
10658 | { | |
23fe70ec | 10659 | Message::SendFail() << "Syntax error at " << anArg; |
4c513386 | 10660 | return 1; |
10661 | } | |
392ac980 | 10662 | aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); |
4c513386 | 10663 | aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 10664 | } |
4c513386 | 10665 | else if (anArg == "-RELDEFL" |
10666 | || anArg == "-RELATIVEDEFLECTION" | |
10667 | || anArg == "-DEVCOEFF" | |
10668 | || anArg == "-DEVIATIONCOEFF" | |
10669 | || anArg == "-DEVIATIONCOEFFICIENT") | |
392ac980 | 10670 | { |
4c513386 | 10671 | if (++anArgIter >= theArgsNb) |
10672 | { | |
23fe70ec | 10673 | Message::SendFail() << "Syntax error at " << anArg; |
4c513386 | 10674 | return 1; |
10675 | } | |
392ac980 | 10676 | aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE); |
4c513386 | 10677 | aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 10678 | } |
4c513386 | 10679 | else if (anArg == "-ANGDEFL" |
10680 | || anArg == "-ANGULARDEFL" | |
10681 | || anArg == "-ANGULARDEFLECTION") | |
392ac980 | 10682 | { |
4c513386 | 10683 | if (++anArgIter >= theArgsNb) |
10684 | { | |
23fe70ec | 10685 | Message::SendFail() << "Syntax error at " << anArg; |
4c513386 | 10686 | return 1; |
10687 | } | |
67441d0c | 10688 | aDefParams->SetDeviationAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0); |
4c513386 | 10689 | } |
385c43e7 | 10690 | else if (anArg == "-AUTOTR" |
10691 | || anArg == "-AUTOTRIANG" | |
10692 | || anArg == "-AUTOTRIANGULATION") | |
4c513386 | 10693 | { |
14c7f553 | 10694 | ++anArgIter; |
10695 | bool toTurnOn = true; | |
10696 | if (anArgIter >= theArgsNb | |
10697 | || !ViewerTest::ParseOnOff (theArgVec[anArgIter], toTurnOn)) | |
4c513386 | 10698 | { |
23fe70ec | 10699 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
4c513386 | 10700 | return 1; |
10701 | } | |
14c7f553 | 10702 | aDefParams->SetAutoTriangulation (toTurnOn); |
392ac980 | 10703 | } |
10704 | else | |
10705 | { | |
23fe70ec | 10706 | Message::SendFail() << "Syntax error: unknown argument '" << anArg << "'"; |
14c7f553 | 10707 | return 1; |
392ac980 | 10708 | } |
10709 | } | |
10710 | ||
10711 | return 0; | |
10712 | } | |
10713 | ||
12381341 | 10714 | //! Auxiliary method |
10715 | inline void addLight (const Handle(V3d_Light)& theLightNew, | |
992ed6b3 | 10716 | const Graphic3d_ZLayerId theLayer, |
12381341 | 10717 | const Standard_Boolean theIsGlobal) |
10718 | { | |
10719 | if (theLightNew.IsNull()) | |
10720 | { | |
10721 | return; | |
10722 | } | |
10723 | ||
992ed6b3 | 10724 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); |
10725 | if (theLayer == Graphic3d_ZLayerId_UNKNOWN) | |
12381341 | 10726 | { |
992ed6b3 | 10727 | aViewer->AddLight (theLightNew); |
10728 | if (theIsGlobal) | |
10729 | { | |
10730 | aViewer->SetLightOn (theLightNew); | |
10731 | } | |
10732 | else | |
10733 | { | |
10734 | ViewerTest::CurrentView()->SetLightOn (theLightNew); | |
10735 | } | |
12381341 | 10736 | } |
10737 | else | |
10738 | { | |
992ed6b3 | 10739 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer); |
10740 | if (aSettings.Lights().IsNull()) | |
10741 | { | |
10742 | aSettings.SetLights (new Graphic3d_LightSet()); | |
10743 | } | |
10744 | aSettings.Lights()->Add (theLightNew); | |
10745 | aViewer->SetZLayerSettings (theLayer, aSettings); | |
12381341 | 10746 | } |
10747 | } | |
10748 | ||
10749 | //! Auxiliary method | |
10750 | inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext) | |
10751 | { | |
10752 | TCollection_AsciiString anArgNextCase (theArgNext); | |
10753 | anArgNextCase.UpperCase(); | |
10754 | if (anArgNextCase.Length() > 5 | |
10755 | && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT")) | |
10756 | { | |
10757 | return theArgNext.SubString (6, theArgNext.Length()).IntegerValue(); | |
10758 | } | |
10759 | else | |
10760 | { | |
10761 | return theArgNext.IntegerValue(); | |
10762 | } | |
10763 | } | |
10764 | ||
10765 | //=============================================================================================== | |
10766 | //function : VLight | |
10767 | //purpose : | |
10768 | //=============================================================================================== | |
10769 | static int VLight (Draw_Interpretor& theDi, | |
10770 | Standard_Integer theArgsNb, | |
10771 | const char** theArgVec) | |
10772 | { | |
10773 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
10774 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
10775 | if (aView.IsNull() | |
10776 | || aViewer.IsNull()) | |
10777 | { | |
23fe70ec | 10778 | Message::SendFail ("Error: no active viewer"); |
12381341 | 10779 | return 1; |
10780 | } | |
10781 | ||
ee2be2a8 | 10782 | Standard_Real anXYZ[3] = {}; |
10783 | Standard_Real anAtten[2] = {}; | |
12381341 | 10784 | if (theArgsNb < 2) |
10785 | { | |
10786 | // print lights info | |
10787 | Standard_Integer aLightId = 0; | |
6a24c6de | 10788 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId) |
12381341 | 10789 | { |
6a24c6de | 10790 | Handle(V3d_Light) aLight = aLightIter.Value(); |
12381341 | 10791 | const Quantity_Color aColor = aLight->Color(); |
992ed6b3 | 10792 | theDi << "Light #" << aLightId |
10793 | << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "") | |
10794 | << " [" << aLight->GetId() << "]" << "\n"; | |
12381341 | 10795 | switch (aLight->Type()) |
10796 | { | |
10797 | case V3d_AMBIENT: | |
10798 | { | |
189f85a3 | 10799 | theDi << " Type: Ambient\n"; |
10800 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
12381341 | 10801 | break; |
10802 | } | |
10803 | case V3d_DIRECTIONAL: | |
10804 | { | |
189f85a3 | 10805 | theDi << " Type: Directional\n"; |
10806 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
10807 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
10808 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; | |
992ed6b3 | 10809 | aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); |
10810 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
12381341 | 10811 | break; |
10812 | } | |
10813 | case V3d_POSITIONAL: | |
10814 | { | |
189f85a3 | 10815 | theDi << " Type: Positional\n"; |
10816 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
10817 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
10818 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; | |
992ed6b3 | 10819 | aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]); |
10820 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
10821 | aLight->Attenuation (anAtten[0], anAtten[1]); | |
10822 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; | |
88b312d3 | 10823 | theDi << " Range: " << aLight->Range() << "\n"; |
12381341 | 10824 | break; |
10825 | } | |
10826 | case V3d_SPOT: | |
10827 | { | |
189f85a3 | 10828 | theDi << " Type: Spot\n"; |
10829 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
10830 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
992ed6b3 | 10831 | aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]); |
10832 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
10833 | aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); | |
10834 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
10835 | aLight->Attenuation (anAtten[0], anAtten[1]); | |
10836 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; | |
10837 | theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n"; | |
10838 | theDi << " Exponent: " << aLight->Concentration() << "\n"; | |
88b312d3 | 10839 | theDi << " Range: " << aLight->Range() << "\n"; |
12381341 | 10840 | break; |
10841 | } | |
10842 | default: | |
10843 | { | |
189f85a3 | 10844 | theDi << " Type: UNKNOWN\n"; |
12381341 | 10845 | break; |
10846 | } | |
10847 | } | |
992ed6b3 | 10848 | theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n"; |
12381341 | 10849 | } |
10850 | } | |
10851 | ||
10852 | Handle(V3d_Light) aLightNew; | |
10853 | Handle(V3d_Light) aLightOld; | |
992ed6b3 | 10854 | Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN; |
12381341 | 10855 | Standard_Boolean isGlobal = Standard_True; |
10856 | Standard_Boolean toCreate = Standard_False; | |
761d8807 | 10857 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
12381341 | 10858 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
10859 | { | |
992ed6b3 | 10860 | Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew; |
12381341 | 10861 | |
10862 | TCollection_AsciiString aName, aValue; | |
10863 | const TCollection_AsciiString anArg (theArgVec[anArgIt]); | |
10864 | TCollection_AsciiString anArgCase (anArg); | |
10865 | anArgCase.UpperCase(); | |
761d8807 | 10866 | if (anUpdateTool.parseRedrawMode (anArg)) |
10867 | { | |
10868 | continue; | |
10869 | } | |
10870 | ||
12381341 | 10871 | if (anArgCase.IsEqual ("NEW") |
10872 | || anArgCase.IsEqual ("ADD") | |
992ed6b3 | 10873 | || anArgCase.IsEqual ("CREATE") |
10874 | || anArgCase.IsEqual ("-NEW") | |
10875 | || anArgCase.IsEqual ("-ADD") | |
10876 | || anArgCase.IsEqual ("-CREATE")) | |
12381341 | 10877 | { |
10878 | toCreate = Standard_True; | |
10879 | } | |
992ed6b3 | 10880 | else if (anArgCase.IsEqual ("-LAYER") |
10881 | || anArgCase.IsEqual ("-ZLAYER")) | |
10882 | { | |
10883 | if (++anArgIt >= theArgsNb) | |
10884 | { | |
23fe70ec | 10885 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
992ed6b3 | 10886 | return 1; |
10887 | } | |
10888 | ||
10889 | TCollection_AsciiString aValStr (theArgVec[anArgIt]); | |
10890 | aValStr.LowerCase(); | |
10891 | if (aValStr == "default" | |
10892 | || aValStr == "def") | |
10893 | { | |
10894 | aLayer = Graphic3d_ZLayerId_Default; | |
10895 | } | |
10896 | else if (aValStr == "top") | |
10897 | { | |
10898 | aLayer = Graphic3d_ZLayerId_Top; | |
10899 | } | |
10900 | else if (aValStr == "topmost") | |
10901 | { | |
10902 | aLayer = Graphic3d_ZLayerId_Topmost; | |
10903 | } | |
10904 | else if (aValStr == "toposd" | |
10905 | || aValStr == "osd") | |
10906 | { | |
10907 | aLayer = Graphic3d_ZLayerId_TopOSD; | |
10908 | } | |
10909 | else if (aValStr == "botosd" | |
10910 | || aValStr == "bottom") | |
10911 | { | |
10912 | aLayer = Graphic3d_ZLayerId_BotOSD; | |
10913 | } | |
10914 | else if (aValStr.IsIntegerValue()) | |
10915 | { | |
10916 | aLayer = Draw::Atoi (theArgVec[anArgIt]); | |
10917 | } | |
10918 | else | |
10919 | { | |
23fe70ec | 10920 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
992ed6b3 | 10921 | return 1; |
10922 | } | |
10923 | } | |
12381341 | 10924 | else if (anArgCase.IsEqual ("GLOB") |
992ed6b3 | 10925 | || anArgCase.IsEqual ("GLOBAL") |
10926 | || anArgCase.IsEqual ("-GLOB") | |
10927 | || anArgCase.IsEqual ("-GLOBAL")) | |
12381341 | 10928 | { |
10929 | isGlobal = Standard_True; | |
10930 | } | |
10931 | else if (anArgCase.IsEqual ("LOC") | |
992ed6b3 | 10932 | || anArgCase.IsEqual ("LOCAL") |
10933 | || anArgCase.IsEqual ("-LOC") | |
10934 | || anArgCase.IsEqual ("-LOCAL")) | |
12381341 | 10935 | { |
10936 | isGlobal = Standard_False; | |
10937 | } | |
4fe9ad57 | 10938 | else if (anArgCase.IsEqual ("DEF") |
992ed6b3 | 10939 | || anArgCase.IsEqual ("DEFAULTS") |
10940 | || anArgCase.IsEqual ("-DEF") | |
10941 | || anArgCase.IsEqual ("-DEFAULTS")) | |
4fe9ad57 | 10942 | { |
10943 | toCreate = Standard_False; | |
10944 | aViewer->SetDefaultLights(); | |
10945 | } | |
10946 | else if (anArgCase.IsEqual ("CLR") | |
992ed6b3 | 10947 | || anArgCase.IsEqual ("CLEAR") |
10948 | || anArgCase.IsEqual ("-CLR") | |
10949 | || anArgCase.IsEqual ("-CLEAR")) | |
4fe9ad57 | 10950 | { |
10951 | toCreate = Standard_False; | |
992ed6b3 | 10952 | |
10953 | TColStd_SequenceOfInteger aLayers; | |
10954 | aViewer->GetAllZLayers (aLayers); | |
10955 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
4fe9ad57 | 10956 | { |
992ed6b3 | 10957 | if (aLayeriter.Value() == aLayer |
10958 | || aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
10959 | { | |
10960 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
10961 | aSettings.SetLights (Handle(Graphic3d_LightSet)()); | |
10962 | aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings); | |
10963 | if (aLayer != Graphic3d_ZLayerId_UNKNOWN) | |
10964 | { | |
10965 | break; | |
10966 | } | |
10967 | } | |
10968 | } | |
10969 | ||
10970 | if (aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
10971 | { | |
10972 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();) | |
10973 | { | |
10974 | Handle(V3d_Light) aLight = aLightIter.Value(); | |
10975 | aViewer->DelLight (aLight); | |
10976 | aLightIter = aView->ActiveLightIterator(); | |
10977 | } | |
4fe9ad57 | 10978 | } |
10979 | } | |
12381341 | 10980 | else if (anArgCase.IsEqual ("AMB") |
10981 | || anArgCase.IsEqual ("AMBIENT") | |
10982 | || anArgCase.IsEqual ("AMBLIGHT")) | |
10983 | { | |
12381341 | 10984 | if (!toCreate) |
10985 | { | |
23fe70ec | 10986 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 10987 | return 1; |
10988 | } | |
992ed6b3 | 10989 | |
10990 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 10991 | toCreate = Standard_False; |
992ed6b3 | 10992 | aLightNew = new V3d_AmbientLight(); |
12381341 | 10993 | } |
10994 | else if (anArgCase.IsEqual ("DIRECTIONAL") | |
10995 | || anArgCase.IsEqual ("DIRLIGHT")) | |
10996 | { | |
12381341 | 10997 | if (!toCreate) |
10998 | { | |
23fe70ec | 10999 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11000 | return 1; |
11001 | } | |
992ed6b3 | 11002 | |
11003 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 11004 | toCreate = Standard_False; |
992ed6b3 | 11005 | aLightNew = new V3d_DirectionalLight(); |
12381341 | 11006 | } |
11007 | else if (anArgCase.IsEqual ("SPOT") | |
11008 | || anArgCase.IsEqual ("SPOTLIGHT")) | |
11009 | { | |
12381341 | 11010 | if (!toCreate) |
11011 | { | |
23fe70ec | 11012 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11013 | return 1; |
11014 | } | |
992ed6b3 | 11015 | |
11016 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 11017 | toCreate = Standard_False; |
992ed6b3 | 11018 | aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0)); |
12381341 | 11019 | } |
11020 | else if (anArgCase.IsEqual ("POSLIGHT") | |
11021 | || anArgCase.IsEqual ("POSITIONAL")) | |
11022 | { | |
12381341 | 11023 | if (!toCreate) |
11024 | { | |
23fe70ec | 11025 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11026 | return 1; |
11027 | } | |
992ed6b3 | 11028 | |
11029 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 11030 | toCreate = Standard_False; |
992ed6b3 | 11031 | aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0)); |
12381341 | 11032 | } |
992ed6b3 | 11033 | else if (anArgCase.IsEqual ("CHANGE") |
11034 | || anArgCase.IsEqual ("-CHANGE")) | |
12381341 | 11035 | { |
12381341 | 11036 | if (++anArgIt >= theArgsNb) |
11037 | { | |
23fe70ec | 11038 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11039 | return 1; |
11040 | } | |
11041 | ||
992ed6b3 | 11042 | addLight (aLightNew, aLayer, isGlobal); |
11043 | aLightNew.Nullify(); | |
12381341 | 11044 | const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]); |
11045 | Standard_Integer aLightIt = 0; | |
6a24c6de | 11046 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt) |
12381341 | 11047 | { |
11048 | if (aLightIt == aLightId) | |
11049 | { | |
6a24c6de | 11050 | aLightOld = aLightIter.Value(); |
12381341 | 11051 | break; |
11052 | } | |
11053 | } | |
11054 | ||
11055 | if (aLightOld.IsNull()) | |
11056 | { | |
23fe70ec | 11057 | Message::SendFail() << "Error: Light " << theArgVec[anArgIt] << " is undefined"; |
12381341 | 11058 | return 1; |
11059 | } | |
11060 | } | |
11061 | else if (anArgCase.IsEqual ("DEL") | |
992ed6b3 | 11062 | || anArgCase.IsEqual ("DELETE") |
11063 | || anArgCase.IsEqual ("-DEL") | |
11064 | || anArgCase.IsEqual ("-DELETE")) | |
12381341 | 11065 | { |
11066 | Handle(V3d_Light) aLightDel; | |
11067 | if (++anArgIt >= theArgsNb) | |
11068 | { | |
23fe70ec | 11069 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11070 | return 1; |
11071 | } | |
11072 | ||
11073 | const TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
11074 | const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]); | |
11075 | Standard_Integer aLightIt = 0; | |
6a24c6de | 11076 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt) |
12381341 | 11077 | { |
6a24c6de | 11078 | aLightDel = aLightIter.Value(); |
12381341 | 11079 | if (aLightIt == aLightDelId) |
11080 | { | |
11081 | break; | |
11082 | } | |
11083 | } | |
992ed6b3 | 11084 | if (aLightDel.IsNull()) |
11085 | { | |
11086 | continue; | |
11087 | } | |
11088 | ||
11089 | TColStd_SequenceOfInteger aLayers; | |
11090 | aViewer->GetAllZLayers (aLayers); | |
11091 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
11092 | { | |
11093 | if (aLayeriter.Value() == aLayer | |
11094 | || aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
11095 | { | |
11096 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
11097 | if (!aSettings.Lights().IsNull()) | |
11098 | { | |
11099 | aSettings.Lights()->Remove (aLightDel); | |
11100 | if (aSettings.Lights()->IsEmpty()) | |
11101 | { | |
11102 | aSettings.SetLights (Handle(Graphic3d_LightSet)()); | |
11103 | } | |
11104 | } | |
11105 | aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings); | |
11106 | if (aLayer != Graphic3d_ZLayerId_UNKNOWN) | |
11107 | { | |
11108 | break; | |
11109 | } | |
11110 | } | |
11111 | } | |
11112 | ||
11113 | if (aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
12381341 | 11114 | { |
11115 | aViewer->DelLight (aLightDel); | |
11116 | } | |
11117 | } | |
11118 | else if (anArgCase.IsEqual ("COLOR") | |
992ed6b3 | 11119 | || anArgCase.IsEqual ("COLOUR") |
11120 | || anArgCase.IsEqual ("-COLOR") | |
11121 | || anArgCase.IsEqual ("-COLOUR")) | |
12381341 | 11122 | { |
992ed6b3 | 11123 | if (++anArgIt >= theArgsNb |
11124 | || aLightCurr.IsNull()) | |
12381341 | 11125 | { |
23fe70ec | 11126 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11127 | return 1; |
11128 | } | |
11129 | ||
11130 | TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
11131 | anArgNext.UpperCase(); | |
11132 | const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString()); | |
992ed6b3 | 11133 | aLightCurr->SetColor (aColor); |
12381341 | 11134 | } |
11135 | else if (anArgCase.IsEqual ("POS") | |
992ed6b3 | 11136 | || anArgCase.IsEqual ("POSITION") |
11137 | || anArgCase.IsEqual ("-POS") | |
11138 | || anArgCase.IsEqual ("-POSITION")) | |
12381341 | 11139 | { |
992ed6b3 | 11140 | if ((anArgIt + 3) >= theArgsNb |
11141 | || aLightCurr.IsNull() | |
11142 | || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL | |
11143 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 11144 | { |
23fe70ec | 11145 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11146 | return 1; |
11147 | } | |
11148 | ||
11149 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
11150 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
11151 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
992ed6b3 | 11152 | aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); |
12381341 | 11153 | } |
11154 | else if (anArgCase.IsEqual ("DIR") | |
992ed6b3 | 11155 | || anArgCase.IsEqual ("DIRECTION") |
11156 | || anArgCase.IsEqual ("-DIR") | |
11157 | || anArgCase.IsEqual ("-DIRECTION")) | |
12381341 | 11158 | { |
992ed6b3 | 11159 | if ((anArgIt + 3) >= theArgsNb |
11160 | || aLightCurr.IsNull() | |
11161 | || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL | |
11162 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 11163 | { |
23fe70ec | 11164 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11165 | return 1; |
11166 | } | |
11167 | ||
11168 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
11169 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
11170 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
992ed6b3 | 11171 | aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); |
12381341 | 11172 | } |
189f85a3 | 11173 | else if (anArgCase.IsEqual ("SM") |
992ed6b3 | 11174 | || anArgCase.IsEqual ("SMOOTHNESS") |
11175 | || anArgCase.IsEqual ("-SM") | |
11176 | || anArgCase.IsEqual ("-SMOOTHNESS")) | |
189f85a3 | 11177 | { |
992ed6b3 | 11178 | if (++anArgIt >= theArgsNb |
11179 | || aLightCurr.IsNull()) | |
189f85a3 | 11180 | { |
23fe70ec | 11181 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
189f85a3 | 11182 | return 1; |
11183 | } | |
11184 | ||
992ed6b3 | 11185 | Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]); |
11186 | if (Abs (aSmoothness) <= ShortRealEpsilon()) | |
189f85a3 | 11187 | { |
11188 | aLightCurr->SetIntensity (1.f); | |
11189 | } | |
992ed6b3 | 11190 | else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon()) |
189f85a3 | 11191 | { |
11192 | aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f); | |
11193 | } | |
11194 | else | |
11195 | { | |
11196 | Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness()); | |
11197 | aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio)); | |
11198 | } | |
11199 | ||
992ed6b3 | 11200 | if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL) |
189f85a3 | 11201 | { |
992ed6b3 | 11202 | aLightCurr->SetSmoothRadius (aSmoothness); |
189f85a3 | 11203 | } |
992ed6b3 | 11204 | else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL) |
189f85a3 | 11205 | { |
992ed6b3 | 11206 | aLightCurr->SetSmoothAngle (aSmoothness); |
189f85a3 | 11207 | } |
11208 | } | |
11209 | else if (anArgCase.IsEqual ("INT") | |
992ed6b3 | 11210 | || anArgCase.IsEqual ("INTENSITY") |
11211 | || anArgCase.IsEqual ("-INT") | |
11212 | || anArgCase.IsEqual ("-INTENSITY")) | |
189f85a3 | 11213 | { |
992ed6b3 | 11214 | if (++anArgIt >= theArgsNb |
11215 | || aLightCurr.IsNull()) | |
189f85a3 | 11216 | { |
23fe70ec | 11217 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
189f85a3 | 11218 | return 1; |
11219 | } | |
11220 | ||
992ed6b3 | 11221 | Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]); |
11222 | aLightCurr->SetIntensity (aIntensity); | |
189f85a3 | 11223 | } |
4fe9ad57 | 11224 | else if (anArgCase.IsEqual ("ANG") |
992ed6b3 | 11225 | || anArgCase.IsEqual ("ANGLE") |
11226 | || anArgCase.IsEqual ("-ANG") | |
11227 | || anArgCase.IsEqual ("-ANGLE")) | |
4fe9ad57 | 11228 | { |
992ed6b3 | 11229 | if (++anArgIt >= theArgsNb |
11230 | || aLightCurr.IsNull() | |
11231 | || aLightCurr->Type() != Graphic3d_TOLS_SPOT) | |
4fe9ad57 | 11232 | { |
23fe70ec | 11233 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
4fe9ad57 | 11234 | return 1; |
11235 | } | |
11236 | ||
992ed6b3 | 11237 | Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]); |
11238 | aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI)); | |
4fe9ad57 | 11239 | } |
12381341 | 11240 | else if (anArgCase.IsEqual ("CONSTATTEN") |
992ed6b3 | 11241 | || anArgCase.IsEqual ("CONSTATTENUATION") |
11242 | || anArgCase.IsEqual ("-CONSTATTEN") | |
11243 | || anArgCase.IsEqual ("-CONSTATTENUATION")) | |
12381341 | 11244 | { |
992ed6b3 | 11245 | if (++anArgIt >= theArgsNb |
11246 | || aLightCurr.IsNull() | |
11247 | || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL | |
11248 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 11249 | { |
23fe70ec | 11250 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11251 | return 1; |
11252 | } | |
11253 | ||
992ed6b3 | 11254 | aLightCurr->Attenuation (anAtten[0], anAtten[1]); |
11255 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
11256 | aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]); | |
12381341 | 11257 | } |
11258 | else if (anArgCase.IsEqual ("LINATTEN") | |
11259 | || anArgCase.IsEqual ("LINEARATTEN") | |
992ed6b3 | 11260 | || anArgCase.IsEqual ("LINEARATTENUATION") |
11261 | || anArgCase.IsEqual ("-LINATTEN") | |
11262 | || anArgCase.IsEqual ("-LINEARATTEN") | |
11263 | || anArgCase.IsEqual ("-LINEARATTENUATION")) | |
12381341 | 11264 | { |
992ed6b3 | 11265 | if (++anArgIt >= theArgsNb |
11266 | || aLightCurr.IsNull() | |
11267 | || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL | |
11268 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 11269 | { |
23fe70ec | 11270 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11271 | return 1; |
11272 | } | |
11273 | ||
992ed6b3 | 11274 | aLightCurr->Attenuation (anAtten[0], anAtten[1]); |
11275 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
11276 | aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]); | |
12381341 | 11277 | } |
11278 | else if (anArgCase.IsEqual ("EXP") | |
11279 | || anArgCase.IsEqual ("EXPONENT") | |
11280 | || anArgCase.IsEqual ("SPOTEXP") | |
992ed6b3 | 11281 | || anArgCase.IsEqual ("SPOTEXPONENT") |
11282 | || anArgCase.IsEqual ("-EXP") | |
11283 | || anArgCase.IsEqual ("-EXPONENT") | |
11284 | || anArgCase.IsEqual ("-SPOTEXP") | |
11285 | || anArgCase.IsEqual ("-SPOTEXPONENT")) | |
12381341 | 11286 | { |
992ed6b3 | 11287 | if (++anArgIt >= theArgsNb |
11288 | || aLightCurr.IsNull() | |
11289 | || aLightCurr->Type() != Graphic3d_TOLS_SPOT) | |
12381341 | 11290 | { |
23fe70ec | 11291 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11292 | return 1; |
11293 | } | |
11294 | ||
992ed6b3 | 11295 | aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt])); |
12381341 | 11296 | } |
88b312d3 | 11297 | else if (anArgCase.IsEqual("RANGE") |
11298 | || anArgCase.IsEqual("-RANGE")) | |
11299 | { | |
11300 | if (++anArgIt >= theArgsNb | |
11301 | || aLightCurr.IsNull() | |
11302 | || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT | |
11303 | || aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL) | |
11304 | { | |
23fe70ec | 11305 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
88b312d3 | 11306 | return 1; |
11307 | } | |
11308 | ||
11309 | aLightCurr->SetRange ((Standard_ShortReal)Atof (theArgVec[anArgIt])); | |
11310 | } | |
12381341 | 11311 | else if (anArgCase.IsEqual ("HEAD") |
992ed6b3 | 11312 | || anArgCase.IsEqual ("HEADLIGHT") |
11313 | || anArgCase.IsEqual ("-HEAD") | |
11314 | || anArgCase.IsEqual ("-HEADLIGHT")) | |
12381341 | 11315 | { |
992ed6b3 | 11316 | if (aLightCurr.IsNull() |
11317 | || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT) | |
12381341 | 11318 | { |
23fe70ec | 11319 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
12381341 | 11320 | return 1; |
11321 | } | |
11322 | ||
992ed6b3 | 11323 | Standard_Boolean isHeadLight = Standard_True; |
11324 | if (anArgIt + 1 < theArgsNb | |
11325 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight)) | |
12381341 | 11326 | { |
992ed6b3 | 11327 | ++anArgIt; |
12381341 | 11328 | } |
992ed6b3 | 11329 | aLightCurr->SetHeadlight (isHeadLight); |
12381341 | 11330 | } |
11331 | else | |
11332 | { | |
23fe70ec | 11333 | Message::SendFail() << "Warning: unknown argument '" << anArg << "'"; |
12381341 | 11334 | } |
11335 | } | |
11336 | ||
992ed6b3 | 11337 | addLight (aLightNew, aLayer, isGlobal); |
12381341 | 11338 | return 0; |
11339 | } | |
11340 | ||
67312b79 | 11341 | //=============================================================================================== |
11342 | //function : VPBREnvironment | |
11343 | //purpose : | |
11344 | //=============================================================================================== | |
11345 | static int VPBREnvironment (Draw_Interpretor&, | |
11346 | Standard_Integer theArgsNb, | |
11347 | const char** theArgVec) | |
11348 | { | |
11349 | if (theArgsNb > 2) | |
11350 | { | |
23fe70ec | 11351 | Message::SendFail ("Syntax error: 'vpbrenv' command has only one argument"); |
67312b79 | 11352 | return 1; |
11353 | } | |
11354 | ||
11355 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
11356 | if (aView.IsNull()) | |
11357 | { | |
23fe70ec | 11358 | Message::SendFail ("Error: no active viewer"); |
67312b79 | 11359 | return 1; |
11360 | } | |
11361 | ||
11362 | TCollection_AsciiString anArg = TCollection_AsciiString (theArgVec[1]); | |
11363 | anArg.LowerCase(); | |
11364 | ||
11365 | if (anArg == "-generate" | |
11366 | || anArg == "-gen") | |
11367 | { | |
11368 | aView->GeneratePBREnvironment (Standard_True); | |
11369 | } | |
11370 | else if (anArg == "-clear") | |
11371 | { | |
11372 | aView->ClearPBREnvironment (Standard_True); | |
11373 | } | |
11374 | else | |
11375 | { | |
23fe70ec | 11376 | Message::SendFail() << "Syntax error: unknown argument [" << theArgVec[1] << "] for 'vpbrenv' command"; |
67312b79 | 11377 | return 1; |
11378 | } | |
11379 | ||
11380 | return 0; | |
11381 | } | |
11382 | ||
15669413 | 11383 | //! Read Graphic3d_RenderingParams::PerfCounters flag. |
11384 | static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue, | |
11385 | Standard_Boolean& theToReset, | |
11386 | Graphic3d_RenderingParams::PerfCounters& theFlagsRem, | |
11387 | Graphic3d_RenderingParams::PerfCounters& theFlagsAdd) | |
11388 | { | |
11389 | Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE; | |
11390 | TCollection_AsciiString aVal = theValue; | |
11391 | Standard_Boolean toReverse = Standard_False; | |
11392 | if (aVal == "none") | |
11393 | { | |
11394 | theToReset = Standard_True; | |
11395 | return Standard_True; | |
11396 | } | |
11397 | else if (aVal.StartsWith ("-")) | |
11398 | { | |
11399 | toReverse = Standard_True; | |
11400 | aVal = aVal.SubString (2, aVal.Length()); | |
11401 | } | |
11402 | else if (aVal.StartsWith ("no")) | |
11403 | { | |
11404 | toReverse = Standard_True; | |
11405 | aVal = aVal.SubString (3, aVal.Length()); | |
11406 | } | |
11407 | else if (aVal.StartsWith ("+")) | |
11408 | { | |
11409 | aVal = aVal.SubString (2, aVal.Length()); | |
11410 | } | |
11411 | else | |
11412 | { | |
11413 | theToReset = Standard_True; | |
11414 | } | |
11415 | ||
11416 | if ( aVal == "fps" | |
11417 | || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate; | |
11418 | else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU; | |
11419 | else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers; | |
11420 | else if (aVal == "structs" | |
11421 | || aVal == "structures" | |
11422 | || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures; | |
11423 | else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups; | |
11424 | else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays; | |
11425 | else if (aVal == "tris" | |
11426 | || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles; | |
11427 | else if (aVal == "pnts" | |
11428 | || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points; | |
b9f43ad1 | 11429 | else if (aVal == "lines") aFlag = Graphic3d_RenderingParams::PerfCounters_Lines; |
15669413 | 11430 | else if (aVal == "mem" |
11431 | || aVal == "gpumem" | |
11432 | || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem; | |
5e30547b | 11433 | else if (aVal == "skipimmediate" |
11434 | || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate; | |
11435 | else if (aVal == "frametime" | |
11436 | || aVal == "frametimers" | |
11437 | || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime; | |
15669413 | 11438 | else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic; |
11439 | else if (aVal == "extended" | |
11440 | || aVal == "verbose" | |
11441 | || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended; | |
5e30547b | 11442 | else if (aVal == "full" |
11443 | || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All; | |
15669413 | 11444 | else |
11445 | { | |
11446 | return Standard_False; | |
11447 | } | |
11448 | ||
11449 | if (toReverse) | |
11450 | { | |
11451 | theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag); | |
11452 | } | |
11453 | else | |
11454 | { | |
11455 | theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag); | |
11456 | } | |
11457 | return Standard_True; | |
11458 | } | |
11459 | ||
11460 | //! Read Graphic3d_RenderingParams::PerfCounters flags. | |
11461 | static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue, | |
11462 | Graphic3d_RenderingParams::PerfCounters& theFlags) | |
11463 | { | |
11464 | TCollection_AsciiString aValue = theValue; | |
11465 | Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE; | |
11466 | Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE; | |
11467 | Standard_Boolean toReset = Standard_False; | |
11468 | for (;;) | |
11469 | { | |
11470 | Standard_Integer aSplitPos = aValue.Search ("|"); | |
11471 | if (aSplitPos <= 0) | |
11472 | { | |
11473 | if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd)) | |
11474 | { | |
11475 | return Standard_False; | |
11476 | } | |
11477 | if (toReset) | |
11478 | { | |
11479 | theFlags = Graphic3d_RenderingParams::PerfCounters_NONE; | |
11480 | } | |
11481 | theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd); | |
11482 | theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem); | |
11483 | return Standard_True; | |
11484 | } | |
11485 | ||
11486 | if (aSplitPos > 1) | |
11487 | { | |
11488 | TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1); | |
11489 | if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd)) | |
11490 | { | |
11491 | return Standard_False; | |
11492 | } | |
11493 | } | |
11494 | aValue = aValue.SubString (aSplitPos + 1, aValue.Length()); | |
11495 | } | |
11496 | } | |
11497 | ||
e276548b | 11498 | //======================================================================= |
bc8c79bb | 11499 | //function : VRenderParams |
11500 | //purpose : Enables/disables rendering features | |
e276548b | 11501 | //======================================================================= |
11502 | ||
bc8c79bb | 11503 | static Standard_Integer VRenderParams (Draw_Interpretor& theDI, |
11504 | Standard_Integer theArgNb, | |
11505 | const char** theArgVec) | |
e276548b | 11506 | { |
7ae4a307 | 11507 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
11508 | if (aView.IsNull()) | |
e276548b | 11509 | { |
23fe70ec | 11510 | Message::SendFail ("Error: no active viewer"); |
e276548b | 11511 | return 1; |
11512 | } | |
bc8c79bb | 11513 | |
11514 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); | |
6b62b2da | 11515 | TCollection_AsciiString aCmdName (theArgVec[0]); |
11516 | aCmdName.LowerCase(); | |
11517 | if (aCmdName == "vraytrace") | |
11518 | { | |
11519 | if (theArgNb == 1) | |
11520 | { | |
11521 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " "; | |
11522 | return 0; | |
11523 | } | |
11524 | else if (theArgNb == 2) | |
11525 | { | |
11526 | TCollection_AsciiString aValue (theArgVec[1]); | |
11527 | aValue.LowerCase(); | |
11528 | if (aValue == "on" | |
11529 | || aValue == "1") | |
11530 | { | |
11531 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
11532 | aView->Redraw(); | |
11533 | return 0; | |
11534 | } | |
11535 | else if (aValue == "off" | |
11536 | || aValue == "0") | |
11537 | { | |
11538 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
11539 | aView->Redraw(); | |
11540 | return 0; | |
11541 | } | |
11542 | else | |
11543 | { | |
23fe70ec | 11544 | Message::SendFail() << "Syntax error: unknown argument '" << theArgVec[1] << "'"; |
6b62b2da | 11545 | return 1; |
11546 | } | |
11547 | } | |
11548 | else | |
11549 | { | |
23fe70ec | 11550 | Message::SendFail ("Syntax error: wrong number of arguments"); |
6b62b2da | 11551 | return 1; |
11552 | } | |
11553 | } | |
bc8c79bb | 11554 | |
11555 | if (theArgNb < 2) | |
e276548b | 11556 | { |
bc8c79bb | 11557 | theDI << "renderMode: "; |
11558 | switch (aParams.Method) | |
11559 | { | |
11560 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
11561 | case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break; | |
11562 | } | |
11563 | theDI << "\n"; | |
a1073ae2 | 11564 | theDI << "transparency: "; |
11565 | switch (aParams.TransparencyMethod) | |
11566 | { | |
11567 | case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break; | |
11568 | case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: " | |
11569 | << TCollection_AsciiString (aParams.OitDepthFactor); break; | |
11570 | } | |
11571 | theDI << "\n"; | |
b4327ba8 | 11572 | theDI << "msaa: " << aParams.NbMsaaSamples << "\n"; |
56689b27 | 11573 | theDI << "rendScale: " << aParams.RenderResolutionScale << "\n"; |
b4327ba8 | 11574 | theDI << "rayDepth: " << aParams.RaytracingDepth << "\n"; |
11575 | theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n"; | |
11576 | theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n"; | |
11577 | theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n"; | |
11578 | theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n"; | |
11579 | theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n"; | |
11580 | theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n"; | |
11581 | theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n"; | |
11582 | theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n"; | |
11583 | theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n"; | |
b09447ed | 11584 | theDI << "max radiance: " << aParams.RadianceClampingValue << "\n"; |
4eaaf9d8 | 11585 | theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n"; |
66d1cdc6 | 11586 | theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n"; |
8625ef7e | 11587 | theDI << "shadingModel: "; |
11588 | switch (aView->ShadingModel()) | |
11589 | { | |
67312b79 | 11590 | case Graphic3d_TOSM_DEFAULT: theDI << "default"; break; |
11591 | case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break; | |
11592 | case Graphic3d_TOSM_FACET: theDI << "flat"; break; | |
11593 | case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break; | |
11594 | case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break; | |
11595 | case Graphic3d_TOSM_PBR: theDI << "pbr"; break; | |
11596 | case Graphic3d_TOSM_PBR_FACET: theDI << "pbr_facet"; break; | |
8625ef7e | 11597 | } |
15669413 | 11598 | { |
11599 | theDI << "perfCounters:"; | |
11600 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0) | |
11601 | { | |
11602 | theDI << " fps"; | |
11603 | } | |
11604 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0) | |
11605 | { | |
11606 | theDI << " cpu"; | |
11607 | } | |
11608 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0) | |
11609 | { | |
11610 | theDI << " structs"; | |
11611 | } | |
11612 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0) | |
11613 | { | |
11614 | theDI << " groups"; | |
11615 | } | |
11616 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0) | |
11617 | { | |
11618 | theDI << " arrays"; | |
11619 | } | |
11620 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0) | |
11621 | { | |
11622 | theDI << " tris"; | |
11623 | } | |
b9f43ad1 | 11624 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Lines) != 0) |
11625 | { | |
11626 | theDI << " lines"; | |
11627 | } | |
15669413 | 11628 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0) |
11629 | { | |
11630 | theDI << " pnts"; | |
11631 | } | |
11632 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0) | |
11633 | { | |
11634 | theDI << " gpumem"; | |
11635 | } | |
5e30547b | 11636 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0) |
11637 | { | |
11638 | theDI << " frameTime"; | |
11639 | } | |
11640 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0) | |
11641 | { | |
11642 | theDI << " skipimmediate"; | |
11643 | } | |
15669413 | 11644 | if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE) |
11645 | { | |
11646 | theDI << " none"; | |
11647 | } | |
11648 | theDI << "\n"; | |
11649 | } | |
f88457e6 | 11650 | theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n"; |
c40eb6b9 | 11651 | theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n"; |
0e3025bc | 11652 | theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" : |
11653 | aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" : | |
11654 | "noUpdate") << "\n"; | |
8625ef7e | 11655 | theDI << "\n"; |
bc8c79bb | 11656 | return 0; |
e276548b | 11657 | } |
11658 | ||
bc8c79bb | 11659 | Standard_Boolean toPrint = Standard_False; |
8625ef7e | 11660 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
e276548b | 11661 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
11662 | { | |
bc8c79bb | 11663 | Standard_CString anArg (theArgVec[anArgIter]); |
11664 | TCollection_AsciiString aFlag (anArg); | |
11665 | aFlag.LowerCase(); | |
8625ef7e | 11666 | if (anUpdateTool.parseRedrawMode (aFlag)) |
11667 | { | |
11668 | continue; | |
11669 | } | |
11670 | else if (aFlag == "-echo" | |
11671 | || aFlag == "-print") | |
e276548b | 11672 | { |
bc8c79bb | 11673 | toPrint = Standard_True; |
8625ef7e | 11674 | anUpdateTool.Invalidate(); |
e276548b | 11675 | } |
bc8c79bb | 11676 | else if (aFlag == "-mode" |
11677 | || aFlag == "-rendermode" | |
11678 | || aFlag == "-render_mode") | |
e276548b | 11679 | { |
bc8c79bb | 11680 | if (toPrint) |
11681 | { | |
11682 | switch (aParams.Method) | |
11683 | { | |
11684 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
11685 | case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break; | |
11686 | } | |
11687 | continue; | |
11688 | } | |
e276548b | 11689 | else |
bc8c79bb | 11690 | { |
23fe70ec | 11691 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
bc8c79bb | 11692 | return 1; |
11693 | } | |
11694 | } | |
11695 | else if (aFlag == "-ray" | |
11696 | || aFlag == "-raytrace") | |
11697 | { | |
11698 | if (toPrint) | |
11699 | { | |
11700 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " "; | |
11701 | continue; | |
11702 | } | |
11703 | ||
11704 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
e276548b | 11705 | } |
bc8c79bb | 11706 | else if (aFlag == "-rast" |
11707 | || aFlag == "-raster" | |
11708 | || aFlag == "-rasterization") | |
e276548b | 11709 | { |
bc8c79bb | 11710 | if (toPrint) |
11711 | { | |
11712 | theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " "; | |
11713 | continue; | |
11714 | } | |
11715 | ||
11716 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
11717 | } | |
3c4b62a4 | 11718 | else if (aFlag == "-msaa") |
11719 | { | |
11720 | if (toPrint) | |
11721 | { | |
11722 | theDI << aParams.NbMsaaSamples << " "; | |
11723 | continue; | |
11724 | } | |
11725 | else if (++anArgIter >= theArgNb) | |
11726 | { | |
23fe70ec | 11727 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
3c4b62a4 | 11728 | return 1; |
11729 | } | |
11730 | ||
11731 | const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]); | |
11732 | if (aNbSamples < 0) | |
11733 | { | |
23fe70ec | 11734 | Message::SendFail() << "Syntax error: invalid number of MSAA samples " << aNbSamples << ""; |
3c4b62a4 | 11735 | return 1; |
11736 | } | |
11737 | else | |
11738 | { | |
11739 | aParams.NbMsaaSamples = aNbSamples; | |
11740 | } | |
11741 | } | |
2a332745 | 11742 | else if (aFlag == "-linefeather" |
11743 | || aFlag == "-edgefeather" | |
11744 | || aFlag == "-feather") | |
11745 | { | |
11746 | if (toPrint) | |
11747 | { | |
11748 | theDI << " " << aParams.LineFeather << " "; | |
11749 | continue; | |
11750 | } | |
11751 | else if (++anArgIter >= theArgNb) | |
11752 | { | |
23fe70ec | 11753 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
2a332745 | 11754 | return 1; |
11755 | } | |
11756 | ||
11757 | TCollection_AsciiString aParam = theArgVec[anArgIter]; | |
11758 | const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]); | |
11759 | if (aFeather <= 0.0f) | |
11760 | { | |
23fe70ec | 11761 | Message::SendFail() << "Syntax error: invalid value of line width feather " << aFeather << ". Should be > 0"; |
2a332745 | 11762 | return 1; |
11763 | } | |
11764 | aParams.LineFeather = aFeather; | |
11765 | } | |
a1073ae2 | 11766 | else if (aFlag == "-oit") |
11767 | { | |
11768 | if (toPrint) | |
11769 | { | |
11770 | if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT) | |
11771 | { | |
11772 | theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " "; | |
11773 | } | |
11774 | else | |
11775 | { | |
11776 | theDI << "off" << " "; | |
11777 | } | |
11778 | continue; | |
11779 | } | |
11780 | else if (++anArgIter >= theArgNb) | |
11781 | { | |
23fe70ec | 11782 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
a1073ae2 | 11783 | return 1; |
11784 | } | |
11785 | ||
11786 | TCollection_AsciiString aParam = theArgVec[anArgIter]; | |
11787 | aParam.LowerCase(); | |
11788 | if (aParam.IsRealValue()) | |
11789 | { | |
11790 | const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]); | |
11791 | if (aWeight < 0.f || aWeight > 1.f) | |
11792 | { | |
23fe70ec | 11793 | Message::SendFail() << "Syntax error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]"; |
a1073ae2 | 11794 | return 1; |
11795 | } | |
11796 | ||
11797 | aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT; | |
11798 | aParams.OitDepthFactor = aWeight; | |
11799 | } | |
11800 | else if (aParam == "off") | |
11801 | { | |
11802 | aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED; | |
11803 | } | |
11804 | else | |
11805 | { | |
23fe70ec | 11806 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
a1073ae2 | 11807 | return 1; |
11808 | } | |
11809 | } | |
f88457e6 | 11810 | else if (aFlag == "-depthprepass") |
11811 | { | |
11812 | if (toPrint) | |
11813 | { | |
11814 | theDI << (aParams.ToEnableDepthPrepass ? "on " : "off "); | |
11815 | continue; | |
11816 | } | |
11817 | aParams.ToEnableDepthPrepass = Standard_True; | |
11818 | if (anArgIter + 1 < theArgNb | |
11819 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass)) | |
11820 | { | |
11821 | ++anArgIter; | |
11822 | } | |
11823 | } | |
c40eb6b9 | 11824 | else if (aFlag == "-samplealphatocoverage" |
11825 | || aFlag == "-alphatocoverage") | |
11826 | { | |
11827 | if (toPrint) | |
11828 | { | |
11829 | theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off "); | |
11830 | continue; | |
11831 | } | |
11832 | aParams.ToEnableAlphaToCoverage = Standard_True; | |
11833 | if (anArgIter + 1 < theArgNb | |
11834 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage)) | |
11835 | { | |
11836 | ++anArgIter; | |
11837 | } | |
11838 | } | |
56689b27 | 11839 | else if (aFlag == "-rendscale" |
11840 | || aFlag == "-renderscale" | |
11841 | || aFlag == "-renderresolutionscale") | |
11842 | { | |
11843 | if (toPrint) | |
11844 | { | |
11845 | theDI << aParams.RenderResolutionScale << " "; | |
11846 | continue; | |
11847 | } | |
11848 | else if (++anArgIter >= theArgNb) | |
11849 | { | |
23fe70ec | 11850 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
56689b27 | 11851 | return 1; |
11852 | } | |
11853 | ||
11854 | const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]); | |
11855 | if (aScale < 0.01) | |
11856 | { | |
23fe70ec | 11857 | Message::SendFail() << "Syntax error: invalid rendering resolution scale " << aScale << ""; |
56689b27 | 11858 | return 1; |
11859 | } | |
11860 | else | |
11861 | { | |
11862 | aParams.RenderResolutionScale = Standard_ShortReal(aScale); | |
11863 | } | |
11864 | } | |
bc8c79bb | 11865 | else if (aFlag == "-raydepth" |
11866 | || aFlag == "-ray_depth") | |
11867 | { | |
11868 | if (toPrint) | |
11869 | { | |
11870 | theDI << aParams.RaytracingDepth << " "; | |
11871 | continue; | |
11872 | } | |
11873 | else if (++anArgIter >= theArgNb) | |
11874 | { | |
23fe70ec | 11875 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
bc8c79bb | 11876 | return 1; |
11877 | } | |
11878 | ||
11879 | const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]); | |
189f85a3 | 11880 | |
11881 | // We allow RaytracingDepth be more than 10 in case of GI enabled | |
11882 | if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled)) | |
bc8c79bb | 11883 | { |
23fe70ec | 11884 | Message::SendFail() << "Syntax error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]"; |
bc8c79bb | 11885 | return 1; |
11886 | } | |
e276548b | 11887 | else |
bc8c79bb | 11888 | { |
11889 | aParams.RaytracingDepth = aDepth; | |
11890 | } | |
11891 | } | |
11892 | else if (aFlag == "-shad" | |
11893 | || aFlag == "-shadows") | |
11894 | { | |
11895 | if (toPrint) | |
11896 | { | |
11897 | theDI << (aParams.IsShadowEnabled ? "on" : "off") << " "; | |
11898 | continue; | |
11899 | } | |
11900 | ||
11901 | Standard_Boolean toEnable = Standard_True; | |
11902 | if (++anArgIter < theArgNb | |
a5565a3c | 11903 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 11904 | { |
11905 | --anArgIter; | |
11906 | } | |
11907 | aParams.IsShadowEnabled = toEnable; | |
11908 | } | |
11909 | else if (aFlag == "-refl" | |
11910 | || aFlag == "-reflections") | |
11911 | { | |
11912 | if (toPrint) | |
11913 | { | |
11914 | theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " "; | |
11915 | continue; | |
11916 | } | |
11917 | ||
11918 | Standard_Boolean toEnable = Standard_True; | |
11919 | if (++anArgIter < theArgNb | |
a5565a3c | 11920 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 11921 | { |
11922 | --anArgIter; | |
11923 | } | |
11924 | aParams.IsReflectionEnabled = toEnable; | |
11925 | } | |
11926 | else if (aFlag == "-fsaa") | |
11927 | { | |
11928 | if (toPrint) | |
11929 | { | |
11930 | theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " "; | |
11931 | continue; | |
11932 | } | |
11933 | ||
11934 | Standard_Boolean toEnable = Standard_True; | |
11935 | if (++anArgIter < theArgNb | |
a5565a3c | 11936 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 11937 | { |
11938 | --anArgIter; | |
11939 | } | |
11940 | aParams.IsAntialiasingEnabled = toEnable; | |
11941 | } | |
11942 | else if (aFlag == "-gleam") | |
11943 | { | |
11944 | if (toPrint) | |
11945 | { | |
11946 | theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " "; | |
11947 | continue; | |
11948 | } | |
11949 | ||
11950 | Standard_Boolean toEnable = Standard_True; | |
11951 | if (++anArgIter < theArgNb | |
a5565a3c | 11952 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 11953 | { |
11954 | --anArgIter; | |
11955 | } | |
11956 | aParams.IsTransparentShadowEnabled = toEnable; | |
e276548b | 11957 | } |
189f85a3 | 11958 | else if (aFlag == "-gi") |
11959 | { | |
11960 | if (toPrint) | |
11961 | { | |
11962 | theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " "; | |
11963 | continue; | |
11964 | } | |
11965 | ||
11966 | Standard_Boolean toEnable = Standard_True; | |
11967 | if (++anArgIter < theArgNb | |
a5565a3c | 11968 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
189f85a3 | 11969 | { |
11970 | --anArgIter; | |
11971 | } | |
11972 | aParams.IsGlobalIlluminationEnabled = toEnable; | |
11973 | if (!toEnable) | |
11974 | { | |
11975 | aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10); | |
11976 | } | |
11977 | } | |
8c820969 | 11978 | else if (aFlag == "-blockedrng" |
11979 | || aFlag == "-brng") | |
11980 | { | |
11981 | if (toPrint) | |
11982 | { | |
11983 | theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " "; | |
11984 | continue; | |
11985 | } | |
11986 | ||
11987 | Standard_Boolean toEnable = Standard_True; | |
11988 | if (++anArgIter < theArgNb | |
a5565a3c | 11989 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8c820969 | 11990 | { |
11991 | --anArgIter; | |
11992 | } | |
11993 | aParams.CoherentPathTracingMode = toEnable; | |
11994 | } | |
b09447ed | 11995 | else if (aFlag == "-maxrad") |
11996 | { | |
11997 | if (toPrint) | |
11998 | { | |
11999 | theDI << aParams.RadianceClampingValue << " "; | |
12000 | continue; | |
12001 | } | |
12002 | else if (++anArgIter >= theArgNb) | |
12003 | { | |
23fe70ec | 12004 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
b09447ed | 12005 | return 1; |
12006 | } | |
12007 | ||
12008 | const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter]; | |
12009 | if (!aMaxRadStr.IsRealValue()) | |
12010 | { | |
23fe70ec | 12011 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
b09447ed | 12012 | return 1; |
12013 | } | |
12014 | ||
12015 | const Standard_Real aMaxRadiance = aMaxRadStr.RealValue(); | |
12016 | if (aMaxRadiance <= 0.0) | |
12017 | { | |
23fe70ec | 12018 | Message::SendFail() << "Syntax error: invalid radiance clamping value " << aMaxRadiance; |
b09447ed | 12019 | return 1; |
12020 | } | |
12021 | else | |
12022 | { | |
12023 | aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance); | |
12024 | } | |
12025 | } | |
3a9b5dc8 | 12026 | else if (aFlag == "-iss") |
12027 | { | |
12028 | if (toPrint) | |
12029 | { | |
12030 | theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " "; | |
12031 | continue; | |
12032 | } | |
12033 | ||
12034 | Standard_Boolean toEnable = Standard_True; | |
12035 | if (++anArgIter < theArgNb | |
12036 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
12037 | { | |
12038 | --anArgIter; | |
12039 | } | |
12040 | aParams.AdaptiveScreenSampling = toEnable; | |
12041 | } | |
e084dbbc | 12042 | else if (aFlag == "-issatomic") |
12043 | { | |
12044 | if (toPrint) | |
12045 | { | |
12046 | theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " "; | |
12047 | continue; | |
12048 | } | |
12049 | ||
12050 | Standard_Boolean toEnable = Standard_True; | |
12051 | if (++anArgIter < theArgNb | |
12052 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
12053 | { | |
12054 | --anArgIter; | |
12055 | } | |
12056 | aParams.AdaptiveScreenSamplingAtomic = toEnable; | |
12057 | } | |
3a9b5dc8 | 12058 | else if (aFlag == "-issd") |
12059 | { | |
12060 | if (toPrint) | |
12061 | { | |
12062 | theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " "; | |
12063 | continue; | |
12064 | } | |
12065 | ||
12066 | Standard_Boolean toEnable = Standard_True; | |
12067 | if (++anArgIter < theArgNb | |
12068 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
12069 | { | |
12070 | --anArgIter; | |
12071 | } | |
12072 | aParams.ShowSamplingTiles = toEnable; | |
12073 | } | |
66d1cdc6 | 12074 | else if (aFlag == "-tilesize") |
12075 | { | |
12076 | if (toPrint) | |
12077 | { | |
12078 | theDI << aParams.RayTracingTileSize << " "; | |
12079 | continue; | |
12080 | } | |
12081 | else if (++anArgIter >= theArgNb) | |
12082 | { | |
23fe70ec | 12083 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
66d1cdc6 | 12084 | return 1; |
12085 | } | |
12086 | ||
12087 | const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]); | |
12088 | if (aTileSize < 1) | |
12089 | { | |
23fe70ec | 12090 | Message::SendFail() << "Syntax error: invalid size of ISS tile " << aTileSize; |
66d1cdc6 | 12091 | return 1; |
12092 | } | |
12093 | aParams.RayTracingTileSize = aTileSize; | |
12094 | } | |
4eaaf9d8 | 12095 | else if (aFlag == "-nbtiles") |
12096 | { | |
12097 | if (toPrint) | |
12098 | { | |
12099 | theDI << aParams.NbRayTracingTiles << " "; | |
12100 | continue; | |
12101 | } | |
12102 | else if (++anArgIter >= theArgNb) | |
12103 | { | |
23fe70ec | 12104 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
4eaaf9d8 | 12105 | return 1; |
12106 | } | |
12107 | ||
12108 | const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]); | |
66d1cdc6 | 12109 | if (aNbTiles < -1) |
4eaaf9d8 | 12110 | { |
23fe70ec | 12111 | Message::SendFail() << "Syntax error: invalid number of ISS tiles " << aNbTiles; |
4eaaf9d8 | 12112 | return 1; |
12113 | } | |
66d1cdc6 | 12114 | else if (aNbTiles > 0 |
12115 | && (aNbTiles < 64 | |
12116 | || aNbTiles > 1024)) | |
4eaaf9d8 | 12117 | { |
23fe70ec | 12118 | Message::SendWarning() << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024]."; |
4eaaf9d8 | 12119 | } |
66d1cdc6 | 12120 | aParams.NbRayTracingTiles = aNbTiles; |
4eaaf9d8 | 12121 | } |
189f85a3 | 12122 | else if (aFlag == "-env") |
12123 | { | |
12124 | if (toPrint) | |
12125 | { | |
12126 | theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " "; | |
12127 | continue; | |
12128 | } | |
12129 | ||
12130 | Standard_Boolean toEnable = Standard_True; | |
12131 | if (++anArgIter < theArgNb | |
a5565a3c | 12132 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
189f85a3 | 12133 | { |
12134 | --anArgIter; | |
12135 | } | |
12136 | aParams.UseEnvironmentMapBackground = toEnable; | |
12137 | } | |
78607702 | 12138 | else if (aFlag == "-ignorenormalmap") |
12139 | { | |
12140 | if (toPrint) | |
12141 | { | |
12142 | theDI << (aParams.ToIgnoreNormalMapInRayTracing ? "on" : "off") << " "; | |
12143 | continue; | |
12144 | } | |
12145 | ||
12146 | Standard_Boolean toEnable = Standard_True; | |
12147 | if (++anArgIter < theArgNb | |
12148 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
12149 | { | |
12150 | --anArgIter; | |
12151 | } | |
12152 | aParams.ToIgnoreNormalMapInRayTracing = toEnable; | |
12153 | } | |
b4327ba8 | 12154 | else if (aFlag == "-twoside") |
12155 | { | |
12156 | if (toPrint) | |
12157 | { | |
12158 | theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " "; | |
12159 | continue; | |
12160 | } | |
12161 | ||
12162 | Standard_Boolean toEnable = Standard_True; | |
12163 | if (++anArgIter < theArgNb | |
12164 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
12165 | { | |
12166 | --anArgIter; | |
12167 | } | |
12168 | aParams.TwoSidedBsdfModels = toEnable; | |
12169 | } | |
8625ef7e | 12170 | else if (aFlag == "-shademodel" |
12171 | || aFlag == "-shadingmodel" | |
12172 | || aFlag == "-shading") | |
12173 | { | |
12174 | if (toPrint) | |
12175 | { | |
12176 | switch (aView->ShadingModel()) | |
12177 | { | |
67312b79 | 12178 | case Graphic3d_TOSM_DEFAULT: theDI << "default"; break; |
12179 | case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break; | |
12180 | case Graphic3d_TOSM_FACET: theDI << "flat "; break; | |
12181 | case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break; | |
12182 | case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break; | |
12183 | case Graphic3d_TOSM_PBR: theDI << "pbr"; break; | |
12184 | case Graphic3d_TOSM_PBR_FACET: theDI << "pbr_facet"; break; | |
8625ef7e | 12185 | } |
12186 | continue; | |
12187 | } | |
12188 | ||
12189 | if (++anArgIter >= theArgNb) | |
12190 | { | |
23fe70ec | 12191 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
8625ef7e | 12192 | } |
12193 | ||
dc89236f | 12194 | Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT; |
12195 | if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel) | |
12196 | && aModel != Graphic3d_TOSM_DEFAULT) | |
8625ef7e | 12197 | { |
dc89236f | 12198 | aView->SetShadingModel (aModel); |
8625ef7e | 12199 | } |
12200 | else | |
12201 | { | |
23fe70ec | 12202 | Message::SendFail() << "Syntax error: unknown shading model '" << theArgVec[anArgIter] << "'"; |
8625ef7e | 12203 | return 1; |
12204 | } | |
12205 | } | |
67312b79 | 12206 | else if (aFlag == "-pbrenvpow2size" |
12207 | || aFlag == "-pbrenvp2s" | |
12208 | || aFlag == "-pep2s") | |
12209 | { | |
12210 | if (++anArgIter >= theArgNb) | |
12211 | { | |
23fe70ec | 12212 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
67312b79 | 12213 | return 1; |
12214 | } | |
12215 | ||
12216 | const Standard_Integer aPbrEnvPow2Size = Draw::Atoi (theArgVec[anArgIter]); | |
12217 | if (aPbrEnvPow2Size < 1) | |
12218 | { | |
23fe70ec | 12219 | Message::SendFail ("Syntax error: 'Pow2Size' of PBR Environment has to be greater or equal 1"); |
67312b79 | 12220 | return 1; |
12221 | } | |
12222 | aParams.PbrEnvPow2Size = aPbrEnvPow2Size; | |
12223 | } | |
12224 | else if (aFlag == "-pbrenvspecmaplevelsnumber" | |
12225 | || aFlag == "-pbrenvspecmapnblevels" | |
12226 | || aFlag == "-pbrenvspecmaplevels" | |
12227 | || aFlag == "-pbrenvsmln" | |
12228 | || aFlag == "-pesmln") | |
12229 | { | |
12230 | if (++anArgIter >= theArgNb) | |
12231 | { | |
23fe70ec | 12232 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
67312b79 | 12233 | return 1; |
12234 | } | |
12235 | ||
12236 | const Standard_Integer aPbrEnvSpecMapNbLevels = Draw::Atoi (theArgVec[anArgIter]); | |
12237 | if (aPbrEnvSpecMapNbLevels < 2) | |
12238 | { | |
23fe70ec | 12239 | Message::SendFail ("Syntax error: 'SpecMapLevelsNumber' of PBR Environment has to be greater or equal 2"); |
67312b79 | 12240 | return 1; |
12241 | } | |
12242 | aParams.PbrEnvSpecMapNbLevels = aPbrEnvSpecMapNbLevels; | |
12243 | } | |
12244 | else if (aFlag == "-pbrenvbakngdiffsamplesnumber" | |
12245 | || aFlag == "-pbrenvbakingdiffsamples" | |
12246 | || aFlag == "-pbrenvbdsn") | |
12247 | { | |
12248 | if (++anArgIter >= theArgNb) | |
12249 | { | |
23fe70ec | 12250 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
67312b79 | 12251 | return 1; |
12252 | } | |
12253 | ||
12254 | const Standard_Integer aPbrEnvBakingDiffNbSamples = Draw::Atoi (theArgVec[anArgIter]); | |
12255 | if (aPbrEnvBakingDiffNbSamples < 1) | |
12256 | { | |
23fe70ec | 12257 | Message::SendFail ("Syntax error: 'BakingDiffSamplesNumber' of PBR Environtment has to be greater or equal 1"); |
67312b79 | 12258 | return 1; |
12259 | } | |
12260 | aParams.PbrEnvBakingDiffNbSamples = aPbrEnvBakingDiffNbSamples; | |
12261 | } | |
12262 | else if (aFlag == "-pbrenvbakngspecsamplesnumber" | |
12263 | || aFlag == "-pbrenvbakingspecsamples" | |
12264 | || aFlag == "-pbrenvbssn") | |
12265 | { | |
12266 | if (++anArgIter >= theArgNb) | |
12267 | { | |
23fe70ec | 12268 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
67312b79 | 12269 | return 1; |
12270 | } | |
12271 | ||
12272 | const Standard_Integer aPbrEnvBakingSpecNbSamples = Draw::Atoi(theArgVec[anArgIter]); | |
12273 | if (aPbrEnvBakingSpecNbSamples < 1) | |
12274 | { | |
23fe70ec | 12275 | Message::SendFail ("Syntax error: 'BakingSpecSamplesNumber' of PBR Environtment has to be greater or equal 1"); |
67312b79 | 12276 | return 1; |
12277 | } | |
12278 | aParams.PbrEnvBakingSpecNbSamples = aPbrEnvBakingSpecNbSamples; | |
12279 | } | |
12280 | else if (aFlag == "-pbrenvbakingprobability" | |
12281 | || aFlag == "-pbrenvbp") | |
12282 | { | |
12283 | if (++anArgIter >= theArgNb) | |
12284 | { | |
23fe70ec | 12285 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
67312b79 | 12286 | return 1; |
12287 | } | |
12288 | const Standard_ShortReal aPbrEnvBakingProbability = static_cast<Standard_ShortReal>(Draw::Atof (theArgVec[anArgIter])); | |
12289 | if (aPbrEnvBakingProbability < 0.f | |
12290 | || aPbrEnvBakingProbability > 1.f) | |
12291 | { | |
23fe70ec | 12292 | Message::SendFail ("Syntax error: 'BakingProbability' of PBR Environtment has to be in range of [0, 1]"); |
67312b79 | 12293 | return 1; |
12294 | } | |
12295 | aParams.PbrEnvBakingProbability = aPbrEnvBakingProbability; | |
12296 | } | |
4b1c8733 | 12297 | else if (aFlag == "-resolution") |
12298 | { | |
12299 | if (++anArgIter >= theArgNb) | |
12300 | { | |
23fe70ec | 12301 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
4b1c8733 | 12302 | return 1; |
12303 | } | |
12304 | ||
12305 | TCollection_AsciiString aResolution (theArgVec[anArgIter]); | |
12306 | if (aResolution.IsIntegerValue()) | |
12307 | { | |
12308 | aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString())); | |
12309 | } | |
12310 | else | |
12311 | { | |
23fe70ec | 12312 | Message::SendFail() << "Syntax error: wrong syntax at argument'" << anArg << "'"; |
4b1c8733 | 12313 | return 1; |
12314 | } | |
12315 | } | |
d877e610 | 12316 | else if (aFlag == "-rebuildglsl" |
12317 | || aFlag == "-rebuild") | |
12318 | { | |
12319 | if (toPrint) | |
12320 | { | |
12321 | theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " "; | |
12322 | continue; | |
12323 | } | |
12324 | ||
12325 | Standard_Boolean toEnable = Standard_True; | |
12326 | if (++anArgIter < theArgNb | |
12327 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
12328 | { | |
12329 | --anArgIter; | |
12330 | } | |
12331 | aParams.RebuildRayTracingShaders = toEnable; | |
12332 | } | |
b27ab03d | 12333 | else if (aFlag == "-focal") |
12334 | { | |
12335 | if (++anArgIter >= theArgNb) | |
12336 | { | |
23fe70ec | 12337 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
b27ab03d | 12338 | return 1; |
12339 | } | |
12340 | ||
12341 | TCollection_AsciiString aParam (theArgVec[anArgIter]); | |
12342 | if (aParam.IsRealValue()) | |
12343 | { | |
12344 | float aFocalDist = static_cast<float> (aParam.RealValue()); | |
12345 | if (aFocalDist < 0) | |
12346 | { | |
23fe70ec | 12347 | Message::SendFail() << "Error: parameter can't be negative at argument '" << anArg << "'"; |
b27ab03d | 12348 | return 1; |
12349 | } | |
12350 | aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist; | |
12351 | } | |
12352 | else | |
12353 | { | |
23fe70ec | 12354 | Message::SendFail() << "Syntax error at argument'" << anArg << "'"; |
b27ab03d | 12355 | return 1; |
12356 | } | |
12357 | } | |
12358 | else if (aFlag == "-aperture") | |
12359 | { | |
12360 | if (++anArgIter >= theArgNb) | |
12361 | { | |
23fe70ec | 12362 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
b27ab03d | 12363 | return 1; |
12364 | } | |
12365 | ||
12366 | TCollection_AsciiString aParam(theArgVec[anArgIter]); | |
12367 | if (aParam.IsRealValue()) | |
12368 | { | |
12369 | float aApertureSize = static_cast<float> (aParam.RealValue()); | |
12370 | if (aApertureSize < 0) | |
12371 | { | |
23fe70ec | 12372 | Message::SendFail() << "Error: parameter can't be negative at argument '" << anArg << "'"; |
b27ab03d | 12373 | return 1; |
12374 | } | |
12375 | aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize; | |
12376 | } | |
12377 | else | |
12378 | { | |
23fe70ec | 12379 | Message::SendFail() << "Syntax error at argument'" << anArg << "'"; |
b27ab03d | 12380 | return 1; |
12381 | } | |
12382 | } | |
eb85ed36 | 12383 | else if (aFlag == "-exposure") |
12384 | { | |
12385 | if (++anArgIter >= theArgNb) | |
12386 | { | |
23fe70ec | 12387 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
eb85ed36 | 12388 | return 1; |
12389 | } | |
12390 | ||
12391 | TCollection_AsciiString anExposure (theArgVec[anArgIter]); | |
12392 | if (anExposure.IsRealValue()) | |
12393 | { | |
12394 | aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue()); | |
12395 | } | |
12396 | else | |
12397 | { | |
23fe70ec | 12398 | Message::SendFail() << "Syntax error at argument'" << anArg << "'"; |
eb85ed36 | 12399 | return 1; |
12400 | } | |
12401 | } | |
12402 | else if (aFlag == "-whitepoint") | |
12403 | { | |
12404 | if (++anArgIter >= theArgNb) | |
12405 | { | |
23fe70ec | 12406 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
eb85ed36 | 12407 | return 1; |
12408 | } | |
12409 | ||
12410 | TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]); | |
12411 | if (aWhitePoint.IsRealValue()) | |
12412 | { | |
12413 | aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue()); | |
12414 | } | |
12415 | else | |
12416 | { | |
23fe70ec | 12417 | Message::SendFail() << "Syntax error at argument'" << anArg << "'"; |
eb85ed36 | 12418 | return 1; |
12419 | } | |
12420 | } | |
12421 | else if (aFlag == "-tonemapping") | |
12422 | { | |
12423 | if (++anArgIter >= theArgNb) | |
12424 | { | |
23fe70ec | 12425 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
eb85ed36 | 12426 | return 1; |
12427 | } | |
12428 | ||
12429 | TCollection_AsciiString aMode (theArgVec[anArgIter]); | |
12430 | aMode.LowerCase(); | |
12431 | ||
12432 | if (aMode == "disabled") | |
12433 | { | |
12434 | aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled; | |
12435 | } | |
12436 | else if (aMode == "filmic") | |
12437 | { | |
12438 | aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic; | |
12439 | } | |
12440 | else | |
12441 | { | |
23fe70ec | 12442 | Message::SendFail() << "Syntax error at argument'" << anArg << "'"; |
eb85ed36 | 12443 | return 1; |
12444 | } | |
12445 | } | |
15669413 | 12446 | else if (aFlag == "-performancestats" |
12447 | || aFlag == "-performancecounters" | |
12448 | || aFlag == "-perfstats" | |
12449 | || aFlag == "-perfcounters" | |
12450 | || aFlag == "-stats") | |
12451 | { | |
12452 | if (++anArgIter >= theArgNb) | |
12453 | { | |
23fe70ec | 12454 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
15669413 | 12455 | return 1; |
12456 | } | |
12457 | ||
12458 | TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]); | |
12459 | aFlagsStr.LowerCase(); | |
12460 | Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats; | |
12461 | if (!convertToPerfStatsFlags (aFlagsStr, aFlags)) | |
12462 | { | |
23fe70ec | 12463 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
15669413 | 12464 | return 1; |
12465 | } | |
12466 | aView->ChangeRenderingParams().CollectedStats = aFlags; | |
12467 | aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE; | |
12468 | } | |
12469 | else if (aFlag == "-perfupdateinterval" | |
12470 | || aFlag == "-statsupdateinterval") | |
12471 | { | |
12472 | if (++anArgIter >= theArgNb) | |
12473 | { | |
23fe70ec | 12474 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
15669413 | 12475 | return 1; |
12476 | } | |
12477 | aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]); | |
12478 | } | |
5e30547b | 12479 | else if (aFlag == "-perfchart" |
12480 | || aFlag == "-statschart") | |
12481 | { | |
12482 | if (++anArgIter >= theArgNb) | |
12483 | { | |
23fe70ec | 12484 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
5e30547b | 12485 | return 1; |
12486 | } | |
12487 | aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]); | |
12488 | } | |
12489 | else if (aFlag == "-perfchartmax" | |
12490 | || aFlag == "-statschartmax") | |
12491 | { | |
12492 | if (++anArgIter >= theArgNb) | |
12493 | { | |
23fe70ec | 12494 | Message::SendFail() << "Syntax error at argument '" << anArg << "'"; |
5e30547b | 12495 | return 1; |
12496 | } | |
12497 | aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]); | |
12498 | } | |
0e3025bc | 12499 | else if (aFlag == "-frustumculling" |
12500 | || aFlag == "-culling") | |
12501 | { | |
12502 | if (toPrint) | |
12503 | { | |
12504 | theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" : | |
12505 | (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" : | |
12506 | "noUpdate") << " "; | |
12507 | continue; | |
12508 | } | |
12509 | ||
12510 | Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On; | |
12511 | if (++anArgIter < theArgNb) | |
12512 | { | |
12513 | TCollection_AsciiString aStateStr(theArgVec[anArgIter]); | |
12514 | aStateStr.LowerCase(); | |
12515 | bool toEnable = true; | |
12516 | if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable)) | |
12517 | { | |
12518 | aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off; | |
12519 | } | |
12520 | else if (aStateStr == "noupdate" | |
12521 | || aStateStr == "freeze") | |
12522 | { | |
12523 | aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate; | |
12524 | } | |
12525 | else | |
12526 | { | |
12527 | --anArgIter; | |
12528 | } | |
12529 | } | |
12530 | aParams.FrustumCullingState = aState; | |
12531 | } | |
e276548b | 12532 | else |
12533 | { | |
23fe70ec | 12534 | Message::SendFail() << "Syntax error: unknown flag '" << anArg << "'"; |
bc8c79bb | 12535 | return 1; |
e276548b | 12536 | } |
12537 | } | |
189f85a3 | 12538 | |
12539 | return 0; | |
12540 | } | |
12541 | ||
79b544e6 | 12542 | //======================================================================= |
12543 | //function : searchInfo | |
12544 | //purpose : | |
12545 | //======================================================================= | |
12546 | inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict, | |
12547 | const TCollection_AsciiString& theKey) | |
12548 | { | |
12549 | for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next()) | |
12550 | { | |
12551 | if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False)) | |
12552 | { | |
12553 | return anIter.Value(); | |
12554 | } | |
12555 | } | |
12556 | return TCollection_AsciiString(); | |
12557 | } | |
12558 | ||
12559 | //======================================================================= | |
12560 | //function : VStatProfiler | |
12561 | //purpose : | |
12562 | //======================================================================= | |
12563 | static Standard_Integer VStatProfiler (Draw_Interpretor& theDI, | |
12564 | Standard_Integer theArgNb, | |
12565 | const char** theArgVec) | |
12566 | { | |
12567 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
12568 | if (aView.IsNull()) | |
12569 | { | |
23fe70ec | 12570 | Message::SendFail ("Error: no active viewer"); |
79b544e6 | 12571 | return 1; |
12572 | } | |
12573 | ||
12574 | Standard_Boolean toRedraw = Standard_True; | |
12575 | Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats; | |
12576 | Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval; | |
12577 | Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE; | |
12578 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
12579 | { | |
12580 | Standard_CString anArg (theArgVec[anArgIter]); | |
12581 | TCollection_AsciiString aFlag (anArg); | |
12582 | aFlag.LowerCase(); | |
12583 | if (aFlag == "-noredraw") | |
12584 | { | |
12585 | toRedraw = Standard_False; | |
12586 | } | |
12587 | else | |
12588 | { | |
12589 | Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE; | |
12590 | if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate; | |
12591 | else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU; | |
12592 | else if (aFlag == "alllayers" | |
12593 | || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers; | |
12594 | else if (aFlag == "allstructs" | |
a2803f37 | 12595 | || aFlag == "allstructures" |
12596 | || aFlag == "structs" | |
12597 | || aFlag == "structures") aParam = Graphic3d_RenderingParams::PerfCounters_Structures; | |
79b544e6 | 12598 | else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups; |
12599 | else if (aFlag == "allarrays" | |
12600 | || aFlag == "fillarrays" | |
12601 | || aFlag == "linearrays" | |
12602 | || aFlag == "pointarrays" | |
12603 | || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays; | |
12604 | else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles; | |
b9f43ad1 | 12605 | else if (aFlag == "lines") aParam = Graphic3d_RenderingParams::PerfCounters_Lines; |
79b544e6 | 12606 | else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points; |
12607 | else if (aFlag == "geommem" | |
12608 | || aFlag == "texturemem" | |
12609 | || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem; | |
12610 | else if (aFlag == "elapsedframe" | |
12611 | || aFlag == "cpuframeaverage" | |
12612 | || aFlag == "cpupickingaverage" | |
12613 | || aFlag == "cpucullingaverage" | |
12614 | || aFlag == "cpudynaverage" | |
12615 | || aFlag == "cpuframemax" | |
12616 | || aFlag == "cpupickingmax" | |
12617 | || aFlag == "cpucullingmax" | |
12618 | || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime; | |
12619 | else | |
12620 | { | |
23fe70ec | 12621 | Message::SendFail() << "Error: unknown argument '" << theArgVec[anArgIter] << "'"; |
79b544e6 | 12622 | continue; |
12623 | } | |
12624 | ||
12625 | aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam); | |
12626 | } | |
12627 | } | |
12628 | ||
12629 | if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE) | |
12630 | { | |
12631 | aView->ChangeRenderingParams().CollectedStats = | |
12632 | Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams); | |
12633 | ||
12634 | if (toRedraw) | |
12635 | { | |
12636 | aView->ChangeRenderingParams().StatsUpdateInterval = -1; | |
12637 | aView->Redraw(); | |
12638 | aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval; | |
12639 | } | |
12640 | ||
12641 | TColStd_IndexedDataMapOfStringString aDict; | |
12642 | aView->StatisticInformation (aDict); | |
12643 | ||
12644 | aView->ChangeRenderingParams().CollectedStats = aPrevCounters; | |
12645 | ||
12646 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
12647 | { | |
12648 | Standard_CString anArg(theArgVec[anArgIter]); | |
12649 | TCollection_AsciiString aFlag(anArg); | |
12650 | aFlag.LowerCase(); | |
12651 | if (aFlag == "fps") | |
12652 | { | |
12653 | theDI << searchInfo (aDict, "FPS") << " "; | |
12654 | } | |
12655 | else if (aFlag == "cpu") | |
12656 | { | |
12657 | theDI << searchInfo (aDict, "CPU FPS") << " "; | |
12658 | } | |
12659 | else if (aFlag == "alllayers") | |
12660 | { | |
12661 | theDI << searchInfo (aDict, "Layers") << " "; | |
12662 | } | |
12663 | else if (aFlag == "layers") | |
12664 | { | |
12665 | theDI << searchInfo (aDict, "Rendered layers") << " "; | |
12666 | } | |
a2803f37 | 12667 | else if (aFlag == "allstructs" |
12668 | || aFlag == "allstructures") | |
79b544e6 | 12669 | { |
12670 | theDI << searchInfo (aDict, "Structs") << " "; | |
12671 | } | |
a2803f37 | 12672 | else if (aFlag == "structs" |
12673 | || aFlag == "structures") | |
79b544e6 | 12674 | { |
a2803f37 | 12675 | TCollection_AsciiString aRend = searchInfo (aDict, "Rendered structs"); |
12676 | if (aRend.IsEmpty()) // all structures rendered | |
12677 | { | |
12678 | aRend = searchInfo (aDict, "Structs"); | |
12679 | } | |
12680 | theDI << aRend << " "; | |
79b544e6 | 12681 | } |
12682 | else if (aFlag == "groups") | |
12683 | { | |
12684 | theDI << searchInfo (aDict, "Rendered groups") << " "; | |
12685 | } | |
12686 | else if (aFlag == "allarrays") | |
12687 | { | |
12688 | theDI << searchInfo (aDict, "Rendered arrays") << " "; | |
12689 | } | |
12690 | else if (aFlag == "fillarrays") | |
12691 | { | |
12692 | theDI << searchInfo (aDict, "Rendered [fill] arrays") << " "; | |
12693 | } | |
12694 | else if (aFlag == "linearrays") | |
12695 | { | |
12696 | theDI << searchInfo (aDict, "Rendered [line] arrays") << " "; | |
12697 | } | |
12698 | else if (aFlag == "pointarrays") | |
12699 | { | |
12700 | theDI << searchInfo (aDict, "Rendered [point] arrays") << " "; | |
12701 | } | |
12702 | else if (aFlag == "textarrays") | |
12703 | { | |
12704 | theDI << searchInfo (aDict, "Rendered [text] arrays") << " "; | |
12705 | } | |
12706 | else if (aFlag == "triangles") | |
12707 | { | |
12708 | theDI << searchInfo (aDict, "Rendered triangles") << " "; | |
12709 | } | |
12710 | else if (aFlag == "points") | |
12711 | { | |
12712 | theDI << searchInfo (aDict, "Rendered points") << " "; | |
12713 | } | |
12714 | else if (aFlag == "geommem") | |
12715 | { | |
12716 | theDI << searchInfo (aDict, "GPU Memory [geometry]") << " "; | |
12717 | } | |
12718 | else if (aFlag == "texturemem") | |
12719 | { | |
12720 | theDI << searchInfo (aDict, "GPU Memory [textures]") << " "; | |
12721 | } | |
12722 | else if (aFlag == "framemem") | |
12723 | { | |
12724 | theDI << searchInfo (aDict, "GPU Memory [frames]") << " "; | |
12725 | } | |
12726 | else if (aFlag == "elapsedframe") | |
12727 | { | |
12728 | theDI << searchInfo (aDict, "Elapsed Frame (average)") << " "; | |
12729 | } | |
12730 | else if (aFlag == "cpuframe_average") | |
12731 | { | |
12732 | theDI << searchInfo (aDict, "CPU Frame (average)") << " "; | |
12733 | } | |
12734 | else if (aFlag == "cpupicking_average") | |
12735 | { | |
12736 | theDI << searchInfo (aDict, "CPU Picking (average)") << " "; | |
12737 | } | |
12738 | else if (aFlag == "cpuculling_average") | |
12739 | { | |
12740 | theDI << searchInfo (aDict, "CPU Culling (average)") << " "; | |
12741 | } | |
12742 | else if (aFlag == "cpudyn_average") | |
12743 | { | |
12744 | theDI << searchInfo (aDict, "CPU Dynamics (average)") << " "; | |
12745 | } | |
12746 | else if (aFlag == "cpuframe_max") | |
12747 | { | |
12748 | theDI << searchInfo (aDict, "CPU Frame (max)") << " "; | |
12749 | } | |
12750 | else if (aFlag == "cpupicking_max") | |
12751 | { | |
12752 | theDI << searchInfo (aDict, "CPU Picking (max)") << " "; | |
12753 | } | |
12754 | else if (aFlag == "cpuculling_max") | |
12755 | { | |
12756 | theDI << searchInfo (aDict, "CPU Culling (max)") << " "; | |
12757 | } | |
12758 | else if (aFlag == "cpudyn_max") | |
12759 | { | |
12760 | theDI << searchInfo (aDict, "CPU Dynamics (max)") << " "; | |
12761 | } | |
12762 | } | |
12763 | } | |
12764 | else | |
12765 | { | |
12766 | if (toRedraw) | |
12767 | { | |
12768 | aView->ChangeRenderingParams().StatsUpdateInterval = -1; | |
12769 | aView->Redraw(); | |
12770 | aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval; | |
12771 | } | |
12772 | theDI << "Statistic info:\n" << aView->StatisticInformation(); | |
12773 | } | |
12774 | return 0; | |
12775 | } | |
12776 | ||
0717ddc1 | 12777 | //======================================================================= |
12778 | //function : VXRotate | |
12779 | //purpose : | |
12780 | //======================================================================= | |
12781 | static Standard_Integer VXRotate (Draw_Interpretor& di, | |
12782 | Standard_Integer argc, | |
12783 | const char ** argv) | |
12784 | { | |
12785 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
12786 | if (aContext.IsNull()) | |
12787 | { | |
586db386 | 12788 | di << argv[0] << "ERROR : use 'vinit' command before \n"; |
0717ddc1 | 12789 | return 1; |
12790 | } | |
8693dfd0 | 12791 | |
0717ddc1 | 12792 | if (argc != 3) |
12793 | { | |
586db386 | 12794 | di << "ERROR : Usage : " << argv[0] << " name angle\n"; |
0717ddc1 | 12795 | return 1; |
12796 | } | |
12797 | ||
12798 | TCollection_AsciiString aName (argv[1]); | |
12799 | Standard_Real anAngle = Draw::Atof (argv[2]); | |
12800 | ||
12801 | // find object | |
12802 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
12803 | Handle(AIS_InteractiveObject) anIObj; | |
8f521168 | 12804 | if (!aMap.Find2 (aName, anIObj)) |
0717ddc1 | 12805 | { |
586db386 | 12806 | di << "Use 'vdisplay' before\n"; |
0717ddc1 | 12807 | return 1; |
12808 | } | |
0717ddc1 | 12809 | |
8f521168 | 12810 | gp_Trsf aTransform; |
12811 | aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle); | |
12812 | aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart()); | |
0717ddc1 | 12813 | |
8f521168 | 12814 | aContext->SetLocation (anIObj, aTransform); |
12815 | aContext->UpdateCurrentViewer(); | |
0717ddc1 | 12816 | return 0; |
12817 | } | |
12818 | ||
625e1958 | 12819 | //=============================================================================================== |
12820 | //function : VManipulator | |
12821 | //purpose : | |
12822 | //=============================================================================================== | |
12823 | static int VManipulator (Draw_Interpretor& theDi, | |
12824 | Standard_Integer theArgsNb, | |
12825 | const char** theArgVec) | |
12826 | { | |
bbf3fcde | 12827 | Handle(V3d_View) aCurrentView = ViewerTest::CurrentView(); |
625e1958 | 12828 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); |
12829 | ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False); | |
bbf3fcde | 12830 | if (aCurrentView.IsNull() |
625e1958 | 12831 | || aViewer.IsNull()) |
12832 | { | |
23fe70ec | 12833 | Message::SendFail ("Error: no active viewer"); |
625e1958 | 12834 | return 1; |
12835 | } | |
12836 | ||
12837 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView()); | |
12838 | Standard_Integer anArgIter = 1; | |
12839 | for (; anArgIter < theArgsNb; ++anArgIter) | |
12840 | { | |
12841 | anUpdateTool.parseRedrawMode (theArgVec[anArgIter]); | |
12842 | } | |
12843 | ||
12844 | ViewerTest_CmdParser aCmd; | |
293211ae | 12845 | aCmd.SetDescription ("Manages manipulator for interactive objects:"); |
625e1958 | 12846 | aCmd.AddOption ("attach", "... object - attach manipulator to an object"); |
12847 | aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching"); | |
12848 | aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching "); | |
12849 | aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching "); | |
bbf3fcde | 12850 | aCmd.AddOption ("view", "... {active | [view name]} - define view in which manipulator will be displayed, 'all' by default"); |
625e1958 | 12851 | aCmd.AddOption ("detach", "... - detach manipulator"); |
12852 | ||
12853 | aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation"); | |
12854 | aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation"); | |
12855 | aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation"); | |
12856 | ||
12857 | aCmd.AddOption ("move", "... x y z - move object"); | |
12858 | aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object"); | |
12859 | aCmd.AddOption ("scale", "... factor - scale object"); | |
12860 | ||
12861 | aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection"); | |
12862 | aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform"); | |
12863 | aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform"); | |
f522ce50 | 12864 | aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform"); |
625e1958 | 12865 | aCmd.AddOption ("gap", "... value - set gap between sub-parts"); |
12866 | aCmd.AddOption ("part", "... axis mode {0|1} - set visual part"); | |
84b904bc | 12867 | aCmd.AddOption ("parts", "... all axes mode {0|1} - set visual part"); |
625e1958 | 12868 | aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator"); |
12869 | aCmd.AddOption ("size", "... size - set size of manipulator"); | |
12870 | aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence"); | |
12871 | ||
12872 | aCmd.Parse (theArgsNb, theArgVec); | |
12873 | ||
12874 | if (aCmd.HasOption ("help")) | |
12875 | { | |
12876 | theDi.PrintHelp (theArgVec[0]); | |
12877 | return 0; | |
12878 | } | |
12879 | ||
12880 | ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS(); | |
12881 | ||
293211ae | 12882 | TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str()); |
625e1958 | 12883 | |
12884 | if (aName.IsEmpty()) | |
12885 | { | |
23fe70ec | 12886 | Message::SendFail ("Syntax error: please specify AIS manipulator's name as the first argument"); |
625e1958 | 12887 | return 1; |
12888 | } | |
12889 | ||
12890 | // ---------------------------------- | |
12891 | // detach existing manipulator object | |
12892 | // ---------------------------------- | |
12893 | ||
12894 | if (aCmd.HasOption ("detach")) | |
12895 | { | |
12896 | if (!aMapAIS.IsBound2 (aName)) | |
12897 | { | |
23fe70ec | 12898 | Message::SendFail() << "Syntax error: could not find \"" << aName << "\" AIS object"; |
625e1958 | 12899 | return 1; |
12900 | } | |
12901 | ||
12902 | Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName)); | |
12903 | if (aManipulator.IsNull()) | |
12904 | { | |
23fe70ec | 12905 | Message::SendFail() << "Syntax error: \"" << aName << "\" is not an AIS manipulator"; |
625e1958 | 12906 | return 1; |
12907 | } | |
12908 | ||
12909 | aManipulator->Detach(); | |
12910 | aMapAIS.UnBind2 (aName); | |
0577ae8c | 12911 | ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True); |
625e1958 | 12912 | |
12913 | return 0; | |
12914 | } | |
12915 | ||
12916 | // ----------------------------------------------- | |
12917 | // find or create manipulator if it does not exist | |
12918 | // ----------------------------------------------- | |
12919 | ||
12920 | Handle(AIS_Manipulator) aManipulator; | |
12921 | if (!aMapAIS.IsBound2 (aName)) | |
12922 | { | |
12923 | std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n"; | |
12924 | ||
8b037fe4 | 12925 | aManipulator = new AIS_Manipulator(); |
49582f9d | 12926 | aManipulator->SetModeActivationOnDetection (true); |
625e1958 | 12927 | aMapAIS.Bind (aManipulator, aName); |
12928 | } | |
12929 | else | |
12930 | { | |
12931 | aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName)); | |
12932 | if (aManipulator.IsNull()) | |
12933 | { | |
23fe70ec | 12934 | Message::SendFail() << "Syntax error: \"" << aName << "\" is not an AIS manipulator"; |
625e1958 | 12935 | return 1; |
12936 | } | |
12937 | } | |
12938 | ||
12939 | // ----------------------------------------- | |
12940 | // change properties of manipulator instance | |
12941 | // ----------------------------------------- | |
12942 | ||
12943 | if (aCmd.HasOption ("autoActivate", 1, Standard_True)) | |
12944 | { | |
12945 | aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate")); | |
12946 | } | |
12947 | if (aCmd.HasOption ("followTranslation", 1, Standard_True)) | |
12948 | { | |
12949 | aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation")); | |
12950 | } | |
12951 | if (aCmd.HasOption ("followRotation", 1, Standard_True)) | |
12952 | { | |
12953 | aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation")); | |
12954 | } | |
f522ce50 | 12955 | if (aCmd.HasOption("followDragging", 1, Standard_True)) |
12956 | { | |
12957 | aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging")); | |
12958 | } | |
625e1958 | 12959 | if (aCmd.HasOption ("gap", 1, Standard_True)) |
12960 | { | |
12961 | aManipulator->SetGap (aCmd.ArgFloat ("gap")); | |
12962 | } | |
12963 | if (aCmd.HasOption ("part", 3, Standard_True)) | |
12964 | { | |
12965 | Standard_Integer anAxis = aCmd.ArgInt ("part", 0); | |
12966 | Standard_Integer aMode = aCmd.ArgInt ("part", 1); | |
12967 | Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2); | |
f522ce50 | 12968 | if (aMode < 1 || aMode > 4) |
625e1958 | 12969 | { |
23fe70ec | 12970 | Message::SendFail ("Syntax error: mode value should be in range [1, 4]"); |
625e1958 | 12971 | return 1; |
12972 | } | |
12973 | ||
12974 | aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff); | |
12975 | } | |
84b904bc | 12976 | if (aCmd.HasOption("parts", 2, Standard_True)) |
12977 | { | |
12978 | Standard_Integer aMode = aCmd.ArgInt("parts", 0); | |
12979 | Standard_Boolean aOnOff = aCmd.ArgBool("parts", 1); | |
12980 | if (aMode < 1 || aMode > 4) | |
12981 | { | |
23fe70ec | 12982 | Message::SendFail ("Syntax error: mode value should be in range [1, 4]"); |
84b904bc | 12983 | return 1; |
12984 | } | |
12985 | ||
12986 | aManipulator->SetPart(static_cast<AIS_ManipulatorMode>(aMode), aOnOff); | |
12987 | } | |
625e1958 | 12988 | if (aCmd.HasOption ("pos", 3, Standard_True)) |
12989 | { | |
12990 | gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0); | |
12991 | gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction(); | |
12992 | gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection(); | |
12993 | ||
12994 | aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir)); | |
12995 | } | |
12996 | if (aCmd.HasOption ("size", 1, Standard_True)) | |
12997 | { | |
12998 | aManipulator->SetSize (aCmd.ArgFloat ("size")); | |
12999 | } | |
13000 | if (aCmd.HasOption ("zoomable", 1, Standard_True)) | |
13001 | { | |
13002 | aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable")); | |
13003 | ||
13004 | if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator)) | |
13005 | { | |
13006 | ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False); | |
13007 | ViewerTest::GetAISContext()->Display (aManipulator, Standard_False); | |
13008 | } | |
13009 | } | |
13010 | ||
13011 | // --------------------------------------------------- | |
13012 | // attach, detach or access manipulator from an object | |
13013 | // --------------------------------------------------- | |
13014 | ||
13015 | if (aCmd.HasOption ("attach")) | |
13016 | { | |
13017 | // Find an object and attach manipulator to it | |
13018 | if (!aCmd.HasOption ("attach", 1, Standard_True)) | |
13019 | { | |
13020 | return 1; | |
13021 | } | |
13022 | ||
13023 | TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str()); | |
8f521168 | 13024 | Handle(AIS_InteractiveObject) anObject; |
13025 | if (!aMapAIS.Find2 (anObjName, anObject)) | |
625e1958 | 13026 | { |
23fe70ec | 13027 | Message::SendFail() << "Syntax error: AIS object \"" << anObjName << "\" does not exist"; |
625e1958 | 13028 | return 1; |
13029 | } | |
13030 | ||
8b037fe4 | 13031 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (aMapAIS); |
13032 | anIter.More(); anIter.Next()) | |
625e1958 | 13033 | { |
8b037fe4 | 13034 | Handle(AIS_Manipulator) aManip = Handle(AIS_Manipulator)::DownCast (anIter.Key1()); |
13035 | if (!aManip.IsNull() | |
13036 | && aManip->IsAttached() | |
13037 | && aManip->Object() == anObject) | |
625e1958 | 13038 | { |
23fe70ec | 13039 | Message::SendFail() << "Syntax error: AIS object \"" << anObjName << "\" already has manipulator"; |
625e1958 | 13040 | return 1; |
13041 | } | |
13042 | } | |
13043 | ||
13044 | AIS_Manipulator::OptionsForAttach anOptions; | |
13045 | if (aCmd.HasOption ("adjustPosition", 1, Standard_True)) | |
13046 | { | |
13047 | anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition")); | |
13048 | } | |
13049 | if (aCmd.HasOption ("adjustSize", 1, Standard_True)) | |
13050 | { | |
13051 | anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize")); | |
13052 | } | |
13053 | if (aCmd.HasOption ("enableModes", 1, Standard_True)) | |
13054 | { | |
13055 | anOptions.SetEnableModes (aCmd.ArgBool ("enableModes")); | |
13056 | } | |
13057 | ||
13058 | aManipulator->Attach (anObject, anOptions); | |
bbf3fcde | 13059 | |
13060 | // Check view option | |
13061 | if (aCmd.HasOption ("view")) | |
13062 | { | |
13063 | if (!aCmd.HasOption ("view", 1, Standard_True)) | |
13064 | { | |
13065 | return 1; | |
13066 | } | |
13067 | TCollection_AsciiString aViewString (aCmd.Arg ("view", 0).c_str()); | |
13068 | Handle(V3d_View) aView; | |
13069 | if (aViewString.IsEqual ("active")) | |
13070 | { | |
13071 | aView = ViewerTest::CurrentView(); | |
13072 | } | |
13073 | else // Check view name | |
13074 | { | |
13075 | ViewerTest_Names aViewNames (aViewString); | |
13076 | if (!ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) | |
13077 | { | |
23fe70ec | 13078 | Message::SendFail() << "Syntax error: wrong view name '" << aViewString << "'"; |
bbf3fcde | 13079 | return 1; |
13080 | } | |
13081 | aView = ViewerTest_myViews.Find1 (aViewNames.GetViewName()); | |
13082 | if (aView.IsNull()) | |
13083 | { | |
23fe70ec | 13084 | Message::SendFail() << "Syntax error: cannot find view with name '" << aViewString << "'"; |
bbf3fcde | 13085 | return 1; |
13086 | } | |
13087 | } | |
13088 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
13089 | anIter (ViewerTest_myViews); anIter.More(); anIter.Next()) | |
13090 | { | |
13091 | ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, anIter.Value(), Standard_False); | |
13092 | } | |
13093 | ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, aView, Standard_True); | |
13094 | } | |
625e1958 | 13095 | } |
13096 | ||
13097 | // -------------------------------------- | |
13098 | // apply transformation using manipulator | |
13099 | // -------------------------------------- | |
13100 | ||
13101 | if (aCmd.HasOption ("startTransform", 2, Standard_True)) | |
13102 | { | |
13103 | aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView()); | |
13104 | } | |
13105 | if (aCmd.HasOption ("transform", 2, Standard_True)) | |
13106 | { | |
13107 | aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView()); | |
13108 | } | |
13109 | if (aCmd.HasOption ("stopTransform")) | |
13110 | { | |
13111 | Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort"); | |
13112 | ||
13113 | aManipulator->StopTransform (toApply); | |
13114 | } | |
13115 | ||
13116 | gp_Trsf aT; | |
13117 | if (aCmd.HasOption ("move", 3, Standard_True)) | |
13118 | { | |
13119 | aT.SetTranslationPart (aCmd.ArgVec ("move")); | |
13120 | } | |
13121 | if (aCmd.HasOption ("rotate", 7, Standard_True)) | |
13122 | { | |
13123 | aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6)); | |
13124 | } | |
13125 | if (aCmd.HasOption ("scale", 1)) | |
13126 | { | |
13127 | aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale")); | |
13128 | } | |
13129 | ||
13130 | if (aT.Form() != gp_Identity) | |
13131 | { | |
13132 | aManipulator->Transform (aT); | |
13133 | } | |
13134 | ||
0577ae8c | 13135 | ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True); |
625e1958 | 13136 | |
13137 | return 0; | |
13138 | } | |
13139 | ||
8e5fb5ea | 13140 | //=============================================================================================== |
13141 | //function : VSelectionProperties | |
13142 | //purpose : | |
13143 | //=============================================================================================== | |
13144 | static int VSelectionProperties (Draw_Interpretor& theDi, | |
13145 | Standard_Integer theArgsNb, | |
13146 | const char** theArgVec) | |
13147 | { | |
13148 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
13149 | if (aCtx.IsNull()) | |
13150 | { | |
23fe70ec | 13151 | Message::SendFail ("Error: no active viewer"); |
8e5fb5ea | 13152 | return 1; |
13153 | } | |
13154 | ||
be3d8cbc | 13155 | if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected") |
13156 | { | |
13157 | // handle obsolete alias | |
13158 | bool toEnable = true; | |
13159 | if (theArgsNb < 2) | |
13160 | { | |
13161 | theDi << (aCtx->ToHilightSelected() ? "on" : "off"); | |
13162 | return 0; | |
13163 | } | |
13164 | else if (theArgsNb != 2 | |
13165 | || !ViewerTest::ParseOnOff (theArgVec[1], toEnable)) | |
13166 | { | |
23fe70ec | 13167 | Message::SendFail ("Syntax error: wrong number of parameters"); |
be3d8cbc | 13168 | return 1; |
13169 | } | |
13170 | if (toEnable != aCtx->ToHilightSelected()) | |
13171 | { | |
13172 | aCtx->ClearDetected(); | |
13173 | aCtx->SetToHilightSelected (toEnable); | |
13174 | } | |
13175 | return 0; | |
13176 | } | |
13177 | ||
f838dac4 | 13178 | Standard_Boolean toPrint = theArgsNb == 1; |
13179 | Standard_Boolean toRedraw = Standard_False; | |
13180 | Standard_Integer anArgIter = 1; | |
13181 | Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None; | |
13182 | if (anArgIter < theArgsNb) | |
13183 | { | |
13184 | TCollection_AsciiString anArgFirst (theArgVec[anArgIter]); | |
13185 | anArgFirst.LowerCase(); | |
13186 | ++anArgIter; | |
13187 | if (anArgFirst == "dynhighlight" | |
13188 | || anArgFirst == "dynhilight" | |
13189 | || anArgFirst == "dynamichighlight" | |
13190 | || anArgFirst == "dynamichilight") | |
13191 | { | |
13192 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
13193 | } | |
13194 | else if (anArgFirst == "localdynhighlight" | |
13195 | || anArgFirst == "localdynhilight" | |
13196 | || anArgFirst == "localdynamichighlight" | |
13197 | || anArgFirst == "localdynamichilight") | |
13198 | { | |
13199 | aType = Prs3d_TypeOfHighlight_LocalDynamic; | |
13200 | } | |
13201 | else if (anArgFirst == "selhighlight" | |
13202 | || anArgFirst == "selhilight" | |
13203 | || anArgFirst == "selectedhighlight" | |
13204 | || anArgFirst == "selectedhilight") | |
13205 | { | |
13206 | aType = Prs3d_TypeOfHighlight_Selected; | |
13207 | } | |
13208 | else if (anArgFirst == "localselhighlight" | |
13209 | || anArgFirst == "localselhilight" | |
13210 | || anArgFirst == "localselectedhighlight" | |
13211 | || anArgFirst == "localselectedhilight") | |
13212 | { | |
13213 | aType = Prs3d_TypeOfHighlight_LocalSelected; | |
13214 | } | |
13215 | else | |
13216 | { | |
13217 | --anArgIter; | |
13218 | } | |
13219 | } | |
13220 | for (; anArgIter < theArgsNb; ++anArgIter) | |
13221 | { | |
13222 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
13223 | anArg.LowerCase(); | |
13224 | if (anArg == "-help") | |
13225 | { | |
13226 | theDi.PrintHelp (theArgVec[0]); | |
13227 | return 0; | |
13228 | } | |
13229 | else if (anArg == "-print") | |
13230 | { | |
13231 | toPrint = Standard_True; | |
13232 | } | |
13233 | else if (anArg == "-autoactivate") | |
13234 | { | |
13235 | Standard_Boolean toEnable = Standard_True; | |
13236 | if (anArgIter + 1 < theArgsNb | |
13237 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
13238 | { | |
13239 | ++anArgIter; | |
13240 | } | |
13241 | aCtx->SetAutoActivateSelection (toEnable); | |
13242 | } | |
be3d8cbc | 13243 | else if (anArg == "-automatichighlight" |
13244 | || anArg == "-automatichilight" | |
13245 | || anArg == "-autohighlight" | |
13246 | || anArg == "-autohilight") | |
13247 | { | |
13248 | Standard_Boolean toEnable = Standard_True; | |
13249 | if (anArgIter + 1 < theArgsNb | |
13250 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
13251 | { | |
13252 | ++anArgIter; | |
13253 | } | |
13254 | aCtx->ClearSelected (false); | |
13255 | aCtx->ClearDetected(); | |
13256 | aCtx->SetAutomaticHilight (toEnable); | |
13257 | toRedraw = true; | |
13258 | } | |
13259 | else if (anArg == "-highlightselected" | |
13260 | || anArg == "-hilightselected") | |
13261 | { | |
13262 | Standard_Boolean toEnable = Standard_True; | |
13263 | if (anArgIter + 1 < theArgsNb | |
13264 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
13265 | { | |
13266 | ++anArgIter; | |
13267 | } | |
13268 | aCtx->ClearDetected(); | |
13269 | aCtx->SetToHilightSelected (toEnable); | |
13270 | toRedraw = true; | |
13271 | } | |
14c4193d | 13272 | else if (anArg == "-pickstrategy" |
13273 | || anArg == "-pickingstrategy") | |
13274 | { | |
13275 | if (++anArgIter >= theArgsNb) | |
13276 | { | |
23fe70ec | 13277 | Message::SendFail ("Syntax error: type of highlighting is undefined"); |
14c4193d | 13278 | return 1; |
13279 | } | |
13280 | ||
13281 | SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable; | |
13282 | TCollection_AsciiString aVal (theArgVec[anArgIter]); | |
13283 | aVal.LowerCase(); | |
13284 | if (aVal == "first" | |
13285 | || aVal == "firstaccepted" | |
13286 | || aVal == "firstacceptable") | |
13287 | { | |
13288 | aStrategy = SelectMgr_PickingStrategy_FirstAcceptable; | |
13289 | } | |
13290 | else if (aVal == "topmost" | |
13291 | || aVal == "onlyTopmost") | |
13292 | { | |
13293 | aStrategy = SelectMgr_PickingStrategy_OnlyTopmost; | |
13294 | } | |
13295 | else | |
13296 | { | |
23fe70ec | 13297 | Message::SendFail() << "Syntax error: unknown picking strategy '" << aVal << "'"; |
14c4193d | 13298 | return 1; |
13299 | } | |
13300 | ||
13301 | aCtx->SetPickingStrategy (aStrategy); | |
13302 | } | |
f838dac4 | 13303 | else if (anArg == "-pixtol" |
13304 | && anArgIter + 1 < theArgsNb) | |
13305 | { | |
13306 | aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter])); | |
13307 | } | |
13308 | else if ((anArg == "-mode" | |
13309 | || anArg == "-dispmode") | |
13310 | && anArgIter + 1 < theArgsNb) | |
13311 | { | |
13312 | if (aType == Prs3d_TypeOfHighlight_None) | |
13313 | { | |
23fe70ec | 13314 | Message::SendFail ("Syntax error: type of highlighting is undefined"); |
f838dac4 | 13315 | return 1; |
13316 | } | |
8e5fb5ea | 13317 | |
f838dac4 | 13318 | const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]); |
13319 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); | |
13320 | aStyle->SetDisplayMode (aDispMode); | |
13321 | toRedraw = Standard_True; | |
13322 | } | |
13323 | else if (anArg == "-layer" | |
13324 | && anArgIter + 1 < theArgsNb) | |
13325 | { | |
13326 | if (aType == Prs3d_TypeOfHighlight_None) | |
13327 | { | |
23fe70ec | 13328 | Message::SendFail ("Syntax error: type of highlighting is undefined"); |
f838dac4 | 13329 | return 1; |
13330 | } | |
8e5fb5ea | 13331 | |
55c8f0f7 BB |
13332 | ++anArgIter; |
13333 | Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN; | |
13334 | if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer)) | |
f838dac4 | 13335 | { |
23fe70ec | 13336 | Message::SendFail() << "Syntax error at " << theArgVec[anArgIter]; |
55c8f0f7 | 13337 | return 1; |
f838dac4 | 13338 | } |
8e5fb5ea | 13339 | |
f838dac4 | 13340 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
13341 | aStyle->SetZLayer (aNewLayer); | |
13342 | toRedraw = Standard_True; | |
13343 | } | |
13344 | else if (anArg == "-hicolor" | |
13345 | || anArg == "-selcolor" | |
13346 | || anArg == "-color") | |
13347 | { | |
13348 | if (anArg.StartsWith ("-hi")) | |
13349 | { | |
13350 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
13351 | } | |
13352 | else if (anArg.StartsWith ("-sel")) | |
13353 | { | |
13354 | aType = Prs3d_TypeOfHighlight_Selected; | |
13355 | } | |
13356 | else if (aType == Prs3d_TypeOfHighlight_None) | |
13357 | { | |
23fe70ec | 13358 | Message::SendFail ("Syntax error: type of highlighting is undefined"); |
f838dac4 | 13359 | return 1; |
13360 | } | |
8e5fb5ea | 13361 | |
f838dac4 | 13362 | Quantity_Color aColor; |
13363 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1, | |
13364 | theArgVec + anArgIter + 1, | |
13365 | aColor); | |
13366 | if (aNbParsed == 0) | |
13367 | { | |
23fe70ec | 13368 | Message::SendFail ("Syntax error: need more arguments"); |
f838dac4 | 13369 | return 1; |
13370 | } | |
13371 | anArgIter += aNbParsed; | |
8e5fb5ea | 13372 | |
f838dac4 | 13373 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
13374 | aStyle->SetColor (aColor); | |
13375 | toRedraw = Standard_True; | |
13376 | } | |
13377 | else if ((anArg == "-transp" | |
13378 | || anArg == "-transparency" | |
13379 | || anArg == "-hitransp" | |
13380 | || anArg == "-seltransp" | |
13381 | || anArg == "-hitransplocal" | |
13382 | || anArg == "-seltransplocal") | |
13383 | && anArgIter + 1 < theArgsNb) | |
13384 | { | |
13385 | if (anArg.StartsWith ("-hi")) | |
13386 | { | |
13387 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
13388 | } | |
13389 | else if (anArg.StartsWith ("-sel")) | |
13390 | { | |
13391 | aType = Prs3d_TypeOfHighlight_Selected; | |
13392 | } | |
13393 | else if (aType == Prs3d_TypeOfHighlight_None) | |
13394 | { | |
23fe70ec | 13395 | Message::SendFail ("Syntax error: type of highlighting is undefined"); |
f838dac4 | 13396 | return 1; |
13397 | } | |
8e5fb5ea | 13398 | |
f838dac4 | 13399 | const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]); |
13400 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); | |
13401 | aStyle->SetTransparency ((Standard_ShortReal )aTransp); | |
13402 | toRedraw = Standard_True; | |
13403 | } | |
13404 | else if ((anArg == "-mat" | |
13405 | || anArg == "-material") | |
13406 | && anArgIter + 1 < theArgsNb) | |
13407 | { | |
13408 | if (aType == Prs3d_TypeOfHighlight_None) | |
13409 | { | |
23fe70ec | 13410 | Message::SendFail ("Syntax error: type of highlighting is undefined"); |
f838dac4 | 13411 | return 1; |
13412 | } | |
8e5fb5ea | 13413 | |
f838dac4 | 13414 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
13415 | Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]); | |
13416 | if (aMatName != Graphic3d_NOM_DEFAULT) | |
13417 | { | |
13418 | ++anArgIter; | |
13419 | Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d(); | |
13420 | *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect(); | |
13421 | Graphic3d_MaterialAspect aMat (aMatName); | |
13422 | aMat.SetColor (aStyle->Color()); | |
13423 | aMat.SetTransparency (aStyle->Transparency()); | |
13424 | anAspect->SetFrontMaterial (aMat); | |
13425 | anAspect->SetInteriorColor (aStyle->Color()); | |
13426 | aStyle->SetBasicFillAreaAspect (anAspect); | |
13427 | } | |
13428 | else | |
13429 | { | |
13430 | aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)()); | |
13431 | } | |
13432 | toRedraw = Standard_True; | |
13433 | } | |
13434 | else | |
13435 | { | |
23fe70ec | 13436 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
f838dac4 | 13437 | } |
8e5fb5ea | 13438 | } |
13439 | ||
f838dac4 | 13440 | if (toPrint) |
8e5fb5ea | 13441 | { |
f838dac4 | 13442 | const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle(); |
13443 | const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle(); | |
8e5fb5ea | 13444 | theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n"; |
be3d8cbc | 13445 | theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n"; |
13446 | theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n"; | |
8e5fb5ea | 13447 | theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n"; |
f838dac4 | 13448 | theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n"; |
13449 | theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n"; | |
13450 | theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n"; | |
13451 | theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n"; | |
13452 | theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n"; | |
13453 | theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n"; | |
13454 | theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n"; | |
13455 | theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n"; | |
8e5fb5ea | 13456 | } |
13457 | ||
13458 | if (aCtx->NbSelected() != 0 && toRedraw) | |
13459 | { | |
13460 | aCtx->HilightSelected (Standard_True); | |
13461 | } | |
13462 | ||
13463 | return 0; | |
13464 | } | |
13465 | ||
decdee7d | 13466 | //=============================================================================================== |
13467 | //function : VDumpSelectionImage | |
13468 | //purpose : | |
13469 | //=============================================================================================== | |
13470 | static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/, | |
13471 | Standard_Integer theArgsNb, | |
13472 | const char** theArgVec) | |
13473 | { | |
13474 | if (theArgsNb < 2) | |
13475 | { | |
23fe70ec | 13476 | Message::SendFail() << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'"; |
decdee7d | 13477 | return 1; |
13478 | } | |
13479 | ||
13480 | const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext(); | |
b40cdc2b | 13481 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); |
decdee7d | 13482 | if (aContext.IsNull()) |
13483 | { | |
23fe70ec | 13484 | Message::SendFail ("Error: no active viewer"); |
decdee7d | 13485 | return 1; |
13486 | } | |
13487 | ||
13488 | TCollection_AsciiString aFile; | |
13489 | StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth; | |
b40cdc2b | 13490 | Handle(Graphic3d_Camera) aCustomCam; |
dc858f4c | 13491 | Image_Format anImgFormat = Image_Format_BGR; |
decdee7d | 13492 | Standard_Integer aPickedIndex = 1; |
13493 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
13494 | { | |
13495 | TCollection_AsciiString aParam (theArgVec[anArgIter]); | |
13496 | aParam.LowerCase(); | |
13497 | if (aParam == "-type") | |
13498 | { | |
13499 | if (++anArgIter >= theArgsNb) | |
13500 | { | |
23fe70ec | 13501 | Message::SendFail ("Syntax error: wrong number parameters of flag '-depth'"); |
decdee7d | 13502 | return 1; |
13503 | } | |
13504 | ||
13505 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
13506 | aValue.LowerCase(); | |
13507 | if (aValue == "depth" | |
13508 | || aValue == "normdepth" | |
13509 | || aValue == "normalizeddepth") | |
13510 | { | |
13511 | aType = StdSelect_TypeOfSelectionImage_NormalizedDepth; | |
dc858f4c | 13512 | anImgFormat = Image_Format_GrayF; |
decdee7d | 13513 | } |
13514 | if (aValue == "depthinverted" | |
13515 | || aValue == "normdepthinverted" | |
13516 | || aValue == "normalizeddepthinverted" | |
13517 | || aValue == "inverted") | |
13518 | { | |
13519 | aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted; | |
dc858f4c | 13520 | anImgFormat = Image_Format_GrayF; |
decdee7d | 13521 | } |
13522 | else if (aValue == "unnormdepth" | |
13523 | || aValue == "unnormalizeddepth") | |
13524 | { | |
13525 | aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth; | |
dc858f4c | 13526 | anImgFormat = Image_Format_GrayF; |
decdee7d | 13527 | } |
13528 | else if (aValue == "objectcolor" | |
13529 | || aValue == "object" | |
13530 | || aValue == "color") | |
13531 | { | |
13532 | aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject; | |
13533 | } | |
13534 | else if (aValue == "entitycolor" | |
13535 | || aValue == "entity") | |
13536 | { | |
13537 | aType = StdSelect_TypeOfSelectionImage_ColoredEntity; | |
13538 | } | |
13539 | else if (aValue == "ownercolor" | |
13540 | || aValue == "owner") | |
13541 | { | |
13542 | aType = StdSelect_TypeOfSelectionImage_ColoredOwner; | |
13543 | } | |
13544 | else if (aValue == "selectionmodecolor" | |
13545 | || aValue == "selectionmode" | |
13546 | || aValue == "selmodecolor" | |
13547 | || aValue == "selmode") | |
13548 | { | |
13549 | aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode; | |
13550 | } | |
13551 | } | |
13552 | else if (aParam == "-picked" | |
13553 | || aParam == "-pickeddepth" | |
13554 | || aParam == "-pickedindex") | |
13555 | { | |
13556 | if (++anArgIter >= theArgsNb) | |
13557 | { | |
23fe70ec | 13558 | Message::SendFail() << "Syntax error: wrong number parameters at '" << aParam << "'"; |
decdee7d | 13559 | return 1; |
13560 | } | |
13561 | ||
13562 | aPickedIndex = Draw::Atoi (theArgVec[anArgIter]); | |
13563 | } | |
b40cdc2b | 13564 | else if (anArgIter + 1 < theArgsNb |
13565 | && aParam == "-xrpose") | |
13566 | { | |
13567 | TCollection_AsciiString anXRArg (theArgVec[++anArgIter]); | |
13568 | anXRArg.LowerCase(); | |
13569 | if (anXRArg == "base") | |
13570 | { | |
13571 | aCustomCam = aView->View()->BaseXRCamera(); | |
13572 | } | |
13573 | else if (anXRArg == "head") | |
13574 | { | |
13575 | aCustomCam = aView->View()->PosedXRCamera(); | |
13576 | } | |
13577 | else | |
13578 | { | |
13579 | Message::SendFail() << "Syntax error: unknown XR pose '" << anXRArg << "'"; | |
13580 | return 1; | |
13581 | } | |
13582 | if (aCustomCam.IsNull()) | |
13583 | { | |
13584 | Message::SendFail() << "Error: undefined XR pose"; | |
13585 | return 0; | |
13586 | } | |
13587 | } | |
decdee7d | 13588 | else if (aFile.IsEmpty()) |
13589 | { | |
13590 | aFile = theArgVec[anArgIter]; | |
13591 | } | |
13592 | else | |
13593 | { | |
23fe70ec | 13594 | Message::SendFail() << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'"; |
decdee7d | 13595 | return 1; |
13596 | } | |
13597 | } | |
13598 | if (aFile.IsEmpty()) | |
13599 | { | |
23fe70ec | 13600 | Message::SendFail ("Syntax error: image file name is missing"); |
decdee7d | 13601 | return 1; |
13602 | } | |
13603 | ||
decdee7d | 13604 | Standard_Integer aWidth = 0, aHeight = 0; |
13605 | aView->Window()->Size (aWidth, aHeight); | |
13606 | ||
13607 | Image_AlienPixMap aPixMap; | |
13608 | if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight)) | |
13609 | { | |
23fe70ec | 13610 | Message::SendFail ("Error: can't allocate image"); |
decdee7d | 13611 | return 1; |
13612 | } | |
b40cdc2b | 13613 | |
13614 | const bool wasImmUpdate = aView->SetImmediateUpdate (false); | |
13615 | Handle(Graphic3d_Camera) aCamBack = aView->Camera(); | |
13616 | if (!aCustomCam.IsNull()) | |
13617 | { | |
13618 | aView->SetCamera (aCustomCam); | |
13619 | } | |
decdee7d | 13620 | if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex)) |
13621 | { | |
23fe70ec | 13622 | Message::SendFail ("Error: can't generate selection image"); |
decdee7d | 13623 | return 1; |
13624 | } | |
b40cdc2b | 13625 | if (!aCustomCam.IsNull()) |
13626 | { | |
13627 | aView->SetCamera (aCamBack); | |
13628 | } | |
13629 | aView->SetImmediateUpdate (wasImmUpdate); | |
13630 | ||
decdee7d | 13631 | if (!aPixMap.Save (aFile)) |
13632 | { | |
23fe70ec | 13633 | Message::SendFail ("Error: can't save selection image"); |
decdee7d | 13634 | return 0; |
13635 | } | |
13636 | return 0; | |
13637 | } | |
13638 | ||
2108d9a2 | 13639 | //=============================================================================================== |
13640 | //function : VViewCube | |
13641 | //purpose : | |
13642 | //=============================================================================================== | |
13643 | static int VViewCube (Draw_Interpretor& , | |
13644 | Standard_Integer theNbArgs, | |
13645 | const char** theArgVec) | |
13646 | { | |
13647 | const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext(); | |
13648 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
13649 | if (aContext.IsNull() || aView.IsNull()) | |
13650 | { | |
23fe70ec | 13651 | Message::SendFail ("Error: no active viewer"); |
2108d9a2 | 13652 | return 1; |
13653 | } | |
13654 | else if (theNbArgs < 2) | |
13655 | { | |
23fe70ec | 13656 | Message::SendFail ("Syntax error: wrong number arguments"); |
2108d9a2 | 13657 | return 1; |
13658 | } | |
13659 | ||
13660 | Handle(AIS_ViewCube) aViewCube; | |
13661 | ViewerTest_AutoUpdater anUpdateTool (aContext, aView); | |
13662 | Quantity_Color aColorRgb; | |
13663 | TCollection_AsciiString aName; | |
13664 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
13665 | { | |
13666 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
13667 | anArg.LowerCase(); | |
13668 | if (anUpdateTool.parseRedrawMode (anArg)) | |
13669 | { | |
13670 | // | |
13671 | } | |
13672 | else if (aViewCube.IsNull()) | |
13673 | { | |
13674 | aName = theArgVec[anArgIter]; | |
13675 | if (aName.StartsWith ("-")) | |
13676 | { | |
23fe70ec | 13677 | Message::SendFail ("Syntax error: object name should be specified"); |
2108d9a2 | 13678 | return 1; |
13679 | } | |
13680 | Handle(AIS_InteractiveObject) aPrs; | |
13681 | GetMapOfAIS().Find2 (aName, aPrs); | |
13682 | aViewCube = Handle(AIS_ViewCube)::DownCast (aPrs); | |
13683 | if (aViewCube.IsNull()) | |
13684 | { | |
13685 | aViewCube = new AIS_ViewCube(); | |
13686 | aViewCube->SetBoxColor (Quantity_NOC_GRAY50); | |
13687 | aViewCube->SetViewAnimation (ViewerTest::CurrentEventManager()->ViewAnimation()); | |
13688 | aViewCube->SetFixedAnimationLoop (false); | |
13689 | } | |
13690 | } | |
13691 | else if (anArg == "-reset") | |
13692 | { | |
13693 | aViewCube->ResetStyles(); | |
13694 | } | |
13695 | else if (anArg == "-color" | |
13696 | || anArg == "-boxcolor" | |
13697 | || anArg == "-boxsidecolor" | |
13698 | || anArg == "-sidecolor" | |
13699 | || anArg == "-boxedgecolor" | |
13700 | || anArg == "-edgecolor" | |
13701 | || anArg == "-boxcornercolor" | |
13702 | || anArg == "-cornercolor" | |
13703 | || anArg == "-innercolor" | |
13704 | || anArg == "-textcolor") | |
13705 | { | |
13706 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - anArgIter - 1, | |
13707 | theArgVec + anArgIter + 1, | |
13708 | aColorRgb); | |
13709 | if (aNbParsed == 0) | |
13710 | { | |
23fe70ec | 13711 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
2108d9a2 | 13712 | return 1; |
13713 | } | |
13714 | anArgIter += aNbParsed; | |
13715 | if (anArg == "-boxcolor") | |
13716 | { | |
13717 | aViewCube->SetBoxColor (aColorRgb); | |
13718 | } | |
13719 | else if (anArg == "-boxsidecolor" | |
13720 | || anArg == "-sidecolor") | |
13721 | { | |
13722 | aViewCube->BoxSideStyle()->SetColor (aColorRgb); | |
13723 | aViewCube->SynchronizeAspects(); | |
13724 | } | |
13725 | else if (anArg == "-boxedgecolor" | |
13726 | || anArg == "-edgecolor") | |
13727 | { | |
13728 | aViewCube->BoxEdgeStyle()->SetColor (aColorRgb); | |
13729 | aViewCube->SynchronizeAspects(); | |
13730 | } | |
13731 | else if (anArg == "-boxcornercolor" | |
13732 | || anArg == "-cornercolor") | |
13733 | { | |
13734 | aViewCube->BoxCornerStyle()->SetColor (aColorRgb); | |
13735 | aViewCube->SynchronizeAspects(); | |
13736 | } | |
13737 | else if (anArg == "-innercolor") | |
13738 | { | |
13739 | aViewCube->SetInnerColor (aColorRgb); | |
13740 | } | |
13741 | else if (anArg == "-textcolor") | |
13742 | { | |
13743 | aViewCube->SetTextColor (aColorRgb); | |
13744 | } | |
13745 | else | |
13746 | { | |
13747 | aViewCube->SetColor (aColorRgb); | |
13748 | } | |
13749 | } | |
13750 | else if (anArgIter + 1 < theNbArgs | |
13751 | && (anArg == "-transparency" | |
13752 | || anArg == "-boxtransparency")) | |
13753 | { | |
13754 | const Standard_Real aValue = Draw::Atof (theArgVec[++anArgIter]); | |
13755 | if (aValue < 0.0 || aValue > 1.0) | |
13756 | { | |
23fe70ec | 13757 | Message::SendFail() << "Syntax error: invalid transparency value " << theArgVec[anArgIter]; |
2108d9a2 | 13758 | return 1; |
13759 | } | |
13760 | ||
13761 | if (anArg == "-boxtransparency") | |
13762 | { | |
13763 | aViewCube->SetBoxTransparency (aValue); | |
13764 | } | |
13765 | else | |
13766 | { | |
13767 | aViewCube->SetTransparency (aValue); | |
13768 | } | |
13769 | } | |
13770 | else if (anArg == "-axes" | |
13771 | || anArg == "-edges" | |
13772 | || anArg == "-vertices" | |
13773 | || anArg == "-vertexes" | |
13774 | || anArg == "-fixedanimation") | |
13775 | { | |
13776 | bool toShow = true; | |
13777 | if (anArgIter + 1 < theNbArgs | |
13778 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShow)) | |
13779 | { | |
13780 | ++anArgIter; | |
13781 | } | |
13782 | if (anArg == "-fixedanimation") | |
13783 | { | |
13784 | aViewCube->SetFixedAnimationLoop (toShow); | |
13785 | } | |
13786 | else if (anArg == "-axes") | |
13787 | { | |
13788 | aViewCube->SetDrawAxes (toShow); | |
13789 | } | |
13790 | else if (anArg == "-edges") | |
13791 | { | |
13792 | aViewCube->SetDrawEdges (toShow); | |
13793 | } | |
13794 | else | |
13795 | { | |
13796 | aViewCube->SetDrawVertices (toShow); | |
13797 | } | |
13798 | } | |
13799 | else if (anArg == "-yup" | |
13800 | || anArg == "-zup") | |
13801 | { | |
13802 | bool isOn = true; | |
13803 | if (anArgIter + 1 < theNbArgs | |
13804 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isOn)) | |
13805 | { | |
13806 | ++anArgIter; | |
13807 | } | |
13808 | if (anArg == "-yup") | |
13809 | { | |
13810 | aViewCube->SetYup (isOn); | |
13811 | } | |
13812 | else | |
13813 | { | |
13814 | aViewCube->SetYup (!isOn); | |
13815 | } | |
13816 | } | |
13817 | else if (anArgIter + 1 < theNbArgs | |
13818 | && anArg == "-font") | |
13819 | { | |
13820 | aViewCube->SetFont (theArgVec[++anArgIter]); | |
13821 | } | |
13822 | else if (anArgIter + 1 < theNbArgs | |
13823 | && anArg == "-fontheight") | |
13824 | { | |
13825 | aViewCube->SetFontHeight (Draw::Atof (theArgVec[++anArgIter])); | |
13826 | } | |
13827 | else if (anArgIter + 1 < theNbArgs | |
13828 | && (anArg == "-size" | |
13829 | || anArg == "-boxsize")) | |
13830 | { | |
13831 | aViewCube->SetSize (Draw::Atof (theArgVec[++anArgIter]), | |
13832 | anArg != "-boxsize"); | |
13833 | } | |
13834 | else if (anArgIter + 1 < theNbArgs | |
13835 | && (anArg == "-boxfacet" | |
13836 | || anArg == "-boxfacetextension" | |
13837 | || anArg == "-facetextension" | |
13838 | || anArg == "-extension")) | |
13839 | { | |
13840 | aViewCube->SetBoxFacetExtension (Draw::Atof (theArgVec[++anArgIter])); | |
13841 | } | |
13842 | else if (anArgIter + 1 < theNbArgs | |
13843 | && (anArg == "-boxedgegap" | |
13844 | || anArg == "-edgegap")) | |
13845 | { | |
13846 | aViewCube->SetBoxEdgeGap (Draw::Atof (theArgVec[++anArgIter])); | |
13847 | } | |
13848 | else if (anArgIter + 1 < theNbArgs | |
13849 | && (anArg == "-boxedgeminsize" | |
13850 | || anArg == "-edgeminsize")) | |
13851 | { | |
13852 | aViewCube->SetBoxEdgeMinSize (Draw::Atof (theArgVec[++anArgIter])); | |
13853 | } | |
13854 | else if (anArgIter + 1 < theNbArgs | |
13855 | && (anArg == "-boxcornerminsize" | |
13856 | || anArg == "-cornerminsize")) | |
13857 | { | |
13858 | aViewCube->SetBoxCornerMinSize (Draw::Atof (theArgVec[++anArgIter])); | |
13859 | } | |
13860 | else if (anArgIter + 1 < theNbArgs | |
13861 | && anArg == "-axespadding") | |
13862 | { | |
13863 | aViewCube->SetAxesPadding (Draw::Atof (theArgVec[++anArgIter])); | |
13864 | } | |
13865 | else if (anArgIter + 1 < theNbArgs | |
13866 | && anArg == "-roundradius") | |
13867 | { | |
13868 | aViewCube->SetRoundRadius (Draw::Atof (theArgVec[++anArgIter])); | |
13869 | } | |
13870 | else if (anArgIter + 1 < theNbArgs | |
13871 | && anArg == "-duration") | |
13872 | { | |
13873 | aViewCube->SetDuration (Draw::Atof (theArgVec[++anArgIter])); | |
13874 | } | |
6466cc9e | 13875 | else if (anArgIter + 1 < theNbArgs |
13876 | && anArg == "-axesradius") | |
13877 | { | |
13878 | aViewCube->SetAxesRadius (Draw::Atof (theArgVec[++anArgIter])); | |
13879 | } | |
13880 | else if (anArgIter + 1 < theNbArgs | |
13881 | && anArg == "-axesconeradius") | |
13882 | { | |
13883 | aViewCube->SetAxesConeRadius (Draw::Atof (theArgVec[++anArgIter])); | |
13884 | } | |
13885 | else if (anArgIter + 1 < theNbArgs | |
13886 | && anArg == "-axessphereradius") | |
13887 | { | |
13888 | aViewCube->SetAxesSphereRadius (Draw::Atof (theArgVec[++anArgIter])); | |
13889 | } | |
2108d9a2 | 13890 | else |
13891 | { | |
23fe70ec | 13892 | Message::SendFail() << "Syntax error: unknown argument '" << anArg << "'"; |
2108d9a2 | 13893 | return 1; |
13894 | } | |
13895 | } | |
13896 | if (aViewCube.IsNull()) | |
13897 | { | |
23fe70ec | 13898 | Message::SendFail ("Syntax error: wrong number of arguments"); |
2108d9a2 | 13899 | return 1; |
13900 | } | |
13901 | ||
13902 | ViewerTest::Display (aName, aViewCube, false); | |
13903 | return 0; | |
13904 | } | |
13905 | ||
14b741b0 | 13906 | //=============================================================================================== |
13907 | //function : VColorConvert | |
13908 | //purpose : | |
13909 | //=============================================================================================== | |
13910 | static int VColorConvert (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec) | |
13911 | { | |
13912 | if (theNbArgs != 6) | |
13913 | { | |
13914 | std::cerr << "Error: command syntax is incorrect, see help" << std::endl; | |
13915 | return 1; | |
13916 | } | |
13917 | ||
13918 | Standard_Boolean convertFrom = (! strcasecmp (theArgVec[1], "from")); | |
13919 | if (! convertFrom && strcasecmp (theArgVec[1], "to")) | |
13920 | { | |
13921 | std::cerr << "Error: first argument must be either \"to\" or \"from\"" << std::endl; | |
13922 | return 1; | |
13923 | } | |
13924 | ||
13925 | const char* aTypeStr = theArgVec[2]; | |
13926 | Quantity_TypeOfColor aType = Quantity_TOC_RGB; | |
13927 | if (! strcasecmp (aTypeStr, "srgb")) | |
13928 | { | |
13929 | aType = Quantity_TOC_sRGB; | |
13930 | } | |
13931 | else if (! strcasecmp (aTypeStr, "hls")) | |
13932 | { | |
13933 | aType = Quantity_TOC_HLS; | |
13934 | } | |
13935 | else if (! strcasecmp (aTypeStr, "lab")) | |
13936 | { | |
13937 | aType = Quantity_TOC_CIELab; | |
13938 | } | |
13939 | else if (! strcasecmp (aTypeStr, "lch")) | |
13940 | { | |
13941 | aType = Quantity_TOC_CIELch; | |
13942 | } | |
13943 | else | |
13944 | { | |
13945 | std::cerr << "Error: unknown colorspace type: " << aTypeStr << std::endl; | |
13946 | return 1; | |
13947 | } | |
13948 | ||
13949 | double aC1 = Draw::Atof (theArgVec[3]); | |
13950 | double aC2 = Draw::Atof (theArgVec[4]); | |
13951 | double aC3 = Draw::Atof (theArgVec[5]); | |
13952 | ||
13953 | Quantity_Color aColor (aC1, aC2, aC3, convertFrom ? aType : Quantity_TOC_RGB); | |
13954 | aColor.Values (aC1, aC2, aC3, convertFrom ? Quantity_TOC_RGB : aType); | |
13955 | ||
13956 | // print values with 6 decimal digits | |
13957 | char buffer[1024]; | |
13958 | Sprintf (buffer, "%.6f %.6f %.6f", aC1, aC2, aC3); | |
13959 | theDI << buffer; | |
13960 | ||
13961 | return 0; | |
13962 | } | |
13963 | ||
13964 | //=============================================================================================== | |
13965 | //function : VColorDiff | |
13966 | //purpose : | |
13967 | //=============================================================================================== | |
13968 | static int VColorDiff (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec) | |
13969 | { | |
13970 | if (theNbArgs != 7) | |
13971 | { | |
13972 | std::cerr << "Error: command syntax is incorrect, see help" << std::endl; | |
13973 | return 1; | |
13974 | } | |
13975 | ||
13976 | double aR1 = Draw::Atof (theArgVec[1]); | |
13977 | double aG1 = Draw::Atof (theArgVec[2]); | |
13978 | double aB1 = Draw::Atof (theArgVec[3]); | |
13979 | double aR2 = Draw::Atof (theArgVec[4]); | |
13980 | double aG2 = Draw::Atof (theArgVec[5]); | |
13981 | double aB2 = Draw::Atof (theArgVec[6]); | |
13982 | ||
13983 | Quantity_Color aColor1 (aR1, aG1, aB1, Quantity_TOC_RGB); | |
13984 | Quantity_Color aColor2 (aR2, aG2, aB2, Quantity_TOC_RGB); | |
13985 | ||
13986 | theDI << aColor1.DeltaE2000 (aColor2); | |
13987 | ||
13988 | return 0; | |
13989 | } | |
13990 | ||
7fd59977 | 13991 | //======================================================================= |
13992 | //function : ViewerCommands | |
13993 | //purpose : | |
13994 | //======================================================================= | |
13995 | ||
13996 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) | |
13997 | { | |
13998 | ||
13999 | const char *group = "ZeViewer"; | |
18d715bd | 14000 | theCommands.Add("vinit", |
fd3f6bd0 | 14001 | "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]" |
2e93433e | 14002 | "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]" |
fd3f6bd0 | 14003 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
14004 | "\n\t\t: [-display displayName]" | |
14005 | #endif | |
14006 | "\n\t\t: Creates new View window with specified name viewName." | |
14007 | "\n\t\t: By default the new view is created in the viewer and in" | |
14008 | "\n\t\t: graphic driver shared with active view." | |
14009 | "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}" | |
14010 | "\n\t\t: If driverName isn't specified the driver will be shared with active view." | |
14011 | "\n\t\t: If viewerName isn't specified the viewer will be shared with active view." | |
14012 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
14013 | "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]" | |
14014 | "\n\t\t: Display name will be used within creation of graphic driver, when specified." | |
18d715bd | 14015 | #endif |
fd3f6bd0 | 14016 | "\n\t\t: -left, -top pixel position of left top corner of the window." |
14017 | "\n\t\t: -width, -height width and heigth of window respectively." | |
9e04ccdc | 14018 | "\n\t\t: -cloneActive floag to copy camera and dimensions of active view." |
fd3f6bd0 | 14019 | "\n\t\t: -exitOnClose when specified, closing the view will exit application." |
14020 | "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape." | |
2e93433e | 14021 | "\n\t\t: -2d_mode when on, view will not react on rotate scene events" |
fd3f6bd0 | 14022 | "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.", |
7fd59977 | 14023 | __FILE__,VInit,group); |
18d715bd | 14024 | theCommands.Add("vclose" , |
d0cc1cb7 | 14025 | "[view_id [keep_context=0|1]]\n" |
18d715bd | 14026 | "or vclose ALL - to remove all created views\n" |
14027 | " - removes view(viewer window) defined by its view_id.\n" | |
14028 | " - keep_context: by default 0; if 1 and the last view is deleted" | |
14029 | " the current context is not removed.", | |
14030 | __FILE__,VClose,group); | |
14031 | theCommands.Add("vactivate" , | |
e084dbbc | 14032 | "vactivate view_id [-noUpdate]" |
18d715bd | 14033 | " - activates view(viewer window) defined by its view_id", |
14034 | __FILE__,VActivate,group); | |
14035 | theCommands.Add("vviewlist", | |
14036 | "vviewlist [format={tree, long}]" | |
14037 | " - prints current list of views per viewer and graphic_driver ID shared between viewers" | |
14038 | " - format: format of result output, if tree the output is a tree view;" | |
14039 | "otherwise it's a list of full view names. By default format = tree", | |
14040 | __FILE__,VViewList,group); | |
7fd59977 | 14041 | theCommands.Add("vhelp" , |
14042 | "vhelp : display help on the viewer commands", | |
14043 | __FILE__,VHelp,group); | |
fc552d84 | 14044 | theCommands.Add("vviewproj", |
14045 | "vviewproj [top|bottom|left|right|front|back|axoLeft|axoRight]" | |
14046 | "\n\t\t: [+-X+-Y+-Z] [-Zup|-Yup] [-frame +-X+-Y]" | |
14047 | "\n\t\t: Setup view direction" | |
14048 | "\n\t\t: -Yup use Y-up convention instead of Zup (which is default)." | |
14049 | "\n\t\t: +-X+-Y+-Z define direction as combination of DX, DY and DZ;" | |
14050 | "\n\t\t: for example '+Z' will show front of the model," | |
14051 | "\n\t\t: '-X-Y+Z' will define left axonometrical view." | |
14052 | "\n\t\t: -frame define camera Up and Right directions (regardless Up convention);" | |
14053 | "\n\t\t: for example '+X+Z' will show front of the model with Z-up." | |
14054 | __FILE__,VViewProj,group); | |
7fd59977 | 14055 | theCommands.Add("vtop" , |
27af3052 | 14056 | "vtop or <T> : Top view. Orientation +X+Y" , |
fc552d84 | 14057 | __FILE__,VViewProj,group); |
44b8f2d6 | 14058 | theCommands.Add("vbottom" , |
27af3052 | 14059 | "vbottom : Bottom view. Orientation +X-Y" , |
fc552d84 | 14060 | __FILE__,VViewProj,group); |
44b8f2d6 | 14061 | theCommands.Add("vleft" , |
27af3052 | 14062 | "vleft : Left view. Orientation -Y+Z" , |
fc552d84 | 14063 | __FILE__,VViewProj,group); |
44b8f2d6 | 14064 | theCommands.Add("vright" , |
27af3052 | 14065 | "vright : Right view. Orientation +Y+Z" , |
fc552d84 | 14066 | __FILE__,VViewProj,group); |
7fd59977 | 14067 | theCommands.Add("vaxo" , |
27af3052 | 14068 | " vaxo or <A> : Axonometric view. Orientation +X-Y+Z", |
fc552d84 | 14069 | __FILE__,VViewProj,group); |
44b8f2d6 | 14070 | theCommands.Add("vfront" , |
27af3052 | 14071 | "vfront : Front view. Orientation +X+Z" , |
fc552d84 | 14072 | __FILE__,VViewProj,group); |
44b8f2d6 | 14073 | theCommands.Add("vback" , |
27af3052 | 14074 | "vback : Back view. Orientation -X+Z" , |
fc552d84 | 14075 | __FILE__,VViewProj,group); |
7fd59977 | 14076 | theCommands.Add("vpick" , |
14077 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", | |
14078 | VPick,group); | |
1beb58d7 | 14079 | theCommands.Add("vfit", |
14080 | "vfit or <F> [-selected] [-noupdate]" | |
b586500b | 14081 | "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects", |
7fd59977 | 14082 | __FILE__,VFit,group); |
6262a303 | 14083 | theCommands.Add ("vfitarea", |
14084 | "vfitarea x1 y1 x2 y2" | |
14085 | "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2" | |
14086 | "\n\t\t: Fit view to show area located between two points" | |
14087 | "\n\t\t: given in world 2D or 3D corrdinates.", | |
14088 | __FILE__, VFitArea, group); | |
197ac94e | 14089 | theCommands.Add ("vzfit", "vzfit [scale]\n" |
14090 | " Matches Z near, Z far view volume planes to the displayed objects.\n" | |
14091 | " \"scale\" - specifies factor to scale computed z range.\n", | |
14092 | __FILE__, VZFit, group); | |
7fd59977 | 14093 | theCommands.Add("vrepaint", |
8693dfd0 | 14094 | "vrepaint [-immediate] [-continuous FPS]" |
14095 | "\n\t\t: force redraw of active View" | |
14096 | "\n\t\t: -immediate flag performs redraw of immediate layers only;" | |
14097 | "\n\t\t: -continuous activates/deactivates continuous redraw of active View," | |
14098 | "\n\t\t: 0 means no continuous rendering," | |
14099 | "\n\t\t: -1 means non-stop redraws," | |
14100 | "\n\t\t: >0 specifies target framerate,", | |
7fd59977 | 14101 | __FILE__,VRepaint,group); |
14102 | theCommands.Add("vclear", | |
faea8b40 | 14103 | "vclear : vclear" |
14104 | "\n\t\t: remove all the object from the viewer", | |
7fd59977 | 14105 | __FILE__,VClear,group); |
293211ae | 14106 | theCommands.Add ( |
14107 | "vbackground", | |
14108 | "Changes background or some background settings.\n" | |
14109 | "\n" | |
14110 | "Usage:\n" | |
14111 | " vbackground -imageFile ImageFile [-imageMode FillType]\n" | |
14112 | " vbackground -imageMode FillType\n" | |
14113 | " vbackground -gradient Color1 Color2 [-gradientMode FillMethod]\n" | |
14114 | " vbackground -gradientMode FillMethod\n" | |
077a220c | 14115 | " vbackground -cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]\n" |
293211ae | 14116 | " vbackground -color Color\n" |
14117 | " vbackground -default -gradient Color1 Color2 [-gradientMode FillType]\n" | |
14118 | " vbackground -default -color Color\n" | |
14119 | " vbackground -help\n" | |
14120 | "\n" | |
14121 | "Options:\n" | |
14122 | " -imageFile (-imgFile, -image, -img): sets filename of image used as background\n" | |
14123 | " -imageMode (-imgMode, -imageMd, -imgMd): sets image fill type\n" | |
14124 | " -gradient (-grad, -gr): sets background gradient starting and ending colors\n" | |
14125 | " -gradientMode (-gradMode, -gradMd, -grMode, -grMd): sets gradient fill method\n" | |
077a220c | 14126 | " -cubemap (-cmap, -cm): sets environmet cubemap as background\n" |
14127 | " -invertedz (-invz, -iz): sets inversion of Z axis for background cubemap rendering\n" | |
14128 | " -order (-o): defines order of tiles in one image cubemap\n" | |
14129 | " (has no effect in case of multi image cubemaps)\n" | |
293211ae | 14130 | " -color (-col): sets background color\n" |
14131 | " -default (-def): sets background default gradient or color\n" | |
14132 | " -help (-h): outputs short help message\n" | |
14133 | "\n" | |
14134 | "Arguments:\n" | |
077a220c | 14135 | " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n" |
293211ae | 14136 | " or reals within the range [0.0, 1.0]\n" |
077a220c | 14137 | " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n" |
14138 | " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n" | |
14139 | " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, " | |
293211ae | 14140 | "CORNER4\n" |
077a220c | 14141 | " FillType: one of CENTERED, TILED, STRETCH, NONE\n" |
14142 | " ImageFile: a name of the file with the image used as a background\n" | |
14143 | " CubemapFilei: a name of the file with one image packed cubemap or names of separate files with every cubemap side\n" | |
14144 | " TileIndexi: a cubemap side index in range [0, 5] for i tile of one image packed cubemap\n", | |
293211ae | 14145 | __FILE__, |
14146 | vbackground, | |
14147 | group); | |
14148 | theCommands.Add ("vsetbg", | |
14149 | "Loads image as background." | |
14150 | "\n\t\t: vsetbg ImageFile [FillType]" | |
14151 | "\n\t\t: vsetbg -imageFile ImageFile [-imageMode FillType]" | |
14152 | "\n\t\t: Alias for 'vbackground -imageFile ImageFile [-imageMode FillType]'.", | |
14153 | __FILE__, | |
14154 | vbackground, | |
14155 | group); | |
14156 | theCommands.Add ("vsetbgmode", | |
14157 | "Changes background image fill type." | |
14158 | "\n\t\t: vsetbgmode [-imageMode] FillType" | |
14159 | "\n\t\t: Alias for 'vbackground -imageMode FillType'.", | |
14160 | __FILE__, | |
14161 | vbackground, | |
14162 | group); | |
14163 | theCommands.Add ("vsetgradientbg", | |
14164 | "Mounts gradient background." | |
14165 | "\n\t\t: vsetgradientbg Color1 Color2 [FillMethod]" | |
14166 | "\n\t\t: vsetgradientbg -gradient Color1 Color2 [-gradientMode FillMethod]" | |
14167 | "\n\t\t: Alias for 'vbackground -gradient Color1 Color2 -gradientMode FillMethod'.", | |
14168 | __FILE__, | |
14169 | vbackground, | |
14170 | group); | |
14171 | theCommands.Add ("vsetgrbgmode", | |
14172 | "Changes gradient background fill method." | |
14173 | "\n\t\t: vsetgrbgmode [-gradientMode] FillMethod" | |
14174 | "\n\t\t: Alias for 'vbackground -gradientMode FillMethod'.", | |
14175 | __FILE__, | |
14176 | vbackground, | |
14177 | group); | |
14178 | theCommands.Add ("vsetcolorbg", | |
14179 | "Sets background color." | |
14180 | "\n\t\t: vsetcolorbg [-color] Color." | |
14181 | "\n\t\t: Alias for 'vbackground -color Color'.", | |
14182 | __FILE__, | |
14183 | vbackground, | |
14184 | group); | |
14185 | theCommands.Add ("vsetdefaultbg", | |
14186 | "Sets default viewer background fill color (flat/gradient)." | |
14187 | "\n\t\t: vsetdefaultbg Color1 Color2 [FillMethod]" | |
14188 | "\n\t\t: vsetdefaultbg -gradient Color1 Color2 [-gradientMode FillMethod]" | |
14189 | "\n\t\t: Alias for 'vbackground -default -gradient Color1 Color2 [-gradientMode FillMethod]'." | |
14190 | "\n\t\t: vsetdefaultbg [-color] Color" | |
14191 | "\n\t\t: Alias for 'vbackground -default -color Color'.", | |
14192 | __FILE__, | |
14193 | vbackground, | |
14194 | group); | |
7fd59977 | 14195 | theCommands.Add("vscale", |
14196 | "vscale : vscale X Y Z", | |
14197 | __FILE__,VScale,group); | |
14198 | theCommands.Add("vzbufftrihedron", | |
536d98e2 | 14199 | "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]" |
14200 | "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]" | |
14201 | "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]" | |
14202 | "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]" | |
14203 | "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]" | |
14204 | "\n\t\t: Displays a trihedron", | |
14205 | __FILE__,VZBuffTrihedron,group); | |
7fd59977 | 14206 | theCommands.Add("vrotate", |
4af098ba | 14207 | "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]" |
14208 | "\n : Option -mouseStart starts rotation according to the mouse position" | |
14209 | "\n : Option -mouseMove continues rotation with angle computed" | |
14210 | "\n : from last and new mouse position." | |
14211 | "\n : vrotate AX AY AZ [X Y Z]", | |
7fd59977 | 14212 | __FILE__,VRotate,group); |
14213 | theCommands.Add("vzoom", | |
14214 | "vzoom : vzoom coef", | |
14215 | __FILE__,VZoom,group); | |
14216 | theCommands.Add("vpan", | |
14217 | "vpan : vpan dx dy", | |
14218 | __FILE__,VPan,group); | |
7fd59977 | 14219 | theCommands.Add("vcolorscale", |
4b3d6eb1 | 14220 | "vcolorscale name [-noupdate|-update] [-demo]" |
14221 | "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]" | |
14222 | "\n\t\t: [-font HeightFont=20]" | |
14223 | "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]" | |
14224 | "\n\t\t: [-smoothTransition {on|off}=off]" | |
14225 | "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]" | |
14226 | "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]" | |
14227 | "\n\t\t: [-textpos {left|right|center|none}=right]" | |
14228 | "\n\t\t: [-labelAtBorder {on|off}=on]" | |
14229 | "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]" | |
14230 | "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]" | |
14231 | "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]" | |
14232 | "\n\t\t: [-xy Left=0 Bottom=0]" | |
14b741b0 | 14233 | "\n\t\t: [-uniform lightness hue_from hue_to]" |
4b3d6eb1 | 14234 | "\n\t\t: -demo - displays a color scale with demonstratio values" |
14235 | "\n\t\t: -colors - set colors for all intervals" | |
14236 | "\n\t\t: -color - set color for specific interval" | |
14b741b0 | 14237 | "\n\t\t: -uniform - generate colors with the same lightness" |
4b3d6eb1 | 14238 | "\n\t\t: -textpos - horizontal label position relative to color scale bar" |
14239 | "\n\t\t: -labelAtBorder - vertical label position relative to color interval;" | |
14240 | "\n\t\t: at border means the value inbetween neighbor intervals," | |
14241 | "\n\t\t: at center means the center value within current interval" | |
14242 | "\n\t\t: -labels - set labels for all intervals" | |
14243 | "\n\t\t: -freeLabels - same as -labels but does not require" | |
14244 | "\n\t\t: matching the number of intervals" | |
14245 | "\n\t\t: -label - set label for specific interval" | |
14246 | "\n\t\t: -title - set title" | |
14247 | "\n\t\t: -reversed - setup smooth color transition between intervals" | |
14248 | "\n\t\t: -smoothTransition - swap colorscale direction" | |
14b741b0 | 14249 | "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values", |
4b3d6eb1 | 14250 | __FILE__, VColorScale, group); |
7fd59977 | 14251 | theCommands.Add("vgraduatedtrihedron", |
a79f67f8 | 14252 | "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n" |
14253 | "\t[-namefont Name] [-valuesfont Name]\n" | |
14254 | "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n" | |
14255 | "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]" | |
14256 | "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n" | |
14257 | "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n" | |
14258 | "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]" | |
14259 | "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n" | |
14260 | "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n" | |
14261 | "\t[-xticks Number] [-yticks Number] [-zticks Number]\n" | |
14262 | "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n" | |
536d98e2 | 14263 | "\t[-drawgrid on/off] [-drawaxes on/off]\n" |
a79f67f8 | 14264 | " - Displays or erases graduated trihedron" |
14265 | " - xname, yname, zname - names of axes, default: X, Y, Z\n" | |
14266 | " - namefont - font of axes names. Default: Arial\n" | |
14267 | " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n" | |
14268 | " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n" | |
14269 | " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n" | |
14270 | " - valuesfont - font of axes values. Default: Arial\n" | |
14271 | " - xcolor, ycolor, zcolor - color of axis and values\n" | |
14272 | " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n" | |
14273 | " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n", | |
7fd59977 | 14274 | __FILE__,VGraduatedTrihedron,group); |
3bffef55 | 14275 | theCommands.Add("vtile" , |
14276 | "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]" | |
14277 | "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)." | |
14278 | "\n\t\t: -totalSize the size of virtual bigger viewport" | |
14279 | "\n\t\t: -tileSize tile size (the view size will be used if omitted)" | |
14280 | "\n\t\t: -lowerLeft tile offset as lower left corner" | |
14281 | "\n\t\t: -upperLeft tile offset as upper left corner", | |
14282 | __FILE__, VTile, group); | |
59f45b7c | 14283 | theCommands.Add("vzlayer", |
7c3ef2f7 | 14284 | "vzlayer [layerId]" |
1c728f2d | 14285 | "\n\t\t: [-add|-delete|-get|-settings] [-insertBefore AnotherLayer] [-insertAfter AnotherLayer]" |
4ecf34cc | 14286 | "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]" |
7c3ef2f7 | 14287 | "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]" |
1c728f2d | 14288 | "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv|rayTracing}]" |
7c3ef2f7 | 14289 | "\n\t\t: ZLayer list management:" |
14290 | "\n\t\t: -add add new z layer to viewer and print its id" | |
1c728f2d | 14291 | "\n\t\t: -insertBefore add new z layer and insert it before existing one" |
14292 | "\n\t\t: -insertAfter add new z layer and insert it after existing one" | |
7c3ef2f7 | 14293 | "\n\t\t: -delete delete z layer" |
14294 | "\n\t\t: -get print sequence of z layers" | |
14295 | "\n\t\t: -settings print status of z layer settings" | |
14296 | "\n\t\t: -disable disables given setting" | |
14297 | "\n\t\t: -enable enables given setting", | |
59f45b7c | 14298 | __FILE__,VZLayer,group); |
20637bd2 | 14299 | theCommands.Add("vlayerline", |
14300 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", | |
14301 | __FILE__,VLayerLine,group); | |
79931835 | 14302 | theCommands.Add("vgrid", |
14303 | "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]" | |
14304 | "\n\t\t: [-step X Y] [-size DX DY]" | |
14305 | "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]", | |
2bd4c032 | 14306 | __FILE__, VGrid, group); |
c40b7d58 | 14307 | theCommands.Add ("vpriviledgedplane", |
14308 | "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]" | |
14309 | "\n\t\t: Ox, Oy, Oz - plane origin" | |
14310 | "\n\t\t: Nx, Ny, Nz - plane normal direction" | |
14311 | "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction" | |
14312 | "\n\t\t: Sets or prints viewer's priviledged plane geometry.", | |
14313 | __FILE__, VPriviledgedPlane, group); | |
f25b82d6 | 14314 | theCommands.Add ("vconvert", |
14315 | "vconvert v [Mode={window|view}]" | |
14316 | "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]" | |
14317 | "\n\t\t: vconvert x y z [Mode={window|grid}]" | |
14318 | "\n\t\t: window - convert to window coordinates, pixels" | |
14319 | "\n\t\t: view - convert to view projection plane" | |
14320 | "\n\t\t: grid - convert to model coordinates, given on grid" | |
14321 | "\n\t\t: ray - convert projection ray to model coordiantes" | |
14322 | "\n\t\t: - vconvert v window : convert view to window;" | |
14323 | "\n\t\t: - vconvert v view : convert window to view;" | |
14324 | "\n\t\t: - vconvert x y window : convert view to window;" | |
14325 | "\n\t\t: - vconvert x y view : convert window to view;" | |
14326 | "\n\t\t: - vconvert x y : convert window to model;" | |
14327 | "\n\t\t: - vconvert x y grid : convert window to model using grid;" | |
14328 | "\n\t\t: - vconvert x y ray : convert window projection line to model;" | |
14329 | "\n\t\t: - vconvert x y z window : convert model to window;" | |
14330 | "\n\t\t: - vconvert x y z grid : convert view to model using grid;" | |
14331 | "\n\t\t: Converts the given coordinates to window/view/model space.", | |
14332 | __FILE__, VConvert, group); | |
208e6839 | 14333 | theCommands.Add ("vfps", |
e084dbbc | 14334 | "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view", |
208e6839 | 14335 | __FILE__, VFps, group); |
58655684 | 14336 | theCommands.Add ("vgldebug", |
c87535af | 14337 | "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]" |
84e84755 | 14338 | "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]" |
c87535af | 14339 | "\n\t\t: Request debug GL context. Should be called BEFORE vinit." |
14340 | "\n\t\t: Debug context can be requested only on Windows" | |
14341 | "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!" | |
14342 | "\n\t\t: -sync - request synchronized debug GL context" | |
14343 | "\n\t\t: -glslWarn - log GLSL compiler/linker warnings," | |
14344 | "\n\t\t: which are suppressed by default," | |
84e84755 | 14345 | "\n\t\t: -glslCode - log GLSL program source code," |
14346 | "\n\t\t: which are suppressed by default," | |
c87535af | 14347 | "\n\t\t: -extraMsg - log extra diagnostic messages from GL context," |
14348 | "\n\t\t: which are suppressed by default", | |
58655684 | 14349 | __FILE__, VGlDebug, group); |
208e6839 | 14350 | theCommands.Add ("vvbo", |
58655684 | 14351 | "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects", |
208e6839 | 14352 | __FILE__, VVbo, group); |
b5ac8292 | 14353 | theCommands.Add ("vstereo", |
f978241f | 14354 | "vstereo [0|1] [-mode Mode] [-reverse {0|1}]" |
b40cdc2b | 14355 | "\n\t\t: [-mirrorComposer] [-hmdfov2d AngleDegrees] [-unitFactor MetersFactor]" |
f978241f | 14356 | "\n\t\t: [-anaglyph Filter]" |
b40cdc2b | 14357 | "\n\t\t: Control stereo output mode." |
14358 | "\n\t\t: When -mirrorComposer is specified, VR rendered frame will be mirrored in window (debug)." | |
14359 | "\n\t\t: Parameter -unitFactor specifies meters scale factor for mapping VR input." | |
14360 | "\n\t\t: Available modes for -mode:" | |
f978241f | 14361 | "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo," |
14362 | "\n\t\t: requires driver support." | |
14363 | "\n\t\t: Should be called BEFORE vinit!" | |
14364 | "\n\t\t: anaglyph - Anaglyph glasses" | |
14365 | "\n\t\t: rowInterlaced - row-interlaced display" | |
14366 | "\n\t\t: columnInterlaced - column-interlaced display" | |
14367 | "\n\t\t: chessBoard - chess-board output" | |
14368 | "\n\t\t: sideBySide - horizontal pair" | |
14369 | "\n\t\t: overUnder - vertical pair" | |
b40cdc2b | 14370 | "\n\t\t: openVR - OpenVR (HMD)" |
f978241f | 14371 | "\n\t\t: Available Anaglyph filters for -anaglyph:" |
14372 | "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple," | |
14373 | "\n\t\t: greenMagentaSimple", | |
b5ac8292 | 14374 | __FILE__, VStereo, group); |
a577aaab | 14375 | theCommands.Add ("vcaps", |
ba00aab7 | 14376 | "vcaps [-sRGB {0|1}] [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]" |
1dfe71a6 | 14377 | "\n\t\t: [-compatibleProfile {0|1}]" |
56689b27 | 14378 | "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]" |
f978241f | 14379 | "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]" |
8625ef7e | 14380 | "\n\t\t: [-softMode {0|1}] [-noupdate|-update]" |
59515ca6 | 14381 | "\n\t\t: [-noExtensions {0|1}] [-maxVersion Major Minor]" |
8625ef7e | 14382 | "\n\t\t: Modify particular graphic driver options:" |
ba00aab7 | 14383 | "\n\t\t: sRGB - enable/disable sRGB rendering" |
8625ef7e | 14384 | "\n\t\t: FFP - use fixed-function pipeline instead of" |
14385 | "\n\t\t: built-in GLSL programs" | |
4e1523ef | 14386 | "\n\t\t: (requires compatible profile)" |
2a332745 | 14387 | "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs" |
8625ef7e | 14388 | "\n\t\t: VBO - use Vertex Buffer Object (copy vertex" |
14389 | "\n\t\t: arrays to GPU memory)" | |
14390 | "\n\t\t: sprite - use textured sprites instead of bitmaps" | |
f978241f | 14391 | "\n\t\t: vsync - switch VSync on or off" |
56689b27 | 14392 | "\n\t\t: winBuffer - allow using window buffer for rendering" |
4e1523ef | 14393 | "\n\t\t: Context creation options:" |
14394 | "\n\t\t: softMode - software OpenGL implementation" | |
14395 | "\n\t\t: compatibleProfile - backward-compatible profile" | |
f978241f | 14396 | "\n\t\t: quadbuffer - QuadBuffer" |
59515ca6 | 14397 | "\n\t\t: noExtensions - disallow usage of extensions" |
14398 | "\n\t\t: maxVersion - force upper OpenGL version to be used" | |
8625ef7e | 14399 | "\n\t\t: Unlike vrenderparams, these parameters control alternative" |
14400 | "\n\t\t: rendering paths producing the same visual result when" | |
14401 | "\n\t\t: possible." | |
14402 | "\n\t\t: Command is intended for testing old hardware compatibility.", | |
a577aaab | 14403 | __FILE__, VCaps, group); |
f0430952 | 14404 | theCommands.Add ("vmemgpu", |
14405 | "vmemgpu [f]: print system-dependent GPU memory information if available;" | |
14406 | " with f option returns free memory in bytes", | |
14407 | __FILE__, VMemGpu, group); | |
85e096c3 | 14408 | theCommands.Add ("vreadpixel", |
ba00aab7 | 14409 | "vreadpixel xPixel yPixel [{rgb|rgba|sRGB|sRGBa|depth|hls|rgbf|rgbaf}=rgba] [-name|-hex]" |
85e096c3 | 14410 | " : Read pixel value for active view", |
14411 | __FILE__, VReadPixel, group); | |
692613e5 | 14412 | theCommands.Add("diffimage", |
fd3f6bd0 | 14413 | "diffimage imageFile1 imageFile2 [diffImageFile]" |
14414 | "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]" | |
14415 | "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]" | |
14416 | "\n\t\t: Compare two images by content and generate difference image." | |
14417 | "\n\t\t: When -exitOnClose is specified, closing the view will exit application." | |
14418 | "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.", | |
692613e5 | 14419 | __FILE__, VDiffImage, group); |
4754e164 | 14420 | theCommands.Add ("vselect", |
2157d6ac | 14421 | "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n" |
4754e164 | 14422 | "- emulates different types of selection:\n" |
14423 | "- 1) single click selection\n" | |
14424 | "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" | |
14425 | "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" | |
a24a7821 | 14426 | "- 4) -allowoverlap manages overlap and inclusion detection in rectangular and polygonal selection.\n" |
14427 | " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined \n" | |
14428 | " rectangle or polygon will be detected, otherwise algorithm will chose only fully included sensitives.\n" | |
14429 | " Default behavior is to detect only full inclusion. (partial inclusion - overlap - is not allowed by default)\n" | |
2157d6ac | 14430 | "- 5) any of these selections with shift button pressed", |
4754e164 | 14431 | __FILE__, VSelect, group); |
14432 | theCommands.Add ("vmoveto", | |
8a590580 | 14433 | "vmoveto [x y] [-reset]" |
14434 | "\n\t\t: Emulates cursor movement to pixel position (x,y)." | |
14435 | "\n\t\t: -reset resets current highlighting", | |
4754e164 | 14436 | __FILE__, VMoveTo, group); |
1beb58d7 | 14437 | theCommands.Add ("vviewparams", |
14438 | "vviewparams [-args] [-scale [s]]" | |
14439 | "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]" | |
14440 | "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]" | |
14441 | "\n\t\t: Manage current view parameters or prints all" | |
14442 | "\n\t\t: current values when called without argument." | |
14443 | "\n\t\t: -scale [s] prints or sets viewport relative scale" | |
14444 | "\n\t\t: -eye [x y z] prints or sets eye location" | |
14445 | "\n\t\t: -at [x y z] prints or sets center of look" | |
14446 | "\n\t\t: -up [x y z] prints or sets direction of up vector" | |
14447 | "\n\t\t: -proj [x y z] prints or sets direction of look" | |
14448 | "\n\t\t: -center x y sets location of center of the screen in pixels" | |
14449 | "\n\t\t: -size [sx] prints viewport projection width and height sizes" | |
14450 | "\n\t\t: or changes the size of its maximum dimension" | |
14451 | "\n\t\t: -args prints vviewparams arguments for restoring current view", | |
197ac94e | 14452 | __FILE__, VViewParams, group); |
1beb58d7 | 14453 | |
2e93433e | 14454 | theCommands.Add("v2dmode", |
14455 | "v2dmode [-name viewName] [-mode {-on|-off}=-on]" | |
14456 | "\n\t\t: name - name of existing view, if not defined, the active view is changed" | |
14457 | "\n\t\t: mode - switches On/Off rotation mode" | |
14458 | "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:" | |
14459 | "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active" | |
14460 | "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right" | |
14461 | "\n\t\t: View camera position might be changed only by commands.", | |
14462 | __FILE__, V2DMode, group); | |
14463 | ||
1beb58d7 | 14464 | theCommands.Add("vanimation", "Alias for vanim", |
14465 | __FILE__, VAnimation, group); | |
14466 | ||
14467 | theCommands.Add("vanim", | |
14468 | "List existing animations:" | |
14469 | "\n\t\t: vanim" | |
14470 | "\n\t\t: Animation playback:" | |
14471 | "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]" | |
14472 | "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]" | |
14473 | "\n\t\t: -speed playback speed (1.0 is normal speed)" | |
14474 | "\n\t\t: -freeLook skip camera animations" | |
14475 | "\n\t\t: -lockLoop disable any interactions" | |
14476 | "\n\t\t:" | |
14477 | "\n\t\t: Animation definition:" | |
14478 | "\n\t\t: vanim Name/sub/name [-clear] [-delete]" | |
14479 | "\n\t\t: [start TimeSec] [duration TimeSec]" | |
14480 | "\n\t\t:" | |
14481 | "\n\t\t: Animation name defined in path-style (anim/name or anim.name)" | |
14482 | "\n\t\t: specifies nested animations." | |
14483 | "\n\t\t: There is no syntax to explicitly add new animation," | |
14484 | "\n\t\t: and all non-existing animations within the name will be" | |
14485 | "\n\t\t: implicitly created on first use (including parents)." | |
14486 | "\n\t\t:" | |
14487 | "\n\t\t: Each animation might define the SINGLE action (see below)," | |
14488 | "\n\t\t: like camera transition, object transformation or custom callback." | |
14489 | "\n\t\t: Child animations can be used for defining concurrent actions." | |
14490 | "\n\t\t:" | |
14491 | "\n\t\t: Camera animation:" | |
14492 | "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]" | |
14493 | "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]" | |
14494 | "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]" | |
14495 | "\n\t\t: [-scale1 Scale] [-scale2 Scale]" | |
14496 | "\n\t\t: -eyeX camera Eye positions pair (start and end)" | |
14497 | "\n\t\t: -atX camera Center positions pair" | |
14498 | "\n\t\t: -upX camera Up directions pair" | |
14499 | "\n\t\t: -scaleX camera Scale factors pair" | |
14500 | "\n\t\t: Object animation:" | |
14501 | "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]" | |
14502 | "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]" | |
14503 | "\n\t\t: [-scale1 Scale] [-scale2 Scale]" | |
14504 | "\n\t\t: -locX object Location points pair (translation)" | |
14505 | "\n\t\t: -rotX object Orientations pair (quaternions)" | |
14506 | "\n\t\t: -scaleX object Scale factors pair (quaternions)" | |
14507 | "\n\t\t: Custom callback:" | |
14508 | "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\"" | |
14509 | "\n\t\t: %Pts overall animation presentation timestamp" | |
14510 | "\n\t\t: %LocalPts local animation timestamp" | |
14511 | "\n\t\t: %Normalized local animation normalized value in range 0..1" | |
08f8a185 | 14512 | "\n\t\t:" |
14513 | "\n\t\t: Video recording:" | |
14514 | "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]" | |
14515 | "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]" | |
14516 | "\n\t\t: [-crf Value] [-preset Preset]" | |
14517 | "\n\t\t: -fps video framerate" | |
14518 | "\n\t\t: -format file format, container (matroska, etc.)" | |
14519 | "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)" | |
14520 | "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)" | |
14521 | "\n\t\t: -crf constant rate factor (specific to codec)" | |
14522 | "\n\t\t: -preset codec parameters preset (specific to codec)" | |
1beb58d7 | 14523 | __FILE__, VAnimation, group); |
14524 | ||
4754e164 | 14525 | theCommands.Add("vchangeselected", |
dc3fe572 | 14526 | "vchangeselected shape" |
4754e164 | 14527 | "- adds to shape to selection or remove one from it", |
14528 | __FILE__, VChangeSelected, group); | |
4754e164 | 14529 | theCommands.Add ("vnbselected", |
faea8b40 | 14530 | "vnbselected" |
14531 | "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group); | |
6b62b2da | 14532 | theCommands.Add ("vcamera", |
30a1b24e | 14533 | "vcamera [PrsName] [-ortho] [-projtype]" |
6b62b2da | 14534 | "\n\t\t: [-persp]" |
14535 | "\n\t\t: [-fovy [Angle]] [-distance [Distance]]" | |
14536 | "\n\t\t: [-stereo] [-leftEye] [-rightEye]" | |
14537 | "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]" | |
14538 | "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]" | |
b40cdc2b | 14539 | "\n\t\t: [-fov2d [Angle]] [-lockZup {0|1}]" |
14540 | "\n\t\t: [-xrPose base|head=base]" | |
30a1b24e | 14541 | "\n\t\t: Manages camera parameters." |
14542 | "\n\t\t: Displays frustum when presntation name PrsName is specified." | |
6b62b2da | 14543 | "\n\t\t: Prints current value when option called without argument." |
14544 | "\n\t\t: Orthographic camera:" | |
14545 | "\n\t\t: -ortho activate orthographic projection" | |
14546 | "\n\t\t: Perspective camera:" | |
14547 | "\n\t\t: -persp activate perspective projection (mono)" | |
14548 | "\n\t\t: -fovy field of view in y axis, in degrees" | |
b40cdc2b | 14549 | "\n\t\t: -fov2d field of view limit for 2d on-screen elements" |
6b62b2da | 14550 | "\n\t\t: -distance distance of eye from camera center" |
b40cdc2b | 14551 | "\n\t\t: -lockZup lock Z up (tunrtable mode)" |
6b62b2da | 14552 | "\n\t\t: Stereoscopic camera:" |
14553 | "\n\t\t: -stereo perspective projection (stereo)" | |
14554 | "\n\t\t: -leftEye perspective projection (left eye)" | |
14555 | "\n\t\t: -rightEye perspective projection (right eye)" | |
14556 | "\n\t\t: -iod intraocular distance value" | |
14557 | "\n\t\t: -iodType distance type, absolute or relative" | |
14558 | "\n\t\t: -zfocus stereographic focus value" | |
14559 | "\n\t\t: -zfocusType focus type, absolute or relative", | |
14560 | __FILE__, VCamera, group); | |
b5ac8292 | 14561 | theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n" |
197ac94e | 14562 | "- vautozfit [on={1|0}] [scale]\n" |
14563 | " Prints or changes parameters of automatic z-fit mode:\n" | |
14564 | " \"on\" - turns automatic z-fit on or off\n" | |
14565 | " \"scale\" - specifies factor to scale computed z range.\n", | |
14566 | __FILE__, VAutoZFit, group); | |
b5ac8292 | 14567 | theCommands.Add ("vzrange", "command to manually access znear and zfar values\n" |
14568 | " vzrange - without parameters shows current values\n" | |
14569 | " vzrange [znear] [zfar] - applies provided values to view", | |
14570 | __FILE__,VZRange, group); | |
4754e164 | 14571 | theCommands.Add ("vpurgedisplay", |
eb4320f2 | 14572 | "vpurgedisplay" |
4754e164 | 14573 | "- removes structures which don't belong to objects displayed in neutral point", |
14574 | __FILE__, VPurgeDisplay, group); | |
14575 | theCommands.Add("vsetviewsize", | |
14576 | "vsetviewsize size", | |
14577 | __FILE__,VSetViewSize,group); | |
14578 | theCommands.Add("vmoveview", | |
14579 | "vmoveview Dx Dy Dz [Start = 1|0]", | |
14580 | __FILE__,VMoveView,group); | |
14581 | theCommands.Add("vtranslateview", | |
14582 | "vtranslateview Dx Dy Dz [Start = 1|0)]", | |
14583 | __FILE__,VTranslateView,group); | |
14584 | theCommands.Add("vturnview", | |
14585 | "vturnview Ax Ay Az [Start = 1|0]", | |
14586 | __FILE__,VTurnView,group); | |
269294d6 | 14587 | theCommands.Add("vtextureenv", |
14588 | "Enables or disables environment mapping in the 3D view, loading the texture from the given standard " | |
14589 | "or user-defined file and optionally applying texture mapping parameters\n" | |
14590 | " Usage:\n" | |
14591 | " vtextureenv off - disables environment mapping\n" | |
14592 | " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n" | |
14593 | " std_texture = (0..7)\n" | |
14594 | " rep = {clamp|repeat}\n" | |
14595 | " mod = {decal|modulate}\n" | |
14596 | " flt = {nearest|bilinear|trilinear}\n" | |
14597 | " ss, st - scale factors for s and t texture coordinates\n" | |
14598 | " ts, tt - translation for s and t texture coordinates\n" | |
14599 | " rot - texture rotation angle in degrees", | |
14600 | __FILE__, VTextureEnv, group); | |
1eeef710 | 14601 | theCommands.Add("vhlr", |
14602 | "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]" | |
14603 | "\n\t\t: Hidden Line Removal algorithm." | |
14604 | "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones" | |
14605 | "\n\t\t: -algoType type of HLR algorithm.\n", | |
0a768f56 | 14606 | __FILE__,VHLR,group); |
1eeef710 | 14607 | theCommands.Add("vhlrtype", |
14608 | "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]" | |
14609 | "\n\t\t: Changes the type of HLR algorithm using for shapes:" | |
14610 | "\n\t\t: 'algo' - exact HLR algorithm is applied" | |
14611 | "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied" | |
14612 | "\n\t\t: If shapes are not given - option is applied to all shapes in the view", | |
0a768f56 | 14613 | __FILE__,VHLRType,group); |
3e05329c | 14614 | theCommands.Add("vclipplane", |
14615 | "vclipplane planeName [{0|1}]" | |
25c35042 | 14616 | "\n\t\t: [-equation1 A B C D]" |
14617 | "\n\t\t: [-equation2 A B C D]" | |
14618 | "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]" | |
32ca7711 | 14619 | "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]" |
3e05329c | 14620 | "\n\t\t: [-maxPlanes]" |
14621 | "\n\t\t: [-capping {0|1}]" | |
1b661a81 | 14622 | "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]" |
3e05329c | 14623 | "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]" |
14624 | "\n\t\t: [-texRotate Angle]" | |
14625 | "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]" | |
14626 | "\n\t\t: [-useObjShader {0|1}]" | |
14627 | "\n\t\t: Clipping planes management:" | |
14628 | "\n\t\t: -maxPlanes print plane limit for view" | |
14629 | "\n\t\t: -delete delete plane with given name" | |
14630 | "\n\t\t: {off|on|0|1} turn clipping on/off" | |
14631 | "\n\t\t: -set|-unset set/unset plane for Object or View list;" | |
14632 | "\n\t\t: applied to active View when list is omitted" | |
14633 | "\n\t\t: -equation A B C D change plane equation" | |
14634 | "\n\t\t: -clone SourcePlane NewPlane clone the plane definition." | |
14635 | "\n\t\t: Capping options:" | |
14636 | "\n\t\t: -capping {off|on|0|1} turn capping on/off" | |
14637 | "\n\t\t: -color R G B set capping color" | |
1b661a81 | 14638 | "\n\t\t: -transparency Value set capping transparency 0..1" |
3e05329c | 14639 | "\n\t\t: -texName Texture set capping texture" |
14640 | "\n\t\t: -texScale SX SY set capping tex scale" | |
14641 | "\n\t\t: -texOrigin TX TY set capping tex origin" | |
14642 | "\n\t\t: -texRotate Angle set capping tex rotation" | |
14643 | "\n\t\t: -hatch {on|off|ID} set capping hatching mask" | |
14644 | "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object" | |
14645 | "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object" | |
14646 | "\n\t\t: -useObjShader {off|on|0|1} use shader program of object", | |
14647 | __FILE__, VClipPlane, group); | |
392ac980 | 14648 | theCommands.Add("vdefaults", |
4c513386 | 14649 | "vdefaults [-absDefl value]" |
14650 | "\n\t\t: [-devCoeff value]" | |
14651 | "\n\t\t: [-angDefl value]" | |
14652 | "\n\t\t: [-autoTriang {off/on | 0/1}]" | |
14653 | , __FILE__, VDefaults, group); | |
12381341 | 14654 | theCommands.Add("vlight", |
816d03ee | 14655 | "tool to manage light sources, without arguments shows list of lights." |
14656 | "\n Main commands: " | |
992ed6b3 | 14657 | "\n '-clear' to clear lights" |
14658 | "\n '-{def}aults' to load deafault lights" | |
14659 | "\n '-add' <type> to add any light source" | |
816d03ee | 14660 | "\n where <type> is one of {amb}ient|directional|{spot}light|positional" |
14661 | "\n 'change' <lightId> to edit light source with specified lightId" | |
14662 | "\n\n In addition to 'add' and 'change' commands you can use light parameters:" | |
992ed6b3 | 14663 | "\n -layer Id" |
14664 | "\n -{pos}ition X Y Z" | |
14665 | "\n -{dir}ection X Y Z (for directional light or for spotlight)" | |
14666 | "\n -color colorName" | |
14667 | "\n -{head}light 0|1" | |
14668 | "\n -{sm}oothness value" | |
14669 | "\n -{int}ensity value" | |
14670 | "\n -{constAtten}uation value" | |
14671 | "\n -{linearAtten}uation value" | |
14672 | "\n -angle angleDeg" | |
14673 | "\n -{spotexp}onent value" | |
88b312d3 | 14674 | "\n -range value" |
992ed6b3 | 14675 | "\n -local|-global" |
14676 | "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red" | |
14677 | "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2", | |
12381341 | 14678 | __FILE__, VLight, group); |
67312b79 | 14679 | theCommands.Add("vpbrenv", |
14680 | "vpbrenv -clear|-generate" | |
14681 | "\n\t\t: Clears or generates PBR environment map of active view." | |
14682 | "\n\t\t: -clear clears PBR environment (fills by white color)" | |
14683 | "\n\t\t: -generate generates PBR environment from current background cubemap", | |
14684 | __FILE__, VPBREnvironment, group); | |
6b62b2da | 14685 | theCommands.Add("vraytrace", |
14686 | "vraytrace [0|1]" | |
189f85a3 | 14687 | "\n\t\t: Turns on/off ray-tracing renderer." |
6b62b2da | 14688 | "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'." |
14689 | "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.", | |
14690 | __FILE__, VRenderParams, group); | |
bc8c79bb | 14691 | theCommands.Add("vrenderparams", |
14692 | "\n Manages rendering parameters: " | |
a1073ae2 | 14693 | "\n '-raster' Disables GPU ray-tracing" |
14694 | "\n '-msaa 0..4' Specifies number of samples for MSAA" | |
2a332745 | 14695 | "\n '-lineFeather > 0' Sets line feather factor" |
a1073ae2 | 14696 | "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor" |
f88457e6 | 14697 | "\n '-depthPrePass on|off' Enables/disables depth pre-pass" |
c40eb6b9 | 14698 | "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)" |
a1073ae2 | 14699 | "\n '-rendScale value Rendering resolution scale factor" |
14700 | "\n '-rayTrace' Enables GPU ray-tracing" | |
14701 | "\n '-rayDepth 0..10' Defines maximum ray-tracing depth" | |
14702 | "\n '-shadows on|off' Enables/disables shadows rendering" | |
14703 | "\n '-reflections on|off' Enables/disables specular reflections" | |
14704 | "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing" | |
14705 | "\n '-gleam on|off' Enables/disables transparency shadow effects" | |
14706 | "\n '-gi on|off' Enables/disables global illumination effects" | |
14707 | "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)" | |
14708 | "\n '-env on|off' Enables/disables environment map background" | |
78607702 | 14709 | "\n '-ignoreNormalMap on|off' Enables/disables normal map ignoring during path tracing" |
a1073ae2 | 14710 | "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)" |
14711 | "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)" | |
14712 | "\n '-issd on|off' Shows screen sampling distribution in ISS mode" | |
14713 | "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)" | |
66d1cdc6 | 14714 | "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)" |
14715 | "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)" | |
a1073ae2 | 14716 | "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)" |
14717 | "\n '-shadingModel model' Controls shading model from enumeration" | |
59ee34ef | 14718 | "\n unlit, flat, gouraud, phong" |
67312b79 | 14719 | "\n '-pbrEnvPow2size > 0' Controls size of IBL maps (real size can be calculates as 2^pbrenvpow2size)" |
14720 | "\n '-pbrEnvSMLN > 1' Controls number of mipmap levels used in specular IBL map" | |
14721 | "\n '-pbrEnvBDSN > 0' Controls number of samples in Monte-Carlo integration during diffuse IBL map's sherical harmonics calculation" | |
14722 | "\n '-pbrEnvBSSN > 0' Controls maximum number of samples per mipmap level in Monte-Carlo integration during specular IBL maps generation" | |
14723 | "\n '-pbrEnvBP [0, 1]' Controls strength of samples number reducing during specular IBL maps generation (1 disables reducing)" | |
a1073ae2 | 14724 | "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size" |
b27ab03d | 14725 | "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)" |
14726 | "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect" | |
eb85ed36 | 14727 | "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)" |
14728 | "\n '-whitepoint value' White point value for filmic tone mapping" | |
14729 | "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)" | |
a2803f37 | 14730 | "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triangles|points" |
5e30547b | 14731 | "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'" |
15669413 | 14732 | "\n Show/hide performance counters (flags can be combined)" |
14733 | "\n '-perfUpdateInterval nbSeconds' Performance counters update interval" | |
5e30547b | 14734 | "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames" |
14735 | "\n '-perfChartMax seconds' Maximum time in seconds with the chart" | |
0e3025bc | 14736 | "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or" |
14737 | "\n set state to check structures culled previously." | |
8625ef7e | 14738 | "\n Unlike vcaps, these parameters dramatically change visual properties." |
14739 | "\n Command is intended to control presentation quality depending on" | |
14740 | "\n hardware capabilities and performance.", | |
bc8c79bb | 14741 | __FILE__, VRenderParams, group); |
79b544e6 | 14742 | theCommands.Add("vstatprofiler", |
14743 | "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups" | |
14744 | "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays" | |
a2803f37 | 14745 | "\n |triangles|points|geomMem|textureMem|frameMem" |
79b544e6 | 14746 | "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage" |
14747 | "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]" | |
14748 | "\n [-noredraw]" | |
14749 | "\n\t\t: Prints rendering statistics." | |
14750 | "\n\t\t: If there are some parameters - print corresponding statistic counters values," | |
14751 | "\n\t\t: else - print all performance counters set previously." | |
14752 | "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n", | |
14753 | __FILE__, VStatProfiler, group); | |
49e1a5c7 | 14754 | theCommands.Add ("vplace", |
14755 | "vplace dx dy" | |
14756 | "\n\t\t: Places the point (in pixels) at the center of the window", | |
14757 | __FILE__, VPlace, group); | |
0717ddc1 | 14758 | theCommands.Add("vxrotate", |
14759 | "vxrotate", | |
14760 | __FILE__,VXRotate,group); | |
14761 | ||
625e1958 | 14762 | theCommands.Add("vmanipulator", |
14763 | "\n vmanipulator Name [-attach AISObject | -detach | ...]" | |
14764 | "\n tool to create and manage AIS manipulators." | |
14765 | "\n Options: " | |
14766 | "\n '-attach AISObject' attach manipulator to AISObject" | |
14767 | "\n '-adjustPosition {0|1}' adjust position when attaching" | |
14768 | "\n '-adjustSize {0|1}' adjust size when attaching" | |
14769 | "\n '-enableModes {0|1}' enable modes when attaching" | |
bbf3fcde | 14770 | "\n '-view {active | [name of view]}' display manipulator only in defined view," |
14771 | "\n by default it is displayed in all views of the current viewer" | |
625e1958 | 14772 | "\n '-detach' detach manipulator" |
14773 | "\n '-startTransform mouse_x mouse_y' - invoke start of transformation" | |
14774 | "\n '-transform mouse_x mouse_y' - invoke transformation" | |
14775 | "\n '-stopTransform [abort]' - invoke stop of transformation" | |
14776 | "\n '-move x y z' - move attached object" | |
14777 | "\n '-rotate x y z dx dy dz angle' - rotate attached object" | |
14778 | "\n '-scale factor' - scale attached object" | |
14779 | "\n '-autoActivate {0|1}' - set activation on detection" | |
14780 | "\n '-followTranslation {0|1}' - set following translation transform" | |
14781 | "\n '-followRotation {0|1}' - set following rotation transform" | |
f522ce50 | 14782 | "\n '-followDragging {0|1}' - set following dragging transform" |
625e1958 | 14783 | "\n '-gap value' - set gap between sub-parts" |
14784 | "\n '-part axis mode {0|1}' - set visual part" | |
84b904bc | 14785 | "\n '-parts axis mode {0|1}' - set visual part" |
625e1958 | 14786 | "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator" |
14787 | "\n '-size value' - set size of manipulator" | |
14788 | "\n '-zoomable {0|1}' - set zoom persistence", | |
14789 | __FILE__, VManipulator, group); | |
14790 | ||
8e5fb5ea | 14791 | theCommands.Add("vselprops", |
f838dac4 | 14792 | "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]" |
8e5fb5ea | 14793 | "\n Customizes selection and dynamic highlight parameters for the whole interactive context:" |
14794 | "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode" | |
be3d8cbc | 14795 | "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer" |
14796 | "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state" | |
14c4193d | 14797 | "\n -pickStrategy {first|topmost} : defines picking strategy" |
14798 | "\n 'first' to pick first acceptable (default)" | |
14799 | "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)" | |
8e5fb5ea | 14800 | "\n -pixTol value : sets up pixel tolerance" |
f838dac4 | 14801 | "\n -dispMode dispMode : sets display mode for highlighting" |
14802 | "\n -layer ZLayer : sets ZLayer for highlighting" | |
14803 | "\n -color {name|r g b} : sets highlight color" | |
14804 | "\n -transp value : sets transparency coefficient for highlight" | |
14805 | "\n -material material : sets highlight material" | |
8e5fb5ea | 14806 | "\n -print : prints current state of all mentioned parameters", |
14807 | __FILE__, VSelectionProperties, group); | |
be3d8cbc | 14808 | theCommands.Add ("vhighlightselected", |
14809 | "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n", | |
14810 | __FILE__, VSelectionProperties, group); | |
8e5fb5ea | 14811 | |
decdee7d | 14812 | theCommands.Add ("vseldump", |
14813 | "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1" | |
b40cdc2b | 14814 | "\n\t\t: [-xrPose base|head=base]" |
decdee7d | 14815 | "\n\t\t: Generate an image based on detection results:" |
14816 | "\n\t\t: depth normalized depth values" | |
14817 | "\n\t\t: unnormDepth unnormalized depth values" | |
14818 | "\n\t\t: object color of detected object" | |
14819 | "\n\t\t: owner color of detected owner" | |
14820 | "\n\t\t: selMode color of selection mode" | |
14821 | "\n\t\t: entity color of etected entity", | |
14822 | __FILE__, VDumpSelectionImage, group); | |
293211ae | 14823 | |
2108d9a2 | 14824 | theCommands.Add ("vviewcube", |
14825 | "vviewcube name" | |
14826 | "\n\t\t: Displays interactive view manipualtion object." | |
14827 | "\n\t\t: Options: " | |
14828 | "\n\t\t: -reset reset geomertical and visual attributes'" | |
14829 | "\n\t\t: -size Size adapted size of View Cube" | |
14830 | "\n\t\t: -boxSize Size box size" | |
14831 | "\n\t\t: -axes {0|1 } show/hide axes (trihedron)" | |
14832 | "\n\t\t: -edges {0|1} show/hide edges of View Cube" | |
14833 | "\n\t\t: -vertices {0|1} show/hide vertices of View Cube" | |
14834 | "\n\t\t: -Yup {0|1} -Zup {0|1} set Y-up or Z-up view orientation" | |
14835 | "\n\t\t: -color Color color of View Cube" | |
14836 | "\n\t\t: -boxColor Color box color" | |
14837 | "\n\t\t: -boxSideColor Color box sides color" | |
14838 | "\n\t\t: -boxEdgeColor Color box edges color" | |
14839 | "\n\t\t: -boxCornerColor Color box corner color" | |
14840 | "\n\t\t: -textColor Color color of side text of view cube" | |
14841 | "\n\t\t: -innerColor Color inner box color" | |
14842 | "\n\t\t: -transparency Value transparency of object within [0, 1] range" | |
14843 | "\n\t\t: -boxTransparency Value transparency of box within [0, 1] range" | |
14844 | "\n\t\t: -font Name font name" | |
14845 | "\n\t\t: -fontHeight Value font height" | |
14846 | "\n\t\t: -boxFacetExtension Value box facet extension" | |
14847 | "\n\t\t: -boxEdgeGap Value gap between box edges and box sides" | |
14848 | "\n\t\t: -boxEdgeMinSize Value minimal box edge size" | |
14849 | "\n\t\t: -boxCornerMinSize Value minimal box corner size" | |
14850 | "\n\t\t: -axesPadding Value padding between box and arrows" | |
14851 | "\n\t\t: -roundRadius Value relative radius of corners of sides within [0.0, 0.5] range" | |
6466cc9e | 14852 | "\n\t\t: -axesRadius Value radius of axes of the trihedron" |
14853 | "\n\t\t: -axesConeRadius Value radius of the cone (arrow) of the trihedron" | |
14854 | "\n\t\t: -axesSphereRadius Value radius of the sphere (central point) of trihedron" | |
2108d9a2 | 14855 | "\n\t\t: -fixedanimation {0|1} uninterruptible animation loop" |
14856 | "\n\t\t: -duration Seconds animation duration in seconds", | |
14857 | __FILE__, VViewCube, group); | |
14858 | ||
14b741b0 | 14859 | theCommands.Add("vcolorconvert" , |
14860 | "vcolorconvert {from|to} type C1 C2 C2" | |
14861 | "\n\t\t: vcolorconvert from type C1 C2 C2: Converts color from specified color space to linear RGB" | |
14862 | "\n\t\t: vcolorconvert to type R G B: Converts linear RGB color to specified color space" | |
14863 | "\n\t\t: type can be sRGB, HLS, Lab, or Lch", | |
14864 | __FILE__,VColorConvert,group); | |
14865 | theCommands.Add("vcolordiff" , | |
14866 | "vcolordiff R1 G1 B1 R2 G2 B2: returns CIEDE2000 color difference between two RGB colors", | |
14867 | __FILE__,VColorDiff,group); | |
2108d9a2 | 14868 | } |