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 | ||
293211ae | 419 | //! the variable set of options that are allowed for the old scenario (without any option passed) |
420 | CommandOptionKeyVariableSet myUnnamedOptionVariableSet; | |
421 | ||
077a220c | 422 | //! the variable set of options that are allowed for setting an environment cubemap as background |
423 | CommandOptionKeyVariableSet myCubeMapOptionVariableSet; | |
424 | ||
293211ae | 425 | //! the variable set of options that are allowed for setting an image as a background |
426 | CommandOptionKeyVariableSet myImageOptionVariableSet; | |
427 | ||
428 | //! the variable set of options that are allowed for setting a background image fill type | |
429 | CommandOptionKeyVariableSet myImageModeOptionVariableSet; | |
430 | ||
431 | //! the variable set of options that are allowed for setting a gradient filling for the background | |
432 | CommandOptionKeyVariableSet myGradientOptionVariableSet; | |
433 | ||
434 | //! the variable set of options that are allowed for setting a background gradient filling method | |
435 | CommandOptionKeyVariableSet myGradientModeOptionVariableSet; | |
436 | ||
437 | //! the variable set of options that are allowed for filling a background with a specific color | |
438 | CommandOptionKeyVariableSet myColorOptionVariableSet; | |
439 | ||
440 | //! the variable set of options that are allowed for setting a default background gradient | |
441 | CommandOptionKeyVariableSet myDefaultGradientOptionVariableSet; | |
442 | ||
443 | //! the variable set of options that are allowed for setting a default background color | |
444 | CommandOptionKeyVariableSet myDefaultColorOptionVariableSet; | |
445 | ||
446 | //! the variable set of options that are allowed for printing help | |
447 | CommandOptionKeyVariableSet myHelpOptionVariableSet; | |
448 | ||
449 | //! Adds options to command parser | |
450 | void addOptionsToCommandParser() | |
451 | { | |
452 | myImageOptionKey = myCommandParser.AddOption ("imageFile|image|imgFile|img", | |
453 | "filename of image used as background"); | |
454 | myImageModeOptionKey = myCommandParser.AddOption ( | |
455 | "imageMode|imgMode", "image fill type, should be one of CENTERED, TILED, STRETCH, NONE"); | |
456 | myGradientOptionKey = myCommandParser.AddOption ("gradient|grad|gr", | |
457 | "sets background gradient starting and ending colors"); | |
458 | myGradientModeOptionKey = | |
459 | myCommandParser.AddOption ("gradientMode|gradMode|gradMd|grMode|grMd", | |
460 | "gradient fill method, should be one of NONE, HOR[IZONTAL], VER[TICAL], " | |
461 | "DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, CORNER4"); | |
462 | myColorOptionKey = myCommandParser.AddOption ("color|col", "background color"); | |
463 | myDefaultOptionKey = myCommandParser.AddOption ("default|def", "sets background default gradient or color"); | |
077a220c | 464 | |
465 | myCubeMapOptionKey = myCommandParser.AddOption ("cubemap|cmap|cm", "background cubemap"); | |
466 | myCubeMapOrderOptionKey = myCommandParser.AddOption ("order|o", "order of sides in one image packed cubemap"); | |
467 | myCubeMapInvertedZOptionKey = myCommandParser.AddOption ( | |
468 | "invertedz|invz|iz", "whether Z axis is inverted or not during background cubemap rendering"); | |
293211ae | 469 | } |
470 | ||
471 | //! Creates option sets used to determine if a passed option set is valid or not | |
472 | void createOptionSets() | |
473 | { | |
474 | ViewerTest_CommandOptionKeySet anUnnamedOptionSet; | |
475 | anUnnamedOptionSet.insert (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY); | |
476 | myUnnamedOptionVariableSet = CommandOptionKeyVariableSet (anUnnamedOptionSet); | |
477 | ||
077a220c | 478 | ViewerTest_CommandOptionKeySet aCubeMapOptionSet; |
479 | aCubeMapOptionSet.insert (myCubeMapOptionKey); | |
480 | ViewerTest_CommandOptionKeySet aCubeMapAdditionalOptionKeySet; | |
481 | aCubeMapAdditionalOptionKeySet.insert (myCubeMapInvertedZOptionKey); | |
482 | aCubeMapAdditionalOptionKeySet.insert (myCubeMapOrderOptionKey); | |
483 | myCubeMapOptionVariableSet = CommandOptionKeyVariableSet (aCubeMapOptionSet, aCubeMapAdditionalOptionKeySet); | |
484 | ||
293211ae | 485 | ViewerTest_CommandOptionKeySet anImageOptionSet; |
486 | anImageOptionSet.insert (myImageOptionKey); | |
487 | ViewerTest_CommandOptionKeySet anImageModeOptionSet; | |
488 | anImageModeOptionSet.insert (myImageModeOptionKey); | |
489 | myImageOptionVariableSet = CommandOptionKeyVariableSet (anImageOptionSet, anImageModeOptionSet); | |
490 | myImageModeOptionVariableSet = CommandOptionKeyVariableSet (anImageModeOptionSet); | |
491 | ||
492 | ViewerTest_CommandOptionKeySet aGradientOptionSet; | |
493 | aGradientOptionSet.insert (myGradientOptionKey); | |
494 | ViewerTest_CommandOptionKeySet aGradientModeOptionSet; | |
495 | aGradientModeOptionSet.insert (myGradientModeOptionKey); | |
496 | myGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet); | |
497 | myGradientModeOptionVariableSet = CommandOptionKeyVariableSet (aGradientModeOptionSet); | |
498 | ||
499 | ViewerTest_CommandOptionKeySet aColorOptionSet; | |
500 | aColorOptionSet.insert (myColorOptionKey); | |
501 | myColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet); | |
502 | ||
503 | aGradientOptionSet.insert (myDefaultOptionKey); | |
504 | myDefaultGradientOptionVariableSet = CommandOptionKeyVariableSet (aGradientOptionSet, aGradientModeOptionSet); | |
505 | aColorOptionSet.insert (myDefaultOptionKey); | |
506 | myDefaultColorOptionVariableSet = CommandOptionKeyVariableSet (aColorOptionSet); | |
507 | ||
508 | ViewerTest_CommandOptionKeySet aHelpOptionSet; | |
509 | aHelpOptionSet.insert (ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY); | |
510 | myHelpOptionVariableSet = CommandOptionKeyVariableSet (aHelpOptionSet); | |
511 | } | |
512 | ||
513 | //! Prepares the command parser. Adds options and creates option sets used to determine | |
514 | //! if a passed option set is valid or not | |
515 | void prepareCommandParser() | |
516 | { | |
517 | addOptionsToCommandParser(); | |
518 | createOptionSets(); | |
519 | } | |
520 | ||
521 | //! Adds a command description to the command parser | |
522 | //! @param theBackgroundCommand the key of the command which description is added to the command parser | |
523 | void addCommandDescription (const BackgroundCommand theBackgroundCommand) | |
524 | { | |
525 | std::string aDescription; | |
526 | bool isMainCommand = false; | |
527 | switch (theBackgroundCommand) | |
528 | { | |
529 | case BackgroundCommand_Main: | |
530 | aDescription = "Command: vbackground (changes background or some background settings)"; | |
531 | isMainCommand = true; | |
532 | break; | |
533 | case BackgroundCommand_Image: | |
534 | aDescription = "Command: vsetbg (loads image as a background)"; | |
535 | break; | |
536 | case BackgroundCommand_ImageMode: | |
537 | aDescription = "Command: vsetbgmode (changes background fill type)"; | |
538 | break; | |
539 | case BackgroundCommand_Gradient: | |
540 | aDescription = "Command: vsetgradientbg (mounts gradient background)"; | |
541 | break; | |
542 | case BackgroundCommand_GradientMode: | |
543 | aDescription = "Command: vsetgradientbgmode (changes gradient background fill method)"; | |
544 | break; | |
545 | case BackgroundCommand_Color: | |
546 | aDescription = "Command: vsetcolorbg (sets color background)"; | |
547 | break; | |
548 | case BackgroundCommand_Default: | |
549 | aDescription = "Command: vsetdefaultbg (sets default viewer background gradient or fill color)"; | |
550 | break; | |
551 | default: | |
552 | return; | |
553 | } | |
554 | if (!isMainCommand) | |
555 | { | |
556 | aDescription += "\nThis command is obsolete. Use vbackground instead."; | |
557 | } | |
558 | myCommandParser.SetDescription (aDescription); | |
559 | } | |
560 | ||
561 | //! Check if a viewer is needed to be initialized | |
562 | //! @param theBackgroundCommand the key of the command that changes the background | |
563 | //! @return true if processing was successful, or false otherwise | |
564 | bool checkViewerIsNeeded (const BackgroundCommand theBackgroundCommand) const | |
565 | { | |
566 | const bool isMain = (theBackgroundCommand == BackgroundCommand_Main); | |
567 | const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions(); | |
568 | const bool aViewerIsNotNeeded = | |
569 | (theBackgroundCommand == BackgroundCommand_Default) | |
570 | || (myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain) | |
571 | || (myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain) | |
572 | || myHelpOptionVariableSet.IsInSet (aUsedOptions); | |
573 | return !aViewerIsNotNeeded; | |
574 | } | |
575 | ||
576 | //! Check if a viewer is initialized | |
577 | //! @param theBackgroundCommandName the name of the command that changes the background | |
578 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
579 | //! @return true if a viewer is initialized, or false otherwise | |
580 | static bool checkViewerIsInitialized (const char* const theBackgroundCommandName, | |
581 | Draw_Interpretor& theDrawInterpretor) | |
582 | { | |
583 | const Handle (AIS_InteractiveContext)& anAISContext = ViewerTest::GetAISContext(); | |
584 | if (anAISContext.IsNull()) | |
585 | { | |
586 | theDrawInterpretor << "Use 'vinit' command before executing '" << theBackgroundCommandName << "' command.\n"; | |
587 | return false; | |
588 | } | |
589 | return true; | |
590 | } | |
591 | ||
592 | //! Processes command options | |
593 | //! @param theBackgroundCommandName the name of the command that changes the background | |
594 | //! @param theBackgroundCommand the key of the command that changes the background | |
595 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
596 | //! @return true if processing was successful, or false otherwise | |
597 | bool processCommandOptions (const char* const theBackgroundCommandName, | |
598 | const BackgroundCommand theBackgroundCommand, | |
599 | Draw_Interpretor& theDrawInterpretor) const | |
600 | { | |
601 | if (myCommandParser.HasNoOption()) | |
602 | { | |
603 | return printHelp (theBackgroundCommandName, theDrawInterpretor); | |
604 | } | |
605 | if (checkViewerIsNeeded (theBackgroundCommand) | |
606 | && !checkViewerIsInitialized (theBackgroundCommandName, theDrawInterpretor)) | |
607 | { | |
608 | return false; | |
609 | } | |
610 | if (myCommandParser.HasOnlyUnnamedOption()) | |
611 | { | |
612 | return processUnnamedOption (theBackgroundCommand); | |
613 | } | |
614 | return processNamedOptions (theBackgroundCommandName, theBackgroundCommand, theDrawInterpretor); | |
615 | } | |
616 | ||
617 | //! Processes the unnamed option | |
618 | //! @param theBackgroundCommand the key of the command that changes the background | |
619 | //! @return true if processing was successful, or false otherwise | |
620 | bool processUnnamedOption (const BackgroundCommand theBackgroundCommand) const | |
621 | { | |
622 | switch (theBackgroundCommand) | |
623 | { | |
624 | case BackgroundCommand_Main: | |
625 | return false; | |
626 | case BackgroundCommand_Image: | |
627 | return processImageUnnamedOption(); | |
628 | case BackgroundCommand_ImageMode: | |
629 | return processImageModeUnnamedOption(); | |
630 | case BackgroundCommand_Gradient: | |
631 | return processGradientUnnamedOption(); | |
632 | case BackgroundCommand_GradientMode: | |
633 | return processGradientModeUnnamedOption(); | |
634 | case BackgroundCommand_Color: | |
635 | return processColorUnnamedOption(); | |
636 | case BackgroundCommand_Default: | |
637 | return processDefaultUnnamedOption(); | |
638 | default: | |
639 | return false; | |
640 | } | |
641 | } | |
642 | ||
643 | //! Processes the image unnamed option | |
644 | //! @return true if processing was successful, or false otherwise | |
645 | bool processImageUnnamedOption() const | |
646 | { | |
647 | const std::size_t aNumberOfImageUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
648 | ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY); | |
649 | if ((aNumberOfImageUnnamedOptionArguments != 1) && (aNumberOfImageUnnamedOptionArguments != 2)) | |
650 | { | |
651 | return false; | |
652 | } | |
653 | std::string anImageFileName; | |
654 | if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0, anImageFileName)) | |
655 | { | |
656 | return false; | |
657 | } | |
658 | Aspect_FillMethod anImageMode = Aspect_FM_CENTERED; | |
659 | if (aNumberOfImageUnnamedOptionArguments == 2) | |
660 | { | |
661 | std::string anImageModeString; | |
662 | if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 1, anImageModeString)) | |
663 | { | |
664 | return false; | |
665 | } | |
666 | if (!getBackgroundImageFillMethodByName (anImageModeString.c_str(), anImageMode)) | |
667 | { | |
668 | return false; | |
669 | } | |
670 | } | |
671 | setImage (anImageFileName.c_str(), anImageMode); | |
672 | return true; | |
673 | } | |
674 | ||
675 | //! Processes the image mode unnamed option | |
676 | //! @return true if processing was successful, or false otherwise | |
677 | bool processImageModeUnnamedOption() const | |
678 | { | |
679 | return processImageModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY); | |
680 | } | |
681 | ||
682 | //! Processes the gradient unnamed option | |
683 | //! @param theSetGradient the function used to set a background gradient filling | |
684 | //! @return true if processing was successful, or false otherwise | |
685 | bool processGradientUnnamedOption (SetGradientFunction* const theSetGradient = setGradient) const | |
686 | { | |
687 | const Standard_Integer aNumberOfGradientUnnamedOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
688 | ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY); | |
689 | if (aNumberOfGradientUnnamedOptionArguments < 2) | |
690 | { | |
691 | return false; | |
692 | } | |
693 | ||
694 | Standard_Integer anArgumentIndex = 0; | |
695 | Quantity_Color aColor1; | |
696 | if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor1)) | |
697 | { | |
698 | return false; | |
699 | } | |
700 | if (anArgumentIndex >= aNumberOfGradientUnnamedOptionArguments) | |
701 | { | |
702 | return false; | |
703 | } | |
704 | ||
705 | Quantity_Color aColor2; | |
706 | if (!myCommandParser.ArgColor (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, anArgumentIndex, aColor2)) | |
707 | { | |
708 | return false; | |
709 | } | |
710 | if (anArgumentIndex > aNumberOfGradientUnnamedOptionArguments) | |
711 | { | |
712 | return false; | |
713 | } | |
714 | ||
715 | Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR; | |
716 | if (anArgumentIndex == aNumberOfGradientUnnamedOptionArguments - 1) | |
717 | { | |
718 | std::string anGradientModeString; | |
719 | ||
720 | if (!myCommandParser.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, | |
721 | anArgumentIndex, | |
722 | anGradientModeString)) | |
723 | { | |
724 | return false; | |
725 | } | |
726 | if (!getBackgroundGradientFillMethodByName (anGradientModeString.c_str(), aGradientMode)) | |
727 | { | |
728 | return false; | |
729 | } | |
730 | ++anArgumentIndex; | |
731 | } | |
732 | if (anArgumentIndex != aNumberOfGradientUnnamedOptionArguments) | |
733 | { | |
734 | return false; | |
735 | } | |
736 | theSetGradient (aColor1, aColor2, aGradientMode); | |
737 | return true; | |
738 | } | |
739 | ||
740 | //! Processes the gradient mode unnamed option | |
741 | //! @return true if processing was successful, or false otherwise | |
742 | bool processGradientModeUnnamedOption() const | |
743 | { | |
744 | return processGradientModeOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY); | |
745 | } | |
746 | ||
747 | //! Processes the color unnamed option | |
748 | //! @param theSetColor the function used to set a background color | |
749 | //! @return true if processing was successful, or false otherwise | |
750 | bool processColorUnnamedOption (SetColorFunction* const theSetColor = setColor) const | |
751 | { | |
752 | return processColorOptionSet (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, theSetColor); | |
753 | } | |
754 | ||
755 | //! Processes the default back unnamed option | |
756 | //! @return true if processing was successful, or false otherwise | |
757 | bool processDefaultUnnamedOption() const | |
758 | { | |
759 | if (processGradientUnnamedOption (setDefaultGradient)) | |
760 | { | |
761 | return true; | |
762 | } | |
763 | return processColorUnnamedOption (setDefaultColor); | |
764 | } | |
765 | ||
766 | //! Processes named options | |
767 | //! @param theBackgroundCommandName the name of the command that changes the background | |
768 | //! @param theBackgroundCommand the key of the command that changes the background | |
769 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
770 | //! @return true if processing was successful, or false otherwise | |
771 | bool processNamedOptions (const char* const theBackgroundCommandName, | |
772 | const BackgroundCommand theBackgroundCommand, | |
773 | Draw_Interpretor& theDrawInterpretor) const | |
774 | { | |
775 | const bool isMain = (theBackgroundCommand == BackgroundCommand_Main); | |
776 | const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions(); | |
077a220c | 777 | if (myCubeMapOptionVariableSet.IsInSet (aUsedOptions) && isMain) |
778 | { | |
779 | return processCubeMapOptionSet(); | |
780 | } | |
293211ae | 781 | if (myImageOptionVariableSet.IsInSet (aUsedOptions) |
782 | && (isMain || (theBackgroundCommand == BackgroundCommand_Image))) | |
783 | { | |
784 | return processImageOptionSet(); | |
785 | } | |
786 | if (myImageModeOptionVariableSet.IsInSet (aUsedOptions) | |
787 | && (isMain || (theBackgroundCommand == BackgroundCommand_ImageMode))) | |
788 | { | |
789 | return processImageModeOptionSet(); | |
790 | } | |
791 | if (myGradientOptionVariableSet.IsInSet (aUsedOptions) | |
792 | && (isMain || (theBackgroundCommand == BackgroundCommand_Gradient))) | |
793 | { | |
794 | return processGradientOptionSet(); | |
795 | } | |
796 | if (myGradientModeOptionVariableSet.IsInSet (aUsedOptions) | |
797 | && (isMain || (theBackgroundCommand == BackgroundCommand_GradientMode))) | |
798 | { | |
799 | return processGradientModeOptionSet(); | |
800 | } | |
801 | if (myColorOptionVariableSet.IsInSet (aUsedOptions) | |
802 | && (isMain || (theBackgroundCommand == BackgroundCommand_Color))) | |
803 | { | |
804 | return processColorOptionSet(); | |
805 | } | |
806 | if ((myDefaultGradientOptionVariableSet.IsInSet (aUsedOptions) && isMain) | |
807 | || (myGradientOptionVariableSet.IsInSet (aUsedOptions) | |
808 | && (theBackgroundCommand == BackgroundCommand_Default))) | |
809 | { | |
810 | return processDefaultGradientOptionSet(); | |
811 | } | |
812 | if ((myDefaultColorOptionVariableSet.IsInSet (aUsedOptions) && isMain) | |
813 | || (myColorOptionVariableSet.IsInSet (aUsedOptions) && (theBackgroundCommand == BackgroundCommand_Default))) | |
814 | { | |
815 | return processDefaultColorOptionSet(); | |
816 | } | |
817 | if (myHelpOptionVariableSet.IsInSet (aUsedOptions)) | |
818 | { | |
819 | return processHelpOptionSet (theBackgroundCommandName, theDrawInterpretor); | |
820 | } | |
821 | return false; | |
822 | } | |
823 | ||
077a220c | 824 | //! Process the cubemap option set in named and unnamed case. |
825 | //! @return true if processing was successful, or false otherwise | |
826 | bool processCubeMapOptionSet() const | |
827 | { | |
828 | NCollection_Array1<TCollection_AsciiString> aFilePaths; | |
829 | ||
830 | if (!processCubeMapOptions (aFilePaths)) | |
831 | { | |
832 | return false; | |
833 | } | |
834 | ||
835 | Graphic3d_CubeMapOrder anOrder = Graphic3d_CubeMapOrder::Default(); | |
836 | ||
837 | if (myCommandParser.HasOption (myCubeMapOrderOptionKey)) | |
838 | { | |
839 | if (!processCubeMapOrderOptions (anOrder)) | |
840 | { | |
841 | return false; | |
842 | } | |
843 | } | |
844 | ||
845 | bool aZIsInverted = false; | |
846 | if (myCommandParser.HasOption (myCubeMapInvertedZOptionKey)) | |
847 | { | |
848 | if (!processCubeMapInvertedZOptionSet()) | |
849 | { | |
850 | return false; | |
851 | } | |
852 | aZIsInverted = true; | |
853 | } | |
854 | ||
855 | setCubeMap (aFilePaths, anOrder.Validated(), aZIsInverted); | |
856 | return true; | |
857 | } | |
858 | ||
293211ae | 859 | //! Processes the image option set |
860 | //! @return true if processing was successful, or false otherwise | |
861 | bool processImageOptionSet() const | |
862 | { | |
863 | std::string anImageFileName; | |
864 | if (!processImageOption (anImageFileName)) | |
865 | { | |
866 | return false; | |
867 | } | |
868 | Aspect_FillMethod anImageMode = Aspect_FM_CENTERED; | |
869 | if (myCommandParser.HasOption (myImageModeOptionKey) && !processImageModeOption (anImageMode)) | |
870 | { | |
871 | return false; | |
872 | } | |
873 | setImage (anImageFileName.c_str(), anImageMode); | |
874 | return true; | |
875 | } | |
876 | ||
877 | //! Processes the image mode option set | |
878 | //! @return true if processing was successful, or false otherwise | |
879 | bool processImageModeOptionSet() const | |
880 | { | |
881 | return processImageModeOptionSet (myImageModeOptionKey); | |
882 | } | |
883 | ||
884 | //! Processes the image mode option set | |
885 | //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option | |
886 | //! @return true if processing was successful, or false otherwise | |
887 | bool processImageModeOptionSet (const ViewerTest_CommandOptionKey theImageModeOptionKey) const | |
888 | { | |
889 | Aspect_FillMethod anImageMode = Aspect_FM_NONE; | |
890 | if (!processImageModeOption (theImageModeOptionKey, anImageMode)) | |
891 | { | |
892 | return false; | |
893 | } | |
894 | setImageMode (anImageMode); | |
895 | return true; | |
896 | } | |
897 | ||
898 | //! Processes the gradient option set | |
899 | //! @param theSetGradient the function used to set a background gradient filling | |
900 | //! @return true if processing was successful, or false otherwise | |
901 | bool processGradientOptionSet (SetGradientFunction* const theSetGradient = setGradient) const | |
902 | { | |
903 | Quantity_Color aColor1; | |
904 | Quantity_Color aColor2; | |
905 | if (!processGradientOption (aColor1, aColor2)) | |
906 | { | |
907 | return false; | |
908 | } | |
909 | Aspect_GradientFillMethod aGradientMode = Aspect_GFM_HOR; | |
910 | if (myCommandParser.HasOption (myGradientModeOptionKey) && !processGradientModeOption (aGradientMode)) | |
911 | { | |
912 | return false; | |
913 | } | |
914 | theSetGradient (aColor1, aColor2, aGradientMode); | |
915 | return true; | |
916 | } | |
917 | ||
918 | //! Processes the gradient mode option set | |
919 | //! @return true if processing was successful, or false otherwise | |
920 | bool processGradientModeOptionSet() const | |
921 | { | |
922 | return processGradientModeOptionSet (myGradientModeOptionKey); | |
923 | } | |
924 | ||
925 | //! Processes the gradient mode option set | |
926 | //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option | |
927 | //! @return true if processing was successful, or false otherwise | |
928 | bool processGradientModeOptionSet (const ViewerTest_CommandOptionKey theGradientModeOptionKey) const | |
929 | { | |
930 | Aspect_GradientFillMethod aGradientMode = Aspect_GFM_NONE; | |
931 | if (!processGradientModeOption (theGradientModeOptionKey, aGradientMode)) | |
932 | { | |
933 | return false; | |
934 | } | |
935 | setGradientMode (aGradientMode); | |
936 | return true; | |
937 | } | |
938 | ||
939 | //! Processes the color option set | |
940 | //! @param theSetColor the function used to set a background color | |
941 | //! @return true if processing was successful, or false otherwise | |
942 | bool processColorOptionSet (SetColorFunction* const theSetColor = setColor) const | |
943 | { | |
944 | return processColorOptionSet (myColorOptionKey, theSetColor); | |
945 | } | |
946 | ||
947 | //! Processes the default color option set | |
948 | //! @return true if processing was successful, or false otherwise | |
949 | bool processDefaultGradientOptionSet() const | |
950 | { | |
951 | return processGradientOptionSet (setDefaultGradient); | |
952 | } | |
953 | ||
954 | //! Processes the default gradient option set | |
955 | //! @return true if processing was successful, or false otherwise | |
956 | bool processDefaultColorOptionSet() const | |
957 | { | |
958 | return processColorOptionSet (setDefaultColor); | |
959 | } | |
960 | ||
961 | //! Processes the color option set | |
962 | //! @param theColorOptionKey the key of the option that is interpreted as a color option | |
963 | //! @param theSetColor the function used to set a background color | |
964 | //! @return true if processing was successful, or false otherwise | |
965 | bool processColorOptionSet (const ViewerTest_CommandOptionKey theColorOptionKey, | |
966 | SetColorFunction* const theSetColor = setColor) const | |
967 | { | |
968 | Quantity_Color aColor; | |
969 | if (!processColorOption (theColorOptionKey, aColor)) | |
970 | { | |
971 | return false; | |
972 | } | |
973 | theSetColor (aColor); | |
974 | return true; | |
975 | } | |
976 | ||
977 | //! Processes the help option set | |
978 | //! @param theBackgroundCommandName the name of the command that changes the background | |
979 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
980 | //! @return true if processing was successful, or false otherwise | |
981 | bool processHelpOptionSet (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor) const | |
982 | { | |
983 | const Standard_Integer aNumberOfHelpOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
984 | ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY); | |
985 | if (aNumberOfHelpOptionArguments != 0) | |
986 | { | |
987 | return false; | |
988 | } | |
989 | return printHelp (theBackgroundCommandName, theDrawInterpretor); | |
990 | } | |
991 | ||
077a220c | 992 | //! Processes the cubemap option |
993 | //! @param theFilePaths the array of filenames of cubemap sides | |
994 | //! @return true if processing was successful, or false otherwise | |
995 | bool processCubeMapOptions (NCollection_Array1<TCollection_AsciiString> &theFilePaths) const | |
996 | { | |
997 | const Standard_Integer aNumberOfCubeMapOptionArguments = myCommandParser.GetNumberOfOptionArguments (myCubeMapOptionKey); | |
998 | ||
999 | if (aNumberOfCubeMapOptionArguments != 1 | |
1000 | && aNumberOfCubeMapOptionArguments != 6) | |
1001 | { | |
1002 | return false; | |
1003 | } | |
1004 | ||
1005 | theFilePaths.Resize(0, aNumberOfCubeMapOptionArguments - 1, Standard_False); | |
1006 | ||
1007 | for (int i = 0; i < aNumberOfCubeMapOptionArguments; ++i) | |
1008 | { | |
1009 | std::string aCubeMapFileName; | |
1010 | if (!myCommandParser.Arg (myCubeMapOptionKey, i, aCubeMapFileName)) | |
1011 | { | |
1012 | return false; | |
1013 | } | |
1014 | theFilePaths[i] = aCubeMapFileName.c_str(); | |
1015 | } | |
1016 | ||
1017 | return true; | |
1018 | } | |
1019 | ||
1020 | //! Processes the cubemap option | |
1021 | //! @param theIsNeededToRedraw defines need of redraw after option's processing | |
1022 | //! @return true if processing was successful, or false otherwise | |
1023 | bool processCubeMapInvertedZOptionSet () const | |
1024 | { | |
1025 | const Standard_Integer aNumberOfCubeMapZInversionOptionArguments = | |
1026 | myCommandParser.GetNumberOfOptionArguments (myCubeMapInvertedZOptionKey); | |
1027 | ||
1028 | if (aNumberOfCubeMapZInversionOptionArguments != 0) | |
1029 | { | |
1030 | return false; | |
1031 | } | |
1032 | ||
1033 | return true; | |
1034 | } | |
1035 | ||
1036 | //! Processes the tiles order option | |
1037 | //! @param theOrder the array of indexes if cubemap sides in tile grid | |
1038 | //! @return true if processing was successful, or false otherwise | |
1039 | bool processCubeMapOrderOptions (Graphic3d_CubeMapOrder& theOrder) const | |
1040 | { | |
1041 | const Standard_Integer aNumberOfCubeMapOrderOptionArguments = myCommandParser.GetNumberOfOptionArguments( | |
1042 | myCubeMapOrderOptionKey); | |
1043 | ||
1044 | if (aNumberOfCubeMapOrderOptionArguments != 6) | |
1045 | { | |
1046 | return false; | |
1047 | } | |
1048 | ||
1049 | ||
1050 | for (unsigned int i = 0; i < 6; ++i) | |
1051 | { | |
1052 | std::string anOrderItem; | |
1053 | if (!myCommandParser.Arg (myCubeMapOrderOptionKey, i, anOrderItem)) | |
1054 | { | |
1055 | return false; | |
1056 | } | |
1057 | ||
1058 | theOrder.Set (Graphic3d_CubeMapSide (i), | |
1059 | static_cast<unsigned char> (Draw::Atoi (anOrderItem.c_str()))); | |
1060 | } | |
1061 | ||
1062 | return theOrder.IsValid(); | |
1063 | } | |
1064 | ||
293211ae | 1065 | //! Processes the image option |
1066 | //! @param theImageFileName the filename of the image to be used as a background | |
1067 | //! @return true if processing was successful, or false otherwise | |
1068 | bool processImageOption (std::string& theImageFileName) const | |
1069 | { | |
1070 | const Standard_Integer aNumberOfImageOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
1071 | myImageOptionKey); | |
1072 | if (aNumberOfImageOptionArguments != 1) | |
1073 | { | |
1074 | return false; | |
1075 | } | |
1076 | std::string anImageFileName; | |
1077 | if (!myCommandParser.Arg (myImageOptionKey, 0, anImageFileName)) | |
1078 | { | |
1079 | return false; | |
1080 | } | |
1081 | theImageFileName = anImageFileName; | |
1082 | return true; | |
1083 | } | |
1084 | ||
1085 | //! Processes the image mode option | |
1086 | //! @param theImageMode the fill type used for a background image | |
1087 | //! @return true if processing was successful, or false otherwise | |
1088 | bool processImageModeOption (Aspect_FillMethod& theImageMode) const | |
1089 | { | |
1090 | return processImageModeOption (myImageModeOptionKey, theImageMode); | |
1091 | } | |
1092 | ||
1093 | //! Processes the image mode option | |
1094 | //! @param theImageModeOptionKey the key of the option that is interpreted as an image mode option | |
1095 | //! @param theImageMode the fill type used for a background image | |
1096 | //! @return true if processing was successful, or false otherwise | |
1097 | bool processImageModeOption (const ViewerTest_CommandOptionKey theImageModeOptionKey, | |
1098 | Aspect_FillMethod& theImageMode) const | |
1099 | { | |
1100 | return processModeOption (theImageModeOptionKey, getBackgroundImageFillMethodByName, theImageMode); | |
1101 | } | |
1102 | ||
1103 | //! Processes the gradient option | |
1104 | //! @param theColor1 the gradient starting color | |
1105 | //! @param theColor2 the gradient ending color | |
1106 | //! @return true if processing was successful, or false otherwise | |
1107 | bool processGradientOption (Quantity_Color& theColor1, Quantity_Color& theColor2) const | |
1108 | { | |
1109 | Standard_Integer anArgumentIndex = 0; | |
1110 | Quantity_Color aColor1; | |
1111 | if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor1)) | |
1112 | { | |
1113 | return false; | |
1114 | } | |
1115 | Quantity_Color aColor2; | |
1116 | if (!myCommandParser.ArgColor (myGradientOptionKey, anArgumentIndex, aColor2)) | |
1117 | { | |
1118 | return false; | |
1119 | } | |
1120 | const Standard_Integer aNumberOfGradientOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
1121 | myGradientOptionKey); | |
1122 | if (anArgumentIndex != aNumberOfGradientOptionArguments) | |
1123 | { | |
1124 | return false; | |
1125 | } | |
1126 | theColor1 = aColor1; | |
1127 | theColor2 = aColor2; | |
1128 | return true; | |
1129 | } | |
1130 | ||
1131 | //! Processes the gradient mode option | |
1132 | //! @param theGradientMode the fill method used for a background gradient filling | |
1133 | //! @return true if processing was successful, or false otherwise | |
1134 | bool processGradientModeOption (Aspect_GradientFillMethod& theGradientMode) const | |
1135 | { | |
1136 | return processGradientModeOption (myGradientModeOptionKey, theGradientMode); | |
1137 | } | |
1138 | ||
1139 | //! Processes the gradient mode option | |
1140 | //! @param theGradientModeOptionKey the key of the option that is interpreted as a gradient mode option | |
1141 | //! @param theGradientMode the fill method used for a background gradient filling | |
1142 | //! @return true if processing was successful, or false otherwise | |
1143 | bool processGradientModeOption (const ViewerTest_CommandOptionKey theGradientModeOptionKey, | |
1144 | Aspect_GradientFillMethod& theGradientMode) const | |
1145 | { | |
1146 | return processModeOption (theGradientModeOptionKey, getBackgroundGradientFillMethodByName, theGradientMode); | |
1147 | } | |
1148 | ||
1149 | //! Processes some mode option | |
1150 | //! @tparam TheMode the type of a mode to be processed | |
1151 | //! @param theModeOptionKey the key of the option that is interpreted as a mode option | |
1152 | //! @param theMode a mode to be processed | |
1153 | //! @return true if processing was successful, or false otherwise | |
1154 | template <typename TheMode> | |
1155 | bool processModeOption (const ViewerTest_CommandOptionKey theModeOptionKey, | |
1156 | bool (*const theGetModeByName) (const TCollection_AsciiString& /* theModeName */, | |
1157 | TheMode& /* theMode */), | |
1158 | TheMode& theMode) const | |
1159 | { | |
1160 | const Standard_Integer aNumberOfModeOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
1161 | theModeOptionKey); | |
1162 | if (aNumberOfModeOptionArguments != 1) | |
1163 | { | |
1164 | return false; | |
1165 | } | |
1166 | std::string aModeString; | |
1167 | if (!myCommandParser.Arg (theModeOptionKey, 0, aModeString)) | |
1168 | { | |
1169 | return false; | |
1170 | } | |
1171 | TheMode aMode = TheMode(); | |
1172 | if (!theGetModeByName (aModeString.c_str(), aMode)) | |
1173 | { | |
1174 | return false; | |
1175 | } | |
1176 | theMode = aMode; | |
1177 | return true; | |
1178 | } | |
1179 | ||
1180 | //! Processes the color option | |
1181 | //! @param theColor a color used for filling a background | |
1182 | //! @return true if processing was successful, or false otherwise | |
1183 | bool processColorOption (Quantity_Color& theColor) const | |
1184 | { | |
1185 | return processColorOption (myColorOptionKey, theColor); | |
1186 | } | |
1187 | ||
1188 | //! Processes the color option | |
1189 | //! @param theColorOptionKey the key of the option that is interpreted as a color option | |
1190 | //! @param theColor a color used for filling a background | |
1191 | //! @return true if processing was successful, or false otherwise | |
1192 | bool processColorOption (const ViewerTest_CommandOptionKey theColorOptionKey, Quantity_Color& theColor) const | |
1193 | { | |
1194 | Standard_Integer anArgumentIndex = 0; | |
1195 | Quantity_Color aColor; | |
1196 | if (!myCommandParser.ArgColor (theColorOptionKey, anArgumentIndex, aColor)) | |
1197 | { | |
1198 | return false; | |
1199 | } | |
1200 | const Standard_Integer aNumberOfColorOptionArguments = myCommandParser.GetNumberOfOptionArguments ( | |
1201 | theColorOptionKey); | |
1202 | if (anArgumentIndex != aNumberOfColorOptionArguments) | |
1203 | { | |
1204 | return false; | |
1205 | } | |
1206 | theColor = aColor; | |
1207 | return true; | |
1208 | } | |
1209 | ||
1210 | //! Prints helping message | |
1211 | //! @param theBackgroundCommandName the name of the command that changes the background | |
1212 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
1213 | //! @return true if printing was successful, or false otherwise | |
1214 | static bool printHelp (const char* const theBackgroundCommandName, Draw_Interpretor& theDrawInterpretor) | |
1215 | { | |
1216 | return theDrawInterpretor.PrintHelp (theBackgroundCommandName) == TCL_OK; | |
1217 | } | |
1218 | ||
077a220c | 1219 | //! Sets the cubemap as a background |
1220 | //! @param theFileNames the array of filenames of packed or multifile cubemap | |
1221 | //! @param theOrder array of cubemap sides indexes mapping them from tiles in packed cubemap | |
1222 | static void setCubeMap (const NCollection_Array1<TCollection_AsciiString>& theFileNames, | |
1223 | const Graphic3d_ValidatedCubeMapOrder theOrder = Graphic3d_CubeMapOrder::Default(), | |
1224 | bool theZIsInverted = false) | |
1225 | { | |
1226 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1227 | Handle(Graphic3d_CubeMap) aCubeMap; | |
1228 | ||
1229 | if (theFileNames.Size() == 1) | |
1230 | aCubeMap = new Graphic3d_CubeMapPacked(theFileNames[0], theOrder); | |
1231 | else | |
1232 | aCubeMap = new Graphic3d_CubeMapSeparate(theFileNames); | |
1233 | ||
1234 | aCubeMap->SetZInversion (theZIsInverted); | |
1235 | ||
1236 | aCubeMap->GetParams()->SetFilter(Graphic3d_TOTF_BILINEAR); | |
1237 | aCubeMap->GetParams()->SetRepeat(Standard_False); | |
1238 | aCubeMap->GetParams()->SetTextureUnit(Graphic3d_TextureUnit_EnvMap); | |
1239 | ||
1240 | aCurrentView->SetBackgroundCubeMap (aCubeMap, Standard_True); | |
1241 | } | |
1242 | ||
293211ae | 1243 | //! Sets the image as a background |
1244 | //! @param theImageFileName the filename of the image to be used as a background | |
1245 | //! @param theImageMode the fill type used for a background image | |
1246 | static void setImage (const Standard_CString theImageFileName, const Aspect_FillMethod theImageMode) | |
1247 | { | |
1248 | const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1249 | aCurrentView->SetBackgroundImage (theImageFileName, theImageMode, Standard_True); | |
1250 | } | |
1251 | ||
1252 | //! Sets the fill type used for a background image | |
1253 | //! @param theImageMode the fill type used for a background image | |
1254 | static void setImageMode (const Aspect_FillMethod theImageMode) | |
1255 | { | |
1256 | const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1257 | aCurrentView->SetBgImageStyle (theImageMode, Standard_True); | |
1258 | } | |
1259 | ||
1260 | //! Sets the gradient filling for a background | |
1261 | //! @param theColor1 the gradient starting color | |
1262 | //! @param theColor2 the gradient ending color | |
1263 | //! @param theGradientMode the fill method used for a background gradient filling | |
1264 | static void setGradient (const Quantity_Color& theColor1, | |
1265 | const Quantity_Color& theColor2, | |
1266 | const Aspect_GradientFillMethod theGradientMode) | |
1267 | { | |
1268 | const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1269 | aCurrentView->SetBgGradientColors (theColor1, theColor2, theGradientMode, Standard_True); | |
1270 | } | |
1271 | ||
1272 | //! Sets the fill method used for a background gradient filling | |
1273 | //! @param theGradientMode the fill method used for a background gradient filling | |
1274 | static void setGradientMode (const Aspect_GradientFillMethod theGradientMode) | |
1275 | { | |
1276 | const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1277 | aCurrentView->SetBgGradientStyle (theGradientMode, Standard_True); | |
1278 | } | |
1279 | ||
1280 | //! Sets the color used for filling a background | |
1281 | //! @param theColor the color used for filling a background | |
1282 | static void setColor (const Quantity_Color& theColor) | |
1283 | { | |
1284 | const Handle (V3d_View)& aCurrentView = ViewerTest::CurrentView(); | |
1285 | aCurrentView->SetBgGradientStyle (Aspect_GFM_NONE); | |
1286 | aCurrentView->SetBackgroundColor (theColor); | |
1287 | aCurrentView->Update(); | |
1288 | } | |
1289 | ||
1290 | //! Sets the gradient filling for a background in a default viewer | |
1291 | //! @param theColor1 the gradient starting color | |
1292 | //! @param theColor2 the gradient ending color | |
1293 | //! @param theGradientMode the fill method used for a background gradient filling | |
1294 | static void setDefaultGradient (const Quantity_Color& theColor1, | |
1295 | const Quantity_Color& theColor2, | |
1296 | const Aspect_GradientFillMethod theGradientMode) | |
1297 | { | |
1298 | ViewerTest_DefaultBackground.GradientColor1 = theColor1; | |
1299 | ViewerTest_DefaultBackground.GradientColor2 = theColor2; | |
1300 | ViewerTest_DefaultBackground.FillMethod = theGradientMode; | |
1301 | setDefaultGradient(); | |
1302 | } | |
1303 | ||
1304 | //! Sets the color used for filling a background in a default viewer | |
1305 | //! @param theColor the color used for filling a background | |
1306 | static void setDefaultColor (const Quantity_Color& theColor) | |
1307 | { | |
1308 | ViewerTest_DefaultBackground.GradientColor1 = Quantity_Color(); | |
1309 | ViewerTest_DefaultBackground.GradientColor2 = Quantity_Color(); | |
1310 | ViewerTest_DefaultBackground.FillMethod = Aspect_GFM_NONE; | |
1311 | ViewerTest_DefaultBackground.FlatColor = theColor; | |
1312 | setDefaultGradient(); | |
1313 | setDefaultColor(); | |
1314 | } | |
1315 | ||
1316 | //! Sets the gradient filling for a background in a default viewer. | |
1317 | //! Gradient settings are taken from ViewerTest_DefaultBackground structure | |
1318 | static void setDefaultGradient() | |
1319 | { | |
1320 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator | |
1321 | anInteractiveContextIterator (ViewerTest_myContexts); | |
1322 | anInteractiveContextIterator.More(); | |
1323 | anInteractiveContextIterator.Next()) | |
1324 | { | |
1325 | const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer(); | |
1326 | aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1, | |
1327 | ViewerTest_DefaultBackground.GradientColor2, | |
1328 | ViewerTest_DefaultBackground.FillMethod); | |
1329 | } | |
1330 | } | |
1331 | ||
1332 | //! Sets the color used for filling a background in a default viewer. | |
1333 | //! The color value is taken from ViewerTest_DefaultBackground structure | |
1334 | static void setDefaultColor() | |
1335 | { | |
1336 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator | |
1337 | anInteractiveContextIterator (ViewerTest_myContexts); | |
1338 | anInteractiveContextIterator.More(); | |
1339 | anInteractiveContextIterator.Next()) | |
1340 | { | |
1341 | const Handle (V3d_Viewer)& aViewer = anInteractiveContextIterator.Value()->CurrentViewer(); | |
1342 | aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor); | |
1343 | } | |
1344 | } | |
1345 | }; | |
1346 | ||
1347 | } // namespace | |
b12e1c7b | 1348 | |
625e1958 | 1349 | typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators; |
1350 | ||
1351 | Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators() | |
1352 | { | |
1353 | static ViewerTest_MapOfAISManipulators aMap; | |
1354 | return aMap; | |
1355 | } | |
1356 | ||
1357 | Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator() | |
1358 | { | |
1359 | ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); | |
1360 | for (; anIt.More(); anIt.Next()) | |
1361 | { | |
1362 | if (anIt.Value()->HasActiveMode()) | |
1363 | { | |
1364 | return anIt.Value(); | |
1365 | } | |
1366 | } | |
1367 | return NULL; | |
1368 | } | |
1369 | ||
7fd59977 | 1370 | //============================================================================== |
1371 | ||
57c28b61 | 1372 | #ifdef _WIN32 |
7fd59977 | 1373 | static LRESULT WINAPI ViewerWindowProc( |
1374 | HWND hwnd, | |
1375 | UINT uMsg, | |
1376 | WPARAM wParam, | |
1377 | LPARAM lParam ); | |
1378 | static LRESULT WINAPI AdvViewerWindowProc( | |
1379 | HWND hwnd, | |
1380 | UINT uMsg, | |
1381 | WPARAM wParam, | |
1382 | LPARAM lParam ); | |
1383 | #endif | |
1384 | ||
1385 | ||
1386 | //============================================================================== | |
1387 | //function : WClass | |
1388 | //purpose : | |
1389 | //============================================================================== | |
1390 | ||
ad03c234 | 1391 | const Handle(Standard_Transient)& ViewerTest::WClass() |
7fd59977 | 1392 | { |
ad03c234 | 1393 | static Handle(Standard_Transient) theWClass; |
58655684 | 1394 | #if defined(_WIN32) |
4fe56619 | 1395 | if (theWClass.IsNull()) |
1396 | { | |
7c65581d | 1397 | theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc, |
ad03c234 | 1398 | CS_VREDRAW | CS_HREDRAW, 0, 0, |
c85a994a | 1399 | ::LoadCursor (NULL, IDC_ARROW)); |
7fd59977 | 1400 | } |
1401 | #endif | |
1402 | return theWClass; | |
1403 | } | |
1404 | ||
18d715bd | 1405 | //============================================================================== |
1406 | //function : CreateName | |
1407 | //purpose : Create numerical name for new object in theMap | |
1408 | //============================================================================== | |
1409 | template <typename ObjectType> | |
1410 | TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap, | |
1411 | const TCollection_AsciiString& theDefaultString) | |
1412 | { | |
1413 | if (theObjectMap.IsEmpty()) | |
1414 | return theDefaultString + TCollection_AsciiString(1); | |
1415 | ||
1416 | Standard_Integer aNextKey = 1; | |
1417 | Standard_Boolean isFound = Standard_False; | |
1418 | while (!isFound) | |
1419 | { | |
1420 | TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey); | |
1421 | // Look for objects with default names | |
1422 | if (theObjectMap.IsBound1(aStringKey)) | |
1423 | { | |
1424 | aNextKey++; | |
1425 | } | |
1426 | else | |
1427 | isFound = Standard_True; | |
1428 | } | |
1429 | ||
1430 | return theDefaultString + TCollection_AsciiString(aNextKey); | |
1431 | } | |
1432 | ||
1433 | //============================================================================== | |
1434 | //structure : ViewerTest_Names | |
1435 | //purpose : Allow to operate with full view name: driverName/viewerName/viewName | |
1436 | //============================================================================== | |
1437 | struct ViewerTest_Names | |
1438 | { | |
1439 | private: | |
1440 | TCollection_AsciiString myDriverName; | |
1441 | TCollection_AsciiString myViewerName; | |
1442 | TCollection_AsciiString myViewName; | |
1443 | ||
1444 | public: | |
1445 | ||
1446 | const TCollection_AsciiString& GetDriverName () const | |
1447 | { | |
1448 | return myDriverName; | |
1449 | } | |
1450 | void SetDriverName (const TCollection_AsciiString& theDriverName) | |
1451 | { | |
1452 | myDriverName = theDriverName; | |
1453 | } | |
1454 | const TCollection_AsciiString& GetViewerName () const | |
1455 | { | |
1456 | return myViewerName; | |
1457 | } | |
1458 | void SetViewerName (const TCollection_AsciiString& theViewerName) | |
1459 | { | |
1460 | myViewerName = theViewerName; | |
1461 | } | |
1462 | const TCollection_AsciiString& GetViewName () const | |
1463 | { | |
1464 | return myViewName; | |
1465 | } | |
1466 | void SetViewName (const TCollection_AsciiString& theViewName) | |
1467 | { | |
1468 | myViewName = theViewName; | |
1469 | } | |
1470 | ||
1471 | //=========================================================================== | |
1472 | //function : Constructor for ViewerTest_Names | |
1473 | //purpose : Get view, viewer, driver names from custom string | |
1474 | //=========================================================================== | |
1475 | ||
1476 | ViewerTest_Names (const TCollection_AsciiString& theInputString) | |
1477 | { | |
1478 | TCollection_AsciiString aName(theInputString); | |
1479 | if (theInputString.IsEmpty()) | |
1480 | { | |
1481 | // Get current configuration | |
1482 | if (ViewerTest_myDrivers.IsEmpty()) | |
1483 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
1484 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
1485 | else | |
1486 | myDriverName = ViewerTest_myDrivers.Find2 | |
1487 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
1488 | ||
1489 | if(ViewerTest_myContexts.IsEmpty()) | |
1490 | { | |
1491 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
1492 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
1493 | } | |
1494 | else | |
c48e2889 | 1495 | { |
18d715bd | 1496 | myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext()); |
c48e2889 | 1497 | } |
18d715bd | 1498 | |
c48e2889 | 1499 | myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View")); |
18d715bd | 1500 | } |
1501 | else | |
1502 | { | |
1503 | // There is at least view name | |
1504 | Standard_Integer aParserNumber = 0; | |
1505 | for (Standard_Integer i = 0; i < 3; ++i) | |
1506 | { | |
1507 | Standard_Integer aParserPos = aName.SearchFromEnd("/"); | |
1508 | if(aParserPos != -1) | |
1509 | { | |
1510 | aParserNumber++; | |
1511 | aName.Split(aParserPos-1); | |
1512 | } | |
1513 | else | |
1514 | break; | |
1515 | } | |
1516 | if (aParserNumber == 0) | |
1517 | { | |
1518 | // Only view name | |
1519 | if (!ViewerTest::GetAISContext().IsNull()) | |
1520 | { | |
1521 | myDriverName = ViewerTest_myDrivers.Find2 | |
1522 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
1523 | myViewerName = ViewerTest_myContexts.Find2 | |
1524 | (ViewerTest::GetAISContext()); | |
1525 | } | |
1526 | else | |
1527 | { | |
1528 | // There is no opened contexts here, need to create names for viewer and driver | |
1529 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
1530 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
1531 | ||
1532 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
1533 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
1534 | } | |
1535 | myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString); | |
1536 | } | |
1537 | else if (aParserNumber == 1) | |
1538 | { | |
1539 | // Here is viewerName/viewName | |
1540 | if (!ViewerTest::GetAISContext().IsNull()) | |
1541 | myDriverName = ViewerTest_myDrivers.Find2 | |
1542 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
1543 | else | |
1544 | { | |
1545 | // There is no opened contexts here, need to create name for driver | |
1546 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
1547 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
1548 | } | |
1549 | myViewerName = TCollection_AsciiString(myDriverName + "/" + aName); | |
1550 | ||
1551 | myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString); | |
1552 | } | |
1553 | else | |
1554 | { | |
1555 | //Here is driverName/viewerName/viewName | |
1556 | myDriverName = TCollection_AsciiString(aName); | |
1557 | ||
1558 | TCollection_AsciiString aViewerName(theInputString); | |
1559 | aViewerName.Split(aViewerName.SearchFromEnd("/") - 1); | |
1560 | myViewerName = TCollection_AsciiString(aViewerName); | |
1561 | ||
1562 | myViewName = TCollection_AsciiString(theInputString); | |
1563 | } | |
1564 | } | |
1565 | } | |
1566 | }; | |
1567 | ||
1568 | //============================================================================== | |
1569 | //function : FindContextByView | |
1570 | //purpose : Find AIS_InteractiveContext by View | |
1571 | //============================================================================== | |
1572 | ||
1573 | Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView) | |
1574 | { | |
1575 | Handle(AIS_InteractiveContext) anAISContext; | |
1576 | ||
1577 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1578 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
1579 | { | |
1580 | if (anIter.Value()->CurrentViewer() == theView->Viewer()) | |
1581 | return anIter.Key2(); | |
1582 | } | |
1583 | return anAISContext; | |
1584 | } | |
1585 | ||
18d715bd | 1586 | //============================================================================== |
1587 | //function : IsWindowOverlapped | |
1588 | //purpose : Check if theWindow overlapp another view | |
1589 | //============================================================================== | |
1590 | ||
1591 | Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft, | |
1592 | const Standard_Integer thePxTop, | |
1593 | const Standard_Integer thePxRight, | |
1594 | const Standard_Integer thePxBottom, | |
1595 | TCollection_AsciiString& theViewId) | |
1596 | { | |
1597 | for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
1598 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
1599 | { | |
1600 | Standard_Integer aTop = 0, | |
1601 | aLeft = 0, | |
1602 | aRight = 0, | |
1603 | aBottom = 0; | |
1604 | anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom); | |
1605 | if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
1606 | (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) || | |
1607 | (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
1608 | (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom)) | |
1609 | { | |
1610 | theViewId = anIter.Key1(); | |
1611 | return Standard_True; | |
1612 | } | |
1613 | } | |
1614 | return Standard_False; | |
1615 | } | |
1616 | ||
1617 | // Workaround: to create and delete non-orthographic views outside ViewerTest | |
1618 | void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName) | |
1619 | { | |
1620 | ViewerTest_myViews.UnBind1 (theName); | |
1621 | } | |
1622 | ||
1623 | void ViewerTest::InitViewName (const TCollection_AsciiString& theName, | |
1624 | const Handle(V3d_View)& theView) | |
1625 | { | |
1626 | ViewerTest_myViews.Bind (theName, theView); | |
1627 | } | |
1628 | ||
1629 | TCollection_AsciiString ViewerTest::GetCurrentViewName () | |
1630 | { | |
1631 | return ViewerTest_myViews.Find2( ViewerTest::CurrentView()); | |
1632 | } | |
8693dfd0 | 1633 | |
1634 | //! Auxiliary tool performing continuous redraws of specified window. | |
1635 | class ViewerTest_ContinuousRedrawer | |
1636 | { | |
1637 | public: | |
1638 | //! Return global instance. | |
1639 | static ViewerTest_ContinuousRedrawer& Instance() | |
1640 | { | |
1641 | static ViewerTest_ContinuousRedrawer aRedrawer; | |
1642 | return aRedrawer; | |
1643 | } | |
1644 | public: | |
1645 | ||
1646 | //! Destructor. | |
1647 | ~ViewerTest_ContinuousRedrawer() | |
1648 | { | |
1649 | Stop(); | |
1650 | } | |
1651 | ||
1652 | //! Start thread. | |
1653 | void Start (const Handle(Aspect_Window)& theWindow, | |
1654 | Standard_Real theTargetFps) | |
1655 | { | |
1656 | if (myWindow != theWindow | |
1657 | || myTargetFps != theTargetFps) | |
1658 | { | |
1659 | Stop(); | |
1660 | myWindow = theWindow; | |
1661 | myTargetFps = theTargetFps; | |
1662 | } | |
1663 | if (myThread.GetId() == 0) | |
1664 | { | |
1665 | myToStop = false; | |
1666 | myThread.Run (this); | |
1667 | } | |
1668 | } | |
1669 | ||
1670 | //! Stop thread. | |
1671 | void Stop (const Handle(Aspect_Window)& theWindow = NULL) | |
1672 | { | |
1673 | if (!theWindow.IsNull() | |
1674 | && myWindow != theWindow) | |
1675 | { | |
1676 | return; | |
1677 | } | |
1678 | ||
1679 | { | |
1680 | Standard_Mutex::Sentry aLock (myMutex); | |
1681 | myToStop = true; | |
1682 | } | |
1683 | myThread.Wait(); | |
1684 | myToStop = false; | |
1685 | myWindow.Nullify(); | |
1686 | } | |
1687 | ||
1688 | private: | |
1689 | ||
1690 | //! Thread loop. | |
1691 | void doThreadLoop() | |
1692 | { | |
1693 | Handle(Aspect_DisplayConnection) aDisp = new Aspect_DisplayConnection(); | |
1694 | OSD_Timer aTimer; | |
1695 | aTimer.Start(); | |
1696 | Standard_Real aTimeOld = 0.0; | |
1697 | const Standard_Real aTargetDur = myTargetFps > 0.0 ? 1.0 / myTargetFps : -1.0; | |
1698 | for (;;) | |
1699 | { | |
1700 | { | |
1701 | Standard_Mutex::Sentry aLock (myMutex); | |
1702 | if (myToStop) | |
1703 | { | |
1704 | return; | |
1705 | } | |
1706 | } | |
1707 | if (myTargetFps > 0.0) | |
1708 | { | |
1709 | const Standard_Real aTimeNew = aTimer.ElapsedTime(); | |
1710 | const Standard_Real aDuration = aTimeNew - aTimeOld; | |
1711 | if (aDuration >= aTargetDur) | |
1712 | { | |
1713 | myWindow->InvalidateContent (aDisp); | |
1714 | aTimeOld = aTimeNew; | |
1715 | } | |
1716 | } | |
1717 | else | |
1718 | { | |
1719 | myWindow->InvalidateContent (aDisp); | |
1720 | } | |
1721 | ||
1722 | OSD::MilliSecSleep (1); | |
1723 | } | |
1724 | } | |
1725 | ||
1726 | //! Thread creation callback. | |
1727 | static Standard_Address doThreadWrapper (Standard_Address theData) | |
1728 | { | |
1729 | ViewerTest_ContinuousRedrawer* aThis = (ViewerTest_ContinuousRedrawer* )theData; | |
1730 | aThis->doThreadLoop(); | |
1731 | return 0; | |
1732 | } | |
1733 | ||
1734 | //! Empty constructor. | |
1735 | ViewerTest_ContinuousRedrawer() | |
1736 | : myThread (doThreadWrapper), | |
1737 | myTargetFps (0.0), | |
1738 | myToStop (false) {} | |
1739 | ||
1740 | private: | |
1741 | Handle(Aspect_Window) myWindow; | |
1742 | OSD_Thread myThread; | |
1743 | Standard_Mutex myMutex; | |
1744 | Standard_Real myTargetFps; | |
1745 | volatile bool myToStop; | |
1746 | }; | |
1747 | ||
7fd59977 | 1748 | //============================================================================== |
1749 | //function : ViewerInit | |
1750 | //purpose : Create the window viewer and initialize all the global variable | |
1751 | //============================================================================== | |
1752 | ||
18d715bd | 1753 | TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft, |
1754 | const Standard_Integer thePxTop, | |
1755 | const Standard_Integer thePxWidth, | |
1756 | const Standard_Integer thePxHeight, | |
9e04ccdc | 1757 | const TCollection_AsciiString& theViewName, |
1758 | const TCollection_AsciiString& theDisplayName, | |
1759 | const Handle(V3d_View)& theViewToClone) | |
7fd59977 | 1760 | { |
8c3c9904 | 1761 | // Default position and dimension of the viewer window. |
4fe56619 | 1762 | // Note that left top corner is set to be sufficiently small to have |
8c3c9904 | 1763 | // window fit in the small screens (actual for remote desktops, see #23003). |
4fe56619 | 1764 | // The position corresponds to the window's client area, thus some |
8c3c9904 | 1765 | // gap is added for window frame to be visible. |
1766 | Standard_Integer aPxLeft = 20; | |
1767 | Standard_Integer aPxTop = 40; | |
7fd59977 | 1768 | Standard_Integer aPxWidth = 409; |
1769 | Standard_Integer aPxHeight = 409; | |
18d715bd | 1770 | Standard_Boolean toCreateViewer = Standard_False; |
9e04ccdc | 1771 | if (!theViewToClone.IsNull()) |
1772 | { | |
1773 | theViewToClone->Window()->Size (aPxWidth, aPxHeight); | |
1774 | } | |
18d715bd | 1775 | |
58655684 | 1776 | Handle(OpenGl_GraphicDriver) aGraphicDriver; |
18d715bd | 1777 | ViewerTest_Names aViewNames(theViewName); |
1778 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ())) | |
1779 | aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View")); | |
1780 | ||
1781 | if (thePxLeft != 0) | |
1782 | aPxLeft = thePxLeft; | |
1783 | if (thePxTop != 0) | |
1784 | aPxTop = thePxTop; | |
1785 | if (thePxWidth != 0) | |
1786 | aPxWidth = thePxWidth; | |
1787 | if (thePxHeight != 0) | |
7fd59977 | 1788 | aPxHeight = thePxHeight; |
4269bd1b | 1789 | |
18d715bd | 1790 | // Get graphic driver (create it or get from another view) |
8693dfd0 | 1791 | const bool isNewDriver = !ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()); |
1792 | if (isNewDriver) | |
18d715bd | 1793 | { |
1794 | // Get connection string | |
58655684 | 1795 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
8693dfd0 | 1796 | if (!theDisplayName.IsEmpty()) |
1797 | { | |
1798 | SetDisplayConnection (new Aspect_DisplayConnection (theDisplayName)); | |
1799 | } | |
18d715bd | 1800 | else |
8693dfd0 | 1801 | { |
1802 | ::Display* aDispX = NULL; | |
1803 | // create dedicated display connection instead of reusing Tk connection | |
1804 | // so that to procede events independently through VProcessEvents()/ViewerMainLoop() callbacks | |
1805 | /*Draw_Interpretor& aCommands = Draw::GetInterpretor(); | |
1806 | Tcl_Interp* aTclInterp = aCommands.Interp(); | |
1807 | Tk_Window aMainWindow = Tk_MainWindow (aTclInterp); | |
1808 | aDispX = aMainWindow != NULL ? Tk_Display (aMainWindow) : NULL;*/ | |
1809 | SetDisplayConnection (new Aspect_DisplayConnection (aDispX)); | |
1810 | } | |
18d715bd | 1811 | #else |
498ce76b | 1812 | (void)theDisplayName; // avoid warning on unused argument |
18d715bd | 1813 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
1814 | #endif | |
14cb22a1 | 1815 | |
1816 | if (Draw_VirtualWindows) | |
1817 | { | |
1818 | // don't waste the time waiting for VSync when window is not displayed on the screen | |
1819 | ViewerTest_myDefaultCaps.swapInterval = 0; | |
1820 | // alternatively we can disable buffer swap at all, but this might be inappropriate for testing | |
1821 | //ViewerTest_myDefaultCaps.buffersNoSwap = true; | |
1822 | } | |
59515ca6 | 1823 | aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection(), false); |
58655684 | 1824 | aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps; |
59515ca6 | 1825 | aGraphicDriver->InitContext(); |
14cb22a1 | 1826 | |
18d715bd | 1827 | ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver); |
1828 | toCreateViewer = Standard_True; | |
1829 | } | |
1830 | else | |
1831 | { | |
58655684 | 1832 | aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName())); |
7fd59977 | 1833 | } |
1834 | ||
18d715bd | 1835 | //Dispose the window if input parameters are default |
1836 | if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0) | |
7fd59977 | 1837 | { |
18d715bd | 1838 | Standard_Integer aTop = 0, |
1839 | aLeft = 0, | |
1840 | aRight = 0, | |
1841 | aBottom = 0, | |
1842 | aScreenWidth = 0, | |
1843 | aScreenHeight = 0; | |
1844 | ||
1845 | // Get screen resolution | |
1846 | #if defined(_WIN32) || defined(__WIN32__) | |
1847 | RECT aWindowSize; | |
1848 | GetClientRect(GetDesktopWindow(), &aWindowSize); | |
1849 | aScreenHeight = aWindowSize.bottom; | |
1850 | aScreenWidth = aWindowSize.right; | |
1851 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1852 | GetCocoaScreenResolution (aScreenWidth, aScreenHeight); | |
1853 | #else | |
1854 | Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay()); | |
1855 | aScreenWidth = WidthOfScreen(aScreen); | |
1856 | aScreenHeight = HeightOfScreen(aScreen); | |
1857 | #endif | |
1858 | ||
1859 | TCollection_AsciiString anOverlappedViewId(""); | |
773f53f1 | 1860 | |
1861 | while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)) | |
dc3fe572 | 1862 | { |
18d715bd | 1863 | ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom); |
1864 | ||
1865 | if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId) | |
1866 | && aRight + 2*aPxWidth + 40 > aScreenWidth) | |
1867 | { | |
1868 | if (aBottom + aPxHeight + 40 > aScreenHeight) | |
1869 | { | |
1870 | aPxLeft = 20; | |
1871 | aPxTop = 40; | |
1872 | break; | |
1873 | } | |
1874 | aPxLeft = 20; | |
1875 | aPxTop = aBottom + 40; | |
1876 | } | |
1877 | else | |
1878 | aPxLeft = aRight + 20; | |
dc3fe572 | 1879 | } |
18d715bd | 1880 | } |
1881 | ||
1882 | // Get viewer name | |
1883 | TCollection_AsciiString aTitle("3D View - "); | |
1884 | aTitle = aTitle + aViewNames.GetViewName() + "(*)"; | |
1885 | ||
1886 | // Change name of current active window | |
49582f9d | 1887 | if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView()) |
18d715bd | 1888 | { |
49582f9d | 1889 | aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView)); |
18d715bd | 1890 | } |
1891 | ||
1892 | // Create viewer | |
eb4320f2 | 1893 | Handle(V3d_Viewer) a3DViewer; |
18d715bd | 1894 | // If it's the single view, we first look for empty context |
1895 | if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty()) | |
1896 | { | |
1897 | NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1898 | anIter(ViewerTest_myContexts); | |
1899 | if (anIter.More()) | |
1900 | ViewerTest::SetAISContext (anIter.Value()); | |
1901 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 1902 | } |
1903 | else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())) | |
1904 | { | |
1905 | ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName())); | |
1906 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 1907 | } |
eb4320f2 | 1908 | else if (a3DViewer.IsNull()) |
18d715bd | 1909 | { |
1910 | toCreateViewer = Standard_True; | |
6a24c6de | 1911 | a3DViewer = new V3d_Viewer(aGraphicDriver); |
f42753ed | 1912 | a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor); |
1913 | a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1, | |
1914 | ViewerTest_DefaultBackground.GradientColor2, | |
1915 | ViewerTest_DefaultBackground.FillMethod); | |
18d715bd | 1916 | } |
1917 | ||
1918 | // AIS context setup | |
1919 | if (ViewerTest::GetAISContext().IsNull() || | |
1920 | !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))) | |
1921 | { | |
e79a94b9 | 1922 | Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer); |
18d715bd | 1923 | ViewerTest::SetAISContext (aContext); |
1924 | ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext()); | |
1925 | } | |
1926 | else | |
e79a94b9 | 1927 | { |
18d715bd | 1928 | ViewerTest::ResetEventManager(); |
e79a94b9 | 1929 | } |
18d715bd | 1930 | |
1931 | // Create window | |
e79a94b9 | 1932 | #if defined(_WIN32) |
1933 | VT_GetWindow() = new WNT_Window (aTitle.ToCString(), | |
1934 | Handle(WNT_WClass)::DownCast (WClass()), | |
62e1beed | 1935 | Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW, |
e79a94b9 | 1936 | aPxLeft, aPxTop, |
1937 | aPxWidth, aPxHeight, | |
1938 | Quantity_NOC_BLACK); | |
4fe56619 | 1939 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
e79a94b9 | 1940 | VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(), |
1941 | aPxLeft, aPxTop, | |
1942 | aPxWidth, aPxHeight); | |
1943 | ViewerTest_SetCocoaEventManagerView (VT_GetWindow()); | |
7fd59977 | 1944 | #else |
e79a94b9 | 1945 | VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(), |
1946 | aTitle.ToCString(), | |
1947 | aPxLeft, aPxTop, | |
1948 | aPxWidth, aPxHeight); | |
7fd59977 | 1949 | #endif |
18d715bd | 1950 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); |
7fd59977 | 1951 | |
d09dda09 | 1952 | // View setup |
9e04ccdc | 1953 | Handle(V3d_View) aView; |
1954 | if (!theViewToClone.IsNull()) | |
1955 | { | |
2e93433e | 1956 | aView = new ViewerTest_V3dView (a3DViewer, theViewToClone); |
9e04ccdc | 1957 | } |
1958 | else | |
1959 | { | |
2e93433e | 1960 | aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView()); |
9e04ccdc | 1961 | } |
1962 | ||
d09dda09 | 1963 | aView->SetWindow (VT_GetWindow()); |
c3282ec1 | 1964 | ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer); |
4269bd1b | 1965 | |
18d715bd | 1966 | ViewerTest::CurrentView(aView); |
1967 | ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView); | |
7fd59977 | 1968 | |
18d715bd | 1969 | // Setup for X11 or NT |
1970 | OSWindowSetup(); | |
7fd59977 | 1971 | |
18d715bd | 1972 | // Set parameters for V3d_View and V3d_Viewer |
1973 | const Handle (V3d_View) aV3dView = ViewerTest::CurrentView(); | |
1974 | aV3dView->SetComputedMode(Standard_False); | |
7fd59977 | 1975 | |
18d715bd | 1976 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
1977 | if (toCreateViewer) | |
1978 | { | |
7fd59977 | 1979 | a3DViewer->SetDefaultLights(); |
1980 | a3DViewer->SetLightOn(); | |
18d715bd | 1981 | } |
7fd59977 | 1982 | |
8693dfd0 | 1983 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
1984 | if (isNewDriver) | |
1985 | { | |
1986 | ::Display* aDispX = GetDisplayConnection()->GetDisplay(); | |
1987 | Tcl_CreateFileHandler (XConnectionNumber (aDispX), TCL_READABLE, VProcessEvents, (ClientData )aDispX); | |
1988 | } | |
1989 | #endif | |
7fd59977 | 1990 | |
7fd59977 | 1991 | VT_GetWindow()->Map(); |
4269bd1b | 1992 | |
18d715bd | 1993 | // Set the handle of created view in the event manager |
1994 | ViewerTest::ResetEventManager(); | |
1995 | ||
4fe56619 | 1996 | ViewerTest::CurrentView()->Redraw(); |
18d715bd | 1997 | |
1998 | aView.Nullify(); | |
1999 | a3DViewer.Nullify(); | |
18d715bd | 2000 | |
2001 | return aViewNames.GetViewName(); | |
2002 | } | |
2003 | ||
4269bd1b | 2004 | //============================================================================== |
2005 | //function : RedrawAllViews | |
2006 | //purpose : Redraw all created views | |
2007 | //============================================================================== | |
2008 | void ViewerTest::RedrawAllViews() | |
2009 | { | |
2010 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
2011 | for (; aViewIt.More(); aViewIt.Next()) | |
2012 | { | |
2013 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
2014 | aView->Redraw(); | |
2015 | } | |
2016 | } | |
2017 | ||
7fd59977 | 2018 | //============================================================================== |
2019 | //function : Vinit | |
2020 | //purpose : Create the window viewer and initialize all the global variable | |
e79a94b9 | 2021 | // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event |
7fd59977 | 2022 | //============================================================================== |
2023 | ||
18d715bd | 2024 | static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 2025 | { |
e79a94b9 | 2026 | TCollection_AsciiString aViewName, aDisplayName; |
2027 | Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0; | |
9e04ccdc | 2028 | Handle(V3d_View) aCopyFrom; |
e79a94b9 | 2029 | TCollection_AsciiString aName, aValue; |
2e93433e | 2030 | int is2dMode = -1; |
e79a94b9 | 2031 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
18d715bd | 2032 | { |
e79a94b9 | 2033 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; |
2034 | TCollection_AsciiString anArgCase = anArg; | |
fd3f6bd0 | 2035 | anArgCase.LowerCase(); |
2036 | if (anArgIt + 1 < theArgsNb | |
2037 | && anArgCase == "-name") | |
2038 | { | |
2039 | aViewName = theArgVec[++anArgIt]; | |
2040 | } | |
2041 | else if (anArgIt + 1 < theArgsNb | |
2042 | && (anArgCase == "-left" | |
2043 | || anArgCase == "-l")) | |
2044 | { | |
2045 | aPxLeft = Draw::Atoi (theArgVec[++anArgIt]); | |
2046 | } | |
2047 | else if (anArgIt + 1 < theArgsNb | |
2048 | && (anArgCase == "-top" | |
2049 | || anArgCase == "-t")) | |
2050 | { | |
2051 | aPxTop = Draw::Atoi (theArgVec[++anArgIt]); | |
2052 | } | |
2053 | else if (anArgIt + 1 < theArgsNb | |
2054 | && (anArgCase == "-width" | |
2055 | || anArgCase == "-w")) | |
2056 | { | |
2057 | aPxWidth = Draw::Atoi (theArgVec[++anArgIt]); | |
2058 | } | |
2059 | else if (anArgIt + 1 < theArgsNb | |
2060 | && (anArgCase == "-height" | |
2061 | || anArgCase == "-h")) | |
18d715bd | 2062 | { |
fd3f6bd0 | 2063 | aPxHeight = Draw::Atoi (theArgVec[++anArgIt]); |
2064 | } | |
2065 | else if (anArgCase == "-exitonclose") | |
2066 | { | |
49582f9d | 2067 | ViewerTest_EventManager::ToExitOnCloseView() = true; |
fd3f6bd0 | 2068 | if (anArgIt + 1 < theArgsNb |
49582f9d | 2069 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToExitOnCloseView())) |
fd3f6bd0 | 2070 | { |
2071 | ++anArgIt; | |
2072 | } | |
2073 | } | |
2074 | else if (anArgCase == "-closeonescape" | |
2075 | || anArgCase == "-closeonesc") | |
2076 | { | |
49582f9d | 2077 | ViewerTest_EventManager::ToCloseViewOnEscape() = true; |
fd3f6bd0 | 2078 | if (anArgIt + 1 < theArgsNb |
49582f9d | 2079 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToCloseViewOnEscape())) |
fd3f6bd0 | 2080 | { |
2081 | ++anArgIt; | |
2082 | } | |
2083 | } | |
2e93433e | 2084 | else if (anArgCase == "-2d_mode" |
2085 | || anArgCase == "-2dmode" | |
2086 | || anArgCase == "-2d") | |
2087 | { | |
2088 | bool toEnable = true; | |
2089 | if (anArgIt + 1 < theArgsNb | |
2090 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable)) | |
2091 | { | |
2092 | ++anArgIt; | |
2093 | } | |
2094 | is2dMode = toEnable ? 1 : 0; | |
2095 | } | |
fd3f6bd0 | 2096 | else if (anArgIt + 1 < theArgsNb |
2097 | && (anArgCase == "-disp" | |
2098 | || anArgCase == "-display")) | |
2099 | { | |
2100 | aDisplayName = theArgVec[++anArgIt]; | |
2101 | } | |
9e04ccdc | 2102 | else if (!ViewerTest::CurrentView().IsNull() |
2103 | && aCopyFrom.IsNull() | |
2104 | && (anArgCase == "-copy" | |
2105 | || anArgCase == "-clone" | |
2106 | || anArgCase == "-cloneactive" | |
2107 | || anArgCase == "-cloneactiveview")) | |
2108 | { | |
2109 | aCopyFrom = ViewerTest::CurrentView(); | |
2110 | } | |
fd3f6bd0 | 2111 | // old syntax |
2112 | else if (ViewerTest::SplitParameter (anArg, aName, aValue)) | |
2113 | { | |
2114 | aName.LowerCase(); | |
2115 | if (aName == "name") | |
18d715bd | 2116 | { |
2117 | aViewName = aValue; | |
2118 | } | |
fd3f6bd0 | 2119 | else if (aName == "l" |
2120 | || aName == "left") | |
e79a94b9 | 2121 | { |
18d715bd | 2122 | aPxLeft = aValue.IntegerValue(); |
e79a94b9 | 2123 | } |
fd3f6bd0 | 2124 | else if (aName == "t" |
2125 | || aName == "top") | |
e79a94b9 | 2126 | { |
18d715bd | 2127 | aPxTop = aValue.IntegerValue(); |
e79a94b9 | 2128 | } |
fd3f6bd0 | 2129 | else if (aName == "disp" |
2130 | || aName == "display") | |
e79a94b9 | 2131 | { |
18d715bd | 2132 | aDisplayName = aValue; |
e79a94b9 | 2133 | } |
fd3f6bd0 | 2134 | else if (aName == "w" |
2135 | || aName == "width") | |
e79a94b9 | 2136 | { |
18d715bd | 2137 | aPxWidth = aValue.IntegerValue(); |
e79a94b9 | 2138 | } |
fd3f6bd0 | 2139 | else if (aName == "h" |
2140 | || aName == "height") | |
e79a94b9 | 2141 | { |
18d715bd | 2142 | aPxHeight = aValue.IntegerValue(); |
e79a94b9 | 2143 | } |
18d715bd | 2144 | else |
2145 | { | |
fd3f6bd0 | 2146 | std::cout << "Syntax error: unknown argument " << anArg << ".\n"; |
2147 | return 1; | |
18d715bd | 2148 | } |
2149 | } | |
e79a94b9 | 2150 | else if (aViewName.IsEmpty()) |
2151 | { | |
2152 | aViewName = anArg; | |
2153 | } | |
2154 | else | |
2155 | { | |
fd3f6bd0 | 2156 | std::cout << "Syntax error: unknown argument " << anArg << ".\n"; |
2157 | return 1; | |
e79a94b9 | 2158 | } |
18d715bd | 2159 | } |
2160 | ||
fd3f6bd0 | 2161 | #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) |
2162 | if (!aDisplayName.IsEmpty()) | |
2163 | { | |
2164 | aDisplayName.Clear(); | |
2165 | std::cout << "Warning: display parameter will be ignored.\n"; | |
2166 | } | |
2167 | #endif | |
2168 | ||
18d715bd | 2169 | ViewerTest_Names aViewNames (aViewName); |
e79a94b9 | 2170 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) |
18d715bd | 2171 | { |
e79a94b9 | 2172 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName(); |
2173 | theDi.Eval (aCommand.ToCString()); | |
2e93433e | 2174 | if (is2dMode != -1) |
2175 | { | |
2176 | ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1); | |
2177 | } | |
18d715bd | 2178 | return 0; |
2179 | } | |
2180 | ||
2181 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight, | |
9e04ccdc | 2182 | aViewName, aDisplayName, aCopyFrom); |
2e93433e | 2183 | if (is2dMode != -1) |
2184 | { | |
2185 | ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1); | |
2186 | } | |
e79a94b9 | 2187 | theDi << aViewId; |
7fd59977 | 2188 | return 0; |
2189 | } | |
2190 | ||
1eeef710 | 2191 | //! Parse HLR algo type. |
2192 | static Standard_Boolean parseHlrAlgoType (const char* theName, | |
2193 | Prs3d_TypeOfHLR& theType) | |
2194 | { | |
2195 | TCollection_AsciiString aName (theName); | |
2196 | aName.LowerCase(); | |
2197 | if (aName == "polyalgo") | |
2198 | { | |
2199 | theType = Prs3d_TOH_PolyAlgo; | |
2200 | } | |
2201 | else if (aName == "algo") | |
2202 | { | |
2203 | theType = Prs3d_TOH_Algo; | |
2204 | } | |
2205 | else | |
2206 | { | |
2207 | return Standard_False; | |
2208 | } | |
2209 | return Standard_True; | |
2210 | } | |
2211 | ||
0a768f56 | 2212 | //============================================================================== |
2213 | //function : VHLR | |
2214 | //purpose : hidden lines removal algorithm | |
2215 | //============================================================================== | |
2216 | ||
2217 | static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2218 | { | |
1eeef710 | 2219 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2220 | const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
2221 | if (aView.IsNull()) | |
0a768f56 | 2222 | { |
1eeef710 | 2223 | std::cerr << "Error: No opened viewer!\n"; |
0a768f56 | 2224 | return 1; |
2225 | } | |
2226 | ||
1eeef710 | 2227 | Standard_Boolean hasHlrOnArg = Standard_False; |
2228 | Standard_Boolean hasShowHiddenArg = Standard_False; | |
2229 | Standard_Boolean isHLROn = Standard_False; | |
2230 | Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine(); | |
2231 | Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet; | |
2232 | ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView); | |
2233 | for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter) | |
0a768f56 | 2234 | { |
1eeef710 | 2235 | TCollection_AsciiString anArg (argv[anArgIter]); |
2236 | anArg.LowerCase(); | |
2237 | if (anUpdateTool.parseRedrawMode (anArg)) | |
2238 | { | |
2239 | continue; | |
2240 | } | |
2241 | else if (anArg == "-showhidden" | |
2242 | && anArgIter + 1 < argc | |
2243 | && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden)) | |
2244 | { | |
2245 | ++anArgIter; | |
2246 | hasShowHiddenArg = Standard_True; | |
2247 | continue; | |
2248 | } | |
2249 | else if ((anArg == "-type" | |
2250 | || anArg == "-algo" | |
2251 | || anArg == "-algotype") | |
2252 | && anArgIter + 1 < argc | |
2253 | && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR)) | |
2254 | { | |
2255 | ++anArgIter; | |
2256 | continue; | |
2257 | } | |
2258 | else if (!hasHlrOnArg | |
2259 | && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn)) | |
2260 | { | |
2261 | hasHlrOnArg = Standard_True; | |
2262 | continue; | |
2263 | } | |
2264 | // old syntax | |
2265 | else if (!hasShowHiddenArg | |
2266 | && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden)) | |
2267 | { | |
2268 | hasShowHiddenArg = Standard_True; | |
2269 | continue; | |
2270 | } | |
2271 | else | |
2272 | { | |
2273 | std::cout << "Syntax error at '" << argv[anArgIter] << "'\n"; | |
2274 | return 1; | |
2275 | } | |
0a768f56 | 2276 | } |
1eeef710 | 2277 | if (!hasHlrOnArg) |
0a768f56 | 2278 | { |
1eeef710 | 2279 | di << "HLR: " << aView->ComputedMode() << "\n"; |
2280 | di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n"; | |
2281 | di << "HlrAlgo: "; | |
2282 | switch (aCtx->DefaultDrawer()->TypeOfHLR()) | |
2283 | { | |
2284 | case Prs3d_TOH_NotSet: di << "NotSet\n"; break; | |
2285 | case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break; | |
2286 | case Prs3d_TOH_Algo: di << "Algo\n"; break; | |
2287 | } | |
2288 | anUpdateTool.Invalidate(); | |
2289 | return 0; | |
0a768f56 | 2290 | } |
2291 | ||
1eeef710 | 2292 | Standard_Boolean toRecompute = Standard_False; |
2293 | if (aTypeOfHLR != Prs3d_TOH_NotSet | |
2294 | && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR()) | |
e9224045 | 2295 | { |
1eeef710 | 2296 | toRecompute = Standard_True; |
2297 | aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR); | |
2298 | } | |
2299 | if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine()) | |
2300 | { | |
2301 | toRecompute = Standard_True; | |
2302 | if (toShowHidden) | |
e9224045 | 2303 | { |
1eeef710 | 2304 | aCtx->DefaultDrawer()->EnableDrawHiddenLine(); |
e9224045 | 2305 | } |
2306 | else | |
2307 | { | |
1eeef710 | 2308 | aCtx->DefaultDrawer()->DisableDrawHiddenLine(); |
e9224045 | 2309 | } |
1eeef710 | 2310 | } |
e9224045 | 2311 | |
1eeef710 | 2312 | // redisplay shapes |
2313 | if (aView->ComputedMode() && isHLROn && toRecompute) | |
2314 | { | |
2315 | AIS_ListOfInteractive aListOfShapes; | |
2316 | aCtx->DisplayedObjects (aListOfShapes); | |
2317 | for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next()) | |
e9224045 | 2318 | { |
1eeef710 | 2319 | if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value())) |
e9224045 | 2320 | { |
1eeef710 | 2321 | aCtx->Redisplay (aShape, Standard_False); |
e9224045 | 2322 | } |
2323 | } | |
2324 | } | |
0a768f56 | 2325 | |
1eeef710 | 2326 | aView->SetComputedMode (isHLROn); |
0a768f56 | 2327 | return 0; |
2328 | } | |
2329 | ||
2330 | //============================================================================== | |
2331 | //function : VHLRType | |
2332 | //purpose : change type of using HLR algorithm | |
2333 | //============================================================================== | |
2334 | ||
1eeef710 | 2335 | static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
0a768f56 | 2336 | { |
1eeef710 | 2337 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2338 | const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
2339 | if (aView.IsNull()) | |
0a768f56 | 2340 | { |
1eeef710 | 2341 | std::cerr << "Error: No opened viewer!\n"; |
0a768f56 | 2342 | return 1; |
2343 | } | |
2344 | ||
1eeef710 | 2345 | Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet; |
2346 | ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView); | |
2347 | AIS_ListOfInteractive aListOfShapes; | |
2348 | for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter) | |
0a768f56 | 2349 | { |
1eeef710 | 2350 | TCollection_AsciiString anArg (argv[anArgIter]); |
2351 | anArg.LowerCase(); | |
2352 | if (anUpdateTool.parseRedrawMode (anArg)) | |
0a768f56 | 2353 | { |
1eeef710 | 2354 | continue; |
0a768f56 | 2355 | } |
1eeef710 | 2356 | else if ((anArg == "-type" |
2357 | || anArg == "-algo" | |
2358 | || anArg == "-algotype") | |
2359 | && anArgIter + 1 < argc | |
2360 | && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR)) | |
2361 | { | |
2362 | ++anArgIter; | |
2363 | continue; | |
2364 | } | |
2365 | // old syntax | |
2366 | else if (aTypeOfHLR == Prs3d_TOH_NotSet | |
2367 | && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR)) | |
2368 | { | |
2369 | continue; | |
2370 | } | |
2371 | else | |
0a768f56 | 2372 | { |
2373 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
1eeef710 | 2374 | TCollection_AsciiString aName (argv[anArgIter]); |
0a768f56 | 2375 | if (!aMap.IsBound2 (aName)) |
2376 | { | |
1eeef710 | 2377 | std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n"; |
2378 | return 1; | |
0a768f56 | 2379 | } |
1eeef710 | 2380 | |
2381 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName)); | |
2382 | if (aShape.IsNull()) | |
2383 | { | |
2384 | std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n"; | |
2385 | return 1; | |
2386 | } | |
2387 | aListOfShapes.Append (aShape); | |
2388 | continue; | |
0a768f56 | 2389 | } |
1eeef710 | 2390 | } |
2391 | if (aTypeOfHLR == Prs3d_TOH_NotSet) | |
2392 | { | |
2393 | std::cout << "Syntax error: wrong number of arguments!\n"; | |
2394 | return 1; | |
2395 | } | |
2396 | ||
2397 | const Standard_Boolean isGlobal = aListOfShapes.IsEmpty(); | |
2398 | if (isGlobal) | |
2399 | { | |
2400 | aCtx->DisplayedObjects (aListOfShapes); | |
2401 | aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR); | |
0a768f56 | 2402 | } |
2403 | ||
1eeef710 | 2404 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next()) |
2405 | { | |
2406 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
2407 | if (aShape.IsNull()) | |
2408 | { | |
2409 | continue; | |
2410 | } | |
2411 | ||
2412 | const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR | |
2413 | && aView->ComputedMode(); | |
2414 | if (!isGlobal | |
2415 | || aShape->TypeOfHLR() != aTypeOfHLR) | |
2416 | { | |
2417 | aShape->SetTypeOfHLR (aTypeOfHLR); | |
2418 | } | |
2419 | if (toUpdateShape) | |
2420 | { | |
2421 | aCtx->Redisplay (aShape, Standard_False); | |
2422 | } | |
2423 | } | |
0a768f56 | 2424 | return 0; |
2425 | } | |
2426 | ||
18d715bd | 2427 | //============================================================================== |
2428 | //function : FindViewIdByWindowHandle | |
2429 | //purpose : Find theView Id in the map of views by window handle | |
2430 | //============================================================================== | |
49582f9d | 2431 | #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
2432 | TCollection_AsciiString FindViewIdByWindowHandle (Aspect_Drawable theWindowHandle) | |
18d715bd | 2433 | { |
2434 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
2435 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
2436 | { | |
49582f9d | 2437 | Aspect_Drawable aWindowHandle = anIter.Value()->Window()->NativeHandle(); |
18d715bd | 2438 | if (aWindowHandle == theWindowHandle) |
2439 | return anIter.Key1(); | |
2440 | } | |
2441 | return TCollection_AsciiString(""); | |
2442 | } | |
2443 | #endif | |
2444 | ||
e084dbbc | 2445 | //! Make the view active |
2446 | void ActivateView (const TCollection_AsciiString& theViewName, | |
2447 | Standard_Boolean theToUpdate = Standard_True) | |
18d715bd | 2448 | { |
2449 | const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
e084dbbc | 2450 | if (aView.IsNull()) |
18d715bd | 2451 | { |
e084dbbc | 2452 | return; |
2453 | } | |
18d715bd | 2454 | |
e084dbbc | 2455 | Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView); |
2456 | if (!anAISContext.IsNull()) | |
2457 | { | |
49582f9d | 2458 | if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView()) |
e084dbbc | 2459 | { |
49582f9d | 2460 | aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView)); |
e084dbbc | 2461 | } |
2462 | ||
2463 | ViewerTest::CurrentView (aView); | |
2464 | ViewerTest::SetAISContext (anAISContext); | |
49582f9d | 2465 | aView->Window()->SetTitle (TCollection_AsciiString("3D View - ") + theViewName + "(*)"); |
1eeef710 | 2466 | #if defined(_WIN32) |
e084dbbc | 2467 | VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
18d715bd | 2468 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
e084dbbc | 2469 | VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
18d715bd | 2470 | #else |
e084dbbc | 2471 | VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
18d715bd | 2472 | #endif |
e084dbbc | 2473 | SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
2474 | if (theToUpdate) | |
2475 | { | |
18d715bd | 2476 | ViewerTest::CurrentView()->Redraw(); |
2477 | } | |
2478 | } | |
2479 | } | |
2480 | ||
0e93d9e5 | 2481 | //============================================================================== |
2482 | //function : RemoveView | |
2483 | //purpose : | |
2484 | //============================================================================== | |
2485 | void ViewerTest::RemoveView (const Handle(V3d_View)& theView, | |
2486 | const Standard_Boolean theToRemoveContext) | |
2487 | { | |
2488 | if (!ViewerTest_myViews.IsBound2 (theView)) | |
2489 | { | |
2490 | return; | |
2491 | } | |
2492 | ||
2493 | const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView); | |
2494 | RemoveView (aViewName, theToRemoveContext); | |
2495 | } | |
2496 | ||
18d715bd | 2497 | //============================================================================== |
2498 | //function : RemoveView | |
2499 | //purpose : Close and remove view from display, clear maps if neccessary | |
2500 | //============================================================================== | |
2501 | void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved) | |
2502 | { | |
2503 | if (!ViewerTest_myViews.IsBound1(theViewName)) | |
2504 | { | |
04232180 | 2505 | std::cout << "Wrong view name\n"; |
18d715bd | 2506 | return; |
2507 | } | |
2508 | ||
2509 | // Activate another view if it's active now | |
2510 | if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView()) | |
2511 | { | |
2512 | if (ViewerTest_myViews.Extent() > 1) | |
2513 | { | |
2514 | TCollection_AsciiString aNewViewName; | |
c48e2889 | 2515 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); |
2516 | anIter.More(); anIter.Next()) | |
2517 | { | |
18d715bd | 2518 | if (anIter.Key1() != theViewName) |
2519 | { | |
2520 | aNewViewName = anIter.Key1(); | |
2521 | break; | |
2522 | } | |
c48e2889 | 2523 | } |
2524 | ActivateView (aNewViewName); | |
18d715bd | 2525 | } |
2526 | else | |
2527 | { | |
e084dbbc | 2528 | VT_GetWindow().Nullify(); |
2529 | ViewerTest::CurrentView (Handle(V3d_View)()); | |
18d715bd | 2530 | if (isContextRemoved) |
2531 | { | |
2532 | Handle(AIS_InteractiveContext) anEmptyContext; | |
2533 | ViewerTest::SetAISContext(anEmptyContext); | |
2534 | } | |
2535 | } | |
2536 | } | |
2537 | ||
2538 | // Delete view | |
2539 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
2540 | Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView); | |
8693dfd0 | 2541 | ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance(); |
2542 | aRedrawer.Stop (aView->Window()); | |
18d715bd | 2543 | |
2544 | // Remove view resources | |
18d715bd | 2545 | ViewerTest_myViews.UnBind1(theViewName); |
851dacdb | 2546 | aView->Window()->Unmap(); |
18d715bd | 2547 | aView->Remove(); |
2548 | ||
2549 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
2550 | XFlush (GetDisplayConnection()->GetDisplay()); | |
2551 | #endif | |
2552 | ||
2553 | // Keep context opened only if the closed view is last to avoid | |
2554 | // unused empty contexts | |
2555 | if (!aCurrentContext.IsNull()) | |
2556 | { | |
2557 | // Check if there are more difined views in the viewer | |
2558 | aCurrentContext->CurrentViewer()->InitDefinedViews(); | |
2559 | if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews()) | |
2560 | { | |
2561 | // Remove driver if there is no viewers that use it | |
2562 | Standard_Boolean isRemoveDriver = Standard_True; | |
2563 | for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
2564 | anIter(ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
2565 | { | |
2566 | if (aCurrentContext != anIter.Key2() && | |
2567 | aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver()) | |
2568 | { | |
2569 | isRemoveDriver = Standard_False; | |
2570 | break; | |
2571 | } | |
2572 | } | |
2ec85268 | 2573 | |
2574 | aCurrentContext->RemoveAll (Standard_False); | |
18d715bd | 2575 | if(isRemoveDriver) |
2576 | { | |
2577 | ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver()); | |
2578 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
8693dfd0 | 2579 | Tcl_DeleteFileHandler (XConnectionNumber (aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); |
18d715bd | 2580 | #endif |
2581 | } | |
2582 | ||
2583 | ViewerTest_myContexts.UnBind2(aCurrentContext); | |
2584 | } | |
2585 | } | |
04232180 | 2586 | std::cout << "3D View - " << theViewName << " was deleted.\n"; |
49582f9d | 2587 | if (ViewerTest_EventManager::ToExitOnCloseView()) |
fd3f6bd0 | 2588 | { |
2589 | Draw_Interprete ("exit"); | |
2590 | } | |
18d715bd | 2591 | } |
2592 | ||
2593 | //============================================================================== | |
2594 | //function : VClose | |
2595 | //purpose : Remove the view defined by its name | |
2596 | //============================================================================== | |
2597 | ||
d0cc1cb7 | 2598 | static int VClose (Draw_Interpretor& /*theDi*/, |
2599 | Standard_Integer theArgsNb, | |
2600 | const char** theArgVec) | |
18d715bd | 2601 | { |
18d715bd | 2602 | NCollection_List<TCollection_AsciiString> aViewList; |
d0cc1cb7 | 2603 | if (theArgsNb > 1) |
18d715bd | 2604 | { |
d0cc1cb7 | 2605 | TCollection_AsciiString anArg (theArgVec[1]); |
2606 | anArg.UpperCase(); | |
2607 | if (anArg.IsEqual ("ALL") | |
2608 | || anArg.IsEqual ("*")) | |
2609 | { | |
2610 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); | |
2611 | anIter.More(); anIter.Next()) | |
2612 | { | |
2613 | aViewList.Append (anIter.Key1()); | |
2614 | } | |
2615 | if (aViewList.IsEmpty()) | |
2616 | { | |
2617 | std::cout << "No view to close\n"; | |
2618 | return 0; | |
2619 | } | |
2620 | } | |
2621 | else | |
18d715bd | 2622 | { |
d0cc1cb7 | 2623 | ViewerTest_Names aViewName (theArgVec[1]); |
2624 | if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName())) | |
2625 | { | |
2626 | std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n"; | |
2627 | return 1; | |
2628 | } | |
2629 | aViewList.Append (aViewName.GetViewName()); | |
18d715bd | 2630 | } |
2631 | } | |
2632 | else | |
2633 | { | |
d0cc1cb7 | 2634 | // close active view |
2635 | if (ViewerTest::CurrentView().IsNull()) | |
2636 | { | |
2637 | std::cerr << "No active view!\n"; | |
2638 | return 1; | |
2639 | } | |
2640 | aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); | |
18d715bd | 2641 | } |
2642 | ||
d0cc1cb7 | 2643 | Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1); |
18d715bd | 2644 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList); |
2645 | anIter.More(); anIter.Next()) | |
2646 | { | |
d0cc1cb7 | 2647 | ViewerTest::RemoveView (anIter.Value(), toRemoveContext); |
18d715bd | 2648 | } |
2649 | ||
2650 | return 0; | |
2651 | } | |
2652 | ||
2653 | //============================================================================== | |
2654 | //function : VActivate | |
2655 | //purpose : Activate the view defined by its ID | |
2656 | //============================================================================== | |
2657 | ||
2658 | static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
2659 | { | |
e084dbbc | 2660 | if (theArgsNb == 1) |
18d715bd | 2661 | { |
2662 | theDi.Eval("vviewlist"); | |
2663 | return 0; | |
2664 | } | |
2665 | ||
e084dbbc | 2666 | TCollection_AsciiString aNameString; |
2667 | Standard_Boolean toUpdate = Standard_True; | |
2668 | Standard_Boolean toActivate = Standard_True; | |
2669 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
18d715bd | 2670 | { |
e084dbbc | 2671 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
2672 | anArg.LowerCase(); | |
2673 | if (toUpdate | |
2674 | && anArg == "-noupdate") | |
2675 | { | |
2676 | toUpdate = Standard_False; | |
2677 | } | |
2678 | else if (toActivate | |
2679 | && aNameString.IsEmpty() | |
2680 | && anArg == "none") | |
2681 | { | |
49582f9d | 2682 | ViewerTest::CurrentView()->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); |
e084dbbc | 2683 | VT_GetWindow().Nullify(); |
2684 | ViewerTest::CurrentView (Handle(V3d_View)()); | |
2685 | ViewerTest::ResetEventManager(); | |
2686 | theDi << theArgVec[0] << ": all views are inactive\n"; | |
2687 | toActivate = Standard_False; | |
2688 | } | |
2689 | else if (toActivate | |
2690 | && aNameString.IsEmpty()) | |
2691 | { | |
2692 | aNameString = theArgVec[anArgIter]; | |
2693 | } | |
2694 | else | |
2695 | { | |
2696 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
2697 | return 1; | |
2698 | } | |
18d715bd | 2699 | } |
2700 | ||
e084dbbc | 2701 | if (!toActivate) |
2702 | { | |
2703 | return 0; | |
2704 | } | |
2705 | else if (aNameString.IsEmpty()) | |
2706 | { | |
2707 | std::cout << "Syntax error: wrong number of arguments\n"; | |
2708 | return 1; | |
2709 | } | |
18d715bd | 2710 | |
2711 | // Check if this view exists in the viewer with the driver | |
e084dbbc | 2712 | ViewerTest_Names aViewNames (aNameString); |
18d715bd | 2713 | if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName())) |
2714 | { | |
e084dbbc | 2715 | theDi << "Syntax error: wrong view name '" << aNameString << "'\n"; |
18d715bd | 2716 | return 1; |
2717 | } | |
2718 | ||
2719 | // Check if it is active already | |
2720 | if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName())) | |
2721 | { | |
2722 | theDi << theArgVec[0] << ": the view is active already\n"; | |
2723 | return 0; | |
2724 | } | |
2725 | ||
e084dbbc | 2726 | ActivateView (aViewNames.GetViewName(), toUpdate); |
18d715bd | 2727 | return 0; |
2728 | } | |
2729 | ||
2730 | //============================================================================== | |
2731 | //function : VViewList | |
2732 | //purpose : Print current list of views per viewer and graphic driver ID | |
2733 | // shared between viewers | |
2734 | //============================================================================== | |
2735 | ||
2736 | static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
2737 | { | |
2738 | if (theArgsNb > 2) | |
2739 | { | |
2740 | theDi << theArgVec[0] << ": Wrong number of command arguments\n" | |
29cb310a | 2741 | << "Usage: " << theArgVec[0] << " name"; |
18d715bd | 2742 | return 1; |
2743 | } | |
2744 | if (ViewerTest_myContexts.Size() < 1) | |
2745 | return 0; | |
2746 | ||
18d715bd | 2747 | Standard_Boolean isTreeView = |
29cb310a | 2748 | (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 )); |
18d715bd | 2749 | |
2750 | if (isTreeView) | |
c48e2889 | 2751 | { |
18d715bd | 2752 | theDi << theArgVec[0] <<":\n"; |
c48e2889 | 2753 | } |
18d715bd | 2754 | |
c48e2889 | 2755 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers); |
2756 | aDriverIter.More(); aDriverIter.Next()) | |
2757 | { | |
2758 | if (isTreeView) | |
2759 | theDi << aDriverIter.Key1() << ":\n"; | |
18d715bd | 2760 | |
c48e2889 | 2761 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator |
2762 | aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next()) | |
2763 | { | |
2764 | if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1) | |
18d715bd | 2765 | { |
c48e2889 | 2766 | if (isTreeView) |
18d715bd | 2767 | { |
c48e2889 | 2768 | TCollection_AsciiString aContextName(aContextIter.Key1()); |
2769 | theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n"; | |
2770 | } | |
18d715bd | 2771 | |
c48e2889 | 2772 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews); |
2773 | aViewIter.More(); aViewIter.Next()) | |
2774 | { | |
2775 | if (aViewIter.Key1().Search(aContextIter.Key1()) != -1) | |
18d715bd | 2776 | { |
c48e2889 | 2777 | TCollection_AsciiString aViewName(aViewIter.Key1()); |
2778 | if (isTreeView) | |
18d715bd | 2779 | { |
c48e2889 | 2780 | if (aViewIter.Value() == ViewerTest::CurrentView()) |
2781 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n"; | |
18d715bd | 2782 | else |
c48e2889 | 2783 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n"; |
2784 | } | |
2785 | else | |
2786 | { | |
2787 | theDi << aViewName << " "; | |
18d715bd | 2788 | } |
2789 | } | |
2790 | } | |
2791 | } | |
2792 | } | |
c48e2889 | 2793 | } |
18d715bd | 2794 | return 0; |
2795 | } | |
2796 | ||
7fd59977 | 2797 | //============================================================================== |
49582f9d | 2798 | //function : GetMousePosition |
2799 | //purpose : | |
7fd59977 | 2800 | //============================================================================== |
49582f9d | 2801 | void ViewerTest::GetMousePosition (Standard_Integer& theX, |
2802 | Standard_Integer& theY) | |
7fd59977 | 2803 | { |
49582f9d | 2804 | if (Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager()) |
4fe56619 | 2805 | { |
49582f9d | 2806 | theX = aViewCtrl->LastMousePosition().x(); |
2807 | theY = aViewCtrl->LastMousePosition().y(); | |
4fe56619 | 2808 | } |
7fd59977 | 2809 | } |
2810 | ||
44b8f2d6 | 2811 | //============================================================================== |
fc552d84 | 2812 | //function : VViewProj |
2813 | //purpose : Switch view projection | |
44b8f2d6 | 2814 | //============================================================================== |
fc552d84 | 2815 | static int VViewProj (Draw_Interpretor& , |
2816 | Standard_Integer theNbArgs, | |
2817 | const char** theArgVec) | |
44b8f2d6 | 2818 | { |
fc552d84 | 2819 | static Standard_Boolean isYup = Standard_False; |
2820 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
2821 | if (aView.IsNull()) | |
44b8f2d6 | 2822 | { |
fc552d84 | 2823 | std::cout << "Error: no active view\n"; |
44b8f2d6 | 2824 | return 1; |
2825 | } | |
2826 | ||
fc552d84 | 2827 | TCollection_AsciiString aCmdName (theArgVec[0]); |
2828 | Standard_Boolean isGeneralCmd = Standard_False; | |
2829 | if (aCmdName == "vfront") | |
2830 | { | |
2831 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup); | |
2832 | } | |
2833 | else if (aCmdName == "vback") | |
2834 | { | |
2835 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup); | |
2836 | } | |
2837 | else if (aCmdName == "vtop") | |
2838 | { | |
2839 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup); | |
2840 | } | |
2841 | else if (aCmdName == "vbottom") | |
2842 | { | |
2843 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup); | |
2844 | } | |
2845 | else if (aCmdName == "vleft") | |
2846 | { | |
2847 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup); | |
2848 | } | |
2849 | else if (aCmdName == "vright") | |
2850 | { | |
2851 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup); | |
2852 | } | |
2853 | else if (aCmdName == "vaxo") | |
2854 | { | |
2855 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup); | |
2856 | } | |
2857 | else | |
2858 | { | |
2859 | isGeneralCmd = Standard_True; | |
2860 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
2861 | { | |
2862 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); | |
2863 | anArgCase.LowerCase(); | |
2864 | if (anArgCase == "-zup") | |
2865 | { | |
2866 | isYup = Standard_False; | |
2867 | } | |
2868 | else if (anArgCase == "-yup") | |
2869 | { | |
2870 | isYup = Standard_True; | |
2871 | } | |
2872 | else if (anArgCase == "-front" | |
2873 | || anArgCase == "front" | |
2874 | || anArgCase == "-f" | |
2875 | || anArgCase == "f") | |
2876 | { | |
2877 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup); | |
2878 | } | |
2879 | else if (anArgCase == "-back" | |
2880 | || anArgCase == "back" | |
2881 | || anArgCase == "-b" | |
2882 | || anArgCase == "b") | |
2883 | { | |
2884 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup); | |
2885 | } | |
2886 | else if (anArgCase == "-top" | |
2887 | || anArgCase == "top" | |
2888 | || anArgCase == "-t" | |
2889 | || anArgCase == "t") | |
2890 | { | |
2891 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup); | |
2892 | } | |
2893 | else if (anArgCase == "-bottom" | |
2894 | || anArgCase == "bottom" | |
2895 | || anArgCase == "-bot" | |
2896 | || anArgCase == "bot" | |
2897 | || anArgCase == "-b" | |
2898 | || anArgCase == "b") | |
2899 | { | |
2900 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup); | |
2901 | } | |
2902 | else if (anArgCase == "-left" | |
2903 | || anArgCase == "left" | |
2904 | || anArgCase == "-l" | |
2905 | || anArgCase == "l") | |
2906 | { | |
2907 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup); | |
2908 | } | |
2909 | else if (anArgCase == "-right" | |
2910 | || anArgCase == "right" | |
2911 | || anArgCase == "-r" | |
2912 | || anArgCase == "r") | |
2913 | { | |
2914 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup); | |
2915 | } | |
2916 | else if (anArgCase == "-axoleft" | |
2917 | || anArgCase == "-leftaxo" | |
2918 | || anArgCase == "axoleft" | |
2919 | || anArgCase == "leftaxo") | |
2920 | { | |
2921 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoLeft : V3d_TypeOfOrientation_Zup_AxoLeft, isYup); | |
2922 | } | |
2923 | else if (anArgCase == "-axo" | |
2924 | || anArgCase == "axo" | |
2925 | || anArgCase == "-a" | |
2926 | || anArgCase == "a" | |
2927 | || anArgCase == "-axoright" | |
2928 | || anArgCase == "-rightaxo" | |
2929 | || anArgCase == "axoright" | |
2930 | || anArgCase == "rightaxo") | |
2931 | { | |
2932 | aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup); | |
2933 | } | |
2934 | else if (anArgCase == "+x") | |
2935 | { | |
2936 | aView->SetProj (V3d_Xpos, isYup); | |
2937 | } | |
2938 | else if (anArgCase == "-x") | |
2939 | { | |
2940 | aView->SetProj (V3d_Xneg, isYup); | |
2941 | } | |
2942 | else if (anArgCase == "+y") | |
2943 | { | |
2944 | aView->SetProj (V3d_Ypos, isYup); | |
2945 | } | |
2946 | else if (anArgCase == "-y") | |
2947 | { | |
2948 | aView->SetProj (V3d_Yneg, isYup); | |
2949 | } | |
2950 | else if (anArgCase == "+z") | |
2951 | { | |
2952 | aView->SetProj (V3d_Zpos, isYup); | |
2953 | } | |
2954 | else if (anArgCase == "-z") | |
2955 | { | |
2956 | aView->SetProj (V3d_Zneg, isYup); | |
2957 | } | |
2958 | else if (anArgCase == "+x+y+z") | |
2959 | { | |
2960 | aView->SetProj (V3d_XposYposZpos, isYup); | |
2961 | } | |
2962 | else if (anArgCase == "+x+y-z") | |
2963 | { | |
2964 | aView->SetProj (V3d_XposYposZneg, isYup); | |
2965 | } | |
2966 | else if (anArgCase == "+x-y+z") | |
2967 | { | |
2968 | aView->SetProj (V3d_XposYnegZpos, isYup); | |
2969 | } | |
2970 | else if (anArgCase == "+x-y-z") | |
2971 | { | |
2972 | aView->SetProj (V3d_XposYnegZneg, isYup); | |
2973 | } | |
2974 | else if (anArgCase == "-x+y+z") | |
2975 | { | |
2976 | aView->SetProj (V3d_XnegYposZpos, isYup); | |
2977 | } | |
2978 | else if (anArgCase == "-x+y-z") | |
2979 | { | |
2980 | aView->SetProj (V3d_XnegYposZneg, isYup); | |
2981 | } | |
2982 | else if (anArgCase == "-x-y+z") | |
2983 | { | |
2984 | aView->SetProj (V3d_XnegYnegZpos, isYup); | |
2985 | } | |
2986 | else if (anArgCase == "-x-y-z") | |
2987 | { | |
2988 | aView->SetProj (V3d_XnegYnegZneg, isYup); | |
2989 | } | |
2990 | else if (anArgCase == "+x+y") | |
2991 | { | |
2992 | aView->SetProj (V3d_XposYpos, isYup); | |
2993 | } | |
2994 | else if (anArgCase == "+x-y") | |
2995 | { | |
2996 | aView->SetProj (V3d_XposYneg, isYup); | |
2997 | } | |
2998 | else if (anArgCase == "-x+y") | |
2999 | { | |
3000 | aView->SetProj (V3d_XnegYpos, isYup); | |
3001 | } | |
3002 | else if (anArgCase == "-x-y") | |
3003 | { | |
3004 | aView->SetProj (V3d_XnegYneg, isYup); | |
3005 | } | |
3006 | else if (anArgCase == "+x+z") | |
3007 | { | |
3008 | aView->SetProj (V3d_XposZpos, isYup); | |
3009 | } | |
3010 | else if (anArgCase == "+x-z") | |
3011 | { | |
3012 | aView->SetProj (V3d_XposZneg, isYup); | |
3013 | } | |
3014 | else if (anArgCase == "-x+z") | |
3015 | { | |
3016 | aView->SetProj (V3d_XnegZpos, isYup); | |
3017 | } | |
3018 | else if (anArgCase == "-x-z") | |
3019 | { | |
3020 | aView->SetProj (V3d_XnegZneg, isYup); | |
3021 | } | |
3022 | else if (anArgCase == "+y+z") | |
3023 | { | |
3024 | aView->SetProj (V3d_YposZpos, isYup); | |
3025 | } | |
3026 | else if (anArgCase == "+y-z") | |
3027 | { | |
3028 | aView->SetProj (V3d_YposZneg, isYup); | |
3029 | } | |
3030 | else if (anArgCase == "-y+z") | |
3031 | { | |
3032 | aView->SetProj (V3d_YnegZpos, isYup); | |
3033 | } | |
3034 | else if (anArgCase == "-y-z") | |
3035 | { | |
3036 | aView->SetProj (V3d_YnegZneg, isYup); | |
3037 | } | |
3038 | else if (anArgIter + 1 < theNbArgs | |
3039 | && anArgCase == "-frame" | |
3040 | && TCollection_AsciiString (theArgVec[anArgIter + 1]).Length() == 4) | |
3041 | { | |
3042 | TCollection_AsciiString aFrameDef (theArgVec[++anArgIter]); | |
3043 | aFrameDef.LowerCase(); | |
3044 | gp_Dir aRight, anUp; | |
3045 | if (aFrameDef.Value (2) == aFrameDef.Value (4)) | |
3046 | { | |
3047 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
3048 | return 1; | |
3049 | } | |
44b8f2d6 | 3050 | |
fc552d84 | 3051 | if (aFrameDef.Value (2) == 'x') |
3052 | { | |
3053 | aRight = aFrameDef.Value (1) == '+' ? gp::DX() : -gp::DX(); | |
3054 | } | |
3055 | else if (aFrameDef.Value (2) == 'y') | |
3056 | { | |
3057 | aRight = aFrameDef.Value (1) == '+' ? gp::DY() : -gp::DY(); | |
3058 | } | |
3059 | else if (aFrameDef.Value (2) == 'z') | |
3060 | { | |
3061 | aRight = aFrameDef.Value (1) == '+' ? gp::DZ() : -gp::DZ(); | |
3062 | } | |
3063 | else | |
3064 | { | |
3065 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
3066 | return 1; | |
3067 | } | |
7fd59977 | 3068 | |
fc552d84 | 3069 | if (aFrameDef.Value (4) == 'x') |
3070 | { | |
3071 | anUp = aFrameDef.Value (3) == '+' ? gp::DX() : -gp::DX(); | |
3072 | } | |
3073 | else if (aFrameDef.Value (4) == 'y') | |
3074 | { | |
3075 | anUp = aFrameDef.Value (3) == '+' ? gp::DY() : -gp::DY(); | |
3076 | } | |
3077 | else if (aFrameDef.Value (4) == 'z') | |
3078 | { | |
3079 | anUp = aFrameDef.Value (3) == '+' ? gp::DZ() : -gp::DZ(); | |
3080 | } | |
3081 | else | |
3082 | { | |
3083 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
3084 | return 1; | |
3085 | } | |
44b8f2d6 | 3086 | |
fc552d84 | 3087 | const Handle(Graphic3d_Camera)& aCamera = aView->Camera(); |
3088 | const gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin()); | |
3089 | const gp_Dir aDir = anUp.Crossed (aRight); | |
3090 | aCamera->SetCenter (gp_Pnt (0, 0, 0)); | |
3091 | aCamera->SetDirection (aDir); | |
3092 | aCamera->SetUp (anUp); | |
3093 | aCamera->OrthogonalizeUp(); | |
44b8f2d6 | 3094 | |
fc552d84 | 3095 | aView->Panning (anOriginVCS.X(), anOriginVCS.Y()); |
3096 | aView->Update(); | |
3097 | } | |
3098 | else | |
3099 | { | |
3100 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
3101 | return 1; | |
3102 | } | |
3103 | } | |
3104 | } | |
44b8f2d6 | 3105 | |
fc552d84 | 3106 | if (!isGeneralCmd |
3107 | && theNbArgs != 1) | |
3108 | { | |
3109 | std::cout << "Syntax error: wrong number of arguments\n"; | |
3110 | return 1; | |
3111 | } | |
3112 | return 0; | |
7fd59977 | 3113 | } |
3114 | ||
3115 | //============================================================================== | |
3116 | //function : VHelp | |
3117 | //purpose : Dsiplay help on viewer Keyboead and mouse commands | |
3118 | //Draw arg : No args | |
3119 | //============================================================================== | |
3120 | ||
3121 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) | |
3122 | { | |
586db386 | 3123 | di << "=========================\n"; |
3124 | di << "F : FitAll\n"; | |
3125 | di << "T : TopView\n"; | |
3126 | di << "B : BottomView\n"; | |
3127 | di << "R : RightView\n"; | |
3128 | di << "L : LeftView\n"; | |
3129 | di << "A : AxonometricView\n"; | |
3130 | di << "D : ResetView\n"; | |
3131 | ||
3132 | di << "=========================\n"; | |
3133 | di << "S : Shading\n"; | |
3134 | di << "W : Wireframe\n"; | |
49582f9d | 3135 | di << "H : HiddenLineRemoval\n"; |
586db386 | 3136 | di << "U : Unset display mode\n"; |
3137 | di << "Delete : Remove selection from viewer\n"; | |
3138 | ||
3139 | di << "=========================\n"; | |
3140 | di << "Selection mode \n"; | |
3141 | di << "0 : Shape\n"; | |
3142 | di << "1 : Vertex\n"; | |
3143 | di << "2 : Edge\n"; | |
3144 | di << "3 : Wire\n"; | |
3145 | di << "4 : Face\n"; | |
3146 | di << "5 : Shell\n"; | |
3147 | di << "6 : Solid\n"; | |
3148 | di << "7 : Compound\n"; | |
3149 | ||
3150 | di << "=========================\n"; | |
49582f9d | 3151 | di << "< : Hilight next detected\n"; |
3152 | di << "> : Hilight previous detected\n"; | |
7fd59977 | 3153 | |
3154 | return 0; | |
3155 | } | |
3156 | ||
57c28b61 | 3157 | #ifdef _WIN32 |
7fd59977 | 3158 | |
49582f9d | 3159 | static LRESULT WINAPI AdvViewerWindowProc (HWND theWinHandle, |
3160 | UINT theMsg, | |
3161 | WPARAM wParam, | |
3162 | LPARAM lParam ) | |
7fd59977 | 3163 | { |
49582f9d | 3164 | if (ViewerTest_myViews.IsEmpty()) |
3165 | { | |
3166 | return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam); | |
3167 | } | |
7fd59977 | 3168 | |
49582f9d | 3169 | switch (theMsg) |
3170 | { | |
18d715bd | 3171 | case WM_CLOSE: |
49582f9d | 3172 | { |
3173 | // Delete view from map of views | |
3174 | ViewerTest::RemoveView (FindViewIdByWindowHandle (theWinHandle)); | |
3175 | return 0; | |
3176 | } | |
18d715bd | 3177 | case WM_ACTIVATE: |
49582f9d | 3178 | { |
3179 | if (LOWORD(wParam) == WA_CLICKACTIVE | |
3180 | || LOWORD(wParam) == WA_ACTIVE | |
3181 | || ViewerTest::CurrentView().IsNull()) | |
18d715bd | 3182 | { |
3183 | // Activate inactive window | |
49582f9d | 3184 | if (VT_GetWindow().IsNull() |
3185 | || (HWND )VT_GetWindow()->HWindow() != theWinHandle) | |
625e1958 | 3186 | { |
49582f9d | 3187 | ActivateView (FindViewIdByWindowHandle (theWinHandle)); |
625e1958 | 3188 | } |
7fd59977 | 3189 | } |
7fd59977 | 3190 | break; |
49582f9d | 3191 | } |
7fd59977 | 3192 | default: |
49582f9d | 3193 | { |
3194 | return ViewerWindowProc (theWinHandle, theMsg, wParam, lParam); | |
7fd59977 | 3195 | } |
7fd59977 | 3196 | } |
49582f9d | 3197 | return 0; |
7fd59977 | 3198 | } |
3199 | ||
49582f9d | 3200 | static LRESULT WINAPI ViewerWindowProc (HWND theWinHandle, |
3201 | UINT theMsg, | |
3202 | WPARAM wParam, | |
3203 | LPARAM lParam) | |
7fd59977 | 3204 | { |
f978241f | 3205 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); |
3206 | if (aView.IsNull()) | |
3207 | { | |
49582f9d | 3208 | return DefWindowProcW (theWinHandle, theMsg, wParam, lParam); |
f978241f | 3209 | } |
7fd59977 | 3210 | |
49582f9d | 3211 | switch (theMsg) |
3212 | { | |
7fd59977 | 3213 | case WM_PAINT: |
49582f9d | 3214 | { |
3215 | PAINTSTRUCT aPaint; | |
3216 | BeginPaint(theWinHandle, &aPaint); | |
3217 | EndPaint (theWinHandle, &aPaint); | |
3218 | ViewerTest::CurrentEventManager()->ProcessExpose(); | |
7fd59977 | 3219 | break; |
49582f9d | 3220 | } |
7fd59977 | 3221 | case WM_SIZE: |
49582f9d | 3222 | { |
3223 | ViewerTest::CurrentEventManager()->ProcessConfigure(); | |
7fd59977 | 3224 | break; |
49582f9d | 3225 | } |
f978241f | 3226 | case WM_MOVE: |
3227 | case WM_MOVING: | |
3228 | case WM_SIZING: | |
49582f9d | 3229 | { |
f978241f | 3230 | switch (aView->RenderingParams().StereoMode) |
3231 | { | |
3232 | case Graphic3d_StereoMode_RowInterlaced: | |
3233 | case Graphic3d_StereoMode_ColumnInterlaced: | |
3234 | case Graphic3d_StereoMode_ChessBoard: | |
49582f9d | 3235 | { |
3236 | // track window moves to reverse stereo pair | |
3237 | aView->MustBeResized(); | |
3238 | aView->Update(); | |
f978241f | 3239 | break; |
49582f9d | 3240 | } |
f978241f | 3241 | default: |
3242 | break; | |
3243 | } | |
3244 | break; | |
49582f9d | 3245 | } |
3246 | case WM_KEYUP: | |
7fd59977 | 3247 | case WM_KEYDOWN: |
49582f9d | 3248 | { |
3249 | const Aspect_VKey aVKey = WNT_Window::VirtualKeyFromNative ((Standard_Integer )wParam); | |
3250 | if (aVKey != Aspect_VKey_UNKNOWN) | |
4fe56619 | 3251 | { |
49582f9d | 3252 | const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime(); |
3253 | if (theMsg == WM_KEYDOWN) | |
f978241f | 3254 | { |
49582f9d | 3255 | ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp); |
f978241f | 3256 | } |
49582f9d | 3257 | else |
f978241f | 3258 | { |
49582f9d | 3259 | ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp); |
f978241f | 3260 | } |
49582f9d | 3261 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); |
7fd59977 | 3262 | } |
3263 | break; | |
49582f9d | 3264 | } |
7fd59977 | 3265 | case WM_LBUTTONUP: |
3266 | case WM_MBUTTONUP: | |
3267 | case WM_RBUTTONUP: | |
7fd59977 | 3268 | case WM_LBUTTONDOWN: |
3269 | case WM_MBUTTONDOWN: | |
3270 | case WM_RBUTTONDOWN: | |
49582f9d | 3271 | { |
3272 | const Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam)); | |
3273 | const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam); | |
3274 | Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE; | |
3275 | switch (theMsg) | |
7fd59977 | 3276 | { |
49582f9d | 3277 | case WM_LBUTTONUP: |
3278 | case WM_LBUTTONDOWN: | |
3279 | aButton = Aspect_VKeyMouse_LeftButton; | |
3280 | break; | |
3281 | case WM_MBUTTONUP: | |
3282 | case WM_MBUTTONDOWN: | |
3283 | aButton = Aspect_VKeyMouse_MiddleButton; | |
3284 | break; | |
3285 | case WM_RBUTTONUP: | |
3286 | case WM_RBUTTONDOWN: | |
3287 | aButton = Aspect_VKeyMouse_RightButton; | |
3288 | break; | |
7fd59977 | 3289 | } |
49582f9d | 3290 | if (theMsg == WM_LBUTTONDOWN |
3291 | || theMsg == WM_MBUTTONDOWN | |
3292 | || theMsg == WM_RBUTTONDOWN) | |
f978241f | 3293 | { |
49582f9d | 3294 | if (aButton == Aspect_VKeyMouse_LeftButton) |
f978241f | 3295 | { |
49582f9d | 3296 | TheIsAnimating = Standard_False; |
f978241f | 3297 | } |
49582f9d | 3298 | |
3299 | SetFocus (theWinHandle); | |
3300 | SetCapture(theWinHandle); | |
3301 | ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false); | |
f978241f | 3302 | } |
3303 | else | |
3304 | { | |
49582f9d | 3305 | ReleaseCapture(); |
3306 | ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false); | |
f978241f | 3307 | } |
49582f9d | 3308 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); |
f978241f | 3309 | break; |
3310 | } | |
49582f9d | 3311 | case WM_MOUSEWHEEL: |
3312 | { | |
3313 | const int aDelta = GET_WHEEL_DELTA_WPARAM (wParam); | |
3314 | const Standard_Real aDeltaF = Standard_Real(aDelta) / Standard_Real(WHEEL_DELTA); | |
3315 | const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (wParam); | |
3316 | Graphic3d_Vec2i aPos (int(short(LOWORD(lParam))), int(short(HIWORD(lParam)))); | |
3317 | POINT aCursorPnt = { aPos.x(), aPos.y() }; | |
3318 | if (ScreenToClient (theWinHandle, &aCursorPnt)) | |
7fd59977 | 3319 | { |
49582f9d | 3320 | aPos.SetValues (aCursorPnt.x, aCursorPnt.y); |
3321 | } | |
7fd59977 | 3322 | |
49582f9d | 3323 | ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags)); |
3324 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); | |
3325 | break; | |
3326 | } | |
3327 | case WM_MOUSEMOVE: | |
3328 | { | |
3329 | Graphic3d_Vec2i aPos (LOWORD(lParam), HIWORD(lParam)); | |
3330 | Aspect_VKeyMouse aButtons = WNT_Window::MouseButtonsFromEvent (wParam); | |
3331 | Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent(wParam); | |
7fd59977 | 3332 | |
49582f9d | 3333 | // don't make a slide-show from input events - fetch the actual mouse cursor position |
3334 | CURSORINFO aCursor; | |
3335 | aCursor.cbSize = sizeof(aCursor); | |
3336 | if (::GetCursorInfo (&aCursor) != FALSE) | |
3337 | { | |
3338 | POINT aCursorPnt = { aCursor.ptScreenPos.x, aCursor.ptScreenPos.y }; | |
3339 | if (ScreenToClient (theWinHandle, &aCursorPnt)) | |
3340 | { | |
3341 | // as we override mouse position, we need overriding also mouse state | |
3342 | aPos.SetValues (aCursorPnt.x, aCursorPnt.y); | |
3343 | aButtons = WNT_Window::MouseButtonsAsync(); | |
3344 | aFlags = WNT_Window::MouseKeyFlagsAsync(); | |
3345 | } | |
3346 | } | |
7fd59977 | 3347 | |
49582f9d | 3348 | if (VT_GetWindow().IsNull() |
3349 | || (HWND )VT_GetWindow()->HWindow() != theWinHandle) | |
3350 | { | |
3351 | // mouse move events come also for inactive windows | |
3352 | break; | |
7fd59977 | 3353 | } |
7fd59977 | 3354 | |
49582f9d | 3355 | ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false); |
3356 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true); | |
3357 | break; | |
3358 | } | |
7fd59977 | 3359 | default: |
49582f9d | 3360 | { |
3361 | return DefWindowProcW (theWinHandle, theMsg, wParam, lParam); | |
7fd59977 | 3362 | } |
49582f9d | 3363 | } |
3364 | return 0L; | |
7fd59977 | 3365 | } |
3366 | ||
7fd59977 | 3367 | //============================================================================== |
3368 | //function : ViewerMainLoop | |
3369 | //purpose : Get a Event on the view and dispatch it | |
3370 | //============================================================================== | |
3371 | ||
49582f9d | 3372 | int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec) |
7fd59977 | 3373 | { |
49582f9d | 3374 | Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager(); |
3375 | if (aViewCtrl.IsNull() | |
3376 | || theNbArgs < 4) | |
3377 | { | |
3378 | return 0; | |
3379 | } | |
7fd59977 | 3380 | |
49582f9d | 3381 | aViewCtrl->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]); |
7fd59977 | 3382 | |
49582f9d | 3383 | std::cout << "Start picking\n"; |
7fd59977 | 3384 | |
49582f9d | 3385 | MSG aMsg; |
3386 | aMsg.wParam = 1; | |
3387 | while (aViewCtrl->ToPickPoint()) | |
3388 | { | |
3389 | // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 | |
3390 | if (GetMessageW (&aMsg, NULL, 0, 0)) | |
3391 | { | |
3392 | TranslateMessage (&aMsg); | |
3393 | DispatchMessageW (&aMsg); | |
7fd59977 | 3394 | } |
7fd59977 | 3395 | } |
3396 | ||
49582f9d | 3397 | std::cout << "Picking done\n"; |
3398 | return 0; | |
7fd59977 | 3399 | } |
3400 | ||
4fe56619 | 3401 | #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 3402 | |
3403 | int min( int a, int b ) | |
3404 | { | |
3405 | if( a<b ) | |
3406 | return a; | |
3407 | else | |
3408 | return b; | |
3409 | } | |
3410 | ||
3411 | int max( int a, int b ) | |
3412 | { | |
3413 | if( a>b ) | |
3414 | return a; | |
3415 | else | |
3416 | return b; | |
3417 | } | |
3418 | ||
49582f9d | 3419 | int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec) |
4269bd1b | 3420 | { |
18d715bd | 3421 | static XEvent aReport; |
49582f9d | 3422 | const Standard_Boolean toPick = theNbArgs > 0; |
3423 | if (theNbArgs > 0) | |
3424 | { | |
3425 | if (ViewerTest::CurrentEventManager().IsNull()) | |
3426 | { | |
3427 | return 0; | |
3428 | } | |
3429 | ViewerTest::CurrentEventManager()->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]); | |
3430 | } | |
3431 | ||
8693dfd0 | 3432 | Display* aDisplay = GetDisplayConnection()->GetDisplay(); |
18d715bd | 3433 | XNextEvent (aDisplay, &aReport); |
7fd59977 | 3434 | |
18d715bd | 3435 | // Handle event for the chosen display connection |
8693dfd0 | 3436 | switch (aReport.type) |
3437 | { | |
3438 | case ClientMessage: | |
3439 | { | |
3440 | if ((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW)) | |
3441 | { | |
3442 | // Close the window | |
3443 | ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window)); | |
3444 | return toPick ? 0 : 1; | |
3445 | } | |
3446 | break; | |
3447 | } | |
3448 | case FocusIn: | |
3449 | { | |
3450 | // Activate inactive view | |
49582f9d | 3451 | Window aWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0; |
8693dfd0 | 3452 | if (aWindow != aReport.xfocus.window) |
3453 | { | |
3454 | ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window)); | |
3455 | } | |
3456 | break; | |
3457 | } | |
3458 | case Expose: | |
3459 | { | |
49582f9d | 3460 | Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0; |
8693dfd0 | 3461 | if (anXWindow == aReport.xexpose.window) |
3462 | { | |
49582f9d | 3463 | ViewerTest::CurrentEventManager()->ProcessExpose(); |
8693dfd0 | 3464 | } |
3465 | ||
3466 | // remove all the ExposureMask and process them at once | |
3467 | for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents) | |
3468 | { | |
3469 | if (!XCheckWindowEvent (aDisplay, anXWindow, ExposureMask, &aReport)) | |
18d715bd | 3470 | { |
8693dfd0 | 3471 | break; |
18d715bd | 3472 | } |
8693dfd0 | 3473 | } |
3474 | ||
3475 | break; | |
3476 | } | |
3477 | case ConfigureNotify: | |
3478 | { | |
3479 | // remove all the StructureNotifyMask and process them at once | |
49582f9d | 3480 | Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0; |
8693dfd0 | 3481 | for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents) |
3482 | { | |
3483 | if (!XCheckWindowEvent (aDisplay, anXWindow, StructureNotifyMask, &aReport)) | |
3484 | { | |
3485 | break; | |
3486 | } | |
3487 | } | |
3488 | ||
3489 | if (anXWindow == aReport.xconfigure.window) | |
3490 | { | |
49582f9d | 3491 | ViewerTest::CurrentEventManager()->ProcessConfigure(); |
8693dfd0 | 3492 | } |
3493 | break; | |
3494 | } | |
3495 | case KeyPress: | |
49582f9d | 3496 | case KeyRelease: |
8693dfd0 | 3497 | { |
49582f9d | 3498 | XKeyEvent* aKeyEvent = (XKeyEvent* )&aReport; |
3499 | const KeySym aKeySym = XLookupKeysym (aKeyEvent, 0); | |
3500 | const Aspect_VKey aVKey = Xw_Window::VirtualKeyFromNative (aKeySym); | |
3501 | if (aVKey != Aspect_VKey_UNKNOWN) | |
8693dfd0 | 3502 | { |
49582f9d | 3503 | const double aTimeStamp = ViewerTest::CurrentEventManager()->EventTime(); |
3504 | if (aReport.type == KeyPress) | |
7fd59977 | 3505 | { |
49582f9d | 3506 | ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp); |
7fd59977 | 3507 | } |
8693dfd0 | 3508 | else |
7fd59977 | 3509 | { |
49582f9d | 3510 | ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp); |
7fd59977 | 3511 | } |
49582f9d | 3512 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); |
8693dfd0 | 3513 | } |
3514 | break; | |
3515 | } | |
49582f9d | 3516 | case ButtonPress: |
8693dfd0 | 3517 | case ButtonRelease: |
3518 | { | |
49582f9d | 3519 | const Graphic3d_Vec2i aPos (aReport.xbutton.x, aReport.xbutton.y); |
3520 | Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE; | |
3521 | Aspect_VKeyMouse aButton = Aspect_VKeyMouse_NONE; | |
3522 | if (aReport.xbutton.button == Button1) | |
8693dfd0 | 3523 | { |
49582f9d | 3524 | aButton = Aspect_VKeyMouse_LeftButton; |
8693dfd0 | 3525 | } |
49582f9d | 3526 | if (aReport.xbutton.button == Button2) |
8693dfd0 | 3527 | { |
49582f9d | 3528 | aButton = Aspect_VKeyMouse_MiddleButton; |
8693dfd0 | 3529 | } |
49582f9d | 3530 | if (aReport.xbutton.button == Button3) |
8693dfd0 | 3531 | { |
49582f9d | 3532 | aButton = Aspect_VKeyMouse_RightButton; |
8693dfd0 | 3533 | } |
7fd59977 | 3534 | |
49582f9d | 3535 | if (aReport.xbutton.state & ControlMask) |
8693dfd0 | 3536 | { |
49582f9d | 3537 | aFlags |= Aspect_VKeyFlags_CTRL; |
3538 | } | |
3539 | if (aReport.xbutton.state & ShiftMask) | |
3540 | { | |
3541 | aFlags |= Aspect_VKeyFlags_SHIFT; | |
3542 | } | |
3543 | if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt)) | |
3544 | { | |
3545 | aFlags |= Aspect_VKeyFlags_ALT; | |
8693dfd0 | 3546 | } |
7fd59977 | 3547 | |
49582f9d | 3548 | if (aReport.xbutton.button == Button4 |
3549 | || aReport.xbutton.button == Button5) | |
8693dfd0 | 3550 | { |
49582f9d | 3551 | if (aReport.type != ButtonPress) |
8693dfd0 | 3552 | { |
49582f9d | 3553 | break; |
7fd59977 | 3554 | } |
49582f9d | 3555 | |
3556 | const double aDeltaF = (aReport.xbutton.button == Button4 ? 1.0 : -1.0); | |
3557 | ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags)); | |
3558 | } | |
3559 | else if (aReport.type == ButtonPress) | |
3560 | { | |
3561 | if (aButton == Aspect_VKeyMouse_LeftButton) | |
7fd59977 | 3562 | { |
49582f9d | 3563 | TheIsAnimating = Standard_False; |
7fd59977 | 3564 | } |
49582f9d | 3565 | ViewerTest::CurrentEventManager()->PressMouseButton (aPos, aButton, aFlags, false); |
8693dfd0 | 3566 | } |
3567 | else | |
3568 | { | |
49582f9d | 3569 | ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, aButton, aFlags, false); |
8693dfd0 | 3570 | } |
49582f9d | 3571 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); |
8693dfd0 | 3572 | break; |
3573 | } | |
3574 | case MotionNotify: | |
3575 | { | |
49582f9d | 3576 | Window anXWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0; |
8693dfd0 | 3577 | if (anXWindow != aReport.xmotion.window) |
3578 | { | |
7fd59977 | 3579 | break; |
8693dfd0 | 3580 | } |
3581 | ||
3582 | // remove all the ButtonMotionMask and process them at once | |
3583 | for (int aNbMaxEvents = XPending (aDisplay); aNbMaxEvents > 0; --aNbMaxEvents) | |
3584 | { | |
3585 | if (!XCheckWindowEvent (aDisplay, anXWindow, ButtonMotionMask | PointerMotionMask, &aReport)) | |
7fd59977 | 3586 | { |
8693dfd0 | 3587 | break; |
3588 | } | |
3589 | } | |
7fd59977 | 3590 | |
49582f9d | 3591 | Graphic3d_Vec2i aPos (aReport.xmotion.x, aReport.xmotion.y); |
3592 | Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE; | |
3593 | Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE; | |
3594 | if ((aReport.xmotion.state & Button1Mask) != 0) | |
8693dfd0 | 3595 | { |
49582f9d | 3596 | aButtons |= Aspect_VKeyMouse_LeftButton; |
3597 | } | |
3598 | else if ((aReport.xmotion.state & Button2Mask) != 0) | |
3599 | { | |
3600 | aButtons |= Aspect_VKeyMouse_MiddleButton; | |
3601 | } | |
3602 | else if ((aReport.xmotion.state & Button3Mask) != 0) | |
3603 | { | |
3604 | aButtons |= Aspect_VKeyMouse_RightButton; | |
3605 | } | |
7fd59977 | 3606 | |
49582f9d | 3607 | if (aReport.xmotion.state & ControlMask) |
3608 | { | |
3609 | aFlags |= Aspect_VKeyFlags_CTRL; | |
8693dfd0 | 3610 | } |
49582f9d | 3611 | if (aReport.xmotion.state & ShiftMask) |
8693dfd0 | 3612 | { |
49582f9d | 3613 | aFlags |= Aspect_VKeyFlags_SHIFT; |
8693dfd0 | 3614 | } |
49582f9d | 3615 | if (ViewerTest::CurrentEventManager()->Keys().IsKeyDown (Aspect_VKey_Alt)) |
3616 | { | |
3617 | aFlags |= Aspect_VKeyFlags_ALT; | |
3618 | } | |
3619 | ||
3620 | ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false); | |
3621 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true); | |
8693dfd0 | 3622 | break; |
3623 | } | |
3624 | } | |
49582f9d | 3625 | return (!toPick || ViewerTest::CurrentEventManager()->ToPickPoint()) ? 1 : 0; |
7fd59977 | 3626 | } |
3627 | ||
3628 | //============================================================================== | |
3629 | //function : VProcessEvents | |
8693dfd0 | 3630 | //purpose : manage the event in the Viewer window (see Tcl_CreateFileHandler()) |
7fd59977 | 3631 | //============================================================================== |
8693dfd0 | 3632 | static void VProcessEvents (ClientData theDispX, int) |
7fd59977 | 3633 | { |
8693dfd0 | 3634 | Display* aDispX = (Display* )theDispX; |
3635 | Handle(Aspect_DisplayConnection) aDispConn; | |
3636 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
3637 | aDriverIter (ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next()) | |
18d715bd | 3638 | { |
8693dfd0 | 3639 | const Handle(Aspect_DisplayConnection)& aDispConnTmp = aDriverIter.Key2()->GetDisplayConnection(); |
3640 | if (aDispConnTmp->GetDisplay() == aDispX) | |
3641 | { | |
3642 | aDispConn = aDispConnTmp; | |
3643 | break; | |
3644 | } | |
3645 | } | |
3646 | if (aDispConn.IsNull()) | |
3647 | { | |
3648 | std::cerr << "Error: ViewerTest is unable processing messages for unknown X Display\n"; | |
3649 | return; | |
4269bd1b | 3650 | } |
8693dfd0 | 3651 | |
3652 | // process new events in queue | |
3653 | SetDisplayConnection (aDispConn); | |
3654 | int aNbRemain = 0; | |
3655 | for (int aNbEventsMax = XPending (aDispX), anEventIter (0);;) | |
18d715bd | 3656 | { |
8693dfd0 | 3657 | const int anEventResult = ViewerMainLoop (0, NULL); |
3658 | if (anEventResult == 0) | |
18d715bd | 3659 | { |
8693dfd0 | 3660 | return; |
3661 | } | |
3662 | ||
3663 | aNbRemain = XPending (aDispX); | |
3664 | if (++anEventIter >= aNbEventsMax | |
3665 | || aNbRemain <= 0) | |
3666 | { | |
3667 | break; | |
18d715bd | 3668 | } |
7fd59977 | 3669 | } |
4269bd1b | 3670 | |
8693dfd0 | 3671 | // Listening X events through Tcl_CreateFileHandler() callback is fragile, |
3672 | // it is possible that new events will arrive to queue before the end of this callback | |
3673 | // so that either this callback should go into an infinite loop (blocking processing of other events) | |
3674 | // or to keep unprocessed events till the next queue update (which can arrive not soon). | |
3675 | // Sending a dummy event in this case is a simple workaround (still, it is possible that new event will be queued in-between). | |
3676 | if (aNbRemain != 0) | |
3677 | { | |
3678 | XEvent aDummyEvent; | |
3679 | memset (&aDummyEvent, 0, sizeof(aDummyEvent)); | |
3680 | aDummyEvent.type = ClientMessage; | |
3681 | aDummyEvent.xclient.format = 32; | |
3682 | XSendEvent (aDispX, InputFocus, False, 0, &aDummyEvent); | |
3683 | XFlush (aDispX); | |
3684 | } | |
4269bd1b | 3685 | |
8693dfd0 | 3686 | if (const Handle(AIS_InteractiveContext)& anActiveCtx = ViewerTest::GetAISContext()) |
3687 | { | |
3688 | SetDisplayConnection (anActiveCtx->CurrentViewer()->Driver()->GetDisplayConnection()); | |
3689 | } | |
7fd59977 | 3690 | } |
3691 | #endif | |
3692 | ||
3693 | //============================================================================== | |
3694 | //function : OSWindowSetup | |
3695 | //purpose : Setup for the X11 window to be able to cath the event | |
3696 | //============================================================================== | |
3697 | ||
3698 | ||
3699 | static void OSWindowSetup() | |
3700 | { | |
4fe56619 | 3701 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 3702 | // X11 |
3703 | ||
3704 | Window window = VT_GetWindow()->XWindow(); | |
18d715bd | 3705 | SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
3706 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
3707 | XSynchronize(aDisplay, 1); | |
7fd59977 | 3708 | |
3709 | // X11 : For keyboard on SUN | |
3710 | XWMHints wmhints; | |
3711 | wmhints.flags = InputHint; | |
3712 | wmhints.input = 1; | |
3713 | ||
18d715bd | 3714 | XSetWMHints( aDisplay, window, &wmhints); |
7fd59977 | 3715 | |
49582f9d | 3716 | XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | KeyReleaseMask | |
7fd59977 | 3717 | ButtonPressMask | ButtonReleaseMask | |
3718 | StructureNotifyMask | | |
3719 | PointerMotionMask | | |
3720 | Button1MotionMask | Button2MotionMask | | |
18d715bd | 3721 | Button3MotionMask | FocusChangeMask |
7fd59977 | 3722 | ); |
18d715bd | 3723 | Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW); |
3724 | XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1); | |
7fd59977 | 3725 | |
18d715bd | 3726 | XSynchronize(aDisplay, 0); |
7fd59977 | 3727 | |
3728 | #else | |
57c28b61 | 3729 | // _WIN32 |
7fd59977 | 3730 | #endif |
3731 | ||
3732 | } | |
3733 | ||
7fd59977 | 3734 | //============================================================================== |
3735 | //function : VFit | |
1beb58d7 | 3736 | //purpose : |
7fd59977 | 3737 | //============================================================================== |
3738 | ||
1beb58d7 | 3739 | static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv) |
7fd59977 | 3740 | { |
1beb58d7 | 3741 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3742 | if (aView.IsNull()) | |
b586500b | 3743 | { |
1beb58d7 | 3744 | std::cout << "Error: no active viewer!\n"; |
3745 | return 1; | |
b586500b | 3746 | } |
3747 | ||
1beb58d7 | 3748 | Standard_Boolean toFit = Standard_True; |
3749 | ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView); | |
3750 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
b586500b | 3751 | { |
1beb58d7 | 3752 | TCollection_AsciiString anArg (theArgv[anArgIter]); |
b586500b | 3753 | anArg.LowerCase(); |
1beb58d7 | 3754 | if (anUpdateTool.parseRedrawMode (anArg)) |
b586500b | 3755 | { |
1beb58d7 | 3756 | continue; |
3757 | } | |
3758 | else if (anArg == "-selected") | |
3759 | { | |
3760 | ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False); | |
3761 | toFit = Standard_False; | |
3762 | } | |
3763 | else | |
3764 | { | |
3765 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
b586500b | 3766 | } |
3767 | } | |
3768 | ||
1beb58d7 | 3769 | if (toFit) |
3770 | { | |
3771 | aView->FitAll (0.01, Standard_False); | |
7fd59977 | 3772 | } |
3773 | return 0; | |
3774 | } | |
3775 | ||
6262a303 | 3776 | //======================================================================= |
3777 | //function : VFitArea | |
3778 | //purpose : Fit view to show area located between two points | |
3779 | // : given in world 2D or 3D coordinates. | |
3780 | //======================================================================= | |
3781 | static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
3782 | { | |
3783 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3784 | if (aView.IsNull()) | |
3785 | { | |
3786 | std::cerr << theArgVec[0] << "Error: No active view.\n"; | |
3787 | return 1; | |
3788 | } | |
3789 | ||
3790 | // Parse arguments. | |
3791 | gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0); | |
3792 | gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0); | |
3793 | ||
3794 | if (theArgNb == 5) | |
3795 | { | |
3796 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
3797 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
3798 | aWorldPnt2.SetX (Draw::Atof (theArgVec[3])); | |
3799 | aWorldPnt2.SetY (Draw::Atof (theArgVec[4])); | |
3800 | } | |
3801 | else if (theArgNb == 7) | |
3802 | { | |
3803 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
3804 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
3805 | aWorldPnt1.SetZ (Draw::Atof (theArgVec[3])); | |
3806 | aWorldPnt2.SetX (Draw::Atof (theArgVec[4])); | |
3807 | aWorldPnt2.SetY (Draw::Atof (theArgVec[5])); | |
3808 | aWorldPnt2.SetZ (Draw::Atof (theArgVec[6])); | |
3809 | } | |
3810 | else | |
3811 | { | |
3812 | std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n"; | |
3813 | theDI.PrintHelp(theArgVec[0]); | |
3814 | return 1; | |
3815 | } | |
3816 | ||
3817 | // Convert model coordinates to view space | |
3818 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
3819 | gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1); | |
3820 | gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2); | |
3821 | ||
3822 | // Determine fit area | |
3823 | gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y())); | |
3824 | gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y())); | |
3825 | ||
3826 | Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner); | |
3827 | ||
3828 | if (aDiagonal < Precision::Confusion()) | |
3829 | { | |
3830 | std::cerr << theArgVec[0] << "Error: view area is too small.\n"; | |
3831 | return 1; | |
3832 | } | |
3833 | ||
3834 | aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y()); | |
3835 | return 0; | |
3836 | } | |
3837 | ||
7fd59977 | 3838 | //============================================================================== |
3839 | //function : VZFit | |
3840 | //purpose : ZFitall, no DRAW arguments | |
3841 | //Draw arg : No args | |
3842 | //============================================================================== | |
197ac94e | 3843 | static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 3844 | { |
197ac94e | 3845 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
3846 | ||
3847 | if (aCurrentView.IsNull()) | |
3848 | { | |
3849 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; | |
3850 | return 1; | |
3851 | } | |
3852 | ||
3853 | if (theArgsNb == 1) | |
3854 | { | |
c357e426 | 3855 | aCurrentView->ZFitAll(); |
197ac94e | 3856 | aCurrentView->Redraw(); |
3857 | return 0; | |
3858 | } | |
3859 | ||
3860 | Standard_Real aScale = 1.0; | |
3861 | ||
3862 | if (theArgsNb >= 2) | |
3863 | { | |
3864 | aScale = Draw::Atoi (theArgVec[1]); | |
3865 | } | |
3866 | ||
c357e426 | 3867 | aCurrentView->ZFitAll (aScale); |
197ac94e | 3868 | aCurrentView->Redraw(); |
7fd59977 | 3869 | |
197ac94e | 3870 | return 0; |
3871 | } | |
7fd59977 | 3872 | |
197ac94e | 3873 | //============================================================================== |
3874 | //function : VRepaint | |
3875 | //purpose : | |
3876 | //============================================================================== | |
56689b27 | 3877 | static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec) |
7fd59977 | 3878 | { |
56689b27 | 3879 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3880 | if (aView.IsNull()) | |
3881 | { | |
3882 | std::cout << "Error: no active viewer!\n"; | |
3883 | return 1; | |
3884 | } | |
3885 | ||
3886 | Standard_Boolean isImmediateUpdate = Standard_False; | |
3887 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
3888 | { | |
3889 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
3890 | anArg.LowerCase(); | |
8693dfd0 | 3891 | if (anArg == "-immediate" |
3892 | || anArg == "-imm") | |
56689b27 | 3893 | { |
3894 | isImmediateUpdate = Standard_True; | |
3895 | if (anArgIter + 1 < theArgNb | |
3896 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate)) | |
3897 | { | |
3898 | ++anArgIter; | |
3899 | } | |
3900 | } | |
8693dfd0 | 3901 | else if (anArg == "-continuous" |
3902 | || anArg == "-cont" | |
3903 | || anArg == "-fps" | |
3904 | || anArg == "-framerate") | |
3905 | { | |
3906 | Standard_Real aFps = -1.0; | |
3907 | if (anArgIter + 1 < theArgNb | |
3908 | && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue()) | |
3909 | { | |
3910 | aFps = Draw::Atof (theArgVec[++anArgIter]); | |
3911 | } | |
3912 | ||
3913 | ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance(); | |
3914 | if (Abs (aFps) >= 1.0) | |
3915 | { | |
3916 | aRedrawer.Start (aView->Window(), aFps); | |
3917 | } | |
3918 | else | |
3919 | { | |
3920 | aRedrawer.Stop(); | |
3921 | } | |
3922 | } | |
56689b27 | 3923 | else |
3924 | { | |
3925 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
8693dfd0 | 3926 | return 1; |
56689b27 | 3927 | } |
3928 | } | |
3929 | ||
3930 | if (isImmediateUpdate) | |
3931 | { | |
3932 | aView->RedrawImmediate(); | |
3933 | } | |
3934 | else | |
3935 | { | |
3936 | aView->Redraw(); | |
3937 | } | |
3938 | return 0; | |
7fd59977 | 3939 | } |
3940 | ||
7fd59977 | 3941 | //============================================================================== |
3942 | //function : VClear | |
3943 | //purpose : Remove all the object from the viewer | |
3944 | //Draw arg : No args | |
3945 | //============================================================================== | |
3946 | ||
3947 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) | |
3948 | { | |
3949 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
3950 | if(!V.IsNull()) | |
3951 | ViewerTest::Clear(); | |
3952 | return 0; | |
3953 | } | |
3954 | ||
3955 | //============================================================================== | |
3956 | //function : VPick | |
3957 | //purpose : | |
3958 | //============================================================================== | |
3959 | ||
49582f9d | 3960 | static int VPick (Draw_Interpretor& , |
3961 | Standard_Integer theNbArgs, | |
3962 | const char** theArgVec) | |
3963 | { | |
3964 | if (ViewerTest::CurrentView().IsNull()) | |
3965 | { | |
3966 | return 1; | |
3967 | } | |
7fd59977 | 3968 | |
49582f9d | 3969 | if (theNbArgs < 4) |
3970 | { | |
3971 | std::cout << "Syntax error: Invalid number of arguments\n"; | |
3972 | return 1; | |
3973 | } | |
7fd59977 | 3974 | |
49582f9d | 3975 | while (ViewerMainLoop (theNbArgs, theArgVec)) |
3976 | { | |
3977 | // | |
3978 | } | |
7fd59977 | 3979 | |
49582f9d | 3980 | return 0; |
7fd59977 | 3981 | } |
3982 | ||
293211ae | 3983 | namespace |
7fd59977 | 3984 | { |
7fd59977 | 3985 | |
293211ae | 3986 | //! Changes the background |
3987 | //! @param theDrawInterpretor the interpreter of the Draw Harness application | |
3988 | //! @param theNumberOfCommandLineArguments the number of passed command line arguments | |
3989 | //! @param theCommandLineArguments the array of command line arguments | |
3990 | //! @return TCL_OK if changing was successful, or TCL_ERROR otherwise | |
3991 | static int vbackground (Draw_Interpretor& theDrawInterpretor, | |
3992 | const Standard_Integer theNumberOfCommandLineArguments, | |
3993 | const char** const theCommandLineArguments) | |
7fd59977 | 3994 | { |
293211ae | 3995 | if (theNumberOfCommandLineArguments < 1) |
7fd59977 | 3996 | { |
293211ae | 3997 | return TCL_ERROR; |
7fd59977 | 3998 | } |
293211ae | 3999 | BackgroundChanger aBackgroundChanger; |
4000 | if (!aBackgroundChanger.ProcessCommandLine (theDrawInterpretor, | |
4001 | theNumberOfCommandLineArguments, | |
4002 | theCommandLineArguments)) | |
f8b2ed36 | 4003 | { |
293211ae | 4004 | theDrawInterpretor << "Wrong command arguments.\n" |
4005 | "Type 'help " | |
4006 | << theCommandLineArguments[0] << "' for information about command options and its arguments.\n"; | |
4007 | return TCL_ERROR; | |
f8b2ed36 | 4008 | } |
293211ae | 4009 | return TCL_OK; |
f8b2ed36 | 4010 | } |
4011 | ||
293211ae | 4012 | } // namespace |
f42753ed | 4013 | |
7fd59977 | 4014 | //============================================================================== |
4015 | //function : VScale | |
4016 | //purpose : View Scaling | |
4017 | //============================================================================== | |
4018 | ||
4019 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
4020 | { | |
4021 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
4022 | if ( V3dView.IsNull() ) return 1; | |
4023 | ||
4024 | if ( argc != 4 ) { | |
586db386 | 4025 | di << argv[0] << "Invalid number of arguments\n"; |
7fd59977 | 4026 | return 1; |
4027 | } | |
91322f44 | 4028 | V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 4029 | return 0; |
4030 | } | |
4031 | //============================================================================== | |
536d98e2 | 4032 | //function : VZBuffTrihedron |
4033 | //purpose : | |
7fd59977 | 4034 | //============================================================================== |
4035 | ||
536d98e2 | 4036 | static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/, |
4037 | Standard_Integer theArgNb, | |
4038 | const char** theArgVec) | |
7fd59977 | 4039 | { |
536d98e2 | 4040 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
4041 | if (aView.IsNull()) | |
4042 | { | |
4043 | std::cout << "Error: no active viewer!\n"; | |
4044 | return 1; | |
4045 | } | |
7fd59977 | 4046 | |
536d98e2 | 4047 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
7c8a8fcc | 4048 | |
536d98e2 | 4049 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; |
4050 | V3d_TypeOfVisualization aVisType = V3d_ZBUFFER; | |
4051 | Quantity_Color aLabelsColor = Quantity_NOC_WHITE; | |
4052 | Quantity_Color anArrowColorX = Quantity_NOC_RED; | |
4053 | Quantity_Color anArrowColorY = Quantity_NOC_GREEN; | |
4054 | Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1; | |
4055 | Standard_Real aScale = 0.1; | |
4056 | Standard_Real aSizeRatio = 0.8; | |
4057 | Standard_Real anArrowDiam = 0.05; | |
4058 | Standard_Integer aNbFacets = 12; | |
4059 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
7c8a8fcc | 4060 | { |
536d98e2 | 4061 | Standard_CString anArg = theArgVec[anArgIter]; |
4062 | TCollection_AsciiString aFlag (anArg); | |
4063 | aFlag.LowerCase(); | |
4064 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
7c8a8fcc | 4065 | { |
536d98e2 | 4066 | continue; |
4067 | } | |
4068 | else if (aFlag == "-on") | |
7c8a8fcc | 4069 | { |
536d98e2 | 4070 | continue; |
4071 | } | |
4072 | else if (aFlag == "-off") | |
7c8a8fcc | 4073 | { |
536d98e2 | 4074 | aView->TriedronErase(); |
4075 | return 0; | |
4076 | } | |
4077 | else if (aFlag == "-pos" | |
4078 | || aFlag == "-position" | |
4079 | || aFlag == "-corner") | |
7c8a8fcc | 4080 | { |
536d98e2 | 4081 | if (++anArgIter >= theArgNb) |
4082 | { | |
4083 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4084 | return 1; | |
4085 | } | |
4086 | ||
4087 | TCollection_AsciiString aPosName (theArgVec[anArgIter]); | |
4088 | aPosName.LowerCase(); | |
4089 | if (aPosName == "center") | |
4090 | { | |
4091 | aPosition = Aspect_TOTP_CENTER; | |
4092 | } | |
4093 | else if (aPosName == "left_lower" | |
4094 | || aPosName == "lower_left" | |
4095 | || aPosName == "leftlower" | |
4096 | || aPosName == "lowerleft") | |
4097 | { | |
4098 | aPosition = Aspect_TOTP_LEFT_LOWER; | |
4099 | } | |
4100 | else if (aPosName == "left_upper" | |
4101 | || aPosName == "upper_left" | |
4102 | || aPosName == "leftupper" | |
4103 | || aPosName == "upperleft") | |
4104 | { | |
4105 | aPosition = Aspect_TOTP_LEFT_UPPER; | |
4106 | } | |
4107 | else if (aPosName == "right_lower" | |
4108 | || aPosName == "lower_right" | |
4109 | || aPosName == "rightlower" | |
4110 | || aPosName == "lowerright") | |
4111 | { | |
4112 | aPosition = Aspect_TOTP_RIGHT_LOWER; | |
4113 | } | |
4114 | else if (aPosName == "right_upper" | |
4115 | || aPosName == "upper_right" | |
4116 | || aPosName == "rightupper" | |
4117 | || aPosName == "upperright") | |
4118 | { | |
4119 | aPosition = Aspect_TOTP_RIGHT_UPPER; | |
4120 | } | |
4121 | else | |
4122 | { | |
4123 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n"; | |
4124 | return 1; | |
4125 | } | |
4126 | } | |
4127 | else if (aFlag == "-type") | |
7c8a8fcc | 4128 | { |
536d98e2 | 4129 | if (++anArgIter >= theArgNb) |
4130 | { | |
4131 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4132 | return 1; | |
4133 | } | |
4134 | ||
4135 | TCollection_AsciiString aTypeName (theArgVec[anArgIter]); | |
4136 | aTypeName.LowerCase(); | |
4137 | if (aTypeName == "wireframe" | |
4138 | || aTypeName == "wire") | |
4139 | { | |
4140 | aVisType = V3d_WIREFRAME; | |
4141 | } | |
4142 | else if (aTypeName == "zbuffer" | |
4143 | || aTypeName == "shaded") | |
4144 | { | |
4145 | aVisType = V3d_ZBUFFER; | |
4146 | } | |
4147 | else | |
4148 | { | |
4149 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n"; | |
4150 | } | |
4151 | } | |
4152 | else if (aFlag == "-scale") | |
7c8a8fcc | 4153 | { |
536d98e2 | 4154 | if (++anArgIter >= theArgNb) |
4155 | { | |
4156 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4157 | return 1; | |
4158 | } | |
4159 | ||
4160 | aScale = Draw::Atof (theArgVec[anArgIter]); | |
7c8a8fcc | 4161 | } |
536d98e2 | 4162 | else if (aFlag == "-size" |
4163 | || aFlag == "-sizeratio") | |
4164 | { | |
4165 | if (++anArgIter >= theArgNb) | |
4166 | { | |
4167 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4168 | return 1; | |
4169 | } | |
7c8a8fcc | 4170 | |
536d98e2 | 4171 | aSizeRatio = Draw::Atof (theArgVec[anArgIter]); |
4172 | } | |
4173 | else if (aFlag == "-arrowdiam" | |
4174 | || aFlag == "-arrowdiameter") | |
4175 | { | |
4176 | if (++anArgIter >= theArgNb) | |
4177 | { | |
4178 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4179 | return 1; | |
4180 | } | |
7c8a8fcc | 4181 | |
536d98e2 | 4182 | anArrowDiam = Draw::Atof (theArgVec[anArgIter]); |
4183 | } | |
4184 | else if (aFlag == "-nbfacets") | |
4185 | { | |
4186 | if (++anArgIter >= theArgNb) | |
4187 | { | |
4188 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4189 | return 1; | |
4190 | } | |
7c8a8fcc | 4191 | |
536d98e2 | 4192 | aNbFacets = Draw::Atoi (theArgVec[anArgIter]); |
4193 | } | |
4194 | else if (aFlag == "-colorlabel" | |
4195 | || aFlag == "-colorlabels") | |
7c8a8fcc | 4196 | { |
536d98e2 | 4197 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
4198 | theArgVec + anArgIter + 1, | |
4199 | aLabelsColor); | |
4200 | if (aNbParsed == 0) | |
4201 | { | |
4202 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4203 | return 1; | |
4204 | } | |
4205 | anArgIter += aNbParsed; | |
7c8a8fcc | 4206 | } |
536d98e2 | 4207 | else if (aFlag == "-colorarrowx") |
7c8a8fcc | 4208 | { |
536d98e2 | 4209 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
4210 | theArgVec + anArgIter + 1, | |
4211 | anArrowColorX); | |
4212 | if (aNbParsed == 0) | |
4213 | { | |
4214 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4215 | return 1; | |
4216 | } | |
4217 | anArgIter += aNbParsed; | |
4218 | } | |
4219 | else if (aFlag == "-colorarrowy") | |
7c8a8fcc | 4220 | { |
536d98e2 | 4221 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
4222 | theArgVec + anArgIter + 1, | |
4223 | anArrowColorY); | |
4224 | if (aNbParsed == 0) | |
4225 | { | |
4226 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4227 | return 1; | |
4228 | } | |
4229 | anArgIter += aNbParsed; | |
4230 | } | |
4231 | else if (aFlag == "-colorarrowz") | |
7c8a8fcc | 4232 | { |
536d98e2 | 4233 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
4234 | theArgVec + anArgIter + 1, | |
4235 | anArrowColorZ); | |
4236 | if (aNbParsed == 0) | |
4237 | { | |
4238 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4239 | return 1; | |
4240 | } | |
4241 | anArgIter += aNbParsed; | |
4242 | } | |
4243 | else | |
4244 | { | |
4245 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
7c8a8fcc | 4246 | return 1; |
4247 | } | |
7c8a8fcc | 4248 | } |
4249 | ||
536d98e2 | 4250 | aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(), |
4251 | aSizeRatio, anArrowDiam, aNbFacets); | |
4252 | aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType); | |
c357e426 | 4253 | aView->ZFitAll(); |
7fd59977 | 4254 | return 0; |
4255 | } | |
4256 | ||
4257 | //============================================================================== | |
4258 | //function : VRotate | |
4259 | //purpose : Camera Rotating | |
4260 | //============================================================================== | |
4261 | ||
4af098ba | 4262 | static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec) |
4263 | { | |
4264 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4265 | if (aView.IsNull()) | |
4266 | { | |
4267 | std::cout << "No active view!\n"; | |
7fd59977 | 4268 | return 1; |
4269 | } | |
4270 | ||
4af098ba | 4271 | Standard_Boolean hasFlags = Standard_False; |
4272 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
4273 | { | |
4274 | Standard_CString anArg (theArgVec[anArgIter]); | |
4275 | TCollection_AsciiString aFlag (anArg); | |
4276 | aFlag.LowerCase(); | |
4277 | if (aFlag == "-mousestart" | |
4278 | || aFlag == "-mousefrom") | |
4279 | { | |
4280 | hasFlags = Standard_True; | |
4281 | if (anArgIter + 2 >= theArgNb) | |
4282 | { | |
4283 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
4284 | return 1; | |
4285 | } | |
4286 | ||
4287 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
4288 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
4289 | aView->StartRotation (anX, anY); | |
4290 | } | |
4291 | else if (aFlag == "-mousemove") | |
4292 | { | |
4293 | hasFlags = Standard_True; | |
4294 | if (anArgIter + 2 >= theArgNb) | |
4295 | { | |
4296 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
4297 | return 1; | |
4298 | } | |
4299 | ||
4300 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
4301 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
4302 | aView->Rotation (anX, anY); | |
4303 | } | |
4304 | else if (theArgNb != 4 | |
4305 | && theArgNb != 7) | |
4306 | { | |
4307 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
4308 | return 1; | |
4309 | } | |
4310 | } | |
4311 | ||
4312 | if (hasFlags) | |
4313 | { | |
7fd59977 | 4314 | return 0; |
4af098ba | 4315 | } |
4316 | else if (theArgNb == 4) | |
4317 | { | |
4318 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
4319 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
4320 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
4321 | aView->Rotate (anAX, anAY, anAZ); | |
4322 | return 0; | |
4323 | } | |
4324 | else if (theArgNb == 7) | |
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 | ||
4330 | Standard_Real anX = Draw::Atof (theArgVec[4]); | |
4331 | Standard_Real anY = Draw::Atof (theArgVec[5]); | |
4332 | Standard_Real anZ = Draw::Atof (theArgVec[6]); | |
4333 | ||
4334 | aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ); | |
7fd59977 | 4335 | return 0; |
7fd59977 | 4336 | } |
4af098ba | 4337 | |
4338 | std::cout << "Error: Invalid number of arguments\n"; | |
4339 | return 1; | |
7fd59977 | 4340 | } |
4341 | ||
4342 | //============================================================================== | |
4343 | //function : VZoom | |
4344 | //purpose : View zoom in / out (relative to current zoom) | |
4345 | //============================================================================== | |
4346 | ||
4347 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
4348 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
4349 | if ( V3dView.IsNull() ) { | |
4350 | return 1; | |
4351 | } | |
4352 | ||
4353 | if ( argc == 2 ) { | |
91322f44 | 4354 | Standard_Real coef = Draw::Atof(argv[1]); |
7fd59977 | 4355 | if ( coef <= 0.0 ) { |
586db386 | 4356 | di << argv[1] << "Invalid value\n"; |
7fd59977 | 4357 | return 1; |
4358 | } | |
91322f44 | 4359 | V3dView->SetZoom( Draw::Atof(argv[1]) ); |
7fd59977 | 4360 | return 0; |
4361 | } else { | |
586db386 | 4362 | di << argv[0] << " Invalid number of arguments\n"; |
7fd59977 | 4363 | return 1; |
4364 | } | |
4365 | } | |
4366 | ||
4367 | //============================================================================== | |
4368 | //function : VPan | |
4369 | //purpose : View panning (in pixels) | |
4370 | //============================================================================== | |
4371 | ||
4372 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
4373 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
4374 | if ( V3dView.IsNull() ) return 1; | |
4375 | ||
4376 | if ( argc == 3 ) { | |
91322f44 | 4377 | V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) ); |
7fd59977 | 4378 | return 0; |
4379 | } else { | |
586db386 | 4380 | di << argv[0] << " Invalid number of arguments\n"; |
7fd59977 | 4381 | return 1; |
4382 | } | |
4383 | } | |
4384 | ||
49e1a5c7 | 4385 | //============================================================================== |
4386 | //function : VPlace | |
4387 | //purpose : Place the point (in pixels) at the center of the window | |
4388 | //============================================================================== | |
4389 | static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs) | |
4390 | { | |
4391 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4392 | if (aView.IsNull()) | |
4393 | { | |
4394 | std::cerr << theArgs[0] << "Error: no active view." << std::endl; | |
4395 | return 1; | |
4396 | } | |
4397 | ||
4398 | if (theArgNb != 3) | |
4399 | { | |
4400 | std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl; | |
4401 | return 1; | |
4402 | } | |
4403 | ||
4404 | aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale()); | |
4405 | ||
4406 | return 0; | |
4407 | } | |
7fd59977 | 4408 | |
71215351 | 4409 | static int VColorScale (Draw_Interpretor& theDI, |
4410 | Standard_Integer theArgNb, | |
4411 | const char** theArgVec) | |
4412 | { | |
7fd59977 | 4413 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
71215351 | 4414 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
4415 | if (aContext.IsNull()) | |
4416 | { | |
4417 | std::cout << "Error: no active view!\n"; | |
4418 | return 1; | |
7fd59977 | 4419 | } |
24a88697 | 4420 | if (theArgNb <= 1) |
4421 | { | |
4422 | std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n"; | |
4423 | return 1; | |
4424 | } | |
7fd59977 | 4425 | |
4b3d6eb1 | 4426 | Handle(AIS_ColorScale) aColorScale; |
7a324550 | 4427 | if (GetMapOfAIS().IsBound2 (theArgVec[1])) |
71215351 | 4428 | { |
4b3d6eb1 | 4429 | // find existing object |
4430 | aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1])); | |
4431 | if (aColorScale.IsNull()) | |
7a324550 | 4432 | { |
4433 | std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n"; | |
4434 | return 1; | |
4435 | } | |
4436 | } | |
71215351 | 4437 | |
7a324550 | 4438 | if (theArgNb <= 2) |
4439 | { | |
4b3d6eb1 | 4440 | if (aColorScale.IsNull()) |
4441 | { | |
4442 | std::cout << "Syntax error: colorscale with a given name does not exist.\n"; | |
4443 | return 1; | |
4444 | } | |
4445 | ||
7a324550 | 4446 | theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n" |
4b3d6eb1 | 4447 | << "Min range: " << aColorScale->GetMin() << "\n" |
4448 | << "Max range: " << aColorScale->GetMax() << "\n" | |
4449 | << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n" | |
4450 | << "Text height: " << aColorScale->GetTextHeight() << "\n" | |
4451 | << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n" | |
4452 | << "Color scale title: " << aColorScale->GetTitle() << "\n" | |
71215351 | 4453 | << "Label position: "; |
4b3d6eb1 | 4454 | switch (aColorScale->GetLabelPosition()) |
71215351 | 4455 | { |
4456 | case Aspect_TOCSP_NONE: | |
4457 | theDI << "None\n"; | |
4458 | break; | |
4459 | case Aspect_TOCSP_LEFT: | |
4460 | theDI << "Left\n"; | |
4461 | break; | |
4462 | case Aspect_TOCSP_RIGHT: | |
4463 | theDI << "Right\n"; | |
4464 | break; | |
4465 | case Aspect_TOCSP_CENTER: | |
4466 | theDI << "Center\n"; | |
4467 | break; | |
4468 | } | |
4469 | return 0; | |
4470 | } | |
71215351 | 4471 | |
4b3d6eb1 | 4472 | if (aColorScale.IsNull()) |
4473 | { | |
4474 | aColorScale = new AIS_ColorScale(); | |
4475 | aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD); | |
4476 | aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); | |
4477 | } | |
4478 | ||
4479 | ViewerTest_AutoUpdater anUpdateTool (aContext, aView); | |
7a324550 | 4480 | for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter) |
71215351 | 4481 | { |
4482 | Standard_CString anArg = theArgVec[anArgIter]; | |
4483 | TCollection_AsciiString aFlag (anArg); | |
4484 | aFlag.LowerCase(); | |
4485 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
4486 | { | |
4487 | continue; | |
4488 | } | |
4489 | else if (aFlag == "-range") | |
4490 | { | |
4491 | if (anArgIter + 3 >= theArgNb) | |
4492 | { | |
4493 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4494 | return 1; | |
4495 | } | |
4496 | ||
4b3d6eb1 | 4497 | const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]); |
4498 | const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]); | |
4499 | const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]); | |
4500 | if (!aRangeMin.IsRealValue() | |
4501 | || !aRangeMax.IsRealValue()) | |
71215351 | 4502 | { |
4b3d6eb1 | 4503 | std::cout << "Error: the range values should be real!\n"; |
71215351 | 4504 | return 1; |
4505 | } | |
4b3d6eb1 | 4506 | else if (!aNbIntervals.IsIntegerValue()) |
71215351 | 4507 | { |
4508 | std::cout << "Error: the number of intervals should be integer!\n"; | |
4509 | return 1; | |
4510 | } | |
4511 | ||
4b3d6eb1 | 4512 | aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue()); |
4513 | aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue()); | |
71215351 | 4514 | } |
4515 | else if (aFlag == "-font") | |
4516 | { | |
4517 | if (anArgIter + 1 >= theArgNb) | |
4518 | { | |
4519 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4520 | return 1; | |
4521 | } | |
51740958 | 4522 | TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]); |
4523 | if (!aFontArg.IsIntegerValue()) | |
71215351 | 4524 | { |
4525 | std::cout << "Error: HeightFont value should be integer!\n"; | |
4526 | return 1; | |
4527 | } | |
4528 | ||
4b3d6eb1 | 4529 | aColorScale->SetTextHeight (aFontArg.IntegerValue()); |
71215351 | 4530 | anArgIter += 1; |
4531 | } | |
4532 | else if (aFlag == "-textpos") | |
4533 | { | |
4534 | if (anArgIter + 1 >= theArgNb) | |
4535 | { | |
4536 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4537 | return 1; | |
4538 | } | |
4b3d6eb1 | 4539 | |
51740958 | 4540 | TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]); |
4541 | aTextPosArg.LowerCase(); | |
4b3d6eb1 | 4542 | Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE; |
51740958 | 4543 | if (aTextPosArg == "none") |
71215351 | 4544 | { |
4545 | aLabPosition = Aspect_TOCSP_NONE; | |
4546 | } | |
51740958 | 4547 | else if (aTextPosArg == "left") |
71215351 | 4548 | { |
4549 | aLabPosition = Aspect_TOCSP_LEFT; | |
4550 | } | |
51740958 | 4551 | else if (aTextPosArg == "right") |
71215351 | 4552 | { |
4553 | aLabPosition = Aspect_TOCSP_RIGHT; | |
4554 | } | |
51740958 | 4555 | else if (aTextPosArg == "center") |
71215351 | 4556 | { |
4557 | aLabPosition = Aspect_TOCSP_CENTER; | |
4558 | } | |
4559 | else | |
4560 | { | |
51740958 | 4561 | std::cout << "Error: unknown position '" << aTextPosArg << "'!\n"; |
71215351 | 4562 | return 1; |
4563 | } | |
4b3d6eb1 | 4564 | aColorScale->SetLabelPosition (aLabPosition); |
71215351 | 4565 | } |
24a88697 | 4566 | else if (aFlag == "-logarithmic" |
4567 | || aFlag == "-log") | |
4568 | { | |
4569 | if (anArgIter + 1 >= theArgNb) | |
4570 | { | |
4571 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4572 | return 1; | |
4573 | } | |
4b3d6eb1 | 4574 | |
24a88697 | 4575 | Standard_Boolean IsLog; |
4576 | if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog)) | |
4577 | { | |
4578 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4579 | return 1; | |
4580 | } | |
4b3d6eb1 | 4581 | aColorScale->SetLogarithmic (IsLog); |
4582 | } | |
4583 | else if (aFlag == "-huerange" | |
4584 | || aFlag == "-hue") | |
4585 | { | |
4586 | if (anArgIter + 2 >= theArgNb) | |
4587 | { | |
4588 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4589 | return 1; | |
4590 | } | |
4591 | ||
4592 | const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]); | |
4593 | const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]); | |
4594 | aColorScale->SetHueRange (aHueMin, aHueMax); | |
4595 | } | |
4596 | else if (aFlag == "-colorrange") | |
4597 | { | |
4598 | Quantity_Color aColorMin, aColorMax; | |
4599 | Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
4600 | theArgVec + (anArgIter + 1), | |
4601 | aColorMin); | |
4602 | anArgIter += aNbParsed1; | |
4603 | Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
4604 | theArgVec + (anArgIter + 1), | |
4605 | aColorMax); | |
4606 | anArgIter += aNbParsed2; | |
4607 | if (aNbParsed1 == 0 | |
4608 | || aNbParsed2 == 0) | |
4609 | { | |
4610 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
4611 | return 1; | |
4612 | } | |
4613 | ||
4614 | aColorScale->SetColorRange (aColorMin, aColorMax); | |
4615 | } | |
4616 | else if (aFlag == "-reversed" | |
4617 | || aFlag == "-inverted" | |
4618 | || aFlag == "-topdown" | |
4619 | || aFlag == "-bottomup") | |
4620 | { | |
4621 | Standard_Boolean toEnable = Standard_True; | |
4622 | if (anArgIter + 1 < theArgNb | |
4623 | && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable)) | |
4624 | { | |
4625 | ++anArgIter; | |
4626 | } | |
4627 | aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable); | |
4628 | } | |
4629 | else if (aFlag == "-smooth" | |
4630 | || aFlag == "-smoothtransition") | |
4631 | { | |
4632 | Standard_Boolean toEnable = Standard_True; | |
4633 | if (anArgIter + 1 < theArgNb | |
4634 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
4635 | { | |
4636 | ++anArgIter; | |
4637 | } | |
4638 | aColorScale->SetSmoothTransition (toEnable); | |
24a88697 | 4639 | } |
71215351 | 4640 | else if (aFlag == "-xy") |
4641 | { | |
4642 | if (anArgIter + 2 >= theArgNb) | |
4643 | { | |
4644 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4645 | return 1; | |
4646 | } | |
4647 | ||
4b3d6eb1 | 4648 | const TCollection_AsciiString anX (theArgVec[++anArgIter]); |
4649 | const TCollection_AsciiString anY (theArgVec[++anArgIter]); | |
4650 | if (!anX.IsIntegerValue() | |
4651 | || !anY.IsIntegerValue()) | |
71215351 | 4652 | { |
b4b2ecca | 4653 | std::cout << "Error: coordinates should be integer values!\n"; |
71215351 | 4654 | return 1; |
4655 | } | |
4656 | ||
4b3d6eb1 | 4657 | aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue()); |
b4b2ecca | 4658 | } |
4659 | else if (aFlag == "-width" | |
4b3d6eb1 | 4660 | || aFlag == "-w" |
4661 | || aFlag == "-breadth") | |
b4b2ecca | 4662 | { |
4663 | if (anArgIter + 1 >= theArgNb) | |
4664 | { | |
4665 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4666 | return 1; | |
4667 | } | |
4668 | ||
4b3d6eb1 | 4669 | const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]); |
4670 | if (!aBreadth.IsIntegerValue()) | |
b4b2ecca | 4671 | { |
4672 | std::cout << "Error: a width should be an integer value!\n"; | |
4673 | return 1; | |
4674 | } | |
4b3d6eb1 | 4675 | aColorScale->SetBreadth (aBreadth.IntegerValue()); |
b4b2ecca | 4676 | } |
4677 | else if (aFlag == "-height" | |
4678 | || aFlag == "-h") | |
4679 | { | |
4680 | if (anArgIter + 1 >= theArgNb) | |
4681 | { | |
4682 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4683 | return 1; | |
4684 | } | |
4685 | ||
4b3d6eb1 | 4686 | const TCollection_AsciiString aHeight (theArgVec[++anArgIter]); |
4687 | if (!aHeight.IsIntegerValue()) | |
b4b2ecca | 4688 | { |
4689 | std::cout << "Error: a width should be an integer value!\n"; | |
4690 | return 1; | |
4691 | } | |
4b3d6eb1 | 4692 | aColorScale->SetHeight (aHeight.IntegerValue()); |
71215351 | 4693 | } |
4694 | else if (aFlag == "-color") | |
4695 | { | |
4b3d6eb1 | 4696 | if (aColorScale->GetColorType() != Aspect_TOCSD_USER) |
71215351 | 4697 | { |
4698 | std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n"; | |
4699 | return 1; | |
4700 | } | |
4b3d6eb1 | 4701 | else if (anArgIter + 2 >= theArgNb) |
71215351 | 4702 | { |
4b3d6eb1 | 4703 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; |
4704 | return 1; | |
71215351 | 4705 | } |
4706 | ||
4b3d6eb1 | 4707 | const TCollection_AsciiString anInd (theArgVec[++anArgIter]); |
71215351 | 4708 | if (!anInd.IsIntegerValue()) |
4709 | { | |
4710 | std::cout << "Error: Index value should be integer!\n"; | |
4711 | return 1; | |
4712 | } | |
4b3d6eb1 | 4713 | const Standard_Integer anIndex = anInd.IntegerValue(); |
4714 | if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals()) | |
71215351 | 4715 | { |
4b3d6eb1 | 4716 | std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n"; |
71215351 | 4717 | return 1; |
4718 | } | |
4719 | ||
4b3d6eb1 | 4720 | Quantity_Color aColor; |
4721 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
4722 | theArgVec + (anArgIter + 1), | |
4723 | aColor); | |
4724 | if (aNbParsed == 0) | |
71215351 | 4725 | { |
4b3d6eb1 | 4726 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
71215351 | 4727 | return 1; |
4728 | } | |
4b3d6eb1 | 4729 | aColorScale->SetIntervalColor (aColor, anIndex); |
4730 | aColorScale->SetColorType (Aspect_TOCSD_USER); | |
4731 | anArgIter += aNbParsed; | |
71215351 | 4732 | } |
4733 | else if (aFlag == "-label") | |
4734 | { | |
4b3d6eb1 | 4735 | if (aColorScale->GetColorType() != Aspect_TOCSD_USER) |
71215351 | 4736 | { |
4737 | std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n"; | |
4738 | return 1; | |
4739 | } | |
4740 | else if (anArgIter + 2 >= theArgNb) | |
4741 | { | |
4742 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4743 | return 1; | |
4744 | } | |
4745 | ||
4746 | Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]); | |
4b3d6eb1 | 4747 | if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1) |
71215351 | 4748 | { |
4b3d6eb1 | 4749 | std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n"; |
71215351 | 4750 | return 1; |
4751 | } | |
4752 | ||
4753 | TCollection_ExtendedString aText (theArgVec[anArgIter + 2]); | |
4b3d6eb1 | 4754 | aColorScale->SetLabel (aText, anIndex); |
4755 | aColorScale->SetLabelType (Aspect_TOCSD_USER); | |
71215351 | 4756 | anArgIter += 2; |
4757 | } | |
4b3d6eb1 | 4758 | else if (aFlag == "-labelat" |
4759 | || aFlag == "-labat" | |
4760 | || aFlag == "-labelatborder" | |
4761 | || aFlag == "-labatborder" | |
4762 | || aFlag == "-labelatcenter" | |
4763 | || aFlag == "-labatcenter") | |
71215351 | 4764 | { |
4b3d6eb1 | 4765 | Standard_Boolean toEnable = Standard_True; |
4766 | if (aFlag == "-labelat" | |
4767 | || aFlag == "-labat") | |
71215351 | 4768 | { |
4b3d6eb1 | 4769 | Standard_Integer aLabAtBorder = -1; |
4770 | if (++anArgIter >= theArgNb) | |
71215351 | 4771 | { |
4b3d6eb1 | 4772 | TCollection_AsciiString anAtBorder (theArgVec[anArgIter]); |
4773 | anAtBorder.LowerCase(); | |
4774 | if (anAtBorder == "border") | |
71215351 | 4775 | { |
4b3d6eb1 | 4776 | aLabAtBorder = 1; |
71215351 | 4777 | } |
4b3d6eb1 | 4778 | else if (anAtBorder == "center") |
71215351 | 4779 | { |
4b3d6eb1 | 4780 | aLabAtBorder = 0; |
71215351 | 4781 | } |
71215351 | 4782 | } |
4b3d6eb1 | 4783 | if (aLabAtBorder == -1) |
4784 | { | |
4785 | std::cout << "Syntax error at argument '" << anArg << "'!\n"; | |
4786 | return 1; | |
4787 | } | |
4788 | toEnable = (aLabAtBorder == 1); | |
4789 | } | |
4790 | else if (anArgIter + 1 < theArgNb | |
4791 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
4792 | { | |
4793 | ++anArgIter; | |
71215351 | 4794 | } |
4b3d6eb1 | 4795 | aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter" |
4796 | || aFlag == "-labatcenter" | |
4797 | ? !toEnable | |
4798 | : toEnable); | |
4799 | } | |
4800 | else if (aFlag == "-colors") | |
4801 | { | |
4802 | Aspect_SequenceOfColor aSeq; | |
4803 | for (;;) | |
4804 | { | |
4805 | Quantity_Color aColor; | |
4806 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
4807 | theArgVec + (anArgIter + 1), | |
4808 | aColor); | |
4809 | if (aNbParsed == 0) | |
4810 | { | |
4811 | break; | |
4812 | } | |
4813 | anArgIter += aNbParsed; | |
4814 | aSeq.Append (aColor); | |
4815 | } | |
4816 | if (aSeq.Length() != aColorScale->GetNumberOfIntervals()) | |
71215351 | 4817 | { |
4818 | std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " | |
4b3d6eb1 | 4819 | << aColorScale->GetNumberOfIntervals() << " intervals\n"; |
71215351 | 4820 | return 1; |
4821 | } | |
4822 | ||
4b3d6eb1 | 4823 | aColorScale->SetColors (aSeq); |
4824 | aColorScale->SetColorType (Aspect_TOCSD_USER); | |
71215351 | 4825 | } |
4b3d6eb1 | 4826 | else if (aFlag == "-labels" |
4827 | || aFlag == "-freelabels") | |
71215351 | 4828 | { |
4b3d6eb1 | 4829 | if (anArgIter + 1 >= theArgNb) |
4830 | { | |
4831 | std::cout << "Syntax error at argument '" << anArg << "'!\n"; | |
4832 | return 1; | |
4833 | } | |
4834 | ||
4835 | Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder() | |
4836 | ? aColorScale->GetNumberOfIntervals() + 1 | |
4837 | : aColorScale->GetNumberOfIntervals(); | |
4838 | if (aFlag == "-freelabels") | |
4839 | { | |
4840 | ++anArgIter; | |
4841 | aNbLabels = Draw::Atoi (theArgVec[anArgIter]); | |
4842 | } | |
4843 | if (anArgIter + aNbLabels >= theArgNb) | |
71215351 | 4844 | { |
4b3d6eb1 | 4845 | std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n"; |
71215351 | 4846 | return 1; |
4847 | } | |
4848 | ||
4849 | TColStd_SequenceOfExtendedString aSeq; | |
4b3d6eb1 | 4850 | for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter) |
71215351 | 4851 | { |
4b3d6eb1 | 4852 | aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter])); |
71215351 | 4853 | } |
4b3d6eb1 | 4854 | aColorScale->SetLabels (aSeq); |
4855 | aColorScale->SetLabelType (Aspect_TOCSD_USER); | |
71215351 | 4856 | } |
4857 | else if (aFlag == "-title") | |
4858 | { | |
4859 | if (anArgIter + 1 >= theArgNb) | |
4860 | { | |
4861 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4862 | return 1; | |
4863 | } | |
4864 | ||
4865 | Standard_Boolean isTwoArgs = Standard_False; | |
4866 | if (anArgIter + 2 < theArgNb) | |
4867 | { | |
4868 | TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]); | |
4869 | aSecondArg.LowerCase(); | |
4b3d6eb1 | 4870 | Standard_DISABLE_DEPRECATION_WARNINGS |
71215351 | 4871 | if (aSecondArg == "none") |
4872 | { | |
4b3d6eb1 | 4873 | aColorScale->SetTitlePosition (Aspect_TOCSP_NONE); |
71215351 | 4874 | isTwoArgs = Standard_True; |
4875 | } | |
4876 | else if (aSecondArg == "left") | |
4877 | { | |
4b3d6eb1 | 4878 | aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT); |
71215351 | 4879 | isTwoArgs = Standard_True; |
4880 | } | |
4881 | else if (aSecondArg == "right") | |
4882 | { | |
4b3d6eb1 | 4883 | aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT); |
71215351 | 4884 | isTwoArgs = Standard_True; |
4885 | } | |
4886 | else if (aSecondArg == "center") | |
4887 | { | |
4b3d6eb1 | 4888 | aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER); |
71215351 | 4889 | isTwoArgs = Standard_True; |
4890 | } | |
4b3d6eb1 | 4891 | Standard_ENABLE_DEPRECATION_WARNINGS |
71215351 | 4892 | } |
4893 | ||
4b3d6eb1 | 4894 | aColorScale->SetTitle (theArgVec[anArgIter + 1]); |
71215351 | 4895 | if (isTwoArgs) |
4896 | { | |
4897 | anArgIter += 1; | |
4898 | } | |
4899 | anArgIter += 1; | |
4900 | } | |
4901 | else if (aFlag == "-demoversion" | |
4902 | || aFlag == "-demo") | |
4903 | { | |
4b3d6eb1 | 4904 | aColorScale->SetPosition (0, 0); |
4905 | aColorScale->SetTextHeight (16); | |
4906 | aColorScale->SetRange (0.0, 100.0); | |
4907 | aColorScale->SetNumberOfIntervals (10); | |
4908 | aColorScale->SetBreadth (0); | |
4909 | aColorScale->SetHeight (0); | |
4910 | aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT); | |
4911 | aColorScale->SetColorType (Aspect_TOCSD_AUTO); | |
4912 | aColorScale->SetLabelType (Aspect_TOCSD_AUTO); | |
71215351 | 4913 | } |
d5514578 | 4914 | else if (aFlag == "-findcolor") |
4915 | { | |
4916 | if (anArgIter + 1 >= theArgNb) | |
4917 | { | |
4918 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4919 | return 1; | |
4920 | } | |
4921 | ||
4922 | TCollection_AsciiString anArg1 (theArgVec[++anArgIter]); | |
4923 | ||
4924 | if (!anArg1.IsRealValue()) | |
4925 | { | |
4926 | std::cout << "Error: the value should be real!\n"; | |
4927 | return 1; | |
4928 | } | |
4929 | ||
4930 | Quantity_Color aColor; | |
4b3d6eb1 | 4931 | aColorScale->FindColor (anArg1.RealValue(), aColor); |
d5514578 | 4932 | theDI << Quantity_Color::StringName (aColor.Name()); |
4933 | return 0; | |
4934 | } | |
71215351 | 4935 | else |
4936 | { | |
4937 | std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n"; | |
4938 | return 1; | |
4939 | } | |
4940 | } | |
4b3d6eb1 | 4941 | |
4942 | Standard_Integer aWinWidth = 0, aWinHeight = 0; | |
4943 | aView->Window()->Size (aWinWidth, aWinHeight); | |
4944 | if (aColorScale->GetBreadth() == 0) | |
b4b2ecca | 4945 | { |
4b3d6eb1 | 4946 | aColorScale->SetBreadth (aWinWidth); |
b4b2ecca | 4947 | } |
4b3d6eb1 | 4948 | if (aColorScale->GetHeight() == 0) |
4949 | { | |
4950 | aColorScale->SetHeight (aWinHeight); | |
4951 | } | |
4952 | aColorScale->SetToUpdate(); | |
4953 | ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True); | |
7fd59977 | 4954 | return 0; |
4955 | } | |
4956 | ||
4957 | //============================================================================== | |
4958 | //function : VGraduatedTrihedron | |
a79f67f8 | 4959 | //purpose : Displays or hides a graduated trihedron |
7fd59977 | 4960 | //============================================================================== |
a79f67f8 | 4961 | static Standard_Boolean GetColor (const TCollection_AsciiString& theValue, |
4962 | Quantity_Color& theColor) | |
13a22457 | 4963 | { |
a79f67f8 | 4964 | Quantity_NameOfColor aColorName; |
4965 | TCollection_AsciiString aVal = theValue; | |
4966 | aVal.UpperCase(); | |
4967 | if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName)) | |
13a22457 | 4968 | { |
a79f67f8 | 4969 | return Standard_False; |
13a22457 | 4970 | } |
a79f67f8 | 4971 | theColor = Quantity_Color (aColorName); |
4972 | return Standard_True; | |
13a22457 S |
4973 | } |
4974 | ||
a79f67f8 | 4975 | static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs) |
7fd59977 | 4976 | { |
a79f67f8 | 4977 | if (theArgNum < 2) |
13a22457 | 4978 | { |
a79f67f8 | 4979 | std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help" |
4980 | << theArgs[0] <<"' for more information.\n"; | |
4981 | return 1; //TCL_ERROR | |
13a22457 | 4982 | } |
7fd59977 | 4983 | |
a79f67f8 | 4984 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs; |
4985 | TCollection_AsciiString aParseKey; | |
4986 | for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt) | |
4987 | { | |
4988 | TCollection_AsciiString anArg (theArgs [anArgIt]); | |
4989 | ||
4990 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
4991 | { | |
4992 | aParseKey = anArg; | |
4993 | aParseKey.Remove (1); | |
4994 | aParseKey.LowerCase(); | |
4995 | aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); | |
4996 | continue; | |
4997 | } | |
13a22457 | 4998 | |
a79f67f8 | 4999 | if (aParseKey.IsEmpty()) |
5000 | { | |
5001 | continue; | |
5002 | } | |
5003 | ||
5004 | aMapOfArgs(aParseKey)->Append (anArg); | |
5005 | } | |
5006 | ||
5007 | // Check parameters | |
5008 | for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs); | |
5009 | aMapIt.More(); aMapIt.Next()) | |
7fd59977 | 5010 | { |
a79f67f8 | 5011 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
5012 | const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); | |
5013 | ||
5014 | // Bool key, without arguments | |
5015 | if ((aKey.IsEqual ("on") || aKey.IsEqual ("off")) | |
5016 | && anArgs->IsEmpty()) | |
5017 | { | |
5018 | continue; | |
5019 | } | |
5020 | ||
5021 | // One argument | |
5022 | if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname")) | |
5023 | && anArgs->Length() == 1) | |
5024 | { | |
5025 | continue; | |
5026 | } | |
5027 | ||
5028 | // On/off arguments | |
5029 | if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname") | |
5030 | || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks") | |
536d98e2 | 5031 | || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues") |
5032 | || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes")) | |
a79f67f8 | 5033 | && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off"))) |
5034 | { | |
5035 | continue; | |
5036 | } | |
5037 | ||
5038 | // One string argument | |
5039 | if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor") | |
5040 | || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor")) | |
5041 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
5042 | { | |
5043 | continue; | |
5044 | } | |
5045 | ||
5046 | // One integer argument | |
5047 | if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks") | |
5048 | || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength") | |
5049 | || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset") | |
5050 | || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset")) | |
5051 | && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue()) | |
5052 | { | |
5053 | continue; | |
5054 | } | |
5055 | ||
5056 | // One real argument | |
5057 | if ( aKey.IsEqual ("arrowlength") | |
5058 | && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue())) | |
5059 | { | |
5060 | continue; | |
5061 | } | |
5062 | ||
5063 | // Two string arguments | |
5064 | if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont")) | |
5065 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
13a22457 | 5066 | { |
a79f67f8 | 5067 | continue; |
13a22457 | 5068 | } |
a79f67f8 | 5069 | |
5070 | TCollection_AsciiString aLowerKey; | |
5071 | aLowerKey = "-"; | |
5072 | aLowerKey += aKey; | |
5073 | aLowerKey.LowerCase(); | |
5074 | std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"; | |
5075 | std::cout << "Type help for more information.\n"; | |
5076 | return 1; | |
7fd59977 | 5077 | } |
5078 | ||
a79f67f8 | 5079 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); |
5080 | if (anAISContext.IsNull()) | |
5081 | { | |
586db386 | 5082 | std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n"; |
a79f67f8 | 5083 | return 1; |
5084 | } | |
7fd59977 | 5085 | |
a79f67f8 | 5086 | Standard_Boolean toDisplay = Standard_True; |
5087 | Quantity_Color aColor; | |
5088 | Graphic3d_GraduatedTrihedron aTrihedronData; | |
5089 | // Process parameters | |
5090 | Handle(TColStd_HSequenceOfAsciiString) aValues; | |
5091 | if (aMapOfArgs.Find ("off", aValues)) | |
7fd59977 | 5092 | { |
a79f67f8 | 5093 | toDisplay = Standard_False; |
5094 | } | |
13a22457 | 5095 | |
a79f67f8 | 5096 | // AXES NAMES |
5097 | if (aMapOfArgs.Find ("xname", aValues)) | |
5098 | { | |
5099 | aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1)); | |
5100 | } | |
5101 | if (aMapOfArgs.Find ("yname", aValues)) | |
5102 | { | |
5103 | aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1)); | |
5104 | } | |
5105 | if (aMapOfArgs.Find ("zname", aValues)) | |
5106 | { | |
5107 | aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1)); | |
5108 | } | |
5109 | if (aMapOfArgs.Find ("xdrawname", aValues)) | |
5110 | { | |
536d98e2 | 5111 | aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5112 | } |
5113 | if (aMapOfArgs.Find ("ydrawname", aValues)) | |
5114 | { | |
536d98e2 | 5115 | aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5116 | } |
5117 | if (aMapOfArgs.Find ("zdrawname", aValues)) | |
5118 | { | |
536d98e2 | 5119 | aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5120 | } |
5121 | if (aMapOfArgs.Find ("xnameoffset", aValues)) | |
5122 | { | |
5123 | aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
5124 | } | |
5125 | if (aMapOfArgs.Find ("ynameoffset", aValues)) | |
5126 | { | |
5127 | aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
5128 | } | |
5129 | if (aMapOfArgs.Find ("znameoffset", aValues)) | |
5130 | { | |
5131 | aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
5132 | } | |
13a22457 | 5133 | |
a79f67f8 | 5134 | // COLORS |
5135 | if (aMapOfArgs.Find ("xnamecolor", aValues)) | |
5136 | { | |
5137 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 5138 | { |
a79f67f8 | 5139 | std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n"; |
5140 | return 1; | |
13a22457 | 5141 | } |
a79f67f8 | 5142 | aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor); |
5143 | } | |
5144 | if (aMapOfArgs.Find ("ynamecolor", aValues)) | |
5145 | { | |
5146 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 5147 | { |
a79f67f8 | 5148 | std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n"; |
5149 | return 1; | |
5150 | } | |
5151 | aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor); | |
5152 | } | |
5153 | if (aMapOfArgs.Find ("znamecolor", aValues)) | |
5154 | { | |
5155 | if (!GetColor (aValues->Value(1), aColor)) | |
5156 | { | |
5157 | std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n"; | |
5158 | return 1; | |
5159 | } | |
5160 | aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor); | |
5161 | } | |
5162 | if (aMapOfArgs.Find ("xcolor", aValues)) | |
5163 | { | |
5164 | if (!GetColor (aValues->Value(1), aColor)) | |
5165 | { | |
5166 | std::cout << theArgs[0] << "error: -xcolor wrong color name.\n"; | |
5167 | return 1; | |
5168 | } | |
5169 | aTrihedronData.ChangeXAxisAspect().SetColor (aColor); | |
5170 | } | |
5171 | if (aMapOfArgs.Find ("ycolor", aValues)) | |
5172 | { | |
5173 | if (!GetColor (aValues->Value(1), aColor)) | |
5174 | { | |
5175 | std::cout << theArgs[0] << "error: -ycolor wrong color name.\n"; | |
5176 | return 1; | |
5177 | } | |
5178 | aTrihedronData.ChangeYAxisAspect().SetColor (aColor); | |
5179 | } | |
5180 | if (aMapOfArgs.Find ("zcolor", aValues)) | |
5181 | { | |
5182 | if (!GetColor (aValues->Value(1), aColor)) | |
5183 | { | |
5184 | std::cout << theArgs[0] << "error: -zcolor wrong color name.\n"; | |
5185 | return 1; | |
5186 | } | |
5187 | aTrihedronData.ChangeZAxisAspect().SetColor (aColor); | |
5188 | } | |
5189 | ||
5190 | // TICKMARKS | |
5191 | if (aMapOfArgs.Find ("xticks", aValues)) | |
5192 | { | |
536d98e2 | 5193 | aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5194 | } |
5195 | if (aMapOfArgs.Find ("yticks", aValues)) | |
5196 | { | |
536d98e2 | 5197 | aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5198 | } |
5199 | if (aMapOfArgs.Find ("zticks", aValues)) | |
5200 | { | |
536d98e2 | 5201 | aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5202 | } |
5203 | if (aMapOfArgs.Find ("xticklength", aValues)) | |
5204 | { | |
536d98e2 | 5205 | aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5206 | } |
5207 | if (aMapOfArgs.Find ("yticklength", aValues)) | |
5208 | { | |
536d98e2 | 5209 | aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5210 | } |
5211 | if (aMapOfArgs.Find ("zticklength", aValues)) | |
5212 | { | |
536d98e2 | 5213 | aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 5214 | } |
5215 | if (aMapOfArgs.Find ("xdrawticks", aValues)) | |
5216 | { | |
536d98e2 | 5217 | aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5218 | } |
5219 | if (aMapOfArgs.Find ("ydrawticks", aValues)) | |
5220 | { | |
536d98e2 | 5221 | aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5222 | } |
5223 | if (aMapOfArgs.Find ("zdrawticks", aValues)) | |
5224 | { | |
536d98e2 | 5225 | aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5226 | } |
5227 | ||
5228 | // VALUES | |
5229 | if (aMapOfArgs.Find ("xdrawvalues", aValues)) | |
5230 | { | |
536d98e2 | 5231 | aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5232 | } |
5233 | if (aMapOfArgs.Find ("ydrawvalues", aValues)) | |
5234 | { | |
536d98e2 | 5235 | aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5236 | } |
5237 | if (aMapOfArgs.Find ("zdrawvalues", aValues)) | |
5238 | { | |
536d98e2 | 5239 | aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 5240 | } |
5241 | if (aMapOfArgs.Find ("xvaluesoffset", aValues)) | |
5242 | { | |
5243 | aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
5244 | } | |
5245 | if (aMapOfArgs.Find ("yvaluesoffset", aValues)) | |
5246 | { | |
5247 | aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
5248 | } | |
5249 | if (aMapOfArgs.Find ("zvaluesoffset", aValues)) | |
5250 | { | |
5251 | aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
5252 | } | |
5253 | ||
5254 | // ARROWS | |
5255 | if (aMapOfArgs.Find ("arrowlength", aValues)) | |
5256 | { | |
536d98e2 | 5257 | aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue()); |
a79f67f8 | 5258 | } |
5259 | ||
5260 | // FONTS | |
5261 | if (aMapOfArgs.Find ("namefont", aValues)) | |
5262 | { | |
5263 | aTrihedronData.SetNamesFont (aValues->Value(1)); | |
5264 | } | |
5265 | if (aMapOfArgs.Find ("valuesfont", aValues)) | |
5266 | { | |
5267 | aTrihedronData.SetValuesFont (aValues->Value(1)); | |
5268 | } | |
5269 | ||
536d98e2 | 5270 | if (aMapOfArgs.Find ("drawgrid", aValues)) |
5271 | { | |
5272 | aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on")); | |
5273 | } | |
5274 | if (aMapOfArgs.Find ("drawaxes", aValues)) | |
5275 | { | |
5276 | aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on")); | |
5277 | } | |
5278 | ||
a79f67f8 | 5279 | // The final step: display of erase trihedron |
5280 | if (toDisplay) | |
5281 | { | |
5282 | ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData); | |
13a22457 | 5283 | } |
7fd59977 | 5284 | else |
a79f67f8 | 5285 | { |
5286 | ViewerTest::CurrentView()->GraduatedTrihedronErase(); | |
5287 | } | |
7fd59977 | 5288 | |
5289 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); | |
a79f67f8 | 5290 | ViewerTest::CurrentView()->Redraw(); |
13a22457 | 5291 | |
7fd59977 | 5292 | return 0; |
5293 | } | |
5294 | ||
3bffef55 | 5295 | //============================================================================== |
5296 | //function : VTile | |
5297 | //purpose : | |
5298 | //============================================================================== | |
5299 | static int VTile (Draw_Interpretor& theDI, | |
5300 | Standard_Integer theArgNb, | |
5301 | const char** theArgVec) | |
5302 | { | |
5303 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5304 | if (aView.IsNull()) | |
5305 | { | |
5306 | std::cerr << "Error: no active viewer.\n"; | |
5307 | return 1; | |
5308 | } | |
5309 | ||
5310 | Graphic3d_CameraTile aTile = aView->Camera()->Tile(); | |
5311 | if (theArgNb < 2) | |
5312 | { | |
5313 | theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n" | |
5314 | << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n" | |
5315 | << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n"; | |
5316 | return 0; | |
5317 | } | |
5318 | ||
5319 | aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y()); | |
5320 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
5321 | { | |
5322 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5323 | anArg.LowerCase(); | |
5324 | if (anArg == "-lowerleft" | |
5325 | || anArg == "-upperleft") | |
5326 | { | |
5327 | if (anArgIter + 3 < theArgNb) | |
5328 | { | |
5329 | std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n"; | |
5330 | return 1; | |
5331 | } | |
5332 | aTile.IsTopDown = (anArg == "-upperleft") == Standard_True; | |
5333 | aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
5334 | aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
5335 | } | |
5336 | else if (anArg == "-total" | |
5337 | || anArg == "-totalsize" | |
5338 | || anArg == "-viewsize") | |
5339 | { | |
5340 | if (anArgIter + 3 < theArgNb) | |
5341 | { | |
5342 | std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n"; | |
5343 | return 1; | |
5344 | } | |
5345 | aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
5346 | aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
5347 | if (aTile.TotalSize.x() < 1 | |
5348 | || aTile.TotalSize.y() < 1) | |
5349 | { | |
5350 | std::cerr << "Error: total size is incorrect.\n"; | |
5351 | return 1; | |
5352 | } | |
5353 | } | |
5354 | else if (anArg == "-tilesize") | |
5355 | { | |
5356 | if (anArgIter + 3 < theArgNb) | |
5357 | { | |
5358 | std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n"; | |
5359 | return 1; | |
5360 | } | |
5361 | ||
5362 | aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
5363 | aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
5364 | if (aTile.TileSize.x() < 1 | |
5365 | || aTile.TileSize.y() < 1) | |
5366 | { | |
5367 | std::cerr << "Error: tile size is incorrect.\n"; | |
5368 | return 1; | |
5369 | } | |
5370 | } | |
5371 | else if (anArg == "-unset") | |
5372 | { | |
5373 | aView->Camera()->SetTile (Graphic3d_CameraTile()); | |
5374 | aView->Redraw(); | |
5375 | return 0; | |
5376 | } | |
5377 | } | |
5378 | ||
5379 | if (aTile.TileSize.x() < 1 | |
5380 | || aTile.TileSize.y() < 1) | |
5381 | { | |
5382 | std::cerr << "Error: tile size is undefined.\n"; | |
5383 | return 1; | |
5384 | } | |
5385 | else if (aTile.TotalSize.x() < 1 | |
5386 | || aTile.TotalSize.y() < 1) | |
5387 | { | |
5388 | std::cerr << "Error: total size is undefined.\n"; | |
5389 | return 1; | |
5390 | } | |
5391 | ||
5392 | aView->Camera()->SetTile (aTile); | |
5393 | aView->Redraw(); | |
5394 | return 0; | |
5395 | } | |
5396 | ||
7c3ef2f7 | 5397 | //! Format ZLayer ID. |
5398 | inline const char* formZLayerId (const Standard_Integer theLayerId) | |
5399 | { | |
5400 | switch (theLayerId) | |
5401 | { | |
5402 | case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]"; | |
5403 | case Graphic3d_ZLayerId_Default: return "[DEFAULT]"; | |
5404 | case Graphic3d_ZLayerId_Top: return "[TOP]"; | |
5405 | case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]"; | |
5406 | case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]"; | |
5407 | case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]"; | |
5408 | } | |
5409 | return ""; | |
5410 | } | |
5411 | ||
5412 | //! Print the ZLayer information. | |
5413 | inline void printZLayerInfo (Draw_Interpretor& theDI, | |
5414 | const Graphic3d_ZLayerSettings& theLayer) | |
5415 | { | |
5416 | if (!theLayer.Name().IsEmpty()) | |
5417 | { | |
5418 | theDI << " Name: " << theLayer.Name() << "\n"; | |
5419 | } | |
5420 | if (theLayer.IsImmediate()) | |
5421 | { | |
5422 | theDI << " Immediate: TRUE\n"; | |
5423 | } | |
5424 | theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n"; | |
4ecf34cc | 5425 | theDI << " Culling distance: " << theLayer.CullingDistance() << "\n"; |
5426 | theDI << " Culling size: " << theLayer.CullingSize() << "\n"; | |
7c3ef2f7 | 5427 | theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n"; |
5428 | theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n"; | |
5429 | theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n"; | |
5430 | if (theLayer.PolygonOffset().Mode != Aspect_POM_None) | |
5431 | { | |
5432 | theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n"; | |
5433 | } | |
5434 | } | |
5435 | ||
59f45b7c | 5436 | //============================================================================== |
5437 | //function : VZLayer | |
5438 | //purpose : Test z layer operations for v3d viewer | |
5439 | //============================================================================== | |
7c3ef2f7 | 5440 | static int VZLayer (Draw_Interpretor& theDI, |
5441 | Standard_Integer theArgNb, | |
5442 | const char** theArgVec) | |
59f45b7c | 5443 | { |
7c3ef2f7 | 5444 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
59f45b7c | 5445 | if (aContextAIS.IsNull()) |
5446 | { | |
7c3ef2f7 | 5447 | std::cout << "No active viewer!\n"; |
59f45b7c | 5448 | return 1; |
5449 | } | |
5450 | ||
5451 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
7c3ef2f7 | 5452 | if (theArgNb < 2) |
59f45b7c | 5453 | { |
7c3ef2f7 | 5454 | TColStd_SequenceOfInteger aLayers; |
5455 | aViewer->GetAllZLayers (aLayers); | |
5456 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
5457 | { | |
5458 | theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n"; | |
5459 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
5460 | printZLayerInfo (theDI, aSettings); | |
5461 | } | |
59f45b7c | 5462 | return 1; |
5463 | } | |
5464 | ||
7c3ef2f7 | 5465 | Standard_Integer anArgIter = 1; |
5466 | Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN; | |
5467 | ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView()); | |
5468 | if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) | |
59f45b7c | 5469 | { |
7c3ef2f7 | 5470 | ++anArgIter; |
5471 | } | |
59f45b7c | 5472 | |
7c3ef2f7 | 5473 | { |
55c8f0f7 BB |
5474 | TCollection_AsciiString aFirstArg (theArgVec[anArgIter]); |
5475 | if (aFirstArg.IsIntegerValue()) | |
c5751993 | 5476 | { |
7c3ef2f7 | 5477 | ++anArgIter; |
55c8f0f7 | 5478 | aLayerId = aFirstArg.IntegerValue(); |
c5751993 | 5479 | } |
7c3ef2f7 | 5480 | else |
c5751993 | 5481 | { |
55c8f0f7 | 5482 | if (ViewerTest::ParseZLayerName (aFirstArg.ToCString(), aLayerId)) |
7c3ef2f7 | 5483 | { |
55c8f0f7 | 5484 | ++anArgIter; |
7c3ef2f7 | 5485 | } |
c5751993 | 5486 | } |
7c3ef2f7 | 5487 | } |
c5751993 | 5488 | |
1c728f2d | 5489 | Graphic3d_ZLayerId anOtherLayerId = Graphic3d_ZLayerId_UNKNOWN; |
7c3ef2f7 | 5490 | for (; anArgIter < theArgNb; ++anArgIter) |
5491 | { | |
5492 | // perform operation | |
5493 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5494 | anArg.LowerCase(); | |
5495 | if (anUpdateTool.parseRedrawMode (anArg)) | |
c5751993 | 5496 | { |
7c3ef2f7 | 5497 | // |
c5751993 | 5498 | } |
7c3ef2f7 | 5499 | else if (anArg == "-add" |
5500 | || anArg == "add") | |
c5751993 | 5501 | { |
7c3ef2f7 | 5502 | aLayerId = Graphic3d_ZLayerId_UNKNOWN; |
5503 | if (!aViewer->AddZLayer (aLayerId)) | |
5504 | { | |
5505 | std::cout << "Error: can not add a new z layer!\n"; | |
5506 | return 0; | |
5507 | } | |
5508 | ||
5509 | theDI << aLayerId; | |
c5751993 | 5510 | } |
1c728f2d | 5511 | else if (anArg == "-insertbefore" |
5512 | && anArgIter + 1 < theArgNb | |
5513 | && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId)) | |
5514 | { | |
5515 | ++anArgIter; | |
5516 | aLayerId = Graphic3d_ZLayerId_UNKNOWN; | |
5517 | if (!aViewer->InsertLayerBefore (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId)) | |
5518 | { | |
5519 | std::cout << "Error: can not add a new z layer!\n"; | |
5520 | return 0; | |
5521 | } | |
5522 | ||
5523 | theDI << aLayerId; | |
5524 | } | |
5525 | else if (anArg == "-insertafter" | |
5526 | && anArgIter + 1 < theArgNb | |
5527 | && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId)) | |
5528 | { | |
5529 | ++anArgIter; | |
5530 | aLayerId = Graphic3d_ZLayerId_UNKNOWN; | |
5531 | if (!aViewer->InsertLayerAfter (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId)) | |
5532 | { | |
5533 | std::cout << "Error: can not add a new z layer!\n"; | |
5534 | return 0; | |
5535 | } | |
5536 | ||
5537 | theDI << aLayerId; | |
5538 | } | |
7c3ef2f7 | 5539 | else if (anArg == "-del" |
5540 | || anArg == "-delete" | |
5541 | || anArg == "del") | |
c5751993 | 5542 | { |
7c3ef2f7 | 5543 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
5544 | { | |
5545 | if (++anArgIter >= theArgNb) | |
5546 | { | |
5547 | std::cout << "Syntax error: id of z layer to remove is missing\n"; | |
5548 | return 1; | |
5549 | } | |
5550 | ||
5551 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); | |
5552 | } | |
5553 | ||
5554 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN | |
5555 | || aLayerId == Graphic3d_ZLayerId_Default | |
5556 | || aLayerId == Graphic3d_ZLayerId_Top | |
5557 | || aLayerId == Graphic3d_ZLayerId_Topmost | |
5558 | || aLayerId == Graphic3d_ZLayerId_TopOSD | |
5559 | || aLayerId == Graphic3d_ZLayerId_BotOSD) | |
5560 | { | |
5561 | std::cout << "Syntax error: standard Z layer can not be removed\n"; | |
5562 | return 1; | |
5563 | } | |
5564 | ||
5565 | // move all object displayed in removing layer to default layer | |
5566 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); | |
5567 | anObjIter.More(); anObjIter.Next()) | |
5568 | { | |
8f521168 | 5569 | const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1(); |
7c3ef2f7 | 5570 | if (aPrs.IsNull() |
5571 | || aPrs->ZLayer() != aLayerId) | |
5572 | { | |
5573 | continue; | |
5574 | } | |
5575 | aPrs->SetZLayer (Graphic3d_ZLayerId_Default); | |
5576 | } | |
5577 | ||
5578 | if (!aViewer->RemoveZLayer (aLayerId)) | |
5579 | { | |
5580 | std::cout << "Z layer can not be removed!\n"; | |
5581 | } | |
5582 | else | |
5583 | { | |
5584 | theDI << aLayerId << " "; | |
5585 | } | |
c5751993 | 5586 | } |
7c3ef2f7 | 5587 | else if (anArg == "-get" |
5588 | || anArg == "get") | |
c5751993 | 5589 | { |
7c3ef2f7 | 5590 | TColStd_SequenceOfInteger aLayers; |
5591 | aViewer->GetAllZLayers (aLayers); | |
5592 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
5593 | { | |
5594 | theDI << aLayeriter.Value() << " "; | |
5595 | } | |
5596 | ||
5597 | theDI << "\n"; | |
c5751993 | 5598 | } |
7c3ef2f7 | 5599 | else if (anArg == "-name") |
c5751993 | 5600 | { |
7c3ef2f7 | 5601 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
c5751993 | 5602 | { |
7c3ef2f7 | 5603 | std::cout << "Syntax error: id of Z layer is missing\n"; |
c5751993 | 5604 | return 1; |
5605 | } | |
5606 | ||
7c3ef2f7 | 5607 | if (++anArgIter >= theArgNb) |
5608 | { | |
5609 | std::cout << "Syntax error: name is missing\n"; | |
5610 | return 1; | |
5611 | } | |
c5751993 | 5612 | |
7c3ef2f7 | 5613 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); |
5614 | aSettings.SetName (theArgVec[anArgIter]); | |
5615 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 5616 | } |
7c3ef2f7 | 5617 | else if (anArg == "-origin") |
c5751993 | 5618 | { |
7c3ef2f7 | 5619 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
5620 | { | |
5621 | std::cout << "Syntax error: id of Z layer is missing\n"; | |
5622 | return 1; | |
5623 | } | |
5624 | ||
5625 | if (anArgIter + 2 >= theArgNb) | |
5626 | { | |
5627 | std::cout << "Syntax error: origin coordinates are missing\n"; | |
5628 | return 1; | |
5629 | } | |
5630 | ||
5631 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
5632 | gp_XYZ anOrigin; | |
5633 | anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1])); | |
5634 | anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2])); | |
5635 | anOrigin.SetZ (0.0); | |
5636 | if (anArgIter + 3 < theArgNb) | |
5637 | { | |
5638 | anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3])); | |
5639 | anArgIter += 3; | |
5640 | } | |
5641 | else | |
5642 | { | |
5643 | anArgIter += 2; | |
5644 | } | |
5645 | aSettings.SetOrigin (anOrigin); | |
5646 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 5647 | } |
4ecf34cc | 5648 | else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN |
5649 | && anArgIter + 1 < theArgNb | |
5650 | && (anArg == "-cullingdistance" | |
5651 | || anArg == "-cullingdist" | |
5652 | || anArg == "-culldistance" | |
5653 | || anArg == "-culldist" | |
5654 | || anArg == "-distcull" | |
5655 | || anArg == "-distculling" | |
5656 | || anArg == "-distanceculling")) | |
5657 | { | |
5658 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
5659 | const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]); | |
5660 | aSettings.SetCullingDistance (aDist); | |
5661 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
5662 | } | |
5663 | else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN | |
5664 | && anArgIter + 1 < theArgNb | |
5665 | && (anArg == "-cullingsize" | |
5666 | || anArg == "-cullsize" | |
5667 | || anArg == "-sizecull" | |
5668 | || anArg == "-sizeculling")) | |
5669 | { | |
5670 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
5671 | const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]); | |
5672 | aSettings.SetCullingSize (aSize); | |
5673 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
5674 | } | |
7c3ef2f7 | 5675 | else if (anArg == "-settings" |
5676 | || anArg == "settings") | |
c5751993 | 5677 | { |
7c3ef2f7 | 5678 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
5679 | { | |
5680 | if (++anArgIter >= theArgNb) | |
5681 | { | |
5682 | std::cout << "Syntax error: id of Z layer is missing\n"; | |
5683 | return 1; | |
5684 | } | |
5685 | ||
5686 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); | |
5687 | } | |
5688 | ||
5689 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
5690 | printZLayerInfo (theDI, aSettings); | |
c5751993 | 5691 | } |
7c3ef2f7 | 5692 | else if (anArg == "-enable" |
5693 | || anArg == "enable" | |
5694 | || anArg == "-disable" | |
5695 | || anArg == "disable") | |
83da37b1 | 5696 | { |
7c3ef2f7 | 5697 | const Standard_Boolean toEnable = anArg == "-enable" |
5698 | || anArg == "enable"; | |
5699 | if (++anArgIter >= theArgNb) | |
5700 | { | |
5701 | std::cout << "Syntax error: option name is missing\n"; | |
5702 | return 1; | |
5703 | } | |
c5751993 | 5704 | |
7c3ef2f7 | 5705 | TCollection_AsciiString aSubOp (theArgVec[anArgIter]); |
5706 | aSubOp.LowerCase(); | |
5707 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) | |
5708 | { | |
5709 | if (++anArgIter >= theArgNb) | |
5710 | { | |
5711 | std::cout << "Syntax error: id of Z layer is missing\n"; | |
5712 | return 1; | |
5713 | } | |
c5751993 | 5714 | |
7c3ef2f7 | 5715 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); |
5716 | } | |
c5751993 | 5717 | |
7c3ef2f7 | 5718 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); |
5719 | if (aSubOp == "depthtest" | |
5720 | || aSubOp == "test") | |
5721 | { | |
5722 | aSettings.SetEnableDepthTest (toEnable); | |
5723 | } | |
5724 | else if (aSubOp == "depthwrite" | |
5725 | || aSubOp == "write") | |
5726 | { | |
5727 | aSettings.SetEnableDepthWrite (toEnable); | |
5728 | } | |
5729 | else if (aSubOp == "depthclear" | |
5730 | || aSubOp == "clear") | |
5731 | { | |
5732 | aSettings.SetClearDepth (toEnable); | |
5733 | } | |
5734 | else if (aSubOp == "depthoffset" | |
5735 | || aSubOp == "offset") | |
5736 | { | |
5737 | Graphic3d_PolygonOffset aParams; | |
5738 | aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None; | |
5739 | if (toEnable) | |
5740 | { | |
5741 | if (anArgIter + 2 >= theArgNb) | |
5742 | { | |
5743 | std::cout << "Syntax error: factor and units values for depth offset are missing\n"; | |
5744 | return 1; | |
5745 | } | |
c5751993 | 5746 | |
7c3ef2f7 | 5747 | aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter])); |
5748 | aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter])); | |
5749 | } | |
5750 | aSettings.SetPolygonOffset (aParams); | |
5751 | } | |
5752 | else if (aSubOp == "positiveoffset" | |
5753 | || aSubOp == "poffset") | |
5754 | { | |
5755 | if (toEnable) | |
5756 | { | |
5757 | aSettings.SetDepthOffsetPositive(); | |
5758 | } | |
5759 | else | |
5760 | { | |
5761 | aSettings.SetPolygonOffset (Graphic3d_PolygonOffset()); | |
5762 | } | |
5763 | } | |
5764 | else if (aSubOp == "negativeoffset" | |
5765 | || aSubOp == "noffset") | |
5766 | { | |
5767 | if (toEnable) | |
5768 | { | |
5769 | aSettings.SetDepthOffsetNegative(); | |
5770 | } | |
5771 | else | |
5772 | { | |
5773 | aSettings.SetPolygonOffset(Graphic3d_PolygonOffset()); | |
5774 | } | |
5775 | } | |
5776 | else if (aSubOp == "textureenv") | |
5777 | { | |
5778 | aSettings.SetEnvironmentTexture (toEnable); | |
5779 | } | |
1c728f2d | 5780 | else if (aSubOp == "raytracing") |
5781 | { | |
5782 | aSettings.SetRaytracable (toEnable); | |
5783 | } | |
7c3ef2f7 | 5784 | |
5785 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 5786 | } |
7c3ef2f7 | 5787 | else |
83da37b1 | 5788 | { |
7c3ef2f7 | 5789 | std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n"; |
5790 | return 1; | |
83da37b1 | 5791 | } |
59f45b7c | 5792 | } |
5793 | ||
5794 | return 0; | |
5795 | } | |
5796 | ||
c357e426 | 5797 | // The interactive presentation of 2d layer item |
5798 | // for "vlayerline" command it provides a presentation of | |
5799 | // line with user-defined linewidth, linetype and transparency. | |
61b0191c | 5800 | class V3d_LineItem : public AIS_InteractiveObject |
20637bd2 | 5801 | { |
5802 | public: | |
5803 | // CASCADE RTTI | |
92efcf78 | 5804 | DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject) |
4fe56619 | 5805 | |
20637bd2 | 5806 | // constructor |
5807 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
5808 | Standard_Real X2, Standard_Real Y2, | |
20637bd2 | 5809 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, |
5810 | Standard_Real theWidth = 0.5, | |
5811 | Standard_Real theTransp = 1.0); | |
5812 | ||
61b0191c | 5813 | private: |
5814 | ||
5815 | void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
5816 | const Handle(Prs3d_Presentation)& thePresentation, | |
79104795 | 5817 | const Standard_Integer theMode) Standard_OVERRIDE; |
61b0191c | 5818 | |
5819 | void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/, | |
79104795 | 5820 | const Standard_Integer /*aMode*/) Standard_OVERRIDE |
5821 | {} | |
20637bd2 | 5822 | |
5823 | private: | |
5824 | ||
5825 | Standard_Real myX1, myY1, myX2, myY2; | |
eafb234b | 5826 | Aspect_TypeOfLine myType; |
20637bd2 | 5827 | Standard_Real myWidth; |
20637bd2 | 5828 | }; |
5829 | ||
20637bd2 | 5830 | // default constructor for line item |
4fe56619 | 5831 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
20637bd2 | 5832 | Standard_Real X2, Standard_Real Y2, |
20637bd2 | 5833 | Aspect_TypeOfLine theType, |
5834 | Standard_Real theWidth, | |
5835 | Standard_Real theTransp) : | |
61b0191c | 5836 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), |
5837 | myType(theType), myWidth(theWidth) | |
20637bd2 | 5838 | { |
61b0191c | 5839 | SetTransparency (1-theTransp); |
20637bd2 | 5840 | } |
5841 | ||
5842 | // render line | |
61b0191c | 5843 | void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/, |
5844 | const Handle(Prs3d_Presentation)& thePresentation, | |
5845 | const Standard_Integer /*theMode*/) | |
20637bd2 | 5846 | { |
61b0191c | 5847 | thePresentation->Clear(); |
5848 | Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB); | |
5849 | Standard_Integer aWidth, aHeight; | |
5850 | ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight); | |
5851 | Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); | |
5852 | Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5); | |
5853 | aPrim->AddVertex(myX1, aHeight-myY1, 0.); | |
5854 | aPrim->AddVertex(myX2, aHeight-myY2, 0.); | |
5855 | Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth); | |
5856 | aGroup->SetPrimitivesAspect (anAspect->Aspect()); | |
5857 | aGroup->AddPrimitiveArray (aPrim); | |
20637bd2 | 5858 | } |
5859 | ||
5860 | //============================================================================= | |
5861 | //function : VLayerLine | |
5862 | //purpose : Draws line in the v3d view layer with given attributes: linetype, | |
5863 | // : linewidth, transparency coefficient | |
5864 | //============================================================================ | |
5865 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
5866 | { | |
5867 | // get the active view | |
5868 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5869 | if (aView.IsNull()) | |
5870 | { | |
5871 | di << "Call vinit before!\n"; | |
5872 | return 1; | |
5873 | } | |
5874 | else if (argc < 5) | |
5875 | { | |
5876 | di << "Use: " << argv[0]; | |
5877 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; | |
5878 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; | |
5879 | di << " 0 - solid \n"; | |
5880 | di << " 1 - dashed \n"; | |
5881 | di << " 2 - dot \n"; | |
5882 | di << " 3 - dashdot\n"; | |
5883 | di << " transparency : { 0.0 - 1.0 } \n"; | |
5884 | di << " 0.0 - transparent\n"; | |
5885 | di << " 1.0 - visible \n"; | |
5886 | return 1; | |
5887 | } | |
5888 | ||
61b0191c | 5889 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
20637bd2 | 5890 | // get the input params |
91322f44 | 5891 | Standard_Real X1 = Draw::Atof(argv[1]); |
5892 | Standard_Real Y1 = Draw::Atof(argv[2]); | |
5893 | Standard_Real X2 = Draw::Atof(argv[3]); | |
5894 | Standard_Real Y2 = Draw::Atof(argv[4]); | |
20637bd2 | 5895 | |
3a4a3962 | 5896 | Standard_Real aWidth = 0.5; |
5897 | Standard_Real aTransparency = 1.0; | |
20637bd2 | 5898 | |
5899 | // has width | |
5900 | if (argc > 5) | |
91322f44 | 5901 | aWidth = Draw::Atof(argv[5]); |
20637bd2 | 5902 | |
3a4a3962 | 5903 | // select appropriate line type |
5904 | Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID; | |
5905 | if (argc > 6 | |
5906 | && !ViewerTest::ParseLineType (argv[6], aLineType)) | |
5907 | { | |
5908 | std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n"; | |
5909 | return 1; | |
5910 | } | |
20637bd2 | 5911 | |
5912 | // has transparency | |
5913 | if (argc > 7) | |
5914 | { | |
91322f44 | 5915 | aTransparency = Draw::Atof(argv[7]); |
4fe56619 | 5916 | if (aTransparency < 0 || aTransparency > 1.0) |
20637bd2 | 5917 | aTransparency = 1.0; |
5918 | } | |
5919 | ||
61b0191c | 5920 | static Handle (V3d_LineItem) aLine; |
5921 | if (!aLine.IsNull()) | |
25289ec1 | 5922 | { |
0577ae8c | 5923 | aContext->Erase (aLine, Standard_False); |
25289ec1 | 5924 | } |
61b0191c | 5925 | aLine = new V3d_LineItem (X1, Y1, X2, Y2, |
5926 | aLineType, aWidth, | |
5927 | aTransparency); | |
25289ec1 | 5928 | |
778cd667 | 5929 | aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); |
61b0191c | 5930 | aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD); |
5931 | aLine->SetToUpdate(); | |
5932 | aContext->Display (aLine, Standard_True); | |
25289ec1 | 5933 | |
5934 | return 0; | |
5935 | } | |
5936 | ||
61b0191c | 5937 | |
2bd4c032 | 5938 | //============================================================================== |
5939 | //function : VGrid | |
5940 | //purpose : | |
5941 | //============================================================================== | |
5942 | ||
35e08fe8 | 5943 | static int VGrid (Draw_Interpretor& /*theDI*/, |
2bd4c032 | 5944 | Standard_Integer theArgNb, |
5945 | const char** theArgVec) | |
5946 | { | |
2bd4c032 | 5947 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
5948 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
5949 | if (aView.IsNull() || aViewer.IsNull()) | |
5950 | { | |
79931835 | 5951 | std::cerr << "Error: no active view\n"; |
2bd4c032 | 5952 | return 1; |
5953 | } | |
5954 | ||
5955 | Aspect_GridType aType = aViewer->GridType(); | |
5956 | Aspect_GridDrawMode aMode = aViewer->GridDrawMode(); | |
79931835 | 5957 | Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY; |
5958 | Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0; | |
5959 | bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false; | |
224f48fa | 5960 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
79931835 | 5961 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
2bd4c032 | 5962 | { |
79931835 | 5963 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
5964 | anArg.LowerCase(); | |
5965 | if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) | |
224f48fa | 5966 | { |
5967 | continue; | |
5968 | } | |
79931835 | 5969 | else if (anArgIter + 1 < theArgNb |
5970 | && anArg == "-type") | |
5971 | { | |
5972 | TCollection_AsciiString anArgNext (theArgVec[++anArgIter]); | |
5973 | anArgNext.LowerCase(); | |
5974 | if (anArgNext == "r" | |
5975 | || anArgNext == "rect" | |
5976 | || anArgNext == "rectangular") | |
5977 | { | |
5978 | aType = Aspect_GT_Rectangular; | |
5979 | } | |
5980 | else if (anArgNext == "c" | |
5981 | || anArgNext == "circ" | |
5982 | || anArgNext == "circular") | |
5983 | { | |
5984 | aType = Aspect_GT_Circular; | |
5985 | } | |
5986 | else | |
5987 | { | |
5988 | std::cout << "Syntax error at '" << anArgNext << "'\n"; | |
5989 | return 1; | |
5990 | } | |
5991 | } | |
5992 | else if (anArgIter + 1 < theArgNb | |
5993 | && anArg == "-mode") | |
5994 | { | |
5995 | TCollection_AsciiString anArgNext (theArgVec[++anArgIter]); | |
5996 | anArgNext.LowerCase(); | |
5997 | if (anArgNext == "l" | |
5998 | || anArgNext == "line" | |
5999 | || anArgNext == "lines") | |
6000 | { | |
6001 | aMode = Aspect_GDM_Lines; | |
6002 | } | |
6003 | else if (anArgNext == "p" | |
6004 | || anArgNext == "point" | |
6005 | || anArgNext == "points") | |
6006 | { | |
6007 | aMode = Aspect_GDM_Points; | |
6008 | } | |
6009 | else | |
6010 | { | |
6011 | std::cout << "Syntax error at '" << anArgNext << "'\n"; | |
6012 | return 1; | |
6013 | } | |
6014 | } | |
6015 | else if (anArgIter + 2 < theArgNb | |
6016 | && (anArg == "-origin" | |
6017 | || anArg == "-orig")) | |
6018 | { | |
6019 | hasOrigin = true; | |
6020 | aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]), | |
6021 | Draw::Atof (theArgVec[anArgIter + 2])); | |
6022 | anArgIter += 2; | |
6023 | } | |
6024 | else if (anArgIter + 2 < theArgNb | |
6025 | && anArg == "-step") | |
6026 | { | |
6027 | hasStep = true; | |
6028 | aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]), | |
6029 | Draw::Atof (theArgVec[anArgIter + 2])); | |
6030 | if (aNewStepXY.x() <= 0.0 | |
6031 | || aNewStepXY.y() <= 0.0) | |
6032 | { | |
6033 | std::cout << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n"; | |
6034 | return 1; | |
6035 | } | |
6036 | anArgIter += 2; | |
6037 | } | |
6038 | else if (anArgIter + 1 < theArgNb | |
6039 | && (anArg == "-angle" | |
6040 | || anArg == "-rotangle" | |
6041 | || anArg == "-rotationangle")) | |
6042 | { | |
6043 | hasRotAngle = true; | |
6044 | aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]); | |
6045 | } | |
6046 | else if (anArgIter + 1 < theArgNb | |
6047 | && (anArg == "-zoffset" | |
6048 | || anArg == "-dz")) | |
6049 | { | |
6050 | hasZOffset = true; | |
6051 | aNewZOffset = Draw::Atof (theArgVec[++anArgIter]); | |
6052 | } | |
6053 | else if (anArgIter + 1 < theArgNb | |
6054 | && anArg == "-radius") | |
6055 | { | |
6056 | hasSize = true; | |
6057 | ++anArgIter; | |
6058 | aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0); | |
6059 | if (aNewStepXY.x() <= 0.0) | |
6060 | { | |
6061 | std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'\n"; | |
6062 | return 1; | |
6063 | } | |
6064 | } | |
6065 | else if (anArgIter + 2 < theArgNb | |
6066 | && anArg == "-size") | |
6067 | { | |
6068 | hasSize = true; | |
6069 | aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]), | |
6070 | Draw::Atof (theArgVec[anArgIter + 2])); | |
6071 | if (aNewStepXY.x() <= 0.0 | |
6072 | || aNewStepXY.y() <= 0.0) | |
6073 | { | |
6074 | std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n"; | |
6075 | return 1; | |
6076 | } | |
6077 | anArgIter += 2; | |
6078 | } | |
6079 | else if (anArg == "r" | |
6080 | || anArg == "rect" | |
6081 | || anArg == "rectangular") | |
2bd4c032 | 6082 | { |
6083 | aType = Aspect_GT_Rectangular; | |
6084 | } | |
79931835 | 6085 | else if (anArg == "c" |
6086 | || anArg == "circ" | |
6087 | || anArg == "circular") | |
2bd4c032 | 6088 | { |
6089 | aType = Aspect_GT_Circular; | |
6090 | } | |
79931835 | 6091 | else if (anArg == "l" |
6092 | || anArg == "line" | |
6093 | || anArg == "lines") | |
2bd4c032 | 6094 | { |
6095 | aMode = Aspect_GDM_Lines; | |
6096 | } | |
79931835 | 6097 | else if (anArg == "p" |
6098 | || anArg == "point" | |
6099 | || anArg == "points") | |
2bd4c032 | 6100 | { |
6101 | aMode = Aspect_GDM_Points; | |
6102 | } | |
79931835 | 6103 | else if (anArgIter + 1 >= theArgNb |
6104 | && anArg == "off") | |
2bd4c032 | 6105 | { |
6106 | aViewer->DeactivateGrid(); | |
6107 | return 0; | |
6108 | } | |
6109 | else | |
6110 | { | |
79931835 | 6111 | std::cout << "Syntax error at '" << anArg << "'\n"; |
6112 | return 1; | |
2bd4c032 | 6113 | } |
6114 | } | |
6115 | ||
2bd4c032 | 6116 | if (aType == Aspect_GT_Rectangular) |
6117 | { | |
79931835 | 6118 | Graphic3d_Vec2d anOrigXY, aStepXY; |
6119 | Standard_Real aRotAngle = 0.0; | |
6120 | aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle); | |
6121 | if (hasOrigin) | |
6122 | { | |
6123 | anOrigXY = aNewOriginXY; | |
6124 | } | |
6125 | if (hasStep) | |
6126 | { | |
6127 | aStepXY = aNewStepXY; | |
6128 | } | |
6129 | if (hasRotAngle) | |
6130 | { | |
6131 | aRotAngle = aNewRotAngle; | |
6132 | } | |
6133 | aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle); | |
6134 | if (hasSize || hasZOffset) | |
2bd4c032 | 6135 | { |
79931835 | 6136 | Graphic3d_Vec3d aSize; |
6137 | aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z()); | |
6138 | if (hasSize) | |
6139 | { | |
6140 | aSize.x() = aNewSizeXY.x(); | |
6141 | aSize.y() = aNewSizeXY.y(); | |
6142 | } | |
6143 | if (hasZOffset) | |
6144 | { | |
6145 | aSize.z() = aNewZOffset; | |
6146 | } | |
6147 | aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z()); | |
2bd4c032 | 6148 | } |
2bd4c032 | 6149 | } |
6150 | else if (aType == Aspect_GT_Circular) | |
6151 | { | |
79931835 | 6152 | Graphic3d_Vec2d anOrigXY; |
ee2be2a8 | 6153 | Standard_Real aRadiusStep; |
2bd4c032 | 6154 | Standard_Integer aDivisionNumber; |
79931835 | 6155 | Standard_Real aRotAngle = 0.0; |
6156 | aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle); | |
6157 | if (hasOrigin) | |
6158 | { | |
6159 | anOrigXY = aNewOriginXY; | |
6160 | } | |
6161 | if (hasStep) | |
6162 | { | |
6163 | aRadiusStep = aNewStepXY[0]; | |
6164 | aDivisionNumber = (int )aNewStepXY[1]; | |
6165 | if (aDivisionNumber < 1) | |
6166 | { | |
6167 | std::cout << "Syntax error: invalid division number '" << aNewStepXY[1] << "'\n"; | |
6168 | return 1; | |
6169 | } | |
6170 | } | |
6171 | if (hasRotAngle) | |
2bd4c032 | 6172 | { |
79931835 | 6173 | aRotAngle = aNewRotAngle; |
2bd4c032 | 6174 | } |
6175 | ||
79931835 | 6176 | aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle); |
6177 | if (hasSize || hasZOffset) | |
6178 | { | |
6179 | Standard_Real aRadius = 0.0, aZOffset = 0.0; | |
6180 | aViewer->CircularGridGraphicValues (aRadius, aZOffset); | |
6181 | if (hasSize) | |
6182 | { | |
6183 | aRadius = aNewSizeXY.x(); | |
6184 | if (aNewSizeXY.y() != 0.0) | |
6185 | { | |
6186 | std::cout << "Syntax error: circular size should be specified as radius\n"; | |
6187 | return 1; | |
6188 | } | |
6189 | } | |
6190 | if (hasZOffset) | |
6191 | { | |
6192 | aZOffset = aNewZOffset; | |
6193 | } | |
6194 | aViewer->SetCircularGridGraphicValues (aRadius, aZOffset); | |
6195 | } | |
2bd4c032 | 6196 | } |
79931835 | 6197 | aViewer->ActivateGrid (aType, aMode); |
2bd4c032 | 6198 | return 0; |
6199 | } | |
6200 | ||
c40b7d58 | 6201 | //============================================================================== |
6202 | //function : VPriviledgedPlane | |
6203 | //purpose : | |
6204 | //============================================================================== | |
6205 | ||
6206 | static int VPriviledgedPlane (Draw_Interpretor& theDI, | |
6207 | Standard_Integer theArgNb, | |
6208 | const char** theArgVec) | |
6209 | { | |
6210 | if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10) | |
6211 | { | |
6212 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
6213 | theDI.PrintHelp (theArgVec[0]); | |
6214 | return 1; | |
6215 | } | |
6216 | ||
6217 | // get the active viewer | |
6218 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
6219 | if (aViewer.IsNull()) | |
6220 | { | |
6221 | std::cerr << "Error: no active viewer. Please call vinit.\n"; | |
6222 | return 1; | |
6223 | } | |
6224 | ||
6225 | if (theArgNb == 1) | |
6226 | { | |
6227 | gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane(); | |
6228 | const gp_Pnt& anOrig = aPriviledgedPlane.Location(); | |
6229 | const gp_Dir& aNorm = aPriviledgedPlane.Direction(); | |
6230 | const gp_Dir& aXDir = aPriviledgedPlane.XDirection(); | |
6231 | theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " " | |
6232 | << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " " | |
6233 | << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n"; | |
6234 | return 0; | |
6235 | } | |
6236 | ||
6237 | Standard_Integer anArgIdx = 1; | |
6238 | Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]); | |
6239 | Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]); | |
6240 | Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]); | |
6241 | Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]); | |
6242 | Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]); | |
6243 | Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]); | |
6244 | ||
6245 | gp_Ax3 aPriviledgedPlane; | |
6246 | gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ); | |
6247 | gp_Dir aNorm (aNormX, aNormY, aNormZ); | |
6248 | if (theArgNb > 7) | |
6249 | { | |
6250 | Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]); | |
6251 | Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]); | |
6252 | Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]); | |
6253 | gp_Dir aXDir (aXDirX, aXDirY, aXDirZ); | |
6254 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir); | |
6255 | } | |
6256 | else | |
6257 | { | |
6258 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm); | |
6259 | } | |
6260 | ||
6261 | aViewer->SetPrivilegedPlane (aPriviledgedPlane); | |
6262 | ||
6263 | return 0; | |
6264 | } | |
6265 | ||
f25b82d6 | 6266 | //============================================================================== |
6267 | //function : VConvert | |
6268 | //purpose : | |
6269 | //============================================================================== | |
6270 | ||
6271 | static int VConvert (Draw_Interpretor& theDI, | |
6272 | Standard_Integer theArgNb, | |
6273 | const char** theArgVec) | |
6274 | { | |
6275 | // get the active view | |
6276 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6277 | if (aView.IsNull()) | |
6278 | { | |
c40b7d58 | 6279 | std::cerr << "Error: no active view. Please call vinit.\n"; |
f25b82d6 | 6280 | return 1; |
6281 | } | |
6282 | ||
6283 | enum { Model, Ray, View, Window, Grid } aMode = Model; | |
6284 | ||
6285 | // access coordinate arguments | |
6286 | TColStd_SequenceOfReal aCoord; | |
6287 | Standard_Integer anArgIdx = 1; | |
6288 | for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx) | |
6289 | { | |
6290 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
6291 | if (!anArg.IsRealValue()) | |
6292 | { | |
6293 | break; | |
6294 | } | |
6295 | aCoord.Append (anArg.RealValue()); | |
6296 | } | |
6297 | ||
6298 | // non-numeric argument too early | |
6299 | if (aCoord.IsEmpty()) | |
6300 | { | |
6301 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
6302 | theDI.PrintHelp (theArgVec[0]); | |
6303 | return 1; | |
6304 | } | |
6305 | ||
6306 | // collect all other arguments and options | |
6307 | for (; anArgIdx < theArgNb; ++anArgIdx) | |
6308 | { | |
6309 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
6310 | anArg.LowerCase(); | |
6311 | if (anArg == "window") aMode = Window; | |
6312 | else if (anArg == "view") aMode = View; | |
6313 | else if (anArg == "grid") aMode = Grid; | |
6314 | else if (anArg == "ray") aMode = Ray; | |
6315 | else | |
6316 | { | |
6317 | std::cerr << "Error: wrong argument " << anArg << "! See usage:\n"; | |
6318 | theDI.PrintHelp (theArgVec[0]); | |
6319 | return 1; | |
6320 | } | |
6321 | } | |
6322 | ||
6323 | // complete input checks | |
6324 | if ((aCoord.Length() == 1 && theArgNb > 3) || | |
6325 | (aCoord.Length() == 2 && theArgNb > 4) || | |
6326 | (aCoord.Length() == 3 && theArgNb > 5)) | |
6327 | { | |
6328 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
6329 | theDI.PrintHelp (theArgVec[0]); | |
6330 | return 1; | |
6331 | } | |
6332 | ||
6333 | Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; | |
6334 | Standard_Integer aXYp[2] = {0, 0}; | |
6335 | ||
6336 | // convert one-dimensional coordinate | |
6337 | if (aCoord.Length() == 1) | |
6338 | { | |
6339 | switch (aMode) | |
6340 | { | |
ee2be2a8 | 6341 | case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0; |
6342 | case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0; | |
f25b82d6 | 6343 | default: |
6344 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
6345 | theDI.PrintHelp (theArgVec[0]); | |
6346 | return 1; | |
6347 | } | |
6348 | } | |
6349 | ||
6350 | // convert 2D coordinates from projection or view reference space | |
6351 | if (aCoord.Length() == 2) | |
6352 | { | |
6353 | switch (aMode) | |
6354 | { | |
6355 | case Model : | |
6356 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
6357 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
6358 | return 0; | |
6359 | ||
6360 | case View : | |
6361 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]); | |
6362 | theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n"; | |
6363 | return 0; | |
6364 | ||
6365 | case Window : | |
ee2be2a8 | 6366 | aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]); |
f25b82d6 | 6367 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; |
6368 | return 0; | |
6369 | ||
6370 | case Grid : | |
6371 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
6372 | aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]); | |
6373 | theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
6374 | return 0; | |
6375 | ||
6376 | case Ray : | |
6377 | aView->ConvertWithProj ((Standard_Integer) aCoord (1), | |
6378 | (Standard_Integer) aCoord (2), | |
6379 | aXYZ[0], aXYZ[1], aXYZ[2], | |
6380 | aXYZ[3], aXYZ[4], aXYZ[5]); | |
6381 | theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
6382 | return 0; | |
6383 | ||
6384 | default: | |
6385 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
6386 | theDI.PrintHelp (theArgVec[0]); | |
6387 | return 1; | |
6388 | } | |
6389 | } | |
6390 | ||
6391 | // convert 3D coordinates from view reference space | |
6392 | else if (aCoord.Length() == 3) | |
6393 | { | |
6394 | switch (aMode) | |
6395 | { | |
6396 | case Window : | |
6397 | aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]); | |
6398 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; | |
6399 | return 0; | |
6400 | ||
6401 | case Grid : | |
6402 | aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]); | |
6403 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
6404 | return 0; | |
6405 | ||
6406 | default: | |
6407 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
6408 | theDI.PrintHelp (theArgVec[0]); | |
6409 | return 1; | |
6410 | } | |
6411 | } | |
6412 | ||
6413 | return 0; | |
6414 | } | |
6415 | ||
208e6839 | 6416 | //============================================================================== |
6417 | //function : VFps | |
6418 | //purpose : | |
6419 | //============================================================================== | |
6420 | ||
6421 | static int VFps (Draw_Interpretor& theDI, | |
6422 | Standard_Integer theArgNb, | |
6423 | const char** theArgVec) | |
6424 | { | |
6425 | // get the active view | |
6426 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6427 | if (aView.IsNull()) | |
6428 | { | |
6429 | std::cerr << "No active view. Please call vinit.\n"; | |
6430 | return 1; | |
6431 | } | |
6432 | ||
e084dbbc | 6433 | Standard_Integer aFramesNb = -1; |
6434 | Standard_Real aDuration = -1.0; | |
6435 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
208e6839 | 6436 | { |
e084dbbc | 6437 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
6438 | anArg.LowerCase(); | |
6439 | if (aDuration < 0.0 | |
6440 | && anArgIter + 1 < theArgNb | |
6441 | && (anArg == "-duration" | |
6442 | || anArg == "-dur" | |
6443 | || anArg == "-time")) | |
6444 | { | |
6445 | aDuration = Draw::Atof (theArgVec[++anArgIter]); | |
6446 | } | |
6447 | else if (aFramesNb < 0 | |
6448 | && anArg.IsIntegerValue()) | |
6449 | { | |
6450 | aFramesNb = anArg.IntegerValue(); | |
6451 | if (aFramesNb <= 0) | |
6452 | { | |
6453 | std::cerr << "Syntax error at '" << anArg << "'\n"; | |
6454 | return 1; | |
6455 | } | |
6456 | } | |
6457 | else | |
6458 | { | |
6459 | std::cerr << "Syntax error at '" << anArg << "'\n"; | |
6460 | return 1; | |
6461 | } | |
6462 | } | |
6463 | if (aFramesNb < 0 && aDuration < 0.0) | |
6464 | { | |
6465 | aFramesNb = 100; | |
208e6839 | 6466 | } |
6467 | ||
6468 | // the time is meaningless for first call | |
6469 | // due to async OpenGl rendering | |
6470 | aView->Redraw(); | |
6471 | ||
6472 | // redraw view in loop to estimate average values | |
6473 | OSD_Timer aTimer; | |
6474 | aTimer.Start(); | |
e084dbbc | 6475 | Standard_Integer aFrameIter = 1; |
6476 | for (;; ++aFrameIter) | |
208e6839 | 6477 | { |
6478 | aView->Redraw(); | |
e084dbbc | 6479 | if ((aFramesNb > 0 |
6480 | && aFrameIter >= aFramesNb) | |
6481 | || (aDuration > 0.0 | |
6482 | && aTimer.ElapsedTime() >= aDuration)) | |
6483 | { | |
6484 | break; | |
6485 | } | |
208e6839 | 6486 | } |
6487 | aTimer.Stop(); | |
6488 | Standard_Real aCpu; | |
6489 | const Standard_Real aTime = aTimer.ElapsedTime(); | |
6490 | aTimer.OSD_Chronometer::Show (aCpu); | |
6491 | ||
e084dbbc | 6492 | const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime; |
6493 | const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter); | |
208e6839 | 6494 | |
6495 | // return statistics | |
6496 | theDI << "FPS: " << aFpsAver << "\n" | |
6497 | << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; | |
6498 | ||
8c820969 | 6499 | // compute additional statistics in ray-tracing mode |
e084dbbc | 6500 | const Graphic3d_RenderingParams& aParams = aView->RenderingParams(); |
8c820969 | 6501 | if (aParams.Method == Graphic3d_RM_RAYTRACING) |
6502 | { | |
e084dbbc | 6503 | Graphic3d_Vec2i aWinSize (0, 0); |
6504 | aView->Window()->Size (aWinSize.x(), aWinSize.y()); | |
8c820969 | 6505 | |
6506 | // 1 shadow ray and 1 secondary ray pew each bounce | |
e084dbbc | 6507 | const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f; |
8c820969 | 6508 | theDI << "MRays/sec (upper bound): " << aMRays << "\n"; |
6509 | } | |
6510 | ||
208e6839 | 6511 | return 0; |
6512 | } | |
6513 | ||
84e84755 | 6514 | //! Auxiliary function for parsing glsl dump level argument. |
6515 | static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg, | |
6516 | OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel) | |
6517 | { | |
6518 | TCollection_AsciiString aTypeStr (theArg); | |
6519 | aTypeStr.LowerCase(); | |
6520 | if (aTypeStr == "off" | |
6521 | || aTypeStr == "0") | |
6522 | { | |
6523 | theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off; | |
6524 | } | |
6525 | else if (aTypeStr == "short") | |
6526 | { | |
6527 | theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short; | |
6528 | } | |
6529 | else if (aTypeStr == "full" | |
6530 | || aTypeStr == "1") | |
6531 | { | |
6532 | theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full; | |
6533 | } | |
6534 | else | |
6535 | { | |
6536 | return Standard_False; | |
6537 | } | |
6538 | return Standard_True; | |
6539 | } | |
6540 | ||
58655684 | 6541 | //============================================================================== |
6542 | //function : VGlDebug | |
6543 | //purpose : | |
6544 | //============================================================================== | |
6545 | ||
6546 | static int VGlDebug (Draw_Interpretor& theDI, | |
6547 | Standard_Integer theArgNb, | |
6548 | const char** theArgVec) | |
6549 | { | |
aaf512f1 | 6550 | Handle(OpenGl_GraphicDriver) aDriver; |
6551 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6552 | if (!aView.IsNull()) | |
6553 | { | |
6554 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver()); | |
6555 | } | |
c87535af | 6556 | OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps; |
6557 | OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL; | |
6558 | ||
58655684 | 6559 | if (theArgNb < 2) |
6560 | { | |
c87535af | 6561 | TCollection_AsciiString aDebActive, aSyncActive; |
6562 | if (aCaps == NULL) | |
58655684 | 6563 | { |
c87535af | 6564 | aCaps = aDefCaps; |
6565 | } | |
6566 | else | |
6567 | { | |
6568 | Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS), | |
6569 | "GL_ARB_debug_output"); | |
6570 | aDebActive = isActive ? " (active)" : " (inactive)"; | |
6571 | if (isActive) | |
6572 | { | |
6573 | // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB | |
6574 | aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)"; | |
6575 | } | |
58655684 | 6576 | } |
6577 | ||
84e84755 | 6578 | TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString() |
6579 | + "glslSourceCode: " | |
6580 | + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off | |
6581 | ? "Off" | |
6582 | : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short | |
6583 | ? "Short" | |
6584 | : "Full") | |
6585 | + "\n"; | |
6586 | theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n" | |
6587 | << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n" | |
6588 | << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n" | |
6589 | << aGlslCodeDebugStatus | |
6590 | << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n"; | |
58655684 | 6591 | return 0; |
6592 | } | |
6593 | ||
c87535af | 6594 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
aaf512f1 | 6595 | { |
c87535af | 6596 | Standard_CString anArg = theArgVec[anArgIter]; |
6597 | TCollection_AsciiString anArgCase (anArg); | |
6598 | anArgCase.LowerCase(); | |
6599 | Standard_Boolean toEnableDebug = Standard_True; | |
6600 | if (anArgCase == "-glsl" | |
6601 | || anArgCase == "-glslwarn" | |
6602 | || anArgCase == "-glslwarns" | |
6603 | || anArgCase == "-glslwarnings") | |
6604 | { | |
6605 | Standard_Boolean toShowWarns = Standard_True; | |
6606 | if (++anArgIter < theArgNb | |
a5565a3c | 6607 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns)) |
c87535af | 6608 | { |
6609 | --anArgIter; | |
6610 | } | |
6611 | aDefCaps->glslWarnings = toShowWarns; | |
6612 | if (aCaps != NULL) | |
6613 | { | |
6614 | aCaps->glslWarnings = toShowWarns; | |
6615 | } | |
6616 | } | |
6617 | else if (anArgCase == "-extra" | |
6618 | || anArgCase == "-extramsg" | |
6619 | || anArgCase == "-extramessages") | |
6620 | { | |
6621 | Standard_Boolean toShow = Standard_True; | |
6622 | if (++anArgIter < theArgNb | |
a5565a3c | 6623 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow)) |
c87535af | 6624 | { |
6625 | --anArgIter; | |
6626 | } | |
6627 | aDefCaps->suppressExtraMsg = !toShow; | |
6628 | if (aCaps != NULL) | |
6629 | { | |
6630 | aCaps->suppressExtraMsg = !toShow; | |
6631 | } | |
6632 | } | |
6633 | else if (anArgCase == "-noextra" | |
6634 | || anArgCase == "-noextramsg" | |
6635 | || anArgCase == "-noextramessages") | |
6636 | { | |
6637 | Standard_Boolean toSuppress = Standard_True; | |
6638 | if (++anArgIter < theArgNb | |
a5565a3c | 6639 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress)) |
c87535af | 6640 | { |
6641 | --anArgIter; | |
6642 | } | |
6643 | aDefCaps->suppressExtraMsg = toSuppress; | |
6644 | if (aCaps != NULL) | |
6645 | { | |
6646 | aCaps->suppressExtraMsg = toSuppress; | |
6647 | } | |
6648 | } | |
6649 | else if (anArgCase == "-sync") | |
6650 | { | |
6651 | Standard_Boolean toSync = Standard_True; | |
6652 | if (++anArgIter < theArgNb | |
a5565a3c | 6653 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync)) |
c87535af | 6654 | { |
6655 | --anArgIter; | |
6656 | } | |
6657 | aDefCaps->contextSyncDebug = toSync; | |
6658 | if (toSync) | |
6659 | { | |
6660 | aDefCaps->contextDebug = Standard_True; | |
6661 | } | |
6662 | } | |
84e84755 | 6663 | else if (anArgCase == "-glslsourcecode" |
6664 | || anArgCase == "-glslcode") | |
6665 | { | |
6666 | OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full; | |
6667 | if (++anArgIter < theArgNb | |
6668 | && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel)) | |
6669 | { | |
6670 | --anArgIter; | |
6671 | } | |
6672 | aDefCaps->glslDumpLevel = aGslsDumpLevel; | |
6673 | if (aCaps != NULL) | |
6674 | { | |
6675 | aCaps->glslDumpLevel = aGslsDumpLevel; | |
6676 | } | |
6677 | } | |
c87535af | 6678 | else if (anArgCase == "-debug") |
6679 | { | |
6680 | if (++anArgIter < theArgNb | |
a5565a3c | 6681 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug)) |
c87535af | 6682 | { |
6683 | --anArgIter; | |
6684 | } | |
6685 | aDefCaps->contextDebug = toEnableDebug; | |
6686 | } | |
a5565a3c | 6687 | else if (ViewerTest::ParseOnOff (anArg, toEnableDebug) |
c87535af | 6688 | && (anArgIter + 1 == theArgNb)) |
6689 | { | |
6690 | // simple alias to turn on almost everything | |
6691 | aDefCaps->contextDebug = toEnableDebug; | |
6692 | aDefCaps->contextSyncDebug = toEnableDebug; | |
6693 | aDefCaps->glslWarnings = toEnableDebug; | |
3b4c6945 | 6694 | if (!toEnableDebug) |
6695 | { | |
6696 | aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off; | |
6697 | } | |
84e84755 | 6698 | aDefCaps->suppressExtraMsg = !toEnableDebug; |
6699 | if (aCaps != NULL) | |
6700 | { | |
6701 | aCaps->contextDebug = toEnableDebug; | |
6702 | aCaps->contextSyncDebug = toEnableDebug; | |
6703 | aCaps->glslWarnings = toEnableDebug; | |
3b4c6945 | 6704 | if (!toEnableDebug) |
6705 | { | |
6706 | aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off; | |
6707 | } | |
84e84755 | 6708 | aCaps->suppressExtraMsg = !toEnableDebug; |
6709 | } | |
c87535af | 6710 | } |
6711 | else | |
6712 | { | |
6713 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
6714 | return 1; | |
6715 | } | |
aaf512f1 | 6716 | } |
6717 | ||
58655684 | 6718 | return 0; |
6719 | } | |
208e6839 | 6720 | |
6721 | //============================================================================== | |
6722 | //function : VVbo | |
6723 | //purpose : | |
6724 | //============================================================================== | |
6725 | ||
58655684 | 6726 | static int VVbo (Draw_Interpretor& theDI, |
208e6839 | 6727 | Standard_Integer theArgNb, |
6728 | const char** theArgVec) | |
6729 | { | |
58655684 | 6730 | const Standard_Boolean toSet = (theArgNb > 1); |
6731 | const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1; | |
6732 | if (toSet) | |
208e6839 | 6733 | { |
58655684 | 6734 | ViewerTest_myDefaultCaps.vboDisable = toUseVbo; |
208e6839 | 6735 | } |
6736 | ||
58655684 | 6737 | // get the context |
6738 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
6739 | if (aContextAIS.IsNull()) | |
208e6839 | 6740 | { |
58655684 | 6741 | if (!toSet) |
6742 | { | |
6743 | std::cerr << "No active view!\n"; | |
6744 | } | |
208e6839 | 6745 | return 1; |
6746 | } | |
58655684 | 6747 | Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); |
6748 | if (!aDriver.IsNull()) | |
208e6839 | 6749 | { |
58655684 | 6750 | if (!toSet) |
6751 | { | |
6752 | theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n"; | |
6753 | } | |
6754 | else | |
6755 | { | |
6756 | aDriver->ChangeOptions().vboDisable = toUseVbo; | |
6757 | } | |
208e6839 | 6758 | } |
6759 | ||
208e6839 | 6760 | return 0; |
6761 | } | |
6762 | ||
a577aaab | 6763 | //============================================================================== |
6764 | //function : VCaps | |
6765 | //purpose : | |
6766 | //============================================================================== | |
6767 | ||
6768 | static int VCaps (Draw_Interpretor& theDI, | |
6769 | Standard_Integer theArgNb, | |
6770 | const char** theArgVec) | |
6771 | { | |
6772 | OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps; | |
6773 | Handle(OpenGl_GraphicDriver) aDriver; | |
8625ef7e | 6774 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
6775 | if (!aContext.IsNull()) | |
a577aaab | 6776 | { |
8625ef7e | 6777 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver()); |
a577aaab | 6778 | aCaps = &aDriver->ChangeOptions(); |
6779 | } | |
6780 | ||
6781 | if (theArgNb < 2) | |
6782 | { | |
6783 | theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n"; | |
6784 | theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n"; | |
abe46077 | 6785 | theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n"; |
8625ef7e | 6786 | theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n"; |
2a332745 | 6787 | theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n"; |
f978241f | 6788 | theDI << "VSync: " << aCaps->swapInterval << "\n"; |
4e1523ef | 6789 | theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n"; |
f978241f | 6790 | theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n"; |
56689b27 | 6791 | theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n"; |
59515ca6 | 6792 | theDI << "NoExt:" << (aCaps->contextNoExtensions ? "1" : "0") << "\n"; |
6793 | theDI << "MaxVersion:" << aCaps->contextMajorVersionUpper << "." << aCaps->contextMinorVersionUpper << "\n"; | |
a577aaab | 6794 | return 0; |
6795 | } | |
6796 | ||
8625ef7e | 6797 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
a577aaab | 6798 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
6799 | { | |
8625ef7e | 6800 | Standard_CString anArg = theArgVec[anArgIter]; |
6801 | TCollection_AsciiString anArgCase (anArg); | |
6802 | anArgCase.LowerCase(); | |
6803 | if (anUpdateTool.parseRedrawMode (anArg)) | |
6804 | { | |
6805 | continue; | |
6806 | } | |
f978241f | 6807 | else if (anArgCase == "-vsync" |
6808 | || anArgCase == "-swapinterval") | |
6809 | { | |
6810 | Standard_Boolean toEnable = Standard_True; | |
6811 | if (++anArgIter < theArgNb | |
a5565a3c | 6812 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 6813 | { |
6814 | --anArgIter; | |
6815 | } | |
6816 | aCaps->swapInterval = toEnable; | |
6817 | } | |
8625ef7e | 6818 | else if (anArgCase == "-ffp") |
6819 | { | |
6820 | Standard_Boolean toEnable = Standard_True; | |
6821 | if (++anArgIter < theArgNb | |
a5565a3c | 6822 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6823 | { |
6824 | --anArgIter; | |
6825 | } | |
6826 | aCaps->ffpEnable = toEnable; | |
6827 | } | |
2a332745 | 6828 | else if (anArgCase == "-polygonmode") |
6829 | { | |
6830 | Standard_Boolean toEnable = Standard_True; | |
6831 | if (++anArgIter < theArgNb | |
6832 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
6833 | { | |
6834 | --anArgIter; | |
6835 | } | |
6836 | aCaps->usePolygonMode = toEnable; | |
6837 | } | |
8625ef7e | 6838 | else if (anArgCase == "-vbo") |
a577aaab | 6839 | { |
8625ef7e | 6840 | Standard_Boolean toEnable = Standard_True; |
6841 | if (++anArgIter < theArgNb | |
a5565a3c | 6842 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6843 | { |
6844 | --anArgIter; | |
6845 | } | |
6846 | aCaps->vboDisable = !toEnable; | |
a577aaab | 6847 | } |
8625ef7e | 6848 | else if (anArgCase == "-sprite" |
6849 | || anArgCase == "-sprites") | |
a577aaab | 6850 | { |
8625ef7e | 6851 | Standard_Boolean toEnable = Standard_True; |
6852 | if (++anArgIter < theArgNb | |
a5565a3c | 6853 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6854 | { |
6855 | --anArgIter; | |
6856 | } | |
6857 | aCaps->pntSpritesDisable = !toEnable; | |
a577aaab | 6858 | } |
8625ef7e | 6859 | else if (anArgCase == "-softmode") |
abe46077 | 6860 | { |
8625ef7e | 6861 | Standard_Boolean toEnable = Standard_True; |
6862 | if (++anArgIter < theArgNb | |
a5565a3c | 6863 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6864 | { |
6865 | --anArgIter; | |
6866 | } | |
6867 | aCaps->contextNoAccel = toEnable; | |
6868 | } | |
56689b27 | 6869 | else if (anArgCase == "-winbuffer" |
6870 | || anArgCase == "-windowbuffer" | |
6871 | || anArgCase == "-usewinbuffer" | |
6872 | || anArgCase == "-usewindowbuffer" | |
6873 | || anArgCase == "-usesystembuffer") | |
6874 | { | |
6875 | Standard_Boolean toEnable = Standard_True; | |
6876 | if (++anArgIter < theArgNb | |
6877 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
6878 | { | |
6879 | --anArgIter; | |
6880 | } | |
6881 | aCaps->useSystemBuffer = toEnable; | |
6882 | } | |
8625ef7e | 6883 | else if (anArgCase == "-accel" |
6884 | || anArgCase == "-acceleration") | |
6885 | { | |
6886 | Standard_Boolean toEnable = Standard_True; | |
6887 | if (++anArgIter < theArgNb | |
a5565a3c | 6888 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6889 | { |
6890 | --anArgIter; | |
6891 | } | |
6892 | aCaps->contextNoAccel = !toEnable; | |
abe46077 | 6893 | } |
4e1523ef | 6894 | else if (anArgCase == "-compat" |
6895 | || anArgCase == "-compatprofile" | |
6896 | || anArgCase == "-compatible" | |
6897 | || anArgCase == "-compatibleprofile") | |
6898 | { | |
6899 | Standard_Boolean toEnable = Standard_True; | |
6900 | if (++anArgIter < theArgNb | |
a5565a3c | 6901 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
4e1523ef | 6902 | { |
6903 | --anArgIter; | |
6904 | } | |
6905 | aCaps->contextCompatible = toEnable; | |
6906 | if (!aCaps->contextCompatible) | |
6907 | { | |
6908 | aCaps->ffpEnable = Standard_False; | |
6909 | } | |
6910 | } | |
6911 | else if (anArgCase == "-core" | |
6912 | || anArgCase == "-coreprofile") | |
6913 | { | |
6914 | Standard_Boolean toEnable = Standard_True; | |
6915 | if (++anArgIter < theArgNb | |
a5565a3c | 6916 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
4e1523ef | 6917 | { |
6918 | --anArgIter; | |
6919 | } | |
6920 | aCaps->contextCompatible = !toEnable; | |
6921 | if (!aCaps->contextCompatible) | |
6922 | { | |
6923 | aCaps->ffpEnable = Standard_False; | |
6924 | } | |
6925 | } | |
f978241f | 6926 | else if (anArgCase == "-stereo" |
6927 | || anArgCase == "-quadbuffer") | |
6928 | { | |
6929 | Standard_Boolean toEnable = Standard_True; | |
6930 | if (++anArgIter < theArgNb | |
a5565a3c | 6931 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 6932 | { |
6933 | --anArgIter; | |
6934 | } | |
6935 | aCaps->contextStereo = toEnable; | |
6936 | } | |
59515ca6 | 6937 | else if (anArgCase == "-noext" |
6938 | || anArgCase == "-noextensions" | |
6939 | || anArgCase == "-noextension") | |
6940 | { | |
6941 | Standard_Boolean toDisable = Standard_True; | |
6942 | if (++anArgIter < theArgNb | |
6943 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable)) | |
6944 | { | |
6945 | --anArgIter; | |
6946 | } | |
6947 | aCaps->contextNoExtensions = toDisable; | |
6948 | } | |
6949 | else if (anArgCase == "-maxversion" | |
6950 | || anArgCase == "-upperversion" | |
6951 | || anArgCase == "-limitversion") | |
6952 | { | |
6953 | Standard_Integer aVer[2] = { -2, -1 }; | |
6954 | for (Standard_Integer aValIter = 0; aValIter < 2; ++aValIter) | |
6955 | { | |
6956 | if (anArgIter + 1 < theArgNb) | |
6957 | { | |
6958 | const TCollection_AsciiString aStr (theArgVec[anArgIter + 1]); | |
6959 | if (aStr.IsIntegerValue()) | |
6960 | { | |
6961 | aVer[aValIter] = aStr.IntegerValue(); | |
6962 | ++anArgIter; | |
6963 | } | |
6964 | } | |
6965 | } | |
6966 | if (aVer[0] < -1 | |
6967 | || aVer[1] < -1) | |
6968 | { | |
6969 | std::cout << "Syntax error at '" << anArgCase << "'\n"; | |
6970 | return 1; | |
6971 | } | |
6972 | aCaps->contextMajorVersionUpper = aVer[0]; | |
6973 | aCaps->contextMinorVersionUpper = aVer[1]; | |
6974 | } | |
a577aaab | 6975 | else |
6976 | { | |
8625ef7e | 6977 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
6978 | return 1; | |
a577aaab | 6979 | } |
6980 | } | |
6981 | if (aCaps != &ViewerTest_myDefaultCaps) | |
6982 | { | |
6983 | ViewerTest_myDefaultCaps = *aCaps; | |
6984 | } | |
6985 | return 0; | |
6986 | } | |
6987 | ||
f0430952 | 6988 | //============================================================================== |
6989 | //function : VMemGpu | |
6990 | //purpose : | |
6991 | //============================================================================== | |
6992 | ||
6993 | static int VMemGpu (Draw_Interpretor& theDI, | |
6994 | Standard_Integer theArgNb, | |
6995 | const char** theArgVec) | |
6996 | { | |
6997 | // get the context | |
6998 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
6999 | if (aContextAIS.IsNull()) | |
7000 | { | |
7001 | std::cerr << "No active view. Please call vinit.\n"; | |
7002 | return 1; | |
7003 | } | |
7004 | ||
dc3fe572 | 7005 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
f0430952 | 7006 | if (aDriver.IsNull()) |
7007 | { | |
7008 | std::cerr << "Graphic driver not available.\n"; | |
7009 | return 1; | |
7010 | } | |
7011 | ||
7012 | Standard_Size aFreeBytes = 0; | |
7013 | TCollection_AsciiString anInfo; | |
7014 | if (!aDriver->MemoryInfo (aFreeBytes, anInfo)) | |
7015 | { | |
7016 | std::cerr << "Information not available.\n"; | |
7017 | return 1; | |
7018 | } | |
7019 | ||
7020 | if (theArgNb > 1 && *theArgVec[1] == 'f') | |
7021 | { | |
7022 | theDI << Standard_Real (aFreeBytes); | |
7023 | } | |
7024 | else | |
7025 | { | |
7026 | theDI << anInfo; | |
7027 | } | |
7028 | ||
7029 | return 0; | |
7030 | } | |
7031 | ||
85e096c3 | 7032 | // ============================================================================== |
7033 | // function : VReadPixel | |
7034 | // purpose : | |
7035 | // ============================================================================== | |
7036 | static int VReadPixel (Draw_Interpretor& theDI, | |
7037 | Standard_Integer theArgNb, | |
7038 | const char** theArgVec) | |
7039 | { | |
7040 | // get the active view | |
7041 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7042 | if (aView.IsNull()) | |
7043 | { | |
7044 | std::cerr << "No active view. Please call vinit.\n"; | |
7045 | return 1; | |
7046 | } | |
7047 | else if (theArgNb < 3) | |
7048 | { | |
7049 | std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n"; | |
7050 | return 1; | |
7051 | } | |
7052 | ||
dc858f4c | 7053 | Image_Format aFormat = Image_Format_RGBA; |
7054 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA; | |
692613e5 | 7055 | |
85e096c3 | 7056 | Standard_Integer aWidth, aHeight; |
7057 | aView->Window()->Size (aWidth, aHeight); | |
91322f44 | 7058 | const Standard_Integer anX = Draw::Atoi (theArgVec[1]); |
7059 | const Standard_Integer anY = Draw::Atoi (theArgVec[2]); | |
85e096c3 | 7060 | if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight) |
7061 | { | |
7062 | std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n"; | |
7063 | return 1; | |
7064 | } | |
7065 | ||
7066 | Standard_Boolean toShowName = Standard_False; | |
7067 | Standard_Boolean toShowHls = Standard_False; | |
7068 | for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) | |
7069 | { | |
dc858f4c | 7070 | TCollection_AsciiString aParam (theArgVec[anIter]); |
7071 | aParam.LowerCase(); | |
55c8f0f7 BB |
7072 | if (aParam == "-rgb" |
7073 | || aParam == "rgb") | |
85e096c3 | 7074 | { |
dc858f4c | 7075 | aFormat = Image_Format_RGB; |
692613e5 | 7076 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 7077 | } |
55c8f0f7 BB |
7078 | else if (aParam == "-hls" |
7079 | || aParam == "hls") | |
85e096c3 | 7080 | { |
dc858f4c | 7081 | aFormat = Image_Format_RGB; |
692613e5 | 7082 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 7083 | toShowHls = Standard_True; |
7084 | } | |
55c8f0f7 BB |
7085 | else if (aParam == "-rgbf" |
7086 | || aParam == "rgbf") | |
85e096c3 | 7087 | { |
dc858f4c | 7088 | aFormat = Image_Format_RGBF; |
692613e5 | 7089 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 7090 | } |
55c8f0f7 BB |
7091 | else if (aParam == "-rgba" |
7092 | || aParam == "rgba") | |
85e096c3 | 7093 | { |
dc858f4c | 7094 | aFormat = Image_Format_RGBA; |
692613e5 | 7095 | aBufferType = Graphic3d_BT_RGBA; |
85e096c3 | 7096 | } |
55c8f0f7 BB |
7097 | else if (aParam == "-rgbaf" |
7098 | || aParam == "rgbaf") | |
85e096c3 | 7099 | { |
dc858f4c | 7100 | aFormat = Image_Format_RGBAF; |
692613e5 | 7101 | aBufferType = Graphic3d_BT_RGBA; |
85e096c3 | 7102 | } |
55c8f0f7 BB |
7103 | else if (aParam == "-depth" |
7104 | || aParam == "depth") | |
85e096c3 | 7105 | { |
dc858f4c | 7106 | aFormat = Image_Format_GrayF; |
692613e5 | 7107 | aBufferType = Graphic3d_BT_Depth; |
85e096c3 | 7108 | } |
55c8f0f7 BB |
7109 | else if (aParam == "-name" |
7110 | || aParam == "name") | |
85e096c3 | 7111 | { |
7112 | toShowName = Standard_True; | |
7113 | } | |
55c8f0f7 BB |
7114 | else |
7115 | { | |
7116 | std::cout << "Syntax error at '" << aParam << "'\n"; | |
7117 | } | |
85e096c3 | 7118 | } |
7119 | ||
692613e5 | 7120 | Image_PixMap anImage; |
7121 | if (!anImage.InitTrash (aFormat, aWidth, aHeight)) | |
7122 | { | |
7123 | std::cerr << "Image allocation failed\n"; | |
7124 | return 1; | |
7125 | } | |
7126 | else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType)) | |
85e096c3 | 7127 | { |
7128 | std::cerr << "Image dump failed\n"; | |
7129 | return 1; | |
7130 | } | |
7131 | ||
68beaa3c | 7132 | // redirect possible warning messages that could have been added by ToPixMap |
7133 | // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not | |
7134 | // contaminate result of the command | |
7135 | Standard_CString aWarnLog = theDI.Result(); | |
7136 | if (aWarnLog != NULL && aWarnLog[0] != '\0') | |
7137 | { | |
7138 | std::cout << aWarnLog << std::endl; | |
7139 | } | |
7140 | theDI.Reset(); | |
7141 | ||
e958a649 | 7142 | Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY); |
85e096c3 | 7143 | if (toShowName) |
7144 | { | |
692613e5 | 7145 | if (aBufferType == Graphic3d_BT_RGBA) |
85e096c3 | 7146 | { |
e958a649 | 7147 | theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha(); |
85e096c3 | 7148 | } |
7149 | else | |
7150 | { | |
e958a649 | 7151 | theDI << Quantity_Color::StringName (aColor.GetRGB().Name()); |
85e096c3 | 7152 | } |
7153 | } | |
7154 | else | |
7155 | { | |
7156 | switch (aBufferType) | |
7157 | { | |
7158 | default: | |
692613e5 | 7159 | case Graphic3d_BT_RGB: |
85e096c3 | 7160 | { |
7161 | if (toShowHls) | |
7162 | { | |
e958a649 | 7163 | theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation(); |
85e096c3 | 7164 | } |
7165 | else | |
7166 | { | |
e958a649 | 7167 | theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue(); |
85e096c3 | 7168 | } |
7169 | break; | |
7170 | } | |
692613e5 | 7171 | case Graphic3d_BT_RGBA: |
85e096c3 | 7172 | { |
e958a649 | 7173 | theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha(); |
85e096c3 | 7174 | break; |
7175 | } | |
692613e5 | 7176 | case Graphic3d_BT_Depth: |
85e096c3 | 7177 | { |
e958a649 | 7178 | theDI << aColor.GetRGB().Red(); |
85e096c3 | 7179 | break; |
7180 | } | |
7181 | } | |
7182 | } | |
7183 | ||
7184 | return 0; | |
7185 | } | |
7186 | ||
fd3f6bd0 | 7187 | //! Auxiliary presentation for an image plane. |
7188 | class ViewerTest_ImagePrs : public AIS_InteractiveObject | |
7189 | { | |
7190 | public: | |
7191 | //! Main constructor. | |
7192 | ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage, | |
7193 | const Standard_Real theWidth, | |
7194 | const Standard_Real theHeight, | |
7195 | const TCollection_AsciiString& theLabel) | |
7196 | : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight) | |
7197 | { | |
7198 | SetDisplayMode (0); | |
7199 | SetHilightMode (1); | |
7200 | myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost); | |
7201 | { | |
7202 | myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); | |
7203 | const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect(); | |
7204 | Graphic3d_MaterialAspect aMat; | |
7205 | aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC); | |
61168418 | 7206 | aMat.SetAmbientColor (Quantity_NOC_BLACK); |
7207 | aMat.SetDiffuseColor (Quantity_NOC_WHITE); | |
7208 | aMat.SetSpecularColor (Quantity_NOC_BLACK); | |
7209 | aMat.SetEmissiveColor (Quantity_NOC_BLACK); | |
fd3f6bd0 | 7210 | aFillAspect->SetFrontMaterial (aMat); |
7211 | aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage)); | |
7212 | aFillAspect->SetTextureMapOn(); | |
7213 | } | |
7214 | { | |
7215 | Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect(); | |
7216 | aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER); | |
7217 | aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER); | |
7218 | myDrawer->SetTextAspect (aTextAspect); | |
7219 | } | |
7220 | { | |
7221 | const gp_Dir aNorm (0.0, 0.0, 1.0); | |
7222 | myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true); | |
7223 | myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0)); | |
7224 | myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0)); | |
7225 | myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0)); | |
7226 | myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0)); | |
7227 | myTris->AddEdge (1); | |
7228 | myTris->AddEdge (2); | |
7229 | myTris->AddEdge (3); | |
7230 | myTris->AddEdge (3); | |
7231 | myTris->AddEdge (2); | |
7232 | myTris->AddEdge (4); | |
7233 | ||
7234 | myRect = new Graphic3d_ArrayOfPolylines (4); | |
7235 | myRect->AddVertex (myTris->Vertice (1)); | |
7236 | myRect->AddVertex (myTris->Vertice (3)); | |
7237 | myRect->AddVertex (myTris->Vertice (4)); | |
7238 | myRect->AddVertex (myTris->Vertice (2)); | |
7239 | } | |
7240 | } | |
7241 | ||
7242 | //! Returns TRUE for accepted display modes. | |
7243 | virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; } | |
7244 | ||
7245 | //! Compute presentation. | |
7246 | virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE | |
7247 | { | |
7248 | switch (theMode) | |
7249 | { | |
7250 | case 0: | |
7251 | { | |
7252 | Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); | |
7253 | aGroup->AddPrimitiveArray (myTris); | |
7254 | aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect()); | |
7255 | aGroup->AddPrimitiveArray (myRect); | |
7256 | aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect()); | |
7257 | return; | |
7258 | } | |
7259 | case 1: | |
7260 | { | |
7261 | Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0)); | |
7262 | Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); | |
7263 | aGroup->AddPrimitiveArray (myRect); | |
7264 | aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect()); | |
7265 | return; | |
7266 | } | |
7267 | } | |
7268 | } | |
7269 | ||
7270 | //! Compute selection. | |
7271 | virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE | |
7272 | { | |
7273 | if (theMode == 0) | |
7274 | { | |
7275 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5); | |
7276 | Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner); | |
7277 | aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location()); | |
7278 | theSel->Add (aSensitive); | |
7279 | } | |
7280 | } | |
7281 | ||
7282 | private: | |
7283 | Handle(Graphic3d_ArrayOfTriangles) myTris; | |
7284 | Handle(Graphic3d_ArrayOfPolylines) myRect; | |
7285 | TCollection_AsciiString myLabel; | |
7286 | Standard_Real myWidth; | |
7287 | Standard_Real myHeight; | |
7288 | }; | |
7289 | ||
692613e5 | 7290 | //============================================================================== |
7291 | //function : VDiffImage | |
7292 | //purpose : The draw-command compares two images. | |
7293 | //============================================================================== | |
7294 | ||
7295 | static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
7296 | { | |
fd3f6bd0 | 7297 | if (theArgNb < 3) |
692613e5 | 7298 | { |
fd3f6bd0 | 7299 | std::cout << "Syntax error: not enough arguments.\n"; |
692613e5 | 7300 | return 1; |
7301 | } | |
7302 | ||
fd3f6bd0 | 7303 | Standard_Integer anArgIter = 1; |
7304 | TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]); | |
7305 | TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]); | |
7306 | TCollection_AsciiString aDiffImagePath; | |
7307 | Standard_Real aTolColor = -1.0; | |
7308 | Standard_Integer toBlackWhite = -1; | |
7309 | Standard_Integer isBorderFilterOn = -1; | |
7310 | Standard_Boolean isOldSyntax = Standard_False; | |
7311 | TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff; | |
7312 | for (; anArgIter < theArgNb; ++anArgIter) | |
7313 | { | |
7314 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
7315 | anArg.LowerCase(); | |
7316 | if (anArgIter + 1 < theArgNb | |
7317 | && (anArg == "-toleranceofcolor" | |
7318 | || anArg == "-tolerancecolor" | |
7319 | || anArg == "-tolerance" | |
7320 | || anArg == "-toler")) | |
7321 | { | |
7322 | aTolColor = Atof (theArgVec[++anArgIter]); | |
7323 | if (aTolColor < 0.0 || aTolColor > 1.0) | |
7324 | { | |
7325 | std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n"; | |
7326 | return 1; | |
7327 | } | |
7328 | } | |
7329 | else if (anArg == "-blackwhite") | |
7330 | { | |
7331 | Standard_Boolean toEnable = Standard_True; | |
7332 | if (anArgIter + 1 < theArgNb | |
7333 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
7334 | { | |
7335 | ++anArgIter; | |
7336 | } | |
7337 | toBlackWhite = toEnable ? 1 : 0; | |
7338 | } | |
7339 | else if (anArg == "-borderfilter") | |
7340 | { | |
7341 | Standard_Boolean toEnable = Standard_True; | |
7342 | if (anArgIter + 1 < theArgNb | |
7343 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
7344 | { | |
7345 | ++anArgIter; | |
7346 | } | |
7347 | isBorderFilterOn = toEnable ? 1 : 0; | |
7348 | } | |
7349 | else if (anArg == "-exitonclose") | |
7350 | { | |
49582f9d | 7351 | ViewerTest_EventManager::ToExitOnCloseView() = true; |
fd3f6bd0 | 7352 | if (anArgIter + 1 < theArgNb |
49582f9d | 7353 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToExitOnCloseView())) |
fd3f6bd0 | 7354 | { |
7355 | ++anArgIter; | |
7356 | } | |
7357 | } | |
7358 | else if (anArg == "-closeonescape" | |
7359 | || anArg == "-closeonesc") | |
7360 | { | |
49582f9d | 7361 | ViewerTest_EventManager::ToCloseViewOnEscape() = true; |
fd3f6bd0 | 7362 | if (anArgIter + 1 < theArgNb |
49582f9d | 7363 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToCloseViewOnEscape())) |
fd3f6bd0 | 7364 | { |
7365 | ++anArgIter; | |
7366 | } | |
7367 | } | |
7368 | else if (anArgIter + 3 < theArgNb | |
7369 | && anArg == "-display") | |
7370 | { | |
7371 | aViewName = theArgVec[++anArgIter]; | |
7372 | aPrsNameRef = theArgVec[++anArgIter]; | |
7373 | aPrsNameNew = theArgVec[++anArgIter]; | |
7374 | if (anArgIter + 1 < theArgNb | |
7375 | && *theArgVec[anArgIter + 1] != '-') | |
7376 | { | |
7377 | aPrsNameDiff = theArgVec[++anArgIter]; | |
7378 | } | |
7379 | } | |
7380 | else if (aTolColor < 0.0 | |
7381 | && anArg.IsRealValue()) | |
7382 | { | |
7383 | isOldSyntax = Standard_True; | |
7384 | aTolColor = anArg.RealValue(); | |
7385 | if (aTolColor < 0.0 || aTolColor > 1.0) | |
7386 | { | |
7387 | std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n"; | |
7388 | return 1; | |
7389 | } | |
7390 | } | |
7391 | else if (isOldSyntax | |
7392 | && toBlackWhite == -1 | |
7393 | && (anArg == "0" || anArg == "1")) | |
7394 | { | |
7395 | toBlackWhite = anArg == "1" ? 1 : 0; | |
7396 | } | |
7397 | else if (isOldSyntax | |
7398 | && isBorderFilterOn == -1 | |
7399 | && (anArg == "0" || anArg == "1")) | |
7400 | { | |
7401 | isBorderFilterOn = anArg == "1" ? 1 : 0; | |
7402 | } | |
7403 | else if (aDiffImagePath.IsEmpty()) | |
7404 | { | |
7405 | aDiffImagePath = theArgVec[anArgIter]; | |
7406 | } | |
7407 | else | |
7408 | { | |
7409 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
7410 | return 1; | |
7411 | } | |
7412 | } | |
692613e5 | 7413 | |
fd3f6bd0 | 7414 | Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap(); |
7415 | Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap(); | |
7416 | if (!anImgRef->Load (anImgPathRef)) | |
7417 | { | |
7418 | std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n"; | |
7419 | return 1; | |
7420 | } | |
7421 | if (!anImgNew->Load (anImgPathNew)) | |
7422 | { | |
7423 | std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n"; | |
7424 | return 1; | |
7425 | } | |
692613e5 | 7426 | |
7427 | // compare the images | |
7428 | Image_Diff aComparer; | |
fd3f6bd0 | 7429 | Standard_Integer aDiffColorsNb = -1; |
7430 | if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1)) | |
692613e5 | 7431 | { |
fd3f6bd0 | 7432 | aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0); |
7433 | aComparer.SetBorderFilterOn (isBorderFilterOn == 1); | |
7434 | aDiffColorsNb = aComparer.Compare(); | |
7435 | theDI << aDiffColorsNb << "\n"; | |
692613e5 | 7436 | } |
7437 | ||
692613e5 | 7438 | // save image of difference |
fd3f6bd0 | 7439 | Handle(Image_AlienPixMap) aDiff; |
7440 | if (aDiffColorsNb > 0 | |
7441 | && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty())) | |
7442 | { | |
7443 | aDiff = new Image_AlienPixMap(); | |
7444 | if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY())) | |
7445 | { | |
7446 | std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n"; | |
7447 | return 1; | |
7448 | } | |
7449 | aComparer.SaveDiffImage (*aDiff); | |
7450 | if (!aDiffImagePath.IsEmpty() | |
7451 | && !aDiff->Save (aDiffImagePath)) | |
7452 | { | |
7453 | std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n"; | |
7454 | return 1; | |
7455 | } | |
7456 | } | |
7457 | ||
7458 | if (aViewName.IsEmpty()) | |
7459 | { | |
7460 | return 0; | |
7461 | } | |
7462 | ||
7463 | ViewerTest_Names aViewNames (aViewName); | |
7464 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) | |
7465 | { | |
7466 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName(); | |
7467 | theDI.Eval (aCommand.ToCString()); | |
7468 | } | |
7469 | ||
7470 | Standard_Integer aPxLeft = 0; | |
7471 | Standard_Integer aPxTop = 0; | |
7472 | Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2); | |
7473 | Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty() | |
7474 | ? int(anImgRef->SizeY() * 2) | |
7475 | : int(anImgRef->SizeY()); | |
7476 | TCollection_AsciiString aDisplayName; | |
9e04ccdc | 7477 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY, |
7478 | aViewName, aDisplayName); | |
fd3f6bd0 | 7479 | |
7480 | Standard_Real aRatio = anImgRef->Ratio(); | |
7481 | Standard_Real aSizeX = 1.0; | |
7482 | Standard_Real aSizeY = aSizeX / aRatio; | |
692613e5 | 7483 | { |
fd3f6bd0 | 7484 | OSD_Path aPath (anImgPathRef); |
7485 | TCollection_AsciiString aLabelRef; | |
7486 | if (!aPath.Name().IsEmpty()) | |
7487 | { | |
7488 | aLabelRef = aPath.Name() + aPath.Extension(); | |
7489 | } | |
7490 | aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY()); | |
7491 | ||
7492 | Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef); | |
7493 | gp_Trsf aTrsfRef; | |
7494 | aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0)); | |
7495 | anImgRefPrs->SetLocalTransformation (aTrsfRef); | |
7496 | ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true); | |
692613e5 | 7497 | } |
fd3f6bd0 | 7498 | { |
7499 | OSD_Path aPath (anImgPathNew); | |
7500 | TCollection_AsciiString aLabelNew; | |
7501 | if (!aPath.Name().IsEmpty()) | |
7502 | { | |
7503 | aLabelNew = aPath.Name() + aPath.Extension(); | |
7504 | } | |
7505 | aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY()); | |
692613e5 | 7506 | |
fd3f6bd0 | 7507 | Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew); |
7508 | gp_Trsf aTrsfRef; | |
7509 | aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0)); | |
7510 | anImgNewPrs->SetLocalTransformation (aTrsfRef); | |
7511 | ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true); | |
7512 | } | |
7513 | Handle(ViewerTest_ImagePrs) anImgDiffPrs; | |
7514 | if (!aDiff.IsNull()) | |
7515 | { | |
7516 | anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels"); | |
7517 | gp_Trsf aTrsfDiff; | |
7518 | aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0)); | |
7519 | anImgDiffPrs->SetLocalTransformation (aTrsfDiff); | |
7520 | } | |
7521 | if (!aPrsNameDiff.IsEmpty()) | |
7522 | { | |
7523 | ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true); | |
7524 | } | |
7525 | ViewerTest::CurrentView()->SetProj (V3d_Zpos); | |
7526 | ViewerTest::CurrentView()->FitAll(); | |
692613e5 | 7527 | return 0; |
7528 | } | |
7529 | ||
4754e164 | 7530 | //======================================================================= |
7531 | //function : VSelect | |
7532 | //purpose : Emulates different types of selection by mouse: | |
7533 | // 1) single click selection | |
7534 | // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) | |
7535 | // 3) selection with polygon having corners at | |
dc3fe572 | 7536 | // pixel positions (x1,y1),...,(xn,yn) |
4754e164 | 7537 | // 4) any of these selections with shift button pressed |
7538 | //======================================================================= | |
49582f9d | 7539 | static Standard_Integer VSelect (Draw_Interpretor& , |
7540 | Standard_Integer theNbArgs, | |
7541 | const char** theArgVec) | |
4754e164 | 7542 | { |
49582f9d | 7543 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
7544 | if (aCtx.IsNull()) | |
4754e164 | 7545 | { |
49582f9d | 7546 | std::cout << "Error: no active View\n"; |
4754e164 | 7547 | return 1; |
7548 | } | |
2157d6ac | 7549 | |
49582f9d | 7550 | NCollection_Sequence<Graphic3d_Vec2i> aPnts; |
7551 | bool isShiftSelection = false, toAllowOverlap = false; | |
7552 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
2157d6ac | 7553 | { |
49582f9d | 7554 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
7555 | anArg.LowerCase(); | |
7556 | if (anArg == "-allowoverlap") | |
7557 | { | |
7558 | toAllowOverlap = true; | |
7559 | if (anArgIter + 1 < theNbArgs | |
7560 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toAllowOverlap)) | |
7561 | { | |
7562 | ++anArgIter; | |
7563 | } | |
7564 | } | |
7565 | else if (anArgIter + 1 < theNbArgs | |
7566 | && anArg.IsIntegerValue() | |
7567 | && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue()) | |
2157d6ac | 7568 | { |
49582f9d | 7569 | const TCollection_AsciiString anArgNext (theArgVec[++anArgIter]); |
7570 | aPnts.Append (Graphic3d_Vec2i (anArg.IntegerValue(), anArgNext.IntegerValue())); | |
7571 | } | |
7572 | else if (anArgIter + 1 == theNbArgs | |
7573 | && anArg.IsIntegerValue()) | |
7574 | { | |
7575 | isShiftSelection = anArg.IntegerValue() == 1; | |
7576 | } | |
7577 | else | |
7578 | { | |
7579 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
2157d6ac | 7580 | return 1; |
7581 | } | |
49582f9d | 7582 | } |
7583 | if (toAllowOverlap | |
7584 | && aPnts.Length() != 2) | |
7585 | { | |
7586 | std::cout << "Syntax error: -allowoverlap key is applied only for rectangle selection\n"; | |
7587 | return 1; | |
7588 | } | |
7589 | if (toAllowOverlap) | |
7590 | { | |
7591 | aCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap); | |
2157d6ac | 7592 | } |
7593 | ||
4754e164 | 7594 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); |
49582f9d | 7595 | if (aPnts.IsEmpty()) |
4754e164 | 7596 | { |
49582f9d | 7597 | if (isShiftSelection) |
7598 | { | |
7599 | aCtx->ShiftSelect (false); | |
7600 | } | |
4754e164 | 7601 | else |
49582f9d | 7602 | { |
7603 | aCtx->Select (false); | |
7604 | } | |
7605 | aCtx->CurrentViewer()->Invalidate(); | |
4754e164 | 7606 | } |
49582f9d | 7607 | else if (aPnts.Length() == 2) |
4754e164 | 7608 | { |
49582f9d | 7609 | if (toAllowOverlap |
7610 | && aPnts.First().y() < aPnts.Last().y()) | |
7611 | { | |
7612 | std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast()); | |
7613 | } | |
7614 | else if (!toAllowOverlap | |
7615 | && aPnts.First().y() > aPnts.Last().y()) | |
7616 | { | |
7617 | std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast()); | |
7618 | } | |
7619 | aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection); | |
4754e164 | 7620 | } |
7621 | else | |
7622 | { | |
49582f9d | 7623 | aCurrentEventManager->SelectInViewer (aPnts, isShiftSelection); |
4754e164 | 7624 | } |
49582f9d | 7625 | aCurrentEventManager->FlushViewEvents (aCtx, ViewerTest::CurrentView(), true); |
4754e164 | 7626 | return 0; |
7627 | } | |
7628 | ||
7629 | //======================================================================= | |
7630 | //function : VMoveTo | |
dc3fe572 | 7631 | //purpose : Emulates cursor movement to defined pixel position |
4754e164 | 7632 | //======================================================================= |
1e756cb9 | 7633 | static Standard_Integer VMoveTo (Draw_Interpretor& theDI, |
8a590580 | 7634 | Standard_Integer theNbArgs, |
7635 | const char** theArgVec) | |
4754e164 | 7636 | { |
8a590580 | 7637 | const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext(); |
7638 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
7639 | if (aContext.IsNull()) | |
4754e164 | 7640 | { |
8a590580 | 7641 | std::cout << "Error: no active View\n"; |
4754e164 | 7642 | return 1; |
7643 | } | |
7644 | ||
8a590580 | 7645 | Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast()); |
7646 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
4754e164 | 7647 | { |
8a590580 | 7648 | TCollection_AsciiString anArgStr (theArgVec[anArgIter]); |
7649 | anArgStr.LowerCase(); | |
7650 | if (anArgStr == "-reset" | |
7651 | || anArgStr == "-clear") | |
7652 | { | |
7653 | if (anArgIter + 1 < theNbArgs) | |
7654 | { | |
7655 | std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n"; | |
7656 | return 1; | |
7657 | } | |
7658 | ||
7659 | const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive() | |
7660 | && aContext->CurrentViewer()->GridEcho(); | |
7661 | if (toEchoGrid) | |
7662 | { | |
7663 | aContext->CurrentViewer()->HideGridEcho (aView); | |
7664 | } | |
7665 | if (aContext->ClearDetected() || toEchoGrid) | |
7666 | { | |
7667 | aContext->CurrentViewer()->RedrawImmediate(); | |
7668 | } | |
7669 | return 0; | |
7670 | } | |
7671 | else if (aMousePos.x() == IntegerLast() | |
7672 | && anArgStr.IsIntegerValue()) | |
7673 | { | |
7674 | aMousePos.x() = anArgStr.IntegerValue(); | |
7675 | } | |
7676 | else if (aMousePos.y() == IntegerLast() | |
7677 | && anArgStr.IsIntegerValue()) | |
7678 | { | |
7679 | aMousePos.y() = anArgStr.IntegerValue(); | |
7680 | } | |
7681 | else | |
7682 | { | |
7683 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
7684 | return 1; | |
7685 | } | |
7686 | } | |
7687 | ||
7688 | if (aMousePos.x() == IntegerLast() | |
7689 | || aMousePos.y() == IntegerLast()) | |
7690 | { | |
7691 | std::cout << "Syntax error: wrong number of arguments\n"; | |
4754e164 | 7692 | return 1; |
7693 | } | |
8a590580 | 7694 | |
49582f9d | 7695 | ViewerTest::CurrentEventManager()->ResetPreviousMoveTo(); |
7696 | ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false); | |
7697 | ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true); | |
7698 | ||
1e756cb9 | 7699 | gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast()); |
7700 | const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner(); | |
7701 | for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter) | |
7702 | { | |
7703 | if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner) | |
7704 | { | |
7705 | aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter); | |
7706 | break; | |
7707 | } | |
7708 | } | |
7709 | theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z(); | |
4754e164 | 7710 | return 0; |
7711 | } | |
7712 | ||
1beb58d7 | 7713 | namespace |
7714 | { | |
7715 | //! Global map storing all animations registered in ViewerTest. | |
7716 | static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap; | |
7717 | ||
7718 | //! The animation calling the Draw Harness command. | |
7719 | class ViewerTest_AnimationProc : public AIS_Animation | |
7720 | { | |
7721 | public: | |
7722 | ||
7723 | //! Main constructor. | |
7724 | ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName, | |
7725 | Draw_Interpretor* theDI, | |
7726 | const TCollection_AsciiString& theCommand) | |
7727 | : AIS_Animation (theAnimationName), | |
7728 | myDrawInter(theDI), | |
7729 | myCommand (theCommand) | |
7730 | { | |
7731 | // | |
7732 | } | |
7733 | ||
7734 | protected: | |
7735 | ||
7736 | //! Evaluate the command. | |
7737 | virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE | |
7738 | { | |
7739 | TCollection_AsciiString aCmd = myCommand; | |
7740 | replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts)); | |
7741 | replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts)); | |
7742 | replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts)); | |
7743 | replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized)); | |
7744 | replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized)); | |
7745 | myDrawInter->Eval (aCmd.ToCString()); | |
7746 | } | |
7747 | ||
7748 | //! Find the keyword in the command and replace it with value. | |
7749 | //! @return the position of the keyword to pass value | |
7750 | void replace (TCollection_AsciiString& theCmd, | |
7751 | const TCollection_AsciiString& theKey, | |
7752 | const TCollection_AsciiString& theVal) | |
7753 | { | |
7754 | TCollection_AsciiString aCmd (theCmd); | |
7755 | aCmd.LowerCase(); | |
7756 | const Standard_Integer aPos = aCmd.Search (theKey); | |
7757 | if (aPos == -1) | |
7758 | { | |
7759 | return; | |
7760 | } | |
7761 | ||
7762 | TCollection_AsciiString aPart1, aPart2; | |
7763 | Standard_Integer aPart1To = aPos - 1; | |
7764 | if (aPart1To >= 1 | |
7765 | && aPart1To <= theCmd.Length()) | |
7766 | { | |
7767 | aPart1 = theCmd.SubString (1, aPart1To); | |
7768 | } | |
7769 | ||
7770 | Standard_Integer aPart2From = aPos + theKey.Length(); | |
7771 | if (aPart2From >= 1 | |
7772 | && aPart2From <= theCmd.Length()) | |
7773 | { | |
7774 | aPart2 = theCmd.SubString (aPart2From, theCmd.Length()); | |
7775 | } | |
7776 | ||
7777 | theCmd = aPart1 + theVal + aPart2; | |
7778 | } | |
7779 | ||
7780 | protected: | |
7781 | ||
7782 | Draw_Interpretor* myDrawInter; | |
7783 | TCollection_AsciiString myCommand; | |
7784 | ||
7785 | }; | |
7786 | ||
7787 | //! Replace the animation with the new one. | |
7788 | static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation, | |
7789 | Handle(AIS_Animation)& theAnimation, | |
7790 | const Handle(AIS_Animation)& theAnimationNew) | |
7791 | { | |
7792 | theAnimationNew->CopyFrom (theAnimation); | |
7793 | if (!theParentAnimation.IsNull()) | |
7794 | { | |
7795 | theParentAnimation->Replace (theAnimation, theAnimationNew); | |
7796 | } | |
7797 | else | |
7798 | { | |
7799 | ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name()); | |
7800 | ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew); | |
7801 | } | |
7802 | theAnimation = theAnimationNew; | |
7803 | } | |
7804 | ||
7805 | //! Parse the point. | |
7806 | static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt) | |
7807 | { | |
7808 | const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] }; | |
7809 | if (!anXYZ[0].IsRealValue() | |
7810 | || !anXYZ[1].IsRealValue() | |
7811 | || !anXYZ[2].IsRealValue()) | |
7812 | { | |
7813 | return Standard_False; | |
7814 | } | |
7815 | ||
7816 | thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue()); | |
7817 | return Standard_True; | |
7818 | } | |
7819 | ||
7820 | //! Parse the quaternion. | |
7821 | static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot) | |
7822 | { | |
7823 | const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]}; | |
7824 | if (!anXYZW[0].IsRealValue() | |
7825 | || !anXYZW[1].IsRealValue() | |
7826 | || !anXYZW[2].IsRealValue() | |
7827 | || !anXYZW[3].IsRealValue()) | |
7828 | { | |
7829 | return Standard_False; | |
7830 | } | |
7831 | ||
7832 | theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue()); | |
7833 | return Standard_True; | |
7834 | } | |
7835 | ||
08f8a185 | 7836 | //! Auxiliary class for flipping image upside-down. |
7837 | class ImageFlipper | |
7838 | { | |
7839 | public: | |
7840 | ||
7841 | //! Empty constructor. | |
7842 | ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {} | |
7843 | ||
7844 | //! Perform flipping. | |
7845 | Standard_Boolean FlipY (Image_PixMap& theImage) | |
7846 | { | |
7847 | if (theImage.IsEmpty() | |
7848 | || theImage.SizeX() == 0 | |
7849 | || theImage.SizeY() == 0) | |
7850 | { | |
7851 | return Standard_False; | |
7852 | } | |
7853 | ||
7854 | const Standard_Size aRowSize = theImage.SizeRowBytes(); | |
7855 | if (myTmp.Size() < aRowSize | |
7856 | && !myTmp.Allocate (aRowSize)) | |
7857 | { | |
7858 | return Standard_False; | |
7859 | } | |
7860 | ||
7861 | // for odd height middle row should be left as is | |
7862 | Standard_Size aNbRowsHalf = theImage.SizeY() / 2; | |
7863 | for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB) | |
7864 | { | |
7865 | Standard_Byte* aTop = theImage.ChangeRow (aRowT); | |
7866 | Standard_Byte* aBot = theImage.ChangeRow (aRowB); | |
7867 | memcpy (myTmp.ChangeData(), aTop, aRowSize); | |
7868 | memcpy (aTop, aBot, aRowSize); | |
7869 | memcpy (aBot, myTmp.Data(), aRowSize); | |
7870 | } | |
7871 | return Standard_True; | |
7872 | } | |
7873 | ||
7874 | private: | |
7875 | NCollection_Buffer myTmp; | |
7876 | }; | |
7877 | ||
1beb58d7 | 7878 | } |
7879 | ||
197ac94e | 7880 | //================================================================================================= |
4754e164 | 7881 | //function : VViewParams |
dc3fe572 | 7882 | //purpose : Gets or sets AIS View characteristics |
197ac94e | 7883 | //================================================================================================= |
7884 | static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
4754e164 | 7885 | { |
1beb58d7 | 7886 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
7887 | if (aView.IsNull()) | |
4754e164 | 7888 | { |
197ac94e | 7889 | std::cout << theArgVec[0] << ": please initialize or activate view.\n"; |
4754e164 | 7890 | return 1; |
7891 | } | |
197ac94e | 7892 | |
1beb58d7 | 7893 | Standard_Boolean toSetProj = Standard_False; |
7894 | Standard_Boolean toSetUp = Standard_False; | |
7895 | Standard_Boolean toSetAt = Standard_False; | |
7896 | Standard_Boolean toSetEye = Standard_False; | |
7897 | Standard_Boolean toSetScale = Standard_False; | |
7898 | Standard_Boolean toSetSize = Standard_False; | |
7899 | Standard_Boolean toSetCenter2d = Standard_False; | |
ee2be2a8 | 7900 | Standard_Real aViewScale = aView->Scale(); |
7901 | Standard_Real aViewSize = 1.0; | |
1beb58d7 | 7902 | Graphic3d_Vec2i aCenter2d; |
7903 | gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye; | |
7904 | aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3)); | |
7905 | aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3)); | |
7906 | aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3)); | |
7907 | aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3)); | |
197ac94e | 7908 | if (theArgsNb == 1) |
4754e164 | 7909 | { |
197ac94e | 7910 | // print all of the available view parameters |
1beb58d7 | 7911 | char aText[4096]; |
7912 | Sprintf (aText, | |
7913 | "Scale: %g\n" | |
7914 | "Proj: %12g %12g %12g\n" | |
7915 | "Up: %12g %12g %12g\n" | |
7916 | "At: %12g %12g %12g\n" | |
7917 | "Eye: %12g %12g %12g\n", | |
7918 | aViewScale, | |
7919 | aViewProj.X(), aViewProj.Y(), aViewProj.Z(), | |
7920 | aViewUp.X(), aViewUp.Y(), aViewUp.Z(), | |
7921 | aViewAt.X(), aViewAt.Y(), aViewAt.Z(), | |
7922 | aViewEye.X(), aViewEye.Y(), aViewEye.Z()); | |
7923 | theDi << aText; | |
197ac94e | 7924 | return 0; |
4754e164 | 7925 | } |
197ac94e | 7926 | |
1beb58d7 | 7927 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
7928 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
197ac94e | 7929 | { |
1beb58d7 | 7930 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
7931 | anArg.LowerCase(); | |
7932 | if (anUpdateTool.parseRedrawMode (anArg)) | |
197ac94e | 7933 | { |
197ac94e | 7934 | continue; |
7935 | } | |
1beb58d7 | 7936 | else if (anArg == "-cmd" |
7937 | || anArg == "-command" | |
7938 | || anArg == "-args") | |
7939 | { | |
7940 | char aText[4096]; | |
7941 | Sprintf (aText, | |
7942 | "-scale %g " | |
7943 | "-proj %g %g %g " | |
7944 | "-up %g %g %g " | |
7945 | "-at %g %g %g\n", | |
7946 | aViewScale, | |
7947 | aViewProj.X(), aViewProj.Y(), aViewProj.Z(), | |
7948 | aViewUp.X(), aViewUp.Y(), aViewUp.Z(), | |
7949 | aViewAt.X(), aViewAt.Y(), aViewAt.Z()); | |
7950 | theDi << aText; | |
7951 | } | |
7952 | else if (anArg == "-scale" | |
7953 | || anArg == "-size") | |
7954 | { | |
7955 | if (anArgIter + 1 < theArgsNb | |
7956 | && *theArgVec[anArgIter + 1] != '-') | |
7957 | { | |
7958 | const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]); | |
7959 | if (aValueArg.IsRealValue()) | |
7960 | { | |
7961 | ++anArgIter; | |
7962 | if (anArg == "-scale") | |
7963 | { | |
7964 | toSetScale = Standard_True; | |
7965 | aViewScale = aValueArg.RealValue(); | |
7966 | } | |
7967 | else if (anArg == "-size") | |
7968 | { | |
7969 | toSetSize = Standard_True; | |
7970 | aViewSize = aValueArg.RealValue(); | |
7971 | } | |
7972 | continue; | |
7973 | } | |
7974 | } | |
7975 | if (anArg == "-scale") | |
7976 | { | |
7977 | theDi << "Scale: " << aView->Scale() << "\n"; | |
7978 | } | |
7979 | else if (anArg == "-size") | |
7980 | { | |
7981 | Graphic3d_Vec2d aSizeXY; | |
7982 | aView->Size (aSizeXY.x(), aSizeXY.y()); | |
7983 | theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n"; | |
7984 | } | |
7985 | } | |
7986 | else if (anArg == "-eye" | |
7987 | || anArg == "-at" | |
7988 | || anArg == "-up" | |
7989 | || anArg == "-proj") | |
7990 | { | |
7991 | if (anArgIter + 3 < theArgsNb) | |
7992 | { | |
7993 | gp_XYZ anXYZ; | |
7994 | if (parseXYZ (theArgVec + anArgIter + 1, anXYZ)) | |
7995 | { | |
7996 | anArgIter += 3; | |
7997 | if (anArg == "-eye") | |
7998 | { | |
7999 | toSetEye = Standard_True; | |
8000 | aViewEye = anXYZ; | |
8001 | } | |
8002 | else if (anArg == "-at") | |
8003 | { | |
8004 | toSetAt = Standard_True; | |
8005 | aViewAt = anXYZ; | |
8006 | } | |
8007 | else if (anArg == "-up") | |
8008 | { | |
8009 | toSetUp = Standard_True; | |
8010 | aViewUp = anXYZ; | |
8011 | } | |
8012 | else if (anArg == "-proj") | |
8013 | { | |
8014 | toSetProj = Standard_True; | |
8015 | aViewProj = anXYZ; | |
8016 | } | |
8017 | continue; | |
8018 | } | |
8019 | } | |
197ac94e | 8020 | |
1beb58d7 | 8021 | if (anArg == "-eye") |
8022 | { | |
8023 | theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n"; | |
8024 | } | |
8025 | else if (anArg == "-at") | |
8026 | { | |
8027 | theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n"; | |
8028 | } | |
8029 | else if (anArg == "-up") | |
8030 | { | |
8031 | theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n"; | |
8032 | } | |
8033 | else if (anArg == "-proj") | |
8034 | { | |
8035 | theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n"; | |
8036 | } | |
8037 | } | |
8038 | else if (anArg == "-center") | |
3dfe95cd | 8039 | { |
1beb58d7 | 8040 | if (anArgIter + 2 < theArgsNb) |
8041 | { | |
8042 | const TCollection_AsciiString anX (theArgVec[anArgIter + 1]); | |
8043 | const TCollection_AsciiString anY (theArgVec[anArgIter + 2]); | |
8044 | if (anX.IsIntegerValue() | |
8045 | && anY.IsIntegerValue()) | |
8046 | { | |
8047 | toSetCenter2d = Standard_True; | |
8048 | aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()); | |
8049 | } | |
8050 | } | |
8051 | } | |
8052 | else | |
8053 | { | |
8054 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
3dfe95cd | 8055 | return 1; |
8056 | } | |
1beb58d7 | 8057 | } |
3dfe95cd | 8058 | |
1beb58d7 | 8059 | // change view parameters in proper order |
8060 | if (toSetScale) | |
8061 | { | |
8062 | aView->SetScale (aViewScale); | |
8063 | } | |
8064 | if (toSetSize) | |
8065 | { | |
8066 | aView->SetSize (aViewSize); | |
8067 | } | |
8068 | if (toSetEye) | |
8069 | { | |
8070 | aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z()); | |
8071 | } | |
8072 | if (toSetAt) | |
8073 | { | |
8074 | aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z()); | |
8075 | } | |
8076 | if (toSetProj) | |
8077 | { | |
8078 | aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z()); | |
8079 | } | |
8080 | if (toSetUp) | |
8081 | { | |
8082 | aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z()); | |
8083 | } | |
8084 | if (toSetCenter2d) | |
8085 | { | |
8086 | aView->SetCenter (aCenter2d.x(), aCenter2d.y()); | |
197ac94e | 8087 | } |
8088 | ||
1beb58d7 | 8089 | return 0; |
8090 | } | |
197ac94e | 8091 | |
2e93433e | 8092 | //============================================================================== |
8093 | //function : V2DMode | |
8094 | //purpose : | |
8095 | //============================================================================== | |
8096 | static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec) | |
8097 | { | |
8098 | bool is2dMode = true; | |
8099 | Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()); | |
8100 | if (aV3dView.IsNull()) | |
8101 | { | |
8102 | std::cout << "Error: no active view.\n"; | |
8103 | return 1; | |
8104 | } | |
8105 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
8106 | { | |
8107 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; | |
8108 | TCollection_AsciiString anArgCase = anArg; | |
8109 | anArgCase.LowerCase(); | |
8110 | if (anArgIt + 1 < theArgsNb | |
8111 | && anArgCase == "-name") | |
8112 | { | |
8113 | ViewerTest_Names aViewNames (theArgVec[++anArgIt]); | |
8114 | TCollection_AsciiString aViewName = aViewNames.GetViewName(); | |
8115 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
8116 | { | |
8117 | std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n"; | |
8118 | return 1; | |
8119 | } | |
8120 | aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName)); | |
8121 | } | |
8122 | else if (anArgCase == "-mode") | |
8123 | { | |
8124 | if (anArgIt + 1 < theArgsNb | |
8125 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode)) | |
8126 | { | |
8127 | ++anArgIt; | |
8128 | } | |
8129 | } | |
8130 | else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode)) | |
8131 | { | |
8132 | // | |
8133 | } | |
8134 | else | |
8135 | { | |
8136 | std::cout << "Syntax error: unknown argument " << anArg << ".\n"; | |
8137 | return 1; | |
8138 | } | |
8139 | } | |
8140 | ||
8141 | aV3dView->SetView2DMode (is2dMode); | |
8142 | return 0; | |
8143 | } | |
8144 | ||
1beb58d7 | 8145 | //============================================================================== |
8146 | //function : VAnimation | |
8147 | //purpose : | |
8148 | //============================================================================== | |
8149 | static Standard_Integer VAnimation (Draw_Interpretor& theDI, | |
8150 | Standard_Integer theArgNb, | |
8151 | const char** theArgVec) | |
8152 | { | |
8153 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
8154 | if (theArgNb < 2) | |
4754e164 | 8155 | { |
1beb58d7 | 8156 | for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator |
8157 | anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next()) | |
8158 | { | |
8159 | theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n"; | |
197ac94e | 8160 | } |
1beb58d7 | 8161 | return 0; |
8162 | } | |
8163 | if (aCtx.IsNull()) | |
8164 | { | |
8165 | std::cout << "Error: no active view\n"; | |
8166 | return 1; | |
4754e164 | 8167 | } |
197ac94e | 8168 | |
1beb58d7 | 8169 | Standard_Integer anArgIter = 1; |
8170 | TCollection_AsciiString aNameArg (theArgVec[anArgIter++]); | |
8171 | if (aNameArg.IsEmpty()) | |
8172 | { | |
8173 | std::cout << "Syntax error: animation name is not defined.\n"; | |
8174 | return 1; | |
8175 | } | |
8176 | ||
8177 | TCollection_AsciiString aNameArgLower = aNameArg; | |
8178 | aNameArgLower.LowerCase(); | |
8179 | if (aNameArgLower == "-reset" | |
8180 | || aNameArgLower == "-clear") | |
8181 | { | |
8182 | ViewerTest_AnimationTimelineMap.Clear(); | |
8183 | return 0; | |
8184 | } | |
8185 | else if (aNameArg.Value (1) == '-') | |
8186 | { | |
8187 | std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n"; | |
8188 | return 1; | |
8189 | } | |
197ac94e | 8190 | |
1beb58d7 | 8191 | const char* aNameSplitter = "/"; |
8192 | Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter); | |
8193 | if (aSplitPos == -1) | |
197ac94e | 8194 | { |
1beb58d7 | 8195 | aNameSplitter = "."; |
8196 | aSplitPos = aNameArg.Search (aNameSplitter); | |
8197 | } | |
8198 | ||
8199 | // find existing or create a new animation by specified name within syntax "parent.child". | |
8200 | Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation; | |
8201 | for (; !aNameArg.IsEmpty();) | |
8202 | { | |
8203 | TCollection_AsciiString aNameParent; | |
8204 | if (aSplitPos != -1) | |
197ac94e | 8205 | { |
1beb58d7 | 8206 | if (aSplitPos == aNameArg.Length()) |
8207 | { | |
8208 | std::cout << "Syntax error: animation name is not defined.\n"; | |
8209 | return 1; | |
8210 | } | |
8211 | ||
8212 | aNameParent = aNameArg.SubString ( 1, aSplitPos - 1); | |
8213 | aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length()); | |
8214 | ||
8215 | aSplitPos = aNameArg.Search (aNameSplitter); | |
197ac94e | 8216 | } |
8217 | else | |
8218 | { | |
1beb58d7 | 8219 | aNameParent = aNameArg; |
8220 | aNameArg.Clear(); | |
197ac94e | 8221 | } |
1beb58d7 | 8222 | |
8223 | if (anAnimation.IsNull()) | |
3dfe95cd | 8224 | { |
1beb58d7 | 8225 | if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation)) |
8226 | { | |
8227 | anAnimation = new AIS_Animation (aNameParent); | |
8228 | ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation); | |
8229 | } | |
8230 | aRootAnimation = anAnimation; | |
3dfe95cd | 8231 | } |
8232 | else | |
8233 | { | |
1beb58d7 | 8234 | aParentAnimation = anAnimation; |
8235 | anAnimation = aParentAnimation->Find (aNameParent); | |
8236 | if (anAnimation.IsNull()) | |
8237 | { | |
8238 | anAnimation = new AIS_Animation (aNameParent); | |
8239 | aParentAnimation->Add (anAnimation); | |
8240 | } | |
3dfe95cd | 8241 | } |
8242 | } | |
1beb58d7 | 8243 | |
8244 | if (anArgIter >= theArgNb) | |
197ac94e | 8245 | { |
1beb58d7 | 8246 | // just print the list of children |
8247 | for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next()) | |
197ac94e | 8248 | { |
1beb58d7 | 8249 | theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n"; |
197ac94e | 8250 | } |
1beb58d7 | 8251 | return 0; |
197ac94e | 8252 | } |
1beb58d7 | 8253 | |
bf7b2ceb | 8254 | // animation parameters |
1beb58d7 | 8255 | Standard_Boolean toPlay = Standard_False; |
8256 | Standard_Real aPlaySpeed = 1.0; | |
8257 | Standard_Real aPlayStartTime = anAnimation->StartPts(); | |
8258 | Standard_Real aPlayDuration = anAnimation->Duration(); | |
1beb58d7 | 8259 | Standard_Boolean isFreeCamera = Standard_False; |
8260 | Standard_Boolean isLockLoop = Standard_False; | |
08f8a185 | 8261 | |
8262 | // video recording parameters | |
8263 | TCollection_AsciiString aRecFile; | |
8264 | Image_VideoParams aRecParams; | |
8265 | ||
1beb58d7 | 8266 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
8267 | for (; anArgIter < theArgNb; ++anArgIter) | |
197ac94e | 8268 | { |
1beb58d7 | 8269 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
8270 | anArg.LowerCase(); | |
bf7b2ceb | 8271 | // general options |
1beb58d7 | 8272 | if (anArg == "-reset" |
8273 | || anArg == "-clear") | |
197ac94e | 8274 | { |
1beb58d7 | 8275 | anAnimation->Clear(); |
8276 | } | |
8277 | else if (anArg == "-remove" | |
8278 | || anArg == "-del" | |
8279 | || anArg == "-delete") | |
8280 | { | |
8281 | if (!aParentAnimation.IsNull()) | |
8282 | { | |
8283 | ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name()); | |
8284 | } | |
8285 | else | |
8286 | { | |
8287 | aParentAnimation->Remove (anAnimation); | |
8288 | } | |
8289 | } | |
bf7b2ceb | 8290 | // playback options |
1beb58d7 | 8291 | else if (anArg == "-play") |
8292 | { | |
8293 | toPlay = Standard_True; | |
8294 | if (++anArgIter < theArgNb) | |
8295 | { | |
8296 | if (*theArgVec[anArgIter] == '-') | |
8297 | { | |
8298 | --anArgIter; | |
8299 | continue; | |
8300 | } | |
8301 | aPlayStartTime = Draw::Atof (theArgVec[anArgIter]); | |
8302 | ||
8303 | if (++anArgIter < theArgNb) | |
8304 | { | |
8305 | if (*theArgVec[anArgIter] == '-') | |
8306 | { | |
8307 | --anArgIter; | |
8308 | continue; | |
8309 | } | |
8310 | aPlayDuration = Draw::Atof (theArgVec[anArgIter]); | |
8311 | } | |
8312 | } | |
8313 | } | |
8314 | else if (anArg == "-resume") | |
8315 | { | |
8316 | toPlay = Standard_True; | |
8317 | aPlayStartTime = anAnimation->ElapsedTime(); | |
8318 | if (++anArgIter < theArgNb) | |
8319 | { | |
8320 | if (*theArgVec[anArgIter] == '-') | |
8321 | { | |
8322 | --anArgIter; | |
8323 | continue; | |
8324 | } | |
8325 | ||
8326 | aPlayDuration = Draw::Atof (theArgVec[anArgIter]); | |
8327 | } | |
8328 | } | |
8329 | else if (anArg == "-playspeed" | |
8330 | || anArg == "-speed") | |
8331 | { | |
8332 | if (++anArgIter >= theArgNb) | |
8333 | { | |
8334 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8335 | return 1; | |
8336 | } | |
8337 | aPlaySpeed = Draw::Atof (theArgVec[anArgIter]); | |
8338 | } | |
8339 | else if (anArg == "-lock" | |
8340 | || anArg == "-lockloop" | |
8341 | || anArg == "-playlockloop") | |
8342 | { | |
8343 | isLockLoop = Standard_True; | |
8344 | } | |
8345 | else if (anArg == "-freecamera" | |
8346 | || anArg == "-playfreecamera" | |
8347 | || anArg == "-freelook") | |
8348 | { | |
8349 | isFreeCamera = Standard_True; | |
8350 | } | |
08f8a185 | 8351 | // video recodring options |
8352 | else if (anArg == "-rec" | |
8353 | || anArg == "-record") | |
8354 | { | |
8355 | if (++anArgIter >= theArgNb) | |
8356 | { | |
8357 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8358 | return 1; | |
8359 | } | |
8360 | ||
8361 | aRecFile = theArgVec[anArgIter]; | |
8362 | if (aRecParams.FpsNum <= 0) | |
8363 | { | |
8364 | aRecParams.FpsNum = 24; | |
8365 | } | |
8366 | ||
8367 | if (anArgIter + 2 < theArgNb | |
8368 | && *theArgVec[anArgIter + 1] != '-' | |
8369 | && *theArgVec[anArgIter + 2] != '-') | |
8370 | { | |
8371 | TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]); | |
8372 | TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]); | |
8373 | if (aWidthArg .IsIntegerValue() | |
8374 | && aHeightArg.IsIntegerValue()) | |
8375 | { | |
8376 | aRecParams.Width = aWidthArg .IntegerValue(); | |
8377 | aRecParams.Height = aHeightArg.IntegerValue(); | |
8378 | anArgIter += 2; | |
8379 | } | |
8380 | } | |
8381 | } | |
1beb58d7 | 8382 | else if (anArg == "-fps") |
8383 | { | |
8384 | if (++anArgIter >= theArgNb) | |
8385 | { | |
8386 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8387 | return 1; | |
8388 | } | |
bf7b2ceb | 8389 | |
8390 | TCollection_AsciiString aFpsArg (theArgVec[anArgIter]); | |
8391 | Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length()); | |
8392 | if (aSplitIndex == 0) | |
8393 | { | |
08f8a185 | 8394 | aRecParams.FpsNum = aFpsArg.IntegerValue(); |
bf7b2ceb | 8395 | } |
8396 | else | |
8397 | { | |
8398 | const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex); | |
8399 | aFpsArg.Split (aFpsArg.Length() - 1); | |
8400 | const TCollection_AsciiString aNumStr = aFpsArg; | |
08f8a185 | 8401 | aRecParams.FpsNum = aNumStr.IntegerValue(); |
8402 | aRecParams.FpsDen = aDenStr.IntegerValue(); | |
8403 | if (aRecParams.FpsDen < 1) | |
bf7b2ceb | 8404 | { |
8405 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8406 | return 1; | |
8407 | } | |
8408 | } | |
1beb58d7 | 8409 | } |
08f8a185 | 8410 | else if (anArg == "-format") |
8411 | { | |
8412 | if (++anArgIter >= theArgNb) | |
8413 | { | |
8414 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8415 | return 1; | |
8416 | } | |
8417 | aRecParams.Format = theArgVec[anArgIter]; | |
8418 | } | |
8419 | else if (anArg == "-pix_fmt" | |
8420 | || anArg == "-pixfmt" | |
8421 | || anArg == "-pixelformat") | |
8422 | { | |
8423 | if (++anArgIter >= theArgNb) | |
8424 | { | |
8425 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8426 | return 1; | |
8427 | } | |
8428 | aRecParams.PixelFormat = theArgVec[anArgIter]; | |
8429 | } | |
8430 | else if (anArg == "-codec" | |
8431 | || anArg == "-vcodec" | |
8432 | || anArg == "-videocodec") | |
8433 | { | |
8434 | if (++anArgIter >= theArgNb) | |
8435 | { | |
8436 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8437 | return 1; | |
8438 | } | |
8439 | aRecParams.VideoCodec = theArgVec[anArgIter]; | |
8440 | } | |
8441 | else if (anArg == "-crf" | |
8442 | || anArg == "-preset" | |
8443 | || anArg == "-qp") | |
8444 | { | |
8445 | const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length()); | |
8446 | if (++anArgIter >= theArgNb) | |
8447 | { | |
8448 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8449 | return 1; | |
8450 | } | |
8451 | ||
8452 | aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]); | |
8453 | } | |
bf7b2ceb | 8454 | // animation definition options |
1beb58d7 | 8455 | else if (anArg == "-start" |
8456 | || anArg == "-starttime" | |
8457 | || anArg == "-startpts") | |
8458 | { | |
8459 | if (++anArgIter >= theArgNb) | |
8460 | { | |
8461 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8462 | return 1; | |
8463 | } | |
8464 | ||
8465 | anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter])); | |
8466 | aRootAnimation->UpdateTotalDuration(); | |
8467 | } | |
8468 | else if (anArg == "-end" | |
8469 | || anArg == "-endtime" | |
8470 | || anArg == "-endpts") | |
8471 | { | |
8472 | if (++anArgIter >= theArgNb) | |
8473 | { | |
8474 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8475 | return 1; | |
8476 | } | |
8477 | ||
8478 | anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts()); | |
8479 | aRootAnimation->UpdateTotalDuration(); | |
8480 | } | |
8481 | else if (anArg == "-dur" | |
8482 | || anArg == "-duration") | |
8483 | { | |
8484 | if (++anArgIter >= theArgNb) | |
8485 | { | |
8486 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8487 | return 1; | |
8488 | } | |
8489 | ||
8490 | anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter])); | |
8491 | aRootAnimation->UpdateTotalDuration(); | |
8492 | } | |
8493 | else if (anArg == "-command" | |
8494 | || anArg == "-cmd" | |
8495 | || anArg == "-invoke" | |
8496 | || anArg == "-eval" | |
8497 | || anArg == "-proc") | |
8498 | { | |
8499 | if (++anArgIter >= theArgNb) | |
8500 | { | |
8501 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8502 | return 1; | |
8503 | } | |
8504 | ||
8505 | Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]); | |
8506 | replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation); | |
8507 | } | |
8508 | else if (anArg == "-objecttrsf" | |
8509 | || anArg == "-objectransformation" | |
8510 | || anArg == "-objtransformation" | |
8511 | || anArg == "-objtrsf" | |
8512 | || anArg == "-object" | |
8513 | || anArg == "-obj") | |
8514 | { | |
8515 | if (++anArgIter >= theArgNb) | |
8516 | { | |
8517 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8518 | return 1; | |
8519 | } | |
8520 | ||
8521 | TCollection_AsciiString anObjName (theArgVec[anArgIter]); | |
8522 | const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS(); | |
8f521168 | 8523 | Handle(AIS_InteractiveObject) anObject; |
8524 | if (!aMapOfAIS.Find2 (anObjName, anObject)) | |
1beb58d7 | 8525 | { |
8526 | std::cout << "Syntax error: wrong object name at " << anArg << "\n"; | |
8527 | return 1; | |
8528 | } | |
8529 | ||
1beb58d7 | 8530 | gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() }; |
8531 | gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() }; | |
8532 | gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() }; | |
8533 | Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() }; | |
8534 | Standard_Boolean isTrsfSet = Standard_False; | |
8535 | Standard_Integer aTrsfArgIter = anArgIter + 1; | |
8536 | for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter) | |
8537 | { | |
8538 | TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]); | |
8539 | aTrsfArg.LowerCase(); | |
8540 | const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1; | |
8541 | if (aTrsfArg.StartsWith ("-rotation") | |
8542 | || aTrsfArg.StartsWith ("-rot")) | |
8543 | { | |
8544 | isTrsfSet = Standard_True; | |
8545 | if (aTrsfArgIter + 4 >= theArgNb | |
8546 | || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex])) | |
8547 | { | |
8548 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
8549 | return 1; | |
8550 | } | |
8551 | aTrsfArgIter += 4; | |
8552 | } | |
8553 | else if (aTrsfArg.StartsWith ("-location") | |
8554 | || aTrsfArg.StartsWith ("-loc")) | |
8555 | { | |
8556 | isTrsfSet = Standard_True; | |
8557 | if (aTrsfArgIter + 3 >= theArgNb | |
8558 | || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex])) | |
8559 | { | |
8560 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
8561 | return 1; | |
8562 | } | |
8563 | aTrsfArgIter += 3; | |
8564 | } | |
8565 | else if (aTrsfArg.StartsWith ("-scale")) | |
8566 | { | |
8567 | isTrsfSet = Standard_True; | |
8568 | if (++aTrsfArgIter >= theArgNb) | |
8569 | { | |
8570 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
8571 | return 1; | |
8572 | } | |
8573 | ||
8574 | const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]); | |
8575 | if (!aScaleStr.IsRealValue()) | |
8576 | { | |
8577 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
8578 | return 1; | |
8579 | } | |
8580 | aScales[anIndex] = aScaleStr.RealValue(); | |
8581 | } | |
8582 | else | |
8583 | { | |
8584 | anArgIter = aTrsfArgIter - 1; | |
8585 | break; | |
8586 | } | |
8587 | } | |
8588 | if (!isTrsfSet) | |
8589 | { | |
8590 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8591 | return 1; | |
8592 | } | |
8593 | else if (aTrsfArgIter >= theArgNb) | |
8594 | { | |
8595 | anArgIter = theArgNb; | |
8596 | } | |
8597 | ||
8598 | aTrsfs[0].SetRotation (aRotQuats[0]); | |
8599 | aTrsfs[1].SetRotation (aRotQuats[1]); | |
8600 | aTrsfs[0].SetTranslationPart (aLocPnts[0]); | |
8601 | aTrsfs[1].SetTranslationPart (aLocPnts[1]); | |
8602 | aTrsfs[0].SetScaleFactor (aScales[0]); | |
8603 | aTrsfs[1].SetScaleFactor (aScales[1]); | |
8604 | ||
8605 | Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]); | |
8606 | replaceAnimation (aParentAnimation, anAnimation, anObjAnimation); | |
8607 | } | |
8608 | else if (anArg == "-viewtrsf" | |
8609 | || anArg == "-view") | |
8610 | { | |
8611 | Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation); | |
8612 | if (aCamAnimation.IsNull()) | |
8613 | { | |
8614 | aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView); | |
8615 | replaceAnimation (aParentAnimation, anAnimation, aCamAnimation); | |
8616 | } | |
8617 | ||
8618 | Handle(Graphic3d_Camera) aCams[2] = | |
8619 | { | |
8620 | new Graphic3d_Camera (aCamAnimation->View()->Camera()), | |
8621 | new Graphic3d_Camera (aCamAnimation->View()->Camera()) | |
8622 | }; | |
8623 | ||
8624 | Standard_Boolean isTrsfSet = Standard_False; | |
8625 | Standard_Integer aViewArgIter = anArgIter + 1; | |
8626 | for (; aViewArgIter < theArgNb; ++aViewArgIter) | |
8627 | { | |
8628 | TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]); | |
8629 | aViewArg.LowerCase(); | |
8630 | const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1; | |
8631 | if (aViewArg.StartsWith ("-scale")) | |
8632 | { | |
8633 | isTrsfSet = Standard_True; | |
8634 | if (++aViewArgIter >= theArgNb) | |
8635 | { | |
8636 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8637 | return 1; | |
8638 | } | |
8639 | ||
8640 | const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]); | |
8641 | if (!aScaleStr.IsRealValue()) | |
8642 | { | |
8643 | std::cout << "Syntax error at " << aViewArg << ".\n"; | |
8644 | return 1; | |
8645 | } | |
8646 | Standard_Real aScale = aScaleStr.RealValue(); | |
8647 | aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale; | |
8648 | aCams[anIndex]->SetScale (aScale); | |
8649 | } | |
8650 | else if (aViewArg.StartsWith ("-eye") | |
8651 | || aViewArg.StartsWith ("-center") | |
8652 | || aViewArg.StartsWith ("-at") | |
8653 | || aViewArg.StartsWith ("-up")) | |
8654 | { | |
8655 | isTrsfSet = Standard_True; | |
8656 | gp_XYZ anXYZ; | |
8657 | if (aViewArgIter + 3 >= theArgNb | |
8658 | || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ)) | |
8659 | { | |
8660 | std::cout << "Syntax error at " << aViewArg << ".\n"; | |
8661 | return 1; | |
8662 | } | |
8663 | aViewArgIter += 3; | |
8664 | ||
8665 | if (aViewArg.StartsWith ("-eye")) | |
8666 | { | |
8667 | aCams[anIndex]->SetEye (anXYZ); | |
8668 | } | |
8669 | else if (aViewArg.StartsWith ("-center") | |
8670 | || aViewArg.StartsWith ("-at")) | |
8671 | { | |
8672 | aCams[anIndex]->SetCenter (anXYZ); | |
8673 | } | |
8674 | else if (aViewArg.StartsWith ("-up")) | |
8675 | { | |
8676 | aCams[anIndex]->SetUp (anXYZ); | |
8677 | } | |
8678 | } | |
8679 | else | |
8680 | { | |
8681 | anArgIter = aViewArgIter - 1; | |
8682 | break; | |
8683 | } | |
8684 | } | |
8685 | if (!isTrsfSet) | |
8686 | { | |
8687 | std::cout << "Syntax error at " << anArg << ".\n"; | |
8688 | return 1; | |
8689 | } | |
8690 | else if (aViewArgIter >= theArgNb) | |
8691 | { | |
8692 | anArgIter = theArgNb; | |
8693 | } | |
8694 | ||
8695 | aCamAnimation->SetCameraStart(aCams[0]); | |
8696 | aCamAnimation->SetCameraEnd (aCams[1]); | |
197ac94e | 8697 | } |
8698 | else | |
8699 | { | |
1beb58d7 | 8700 | std::cout << "Syntax error at " << anArg << ".\n"; |
8701 | return 1; | |
197ac94e | 8702 | } |
8703 | } | |
1beb58d7 | 8704 | |
08f8a185 | 8705 | if (!toPlay && aRecFile.IsEmpty()) |
197ac94e | 8706 | { |
1beb58d7 | 8707 | return 0; |
8708 | } | |
8709 | ||
8710 | // Start animation timeline and process frame updating. | |
8711 | TheIsAnimating = Standard_True; | |
8712 | const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False); | |
8713 | Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera()); | |
bf7b2ceb | 8714 | anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0); |
1beb58d7 | 8715 | if (isFreeCamera) |
8716 | { | |
8717 | aView->Camera()->Copy (aCameraBack); | |
8718 | } | |
8719 | ||
8720 | const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration; | |
08f8a185 | 8721 | if (aRecParams.FpsNum <= 0) |
1beb58d7 | 8722 | { |
8723 | while (!anAnimation->IsStopped()) | |
197ac94e | 8724 | { |
1beb58d7 | 8725 | aCameraBack->Copy (aView->Camera()); |
8726 | const Standard_Real aPts = anAnimation->UpdateTimer(); | |
8727 | if (isFreeCamera) | |
8728 | { | |
8729 | aView->Camera()->Copy (aCameraBack); | |
8730 | } | |
8731 | ||
8732 | if (aPts >= anUpperPts) | |
8733 | { | |
8734 | anAnimation->Pause(); | |
8735 | break; | |
8736 | } | |
8737 | ||
8738 | if (aView->IsInvalidated()) | |
8739 | { | |
8740 | aView->Redraw(); | |
8741 | } | |
8742 | else | |
8743 | { | |
8744 | aView->RedrawImmediate(); | |
8745 | } | |
8746 | ||
8747 | if (!isLockLoop) | |
8748 | { | |
8749 | // handle user events | |
8750 | theDI.Eval ("after 1 set waiter 1"); | |
8751 | theDI.Eval ("vwait waiter"); | |
8752 | } | |
8753 | if (!TheIsAnimating) | |
8754 | { | |
8755 | anAnimation->Pause(); | |
8756 | theDI << aPts; | |
8757 | break; | |
8758 | } | |
8759 | } | |
8760 | ||
8761 | if (aView->IsInvalidated()) | |
8762 | { | |
8763 | aView->Redraw(); | |
197ac94e | 8764 | } |
8765 | else | |
8766 | { | |
1beb58d7 | 8767 | aView->RedrawImmediate(); |
197ac94e | 8768 | } |
8769 | } | |
1beb58d7 | 8770 | else |
197ac94e | 8771 | { |
bf7b2ceb | 8772 | OSD_Timer aPerfTimer; |
8773 | aPerfTimer.Start(); | |
1beb58d7 | 8774 | |
08f8a185 | 8775 | Handle(Image_VideoRecorder) aRecorder; |
8776 | ImageFlipper aFlipper; | |
8777 | Handle(Draw_ProgressIndicator) aProgress; | |
8778 | if (!aRecFile.IsEmpty()) | |
8779 | { | |
8780 | if (aRecParams.Width <= 0 | |
8781 | || aRecParams.Height <= 0) | |
8782 | { | |
8783 | aView->Window()->Size (aRecParams.Width, aRecParams.Height); | |
8784 | } | |
8785 | ||
8786 | aRecorder = new Image_VideoRecorder(); | |
8787 | if (!aRecorder->Open (aRecFile.ToCString(), aRecParams)) | |
8788 | { | |
8789 | std::cout << "Error: failed to open video file for recording\n"; | |
8790 | return 0; | |
8791 | } | |
8792 | ||
8793 | aProgress = new Draw_ProgressIndicator (theDI, 1); | |
8794 | } | |
8795 | ||
1beb58d7 | 8796 | // Manage frame-rated animation here |
8797 | Standard_Real aPts = aPlayStartTime; | |
bf7b2ceb | 8798 | int64_t aNbFrames = 0; |
08f8a185 | 8799 | Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1); |
8800 | Standard_Integer aSecondsProgress = 0; | |
8801 | for (; aPts <= anUpperPts && aPSentry.More();) | |
197ac94e | 8802 | { |
08f8a185 | 8803 | const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames)); |
bf7b2ceb | 8804 | aPts = aPlayStartTime + aRecPts; |
8805 | ++aNbFrames; | |
1beb58d7 | 8806 | if (!anAnimation->Update (aPts)) |
8807 | { | |
8808 | break; | |
8809 | } | |
8810 | ||
08f8a185 | 8811 | if (!aRecorder.IsNull()) |
8812 | { | |
8813 | V3d_ImageDumpOptions aDumpParams; | |
8814 | aDumpParams.Width = aRecParams.Width; | |
8815 | aDumpParams.Height = aRecParams.Height; | |
8816 | aDumpParams.BufferType = Graphic3d_BT_RGBA; | |
8817 | aDumpParams.StereoOptions = V3d_SDO_MONO; | |
8818 | aDumpParams.ToAdjustAspect = Standard_True; | |
8819 | if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams)) | |
8820 | { | |
8821 | std::cout << "Error: view dump is failed!\n"; | |
8822 | return 0; | |
8823 | } | |
8824 | aFlipper.FlipY (aRecorder->ChangeFrame()); | |
8825 | if (!aRecorder->PushFrame()) | |
8826 | { | |
8827 | return 0; | |
8828 | } | |
8829 | } | |
8830 | else | |
8831 | { | |
8832 | aView->Redraw(); | |
8833 | } | |
8834 | ||
8835 | while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed)) | |
8836 | { | |
8837 | aPSentry.Next(); | |
8838 | ++aSecondsProgress; | |
8839 | } | |
197ac94e | 8840 | } |
bf7b2ceb | 8841 | |
8842 | aPerfTimer.Stop(); | |
1beb58d7 | 8843 | anAnimation->Stop(); |
bf7b2ceb | 8844 | const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime(); |
8845 | theDI << "Average FPS: " << aRecFps << "\n" | |
8846 | << "Nb. Frames: " << Standard_Real(aNbFrames); | |
8847 | ||
8848 | aView->Redraw(); | |
197ac94e | 8849 | } |
8850 | ||
1beb58d7 | 8851 | aView->SetImmediateUpdate (wasImmediateUpdate); |
8852 | TheIsAnimating = Standard_False; | |
4754e164 | 8853 | return 0; |
8854 | } | |
8855 | ||
1beb58d7 | 8856 | |
4754e164 | 8857 | //======================================================================= |
8858 | //function : VChangeSelected | |
dc3fe572 | 8859 | //purpose : Adds the shape to selection or remove one from it |
4754e164 | 8860 | //======================================================================= |
8861 | static Standard_Integer VChangeSelected (Draw_Interpretor& di, | |
8862 | Standard_Integer argc, | |
8863 | const char ** argv) | |
8864 | { | |
8865 | if(argc != 2) | |
8866 | { | |
8867 | di<<"Usage : " << argv[0] << " shape \n"; | |
8868 | return 1; | |
8869 | } | |
8870 | //get AIS_Shape: | |
4754e164 | 8871 | TCollection_AsciiString aName(argv[1]); |
8872 | Handle(AIS_InteractiveObject) anAISObject; | |
8f521168 | 8873 | if (!GetMapOfAIS().Find2 (aName, anAISObject) |
8874 | || anAISObject.IsNull()) | |
4754e164 | 8875 | { |
8876 | di<<"Use 'vdisplay' before"; | |
8877 | return 1; | |
8878 | } | |
4754e164 | 8879 | |
8f521168 | 8880 | ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True); |
4754e164 | 8881 | return 0; |
8882 | } | |
8883 | ||
4754e164 | 8884 | //======================================================================= |
8885 | //function : VNbSelected | |
dc3fe572 | 8886 | //purpose : Returns number of selected objects |
4754e164 | 8887 | //======================================================================= |
8888 | static Standard_Integer VNbSelected (Draw_Interpretor& di, | |
8889 | Standard_Integer argc, | |
8890 | const char ** argv) | |
8891 | { | |
8892 | if(argc != 1) | |
8893 | { | |
8894 | di << "Usage : " << argv[0] << "\n"; | |
8895 | return 1; | |
8896 | } | |
8897 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8898 | if(aContext.IsNull()) | |
8899 | { | |
8900 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8901 | return 1; | |
8902 | } | |
8903 | di << aContext->NbSelected() << "\n"; | |
8904 | return 0; | |
8905 | } | |
8906 | ||
4754e164 | 8907 | //======================================================================= |
8908 | //function : VPurgeDisplay | |
dc3fe572 | 8909 | //purpose : Switches altialiasing on or off |
4754e164 | 8910 | //======================================================================= |
8911 | static Standard_Integer VPurgeDisplay (Draw_Interpretor& di, | |
8912 | Standard_Integer argc, | |
8913 | const char ** argv) | |
8914 | { | |
eb4320f2 | 8915 | if (argc > 1) |
4754e164 | 8916 | { |
eb4320f2 | 8917 | di << "Usage : " << argv[0] << "\n"; |
4754e164 | 8918 | return 1; |
8919 | } | |
4754e164 | 8920 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
8921 | if (aContext.IsNull()) | |
8922 | { | |
8923 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8924 | return 1; | |
8925 | } | |
404c8936 | 8926 | |
eb4320f2 | 8927 | di << aContext->PurgeDisplay() << "\n"; |
4754e164 | 8928 | return 0; |
8929 | } | |
8930 | ||
8931 | //======================================================================= | |
8932 | //function : VSetViewSize | |
8933 | //purpose : | |
8934 | //======================================================================= | |
8935 | static Standard_Integer VSetViewSize (Draw_Interpretor& di, | |
8936 | Standard_Integer argc, | |
8937 | const char ** argv) | |
8938 | { | |
8939 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8940 | if(aContext.IsNull()) | |
8941 | { | |
8942 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8943 | return 1; | |
8944 | } | |
8945 | if(argc != 2) | |
8946 | { | |
8947 | di<<"Usage : " << argv[0] << " Size\n"; | |
8948 | return 1; | |
8949 | } | |
6b62b2da | 8950 | Standard_Real aSize = Draw::Atof (argv[1]); |
4754e164 | 8951 | if (aSize <= 0.) |
8952 | { | |
8953 | di<<"Bad Size value : " << aSize << "\n"; | |
8954 | return 1; | |
8955 | } | |
8956 | ||
8957 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8958 | aView->SetSize(aSize); | |
8959 | return 0; | |
8960 | } | |
8961 | ||
8962 | //======================================================================= | |
8963 | //function : VMoveView | |
8964 | //purpose : | |
8965 | //======================================================================= | |
8966 | static Standard_Integer VMoveView (Draw_Interpretor& di, | |
8967 | Standard_Integer argc, | |
8968 | const char ** argv) | |
8969 | { | |
8970 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8971 | if(aContext.IsNull()) | |
8972 | { | |
8973 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8974 | return 1; | |
8975 | } | |
8976 | if(argc < 4 || argc > 5) | |
8977 | { | |
8978 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
8979 | return 1; | |
8980 | } | |
6b62b2da | 8981 | Standard_Real Dx = Draw::Atof (argv[1]); |
8982 | Standard_Real Dy = Draw::Atof (argv[2]); | |
8983 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 8984 | Standard_Boolean aStart = Standard_True; |
8985 | if (argc == 5) | |
8986 | { | |
6b62b2da | 8987 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 8988 | } |
8989 | ||
8990 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8991 | aView->Move(Dx,Dy,Dz,aStart); | |
8992 | return 0; | |
8993 | } | |
8994 | ||
8995 | //======================================================================= | |
8996 | //function : VTranslateView | |
8997 | //purpose : | |
8998 | //======================================================================= | |
8999 | static Standard_Integer VTranslateView (Draw_Interpretor& di, | |
9000 | Standard_Integer argc, | |
9001 | const char ** argv) | |
9002 | { | |
9003 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
9004 | if(aContext.IsNull()) | |
9005 | { | |
9006 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
9007 | return 1; | |
9008 | } | |
9009 | if(argc < 4 || argc > 5) | |
9010 | { | |
9011 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
9012 | return 1; | |
9013 | } | |
6b62b2da | 9014 | Standard_Real Dx = Draw::Atof (argv[1]); |
9015 | Standard_Real Dy = Draw::Atof (argv[2]); | |
9016 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 9017 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 9018 | if (argc == 5) |
4754e164 | 9019 | { |
6b62b2da | 9020 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 9021 | } |
9022 | ||
9023 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9024 | aView->Translate(Dx,Dy,Dz,aStart); | |
9025 | return 0; | |
9026 | } | |
9027 | ||
9028 | //======================================================================= | |
9029 | //function : VTurnView | |
9030 | //purpose : | |
9031 | //======================================================================= | |
9032 | static Standard_Integer VTurnView (Draw_Interpretor& di, | |
9033 | Standard_Integer argc, | |
9034 | const char ** argv) | |
9035 | { | |
9036 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
9037 | if(aContext.IsNull()) { | |
9038 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
9039 | return 1; | |
9040 | } | |
9041 | if(argc < 4 || argc > 5){ | |
9042 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n"; | |
9043 | return 1; | |
9044 | } | |
6b62b2da | 9045 | Standard_Real Ax = Draw::Atof (argv[1]); |
9046 | Standard_Real Ay = Draw::Atof (argv[2]); | |
9047 | Standard_Real Az = Draw::Atof (argv[3]); | |
4754e164 | 9048 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 9049 | if (argc == 5) |
4754e164 | 9050 | { |
6b62b2da | 9051 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 9052 | } |
9053 | ||
9054 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9055 | aView->Turn(Ax,Ay,Az,aStart); | |
9056 | return 0; | |
9057 | } | |
9058 | ||
269294d6 | 9059 | //============================================================================== |
9060 | //function : VTextureEnv | |
9061 | //purpose : ENables or disables environment mapping | |
9062 | //============================================================================== | |
9063 | class OCC_TextureEnv : public Graphic3d_TextureEnv | |
9064 | { | |
9065 | public: | |
9066 | OCC_TextureEnv(const Standard_CString FileName); | |
9067 | OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName); | |
9068 | void SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
9069 | const Standard_Boolean theModulateFlag, | |
9070 | const Graphic3d_TypeOfTextureFilter theFilter, | |
9071 | const Standard_ShortReal theXScale, | |
9072 | const Standard_ShortReal theYScale, | |
9073 | const Standard_ShortReal theXShift, | |
9074 | const Standard_ShortReal theYShift, | |
9075 | const Standard_ShortReal theAngle); | |
68858c7d | 9076 | DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv) |
269294d6 | 9077 | }; |
a3f6f591 | 9078 | DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv) |
ec357c5c | 9079 | |
269294d6 | 9080 | OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName) |
9081 | : Graphic3d_TextureEnv(theFileName) | |
9082 | { | |
9083 | } | |
9084 | ||
9085 | OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId) | |
9086 | : Graphic3d_TextureEnv(theTexId) | |
9087 | { | |
9088 | } | |
9089 | ||
9090 | void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
9091 | const Standard_Boolean theModulateFlag, | |
9092 | const Graphic3d_TypeOfTextureFilter theFilter, | |
9093 | const Standard_ShortReal theXScale, | |
9094 | const Standard_ShortReal theYScale, | |
9095 | const Standard_ShortReal theXShift, | |
9096 | const Standard_ShortReal theYShift, | |
9097 | const Standard_ShortReal theAngle) | |
9098 | { | |
9099 | myParams->SetRepeat (theRepeatFlag); | |
9100 | myParams->SetModulate (theModulateFlag); | |
9101 | myParams->SetFilter (theFilter); | |
9102 | myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale)); | |
9103 | myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift)); | |
9104 | myParams->SetRotation (theAngle); | |
9105 | } | |
9106 | ||
35e08fe8 | 9107 | static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) |
269294d6 | 9108 | { |
9109 | // get the active view | |
9110 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9111 | if (aView.IsNull()) | |
9112 | { | |
9113 | std::cerr << "No active view. Please call vinit.\n"; | |
9114 | return 1; | |
9115 | } | |
9116 | ||
9117 | // Checking the input arguments | |
9118 | Standard_Boolean anEnableFlag = Standard_False; | |
9119 | Standard_Boolean isOk = theArgNb >= 2; | |
9120 | if (isOk) | |
9121 | { | |
9122 | TCollection_AsciiString anEnableOpt(theArgVec[1]); | |
9123 | anEnableFlag = anEnableOpt.IsEqual("on"); | |
9124 | isOk = anEnableFlag || anEnableOpt.IsEqual("off"); | |
9125 | } | |
9126 | if (anEnableFlag) | |
9127 | { | |
9128 | isOk = (theArgNb == 3 || theArgNb == 11); | |
9129 | if (isOk) | |
9130 | { | |
9131 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
9132 | isOk = (!aTextureOpt.IsIntegerValue() || | |
9133 | (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN)); | |
9134 | ||
9135 | if (isOk && theArgNb == 11) | |
9136 | { | |
9137 | TCollection_AsciiString aRepeatOpt (theArgVec[3]), | |
9138 | aModulateOpt(theArgVec[4]), | |
9139 | aFilterOpt (theArgVec[5]), | |
9140 | aSScaleOpt (theArgVec[6]), | |
9141 | aTScaleOpt (theArgVec[7]), | |
9142 | aSTransOpt (theArgVec[8]), | |
9143 | aTTransOpt (theArgVec[9]), | |
9144 | anAngleOpt (theArgVec[10]); | |
9145 | isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) && | |
9146 | (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) && | |
9147 | (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) && | |
9148 | aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() && | |
9149 | aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() && | |
9150 | anAngleOpt.IsRealValue()); | |
9151 | } | |
9152 | } | |
9153 | } | |
9154 | ||
9155 | if (!isOk) | |
9156 | { | |
9157 | std::cerr << "Usage :" << std::endl; | |
9158 | std::cerr << theArgVec[0] << " off" << std::endl; | |
9159 | std::cerr << theArgVec[0] << " on {index_of_std_texture(0..7)|texture_file_name} [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} scale_s scale_t translation_s translation_t rotation_degrees]" << std::endl; | |
9160 | return 1; | |
9161 | } | |
9162 | ||
9163 | if (anEnableFlag) | |
9164 | { | |
9165 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
9166 | Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ? | |
9167 | new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) : | |
9168 | new OCC_TextureEnv(theArgVec[2]); | |
9169 | ||
9170 | if (theArgNb == 11) | |
9171 | { | |
9172 | TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]); | |
9173 | aTexEnv->SetTextureParameters( | |
9174 | aRepeatOpt. IsEqual("repeat"), | |
9175 | aModulateOpt.IsEqual("modulate"), | |
9176 | aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST : | |
9177 | aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR : | |
9178 | Graphic3d_TOTF_TRILINEAR, | |
9179 | (Standard_ShortReal)Draw::Atof(theArgVec[6]), | |
9180 | (Standard_ShortReal)Draw::Atof(theArgVec[7]), | |
9181 | (Standard_ShortReal)Draw::Atof(theArgVec[8]), | |
9182 | (Standard_ShortReal)Draw::Atof(theArgVec[9]), | |
9183 | (Standard_ShortReal)Draw::Atof(theArgVec[10]) | |
9184 | ); | |
9185 | } | |
9186 | aView->SetTextureEnv(aTexEnv); | |
269294d6 | 9187 | } |
9188 | else // Disabling environment mapping | |
9189 | { | |
269294d6 | 9190 | Handle(Graphic3d_TextureEnv) aTexture; |
9191 | aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data | |
9192 | } | |
9193 | ||
9194 | aView->Redraw(); | |
9195 | return 0; | |
9196 | } | |
9197 | ||
3e05329c | 9198 | namespace |
9199 | { | |
9200 | typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes; | |
9201 | ||
9202 | //! Remove registered clipping plane from all views and objects. | |
9203 | static void removePlane (MapOfPlanes& theRegPlanes, | |
9204 | const TCollection_AsciiString& theName) | |
9205 | { | |
9206 | Handle(Graphic3d_ClipPlane) aClipPlane; | |
9207 | if (!theRegPlanes.Find (theName, aClipPlane)) | |
9208 | { | |
9209 | std::cout << "Warning: no such plane.\n"; | |
9210 | return; | |
9211 | } | |
9212 | ||
9213 | theRegPlanes.UnBind (theName); | |
9214 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS()); | |
9215 | anIObjIt.More(); anIObjIt.Next()) | |
9216 | { | |
8f521168 | 9217 | const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1(); |
3e05329c | 9218 | aPrs->RemoveClipPlane (aClipPlane); |
9219 | } | |
9220 | ||
9221 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
9222 | aViewIt.More(); aViewIt.Next()) | |
9223 | { | |
9224 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
9225 | aView->RemoveClipPlane(aClipPlane); | |
9226 | } | |
9227 | ||
9228 | ViewerTest::RedrawAllViews(); | |
9229 | } | |
9230 | } | |
9231 | ||
4269bd1b | 9232 | //=============================================================================================== |
9233 | //function : VClipPlane | |
9234 | //purpose : | |
9235 | //=============================================================================================== | |
9236 | static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
9237 | { | |
9238 | // use short-cut for created clip planes map of created (or "registered by name") clip planes | |
4269bd1b | 9239 | static MapOfPlanes aRegPlanes; |
9240 | ||
9241 | if (theArgsNb < 2) | |
9242 | { | |
3e05329c | 9243 | for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next()) |
9244 | { | |
9245 | theDi << aPlaneIter.Key() << " "; | |
9246 | } | |
9247 | return 0; | |
4269bd1b | 9248 | } |
9249 | ||
9250 | TCollection_AsciiString aCommand (theArgVec[1]); | |
3e05329c | 9251 | aCommand.LowerCase(); |
9252 | const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView(); | |
9253 | if (anActiveView.IsNull()) | |
9254 | { | |
9255 | std::cout << "Error: no active view.\n"; | |
9256 | return 1; | |
9257 | } | |
4269bd1b | 9258 | |
9259 | // print maximum number of planes for current viewer | |
3e05329c | 9260 | if (aCommand == "-maxplanes" |
9261 | || aCommand == "maxplanes") | |
4269bd1b | 9262 | { |
3e05329c | 9263 | theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit() |
9264 | << " plane slots provided by driver.\n"; | |
4269bd1b | 9265 | return 0; |
9266 | } | |
9267 | ||
9268 | // create / delete plane instance | |
3e05329c | 9269 | if (aCommand == "-create" |
9270 | || aCommand == "create" | |
9271 | || aCommand == "-delete" | |
9272 | || aCommand == "delete" | |
9273 | || aCommand == "-clone" | |
9274 | || aCommand == "clone") | |
4269bd1b | 9275 | { |
9276 | if (theArgsNb < 3) | |
9277 | { | |
3e05329c | 9278 | std::cout << "Syntax error: plane name is required.\n"; |
4269bd1b | 9279 | return 1; |
9280 | } | |
9281 | ||
3e05329c | 9282 | Standard_Boolean toCreate = aCommand == "-create" |
9283 | || aCommand == "create"; | |
9284 | Standard_Boolean toClone = aCommand == "-clone" | |
9285 | || aCommand == "clone"; | |
9286 | Standard_Boolean toDelete = aCommand == "-delete" | |
9287 | || aCommand == "delete"; | |
4269bd1b | 9288 | TCollection_AsciiString aPlane (theArgVec[2]); |
9289 | ||
9290 | if (toCreate) | |
9291 | { | |
9292 | if (aRegPlanes.IsBound (aPlane)) | |
9293 | { | |
3e05329c | 9294 | std::cout << "Warning: existing plane has been overridden.\n"; |
9295 | toDelete = true; | |
9296 | } | |
9297 | else | |
9298 | { | |
9299 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
9300 | return 0; | |
4269bd1b | 9301 | } |
4269bd1b | 9302 | } |
9303 | else if (toClone) // toClone | |
9304 | { | |
9305 | if (!aRegPlanes.IsBound (aPlane)) | |
9306 | { | |
3e05329c | 9307 | std::cout << "Error: no such plane.\n"; |
4269bd1b | 9308 | return 1; |
9309 | } | |
3e05329c | 9310 | else if (theArgsNb < 4) |
4269bd1b | 9311 | { |
3e05329c | 9312 | std::cout << "Syntax error: enter name for new plane.\n"; |
4269bd1b | 9313 | return 1; |
9314 | } | |
9315 | ||
9316 | TCollection_AsciiString aClone (theArgVec[3]); | |
9317 | if (aRegPlanes.IsBound (aClone)) | |
9318 | { | |
3e05329c | 9319 | std::cout << "Error: plane name is in use.\n"; |
4269bd1b | 9320 | return 1; |
9321 | } | |
9322 | ||
9323 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
9324 | ||
9325 | aRegPlanes.Bind (aClone, aClipPlane->Clone()); | |
3e05329c | 9326 | return 0; |
4269bd1b | 9327 | } |
4269bd1b | 9328 | |
3e05329c | 9329 | if (toDelete) |
9330 | { | |
9331 | if (aPlane == "ALL" | |
9332 | || aPlane == "all" | |
9333 | || aPlane == "*") | |
4269bd1b | 9334 | { |
3e05329c | 9335 | for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();) |
9336 | { | |
9337 | aPlane = aPlaneIter.Key(); | |
9338 | removePlane (aRegPlanes, aPlane); | |
9339 | aPlaneIter = MapOfPlanes::Iterator (aRegPlanes); | |
9340 | } | |
4269bd1b | 9341 | } |
3e05329c | 9342 | else |
4269bd1b | 9343 | { |
3e05329c | 9344 | removePlane (aRegPlanes, aPlane); |
4269bd1b | 9345 | } |
4269bd1b | 9346 | } |
9347 | ||
3e05329c | 9348 | if (toCreate) |
9349 | { | |
9350 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
9351 | } | |
4269bd1b | 9352 | return 0; |
9353 | } | |
9354 | ||
9355 | // set / unset plane command | |
3e05329c | 9356 | if (aCommand == "set" |
9357 | || aCommand == "unset") | |
4269bd1b | 9358 | { |
3e05329c | 9359 | if (theArgsNb < 5) |
4269bd1b | 9360 | { |
3e05329c | 9361 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 9362 | return 1; |
9363 | } | |
9364 | ||
3e05329c | 9365 | // redirect to new syntax |
9366 | NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1); | |
9367 | anArgVec.SetValue (1, theArgVec[0]); | |
9368 | anArgVec.SetValue (2, theArgVec[2]); | |
9369 | anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset"); | |
9370 | for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt) | |
4269bd1b | 9371 | { |
3e05329c | 9372 | anArgVec.SetValue (anIt, theArgVec[anIt]); |
4269bd1b | 9373 | } |
9374 | ||
3e05329c | 9375 | return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst()); |
4269bd1b | 9376 | } |
9377 | ||
9378 | // change plane command | |
3e05329c | 9379 | TCollection_AsciiString aPlaneName; |
9380 | Handle(Graphic3d_ClipPlane) aClipPlane; | |
9381 | Standard_Integer anArgIter = 0; | |
9382 | if (aCommand == "-change" | |
9383 | || aCommand == "change") | |
4269bd1b | 9384 | { |
3e05329c | 9385 | // old syntax support |
9386 | if (theArgsNb < 3) | |
4269bd1b | 9387 | { |
3e05329c | 9388 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 9389 | return 1; |
9390 | } | |
9391 | ||
3e05329c | 9392 | anArgIter = 3; |
9393 | aPlaneName = theArgVec[2]; | |
9394 | if (!aRegPlanes.Find (aPlaneName, aClipPlane)) | |
4269bd1b | 9395 | { |
3e05329c | 9396 | std::cout << "Error: no such plane '" << aPlaneName << "'.\n"; |
4269bd1b | 9397 | return 1; |
9398 | } | |
3e05329c | 9399 | } |
9400 | else if (aRegPlanes.Find (theArgVec[1], aClipPlane)) | |
9401 | { | |
9402 | anArgIter = 2; | |
9403 | aPlaneName = theArgVec[1]; | |
9404 | } | |
9405 | else | |
9406 | { | |
9407 | anArgIter = 2; | |
9408 | aPlaneName = theArgVec[1]; | |
9409 | aClipPlane = new Graphic3d_ClipPlane(); | |
9410 | aRegPlanes.Bind (aPlaneName, aClipPlane); | |
9411 | theDi << "Created new plane " << aPlaneName << ".\n"; | |
9412 | } | |
4269bd1b | 9413 | |
3e05329c | 9414 | if (theArgsNb - anArgIter < 1) |
9415 | { | |
9416 | std::cout << "Syntax error: need more arguments.\n"; | |
9417 | return 1; | |
9418 | } | |
4269bd1b | 9419 | |
3e05329c | 9420 | for (; anArgIter < theArgsNb; ++anArgIter) |
9421 | { | |
9422 | const char** aChangeArgs = theArgVec + anArgIter; | |
9423 | Standard_Integer aNbChangeArgs = theArgsNb - anArgIter; | |
9424 | TCollection_AsciiString aChangeArg (aChangeArgs[0]); | |
9425 | aChangeArg.LowerCase(); | |
4269bd1b | 9426 | |
3e05329c | 9427 | Standard_Boolean toEnable = Standard_True; |
9428 | if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable)) | |
4269bd1b | 9429 | { |
3e05329c | 9430 | aClipPlane->SetOn (toEnable); |
4269bd1b | 9431 | } |
25c35042 | 9432 | else if (aChangeArg.StartsWith ("-equation") |
9433 | || aChangeArg.StartsWith ("equation")) | |
4269bd1b | 9434 | { |
3e05329c | 9435 | if (aNbChangeArgs < 5) |
4269bd1b | 9436 | { |
3e05329c | 9437 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 9438 | return 1; |
9439 | } | |
9440 | ||
25c35042 | 9441 | Standard_Integer aSubIndex = 1; |
9442 | Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0); | |
9443 | if (aPrefixLen < aChangeArg.Length()) | |
9444 | { | |
9445 | TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length()); | |
9446 | if (!aSubStr.IsIntegerValue() | |
9447 | || aSubStr.IntegerValue() <= 0) | |
9448 | { | |
9449 | std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n"; | |
9450 | return 1; | |
9451 | } | |
9452 | aSubIndex = aSubStr.IntegerValue(); | |
9453 | } | |
9454 | ||
9455 | Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]); | |
9456 | Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]); | |
9457 | Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]); | |
9458 | Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]); | |
9459 | Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane; | |
9460 | for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter) | |
9461 | { | |
9462 | if (aSubPln->ChainNextPlane().IsNull()) | |
9463 | { | |
9464 | aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln)); | |
9465 | } | |
9466 | aSubPln = aSubPln->ChainNextPlane(); | |
9467 | } | |
9468 | aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)()); | |
9469 | aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD)); | |
3e05329c | 9470 | anArgIter += 4; |
4269bd1b | 9471 | } |
25c35042 | 9472 | else if ((aChangeArg == "-boxinterior" |
9473 | || aChangeArg == "-boxint" | |
9474 | || aChangeArg == "-box") | |
9475 | && aNbChangeArgs >= 7) | |
9476 | { | |
9477 | Graphic3d_BndBox3d aBndBox; | |
9478 | aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3]))); | |
9479 | aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6]))); | |
9480 | anArgIter += 6; | |
9481 | ||
9482 | Standard_Integer aNbSubPlanes = 6; | |
9483 | const Graphic3d_Vec3d aDirArray[6] = | |
9484 | { | |
9485 | Graphic3d_Vec3d (-1, 0, 0), | |
9486 | Graphic3d_Vec3d ( 1, 0, 0), | |
9487 | Graphic3d_Vec3d ( 0,-1, 0), | |
9488 | Graphic3d_Vec3d ( 0, 1, 0), | |
9489 | Graphic3d_Vec3d ( 0, 0,-1), | |
9490 | Graphic3d_Vec3d ( 0, 0, 1), | |
9491 | }; | |
9492 | Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane; | |
9493 | for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter) | |
9494 | { | |
9495 | const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter]; | |
9496 | const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin()); | |
9497 | aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW)); | |
9498 | if (aSubPlaneIter + 1 == aNbSubPlanes) | |
9499 | { | |
9500 | aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)()); | |
9501 | } | |
9502 | else | |
9503 | { | |
9504 | aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln)); | |
9505 | } | |
9506 | aSubPln = aSubPln->ChainNextPlane(); | |
9507 | } | |
9508 | } | |
3e05329c | 9509 | else if (aChangeArg == "-capping" |
9510 | || aChangeArg == "capping") | |
4269bd1b | 9511 | { |
3e05329c | 9512 | if (aNbChangeArgs < 2) |
4269bd1b | 9513 | { |
3e05329c | 9514 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 9515 | return 1; |
9516 | } | |
9517 | ||
3e05329c | 9518 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
4269bd1b | 9519 | { |
3e05329c | 9520 | aClipPlane->SetCapping (toEnable); |
9521 | anArgIter += 1; | |
9522 | } | |
9523 | else | |
9524 | { | |
9525 | // just skip otherwise (old syntax) | |
9526 | } | |
9527 | } | |
9528 | else if (aChangeArg == "-useobjectmaterial" | |
9529 | || aChangeArg == "-useobjectmat" | |
9530 | || aChangeArg == "-useobjmat" | |
9531 | || aChangeArg == "-useobjmaterial") | |
9532 | { | |
9533 | if (aNbChangeArgs < 2) | |
9534 | { | |
9535 | std::cout << "Syntax error: need more arguments.\n"; | |
4269bd1b | 9536 | return 1; |
9537 | } | |
9538 | ||
3e05329c | 9539 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
4269bd1b | 9540 | { |
3e05329c | 9541 | aClipPlane->SetUseObjectMaterial (toEnable == Standard_True); |
9542 | anArgIter += 1; | |
4269bd1b | 9543 | } |
3e05329c | 9544 | } |
9545 | else if (aChangeArg == "-useobjecttexture" | |
9546 | || aChangeArg == "-useobjecttex" | |
9547 | || aChangeArg == "-useobjtexture" | |
9548 | || aChangeArg == "-useobjtex") | |
9549 | { | |
9550 | if (aNbChangeArgs < 2) | |
4269bd1b | 9551 | { |
3e05329c | 9552 | std::cout << "Syntax error: need more arguments.\n"; |
9553 | return 1; | |
9554 | } | |
4269bd1b | 9555 | |
3e05329c | 9556 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
9557 | { | |
9558 | aClipPlane->SetUseObjectTexture (toEnable == Standard_True); | |
9559 | anArgIter += 1; | |
9560 | } | |
9561 | } | |
9562 | else if (aChangeArg == "-useobjectshader" | |
9563 | || aChangeArg == "-useobjshader") | |
9564 | { | |
9565 | if (aNbChangeArgs < 2) | |
9566 | { | |
9567 | std::cout << "Syntax error: need more arguments.\n"; | |
9568 | return 1; | |
9569 | } | |
4269bd1b | 9570 | |
3e05329c | 9571 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
9572 | { | |
9573 | aClipPlane->SetUseObjectShader (toEnable == Standard_True); | |
9574 | anArgIter += 1; | |
4269bd1b | 9575 | } |
3e05329c | 9576 | } |
9577 | else if (aChangeArg == "-color" | |
9578 | || aChangeArg == "color") | |
9579 | { | |
9580 | Quantity_Color aColor; | |
9581 | Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1, | |
9582 | aChangeArgs + 1, | |
9583 | aColor); | |
9584 | if (aNbParsed == 0) | |
4269bd1b | 9585 | { |
3e05329c | 9586 | std::cout << "Syntax error: need more arguments.\n"; |
9587 | return 1; | |
9588 | } | |
61168418 | 9589 | aClipPlane->SetCappingColor (aColor); |
3e05329c | 9590 | anArgIter += aNbParsed; |
9591 | } | |
61168418 | 9592 | else if (aNbChangeArgs >= 1 |
9593 | && (aChangeArg == "-material" | |
9594 | || aChangeArg == "material")) | |
9595 | { | |
9596 | ++anArgIter; | |
9597 | Graphic3d_NameOfMaterial aMatName; | |
9598 | if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeArgs[1], aMatName)) | |
9599 | { | |
9600 | std::cout << "Syntax error: unknown material '" << aChangeArgs[1] << "'.\n"; | |
9601 | return 1; | |
9602 | } | |
9603 | aClipPlane->SetCappingMaterial (aMatName); | |
9604 | } | |
1b661a81 | 9605 | else if ((aChangeArg == "-transparency" |
9606 | || aChangeArg == "-transp") | |
9607 | && aNbChangeArgs >= 2) | |
9608 | { | |
9609 | TCollection_AsciiString aValStr (aChangeArgs[1]); | |
9610 | Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect(); | |
9611 | if (aValStr.IsRealValue()) | |
9612 | { | |
9613 | Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); | |
9614 | aMat.SetTransparency ((float )aValStr.RealValue()); | |
9615 | anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto); | |
9616 | aClipPlane->SetCappingMaterial (aMat); | |
9617 | } | |
9618 | else | |
9619 | { | |
9620 | aValStr.LowerCase(); | |
9621 | Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto; | |
9622 | if (aValStr == "opaque") | |
9623 | { | |
9624 | aMode = Graphic3d_AlphaMode_Opaque; | |
9625 | } | |
9626 | else if (aValStr == "mask") | |
9627 | { | |
9628 | aMode = Graphic3d_AlphaMode_Mask; | |
9629 | } | |
9630 | else if (aValStr == "blend") | |
9631 | { | |
9632 | aMode = Graphic3d_AlphaMode_Blend; | |
9633 | } | |
9634 | else if (aValStr == "blendauto") | |
9635 | { | |
9636 | aMode = Graphic3d_AlphaMode_BlendAuto; | |
9637 | } | |
9638 | else | |
9639 | { | |
9640 | std::cout << "Syntax error at '" << aValStr << "'\n"; | |
9641 | return 1; | |
9642 | } | |
9643 | anAspect->SetAlphaMode (aMode); | |
9644 | aClipPlane->SetCappingAspect (anAspect); | |
9645 | } | |
9646 | anArgIter += 1; | |
9647 | } | |
3e05329c | 9648 | else if (aChangeArg == "-texname" |
9649 | || aChangeArg == "texname") | |
9650 | { | |
9651 | if (aNbChangeArgs < 2) | |
9652 | { | |
9653 | std::cout << "Syntax error: need more arguments.\n"; | |
9654 | return 1; | |
9655 | } | |
4269bd1b | 9656 | |
3e05329c | 9657 | TCollection_AsciiString aTextureName (aChangeArgs[1]); |
9658 | Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); | |
9659 | if (!aTexture->IsDone()) | |
9660 | { | |
9661 | aClipPlane->SetCappingTexture (NULL); | |
4269bd1b | 9662 | } |
3e05329c | 9663 | else |
4269bd1b | 9664 | { |
3e05329c | 9665 | aTexture->EnableModulate(); |
9666 | aTexture->EnableRepeat(); | |
9667 | aClipPlane->SetCappingTexture (aTexture); | |
9668 | } | |
9669 | anArgIter += 1; | |
9670 | } | |
9671 | else if (aChangeArg == "-texscale" | |
9672 | || aChangeArg == "texscale") | |
9673 | { | |
9674 | if (aClipPlane->CappingTexture().IsNull()) | |
9675 | { | |
9676 | std::cout << "Error: no texture is set.\n"; | |
9677 | return 1; | |
9678 | } | |
4269bd1b | 9679 | |
3e05329c | 9680 | if (aNbChangeArgs < 3) |
9681 | { | |
9682 | std::cout << "Syntax error: need more arguments.\n"; | |
9683 | return 1; | |
9684 | } | |
4269bd1b | 9685 | |
3e05329c | 9686 | Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); |
9687 | Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); | |
9688 | aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); | |
9689 | anArgIter += 2; | |
9690 | } | |
9691 | else if (aChangeArg == "-texorigin" | |
9692 | || aChangeArg == "texorigin") // texture origin | |
9693 | { | |
9694 | if (aClipPlane->CappingTexture().IsNull()) | |
9695 | { | |
9696 | std::cout << "Error: no texture is set.\n"; | |
9697 | return 1; | |
9698 | } | |
4269bd1b | 9699 | |
3e05329c | 9700 | if (aNbChangeArgs < 3) |
9701 | { | |
9702 | std::cout << "Syntax error: need more arguments.\n"; | |
9703 | return 1; | |
4269bd1b | 9704 | } |
3e05329c | 9705 | |
9706 | Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); | |
9707 | Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); | |
9708 | ||
9709 | aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); | |
9710 | anArgIter += 2; | |
9711 | } | |
9712 | else if (aChangeArg == "-texrotate" | |
9713 | || aChangeArg == "texrotate") // texture rotation | |
9714 | { | |
9715 | if (aClipPlane->CappingTexture().IsNull()) | |
4269bd1b | 9716 | { |
3e05329c | 9717 | std::cout << "Error: no texture is set.\n"; |
9718 | return 1; | |
9719 | } | |
4269bd1b | 9720 | |
3e05329c | 9721 | if (aNbChangeArgs < 2) |
9722 | { | |
9723 | std::cout << "Syntax error: need more arguments.\n"; | |
9724 | return 1; | |
9725 | } | |
4269bd1b | 9726 | |
3e05329c | 9727 | Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); |
9728 | aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot); | |
9729 | anArgIter += 1; | |
9730 | } | |
9731 | else if (aChangeArg == "-hatch" | |
9732 | || aChangeArg == "hatch") | |
9733 | { | |
9734 | if (aNbChangeArgs < 2) | |
9735 | { | |
9736 | std::cout << "Syntax error: need more arguments.\n"; | |
9737 | return 1; | |
9738 | } | |
4269bd1b | 9739 | |
3e05329c | 9740 | TCollection_AsciiString aHatchStr (aChangeArgs[1]); |
9741 | aHatchStr.LowerCase(); | |
9742 | if (aHatchStr == "on") | |
9743 | { | |
9744 | aClipPlane->SetCappingHatchOn(); | |
9745 | } | |
9746 | else if (aHatchStr == "off") | |
9747 | { | |
9748 | aClipPlane->SetCappingHatchOff(); | |
4269bd1b | 9749 | } |
3e05329c | 9750 | else |
4269bd1b | 9751 | { |
3e05329c | 9752 | aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1])); |
9753 | } | |
9754 | anArgIter += 1; | |
9755 | } | |
9756 | else if (aChangeArg == "-delete" | |
9757 | || aChangeArg == "delete") | |
9758 | { | |
9759 | removePlane (aRegPlanes, aPlaneName); | |
9760 | return 0; | |
9761 | } | |
9762 | else if (aChangeArg == "-set" | |
32ca7711 | 9763 | || aChangeArg == "-unset" |
9764 | || aChangeArg == "-setoverrideglobal") | |
3e05329c | 9765 | { |
9766 | // set / unset plane command | |
32ca7711 | 9767 | const Standard_Boolean toSet = aChangeArg.StartsWith ("-set"); |
9768 | const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal"; | |
3e05329c | 9769 | Standard_Integer anIt = 1; |
9770 | for (; anIt < aNbChangeArgs; ++anIt) | |
9771 | { | |
9772 | TCollection_AsciiString anEntityName (aChangeArgs[anIt]); | |
9773 | if (anEntityName.IsEmpty() | |
9774 | || anEntityName.Value (1) == '-') | |
4269bd1b | 9775 | { |
3e05329c | 9776 | break; |
4269bd1b | 9777 | } |
32ca7711 | 9778 | else if (!toOverrideGlobal |
9779 | && ViewerTest_myViews.IsBound1 (anEntityName)) | |
4269bd1b | 9780 | { |
3e05329c | 9781 | Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName); |
9782 | if (toSet) | |
9783 | { | |
9784 | aView->AddClipPlane (aClipPlane); | |
9785 | } | |
9786 | else | |
9787 | { | |
9788 | aView->RemoveClipPlane (aClipPlane); | |
9789 | } | |
9790 | continue; | |
4269bd1b | 9791 | } |
3e05329c | 9792 | else if (GetMapOfAIS().IsBound2 (anEntityName)) |
4269bd1b | 9793 | { |
8f521168 | 9794 | Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName); |
3e05329c | 9795 | if (toSet) |
9796 | { | |
9797 | aIObj->AddClipPlane (aClipPlane); | |
9798 | } | |
9799 | else | |
9800 | { | |
9801 | aIObj->RemoveClipPlane (aClipPlane); | |
9802 | } | |
32ca7711 | 9803 | if (!aIObj->ClipPlanes().IsNull()) |
9804 | { | |
9805 | aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal); | |
9806 | } | |
4269bd1b | 9807 | } |
3e05329c | 9808 | else |
4269bd1b | 9809 | { |
3e05329c | 9810 | std::cout << "Error: object/view '" << anEntityName << "' is not found!\n"; |
9811 | return 1; | |
4269bd1b | 9812 | } |
3e05329c | 9813 | } |
9814 | ||
9815 | if (anIt == 1) | |
9816 | { | |
9817 | // apply to active view | |
9818 | if (toSet) | |
4269bd1b | 9819 | { |
3e05329c | 9820 | anActiveView->AddClipPlane (aClipPlane); |
4269bd1b | 9821 | } |
9822 | else | |
9823 | { | |
3e05329c | 9824 | anActiveView->RemoveClipPlane (aClipPlane); |
4269bd1b | 9825 | } |
9826 | } | |
3e05329c | 9827 | else |
9828 | { | |
9829 | anArgIter = anArgIter + anIt - 1; | |
9830 | } | |
9831 | } | |
9832 | else | |
9833 | { | |
9834 | std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n"; | |
9835 | return 1; | |
4269bd1b | 9836 | } |
4269bd1b | 9837 | } |
9838 | ||
3e05329c | 9839 | ViewerTest::RedrawAllViews(); |
9840 | return 0; | |
4269bd1b | 9841 | } |
9842 | ||
b5ac8292 | 9843 | //=============================================================================================== |
9844 | //function : VZRange | |
9845 | //purpose : | |
9846 | //=============================================================================================== | |
9847 | static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
9848 | { | |
197ac94e | 9849 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
9850 | ||
9851 | if (aCurrentView.IsNull()) | |
b5ac8292 | 9852 | { |
197ac94e | 9853 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 9854 | return 1; |
9855 | } | |
9856 | ||
197ac94e | 9857 | Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera(); |
b5ac8292 | 9858 | |
9859 | if (theArgsNb < 2) | |
9860 | { | |
9861 | theDi << "ZNear: " << aCamera->ZNear() << "\n"; | |
9862 | theDi << "ZFar: " << aCamera->ZFar() << "\n"; | |
9863 | return 0; | |
9864 | } | |
9865 | ||
9866 | if (theArgsNb == 3) | |
9867 | { | |
6b62b2da | 9868 | Standard_Real aNewZNear = Draw::Atof (theArgVec[1]); |
9869 | Standard_Real aNewZFar = Draw::Atof (theArgVec[2]); | |
197ac94e | 9870 | |
9871 | if (aNewZNear >= aNewZFar) | |
9872 | { | |
9873 | std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n"; | |
9874 | return 1; | |
9875 | } | |
9876 | ||
9877 | if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0)) | |
9878 | { | |
9879 | std::cout << theArgVec[0] << ": invalid arguments: "; | |
9880 | std::cout << "znear, zfar should be positive for perspective camera.\n"; | |
9881 | return 1; | |
9882 | } | |
9883 | ||
9884 | aCamera->SetZRange (aNewZNear, aNewZFar); | |
b5ac8292 | 9885 | } |
9886 | else | |
9887 | { | |
197ac94e | 9888 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
b5ac8292 | 9889 | return 1; |
9890 | } | |
9891 | ||
197ac94e | 9892 | aCurrentView->Redraw(); |
9893 | ||
b5ac8292 | 9894 | return 0; |
9895 | } | |
9896 | ||
9897 | //=============================================================================================== | |
9898 | //function : VAutoZFit | |
9899 | //purpose : | |
9900 | //=============================================================================================== | |
9901 | static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
9902 | { | |
197ac94e | 9903 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
9904 | ||
9905 | if (aCurrentView.IsNull()) | |
b5ac8292 | 9906 | { |
197ac94e | 9907 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 9908 | return 1; |
9909 | } | |
9910 | ||
c357e426 | 9911 | Standard_Real aScale = aCurrentView->AutoZFitScaleFactor(); |
197ac94e | 9912 | |
9913 | if (theArgsNb > 3) | |
b5ac8292 | 9914 | { |
197ac94e | 9915 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
9916 | return 1; | |
b5ac8292 | 9917 | } |
9918 | ||
197ac94e | 9919 | if (theArgsNb < 2) |
b5ac8292 | 9920 | { |
586db386 | 9921 | theDi << "Auto z-fit mode: \n" |
c357e426 | 9922 | << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n" |
197ac94e | 9923 | << "Scale: " << aScale << "\n"; |
9924 | return 0; | |
b5ac8292 | 9925 | } |
197ac94e | 9926 | |
9927 | Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1; | |
9928 | ||
9929 | if (theArgsNb >= 3) | |
b5ac8292 | 9930 | { |
197ac94e | 9931 | aScale = Draw::Atoi (theArgVec[2]); |
b5ac8292 | 9932 | } |
9933 | ||
c357e426 | 9934 | aCurrentView->SetAutoZFitMode (isOn, aScale); |
9935 | aCurrentView->AutoZFit(); | |
197ac94e | 9936 | aCurrentView->Redraw(); |
9937 | ||
b5ac8292 | 9938 | return 0; |
9939 | } | |
9940 | ||
6b62b2da | 9941 | //! Auxiliary function to print projection type |
9942 | inline const char* projTypeName (Graphic3d_Camera::Projection theProjType) | |
9943 | { | |
9944 | switch (theProjType) | |
9945 | { | |
9946 | case Graphic3d_Camera::Projection_Orthographic: return "orthographic"; | |
9947 | case Graphic3d_Camera::Projection_Perspective: return "perspective"; | |
9948 | case Graphic3d_Camera::Projection_Stereo: return "stereoscopic"; | |
9949 | case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye"; | |
9950 | case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye"; | |
9951 | } | |
9952 | return "UNKNOWN"; | |
9953 | } | |
9954 | ||
b5ac8292 | 9955 | //=============================================================================================== |
6b62b2da | 9956 | //function : VCamera |
b5ac8292 | 9957 | //purpose : |
9958 | //=============================================================================================== | |
6b62b2da | 9959 | static int VCamera (Draw_Interpretor& theDI, |
9960 | Standard_Integer theArgsNb, | |
9961 | const char** theArgVec) | |
b5ac8292 | 9962 | { |
6b62b2da | 9963 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
9964 | if (aView.IsNull()) | |
b5ac8292 | 9965 | { |
6b62b2da | 9966 | std::cout << "Error: no active view.\n"; |
b5ac8292 | 9967 | return 1; |
9968 | } | |
9969 | ||
6b62b2da | 9970 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); |
9971 | if (theArgsNb < 2) | |
b5ac8292 | 9972 | { |
6b62b2da | 9973 | theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n"; |
9974 | theDI << "FOVy: " << aCamera->FOVy() << "\n"; | |
9975 | theDI << "Distance: " << aCamera->Distance() << "\n"; | |
9976 | theDI << "IOD: " << aCamera->IOD() << "\n"; | |
9977 | theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n"; | |
9978 | theDI << "ZFocus: " << aCamera->ZFocus() << "\n"; | |
9979 | theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n"; | |
9980 | return 0; | |
b5ac8292 | 9981 | } |
9982 | ||
30a1b24e | 9983 | TCollection_AsciiString aPrsName; |
6b62b2da | 9984 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
b5ac8292 | 9985 | { |
6b62b2da | 9986 | Standard_CString anArg = theArgVec[anArgIter]; |
9987 | TCollection_AsciiString anArgCase (anArg); | |
9988 | anArgCase.LowerCase(); | |
9989 | if (anArgCase == "-proj" | |
9990 | || anArgCase == "-projection" | |
9991 | || anArgCase == "-projtype" | |
9992 | || anArgCase == "-projectiontype") | |
9993 | { | |
9994 | theDI << projTypeName (aCamera->ProjectionType()) << " "; | |
9995 | } | |
9996 | else if (anArgCase == "-ortho" | |
9997 | || anArgCase == "-orthographic") | |
b5ac8292 | 9998 | { |
9999 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic); | |
6b62b2da | 10000 | } |
10001 | else if (anArgCase == "-persp" | |
10002 | || anArgCase == "-perspective" | |
10003 | || anArgCase == "-perspmono" | |
10004 | || anArgCase == "-perspectivemono" | |
10005 | || anArgCase == "-mono") | |
b5ac8292 | 10006 | { |
10007 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
10008 | } | |
6b62b2da | 10009 | else if (anArgCase == "-stereo" |
10010 | || anArgCase == "-stereoscopic" | |
10011 | || anArgCase == "-perspstereo" | |
10012 | || anArgCase == "-perspectivestereo") | |
10013 | { | |
10014 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
10015 | } | |
10016 | else if (anArgCase == "-left" | |
10017 | || anArgCase == "-lefteye" | |
10018 | || anArgCase == "-monoleft" | |
10019 | || anArgCase == "-monolefteye" | |
10020 | || anArgCase == "-perpsleft" | |
10021 | || anArgCase == "-perpslefteye") | |
b5ac8292 | 10022 | { |
10023 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); | |
10024 | } | |
6b62b2da | 10025 | else if (anArgCase == "-right" |
10026 | || anArgCase == "-righteye" | |
10027 | || anArgCase == "-monoright" | |
10028 | || anArgCase == "-monorighteye" | |
10029 | || anArgCase == "-perpsright") | |
b5ac8292 | 10030 | { |
10031 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); | |
10032 | } | |
6b62b2da | 10033 | else if (anArgCase == "-dist" |
10034 | || anArgCase == "-distance") | |
b5ac8292 | 10035 | { |
6b62b2da | 10036 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
10037 | if (anArgValue != NULL | |
10038 | && *anArgValue != '-') | |
10039 | { | |
10040 | ++anArgIter; | |
10041 | aCamera->SetDistance (Draw::Atof (anArgValue)); | |
10042 | continue; | |
10043 | } | |
10044 | theDI << aCamera->Distance() << " "; | |
b5ac8292 | 10045 | } |
6b62b2da | 10046 | else if (anArgCase == "-iod") |
b5ac8292 | 10047 | { |
6b62b2da | 10048 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
10049 | if (anArgValue != NULL | |
10050 | && *anArgValue != '-') | |
10051 | { | |
10052 | ++anArgIter; | |
10053 | aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue)); | |
10054 | continue; | |
10055 | } | |
10056 | theDI << aCamera->IOD() << " "; | |
b5ac8292 | 10057 | } |
6b62b2da | 10058 | else if (anArgCase == "-iodtype") |
b5ac8292 | 10059 | { |
6b62b2da | 10060 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
10061 | TCollection_AsciiString anValueCase (anArgValue); | |
10062 | anValueCase.LowerCase(); | |
10063 | if (anValueCase == "abs" | |
10064 | || anValueCase == "absolute") | |
10065 | { | |
10066 | ++anArgIter; | |
10067 | aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD()); | |
10068 | continue; | |
10069 | } | |
10070 | else if (anValueCase == "rel" | |
10071 | || anValueCase == "relative") | |
10072 | { | |
10073 | ++anArgIter; | |
10074 | aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD()); | |
10075 | continue; | |
10076 | } | |
10077 | else if (*anArgValue != '-') | |
10078 | { | |
10079 | std::cout << "Error: unknown IOD type '" << anArgValue << "'\n"; | |
10080 | return 1; | |
10081 | } | |
10082 | switch (aCamera->GetIODType()) | |
10083 | { | |
10084 | case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break; | |
10085 | case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break; | |
10086 | } | |
b5ac8292 | 10087 | } |
6b62b2da | 10088 | else if (anArgCase == "-zfocus") |
b5ac8292 | 10089 | { |
6b62b2da | 10090 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
10091 | if (anArgValue != NULL | |
10092 | && *anArgValue != '-') | |
10093 | { | |
10094 | ++anArgIter; | |
10095 | aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue)); | |
10096 | continue; | |
10097 | } | |
10098 | theDI << aCamera->ZFocus() << " "; | |
b5ac8292 | 10099 | } |
6b62b2da | 10100 | else if (anArgCase == "-zfocustype") |
b5ac8292 | 10101 | { |
6b62b2da | 10102 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
10103 | TCollection_AsciiString anValueCase (anArgValue); | |
10104 | anValueCase.LowerCase(); | |
10105 | if (anValueCase == "abs" | |
10106 | || anValueCase == "absolute") | |
10107 | { | |
10108 | ++anArgIter; | |
10109 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus()); | |
10110 | continue; | |
10111 | } | |
10112 | else if (anValueCase == "rel" | |
10113 | || anValueCase == "relative") | |
10114 | { | |
10115 | ++anArgIter; | |
10116 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus()); | |
10117 | continue; | |
10118 | } | |
10119 | else if (*anArgValue != '-') | |
10120 | { | |
10121 | std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n"; | |
10122 | return 1; | |
10123 | } | |
10124 | switch (aCamera->ZFocusType()) | |
10125 | { | |
10126 | case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break; | |
10127 | case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break; | |
10128 | } | |
10129 | } | |
10130 | else if (anArgCase == "-fov" | |
10131 | || anArgCase == "-fovy") | |
b5ac8292 | 10132 | { |
6b62b2da | 10133 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
10134 | if (anArgValue != NULL | |
10135 | && *anArgValue != '-') | |
10136 | { | |
10137 | ++anArgIter; | |
10138 | aCamera->SetFOVy (Draw::Atof (anArgValue)); | |
10139 | continue; | |
10140 | } | |
10141 | theDI << aCamera->FOVy() << " "; | |
b5ac8292 | 10142 | } |
30a1b24e | 10143 | else if (aPrsName.IsEmpty() |
10144 | && !anArgCase.StartsWith ("-")) | |
10145 | { | |
10146 | aPrsName = anArg; | |
10147 | } | |
b5ac8292 | 10148 | else |
10149 | { | |
6b62b2da | 10150 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
b5ac8292 | 10151 | return 1; |
10152 | } | |
10153 | } | |
b5ac8292 | 10154 | |
30a1b24e | 10155 | if (aPrsName.IsEmpty() |
10156 | || theArgsNb > 2) | |
10157 | { | |
10158 | aView->AutoZFit(); | |
10159 | aView->Redraw(); | |
10160 | } | |
10161 | ||
10162 | if (!aPrsName.IsEmpty()) | |
10163 | { | |
10164 | Handle(AIS_CameraFrustum) aCameraFrustum; | |
10165 | if (GetMapOfAIS().IsBound2 (aPrsName)) | |
10166 | { | |
10167 | // find existing object | |
10168 | aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1])); | |
10169 | if (aCameraFrustum.IsNull()) | |
10170 | { | |
10171 | std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n"; | |
10172 | return 1; | |
10173 | } | |
10174 | } | |
10175 | ||
10176 | if (aCameraFrustum.IsNull()) | |
10177 | { | |
10178 | aCameraFrustum = new AIS_CameraFrustum(); | |
10179 | } | |
10180 | else | |
10181 | { | |
10182 | // not include displayed object of old camera frustum in the new one. | |
10183 | ViewerTest::GetAISContext()->Erase (aCameraFrustum, false); | |
10184 | aView->ZFitAll(); | |
10185 | } | |
10186 | aCameraFrustum->SetCameraFrustum (aView->Camera()); | |
10187 | ||
10188 | ViewerTest::Display (aPrsName, aCameraFrustum); | |
10189 | } | |
b5ac8292 | 10190 | |
10191 | return 0; | |
10192 | } | |
10193 | ||
f978241f | 10194 | //! Parse stereo output mode |
10195 | inline Standard_Boolean parseStereoMode (Standard_CString theArg, | |
10196 | Graphic3d_StereoMode& theMode) | |
10197 | { | |
10198 | TCollection_AsciiString aFlag (theArg); | |
10199 | aFlag.LowerCase(); | |
10200 | if (aFlag == "quadbuffer") | |
10201 | { | |
10202 | theMode = Graphic3d_StereoMode_QuadBuffer; | |
10203 | } | |
10204 | else if (aFlag == "anaglyph") | |
10205 | { | |
10206 | theMode = Graphic3d_StereoMode_Anaglyph; | |
10207 | } | |
10208 | else if (aFlag == "row" | |
10209 | || aFlag == "rowinterlaced") | |
10210 | { | |
10211 | theMode = Graphic3d_StereoMode_RowInterlaced; | |
10212 | } | |
10213 | else if (aFlag == "col" | |
10214 | || aFlag == "colinterlaced" | |
10215 | || aFlag == "columninterlaced") | |
10216 | { | |
10217 | theMode = Graphic3d_StereoMode_ColumnInterlaced; | |
10218 | } | |
10219 | else if (aFlag == "chess" | |
10220 | || aFlag == "chessboard") | |
10221 | { | |
10222 | theMode = Graphic3d_StereoMode_ChessBoard; | |
10223 | } | |
10224 | else if (aFlag == "sbs" | |
10225 | || aFlag == "sidebyside") | |
10226 | { | |
10227 | theMode = Graphic3d_StereoMode_SideBySide; | |
10228 | } | |
10229 | else if (aFlag == "ou" | |
10230 | || aFlag == "overunder") | |
10231 | { | |
10232 | theMode = Graphic3d_StereoMode_OverUnder; | |
10233 | } | |
10234 | else if (aFlag == "pageflip" | |
10235 | || aFlag == "softpageflip") | |
10236 | { | |
10237 | theMode = Graphic3d_StereoMode_SoftPageFlip; | |
10238 | } | |
10239 | else | |
10240 | { | |
10241 | return Standard_False; | |
10242 | } | |
10243 | return Standard_True; | |
10244 | } | |
10245 | ||
10246 | //! Parse anaglyph filter | |
10247 | inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg, | |
10248 | Graphic3d_RenderingParams::Anaglyph& theFilter) | |
10249 | { | |
10250 | TCollection_AsciiString aFlag (theArg); | |
10251 | aFlag.LowerCase(); | |
10252 | if (aFlag == "redcyansimple") | |
10253 | { | |
10254 | theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple; | |
10255 | } | |
10256 | else if (aFlag == "redcyan" | |
10257 | || aFlag == "redcyanoptimized") | |
10258 | { | |
10259 | theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized; | |
10260 | } | |
10261 | else if (aFlag == "yellowbluesimple") | |
10262 | { | |
10263 | theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple; | |
10264 | } | |
10265 | else if (aFlag == "yellowblue" | |
10266 | || aFlag == "yellowblueoptimized") | |
10267 | { | |
10268 | theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized; | |
10269 | } | |
10270 | else if (aFlag == "greenmagenta" | |
10271 | || aFlag == "greenmagentasimple") | |
10272 | { | |
10273 | theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple; | |
10274 | } | |
10275 | else | |
10276 | { | |
10277 | return Standard_False; | |
10278 | } | |
10279 | return Standard_True; | |
10280 | } | |
10281 | ||
b5ac8292 | 10282 | //============================================================================== |
10283 | //function : VStereo | |
10284 | //purpose : | |
10285 | //============================================================================== | |
10286 | ||
10287 | static int VStereo (Draw_Interpretor& theDI, | |
10288 | Standard_Integer theArgNb, | |
10289 | const char** theArgVec) | |
10290 | { | |
f978241f | 10291 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
b5ac8292 | 10292 | if (theArgNb < 2) |
10293 | { | |
b5ac8292 | 10294 | if (aView.IsNull()) |
10295 | { | |
f978241f | 10296 | std::cout << "Error: no active viewer!\n"; |
b5ac8292 | 10297 | return 0; |
10298 | } | |
10299 | ||
10300 | Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo; | |
10301 | theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n"; | |
bf02aa7d | 10302 | if (isActive) |
10303 | { | |
10304 | TCollection_AsciiString aMode; | |
10305 | switch (aView->RenderingParams().StereoMode) | |
10306 | { | |
10307 | case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break; | |
10308 | case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break; | |
10309 | case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break; | |
10310 | case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break; | |
10311 | case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break; | |
10312 | case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break; | |
10313 | case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break; | |
10314 | case Graphic3d_StereoMode_Anaglyph : | |
10315 | aMode = "anaglyph"; | |
10316 | switch (aView->RenderingParams().AnaglyphFilter) | |
10317 | { | |
10318 | case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break; | |
10319 | case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break; | |
10320 | case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break; | |
10321 | case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break; | |
10322 | case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break; | |
10323 | default: break; | |
10324 | } | |
10325 | default: break; | |
10326 | } | |
10327 | theDI << "Mode " << aMode << "\n"; | |
10328 | } | |
b5ac8292 | 10329 | return 0; |
10330 | } | |
10331 | ||
f978241f | 10332 | Handle(Graphic3d_Camera) aCamera; |
10333 | Graphic3d_RenderingParams* aParams = NULL; | |
10334 | Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer; | |
10335 | if (!aView.IsNull()) | |
10336 | { | |
10337 | aParams = &aView->ChangeRenderingParams(); | |
10338 | aMode = aParams->StereoMode; | |
10339 | aCamera = aView->Camera(); | |
10340 | } | |
10341 | ||
10342 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); | |
10343 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
10344 | { | |
10345 | Standard_CString anArg = theArgVec[anArgIter]; | |
10346 | TCollection_AsciiString aFlag (anArg); | |
10347 | aFlag.LowerCase(); | |
10348 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
10349 | { | |
10350 | continue; | |
10351 | } | |
10352 | else if (aFlag == "0" | |
10353 | || aFlag == "off") | |
10354 | { | |
10355 | if (++anArgIter < theArgNb) | |
10356 | { | |
10357 | std::cout << "Error: wrong number of arguments!\n"; | |
10358 | return 1; | |
10359 | } | |
10360 | ||
10361 | if (!aCamera.IsNull() | |
10362 | && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo) | |
10363 | { | |
10364 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
10365 | } | |
10366 | ViewerTest_myDefaultCaps.contextStereo = Standard_False; | |
10367 | return 0; | |
10368 | } | |
10369 | else if (aFlag == "1" | |
10370 | || aFlag == "on") | |
10371 | { | |
10372 | if (++anArgIter < theArgNb) | |
10373 | { | |
10374 | std::cout << "Error: wrong number of arguments!\n"; | |
10375 | return 1; | |
10376 | } | |
10377 | ||
10378 | if (!aCamera.IsNull()) | |
10379 | { | |
10380 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
10381 | } | |
10382 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
10383 | return 0; | |
10384 | } | |
10385 | else if (aFlag == "-reverse" | |
10386 | || aFlag == "-reversed" | |
10387 | || aFlag == "-swap") | |
10388 | { | |
10389 | Standard_Boolean toEnable = Standard_True; | |
10390 | if (++anArgIter < theArgNb | |
a5565a3c | 10391 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 10392 | { |
10393 | --anArgIter; | |
10394 | } | |
10395 | aParams->ToReverseStereo = toEnable; | |
10396 | } | |
10397 | else if (aFlag == "-noreverse" | |
10398 | || aFlag == "-noswap") | |
10399 | { | |
10400 | Standard_Boolean toDisable = Standard_True; | |
10401 | if (++anArgIter < theArgNb | |
a5565a3c | 10402 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable)) |
f978241f | 10403 | { |
10404 | --anArgIter; | |
10405 | } | |
10406 | aParams->ToReverseStereo = !toDisable; | |
10407 | } | |
10408 | else if (aFlag == "-mode" | |
10409 | || aFlag == "-stereomode") | |
10410 | { | |
10411 | if (++anArgIter >= theArgNb | |
10412 | || !parseStereoMode (theArgVec[anArgIter], aMode)) | |
10413 | { | |
10414 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
10415 | return 1; | |
10416 | } | |
10417 | ||
10418 | if (aMode == Graphic3d_StereoMode_QuadBuffer) | |
10419 | { | |
10420 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
10421 | } | |
10422 | } | |
10423 | else if (aFlag == "-anaglyph" | |
10424 | || aFlag == "-anaglyphfilter") | |
10425 | { | |
10426 | Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple; | |
10427 | if (++anArgIter >= theArgNb | |
10428 | || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter)) | |
10429 | { | |
10430 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
10431 | return 1; | |
10432 | } | |
10433 | ||
10434 | aMode = Graphic3d_StereoMode_Anaglyph; | |
10435 | aParams->AnaglyphFilter = aFilter; | |
10436 | } | |
10437 | else if (parseStereoMode (anArg, aMode)) // short syntax | |
10438 | { | |
10439 | if (aMode == Graphic3d_StereoMode_QuadBuffer) | |
10440 | { | |
10441 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
10442 | } | |
10443 | } | |
10444 | else | |
10445 | { | |
10446 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
10447 | return 1; | |
10448 | } | |
10449 | } | |
10450 | ||
10451 | if (!aView.IsNull()) | |
10452 | { | |
10453 | aParams->StereoMode = aMode; | |
10454 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
10455 | } | |
b5ac8292 | 10456 | return 0; |
10457 | } | |
10458 | ||
392ac980 | 10459 | //=============================================================================================== |
10460 | //function : VDefaults | |
10461 | //purpose : | |
10462 | //=============================================================================================== | |
10463 | static int VDefaults (Draw_Interpretor& theDi, | |
10464 | Standard_Integer theArgsNb, | |
10465 | const char** theArgVec) | |
10466 | { | |
10467 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
10468 | if (aCtx.IsNull()) | |
10469 | { | |
14c7f553 | 10470 | std::cout << "Error: no active viewer\n"; |
392ac980 | 10471 | return 1; |
10472 | } | |
10473 | ||
10474 | Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer(); | |
10475 | if (theArgsNb < 2) | |
10476 | { | |
10477 | if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE) | |
10478 | { | |
10479 | theDi << "DeflType: relative\n" | |
10480 | << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n"; | |
10481 | } | |
10482 | else | |
10483 | { | |
10484 | theDi << "DeflType: absolute\n" | |
10485 | << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n"; | |
10486 | } | |
10487 | theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n"; | |
4c513386 | 10488 | theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n"; |
392ac980 | 10489 | return 0; |
10490 | } | |
10491 | ||
10492 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
10493 | { | |
10494 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4c513386 | 10495 | anArg.UpperCase(); |
10496 | if (anArg == "-ABSDEFL" | |
10497 | || anArg == "-ABSOLUTEDEFLECTION" | |
10498 | || anArg == "-DEFL" | |
10499 | || anArg == "-DEFLECTION") | |
392ac980 | 10500 | { |
4c513386 | 10501 | if (++anArgIter >= theArgsNb) |
10502 | { | |
10503 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
10504 | return 1; | |
10505 | } | |
392ac980 | 10506 | aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); |
4c513386 | 10507 | aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 10508 | } |
4c513386 | 10509 | else if (anArg == "-RELDEFL" |
10510 | || anArg == "-RELATIVEDEFLECTION" | |
10511 | || anArg == "-DEVCOEFF" | |
10512 | || anArg == "-DEVIATIONCOEFF" | |
10513 | || anArg == "-DEVIATIONCOEFFICIENT") | |
392ac980 | 10514 | { |
4c513386 | 10515 | if (++anArgIter >= theArgsNb) |
10516 | { | |
10517 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
10518 | return 1; | |
10519 | } | |
392ac980 | 10520 | aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE); |
4c513386 | 10521 | aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 10522 | } |
4c513386 | 10523 | else if (anArg == "-ANGDEFL" |
10524 | || anArg == "-ANGULARDEFL" | |
10525 | || anArg == "-ANGULARDEFLECTION") | |
392ac980 | 10526 | { |
4c513386 | 10527 | if (++anArgIter >= theArgsNb) |
10528 | { | |
10529 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
10530 | return 1; | |
10531 | } | |
392ac980 | 10532 | // currently HLRDeviationAngle is used instead of DeviationAngle in most places |
4c513386 | 10533 | aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0); |
10534 | } | |
385c43e7 | 10535 | else if (anArg == "-AUTOTR" |
10536 | || anArg == "-AUTOTRIANG" | |
10537 | || anArg == "-AUTOTRIANGULATION") | |
4c513386 | 10538 | { |
14c7f553 | 10539 | ++anArgIter; |
10540 | bool toTurnOn = true; | |
10541 | if (anArgIter >= theArgsNb | |
10542 | || !ViewerTest::ParseOnOff (theArgVec[anArgIter], toTurnOn)) | |
4c513386 | 10543 | { |
14c7f553 | 10544 | std::cout << "Syntax error at '" << anArg << "'\n"; |
4c513386 | 10545 | return 1; |
10546 | } | |
14c7f553 | 10547 | aDefParams->SetAutoTriangulation (toTurnOn); |
392ac980 | 10548 | } |
10549 | else | |
10550 | { | |
14c7f553 | 10551 | std::cout << "Syntax error: unknown argument '" << anArg << "'\n"; |
10552 | return 1; | |
392ac980 | 10553 | } |
10554 | } | |
10555 | ||
10556 | return 0; | |
10557 | } | |
10558 | ||
12381341 | 10559 | //! Auxiliary method |
10560 | inline void addLight (const Handle(V3d_Light)& theLightNew, | |
992ed6b3 | 10561 | const Graphic3d_ZLayerId theLayer, |
12381341 | 10562 | const Standard_Boolean theIsGlobal) |
10563 | { | |
10564 | if (theLightNew.IsNull()) | |
10565 | { | |
10566 | return; | |
10567 | } | |
10568 | ||
992ed6b3 | 10569 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); |
10570 | if (theLayer == Graphic3d_ZLayerId_UNKNOWN) | |
12381341 | 10571 | { |
992ed6b3 | 10572 | aViewer->AddLight (theLightNew); |
10573 | if (theIsGlobal) | |
10574 | { | |
10575 | aViewer->SetLightOn (theLightNew); | |
10576 | } | |
10577 | else | |
10578 | { | |
10579 | ViewerTest::CurrentView()->SetLightOn (theLightNew); | |
10580 | } | |
12381341 | 10581 | } |
10582 | else | |
10583 | { | |
992ed6b3 | 10584 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer); |
10585 | if (aSettings.Lights().IsNull()) | |
10586 | { | |
10587 | aSettings.SetLights (new Graphic3d_LightSet()); | |
10588 | } | |
10589 | aSettings.Lights()->Add (theLightNew); | |
10590 | aViewer->SetZLayerSettings (theLayer, aSettings); | |
12381341 | 10591 | } |
10592 | } | |
10593 | ||
10594 | //! Auxiliary method | |
10595 | inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext) | |
10596 | { | |
10597 | TCollection_AsciiString anArgNextCase (theArgNext); | |
10598 | anArgNextCase.UpperCase(); | |
10599 | if (anArgNextCase.Length() > 5 | |
10600 | && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT")) | |
10601 | { | |
10602 | return theArgNext.SubString (6, theArgNext.Length()).IntegerValue(); | |
10603 | } | |
10604 | else | |
10605 | { | |
10606 | return theArgNext.IntegerValue(); | |
10607 | } | |
10608 | } | |
10609 | ||
10610 | //=============================================================================================== | |
10611 | //function : VLight | |
10612 | //purpose : | |
10613 | //=============================================================================================== | |
10614 | static int VLight (Draw_Interpretor& theDi, | |
10615 | Standard_Integer theArgsNb, | |
10616 | const char** theArgVec) | |
10617 | { | |
10618 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
10619 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
10620 | if (aView.IsNull() | |
10621 | || aViewer.IsNull()) | |
10622 | { | |
10623 | std::cerr << "No active viewer!\n"; | |
10624 | return 1; | |
10625 | } | |
10626 | ||
ee2be2a8 | 10627 | Standard_Real anXYZ[3] = {}; |
10628 | Standard_Real anAtten[2] = {}; | |
12381341 | 10629 | if (theArgsNb < 2) |
10630 | { | |
10631 | // print lights info | |
10632 | Standard_Integer aLightId = 0; | |
6a24c6de | 10633 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId) |
12381341 | 10634 | { |
6a24c6de | 10635 | Handle(V3d_Light) aLight = aLightIter.Value(); |
12381341 | 10636 | const Quantity_Color aColor = aLight->Color(); |
992ed6b3 | 10637 | theDi << "Light #" << aLightId |
10638 | << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "") | |
10639 | << " [" << aLight->GetId() << "]" << "\n"; | |
12381341 | 10640 | switch (aLight->Type()) |
10641 | { | |
10642 | case V3d_AMBIENT: | |
10643 | { | |
189f85a3 | 10644 | theDi << " Type: Ambient\n"; |
10645 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
12381341 | 10646 | break; |
10647 | } | |
10648 | case V3d_DIRECTIONAL: | |
10649 | { | |
189f85a3 | 10650 | theDi << " Type: Directional\n"; |
10651 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
10652 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
10653 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; | |
992ed6b3 | 10654 | aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); |
10655 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
12381341 | 10656 | break; |
10657 | } | |
10658 | case V3d_POSITIONAL: | |
10659 | { | |
189f85a3 | 10660 | theDi << " Type: Positional\n"; |
10661 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
10662 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
10663 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; | |
992ed6b3 | 10664 | aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]); |
10665 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
10666 | aLight->Attenuation (anAtten[0], anAtten[1]); | |
10667 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; | |
12381341 | 10668 | break; |
10669 | } | |
10670 | case V3d_SPOT: | |
10671 | { | |
189f85a3 | 10672 | theDi << " Type: Spot\n"; |
10673 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
10674 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
992ed6b3 | 10675 | aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]); |
10676 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
10677 | aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); | |
10678 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
10679 | aLight->Attenuation (anAtten[0], anAtten[1]); | |
10680 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; | |
10681 | theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n"; | |
10682 | theDi << " Exponent: " << aLight->Concentration() << "\n"; | |
12381341 | 10683 | break; |
10684 | } | |
10685 | default: | |
10686 | { | |
189f85a3 | 10687 | theDi << " Type: UNKNOWN\n"; |
12381341 | 10688 | break; |
10689 | } | |
10690 | } | |
992ed6b3 | 10691 | theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n"; |
12381341 | 10692 | } |
10693 | } | |
10694 | ||
10695 | Handle(V3d_Light) aLightNew; | |
10696 | Handle(V3d_Light) aLightOld; | |
992ed6b3 | 10697 | Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN; |
12381341 | 10698 | Standard_Boolean isGlobal = Standard_True; |
10699 | Standard_Boolean toCreate = Standard_False; | |
761d8807 | 10700 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
12381341 | 10701 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
10702 | { | |
992ed6b3 | 10703 | Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew; |
12381341 | 10704 | |
10705 | TCollection_AsciiString aName, aValue; | |
10706 | const TCollection_AsciiString anArg (theArgVec[anArgIt]); | |
10707 | TCollection_AsciiString anArgCase (anArg); | |
10708 | anArgCase.UpperCase(); | |
761d8807 | 10709 | if (anUpdateTool.parseRedrawMode (anArg)) |
10710 | { | |
10711 | continue; | |
10712 | } | |
10713 | ||
12381341 | 10714 | if (anArgCase.IsEqual ("NEW") |
10715 | || anArgCase.IsEqual ("ADD") | |
992ed6b3 | 10716 | || anArgCase.IsEqual ("CREATE") |
10717 | || anArgCase.IsEqual ("-NEW") | |
10718 | || anArgCase.IsEqual ("-ADD") | |
10719 | || anArgCase.IsEqual ("-CREATE")) | |
12381341 | 10720 | { |
10721 | toCreate = Standard_True; | |
10722 | } | |
992ed6b3 | 10723 | else if (anArgCase.IsEqual ("-LAYER") |
10724 | || anArgCase.IsEqual ("-ZLAYER")) | |
10725 | { | |
10726 | if (++anArgIt >= theArgsNb) | |
10727 | { | |
10728 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10729 | return 1; | |
10730 | } | |
10731 | ||
10732 | TCollection_AsciiString aValStr (theArgVec[anArgIt]); | |
10733 | aValStr.LowerCase(); | |
10734 | if (aValStr == "default" | |
10735 | || aValStr == "def") | |
10736 | { | |
10737 | aLayer = Graphic3d_ZLayerId_Default; | |
10738 | } | |
10739 | else if (aValStr == "top") | |
10740 | { | |
10741 | aLayer = Graphic3d_ZLayerId_Top; | |
10742 | } | |
10743 | else if (aValStr == "topmost") | |
10744 | { | |
10745 | aLayer = Graphic3d_ZLayerId_Topmost; | |
10746 | } | |
10747 | else if (aValStr == "toposd" | |
10748 | || aValStr == "osd") | |
10749 | { | |
10750 | aLayer = Graphic3d_ZLayerId_TopOSD; | |
10751 | } | |
10752 | else if (aValStr == "botosd" | |
10753 | || aValStr == "bottom") | |
10754 | { | |
10755 | aLayer = Graphic3d_ZLayerId_BotOSD; | |
10756 | } | |
10757 | else if (aValStr.IsIntegerValue()) | |
10758 | { | |
10759 | aLayer = Draw::Atoi (theArgVec[anArgIt]); | |
10760 | } | |
10761 | else | |
10762 | { | |
10763 | std::cout << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10764 | return 1; | |
10765 | } | |
10766 | } | |
12381341 | 10767 | else if (anArgCase.IsEqual ("GLOB") |
992ed6b3 | 10768 | || anArgCase.IsEqual ("GLOBAL") |
10769 | || anArgCase.IsEqual ("-GLOB") | |
10770 | || anArgCase.IsEqual ("-GLOBAL")) | |
12381341 | 10771 | { |
10772 | isGlobal = Standard_True; | |
10773 | } | |
10774 | else if (anArgCase.IsEqual ("LOC") | |
992ed6b3 | 10775 | || anArgCase.IsEqual ("LOCAL") |
10776 | || anArgCase.IsEqual ("-LOC") | |
10777 | || anArgCase.IsEqual ("-LOCAL")) | |
12381341 | 10778 | { |
10779 | isGlobal = Standard_False; | |
10780 | } | |
4fe9ad57 | 10781 | else if (anArgCase.IsEqual ("DEF") |
992ed6b3 | 10782 | || anArgCase.IsEqual ("DEFAULTS") |
10783 | || anArgCase.IsEqual ("-DEF") | |
10784 | || anArgCase.IsEqual ("-DEFAULTS")) | |
4fe9ad57 | 10785 | { |
10786 | toCreate = Standard_False; | |
10787 | aViewer->SetDefaultLights(); | |
10788 | } | |
10789 | else if (anArgCase.IsEqual ("CLR") | |
992ed6b3 | 10790 | || anArgCase.IsEqual ("CLEAR") |
10791 | || anArgCase.IsEqual ("-CLR") | |
10792 | || anArgCase.IsEqual ("-CLEAR")) | |
4fe9ad57 | 10793 | { |
10794 | toCreate = Standard_False; | |
992ed6b3 | 10795 | |
10796 | TColStd_SequenceOfInteger aLayers; | |
10797 | aViewer->GetAllZLayers (aLayers); | |
10798 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
4fe9ad57 | 10799 | { |
992ed6b3 | 10800 | if (aLayeriter.Value() == aLayer |
10801 | || aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
10802 | { | |
10803 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
10804 | aSettings.SetLights (Handle(Graphic3d_LightSet)()); | |
10805 | aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings); | |
10806 | if (aLayer != Graphic3d_ZLayerId_UNKNOWN) | |
10807 | { | |
10808 | break; | |
10809 | } | |
10810 | } | |
10811 | } | |
10812 | ||
10813 | if (aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
10814 | { | |
10815 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();) | |
10816 | { | |
10817 | Handle(V3d_Light) aLight = aLightIter.Value(); | |
10818 | aViewer->DelLight (aLight); | |
10819 | aLightIter = aView->ActiveLightIterator(); | |
10820 | } | |
4fe9ad57 | 10821 | } |
10822 | } | |
12381341 | 10823 | else if (anArgCase.IsEqual ("AMB") |
10824 | || anArgCase.IsEqual ("AMBIENT") | |
10825 | || anArgCase.IsEqual ("AMBLIGHT")) | |
10826 | { | |
12381341 | 10827 | if (!toCreate) |
10828 | { | |
10829 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10830 | return 1; | |
10831 | } | |
992ed6b3 | 10832 | |
10833 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 10834 | toCreate = Standard_False; |
992ed6b3 | 10835 | aLightNew = new V3d_AmbientLight(); |
12381341 | 10836 | } |
10837 | else if (anArgCase.IsEqual ("DIRECTIONAL") | |
10838 | || anArgCase.IsEqual ("DIRLIGHT")) | |
10839 | { | |
12381341 | 10840 | if (!toCreate) |
10841 | { | |
10842 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10843 | return 1; | |
10844 | } | |
992ed6b3 | 10845 | |
10846 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 10847 | toCreate = Standard_False; |
992ed6b3 | 10848 | aLightNew = new V3d_DirectionalLight(); |
12381341 | 10849 | } |
10850 | else if (anArgCase.IsEqual ("SPOT") | |
10851 | || anArgCase.IsEqual ("SPOTLIGHT")) | |
10852 | { | |
12381341 | 10853 | if (!toCreate) |
10854 | { | |
10855 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10856 | return 1; | |
10857 | } | |
992ed6b3 | 10858 | |
10859 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 10860 | toCreate = Standard_False; |
992ed6b3 | 10861 | aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0)); |
12381341 | 10862 | } |
10863 | else if (anArgCase.IsEqual ("POSLIGHT") | |
10864 | || anArgCase.IsEqual ("POSITIONAL")) | |
10865 | { | |
12381341 | 10866 | if (!toCreate) |
10867 | { | |
10868 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10869 | return 1; | |
10870 | } | |
992ed6b3 | 10871 | |
10872 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 10873 | toCreate = Standard_False; |
992ed6b3 | 10874 | aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0)); |
12381341 | 10875 | } |
992ed6b3 | 10876 | else if (anArgCase.IsEqual ("CHANGE") |
10877 | || anArgCase.IsEqual ("-CHANGE")) | |
12381341 | 10878 | { |
12381341 | 10879 | if (++anArgIt >= theArgsNb) |
10880 | { | |
10881 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10882 | return 1; | |
10883 | } | |
10884 | ||
992ed6b3 | 10885 | addLight (aLightNew, aLayer, isGlobal); |
10886 | aLightNew.Nullify(); | |
12381341 | 10887 | const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]); |
10888 | Standard_Integer aLightIt = 0; | |
6a24c6de | 10889 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt) |
12381341 | 10890 | { |
10891 | if (aLightIt == aLightId) | |
10892 | { | |
6a24c6de | 10893 | aLightOld = aLightIter.Value(); |
12381341 | 10894 | break; |
10895 | } | |
10896 | } | |
10897 | ||
10898 | if (aLightOld.IsNull()) | |
10899 | { | |
10900 | std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n"; | |
10901 | return 1; | |
10902 | } | |
10903 | } | |
10904 | else if (anArgCase.IsEqual ("DEL") | |
992ed6b3 | 10905 | || anArgCase.IsEqual ("DELETE") |
10906 | || anArgCase.IsEqual ("-DEL") | |
10907 | || anArgCase.IsEqual ("-DELETE")) | |
12381341 | 10908 | { |
10909 | Handle(V3d_Light) aLightDel; | |
10910 | if (++anArgIt >= theArgsNb) | |
10911 | { | |
10912 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10913 | return 1; | |
10914 | } | |
10915 | ||
10916 | const TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
10917 | const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]); | |
10918 | Standard_Integer aLightIt = 0; | |
6a24c6de | 10919 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt) |
12381341 | 10920 | { |
6a24c6de | 10921 | aLightDel = aLightIter.Value(); |
12381341 | 10922 | if (aLightIt == aLightDelId) |
10923 | { | |
10924 | break; | |
10925 | } | |
10926 | } | |
992ed6b3 | 10927 | if (aLightDel.IsNull()) |
10928 | { | |
10929 | continue; | |
10930 | } | |
10931 | ||
10932 | TColStd_SequenceOfInteger aLayers; | |
10933 | aViewer->GetAllZLayers (aLayers); | |
10934 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
10935 | { | |
10936 | if (aLayeriter.Value() == aLayer | |
10937 | || aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
10938 | { | |
10939 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
10940 | if (!aSettings.Lights().IsNull()) | |
10941 | { | |
10942 | aSettings.Lights()->Remove (aLightDel); | |
10943 | if (aSettings.Lights()->IsEmpty()) | |
10944 | { | |
10945 | aSettings.SetLights (Handle(Graphic3d_LightSet)()); | |
10946 | } | |
10947 | } | |
10948 | aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings); | |
10949 | if (aLayer != Graphic3d_ZLayerId_UNKNOWN) | |
10950 | { | |
10951 | break; | |
10952 | } | |
10953 | } | |
10954 | } | |
10955 | ||
10956 | if (aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
12381341 | 10957 | { |
10958 | aViewer->DelLight (aLightDel); | |
10959 | } | |
10960 | } | |
10961 | else if (anArgCase.IsEqual ("COLOR") | |
992ed6b3 | 10962 | || anArgCase.IsEqual ("COLOUR") |
10963 | || anArgCase.IsEqual ("-COLOR") | |
10964 | || anArgCase.IsEqual ("-COLOUR")) | |
12381341 | 10965 | { |
992ed6b3 | 10966 | if (++anArgIt >= theArgsNb |
10967 | || aLightCurr.IsNull()) | |
12381341 | 10968 | { |
10969 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10970 | return 1; | |
10971 | } | |
10972 | ||
10973 | TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
10974 | anArgNext.UpperCase(); | |
10975 | const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString()); | |
992ed6b3 | 10976 | aLightCurr->SetColor (aColor); |
12381341 | 10977 | } |
10978 | else if (anArgCase.IsEqual ("POS") | |
992ed6b3 | 10979 | || anArgCase.IsEqual ("POSITION") |
10980 | || anArgCase.IsEqual ("-POS") | |
10981 | || anArgCase.IsEqual ("-POSITION")) | |
12381341 | 10982 | { |
992ed6b3 | 10983 | if ((anArgIt + 3) >= theArgsNb |
10984 | || aLightCurr.IsNull() | |
10985 | || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL | |
10986 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 10987 | { |
10988 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10989 | return 1; | |
10990 | } | |
10991 | ||
10992 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
10993 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
10994 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
992ed6b3 | 10995 | aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); |
12381341 | 10996 | } |
10997 | else if (anArgCase.IsEqual ("DIR") | |
992ed6b3 | 10998 | || anArgCase.IsEqual ("DIRECTION") |
10999 | || anArgCase.IsEqual ("-DIR") | |
11000 | || anArgCase.IsEqual ("-DIRECTION")) | |
12381341 | 11001 | { |
992ed6b3 | 11002 | if ((anArgIt + 3) >= theArgsNb |
11003 | || aLightCurr.IsNull() | |
11004 | || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL | |
11005 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 11006 | { |
11007 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
11008 | return 1; | |
11009 | } | |
11010 | ||
11011 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
11012 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
11013 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
992ed6b3 | 11014 | aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); |
12381341 | 11015 | } |
189f85a3 | 11016 | else if (anArgCase.IsEqual ("SM") |
992ed6b3 | 11017 | || anArgCase.IsEqual ("SMOOTHNESS") |
11018 | || anArgCase.IsEqual ("-SM") | |
11019 | || anArgCase.IsEqual ("-SMOOTHNESS")) | |
189f85a3 | 11020 | { |
992ed6b3 | 11021 | if (++anArgIt >= theArgsNb |
11022 | || aLightCurr.IsNull()) | |
189f85a3 | 11023 | { |
11024 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
11025 | return 1; | |
11026 | } | |
11027 | ||
992ed6b3 | 11028 | Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]); |
11029 | if (Abs (aSmoothness) <= ShortRealEpsilon()) | |
189f85a3 | 11030 | { |
11031 | aLightCurr->SetIntensity (1.f); | |
11032 | } | |
992ed6b3 | 11033 | else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon()) |
189f85a3 | 11034 | { |
11035 | aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f); | |
11036 | } | |
11037 | else | |
11038 | { | |
11039 | Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness()); | |
11040 | aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio)); | |
11041 | } | |
11042 | ||
992ed6b3 | 11043 | if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL) |
189f85a3 | 11044 | { |
992ed6b3 | 11045 | aLightCurr->SetSmoothRadius (aSmoothness); |
189f85a3 | 11046 | } |
992ed6b3 | 11047 | else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL) |
189f85a3 | 11048 | { |
992ed6b3 | 11049 | aLightCurr->SetSmoothAngle (aSmoothness); |
189f85a3 | 11050 | } |
11051 | } | |
11052 | else if (anArgCase.IsEqual ("INT") | |
992ed6b3 | 11053 | || anArgCase.IsEqual ("INTENSITY") |
11054 | || anArgCase.IsEqual ("-INT") | |
11055 | || anArgCase.IsEqual ("-INTENSITY")) | |
189f85a3 | 11056 | { |
992ed6b3 | 11057 | if (++anArgIt >= theArgsNb |
11058 | || aLightCurr.IsNull()) | |
189f85a3 | 11059 | { |
11060 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
11061 | return 1; | |
11062 | } | |
11063 | ||
992ed6b3 | 11064 | Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]); |
11065 | aLightCurr->SetIntensity (aIntensity); | |
189f85a3 | 11066 | } |
4fe9ad57 | 11067 | else if (anArgCase.IsEqual ("ANG") |
992ed6b3 | 11068 | || anArgCase.IsEqual ("ANGLE") |
11069 | || anArgCase.IsEqual ("-ANG") | |
11070 | || anArgCase.IsEqual ("-ANGLE")) | |
4fe9ad57 | 11071 | { |
992ed6b3 | 11072 | if (++anArgIt >= theArgsNb |
11073 | || aLightCurr.IsNull() | |
11074 | || aLightCurr->Type() != Graphic3d_TOLS_SPOT) | |
4fe9ad57 | 11075 | { |
11076 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
11077 | return 1; | |
11078 | } | |
11079 | ||
992ed6b3 | 11080 | Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]); |
11081 | aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI)); | |
4fe9ad57 | 11082 | } |
12381341 | 11083 | else if (anArgCase.IsEqual ("CONSTATTEN") |
992ed6b3 | 11084 | || anArgCase.IsEqual ("CONSTATTENUATION") |
11085 | || anArgCase.IsEqual ("-CONSTATTEN") | |
11086 | || anArgCase.IsEqual ("-CONSTATTENUATION")) | |
12381341 | 11087 | { |
992ed6b3 | 11088 | if (++anArgIt >= theArgsNb |
11089 | || aLightCurr.IsNull() | |
11090 | || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL | |
11091 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 11092 | { |
11093 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
11094 | return 1; | |
11095 | } | |
11096 | ||
992ed6b3 | 11097 | aLightCurr->Attenuation (anAtten[0], anAtten[1]); |
11098 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
11099 | aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]); | |
12381341 | 11100 | } |
11101 | else if (anArgCase.IsEqual ("LINATTEN") | |
11102 | || anArgCase.IsEqual ("LINEARATTEN") | |
992ed6b3 | 11103 | || anArgCase.IsEqual ("LINEARATTENUATION") |
11104 | || anArgCase.IsEqual ("-LINATTEN") | |
11105 | || anArgCase.IsEqual ("-LINEARATTEN") | |
11106 | || anArgCase.IsEqual ("-LINEARATTENUATION")) | |
12381341 | 11107 | { |
992ed6b3 | 11108 | if (++anArgIt >= theArgsNb |
11109 | || aLightCurr.IsNull() | |
11110 | || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL | |
11111 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 11112 | { |
11113 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
11114 | return 1; | |
11115 | } | |
11116 | ||
992ed6b3 | 11117 | aLightCurr->Attenuation (anAtten[0], anAtten[1]); |
11118 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
11119 | aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]); | |
12381341 | 11120 | } |
11121 | else if (anArgCase.IsEqual ("EXP") | |
11122 | || anArgCase.IsEqual ("EXPONENT") | |
11123 | || anArgCase.IsEqual ("SPOTEXP") | |
992ed6b3 | 11124 | || anArgCase.IsEqual ("SPOTEXPONENT") |
11125 | || anArgCase.IsEqual ("-EXP") | |
11126 | || anArgCase.IsEqual ("-EXPONENT") | |
11127 | || anArgCase.IsEqual ("-SPOTEXP") | |
11128 | || anArgCase.IsEqual ("-SPOTEXPONENT")) | |
12381341 | 11129 | { |
992ed6b3 | 11130 | if (++anArgIt >= theArgsNb |
11131 | || aLightCurr.IsNull() | |
11132 | || aLightCurr->Type() != Graphic3d_TOLS_SPOT) | |
12381341 | 11133 | { |
11134 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
11135 | return 1; | |
11136 | } | |
11137 | ||
992ed6b3 | 11138 | aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt])); |
12381341 | 11139 | } |
11140 | else if (anArgCase.IsEqual ("HEAD") | |
992ed6b3 | 11141 | || anArgCase.IsEqual ("HEADLIGHT") |
11142 | || anArgCase.IsEqual ("-HEAD") | |
11143 | || anArgCase.IsEqual ("-HEADLIGHT")) | |
12381341 | 11144 | { |
992ed6b3 | 11145 | if (aLightCurr.IsNull() |
11146 | || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT) | |
12381341 | 11147 | { |
11148 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
11149 | return 1; | |
11150 | } | |
11151 | ||
992ed6b3 | 11152 | Standard_Boolean isHeadLight = Standard_True; |
11153 | if (anArgIt + 1 < theArgsNb | |
11154 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight)) | |
12381341 | 11155 | { |
992ed6b3 | 11156 | ++anArgIt; |
12381341 | 11157 | } |
992ed6b3 | 11158 | aLightCurr->SetHeadlight (isHeadLight); |
12381341 | 11159 | } |
11160 | else | |
11161 | { | |
11162 | std::cerr << "Warning: unknown argument '" << anArg << "'\n"; | |
11163 | } | |
11164 | } | |
11165 | ||
992ed6b3 | 11166 | addLight (aLightNew, aLayer, isGlobal); |
12381341 | 11167 | return 0; |
11168 | } | |
11169 | ||
15669413 | 11170 | //! Read Graphic3d_RenderingParams::PerfCounters flag. |
11171 | static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue, | |
11172 | Standard_Boolean& theToReset, | |
11173 | Graphic3d_RenderingParams::PerfCounters& theFlagsRem, | |
11174 | Graphic3d_RenderingParams::PerfCounters& theFlagsAdd) | |
11175 | { | |
11176 | Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE; | |
11177 | TCollection_AsciiString aVal = theValue; | |
11178 | Standard_Boolean toReverse = Standard_False; | |
11179 | if (aVal == "none") | |
11180 | { | |
11181 | theToReset = Standard_True; | |
11182 | return Standard_True; | |
11183 | } | |
11184 | else if (aVal.StartsWith ("-")) | |
11185 | { | |
11186 | toReverse = Standard_True; | |
11187 | aVal = aVal.SubString (2, aVal.Length()); | |
11188 | } | |
11189 | else if (aVal.StartsWith ("no")) | |
11190 | { | |
11191 | toReverse = Standard_True; | |
11192 | aVal = aVal.SubString (3, aVal.Length()); | |
11193 | } | |
11194 | else if (aVal.StartsWith ("+")) | |
11195 | { | |
11196 | aVal = aVal.SubString (2, aVal.Length()); | |
11197 | } | |
11198 | else | |
11199 | { | |
11200 | theToReset = Standard_True; | |
11201 | } | |
11202 | ||
11203 | if ( aVal == "fps" | |
11204 | || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate; | |
11205 | else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU; | |
11206 | else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers; | |
11207 | else if (aVal == "structs" | |
11208 | || aVal == "structures" | |
11209 | || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures; | |
11210 | else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups; | |
11211 | else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays; | |
11212 | else if (aVal == "tris" | |
11213 | || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles; | |
11214 | else if (aVal == "pnts" | |
11215 | || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points; | |
11216 | else if (aVal == "mem" | |
11217 | || aVal == "gpumem" | |
11218 | || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem; | |
5e30547b | 11219 | else if (aVal == "skipimmediate" |
11220 | || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate; | |
11221 | else if (aVal == "frametime" | |
11222 | || aVal == "frametimers" | |
11223 | || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime; | |
15669413 | 11224 | else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic; |
11225 | else if (aVal == "extended" | |
11226 | || aVal == "verbose" | |
11227 | || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended; | |
5e30547b | 11228 | else if (aVal == "full" |
11229 | || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All; | |
15669413 | 11230 | else |
11231 | { | |
11232 | return Standard_False; | |
11233 | } | |
11234 | ||
11235 | if (toReverse) | |
11236 | { | |
11237 | theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag); | |
11238 | } | |
11239 | else | |
11240 | { | |
11241 | theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag); | |
11242 | } | |
11243 | return Standard_True; | |
11244 | } | |
11245 | ||
11246 | //! Read Graphic3d_RenderingParams::PerfCounters flags. | |
11247 | static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue, | |
11248 | Graphic3d_RenderingParams::PerfCounters& theFlags) | |
11249 | { | |
11250 | TCollection_AsciiString aValue = theValue; | |
11251 | Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE; | |
11252 | Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE; | |
11253 | Standard_Boolean toReset = Standard_False; | |
11254 | for (;;) | |
11255 | { | |
11256 | Standard_Integer aSplitPos = aValue.Search ("|"); | |
11257 | if (aSplitPos <= 0) | |
11258 | { | |
11259 | if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd)) | |
11260 | { | |
11261 | return Standard_False; | |
11262 | } | |
11263 | if (toReset) | |
11264 | { | |
11265 | theFlags = Graphic3d_RenderingParams::PerfCounters_NONE; | |
11266 | } | |
11267 | theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd); | |
11268 | theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem); | |
11269 | return Standard_True; | |
11270 | } | |
11271 | ||
11272 | if (aSplitPos > 1) | |
11273 | { | |
11274 | TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1); | |
11275 | if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd)) | |
11276 | { | |
11277 | return Standard_False; | |
11278 | } | |
11279 | } | |
11280 | aValue = aValue.SubString (aSplitPos + 1, aValue.Length()); | |
11281 | } | |
11282 | } | |
11283 | ||
e276548b | 11284 | //======================================================================= |
bc8c79bb | 11285 | //function : VRenderParams |
11286 | //purpose : Enables/disables rendering features | |
e276548b | 11287 | //======================================================================= |
11288 | ||
bc8c79bb | 11289 | static Standard_Integer VRenderParams (Draw_Interpretor& theDI, |
11290 | Standard_Integer theArgNb, | |
11291 | const char** theArgVec) | |
e276548b | 11292 | { |
7ae4a307 | 11293 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
11294 | if (aView.IsNull()) | |
e276548b | 11295 | { |
bc8c79bb | 11296 | std::cerr << "Error: no active viewer!\n"; |
e276548b | 11297 | return 1; |
11298 | } | |
bc8c79bb | 11299 | |
11300 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); | |
6b62b2da | 11301 | TCollection_AsciiString aCmdName (theArgVec[0]); |
11302 | aCmdName.LowerCase(); | |
11303 | if (aCmdName == "vraytrace") | |
11304 | { | |
11305 | if (theArgNb == 1) | |
11306 | { | |
11307 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " "; | |
11308 | return 0; | |
11309 | } | |
11310 | else if (theArgNb == 2) | |
11311 | { | |
11312 | TCollection_AsciiString aValue (theArgVec[1]); | |
11313 | aValue.LowerCase(); | |
11314 | if (aValue == "on" | |
11315 | || aValue == "1") | |
11316 | { | |
11317 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
11318 | aView->Redraw(); | |
11319 | return 0; | |
11320 | } | |
11321 | else if (aValue == "off" | |
11322 | || aValue == "0") | |
11323 | { | |
11324 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
11325 | aView->Redraw(); | |
11326 | return 0; | |
11327 | } | |
11328 | else | |
11329 | { | |
11330 | std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n"; | |
11331 | return 1; | |
11332 | } | |
11333 | } | |
11334 | else | |
11335 | { | |
11336 | std::cout << "Error: wrong number of arguments\n"; | |
11337 | return 1; | |
11338 | } | |
11339 | } | |
bc8c79bb | 11340 | |
11341 | if (theArgNb < 2) | |
e276548b | 11342 | { |
bc8c79bb | 11343 | theDI << "renderMode: "; |
11344 | switch (aParams.Method) | |
11345 | { | |
11346 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
11347 | case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break; | |
11348 | } | |
11349 | theDI << "\n"; | |
a1073ae2 | 11350 | theDI << "transparency: "; |
11351 | switch (aParams.TransparencyMethod) | |
11352 | { | |
11353 | case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break; | |
11354 | case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: " | |
11355 | << TCollection_AsciiString (aParams.OitDepthFactor); break; | |
11356 | } | |
11357 | theDI << "\n"; | |
b4327ba8 | 11358 | theDI << "msaa: " << aParams.NbMsaaSamples << "\n"; |
56689b27 | 11359 | theDI << "rendScale: " << aParams.RenderResolutionScale << "\n"; |
b4327ba8 | 11360 | theDI << "rayDepth: " << aParams.RaytracingDepth << "\n"; |
11361 | theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n"; | |
11362 | theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n"; | |
11363 | theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n"; | |
11364 | theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n"; | |
11365 | theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n"; | |
11366 | theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n"; | |
11367 | theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n"; | |
11368 | theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n"; | |
11369 | theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n"; | |
b09447ed | 11370 | theDI << "max radiance: " << aParams.RadianceClampingValue << "\n"; |
4eaaf9d8 | 11371 | theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n"; |
66d1cdc6 | 11372 | theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n"; |
8625ef7e | 11373 | theDI << "shadingModel: "; |
11374 | switch (aView->ShadingModel()) | |
11375 | { | |
dc89236f | 11376 | case Graphic3d_TOSM_DEFAULT: theDI << "default"; break; |
11377 | case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break; | |
11378 | case Graphic3d_TOSM_FACET: theDI << "flat"; break; | |
11379 | case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break; | |
11380 | case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break; | |
8625ef7e | 11381 | } |
15669413 | 11382 | { |
11383 | theDI << "perfCounters:"; | |
11384 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0) | |
11385 | { | |
11386 | theDI << " fps"; | |
11387 | } | |
11388 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0) | |
11389 | { | |
11390 | theDI << " cpu"; | |
11391 | } | |
11392 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0) | |
11393 | { | |
11394 | theDI << " structs"; | |
11395 | } | |
11396 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0) | |
11397 | { | |
11398 | theDI << " groups"; | |
11399 | } | |
11400 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0) | |
11401 | { | |
11402 | theDI << " arrays"; | |
11403 | } | |
11404 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0) | |
11405 | { | |
11406 | theDI << " tris"; | |
11407 | } | |
11408 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0) | |
11409 | { | |
11410 | theDI << " pnts"; | |
11411 | } | |
11412 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0) | |
11413 | { | |
11414 | theDI << " gpumem"; | |
11415 | } | |
5e30547b | 11416 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0) |
11417 | { | |
11418 | theDI << " frameTime"; | |
11419 | } | |
11420 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0) | |
11421 | { | |
11422 | theDI << " skipimmediate"; | |
11423 | } | |
15669413 | 11424 | if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE) |
11425 | { | |
11426 | theDI << " none"; | |
11427 | } | |
11428 | theDI << "\n"; | |
11429 | } | |
f88457e6 | 11430 | theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n"; |
c40eb6b9 | 11431 | theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n"; |
0e3025bc | 11432 | theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" : |
11433 | aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" : | |
11434 | "noUpdate") << "\n"; | |
8625ef7e | 11435 | theDI << "\n"; |
bc8c79bb | 11436 | return 0; |
e276548b | 11437 | } |
11438 | ||
bc8c79bb | 11439 | Standard_Boolean toPrint = Standard_False; |
8625ef7e | 11440 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
e276548b | 11441 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
11442 | { | |
bc8c79bb | 11443 | Standard_CString anArg (theArgVec[anArgIter]); |
11444 | TCollection_AsciiString aFlag (anArg); | |
11445 | aFlag.LowerCase(); | |
8625ef7e | 11446 | if (anUpdateTool.parseRedrawMode (aFlag)) |
11447 | { | |
11448 | continue; | |
11449 | } | |
11450 | else if (aFlag == "-echo" | |
11451 | || aFlag == "-print") | |
e276548b | 11452 | { |
bc8c79bb | 11453 | toPrint = Standard_True; |
8625ef7e | 11454 | anUpdateTool.Invalidate(); |
e276548b | 11455 | } |
bc8c79bb | 11456 | else if (aFlag == "-mode" |
11457 | || aFlag == "-rendermode" | |
11458 | || aFlag == "-render_mode") | |
e276548b | 11459 | { |
bc8c79bb | 11460 | if (toPrint) |
11461 | { | |
11462 | switch (aParams.Method) | |
11463 | { | |
11464 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
11465 | case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break; | |
11466 | } | |
11467 | continue; | |
11468 | } | |
e276548b | 11469 | else |
bc8c79bb | 11470 | { |
11471 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11472 | return 1; | |
11473 | } | |
11474 | } | |
11475 | else if (aFlag == "-ray" | |
11476 | || aFlag == "-raytrace") | |
11477 | { | |
11478 | if (toPrint) | |
11479 | { | |
11480 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " "; | |
11481 | continue; | |
11482 | } | |
11483 | ||
11484 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
e276548b | 11485 | } |
bc8c79bb | 11486 | else if (aFlag == "-rast" |
11487 | || aFlag == "-raster" | |
11488 | || aFlag == "-rasterization") | |
e276548b | 11489 | { |
bc8c79bb | 11490 | if (toPrint) |
11491 | { | |
11492 | theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " "; | |
11493 | continue; | |
11494 | } | |
11495 | ||
11496 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
11497 | } | |
3c4b62a4 | 11498 | else if (aFlag == "-msaa") |
11499 | { | |
11500 | if (toPrint) | |
11501 | { | |
11502 | theDI << aParams.NbMsaaSamples << " "; | |
11503 | continue; | |
11504 | } | |
11505 | else if (++anArgIter >= theArgNb) | |
11506 | { | |
11507 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11508 | return 1; | |
11509 | } | |
11510 | ||
11511 | const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]); | |
11512 | if (aNbSamples < 0) | |
11513 | { | |
11514 | std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n"; | |
11515 | return 1; | |
11516 | } | |
11517 | else | |
11518 | { | |
11519 | aParams.NbMsaaSamples = aNbSamples; | |
11520 | } | |
11521 | } | |
2a332745 | 11522 | else if (aFlag == "-linefeather" |
11523 | || aFlag == "-edgefeather" | |
11524 | || aFlag == "-feather") | |
11525 | { | |
11526 | if (toPrint) | |
11527 | { | |
11528 | theDI << " " << aParams.LineFeather << " "; | |
11529 | continue; | |
11530 | } | |
11531 | else if (++anArgIter >= theArgNb) | |
11532 | { | |
11533 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11534 | return 1; | |
11535 | } | |
11536 | ||
11537 | TCollection_AsciiString aParam = theArgVec[anArgIter]; | |
11538 | const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]); | |
11539 | if (aFeather <= 0.0f) | |
11540 | { | |
11541 | std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n"; | |
11542 | return 1; | |
11543 | } | |
11544 | aParams.LineFeather = aFeather; | |
11545 | } | |
a1073ae2 | 11546 | else if (aFlag == "-oit") |
11547 | { | |
11548 | if (toPrint) | |
11549 | { | |
11550 | if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT) | |
11551 | { | |
11552 | theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " "; | |
11553 | } | |
11554 | else | |
11555 | { | |
11556 | theDI << "off" << " "; | |
11557 | } | |
11558 | continue; | |
11559 | } | |
11560 | else if (++anArgIter >= theArgNb) | |
11561 | { | |
11562 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11563 | return 1; | |
11564 | } | |
11565 | ||
11566 | TCollection_AsciiString aParam = theArgVec[anArgIter]; | |
11567 | aParam.LowerCase(); | |
11568 | if (aParam.IsRealValue()) | |
11569 | { | |
11570 | const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]); | |
11571 | if (aWeight < 0.f || aWeight > 1.f) | |
11572 | { | |
11573 | std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n"; | |
11574 | return 1; | |
11575 | } | |
11576 | ||
11577 | aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT; | |
11578 | aParams.OitDepthFactor = aWeight; | |
11579 | } | |
11580 | else if (aParam == "off") | |
11581 | { | |
11582 | aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED; | |
11583 | } | |
11584 | else | |
11585 | { | |
11586 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11587 | return 1; | |
11588 | } | |
11589 | } | |
f88457e6 | 11590 | else if (aFlag == "-depthprepass") |
11591 | { | |
11592 | if (toPrint) | |
11593 | { | |
11594 | theDI << (aParams.ToEnableDepthPrepass ? "on " : "off "); | |
11595 | continue; | |
11596 | } | |
11597 | aParams.ToEnableDepthPrepass = Standard_True; | |
11598 | if (anArgIter + 1 < theArgNb | |
11599 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass)) | |
11600 | { | |
11601 | ++anArgIter; | |
11602 | } | |
11603 | } | |
c40eb6b9 | 11604 | else if (aFlag == "-samplealphatocoverage" |
11605 | || aFlag == "-alphatocoverage") | |
11606 | { | |
11607 | if (toPrint) | |
11608 | { | |
11609 | theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off "); | |
11610 | continue; | |
11611 | } | |
11612 | aParams.ToEnableAlphaToCoverage = Standard_True; | |
11613 | if (anArgIter + 1 < theArgNb | |
11614 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage)) | |
11615 | { | |
11616 | ++anArgIter; | |
11617 | } | |
11618 | } | |
56689b27 | 11619 | else if (aFlag == "-rendscale" |
11620 | || aFlag == "-renderscale" | |
11621 | || aFlag == "-renderresolutionscale") | |
11622 | { | |
11623 | if (toPrint) | |
11624 | { | |
11625 | theDI << aParams.RenderResolutionScale << " "; | |
11626 | continue; | |
11627 | } | |
11628 | else if (++anArgIter >= theArgNb) | |
11629 | { | |
11630 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11631 | return 1; | |
11632 | } | |
11633 | ||
11634 | const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]); | |
11635 | if (aScale < 0.01) | |
11636 | { | |
11637 | std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n"; | |
11638 | return 1; | |
11639 | } | |
11640 | else | |
11641 | { | |
11642 | aParams.RenderResolutionScale = Standard_ShortReal(aScale); | |
11643 | } | |
11644 | } | |
bc8c79bb | 11645 | else if (aFlag == "-raydepth" |
11646 | || aFlag == "-ray_depth") | |
11647 | { | |
11648 | if (toPrint) | |
11649 | { | |
11650 | theDI << aParams.RaytracingDepth << " "; | |
11651 | continue; | |
11652 | } | |
11653 | else if (++anArgIter >= theArgNb) | |
11654 | { | |
11655 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11656 | return 1; | |
11657 | } | |
11658 | ||
11659 | const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]); | |
189f85a3 | 11660 | |
11661 | // We allow RaytracingDepth be more than 10 in case of GI enabled | |
11662 | if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled)) | |
bc8c79bb | 11663 | { |
11664 | std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n"; | |
11665 | return 1; | |
11666 | } | |
e276548b | 11667 | else |
bc8c79bb | 11668 | { |
11669 | aParams.RaytracingDepth = aDepth; | |
11670 | } | |
11671 | } | |
11672 | else if (aFlag == "-shad" | |
11673 | || aFlag == "-shadows") | |
11674 | { | |
11675 | if (toPrint) | |
11676 | { | |
11677 | theDI << (aParams.IsShadowEnabled ? "on" : "off") << " "; | |
11678 | continue; | |
11679 | } | |
11680 | ||
11681 | Standard_Boolean toEnable = Standard_True; | |
11682 | if (++anArgIter < theArgNb | |
a5565a3c | 11683 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 11684 | { |
11685 | --anArgIter; | |
11686 | } | |
11687 | aParams.IsShadowEnabled = toEnable; | |
11688 | } | |
11689 | else if (aFlag == "-refl" | |
11690 | || aFlag == "-reflections") | |
11691 | { | |
11692 | if (toPrint) | |
11693 | { | |
11694 | theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " "; | |
11695 | continue; | |
11696 | } | |
11697 | ||
11698 | Standard_Boolean toEnable = Standard_True; | |
11699 | if (++anArgIter < theArgNb | |
a5565a3c | 11700 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 11701 | { |
11702 | --anArgIter; | |
11703 | } | |
11704 | aParams.IsReflectionEnabled = toEnable; | |
11705 | } | |
11706 | else if (aFlag == "-fsaa") | |
11707 | { | |
11708 | if (toPrint) | |
11709 | { | |
11710 | theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " "; | |
11711 | continue; | |
11712 | } | |
11713 | ||
11714 | Standard_Boolean toEnable = Standard_True; | |
11715 | if (++anArgIter < theArgNb | |
a5565a3c | 11716 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 11717 | { |
11718 | --anArgIter; | |
11719 | } | |
11720 | aParams.IsAntialiasingEnabled = toEnable; | |
11721 | } | |
11722 | else if (aFlag == "-gleam") | |
11723 | { | |
11724 | if (toPrint) | |
11725 | { | |
11726 | theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " "; | |
11727 | continue; | |
11728 | } | |
11729 | ||
11730 | Standard_Boolean toEnable = Standard_True; | |
11731 | if (++anArgIter < theArgNb | |
a5565a3c | 11732 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 11733 | { |
11734 | --anArgIter; | |
11735 | } | |
11736 | aParams.IsTransparentShadowEnabled = toEnable; | |
e276548b | 11737 | } |
189f85a3 | 11738 | else if (aFlag == "-gi") |
11739 | { | |
11740 | if (toPrint) | |
11741 | { | |
11742 | theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " "; | |
11743 | continue; | |
11744 | } | |
11745 | ||
11746 | Standard_Boolean toEnable = Standard_True; | |
11747 | if (++anArgIter < theArgNb | |
a5565a3c | 11748 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
189f85a3 | 11749 | { |
11750 | --anArgIter; | |
11751 | } | |
11752 | aParams.IsGlobalIlluminationEnabled = toEnable; | |
11753 | if (!toEnable) | |
11754 | { | |
11755 | aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10); | |
11756 | } | |
11757 | } | |
8c820969 | 11758 | else if (aFlag == "-blockedrng" |
11759 | || aFlag == "-brng") | |
11760 | { | |
11761 | if (toPrint) | |
11762 | { | |
11763 | theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " "; | |
11764 | continue; | |
11765 | } | |
11766 | ||
11767 | Standard_Boolean toEnable = Standard_True; | |
11768 | if (++anArgIter < theArgNb | |
a5565a3c | 11769 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8c820969 | 11770 | { |
11771 | --anArgIter; | |
11772 | } | |
11773 | aParams.CoherentPathTracingMode = toEnable; | |
11774 | } | |
b09447ed | 11775 | else if (aFlag == "-maxrad") |
11776 | { | |
11777 | if (toPrint) | |
11778 | { | |
11779 | theDI << aParams.RadianceClampingValue << " "; | |
11780 | continue; | |
11781 | } | |
11782 | else if (++anArgIter >= theArgNb) | |
11783 | { | |
11784 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11785 | return 1; | |
11786 | } | |
11787 | ||
11788 | const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter]; | |
11789 | if (!aMaxRadStr.IsRealValue()) | |
11790 | { | |
11791 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11792 | return 1; | |
11793 | } | |
11794 | ||
11795 | const Standard_Real aMaxRadiance = aMaxRadStr.RealValue(); | |
11796 | if (aMaxRadiance <= 0.0) | |
11797 | { | |
11798 | std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n"; | |
11799 | return 1; | |
11800 | } | |
11801 | else | |
11802 | { | |
11803 | aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance); | |
11804 | } | |
11805 | } | |
3a9b5dc8 | 11806 | else if (aFlag == "-iss") |
11807 | { | |
11808 | if (toPrint) | |
11809 | { | |
11810 | theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " "; | |
11811 | continue; | |
11812 | } | |
11813 | ||
11814 | Standard_Boolean toEnable = Standard_True; | |
11815 | if (++anArgIter < theArgNb | |
11816 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
11817 | { | |
11818 | --anArgIter; | |
11819 | } | |
11820 | aParams.AdaptiveScreenSampling = toEnable; | |
11821 | } | |
e084dbbc | 11822 | else if (aFlag == "-issatomic") |
11823 | { | |
11824 | if (toPrint) | |
11825 | { | |
11826 | theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " "; | |
11827 | continue; | |
11828 | } | |
11829 | ||
11830 | Standard_Boolean toEnable = Standard_True; | |
11831 | if (++anArgIter < theArgNb | |
11832 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
11833 | { | |
11834 | --anArgIter; | |
11835 | } | |
11836 | aParams.AdaptiveScreenSamplingAtomic = toEnable; | |
11837 | } | |
3a9b5dc8 | 11838 | else if (aFlag == "-issd") |
11839 | { | |
11840 | if (toPrint) | |
11841 | { | |
11842 | theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " "; | |
11843 | continue; | |
11844 | } | |
11845 | ||
11846 | Standard_Boolean toEnable = Standard_True; | |
11847 | if (++anArgIter < theArgNb | |
11848 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
11849 | { | |
11850 | --anArgIter; | |
11851 | } | |
11852 | aParams.ShowSamplingTiles = toEnable; | |
11853 | } | |
66d1cdc6 | 11854 | else if (aFlag == "-tilesize") |
11855 | { | |
11856 | if (toPrint) | |
11857 | { | |
11858 | theDI << aParams.RayTracingTileSize << " "; | |
11859 | continue; | |
11860 | } | |
11861 | else if (++anArgIter >= theArgNb) | |
11862 | { | |
11863 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11864 | return 1; | |
11865 | } | |
11866 | ||
11867 | const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]); | |
11868 | if (aTileSize < 1) | |
11869 | { | |
11870 | std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n"; | |
11871 | return 1; | |
11872 | } | |
11873 | aParams.RayTracingTileSize = aTileSize; | |
11874 | } | |
4eaaf9d8 | 11875 | else if (aFlag == "-nbtiles") |
11876 | { | |
11877 | if (toPrint) | |
11878 | { | |
11879 | theDI << aParams.NbRayTracingTiles << " "; | |
11880 | continue; | |
11881 | } | |
11882 | else if (++anArgIter >= theArgNb) | |
11883 | { | |
11884 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11885 | return 1; | |
11886 | } | |
11887 | ||
11888 | const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]); | |
66d1cdc6 | 11889 | if (aNbTiles < -1) |
4eaaf9d8 | 11890 | { |
11891 | std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n"; | |
4eaaf9d8 | 11892 | return 1; |
11893 | } | |
66d1cdc6 | 11894 | else if (aNbTiles > 0 |
11895 | && (aNbTiles < 64 | |
11896 | || aNbTiles > 1024)) | |
4eaaf9d8 | 11897 | { |
66d1cdc6 | 11898 | std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n"; |
4eaaf9d8 | 11899 | } |
66d1cdc6 | 11900 | aParams.NbRayTracingTiles = aNbTiles; |
4eaaf9d8 | 11901 | } |
189f85a3 | 11902 | else if (aFlag == "-env") |
11903 | { | |
11904 | if (toPrint) | |
11905 | { | |
11906 | theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " "; | |
11907 | continue; | |
11908 | } | |
11909 | ||
11910 | Standard_Boolean toEnable = Standard_True; | |
11911 | if (++anArgIter < theArgNb | |
a5565a3c | 11912 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
189f85a3 | 11913 | { |
11914 | --anArgIter; | |
11915 | } | |
11916 | aParams.UseEnvironmentMapBackground = toEnable; | |
11917 | } | |
b4327ba8 | 11918 | else if (aFlag == "-twoside") |
11919 | { | |
11920 | if (toPrint) | |
11921 | { | |
11922 | theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " "; | |
11923 | continue; | |
11924 | } | |
11925 | ||
11926 | Standard_Boolean toEnable = Standard_True; | |
11927 | if (++anArgIter < theArgNb | |
11928 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
11929 | { | |
11930 | --anArgIter; | |
11931 | } | |
11932 | aParams.TwoSidedBsdfModels = toEnable; | |
11933 | } | |
8625ef7e | 11934 | else if (aFlag == "-shademodel" |
11935 | || aFlag == "-shadingmodel" | |
11936 | || aFlag == "-shading") | |
11937 | { | |
11938 | if (toPrint) | |
11939 | { | |
11940 | switch (aView->ShadingModel()) | |
11941 | { | |
dc89236f | 11942 | case Graphic3d_TOSM_DEFAULT: theDI << "default"; break; |
11943 | case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break; | |
11944 | case Graphic3d_TOSM_FACET: theDI << "flat "; break; | |
11945 | case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break; | |
11946 | case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break; | |
8625ef7e | 11947 | } |
11948 | continue; | |
11949 | } | |
11950 | ||
11951 | if (++anArgIter >= theArgNb) | |
11952 | { | |
11953 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11954 | } | |
11955 | ||
dc89236f | 11956 | Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT; |
11957 | if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel) | |
11958 | && aModel != Graphic3d_TOSM_DEFAULT) | |
8625ef7e | 11959 | { |
dc89236f | 11960 | aView->SetShadingModel (aModel); |
8625ef7e | 11961 | } |
11962 | else | |
11963 | { | |
dc89236f | 11964 | std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n"; |
8625ef7e | 11965 | return 1; |
11966 | } | |
11967 | } | |
4b1c8733 | 11968 | else if (aFlag == "-resolution") |
11969 | { | |
11970 | if (++anArgIter >= theArgNb) | |
11971 | { | |
11972 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11973 | return 1; | |
11974 | } | |
11975 | ||
11976 | TCollection_AsciiString aResolution (theArgVec[anArgIter]); | |
11977 | if (aResolution.IsIntegerValue()) | |
11978 | { | |
11979 | aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString())); | |
11980 | } | |
11981 | else | |
11982 | { | |
11983 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
11984 | return 1; | |
11985 | } | |
11986 | } | |
d877e610 | 11987 | else if (aFlag == "-rebuildglsl" |
11988 | || aFlag == "-rebuild") | |
11989 | { | |
11990 | if (toPrint) | |
11991 | { | |
11992 | theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " "; | |
11993 | continue; | |
11994 | } | |
11995 | ||
11996 | Standard_Boolean toEnable = Standard_True; | |
11997 | if (++anArgIter < theArgNb | |
11998 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
11999 | { | |
12000 | --anArgIter; | |
12001 | } | |
12002 | aParams.RebuildRayTracingShaders = toEnable; | |
12003 | } | |
b27ab03d | 12004 | else if (aFlag == "-focal") |
12005 | { | |
12006 | if (++anArgIter >= theArgNb) | |
12007 | { | |
12008 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
12009 | return 1; | |
12010 | } | |
12011 | ||
12012 | TCollection_AsciiString aParam (theArgVec[anArgIter]); | |
12013 | if (aParam.IsRealValue()) | |
12014 | { | |
12015 | float aFocalDist = static_cast<float> (aParam.RealValue()); | |
12016 | if (aFocalDist < 0) | |
12017 | { | |
12018 | std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n"; | |
12019 | return 1; | |
12020 | } | |
12021 | aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist; | |
12022 | } | |
12023 | else | |
12024 | { | |
12025 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
12026 | return 1; | |
12027 | } | |
12028 | } | |
12029 | else if (aFlag == "-aperture") | |
12030 | { | |
12031 | if (++anArgIter >= theArgNb) | |
12032 | { | |
12033 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
12034 | return 1; | |
12035 | } | |
12036 | ||
12037 | TCollection_AsciiString aParam(theArgVec[anArgIter]); | |
12038 | if (aParam.IsRealValue()) | |
12039 | { | |
12040 | float aApertureSize = static_cast<float> (aParam.RealValue()); | |
12041 | if (aApertureSize < 0) | |
12042 | { | |
12043 | std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n"; | |
12044 | return 1; | |
12045 | } | |
12046 | aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize; | |
12047 | } | |
12048 | else | |
12049 | { | |
12050 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
12051 | return 1; | |
12052 | } | |
12053 | } | |
eb85ed36 | 12054 | else if (aFlag == "-exposure") |
12055 | { | |
12056 | if (++anArgIter >= theArgNb) | |
12057 | { | |
12058 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
12059 | return 1; | |
12060 | } | |
12061 | ||
12062 | TCollection_AsciiString anExposure (theArgVec[anArgIter]); | |
12063 | if (anExposure.IsRealValue()) | |
12064 | { | |
12065 | aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue()); | |
12066 | } | |
12067 | else | |
12068 | { | |
12069 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
12070 | return 1; | |
12071 | } | |
12072 | } | |
12073 | else if (aFlag == "-whitepoint") | |
12074 | { | |
12075 | if (++anArgIter >= theArgNb) | |
12076 | { | |
12077 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
12078 | return 1; | |
12079 | } | |
12080 | ||
12081 | TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]); | |
12082 | if (aWhitePoint.IsRealValue()) | |
12083 | { | |
12084 | aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue()); | |
12085 | } | |
12086 | else | |
12087 | { | |
12088 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
12089 | return 1; | |
12090 | } | |
12091 | } | |
12092 | else if (aFlag == "-tonemapping") | |
12093 | { | |
12094 | if (++anArgIter >= theArgNb) | |
12095 | { | |
12096 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
12097 | return 1; | |
12098 | } | |
12099 | ||
12100 | TCollection_AsciiString aMode (theArgVec[anArgIter]); | |
12101 | aMode.LowerCase(); | |
12102 | ||
12103 | if (aMode == "disabled") | |
12104 | { | |
12105 | aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled; | |
12106 | } | |
12107 | else if (aMode == "filmic") | |
12108 | { | |
12109 | aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic; | |
12110 | } | |
12111 | else | |
12112 | { | |
12113 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
12114 | return 1; | |
12115 | } | |
12116 | } | |
15669413 | 12117 | else if (aFlag == "-performancestats" |
12118 | || aFlag == "-performancecounters" | |
12119 | || aFlag == "-perfstats" | |
12120 | || aFlag == "-perfcounters" | |
12121 | || aFlag == "-stats") | |
12122 | { | |
12123 | if (++anArgIter >= theArgNb) | |
12124 | { | |
12125 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
12126 | return 1; | |
12127 | } | |
12128 | ||
12129 | TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]); | |
12130 | aFlagsStr.LowerCase(); | |
12131 | Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats; | |
12132 | if (!convertToPerfStatsFlags (aFlagsStr, aFlags)) | |
12133 | { | |
12134 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
12135 | return 1; | |
12136 | } | |
12137 | aView->ChangeRenderingParams().CollectedStats = aFlags; | |
12138 | aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE; | |
12139 | } | |
12140 | else if (aFlag == "-perfupdateinterval" | |
12141 | || aFlag == "-statsupdateinterval") | |
12142 | { | |
12143 | if (++anArgIter >= theArgNb) | |
12144 | { | |
12145 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
12146 | return 1; | |
12147 | } | |
12148 | aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]); | |
12149 | } | |
5e30547b | 12150 | else if (aFlag == "-perfchart" |
12151 | || aFlag == "-statschart") | |
12152 | { | |
12153 | if (++anArgIter >= theArgNb) | |
12154 | { | |
12155 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
12156 | return 1; | |
12157 | } | |
12158 | aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]); | |
12159 | } | |
12160 | else if (aFlag == "-perfchartmax" | |
12161 | || aFlag == "-statschartmax") | |
12162 | { | |
12163 | if (++anArgIter >= theArgNb) | |
12164 | { | |
12165 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
12166 | return 1; | |
12167 | } | |
12168 | aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]); | |
12169 | } | |
0e3025bc | 12170 | else if (aFlag == "-frustumculling" |
12171 | || aFlag == "-culling") | |
12172 | { | |
12173 | if (toPrint) | |
12174 | { | |
12175 | theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" : | |
12176 | (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" : | |
12177 | "noUpdate") << " "; | |
12178 | continue; | |
12179 | } | |
12180 | ||
12181 | Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On; | |
12182 | if (++anArgIter < theArgNb) | |
12183 | { | |
12184 | TCollection_AsciiString aStateStr(theArgVec[anArgIter]); | |
12185 | aStateStr.LowerCase(); | |
12186 | bool toEnable = true; | |
12187 | if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable)) | |
12188 | { | |
12189 | aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off; | |
12190 | } | |
12191 | else if (aStateStr == "noupdate" | |
12192 | || aStateStr == "freeze") | |
12193 | { | |
12194 | aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate; | |
12195 | } | |
12196 | else | |
12197 | { | |
12198 | --anArgIter; | |
12199 | } | |
12200 | } | |
12201 | aParams.FrustumCullingState = aState; | |
12202 | } | |
e276548b | 12203 | else |
12204 | { | |
bc8c79bb | 12205 | std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n"; |
12206 | return 1; | |
e276548b | 12207 | } |
12208 | } | |
189f85a3 | 12209 | |
12210 | return 0; | |
12211 | } | |
12212 | ||
79b544e6 | 12213 | //======================================================================= |
12214 | //function : searchInfo | |
12215 | //purpose : | |
12216 | //======================================================================= | |
12217 | inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict, | |
12218 | const TCollection_AsciiString& theKey) | |
12219 | { | |
12220 | for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next()) | |
12221 | { | |
12222 | if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False)) | |
12223 | { | |
12224 | return anIter.Value(); | |
12225 | } | |
12226 | } | |
12227 | return TCollection_AsciiString(); | |
12228 | } | |
12229 | ||
12230 | //======================================================================= | |
12231 | //function : VStatProfiler | |
12232 | //purpose : | |
12233 | //======================================================================= | |
12234 | static Standard_Integer VStatProfiler (Draw_Interpretor& theDI, | |
12235 | Standard_Integer theArgNb, | |
12236 | const char** theArgVec) | |
12237 | { | |
12238 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
12239 | if (aView.IsNull()) | |
12240 | { | |
12241 | std::cerr << "Error: no active viewer!\n"; | |
12242 | return 1; | |
12243 | } | |
12244 | ||
12245 | Standard_Boolean toRedraw = Standard_True; | |
12246 | Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats; | |
12247 | Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval; | |
12248 | Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE; | |
12249 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
12250 | { | |
12251 | Standard_CString anArg (theArgVec[anArgIter]); | |
12252 | TCollection_AsciiString aFlag (anArg); | |
12253 | aFlag.LowerCase(); | |
12254 | if (aFlag == "-noredraw") | |
12255 | { | |
12256 | toRedraw = Standard_False; | |
12257 | } | |
12258 | else | |
12259 | { | |
12260 | Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE; | |
12261 | if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate; | |
12262 | else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU; | |
12263 | else if (aFlag == "alllayers" | |
12264 | || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers; | |
12265 | else if (aFlag == "allstructs" | |
12266 | || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures; | |
12267 | else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups; | |
12268 | else if (aFlag == "allarrays" | |
12269 | || aFlag == "fillarrays" | |
12270 | || aFlag == "linearrays" | |
12271 | || aFlag == "pointarrays" | |
12272 | || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays; | |
12273 | else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles; | |
12274 | else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points; | |
12275 | else if (aFlag == "geommem" | |
12276 | || aFlag == "texturemem" | |
12277 | || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem; | |
12278 | else if (aFlag == "elapsedframe" | |
12279 | || aFlag == "cpuframeaverage" | |
12280 | || aFlag == "cpupickingaverage" | |
12281 | || aFlag == "cpucullingaverage" | |
12282 | || aFlag == "cpudynaverage" | |
12283 | || aFlag == "cpuframemax" | |
12284 | || aFlag == "cpupickingmax" | |
12285 | || aFlag == "cpucullingmax" | |
12286 | || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime; | |
12287 | else | |
12288 | { | |
12289 | std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n"; | |
12290 | continue; | |
12291 | } | |
12292 | ||
12293 | aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam); | |
12294 | } | |
12295 | } | |
12296 | ||
12297 | if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE) | |
12298 | { | |
12299 | aView->ChangeRenderingParams().CollectedStats = | |
12300 | Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams); | |
12301 | ||
12302 | if (toRedraw) | |
12303 | { | |
12304 | aView->ChangeRenderingParams().StatsUpdateInterval = -1; | |
12305 | aView->Redraw(); | |
12306 | aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval; | |
12307 | } | |
12308 | ||
12309 | TColStd_IndexedDataMapOfStringString aDict; | |
12310 | aView->StatisticInformation (aDict); | |
12311 | ||
12312 | aView->ChangeRenderingParams().CollectedStats = aPrevCounters; | |
12313 | ||
12314 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
12315 | { | |
12316 | Standard_CString anArg(theArgVec[anArgIter]); | |
12317 | TCollection_AsciiString aFlag(anArg); | |
12318 | aFlag.LowerCase(); | |
12319 | if (aFlag == "fps") | |
12320 | { | |
12321 | theDI << searchInfo (aDict, "FPS") << " "; | |
12322 | } | |
12323 | else if (aFlag == "cpu") | |
12324 | { | |
12325 | theDI << searchInfo (aDict, "CPU FPS") << " "; | |
12326 | } | |
12327 | else if (aFlag == "alllayers") | |
12328 | { | |
12329 | theDI << searchInfo (aDict, "Layers") << " "; | |
12330 | } | |
12331 | else if (aFlag == "layers") | |
12332 | { | |
12333 | theDI << searchInfo (aDict, "Rendered layers") << " "; | |
12334 | } | |
12335 | else if (aFlag == "allstructs") | |
12336 | { | |
12337 | theDI << searchInfo (aDict, "Structs") << " "; | |
12338 | } | |
12339 | else if (aFlag == "structs") | |
12340 | { | |
12341 | theDI << searchInfo (aDict, "Rendered structs") << " "; | |
12342 | } | |
12343 | else if (aFlag == "groups") | |
12344 | { | |
12345 | theDI << searchInfo (aDict, "Rendered groups") << " "; | |
12346 | } | |
12347 | else if (aFlag == "allarrays") | |
12348 | { | |
12349 | theDI << searchInfo (aDict, "Rendered arrays") << " "; | |
12350 | } | |
12351 | else if (aFlag == "fillarrays") | |
12352 | { | |
12353 | theDI << searchInfo (aDict, "Rendered [fill] arrays") << " "; | |
12354 | } | |
12355 | else if (aFlag == "linearrays") | |
12356 | { | |
12357 | theDI << searchInfo (aDict, "Rendered [line] arrays") << " "; | |
12358 | } | |
12359 | else if (aFlag == "pointarrays") | |
12360 | { | |
12361 | theDI << searchInfo (aDict, "Rendered [point] arrays") << " "; | |
12362 | } | |
12363 | else if (aFlag == "textarrays") | |
12364 | { | |
12365 | theDI << searchInfo (aDict, "Rendered [text] arrays") << " "; | |
12366 | } | |
12367 | else if (aFlag == "triangles") | |
12368 | { | |
12369 | theDI << searchInfo (aDict, "Rendered triangles") << " "; | |
12370 | } | |
12371 | else if (aFlag == "points") | |
12372 | { | |
12373 | theDI << searchInfo (aDict, "Rendered points") << " "; | |
12374 | } | |
12375 | else if (aFlag == "geommem") | |
12376 | { | |
12377 | theDI << searchInfo (aDict, "GPU Memory [geometry]") << " "; | |
12378 | } | |
12379 | else if (aFlag == "texturemem") | |
12380 | { | |
12381 | theDI << searchInfo (aDict, "GPU Memory [textures]") << " "; | |
12382 | } | |
12383 | else if (aFlag == "framemem") | |
12384 | { | |
12385 | theDI << searchInfo (aDict, "GPU Memory [frames]") << " "; | |
12386 | } | |
12387 | else if (aFlag == "elapsedframe") | |
12388 | { | |
12389 | theDI << searchInfo (aDict, "Elapsed Frame (average)") << " "; | |
12390 | } | |
12391 | else if (aFlag == "cpuframe_average") | |
12392 | { | |
12393 | theDI << searchInfo (aDict, "CPU Frame (average)") << " "; | |
12394 | } | |
12395 | else if (aFlag == "cpupicking_average") | |
12396 | { | |
12397 | theDI << searchInfo (aDict, "CPU Picking (average)") << " "; | |
12398 | } | |
12399 | else if (aFlag == "cpuculling_average") | |
12400 | { | |
12401 | theDI << searchInfo (aDict, "CPU Culling (average)") << " "; | |
12402 | } | |
12403 | else if (aFlag == "cpudyn_average") | |
12404 | { | |
12405 | theDI << searchInfo (aDict, "CPU Dynamics (average)") << " "; | |
12406 | } | |
12407 | else if (aFlag == "cpuframe_max") | |
12408 | { | |
12409 | theDI << searchInfo (aDict, "CPU Frame (max)") << " "; | |
12410 | } | |
12411 | else if (aFlag == "cpupicking_max") | |
12412 | { | |
12413 | theDI << searchInfo (aDict, "CPU Picking (max)") << " "; | |
12414 | } | |
12415 | else if (aFlag == "cpuculling_max") | |
12416 | { | |
12417 | theDI << searchInfo (aDict, "CPU Culling (max)") << " "; | |
12418 | } | |
12419 | else if (aFlag == "cpudyn_max") | |
12420 | { | |
12421 | theDI << searchInfo (aDict, "CPU Dynamics (max)") << " "; | |
12422 | } | |
12423 | } | |
12424 | } | |
12425 | else | |
12426 | { | |
12427 | if (toRedraw) | |
12428 | { | |
12429 | aView->ChangeRenderingParams().StatsUpdateInterval = -1; | |
12430 | aView->Redraw(); | |
12431 | aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval; | |
12432 | } | |
12433 | theDI << "Statistic info:\n" << aView->StatisticInformation(); | |
12434 | } | |
12435 | return 0; | |
12436 | } | |
12437 | ||
0717ddc1 | 12438 | //======================================================================= |
12439 | //function : VXRotate | |
12440 | //purpose : | |
12441 | //======================================================================= | |
12442 | static Standard_Integer VXRotate (Draw_Interpretor& di, | |
12443 | Standard_Integer argc, | |
12444 | const char ** argv) | |
12445 | { | |
12446 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
12447 | if (aContext.IsNull()) | |
12448 | { | |
586db386 | 12449 | di << argv[0] << "ERROR : use 'vinit' command before \n"; |
0717ddc1 | 12450 | return 1; |
12451 | } | |
8693dfd0 | 12452 | |
0717ddc1 | 12453 | if (argc != 3) |
12454 | { | |
586db386 | 12455 | di << "ERROR : Usage : " << argv[0] << " name angle\n"; |
0717ddc1 | 12456 | return 1; |
12457 | } | |
12458 | ||
12459 | TCollection_AsciiString aName (argv[1]); | |
12460 | Standard_Real anAngle = Draw::Atof (argv[2]); | |
12461 | ||
12462 | // find object | |
12463 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
12464 | Handle(AIS_InteractiveObject) anIObj; | |
8f521168 | 12465 | if (!aMap.Find2 (aName, anIObj)) |
0717ddc1 | 12466 | { |
586db386 | 12467 | di << "Use 'vdisplay' before\n"; |
0717ddc1 | 12468 | return 1; |
12469 | } | |
0717ddc1 | 12470 | |
8f521168 | 12471 | gp_Trsf aTransform; |
12472 | aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle); | |
12473 | aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart()); | |
0717ddc1 | 12474 | |
8f521168 | 12475 | aContext->SetLocation (anIObj, aTransform); |
12476 | aContext->UpdateCurrentViewer(); | |
0717ddc1 | 12477 | return 0; |
12478 | } | |
12479 | ||
625e1958 | 12480 | //=============================================================================================== |
12481 | //class : ViewerTest_AISManipulator | |
12482 | //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances | |
12483 | //=============================================================================================== | |
12484 | DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator) | |
12485 | ||
12486 | class ViewerTest_AISManipulator : public AIS_Manipulator | |
12487 | { | |
12488 | public: | |
12489 | ||
12490 | ViewerTest_AISManipulator() : AIS_Manipulator() | |
12491 | { | |
12492 | GetMapOfAISManipulators().Add (this); | |
12493 | } | |
12494 | ||
12495 | virtual ~ViewerTest_AISManipulator() | |
12496 | { | |
12497 | GetMapOfAISManipulators().Remove (this); | |
12498 | } | |
12499 | ||
12500 | DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator) | |
12501 | }; | |
12502 | ||
12503 | IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator) | |
12504 | IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator) | |
12505 | ||
12506 | //=============================================================================================== | |
12507 | //function : VManipulator | |
12508 | //purpose : | |
12509 | //=============================================================================================== | |
12510 | static int VManipulator (Draw_Interpretor& theDi, | |
12511 | Standard_Integer theArgsNb, | |
12512 | const char** theArgVec) | |
12513 | { | |
bbf3fcde | 12514 | Handle(V3d_View) aCurrentView = ViewerTest::CurrentView(); |
625e1958 | 12515 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); |
12516 | ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False); | |
bbf3fcde | 12517 | if (aCurrentView.IsNull() |
625e1958 | 12518 | || aViewer.IsNull()) |
12519 | { | |
12520 | std::cerr << "No active viewer!\n"; | |
12521 | return 1; | |
12522 | } | |
12523 | ||
12524 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView()); | |
12525 | Standard_Integer anArgIter = 1; | |
12526 | for (; anArgIter < theArgsNb; ++anArgIter) | |
12527 | { | |
12528 | anUpdateTool.parseRedrawMode (theArgVec[anArgIter]); | |
12529 | } | |
12530 | ||
12531 | ViewerTest_CmdParser aCmd; | |
293211ae | 12532 | aCmd.SetDescription ("Manages manipulator for interactive objects:"); |
625e1958 | 12533 | aCmd.AddOption ("attach", "... object - attach manipulator to an object"); |
12534 | aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching"); | |
12535 | aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching "); | |
12536 | aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching "); | |
bbf3fcde | 12537 | aCmd.AddOption ("view", "... {active | [view name]} - define view in which manipulator will be displayed, 'all' by default"); |
625e1958 | 12538 | aCmd.AddOption ("detach", "... - detach manipulator"); |
12539 | ||
12540 | aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation"); | |
12541 | aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation"); | |
12542 | aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation"); | |
12543 | ||
12544 | aCmd.AddOption ("move", "... x y z - move object"); | |
12545 | aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object"); | |
12546 | aCmd.AddOption ("scale", "... factor - scale object"); | |
12547 | ||
12548 | aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection"); | |
12549 | aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform"); | |
12550 | aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform"); | |
f522ce50 | 12551 | aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform"); |
625e1958 | 12552 | aCmd.AddOption ("gap", "... value - set gap between sub-parts"); |
12553 | aCmd.AddOption ("part", "... axis mode {0|1} - set visual part"); | |
84b904bc | 12554 | aCmd.AddOption ("parts", "... all axes mode {0|1} - set visual part"); |
625e1958 | 12555 | aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator"); |
12556 | aCmd.AddOption ("size", "... size - set size of manipulator"); | |
12557 | aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence"); | |
12558 | ||
12559 | aCmd.Parse (theArgsNb, theArgVec); | |
12560 | ||
12561 | if (aCmd.HasOption ("help")) | |
12562 | { | |
12563 | theDi.PrintHelp (theArgVec[0]); | |
12564 | return 0; | |
12565 | } | |
12566 | ||
12567 | ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS(); | |
12568 | ||
293211ae | 12569 | TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str()); |
625e1958 | 12570 | |
12571 | if (aName.IsEmpty()) | |
12572 | { | |
12573 | std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n"; | |
12574 | return 1; | |
12575 | } | |
12576 | ||
12577 | // ---------------------------------- | |
12578 | // detach existing manipulator object | |
12579 | // ---------------------------------- | |
12580 | ||
12581 | if (aCmd.HasOption ("detach")) | |
12582 | { | |
12583 | if (!aMapAIS.IsBound2 (aName)) | |
12584 | { | |
12585 | std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n"; | |
12586 | return 1; | |
12587 | } | |
12588 | ||
12589 | Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName)); | |
12590 | if (aManipulator.IsNull()) | |
12591 | { | |
12592 | std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n"; | |
12593 | return 1; | |
12594 | } | |
12595 | ||
12596 | aManipulator->Detach(); | |
12597 | aMapAIS.UnBind2 (aName); | |
0577ae8c | 12598 | ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True); |
625e1958 | 12599 | |
12600 | return 0; | |
12601 | } | |
12602 | ||
12603 | // ----------------------------------------------- | |
12604 | // find or create manipulator if it does not exist | |
12605 | // ----------------------------------------------- | |
12606 | ||
12607 | Handle(AIS_Manipulator) aManipulator; | |
12608 | if (!aMapAIS.IsBound2 (aName)) | |
12609 | { | |
12610 | std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n"; | |
12611 | ||
12612 | aManipulator = new ViewerTest_AISManipulator(); | |
49582f9d | 12613 | aManipulator->SetModeActivationOnDetection (true); |
625e1958 | 12614 | aMapAIS.Bind (aManipulator, aName); |
12615 | } | |
12616 | else | |
12617 | { | |
12618 | aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName)); | |
12619 | if (aManipulator.IsNull()) | |
12620 | { | |
12621 | std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n"; | |
12622 | return 1; | |
12623 | } | |
12624 | } | |
12625 | ||
12626 | // ----------------------------------------- | |
12627 | // change properties of manipulator instance | |
12628 | // ----------------------------------------- | |
12629 | ||
12630 | if (aCmd.HasOption ("autoActivate", 1, Standard_True)) | |
12631 | { | |
12632 | aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate")); | |
12633 | } | |
12634 | if (aCmd.HasOption ("followTranslation", 1, Standard_True)) | |
12635 | { | |
12636 | aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation")); | |
12637 | } | |
12638 | if (aCmd.HasOption ("followRotation", 1, Standard_True)) | |
12639 | { | |
12640 | aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation")); | |
12641 | } | |
f522ce50 | 12642 | if (aCmd.HasOption("followDragging", 1, Standard_True)) |
12643 | { | |
12644 | aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging")); | |
12645 | } | |
625e1958 | 12646 | if (aCmd.HasOption ("gap", 1, Standard_True)) |
12647 | { | |
12648 | aManipulator->SetGap (aCmd.ArgFloat ("gap")); | |
12649 | } | |
12650 | if (aCmd.HasOption ("part", 3, Standard_True)) | |
12651 | { | |
12652 | Standard_Integer anAxis = aCmd.ArgInt ("part", 0); | |
12653 | Standard_Integer aMode = aCmd.ArgInt ("part", 1); | |
12654 | Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2); | |
f522ce50 | 12655 | if (aMode < 1 || aMode > 4) |
625e1958 | 12656 | { |
f522ce50 | 12657 | std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n"; |
625e1958 | 12658 | return 1; |
12659 | } | |
12660 | ||
12661 | aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff); | |
12662 | } | |
84b904bc | 12663 | if (aCmd.HasOption("parts", 2, Standard_True)) |
12664 | { | |
12665 | Standard_Integer aMode = aCmd.ArgInt("parts", 0); | |
12666 | Standard_Boolean aOnOff = aCmd.ArgBool("parts", 1); | |
12667 | if (aMode < 1 || aMode > 4) | |
12668 | { | |
12669 | std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n"; | |
12670 | return 1; | |
12671 | } | |
12672 | ||
12673 | aManipulator->SetPart(static_cast<AIS_ManipulatorMode>(aMode), aOnOff); | |
12674 | } | |
625e1958 | 12675 | if (aCmd.HasOption ("pos", 3, Standard_True)) |
12676 | { | |
12677 | gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0); | |
12678 | gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction(); | |
12679 | gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection(); | |
12680 | ||
12681 | aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir)); | |
12682 | } | |
12683 | if (aCmd.HasOption ("size", 1, Standard_True)) | |
12684 | { | |
12685 | aManipulator->SetSize (aCmd.ArgFloat ("size")); | |
12686 | } | |
12687 | if (aCmd.HasOption ("zoomable", 1, Standard_True)) | |
12688 | { | |
12689 | aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable")); | |
12690 | ||
12691 | if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator)) | |
12692 | { | |
12693 | ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False); | |
12694 | ViewerTest::GetAISContext()->Display (aManipulator, Standard_False); | |
12695 | } | |
12696 | } | |
12697 | ||
12698 | // --------------------------------------------------- | |
12699 | // attach, detach or access manipulator from an object | |
12700 | // --------------------------------------------------- | |
12701 | ||
12702 | if (aCmd.HasOption ("attach")) | |
12703 | { | |
12704 | // Find an object and attach manipulator to it | |
12705 | if (!aCmd.HasOption ("attach", 1, Standard_True)) | |
12706 | { | |
12707 | return 1; | |
12708 | } | |
12709 | ||
12710 | TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str()); | |
8f521168 | 12711 | Handle(AIS_InteractiveObject) anObject; |
12712 | if (!aMapAIS.Find2 (anObjName, anObject)) | |
625e1958 | 12713 | { |
12714 | std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n"; | |
12715 | return 1; | |
12716 | } | |
12717 | ||
8f521168 | 12718 | for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next()) |
625e1958 | 12719 | { |
12720 | if (anIt.Value()->IsAttached() | |
12721 | && anIt.Value()->Object() == anObject) | |
12722 | { | |
12723 | std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n"; | |
12724 | return 1; | |
12725 | } | |
12726 | } | |
12727 | ||
12728 | AIS_Manipulator::OptionsForAttach anOptions; | |
12729 | if (aCmd.HasOption ("adjustPosition", 1, Standard_True)) | |
12730 | { | |
12731 | anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition")); | |
12732 | } | |
12733 | if (aCmd.HasOption ("adjustSize", 1, Standard_True)) | |
12734 | { | |
12735 | anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize")); | |
12736 | } | |
12737 | if (aCmd.HasOption ("enableModes", 1, Standard_True)) | |
12738 | { | |
12739 | anOptions.SetEnableModes (aCmd.ArgBool ("enableModes")); | |
12740 | } | |
12741 | ||
12742 | aManipulator->Attach (anObject, anOptions); | |
bbf3fcde | 12743 | |
12744 | // Check view option | |
12745 | if (aCmd.HasOption ("view")) | |
12746 | { | |
12747 | if (!aCmd.HasOption ("view", 1, Standard_True)) | |
12748 | { | |
12749 | return 1; | |
12750 | } | |
12751 | TCollection_AsciiString aViewString (aCmd.Arg ("view", 0).c_str()); | |
12752 | Handle(V3d_View) aView; | |
12753 | if (aViewString.IsEqual ("active")) | |
12754 | { | |
12755 | aView = ViewerTest::CurrentView(); | |
12756 | } | |
12757 | else // Check view name | |
12758 | { | |
12759 | ViewerTest_Names aViewNames (aViewString); | |
12760 | if (!ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) | |
12761 | { | |
12762 | std::cerr << theArgVec[0] << " error: wrong view name '" << aViewString << "'\n"; | |
12763 | return 1; | |
12764 | } | |
12765 | aView = ViewerTest_myViews.Find1 (aViewNames.GetViewName()); | |
12766 | if (aView.IsNull()) | |
12767 | { | |
12768 | std::cerr << theArgVec[0] << " error: cannot find view with name '" << aViewString << "'\n"; | |
12769 | return 1; | |
12770 | } | |
12771 | } | |
12772 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
12773 | anIter (ViewerTest_myViews); anIter.More(); anIter.Next()) | |
12774 | { | |
12775 | ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, anIter.Value(), Standard_False); | |
12776 | } | |
12777 | ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, aView, Standard_True); | |
12778 | } | |
625e1958 | 12779 | } |
12780 | ||
12781 | // -------------------------------------- | |
12782 | // apply transformation using manipulator | |
12783 | // -------------------------------------- | |
12784 | ||
12785 | if (aCmd.HasOption ("startTransform", 2, Standard_True)) | |
12786 | { | |
12787 | aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView()); | |
12788 | } | |
12789 | if (aCmd.HasOption ("transform", 2, Standard_True)) | |
12790 | { | |
12791 | aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView()); | |
12792 | } | |
12793 | if (aCmd.HasOption ("stopTransform")) | |
12794 | { | |
12795 | Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort"); | |
12796 | ||
12797 | aManipulator->StopTransform (toApply); | |
12798 | } | |
12799 | ||
12800 | gp_Trsf aT; | |
12801 | if (aCmd.HasOption ("move", 3, Standard_True)) | |
12802 | { | |
12803 | aT.SetTranslationPart (aCmd.ArgVec ("move")); | |
12804 | } | |
12805 | if (aCmd.HasOption ("rotate", 7, Standard_True)) | |
12806 | { | |
12807 | aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6)); | |
12808 | } | |
12809 | if (aCmd.HasOption ("scale", 1)) | |
12810 | { | |
12811 | aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale")); | |
12812 | } | |
12813 | ||
12814 | if (aT.Form() != gp_Identity) | |
12815 | { | |
12816 | aManipulator->Transform (aT); | |
12817 | } | |
12818 | ||
0577ae8c | 12819 | ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True); |
625e1958 | 12820 | |
12821 | return 0; | |
12822 | } | |
12823 | ||
8e5fb5ea | 12824 | //=============================================================================================== |
12825 | //function : VSelectionProperties | |
12826 | //purpose : | |
12827 | //=============================================================================================== | |
12828 | static int VSelectionProperties (Draw_Interpretor& theDi, | |
12829 | Standard_Integer theArgsNb, | |
12830 | const char** theArgVec) | |
12831 | { | |
12832 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
12833 | if (aCtx.IsNull()) | |
12834 | { | |
12835 | std::cerr << "No active viewer!\n"; | |
12836 | return 1; | |
12837 | } | |
12838 | ||
be3d8cbc | 12839 | if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected") |
12840 | { | |
12841 | // handle obsolete alias | |
12842 | bool toEnable = true; | |
12843 | if (theArgsNb < 2) | |
12844 | { | |
12845 | theDi << (aCtx->ToHilightSelected() ? "on" : "off"); | |
12846 | return 0; | |
12847 | } | |
12848 | else if (theArgsNb != 2 | |
12849 | || !ViewerTest::ParseOnOff (theArgVec[1], toEnable)) | |
12850 | { | |
12851 | std::cout << "Syntax error: wrong number of parameters."; | |
12852 | return 1; | |
12853 | } | |
12854 | if (toEnable != aCtx->ToHilightSelected()) | |
12855 | { | |
12856 | aCtx->ClearDetected(); | |
12857 | aCtx->SetToHilightSelected (toEnable); | |
12858 | } | |
12859 | return 0; | |
12860 | } | |
12861 | ||
f838dac4 | 12862 | Standard_Boolean toPrint = theArgsNb == 1; |
12863 | Standard_Boolean toRedraw = Standard_False; | |
12864 | Standard_Integer anArgIter = 1; | |
12865 | Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None; | |
12866 | if (anArgIter < theArgsNb) | |
12867 | { | |
12868 | TCollection_AsciiString anArgFirst (theArgVec[anArgIter]); | |
12869 | anArgFirst.LowerCase(); | |
12870 | ++anArgIter; | |
12871 | if (anArgFirst == "dynhighlight" | |
12872 | || anArgFirst == "dynhilight" | |
12873 | || anArgFirst == "dynamichighlight" | |
12874 | || anArgFirst == "dynamichilight") | |
12875 | { | |
12876 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
12877 | } | |
12878 | else if (anArgFirst == "localdynhighlight" | |
12879 | || anArgFirst == "localdynhilight" | |
12880 | || anArgFirst == "localdynamichighlight" | |
12881 | || anArgFirst == "localdynamichilight") | |
12882 | { | |
12883 | aType = Prs3d_TypeOfHighlight_LocalDynamic; | |
12884 | } | |
12885 | else if (anArgFirst == "selhighlight" | |
12886 | || anArgFirst == "selhilight" | |
12887 | || anArgFirst == "selectedhighlight" | |
12888 | || anArgFirst == "selectedhilight") | |
12889 | { | |
12890 | aType = Prs3d_TypeOfHighlight_Selected; | |
12891 | } | |
12892 | else if (anArgFirst == "localselhighlight" | |
12893 | || anArgFirst == "localselhilight" | |
12894 | || anArgFirst == "localselectedhighlight" | |
12895 | || anArgFirst == "localselectedhilight") | |
12896 | { | |
12897 | aType = Prs3d_TypeOfHighlight_LocalSelected; | |
12898 | } | |
12899 | else | |
12900 | { | |
12901 | --anArgIter; | |
12902 | } | |
12903 | } | |
12904 | for (; anArgIter < theArgsNb; ++anArgIter) | |
12905 | { | |
12906 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
12907 | anArg.LowerCase(); | |
12908 | if (anArg == "-help") | |
12909 | { | |
12910 | theDi.PrintHelp (theArgVec[0]); | |
12911 | return 0; | |
12912 | } | |
12913 | else if (anArg == "-print") | |
12914 | { | |
12915 | toPrint = Standard_True; | |
12916 | } | |
12917 | else if (anArg == "-autoactivate") | |
12918 | { | |
12919 | Standard_Boolean toEnable = Standard_True; | |
12920 | if (anArgIter + 1 < theArgsNb | |
12921 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
12922 | { | |
12923 | ++anArgIter; | |
12924 | } | |
12925 | aCtx->SetAutoActivateSelection (toEnable); | |
12926 | } | |
be3d8cbc | 12927 | else if (anArg == "-automatichighlight" |
12928 | || anArg == "-automatichilight" | |
12929 | || anArg == "-autohighlight" | |
12930 | || anArg == "-autohilight") | |
12931 | { | |
12932 | Standard_Boolean toEnable = Standard_True; | |
12933 | if (anArgIter + 1 < theArgsNb | |
12934 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
12935 | { | |
12936 | ++anArgIter; | |
12937 | } | |
12938 | aCtx->ClearSelected (false); | |
12939 | aCtx->ClearDetected(); | |
12940 | aCtx->SetAutomaticHilight (toEnable); | |
12941 | toRedraw = true; | |
12942 | } | |
12943 | else if (anArg == "-highlightselected" | |
12944 | || anArg == "-hilightselected") | |
12945 | { | |
12946 | Standard_Boolean toEnable = Standard_True; | |
12947 | if (anArgIter + 1 < theArgsNb | |
12948 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
12949 | { | |
12950 | ++anArgIter; | |
12951 | } | |
12952 | aCtx->ClearDetected(); | |
12953 | aCtx->SetToHilightSelected (toEnable); | |
12954 | toRedraw = true; | |
12955 | } | |
14c4193d | 12956 | else if (anArg == "-pickstrategy" |
12957 | || anArg == "-pickingstrategy") | |
12958 | { | |
12959 | if (++anArgIter >= theArgsNb) | |
12960 | { | |
12961 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
12962 | return 1; | |
12963 | } | |
12964 | ||
12965 | SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable; | |
12966 | TCollection_AsciiString aVal (theArgVec[anArgIter]); | |
12967 | aVal.LowerCase(); | |
12968 | if (aVal == "first" | |
12969 | || aVal == "firstaccepted" | |
12970 | || aVal == "firstacceptable") | |
12971 | { | |
12972 | aStrategy = SelectMgr_PickingStrategy_FirstAcceptable; | |
12973 | } | |
12974 | else if (aVal == "topmost" | |
12975 | || aVal == "onlyTopmost") | |
12976 | { | |
12977 | aStrategy = SelectMgr_PickingStrategy_OnlyTopmost; | |
12978 | } | |
12979 | else | |
12980 | { | |
12981 | std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n"; | |
12982 | return 1; | |
12983 | } | |
12984 | ||
12985 | aCtx->SetPickingStrategy (aStrategy); | |
12986 | } | |
f838dac4 | 12987 | else if (anArg == "-pixtol" |
12988 | && anArgIter + 1 < theArgsNb) | |
12989 | { | |
12990 | aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter])); | |
12991 | } | |
12992 | else if ((anArg == "-mode" | |
12993 | || anArg == "-dispmode") | |
12994 | && anArgIter + 1 < theArgsNb) | |
12995 | { | |
12996 | if (aType == Prs3d_TypeOfHighlight_None) | |
12997 | { | |
12998 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
12999 | return 1; | |
13000 | } | |
8e5fb5ea | 13001 | |
f838dac4 | 13002 | const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]); |
13003 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); | |
13004 | aStyle->SetDisplayMode (aDispMode); | |
13005 | toRedraw = Standard_True; | |
13006 | } | |
13007 | else if (anArg == "-layer" | |
13008 | && anArgIter + 1 < theArgsNb) | |
13009 | { | |
13010 | if (aType == Prs3d_TypeOfHighlight_None) | |
13011 | { | |
13012 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
13013 | return 1; | |
13014 | } | |
8e5fb5ea | 13015 | |
55c8f0f7 BB |
13016 | ++anArgIter; |
13017 | Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN; | |
13018 | if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer)) | |
f838dac4 | 13019 | { |
55c8f0f7 BB |
13020 | std::cerr << "Error: wrong syntax at " << theArgVec[anArgIter] << ".\n"; |
13021 | return 1; | |
f838dac4 | 13022 | } |
8e5fb5ea | 13023 | |
f838dac4 | 13024 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
13025 | aStyle->SetZLayer (aNewLayer); | |
13026 | toRedraw = Standard_True; | |
13027 | } | |
13028 | else if (anArg == "-hicolor" | |
13029 | || anArg == "-selcolor" | |
13030 | || anArg == "-color") | |
13031 | { | |
13032 | if (anArg.StartsWith ("-hi")) | |
13033 | { | |
13034 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
13035 | } | |
13036 | else if (anArg.StartsWith ("-sel")) | |
13037 | { | |
13038 | aType = Prs3d_TypeOfHighlight_Selected; | |
13039 | } | |
13040 | else if (aType == Prs3d_TypeOfHighlight_None) | |
13041 | { | |
13042 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
13043 | return 1; | |
13044 | } | |
8e5fb5ea | 13045 | |
f838dac4 | 13046 | Quantity_Color aColor; |
13047 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1, | |
13048 | theArgVec + anArgIter + 1, | |
13049 | aColor); | |
13050 | if (aNbParsed == 0) | |
13051 | { | |
13052 | std::cout << "Syntax error: need more arguments.\n"; | |
13053 | return 1; | |
13054 | } | |
13055 | anArgIter += aNbParsed; | |
8e5fb5ea | 13056 | |
f838dac4 | 13057 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
13058 | aStyle->SetColor (aColor); | |
13059 | toRedraw = Standard_True; | |
13060 | } | |
13061 | else if ((anArg == "-transp" | |
13062 | || anArg == "-transparency" | |
13063 | || anArg == "-hitransp" | |
13064 | || anArg == "-seltransp" | |
13065 | || anArg == "-hitransplocal" | |
13066 | || anArg == "-seltransplocal") | |
13067 | && anArgIter + 1 < theArgsNb) | |
13068 | { | |
13069 | if (anArg.StartsWith ("-hi")) | |
13070 | { | |
13071 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
13072 | } | |
13073 | else if (anArg.StartsWith ("-sel")) | |
13074 | { | |
13075 | aType = Prs3d_TypeOfHighlight_Selected; | |
13076 | } | |
13077 | else if (aType == Prs3d_TypeOfHighlight_None) | |
13078 | { | |
13079 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
13080 | return 1; | |
13081 | } | |
8e5fb5ea | 13082 | |
f838dac4 | 13083 | const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]); |
13084 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); | |
13085 | aStyle->SetTransparency ((Standard_ShortReal )aTransp); | |
13086 | toRedraw = Standard_True; | |
13087 | } | |
13088 | else if ((anArg == "-mat" | |
13089 | || anArg == "-material") | |
13090 | && anArgIter + 1 < theArgsNb) | |
13091 | { | |
13092 | if (aType == Prs3d_TypeOfHighlight_None) | |
13093 | { | |
13094 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
13095 | return 1; | |
13096 | } | |
8e5fb5ea | 13097 | |
f838dac4 | 13098 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
13099 | Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]); | |
13100 | if (aMatName != Graphic3d_NOM_DEFAULT) | |
13101 | { | |
13102 | ++anArgIter; | |
13103 | Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d(); | |
13104 | *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect(); | |
13105 | Graphic3d_MaterialAspect aMat (aMatName); | |
13106 | aMat.SetColor (aStyle->Color()); | |
13107 | aMat.SetTransparency (aStyle->Transparency()); | |
13108 | anAspect->SetFrontMaterial (aMat); | |
13109 | anAspect->SetInteriorColor (aStyle->Color()); | |
13110 | aStyle->SetBasicFillAreaAspect (anAspect); | |
13111 | } | |
13112 | else | |
13113 | { | |
13114 | aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)()); | |
13115 | } | |
13116 | toRedraw = Standard_True; | |
13117 | } | |
13118 | else | |
13119 | { | |
13120 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
13121 | } | |
8e5fb5ea | 13122 | } |
13123 | ||
f838dac4 | 13124 | if (toPrint) |
8e5fb5ea | 13125 | { |
f838dac4 | 13126 | const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle(); |
13127 | const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle(); | |
8e5fb5ea | 13128 | theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n"; |
be3d8cbc | 13129 | theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n"; |
13130 | theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n"; | |
8e5fb5ea | 13131 | theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n"; |
f838dac4 | 13132 | theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n"; |
13133 | theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n"; | |
13134 | theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n"; | |
13135 | theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n"; | |
13136 | theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n"; | |
13137 | theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n"; | |
13138 | theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n"; | |
13139 | theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n"; | |
8e5fb5ea | 13140 | } |
13141 | ||
13142 | if (aCtx->NbSelected() != 0 && toRedraw) | |
13143 | { | |
13144 | aCtx->HilightSelected (Standard_True); | |
13145 | } | |
13146 | ||
13147 | return 0; | |
13148 | } | |
13149 | ||
decdee7d | 13150 | //=============================================================================================== |
13151 | //function : VDumpSelectionImage | |
13152 | //purpose : | |
13153 | //=============================================================================================== | |
13154 | static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/, | |
13155 | Standard_Integer theArgsNb, | |
13156 | const char** theArgVec) | |
13157 | { | |
13158 | if (theArgsNb < 2) | |
13159 | { | |
13160 | std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n"; | |
13161 | return 1; | |
13162 | } | |
13163 | ||
13164 | const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext(); | |
13165 | if (aContext.IsNull()) | |
13166 | { | |
13167 | std::cout << "Error: no active view.\n"; | |
13168 | return 1; | |
13169 | } | |
13170 | ||
13171 | TCollection_AsciiString aFile; | |
13172 | StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth; | |
dc858f4c | 13173 | Image_Format anImgFormat = Image_Format_BGR; |
decdee7d | 13174 | Standard_Integer aPickedIndex = 1; |
13175 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
13176 | { | |
13177 | TCollection_AsciiString aParam (theArgVec[anArgIter]); | |
13178 | aParam.LowerCase(); | |
13179 | if (aParam == "-type") | |
13180 | { | |
13181 | if (++anArgIter >= theArgsNb) | |
13182 | { | |
13183 | std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n"; | |
13184 | return 1; | |
13185 | } | |
13186 | ||
13187 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
13188 | aValue.LowerCase(); | |
13189 | if (aValue == "depth" | |
13190 | || aValue == "normdepth" | |
13191 | || aValue == "normalizeddepth") | |
13192 | { | |
13193 | aType = StdSelect_TypeOfSelectionImage_NormalizedDepth; | |
dc858f4c | 13194 | anImgFormat = Image_Format_GrayF; |
decdee7d | 13195 | } |
13196 | if (aValue == "depthinverted" | |
13197 | || aValue == "normdepthinverted" | |
13198 | || aValue == "normalizeddepthinverted" | |
13199 | || aValue == "inverted") | |
13200 | { | |
13201 | aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted; | |
dc858f4c | 13202 | anImgFormat = Image_Format_GrayF; |
decdee7d | 13203 | } |
13204 | else if (aValue == "unnormdepth" | |
13205 | || aValue == "unnormalizeddepth") | |
13206 | { | |
13207 | aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth; | |
dc858f4c | 13208 | anImgFormat = Image_Format_GrayF; |
decdee7d | 13209 | } |
13210 | else if (aValue == "objectcolor" | |
13211 | || aValue == "object" | |
13212 | || aValue == "color") | |
13213 | { | |
13214 | aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject; | |
13215 | } | |
13216 | else if (aValue == "entitycolor" | |
13217 | || aValue == "entity") | |
13218 | { | |
13219 | aType = StdSelect_TypeOfSelectionImage_ColoredEntity; | |
13220 | } | |
13221 | else if (aValue == "ownercolor" | |
13222 | || aValue == "owner") | |
13223 | { | |
13224 | aType = StdSelect_TypeOfSelectionImage_ColoredOwner; | |
13225 | } | |
13226 | else if (aValue == "selectionmodecolor" | |
13227 | || aValue == "selectionmode" | |
13228 | || aValue == "selmodecolor" | |
13229 | || aValue == "selmode") | |
13230 | { | |
13231 | aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode; | |
13232 | } | |
13233 | } | |
13234 | else if (aParam == "-picked" | |
13235 | || aParam == "-pickeddepth" | |
13236 | || aParam == "-pickedindex") | |
13237 | { | |
13238 | if (++anArgIter >= theArgsNb) | |
13239 | { | |
13240 | std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n"; | |
13241 | return 1; | |
13242 | } | |
13243 | ||
13244 | aPickedIndex = Draw::Atoi (theArgVec[anArgIter]); | |
13245 | } | |
13246 | else if (aFile.IsEmpty()) | |
13247 | { | |
13248 | aFile = theArgVec[anArgIter]; | |
13249 | } | |
13250 | else | |
13251 | { | |
13252 | std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n"; | |
13253 | return 1; | |
13254 | } | |
13255 | } | |
13256 | if (aFile.IsEmpty()) | |
13257 | { | |
13258 | std::cout << "Syntax error: image file name is missing.\n"; | |
13259 | return 1; | |
13260 | } | |
13261 | ||
13262 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
13263 | Standard_Integer aWidth = 0, aHeight = 0; | |
13264 | aView->Window()->Size (aWidth, aHeight); | |
13265 | ||
13266 | Image_AlienPixMap aPixMap; | |
13267 | if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight)) | |
13268 | { | |
13269 | std::cout << "Error: can't allocate image.\n"; | |
13270 | return 1; | |
13271 | } | |
13272 | if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex)) | |
13273 | { | |
13274 | std::cout << "Error: can't generate selection image.\n"; | |
13275 | return 1; | |
13276 | } | |
13277 | if (!aPixMap.Save (aFile)) | |
13278 | { | |
13279 | std::cout << "Error: can't save selection image.\n"; | |
13280 | return 0; | |
13281 | } | |
13282 | return 0; | |
13283 | } | |
13284 | ||
2108d9a2 | 13285 | //=============================================================================================== |
13286 | //function : VViewCube | |
13287 | //purpose : | |
13288 | //=============================================================================================== | |
13289 | static int VViewCube (Draw_Interpretor& , | |
13290 | Standard_Integer theNbArgs, | |
13291 | const char** theArgVec) | |
13292 | { | |
13293 | const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext(); | |
13294 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
13295 | if (aContext.IsNull() || aView.IsNull()) | |
13296 | { | |
13297 | std::cout << "Error: no active view.\n"; | |
13298 | return 1; | |
13299 | } | |
13300 | else if (theNbArgs < 2) | |
13301 | { | |
13302 | std::cout << "Syntax error: wrong number arguments\n"; | |
13303 | return 1; | |
13304 | } | |
13305 | ||
13306 | Handle(AIS_ViewCube) aViewCube; | |
13307 | ViewerTest_AutoUpdater anUpdateTool (aContext, aView); | |
13308 | Quantity_Color aColorRgb; | |
13309 | TCollection_AsciiString aName; | |
13310 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
13311 | { | |
13312 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
13313 | anArg.LowerCase(); | |
13314 | if (anUpdateTool.parseRedrawMode (anArg)) | |
13315 | { | |
13316 | // | |
13317 | } | |
13318 | else if (aViewCube.IsNull()) | |
13319 | { | |
13320 | aName = theArgVec[anArgIter]; | |
13321 | if (aName.StartsWith ("-")) | |
13322 | { | |
13323 | std::cout << "Syntax error: object name should be specified.\n"; | |
13324 | return 1; | |
13325 | } | |
13326 | Handle(AIS_InteractiveObject) aPrs; | |
13327 | GetMapOfAIS().Find2 (aName, aPrs); | |
13328 | aViewCube = Handle(AIS_ViewCube)::DownCast (aPrs); | |
13329 | if (aViewCube.IsNull()) | |
13330 | { | |
13331 | aViewCube = new AIS_ViewCube(); | |
13332 | aViewCube->SetBoxColor (Quantity_NOC_GRAY50); | |
13333 | aViewCube->SetViewAnimation (ViewerTest::CurrentEventManager()->ViewAnimation()); | |
13334 | aViewCube->SetFixedAnimationLoop (false); | |
13335 | } | |
13336 | } | |
13337 | else if (anArg == "-reset") | |
13338 | { | |
13339 | aViewCube->ResetStyles(); | |
13340 | } | |
13341 | else if (anArg == "-color" | |
13342 | || anArg == "-boxcolor" | |
13343 | || anArg == "-boxsidecolor" | |
13344 | || anArg == "-sidecolor" | |
13345 | || anArg == "-boxedgecolor" | |
13346 | || anArg == "-edgecolor" | |
13347 | || anArg == "-boxcornercolor" | |
13348 | || anArg == "-cornercolor" | |
13349 | || anArg == "-innercolor" | |
13350 | || anArg == "-textcolor") | |
13351 | { | |
13352 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - anArgIter - 1, | |
13353 | theArgVec + anArgIter + 1, | |
13354 | aColorRgb); | |
13355 | if (aNbParsed == 0) | |
13356 | { | |
13357 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
13358 | return 1; | |
13359 | } | |
13360 | anArgIter += aNbParsed; | |
13361 | if (anArg == "-boxcolor") | |
13362 | { | |
13363 | aViewCube->SetBoxColor (aColorRgb); | |
13364 | } | |
13365 | else if (anArg == "-boxsidecolor" | |
13366 | || anArg == "-sidecolor") | |
13367 | { | |
13368 | aViewCube->BoxSideStyle()->SetColor (aColorRgb); | |
13369 | aViewCube->SynchronizeAspects(); | |
13370 | } | |
13371 | else if (anArg == "-boxedgecolor" | |
13372 | || anArg == "-edgecolor") | |
13373 | { | |
13374 | aViewCube->BoxEdgeStyle()->SetColor (aColorRgb); | |
13375 | aViewCube->SynchronizeAspects(); | |
13376 | } | |
13377 | else if (anArg == "-boxcornercolor" | |
13378 | || anArg == "-cornercolor") | |
13379 | { | |
13380 | aViewCube->BoxCornerStyle()->SetColor (aColorRgb); | |
13381 | aViewCube->SynchronizeAspects(); | |
13382 | } | |
13383 | else if (anArg == "-innercolor") | |
13384 | { | |
13385 | aViewCube->SetInnerColor (aColorRgb); | |
13386 | } | |
13387 | else if (anArg == "-textcolor") | |
13388 | { | |
13389 | aViewCube->SetTextColor (aColorRgb); | |
13390 | } | |
13391 | else | |
13392 | { | |
13393 | aViewCube->SetColor (aColorRgb); | |
13394 | } | |
13395 | } | |
13396 | else if (anArgIter + 1 < theNbArgs | |
13397 | && (anArg == "-transparency" | |
13398 | || anArg == "-boxtransparency")) | |
13399 | { | |
13400 | const Standard_Real aValue = Draw::Atof (theArgVec[++anArgIter]); | |
13401 | if (aValue < 0.0 || aValue > 1.0) | |
13402 | { | |
13403 | std::cout << "Syntax error: invalid transparency value " << theArgVec[anArgIter] << "\n"; | |
13404 | return 1; | |
13405 | } | |
13406 | ||
13407 | if (anArg == "-boxtransparency") | |
13408 | { | |
13409 | aViewCube->SetBoxTransparency (aValue); | |
13410 | } | |
13411 | else | |
13412 | { | |
13413 | aViewCube->SetTransparency (aValue); | |
13414 | } | |
13415 | } | |
13416 | else if (anArg == "-axes" | |
13417 | || anArg == "-edges" | |
13418 | || anArg == "-vertices" | |
13419 | || anArg == "-vertexes" | |
13420 | || anArg == "-fixedanimation") | |
13421 | { | |
13422 | bool toShow = true; | |
13423 | if (anArgIter + 1 < theNbArgs | |
13424 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShow)) | |
13425 | { | |
13426 | ++anArgIter; | |
13427 | } | |
13428 | if (anArg == "-fixedanimation") | |
13429 | { | |
13430 | aViewCube->SetFixedAnimationLoop (toShow); | |
13431 | } | |
13432 | else if (anArg == "-axes") | |
13433 | { | |
13434 | aViewCube->SetDrawAxes (toShow); | |
13435 | } | |
13436 | else if (anArg == "-edges") | |
13437 | { | |
13438 | aViewCube->SetDrawEdges (toShow); | |
13439 | } | |
13440 | else | |
13441 | { | |
13442 | aViewCube->SetDrawVertices (toShow); | |
13443 | } | |
13444 | } | |
13445 | else if (anArg == "-yup" | |
13446 | || anArg == "-zup") | |
13447 | { | |
13448 | bool isOn = true; | |
13449 | if (anArgIter + 1 < theNbArgs | |
13450 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isOn)) | |
13451 | { | |
13452 | ++anArgIter; | |
13453 | } | |
13454 | if (anArg == "-yup") | |
13455 | { | |
13456 | aViewCube->SetYup (isOn); | |
13457 | } | |
13458 | else | |
13459 | { | |
13460 | aViewCube->SetYup (!isOn); | |
13461 | } | |
13462 | } | |
13463 | else if (anArgIter + 1 < theNbArgs | |
13464 | && anArg == "-font") | |
13465 | { | |
13466 | aViewCube->SetFont (theArgVec[++anArgIter]); | |
13467 | } | |
13468 | else if (anArgIter + 1 < theNbArgs | |
13469 | && anArg == "-fontheight") | |
13470 | { | |
13471 | aViewCube->SetFontHeight (Draw::Atof (theArgVec[++anArgIter])); | |
13472 | } | |
13473 | else if (anArgIter + 1 < theNbArgs | |
13474 | && (anArg == "-size" | |
13475 | || anArg == "-boxsize")) | |
13476 | { | |
13477 | aViewCube->SetSize (Draw::Atof (theArgVec[++anArgIter]), | |
13478 | anArg != "-boxsize"); | |
13479 | } | |
13480 | else if (anArgIter + 1 < theNbArgs | |
13481 | && (anArg == "-boxfacet" | |
13482 | || anArg == "-boxfacetextension" | |
13483 | || anArg == "-facetextension" | |
13484 | || anArg == "-extension")) | |
13485 | { | |
13486 | aViewCube->SetBoxFacetExtension (Draw::Atof (theArgVec[++anArgIter])); | |
13487 | } | |
13488 | else if (anArgIter + 1 < theNbArgs | |
13489 | && (anArg == "-boxedgegap" | |
13490 | || anArg == "-edgegap")) | |
13491 | { | |
13492 | aViewCube->SetBoxEdgeGap (Draw::Atof (theArgVec[++anArgIter])); | |
13493 | } | |
13494 | else if (anArgIter + 1 < theNbArgs | |
13495 | && (anArg == "-boxedgeminsize" | |
13496 | || anArg == "-edgeminsize")) | |
13497 | { | |
13498 | aViewCube->SetBoxEdgeMinSize (Draw::Atof (theArgVec[++anArgIter])); | |
13499 | } | |
13500 | else if (anArgIter + 1 < theNbArgs | |
13501 | && (anArg == "-boxcornerminsize" | |
13502 | || anArg == "-cornerminsize")) | |
13503 | { | |
13504 | aViewCube->SetBoxCornerMinSize (Draw::Atof (theArgVec[++anArgIter])); | |
13505 | } | |
13506 | else if (anArgIter + 1 < theNbArgs | |
13507 | && anArg == "-axespadding") | |
13508 | { | |
13509 | aViewCube->SetAxesPadding (Draw::Atof (theArgVec[++anArgIter])); | |
13510 | } | |
13511 | else if (anArgIter + 1 < theNbArgs | |
13512 | && anArg == "-roundradius") | |
13513 | { | |
13514 | aViewCube->SetRoundRadius (Draw::Atof (theArgVec[++anArgIter])); | |
13515 | } | |
13516 | else if (anArgIter + 1 < theNbArgs | |
13517 | && anArg == "-duration") | |
13518 | { | |
13519 | aViewCube->SetDuration (Draw::Atof (theArgVec[++anArgIter])); | |
13520 | } | |
13521 | else | |
13522 | { | |
13523 | std::cout << "Syntax error: unknown argument '" << anArg << "'\n"; | |
13524 | return 1; | |
13525 | } | |
13526 | } | |
13527 | if (aViewCube.IsNull()) | |
13528 | { | |
13529 | std::cout << "Syntax error: wrong number of arguments\n"; | |
13530 | return 1; | |
13531 | } | |
13532 | ||
13533 | ViewerTest::Display (aName, aViewCube, false); | |
13534 | return 0; | |
13535 | } | |
13536 | ||
7fd59977 | 13537 | //======================================================================= |
13538 | //function : ViewerCommands | |
13539 | //purpose : | |
13540 | //======================================================================= | |
13541 | ||
13542 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) | |
13543 | { | |
13544 | ||
13545 | const char *group = "ZeViewer"; | |
18d715bd | 13546 | theCommands.Add("vinit", |
fd3f6bd0 | 13547 | "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]" |
2e93433e | 13548 | "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]" |
fd3f6bd0 | 13549 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
13550 | "\n\t\t: [-display displayName]" | |
13551 | #endif | |
13552 | "\n\t\t: Creates new View window with specified name viewName." | |
13553 | "\n\t\t: By default the new view is created in the viewer and in" | |
13554 | "\n\t\t: graphic driver shared with active view." | |
13555 | "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}" | |
13556 | "\n\t\t: If driverName isn't specified the driver will be shared with active view." | |
13557 | "\n\t\t: If viewerName isn't specified the viewer will be shared with active view." | |
13558 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
13559 | "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]" | |
13560 | "\n\t\t: Display name will be used within creation of graphic driver, when specified." | |
18d715bd | 13561 | #endif |
fd3f6bd0 | 13562 | "\n\t\t: -left, -top pixel position of left top corner of the window." |
13563 | "\n\t\t: -width, -height width and heigth of window respectively." | |
9e04ccdc | 13564 | "\n\t\t: -cloneActive floag to copy camera and dimensions of active view." |
fd3f6bd0 | 13565 | "\n\t\t: -exitOnClose when specified, closing the view will exit application." |
13566 | "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape." | |
2e93433e | 13567 | "\n\t\t: -2d_mode when on, view will not react on rotate scene events" |
fd3f6bd0 | 13568 | "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.", |
7fd59977 | 13569 | __FILE__,VInit,group); |
18d715bd | 13570 | theCommands.Add("vclose" , |
d0cc1cb7 | 13571 | "[view_id [keep_context=0|1]]\n" |
18d715bd | 13572 | "or vclose ALL - to remove all created views\n" |
13573 | " - removes view(viewer window) defined by its view_id.\n" | |
13574 | " - keep_context: by default 0; if 1 and the last view is deleted" | |
13575 | " the current context is not removed.", | |
13576 | __FILE__,VClose,group); | |
13577 | theCommands.Add("vactivate" , | |
e084dbbc | 13578 | "vactivate view_id [-noUpdate]" |
18d715bd | 13579 | " - activates view(viewer window) defined by its view_id", |
13580 | __FILE__,VActivate,group); | |
13581 | theCommands.Add("vviewlist", | |
13582 | "vviewlist [format={tree, long}]" | |
13583 | " - prints current list of views per viewer and graphic_driver ID shared between viewers" | |
13584 | " - format: format of result output, if tree the output is a tree view;" | |
13585 | "otherwise it's a list of full view names. By default format = tree", | |
13586 | __FILE__,VViewList,group); | |
7fd59977 | 13587 | theCommands.Add("vhelp" , |
13588 | "vhelp : display help on the viewer commands", | |
13589 | __FILE__,VHelp,group); | |
fc552d84 | 13590 | theCommands.Add("vviewproj", |
13591 | "vviewproj [top|bottom|left|right|front|back|axoLeft|axoRight]" | |
13592 | "\n\t\t: [+-X+-Y+-Z] [-Zup|-Yup] [-frame +-X+-Y]" | |
13593 | "\n\t\t: Setup view direction" | |
13594 | "\n\t\t: -Yup use Y-up convention instead of Zup (which is default)." | |
13595 | "\n\t\t: +-X+-Y+-Z define direction as combination of DX, DY and DZ;" | |
13596 | "\n\t\t: for example '+Z' will show front of the model," | |
13597 | "\n\t\t: '-X-Y+Z' will define left axonometrical view." | |
13598 | "\n\t\t: -frame define camera Up and Right directions (regardless Up convention);" | |
13599 | "\n\t\t: for example '+X+Z' will show front of the model with Z-up." | |
13600 | __FILE__,VViewProj,group); | |
7fd59977 | 13601 | theCommands.Add("vtop" , |
27af3052 | 13602 | "vtop or <T> : Top view. Orientation +X+Y" , |
fc552d84 | 13603 | __FILE__,VViewProj,group); |
44b8f2d6 | 13604 | theCommands.Add("vbottom" , |
27af3052 | 13605 | "vbottom : Bottom view. Orientation +X-Y" , |
fc552d84 | 13606 | __FILE__,VViewProj,group); |
44b8f2d6 | 13607 | theCommands.Add("vleft" , |
27af3052 | 13608 | "vleft : Left view. Orientation -Y+Z" , |
fc552d84 | 13609 | __FILE__,VViewProj,group); |
44b8f2d6 | 13610 | theCommands.Add("vright" , |
27af3052 | 13611 | "vright : Right view. Orientation +Y+Z" , |
fc552d84 | 13612 | __FILE__,VViewProj,group); |
7fd59977 | 13613 | theCommands.Add("vaxo" , |
27af3052 | 13614 | " vaxo or <A> : Axonometric view. Orientation +X-Y+Z", |
fc552d84 | 13615 | __FILE__,VViewProj,group); |
44b8f2d6 | 13616 | theCommands.Add("vfront" , |
27af3052 | 13617 | "vfront : Front view. Orientation +X+Z" , |
fc552d84 | 13618 | __FILE__,VViewProj,group); |
44b8f2d6 | 13619 | theCommands.Add("vback" , |
27af3052 | 13620 | "vback : Back view. Orientation -X+Z" , |
fc552d84 | 13621 | __FILE__,VViewProj,group); |
7fd59977 | 13622 | theCommands.Add("vpick" , |
13623 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", | |
13624 | VPick,group); | |
1beb58d7 | 13625 | theCommands.Add("vfit", |
13626 | "vfit or <F> [-selected] [-noupdate]" | |
b586500b | 13627 | "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects", |
7fd59977 | 13628 | __FILE__,VFit,group); |
6262a303 | 13629 | theCommands.Add ("vfitarea", |
13630 | "vfitarea x1 y1 x2 y2" | |
13631 | "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2" | |
13632 | "\n\t\t: Fit view to show area located between two points" | |
13633 | "\n\t\t: given in world 2D or 3D corrdinates.", | |
13634 | __FILE__, VFitArea, group); | |
197ac94e | 13635 | theCommands.Add ("vzfit", "vzfit [scale]\n" |
13636 | " Matches Z near, Z far view volume planes to the displayed objects.\n" | |
13637 | " \"scale\" - specifies factor to scale computed z range.\n", | |
13638 | __FILE__, VZFit, group); | |
7fd59977 | 13639 | theCommands.Add("vrepaint", |
8693dfd0 | 13640 | "vrepaint [-immediate] [-continuous FPS]" |
13641 | "\n\t\t: force redraw of active View" | |
13642 | "\n\t\t: -immediate flag performs redraw of immediate layers only;" | |
13643 | "\n\t\t: -continuous activates/deactivates continuous redraw of active View," | |
13644 | "\n\t\t: 0 means no continuous rendering," | |
13645 | "\n\t\t: -1 means non-stop redraws," | |
13646 | "\n\t\t: >0 specifies target framerate,", | |
7fd59977 | 13647 | __FILE__,VRepaint,group); |
13648 | theCommands.Add("vclear", | |
faea8b40 | 13649 | "vclear : vclear" |
13650 | "\n\t\t: remove all the object from the viewer", | |
7fd59977 | 13651 | __FILE__,VClear,group); |
293211ae | 13652 | theCommands.Add ( |
13653 | "vbackground", | |
13654 | "Changes background or some background settings.\n" | |
13655 | "\n" | |
13656 | "Usage:\n" | |
13657 | " vbackground -imageFile ImageFile [-imageMode FillType]\n" | |
13658 | " vbackground -imageMode FillType\n" | |
13659 | " vbackground -gradient Color1 Color2 [-gradientMode FillMethod]\n" | |
13660 | " vbackground -gradientMode FillMethod\n" | |
077a220c | 13661 | " vbackground -cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]\n" |
293211ae | 13662 | " vbackground -color Color\n" |
13663 | " vbackground -default -gradient Color1 Color2 [-gradientMode FillType]\n" | |
13664 | " vbackground -default -color Color\n" | |
13665 | " vbackground -help\n" | |
13666 | "\n" | |
13667 | "Options:\n" | |
13668 | " -imageFile (-imgFile, -image, -img): sets filename of image used as background\n" | |
13669 | " -imageMode (-imgMode, -imageMd, -imgMd): sets image fill type\n" | |
13670 | " -gradient (-grad, -gr): sets background gradient starting and ending colors\n" | |
13671 | " -gradientMode (-gradMode, -gradMd, -grMode, -grMd): sets gradient fill method\n" | |
077a220c | 13672 | " -cubemap (-cmap, -cm): sets environmet cubemap as background\n" |
13673 | " -invertedz (-invz, -iz): sets inversion of Z axis for background cubemap rendering\n" | |
13674 | " -order (-o): defines order of tiles in one image cubemap\n" | |
13675 | " (has no effect in case of multi image cubemaps)\n" | |
293211ae | 13676 | " -color (-col): sets background color\n" |
13677 | " -default (-def): sets background default gradient or color\n" | |
13678 | " -help (-h): outputs short help message\n" | |
13679 | "\n" | |
13680 | "Arguments:\n" | |
077a220c | 13681 | " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n" |
293211ae | 13682 | " or reals within the range [0.0, 1.0]\n" |
077a220c | 13683 | " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n" |
13684 | " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n" | |
13685 | " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, " | |
293211ae | 13686 | "CORNER4\n" |
077a220c | 13687 | " FillType: one of CENTERED, TILED, STRETCH, NONE\n" |
13688 | " ImageFile: a name of the file with the image used as a background\n" | |
13689 | " CubemapFilei: a name of the file with one image packed cubemap or names of separate files with every cubemap side\n" | |
13690 | " TileIndexi: a cubemap side index in range [0, 5] for i tile of one image packed cubemap\n", | |
293211ae | 13691 | __FILE__, |
13692 | vbackground, | |
13693 | group); | |
13694 | theCommands.Add ("vsetbg", | |
13695 | "Loads image as background." | |
13696 | "\n\t\t: vsetbg ImageFile [FillType]" | |
13697 | "\n\t\t: vsetbg -imageFile ImageFile [-imageMode FillType]" | |
13698 | "\n\t\t: Alias for 'vbackground -imageFile ImageFile [-imageMode FillType]'.", | |
13699 | __FILE__, | |
13700 | vbackground, | |
13701 | group); | |
13702 | theCommands.Add ("vsetbgmode", | |
13703 | "Changes background image fill type." | |
13704 | "\n\t\t: vsetbgmode [-imageMode] FillType" | |
13705 | "\n\t\t: Alias for 'vbackground -imageMode FillType'.", | |
13706 | __FILE__, | |
13707 | vbackground, | |
13708 | group); | |
13709 | theCommands.Add ("vsetgradientbg", | |
13710 | "Mounts gradient background." | |
13711 | "\n\t\t: vsetgradientbg Color1 Color2 [FillMethod]" | |
13712 | "\n\t\t: vsetgradientbg -gradient Color1 Color2 [-gradientMode FillMethod]" | |
13713 | "\n\t\t: Alias for 'vbackground -gradient Color1 Color2 -gradientMode FillMethod'.", | |
13714 | __FILE__, | |
13715 | vbackground, | |
13716 | group); | |
13717 | theCommands.Add ("vsetgrbgmode", | |
13718 | "Changes gradient background fill method." | |
13719 | "\n\t\t: vsetgrbgmode [-gradientMode] FillMethod" | |
13720 | "\n\t\t: Alias for 'vbackground -gradientMode FillMethod'.", | |
13721 | __FILE__, | |
13722 | vbackground, | |
13723 | group); | |
13724 | theCommands.Add ("vsetcolorbg", | |
13725 | "Sets background color." | |
13726 | "\n\t\t: vsetcolorbg [-color] Color." | |
13727 | "\n\t\t: Alias for 'vbackground -color Color'.", | |
13728 | __FILE__, | |
13729 | vbackground, | |
13730 | group); | |
13731 | theCommands.Add ("vsetdefaultbg", | |
13732 | "Sets default viewer background fill color (flat/gradient)." | |
13733 | "\n\t\t: vsetdefaultbg Color1 Color2 [FillMethod]" | |
13734 | "\n\t\t: vsetdefaultbg -gradient Color1 Color2 [-gradientMode FillMethod]" | |
13735 | "\n\t\t: Alias for 'vbackground -default -gradient Color1 Color2 [-gradientMode FillMethod]'." | |
13736 | "\n\t\t: vsetdefaultbg [-color] Color" | |
13737 | "\n\t\t: Alias for 'vbackground -default -color Color'.", | |
13738 | __FILE__, | |
13739 | vbackground, | |
13740 | group); | |
7fd59977 | 13741 | theCommands.Add("vscale", |
13742 | "vscale : vscale X Y Z", | |
13743 | __FILE__,VScale,group); | |
13744 | theCommands.Add("vzbufftrihedron", | |
536d98e2 | 13745 | "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]" |
13746 | "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]" | |
13747 | "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]" | |
13748 | "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]" | |
13749 | "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]" | |
13750 | "\n\t\t: Displays a trihedron", | |
13751 | __FILE__,VZBuffTrihedron,group); | |
7fd59977 | 13752 | theCommands.Add("vrotate", |
4af098ba | 13753 | "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]" |
13754 | "\n : Option -mouseStart starts rotation according to the mouse position" | |
13755 | "\n : Option -mouseMove continues rotation with angle computed" | |
13756 | "\n : from last and new mouse position." | |
13757 | "\n : vrotate AX AY AZ [X Y Z]", | |
7fd59977 | 13758 | __FILE__,VRotate,group); |
13759 | theCommands.Add("vzoom", | |
13760 | "vzoom : vzoom coef", | |
13761 | __FILE__,VZoom,group); | |
13762 | theCommands.Add("vpan", | |
13763 | "vpan : vpan dx dy", | |
13764 | __FILE__,VPan,group); | |
7fd59977 | 13765 | theCommands.Add("vcolorscale", |
4b3d6eb1 | 13766 | "vcolorscale name [-noupdate|-update] [-demo]" |
13767 | "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]" | |
13768 | "\n\t\t: [-font HeightFont=20]" | |
13769 | "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]" | |
13770 | "\n\t\t: [-smoothTransition {on|off}=off]" | |
13771 | "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]" | |
13772 | "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]" | |
13773 | "\n\t\t: [-textpos {left|right|center|none}=right]" | |
13774 | "\n\t\t: [-labelAtBorder {on|off}=on]" | |
13775 | "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]" | |
13776 | "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]" | |
13777 | "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]" | |
13778 | "\n\t\t: [-xy Left=0 Bottom=0]" | |
13779 | "\n\t\t: -demo - displays a color scale with demonstratio values" | |
13780 | "\n\t\t: -colors - set colors for all intervals" | |
13781 | "\n\t\t: -color - set color for specific interval" | |
13782 | "\n\t\t: -textpos - horizontal label position relative to color scale bar" | |
13783 | "\n\t\t: -labelAtBorder - vertical label position relative to color interval;" | |
13784 | "\n\t\t: at border means the value inbetween neighbor intervals," | |
13785 | "\n\t\t: at center means the center value within current interval" | |
13786 | "\n\t\t: -labels - set labels for all intervals" | |
13787 | "\n\t\t: -freeLabels - same as -labels but does not require" | |
13788 | "\n\t\t: matching the number of intervals" | |
13789 | "\n\t\t: -label - set label for specific interval" | |
13790 | "\n\t\t: -title - set title" | |
13791 | "\n\t\t: -reversed - setup smooth color transition between intervals" | |
13792 | "\n\t\t: -smoothTransition - swap colorscale direction" | |
13793 | "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values" | |
13794 | __FILE__, VColorScale, group); | |
7fd59977 | 13795 | theCommands.Add("vgraduatedtrihedron", |
a79f67f8 | 13796 | "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n" |
13797 | "\t[-namefont Name] [-valuesfont Name]\n" | |
13798 | "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n" | |
13799 | "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]" | |
13800 | "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n" | |
13801 | "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n" | |
13802 | "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]" | |
13803 | "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n" | |
13804 | "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n" | |
13805 | "\t[-xticks Number] [-yticks Number] [-zticks Number]\n" | |
13806 | "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n" | |
536d98e2 | 13807 | "\t[-drawgrid on/off] [-drawaxes on/off]\n" |
a79f67f8 | 13808 | " - Displays or erases graduated trihedron" |
13809 | " - xname, yname, zname - names of axes, default: X, Y, Z\n" | |
13810 | " - namefont - font of axes names. Default: Arial\n" | |
13811 | " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n" | |
13812 | " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n" | |
13813 | " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n" | |
13814 | " - valuesfont - font of axes values. Default: Arial\n" | |
13815 | " - xcolor, ycolor, zcolor - color of axis and values\n" | |
13816 | " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n" | |
13817 | " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n", | |
7fd59977 | 13818 | __FILE__,VGraduatedTrihedron,group); |
3bffef55 | 13819 | theCommands.Add("vtile" , |
13820 | "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]" | |
13821 | "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)." | |
13822 | "\n\t\t: -totalSize the size of virtual bigger viewport" | |
13823 | "\n\t\t: -tileSize tile size (the view size will be used if omitted)" | |
13824 | "\n\t\t: -lowerLeft tile offset as lower left corner" | |
13825 | "\n\t\t: -upperLeft tile offset as upper left corner", | |
13826 | __FILE__, VTile, group); | |
59f45b7c | 13827 | theCommands.Add("vzlayer", |
7c3ef2f7 | 13828 | "vzlayer [layerId]" |
1c728f2d | 13829 | "\n\t\t: [-add|-delete|-get|-settings] [-insertBefore AnotherLayer] [-insertAfter AnotherLayer]" |
4ecf34cc | 13830 | "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]" |
7c3ef2f7 | 13831 | "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]" |
1c728f2d | 13832 | "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv|rayTracing}]" |
7c3ef2f7 | 13833 | "\n\t\t: ZLayer list management:" |
13834 | "\n\t\t: -add add new z layer to viewer and print its id" | |
1c728f2d | 13835 | "\n\t\t: -insertBefore add new z layer and insert it before existing one" |
13836 | "\n\t\t: -insertAfter add new z layer and insert it after existing one" | |
7c3ef2f7 | 13837 | "\n\t\t: -delete delete z layer" |
13838 | "\n\t\t: -get print sequence of z layers" | |
13839 | "\n\t\t: -settings print status of z layer settings" | |
13840 | "\n\t\t: -disable disables given setting" | |
13841 | "\n\t\t: -enable enables given setting", | |
59f45b7c | 13842 | __FILE__,VZLayer,group); |
20637bd2 | 13843 | theCommands.Add("vlayerline", |
13844 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", | |
13845 | __FILE__,VLayerLine,group); | |
79931835 | 13846 | theCommands.Add("vgrid", |
13847 | "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]" | |
13848 | "\n\t\t: [-step X Y] [-size DX DY]" | |
13849 | "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]", | |
2bd4c032 | 13850 | __FILE__, VGrid, group); |
c40b7d58 | 13851 | theCommands.Add ("vpriviledgedplane", |
13852 | "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]" | |
13853 | "\n\t\t: Ox, Oy, Oz - plane origin" | |
13854 | "\n\t\t: Nx, Ny, Nz - plane normal direction" | |
13855 | "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction" | |
13856 | "\n\t\t: Sets or prints viewer's priviledged plane geometry.", | |
13857 | __FILE__, VPriviledgedPlane, group); | |
f25b82d6 | 13858 | theCommands.Add ("vconvert", |
13859 | "vconvert v [Mode={window|view}]" | |
13860 | "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]" | |
13861 | "\n\t\t: vconvert x y z [Mode={window|grid}]" | |
13862 | "\n\t\t: window - convert to window coordinates, pixels" | |
13863 | "\n\t\t: view - convert to view projection plane" | |
13864 | "\n\t\t: grid - convert to model coordinates, given on grid" | |
13865 | "\n\t\t: ray - convert projection ray to model coordiantes" | |
13866 | "\n\t\t: - vconvert v window : convert view to window;" | |
13867 | "\n\t\t: - vconvert v view : convert window to view;" | |
13868 | "\n\t\t: - vconvert x y window : convert view to window;" | |
13869 | "\n\t\t: - vconvert x y view : convert window to view;" | |
13870 | "\n\t\t: - vconvert x y : convert window to model;" | |
13871 | "\n\t\t: - vconvert x y grid : convert window to model using grid;" | |
13872 | "\n\t\t: - vconvert x y ray : convert window projection line to model;" | |
13873 | "\n\t\t: - vconvert x y z window : convert model to window;" | |
13874 | "\n\t\t: - vconvert x y z grid : convert view to model using grid;" | |
13875 | "\n\t\t: Converts the given coordinates to window/view/model space.", | |
13876 | __FILE__, VConvert, group); | |
208e6839 | 13877 | theCommands.Add ("vfps", |
e084dbbc | 13878 | "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view", |
208e6839 | 13879 | __FILE__, VFps, group); |
58655684 | 13880 | theCommands.Add ("vgldebug", |
c87535af | 13881 | "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]" |
84e84755 | 13882 | "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]" |
c87535af | 13883 | "\n\t\t: Request debug GL context. Should be called BEFORE vinit." |
13884 | "\n\t\t: Debug context can be requested only on Windows" | |
13885 | "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!" | |
13886 | "\n\t\t: -sync - request synchronized debug GL context" | |
13887 | "\n\t\t: -glslWarn - log GLSL compiler/linker warnings," | |
13888 | "\n\t\t: which are suppressed by default," | |
84e84755 | 13889 | "\n\t\t: -glslCode - log GLSL program source code," |
13890 | "\n\t\t: which are suppressed by default," | |
c87535af | 13891 | "\n\t\t: -extraMsg - log extra diagnostic messages from GL context," |
13892 | "\n\t\t: which are suppressed by default", | |
58655684 | 13893 | __FILE__, VGlDebug, group); |
208e6839 | 13894 | theCommands.Add ("vvbo", |
58655684 | 13895 | "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects", |
208e6839 | 13896 | __FILE__, VVbo, group); |
b5ac8292 | 13897 | theCommands.Add ("vstereo", |
f978241f | 13898 | "vstereo [0|1] [-mode Mode] [-reverse {0|1}]" |
13899 | "\n\t\t: [-anaglyph Filter]" | |
13900 | "\n\t\t: Control stereo output mode. Available modes for -mode:" | |
13901 | "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo," | |
13902 | "\n\t\t: requires driver support." | |
13903 | "\n\t\t: Should be called BEFORE vinit!" | |
13904 | "\n\t\t: anaglyph - Anaglyph glasses" | |
13905 | "\n\t\t: rowInterlaced - row-interlaced display" | |
13906 | "\n\t\t: columnInterlaced - column-interlaced display" | |
13907 | "\n\t\t: chessBoard - chess-board output" | |
13908 | "\n\t\t: sideBySide - horizontal pair" | |
13909 | "\n\t\t: overUnder - vertical pair" | |
13910 | "\n\t\t: Available Anaglyph filters for -anaglyph:" | |
13911 | "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple," | |
13912 | "\n\t\t: greenMagentaSimple", | |
b5ac8292 | 13913 | __FILE__, VStereo, group); |
a577aaab | 13914 | theCommands.Add ("vcaps", |
2a332745 | 13915 | "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]" |
1dfe71a6 | 13916 | "\n\t\t: [-compatibleProfile {0|1}]" |
56689b27 | 13917 | "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]" |
f978241f | 13918 | "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]" |
8625ef7e | 13919 | "\n\t\t: [-softMode {0|1}] [-noupdate|-update]" |
59515ca6 | 13920 | "\n\t\t: [-noExtensions {0|1}] [-maxVersion Major Minor]" |
8625ef7e | 13921 | "\n\t\t: Modify particular graphic driver options:" |
13922 | "\n\t\t: FFP - use fixed-function pipeline instead of" | |
13923 | "\n\t\t: built-in GLSL programs" | |
4e1523ef | 13924 | "\n\t\t: (requires compatible profile)" |
2a332745 | 13925 | "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs" |
8625ef7e | 13926 | "\n\t\t: VBO - use Vertex Buffer Object (copy vertex" |
13927 | "\n\t\t: arrays to GPU memory)" | |
13928 | "\n\t\t: sprite - use textured sprites instead of bitmaps" | |
f978241f | 13929 | "\n\t\t: vsync - switch VSync on or off" |
56689b27 | 13930 | "\n\t\t: winBuffer - allow using window buffer for rendering" |
4e1523ef | 13931 | "\n\t\t: Context creation options:" |
13932 | "\n\t\t: softMode - software OpenGL implementation" | |
13933 | "\n\t\t: compatibleProfile - backward-compatible profile" | |
f978241f | 13934 | "\n\t\t: quadbuffer - QuadBuffer" |
59515ca6 | 13935 | "\n\t\t: noExtensions - disallow usage of extensions" |
13936 | "\n\t\t: maxVersion - force upper OpenGL version to be used" | |
8625ef7e | 13937 | "\n\t\t: Unlike vrenderparams, these parameters control alternative" |
13938 | "\n\t\t: rendering paths producing the same visual result when" | |
13939 | "\n\t\t: possible." | |
13940 | "\n\t\t: Command is intended for testing old hardware compatibility.", | |
a577aaab | 13941 | __FILE__, VCaps, group); |
f0430952 | 13942 | theCommands.Add ("vmemgpu", |
13943 | "vmemgpu [f]: print system-dependent GPU memory information if available;" | |
13944 | " with f option returns free memory in bytes", | |
13945 | __FILE__, VMemGpu, group); | |
85e096c3 | 13946 | theCommands.Add ("vreadpixel", |
55c8f0f7 | 13947 | "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [-name]" |
85e096c3 | 13948 | " : Read pixel value for active view", |
13949 | __FILE__, VReadPixel, group); | |
692613e5 | 13950 | theCommands.Add("diffimage", |
fd3f6bd0 | 13951 | "diffimage imageFile1 imageFile2 [diffImageFile]" |
13952 | "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]" | |
13953 | "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]" | |
13954 | "\n\t\t: Compare two images by content and generate difference image." | |
13955 | "\n\t\t: When -exitOnClose is specified, closing the view will exit application." | |
13956 | "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.", | |
692613e5 | 13957 | __FILE__, VDiffImage, group); |
4754e164 | 13958 | theCommands.Add ("vselect", |
2157d6ac | 13959 | "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n" |
4754e164 | 13960 | "- emulates different types of selection:\n" |
13961 | "- 1) single click selection\n" | |
13962 | "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" | |
13963 | "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" | |
faea8b40 | 13964 | "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n" |
13965 | " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n" | |
13966 | " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. " | |
2157d6ac | 13967 | " (partial inclusion - overlap - is not allowed by default)\n" |
13968 | "- 5) any of these selections with shift button pressed", | |
4754e164 | 13969 | __FILE__, VSelect, group); |
13970 | theCommands.Add ("vmoveto", | |
8a590580 | 13971 | "vmoveto [x y] [-reset]" |
13972 | "\n\t\t: Emulates cursor movement to pixel position (x,y)." | |
13973 | "\n\t\t: -reset resets current highlighting", | |
4754e164 | 13974 | __FILE__, VMoveTo, group); |
1beb58d7 | 13975 | theCommands.Add ("vviewparams", |
13976 | "vviewparams [-args] [-scale [s]]" | |
13977 | "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]" | |
13978 | "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]" | |
13979 | "\n\t\t: Manage current view parameters or prints all" | |
13980 | "\n\t\t: current values when called without argument." | |
13981 | "\n\t\t: -scale [s] prints or sets viewport relative scale" | |
13982 | "\n\t\t: -eye [x y z] prints or sets eye location" | |
13983 | "\n\t\t: -at [x y z] prints or sets center of look" | |
13984 | "\n\t\t: -up [x y z] prints or sets direction of up vector" | |
13985 | "\n\t\t: -proj [x y z] prints or sets direction of look" | |
13986 | "\n\t\t: -center x y sets location of center of the screen in pixels" | |
13987 | "\n\t\t: -size [sx] prints viewport projection width and height sizes" | |
13988 | "\n\t\t: or changes the size of its maximum dimension" | |
13989 | "\n\t\t: -args prints vviewparams arguments for restoring current view", | |
197ac94e | 13990 | __FILE__, VViewParams, group); |
1beb58d7 | 13991 | |
2e93433e | 13992 | theCommands.Add("v2dmode", |
13993 | "v2dmode [-name viewName] [-mode {-on|-off}=-on]" | |
13994 | "\n\t\t: name - name of existing view, if not defined, the active view is changed" | |
13995 | "\n\t\t: mode - switches On/Off rotation mode" | |
13996 | "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:" | |
13997 | "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active" | |
13998 | "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right" | |
13999 | "\n\t\t: View camera position might be changed only by commands.", | |
14000 | __FILE__, V2DMode, group); | |
14001 | ||
1beb58d7 | 14002 | theCommands.Add("vanimation", "Alias for vanim", |
14003 | __FILE__, VAnimation, group); | |
14004 | ||
14005 | theCommands.Add("vanim", | |
14006 | "List existing animations:" | |
14007 | "\n\t\t: vanim" | |
14008 | "\n\t\t: Animation playback:" | |
14009 | "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]" | |
14010 | "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]" | |
14011 | "\n\t\t: -speed playback speed (1.0 is normal speed)" | |
14012 | "\n\t\t: -freeLook skip camera animations" | |
14013 | "\n\t\t: -lockLoop disable any interactions" | |
14014 | "\n\t\t:" | |
14015 | "\n\t\t: Animation definition:" | |
14016 | "\n\t\t: vanim Name/sub/name [-clear] [-delete]" | |
14017 | "\n\t\t: [start TimeSec] [duration TimeSec]" | |
14018 | "\n\t\t:" | |
14019 | "\n\t\t: Animation name defined in path-style (anim/name or anim.name)" | |
14020 | "\n\t\t: specifies nested animations." | |
14021 | "\n\t\t: There is no syntax to explicitly add new animation," | |
14022 | "\n\t\t: and all non-existing animations within the name will be" | |
14023 | "\n\t\t: implicitly created on first use (including parents)." | |
14024 | "\n\t\t:" | |
14025 | "\n\t\t: Each animation might define the SINGLE action (see below)," | |
14026 | "\n\t\t: like camera transition, object transformation or custom callback." | |
14027 | "\n\t\t: Child animations can be used for defining concurrent actions." | |
14028 | "\n\t\t:" | |
14029 | "\n\t\t: Camera animation:" | |
14030 | "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]" | |
14031 | "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]" | |
14032 | "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]" | |
14033 | "\n\t\t: [-scale1 Scale] [-scale2 Scale]" | |
14034 | "\n\t\t: -eyeX camera Eye positions pair (start and end)" | |
14035 | "\n\t\t: -atX camera Center positions pair" | |
14036 | "\n\t\t: -upX camera Up directions pair" | |
14037 | "\n\t\t: -scaleX camera Scale factors pair" | |
14038 | "\n\t\t: Object animation:" | |
14039 | "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]" | |
14040 | "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]" | |
14041 | "\n\t\t: [-scale1 Scale] [-scale2 Scale]" | |
14042 | "\n\t\t: -locX object Location points pair (translation)" | |
14043 | "\n\t\t: -rotX object Orientations pair (quaternions)" | |
14044 | "\n\t\t: -scaleX object Scale factors pair (quaternions)" | |
14045 | "\n\t\t: Custom callback:" | |
14046 | "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\"" | |
14047 | "\n\t\t: %Pts overall animation presentation timestamp" | |
14048 | "\n\t\t: %LocalPts local animation timestamp" | |
14049 | "\n\t\t: %Normalized local animation normalized value in range 0..1" | |
08f8a185 | 14050 | "\n\t\t:" |
14051 | "\n\t\t: Video recording:" | |
14052 | "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]" | |
14053 | "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]" | |
14054 | "\n\t\t: [-crf Value] [-preset Preset]" | |
14055 | "\n\t\t: -fps video framerate" | |
14056 | "\n\t\t: -format file format, container (matroska, etc.)" | |
14057 | "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)" | |
14058 | "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)" | |
14059 | "\n\t\t: -crf constant rate factor (specific to codec)" | |
14060 | "\n\t\t: -preset codec parameters preset (specific to codec)" | |
1beb58d7 | 14061 | __FILE__, VAnimation, group); |
14062 | ||
4754e164 | 14063 | theCommands.Add("vchangeselected", |
dc3fe572 | 14064 | "vchangeselected shape" |
4754e164 | 14065 | "- adds to shape to selection or remove one from it", |
14066 | __FILE__, VChangeSelected, group); | |
4754e164 | 14067 | theCommands.Add ("vnbselected", |
faea8b40 | 14068 | "vnbselected" |
14069 | "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group); | |
6b62b2da | 14070 | theCommands.Add ("vcamera", |
30a1b24e | 14071 | "vcamera [PrsName] [-ortho] [-projtype]" |
6b62b2da | 14072 | "\n\t\t: [-persp]" |
14073 | "\n\t\t: [-fovy [Angle]] [-distance [Distance]]" | |
14074 | "\n\t\t: [-stereo] [-leftEye] [-rightEye]" | |
14075 | "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]" | |
14076 | "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]" | |
30a1b24e | 14077 | "\n\t\t: Manages camera parameters." |
14078 | "\n\t\t: Displays frustum when presntation name PrsName is specified." | |
6b62b2da | 14079 | "\n\t\t: Prints current value when option called without argument." |
14080 | "\n\t\t: Orthographic camera:" | |
14081 | "\n\t\t: -ortho activate orthographic projection" | |
14082 | "\n\t\t: Perspective camera:" | |
14083 | "\n\t\t: -persp activate perspective projection (mono)" | |
14084 | "\n\t\t: -fovy field of view in y axis, in degrees" | |
14085 | "\n\t\t: -distance distance of eye from camera center" | |
14086 | "\n\t\t: Stereoscopic camera:" | |
14087 | "\n\t\t: -stereo perspective projection (stereo)" | |
14088 | "\n\t\t: -leftEye perspective projection (left eye)" | |
14089 | "\n\t\t: -rightEye perspective projection (right eye)" | |
14090 | "\n\t\t: -iod intraocular distance value" | |
14091 | "\n\t\t: -iodType distance type, absolute or relative" | |
14092 | "\n\t\t: -zfocus stereographic focus value" | |
14093 | "\n\t\t: -zfocusType focus type, absolute or relative", | |
14094 | __FILE__, VCamera, group); | |
b5ac8292 | 14095 | theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n" |
197ac94e | 14096 | "- vautozfit [on={1|0}] [scale]\n" |
14097 | " Prints or changes parameters of automatic z-fit mode:\n" | |
14098 | " \"on\" - turns automatic z-fit on or off\n" | |
14099 | " \"scale\" - specifies factor to scale computed z range.\n", | |
14100 | __FILE__, VAutoZFit, group); | |
b5ac8292 | 14101 | theCommands.Add ("vzrange", "command to manually access znear and zfar values\n" |
14102 | " vzrange - without parameters shows current values\n" | |
14103 | " vzrange [znear] [zfar] - applies provided values to view", | |
14104 | __FILE__,VZRange, group); | |
4754e164 | 14105 | theCommands.Add ("vpurgedisplay", |
eb4320f2 | 14106 | "vpurgedisplay" |
4754e164 | 14107 | "- removes structures which don't belong to objects displayed in neutral point", |
14108 | __FILE__, VPurgeDisplay, group); | |
14109 | theCommands.Add("vsetviewsize", | |
14110 | "vsetviewsize size", | |
14111 | __FILE__,VSetViewSize,group); | |
14112 | theCommands.Add("vmoveview", | |
14113 | "vmoveview Dx Dy Dz [Start = 1|0]", | |
14114 | __FILE__,VMoveView,group); | |
14115 | theCommands.Add("vtranslateview", | |
14116 | "vtranslateview Dx Dy Dz [Start = 1|0)]", | |
14117 | __FILE__,VTranslateView,group); | |
14118 | theCommands.Add("vturnview", | |
14119 | "vturnview Ax Ay Az [Start = 1|0]", | |
14120 | __FILE__,VTurnView,group); | |
269294d6 | 14121 | theCommands.Add("vtextureenv", |
14122 | "Enables or disables environment mapping in the 3D view, loading the texture from the given standard " | |
14123 | "or user-defined file and optionally applying texture mapping parameters\n" | |
14124 | " Usage:\n" | |
14125 | " vtextureenv off - disables environment mapping\n" | |
14126 | " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n" | |
14127 | " std_texture = (0..7)\n" | |
14128 | " rep = {clamp|repeat}\n" | |
14129 | " mod = {decal|modulate}\n" | |
14130 | " flt = {nearest|bilinear|trilinear}\n" | |
14131 | " ss, st - scale factors for s and t texture coordinates\n" | |
14132 | " ts, tt - translation for s and t texture coordinates\n" | |
14133 | " rot - texture rotation angle in degrees", | |
14134 | __FILE__, VTextureEnv, group); | |
1eeef710 | 14135 | theCommands.Add("vhlr", |
14136 | "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]" | |
14137 | "\n\t\t: Hidden Line Removal algorithm." | |
14138 | "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones" | |
14139 | "\n\t\t: -algoType type of HLR algorithm.\n", | |
0a768f56 | 14140 | __FILE__,VHLR,group); |
1eeef710 | 14141 | theCommands.Add("vhlrtype", |
14142 | "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]" | |
14143 | "\n\t\t: Changes the type of HLR algorithm using for shapes:" | |
14144 | "\n\t\t: 'algo' - exact HLR algorithm is applied" | |
14145 | "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied" | |
14146 | "\n\t\t: If shapes are not given - option is applied to all shapes in the view", | |
0a768f56 | 14147 | __FILE__,VHLRType,group); |
3e05329c | 14148 | theCommands.Add("vclipplane", |
14149 | "vclipplane planeName [{0|1}]" | |
25c35042 | 14150 | "\n\t\t: [-equation1 A B C D]" |
14151 | "\n\t\t: [-equation2 A B C D]" | |
14152 | "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]" | |
32ca7711 | 14153 | "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]" |
3e05329c | 14154 | "\n\t\t: [-maxPlanes]" |
14155 | "\n\t\t: [-capping {0|1}]" | |
1b661a81 | 14156 | "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]" |
3e05329c | 14157 | "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]" |
14158 | "\n\t\t: [-texRotate Angle]" | |
14159 | "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]" | |
14160 | "\n\t\t: [-useObjShader {0|1}]" | |
14161 | "\n\t\t: Clipping planes management:" | |
14162 | "\n\t\t: -maxPlanes print plane limit for view" | |
14163 | "\n\t\t: -delete delete plane with given name" | |
14164 | "\n\t\t: {off|on|0|1} turn clipping on/off" | |
14165 | "\n\t\t: -set|-unset set/unset plane for Object or View list;" | |
14166 | "\n\t\t: applied to active View when list is omitted" | |
14167 | "\n\t\t: -equation A B C D change plane equation" | |
14168 | "\n\t\t: -clone SourcePlane NewPlane clone the plane definition." | |
14169 | "\n\t\t: Capping options:" | |
14170 | "\n\t\t: -capping {off|on|0|1} turn capping on/off" | |
14171 | "\n\t\t: -color R G B set capping color" | |
1b661a81 | 14172 | "\n\t\t: -transparency Value set capping transparency 0..1" |
3e05329c | 14173 | "\n\t\t: -texName Texture set capping texture" |
14174 | "\n\t\t: -texScale SX SY set capping tex scale" | |
14175 | "\n\t\t: -texOrigin TX TY set capping tex origin" | |
14176 | "\n\t\t: -texRotate Angle set capping tex rotation" | |
14177 | "\n\t\t: -hatch {on|off|ID} set capping hatching mask" | |
14178 | "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object" | |
14179 | "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object" | |
14180 | "\n\t\t: -useObjShader {off|on|0|1} use shader program of object", | |
14181 | __FILE__, VClipPlane, group); | |
392ac980 | 14182 | theCommands.Add("vdefaults", |
4c513386 | 14183 | "vdefaults [-absDefl value]" |
14184 | "\n\t\t: [-devCoeff value]" | |
14185 | "\n\t\t: [-angDefl value]" | |
14186 | "\n\t\t: [-autoTriang {off/on | 0/1}]" | |
14187 | , __FILE__, VDefaults, group); | |
12381341 | 14188 | theCommands.Add("vlight", |
816d03ee | 14189 | "tool to manage light sources, without arguments shows list of lights." |
14190 | "\n Main commands: " | |
992ed6b3 | 14191 | "\n '-clear' to clear lights" |
14192 | "\n '-{def}aults' to load deafault lights" | |
14193 | "\n '-add' <type> to add any light source" | |
816d03ee | 14194 | "\n where <type> is one of {amb}ient|directional|{spot}light|positional" |
14195 | "\n 'change' <lightId> to edit light source with specified lightId" | |
14196 | "\n\n In addition to 'add' and 'change' commands you can use light parameters:" | |
992ed6b3 | 14197 | "\n -layer Id" |
14198 | "\n -{pos}ition X Y Z" | |
14199 | "\n -{dir}ection X Y Z (for directional light or for spotlight)" | |
14200 | "\n -color colorName" | |
14201 | "\n -{head}light 0|1" | |
14202 | "\n -{sm}oothness value" | |
14203 | "\n -{int}ensity value" | |
14204 | "\n -{constAtten}uation value" | |
14205 | "\n -{linearAtten}uation value" | |
14206 | "\n -angle angleDeg" | |
14207 | "\n -{spotexp}onent value" | |
14208 | "\n -local|-global" | |
14209 | "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red" | |
14210 | "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2", | |
12381341 | 14211 | __FILE__, VLight, group); |
6b62b2da | 14212 | theCommands.Add("vraytrace", |
14213 | "vraytrace [0|1]" | |
189f85a3 | 14214 | "\n\t\t: Turns on/off ray-tracing renderer." |
6b62b2da | 14215 | "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'." |
14216 | "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.", | |
14217 | __FILE__, VRenderParams, group); | |
bc8c79bb | 14218 | theCommands.Add("vrenderparams", |
14219 | "\n Manages rendering parameters: " | |
a1073ae2 | 14220 | "\n '-raster' Disables GPU ray-tracing" |
14221 | "\n '-msaa 0..4' Specifies number of samples for MSAA" | |
2a332745 | 14222 | "\n '-lineFeather > 0' Sets line feather factor" |
a1073ae2 | 14223 | "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor" |
f88457e6 | 14224 | "\n '-depthPrePass on|off' Enables/disables depth pre-pass" |
c40eb6b9 | 14225 | "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)" |
a1073ae2 | 14226 | "\n '-rendScale value Rendering resolution scale factor" |
14227 | "\n '-rayTrace' Enables GPU ray-tracing" | |
14228 | "\n '-rayDepth 0..10' Defines maximum ray-tracing depth" | |
14229 | "\n '-shadows on|off' Enables/disables shadows rendering" | |
14230 | "\n '-reflections on|off' Enables/disables specular reflections" | |
14231 | "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing" | |
14232 | "\n '-gleam on|off' Enables/disables transparency shadow effects" | |
14233 | "\n '-gi on|off' Enables/disables global illumination effects" | |
14234 | "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)" | |
14235 | "\n '-env on|off' Enables/disables environment map background" | |
14236 | "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)" | |
14237 | "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)" | |
14238 | "\n '-issd on|off' Shows screen sampling distribution in ISS mode" | |
14239 | "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)" | |
66d1cdc6 | 14240 | "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)" |
14241 | "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)" | |
a1073ae2 | 14242 | "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)" |
14243 | "\n '-shadingModel model' Controls shading model from enumeration" | |
59ee34ef | 14244 | "\n unlit, flat, gouraud, phong" |
a1073ae2 | 14245 | "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size" |
b27ab03d | 14246 | "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)" |
14247 | "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect" | |
eb85ed36 | 14248 | "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)" |
14249 | "\n '-whitepoint value' White point value for filmic tone mapping" | |
14250 | "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)" | |
5e30547b | 14251 | "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points" |
14252 | "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'" | |
15669413 | 14253 | "\n Show/hide performance counters (flags can be combined)" |
14254 | "\n '-perfUpdateInterval nbSeconds' Performance counters update interval" | |
5e30547b | 14255 | "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames" |
14256 | "\n '-perfChartMax seconds' Maximum time in seconds with the chart" | |
0e3025bc | 14257 | "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or" |
14258 | "\n set state to check structures culled previously." | |
8625ef7e | 14259 | "\n Unlike vcaps, these parameters dramatically change visual properties." |
14260 | "\n Command is intended to control presentation quality depending on" | |
14261 | "\n hardware capabilities and performance.", | |
bc8c79bb | 14262 | __FILE__, VRenderParams, group); |
79b544e6 | 14263 | theCommands.Add("vstatprofiler", |
14264 | "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups" | |
14265 | "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays" | |
14266 | "\n |triagles|points|geomMem|textureMem|frameMem" | |
14267 | "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage" | |
14268 | "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]" | |
14269 | "\n [-noredraw]" | |
14270 | "\n\t\t: Prints rendering statistics." | |
14271 | "\n\t\t: If there are some parameters - print corresponding statistic counters values," | |
14272 | "\n\t\t: else - print all performance counters set previously." | |
14273 | "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n", | |
14274 | __FILE__, VStatProfiler, group); | |
49e1a5c7 | 14275 | theCommands.Add ("vplace", |
14276 | "vplace dx dy" | |
14277 | "\n\t\t: Places the point (in pixels) at the center of the window", | |
14278 | __FILE__, VPlace, group); | |
0717ddc1 | 14279 | theCommands.Add("vxrotate", |
14280 | "vxrotate", | |
14281 | __FILE__,VXRotate,group); | |
14282 | ||
625e1958 | 14283 | theCommands.Add("vmanipulator", |
14284 | "\n vmanipulator Name [-attach AISObject | -detach | ...]" | |
14285 | "\n tool to create and manage AIS manipulators." | |
14286 | "\n Options: " | |
14287 | "\n '-attach AISObject' attach manipulator to AISObject" | |
14288 | "\n '-adjustPosition {0|1}' adjust position when attaching" | |
14289 | "\n '-adjustSize {0|1}' adjust size when attaching" | |
14290 | "\n '-enableModes {0|1}' enable modes when attaching" | |
bbf3fcde | 14291 | "\n '-view {active | [name of view]}' display manipulator only in defined view," |
14292 | "\n by default it is displayed in all views of the current viewer" | |
625e1958 | 14293 | "\n '-detach' detach manipulator" |
14294 | "\n '-startTransform mouse_x mouse_y' - invoke start of transformation" | |
14295 | "\n '-transform mouse_x mouse_y' - invoke transformation" | |
14296 | "\n '-stopTransform [abort]' - invoke stop of transformation" | |
14297 | "\n '-move x y z' - move attached object" | |
14298 | "\n '-rotate x y z dx dy dz angle' - rotate attached object" | |
14299 | "\n '-scale factor' - scale attached object" | |
14300 | "\n '-autoActivate {0|1}' - set activation on detection" | |
14301 | "\n '-followTranslation {0|1}' - set following translation transform" | |
14302 | "\n '-followRotation {0|1}' - set following rotation transform" | |
f522ce50 | 14303 | "\n '-followDragging {0|1}' - set following dragging transform" |
625e1958 | 14304 | "\n '-gap value' - set gap between sub-parts" |
14305 | "\n '-part axis mode {0|1}' - set visual part" | |
84b904bc | 14306 | "\n '-parts axis mode {0|1}' - set visual part" |
625e1958 | 14307 | "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator" |
14308 | "\n '-size value' - set size of manipulator" | |
14309 | "\n '-zoomable {0|1}' - set zoom persistence", | |
14310 | __FILE__, VManipulator, group); | |
14311 | ||
8e5fb5ea | 14312 | theCommands.Add("vselprops", |
f838dac4 | 14313 | "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]" |
8e5fb5ea | 14314 | "\n Customizes selection and dynamic highlight parameters for the whole interactive context:" |
14315 | "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode" | |
be3d8cbc | 14316 | "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer" |
14317 | "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state" | |
14c4193d | 14318 | "\n -pickStrategy {first|topmost} : defines picking strategy" |
14319 | "\n 'first' to pick first acceptable (default)" | |
14320 | "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)" | |
8e5fb5ea | 14321 | "\n -pixTol value : sets up pixel tolerance" |
f838dac4 | 14322 | "\n -dispMode dispMode : sets display mode for highlighting" |
14323 | "\n -layer ZLayer : sets ZLayer for highlighting" | |
14324 | "\n -color {name|r g b} : sets highlight color" | |
14325 | "\n -transp value : sets transparency coefficient for highlight" | |
14326 | "\n -material material : sets highlight material" | |
8e5fb5ea | 14327 | "\n -print : prints current state of all mentioned parameters", |
14328 | __FILE__, VSelectionProperties, group); | |
be3d8cbc | 14329 | theCommands.Add ("vhighlightselected", |
14330 | "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n", | |
14331 | __FILE__, VSelectionProperties, group); | |
8e5fb5ea | 14332 | |
decdee7d | 14333 | theCommands.Add ("vseldump", |
14334 | "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1" | |
14335 | "\n\t\t: Generate an image based on detection results:" | |
14336 | "\n\t\t: depth normalized depth values" | |
14337 | "\n\t\t: unnormDepth unnormalized depth values" | |
14338 | "\n\t\t: object color of detected object" | |
14339 | "\n\t\t: owner color of detected owner" | |
14340 | "\n\t\t: selMode color of selection mode" | |
14341 | "\n\t\t: entity color of etected entity", | |
14342 | __FILE__, VDumpSelectionImage, group); | |
293211ae | 14343 | |
2108d9a2 | 14344 | theCommands.Add ("vviewcube", |
14345 | "vviewcube name" | |
14346 | "\n\t\t: Displays interactive view manipualtion object." | |
14347 | "\n\t\t: Options: " | |
14348 | "\n\t\t: -reset reset geomertical and visual attributes'" | |
14349 | "\n\t\t: -size Size adapted size of View Cube" | |
14350 | "\n\t\t: -boxSize Size box size" | |
14351 | "\n\t\t: -axes {0|1 } show/hide axes (trihedron)" | |
14352 | "\n\t\t: -edges {0|1} show/hide edges of View Cube" | |
14353 | "\n\t\t: -vertices {0|1} show/hide vertices of View Cube" | |
14354 | "\n\t\t: -Yup {0|1} -Zup {0|1} set Y-up or Z-up view orientation" | |
14355 | "\n\t\t: -color Color color of View Cube" | |
14356 | "\n\t\t: -boxColor Color box color" | |
14357 | "\n\t\t: -boxSideColor Color box sides color" | |
14358 | "\n\t\t: -boxEdgeColor Color box edges color" | |
14359 | "\n\t\t: -boxCornerColor Color box corner color" | |
14360 | "\n\t\t: -textColor Color color of side text of view cube" | |
14361 | "\n\t\t: -innerColor Color inner box color" | |
14362 | "\n\t\t: -transparency Value transparency of object within [0, 1] range" | |
14363 | "\n\t\t: -boxTransparency Value transparency of box within [0, 1] range" | |
14364 | "\n\t\t: -font Name font name" | |
14365 | "\n\t\t: -fontHeight Value font height" | |
14366 | "\n\t\t: -boxFacetExtension Value box facet extension" | |
14367 | "\n\t\t: -boxEdgeGap Value gap between box edges and box sides" | |
14368 | "\n\t\t: -boxEdgeMinSize Value minimal box edge size" | |
14369 | "\n\t\t: -boxCornerMinSize Value minimal box corner size" | |
14370 | "\n\t\t: -axesPadding Value padding between box and arrows" | |
14371 | "\n\t\t: -roundRadius Value relative radius of corners of sides within [0.0, 0.5] range" | |
14372 | "\n\t\t: -fixedanimation {0|1} uninterruptible animation loop" | |
14373 | "\n\t\t: -duration Seconds animation duration in seconds", | |
14374 | __FILE__, VViewCube, group); | |
14375 | ||
14376 | } |